@yimoka/designable-playground 0.0.0-stage → 0.1.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/README.md +8 -2
- package/dist/demo/components/Alert/index.d.ts +4 -0
- package/dist/demo/components/Alert/index.js +41 -0
- package/dist/demo/components/ArrayCards/index.d.ts +17 -0
- package/dist/demo/components/ArrayCards/index.js +62 -0
- package/dist/demo/components/ArrayList/index.d.ts +25 -0
- package/dist/demo/components/ArrayList/index.js +143 -0
- package/dist/demo/components/ArrayTable/index.d.ts +39 -0
- package/dist/demo/components/ArrayTable/index.js +247 -0
- package/dist/demo/components/AutoComplete/index.d.ts +4 -0
- package/dist/demo/components/AutoComplete/index.js +52 -0
- package/dist/demo/components/Avatar/index.d.ts +4 -0
- package/dist/demo/components/Avatar/index.js +34 -0
- package/dist/demo/components/Badge/index.d.ts +4 -0
- package/dist/demo/components/Badge/index.js +35 -0
- package/dist/demo/components/Button/index.d.ts +4 -0
- package/dist/demo/components/Button/index.js +86 -0
- package/dist/demo/components/Card/index.d.ts +4 -0
- package/dist/demo/components/Card/index.js +72 -0
- package/dist/demo/components/Carousel/index.d.ts +4 -0
- package/dist/demo/components/Carousel/index.js +33 -0
- package/dist/demo/components/Cascader/index.d.ts +4 -0
- package/dist/demo/components/Cascader/index.js +60 -0
- package/dist/demo/components/Checkbox/index.d.ts +8 -0
- package/dist/demo/components/Checkbox/index.js +55 -0
- package/dist/demo/components/ColorPicker/index.d.ts +4 -0
- package/dist/demo/components/ColorPicker/index.js +38 -0
- package/dist/demo/components/DatePicker/index.d.ts +4 -0
- package/dist/demo/components/DatePicker/index.js +61 -0
- package/dist/demo/components/DateRangePicker/index.d.ts +4 -0
- package/dist/demo/components/DateRangePicker/index.js +58 -0
- package/dist/demo/components/Divider/index.d.ts +4 -0
- package/dist/demo/components/Divider/index.js +39 -0
- package/dist/demo/components/Empty/index.d.ts +4 -0
- package/dist/demo/components/Empty/index.js +29 -0
- package/dist/demo/components/Flex/index.d.ts +4 -0
- package/dist/demo/components/Flex/index.js +51 -0
- package/dist/demo/components/Form/index.d.ts +21 -0
- package/dist/demo/components/Form/index.js +116 -0
- package/dist/demo/components/FormCollapse/index.d.ts +28 -0
- package/dist/demo/components/FormCollapse/index.js +164 -0
- package/dist/demo/components/FormGrid/index.d.ts +22 -0
- package/dist/demo/components/FormGrid/index.js +134 -0
- package/dist/demo/components/FormItem/index.d.ts +14 -0
- package/dist/demo/components/FormItem/index.js +33 -0
- package/dist/demo/components/FormLayout/index.d.ts +26 -0
- package/dist/demo/components/FormLayout/index.js +260 -0
- package/dist/demo/components/FormTab/index.d.ts +15 -0
- package/dist/demo/components/FormTab/index.js +186 -0
- package/dist/demo/components/GridCol/index.d.ts +4 -0
- package/dist/demo/components/GridCol/index.js +53 -0
- package/dist/demo/components/GridRow/index.d.ts +4 -0
- package/dist/demo/components/GridRow/index.js +70 -0
- package/dist/demo/components/HTMLContent/index.d.ts +4 -0
- package/dist/demo/components/HTMLContent/index.js +34 -0
- package/dist/demo/components/I18nEditor/index.d.ts +8 -0
- package/dist/demo/components/I18nEditor/index.js +64 -0
- package/dist/demo/components/Image/index.d.ts +4 -0
- package/dist/demo/components/Image/index.js +36 -0
- package/dist/demo/components/Input/index.d.ts +4 -0
- package/dist/demo/components/Input/index.js +36 -0
- package/dist/demo/components/InputSearch/index.d.ts +4 -0
- package/dist/demo/components/InputSearch/index.js +40 -0
- package/dist/demo/components/Link/index.d.ts +4 -0
- package/dist/demo/components/Link/index.js +37 -0
- package/dist/demo/components/Mentions/index.d.ts +4 -0
- package/dist/demo/components/Mentions/index.js +41 -0
- package/dist/demo/components/NumberPicker/index.d.ts +6 -0
- package/dist/demo/components/NumberPicker/index.js +63 -0
- package/dist/demo/components/ObjectContainer/index.d.ts +14 -0
- package/dist/demo/components/ObjectContainer/index.js +46 -0
- package/dist/demo/components/Password/index.d.ts +6 -0
- package/dist/demo/components/Password/index.js +44 -0
- package/dist/demo/components/QRCode/index.d.ts +4 -0
- package/dist/demo/components/QRCode/index.js +34 -0
- package/dist/demo/components/Radio/index.d.ts +6 -0
- package/dist/demo/components/Radio/index.js +49 -0
- package/dist/demo/components/Rate/index.d.ts +6 -0
- package/dist/demo/components/Rate/index.js +43 -0
- package/dist/demo/components/Search/index.d.ts +4 -0
- package/dist/demo/components/Search/index.js +42 -0
- package/dist/demo/components/SearchSelect/index.d.ts +4 -0
- package/dist/demo/components/SearchSelect/index.js +53 -0
- package/dist/demo/components/Select/index.d.ts +4 -0
- package/dist/demo/components/Select/index.js +59 -0
- package/dist/demo/components/Slider/index.d.ts +6 -0
- package/dist/demo/components/Slider/index.js +61 -0
- package/dist/demo/components/Space/index.d.ts +9 -0
- package/dist/demo/components/Space/index.js +61 -0
- package/dist/demo/components/Statistic/index.d.ts +4 -0
- package/dist/demo/components/Statistic/index.js +33 -0
- package/dist/demo/components/Switch/index.d.ts +4 -0
- package/dist/demo/components/Switch/index.js +49 -0
- package/dist/demo/components/Tabs/index.d.ts +10 -0
- package/dist/demo/components/Tabs/index.js +181 -0
- package/dist/demo/components/Tag/index.d.ts +4 -0
- package/dist/demo/components/Tag/index.js +33 -0
- package/dist/demo/components/Text/index.d.ts +11 -0
- package/dist/demo/components/Text/index.js +64 -0
- package/dist/demo/components/TextArea/index.d.ts +6 -0
- package/dist/demo/components/TextArea/index.js +43 -0
- package/dist/demo/components/TimePicker/index.d.ts +4 -0
- package/dist/demo/components/TimePicker/index.js +69 -0
- package/dist/demo/components/TimeRangePicker/index.d.ts +4 -0
- package/dist/demo/components/TimeRangePicker/index.js +68 -0
- package/dist/demo/components/Transfer/index.d.ts +6 -0
- package/dist/demo/components/Transfer/index.js +59 -0
- package/dist/demo/components/TreeSelect/index.d.ts +4 -0
- package/dist/demo/components/TreeSelect/index.js +63 -0
- package/dist/demo/components/Upload/index.d.ts +8 -0
- package/dist/demo/components/Upload/index.js +64 -0
- package/dist/demo/components/index.d.ts +55 -0
- package/dist/demo/components/index.js +55 -0
- package/dist/demo/components/shared.d.ts +143 -0
- package/dist/demo/components/shared.js +315 -0
- package/dist/src/Playground.d.ts +3 -0
- package/dist/src/Playground.js +304 -0
- package/dist/src/antd/AntdPlayground.d.ts +16 -0
- package/dist/src/antd/AntdPlayground.js +136 -0
- package/dist/src/antd/index.d.ts +1 -0
- package/dist/src/antd/index.js +1 -0
- package/dist/src/context.d.ts +4 -0
- package/dist/src/context.js +13 -0
- package/dist/src/examples/index.d.ts +267 -0
- package/dist/src/examples/index.js +824 -0
- package/dist/src/hooks/index.d.ts +4 -0
- package/dist/src/hooks/index.js +4 -0
- package/dist/src/hooks/remoteSchemaAdapter.d.ts +53 -0
- package/dist/src/hooks/remoteSchemaAdapter.js +262 -0
- package/dist/src/hooks/usePlayground.d.ts +38 -0
- package/dist/src/hooks/usePlayground.js +642 -0
- package/dist/src/hooks/usePlaygroundRemotePersistence.d.ts +135 -0
- package/dist/src/hooks/usePlaygroundRemotePersistence.js +736 -0
- package/dist/src/hooks/useSchemaEditorDraft.d.ts +4 -0
- package/dist/src/hooks/useSchemaEditorDraft.js +44 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +14 -0
- package/dist/src/layouts/PlaygroundLayout/ErrorBoundaries.d.ts +59 -0
- package/dist/src/layouts/PlaygroundLayout/ErrorBoundaries.js +161 -0
- package/dist/src/layouts/PlaygroundLayout/index.d.ts +7 -0
- package/dist/src/layouts/PlaygroundLayout/index.js +443 -0
- package/dist/src/layouts/index.d.ts +1 -0
- package/dist/src/layouts/index.js +1 -0
- package/dist/src/panels/CompositePanel/index.d.ts +6 -0
- package/dist/src/panels/CompositePanel/index.js +139 -0
- package/dist/src/panels/ToolbarPanel/index.d.ts +3 -0
- package/dist/src/panels/ToolbarPanel/index.js +24 -0
- package/dist/src/panels/index.d.ts +2 -0
- package/dist/src/panels/index.js +2 -0
- package/dist/src/presets/antd.d.ts +19 -0
- package/dist/src/presets/antd.js +112 -0
- package/dist/src/presets/index.d.ts +4 -0
- package/dist/src/presets/index.js +3 -0
- package/dist/src/presets/runtime-array-helpers.d.ts +8 -0
- package/dist/src/presets/runtime-array-helpers.js +147 -0
- package/dist/src/presets/runtime-component-props.d.ts +3 -0
- package/dist/src/presets/runtime-component-props.js +5 -0
- package/dist/src/presets/runtime-components.d.ts +5 -0
- package/dist/src/presets/runtime-components.js +419 -0
- package/dist/src/presets/runtime-form-components.d.ts +9 -0
- package/dist/src/presets/runtime-form-components.js +94 -0
- package/dist/src/presets/scenario-catalog.d.ts +6 -0
- package/dist/src/presets/scenario-catalog.js +128 -0
- package/dist/src/presets/scenarios.d.ts +52 -0
- package/dist/src/presets/scenarios.js +603 -0
- package/dist/src/runtime/actions.d.ts +19 -0
- package/dist/src/runtime/actions.js +307 -0
- package/dist/src/runtime/contracts.d.ts +149 -0
- package/dist/src/runtime/contracts.js +1 -0
- package/dist/src/runtime/document-bindings.d.ts +3 -0
- package/dist/src/runtime/document-bindings.js +101 -0
- package/dist/src/runtime/document-core.d.ts +57 -0
- package/dist/src/runtime/document-core.js +379 -0
- package/dist/src/runtime/document-entity.d.ts +12 -0
- package/dist/src/runtime/document-entity.js +351 -0
- package/dist/src/runtime/document-expressions.d.ts +35 -0
- package/dist/src/runtime/document-expressions.js +346 -0
- package/dist/src/runtime/document-security.d.ts +34 -0
- package/dist/src/runtime/document-security.js +538 -0
- package/dist/src/runtime/document.d.ts +16 -0
- package/dist/src/runtime/document.js +212 -0
- package/dist/src/runtime/environment.d.ts +16 -0
- package/dist/src/runtime/environment.js +76 -0
- package/dist/src/runtime/i18n-schema.d.ts +36 -0
- package/dist/src/runtime/i18n-schema.js +338 -0
- package/dist/src/runtime/i18n.d.ts +25 -0
- package/dist/src/runtime/i18n.js +447 -0
- package/dist/src/runtime/index.d.ts +8 -0
- package/dist/src/runtime/index.js +8 -0
- package/dist/src/runtime/navigation.d.ts +5 -0
- package/dist/src/runtime/navigation.js +43 -0
- package/dist/src/runtime/playground.d.ts +30 -0
- package/dist/src/runtime/playground.js +243 -0
- package/dist/src/runtime/preview-boundaries.d.ts +13 -0
- package/dist/src/runtime/preview-boundaries.js +43 -0
- package/dist/src/runtime/preview.d.ts +44 -0
- package/dist/src/runtime/preview.js +574 -0
- package/dist/src/runtime/settings/RuntimeJsonEditor.d.ts +10 -0
- package/dist/src/runtime/settings/RuntimeJsonEditor.js +21 -0
- package/dist/src/runtime/settings/RuntimeStoreEntitySettings.d.ts +15 -0
- package/dist/src/runtime/settings/RuntimeStoreEntitySettings.js +65 -0
- package/dist/src/runtime/templates.d.ts +1560 -0
- package/dist/src/runtime/templates.js +508 -0
- package/dist/src/runtime/website-contact-template.d.ts +1 -0
- package/dist/src/runtime/website-contact-template.js +66 -0
- package/dist/src/runtime/website-template-shared.d.ts +14 -0
- package/dist/src/runtime/website-template-shared.js +210 -0
- package/dist/src/runtime/website-templates.d.ts +5 -0
- package/dist/src/runtime/website-templates.js +976 -0
- package/dist/src/shared/clipboard.d.ts +4 -0
- package/dist/src/shared/clipboard.js +56 -0
- package/dist/src/shared/componentRegistry.d.ts +133 -0
- package/dist/src/shared/componentRegistry.js +381 -0
- package/dist/src/shared/formilyCompatibility.d.ts +8 -0
- package/dist/src/shared/formilyCompatibility.js +40 -0
- package/dist/src/shared/index.d.ts +6 -0
- package/dist/src/shared/index.js +6 -0
- package/dist/src/shared/productionAcceptance.d.ts +63 -0
- package/dist/src/shared/productionAcceptance.js +201 -0
- package/dist/src/shared/schema-options.d.ts +16 -0
- package/dist/src/shared/schema-options.js +138 -0
- package/dist/src/shared/schema.d.ts +63 -0
- package/dist/src/shared/schema.js +627 -0
- package/dist/src/shared/styleSecurity.d.ts +2 -0
- package/dist/src/shared/styleSecurity.js +35 -0
- package/dist/src/transformers/formily.d.ts +34 -0
- package/dist/src/transformers/formily.js +943 -0
- package/dist/src/transformers/index.d.ts +1 -0
- package/dist/src/transformers/index.js +1 -0
- package/dist/src/types.d.ts +186 -0
- package/dist/src/types.js +1 -0
- package/dist/src/widgets/ActionsWidget/index.d.ts +3 -0
- package/dist/src/widgets/ActionsWidget/index.js +10 -0
- package/dist/src/widgets/ComponentTreeWidget/index.d.ts +3 -0
- package/dist/src/widgets/ComponentTreeWidget/index.js +333 -0
- package/dist/src/widgets/NodeActionsWidget/index.d.ts +2 -0
- package/dist/src/widgets/NodeActionsWidget/index.js +125 -0
- package/dist/src/widgets/OutlineTreeWidget/index.d.ts +3 -0
- package/dist/src/widgets/OutlineTreeWidget/index.js +432 -0
- package/dist/src/widgets/OutlineTreeWidget/shared.d.ts +32 -0
- package/dist/src/widgets/OutlineTreeWidget/shared.js +79 -0
- package/dist/src/widgets/PreviewWidget/index.d.ts +2 -0
- package/dist/src/widgets/PreviewWidget/index.js +1566 -0
- package/dist/src/widgets/ProductionReadinessWidget/index.d.ts +18 -0
- package/dist/src/widgets/ProductionReadinessWidget/index.js +356 -0
- package/dist/src/widgets/RemotePersistenceStatusWidget/index.d.ts +18 -0
- package/dist/src/widgets/RemotePersistenceStatusWidget/index.js +438 -0
- package/dist/src/widgets/RemoteVersionHistoryWidget/index.d.ts +39 -0
- package/dist/src/widgets/RemoteVersionHistoryWidget/index.js +475 -0
- package/dist/src/widgets/ResourceWidget/index.d.ts +3 -0
- package/dist/src/widgets/ResourceWidget/index.js +491 -0
- package/dist/src/widgets/SchemaCodeView/index.d.ts +7 -0
- package/dist/src/widgets/SchemaCodeView/index.js +225 -0
- package/dist/src/widgets/SchemaEditorWidget/index.d.ts +10 -0
- package/dist/src/widgets/SchemaEditorWidget/index.js +484 -0
- package/dist/src/widgets/SettingsPanelWidget/index.d.ts +3 -0
- package/dist/src/widgets/SettingsPanelWidget/index.js +190 -0
- package/dist/src/widgets/StorageActionsWidget/index.d.ts +2 -0
- package/dist/src/widgets/StorageActionsWidget/index.js +284 -0
- package/dist/src/widgets/index.d.ts +13 -0
- package/dist/src/widgets/index.js +13 -0
- package/package.json +100 -4
|
@@ -0,0 +1,943 @@
|
|
|
1
|
+
import { TreeNode } from '@yimoka/designable-core';
|
|
2
|
+
import { DEFAULT_FORMILY_COMPONENT_NAME_ALIASES, HISTORICAL_FIELD_COMPONENT_NAME, IGNORED_HISTORICAL_FORMILY_COMPONENT_NAMES, } from "../shared/formilyCompatibility.js";
|
|
3
|
+
import { assertSafeSchemaObjectKeys, FORMILY_SCHEMA_ARRAY_CHILD_KEYS, FORMILY_SCHEMA_RECORD_CHILD_KEYS, FORMILY_SCHEMA_SINGLE_CHILD_KEYS, INTERNAL_DESIGNABLE_SCHEMA_PROP_NAMES, isSafeSchemaObjectKey, isSchemaMetadataPropName, RESERVED_FORMILY_SCHEMA_PROP_NAMES, } from "../shared/schema.js";
|
|
4
|
+
const DEFAULT_COMPONENT_TYPES = {
|
|
5
|
+
Input: 'string',
|
|
6
|
+
InputSearch: 'string',
|
|
7
|
+
TextArea: 'string',
|
|
8
|
+
Password: 'string',
|
|
9
|
+
AutoComplete: 'string',
|
|
10
|
+
Search: 'string',
|
|
11
|
+
Mentions: 'string',
|
|
12
|
+
Text: 'void',
|
|
13
|
+
Avatar: 'void',
|
|
14
|
+
Alert: 'void',
|
|
15
|
+
Badge: 'void',
|
|
16
|
+
Divider: 'void',
|
|
17
|
+
Empty: 'void',
|
|
18
|
+
HTMLContent: 'void',
|
|
19
|
+
Image: 'void',
|
|
20
|
+
Link: 'void',
|
|
21
|
+
QRCode: 'void',
|
|
22
|
+
Statistic: 'void',
|
|
23
|
+
Tag: 'void',
|
|
24
|
+
Select: 'string',
|
|
25
|
+
SearchSelect: 'string',
|
|
26
|
+
ColorPicker: 'string',
|
|
27
|
+
DatePicker: 'string',
|
|
28
|
+
DateRangePicker: 'array',
|
|
29
|
+
TimePicker: 'string',
|
|
30
|
+
TimeRangePicker: 'array',
|
|
31
|
+
NumberPicker: 'number',
|
|
32
|
+
Cascader: 'array',
|
|
33
|
+
TreeSelect: 'string',
|
|
34
|
+
Transfer: 'array',
|
|
35
|
+
Checkbox: 'boolean',
|
|
36
|
+
Radio: 'string',
|
|
37
|
+
Switch: 'boolean',
|
|
38
|
+
Slider: 'number',
|
|
39
|
+
Rate: 'number',
|
|
40
|
+
Upload: 'array',
|
|
41
|
+
Button: 'void',
|
|
42
|
+
Form: 'object',
|
|
43
|
+
FormCollapse: 'void',
|
|
44
|
+
FormCollapsePanel: 'void',
|
|
45
|
+
FormGrid: 'void',
|
|
46
|
+
FormGridColumn: 'void',
|
|
47
|
+
FormLayout: 'void',
|
|
48
|
+
FormTab: 'void',
|
|
49
|
+
'FormTab.TabPane': 'void',
|
|
50
|
+
Card: 'void',
|
|
51
|
+
GridRow: 'void',
|
|
52
|
+
GridCol: 'void',
|
|
53
|
+
Flex: 'void',
|
|
54
|
+
Space: 'void',
|
|
55
|
+
Tabs: 'void',
|
|
56
|
+
TabPane: 'void',
|
|
57
|
+
ArrayList: 'array',
|
|
58
|
+
ArrayItem: 'void',
|
|
59
|
+
ArrayCards: 'array',
|
|
60
|
+
ArrayTable: 'array',
|
|
61
|
+
ArrayTableColumn: 'void',
|
|
62
|
+
Object: 'object',
|
|
63
|
+
};
|
|
64
|
+
const DEFAULT_COMPONENT_DECORATORS = {
|
|
65
|
+
Cascader: 'FormItem',
|
|
66
|
+
Checkbox: 'FormItem',
|
|
67
|
+
DatePicker: 'FormItem',
|
|
68
|
+
DateRangePicker: 'FormItem',
|
|
69
|
+
AutoComplete: 'FormItem',
|
|
70
|
+
ColorPicker: 'FormItem',
|
|
71
|
+
Input: 'FormItem',
|
|
72
|
+
InputSearch: 'FormItem',
|
|
73
|
+
Mentions: 'FormItem',
|
|
74
|
+
NumberPicker: 'FormItem',
|
|
75
|
+
Password: 'FormItem',
|
|
76
|
+
Radio: 'FormItem',
|
|
77
|
+
Rate: 'FormItem',
|
|
78
|
+
Select: 'FormItem',
|
|
79
|
+
Search: 'FormItem',
|
|
80
|
+
SearchSelect: 'FormItem',
|
|
81
|
+
Slider: 'FormItem',
|
|
82
|
+
Switch: 'FormItem',
|
|
83
|
+
TextArea: 'FormItem',
|
|
84
|
+
TimePicker: 'FormItem',
|
|
85
|
+
TimeRangePicker: 'FormItem',
|
|
86
|
+
Transfer: 'FormItem',
|
|
87
|
+
TreeSelect: 'FormItem',
|
|
88
|
+
Upload: 'FormItem',
|
|
89
|
+
};
|
|
90
|
+
const DEFAULT_COMPONENT_NAME_BY_TYPE = {
|
|
91
|
+
string: 'Input',
|
|
92
|
+
number: 'NumberPicker',
|
|
93
|
+
integer: 'NumberPicker',
|
|
94
|
+
boolean: 'Switch',
|
|
95
|
+
array: 'ArrayList',
|
|
96
|
+
object: 'Object',
|
|
97
|
+
void: 'Text',
|
|
98
|
+
};
|
|
99
|
+
const STRING_VALUE_SCHEMA_COMPONENTS = new Set([
|
|
100
|
+
'Cascader',
|
|
101
|
+
'DateRangePicker',
|
|
102
|
+
'TimeRangePicker',
|
|
103
|
+
'Transfer',
|
|
104
|
+
]);
|
|
105
|
+
const RESERVED_COMPONENT_PROP_NAMES = new Set([
|
|
106
|
+
'name',
|
|
107
|
+
'title',
|
|
108
|
+
]);
|
|
109
|
+
const COMPONENT_RESERVED_PROP_NAMES_AS_COMPONENT_PROPS = {
|
|
110
|
+
ArrayTableColumn: new Set(['title']),
|
|
111
|
+
Statistic: new Set(['title']),
|
|
112
|
+
};
|
|
113
|
+
const isReservedComponentPropName = (componentName, key) => (RESERVED_COMPONENT_PROP_NAMES.has(key)
|
|
114
|
+
&& !(componentName && COMPONENT_RESERVED_PROP_NAMES_AS_COMPONENT_PROPS[componentName]?.has(key)));
|
|
115
|
+
const SCHEMA_KEY_PROP = 'x-designable-schema-key';
|
|
116
|
+
const FORMILY_PACKAGE_PROP = 'x-designable-formily-package';
|
|
117
|
+
const FORMILY_ROOT_FORM_PROP = 'x-designable-root-form';
|
|
118
|
+
const FORMILY_ROOT_SCHEMA_PROP = 'x-designable-root-schema';
|
|
119
|
+
const FORMILY_ROOT_SCHEMA_FORM_PROP = 'x-designable-root-schema-form';
|
|
120
|
+
const FORMILY_SCHEMA_TYPE_PROP = 'x-designable-schema-type';
|
|
121
|
+
const FORMILY_STATE_HIDDEN_FROM_VISIBLE_PROP = 'x-designable-state-hidden-from-visible';
|
|
122
|
+
const FORMILY_SCALAR_ARRAY_ITEM_PROP = 'x-designable-scalar-array-item';
|
|
123
|
+
const FORMILY_SYNTHETIC_ARRAY_ITEM_PROP = 'x-designable-synthetic-array-item';
|
|
124
|
+
const INTERNAL_PROP_NAMES = INTERNAL_DESIGNABLE_SCHEMA_PROP_NAMES;
|
|
125
|
+
const clonePlainValue = (value) => {
|
|
126
|
+
if (value === undefined || value === null)
|
|
127
|
+
return value;
|
|
128
|
+
return JSON.parse(JSON.stringify(value));
|
|
129
|
+
};
|
|
130
|
+
const clonePlainRecord = (value) => (isRecord(value) ? clonePlainValue(value) : {});
|
|
131
|
+
const getStringProp = (value, key) => (typeof value[key] === 'string' && value[key].trim()
|
|
132
|
+
? value[key]
|
|
133
|
+
: undefined);
|
|
134
|
+
const getSafeSchemaKey = (value) => (typeof value === 'string'
|
|
135
|
+
&& value.trim()
|
|
136
|
+
&& isSafeSchemaObjectKey(value.trim())
|
|
137
|
+
? value.trim()
|
|
138
|
+
: undefined);
|
|
139
|
+
const omitUndefined = (value) => {
|
|
140
|
+
const result = {};
|
|
141
|
+
Object.entries(value).forEach(([key, item]) => {
|
|
142
|
+
if (item !== undefined) {
|
|
143
|
+
result[key] = item;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
return result;
|
|
147
|
+
};
|
|
148
|
+
const getSchemaKey = (node, index, fieldNamePrefix) => {
|
|
149
|
+
const name = getSafeSchemaKey(node.props?.name);
|
|
150
|
+
if (name)
|
|
151
|
+
return name;
|
|
152
|
+
const schemaKey = getSafeSchemaKey(node.props?.[SCHEMA_KEY_PROP]);
|
|
153
|
+
if (schemaKey)
|
|
154
|
+
return schemaKey;
|
|
155
|
+
return `${fieldNamePrefix}_${node.id || index}`;
|
|
156
|
+
};
|
|
157
|
+
const getUniqueSchemaKey = (properties, key) => {
|
|
158
|
+
const baseKey = getSafeSchemaKey(key) ?? 'field';
|
|
159
|
+
if (!Object.prototype.hasOwnProperty.call(properties, baseKey))
|
|
160
|
+
return baseKey;
|
|
161
|
+
let index = 2;
|
|
162
|
+
let nextKey = `${baseKey}_${index}`;
|
|
163
|
+
while (Object.prototype.hasOwnProperty.call(properties, nextKey)) {
|
|
164
|
+
index += 1;
|
|
165
|
+
nextKey = `${baseKey}_${index}`;
|
|
166
|
+
}
|
|
167
|
+
return nextKey;
|
|
168
|
+
};
|
|
169
|
+
const getExplicitSchemaType = (props) => (typeof props[FORMILY_SCHEMA_TYPE_PROP] === 'string'
|
|
170
|
+
? props[FORMILY_SCHEMA_TYPE_PROP]
|
|
171
|
+
: undefined);
|
|
172
|
+
const getMultiValueSchemaType = (props) => (props.valueType === 'string' ? 'string' : 'array');
|
|
173
|
+
const inferSelectSchemaType = (componentName, props) => {
|
|
174
|
+
if (componentName !== 'Select' && componentName !== 'SearchSelect')
|
|
175
|
+
return undefined;
|
|
176
|
+
if (props.mode !== 'multiple' && props.mode !== 'tags')
|
|
177
|
+
return undefined;
|
|
178
|
+
return getMultiValueSchemaType(props);
|
|
179
|
+
};
|
|
180
|
+
const inferCheckboxSchemaType = (componentName, props) => {
|
|
181
|
+
if (componentName !== 'Checkbox')
|
|
182
|
+
return undefined;
|
|
183
|
+
const hasGroupData = (Array.isArray(props.options) && props.options.length > 0)
|
|
184
|
+
|| (Array.isArray(props.data) && props.data.length > 0)
|
|
185
|
+
|| (typeof props.dataKey === 'string' && props.dataKey.trim().length > 0);
|
|
186
|
+
if (!hasGroupData)
|
|
187
|
+
return undefined;
|
|
188
|
+
return getMultiValueSchemaType(props);
|
|
189
|
+
};
|
|
190
|
+
const inferTreeSelectSchemaType = (componentName, props) => {
|
|
191
|
+
if (componentName !== 'TreeSelect')
|
|
192
|
+
return undefined;
|
|
193
|
+
if (props.multiple !== true && props.treeCheckable !== true)
|
|
194
|
+
return undefined;
|
|
195
|
+
return 'array';
|
|
196
|
+
};
|
|
197
|
+
const inferStringValueSchemaType = (componentName, props) => {
|
|
198
|
+
if (!STRING_VALUE_SCHEMA_COMPONENTS.has(componentName))
|
|
199
|
+
return undefined;
|
|
200
|
+
return props.valueType === 'string' ? 'string' : undefined;
|
|
201
|
+
};
|
|
202
|
+
const inferDateTimeSchemaType = (componentName, props) => {
|
|
203
|
+
if (componentName !== 'DatePicker' && componentName !== 'TimePicker')
|
|
204
|
+
return undefined;
|
|
205
|
+
if (componentName === 'DatePicker' && (props.dataValueType === 's' || props.dataValueType === 'ms')) {
|
|
206
|
+
return 'number';
|
|
207
|
+
}
|
|
208
|
+
if (props.multiple !== true)
|
|
209
|
+
return undefined;
|
|
210
|
+
return getMultiValueSchemaType(props);
|
|
211
|
+
};
|
|
212
|
+
const inferComponentSchemaType = (componentName, props, componentTypes) => (inferSelectSchemaType(componentName, props)
|
|
213
|
+
?? inferCheckboxSchemaType(componentName, props)
|
|
214
|
+
?? inferTreeSelectSchemaType(componentName, props)
|
|
215
|
+
?? inferStringValueSchemaType(componentName, props)
|
|
216
|
+
?? inferDateTimeSchemaType(componentName, props)
|
|
217
|
+
?? componentTypes[componentName]
|
|
218
|
+
?? 'void');
|
|
219
|
+
const sortSchemaEntries = (schema) => (Object.entries(schema.properties ?? {})
|
|
220
|
+
.map((entry, declarationIndex) => ({ declarationIndex, entry }))
|
|
221
|
+
.sort((before, after) => {
|
|
222
|
+
const beforeIndex = before.entry[1]['x-index'];
|
|
223
|
+
const afterIndex = after.entry[1]['x-index'];
|
|
224
|
+
if (typeof beforeIndex === 'number' && typeof afterIndex === 'number') {
|
|
225
|
+
return beforeIndex - afterIndex || before.declarationIndex - after.declarationIndex;
|
|
226
|
+
}
|
|
227
|
+
return before.declarationIndex - after.declarationIndex;
|
|
228
|
+
})
|
|
229
|
+
.map(item => item.entry));
|
|
230
|
+
const isRecord = (value) => (typeof value === 'object' && value !== null && !Array.isArray(value));
|
|
231
|
+
const isSchemaPropName = (key, componentName) => (isSchemaMetadataPropName(key, componentName));
|
|
232
|
+
const pickSchemaProps = (value, componentName) => {
|
|
233
|
+
const result = {};
|
|
234
|
+
Object.entries(value).forEach(([key, item]) => {
|
|
235
|
+
if (isSchemaPropName(key, componentName) && item !== undefined) {
|
|
236
|
+
result[key] = item;
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
return result;
|
|
240
|
+
};
|
|
241
|
+
const omitSchemaProps = (value, componentName) => {
|
|
242
|
+
const result = {};
|
|
243
|
+
Object.entries(value).forEach(([key, item]) => {
|
|
244
|
+
if (!INTERNAL_PROP_NAMES.has(key)
|
|
245
|
+
&& !isSchemaPropName(key, componentName)
|
|
246
|
+
&& !isReservedComponentPropName(componentName, key)) {
|
|
247
|
+
result[key] = item;
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
return result;
|
|
251
|
+
};
|
|
252
|
+
const omitInternalProps = (value) => {
|
|
253
|
+
const result = {};
|
|
254
|
+
Object.entries(value).forEach(([key, item]) => {
|
|
255
|
+
if (!INTERNAL_PROP_NAMES.has(key)) {
|
|
256
|
+
result[key] = item;
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
return result;
|
|
260
|
+
};
|
|
261
|
+
const hasOwnProperties = (value) => (Object.keys(value).length > 0);
|
|
262
|
+
const getSchemaPassthroughProps = (schema) => {
|
|
263
|
+
const result = {};
|
|
264
|
+
Object.entries(schema).forEach(([key, item]) => {
|
|
265
|
+
if (!INTERNAL_PROP_NAMES.has(key) && !RESERVED_FORMILY_SCHEMA_PROP_NAMES.has(key) && item !== undefined) {
|
|
266
|
+
result[key] = item;
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
return result;
|
|
270
|
+
};
|
|
271
|
+
const getRootSchemaPassthroughProps = (schema) => ({
|
|
272
|
+
...getSchemaPassthroughProps(schema),
|
|
273
|
+
...(schema.title !== undefined ? { title: schema.title } : {}),
|
|
274
|
+
});
|
|
275
|
+
const getTreeRootSchemaProps = (props) => ({
|
|
276
|
+
...pickSchemaProps(props),
|
|
277
|
+
...(props.title !== undefined ? { title: props.title } : {}),
|
|
278
|
+
});
|
|
279
|
+
const mergeRequiredKeys = (rootRequired, schemaRequired, propertyKeys) => {
|
|
280
|
+
const required = getRequiredKeySet(rootRequired);
|
|
281
|
+
propertyKeys.forEach(key => required.delete(key));
|
|
282
|
+
getRequiredKeySet(schemaRequired).forEach(key => required.add(key));
|
|
283
|
+
return required.size ? Array.from(required) : undefined;
|
|
284
|
+
};
|
|
285
|
+
const mergeRootSchemaProps = (schema, rootProps) => {
|
|
286
|
+
const required = mergeRequiredKeys(rootProps.required, schema.required, Object.keys(schema.properties ?? {}));
|
|
287
|
+
const merged = {
|
|
288
|
+
...rootProps,
|
|
289
|
+
...schema,
|
|
290
|
+
};
|
|
291
|
+
if (required) {
|
|
292
|
+
merged.required = required;
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
delete merged.required;
|
|
296
|
+
}
|
|
297
|
+
return merged;
|
|
298
|
+
};
|
|
299
|
+
const DECORATOR_COL_PROP_NAMES = [
|
|
300
|
+
'labelCol',
|
|
301
|
+
'wrapperCol',
|
|
302
|
+
];
|
|
303
|
+
const FORM_COL_PROP_NAMES = [
|
|
304
|
+
'labelCol',
|
|
305
|
+
'wrapperCol',
|
|
306
|
+
];
|
|
307
|
+
const normalizeDecoratorColForSchema = (value) => {
|
|
308
|
+
if (typeof value === 'number') {
|
|
309
|
+
return value > 0 ? { span: value } : undefined;
|
|
310
|
+
}
|
|
311
|
+
return value;
|
|
312
|
+
};
|
|
313
|
+
const normalizeDecoratorColForProps = (value) => {
|
|
314
|
+
if (isRecord(value) && typeof value.span === 'number') {
|
|
315
|
+
return value.span;
|
|
316
|
+
}
|
|
317
|
+
return value;
|
|
318
|
+
};
|
|
319
|
+
const normalizeFormColForSchema = normalizeDecoratorColForSchema;
|
|
320
|
+
const normalizeFormColForProps = normalizeDecoratorColForProps;
|
|
321
|
+
const normalizeRequiredMarkForSchema = (value) => {
|
|
322
|
+
if (value === 'true')
|
|
323
|
+
return true;
|
|
324
|
+
if (value === 'false')
|
|
325
|
+
return false;
|
|
326
|
+
return value;
|
|
327
|
+
};
|
|
328
|
+
const applyDecoratorPropsAliasesToSchema = (schemaProps) => {
|
|
329
|
+
const decoratorProps = schemaProps['x-decorator-props'];
|
|
330
|
+
if (!isRecord(decoratorProps))
|
|
331
|
+
return schemaProps;
|
|
332
|
+
const nextDecoratorProps = { ...decoratorProps };
|
|
333
|
+
DECORATOR_COL_PROP_NAMES.forEach((key) => {
|
|
334
|
+
const value = normalizeDecoratorColForSchema(nextDecoratorProps[key]);
|
|
335
|
+
if (value === undefined) {
|
|
336
|
+
delete nextDecoratorProps[key];
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
nextDecoratorProps[key] = value;
|
|
340
|
+
}
|
|
341
|
+
});
|
|
342
|
+
return {
|
|
343
|
+
...schemaProps,
|
|
344
|
+
'x-decorator-props': nextDecoratorProps,
|
|
345
|
+
};
|
|
346
|
+
};
|
|
347
|
+
const applyDecoratorSchemaAliasesToProps = (schemaProps) => {
|
|
348
|
+
const decoratorProps = schemaProps['x-decorator-props'];
|
|
349
|
+
if (!isRecord(decoratorProps))
|
|
350
|
+
return schemaProps;
|
|
351
|
+
const nextDecoratorProps = { ...decoratorProps };
|
|
352
|
+
DECORATOR_COL_PROP_NAMES.forEach((key) => {
|
|
353
|
+
nextDecoratorProps[key] = normalizeDecoratorColForProps(nextDecoratorProps[key]);
|
|
354
|
+
});
|
|
355
|
+
return {
|
|
356
|
+
...schemaProps,
|
|
357
|
+
'x-decorator-props': nextDecoratorProps,
|
|
358
|
+
};
|
|
359
|
+
};
|
|
360
|
+
const normalizeFormPropsForSchema = (props) => {
|
|
361
|
+
const nextProps = { ...props };
|
|
362
|
+
FORM_COL_PROP_NAMES.forEach((key) => {
|
|
363
|
+
const value = normalizeFormColForSchema(nextProps[key]);
|
|
364
|
+
if (value === undefined) {
|
|
365
|
+
delete nextProps[key];
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
nextProps[key] = value;
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
if (nextProps.requiredMark !== undefined) {
|
|
372
|
+
nextProps.requiredMark = normalizeRequiredMarkForSchema(nextProps.requiredMark);
|
|
373
|
+
}
|
|
374
|
+
return nextProps;
|
|
375
|
+
};
|
|
376
|
+
const normalizeFormPropsForTree = (props) => {
|
|
377
|
+
const nextProps = { ...props };
|
|
378
|
+
FORM_COL_PROP_NAMES.forEach((key) => {
|
|
379
|
+
nextProps[key] = normalizeFormColForProps(nextProps[key]);
|
|
380
|
+
});
|
|
381
|
+
return nextProps;
|
|
382
|
+
};
|
|
383
|
+
const normalizeComponentPropsForSchema = (componentName, props) => (componentName === 'Form' ? normalizeFormPropsForSchema(props) : props);
|
|
384
|
+
const normalizeComponentPropsForTree = (componentName, props) => (componentName === 'Form' ? normalizeFormPropsForTree(props) : props);
|
|
385
|
+
const applyReadOnlyPropAliasToSchema = (schemaProps, componentProps) => {
|
|
386
|
+
const nextSchemaProps = { ...schemaProps };
|
|
387
|
+
if (typeof nextSchemaProps.readOnly === 'boolean' && nextSchemaProps['x-read-only'] === undefined) {
|
|
388
|
+
nextSchemaProps['x-read-only'] = nextSchemaProps.readOnly;
|
|
389
|
+
delete nextSchemaProps.readOnly;
|
|
390
|
+
}
|
|
391
|
+
if (componentProps.readOnly !== undefined && nextSchemaProps['x-read-only'] === undefined) {
|
|
392
|
+
nextSchemaProps['x-read-only'] = componentProps.readOnly;
|
|
393
|
+
}
|
|
394
|
+
return nextSchemaProps;
|
|
395
|
+
};
|
|
396
|
+
const applyDisabledPropAliasToSchema = (schemaProps, componentProps) => {
|
|
397
|
+
if (componentProps.disabled === undefined || schemaProps['x-disabled'] !== undefined) {
|
|
398
|
+
return schemaProps;
|
|
399
|
+
}
|
|
400
|
+
return {
|
|
401
|
+
...schemaProps,
|
|
402
|
+
'x-disabled': componentProps.disabled,
|
|
403
|
+
};
|
|
404
|
+
};
|
|
405
|
+
const isHiddenDerivedFromVisibleAlias = (schemaProps, sourceProps) => (sourceProps[FORMILY_STATE_HIDDEN_FROM_VISIBLE_PROP] === true
|
|
406
|
+
&& schemaProps['x-visible'] === false);
|
|
407
|
+
const applyHiddenPropAliasToSchema = (schemaProps, componentProps, sourceProps) => {
|
|
408
|
+
const isHiddenDerivedFromVisible = isHiddenDerivedFromVisibleAlias(schemaProps, sourceProps);
|
|
409
|
+
if (componentProps.hidden !== undefined && schemaProps['x-hidden'] === undefined) {
|
|
410
|
+
if (isHiddenDerivedFromVisible) {
|
|
411
|
+
const nextSchemaProps = { ...schemaProps };
|
|
412
|
+
if (componentProps.hidden !== true) {
|
|
413
|
+
delete nextSchemaProps['x-visible'];
|
|
414
|
+
}
|
|
415
|
+
return nextSchemaProps;
|
|
416
|
+
}
|
|
417
|
+
return {
|
|
418
|
+
...schemaProps,
|
|
419
|
+
'x-hidden': componentProps.hidden,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
if (isHiddenDerivedFromVisible && componentProps.hidden !== true) {
|
|
423
|
+
const nextSchemaProps = { ...schemaProps };
|
|
424
|
+
delete nextSchemaProps['x-visible'];
|
|
425
|
+
return nextSchemaProps;
|
|
426
|
+
}
|
|
427
|
+
return schemaProps;
|
|
428
|
+
};
|
|
429
|
+
const omitStateComponentProps = (componentProps) => {
|
|
430
|
+
const nextComponentProps = { ...componentProps };
|
|
431
|
+
delete nextComponentProps.disabled;
|
|
432
|
+
delete nextComponentProps.hidden;
|
|
433
|
+
delete nextComponentProps.readOnly;
|
|
434
|
+
return nextComponentProps;
|
|
435
|
+
};
|
|
436
|
+
const applyStatePropAliasesToSchema = (schemaProps, componentProps, sourceProps) => {
|
|
437
|
+
const readOnlySchemaProps = applyReadOnlyPropAliasToSchema(schemaProps, componentProps);
|
|
438
|
+
const disabledSchemaProps = applyDisabledPropAliasToSchema(readOnlySchemaProps, componentProps);
|
|
439
|
+
const nextSchemaProps = applyHiddenPropAliasToSchema(disabledSchemaProps, componentProps, sourceProps);
|
|
440
|
+
return {
|
|
441
|
+
componentProps: omitStateComponentProps(componentProps),
|
|
442
|
+
schemaProps: nextSchemaProps,
|
|
443
|
+
};
|
|
444
|
+
};
|
|
445
|
+
const applyStateSchemaAliasesToProps = (schemaProps, props) => {
|
|
446
|
+
const nextSchemaProps = { ...schemaProps };
|
|
447
|
+
const nextProps = { ...props };
|
|
448
|
+
if (typeof nextSchemaProps['x-disabled'] === 'boolean') {
|
|
449
|
+
nextProps.disabled = nextSchemaProps['x-disabled'];
|
|
450
|
+
delete nextProps['x-disabled'];
|
|
451
|
+
}
|
|
452
|
+
if (typeof nextSchemaProps['x-hidden'] === 'boolean') {
|
|
453
|
+
nextProps.hidden = nextSchemaProps['x-hidden'];
|
|
454
|
+
delete nextProps['x-hidden'];
|
|
455
|
+
}
|
|
456
|
+
if (nextSchemaProps['x-visible'] === false) {
|
|
457
|
+
nextProps.hidden = true;
|
|
458
|
+
nextProps[FORMILY_STATE_HIDDEN_FROM_VISIBLE_PROP] = true;
|
|
459
|
+
}
|
|
460
|
+
if (typeof nextSchemaProps['x-read-only'] === 'boolean') {
|
|
461
|
+
nextProps.readOnly = nextSchemaProps['x-read-only'];
|
|
462
|
+
delete nextProps['x-read-only'];
|
|
463
|
+
}
|
|
464
|
+
return {
|
|
465
|
+
props: nextProps,
|
|
466
|
+
schemaProps: nextSchemaProps,
|
|
467
|
+
};
|
|
468
|
+
};
|
|
469
|
+
const hasStaticRequiredValidator = (schemaProps) => {
|
|
470
|
+
const validator = schemaProps['x-validator'];
|
|
471
|
+
if (!Array.isArray(validator))
|
|
472
|
+
return false;
|
|
473
|
+
return validator.some(item => (isRecord(item)
|
|
474
|
+
&& item.required === true));
|
|
475
|
+
};
|
|
476
|
+
const getRequiredKeySet = (required) => (Array.isArray(required)
|
|
477
|
+
? new Set(required.filter((key) => typeof key === 'string' && key.trim().length > 0))
|
|
478
|
+
: new Set());
|
|
479
|
+
const syncRequiredFromProperties = (schema) => {
|
|
480
|
+
const propertyEntries = Object.entries(schema.properties ?? {});
|
|
481
|
+
if (!propertyEntries.length)
|
|
482
|
+
return schema;
|
|
483
|
+
const propertyKeys = new Set(propertyEntries.map(([key]) => key));
|
|
484
|
+
const required = getRequiredKeySet(schema.required);
|
|
485
|
+
propertyKeys.forEach(key => required.delete(key));
|
|
486
|
+
propertyEntries.forEach(([key, child]) => {
|
|
487
|
+
if (child.required === true) {
|
|
488
|
+
required.add(key);
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
const nextSchema = { ...schema };
|
|
492
|
+
if (required.size > 0)
|
|
493
|
+
return { ...nextSchema, required: Array.from(required) };
|
|
494
|
+
delete nextSchema.required;
|
|
495
|
+
return nextSchema;
|
|
496
|
+
};
|
|
497
|
+
const assertSchemaPropsFields = (schema, path) => {
|
|
498
|
+
[
|
|
499
|
+
'x-component',
|
|
500
|
+
'x-decorator',
|
|
501
|
+
].forEach((key) => {
|
|
502
|
+
if (schema[key] !== undefined && typeof schema[key] !== 'string') {
|
|
503
|
+
throw new Error(`${path}.${key} 必须是字符串`);
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
[
|
|
507
|
+
'x-component-props',
|
|
508
|
+
'x-decorator-props',
|
|
509
|
+
].forEach((key) => {
|
|
510
|
+
if (schema[key] !== undefined && !isRecord(schema[key])) {
|
|
511
|
+
throw new Error(`${path}.${key} 必须是对象`);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
};
|
|
515
|
+
function assertSchemaNode(schema, path) {
|
|
516
|
+
if (!isRecord(schema)) {
|
|
517
|
+
throw new Error(`${path} 必须是对象`);
|
|
518
|
+
}
|
|
519
|
+
assertSchemaPropsFields(schema, path);
|
|
520
|
+
FORMILY_SCHEMA_RECORD_CHILD_KEYS.forEach((key) => {
|
|
521
|
+
const children = schema[key];
|
|
522
|
+
if (children === undefined)
|
|
523
|
+
return;
|
|
524
|
+
if (!isRecord(children)) {
|
|
525
|
+
throw new Error(`${path}.${key} 必须是对象`);
|
|
526
|
+
}
|
|
527
|
+
Object.entries(children).forEach(([childKey, child]) => {
|
|
528
|
+
const childPath = path === 'root' && key === 'properties'
|
|
529
|
+
? `properties.${childKey}`
|
|
530
|
+
: `${path}.${key}.${childKey}`;
|
|
531
|
+
assertSchemaNode(child, childPath);
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
FORMILY_SCHEMA_SINGLE_CHILD_KEYS.forEach((key) => {
|
|
535
|
+
const child = schema[key];
|
|
536
|
+
if (child === undefined)
|
|
537
|
+
return;
|
|
538
|
+
if ((key === 'additionalProperties' || key === 'additionalItems')
|
|
539
|
+
&& typeof child === 'boolean')
|
|
540
|
+
return;
|
|
541
|
+
assertSchemaNode(child, `${path}.${key}`);
|
|
542
|
+
});
|
|
543
|
+
FORMILY_SCHEMA_ARRAY_CHILD_KEYS.forEach((key) => {
|
|
544
|
+
const children = schema[key];
|
|
545
|
+
if (children === undefined)
|
|
546
|
+
return;
|
|
547
|
+
if (!Array.isArray(children)) {
|
|
548
|
+
throw new Error(`${path}.${key} 必须是数组`);
|
|
549
|
+
}
|
|
550
|
+
children.forEach((child, index) => {
|
|
551
|
+
assertSchemaNode(child, `${path}.${key}.${index}`);
|
|
552
|
+
});
|
|
553
|
+
});
|
|
554
|
+
const { items } = schema;
|
|
555
|
+
if (items === undefined)
|
|
556
|
+
return;
|
|
557
|
+
if (Array.isArray(items)) {
|
|
558
|
+
items.forEach((child, index) => {
|
|
559
|
+
assertSchemaNode(child, `${path}.items.${index}`);
|
|
560
|
+
});
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
assertSchemaNode(items, `${path}.items`);
|
|
564
|
+
}
|
|
565
|
+
function assertSchemaDocument(schema) {
|
|
566
|
+
assertSafeSchemaObjectKeys(schema, 'root');
|
|
567
|
+
if (!isRecord(schema)) {
|
|
568
|
+
throw new Error('Formily Schema 必须是对象');
|
|
569
|
+
}
|
|
570
|
+
if (schema.type !== 'object') {
|
|
571
|
+
throw new Error('Formily Schema 根节点 type 必须是 object');
|
|
572
|
+
}
|
|
573
|
+
if (schema.properties !== undefined && !isRecord(schema.properties)) {
|
|
574
|
+
throw new Error('Formily Schema 根节点 properties 必须是对象');
|
|
575
|
+
}
|
|
576
|
+
assertSchemaNode(schema, 'root');
|
|
577
|
+
}
|
|
578
|
+
export function assertFormilySchemaNode(schema, path = 'root') {
|
|
579
|
+
assertSafeSchemaObjectKeys(schema, path);
|
|
580
|
+
assertSchemaNode(schema, path);
|
|
581
|
+
}
|
|
582
|
+
export function assertFormilySchemaDocument(schema) {
|
|
583
|
+
assertSchemaDocument(schema);
|
|
584
|
+
}
|
|
585
|
+
function assertSchemaPackage(schema) {
|
|
586
|
+
assertSafeSchemaObjectKeys(schema, 'package');
|
|
587
|
+
if (!isRecord(schema)) {
|
|
588
|
+
throw new Error('Formily Schema 包装必须是对象');
|
|
589
|
+
}
|
|
590
|
+
if (schema.form !== undefined && !isRecord(schema.form)) {
|
|
591
|
+
throw new Error('Formily Schema 包装 form 必须是对象');
|
|
592
|
+
}
|
|
593
|
+
assertSchemaDocument(schema.schema);
|
|
594
|
+
}
|
|
595
|
+
const isSchemaPackage = (schema) => (isRecord(schema)
|
|
596
|
+
&& schema.schema !== undefined);
|
|
597
|
+
const isRootFormSchema = (schema) => (schema['x-component'] === 'Form');
|
|
598
|
+
const isScalarArrayItemSchema = (schema, arrayItemComponentName) => (!schema.properties
|
|
599
|
+
&& !schema.items
|
|
600
|
+
&& schema['x-component'] !== arrayItemComponentName
|
|
601
|
+
&& schema.type !== 'object'
|
|
602
|
+
&& schema.type !== 'void');
|
|
603
|
+
const isIgnoredHistoricalSchemaNode = (schema) => (typeof schema['x-component'] === 'string'
|
|
604
|
+
&& IGNORED_HISTORICAL_FORMILY_COMPONENT_NAMES.has(schema['x-component']));
|
|
605
|
+
const createSchemaDocumentFromTree = (tree, toSchemaNode) => {
|
|
606
|
+
const rootProps = clonePlainValue(tree.props ?? {});
|
|
607
|
+
const schema = {
|
|
608
|
+
...pickSchemaProps(rootProps),
|
|
609
|
+
...(rootProps.title !== undefined ? { title: rootProps.title } : {}),
|
|
610
|
+
type: 'object',
|
|
611
|
+
properties: {},
|
|
612
|
+
};
|
|
613
|
+
tree.children?.forEach((child, index) => {
|
|
614
|
+
const [key, childSchema] = toSchemaNode(child, index);
|
|
615
|
+
schema.properties[getUniqueSchemaKey(schema.properties, key)] = childSchema;
|
|
616
|
+
});
|
|
617
|
+
return syncRequiredFromProperties(schema);
|
|
618
|
+
};
|
|
619
|
+
export const createFormilySchemaTransformer = (options = {}) => {
|
|
620
|
+
const { rootComponentName = 'Root', componentTypes = DEFAULT_COMPONENT_TYPES, componentDecorators = DEFAULT_COMPONENT_DECORATORS, componentNameAliases = DEFAULT_FORMILY_COMPONENT_NAME_ALIASES, componentNameByType = DEFAULT_COMPONENT_NAME_BY_TYPE, arrayItemComponentName = 'ArrayItem', fieldNamePrefix = 'field', } = options;
|
|
621
|
+
const normalizeComponentName = (componentName) => (componentNameAliases[componentName] ?? componentName);
|
|
622
|
+
const getHistoricalFieldComponentName = (props) => {
|
|
623
|
+
const componentName = getStringProp(props, 'x-component');
|
|
624
|
+
return componentName ? normalizeComponentName(componentName) : undefined;
|
|
625
|
+
};
|
|
626
|
+
const resolveTreeComponentName = (componentName, props) => {
|
|
627
|
+
const normalizedComponentName = normalizeComponentName(componentName);
|
|
628
|
+
if (normalizedComponentName !== HISTORICAL_FIELD_COMPONENT_NAME) {
|
|
629
|
+
return normalizedComponentName;
|
|
630
|
+
}
|
|
631
|
+
const fieldComponentName = getHistoricalFieldComponentName(props);
|
|
632
|
+
if (fieldComponentName)
|
|
633
|
+
return fieldComponentName;
|
|
634
|
+
const schemaType = getStringProp(props, 'type');
|
|
635
|
+
return schemaType && componentNameByType[schemaType]
|
|
636
|
+
? componentNameByType[schemaType]
|
|
637
|
+
: normalizedComponentName;
|
|
638
|
+
};
|
|
639
|
+
const getTreeComponentProps = (sourceComponentName, componentName, props) => {
|
|
640
|
+
const baseProps = omitSchemaProps(props, componentName);
|
|
641
|
+
if (normalizeComponentName(sourceComponentName) !== HISTORICAL_FIELD_COMPONENT_NAME) {
|
|
642
|
+
return baseProps;
|
|
643
|
+
}
|
|
644
|
+
const componentProps = {
|
|
645
|
+
...clonePlainRecord(props['x-component-props']),
|
|
646
|
+
...baseProps,
|
|
647
|
+
};
|
|
648
|
+
delete componentProps.type;
|
|
649
|
+
delete componentProps['x-component'];
|
|
650
|
+
delete componentProps['x-component-props'];
|
|
651
|
+
return componentProps;
|
|
652
|
+
};
|
|
653
|
+
const getTreeSchemaType = (componentName, props) => (getExplicitSchemaType(props)
|
|
654
|
+
?? (normalizeComponentName(componentName) === HISTORICAL_FIELD_COMPONENT_NAME
|
|
655
|
+
? getStringProp(props, 'type')
|
|
656
|
+
: undefined));
|
|
657
|
+
const inferComponentName = (key, schema) => {
|
|
658
|
+
if (typeof schema['x-component'] === 'string' && schema['x-component']) {
|
|
659
|
+
return normalizeComponentName(schema['x-component']);
|
|
660
|
+
}
|
|
661
|
+
if (typeof schema.type === 'string' && componentNameByType[schema.type]) {
|
|
662
|
+
return componentNameByType[schema.type];
|
|
663
|
+
}
|
|
664
|
+
return key;
|
|
665
|
+
};
|
|
666
|
+
const normalizeArrayItemSchema = (itemSchema) => (itemSchema.type === 'void'
|
|
667
|
+
? { ...itemSchema, type: 'object' }
|
|
668
|
+
: itemSchema);
|
|
669
|
+
const getArrayItemSchemaType = (explicitSchemaType) => {
|
|
670
|
+
if (explicitSchemaType)
|
|
671
|
+
return explicitSchemaType;
|
|
672
|
+
return componentTypes[arrayItemComponentName] === 'array' ? 'array' : 'object';
|
|
673
|
+
};
|
|
674
|
+
const appendSchemaProperties = (schemaNode, children) => {
|
|
675
|
+
if (!children.length)
|
|
676
|
+
return schemaNode;
|
|
677
|
+
const properties = {};
|
|
678
|
+
children.forEach((child, childIndex) => {
|
|
679
|
+
const [childKey, childSchema] = toSchemaNode(child, childIndex);
|
|
680
|
+
properties[getUniqueSchemaKey(properties, childKey)] = childSchema;
|
|
681
|
+
});
|
|
682
|
+
return syncRequiredFromProperties({
|
|
683
|
+
...schemaNode,
|
|
684
|
+
properties,
|
|
685
|
+
});
|
|
686
|
+
};
|
|
687
|
+
const toSyntheticArrayItemSchema = (node, props, rawSchemaProps) => {
|
|
688
|
+
if (props[FORMILY_SCALAR_ARRAY_ITEM_PROP] === true && node.children?.[0]) {
|
|
689
|
+
const [, itemSchema] = toSchemaNode(node.children[0], 0);
|
|
690
|
+
const nextItemSchema = { ...itemSchema };
|
|
691
|
+
delete nextItemSchema['x-index'];
|
|
692
|
+
delete nextItemSchema['x-designable-id'];
|
|
693
|
+
return nextItemSchema;
|
|
694
|
+
}
|
|
695
|
+
const explicitSchemaType = getTreeSchemaType(node.componentName, props);
|
|
696
|
+
const itemSchemaNode = omitUndefined({
|
|
697
|
+
...rawSchemaProps,
|
|
698
|
+
type: getArrayItemSchemaType(explicitSchemaType),
|
|
699
|
+
title: typeof props.title === 'string' ? props.title : undefined,
|
|
700
|
+
});
|
|
701
|
+
return appendSchemaProperties(itemSchemaNode, node.children ?? []);
|
|
702
|
+
};
|
|
703
|
+
const getArrayExportChildren = (children) => ({
|
|
704
|
+
arrayItemChild: children.find(child => child.componentName === arrayItemComponentName),
|
|
705
|
+
propertyChildren: children.filter(child => child.componentName !== arrayItemComponentName),
|
|
706
|
+
syntheticArrayItemChildren: children.filter(child => (child.componentName === arrayItemComponentName
|
|
707
|
+
&& child.props?.[FORMILY_SYNTHETIC_ARRAY_ITEM_PROP] === true)),
|
|
708
|
+
});
|
|
709
|
+
const applyArrayItemsToSchema = (schemaNode, children) => {
|
|
710
|
+
const { arrayItemChild, syntheticArrayItemChildren, } = getArrayExportChildren(children);
|
|
711
|
+
if (syntheticArrayItemChildren.length > 1) {
|
|
712
|
+
return {
|
|
713
|
+
...schemaNode,
|
|
714
|
+
items: syntheticArrayItemChildren.map((child, childIndex) => {
|
|
715
|
+
const [, itemSchema] = toSchemaNode(child, childIndex);
|
|
716
|
+
return normalizeArrayItemSchema(itemSchema);
|
|
717
|
+
}),
|
|
718
|
+
};
|
|
719
|
+
}
|
|
720
|
+
if (!arrayItemChild)
|
|
721
|
+
return schemaNode;
|
|
722
|
+
const [, itemSchema] = toSchemaNode(arrayItemChild, 0);
|
|
723
|
+
return {
|
|
724
|
+
...schemaNode,
|
|
725
|
+
items: normalizeArrayItemSchema(itemSchema),
|
|
726
|
+
};
|
|
727
|
+
};
|
|
728
|
+
const applySchemaNodeChildren = (schemaNode, children) => {
|
|
729
|
+
if (!children.length)
|
|
730
|
+
return schemaNode;
|
|
731
|
+
if (schemaNode.type !== 'array') {
|
|
732
|
+
return appendSchemaProperties(schemaNode, children);
|
|
733
|
+
}
|
|
734
|
+
const { propertyChildren, } = getArrayExportChildren(children);
|
|
735
|
+
return appendSchemaProperties(applyArrayItemsToSchema(schemaNode, children), propertyChildren);
|
|
736
|
+
};
|
|
737
|
+
const toSchemaNode = (node, index) => {
|
|
738
|
+
const key = getSchemaKey(node, index, fieldNamePrefix);
|
|
739
|
+
const props = clonePlainValue(node.props ?? {});
|
|
740
|
+
const componentName = resolveTreeComponentName(node.componentName, props);
|
|
741
|
+
const rawSchemaProps = pickSchemaProps(props, componentName);
|
|
742
|
+
if (componentName === arrayItemComponentName && props[FORMILY_SYNTHETIC_ARRAY_ITEM_PROP] === true) {
|
|
743
|
+
return [key, toSyntheticArrayItemSchema(node, props, rawSchemaProps)];
|
|
744
|
+
}
|
|
745
|
+
const componentProps = normalizeComponentPropsForSchema(componentName, getTreeComponentProps(node.componentName, componentName, props));
|
|
746
|
+
const decorator = componentDecorators[componentName];
|
|
747
|
+
const schemaProps = decorator && rawSchemaProps['x-decorator'] === undefined
|
|
748
|
+
? { ...rawSchemaProps, 'x-decorator': decorator }
|
|
749
|
+
: rawSchemaProps;
|
|
750
|
+
const decoratorAliasedSchemaProps = applyDecoratorPropsAliasesToSchema(schemaProps);
|
|
751
|
+
const { componentProps: schemaComponentProps, schemaProps: aliasedSchemaProps, } = applyStatePropAliasesToSchema(decoratorAliasedSchemaProps, componentProps, props);
|
|
752
|
+
const explicitSchemaType = getTreeSchemaType(node.componentName, props);
|
|
753
|
+
const schemaNode = omitUndefined({
|
|
754
|
+
...aliasedSchemaProps,
|
|
755
|
+
type: explicitSchemaType
|
|
756
|
+
? explicitSchemaType
|
|
757
|
+
: inferComponentSchemaType(componentName, schemaComponentProps, componentTypes),
|
|
758
|
+
title: typeof props.title === 'string' ? props.title : undefined,
|
|
759
|
+
'x-component': componentName,
|
|
760
|
+
'x-component-props': hasOwnProperties(schemaComponentProps) ? schemaComponentProps : undefined,
|
|
761
|
+
'x-designable-id': node.id,
|
|
762
|
+
'x-index': index,
|
|
763
|
+
});
|
|
764
|
+
return [key, applySchemaNodeChildren(schemaNode, node.children ?? [])];
|
|
765
|
+
};
|
|
766
|
+
function toSchemaPropertiesTreeNodes(schema) {
|
|
767
|
+
return sortSchemaEntries(schema)
|
|
768
|
+
.filter(([, childSchema]) => !isIgnoredHistoricalSchemaNode(childSchema))
|
|
769
|
+
.map(([childKey, childSchema]) => (toTreeNodeSchema(childKey, childSchema, getRequiredKeySet(schema.required))));
|
|
770
|
+
}
|
|
771
|
+
function toSyntheticArrayItemTreeNode(itemSchema, itemKey) {
|
|
772
|
+
const isScalarItem = isScalarArrayItemSchema(itemSchema, arrayItemComponentName);
|
|
773
|
+
const itemProps = omitUndefined({
|
|
774
|
+
...getSchemaPassthroughProps(itemSchema),
|
|
775
|
+
title: itemSchema.title,
|
|
776
|
+
[FORMILY_SCALAR_ARRAY_ITEM_PROP]: isScalarItem ? true : undefined,
|
|
777
|
+
[FORMILY_SYNTHETIC_ARRAY_ITEM_PROP]: true,
|
|
778
|
+
});
|
|
779
|
+
return {
|
|
780
|
+
componentName: arrayItemComponentName,
|
|
781
|
+
props: itemProps,
|
|
782
|
+
children: itemSchema.properties
|
|
783
|
+
? toSchemaPropertiesTreeNodes(itemSchema)
|
|
784
|
+
: [toTreeNodeSchema(itemKey, itemSchema)],
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
function toArrayItemsTreeNodes(schema) {
|
|
788
|
+
if (schema.type !== 'array' || !schema.items)
|
|
789
|
+
return [];
|
|
790
|
+
if (Array.isArray(schema.items)) {
|
|
791
|
+
return schema.items.map((itemSchema, itemIndex) => (toSyntheticArrayItemTreeNode(itemSchema, `items_${itemIndex}`)));
|
|
792
|
+
}
|
|
793
|
+
if (inferComponentName('items', schema.items) === arrayItemComponentName) {
|
|
794
|
+
return [toTreeNodeSchema('items', schema.items)];
|
|
795
|
+
}
|
|
796
|
+
return [toSyntheticArrayItemTreeNode(schema.items, 'value')];
|
|
797
|
+
}
|
|
798
|
+
function getDecoratedSchemaProps(componentName, rawSchemaProps) {
|
|
799
|
+
const decorator = componentDecorators[componentName];
|
|
800
|
+
if (!decorator || rawSchemaProps['x-decorator'] !== undefined) {
|
|
801
|
+
return rawSchemaProps;
|
|
802
|
+
}
|
|
803
|
+
return { ...rawSchemaProps, 'x-decorator': decorator };
|
|
804
|
+
}
|
|
805
|
+
function getTreeRequiredProp(key, parentRequiredKeys, schemaProps, componentProps) {
|
|
806
|
+
if (schemaProps.required !== undefined)
|
|
807
|
+
return schemaProps.required;
|
|
808
|
+
if (componentProps.required !== undefined)
|
|
809
|
+
return componentProps.required;
|
|
810
|
+
if (!parentRequiredKeys.has(key) && !hasStaticRequiredValidator(schemaProps))
|
|
811
|
+
return undefined;
|
|
812
|
+
return true;
|
|
813
|
+
}
|
|
814
|
+
function getTreeNameProp(key, schema, componentName, componentProps) {
|
|
815
|
+
if (componentProps.name !== undefined)
|
|
816
|
+
return componentProps.name;
|
|
817
|
+
if (schema.type === 'void' || componentName === arrayItemComponentName)
|
|
818
|
+
return undefined;
|
|
819
|
+
return key;
|
|
820
|
+
}
|
|
821
|
+
function getTreeSchemaKeyProp(key, schema, componentProps) {
|
|
822
|
+
if (componentProps.name !== undefined || schema.type !== 'void')
|
|
823
|
+
return undefined;
|
|
824
|
+
return key;
|
|
825
|
+
}
|
|
826
|
+
function getTreeSchemaProps(key, schema, componentName, parentRequiredKeys) {
|
|
827
|
+
const rawSchemaProps = getSchemaPassthroughProps(schema);
|
|
828
|
+
const schemaProps = getDecoratedSchemaProps(componentName, rawSchemaProps);
|
|
829
|
+
const decoratorAliasedSchemaProps = applyDecoratorSchemaAliasesToProps(schemaProps);
|
|
830
|
+
const componentProps = normalizeComponentPropsForTree(componentName, clonePlainValue(schema['x-component-props'] ?? {}));
|
|
831
|
+
const baseProps = omitUndefined({
|
|
832
|
+
...decoratorAliasedSchemaProps,
|
|
833
|
+
...componentProps,
|
|
834
|
+
[FORMILY_SCHEMA_TYPE_PROP]: schema.type,
|
|
835
|
+
required: getTreeRequiredProp(key, parentRequiredKeys, decoratorAliasedSchemaProps, componentProps),
|
|
836
|
+
name: getTreeNameProp(key, schema, componentName, componentProps),
|
|
837
|
+
[SCHEMA_KEY_PROP]: getTreeSchemaKeyProp(key, schema, componentProps),
|
|
838
|
+
title: componentProps.title ?? schema.title,
|
|
839
|
+
});
|
|
840
|
+
const { props } = applyStateSchemaAliasesToProps(decoratorAliasedSchemaProps, baseProps);
|
|
841
|
+
return props;
|
|
842
|
+
}
|
|
843
|
+
function toTreeNodeSchema(key, schema, parentRequiredKeys = new Set()) {
|
|
844
|
+
const componentName = inferComponentName(key, schema);
|
|
845
|
+
return {
|
|
846
|
+
id: schema['x-designable-id'],
|
|
847
|
+
componentName,
|
|
848
|
+
props: getTreeSchemaProps(key, schema, componentName, parentRequiredKeys),
|
|
849
|
+
children: [
|
|
850
|
+
...toArrayItemsTreeNodes(schema),
|
|
851
|
+
...toSchemaPropertiesTreeNodes(schema),
|
|
852
|
+
],
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
function getRootSchemaFormNode(tree) {
|
|
856
|
+
if (tree.props?.[FORMILY_ROOT_SCHEMA_PROP] !== true)
|
|
857
|
+
return undefined;
|
|
858
|
+
return tree.children?.find(child => child.props?.[FORMILY_ROOT_SCHEMA_FORM_PROP] === true);
|
|
859
|
+
}
|
|
860
|
+
function getPackageRootFormNode(tree) {
|
|
861
|
+
if (tree.props?.[FORMILY_PACKAGE_PROP] !== true)
|
|
862
|
+
return undefined;
|
|
863
|
+
return tree.children?.find(child => child.props?.[FORMILY_ROOT_FORM_PROP] === true);
|
|
864
|
+
}
|
|
865
|
+
function toRootFormSchemaDocument(tree, rootSchemaFormNode) {
|
|
866
|
+
const schema = createSchemaDocumentFromTree(rootSchemaFormNode, toSchemaNode);
|
|
867
|
+
const rootProps = clonePlainValue(tree.props ?? {});
|
|
868
|
+
const formProps = normalizeFormPropsForSchema(omitInternalProps(clonePlainValue(rootSchemaFormNode.props ?? {})));
|
|
869
|
+
return {
|
|
870
|
+
...mergeRootSchemaProps(schema, getTreeRootSchemaProps(rootProps)),
|
|
871
|
+
'x-component': rootSchemaFormNode.componentName,
|
|
872
|
+
'x-component-props': hasOwnProperties(formProps) ? formProps : undefined,
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
function toSchemaPackageDocument(tree, rootFormNode) {
|
|
876
|
+
const schema = createSchemaDocumentFromTree(rootFormNode, toSchemaNode);
|
|
877
|
+
const rootProps = clonePlainValue(tree.props ?? {});
|
|
878
|
+
return {
|
|
879
|
+
form: normalizeFormPropsForSchema(omitInternalProps(clonePlainValue(rootFormNode.props ?? {}))),
|
|
880
|
+
schema: mergeRootSchemaProps(schema, getTreeRootSchemaProps(rootProps)),
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
return {
|
|
884
|
+
toSchema(tree) {
|
|
885
|
+
const rootSchemaFormNode = getRootSchemaFormNode(tree);
|
|
886
|
+
const rootFormNode = getPackageRootFormNode(tree);
|
|
887
|
+
if (rootSchemaFormNode) {
|
|
888
|
+
return toRootFormSchemaDocument(tree, rootSchemaFormNode);
|
|
889
|
+
}
|
|
890
|
+
if (rootFormNode) {
|
|
891
|
+
return toSchemaPackageDocument(tree, rootFormNode);
|
|
892
|
+
}
|
|
893
|
+
return createSchemaDocumentFromTree(tree, toSchemaNode);
|
|
894
|
+
},
|
|
895
|
+
toTreeNode(schema) {
|
|
896
|
+
if (isSchemaPackage(schema)) {
|
|
897
|
+
assertSchemaPackage(schema);
|
|
898
|
+
return new TreeNode({
|
|
899
|
+
componentName: rootComponentName,
|
|
900
|
+
props: {
|
|
901
|
+
...getRootSchemaPassthroughProps(schema.schema),
|
|
902
|
+
[FORMILY_PACKAGE_PROP]: true,
|
|
903
|
+
},
|
|
904
|
+
children: [
|
|
905
|
+
{
|
|
906
|
+
componentName: 'Form',
|
|
907
|
+
props: {
|
|
908
|
+
...normalizeFormPropsForTree(clonePlainRecord(schema.form)),
|
|
909
|
+
[FORMILY_ROOT_FORM_PROP]: true,
|
|
910
|
+
},
|
|
911
|
+
children: sortSchemaEntries(schema.schema).map(([key, childSchema]) => (toTreeNodeSchema(key, childSchema, getRequiredKeySet(schema.schema.required)))),
|
|
912
|
+
},
|
|
913
|
+
],
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
assertSchemaDocument(schema);
|
|
917
|
+
if (isRootFormSchema(schema)) {
|
|
918
|
+
return new TreeNode({
|
|
919
|
+
componentName: rootComponentName,
|
|
920
|
+
props: {
|
|
921
|
+
...getRootSchemaPassthroughProps(schema),
|
|
922
|
+
[FORMILY_ROOT_SCHEMA_PROP]: true,
|
|
923
|
+
},
|
|
924
|
+
children: [
|
|
925
|
+
{
|
|
926
|
+
componentName: 'Form',
|
|
927
|
+
props: {
|
|
928
|
+
...normalizeFormPropsForTree(clonePlainRecord(schema['x-component-props'])),
|
|
929
|
+
[FORMILY_ROOT_SCHEMA_FORM_PROP]: true,
|
|
930
|
+
},
|
|
931
|
+
children: sortSchemaEntries(schema).map(([key, childSchema]) => (toTreeNodeSchema(key, childSchema, getRequiredKeySet(schema.required)))),
|
|
932
|
+
},
|
|
933
|
+
],
|
|
934
|
+
});
|
|
935
|
+
}
|
|
936
|
+
return new TreeNode({
|
|
937
|
+
componentName: rootComponentName,
|
|
938
|
+
props: getRootSchemaPassthroughProps(schema),
|
|
939
|
+
children: sortSchemaEntries(schema).map(([key, childSchema]) => (toTreeNodeSchema(key, childSchema, getRequiredKeySet(schema.required)))),
|
|
940
|
+
});
|
|
941
|
+
},
|
|
942
|
+
};
|
|
943
|
+
};
|