@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,1104 @@
|
|
|
1
|
+
import { log, isEqual as isEqual$1, cloneDeep, get, set } from '@cicctencent/ark-util';
|
|
2
|
+
import { isEqual } from 'lodash-es';
|
|
3
|
+
|
|
4
|
+
const WHITE_COMPONENTS = ['HotArea', 'Event', 'AnyOf', 'OneOf', 'Middleware'];
|
|
5
|
+
|
|
6
|
+
const FORMILY_KEYS = [
|
|
7
|
+
'type',
|
|
8
|
+
'title',
|
|
9
|
+
'description',
|
|
10
|
+
'default',
|
|
11
|
+
'readOnly',
|
|
12
|
+
'writeOnly',
|
|
13
|
+
'enum',
|
|
14
|
+
'const',
|
|
15
|
+
'multipleOf',
|
|
16
|
+
'maximum',
|
|
17
|
+
'exclusiveMaximum',
|
|
18
|
+
'minimum',
|
|
19
|
+
'exclusiveMinimum',
|
|
20
|
+
'maxLength',
|
|
21
|
+
'minLength',
|
|
22
|
+
'pattern',
|
|
23
|
+
'maxItems',
|
|
24
|
+
'minItems',
|
|
25
|
+
'uniqueItems',
|
|
26
|
+
'maxProperties',
|
|
27
|
+
'minProperties',
|
|
28
|
+
'required',
|
|
29
|
+
'format',
|
|
30
|
+
'additionalItems',
|
|
31
|
+
'patternProperties',
|
|
32
|
+
'additionalProperties',
|
|
33
|
+
'definitions',
|
|
34
|
+
'$ref',
|
|
35
|
+
];
|
|
36
|
+
const FORMILY_EXPAND_KEYS = [
|
|
37
|
+
'asterisk',
|
|
38
|
+
];
|
|
39
|
+
const COMMON_KEYS = [
|
|
40
|
+
'description',
|
|
41
|
+
'default',
|
|
42
|
+
'type',
|
|
43
|
+
'title',
|
|
44
|
+
'maxLength',
|
|
45
|
+
'multipleOf',
|
|
46
|
+
'const',
|
|
47
|
+
'x-decorator',
|
|
48
|
+
'x-component',
|
|
49
|
+
'x-component-props',
|
|
50
|
+
'x-decorator-props',
|
|
51
|
+
];
|
|
52
|
+
const COMPONENT_MAP = {
|
|
53
|
+
RadioWidget: 'Radio',
|
|
54
|
+
UploadWidget: 'UploadButton',
|
|
55
|
+
'hot-area': 'HotArea',
|
|
56
|
+
'rich-editor': 'RichEditor',
|
|
57
|
+
'el-color-picker': 'ColorPicker',
|
|
58
|
+
};
|
|
59
|
+
const FIELD_MAP = {
|
|
60
|
+
'ui:hidden': 'x-hidden',
|
|
61
|
+
};
|
|
62
|
+
const FIELD_KEYS = ['ui:hidden'];
|
|
63
|
+
var UniqueType;
|
|
64
|
+
(function (UniqueType) {
|
|
65
|
+
UniqueType[UniqueType["page"] = 1] = "page";
|
|
66
|
+
UniqueType[UniqueType["component"] = 2] = "component";
|
|
67
|
+
})(UniqueType || (UniqueType = {}));
|
|
68
|
+
|
|
69
|
+
function getComponentName(data) {
|
|
70
|
+
const keys = Object.keys(data);
|
|
71
|
+
if (keys.includes('x-component')) {
|
|
72
|
+
return data['x-component'];
|
|
73
|
+
}
|
|
74
|
+
else if (keys.includes('ui:widget')) {
|
|
75
|
+
return COMPONENT_MAP[data['ui:widget']];
|
|
76
|
+
}
|
|
77
|
+
else if (keys.includes('enum')) {
|
|
78
|
+
return 'Select';
|
|
79
|
+
}
|
|
80
|
+
else if (keys.includes('format')) {
|
|
81
|
+
switch (data['format']) {
|
|
82
|
+
case 'color':
|
|
83
|
+
return 'ColorPicker';
|
|
84
|
+
case 'date-time':
|
|
85
|
+
return 'DateTime';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else if (keys.includes('type')) {
|
|
89
|
+
switch (data['type']) {
|
|
90
|
+
case 'string':
|
|
91
|
+
return 'Input';
|
|
92
|
+
case 'number':
|
|
93
|
+
return 'InputNumber';
|
|
94
|
+
case 'boolean':
|
|
95
|
+
return 'Switch';
|
|
96
|
+
case 'array':
|
|
97
|
+
return 'ArrayItems';
|
|
98
|
+
case 'object':
|
|
99
|
+
if (keys.includes('oneOf')) {
|
|
100
|
+
return 'OneOf';
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
else if (keys.includes('anyOf')) {
|
|
105
|
+
return 'AnyOf';
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function isAnyOf(data) {
|
|
109
|
+
return 'anyOf' in data;
|
|
110
|
+
}
|
|
111
|
+
function isOneOf(data) {
|
|
112
|
+
return 'oneOf' in data;
|
|
113
|
+
}
|
|
114
|
+
function oneOfTransformEnum(oneOfData) {
|
|
115
|
+
const result = [];
|
|
116
|
+
oneOfData.forEach(o => {
|
|
117
|
+
const properties = o === null || o === void 0 ? void 0 : o.properties;
|
|
118
|
+
let value = {};
|
|
119
|
+
for (const key in properties) {
|
|
120
|
+
if ('default' in properties[key]) {
|
|
121
|
+
value[key] = properties[key].default;
|
|
122
|
+
}
|
|
123
|
+
else if ('properties' in properties[key]) {
|
|
124
|
+
value[key] = {};
|
|
125
|
+
Object.keys(properties[key].properties).forEach(oKey => {
|
|
126
|
+
value[key][oKey] = properties[key].properties[oKey].default;
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
result.push({ label: o.title, value });
|
|
131
|
+
});
|
|
132
|
+
return result;
|
|
133
|
+
}
|
|
134
|
+
function emitEnum(enumValues, enumNames = []) {
|
|
135
|
+
if (!Array.isArray(enumValues)) {
|
|
136
|
+
return [];
|
|
137
|
+
}
|
|
138
|
+
if (typeof enumValues[0] === 'object') {
|
|
139
|
+
return enumValues;
|
|
140
|
+
}
|
|
141
|
+
const result = [];
|
|
142
|
+
if (Array.isArray(enumNames) && enumNames.length > 0) {
|
|
143
|
+
for (let i = 0; i < enumValues.length; i++) {
|
|
144
|
+
result.push({ label: enumNames[i], value: enumValues[i] });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
for (let i = 0; i < enumValues.length; i++) {
|
|
149
|
+
result.push({ label: enumValues[i], value: enumValues[i] });
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
function mergePropertiesColors(properties) {
|
|
155
|
+
var _a, _b;
|
|
156
|
+
if (!properties || typeof properties !== 'object') {
|
|
157
|
+
return {};
|
|
158
|
+
}
|
|
159
|
+
const colorGroup = {};
|
|
160
|
+
for (const key in properties) {
|
|
161
|
+
if (!properties[key]) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (((_a = properties[key]) === null || _a === void 0 ? void 0 : _a.format) === 'color' ||
|
|
165
|
+
((_b = properties[key]) === null || _b === void 0 ? void 0 : _b['x-component']) === 'ColorPicker' ||
|
|
166
|
+
properties[key]['ui:widget'] === 'el-color-picker' ||
|
|
167
|
+
key.toLocaleUpperCase().indexOf('COLOR') !== -1 ||
|
|
168
|
+
key.toLocaleUpperCase() == 'BACKGROUND') {
|
|
169
|
+
colorGroup[key] = properties[key];
|
|
170
|
+
delete properties[key];
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return colorGroup;
|
|
174
|
+
}
|
|
175
|
+
function simpleGenerationSchemaItem(data) {
|
|
176
|
+
const result = Object.assign(Object.assign({ 'x-component': getComponentName(data), 'x-decorator': 'FormItem' }, data), { 'x-decorator-props': { layout: 'vertical', labelAlign: 'left', labelWrap: true } });
|
|
177
|
+
return result;
|
|
178
|
+
}
|
|
179
|
+
function getXData(data) {
|
|
180
|
+
if ('x-data' in data) {
|
|
181
|
+
return data['x-data'];
|
|
182
|
+
}
|
|
183
|
+
return {};
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function isSchemaConfig(data = {}) {
|
|
187
|
+
if (!data || typeof data !== 'object') {
|
|
188
|
+
return false;
|
|
189
|
+
}
|
|
190
|
+
if (data['x-component'] || data['properties'] || data['title'] || data['type']) {
|
|
191
|
+
return true;
|
|
192
|
+
}
|
|
193
|
+
return false;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
class TransformCore {
|
|
197
|
+
constructor(state) {
|
|
198
|
+
Object.defineProperty(this, "existGroup", {
|
|
199
|
+
enumerable: true,
|
|
200
|
+
configurable: true,
|
|
201
|
+
writable: true,
|
|
202
|
+
value: false
|
|
203
|
+
});
|
|
204
|
+
Object.defineProperty(this, "state", {
|
|
205
|
+
enumerable: true,
|
|
206
|
+
configurable: true,
|
|
207
|
+
writable: true,
|
|
208
|
+
value: { schema: null, ctx: null, group: false }
|
|
209
|
+
});
|
|
210
|
+
this.state = Object.assign({}, this.state, state !== null && state !== void 0 ? state : {});
|
|
211
|
+
}
|
|
212
|
+
get existEvent() {
|
|
213
|
+
var _a, _b, _c, _d;
|
|
214
|
+
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, {});
|
|
215
|
+
}
|
|
216
|
+
compile() {
|
|
217
|
+
var _a, _b, _c, _d;
|
|
218
|
+
const result = this.compileItem(this.state.schema);
|
|
219
|
+
if (!this.existGroup && ((_a = this.state) === null || _a === void 0 ? void 0 : _a.group)) {
|
|
220
|
+
const groupConfig = {
|
|
221
|
+
_group1: {
|
|
222
|
+
type: 'void',
|
|
223
|
+
'x-decorator': 'LayoutGroup',
|
|
224
|
+
'x-decorator-props': {
|
|
225
|
+
title: '基础配置'
|
|
226
|
+
},
|
|
227
|
+
properties: {
|
|
228
|
+
props: (_b = result === null || result === void 0 ? void 0 : result.properties) === null || _b === void 0 ? void 0 : _b.props,
|
|
229
|
+
style: (_c = result === null || result === void 0 ? void 0 : result.properties) === null || _c === void 0 ? void 0 : _c.style
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
if (this.existEvent) {
|
|
234
|
+
groupConfig['_group2'] = {
|
|
235
|
+
type: 'void',
|
|
236
|
+
'x-decorator': 'LayoutGroup',
|
|
237
|
+
'x-decorator-props': {
|
|
238
|
+
title: ''
|
|
239
|
+
},
|
|
240
|
+
properties: {
|
|
241
|
+
event: (_d = result === null || result === void 0 ? void 0 : result.properties) === null || _d === void 0 ? void 0 : _d.event,
|
|
242
|
+
}
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
type: 'object',
|
|
247
|
+
properties: Object.assign({}, groupConfig)
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
return result;
|
|
251
|
+
}
|
|
252
|
+
compileItem(data) {
|
|
253
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
254
|
+
if (!data || isEqual(data, {})) {
|
|
255
|
+
return {};
|
|
256
|
+
}
|
|
257
|
+
let result = {};
|
|
258
|
+
for (const key in data) {
|
|
259
|
+
if (key === 'properties') {
|
|
260
|
+
result[key] = this.compileProperties(data[key], (_a = data['required']) !== null && _a !== void 0 ? _a : []);
|
|
261
|
+
return result;
|
|
262
|
+
}
|
|
263
|
+
if (key === 'items') {
|
|
264
|
+
if ('format' in data && data['format'] === 'date-time') {
|
|
265
|
+
result[key] = data[key];
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
result = Object.assign({}, result, this.compileItems(data[key]));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (FORMILY_KEYS.includes(key) || key.indexOf('x-') !== -1 || FORMILY_EXPAND_KEYS.includes(key)) {
|
|
272
|
+
result[key] = data[key];
|
|
273
|
+
}
|
|
274
|
+
else if (key.indexOf('ui:') !== -1) {
|
|
275
|
+
if (key === 'ui:options') {
|
|
276
|
+
if (data['ui:widget'] === 'hot-area' && 'event' in data['ui:options']) {
|
|
277
|
+
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;
|
|
278
|
+
data['ui:options'].event = JSON.stringify(data['ui:options'].event);
|
|
279
|
+
}
|
|
280
|
+
this.setComponentProps(result, Object.assign({}, data['ui:options']));
|
|
281
|
+
}
|
|
282
|
+
else if (key === 'ui:hidden') {
|
|
283
|
+
result['x-hidden'] = data[key];
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (key === 'unique') {
|
|
287
|
+
result[key] = data[key];
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
if ('enum' in data) {
|
|
291
|
+
result['enum'] = emitEnum(data['enum'], (_k = data['enumNames']) !== null && _k !== void 0 ? _k : []);
|
|
292
|
+
}
|
|
293
|
+
if (!result['x-component']) {
|
|
294
|
+
result['x-component'] = getComponentName(data);
|
|
295
|
+
}
|
|
296
|
+
if (!data['x-decorator'] && data['type'] !== 'void') {
|
|
297
|
+
result['x-decorator'] = 'FormItem';
|
|
298
|
+
}
|
|
299
|
+
if (isOneOf(data)) {
|
|
300
|
+
this.setComponentProps(result, {
|
|
301
|
+
list: '[]',
|
|
302
|
+
title: data.title,
|
|
303
|
+
});
|
|
304
|
+
result['title'] = '';
|
|
305
|
+
}
|
|
306
|
+
if (isAnyOf(data)) {
|
|
307
|
+
this.setComponentProps(result, {
|
|
308
|
+
list: JSON.stringify((_l = data.anyOf) !== null && _l !== void 0 ? _l : []),
|
|
309
|
+
title: data.title,
|
|
310
|
+
'@fileUpload': (file, done) => {
|
|
311
|
+
this.state.ctx.emit('fileUpload', file, done);
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
result['title'] = '';
|
|
315
|
+
result['required'] = (_m = result['required']) !== null && _m !== void 0 ? _m : true;
|
|
316
|
+
}
|
|
317
|
+
if (['HotArea', 'CloudButton', 'InformationConfig', 'Qa'].includes(result['x-component'])) {
|
|
318
|
+
result['title'] = '';
|
|
319
|
+
result['x-decorator'] = null;
|
|
320
|
+
}
|
|
321
|
+
this.setDecoratorProps(result);
|
|
322
|
+
this.setComponentProps(result, this.compileEvent(data));
|
|
323
|
+
if (result['x-component'] === 'Select') {
|
|
324
|
+
this.setComponentProps(result, { options: (_o = result['enum']) !== null && _o !== void 0 ? _o : [] });
|
|
325
|
+
if (!data['title'] && !!(data === null || data === void 0 ? void 0 : data.inlineTitle)) {
|
|
326
|
+
this.setComponentProps(result, { prefix: data === null || data === void 0 ? void 0 : data.inlineTitle });
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
else if (result['x-component'] === 'UploadButton') {
|
|
330
|
+
if (result['title'] && result['title'].indexOf('背景图片') === -1) {
|
|
331
|
+
this.setComponentProps(result, { title: '替换图片' });
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
return result;
|
|
335
|
+
}
|
|
336
|
+
compileItems(data) {
|
|
337
|
+
var _a, _b, _c, _d, _e, _f;
|
|
338
|
+
if (isOneOf(data)) {
|
|
339
|
+
return {
|
|
340
|
+
enum: oneOfTransformEnum(data.oneOf),
|
|
341
|
+
'x-component': 'Select',
|
|
342
|
+
'x-component-props': {
|
|
343
|
+
'value-key': 'name',
|
|
344
|
+
multiple: true,
|
|
345
|
+
'collapse-tags': true,
|
|
346
|
+
},
|
|
347
|
+
'x-decorator': 'FormItem',
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
const xData = getXData(data) || {};
|
|
351
|
+
if (!('properties' in data)) {
|
|
352
|
+
return {
|
|
353
|
+
items: Object.assign({}, simpleGenerationSchemaItem(data)),
|
|
354
|
+
properties: {
|
|
355
|
+
add: {
|
|
356
|
+
type: 'void',
|
|
357
|
+
title: (xData === null || xData === void 0 ? void 0 : xData.addButtonTitle) ? xData === null || xData === void 0 ? void 0 : xData.addButtonTitle : '添加条目',
|
|
358
|
+
'x-component': 'ArrayItems.Addition',
|
|
359
|
+
'x-component-props': {
|
|
360
|
+
type: (xData === null || xData === void 0 ? void 0 : xData.addButtonType) || 'primary',
|
|
361
|
+
size: (xData === null || xData === void 0 ? void 0 : xData.addButtonSize) || 'default',
|
|
362
|
+
plain: (xData === null || xData === void 0 ? void 0 : xData.addButtonPlain) || false,
|
|
363
|
+
},
|
|
364
|
+
},
|
|
365
|
+
},
|
|
366
|
+
};
|
|
367
|
+
}
|
|
368
|
+
const result = {};
|
|
369
|
+
for (const key in data) {
|
|
370
|
+
if (key === 'properties') {
|
|
371
|
+
result[key] = this.compileProperties(data[key], (_a = data['required']) !== null && _a !== void 0 ? _a : []);
|
|
372
|
+
}
|
|
373
|
+
if (COMMON_KEYS.includes(key)) {
|
|
374
|
+
result[key] = data[key];
|
|
375
|
+
}
|
|
376
|
+
if (FIELD_KEYS.includes(key)) {
|
|
377
|
+
result[FIELD_MAP[key]] = data[key];
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (!(result === null || result === void 0 ? void 0 : result.type)) {
|
|
381
|
+
result['type'] = 'object';
|
|
382
|
+
}
|
|
383
|
+
if (!(result === null || result === void 0 ? void 0 : result.required)) {
|
|
384
|
+
result['required'] = data['required'];
|
|
385
|
+
}
|
|
386
|
+
const listRes = { items: Object.assign({}, result) };
|
|
387
|
+
listRes['properties'] = {
|
|
388
|
+
add: {
|
|
389
|
+
type: 'void',
|
|
390
|
+
title: ((_b = getXData(data)) === null || _b === void 0 ? void 0 : _b.addButtonTitle) ? (_c = getXData(data)) === null || _c === void 0 ? void 0 : _c.addButtonTitle : '添加条目',
|
|
391
|
+
'x-component': 'ArrayItems.Addition',
|
|
392
|
+
'x-component-props': {
|
|
393
|
+
type: ((_d = getXData(data)) === null || _d === void 0 ? void 0 : _d.addButtonType) || 'primary',
|
|
394
|
+
size: ((_e = getXData(data)) === null || _e === void 0 ? void 0 : _e.addButtonSize) || 'default',
|
|
395
|
+
plain: ((_f = getXData(data)) === null || _f === void 0 ? void 0 : _f.addButtonPlain) || false,
|
|
396
|
+
},
|
|
397
|
+
},
|
|
398
|
+
};
|
|
399
|
+
return listRes;
|
|
400
|
+
}
|
|
401
|
+
compileProperties(data, requireds) {
|
|
402
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
403
|
+
let result = {};
|
|
404
|
+
for (const key in data) {
|
|
405
|
+
if (!isSchemaConfig(data[key])) {
|
|
406
|
+
result[key] = data[key];
|
|
407
|
+
}
|
|
408
|
+
else if (key === 'event' && ((_b = (_a = data[key]) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.list)) {
|
|
409
|
+
result[key] = {
|
|
410
|
+
type: 'object',
|
|
411
|
+
'x-component': 'Event',
|
|
412
|
+
'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')),
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
result[key] = this.compileItem(data[key]);
|
|
417
|
+
if (Array.isArray(requireds) && requireds.includes(key)) {
|
|
418
|
+
result[key]['required'] = true;
|
|
419
|
+
}
|
|
420
|
+
if (key === 'buryReportName') {
|
|
421
|
+
result[key]['unique'] = UniqueType.page;
|
|
422
|
+
result[key]['required'] = true;
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
if (key.indexOf('group') > -1) {
|
|
426
|
+
this.existGroup = true;
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return result;
|
|
430
|
+
}
|
|
431
|
+
compileEvent(data, componentName) {
|
|
432
|
+
const _componentName = componentName || getComponentName(data);
|
|
433
|
+
const result = {};
|
|
434
|
+
result['@getData'] = (cmdname, done, cmdParams) => {
|
|
435
|
+
this.state.ctx.emit('getData', cmdname, done, cmdParams);
|
|
436
|
+
};
|
|
437
|
+
switch (_componentName) {
|
|
438
|
+
case 'Event':
|
|
439
|
+
result['@fileUpload'] = (file, done, config) => {
|
|
440
|
+
this.state.ctx.emit('fileUpload', file, done, config);
|
|
441
|
+
};
|
|
442
|
+
break;
|
|
443
|
+
case 'AnyOf':
|
|
444
|
+
result['@fileUpload'] = (file, done, config) => {
|
|
445
|
+
this.state.ctx.emit('fileUpload', file, done, config);
|
|
446
|
+
};
|
|
447
|
+
break;
|
|
448
|
+
case COMPONENT_MAP.UploadWidget:
|
|
449
|
+
result['@fileUpload'] = (file, done) => {
|
|
450
|
+
var _a, _b, _c;
|
|
451
|
+
this.state.ctx.emit('fileUpload', file, done, data);
|
|
452
|
+
if (((_a = this.state.ctx.type) === null || _a === void 0 ? void 0 : _a.name) === 'HotArea') {
|
|
453
|
+
(_c = (_b = this.state.ctx) === null || _b === void 0 ? void 0 : _b.exposed) === null || _c === void 0 ? void 0 : _c.getUploadImageUrl(file, done);
|
|
454
|
+
}
|
|
455
|
+
};
|
|
456
|
+
break;
|
|
457
|
+
case 'CloudButton':
|
|
458
|
+
result['@openCloud'] = (params, done) => {
|
|
459
|
+
this.state.ctx.emit('openCloud', { data: params, config: data }, done);
|
|
460
|
+
};
|
|
461
|
+
result['@preload'] = (url) => {
|
|
462
|
+
this.state.ctx.emit('preloadCloud', url);
|
|
463
|
+
};
|
|
464
|
+
}
|
|
465
|
+
return result;
|
|
466
|
+
}
|
|
467
|
+
setDecoratorProps(data) {
|
|
468
|
+
var _a, _b;
|
|
469
|
+
let decoratorProps = {};
|
|
470
|
+
if (data['x-component'] === 'Switch') {
|
|
471
|
+
decoratorProps['wrapperAlign'] = 'right';
|
|
472
|
+
decoratorProps['labelAlign'] = 'left';
|
|
473
|
+
}
|
|
474
|
+
else {
|
|
475
|
+
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';
|
|
476
|
+
decoratorProps['labelAlign'] = 'left';
|
|
477
|
+
decoratorProps['labelWrap'] = true;
|
|
478
|
+
}
|
|
479
|
+
if (data === null || data === void 0 ? void 0 : data.description) {
|
|
480
|
+
if (data['x-component'] === 'Input') {
|
|
481
|
+
this.setComponentProps(data, { toolTip: data['description'] });
|
|
482
|
+
}
|
|
483
|
+
else {
|
|
484
|
+
decoratorProps['tooltip'] = data['description'];
|
|
485
|
+
}
|
|
486
|
+
delete data['description'];
|
|
487
|
+
}
|
|
488
|
+
if ('asterisk' in data && data['asterisk']) {
|
|
489
|
+
decoratorProps['asterisk'] = true;
|
|
490
|
+
}
|
|
491
|
+
data['x-decorator-props'] = Object.assign({}, (_b = data['x-decorator-props']) !== null && _b !== void 0 ? _b : {}, decoratorProps);
|
|
492
|
+
}
|
|
493
|
+
setComponentProps(data, _props = {}) {
|
|
494
|
+
var _a;
|
|
495
|
+
const componentProps = {};
|
|
496
|
+
for (const key in _props) {
|
|
497
|
+
componentProps[key] = _props[key];
|
|
498
|
+
}
|
|
499
|
+
data['x-component-props'] = Object.assign({}, (_a = data['x-component-props']) !== null && _a !== void 0 ? _a : {}, componentProps);
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function transformSchema({ schema, ctx, group = false, layout = 'vertical' }) {
|
|
504
|
+
if (!schema) {
|
|
505
|
+
return {};
|
|
506
|
+
}
|
|
507
|
+
let resConfig = {};
|
|
508
|
+
if ('properties' in schema) {
|
|
509
|
+
const data = Object.assign({}, schema);
|
|
510
|
+
formatColor(data);
|
|
511
|
+
resConfig = Object.assign({}, data);
|
|
512
|
+
}
|
|
513
|
+
else {
|
|
514
|
+
const properties = Object.assign({}, schema);
|
|
515
|
+
const data = {
|
|
516
|
+
type: 'object',
|
|
517
|
+
properties: properties,
|
|
518
|
+
};
|
|
519
|
+
formatColor(data);
|
|
520
|
+
resConfig = Object.assign({}, data);
|
|
521
|
+
}
|
|
522
|
+
const result = new TransformCore({ schema: resConfig, ctx, group, layout }).compile();
|
|
523
|
+
console.log('[jt-formily Transform]', 'transformSchema', 'result:', result);
|
|
524
|
+
return result;
|
|
525
|
+
}
|
|
526
|
+
function mergeColor(properties) {
|
|
527
|
+
let colors = mergePropertiesColors(properties);
|
|
528
|
+
if (colors && JSON.stringify(colors) != '{}') {
|
|
529
|
+
properties['colorGroup'] = {
|
|
530
|
+
type: 'void',
|
|
531
|
+
'x-decorator': 'ColorGroup',
|
|
532
|
+
properties: Object.assign({}, colors)
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
function formatColor(data) {
|
|
537
|
+
if (!(data === null || data === void 0 ? void 0 : data.properties)) {
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
if ('colorGroup' in (data === null || data === void 0 ? void 0 : data.properties)) {
|
|
541
|
+
return;
|
|
542
|
+
}
|
|
543
|
+
for (const key in data.properties) {
|
|
544
|
+
formatColor(data.properties[key]);
|
|
545
|
+
}
|
|
546
|
+
mergeColor(data.properties);
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const infoLog$1 = log('[jt-formily anyof_utils]');
|
|
550
|
+
function getAnyOfConfig(schemaList, data) {
|
|
551
|
+
infoLog$1('getAnyOfConfig()', schemaList, data);
|
|
552
|
+
const { isEmptyProperties, defaultConfig, anyOf_val, maxConfig, anyOfConfig, emptyConfig } = getData(schemaList, data);
|
|
553
|
+
if (!schemaList.length) {
|
|
554
|
+
return {};
|
|
555
|
+
}
|
|
556
|
+
if (!data || isEqual$1(data, {})) {
|
|
557
|
+
infoLog$1('data is undefined or {}', schemaList, data);
|
|
558
|
+
if (isEmptyProperties) {
|
|
559
|
+
infoLog$1('走null分支', schemaList, data);
|
|
560
|
+
return emptyConfig;
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
infoLog$1('走获取默认配置分支', defaultConfig);
|
|
564
|
+
return defaultConfig !== null && defaultConfig !== void 0 ? defaultConfig : schemaList[0];
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
if (anyOf_val) {
|
|
569
|
+
infoLog$1('走anyOf_val分支', schemaList, data);
|
|
570
|
+
return anyOfConfig !== null && anyOfConfig !== void 0 ? anyOfConfig : {};
|
|
571
|
+
}
|
|
572
|
+
else {
|
|
573
|
+
infoLog$1('走匹配分支', schemaList, data);
|
|
574
|
+
return maxConfig !== null && maxConfig !== void 0 ? maxConfig : {};
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
function getData(schemaList, data) {
|
|
579
|
+
const dataKeys = Object.keys(data !== null && data !== void 0 ? data : {});
|
|
580
|
+
let maxConfig = null;
|
|
581
|
+
let maxLength = 0;
|
|
582
|
+
let defaultConfig = null;
|
|
583
|
+
let anyOf_val = null;
|
|
584
|
+
let anyOfConfig = null;
|
|
585
|
+
let isEmptyProperties = false;
|
|
586
|
+
let emptyConfig = null;
|
|
587
|
+
if (data && 'anyOf_val' in data) {
|
|
588
|
+
anyOf_val = data['anyOf_val'];
|
|
589
|
+
}
|
|
590
|
+
schemaList.forEach(item => {
|
|
591
|
+
var _a, _b;
|
|
592
|
+
const propertiesKeys = Object.keys((_a = item === null || item === void 0 ? void 0 : item.properties) !== null && _a !== void 0 ? _a : {});
|
|
593
|
+
if (!propertiesKeys.length) {
|
|
594
|
+
isEmptyProperties = true;
|
|
595
|
+
emptyConfig = cloneDeep(item);
|
|
596
|
+
}
|
|
597
|
+
if (anyOf_val === (item === null || item === void 0 ? void 0 : item.title)) {
|
|
598
|
+
anyOfConfig = cloneDeep(item);
|
|
599
|
+
}
|
|
600
|
+
if (dataKeys.length) {
|
|
601
|
+
let length = dataKeys.filter(d => propertiesKeys.includes(d)).length;
|
|
602
|
+
if (length > maxLength) {
|
|
603
|
+
maxLength = length;
|
|
604
|
+
maxConfig = cloneDeep(item);
|
|
605
|
+
}
|
|
606
|
+
}
|
|
607
|
+
if (item && 'x-data' in item) {
|
|
608
|
+
const activity = (_b = item['x-data']) === null || _b === void 0 ? void 0 : _b.activity;
|
|
609
|
+
if (activity) {
|
|
610
|
+
defaultConfig = cloneDeep(item);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
return { maxConfig, defaultConfig, anyOf_val, isEmptyProperties, anyOfConfig, emptyConfig };
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
const infoLog = log('[jt-formily validate]');
|
|
618
|
+
class FormilyValidate {
|
|
619
|
+
constructor(state) {
|
|
620
|
+
Object.defineProperty(this, "state", {
|
|
621
|
+
enumerable: true,
|
|
622
|
+
configurable: true,
|
|
623
|
+
writable: true,
|
|
624
|
+
value: void 0
|
|
625
|
+
});
|
|
626
|
+
Object.defineProperty(this, "errList", {
|
|
627
|
+
enumerable: true,
|
|
628
|
+
configurable: true,
|
|
629
|
+
writable: true,
|
|
630
|
+
value: void 0
|
|
631
|
+
});
|
|
632
|
+
Object.defineProperty(this, "pathList", {
|
|
633
|
+
enumerable: true,
|
|
634
|
+
configurable: true,
|
|
635
|
+
writable: true,
|
|
636
|
+
value: void 0
|
|
637
|
+
});
|
|
638
|
+
this.init(state);
|
|
639
|
+
}
|
|
640
|
+
init(state) {
|
|
641
|
+
const { data, schema, validateData } = state;
|
|
642
|
+
this.state = {
|
|
643
|
+
data: data !== null && data !== void 0 ? data : {},
|
|
644
|
+
schema: transformSchema({ schema: schema !== null && schema !== void 0 ? schema : {}, ctx: null }),
|
|
645
|
+
validateData: validateData !== null && validateData !== void 0 ? validateData : [],
|
|
646
|
+
};
|
|
647
|
+
this.errList = [];
|
|
648
|
+
this.pathList = [];
|
|
649
|
+
}
|
|
650
|
+
validate() {
|
|
651
|
+
var _a, _b;
|
|
652
|
+
this.validateProperties((_b = (_a = this.state.schema) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {});
|
|
653
|
+
infoLog('validate', this.errList);
|
|
654
|
+
return this.errList;
|
|
655
|
+
}
|
|
656
|
+
validateItem(data) {
|
|
657
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z;
|
|
658
|
+
if ('x-component' in data && WHITE_COMPONENTS.includes(data['x-component'])) {
|
|
659
|
+
switch (data['x-component']) {
|
|
660
|
+
case 'Middleware': {
|
|
661
|
+
const { parametersDescriptor } = (_a = data['x-component-props']) !== null && _a !== void 0 ? _a : { parametersDescriptor: '{}' };
|
|
662
|
+
const result = this.getMiddlewareSchema(typeof parametersDescriptor === 'string' ? JSON.parse(parametersDescriptor) : parametersDescriptor, get(this.state.data, this.path));
|
|
663
|
+
this.validateMiddleware(result);
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
666
|
+
case 'AnyOf':
|
|
667
|
+
{
|
|
668
|
+
const { list } = (_b = data['x-component-props']) !== null && _b !== void 0 ? _b : { list: [] };
|
|
669
|
+
let result = null;
|
|
670
|
+
if (typeof list === 'string') {
|
|
671
|
+
result = getAnyOfConfig(JSON.parse(list), get(this.state.data, this.path));
|
|
672
|
+
}
|
|
673
|
+
else {
|
|
674
|
+
result = getAnyOfConfig(list, get(this.state.data, this.path));
|
|
675
|
+
}
|
|
676
|
+
infoLog('anyOf Config', result);
|
|
677
|
+
this.validateProperties((_c = result === null || result === void 0 ? void 0 : result.properties) !== null && _c !== void 0 ? _c : {});
|
|
678
|
+
return false;
|
|
679
|
+
}
|
|
680
|
+
case 'OneOf':
|
|
681
|
+
{
|
|
682
|
+
const { list } = (_d = data['x-component-props']) !== null && _d !== void 0 ? _d : { list: [] };
|
|
683
|
+
let result = null;
|
|
684
|
+
if (typeof list === 'string') {
|
|
685
|
+
result = this.getOneOfProperties(JSON.parse(list));
|
|
686
|
+
}
|
|
687
|
+
else {
|
|
688
|
+
result = this.getOneOfProperties(list);
|
|
689
|
+
}
|
|
690
|
+
this.validateProperties(result === null || result === void 0 ? void 0 : result.properties);
|
|
691
|
+
return false;
|
|
692
|
+
}
|
|
693
|
+
case 'Event': {
|
|
694
|
+
const result = this.getEventProperties(data);
|
|
695
|
+
this.validateProperties(result.properties);
|
|
696
|
+
return false;
|
|
697
|
+
}
|
|
698
|
+
case 'HotArea': {
|
|
699
|
+
const result = this.getHotAreaProperties(data);
|
|
700
|
+
this.validateHotArea(result);
|
|
701
|
+
}
|
|
702
|
+
}
|
|
703
|
+
return false;
|
|
704
|
+
}
|
|
705
|
+
else if ('items' in data) {
|
|
706
|
+
if (this.isRequiredByArray(data['items'])) {
|
|
707
|
+
this.validateArray(data['items']);
|
|
708
|
+
}
|
|
709
|
+
return false;
|
|
710
|
+
}
|
|
711
|
+
else if ('properties' in data) {
|
|
712
|
+
if (this.validateReactions(data)) {
|
|
713
|
+
const dependencies = (_f = (_e = data['x-reactions']) === null || _e === void 0 ? void 0 : _e['dependencies']) !== null && _f !== void 0 ? _f : [];
|
|
714
|
+
let depValue = undefined;
|
|
715
|
+
if ((data === null || data === void 0 ? void 0 : data.type) === 'void') {
|
|
716
|
+
depValue = this.parseExpression(dependencies, null, (_j = (_h = (_g = data['x-reactions']) === null || _g === void 0 ? void 0 : _g.fulfill) === null || _h === void 0 ? void 0 : _h.schema) === null || _j === void 0 ? void 0 : _j['x-visible'], this.path, this.state.data, true);
|
|
717
|
+
}
|
|
718
|
+
else {
|
|
719
|
+
depValue = this.parseExpression(dependencies, null, (_m = (_l = (_k = data['x-reactions']) === null || _k === void 0 ? void 0 : _k.fulfill) === null || _l === void 0 ? void 0 : _l.schema) === null || _m === void 0 ? void 0 : _m['x-visible'], this.path, this.state.data);
|
|
720
|
+
}
|
|
721
|
+
let expression = (_r = (_q = (_p = (_o = data['x-reactions']) === null || _o === void 0 ? void 0 : _o.fulfill) === null || _p === void 0 ? void 0 : _p.schema) === null || _q === void 0 ? void 0 : _q['x-visible']) !== null && _r !== void 0 ? _r : '';
|
|
722
|
+
if (!this.calculateReactions(expression.replace(/\$deps\[\d\]/, typeof depValue === 'string' ? `'${depValue}'` : depValue))) {
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
this.validateProperties(data['properties']);
|
|
727
|
+
return false;
|
|
728
|
+
}
|
|
729
|
+
else if ('required' in data && data['required']) {
|
|
730
|
+
if (this.validateReactions(data)) {
|
|
731
|
+
const dependencies = (_s = data['x-reactions']) === null || _s === void 0 ? void 0 : _s['dependencies'];
|
|
732
|
+
const depValue = this.parseExpression(dependencies, null, (_v = (_u = (_t = data['x-reactions']) === null || _t === void 0 ? void 0 : _t.fulfill) === null || _u === void 0 ? void 0 : _u.schema) === null || _v === void 0 ? void 0 : _v['x-visible'], this.path, this.state.data);
|
|
733
|
+
let expression = (_z = (_y = (_x = (_w = data['x-reactions']) === null || _w === void 0 ? void 0 : _w.fulfill) === null || _x === void 0 ? void 0 : _x.schema) === null || _y === void 0 ? void 0 : _y['x-visible']) !== null && _z !== void 0 ? _z : '';
|
|
734
|
+
return this.calculateReactions(expression.replace(/\$deps\[\d\]/, typeof depValue === 'string' ? `'${depValue}'` : depValue));
|
|
735
|
+
}
|
|
736
|
+
return true;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
validateReactions(data) {
|
|
740
|
+
var _a, _b, _c;
|
|
741
|
+
if (!('x-reactions' in data)) {
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
if ((_c = (_b = (_a = data['x-reactions']) === null || _a === void 0 ? void 0 : _a.fulfill) === null || _b === void 0 ? void 0 : _b.schema) === null || _c === void 0 ? void 0 : _c['x-visible']) {
|
|
745
|
+
return true;
|
|
746
|
+
}
|
|
747
|
+
return false;
|
|
748
|
+
}
|
|
749
|
+
calculateReactions(expression) {
|
|
750
|
+
const ExpRE = /^\s*\{\{([\s\S]*)\}\}\s*$/;
|
|
751
|
+
const matchData = expression.match(ExpRE);
|
|
752
|
+
if (matchData.length === 2) {
|
|
753
|
+
return this.calc(matchData[1]) ? true : false;
|
|
754
|
+
}
|
|
755
|
+
return false;
|
|
756
|
+
}
|
|
757
|
+
calc(expr) {
|
|
758
|
+
return Function('return (' + expr + ')')();
|
|
759
|
+
}
|
|
760
|
+
validateHotArea(data) {
|
|
761
|
+
const hotData = get(this.state.data, this.path);
|
|
762
|
+
if (Array.isArray(hotData) && hotData.length > 0) {
|
|
763
|
+
hotData.forEach((item, index) => {
|
|
764
|
+
this.insertPath(`${index}`);
|
|
765
|
+
this.insertPath('event');
|
|
766
|
+
if ('properties' in data) {
|
|
767
|
+
this.validateProperties(data.properties);
|
|
768
|
+
}
|
|
769
|
+
this.deletePath();
|
|
770
|
+
this.deletePath();
|
|
771
|
+
});
|
|
772
|
+
}
|
|
773
|
+
}
|
|
774
|
+
getHotAreaProperties(data) {
|
|
775
|
+
var _a;
|
|
776
|
+
const { event } = (_a = data['x-component-props']) !== null && _a !== void 0 ? _a : { event: {} };
|
|
777
|
+
return transformSchema(typeof event === 'string' ? { schema: JSON.parse(event), ctx: null } : { schema: event, ctx: null });
|
|
778
|
+
}
|
|
779
|
+
getEventProperties(data) {
|
|
780
|
+
var _a, _b, _c, _d;
|
|
781
|
+
const { schema } = (_a = data['x-component-props']) !== null && _a !== void 0 ? _a : { schema: {} };
|
|
782
|
+
const result = {
|
|
783
|
+
type: 'object',
|
|
784
|
+
properties: {
|
|
785
|
+
list: typeof schema === 'string' ? (_c = (_b = JSON.parse(schema)) === null || _b === void 0 ? void 0 : _b.list) !== null && _c !== void 0 ? _c : [] : (_d = schema === null || schema === void 0 ? void 0 : schema.list) !== null && _d !== void 0 ? _d : []
|
|
786
|
+
}
|
|
787
|
+
};
|
|
788
|
+
return transformSchema({ schema: result, ctx: null });
|
|
789
|
+
}
|
|
790
|
+
validateProperties(data) {
|
|
791
|
+
var _a, _b;
|
|
792
|
+
for (const key in data) {
|
|
793
|
+
if (key !== 'input' && ((_a = data[key]) === null || _a === void 0 ? void 0 : _a.type) !== 'void') {
|
|
794
|
+
this.insertPath(key);
|
|
795
|
+
}
|
|
796
|
+
if (!isSchemaConfig(data[key])) {
|
|
797
|
+
const tmpPath = cloneDeep(this.pathList);
|
|
798
|
+
tmpPath.pop();
|
|
799
|
+
const validateKey = get(this.state.data, tmpPath.join(".") + '._validateKey');
|
|
800
|
+
if (validateKey) {
|
|
801
|
+
data[key] = data[key][validateKey];
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
if (this.validateItem(data[key])) {
|
|
805
|
+
const checkData = get(this.state.data, this.path);
|
|
806
|
+
if (this.checkResult(checkData)) {
|
|
807
|
+
const values = Object.values(UniqueType).filter(v => !isNaN(Number(v)));
|
|
808
|
+
if ('unique' in data[key] && values.includes(data[key]['unique'])) {
|
|
809
|
+
if (this.isUnique(checkData, data[key]['unique'])) ;
|
|
810
|
+
else {
|
|
811
|
+
const schemaData = {};
|
|
812
|
+
schemaData[key] = Object.assign(Object.assign({}, data[key]), { default: checkData, 'x-validator': Object.assign({ buryReportName: true, value: checkData }, data[key]['x-validator']) });
|
|
813
|
+
if (this.pathList.includes('buryReportName')) {
|
|
814
|
+
schemaData[key]['title'] = this.path.indexOf('event') !== -1 ? '事件埋点' : data[key]['title'];
|
|
815
|
+
}
|
|
816
|
+
if ('x-reactions' in schemaData[key]) {
|
|
817
|
+
this.parseReactions(schemaData[key], ['x-visible']);
|
|
818
|
+
delete schemaData[key]['x-reactions'];
|
|
819
|
+
}
|
|
820
|
+
this.errList.push({
|
|
821
|
+
path: this.path,
|
|
822
|
+
schema: schemaData,
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
else {
|
|
828
|
+
const schemaData = {};
|
|
829
|
+
schemaData[key] = data[key];
|
|
830
|
+
if ('x-reactions' in schemaData[key]) {
|
|
831
|
+
this.parseReactions(schemaData[key], ['x-visible']);
|
|
832
|
+
delete schemaData[key]['x-reactions'];
|
|
833
|
+
}
|
|
834
|
+
this.errList.push({
|
|
835
|
+
path: this.path,
|
|
836
|
+
schema: schemaData,
|
|
837
|
+
});
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
if (key !== 'input' && ((_b = data[key]) === null || _b === void 0 ? void 0 : _b.type) !== 'void') {
|
|
841
|
+
this.deletePath();
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
validateArray(data) {
|
|
846
|
+
const itemData = get(this.state.data, this.path);
|
|
847
|
+
if (Array.isArray(itemData)) {
|
|
848
|
+
for (let i = 0; i < itemData.length; ++i) {
|
|
849
|
+
this.insertPath(`${i}`);
|
|
850
|
+
if ('properties' in data) {
|
|
851
|
+
const properties = cloneDeep(data['properties']);
|
|
852
|
+
for (const key in properties) {
|
|
853
|
+
if ((data['required'] && data['required'].includes(key)) || 'unique' in properties[key] || ('required' in properties[key] && properties[key]['required'])) {
|
|
854
|
+
properties[key].title = `${i + 1}.${properties[key].title || ''}`;
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
this.validateProperties(properties);
|
|
858
|
+
}
|
|
859
|
+
else {
|
|
860
|
+
if ('required' in data) {
|
|
861
|
+
if (!get(this.state.data, this.path)) {
|
|
862
|
+
const schemaData = {};
|
|
863
|
+
const key = ((Math.random() * 100000).toFixed(0) + Date.now()).toString();
|
|
864
|
+
schemaData[key] = data;
|
|
865
|
+
this.errList.push({
|
|
866
|
+
path: this.path,
|
|
867
|
+
schema: schemaData,
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
}
|
|
872
|
+
this.deletePath();
|
|
873
|
+
}
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
insertPath(path) {
|
|
877
|
+
this.pathList.push(path);
|
|
878
|
+
}
|
|
879
|
+
deletePath() {
|
|
880
|
+
this.pathList.pop();
|
|
881
|
+
}
|
|
882
|
+
isRequiredByArray(items) {
|
|
883
|
+
infoLog('isRequiredByArray', items);
|
|
884
|
+
if ('properties' in items) {
|
|
885
|
+
return true;
|
|
886
|
+
}
|
|
887
|
+
else {
|
|
888
|
+
if ('required' in items) {
|
|
889
|
+
return true;
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
return false;
|
|
893
|
+
}
|
|
894
|
+
isUnique(value, unique) {
|
|
895
|
+
var _a, _b;
|
|
896
|
+
if (value === '') {
|
|
897
|
+
return false;
|
|
898
|
+
}
|
|
899
|
+
let countFlag = 0;
|
|
900
|
+
if (unique === UniqueType.page) {
|
|
901
|
+
for (let i = 0; i < this.state.validateData.length; i++) {
|
|
902
|
+
const values = this.getObjectValues((_a = this.state.validateData[i]) !== null && _a !== void 0 ? _a : {});
|
|
903
|
+
countFlag += values.filter(v => v === value).length;
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
else if (unique === UniqueType.component) {
|
|
907
|
+
const values = this.getObjectValues((_b = this.state.data) !== null && _b !== void 0 ? _b : {});
|
|
908
|
+
countFlag += values.filter(v => v === value).length;
|
|
909
|
+
}
|
|
910
|
+
if (countFlag > 1) {
|
|
911
|
+
return false;
|
|
912
|
+
}
|
|
913
|
+
return true;
|
|
914
|
+
}
|
|
915
|
+
get path() {
|
|
916
|
+
return this.pathList.join('.');
|
|
917
|
+
}
|
|
918
|
+
getAnyOfProperties(configList, data) {
|
|
919
|
+
var _a, _b;
|
|
920
|
+
if (Object.keys(data || {}).length === 0) {
|
|
921
|
+
return {};
|
|
922
|
+
}
|
|
923
|
+
const config = configList.map(item => ({
|
|
924
|
+
item,
|
|
925
|
+
score: this.checkAnyOfProperties(item),
|
|
926
|
+
})).sort((a, b) => b.score - a.score)[0];
|
|
927
|
+
return (_b = (_a = config.item) === null || _a === void 0 ? void 0 : _a.properties) !== null && _b !== void 0 ? _b : {};
|
|
928
|
+
}
|
|
929
|
+
isAnyOf(data) {
|
|
930
|
+
return data['x-component'] === 'AnyOf';
|
|
931
|
+
}
|
|
932
|
+
checkAnyOfProperties(data) {
|
|
933
|
+
var _a, _b;
|
|
934
|
+
const value = (_a = get(this.state.data, this.path)) !== null && _a !== void 0 ? _a : {};
|
|
935
|
+
const dataKeys = Object.keys(value);
|
|
936
|
+
const propertiesKeys = Object.keys((_b = data === null || data === void 0 ? void 0 : data.properties) !== null && _b !== void 0 ? _b : {});
|
|
937
|
+
let count = -1;
|
|
938
|
+
for (let j = 0; j < dataKeys.length; j++) {
|
|
939
|
+
if (!propertiesKeys.includes(dataKeys[j])) {
|
|
940
|
+
return -1;
|
|
941
|
+
}
|
|
942
|
+
else {
|
|
943
|
+
count++;
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
return count;
|
|
947
|
+
}
|
|
948
|
+
getOneOfProperties(configList) {
|
|
949
|
+
var _a, _b, _c, _d;
|
|
950
|
+
const data = get(this.state.data, this.path + '.name');
|
|
951
|
+
for (let i = 0; i < configList.length; i++) {
|
|
952
|
+
if (((_c = (_b = (_a = configList[i]) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.name) === null || _c === void 0 ? void 0 : _c.default) === data) {
|
|
953
|
+
const keys = Object.keys((_d = configList[i]) === null || _d === void 0 ? void 0 : _d.properties).filter(key => key !== 'name');
|
|
954
|
+
const result = { properties: {} };
|
|
955
|
+
keys.forEach(k => {
|
|
956
|
+
var _a, _b;
|
|
957
|
+
result['properties'][k] = (_b = (_a = configList[i]) === null || _a === void 0 ? void 0 : _a.properties[k]) !== null && _b !== void 0 ? _b : {};
|
|
958
|
+
});
|
|
959
|
+
return transformSchema({ schema: result, ctx: null });
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
return { properties: {} };
|
|
963
|
+
}
|
|
964
|
+
getObjectValues(data) {
|
|
965
|
+
let valueArr = [];
|
|
966
|
+
if (!data) {
|
|
967
|
+
return valueArr;
|
|
968
|
+
}
|
|
969
|
+
Object.keys(data).forEach(it => {
|
|
970
|
+
if (data[it] && typeof data[it] === 'object' && !Array.isArray(data[it])) {
|
|
971
|
+
valueArr = valueArr.concat(this.getObjectValues(data[it]));
|
|
972
|
+
}
|
|
973
|
+
else if (data[it] && Array.isArray(data[it])) {
|
|
974
|
+
for (let i = 0; i < data[it].length; i++) {
|
|
975
|
+
valueArr = valueArr.concat(this.getObjectValues(data[it][i]));
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
else if (typeof data[it] === 'string') {
|
|
979
|
+
if (this.pathList.length) {
|
|
980
|
+
if (it === this.pathList[this.pathList.length - 1]) {
|
|
981
|
+
valueArr.push(data[it]);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
else {
|
|
985
|
+
valueArr.push(data[it]);
|
|
986
|
+
}
|
|
987
|
+
}
|
|
988
|
+
});
|
|
989
|
+
return valueArr;
|
|
990
|
+
}
|
|
991
|
+
parseReactions(schema, ignore = []) {
|
|
992
|
+
var _a, _b;
|
|
993
|
+
try {
|
|
994
|
+
if (!schema) {
|
|
995
|
+
return schema;
|
|
996
|
+
}
|
|
997
|
+
if ('x-reactions' in schema) {
|
|
998
|
+
if ('dependencies' in schema['x-reactions']) {
|
|
999
|
+
const dependencies = schema['x-reactions']['dependencies'];
|
|
1000
|
+
const reactionsSchema = (_b = (_a = schema['x-reactions']) === null || _a === void 0 ? void 0 : _a.fulfill) === null || _b === void 0 ? void 0 : _b.schema;
|
|
1001
|
+
if (reactionsSchema) {
|
|
1002
|
+
Object.keys(reactionsSchema || {}).forEach((key) => {
|
|
1003
|
+
if (ignore.includes(key) || typeof reactionsSchema[key] !== 'string') {
|
|
1004
|
+
return;
|
|
1005
|
+
}
|
|
1006
|
+
const value = this.parseExpression(dependencies, null, reactionsSchema[key], this.path, this.state.data);
|
|
1007
|
+
if (value) {
|
|
1008
|
+
set(schema, key, value);
|
|
1009
|
+
}
|
|
1010
|
+
else {
|
|
1011
|
+
infoLog('parseReactions', '解析失败');
|
|
1012
|
+
}
|
|
1013
|
+
});
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
else if ('target' in schema['x-reactions']) {
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
}
|
|
1020
|
+
catch (error) {
|
|
1021
|
+
infoLog(`parseReactions error, schema: ${typeof schema !== 'string' ? JSON.stringify(schema) : schema} error: ${typeof error !== 'string' ? JSON.stringify(error) : error}`);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
parseExpression(dependencies, target, exp, path, data, isVoid = false) {
|
|
1025
|
+
const indexStr = exp.match(/\$deps\[(\d+)\]/);
|
|
1026
|
+
if (indexStr) {
|
|
1027
|
+
const index = parseInt(indexStr[1]);
|
|
1028
|
+
const depString = dependencies[index];
|
|
1029
|
+
let hierarchy = depString.match(/\.+/i) ? depString.match(/\.+/i)[0].length : 0;
|
|
1030
|
+
const newPath = path.split('.');
|
|
1031
|
+
if (hierarchy) {
|
|
1032
|
+
if (isVoid) {
|
|
1033
|
+
hierarchy--;
|
|
1034
|
+
}
|
|
1035
|
+
for (let i = 0; i < hierarchy; i++) {
|
|
1036
|
+
newPath.pop();
|
|
1037
|
+
}
|
|
1038
|
+
newPath.push(depString.replace(/\.+/, ''));
|
|
1039
|
+
const value = get(data, newPath.join('.'));
|
|
1040
|
+
return value;
|
|
1041
|
+
}
|
|
1042
|
+
}
|
|
1043
|
+
return null;
|
|
1044
|
+
}
|
|
1045
|
+
checkResult(value) {
|
|
1046
|
+
if (!value) {
|
|
1047
|
+
if (value === 0) {
|
|
1048
|
+
return true;
|
|
1049
|
+
}
|
|
1050
|
+
return false;
|
|
1051
|
+
}
|
|
1052
|
+
if (Array.isArray(value)) {
|
|
1053
|
+
if (!value.length) {
|
|
1054
|
+
return false;
|
|
1055
|
+
}
|
|
1056
|
+
if (typeof value[0] === 'object') {
|
|
1057
|
+
for (let i = 0; i < value.length; i++) {
|
|
1058
|
+
if (value[i] && '__validate_value__' in value[i]) {
|
|
1059
|
+
if (!value[i]['__validate_value__']) {
|
|
1060
|
+
return false;
|
|
1061
|
+
}
|
|
1062
|
+
}
|
|
1063
|
+
}
|
|
1064
|
+
}
|
|
1065
|
+
return true;
|
|
1066
|
+
}
|
|
1067
|
+
if (typeof value === 'object') {
|
|
1068
|
+
if ('__validate_value__' in value) {
|
|
1069
|
+
return !!value['__validate_value__'];
|
|
1070
|
+
}
|
|
1071
|
+
else if (isEqual$1(value, {})) {
|
|
1072
|
+
return false;
|
|
1073
|
+
}
|
|
1074
|
+
return true;
|
|
1075
|
+
}
|
|
1076
|
+
return true;
|
|
1077
|
+
}
|
|
1078
|
+
getMiddlewareSchema(parametersDescriptor, data) {
|
|
1079
|
+
const schemaList = [];
|
|
1080
|
+
data.forEach(it => {
|
|
1081
|
+
schemaList.push({
|
|
1082
|
+
properties: {
|
|
1083
|
+
options: {
|
|
1084
|
+
type: 'object',
|
|
1085
|
+
properties: Object.assign({}, parametersDescriptor[it.name])
|
|
1086
|
+
}
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1089
|
+
});
|
|
1090
|
+
return schemaList;
|
|
1091
|
+
}
|
|
1092
|
+
validateMiddleware(data) {
|
|
1093
|
+
const middlewareData = get(this.state.data, this.path);
|
|
1094
|
+
if (Array.isArray(middlewareData)) {
|
|
1095
|
+
for (let i = 0; i < middlewareData.length; ++i) {
|
|
1096
|
+
this.insertPath(`${i}`);
|
|
1097
|
+
this.validateProperties(data[i]['properties']);
|
|
1098
|
+
this.deletePath();
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
}
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
export { FormilyValidate };
|