@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,307 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Alert, Button, Drawer, Modal, Space, Tabs, Typography, } from 'antd';
|
|
3
|
+
import { useEffect, useMemo, useRef, useState, } from 'react';
|
|
4
|
+
import { RuntimeDocumentValidationError, validateRuntimeDocument, } from "./document.js";
|
|
5
|
+
import { RuntimeI18nSettingsPanel } from "./i18n.js";
|
|
6
|
+
import { RuntimeJsonEditor } from "./settings/RuntimeJsonEditor.js";
|
|
7
|
+
import { RuntimeStoreEntitySettings } from "./settings/RuntimeStoreEntitySettings.js";
|
|
8
|
+
import { applyRuntimeTemplate, findRuntimeTemplate, } from "./templates.js";
|
|
9
|
+
const formatOptionalRuntimeJson = (value) => (value === undefined ? '' : JSON.stringify(value, null, 2));
|
|
10
|
+
const serializeRuntimeDocumentSnapshot = (document) => (JSON.stringify(document));
|
|
11
|
+
const parseOptionalRuntimeObject = (value, label) => {
|
|
12
|
+
if (!value.trim())
|
|
13
|
+
return undefined;
|
|
14
|
+
const parsed = JSON.parse(value);
|
|
15
|
+
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
16
|
+
throw new Error(`${label} 必须是 JSON 对象`);
|
|
17
|
+
}
|
|
18
|
+
return parsed;
|
|
19
|
+
};
|
|
20
|
+
const validateRuntimeSettingsDraft = (value) => {
|
|
21
|
+
const validation = validateRuntimeDocument(value);
|
|
22
|
+
if (!validation.valid || !validation.document) {
|
|
23
|
+
throw new RuntimeDocumentValidationError(validation.issues);
|
|
24
|
+
}
|
|
25
|
+
return validation.document;
|
|
26
|
+
};
|
|
27
|
+
const mergeRuntimeStoreEntityDraft = (document, storeJson, entityJson) => {
|
|
28
|
+
const nextStore = parseOptionalRuntimeObject(storeJson, 'Store');
|
|
29
|
+
const nextEntity = parseOptionalRuntimeObject(entityJson, 'Entity');
|
|
30
|
+
const nextDocument = {
|
|
31
|
+
...document,
|
|
32
|
+
};
|
|
33
|
+
if (nextStore) {
|
|
34
|
+
nextDocument.store = nextStore;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
delete nextDocument.store;
|
|
38
|
+
}
|
|
39
|
+
if (nextEntity) {
|
|
40
|
+
nextDocument.entityConfig = nextEntity;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
delete nextDocument.entityConfig;
|
|
44
|
+
}
|
|
45
|
+
return nextDocument;
|
|
46
|
+
};
|
|
47
|
+
const resolveRuntimeSettingsDraft = ({ activeTab, document, entityJson, i18nDraftValid, runtimeJson, storeJson, }) => {
|
|
48
|
+
if (activeTab === 'json') {
|
|
49
|
+
return validateRuntimeSettingsDraft(JSON.parse(runtimeJson));
|
|
50
|
+
}
|
|
51
|
+
if (activeTab === 'store-entity') {
|
|
52
|
+
return validateRuntimeSettingsDraft(mergeRuntimeStoreEntityDraft(document, storeJson, entityJson));
|
|
53
|
+
}
|
|
54
|
+
if (!i18nDraftValid) {
|
|
55
|
+
throw new Error('多语言映射草稿无效,请修正后再应用');
|
|
56
|
+
}
|
|
57
|
+
return validateRuntimeSettingsDraft(document);
|
|
58
|
+
};
|
|
59
|
+
const getRuntimeActionErrorMessage = (error) => (error instanceof Error ? error.message : String(error));
|
|
60
|
+
const confirmRuntimeTemplateReplacement = template => (new Promise((resolve) => {
|
|
61
|
+
Modal.confirm({
|
|
62
|
+
content: `当前画布存在未保存修改,确认套用“${template.title}”并覆盖当前内容吗?`,
|
|
63
|
+
okText: '确认套用',
|
|
64
|
+
title: '套用模板',
|
|
65
|
+
onCancel: () => resolve(false),
|
|
66
|
+
onOk: () => resolve(true),
|
|
67
|
+
});
|
|
68
|
+
}));
|
|
69
|
+
export const RuntimeSettingsAction = ({ api, environment, onError, }) => {
|
|
70
|
+
const [activeTab, setActiveTab] = useState('store-entity');
|
|
71
|
+
const [draftDocument, setDraftDocument] = useState();
|
|
72
|
+
const [entityJson, setEntityJson] = useState('');
|
|
73
|
+
const [errorMessage, setErrorMessage] = useState('');
|
|
74
|
+
const [i18nDraftValid, setI18nDraftValid] = useState(true);
|
|
75
|
+
const [open, setOpen] = useState(false);
|
|
76
|
+
const [runtimeJson, setRuntimeJson] = useState('');
|
|
77
|
+
const [storeJson, setStoreJson] = useState('');
|
|
78
|
+
const openingContextRef = useRef(undefined);
|
|
79
|
+
const openingDocumentSnapshotRef = useRef('');
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
if (!open || !openingContextRef.current)
|
|
82
|
+
return;
|
|
83
|
+
if (openingContextRef.current.api === api
|
|
84
|
+
&& openingContextRef.current.engine === api?.engine)
|
|
85
|
+
return;
|
|
86
|
+
openingContextRef.current = undefined;
|
|
87
|
+
setOpen(false);
|
|
88
|
+
setErrorMessage('');
|
|
89
|
+
}, [api, api?.engine, open]);
|
|
90
|
+
const synchronizeDraftViews = (document) => {
|
|
91
|
+
setDraftDocument(document);
|
|
92
|
+
setStoreJson(formatOptionalRuntimeJson(document.store));
|
|
93
|
+
setEntityJson(formatOptionalRuntimeJson(document.entityConfig));
|
|
94
|
+
setRuntimeJson(JSON.stringify(document, null, 2));
|
|
95
|
+
};
|
|
96
|
+
const openSettings = () => {
|
|
97
|
+
if (!api)
|
|
98
|
+
return;
|
|
99
|
+
try {
|
|
100
|
+
const current = api.getSchema();
|
|
101
|
+
const validation = validateRuntimeDocument(current);
|
|
102
|
+
if (!validation.valid || !validation.document) {
|
|
103
|
+
throw new RuntimeDocumentValidationError(validation.issues);
|
|
104
|
+
}
|
|
105
|
+
openingDocumentSnapshotRef.current = serializeRuntimeDocumentSnapshot(validation.document);
|
|
106
|
+
openingContextRef.current = {
|
|
107
|
+
api,
|
|
108
|
+
engine: api.engine,
|
|
109
|
+
};
|
|
110
|
+
synchronizeDraftViews(validation.document);
|
|
111
|
+
setI18nDraftValid(true);
|
|
112
|
+
setErrorMessage('');
|
|
113
|
+
setOpen(true);
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
setErrorMessage(getRuntimeActionErrorMessage(error));
|
|
117
|
+
onError?.(error);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
const changeSettingsTab = (nextTab) => {
|
|
121
|
+
if (!draftDocument)
|
|
122
|
+
return;
|
|
123
|
+
try {
|
|
124
|
+
const nextDocument = resolveRuntimeSettingsDraft({
|
|
125
|
+
activeTab,
|
|
126
|
+
document: draftDocument,
|
|
127
|
+
entityJson,
|
|
128
|
+
i18nDraftValid,
|
|
129
|
+
runtimeJson,
|
|
130
|
+
storeJson,
|
|
131
|
+
});
|
|
132
|
+
synchronizeDraftViews(nextDocument);
|
|
133
|
+
setErrorMessage('');
|
|
134
|
+
setActiveTab(nextTab);
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
setErrorMessage(getRuntimeActionErrorMessage(error));
|
|
138
|
+
onError?.(error);
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
const applySettings = () => {
|
|
142
|
+
if (!api || !draftDocument)
|
|
143
|
+
return;
|
|
144
|
+
try {
|
|
145
|
+
if (openingContextRef.current?.api !== api
|
|
146
|
+
|| openingContextRef.current.engine !== api.engine) {
|
|
147
|
+
throw new Error('Runtime 上下文已切换,请重新打开配置后再应用');
|
|
148
|
+
}
|
|
149
|
+
const currentValidation = validateRuntimeDocument(api.getSchema());
|
|
150
|
+
if (!currentValidation.valid || !currentValidation.document) {
|
|
151
|
+
throw new RuntimeDocumentValidationError(currentValidation.issues);
|
|
152
|
+
}
|
|
153
|
+
if (serializeRuntimeDocumentSnapshot(currentValidation.document)
|
|
154
|
+
!== openingDocumentSnapshotRef.current) {
|
|
155
|
+
throw new Error('配置期间画布已更新,请关闭并重新打开 Runtime 配置后再应用');
|
|
156
|
+
}
|
|
157
|
+
const nextDocument = resolveRuntimeSettingsDraft({
|
|
158
|
+
activeTab,
|
|
159
|
+
document: draftDocument,
|
|
160
|
+
entityJson,
|
|
161
|
+
i18nDraftValid,
|
|
162
|
+
runtimeJson,
|
|
163
|
+
storeJson,
|
|
164
|
+
});
|
|
165
|
+
const applied = api.setSchema(nextDocument, {
|
|
166
|
+
snapshotType: `runtime-settings:${activeTab}`,
|
|
167
|
+
});
|
|
168
|
+
if (!applied) {
|
|
169
|
+
throw api.getLastError?.()?.error ?? new Error('Runtime 配置应用失败');
|
|
170
|
+
}
|
|
171
|
+
synchronizeDraftViews(nextDocument);
|
|
172
|
+
setErrorMessage('');
|
|
173
|
+
setOpen(false);
|
|
174
|
+
openingContextRef.current = undefined;
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
setErrorMessage(getRuntimeActionErrorMessage(error));
|
|
178
|
+
onError?.(error);
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
const tabItems = useMemo(() => [
|
|
182
|
+
{
|
|
183
|
+
children: draftDocument ? (_jsx(RuntimeStoreEntitySettings, { document: draftDocument, entityJson: entityJson, environment: environment, setEntityJson: setEntityJson, setStoreJson: setStoreJson, storeJson: storeJson, onDocumentChange: synchronizeDraftViews })) : null,
|
|
184
|
+
key: 'store-entity',
|
|
185
|
+
label: 'Store/Entity',
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
children: draftDocument ? (_jsx(RuntimeI18nSettingsPanel, { document: draftDocument, languageCatalog: environment?.languageCatalog, resetKey: "runtime-settings-i18n-draft", onDocumentChange: (nextDocument) => {
|
|
189
|
+
synchronizeDraftViews(nextDocument);
|
|
190
|
+
}, onDraftValidityChange: setI18nDraftValid })) : null,
|
|
191
|
+
key: 'i18n',
|
|
192
|
+
label: '多语言',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
children: (_jsx(RuntimeJsonEditor, { ariaLabel: "Runtime JSON", height: 620, value: runtimeJson, onChange: setRuntimeJson })),
|
|
196
|
+
key: 'json',
|
|
197
|
+
label: 'Runtime JSON',
|
|
198
|
+
},
|
|
199
|
+
], [
|
|
200
|
+
draftDocument,
|
|
201
|
+
entityJson,
|
|
202
|
+
environment,
|
|
203
|
+
runtimeJson,
|
|
204
|
+
storeJson,
|
|
205
|
+
]);
|
|
206
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { disabled: !api, onClick: openSettings, children: "Runtime \u914D\u7F6E" }), _jsx(Drawer, { destroyOnHidden: true, extra: (_jsx(Button, { type: "primary", onClick: applySettings, children: "\u5E94\u7528" })), open: open, size: 760, title: "Runtime \u914D\u7F6E", onClose: () => {
|
|
207
|
+
openingContextRef.current = undefined;
|
|
208
|
+
setOpen(false);
|
|
209
|
+
setErrorMessage('');
|
|
210
|
+
}, children: _jsxs(Space, { orientation: "vertical", size: "middle", style: { width: '100%' }, children: [errorMessage && (_jsx(Alert, { showIcon: true, title: errorMessage, type: "error" })), _jsx(Tabs, { destroyOnHidden: true, activeKey: activeTab, items: tabItems, onChange: key => changeSettingsTab(key) })] }) })] }));
|
|
211
|
+
};
|
|
212
|
+
export const RuntimeTemplateSelectorAction = ({ api, confirm = confirmRuntimeTemplateReplacement, onError, scenarioId, templateIds, templates: customTemplates, }) => {
|
|
213
|
+
const [errorMessage, setErrorMessage] = useState('');
|
|
214
|
+
const [open, setOpen] = useState(false);
|
|
215
|
+
const [pending, setPending] = useState(false);
|
|
216
|
+
const currentContextRef = useRef({ api, engine: api?.engine });
|
|
217
|
+
const mountedRef = useRef(false);
|
|
218
|
+
const contextGenerationRef = useRef(0);
|
|
219
|
+
useEffect(() => {
|
|
220
|
+
mountedRef.current = true;
|
|
221
|
+
contextGenerationRef.current += 1;
|
|
222
|
+
currentContextRef.current = { api, engine: api?.engine };
|
|
223
|
+
return () => {
|
|
224
|
+
mountedRef.current = false;
|
|
225
|
+
contextGenerationRef.current += 1;
|
|
226
|
+
currentContextRef.current = {};
|
|
227
|
+
};
|
|
228
|
+
}, [api, api?.engine]);
|
|
229
|
+
const templates = useMemo(() => templateIds
|
|
230
|
+
.map(templateId => findRuntimeTemplate(templateId, customTemplates))
|
|
231
|
+
.filter((template) => (template?.scenarioId === scenarioId)), [customTemplates, scenarioId, templateIds]);
|
|
232
|
+
const applyTemplate = async (template) => {
|
|
233
|
+
if (!api || pending)
|
|
234
|
+
return;
|
|
235
|
+
const applyingApi = api;
|
|
236
|
+
const applyingEngine = api.engine;
|
|
237
|
+
const applyingGeneration = contextGenerationRef.current;
|
|
238
|
+
setPending(true);
|
|
239
|
+
setErrorMessage('');
|
|
240
|
+
try {
|
|
241
|
+
const result = await applyRuntimeTemplate({
|
|
242
|
+
confirm,
|
|
243
|
+
currentDocument: applyingApi.getSchema(),
|
|
244
|
+
dirty: applyingApi.isDirty(),
|
|
245
|
+
getCurrentDocument: applyingApi.getSchema,
|
|
246
|
+
onError,
|
|
247
|
+
scenarioId,
|
|
248
|
+
templateId: template.id,
|
|
249
|
+
templates: customTemplates,
|
|
250
|
+
version: template.version,
|
|
251
|
+
});
|
|
252
|
+
if (!mountedRef.current)
|
|
253
|
+
return;
|
|
254
|
+
if (contextGenerationRef.current !== applyingGeneration) {
|
|
255
|
+
setErrorMessage('确认期间 Runtime 上下文已切换,请重新选择模板并确认');
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (!result.applied) {
|
|
259
|
+
if ('error' in result) {
|
|
260
|
+
setErrorMessage(result.error.message);
|
|
261
|
+
}
|
|
262
|
+
else if (result.reason === 'document-changed') {
|
|
263
|
+
setErrorMessage('确认期间画布已更新,请重新选择模板并确认');
|
|
264
|
+
}
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (currentContextRef.current.api !== applyingApi
|
|
268
|
+
|| currentContextRef.current.engine !== applyingEngine) {
|
|
269
|
+
setErrorMessage('确认期间 Runtime 上下文已切换,请重新选择模板并确认');
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const applied = applyingApi.setSchema(result.document, {
|
|
273
|
+
snapshotType: `template:${template.id}@${template.version}`,
|
|
274
|
+
});
|
|
275
|
+
if (!applied) {
|
|
276
|
+
const error = applyingApi.getLastError?.()?.error ?? new Error('模板应用失败');
|
|
277
|
+
setErrorMessage(getRuntimeActionErrorMessage(error));
|
|
278
|
+
onError?.(error);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
setOpen(false);
|
|
282
|
+
}
|
|
283
|
+
catch (error) {
|
|
284
|
+
if (mountedRef.current) {
|
|
285
|
+
setErrorMessage(getRuntimeActionErrorMessage(error));
|
|
286
|
+
onError?.(error);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
finally {
|
|
290
|
+
if (mountedRef.current)
|
|
291
|
+
setPending(false);
|
|
292
|
+
}
|
|
293
|
+
};
|
|
294
|
+
if (!templates.length) {
|
|
295
|
+
return (_jsxs(Space, { size: "small", children: [_jsx(Button, { disabled: true, children: "\u9009\u62E9\u6A21\u677F" }), _jsx(Typography.Text, { type: "secondary", children: "\u5F53\u524D\u573A\u666F\u6682\u65E0\u6A21\u677F" })] }));
|
|
296
|
+
}
|
|
297
|
+
return (_jsxs(_Fragment, { children: [_jsx(Button, { disabled: !api, onClick: () => setOpen(true), children: "\u9009\u62E9\u6A21\u677F" }), _jsx(Modal, { footer: null, open: open, title: "\u9009\u62E9\u6A21\u677F", onCancel: () => {
|
|
298
|
+
setOpen(false);
|
|
299
|
+
setErrorMessage('');
|
|
300
|
+
}, children: _jsxs(Space, { orientation: "vertical", size: "middle", style: { width: '100%' }, children: [errorMessage && (_jsx(Alert, { showIcon: true, title: errorMessage, type: "error" })), _jsx("div", { "aria-label": "\u53EF\u7528\u6A21\u677F", role: "listbox", children: templates.map(template => (_jsx(Button, { "aria-label": template.title, disabled: pending, role: "option", style: {
|
|
301
|
+
height: 'auto',
|
|
302
|
+
justifyContent: 'flex-start',
|
|
303
|
+
padding: 12,
|
|
304
|
+
textAlign: 'left',
|
|
305
|
+
width: '100%',
|
|
306
|
+
}, onClick: () => void applyTemplate(template), children: _jsxs(Space, { orientation: "vertical", size: 2, children: [_jsx(Typography.Text, { strong: true, children: template.title }), _jsx(Typography.Text, { type: "secondary", children: template.description })] }) }, `${template.id}@${template.version}`))) })] }) })] }));
|
|
307
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import type { IDataBindingCatalogItem } from '@yimoka/designable-antd/settings-form/components';
|
|
2
|
+
import type { DnComponentRegistryItem } from '@yimoka/designable-react';
|
|
3
|
+
import type { DynamicViewProps } from '@yimoka/react';
|
|
4
|
+
import type { Entity as StoreEntity, IStore, IStoreConfig, IStoreHTTPRequest } from '@yimoka/store';
|
|
5
|
+
import type { ComponentType, Key } from 'react';
|
|
6
|
+
import type { IFormilySchemaDocument } from "../transformers/index.js";
|
|
7
|
+
import type { IComponentCategory, IPlaygroundLayoutProps, IPreviewWidgetProps, ISchemaTransformer } from "../types.js";
|
|
8
|
+
export type RuntimeJsonPrimitive = string | number | boolean | null;
|
|
9
|
+
export type RuntimeJsonValue = RuntimeJsonPrimitive | RuntimeJsonValue[] | RuntimeJsonObject;
|
|
10
|
+
export interface RuntimeJsonObject {
|
|
11
|
+
[key: string]: RuntimeJsonValue;
|
|
12
|
+
}
|
|
13
|
+
export interface RuntimeAPIRequestConfigV1 {
|
|
14
|
+
url: string;
|
|
15
|
+
method?: string;
|
|
16
|
+
params?: RuntimeJsonObject;
|
|
17
|
+
data?: RuntimeJsonObject;
|
|
18
|
+
}
|
|
19
|
+
export interface RuntimeDictConfigV1 {
|
|
20
|
+
field: string;
|
|
21
|
+
data?: RuntimeJsonValue;
|
|
22
|
+
api?: RuntimeAPIRequestConfigV1;
|
|
23
|
+
toOptions?: boolean;
|
|
24
|
+
toMap?: boolean;
|
|
25
|
+
keys?: RuntimeJsonObject;
|
|
26
|
+
childrenKey?: string;
|
|
27
|
+
type?: 'self' | 'by';
|
|
28
|
+
byField?: string | string[];
|
|
29
|
+
paramKeys?: string | RuntimeJsonObject;
|
|
30
|
+
}
|
|
31
|
+
export interface RuntimeStoreConfigV1 {
|
|
32
|
+
type?: 'base' | 'list';
|
|
33
|
+
defaultValues?: RuntimeJsonObject;
|
|
34
|
+
fieldsConfig?: RuntimeJsonObject;
|
|
35
|
+
dictConfig?: RuntimeDictConfigV1[];
|
|
36
|
+
api?: RuntimeAPIRequestConfigV1;
|
|
37
|
+
options?: RuntimeJsonObject;
|
|
38
|
+
extInfo?: RuntimeJsonObject;
|
|
39
|
+
}
|
|
40
|
+
export interface RuntimeEntityConfigV1 {
|
|
41
|
+
name?: string;
|
|
42
|
+
idKey?: string;
|
|
43
|
+
idsKey?: string;
|
|
44
|
+
labelKey?: string;
|
|
45
|
+
basePath?: string;
|
|
46
|
+
path?: RuntimeJsonObject;
|
|
47
|
+
breadcrumb?: RuntimeJsonObject[];
|
|
48
|
+
fieldsConfig?: RuntimeJsonObject;
|
|
49
|
+
dictConfig?: RuntimeDictConfigV1[];
|
|
50
|
+
api?: Record<string, RuntimeAPIRequestConfigV1>;
|
|
51
|
+
map?: RuntimeJsonObject;
|
|
52
|
+
options?: RuntimeJsonObject;
|
|
53
|
+
defaultFormValues?: RuntimeJsonObject;
|
|
54
|
+
defaultQueryValues?: RuntimeJsonObject;
|
|
55
|
+
defaultDetailValues?: RuntimeJsonObject;
|
|
56
|
+
i18nFieldMap?: Record<string, string>;
|
|
57
|
+
i18nInSchema?: IFormilySchemaDocument;
|
|
58
|
+
i18nOutSchema?: IFormilySchemaDocument;
|
|
59
|
+
i18nLangAPI?: RuntimeAPIRequestConfigV1;
|
|
60
|
+
extensions?: RuntimeJsonObject;
|
|
61
|
+
}
|
|
62
|
+
export interface RuntimeTemplateReferenceV1 {
|
|
63
|
+
id: string;
|
|
64
|
+
version: number;
|
|
65
|
+
}
|
|
66
|
+
export interface RuntimeDocumentMetadataV1 {
|
|
67
|
+
scenarioId?: string;
|
|
68
|
+
template?: RuntimeTemplateReferenceV1;
|
|
69
|
+
extensions?: RuntimeJsonObject;
|
|
70
|
+
}
|
|
71
|
+
export interface RuntimeDocumentV1 {
|
|
72
|
+
kind: 'yimoka.designable.runtime-document';
|
|
73
|
+
version: 1;
|
|
74
|
+
schema: IFormilySchemaDocument;
|
|
75
|
+
store?: RuntimeStoreConfigV1;
|
|
76
|
+
entityConfig?: RuntimeEntityConfigV1;
|
|
77
|
+
scope?: RuntimeJsonObject;
|
|
78
|
+
metadata?: RuntimeDocumentMetadataV1;
|
|
79
|
+
}
|
|
80
|
+
export type RuntimeDataCatalogItem = IDataBindingCatalogItem;
|
|
81
|
+
export interface RuntimeLanguageCatalogItem {
|
|
82
|
+
id: string;
|
|
83
|
+
label: string;
|
|
84
|
+
langAPI: RuntimeAPIRequestConfigV1;
|
|
85
|
+
}
|
|
86
|
+
export interface RuntimeStoreCatalogItem {
|
|
87
|
+
id: string;
|
|
88
|
+
label: string;
|
|
89
|
+
description?: string;
|
|
90
|
+
store: IStore | IStoreConfig;
|
|
91
|
+
entity?: StoreEntity;
|
|
92
|
+
apiExecutor?: IStoreHTTPRequest;
|
|
93
|
+
}
|
|
94
|
+
export interface RuntimeEnvironment {
|
|
95
|
+
store?: IStore | IStoreConfig;
|
|
96
|
+
entity?: StoreEntity;
|
|
97
|
+
apiExecutor?: IStoreHTTPRequest;
|
|
98
|
+
components?: DynamicViewProps['components'];
|
|
99
|
+
scope?: RuntimeJsonObject;
|
|
100
|
+
schemaKey?: Key;
|
|
101
|
+
dataCatalog?: RuntimeDataCatalogItem[];
|
|
102
|
+
languageCatalog?: RuntimeLanguageCatalogItem[];
|
|
103
|
+
storeCatalog?: RuntimeStoreCatalogItem[];
|
|
104
|
+
}
|
|
105
|
+
export type ScenarioLayoutProps = Pick<IPlaygroundLayoutProps<RuntimeDocumentV1>, 'theme' | 'variables' | 'position' | 'defaultView' | 'availableViews' | 'resourcePanelProps' | 'schemaEditorReadonly' | 'leftPanelWidth' | 'rightPanelWidth' | 'showResourcePanel' | 'showOutlinePanel' | 'showHistoryPanel' | 'showSettingsPanel' | 'showDesignerTools' | 'showNodeActions' | 'showStorageActions' | 'showViewTools'>;
|
|
106
|
+
export interface IPlaygroundScenarioPreset<S = RuntimeDocumentV1> {
|
|
107
|
+
id: string;
|
|
108
|
+
title: string;
|
|
109
|
+
designerComponents: Record<string, DnComponentRegistryItem>;
|
|
110
|
+
runtimeComponents: NonNullable<DynamicViewProps['components']>;
|
|
111
|
+
categories: IComponentCategory[];
|
|
112
|
+
transformer: ISchemaTransformer<S>;
|
|
113
|
+
settingsPanel?: ComponentType;
|
|
114
|
+
PreviewRenderer?: ComponentType<IPreviewWidgetProps<S>>;
|
|
115
|
+
layoutProps?: ScenarioLayoutProps;
|
|
116
|
+
templateIds: string[];
|
|
117
|
+
exampleIds: string[];
|
|
118
|
+
}
|
|
119
|
+
export interface TemplatePreviewV1 {
|
|
120
|
+
src: string;
|
|
121
|
+
alt?: string;
|
|
122
|
+
}
|
|
123
|
+
export interface TemplateDescriptorV1 {
|
|
124
|
+
id: string;
|
|
125
|
+
version: number;
|
|
126
|
+
title: string;
|
|
127
|
+
category: string;
|
|
128
|
+
scenarioId: string;
|
|
129
|
+
document: RuntimeDocumentV1;
|
|
130
|
+
description?: string;
|
|
131
|
+
preview?: TemplatePreviewV1;
|
|
132
|
+
}
|
|
133
|
+
export interface ExampleSourceV1 {
|
|
134
|
+
url: string;
|
|
135
|
+
revision: string;
|
|
136
|
+
adaptation: string;
|
|
137
|
+
license?: string;
|
|
138
|
+
}
|
|
139
|
+
export interface ExampleDescriptorV1 {
|
|
140
|
+
id: string;
|
|
141
|
+
title: string;
|
|
142
|
+
description: string;
|
|
143
|
+
scenarioId: string;
|
|
144
|
+
document: RuntimeDocumentV1;
|
|
145
|
+
templateId?: string;
|
|
146
|
+
source?: ExampleSourceV1;
|
|
147
|
+
}
|
|
148
|
+
export type RuntimeBlockingErrorCode = 'unsupported-runtime-document-version' | 'invalid-runtime-document' | 'invalid-runtime-schema-root' | 'runtime-non-json-value' | 'runtime-unsafe-key' | 'runtime-unsafe-request-config' | 'invalid-playground-scenario-preset' | 'missing-runtime-store' | 'invalid-runtime-store-catalog' | 'unknown-runtime-store-reference' | 'runtime-scenario-mismatch' | 'conflicting-data-binding' | 'conflicting-manual-data-binding' | 'invalid-data-key' | 'invalid-i18n-field-map' | 'template-not-found' | 'template-version-unsupported' | 'template-metadata-mismatch' | 'template-scenario-mismatch';
|
|
149
|
+
export type RuntimeDiagnosticCode = 'unknown-data-key' | 'custom-i18n-language-source' | 'missing-i18n-language-source' | 'unsupported-i18n-schema-ref' | 'runtime-executor-requires-config-store' | 'runtime-component-not-registered';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { IRuntimeDocumentValidationIssue } from "./document-core.js";
|
|
2
|
+
export declare const validateRuntimeI18nFieldMap: (value: unknown, issues: IRuntimeDocumentValidationIssue[], path: string) => void;
|
|
3
|
+
export declare const validateRuntimeDataBindingNode: (value: Record<string, unknown>, issues: IRuntimeDocumentValidationIssue[], path: string, componentName: string | undefined) => void;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { UNSAFE_SCHEMA_OBJECT_KEYS } from "../shared/schema.js";
|
|
2
|
+
import { DATA_BINDING_MANUAL_KEYS, isObjectRecord, pushRuntimeIssue, RUNTIME_OPTION_SCHEMA_KEYS, } from "./document-core.js";
|
|
3
|
+
import { isAllowedRuntimeDataKeyPath } from "./document-expressions.js";
|
|
4
|
+
export const validateRuntimeI18nFieldMap = (value, issues, path) => {
|
|
5
|
+
if (!isObjectRecord(value)) {
|
|
6
|
+
pushRuntimeIssue(issues, 'invalid-i18n-field-map', path, 'i18nFieldMap 必须是对象');
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const targetFields = new Set();
|
|
10
|
+
Object.entries(value).forEach(([sourceField, targetField]) => {
|
|
11
|
+
if (!sourceField.trim()
|
|
12
|
+
|| sourceField.trim() !== sourceField
|
|
13
|
+
|| UNSAFE_SCHEMA_OBJECT_KEYS.has(sourceField)
|
|
14
|
+
|| typeof targetField !== 'string'
|
|
15
|
+
|| !targetField.trim()
|
|
16
|
+
|| targetField.trim() !== targetField
|
|
17
|
+
|| UNSAFE_SCHEMA_OBJECT_KEYS.has(targetField)
|
|
18
|
+
|| targetFields.has(targetField)) {
|
|
19
|
+
pushRuntimeIssue(issues, 'invalid-i18n-field-map', `${path}.${sourceField}`, '多语言值字段和单语言字段必须是安全、非空且一对一的字符串');
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
targetFields.add(targetField);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
const isNonEmptyDataBindingValue = (value) => {
|
|
26
|
+
if (value === undefined || value === null)
|
|
27
|
+
return false;
|
|
28
|
+
if (typeof value === 'string')
|
|
29
|
+
return Boolean(value.trim());
|
|
30
|
+
if (Array.isArray(value))
|
|
31
|
+
return value.length > 0;
|
|
32
|
+
if (isObjectRecord(value))
|
|
33
|
+
return Object.keys(value).length > 0;
|
|
34
|
+
return true;
|
|
35
|
+
};
|
|
36
|
+
const isDefinedManualDataBindingValue = (value) => value !== undefined;
|
|
37
|
+
const getRuntimeTransferOptionKey = (item, optionKey) => {
|
|
38
|
+
if (!isObjectRecord(item))
|
|
39
|
+
return item;
|
|
40
|
+
const candidateKeys = optionKey === 'oneOf'
|
|
41
|
+
? ['const', 'value']
|
|
42
|
+
: ['value', 'const', 'key'];
|
|
43
|
+
const candidate = candidateKeys.find(key => Object.prototype.hasOwnProperty.call(item, key));
|
|
44
|
+
return candidate === undefined ? undefined : item[candidate];
|
|
45
|
+
};
|
|
46
|
+
const validateRuntimeTransferOptionKeys = (value, issues, path) => {
|
|
47
|
+
RUNTIME_OPTION_SCHEMA_KEYS.forEach((optionKey) => {
|
|
48
|
+
const source = value[optionKey];
|
|
49
|
+
if (!Array.isArray(source))
|
|
50
|
+
return;
|
|
51
|
+
source.forEach((item, index) => {
|
|
52
|
+
const key = getRuntimeTransferOptionKey(item, optionKey);
|
|
53
|
+
if (key === undefined || typeof key === 'string' || typeof key === 'number')
|
|
54
|
+
return;
|
|
55
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.${optionKey}[${index}]`, 'Transfer 枚举值必须是字符串或数字');
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
export const validateRuntimeDataBindingNode = (value, issues, path, componentName) => {
|
|
60
|
+
if (!componentName)
|
|
61
|
+
return;
|
|
62
|
+
const manualKeys = DATA_BINDING_MANUAL_KEYS[componentName];
|
|
63
|
+
if (!manualKeys)
|
|
64
|
+
return;
|
|
65
|
+
if (componentName === 'Transfer') {
|
|
66
|
+
validateRuntimeTransferOptionKeys(value, issues, path);
|
|
67
|
+
}
|
|
68
|
+
const componentProps = value['x-component-props'];
|
|
69
|
+
if (componentProps === undefined)
|
|
70
|
+
return;
|
|
71
|
+
if (!isObjectRecord(componentProps)) {
|
|
72
|
+
pushRuntimeIssue(issues, 'invalid-runtime-document', `${path}.x-component-props`, 'x-component-props 必须是对象');
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const activeManualKeys = manualKeys.filter(key => (isDefinedManualDataBindingValue(componentProps[key])));
|
|
76
|
+
const activeSchemaOptionKeys = RUNTIME_OPTION_SCHEMA_KEYS.filter(key => (isDefinedManualDataBindingValue(value[key])));
|
|
77
|
+
const { dataKey } = componentProps;
|
|
78
|
+
if (dataKey !== undefined
|
|
79
|
+
&& dataKey !== null
|
|
80
|
+
&& typeof dataKey !== 'string') {
|
|
81
|
+
pushRuntimeIssue(issues, 'invalid-data-key', `${path}.x-component-props.dataKey`, `${componentName} 的 dataKey 必须是字符串`);
|
|
82
|
+
}
|
|
83
|
+
if (typeof dataKey === 'string'
|
|
84
|
+
&& dataKey.length > 0
|
|
85
|
+
&& dataKey.trim() !== dataKey) {
|
|
86
|
+
pushRuntimeIssue(issues, 'invalid-data-key', `${path}.x-component-props.dataKey`, `${componentName} 的 dataKey 不能包含首尾空白`);
|
|
87
|
+
}
|
|
88
|
+
if (typeof dataKey === 'string') {
|
|
89
|
+
if (dataKey.trim() === dataKey && !isAllowedRuntimeDataKeyPath(dataKey)) {
|
|
90
|
+
pushRuntimeIssue(issues, 'invalid-data-key', `${path}.x-component-props.dataKey`, `${componentName} 的 dataKey 只能读取 Store 数据命名空间且不能包含原型链路径段`);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (isNonEmptyDataBindingValue(dataKey)
|
|
94
|
+
&& (activeManualKeys.length > 0 || activeSchemaOptionKeys.length > 0)) {
|
|
95
|
+
const conflicts = [...activeManualKeys, ...activeSchemaOptionKeys];
|
|
96
|
+
pushRuntimeIssue(issues, 'conflicting-data-binding', `${path}.x-component-props`, `${componentName} 的 dataKey 不能与 ${conflicts.join('/')} 同时存在`);
|
|
97
|
+
}
|
|
98
|
+
if (activeManualKeys.length > 1) {
|
|
99
|
+
pushRuntimeIssue(issues, 'conflicting-manual-data-binding', `${path}.x-component-props`, `${componentName} 只能保留一个手填数据字段`);
|
|
100
|
+
}
|
|
101
|
+
};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { RuntimeBlockingErrorCode, RuntimeDocumentV1, RuntimeJsonObject, RuntimeJsonValue } from "./contracts.js";
|
|
2
|
+
export declare const RUNTIME_DOCUMENT_KIND = "yimoka.designable.runtime-document";
|
|
3
|
+
export declare const RUNTIME_DOCUMENT_VERSION = 1;
|
|
4
|
+
export declare const RUNTIME_SCHEMA_FIDELITY_PROP = "$runtimeSchemaFidelityV1";
|
|
5
|
+
export declare const RUNTIME_DOCUMENT_KEYS: Set<string>;
|
|
6
|
+
export declare const RUNTIME_DOCUMENT_SIDECAR_KEYS: Set<string>;
|
|
7
|
+
export declare const RUNTIME_SCOPE_RESERVED_KEYS: Set<string>;
|
|
8
|
+
export declare const RUNTIME_STORE_KEYS: Set<string>;
|
|
9
|
+
export declare const RUNTIME_DICT_KEYS: Set<string>;
|
|
10
|
+
export declare const RUNTIME_ENTITY_KEYS: Set<string>;
|
|
11
|
+
export declare const RUNTIME_REQUEST_KEYS: Set<string>;
|
|
12
|
+
export declare const RUNTIME_METADATA_KEYS: Set<string>;
|
|
13
|
+
export declare const RUNTIME_TEMPLATE_REFERENCE_KEYS: Set<string>;
|
|
14
|
+
export declare const DATA_BINDING_MANUAL_KEYS: Record<string, readonly string[]>;
|
|
15
|
+
export declare const RUNTIME_OPTION_SCHEMA_KEYS: readonly ["enum", "oneOf", "x-enum"];
|
|
16
|
+
export declare const RUNTIME_UPLOAD_NETWORK_KEYS: Set<string>;
|
|
17
|
+
export declare const RUNTIME_SEARCH_REQUEST_PROP_KEYS: Record<string, readonly string[]>;
|
|
18
|
+
export declare const RUNTIME_NAVIGATION_PROP_KEYS: Record<string, readonly string[]>;
|
|
19
|
+
export interface IRuntimeSchemaFidelityV1 {
|
|
20
|
+
omitDesignableIdFor: string[];
|
|
21
|
+
omitIndexFor: string[];
|
|
22
|
+
}
|
|
23
|
+
export type RuntimeDocumentSidecarV1 = Omit<RuntimeDocumentV1, 'schema'> & {
|
|
24
|
+
[RUNTIME_SCHEMA_FIDELITY_PROP]?: IRuntimeSchemaFidelityV1;
|
|
25
|
+
};
|
|
26
|
+
export interface IRuntimeDocumentValidationIssue {
|
|
27
|
+
code: RuntimeBlockingErrorCode;
|
|
28
|
+
message: string;
|
|
29
|
+
path: string;
|
|
30
|
+
severity: 'error';
|
|
31
|
+
}
|
|
32
|
+
export interface IRuntimeDocumentValidationResult {
|
|
33
|
+
document?: RuntimeDocumentV1;
|
|
34
|
+
issues: IRuntimeDocumentValidationIssue[];
|
|
35
|
+
valid: boolean;
|
|
36
|
+
}
|
|
37
|
+
export interface IRuntimeEnvironmentScopeValidationResult {
|
|
38
|
+
issues: IRuntimeDocumentValidationIssue[];
|
|
39
|
+
scope?: RuntimeJsonObject;
|
|
40
|
+
valid: boolean;
|
|
41
|
+
}
|
|
42
|
+
export declare class RuntimeDocumentValidationError extends Error {
|
|
43
|
+
readonly code: RuntimeBlockingErrorCode;
|
|
44
|
+
readonly issues: IRuntimeDocumentValidationIssue[];
|
|
45
|
+
constructor(issues: IRuntimeDocumentValidationIssue[]);
|
|
46
|
+
}
|
|
47
|
+
export declare const isObjectRecord: (value: unknown) => value is Record<string, unknown>;
|
|
48
|
+
export declare const pushRuntimeIssue: (issues: IRuntimeDocumentValidationIssue[], code: RuntimeBlockingErrorCode, path: string, message: string) => void;
|
|
49
|
+
export declare const cloneRuntimeJsonValue: (value: unknown, path: string, issues: IRuntimeDocumentValidationIssue[], ancestors: Set<object>) => RuntimeJsonValue | undefined;
|
|
50
|
+
export declare const validateAllowedKeys: (value: Record<string, unknown>, allowedKeys: Set<string>, issues: IRuntimeDocumentValidationIssue[], path: string, code: RuntimeBlockingErrorCode) => void;
|
|
51
|
+
export declare const RUNTIME_EXPRESSION_PATTERN: RegExp;
|
|
52
|
+
export declare const validateRuntimeRequestExpressionFreeValue: (value: unknown, issues: IRuntimeDocumentValidationIssue[], path: string) => void;
|
|
53
|
+
export declare const validateRuntimeRequestConfig: (value: unknown, issues: IRuntimeDocumentValidationIssue[], path: string) => void;
|
|
54
|
+
export declare const validateRuntimeDictMode: (value: Record<string, unknown>, issues: IRuntimeDocumentValidationIssue[], path: string) => void;
|
|
55
|
+
export declare const validateRuntimeDictOptions: (value: Record<string, unknown>, issues: IRuntimeDocumentValidationIssue[], path: string) => void;
|
|
56
|
+
export declare const validateRuntimeDictConfig: (value: unknown, issues: IRuntimeDocumentValidationIssue[], path: string) => void;
|
|
57
|
+
export declare const validateRuntimeStoreConfig: (value: unknown, issues: IRuntimeDocumentValidationIssue[], path: string) => void;
|