Skip to content

Commit 8ef3788

Browse files
authored
Merge pull request #418 from vip-git/universal-schema
feat: universal schema setup for cross framework compilation
2 parents 05a5e9d + 087e33f commit 8ef3788

File tree

371 files changed

+28990
-1063
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

371 files changed

+28990
-1063
lines changed

.eslintrc.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module.exports = {
1919
'no-trailing-spaces': 'off',
2020
'react/jsx-indent': 'off',
2121
'no-unused-vars': 'off',
22+
'no-mixed-spaces-and-tabs': 'off',
2223
'react/jsx-indent-props': 'off',
2324
'react/jsx-props-no-spreading': 'off',
2425
'react/prop-types': 'off',
@@ -74,4 +75,7 @@ module.exports = {
7475
'env': {
7576
'jest/globals': true
7677
},
78+
"ignorePatterns": [
79+
"src/types/helpers/TransformSchema.type.ts"
80+
],
7781
};

.github/workflows/node-e2e.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
uses: actions/setup-node@v1
3434
with:
3535
node-version: ${{ matrix.node-version }}
36-
- run: rm -rf package.json && mv wdio-package.json package.json && npm install
36+
- run: rm -rf package.json && mv wdio-package.json package.json && npm install && npm run install-react-mui
3737
#- name: "Check if deployment is done"
3838
#env:
3939
# VERCEL_TOKEN: ${{secrets.VERCEL_TOKEN}}

.github/workflows/node.js.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
with:
3030
node-version: ${{ matrix.node-version }}
3131
- run: npm install --force
32+
- run: npm run install-react-mui
3233
- run: npm run build
3334
- run: npx jest --env=jsdom --config=jest.config.js --coverage --ci --updateSnapshot --detectOpenHandles --forceExit
3435
- name: Codecov

.github/workflows/prerelease.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
with:
1818
node-version: 14
1919
- run: npm install
20+
- run: npm run install-react-mui
2021
- run: npm run build
2122
- run: npx jest --env=jsdom --config=jest.config.js --coverage --ci --updateSnapshot --detectOpenHandles --forceExit
2223

@@ -31,6 +32,7 @@ jobs:
3132
node-version: 14
3233
registry-url: https://registry.npmjs.org/
3334
- run: npm install
35+
- run: npm run install-react-mui
3436
- run: npm run build
3537
- run: npm install -g json
3638
- run: json -I -f package.json -e 'this.scripts.postinstall="echo done"'
@@ -49,6 +51,7 @@ jobs:
4951
node-version: 14
5052
registry-url: https://npm.pkg.github.com/
5153
- run: npm install
54+
- run: npm run install-react-mui
5255
- run: npm run build
5356
- run: npm install -g json
5457
- run: json -I -f package.json -e 'this.name="@vip-git/react-jsonschema-form-material-ui"'

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
with:
1818
node-version: 14
1919
- run: npm install
20+
- run: npm run install-react-mui
2021
- run: npm run build
2122
- run: npx jest --env=jsdom --config=jest.config.js --coverage --ci --updateSnapshot --detectOpenHandles --forceExit
2223

@@ -31,6 +32,7 @@ jobs:
3132
node-version: 14
3233
registry-url: https://registry.npmjs.org/
3334
- run: npm install
35+
- run: npm run install-react-mui
3436
- run: npm run build
3537
- run: npx tsc index.js --declaration --allowJs --emitDeclarationOnly --skipLibCheck --outDir .
3638
- run: npm install -g json
@@ -50,6 +52,7 @@ jobs:
5052
node-version: 14
5153
registry-url: https://npm.pkg.github.com/
5254
- run: npm install
55+
- run: npm run install-react-mui
5356
- run: npm run build
5457
- run: npx tsc index.js --declaration --allowJs --emitDeclarationOnly --skipLibCheck --outDir .
5558
- run: npm install -g json

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ generator/package.json
1212
coverage
1313
.husky
1414
src/fields/components/**/package-lock.json
15+
src/framework
16+
src/universal-schema/ui-framework.ts
17+
src/universal-schema/types/ui-framework.type.ts
18+
scripts/installer/templates/react/src/ui-framework/index.ts
19+
package-lock.json
20+
temp
21+
scripts/installer/frameworks/**/config
22+
scripts/installer/frameworks/**/helpers
23+
scripts/installer/frameworks/**/universal-schema
24+
scripts/installer/frameworks/**/src/types
25+
scripts/generator/package-lock.json
26+
scripts/generator/package.json

changelog.md

Lines changed: 2 additions & 2 deletions
File renamed without changes.

demo/web/react/examples/stepper/index.js renamed to demo/examples/stepper/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import schema from './schema.json';
66
import uiSchema from './ui-schema.json';
77
import xhrSchema from './xhr-schema.json';
88
import formData from './form-data.json';
9-
import config from '../../../../../scripts/generator/components.json';
9+
import config from '../../../scripts/generator/frameworks/react/mui/components.json';
1010

1111
const sessionId = generate();
1212

demo/examples/stepper/index.native.js

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// JSON
2+
import schema from './schema.json';
3+
import uiSchema from './ui-schema.json';
4+
import xhrSchema from './xhr-schema.json';
5+
import formData from './form-data.json';
6+
import config from '../../../scripts/generator/frameworks/react-native/rnpaper/components.json';
7+
8+
const sessionId = Math.random(123);
9+
10+
formData.SelectComponents = {
11+
sessionId,
12+
};
13+
formData.PublishPackage = {
14+
sessionId,
15+
};
16+
formData.SelectComponents.listOfComponents = [];
17+
formData.SelectComponents.listOfInterceptors = [];
18+
formData.SelectComponents.listOfUtils = [];
19+
20+
Object.keys(config.interceptors).forEach((interceptor) => {
21+
schema.definitions.componentsList.dependencies.selectTheme.oneOf[1].properties.listOfInterceptors.items.enum.push(
22+
{
23+
key: config.interceptors[interceptor].name,
24+
value: config.interceptors[interceptor].name,
25+
disabled: config.interceptors[interceptor].isRequired,
26+
},
27+
);
28+
29+
if (config.interceptors[interceptor].isRequired) {
30+
formData.SelectComponents.listOfInterceptors.push(
31+
config.interceptors[interceptor].name,
32+
);
33+
}
34+
});
35+
36+
Object.keys(config.utils).forEach((util) => {
37+
/**
38+
* Todo: add support for component utils to be selected automatically and disabled
39+
*/
40+
schema.definitions.componentsList.dependencies.selectTheme.oneOf[1].properties.listOfUtils.items.enum.push(
41+
{
42+
key: config.utils[util].name,
43+
value: config.utils[util].name,
44+
disabled: config.utils[util].isRequired,
45+
},
46+
);
47+
48+
if (config.utils[util].isRequired) {
49+
formData.SelectComponents.listOfUtils.push(config.utils[util].name);
50+
}
51+
});
52+
53+
Object.keys(config.components).forEach((comp) => {
54+
const compEnums = schema
55+
.definitions
56+
.componentsList
57+
.dependencies
58+
.selectTheme.oneOf[1]
59+
.properties
60+
.listOfComponents
61+
.items
62+
.enum;
63+
64+
const compEnumVal = {
65+
key: config.components[comp].name,
66+
value: config.components[comp].name,
67+
disabled:
68+
config.components[comp].isDefault || config.components[comp].isRequired,
69+
};
70+
71+
if (config.components[comp]?.utils) {
72+
// Todo: Covert this to rules.json
73+
compEnumVal.onData = {
74+
equals: config.components[comp].name,
75+
adds: {
76+
listOfUtils: [],
77+
},
78+
};
79+
config.components[comp].utils.forEach((cu) => {
80+
const cUtils = config.utils[cu];
81+
compEnumVal.onData.adds.listOfUtils.push(cUtils.name);
82+
});
83+
}
84+
85+
compEnums.push(compEnumVal);
86+
87+
if (config.components[comp].isDefault || config.components[comp].isRequired) {
88+
formData.SelectComponents.listOfComponents.push(
89+
config.components[comp].name,
90+
);
91+
}
92+
});
93+
94+
export default {
95+
title: 'Steps UI',
96+
schema,
97+
uiSchema,
98+
formData,
99+
xhrSchema,
100+
};
File renamed without changes.

demo/mobile/reactnative/App.tsx

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22
import React from 'react';
33
import {
44
DefaultTheme,
5-
Provider as PaperProvider,
6-
Avatar,
7-
Button,
85
Card,
9-
Title,
10-
Paragraph
6+
Provider as PaperProvider,
117
} from 'react-native-paper';
128
import {
139
SafeAreaView,
@@ -17,9 +13,10 @@ import {
1713
} from 'react-native';
1814

1915
// Internal
20-
import ReactNativeForm from '../../../src/Form';
16+
import ReactNativeForm from '../../../src/cross-framework-wrapper/react/Form';
2117

22-
const LeftContent = (props: any) => <Avatar.Icon {...props} icon="folder" />
18+
// Demo
19+
import examples from '../../examples';
2320

2421
const App = () => {
2522
const isDarkMode = useColorScheme() === 'dark';
@@ -33,28 +30,45 @@ const App = () => {
3330
},
3431
};
3532

36-
3733
const backgroundStyle = {
3834
backgroundColor: isDarkMode ? theme.colors.primary : theme.colors.accent,
3935
};
36+
37+
// Make this dynamic based on array selection
38+
const { schema, uiSchema, formData } = examples[3].numbers;
39+
40+
const onSubmit = () => {};
41+
const onCancel = () => {};
42+
const onUpload = () => {};
43+
const onFormChanged = () => {};
44+
const onError = () => {};
4045

4146
return (
4247
<PaperProvider theme={theme}>
4348
<SafeAreaView style={backgroundStyle}>
4449
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
4550
<Card>
46-
<Card.Title title="Card Title" subtitle="Card Subtitle" left={LeftContent} />
51+
<Card.Title title="JSON Schema Form" subtitle="React-Native Paper" />
4752
<Card.Content>
48-
<Title>Card title</Title>
49-
<Paragraph>Card content</Paragraph>
53+
<ReactNativeForm
54+
schema={schema}
55+
xhrSchema={{}}
56+
uiSchema={uiSchema}
57+
formData={formData}
58+
onCancel={onCancel}
59+
onSubmit={onSubmit}
60+
onStepNext={onSubmit}
61+
onUpload={onUpload}
62+
onChange={onFormChanged}
63+
onError={onError}
64+
interceptors={{}}
65+
components={{}}
66+
validations={{}}
67+
submitOnEnter
68+
activityIndicatorEnabled
69+
/>
5070
</Card.Content>
51-
<Card.Cover source={{ uri: 'https://picsum.photos/700' }} />
52-
<Card.Actions>
53-
<Button>Cancel</Button>
54-
<Button>Ok</Button>
55-
</Card.Actions>
5671
</Card>
57-
<ReactNativeForm />
5872
</SafeAreaView>
5973
</PaperProvider>
6074
);

demo/mobile/reactnative/metro.config.js

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@
88
const path = require('path');
99

1010
const extraNodeModules = {
11-
'../../../src': path.resolve(__dirname + '/../../../src'),
11+
'../../../scripts/installer/frameworks/react-native/src': path.resolve(__dirname + '/../../../scripts/installer/frameworks/react-native/src'),
12+
'../../examples': path.resolve(__dirname + '/../../examples'),
13+
'../../../scripts/generator': path.resolve(__dirname + '/../../../scripts/generator'),
14+
'../../../src': path.resolve(__dirname + '/../../../src')
1215
};
1316

1417
const watchFolders = [
15-
path.resolve(__dirname + '/../../../src')
18+
path.resolve(__dirname + '/../../../scripts/installer/frameworks/react-native/src'),
19+
path.resolve(__dirname + '/../../examples'),
20+
path.resolve(__dirname + '/../../../scripts/generator'),
21+
path.resolve(__dirname + '/../../../src'),
1622
];
1723

1824
module.exports = {
@@ -30,6 +36,29 @@ module.exports = {
3036
//redirects dependencies referenced from common/ to local node_modules
3137
name in target ? target[name] : path.join(process.cwd(), `node_modules/${name}`),
3238
}),
39+
resolveRequest: (context, realModuleName, platform, moduleName) => {
40+
let module = realModuleName;
41+
if(realModuleName.includes('@universal-schema')) {
42+
module = module.replace('@universal-schema', path.resolve(__dirname + '/../../../src/universal-schema'));
43+
}
44+
if(realModuleName.includes('@core-types')) {
45+
module = module.replace('@core-types', path.resolve(__dirname + '/../../../src/types'));
46+
}
47+
if(realModuleName.includes('@helpers')) {
48+
module = module.replace('@helpers', path.resolve(__dirname + '/../../../src/helpers'));
49+
}
50+
if(realModuleName.includes('@framework')) {
51+
module = module.replace('@framework', path.resolve(__dirname + '/../../../scripts/installer/frameworks/react-native/src'));
52+
}
53+
if(realModuleName.includes('@config')) {
54+
module = module.replace('@config', path.resolve(__dirname + '/../../../src/config'));
55+
}
56+
if(realModuleName.includes('@generated')) {
57+
module = module.replace('@generated', path.resolve(__dirname + '/../../../scripts/installer/frameworks/react-native/src/generated'));
58+
}
59+
const { resolveRequest: removed, ...restContext } = context;
60+
return require("metro-resolver").resolve(restContext, module, platform);
61+
}
3362
},
3463
watchFolders,
3564
};

0 commit comments

Comments
 (0)