@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,574 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { DynamicView, } from '@yimoka/react';
|
|
3
|
+
import { BaseStore, ListStore, } from '@yimoka/store';
|
|
4
|
+
import { cloneDeep, mergeWith } from 'lodash-es';
|
|
5
|
+
import { useEffect, useMemo, } from 'react';
|
|
6
|
+
import { DEFAULT_FORMILY_COMPONENT_NAME_ALIASES } from "../shared/formilyCompatibility.js";
|
|
7
|
+
import { decodeJsonPointerSegment, FORMILY_SCHEMA_ARRAY_CHILD_KEYS, FORMILY_SCHEMA_RECORD_CHILD_KEYS, FORMILY_SCHEMA_SINGLE_CHILD_KEYS, visitFormilySchemaNodes, } from "../shared/schema.js";
|
|
8
|
+
import { validateRuntimeDocument, validateRuntimeEnvironmentScope, } from "./document.js";
|
|
9
|
+
import { resolveRuntimeStoreCatalogBinding } from "./environment.js";
|
|
10
|
+
import { RuntimeExecutorBoundary, RuntimePreviewDiagnostics, } from "./preview-boundaries.js";
|
|
11
|
+
const isObjectRecord = (value) => (typeof value === 'object'
|
|
12
|
+
&& value !== null
|
|
13
|
+
&& !Array.isArray(value));
|
|
14
|
+
const isDynamicComponentExpression = (value) => (/^\s*\{\{[\s\S]*\}\}\s*$/.test(value));
|
|
15
|
+
const normalizeRuntimeDocumentComponentAliases = (document) => {
|
|
16
|
+
const normalizedDocument = cloneDeep(document);
|
|
17
|
+
const normalizeNode = (node) => {
|
|
18
|
+
['x-component', 'x-decorator'].forEach((propertyName) => {
|
|
19
|
+
const componentName = node[propertyName];
|
|
20
|
+
if (typeof componentName !== 'string')
|
|
21
|
+
return;
|
|
22
|
+
const normalizedName = DEFAULT_FORMILY_COMPONENT_NAME_ALIASES[componentName];
|
|
23
|
+
if (normalizedName)
|
|
24
|
+
node[propertyName] = normalizedName;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
function normalizeReactionSchemaPatches(value) {
|
|
28
|
+
if (Array.isArray(value)) {
|
|
29
|
+
value.forEach(normalizeReactionSchemaPatches);
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!isObjectRecord(value))
|
|
33
|
+
return;
|
|
34
|
+
['fulfill', 'otherwise'].forEach((branchName) => {
|
|
35
|
+
const branch = value[branchName];
|
|
36
|
+
if (!isObjectRecord(branch) || !Object.prototype.hasOwnProperty.call(branch, 'schema'))
|
|
37
|
+
return;
|
|
38
|
+
normalizeSchemaBranch(branch.schema);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
function normalizeSchemaBranch(value) {
|
|
42
|
+
visitFormilySchemaNodes(value, 'schema', ({ node }) => {
|
|
43
|
+
normalizeNode(node);
|
|
44
|
+
normalizeReactionSchemaPatches(node['x-reactions']);
|
|
45
|
+
if (node['x-component'] !== 'I18nEditor')
|
|
46
|
+
return;
|
|
47
|
+
const componentProps = node['x-component-props'];
|
|
48
|
+
if (!isObjectRecord(componentProps))
|
|
49
|
+
return;
|
|
50
|
+
['inSchema', 'outSchema'].forEach((propertyName) => {
|
|
51
|
+
if (Object.prototype.hasOwnProperty.call(componentProps, propertyName)) {
|
|
52
|
+
normalizeSchemaBranch(componentProps[propertyName]);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
normalizeSchemaBranch(normalizedDocument.schema);
|
|
58
|
+
normalizeSchemaBranch(normalizedDocument.entityConfig?.i18nInSchema);
|
|
59
|
+
normalizeSchemaBranch(normalizedDocument.entityConfig?.i18nOutSchema);
|
|
60
|
+
return normalizedDocument;
|
|
61
|
+
};
|
|
62
|
+
const parseRuntimeLocalSchemaReference = (value) => {
|
|
63
|
+
if (typeof value !== 'string')
|
|
64
|
+
return undefined;
|
|
65
|
+
const match = /^#\/(definitions|\$defs)\/([^/]+)(?:\/|$)/.exec(value);
|
|
66
|
+
if (!match?.[1] || !match[2])
|
|
67
|
+
return undefined;
|
|
68
|
+
const name = decodeJsonPointerSegment(match[2]);
|
|
69
|
+
if (name === undefined)
|
|
70
|
+
return undefined;
|
|
71
|
+
return {
|
|
72
|
+
collection: match[1],
|
|
73
|
+
name,
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
const visitReachableRuntimeSchemaBranch = (value, path, visitor) => {
|
|
77
|
+
if (!isObjectRecord(value))
|
|
78
|
+
return;
|
|
79
|
+
visitor({ node: value, path });
|
|
80
|
+
FORMILY_SCHEMA_RECORD_CHILD_KEYS.forEach((key) => {
|
|
81
|
+
if (key === 'definitions' || key === '$defs')
|
|
82
|
+
return;
|
|
83
|
+
const children = value[key];
|
|
84
|
+
if (!isObjectRecord(children))
|
|
85
|
+
return;
|
|
86
|
+
Object.entries(children).forEach(([childKey, child]) => {
|
|
87
|
+
visitReachableRuntimeSchemaBranch(child, `${path}.${key}.${childKey}`, visitor);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
FORMILY_SCHEMA_SINGLE_CHILD_KEYS.forEach((key) => {
|
|
91
|
+
visitReachableRuntimeSchemaBranch(value[key], `${path}.${key}`, visitor);
|
|
92
|
+
});
|
|
93
|
+
FORMILY_SCHEMA_ARRAY_CHILD_KEYS.forEach((key) => {
|
|
94
|
+
const children = value[key];
|
|
95
|
+
if (!Array.isArray(children))
|
|
96
|
+
return;
|
|
97
|
+
children.forEach((child, index) => {
|
|
98
|
+
visitReachableRuntimeSchemaBranch(child, `${path}.${key}[${index}]`, visitor);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
const { items } = value;
|
|
102
|
+
if (Array.isArray(items)) {
|
|
103
|
+
items.forEach((item, index) => {
|
|
104
|
+
visitReachableRuntimeSchemaBranch(item, `${path}.items[${index}]`, visitor);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
visitReachableRuntimeSchemaBranch(items, `${path}.items`, visitor);
|
|
109
|
+
}
|
|
110
|
+
visitRuntimeReactionSchemaPatches(value['x-reactions'], `${path}.x-reactions`, visitor);
|
|
111
|
+
};
|
|
112
|
+
const visitRuntimeReactionSchemaPatches = (value, path, visitor) => {
|
|
113
|
+
if (Array.isArray(value)) {
|
|
114
|
+
value.forEach((reaction, index) => {
|
|
115
|
+
visitRuntimeReactionSchemaPatches(reaction, `${path}[${index}]`, visitor);
|
|
116
|
+
});
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (!isObjectRecord(value))
|
|
120
|
+
return;
|
|
121
|
+
['fulfill', 'otherwise'].forEach((branchName) => {
|
|
122
|
+
const branch = value[branchName];
|
|
123
|
+
if (!isObjectRecord(branch) || !Object.prototype.hasOwnProperty.call(branch, 'schema')) {
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
visitReachableRuntimeSchemaBranch(branch.schema, `${path}.${branchName}.schema`, visitor);
|
|
127
|
+
});
|
|
128
|
+
};
|
|
129
|
+
const visitRuntimeReactionStateComponents = (value, path, visitor) => {
|
|
130
|
+
if (Array.isArray(value)) {
|
|
131
|
+
value.forEach((reaction, index) => {
|
|
132
|
+
visitRuntimeReactionStateComponents(reaction, `${path}[${index}]`, visitor);
|
|
133
|
+
});
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (!isObjectRecord(value))
|
|
137
|
+
return;
|
|
138
|
+
['fulfill', 'otherwise'].forEach((branchName) => {
|
|
139
|
+
const branch = value[branchName];
|
|
140
|
+
if (!isObjectRecord(branch) || !isObjectRecord(branch.state))
|
|
141
|
+
return;
|
|
142
|
+
const { state } = branch;
|
|
143
|
+
['component', 'decorator'].forEach((propertyName) => {
|
|
144
|
+
if (!Object.prototype.hasOwnProperty.call(state, propertyName))
|
|
145
|
+
return;
|
|
146
|
+
const stateValue = state[propertyName];
|
|
147
|
+
const componentName = Array.isArray(stateValue) ? stateValue[0] : stateValue;
|
|
148
|
+
visitor(componentName, `${path}.${branchName}.state.${propertyName}`);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
};
|
|
152
|
+
const pushRuntimeDiagnostic = (diagnostics, code, path, message) => {
|
|
153
|
+
diagnostics.push({
|
|
154
|
+
code,
|
|
155
|
+
message,
|
|
156
|
+
path,
|
|
157
|
+
severity: 'warning',
|
|
158
|
+
});
|
|
159
|
+
};
|
|
160
|
+
const createRuntimeFieldDefinitions = (entityFieldsConfig, entityFieldsPath, storeFieldsConfig, storeFieldsPath, isListRuntimeStore) => {
|
|
161
|
+
const runtimeFields = new Map();
|
|
162
|
+
const registerRuntimeFields = (fieldsConfig, fieldsPath) => {
|
|
163
|
+
if (!isObjectRecord(fieldsConfig))
|
|
164
|
+
return;
|
|
165
|
+
Object.entries(fieldsConfig).forEach(([field, schema]) => {
|
|
166
|
+
if (!isObjectRecord(schema))
|
|
167
|
+
return;
|
|
168
|
+
const { 'x-output-schema': outputSchema, 'x-query-schema': querySchema, ...rest } = schema;
|
|
169
|
+
const querySafeRest = { ...rest };
|
|
170
|
+
if (isListRuntimeStore) {
|
|
171
|
+
delete querySafeRest.required;
|
|
172
|
+
delete querySafeRest['x-validator'];
|
|
173
|
+
}
|
|
174
|
+
const usesQuerySchema = isListRuntimeStore && isObjectRecord(querySchema);
|
|
175
|
+
const effectiveSchema = usesQuerySchema
|
|
176
|
+
? mergeWith({}, querySafeRest, querySchema, (_targetValue, sourceValue) => (Array.isArray(sourceValue) ? sourceValue : undefined))
|
|
177
|
+
: querySafeRest;
|
|
178
|
+
if (isListRuntimeStore) {
|
|
179
|
+
delete effectiveSchema.required;
|
|
180
|
+
delete effectiveSchema['x-validator'];
|
|
181
|
+
}
|
|
182
|
+
runtimeFields.set(field, {
|
|
183
|
+
path: usesQuerySchema
|
|
184
|
+
? `${fieldsPath}.${field}.x-query-schema`
|
|
185
|
+
: `${fieldsPath}.${field}`,
|
|
186
|
+
schema: effectiveSchema,
|
|
187
|
+
});
|
|
188
|
+
runtimeFields.delete(`__output__${field}`);
|
|
189
|
+
if (isObjectRecord(outputSchema) && Object.keys(outputSchema).length > 0) {
|
|
190
|
+
runtimeFields.set(`__output__${field}`, {
|
|
191
|
+
path: `${fieldsPath}.${field}.x-output-schema`,
|
|
192
|
+
schema: outputSchema,
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
};
|
|
197
|
+
registerRuntimeFields(entityFieldsConfig, entityFieldsPath);
|
|
198
|
+
registerRuntimeFields(storeFieldsConfig, storeFieldsPath);
|
|
199
|
+
return runtimeFields;
|
|
200
|
+
};
|
|
201
|
+
const createRuntimeDocumentFieldDefinitions = (document, environment) => {
|
|
202
|
+
const runtimeStoreSource = environment.store ?? document.store;
|
|
203
|
+
const isListRuntimeStore = runtimeStoreSource instanceof ListStore
|
|
204
|
+
|| (isObjectRecord(runtimeStoreSource)
|
|
205
|
+
&& runtimeStoreSource.type === 'list');
|
|
206
|
+
const storeIsInstance = environment.store instanceof BaseStore;
|
|
207
|
+
const entityFieldsConfig = storeIsInstance
|
|
208
|
+
? undefined
|
|
209
|
+
: document.entityConfig?.fieldsConfig
|
|
210
|
+
?? environment.entity?.config.fieldsConfig;
|
|
211
|
+
const entityFieldsPath = document.entityConfig?.fieldsConfig
|
|
212
|
+
? 'document.entityConfig.fieldsConfig'
|
|
213
|
+
: 'environment.entity.config.fieldsConfig';
|
|
214
|
+
const hasEnvironmentStore = environment.store !== undefined;
|
|
215
|
+
const storeFieldsConfig = hasEnvironmentStore
|
|
216
|
+
? environment.store?.fieldsConfig
|
|
217
|
+
: document.store?.fieldsConfig;
|
|
218
|
+
const storeFieldsPath = hasEnvironmentStore
|
|
219
|
+
? 'environment.store.fieldsConfig'
|
|
220
|
+
: 'document.store.fieldsConfig';
|
|
221
|
+
return createRuntimeFieldDefinitions(entityFieldsConfig, entityFieldsPath, storeFieldsConfig, storeFieldsPath, isListRuntimeStore);
|
|
222
|
+
};
|
|
223
|
+
const collectRuntimeDiagnostics = (document, components, environment) => {
|
|
224
|
+
const diagnostics = [];
|
|
225
|
+
const referencedFieldNames = new Set();
|
|
226
|
+
const inspectedComponentDiagnosticPaths = new Set();
|
|
227
|
+
const knownDataKeys = environment.dataCatalog
|
|
228
|
+
? new Set(environment.dataCatalog
|
|
229
|
+
.map(item => item.dataKey.trim())
|
|
230
|
+
.filter(Boolean))
|
|
231
|
+
: undefined;
|
|
232
|
+
const inspectComponentProperty = (componentName, componentPath) => {
|
|
233
|
+
if (typeof componentName !== 'string'
|
|
234
|
+
|| !componentName.trim()
|
|
235
|
+
|| isDynamicComponentExpression(componentName)) {
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
const normalizedName = componentName.trim();
|
|
239
|
+
if (components[normalizedName])
|
|
240
|
+
return;
|
|
241
|
+
if (inspectedComponentDiagnosticPaths.has(componentPath))
|
|
242
|
+
return;
|
|
243
|
+
inspectedComponentDiagnosticPaths.add(componentPath);
|
|
244
|
+
pushRuntimeDiagnostic(diagnostics, 'runtime-component-not-registered', componentPath, `Runtime 组件 ${normalizedName} 未注册`);
|
|
245
|
+
};
|
|
246
|
+
const inspectNodeDataKey = ({ node, path }) => {
|
|
247
|
+
if (!knownDataKeys)
|
|
248
|
+
return;
|
|
249
|
+
const componentProps = node['x-component-props'];
|
|
250
|
+
if (!isObjectRecord(componentProps))
|
|
251
|
+
return;
|
|
252
|
+
const { dataKey } = componentProps;
|
|
253
|
+
if (typeof dataKey !== 'string' || !dataKey.trim())
|
|
254
|
+
return;
|
|
255
|
+
if (knownDataKeys.has(dataKey.trim()))
|
|
256
|
+
return;
|
|
257
|
+
pushRuntimeDiagnostic(diagnostics, 'unknown-data-key', `${path}.x-component-props.dataKey`, `Runtime 数据键 ${dataKey} 不在宿主目录中`);
|
|
258
|
+
};
|
|
259
|
+
const inspectDocumentSchema = (schema, path) => {
|
|
260
|
+
if (!isObjectRecord(schema))
|
|
261
|
+
return;
|
|
262
|
+
const definitions = {
|
|
263
|
+
$defs: isObjectRecord(schema.$defs) ? schema.$defs : {},
|
|
264
|
+
definitions: isObjectRecord(schema.definitions) ? schema.definitions : {},
|
|
265
|
+
};
|
|
266
|
+
const pendingDefinitions = [];
|
|
267
|
+
const inspectedDefinitions = new Set();
|
|
268
|
+
const resolveLocalComponentProperty = (node, nodePath, propertyName, visited = new Set()) => {
|
|
269
|
+
if (Object.prototype.hasOwnProperty.call(node, propertyName)) {
|
|
270
|
+
return {
|
|
271
|
+
path: `${nodePath}.${propertyName}`,
|
|
272
|
+
value: node[propertyName],
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
if (visited.has(node))
|
|
276
|
+
return undefined;
|
|
277
|
+
visited.add(node);
|
|
278
|
+
const reference = parseRuntimeLocalSchemaReference(node.$ref);
|
|
279
|
+
if (!reference)
|
|
280
|
+
return undefined;
|
|
281
|
+
const referencedNode = definitions[reference.collection][reference.name];
|
|
282
|
+
if (!isObjectRecord(referencedNode))
|
|
283
|
+
return undefined;
|
|
284
|
+
return resolveLocalComponentProperty(referencedNode, `${path}.${reference.collection}.${reference.name}`, propertyName, visited);
|
|
285
|
+
};
|
|
286
|
+
const inspectVisit = (visit, skipComponentInspection = false) => {
|
|
287
|
+
const reference = parseRuntimeLocalSchemaReference(visit.node.$ref);
|
|
288
|
+
if (reference) {
|
|
289
|
+
const localDefinition = definitions[reference.collection][reference.name];
|
|
290
|
+
if (isObjectRecord(localDefinition)) {
|
|
291
|
+
pendingDefinitions.push(reference);
|
|
292
|
+
}
|
|
293
|
+
else if (reference.collection === 'definitions') {
|
|
294
|
+
referencedFieldNames.add(reference.name);
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (!skipComponentInspection) {
|
|
298
|
+
['x-component', 'x-decorator'].forEach((propertyName) => {
|
|
299
|
+
const resolution = resolveLocalComponentProperty(visit.node, visit.path, propertyName);
|
|
300
|
+
if (resolution)
|
|
301
|
+
inspectComponentProperty(resolution.value, resolution.path);
|
|
302
|
+
});
|
|
303
|
+
visitRuntimeReactionStateComponents(visit.node['x-reactions'], `${visit.path}.x-reactions`, inspectComponentProperty);
|
|
304
|
+
}
|
|
305
|
+
inspectNodeDataKey(visit);
|
|
306
|
+
const componentResolution = resolveLocalComponentProperty(visit.node, visit.path, 'x-component');
|
|
307
|
+
if (typeof componentResolution?.value !== 'string'
|
|
308
|
+
|| componentResolution.value.trim() !== 'I18nEditor')
|
|
309
|
+
return;
|
|
310
|
+
const componentProps = visit.node['x-component-props'];
|
|
311
|
+
if (!isObjectRecord(componentProps))
|
|
312
|
+
return;
|
|
313
|
+
['inSchema', 'outSchema'].forEach((propertyName) => {
|
|
314
|
+
if (!Object.prototype.hasOwnProperty.call(componentProps, propertyName))
|
|
315
|
+
return;
|
|
316
|
+
inspectDocumentSchema(componentProps[propertyName], `${visit.path}.x-component-props.${propertyName}`);
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
visitReachableRuntimeSchemaBranch(schema, path, inspectVisit);
|
|
320
|
+
while (pendingDefinitions.length > 0) {
|
|
321
|
+
const reference = pendingDefinitions.shift();
|
|
322
|
+
if (!reference)
|
|
323
|
+
break;
|
|
324
|
+
const definitionKey = `${reference.collection}/${reference.name}`;
|
|
325
|
+
if (inspectedDefinitions.has(definitionKey))
|
|
326
|
+
continue;
|
|
327
|
+
inspectedDefinitions.add(definitionKey);
|
|
328
|
+
const definitionPath = `${path}.${reference.collection}.${reference.name}`;
|
|
329
|
+
visitReachableRuntimeSchemaBranch(definitions[reference.collection][reference.name], definitionPath, visit => inspectVisit(visit, visit.path === definitionPath));
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
inspectDocumentSchema(document.schema, 'document.schema');
|
|
333
|
+
if (document.entityConfig?.i18nInSchema) {
|
|
334
|
+
inspectDocumentSchema(document.entityConfig.i18nInSchema, 'document.entityConfig.i18nInSchema');
|
|
335
|
+
}
|
|
336
|
+
if (document.entityConfig?.i18nOutSchema) {
|
|
337
|
+
inspectDocumentSchema(document.entityConfig.i18nOutSchema, 'document.entityConfig.i18nOutSchema');
|
|
338
|
+
}
|
|
339
|
+
const runtimeFields = createRuntimeDocumentFieldDefinitions(document, environment);
|
|
340
|
+
const inspectedFieldNames = new Set();
|
|
341
|
+
while (true) {
|
|
342
|
+
const field = [...referencedFieldNames].find(name => !inspectedFieldNames.has(name));
|
|
343
|
+
if (!field)
|
|
344
|
+
break;
|
|
345
|
+
inspectedFieldNames.add(field);
|
|
346
|
+
const runtimeField = runtimeFields.get(field);
|
|
347
|
+
if (!runtimeField)
|
|
348
|
+
continue;
|
|
349
|
+
inspectDocumentSchema(runtimeField.schema, runtimeField.path);
|
|
350
|
+
}
|
|
351
|
+
return diagnostics;
|
|
352
|
+
};
|
|
353
|
+
const isRuntimeStoreInstance = (store) => store instanceof BaseStore;
|
|
354
|
+
const resolveRuntimeStore = (document, environment) => {
|
|
355
|
+
if (isRuntimeStoreInstance(environment.store)) {
|
|
356
|
+
return environment.store;
|
|
357
|
+
}
|
|
358
|
+
const source = environment.store ?? document.store;
|
|
359
|
+
if (!source)
|
|
360
|
+
return undefined;
|
|
361
|
+
const store = cloneDeep(source);
|
|
362
|
+
store.apiExecutor = environment.apiExecutor;
|
|
363
|
+
return store;
|
|
364
|
+
};
|
|
365
|
+
const resolveRuntimeEntityProps = (document, environment, storeIsInstance) => {
|
|
366
|
+
const { entity } = environment;
|
|
367
|
+
if (storeIsInstance && entity) {
|
|
368
|
+
const config = cloneDeep(entity.config ?? {});
|
|
369
|
+
if (document.entityConfig) {
|
|
370
|
+
Object.assign(config, cloneDeep(document.entityConfig));
|
|
371
|
+
}
|
|
372
|
+
delete config.apiExecutor;
|
|
373
|
+
return { config };
|
|
374
|
+
}
|
|
375
|
+
if (storeIsInstance) {
|
|
376
|
+
if (!document.entityConfig)
|
|
377
|
+
return undefined;
|
|
378
|
+
const config = cloneDeep(document.entityConfig);
|
|
379
|
+
delete config.apiExecutor;
|
|
380
|
+
return { config };
|
|
381
|
+
}
|
|
382
|
+
const hasConfigOverride = Boolean(document.entityConfig || environment.apiExecutor);
|
|
383
|
+
if (!hasConfigOverride) {
|
|
384
|
+
return undefined;
|
|
385
|
+
}
|
|
386
|
+
const config = {
|
|
387
|
+
...(entity?.config ?? {}),
|
|
388
|
+
};
|
|
389
|
+
if (document.entityConfig) {
|
|
390
|
+
Object.assign(config, cloneDeep(document.entityConfig));
|
|
391
|
+
}
|
|
392
|
+
if (environment.apiExecutor) {
|
|
393
|
+
config.apiExecutor = environment.apiExecutor;
|
|
394
|
+
}
|
|
395
|
+
return { config };
|
|
396
|
+
};
|
|
397
|
+
const createMissingRuntimeStoreIssue = () => ({
|
|
398
|
+
code: 'missing-runtime-store',
|
|
399
|
+
message: 'Runtime 预览需要 Store 配置、Store 实例或 Entity 实例',
|
|
400
|
+
path: 'environment.store',
|
|
401
|
+
severity: 'error',
|
|
402
|
+
});
|
|
403
|
+
const runtimeEnvironmentIdentityMap = new WeakMap();
|
|
404
|
+
let runtimeEnvironmentIdentitySequence = 0;
|
|
405
|
+
const getRuntimeEnvironmentIdentity = (value) => {
|
|
406
|
+
if ((typeof value !== 'object' || value === null)
|
|
407
|
+
&& typeof value !== 'function') {
|
|
408
|
+
return null;
|
|
409
|
+
}
|
|
410
|
+
const objectValue = value;
|
|
411
|
+
const current = runtimeEnvironmentIdentityMap.get(objectValue);
|
|
412
|
+
if (current)
|
|
413
|
+
return current;
|
|
414
|
+
runtimeEnvironmentIdentitySequence += 1;
|
|
415
|
+
runtimeEnvironmentIdentityMap.set(objectValue, runtimeEnvironmentIdentitySequence);
|
|
416
|
+
return runtimeEnvironmentIdentitySequence;
|
|
417
|
+
};
|
|
418
|
+
const stringifyRuntimeResetConfig = (value, ancestors = new WeakSet()) => {
|
|
419
|
+
if (value === null)
|
|
420
|
+
return 'null';
|
|
421
|
+
if (value === undefined)
|
|
422
|
+
return 'undefined';
|
|
423
|
+
if (typeof value === 'string' || typeof value === 'boolean')
|
|
424
|
+
return JSON.stringify(value);
|
|
425
|
+
if (typeof value === 'number')
|
|
426
|
+
return Number.isFinite(value) ? String(value) : `number:${value}`;
|
|
427
|
+
if (typeof value === 'bigint' || typeof value === 'symbol')
|
|
428
|
+
return `${typeof value}:${String(value)}`;
|
|
429
|
+
if (typeof value === 'function')
|
|
430
|
+
return `identity:${getRuntimeEnvironmentIdentity(value)}`;
|
|
431
|
+
if (Array.isArray(value)) {
|
|
432
|
+
if (ancestors.has(value))
|
|
433
|
+
return `identity:${getRuntimeEnvironmentIdentity(value)}`;
|
|
434
|
+
ancestors.add(value);
|
|
435
|
+
const result = `[${value.map(item => stringifyRuntimeResetConfig(item, ancestors)).join(',')}]`;
|
|
436
|
+
ancestors.delete(value);
|
|
437
|
+
return result;
|
|
438
|
+
}
|
|
439
|
+
if (!isObjectRecord(value))
|
|
440
|
+
return `identity:${getRuntimeEnvironmentIdentity(value)}`;
|
|
441
|
+
const prototype = Object.getPrototypeOf(value);
|
|
442
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
443
|
+
return `identity:${getRuntimeEnvironmentIdentity(value)}`;
|
|
444
|
+
}
|
|
445
|
+
if (ancestors.has(value))
|
|
446
|
+
return `identity:${getRuntimeEnvironmentIdentity(value)}`;
|
|
447
|
+
ancestors.add(value);
|
|
448
|
+
const entries = Object.keys(value)
|
|
449
|
+
.sort()
|
|
450
|
+
.map(key => `${JSON.stringify(key)}:${stringifyRuntimeResetConfig(value[key], ancestors)}`)
|
|
451
|
+
.join(',');
|
|
452
|
+
const result = `{${entries}}`;
|
|
453
|
+
ancestors.delete(value);
|
|
454
|
+
return result;
|
|
455
|
+
};
|
|
456
|
+
const createRuntimeStoreConfigResetKey = (document, environment) => {
|
|
457
|
+
if (isRuntimeStoreInstance(environment.store)) {
|
|
458
|
+
return `instance:${getRuntimeEnvironmentIdentity(environment.store)}`;
|
|
459
|
+
}
|
|
460
|
+
const source = environment.store ?? document.store;
|
|
461
|
+
if (!source)
|
|
462
|
+
return null;
|
|
463
|
+
const effectiveStore = { ...source };
|
|
464
|
+
delete effectiveStore.apiExecutor;
|
|
465
|
+
return stringifyRuntimeResetConfig(effectiveStore);
|
|
466
|
+
};
|
|
467
|
+
const createRuntimeStoreResetKey = (document, environment) => JSON.stringify({
|
|
468
|
+
apiExecutor: getRuntimeEnvironmentIdentity(environment.apiExecutor),
|
|
469
|
+
entityConfig: document.entityConfig ?? null,
|
|
470
|
+
environmentEntity: getRuntimeEnvironmentIdentity(environment.entity),
|
|
471
|
+
store: createRuntimeStoreConfigResetKey(document, environment),
|
|
472
|
+
});
|
|
473
|
+
export const resolveRuntimeDynamicViewProps = (options) => {
|
|
474
|
+
const validation = validateRuntimeDocument(options.document);
|
|
475
|
+
if (!validation.valid || !validation.document) {
|
|
476
|
+
return {
|
|
477
|
+
diagnostics: [],
|
|
478
|
+
issues: validation.issues,
|
|
479
|
+
valid: false,
|
|
480
|
+
};
|
|
481
|
+
}
|
|
482
|
+
const { document: validatedDocument } = validation;
|
|
483
|
+
const document = normalizeRuntimeDocumentComponentAliases(validatedDocument);
|
|
484
|
+
const catalogBinding = resolveRuntimeStoreCatalogBinding(document, options.environment ?? {});
|
|
485
|
+
if (catalogBinding.issue) {
|
|
486
|
+
return {
|
|
487
|
+
diagnostics: [],
|
|
488
|
+
document,
|
|
489
|
+
issues: [catalogBinding.issue],
|
|
490
|
+
valid: false,
|
|
491
|
+
};
|
|
492
|
+
}
|
|
493
|
+
const { environment } = catalogBinding;
|
|
494
|
+
const scopeValidation = validateRuntimeEnvironmentScope(environment.scope);
|
|
495
|
+
if (!scopeValidation.valid) {
|
|
496
|
+
return {
|
|
497
|
+
diagnostics: [],
|
|
498
|
+
issues: scopeValidation.issues,
|
|
499
|
+
valid: false,
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
const components = {
|
|
503
|
+
...(options.runtimeComponents ?? {}),
|
|
504
|
+
...(environment.components ?? {}),
|
|
505
|
+
};
|
|
506
|
+
const scope = {
|
|
507
|
+
...(document.scope ?? {}),
|
|
508
|
+
...(scopeValidation.scope ?? {}),
|
|
509
|
+
components,
|
|
510
|
+
};
|
|
511
|
+
const storeIsInstance = isRuntimeStoreInstance(environment.store);
|
|
512
|
+
const store = resolveRuntimeStore(document, environment);
|
|
513
|
+
const diagnostics = collectRuntimeDiagnostics(document, components, environment);
|
|
514
|
+
if (storeIsInstance && environment.apiExecutor) {
|
|
515
|
+
pushRuntimeDiagnostic(diagnostics, 'runtime-executor-requires-config-store', 'environment.apiExecutor', 'Store 实例不会接收顶层 apiExecutor,请在构造 Store 时注入执行器');
|
|
516
|
+
}
|
|
517
|
+
if (!store && !environment.entity) {
|
|
518
|
+
return {
|
|
519
|
+
diagnostics,
|
|
520
|
+
document,
|
|
521
|
+
issues: [createMissingRuntimeStoreIssue()],
|
|
522
|
+
valid: false,
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
return {
|
|
526
|
+
apiExecutor: environment.apiExecutor,
|
|
527
|
+
diagnostics,
|
|
528
|
+
document,
|
|
529
|
+
issues: [],
|
|
530
|
+
props: {
|
|
531
|
+
components,
|
|
532
|
+
entity: environment.entity,
|
|
533
|
+
entityProps: resolveRuntimeEntityProps(document, environment, storeIsInstance),
|
|
534
|
+
resetKey: createRuntimeStoreResetKey(document, environment),
|
|
535
|
+
schema: document.schema,
|
|
536
|
+
schemaKey: environment.schemaKey ?? stringifyRuntimeResetConfig(document.schema),
|
|
537
|
+
scope,
|
|
538
|
+
store,
|
|
539
|
+
},
|
|
540
|
+
valid: true,
|
|
541
|
+
};
|
|
542
|
+
};
|
|
543
|
+
export const RuntimeDynamicViewPreview = ({ document, environment, onResolution, runtimeComponents, }) => {
|
|
544
|
+
const resolution = useMemo(() => resolveRuntimeDynamicViewProps({
|
|
545
|
+
document,
|
|
546
|
+
environment,
|
|
547
|
+
runtimeComponents,
|
|
548
|
+
}), [document, environment, runtimeComponents]);
|
|
549
|
+
useEffect(() => {
|
|
550
|
+
onResolution?.(resolution);
|
|
551
|
+
}, [onResolution, resolution]);
|
|
552
|
+
const hasMissingComponent = resolution.diagnostics.some(item => item.code === 'runtime-component-not-registered');
|
|
553
|
+
const { props } = resolution;
|
|
554
|
+
const boundaryExecutor = props?.store instanceof BaseStore
|
|
555
|
+
? props.store.apiExecutor
|
|
556
|
+
: resolution.apiExecutor;
|
|
557
|
+
return (_jsxs(_Fragment, { children: [_jsx(RuntimePreviewDiagnostics, { diagnostics: resolution.diagnostics, issues: resolution.issues }), resolution.valid && props && !hasMissingComponent ? (_jsx(RuntimeExecutorBoundary, { apiExecutor: boundaryExecutor, children: _jsx(DynamicView, { components: props.components, entity: props.entity, entityProps: props.entityProps, resetKey: props.resetKey, schema: props.schema, schemaKey: props.schemaKey, scope: props.scope, store: props.store }) })) : null] }));
|
|
558
|
+
};
|
|
559
|
+
export const RuntimeDynamicViewPreviewRenderer = ({ environment, onResolution, runtimeComponents, schema, }) => (_jsx(RuntimeDynamicViewPreview, { document: schema, environment: environment, runtimeComponents: runtimeComponents, onResolution: onResolution }));
|
|
560
|
+
const runtimeDynamicViewPreviewRendererOptions = new WeakMap();
|
|
561
|
+
export const isRuntimeDynamicViewPreviewRenderer = (value) => ((typeof value === 'function'
|
|
562
|
+
|| (typeof value === 'object' && value !== null))
|
|
563
|
+
&& runtimeDynamicViewPreviewRendererOptions.has(value));
|
|
564
|
+
export const getRuntimeDynamicViewPreviewRendererOptions = (value) => {
|
|
565
|
+
if (!isRuntimeDynamicViewPreviewRenderer(value))
|
|
566
|
+
return undefined;
|
|
567
|
+
return runtimeDynamicViewPreviewRendererOptions.get(value);
|
|
568
|
+
};
|
|
569
|
+
export const createRuntimeDynamicViewPreviewRenderer = (options) => {
|
|
570
|
+
const BoundRuntimeDynamicViewPreviewRenderer = (props) => (_jsx(RuntimeDynamicViewPreviewRenderer, { ...props, environment: options.environment, runtimeComponents: options.runtimeComponents, onResolution: options.onResolution }));
|
|
571
|
+
BoundRuntimeDynamicViewPreviewRenderer.displayName = 'RuntimeDynamicViewPreviewRenderer';
|
|
572
|
+
runtimeDynamicViewPreviewRendererOptions.set(BoundRuntimeDynamicViewPreviewRenderer, options);
|
|
573
|
+
return BoundRuntimeDynamicViewPreviewRenderer;
|
|
574
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface IRuntimeJsonEditorProps {
|
|
2
|
+
ariaLabel: string;
|
|
3
|
+
height?: number;
|
|
4
|
+
value: string;
|
|
5
|
+
onChange: (value: string) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function RuntimeJsonEditor({ ariaLabel, height, onChange, value, }: IRuntimeJsonEditorProps): import("react").JSX.Element;
|
|
8
|
+
export declare namespace RuntimeJsonEditor {
|
|
9
|
+
var displayName: string;
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import Editor from '@monaco-editor/react';
|
|
3
|
+
import { useConfigComponents } from '@yimoka/react';
|
|
4
|
+
import { Alert } from 'antd';
|
|
5
|
+
import { createElement } from 'react';
|
|
6
|
+
export function RuntimeJsonEditor({ ariaLabel, height = 260, onChange, value, }) {
|
|
7
|
+
const loading = useConfigComponents()?.Loading;
|
|
8
|
+
return (_jsx("div", { "aria-label": ariaLabel, role: "group", children: _jsx(Editor, { height: height, language: "json", loading: loading ? createElement(loading) : _jsx(Alert, { showIcon: true, title: "JSON \u7F16\u8F91\u5668\u52A0\u8F7D\u4E2D", type: "info" }), options: {
|
|
9
|
+
ariaLabel,
|
|
10
|
+
accessibilitySupport: 'on',
|
|
11
|
+
automaticLayout: true,
|
|
12
|
+
folding: true,
|
|
13
|
+
fontSize: 13,
|
|
14
|
+
formatOnPaste: true,
|
|
15
|
+
minimap: { enabled: false },
|
|
16
|
+
scrollBeyondLastLine: false,
|
|
17
|
+
tabSize: 2,
|
|
18
|
+
wordWrap: 'on',
|
|
19
|
+
}, value: value, onChange: nextValue => onChange(nextValue ?? '') }) }));
|
|
20
|
+
}
|
|
21
|
+
RuntimeJsonEditor.displayName = 'RuntimeJsonEditor';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { RuntimeDocumentV1, RuntimeEnvironment } from "../contracts.js";
|
|
3
|
+
export interface IRuntimeStoreEntitySettingsProps {
|
|
4
|
+
document: RuntimeDocumentV1;
|
|
5
|
+
entityJson: string;
|
|
6
|
+
environment?: RuntimeEnvironment;
|
|
7
|
+
setEntityJson: (value: string) => void;
|
|
8
|
+
setStoreJson: (value: string) => void;
|
|
9
|
+
storeJson: string;
|
|
10
|
+
onDocumentChange: (document: RuntimeDocumentV1) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare const RuntimeStoreEntitySettings: {
|
|
13
|
+
({ document, entityJson, environment, onDocumentChange, setEntityJson, setStoreJson, storeJson, }: IRuntimeStoreEntitySettingsProps): React.JSX.Element;
|
|
14
|
+
displayName: string;
|
|
15
|
+
};
|