@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,253 @@
|
|
|
1
|
+
import {
|
|
2
|
+
emitEnum,
|
|
3
|
+
getComponentName,
|
|
4
|
+
getXData,
|
|
5
|
+
isAnyOf,
|
|
6
|
+
isOneOf,
|
|
7
|
+
mergePropertiesColors,
|
|
8
|
+
oneOfTransformEnum,
|
|
9
|
+
simpleGenerationSchemaItem,
|
|
10
|
+
} from '../../src/transform/utils/func';
|
|
11
|
+
import { TransformCore } from '../../src/transform';
|
|
12
|
+
|
|
13
|
+
describe('transform', () => {
|
|
14
|
+
it('setComponentProps', () => {
|
|
15
|
+
const testTransform = new TransformCore({ ctx: null, schema: {} });
|
|
16
|
+
const result = {};
|
|
17
|
+
testTransform.setComponentProps(result, { a: 1 });
|
|
18
|
+
expect(result).toEqual({ 'x-component-props': { a: 1 } });
|
|
19
|
+
});
|
|
20
|
+
it('setDecoratorProps', () => {
|
|
21
|
+
const testTransform = new TransformCore({ ctx: null, schema: {} });
|
|
22
|
+
|
|
23
|
+
/** Switch */
|
|
24
|
+
const result = { 'x-component': 'Switch' };
|
|
25
|
+
testTransform.setDecoratorProps(result);
|
|
26
|
+
expect(result).toEqual({
|
|
27
|
+
'x-component': 'Switch',
|
|
28
|
+
'x-decorator-props': { wrapperAlign: 'right', labelAlign: 'left' },
|
|
29
|
+
});
|
|
30
|
+
/** Switch */
|
|
31
|
+
// Other 代表非Switch组件
|
|
32
|
+
const result1 = { 'x-component': 'Other' };
|
|
33
|
+
testTransform.setDecoratorProps(result1);
|
|
34
|
+
expect(result1).toEqual({
|
|
35
|
+
'x-component': 'Other',
|
|
36
|
+
'x-decorator-props': {
|
|
37
|
+
layout: 'vertical',
|
|
38
|
+
labelAlign: 'left',
|
|
39
|
+
labelWrap: true,
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/** description 说明 */
|
|
44
|
+
const result2 = { 'x-component': 'Other', description: '说明文案' };
|
|
45
|
+
testTransform.setDecoratorProps(result2);
|
|
46
|
+
expect(result2).toEqual({
|
|
47
|
+
'x-component': 'Other',
|
|
48
|
+
'x-decorator-props': {
|
|
49
|
+
layout: 'vertical',
|
|
50
|
+
labelAlign: 'left',
|
|
51
|
+
labelWrap: true,
|
|
52
|
+
tooltip: '说明文案',
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
/** description(input) 说明 */
|
|
57
|
+
const result3 = { 'x-component': 'Input', description: '说明文案' };
|
|
58
|
+
testTransform.setDecoratorProps(result3);
|
|
59
|
+
expect(result3).toEqual({
|
|
60
|
+
'x-component': 'Input',
|
|
61
|
+
'x-decorator-props': {
|
|
62
|
+
layout: 'vertical',
|
|
63
|
+
labelAlign: 'left',
|
|
64
|
+
labelWrap: true,
|
|
65
|
+
},
|
|
66
|
+
'x-component-props': { toolTip: '说明文案' },
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
/** 必填项 */
|
|
70
|
+
const result4 = { 'x-component': 'Input', asterisk: true };
|
|
71
|
+
testTransform.setDecoratorProps(result4);
|
|
72
|
+
expect(result4).toEqual({
|
|
73
|
+
'x-component': 'Input',
|
|
74
|
+
asterisk: true,
|
|
75
|
+
'x-decorator-props': {
|
|
76
|
+
layout: 'vertical',
|
|
77
|
+
labelAlign: 'left',
|
|
78
|
+
labelWrap: true,
|
|
79
|
+
asterisk: true,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
/** 默认选项 */
|
|
84
|
+
const result5 = { 'x-component': 'Input', 'x-decorator-props': { a: 1 } };
|
|
85
|
+
testTransform.setDecoratorProps(result5);
|
|
86
|
+
expect(result5).toEqual({
|
|
87
|
+
'x-component': 'Input',
|
|
88
|
+
'x-decorator-props': {
|
|
89
|
+
layout: 'vertical',
|
|
90
|
+
labelAlign: 'left',
|
|
91
|
+
labelWrap: true,
|
|
92
|
+
a: 1,
|
|
93
|
+
},
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
it('compileEvent', () => {
|
|
97
|
+
const testTransform = new TransformCore({ ctx: null, schema: {} });
|
|
98
|
+
/** UploadButton */
|
|
99
|
+
const result1 = testTransform.compileEvent({
|
|
100
|
+
'x-component': 'UploadButton',
|
|
101
|
+
});
|
|
102
|
+
const keys = Object.keys(result1);
|
|
103
|
+
expect(keys.includes('@fileUpload')).toEqual(true);
|
|
104
|
+
});
|
|
105
|
+
/**
|
|
106
|
+
* 获取组件名
|
|
107
|
+
*/
|
|
108
|
+
it('getComponentName', () => {
|
|
109
|
+
const result1 = getComponentName({ type: 'string' });
|
|
110
|
+
expect(result1).toEqual('Input');
|
|
111
|
+
const result2 = getComponentName({ enum: [] });
|
|
112
|
+
expect(result2).toEqual('Select');
|
|
113
|
+
/** vjsf */
|
|
114
|
+
const result3 = getComponentName({ 'ui:widget': 'UploadWidget' });
|
|
115
|
+
expect(result3).toEqual('UploadButton');
|
|
116
|
+
const result4 = getComponentName({ format: 'color' });
|
|
117
|
+
expect(result4).toEqual('ColorPicker');
|
|
118
|
+
const result5 = getComponentName({ format: 'date-time' });
|
|
119
|
+
expect(result5).toEqual('DateTime');
|
|
120
|
+
const result6 = getComponentName({ anyOf: [] });
|
|
121
|
+
expect(result6).toEqual('AnyOf');
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('isAnyOf', () => {
|
|
125
|
+
expect(isAnyOf({ anyOf: [] })).toEqual(true);
|
|
126
|
+
expect(isAnyOf({ items: [] })).toEqual(false);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('isOneOf', () => {
|
|
130
|
+
expect(isOneOf({ oneOf: [] })).toEqual(true);
|
|
131
|
+
expect(isOneOf({ items: [] })).toEqual(false);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('simpleGenerationSchemaItem', () => {
|
|
135
|
+
expect(
|
|
136
|
+
simpleGenerationSchemaItem({
|
|
137
|
+
type: 'string',
|
|
138
|
+
})
|
|
139
|
+
).toEqual({
|
|
140
|
+
type: 'string',
|
|
141
|
+
'x-component': 'Input',
|
|
142
|
+
'x-decorator': 'FormItem',
|
|
143
|
+
'x-decorator-props': {
|
|
144
|
+
layout: 'vertical',
|
|
145
|
+
labelAlign: 'left',
|
|
146
|
+
labelWrap: true,
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
it('getXData', () => {
|
|
151
|
+
expect(getXData({ 'x-data': true })).toEqual(true);
|
|
152
|
+
expect(getXData({ 'x-data': 1 })).toEqual(1);
|
|
153
|
+
expect(getXData({})).toEqual({});
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('emitEnum', () => {
|
|
157
|
+
const values = [1, 2, 3, 4, 5];
|
|
158
|
+
const names = ['a', 'b', 'c', 'd', 'e'];
|
|
159
|
+
expect(emitEnum(values, names)).toEqual([
|
|
160
|
+
{ label: 'a', value: 1 },
|
|
161
|
+
{ label: 'b', value: 2 },
|
|
162
|
+
{ label: 'c', value: 3 },
|
|
163
|
+
{ label: 'd', value: 4 },
|
|
164
|
+
{ label: 'e', value: 5 },
|
|
165
|
+
]);
|
|
166
|
+
/** formily 协议的 enum */
|
|
167
|
+
expect(emitEnum([{ label: 'a', value: 1 }])).toEqual([
|
|
168
|
+
{ label: 'a', value: 1 },
|
|
169
|
+
]);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it('oneOfTransformEnum', () => {
|
|
173
|
+
const result = oneOfTransformEnum([
|
|
174
|
+
{
|
|
175
|
+
title: '检查用户是否风测',
|
|
176
|
+
properties: {
|
|
177
|
+
name: {
|
|
178
|
+
const: 'goTovRiskEvaluate',
|
|
179
|
+
default: 'goTovRiskEvaluate',
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
title: '理财通授权-联系顾问',
|
|
185
|
+
properties: {
|
|
186
|
+
name: {
|
|
187
|
+
const: 'goWithConsultDetail',
|
|
188
|
+
default: 'goWithConsultDetail',
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
]);
|
|
193
|
+
expect(result).toEqual([
|
|
194
|
+
{ label: '检查用户是否风测', value: { name: 'goTovRiskEvaluate' } },
|
|
195
|
+
{ label: '理财通授权-联系顾问', value: { name: 'goWithConsultDetail' } },
|
|
196
|
+
]);
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('mergePropertiesColors', () => {
|
|
200
|
+
expect(mergePropertiesColors(null)).toEqual({});
|
|
201
|
+
expect(
|
|
202
|
+
mergePropertiesColors({
|
|
203
|
+
a: {},
|
|
204
|
+
b: {},
|
|
205
|
+
color: {},
|
|
206
|
+
backgroundColor: {},
|
|
207
|
+
background: {},
|
|
208
|
+
c: { format: 'color' },
|
|
209
|
+
d: { 'ui:widget': 'el-color-picker' },
|
|
210
|
+
})
|
|
211
|
+
).toEqual({
|
|
212
|
+
color: {},
|
|
213
|
+
backgroundColor: {},
|
|
214
|
+
background: {},
|
|
215
|
+
c: { format: 'color' },
|
|
216
|
+
d: { 'ui:widget': 'el-color-picker' },
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('compileItem', () => {
|
|
221
|
+
const testTransform = new TransformCore({ ctx: null, schema: {} });
|
|
222
|
+
|
|
223
|
+
/** 类型推断组件名 */
|
|
224
|
+
const result1 = testTransform.compileItem({
|
|
225
|
+
type: 'string',
|
|
226
|
+
});
|
|
227
|
+
expect(result1['x-component']).toEqual('Input');
|
|
228
|
+
expect(result1.type).toEqual('string');
|
|
229
|
+
expect(result1['x-decorator']).toEqual('FormItem');
|
|
230
|
+
expect(result1['x-decorator-props']).toEqual({
|
|
231
|
+
layout: 'vertical',
|
|
232
|
+
labelAlign: 'left',
|
|
233
|
+
labelWrap: true,
|
|
234
|
+
});
|
|
235
|
+
expect(result1['x-component-props']).toHaveProperty('@getData');
|
|
236
|
+
|
|
237
|
+
/** formily 协议属性照搬 */
|
|
238
|
+
const result2 = testTransform.compileItem({
|
|
239
|
+
type: 'string',
|
|
240
|
+
required: true,
|
|
241
|
+
});
|
|
242
|
+
expect(result2.type).toEqual('string');
|
|
243
|
+
expect(result2['x-component']).toEqual('Input');
|
|
244
|
+
expect(result2.required).toEqual(true);
|
|
245
|
+
expect(result2['x-decorator']).toEqual('FormItem');
|
|
246
|
+
expect(result2['x-decorator-props']).toEqual({
|
|
247
|
+
layout: 'vertical',
|
|
248
|
+
labelAlign: 'left',
|
|
249
|
+
labelWrap: true,
|
|
250
|
+
});
|
|
251
|
+
expect(result2['x-component-props']).toHaveProperty('@getData');
|
|
252
|
+
});
|
|
253
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isSchemaConfig } from "../../src/utils/common"
|
|
2
|
+
|
|
3
|
+
describe('utils', () => {
|
|
4
|
+
|
|
5
|
+
it("isSchemaConfig", () => {
|
|
6
|
+
expect(isSchemaConfig({ type: "1" })).toEqual(true);
|
|
7
|
+
expect(isSchemaConfig({ a: "1", "x-component": "Input" })).toEqual(true);
|
|
8
|
+
expect(isSchemaConfig({ a: "1", v: {} })).toEqual(false);
|
|
9
|
+
})
|
|
10
|
+
})
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import { case1, case2 } from "../fixtures/validate";
|
|
2
|
+
import { getAnyOfConfig } from "../../src/utils/anyof_utils";
|
|
3
|
+
import { FormilyValidate } from "../../src/validate";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describe('validate',() =>{
|
|
7
|
+
it('insertPath',() => {
|
|
8
|
+
const validate = new FormilyValidate({schema:{},data:{}});
|
|
9
|
+
validate.insertPath('a');
|
|
10
|
+
expect(validate.path).toEqual('a');
|
|
11
|
+
validate.insertPath('b');
|
|
12
|
+
expect(validate.path).toEqual('a.b');
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('deletePath', () => {
|
|
16
|
+
const validate = new FormilyValidate({schema:{},data:{}});
|
|
17
|
+
|
|
18
|
+
validate.insertPath('a');
|
|
19
|
+
validate.insertPath('b');
|
|
20
|
+
validate.insertPath('c');
|
|
21
|
+
validate.deletePath();
|
|
22
|
+
expect(validate.path).toEqual('a.b');
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('getObjectValues', () =>{
|
|
26
|
+
const validate = new FormilyValidate({ schema: {}, data: {}})
|
|
27
|
+
validate.pathList = []
|
|
28
|
+
expect(validate.getObjectValues({ a: '1', v: '2', d: { c: '3' } })).toEqual(['1','2','3']);
|
|
29
|
+
expect(validate.getObjectValues({ a: '1', v: '2', d: [ '3','3','3','3' ] })).toEqual(['1','2','3', '3', '3', '3']);
|
|
30
|
+
|
|
31
|
+
validate.pathList = ['d','c']
|
|
32
|
+
expect(validate.getObjectValues({ a: '1', v: '2', d: { c: '3' } })).toEqual(['3']);
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('getAnyOfConfig', () =>{
|
|
36
|
+
const vdata1 = [
|
|
37
|
+
{
|
|
38
|
+
title: '填写资讯ID',
|
|
39
|
+
required: [],
|
|
40
|
+
properties: {
|
|
41
|
+
remarkUnderId: {
|
|
42
|
+
type: 'string',
|
|
43
|
+
'ui:options': {
|
|
44
|
+
placeholder: '请输入备注',
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
'x-data': {
|
|
49
|
+
activity: true, // 默认选项
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
title: '直接新增',
|
|
54
|
+
required: ['title'],
|
|
55
|
+
properties: {
|
|
56
|
+
title: {
|
|
57
|
+
type: 'string',
|
|
58
|
+
default: '央行发布重磅报告!货币政策怎么走?注意那些风险,基金市场如何布局面?',
|
|
59
|
+
'ui:options': {
|
|
60
|
+
placeholder: '请输入文章标题',
|
|
61
|
+
},
|
|
62
|
+
'err:required': '请输入文章标题',
|
|
63
|
+
required: true,
|
|
64
|
+
},
|
|
65
|
+
remark: {
|
|
66
|
+
type: 'string',
|
|
67
|
+
'ui:options': {
|
|
68
|
+
placeholder: '请输入备注',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
expect(getAnyOfConfig(vdata1,{remarkUnderId: ''})).toEqual({
|
|
75
|
+
title: '填写资讯ID',
|
|
76
|
+
required: [],
|
|
77
|
+
properties: {
|
|
78
|
+
remarkUnderId: {
|
|
79
|
+
type: 'string',
|
|
80
|
+
'ui:options': {
|
|
81
|
+
placeholder: '请输入备注',
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
'x-data': {
|
|
86
|
+
activity: true, // 默认选项
|
|
87
|
+
},
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
it('getAnyofPropertiesData', () =>{
|
|
92
|
+
const vdata1 = [
|
|
93
|
+
{
|
|
94
|
+
title: '填写资讯ID',
|
|
95
|
+
required: [],
|
|
96
|
+
properties: {
|
|
97
|
+
remarkUnderId: {
|
|
98
|
+
type: 'string',
|
|
99
|
+
'ui:options': {
|
|
100
|
+
placeholder: '请输入备注',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
'x-data': {
|
|
105
|
+
activity: true, // 默认选项
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
title: '直接新增',
|
|
110
|
+
required: ['title'],
|
|
111
|
+
properties: {
|
|
112
|
+
title: {
|
|
113
|
+
type: 'string',
|
|
114
|
+
default: '央行发布重磅报告!货币政策怎么走?注意那些风险,基金市场如何布局面?',
|
|
115
|
+
'ui:options': {
|
|
116
|
+
placeholder: '请输入文章标题',
|
|
117
|
+
},
|
|
118
|
+
'err:required': '请输入文章标题',
|
|
119
|
+
required: true,
|
|
120
|
+
},
|
|
121
|
+
remark: {
|
|
122
|
+
type: 'string',
|
|
123
|
+
'ui:options': {
|
|
124
|
+
placeholder: '请输入备注',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
];
|
|
130
|
+
// expect(getAnyofPropertiesData(vdata1,{ remarkUnderId: '' }).config).toEqual(null);
|
|
131
|
+
})
|
|
132
|
+
it('parseExpression', ()=>{
|
|
133
|
+
const validate = new FormilyValidate({ schema: {}, data: {}})
|
|
134
|
+
const data = {
|
|
135
|
+
middlewares: [
|
|
136
|
+
{
|
|
137
|
+
name: "goWithConsultDetail"
|
|
138
|
+
}
|
|
139
|
+
],
|
|
140
|
+
handler: {
|
|
141
|
+
name: "goToPage",
|
|
142
|
+
options: {
|
|
143
|
+
url: "",
|
|
144
|
+
buryReportName: ""
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
type: "click"
|
|
148
|
+
}
|
|
149
|
+
expect(validate.parseExpression(['..a'],null,'{{$deps[0] == 222}}','d.f',case2)).toEqual(87);
|
|
150
|
+
|
|
151
|
+
expect(validate.parseExpression(['.name'],null,'{{$deps[0] === "goToHome"}}','handler.options',data)).toEqual("goToPage");
|
|
152
|
+
})
|
|
153
|
+
it('parseReactions',() =>{
|
|
154
|
+
const validate = new FormilyValidate({ schema: {}, data: { subscribeType: 98, test:null}});
|
|
155
|
+
validate.insertPath('subscribeType');
|
|
156
|
+
|
|
157
|
+
const data1 = {
|
|
158
|
+
title: "订阅id",
|
|
159
|
+
type: "string",
|
|
160
|
+
default: "",
|
|
161
|
+
"x-reactions": {
|
|
162
|
+
dependencies: [
|
|
163
|
+
".subscribeType"
|
|
164
|
+
],
|
|
165
|
+
fulfill: {
|
|
166
|
+
schema: {
|
|
167
|
+
"x-component-props.cmdParams.subType": "{{$deps[0]}}"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
}
|
|
172
|
+
validate.parseReactions(data1)
|
|
173
|
+
expect(data1).toEqual({...data1,'x-component-props':{ cmdParams: { subType: 98}}})
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
it('checkResult',()=>{
|
|
177
|
+
const validate = new FormilyValidate({ schema: {}, data: { }});
|
|
178
|
+
expect(validate.checkResult(1)).toEqual(true);
|
|
179
|
+
expect(validate.checkResult(0)).toEqual(true);
|
|
180
|
+
expect(validate.checkResult([])).toEqual(false);
|
|
181
|
+
expect(validate.checkResult([1])).toEqual(true);
|
|
182
|
+
expect(validate.checkResult({})).toEqual(false);
|
|
183
|
+
expect(validate.checkResult({a:5})).toEqual(true);
|
|
184
|
+
expect(validate.checkResult({a:5, __validate_value__: false})).toEqual(false);
|
|
185
|
+
expect(validate.checkResult({a:5, __validate_value__: true})).toEqual(true);
|
|
186
|
+
expect(validate.checkResult(null)).toEqual(false);
|
|
187
|
+
expect(validate.checkResult('')).toEqual(false);
|
|
188
|
+
expect(validate.checkResult(undefined)).toEqual(false);
|
|
189
|
+
expect(validate.checkResult([{a:5}])).toEqual(true);
|
|
190
|
+
expect(validate.checkResult([{ a: 5, __validate_value__: false},{ b: 6, __validate_value__: true}])).toEqual(false);
|
|
191
|
+
expect(validate.checkResult([{ a: 5, __validate_value__: true},{ b: 6, __validate_value__: true}])).toEqual(true);
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
it('validateReactions',()=>{
|
|
195
|
+
const validate = new FormilyValidate({ schema: {}, data: { }});
|
|
196
|
+
const data1 = {
|
|
197
|
+
'x-reactions':{}
|
|
198
|
+
}
|
|
199
|
+
expect(validate.validateReactions(data1)).toEqual(false)
|
|
200
|
+
const data2 = {
|
|
201
|
+
'x-reactions':{
|
|
202
|
+
dependencies:['.showTitle'],
|
|
203
|
+
fulfill:{
|
|
204
|
+
schema:{
|
|
205
|
+
'x-visible': '{{$deps[0]===true}}'
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
expect(validate.validateReactions(data2)).toEqual(true)
|
|
211
|
+
const data3 = {
|
|
212
|
+
'x-reactions':{
|
|
213
|
+
dependencies:['.showTitle'],
|
|
214
|
+
fulfill:{
|
|
215
|
+
schema:{
|
|
216
|
+
'x-component-props.show': '{{$deps[0]}}'
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
expect(validate.validateReactions(data3)).toEqual(false)
|
|
222
|
+
})
|
|
223
|
+
it('calc',()=>{
|
|
224
|
+
const validate = new FormilyValidate({ schema: {}, data: { }});
|
|
225
|
+
expect(validate.calc("6===6")).toEqual(true)
|
|
226
|
+
expect(validate.calc("6")).toEqual(6)
|
|
227
|
+
expect(validate.calc("6 === '6'")).toEqual(false);
|
|
228
|
+
expect(validate.calc("6 == '6'")).toEqual(true);
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
it('calculateReactions', ()=>{
|
|
232
|
+
const validate = new FormilyValidate({ schema: {}, data: { }});
|
|
233
|
+
expect(validate.calculateReactions("{{6 === 6}}")).toEqual(true)
|
|
234
|
+
expect(validate.calculateReactions("{{6}}")).toEqual(true)
|
|
235
|
+
expect(validate.calculateReactions("{{6 == '6'}}")).toEqual(true)
|
|
236
|
+
expect(validate.calculateReactions("{{6 === '6'}}")).toEqual(false)
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
it("validate",()=>{
|
|
240
|
+
const data1 = { a: true , b: { b1: '111', b2: { c1: '222', c2: '333'}}};
|
|
241
|
+
const validate = new FormilyValidate({ schema: (case1 as any), data: data1});
|
|
242
|
+
expect(validate.validate()).toEqual([])
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
const data2 = { a: true , b: { b2: { c1: '222'}}};
|
|
246
|
+
const validate2 = new FormilyValidate({ schema: (case1 as any), data: data2}).validate();
|
|
247
|
+
expect(validate2.length).toEqual(1)
|
|
248
|
+
expect(validate2[0].path).toEqual('b.b1')
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
const data3 = { a: true , b: { b1: '222', b2: { c1: '222'}}};
|
|
252
|
+
const validate3 = new FormilyValidate({ schema: (case1 as any), data: data3}).validate();
|
|
253
|
+
expect(validate3.length).toEqual(1)
|
|
254
|
+
expect(validate3[0].path).toEqual('b.b2.c2')
|
|
255
|
+
})
|
|
256
|
+
})
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "ESNext",
|
|
4
|
+
"declaration": true,
|
|
5
|
+
"noImplicitAny": false,
|
|
6
|
+
"removeComments": true,
|
|
7
|
+
"moduleResolution": "node",
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"jsx": "preserve",
|
|
10
|
+
"noLib": false,
|
|
11
|
+
"target": "es6",
|
|
12
|
+
"sourceMap": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"useDefineForClassFields": true,
|
|
17
|
+
"baseUrl": ".",
|
|
18
|
+
"types": ["jest"],
|
|
19
|
+
"paths": {},
|
|
20
|
+
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
|
|
21
|
+
},
|
|
22
|
+
"exclude": ["node_modules"]
|
|
23
|
+
}
|