@cicctencent/formily 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +40 -0
- package/.prettierrc.js +28 -0
- package/.vscode/launch.json +23 -0
- package/CHANGELOG.md +8 -0
- package/README.md +22 -2
- package/babel.config.js +3 -0
- package/build/build.js +96 -0
- package/build/rollup.config.bundle.js +63 -0
- package/build/update.version.js +35 -0
- package/dist/index.css +2516 -0
- package/dist/index.js +8377 -0
- package/dist/schema-field/index.css +2466 -0
- package/dist/schema-field/index.js +8213 -0
- package/dist/transform/index.js +551 -0
- package/dist/validate/index.js +1104 -0
- package/dist/vue-form/index.css +2516 -0
- package/dist/vue-form/index.js +8359 -0
- package/docs/.vuepress/client.ts +15 -0
- package/docs/.vuepress/components/code-preview.vue +203 -0
- package/docs/.vuepress/components/highlight.ts +53 -0
- package/docs/.vuepress/config.ts +39 -0
- package/docs/.vuepress/util.ts +7 -0
- package/docs/README.md +30 -0
- package/docs/components/anyOf.md +26 -0
- package/docs/components/array-cards.md +12 -0
- package/docs/components/array-collapse.md +12 -0
- package/docs/components/array-items.md +12 -0
- package/docs/components/array-table.md +12 -0
- package/docs/components/array-tabs.md +16 -0
- package/docs/components/cascader.md +12 -0
- package/docs/components/checkbox.md +12 -0
- package/docs/components/event.md +27 -0
- package/docs/components/hotArea.md +25 -0
- package/docs/components/index.md +4 -0
- package/docs/components/input.md +30 -0
- package/docs/components/layout-group.md +19 -0
- package/docs/components/link.md +22 -0
- package/docs/components/oneOf.md +8 -0
- package/docs/components/radio.md +12 -0
- package/docs/components/rich-editor.md +21 -0
- package/docs/components/select.md +34 -0
- package/docs/components/space.md +11 -0
- package/docs/components/switch.md +20 -0
- package/docs/components/text.md +21 -0
- package/docs/components/time-picker.md +11 -0
- package/docs/components/transfer.md +14 -0
- package/docs/components/upload-button.md +28 -0
- package/docs/demos/any-of/index.vue +66 -0
- package/docs/demos/array-cards/index.vue +105 -0
- package/docs/demos/array-collapse/index.vue +155 -0
- package/docs/demos/array-items/index.vue +171 -0
- package/docs/demos/array-table/index.vue +115 -0
- package/docs/demos/array-tabs/index.vue +56 -0
- package/docs/demos/cascader/index.vue +297 -0
- package/docs/demos/checkbox/index.vue +39 -0
- package/docs/demos/event/index.vue +436 -0
- package/docs/demos/hotArea/index.vue +240 -0
- package/docs/demos/index.vue +36 -0
- package/docs/demos/input/index.vue +46 -0
- package/docs/demos/layout-group/index.vue +51 -0
- package/docs/demos/link/index.vue +32 -0
- package/docs/demos/radio/index.vue +36 -0
- package/docs/demos/rich-editor/index.vue +22 -0
- package/docs/demos/select/index.vue +76 -0
- package/docs/demos/space/index.vue +93 -0
- package/docs/demos/switch/index.vue +31 -0
- package/docs/demos/text/index.vue +38 -0
- package/docs/demos/time-picker/index.vue +39 -0
- package/docs/demos/transfer/index.vue +26 -0
- package/docs/demos/upload-button/index.vue +27 -0
- package/docs/demos/x-data/add-button-title.vue +101 -0
- package/docs/demos/x-data/send-message.vue +33 -0
- package/docs/demos/x-reactions/any-of.vue +40 -0
- package/docs/demos/x-reactions/x-reactions.vue +39 -0
- package/docs/guide/component-extend.md +23 -0
- package/docs/guide/extra-bury-report.md +64 -0
- package/docs/guide/schema.md +22 -0
- package/docs/guide/x-data.md +41 -0
- package/docs/guide/x-reactions.md +20 -0
- package/example/.browserslistrc +4 -0
- package/example/.eslintrc.js +20 -0
- package/example/README.md +24 -0
- package/example/index.html +15 -0
- package/example/jest.config.js +26 -0
- package/example/package.json +50 -0
- package/example/public/favicon.ico +0 -0
- package/example/public/index.html +17 -0
- package/example/src/App.vue +25 -0
- package/example/src/assets/logo.png +0 -0
- package/example/src/components/HelloWorld.vue +148 -0
- package/example/src/components/group/index.vue +16 -0
- package/example/src/components/uploadBtn/index.vue +44 -0
- package/example/src/components/uploadBtn/upload-icon.svg +6 -0
- package/example/src/layout/component/Aside.vue +39 -0
- package/example/src/layout/component/Main.vue +9 -0
- package/example/src/layout/index.vue +15 -0
- package/example/src/main.ts +17 -0
- package/example/src/router/index.ts +99 -0
- package/example/src/shims-vue.d.ts +6 -0
- package/example/src/store/index.ts +9 -0
- package/example/src/views/demo/any-of/data.ts +38 -0
- package/example/src/views/demo/any-of/index.vue +35 -0
- package/example/src/views/demo/array-cards/data.ts +65 -0
- package/example/src/views/demo/array-cards/index.vue +33 -0
- package/example/src/views/demo/array-items/data.ts +29 -0
- package/example/src/views/demo/array-items/index.vue +33 -0
- package/example/src/views/demo/cloud-button/data.ts +14 -0
- package/example/src/views/demo/cloud-button/index.vue +22 -0
- package/example/src/views/demo/color-group/data.ts +15 -0
- package/example/src/views/demo/color-group/index.vue +22 -0
- package/example/src/views/demo/color-picker/data.ts +21 -0
- package/example/src/views/demo/color-picker/index.vue +33 -0
- package/example/src/views/demo/datatime/data.ts +62 -0
- package/example/src/views/demo/datatime/index.vue +22 -0
- package/example/src/views/demo/event/data.ts +184 -0
- package/example/src/views/demo/event/index.vue +33 -0
- package/example/src/views/demo/hot-area/data.ts +196 -0
- package/example/src/views/demo/hot-area/index.vue +33 -0
- package/example/src/views/demo/input/data.ts +39 -0
- package/example/src/views/demo/input/index.vue +33 -0
- package/example/src/views/demo/link/data.ts +23 -0
- package/example/src/views/demo/link/index.vue +22 -0
- package/example/src/views/demo/one-of/data.ts +139 -0
- package/example/src/views/demo/one-of/index.vue +33 -0
- package/example/src/views/demo/rich-editor/data.ts +12 -0
- package/example/src/views/demo/rich-editor/index.vue +24 -0
- package/example/src/views/demo/select/data.ts +38 -0
- package/example/src/views/demo/select/index.vue +33 -0
- package/example/src/views/demo/upload-button/data1.ts +11 -0
- package/example/src/views/demo/upload-button/data2.ts +12 -0
- package/example/src/views/demo/upload-button/index.vue +42 -0
- package/example/tsconfig.json +32 -0
- package/example/vite.config.ts +12 -0
- package/jest.config.js +4 -0
- package/package.json +92 -4
- package/src/components/__builtins__/configs/index.ts +1 -0
- package/src/components/__builtins__/index.ts +2 -0
- package/src/components/__builtins__/shared/create-context.ts +54 -0
- package/src/components/__builtins__/shared/index.ts +7 -0
- package/src/components/__builtins__/shared/loading.ts +20 -0
- package/src/components/__builtins__/shared/portal.ts +43 -0
- package/src/components/__builtins__/shared/resolve-component.ts +22 -0
- package/src/components/__builtins__/shared/transform-component.ts +33 -0
- package/src/components/__builtins__/shared/types.ts +8 -0
- package/src/components/__builtins__/shared/utils.ts +35 -0
- package/src/components/__builtins__/styles/common.scss +22 -0
- package/src/components/__builtins__/styles/element-plus.scss +1094 -0
- package/src/components/any-of/index.ts +20 -0
- package/src/components/array-base/index.ts +413 -0
- package/src/components/array-base/style.scss +53 -0
- package/src/components/array-base/style.ts +2 -0
- package/src/components/array-cards/index.ts +253 -0
- package/src/components/array-cards/style.scss +33 -0
- package/src/components/array-cards/style.ts +7 -0
- package/src/components/array-collapse/index.ts +381 -0
- package/src/components/array-collapse/style.scss +38 -0
- package/src/components/array-collapse/style.ts +10 -0
- package/src/components/array-items/index.ts +213 -0
- package/src/components/array-items/style.scss +82 -0
- package/src/components/array-items/style.ts +4 -0
- package/src/components/array-table/index.ts +567 -0
- package/src/components/array-table/style.scss +84 -0
- package/src/components/array-table/style.ts +11 -0
- package/src/components/array-tabs/index.ts +141 -0
- package/src/components/array-tabs/style.scss +16 -0
- package/src/components/array-tabs/style.ts +5 -0
- package/src/components/base/AnyOf/index.ts +155 -0
- package/src/components/base/AnyOf/index.vue +111 -0
- package/src/components/base/CloudButton/index.ts +46 -0
- package/src/components/base/CloudButton/index.vue +128 -0
- package/src/components/base/ColorGroup/index.ts +57 -0
- package/src/components/base/ColorGroup/index.vue +30 -0
- package/src/components/base/ColorPicker/index.ts +45 -0
- package/src/components/base/ColorPicker/index.vue +50 -0
- package/src/components/base/Container/index.vue +39 -0
- package/src/components/base/HotArea/index.ts +698 -0
- package/src/components/base/HotArea/index.vue +565 -0
- package/src/components/base/HotArea/type.ts +18 -0
- package/src/components/base/Input/index.vue +150 -0
- package/src/components/base/LayoutGroup/index.vue +40 -0
- package/src/components/base/Link/index.vue +43 -0
- package/src/components/base/Middleware/index.ts +235 -0
- package/src/components/base/Middleware/index.vue +169 -0
- package/src/components/base/OneOf/index.ts +105 -0
- package/src/components/base/OneOf/index.vue +85 -0
- package/src/components/base/RichEditor/index.ts +13 -0
- package/src/components/base/RichEditor/index.vue +120 -0
- package/src/components/base/RichEditor/options.ts +24 -0
- package/src/components/base/Select/index.ts +106 -0
- package/src/components/base/Select/index.vue +161 -0
- package/src/components/base/Switch/index.vue +42 -0
- package/src/components/base/Text/index.vue +47 -0
- package/src/components/base/event/index.ts +226 -0
- package/src/components/base/event/index.vue +356 -0
- package/src/components/cascader/index.ts +48 -0
- package/src/components/cascader/style.ts +5 -0
- package/src/components/checkbox/index.ts +166 -0
- package/src/components/checkbox/style.ts +5 -0
- package/src/components/cloud-button/index.ts +21 -0
- package/src/components/color-group/index.ts +18 -0
- package/src/components/color-picker/index.ts +18 -0
- package/src/components/container/index.ts +18 -0
- package/src/components/data-time/index.ts +24 -0
- package/src/components/date-picker/index.ts +51 -0
- package/src/components/date-picker/style.ts +4 -0
- package/src/components/editable/index.ts +261 -0
- package/src/components/editable/style.scss +55 -0
- package/src/components/editable/style.ts +5 -0
- package/src/components/el-form-item/index.ts +21 -0
- package/src/components/el-form-item/style.ts +3 -0
- package/src/components/event/index.ts +16 -0
- package/src/components/form/index.ts +94 -0
- package/src/components/form/style.scss +0 -0
- package/src/components/form/style.ts +3 -0
- package/src/components/form-button-group/index.ts +74 -0
- package/src/components/form-button-group/style.scss +0 -0
- package/src/components/form-button-group/style.ts +4 -0
- package/src/components/form-collapse/index.ts +215 -0
- package/src/components/form-collapse/style.scss +6 -0
- package/src/components/form-collapse/style.ts +4 -0
- package/src/components/form-dialog/index.ts +433 -0
- package/src/components/form-dialog/style.ts +4 -0
- package/src/components/form-drawer/index.ts +424 -0
- package/src/components/form-drawer/style.scss +21 -0
- package/src/components/form-drawer/style.ts +4 -0
- package/src/components/form-grid/index.ts +181 -0
- package/src/components/form-grid/style.scss +5 -0
- package/src/components/form-grid/style.ts +1 -0
- package/src/components/form-item/animation.scss +72 -0
- package/src/components/form-item/grid.scss +171 -0
- package/src/components/form-item/index.ts +642 -0
- package/src/components/form-item/style.scss +521 -0
- package/src/components/form-item/style.ts +2 -0
- package/src/components/form-item/var.scss +17 -0
- package/src/components/form-layout/index.ts +161 -0
- package/src/components/form-layout/style.scss +6 -0
- package/src/components/form-layout/style.ts +1 -0
- package/src/components/form-layout/useResponsiveFormLayout.ts +118 -0
- package/src/components/form-step/index.ts +210 -0
- package/src/components/form-step/style.ts +2 -0
- package/src/components/form-tab/index.ts +172 -0
- package/src/components/form-tab/style.scss +6 -0
- package/src/components/form-tab/style.ts +4 -0
- package/src/components/hot-area/index.ts +20 -0
- package/src/components/index.ts +49 -0
- package/src/components/input/index.ts +35 -0
- package/src/components/input/style.ts +4 -0
- package/src/components/input-number/index.ts +36 -0
- package/src/components/input-number/style.ts +3 -0
- package/src/components/layout-group/index.ts +18 -0
- package/src/components/link/index.ts +18 -0
- package/src/components/middleware/index.ts +21 -0
- package/src/components/one-of/index.ts +20 -0
- package/src/components/placeholder-input/index.ts +21 -0
- package/src/components/placeholder-input/index.vue +87 -0
- package/src/components/preview-text/index.ts +303 -0
- package/src/components/preview-text/style.ts +9 -0
- package/src/components/radio/index.ts +109 -0
- package/src/components/radio/style.ts +3 -0
- package/src/components/reset/index.ts +52 -0
- package/src/components/reset/style.ts +1 -0
- package/src/components/rich-editor/index.ts +18 -0
- package/src/components/row/index.ts +20 -0
- package/src/components/row/index.vue +53 -0
- package/src/components/select/index.ts +19 -0
- package/src/components/select/style.ts +5 -0
- package/src/components/space/index.ts +98 -0
- package/src/components/space/style.scss +24 -0
- package/src/components/space/style.ts +1 -0
- package/src/components/submit/index.ts +59 -0
- package/src/components/submit/style.ts +1 -0
- package/src/components/switch/index.ts +9 -0
- package/src/components/switch/style.ts +1 -0
- package/src/components/text/index.ts +21 -0
- package/src/components/time-picker/index.ts +21 -0
- package/src/components/time-picker/style.ts +4 -0
- package/src/components/transfer/index.ts +12 -0
- package/src/components/transfer/style.ts +1 -0
- package/src/components/upload/index.ts +136 -0
- package/src/components/upload/style.ts +2 -0
- package/src/components/upload-button/index.ts +21 -0
- package/src/components/upload-button/index.vue +199 -0
- package/src/createScemaField.ts +14 -0
- package/src/index.ts +41 -0
- package/src/schema-field/index.ts +11 -0
- package/src/scope.ts +29 -0
- package/src/transform/core.ts +404 -0
- package/src/transform/index.ts +11 -0
- package/src/transform/transform.ts +59 -0
- package/src/transform/utils/constant.ts +79 -0
- package/src/transform/utils/func.ts +145 -0
- package/src/typings/common.ts +37 -0
- package/src/typings/vue-shim.d.ts +7 -0
- package/src/typings/vue-test-utils.d.ts +11 -0
- package/src/utils/anyof_utils.ts +95 -0
- package/src/utils/common.ts +15 -0
- package/src/validate/index.ts +648 -0
- package/src/validate/utils/constant.ts +2 -0
- package/src/vue-form/index.ts +18 -0
- package/src/vue-form/index.vue +106 -0
- package/src/vue-form/useForm.ts +112 -0
- package/tests/data/anyof.ts +40 -0
- package/tests/data/image.ts +472 -0
- package/tests/fixtures/validate.ts +63 -0
- package/tests/unit/transform.spec.ts +253 -0
- package/tests/unit/utils.spec.ts +10 -0
- package/tests/unit/validate.spec.ts +256 -0
- package/tsconfig.json +23 -0
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
import { isEqual } from 'lodash-es';
|
|
2
|
+
|
|
3
|
+
const FORMILY_KEYS = [
|
|
4
|
+
'type',
|
|
5
|
+
'title',
|
|
6
|
+
'description',
|
|
7
|
+
'default',
|
|
8
|
+
'readOnly',
|
|
9
|
+
'writeOnly',
|
|
10
|
+
'enum',
|
|
11
|
+
'const',
|
|
12
|
+
'multipleOf',
|
|
13
|
+
'maximum',
|
|
14
|
+
'exclusiveMaximum',
|
|
15
|
+
'minimum',
|
|
16
|
+
'exclusiveMinimum',
|
|
17
|
+
'maxLength',
|
|
18
|
+
'minLength',
|
|
19
|
+
'pattern',
|
|
20
|
+
'maxItems',
|
|
21
|
+
'minItems',
|
|
22
|
+
'uniqueItems',
|
|
23
|
+
'maxProperties',
|
|
24
|
+
'minProperties',
|
|
25
|
+
'required',
|
|
26
|
+
'format',
|
|
27
|
+
'additionalItems',
|
|
28
|
+
'patternProperties',
|
|
29
|
+
'additionalProperties',
|
|
30
|
+
'definitions',
|
|
31
|
+
'$ref',
|
|
32
|
+
];
|
|
33
|
+
const FORMILY_EXPAND_KEYS = [
|
|
34
|
+
'asterisk',
|
|
35
|
+
];
|
|
36
|
+
const COMMON_KEYS = [
|
|
37
|
+
'description',
|
|
38
|
+
'default',
|
|
39
|
+
'type',
|
|
40
|
+
'title',
|
|
41
|
+
'maxLength',
|
|
42
|
+
'multipleOf',
|
|
43
|
+
'const',
|
|
44
|
+
'x-decorator',
|
|
45
|
+
'x-component',
|
|
46
|
+
'x-component-props',
|
|
47
|
+
'x-decorator-props',
|
|
48
|
+
];
|
|
49
|
+
const COMPONENT_MAP = {
|
|
50
|
+
RadioWidget: 'Radio',
|
|
51
|
+
UploadWidget: 'UploadButton',
|
|
52
|
+
'hot-area': 'HotArea',
|
|
53
|
+
'rich-editor': 'RichEditor',
|
|
54
|
+
'el-color-picker': 'ColorPicker',
|
|
55
|
+
};
|
|
56
|
+
const FIELD_MAP = {
|
|
57
|
+
'ui:hidden': 'x-hidden',
|
|
58
|
+
};
|
|
59
|
+
const FIELD_KEYS = ['ui:hidden'];
|
|
60
|
+
var UniqueType;
|
|
61
|
+
(function (UniqueType) {
|
|
62
|
+
UniqueType[UniqueType["page"] = 1] = "page";
|
|
63
|
+
UniqueType[UniqueType["component"] = 2] = "component";
|
|
64
|
+
})(UniqueType || (UniqueType = {}));
|
|
65
|
+
|
|
66
|
+
function getComponentName(data) {
|
|
67
|
+
const keys = Object.keys(data);
|
|
68
|
+
if (keys.includes('x-component')) {
|
|
69
|
+
return data['x-component'];
|
|
70
|
+
}
|
|
71
|
+
else if (keys.includes('ui:widget')) {
|
|
72
|
+
return COMPONENT_MAP[data['ui:widget']];
|
|
73
|
+
}
|
|
74
|
+
else if (keys.includes('enum')) {
|
|
75
|
+
return 'Select';
|
|
76
|
+
}
|
|
77
|
+
else if (keys.includes('format')) {
|
|
78
|
+
switch (data['format']) {
|
|
79
|
+
case 'color':
|
|
80
|
+
return 'ColorPicker';
|
|
81
|
+
case 'date-time':
|
|
82
|
+
return 'DateTime';
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else if (keys.includes('type')) {
|
|
86
|
+
switch (data['type']) {
|
|
87
|
+
case 'string':
|
|
88
|
+
return 'Input';
|
|
89
|
+
case 'number':
|
|
90
|
+
return 'InputNumber';
|
|
91
|
+
case 'boolean':
|
|
92
|
+
return 'Switch';
|
|
93
|
+
case 'array':
|
|
94
|
+
return 'ArrayItems';
|
|
95
|
+
case 'object':
|
|
96
|
+
if (keys.includes('oneOf')) {
|
|
97
|
+
return 'OneOf';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (keys.includes('anyOf')) {
|
|
102
|
+
return 'AnyOf';
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
function isAnyOf(data) {
|
|
106
|
+
return 'anyOf' in data;
|
|
107
|
+
}
|
|
108
|
+
function isOneOf(data) {
|
|
109
|
+
return 'oneOf' in data;
|
|
110
|
+
}
|
|
111
|
+
function oneOfTransformEnum(oneOfData) {
|
|
112
|
+
const result = [];
|
|
113
|
+
oneOfData.forEach(o => {
|
|
114
|
+
const properties = o === null || o === void 0 ? void 0 : o.properties;
|
|
115
|
+
let value = {};
|
|
116
|
+
for (const key in properties) {
|
|
117
|
+
if ('default' in properties[key]) {
|
|
118
|
+
value[key] = properties[key].default;
|
|
119
|
+
}
|
|
120
|
+
else if ('properties' in properties[key]) {
|
|
121
|
+
value[key] = {};
|
|
122
|
+
Object.keys(properties[key].properties).forEach(oKey => {
|
|
123
|
+
value[key][oKey] = properties[key].properties[oKey].default;
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
result.push({ label: o.title, value });
|
|
128
|
+
});
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
function emitEnum(enumValues, enumNames = []) {
|
|
132
|
+
if (!Array.isArray(enumValues)) {
|
|
133
|
+
return [];
|
|
134
|
+
}
|
|
135
|
+
if (typeof enumValues[0] === 'object') {
|
|
136
|
+
return enumValues;
|
|
137
|
+
}
|
|
138
|
+
const result = [];
|
|
139
|
+
if (Array.isArray(enumNames) && enumNames.length > 0) {
|
|
140
|
+
for (let i = 0; i < enumValues.length; i++) {
|
|
141
|
+
result.push({ label: enumNames[i], value: enumValues[i] });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
for (let i = 0; i < enumValues.length; i++) {
|
|
146
|
+
result.push({ label: enumValues[i], value: enumValues[i] });
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
function mergePropertiesColors(properties) {
|
|
152
|
+
var _a, _b;
|
|
153
|
+
if (!properties || typeof properties !== 'object') {
|
|
154
|
+
return {};
|
|
155
|
+
}
|
|
156
|
+
const colorGroup = {};
|
|
157
|
+
for (const key in properties) {
|
|
158
|
+
if (!properties[key]) {
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (((_a = properties[key]) === null || _a === void 0 ? void 0 : _a.format) === 'color' ||
|
|
162
|
+
((_b = properties[key]) === null || _b === void 0 ? void 0 : _b['x-component']) === 'ColorPicker' ||
|
|
163
|
+
properties[key]['ui:widget'] === 'el-color-picker' ||
|
|
164
|
+
key.toLocaleUpperCase().indexOf('COLOR') !== -1 ||
|
|
165
|
+
key.toLocaleUpperCase() == 'BACKGROUND') {
|
|
166
|
+
colorGroup[key] = properties[key];
|
|
167
|
+
delete properties[key];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return colorGroup;
|
|
171
|
+
}
|
|
172
|
+
function simpleGenerationSchemaItem(data) {
|
|
173
|
+
const result = Object.assign(Object.assign({ 'x-component': getComponentName(data), 'x-decorator': 'FormItem' }, data), { 'x-decorator-props': { layout: 'vertical', labelAlign: 'left', labelWrap: true } });
|
|
174
|
+
return result;
|
|
175
|
+
}
|
|
176
|
+
function getXData(data) {
|
|
177
|
+
if ('x-data' in data) {
|
|
178
|
+
return data['x-data'];
|
|
179
|
+
}
|
|
180
|
+
return {};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function isSchemaConfig(data = {}) {
|
|
184
|
+
if (!data || typeof data !== 'object') {
|
|
185
|
+
return false;
|
|
186
|
+
}
|
|
187
|
+
if (data['x-component'] || data['properties'] || data['title'] || data['type']) {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
class TransformCore {
|
|
194
|
+
constructor(state) {
|
|
195
|
+
Object.defineProperty(this, "existGroup", {
|
|
196
|
+
enumerable: true,
|
|
197
|
+
configurable: true,
|
|
198
|
+
writable: true,
|
|
199
|
+
value: false
|
|
200
|
+
});
|
|
201
|
+
Object.defineProperty(this, "state", {
|
|
202
|
+
enumerable: true,
|
|
203
|
+
configurable: true,
|
|
204
|
+
writable: true,
|
|
205
|
+
value: { schema: null, ctx: null, group: false }
|
|
206
|
+
});
|
|
207
|
+
this.state = Object.assign({}, this.state, state !== null && state !== void 0 ? state : {});
|
|
208
|
+
}
|
|
209
|
+
get existEvent() {
|
|
210
|
+
var _a, _b, _c, _d;
|
|
211
|
+
return ((_a = this.state.schema.properties) === null || _a === void 0 ? void 0 : _a.event) && !isEqual((_b = this.state.schema.properties) === null || _b === void 0 ? void 0 : _b.event, {}) && !isEqual((_d = (_c = this.state.schema.properties) === null || _c === void 0 ? void 0 : _c.event) === null || _d === void 0 ? void 0 : _d.properties, {});
|
|
212
|
+
}
|
|
213
|
+
compile() {
|
|
214
|
+
var _a, _b, _c, _d;
|
|
215
|
+
const result = this.compileItem(this.state.schema);
|
|
216
|
+
if (!this.existGroup && ((_a = this.state) === null || _a === void 0 ? void 0 : _a.group)) {
|
|
217
|
+
const groupConfig = {
|
|
218
|
+
_group1: {
|
|
219
|
+
type: 'void',
|
|
220
|
+
'x-decorator': 'LayoutGroup',
|
|
221
|
+
'x-decorator-props': {
|
|
222
|
+
title: '基础配置'
|
|
223
|
+
},
|
|
224
|
+
properties: {
|
|
225
|
+
props: (_b = result === null || result === void 0 ? void 0 : result.properties) === null || _b === void 0 ? void 0 : _b.props,
|
|
226
|
+
style: (_c = result === null || result === void 0 ? void 0 : result.properties) === null || _c === void 0 ? void 0 : _c.style
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
if (this.existEvent) {
|
|
231
|
+
groupConfig['_group2'] = {
|
|
232
|
+
type: 'void',
|
|
233
|
+
'x-decorator': 'LayoutGroup',
|
|
234
|
+
'x-decorator-props': {
|
|
235
|
+
title: ''
|
|
236
|
+
},
|
|
237
|
+
properties: {
|
|
238
|
+
event: (_d = result === null || result === void 0 ? void 0 : result.properties) === null || _d === void 0 ? void 0 : _d.event,
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
type: 'object',
|
|
244
|
+
properties: Object.assign({}, groupConfig)
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
return result;
|
|
248
|
+
}
|
|
249
|
+
compileItem(data) {
|
|
250
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
251
|
+
if (!data || isEqual(data, {})) {
|
|
252
|
+
return {};
|
|
253
|
+
}
|
|
254
|
+
let result = {};
|
|
255
|
+
for (const key in data) {
|
|
256
|
+
if (key === 'properties') {
|
|
257
|
+
result[key] = this.compileProperties(data[key], (_a = data['required']) !== null && _a !== void 0 ? _a : []);
|
|
258
|
+
return result;
|
|
259
|
+
}
|
|
260
|
+
if (key === 'items') {
|
|
261
|
+
if ('format' in data && data['format'] === 'date-time') {
|
|
262
|
+
result[key] = data[key];
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
result = Object.assign({}, result, this.compileItems(data[key]));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
if (FORMILY_KEYS.includes(key) || key.indexOf('x-') !== -1 || FORMILY_EXPAND_KEYS.includes(key)) {
|
|
269
|
+
result[key] = data[key];
|
|
270
|
+
}
|
|
271
|
+
else if (key.indexOf('ui:') !== -1) {
|
|
272
|
+
if (key === 'ui:options') {
|
|
273
|
+
if (data['ui:widget'] === 'hot-area' && 'event' in data['ui:options']) {
|
|
274
|
+
data['ui:options'].options = (_j = (_h = (_g = (_f = (_e = (_d = (_c = (_b = data['ui:options'].event) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c.list) === null || _d === void 0 ? void 0 : _d.items) === null || _e === void 0 ? void 0 : _e.properties) === null || _f === void 0 ? void 0 : _f.handler) === null || _g === void 0 ? void 0 : _g.properties) === null || _h === void 0 ? void 0 : _h.name) === null || _j === void 0 ? void 0 : _j.enum;
|
|
275
|
+
data['ui:options'].event = JSON.stringify(data['ui:options'].event);
|
|
276
|
+
}
|
|
277
|
+
this.setComponentProps(result, Object.assign({}, data['ui:options']));
|
|
278
|
+
}
|
|
279
|
+
else if (key === 'ui:hidden') {
|
|
280
|
+
result['x-hidden'] = data[key];
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
if (key === 'unique') {
|
|
284
|
+
result[key] = data[key];
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
if ('enum' in data) {
|
|
288
|
+
result['enum'] = emitEnum(data['enum'], (_k = data['enumNames']) !== null && _k !== void 0 ? _k : []);
|
|
289
|
+
}
|
|
290
|
+
if (!result['x-component']) {
|
|
291
|
+
result['x-component'] = getComponentName(data);
|
|
292
|
+
}
|
|
293
|
+
if (!data['x-decorator'] && data['type'] !== 'void') {
|
|
294
|
+
result['x-decorator'] = 'FormItem';
|
|
295
|
+
}
|
|
296
|
+
if (isOneOf(data)) {
|
|
297
|
+
this.setComponentProps(result, {
|
|
298
|
+
list: '[]',
|
|
299
|
+
title: data.title,
|
|
300
|
+
});
|
|
301
|
+
result['title'] = '';
|
|
302
|
+
}
|
|
303
|
+
if (isAnyOf(data)) {
|
|
304
|
+
this.setComponentProps(result, {
|
|
305
|
+
list: JSON.stringify((_l = data.anyOf) !== null && _l !== void 0 ? _l : []),
|
|
306
|
+
title: data.title,
|
|
307
|
+
'@fileUpload': (file, done) => {
|
|
308
|
+
this.state.ctx.emit('fileUpload', file, done);
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
result['title'] = '';
|
|
312
|
+
result['required'] = (_m = result['required']) !== null && _m !== void 0 ? _m : true;
|
|
313
|
+
}
|
|
314
|
+
if (['HotArea', 'CloudButton', 'InformationConfig', 'Qa'].includes(result['x-component'])) {
|
|
315
|
+
result['title'] = '';
|
|
316
|
+
result['x-decorator'] = null;
|
|
317
|
+
}
|
|
318
|
+
this.setDecoratorProps(result);
|
|
319
|
+
this.setComponentProps(result, this.compileEvent(data));
|
|
320
|
+
if (result['x-component'] === 'Select') {
|
|
321
|
+
this.setComponentProps(result, { options: (_o = result['enum']) !== null && _o !== void 0 ? _o : [] });
|
|
322
|
+
if (!data['title'] && !!(data === null || data === void 0 ? void 0 : data.inlineTitle)) {
|
|
323
|
+
this.setComponentProps(result, { prefix: data === null || data === void 0 ? void 0 : data.inlineTitle });
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
else if (result['x-component'] === 'UploadButton') {
|
|
327
|
+
if (result['title'] && result['title'].indexOf('背景图片') === -1) {
|
|
328
|
+
this.setComponentProps(result, { title: '替换图片' });
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
}
|
|
333
|
+
compileItems(data) {
|
|
334
|
+
var _a, _b, _c, _d, _e, _f;
|
|
335
|
+
if (isOneOf(data)) {
|
|
336
|
+
return {
|
|
337
|
+
enum: oneOfTransformEnum(data.oneOf),
|
|
338
|
+
'x-component': 'Select',
|
|
339
|
+
'x-component-props': {
|
|
340
|
+
'value-key': 'name',
|
|
341
|
+
multiple: true,
|
|
342
|
+
'collapse-tags': true,
|
|
343
|
+
},
|
|
344
|
+
'x-decorator': 'FormItem',
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
const xData = getXData(data) || {};
|
|
348
|
+
if (!('properties' in data)) {
|
|
349
|
+
return {
|
|
350
|
+
items: Object.assign({}, simpleGenerationSchemaItem(data)),
|
|
351
|
+
properties: {
|
|
352
|
+
add: {
|
|
353
|
+
type: 'void',
|
|
354
|
+
title: (xData === null || xData === void 0 ? void 0 : xData.addButtonTitle) ? xData === null || xData === void 0 ? void 0 : xData.addButtonTitle : '添加条目',
|
|
355
|
+
'x-component': 'ArrayItems.Addition',
|
|
356
|
+
'x-component-props': {
|
|
357
|
+
type: (xData === null || xData === void 0 ? void 0 : xData.addButtonType) || 'primary',
|
|
358
|
+
size: (xData === null || xData === void 0 ? void 0 : xData.addButtonSize) || 'default',
|
|
359
|
+
plain: (xData === null || xData === void 0 ? void 0 : xData.addButtonPlain) || false,
|
|
360
|
+
},
|
|
361
|
+
},
|
|
362
|
+
},
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
const result = {};
|
|
366
|
+
for (const key in data) {
|
|
367
|
+
if (key === 'properties') {
|
|
368
|
+
result[key] = this.compileProperties(data[key], (_a = data['required']) !== null && _a !== void 0 ? _a : []);
|
|
369
|
+
}
|
|
370
|
+
if (COMMON_KEYS.includes(key)) {
|
|
371
|
+
result[key] = data[key];
|
|
372
|
+
}
|
|
373
|
+
if (FIELD_KEYS.includes(key)) {
|
|
374
|
+
result[FIELD_MAP[key]] = data[key];
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
if (!(result === null || result === void 0 ? void 0 : result.type)) {
|
|
378
|
+
result['type'] = 'object';
|
|
379
|
+
}
|
|
380
|
+
if (!(result === null || result === void 0 ? void 0 : result.required)) {
|
|
381
|
+
result['required'] = data['required'];
|
|
382
|
+
}
|
|
383
|
+
const listRes = { items: Object.assign({}, result) };
|
|
384
|
+
listRes['properties'] = {
|
|
385
|
+
add: {
|
|
386
|
+
type: 'void',
|
|
387
|
+
title: ((_b = getXData(data)) === null || _b === void 0 ? void 0 : _b.addButtonTitle) ? (_c = getXData(data)) === null || _c === void 0 ? void 0 : _c.addButtonTitle : '添加条目',
|
|
388
|
+
'x-component': 'ArrayItems.Addition',
|
|
389
|
+
'x-component-props': {
|
|
390
|
+
type: ((_d = getXData(data)) === null || _d === void 0 ? void 0 : _d.addButtonType) || 'primary',
|
|
391
|
+
size: ((_e = getXData(data)) === null || _e === void 0 ? void 0 : _e.addButtonSize) || 'default',
|
|
392
|
+
plain: ((_f = getXData(data)) === null || _f === void 0 ? void 0 : _f.addButtonPlain) || false,
|
|
393
|
+
},
|
|
394
|
+
},
|
|
395
|
+
};
|
|
396
|
+
return listRes;
|
|
397
|
+
}
|
|
398
|
+
compileProperties(data, requireds) {
|
|
399
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
400
|
+
let result = {};
|
|
401
|
+
for (const key in data) {
|
|
402
|
+
if (!isSchemaConfig(data[key])) {
|
|
403
|
+
result[key] = data[key];
|
|
404
|
+
}
|
|
405
|
+
else if (key === 'event' && ((_b = (_a = data[key]) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.list)) {
|
|
406
|
+
result[key] = {
|
|
407
|
+
type: 'object',
|
|
408
|
+
'x-component': 'Event',
|
|
409
|
+
'x-component-props': Object.assign({ schema: JSON.stringify((_d = (_c = data[key]) === null || _c === void 0 ? void 0 : _c.properties) !== null && _d !== void 0 ? _d : {}), options: (_m = (_l = (_k = (_j = (_h = (_g = (_f = (_e = data[key]) === null || _e === void 0 ? void 0 : _e.properties) === null || _f === void 0 ? void 0 : _f.list) === null || _g === void 0 ? void 0 : _g.items) === null || _h === void 0 ? void 0 : _h.properties) === null || _j === void 0 ? void 0 : _j.handler) === null || _k === void 0 ? void 0 : _k.properties) === null || _l === void 0 ? void 0 : _l.name) === null || _m === void 0 ? void 0 : _m.enum }, this.compileEvent(data, 'Event')),
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
result[key] = this.compileItem(data[key]);
|
|
414
|
+
if (Array.isArray(requireds) && requireds.includes(key)) {
|
|
415
|
+
result[key]['required'] = true;
|
|
416
|
+
}
|
|
417
|
+
if (key === 'buryReportName') {
|
|
418
|
+
result[key]['unique'] = UniqueType.page;
|
|
419
|
+
result[key]['required'] = true;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
if (key.indexOf('group') > -1) {
|
|
423
|
+
this.existGroup = true;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return result;
|
|
427
|
+
}
|
|
428
|
+
compileEvent(data, componentName) {
|
|
429
|
+
const _componentName = componentName || getComponentName(data);
|
|
430
|
+
const result = {};
|
|
431
|
+
result['@getData'] = (cmdname, done, cmdParams) => {
|
|
432
|
+
this.state.ctx.emit('getData', cmdname, done, cmdParams);
|
|
433
|
+
};
|
|
434
|
+
switch (_componentName) {
|
|
435
|
+
case 'Event':
|
|
436
|
+
result['@fileUpload'] = (file, done, config) => {
|
|
437
|
+
this.state.ctx.emit('fileUpload', file, done, config);
|
|
438
|
+
};
|
|
439
|
+
break;
|
|
440
|
+
case 'AnyOf':
|
|
441
|
+
result['@fileUpload'] = (file, done, config) => {
|
|
442
|
+
this.state.ctx.emit('fileUpload', file, done, config);
|
|
443
|
+
};
|
|
444
|
+
break;
|
|
445
|
+
case COMPONENT_MAP.UploadWidget:
|
|
446
|
+
result['@fileUpload'] = (file, done) => {
|
|
447
|
+
var _a, _b, _c;
|
|
448
|
+
this.state.ctx.emit('fileUpload', file, done, data);
|
|
449
|
+
if (((_a = this.state.ctx.type) === null || _a === void 0 ? void 0 : _a.name) === 'HotArea') {
|
|
450
|
+
(_c = (_b = this.state.ctx) === null || _b === void 0 ? void 0 : _b.exposed) === null || _c === void 0 ? void 0 : _c.getUploadImageUrl(file, done);
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
break;
|
|
454
|
+
case 'CloudButton':
|
|
455
|
+
result['@openCloud'] = (params, done) => {
|
|
456
|
+
this.state.ctx.emit('openCloud', { data: params, config: data }, done);
|
|
457
|
+
};
|
|
458
|
+
result['@preload'] = (url) => {
|
|
459
|
+
this.state.ctx.emit('preloadCloud', url);
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
return result;
|
|
463
|
+
}
|
|
464
|
+
setDecoratorProps(data) {
|
|
465
|
+
var _a, _b;
|
|
466
|
+
let decoratorProps = {};
|
|
467
|
+
if (data['x-component'] === 'Switch') {
|
|
468
|
+
decoratorProps['wrapperAlign'] = 'right';
|
|
469
|
+
decoratorProps['labelAlign'] = 'left';
|
|
470
|
+
}
|
|
471
|
+
else {
|
|
472
|
+
decoratorProps['layout'] = ((_a = data === null || data === void 0 ? void 0 : data['x-decorator-props']) === null || _a === void 0 ? void 0 : _a.layout) || this.state.layout || 'vertical';
|
|
473
|
+
decoratorProps['labelAlign'] = 'left';
|
|
474
|
+
decoratorProps['labelWrap'] = true;
|
|
475
|
+
}
|
|
476
|
+
if (data === null || data === void 0 ? void 0 : data.description) {
|
|
477
|
+
if (data['x-component'] === 'Input') {
|
|
478
|
+
this.setComponentProps(data, { toolTip: data['description'] });
|
|
479
|
+
}
|
|
480
|
+
else {
|
|
481
|
+
decoratorProps['tooltip'] = data['description'];
|
|
482
|
+
}
|
|
483
|
+
delete data['description'];
|
|
484
|
+
}
|
|
485
|
+
if ('asterisk' in data && data['asterisk']) {
|
|
486
|
+
decoratorProps['asterisk'] = true;
|
|
487
|
+
}
|
|
488
|
+
data['x-decorator-props'] = Object.assign({}, (_b = data['x-decorator-props']) !== null && _b !== void 0 ? _b : {}, decoratorProps);
|
|
489
|
+
}
|
|
490
|
+
setComponentProps(data, _props = {}) {
|
|
491
|
+
var _a;
|
|
492
|
+
const componentProps = {};
|
|
493
|
+
for (const key in _props) {
|
|
494
|
+
componentProps[key] = _props[key];
|
|
495
|
+
}
|
|
496
|
+
data['x-component-props'] = Object.assign({}, (_a = data['x-component-props']) !== null && _a !== void 0 ? _a : {}, componentProps);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
function transformSchema({ schema, ctx, group = false, layout = 'vertical' }) {
|
|
501
|
+
if (!schema) {
|
|
502
|
+
return {};
|
|
503
|
+
}
|
|
504
|
+
let resConfig = {};
|
|
505
|
+
if ('properties' in schema) {
|
|
506
|
+
const data = Object.assign({}, schema);
|
|
507
|
+
formatColor(data);
|
|
508
|
+
resConfig = Object.assign({}, data);
|
|
509
|
+
}
|
|
510
|
+
else {
|
|
511
|
+
const properties = Object.assign({}, schema);
|
|
512
|
+
const data = {
|
|
513
|
+
type: 'object',
|
|
514
|
+
properties: properties,
|
|
515
|
+
};
|
|
516
|
+
formatColor(data);
|
|
517
|
+
resConfig = Object.assign({}, data);
|
|
518
|
+
}
|
|
519
|
+
const result = new TransformCore({ schema: resConfig, ctx, group, layout }).compile();
|
|
520
|
+
console.log('[jt-formily Transform]', 'transformSchema', 'result:', result);
|
|
521
|
+
return result;
|
|
522
|
+
}
|
|
523
|
+
function mergeColor(properties) {
|
|
524
|
+
let colors = mergePropertiesColors(properties);
|
|
525
|
+
if (colors && JSON.stringify(colors) != '{}') {
|
|
526
|
+
properties['colorGroup'] = {
|
|
527
|
+
type: 'void',
|
|
528
|
+
'x-decorator': 'ColorGroup',
|
|
529
|
+
properties: Object.assign({}, colors)
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
function formatColor(data) {
|
|
534
|
+
if (!(data === null || data === void 0 ? void 0 : data.properties)) {
|
|
535
|
+
return;
|
|
536
|
+
}
|
|
537
|
+
if ('colorGroup' in (data === null || data === void 0 ? void 0 : data.properties)) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
for (const key in data.properties) {
|
|
541
|
+
formatColor(data.properties[key]);
|
|
542
|
+
}
|
|
543
|
+
mergeColor(data.properties);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
var index = {
|
|
547
|
+
transformSchema,
|
|
548
|
+
TransformCore,
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
export { TransformCore, index as default, transformSchema };
|