@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,243 @@
|
|
|
1
|
+
import { createElement as _createElement } from "react";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { SettingsForm } from '@yimoka/designable-antd';
|
|
4
|
+
import { Space } from 'antd';
|
|
5
|
+
import React, { useCallback, useContext, useMemo, useState, } from 'react';
|
|
6
|
+
import { AntdPlayground, } from "../antd/index.js";
|
|
7
|
+
import { createFormPlaygroundPreset, getBuiltInScenarioEngineKey, } from "../presets/scenarios.js";
|
|
8
|
+
import { RuntimeSettingsAction, RuntimeTemplateSelectorAction, } from "./actions.js";
|
|
9
|
+
import { assertRuntimeDocument, isAllowedRuntimeDataKeyPath, } from "./document.js";
|
|
10
|
+
import { getRuntimeDynamicViewPreviewRendererOptions, isRuntimeDynamicViewPreviewRenderer, RuntimeDynamicViewPreviewRenderer, } from "./preview.js";
|
|
11
|
+
import { runtimeTemplates } from "./templates.js";
|
|
12
|
+
const BUILT_IN_TEMPLATE_SCENARIOS = Object.fromEntries(runtimeTemplates.map(template => [template.id, template.scenarioId]));
|
|
13
|
+
const BUILT_IN_TEMPLATE_IDS = new Set(runtimeTemplates.map(template => template.id));
|
|
14
|
+
const RUNTIME_SCENARIO_RESOURCE_IDENTITIES = new WeakMap();
|
|
15
|
+
const BUILT_IN_RUNTIME_PREVIEW_RENDERERS = new Map();
|
|
16
|
+
let nextRuntimeScenarioResourceIdentity = 0;
|
|
17
|
+
const getRuntimeScenarioResourceIdentity = (resource) => {
|
|
18
|
+
const existingIdentity = RUNTIME_SCENARIO_RESOURCE_IDENTITIES.get(resource);
|
|
19
|
+
if (existingIdentity !== undefined)
|
|
20
|
+
return existingIdentity;
|
|
21
|
+
nextRuntimeScenarioResourceIdentity += 1;
|
|
22
|
+
RUNTIME_SCENARIO_RESOURCE_IDENTITIES.set(resource, nextRuntimeScenarioResourceIdentity);
|
|
23
|
+
return nextRuntimeScenarioResourceIdentity;
|
|
24
|
+
};
|
|
25
|
+
const createRuntimeScenarioEngineKey = (preset) => getBuiltInScenarioEngineKey(preset) ?? [
|
|
26
|
+
preset.id,
|
|
27
|
+
getRuntimeScenarioResourceIdentity(preset.transformer),
|
|
28
|
+
getRuntimeScenarioResourceIdentity(preset.designerComponents),
|
|
29
|
+
getRuntimeScenarioResourceIdentity(preset.runtimeComponents),
|
|
30
|
+
getRuntimeScenarioResourceIdentity(preset.categories),
|
|
31
|
+
].join(':');
|
|
32
|
+
const createCustomTemplateScenarioIndex = (templates) => {
|
|
33
|
+
const index = {};
|
|
34
|
+
(templates ?? []).forEach((template) => {
|
|
35
|
+
if (BUILT_IN_TEMPLATE_IDS.has(template.id)
|
|
36
|
+
|| Object.prototype.hasOwnProperty.call(index, template.id)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
index[template.id] = template.scenarioId;
|
|
40
|
+
});
|
|
41
|
+
return index;
|
|
42
|
+
};
|
|
43
|
+
const createEmptyRuntimeDocument = (scenarioId) => ({
|
|
44
|
+
kind: 'yimoka.designable.runtime-document',
|
|
45
|
+
metadata: {
|
|
46
|
+
scenarioId,
|
|
47
|
+
},
|
|
48
|
+
schema: {
|
|
49
|
+
properties: {},
|
|
50
|
+
type: 'object',
|
|
51
|
+
},
|
|
52
|
+
store: {
|
|
53
|
+
defaultValues: {},
|
|
54
|
+
},
|
|
55
|
+
version: 1,
|
|
56
|
+
});
|
|
57
|
+
export const createRuntimePlaygroundApi = (api, onError) => {
|
|
58
|
+
let runtimeImportError = null;
|
|
59
|
+
const reportRuntimeImportError = (error) => {
|
|
60
|
+
runtimeImportError = {
|
|
61
|
+
error,
|
|
62
|
+
type: 'import:schema',
|
|
63
|
+
};
|
|
64
|
+
try {
|
|
65
|
+
onError?.(error, {
|
|
66
|
+
engine: api.engine,
|
|
67
|
+
type: 'import:schema',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
catch (notifyError) {
|
|
71
|
+
runtimeImportError = {
|
|
72
|
+
error: notifyError,
|
|
73
|
+
type: 'notify:error',
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const runAndClearRuntimeError = (operation) => {
|
|
78
|
+
const succeeded = operation();
|
|
79
|
+
if (succeeded)
|
|
80
|
+
runtimeImportError = null;
|
|
81
|
+
return succeeded;
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
...api,
|
|
85
|
+
clearDesign: () => runAndClearRuntimeError(api.clearDesign),
|
|
86
|
+
get dirty() {
|
|
87
|
+
return api.isDirty();
|
|
88
|
+
},
|
|
89
|
+
getLastError: () => runtimeImportError ?? api.getLastError?.() ?? null,
|
|
90
|
+
getSchema: () => assertRuntimeDocument(api.getSchema()),
|
|
91
|
+
get lastChangeType() {
|
|
92
|
+
return api.getLastChangeType();
|
|
93
|
+
},
|
|
94
|
+
get storageEnabled() {
|
|
95
|
+
return api.storageEnabled;
|
|
96
|
+
},
|
|
97
|
+
importDesign: (schema) => {
|
|
98
|
+
try {
|
|
99
|
+
const parsed = typeof schema === 'string'
|
|
100
|
+
? JSON.parse(schema)
|
|
101
|
+
: schema;
|
|
102
|
+
const imported = api.importDesign(assertRuntimeDocument(parsed));
|
|
103
|
+
if (imported)
|
|
104
|
+
runtimeImportError = null;
|
|
105
|
+
return imported;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
reportRuntimeImportError(error);
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
loadDesign: () => runAndClearRuntimeError(api.loadDesign),
|
|
113
|
+
markSaved: () => runAndClearRuntimeError(api.markSaved),
|
|
114
|
+
saveDesign: () => runAndClearRuntimeError(api.saveDesign),
|
|
115
|
+
setSchema: (schema, options) => {
|
|
116
|
+
const applied = api.setSchema(assertRuntimeDocument(schema), options);
|
|
117
|
+
if (applied)
|
|
118
|
+
runtimeImportError = null;
|
|
119
|
+
return applied;
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
const RuntimeEnvironmentContext = React.createContext(undefined);
|
|
124
|
+
export const normalizeRuntimeDataCatalog = (dataCatalog) => dataCatalog?.map(item => (isAllowedRuntimeDataKeyPath(item.dataKey.trim())
|
|
125
|
+
? item
|
|
126
|
+
: { ...item, dataKey: '' }));
|
|
127
|
+
const RuntimeSettingsPanel = () => {
|
|
128
|
+
const environment = useContext(RuntimeEnvironmentContext);
|
|
129
|
+
return _jsx(SettingsForm, { dataCatalog: environment?.dataCatalog });
|
|
130
|
+
};
|
|
131
|
+
const mergeRuntimePreviewEnvironment = (bound, current) => {
|
|
132
|
+
if (!bound)
|
|
133
|
+
return current;
|
|
134
|
+
if (!current)
|
|
135
|
+
return bound;
|
|
136
|
+
return {
|
|
137
|
+
...bound,
|
|
138
|
+
...current,
|
|
139
|
+
components: bound.components || current.components
|
|
140
|
+
? { ...(bound.components ?? {}), ...(current.components ?? {}) }
|
|
141
|
+
: undefined,
|
|
142
|
+
scope: bound.scope || current.scope
|
|
143
|
+
? { ...(bound.scope ?? {}), ...(current.scope ?? {}) }
|
|
144
|
+
: undefined,
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
const createRuntimeContextPreviewRenderer = (options) => {
|
|
148
|
+
const RuntimeContextPreviewRenderer = (props) => {
|
|
149
|
+
const currentEnvironment = useContext(RuntimeEnvironmentContext);
|
|
150
|
+
const environment = useMemo(() => mergeRuntimePreviewEnvironment(options.environment, currentEnvironment), [currentEnvironment]);
|
|
151
|
+
return (_jsx(RuntimeDynamicViewPreviewRenderer, { ...props, environment: environment, runtimeComponents: options.runtimeComponents, onResolution: options.onResolution }));
|
|
152
|
+
};
|
|
153
|
+
RuntimeContextPreviewRenderer.displayName = 'RuntimeContextPreviewRenderer';
|
|
154
|
+
return RuntimeContextPreviewRenderer;
|
|
155
|
+
};
|
|
156
|
+
const createRuntimeScenarioPreset = (preset) => {
|
|
157
|
+
const boundOptions = getRuntimeDynamicViewPreviewRendererOptions(preset.PreviewRenderer);
|
|
158
|
+
const builtInEngineKey = getBuiltInScenarioEngineKey(preset);
|
|
159
|
+
let previewRenderer = builtInEngineKey
|
|
160
|
+
? BUILT_IN_RUNTIME_PREVIEW_RENDERERS.get(builtInEngineKey)
|
|
161
|
+
: undefined;
|
|
162
|
+
if (!previewRenderer) {
|
|
163
|
+
previewRenderer = createRuntimeContextPreviewRenderer({
|
|
164
|
+
environment: boundOptions?.environment,
|
|
165
|
+
onResolution: boundOptions?.onResolution,
|
|
166
|
+
runtimeComponents: {
|
|
167
|
+
...preset.runtimeComponents,
|
|
168
|
+
...(boundOptions?.runtimeComponents ?? {}),
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
if (builtInEngineKey) {
|
|
172
|
+
BUILT_IN_RUNTIME_PREVIEW_RENDERERS.set(builtInEngineKey, previewRenderer);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
...preset,
|
|
177
|
+
PreviewRenderer: preset.PreviewRenderer
|
|
178
|
+
&& !isRuntimeDynamicViewPreviewRenderer(preset.PreviewRenderer)
|
|
179
|
+
? preset.PreviewRenderer
|
|
180
|
+
: previewRenderer,
|
|
181
|
+
settingsPanel: preset.settingsPanel && preset.settingsPanel !== SettingsForm
|
|
182
|
+
? preset.settingsPanel
|
|
183
|
+
: RuntimeSettingsPanel,
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
export const AntdRuntimePlayground = ({ actions, environment, initialSchema, onError, onReady, onSchemaChange, scenarioPreset, scenarioValidationResources, schema, templates, ...props }) => {
|
|
187
|
+
const [api, setApi] = useState(null);
|
|
188
|
+
const baseScenario = useMemo(() => scenarioPreset ?? createFormPlaygroundPreset(), [scenarioPreset]);
|
|
189
|
+
const resolvedScenario = useMemo(() => createRuntimeScenarioPreset(baseScenario), [baseScenario]);
|
|
190
|
+
const scenarioEngineKey = createRuntimeScenarioEngineKey(baseScenario);
|
|
191
|
+
const resolvedScenarioValidationResources = useMemo(() => {
|
|
192
|
+
if (!templates?.length && !scenarioValidationResources)
|
|
193
|
+
return undefined;
|
|
194
|
+
return {
|
|
195
|
+
...scenarioValidationResources,
|
|
196
|
+
templates: {
|
|
197
|
+
...(scenarioValidationResources?.templates ?? {}),
|
|
198
|
+
...createCustomTemplateScenarioIndex(templates),
|
|
199
|
+
...BUILT_IN_TEMPLATE_SCENARIOS,
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}, [scenarioValidationResources, templates]);
|
|
203
|
+
const resolvedEnvironment = useMemo(() => {
|
|
204
|
+
if (!environment?.dataCatalog)
|
|
205
|
+
return environment;
|
|
206
|
+
return {
|
|
207
|
+
...environment,
|
|
208
|
+
dataCatalog: normalizeRuntimeDataCatalog(environment.dataCatalog),
|
|
209
|
+
};
|
|
210
|
+
}, [environment]);
|
|
211
|
+
const resolvedInitialSchema = useMemo(() => {
|
|
212
|
+
if (initialSchema !== undefined)
|
|
213
|
+
return initialSchema;
|
|
214
|
+
if (schema === undefined)
|
|
215
|
+
return createEmptyRuntimeDocument(baseScenario.id);
|
|
216
|
+
return undefined;
|
|
217
|
+
}, [baseScenario.id, initialSchema, schema]);
|
|
218
|
+
const handleActionError = (error) => {
|
|
219
|
+
if (!api)
|
|
220
|
+
return;
|
|
221
|
+
onError?.(error, {
|
|
222
|
+
engine: api.engine,
|
|
223
|
+
type: 'runtime:action',
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
const handlePlaygroundReady = useCallback((nextApi) => {
|
|
227
|
+
const runtimeApi = createRuntimePlaygroundApi(nextApi, onError);
|
|
228
|
+
setApi(runtimeApi);
|
|
229
|
+
const cleanup = onReady?.(runtimeApi);
|
|
230
|
+
return () => {
|
|
231
|
+
setApi((current) => {
|
|
232
|
+
if (current === runtimeApi)
|
|
233
|
+
return null;
|
|
234
|
+
return current;
|
|
235
|
+
});
|
|
236
|
+
cleanup?.();
|
|
237
|
+
};
|
|
238
|
+
}, [onError, onReady]);
|
|
239
|
+
return (_jsx(RuntimeEnvironmentContext.Provider, { value: resolvedEnvironment, children: _createElement(AntdPlayground, { ...props, key: scenarioEngineKey, actions: (_jsxs(Space, { wrap: true, size: "small", children: [_jsx(RuntimeSettingsAction, { api: api, environment: resolvedEnvironment, onError: handleActionError }), _jsx(RuntimeTemplateSelectorAction, { api: api, scenarioId: resolvedScenario.id, templateIds: resolvedScenario.templateIds, templates: templates, onError: handleActionError }), actions] })), initialSchema: resolvedInitialSchema, scenarioPreset: resolvedScenario, scenarioValidationResources: resolvedScenarioValidationResources, schema: schema, storageKey: props.storageKey ?? false, validateSchemaEditorSchema: assertRuntimeDocument, onError: onError, onReady: handlePlaygroundReady, onSchemaChange: (nextSchema, context) => {
|
|
240
|
+
onSchemaChange?.(assertRuntimeDocument(nextSchema), context);
|
|
241
|
+
} }) }));
|
|
242
|
+
};
|
|
243
|
+
AntdRuntimePlayground.displayName = 'AntdRuntimePlayground';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React, { type PropsWithChildren } from 'react';
|
|
2
|
+
import type { RuntimeEnvironment } from "./contracts.js";
|
|
3
|
+
interface IRuntimePreviewDiagnosticItem {
|
|
4
|
+
code: string;
|
|
5
|
+
message: string;
|
|
6
|
+
path: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const RuntimePreviewDiagnostics: ({ diagnostics, issues, }: {
|
|
9
|
+
diagnostics: IRuntimePreviewDiagnosticItem[];
|
|
10
|
+
issues: IRuntimePreviewDiagnosticItem[];
|
|
11
|
+
}) => React.JSX.Element | null;
|
|
12
|
+
export declare const RuntimeExecutorBoundary: ({ apiExecutor, children, }: PropsWithChildren<Pick<RuntimeEnvironment, "apiExecutor">>) => React.JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { CalendarOutlined, CheckCircleOutlined, ClockCircleOutlined, CloseCircleOutlined, DeleteOutlined, EditOutlined, InfoCircleOutlined, PlusOutlined, SearchOutlined, UploadOutlined, UserOutlined, WarningOutlined, } from '@ant-design/icons';
|
|
3
|
+
import { ConfigProvider } from '@yimoka/react';
|
|
4
|
+
const RUNTIME_ICON_ALLOWLIST = {
|
|
5
|
+
CalendarOutlined,
|
|
6
|
+
CheckCircleOutlined,
|
|
7
|
+
ClockCircleOutlined,
|
|
8
|
+
CloseCircleOutlined,
|
|
9
|
+
DeleteOutlined,
|
|
10
|
+
EditOutlined,
|
|
11
|
+
InfoCircleOutlined,
|
|
12
|
+
PlusOutlined,
|
|
13
|
+
SearchOutlined,
|
|
14
|
+
UploadOutlined,
|
|
15
|
+
UserOutlined,
|
|
16
|
+
WarningOutlined,
|
|
17
|
+
};
|
|
18
|
+
const resolveRuntimeIcon = (name) => RUNTIME_ICON_ALLOWLIST[name];
|
|
19
|
+
export const RuntimePreviewDiagnostics = ({ diagnostics, issues, }) => {
|
|
20
|
+
if (diagnostics.length === 0 && issues.length === 0)
|
|
21
|
+
return null;
|
|
22
|
+
return (_jsx("div", { "aria-live": issues.length > 0 ? 'assertive' : 'polite', "data-testid": "runtime-preview-diagnostics", role: issues.length > 0 ? 'alert' : 'status', children: [...issues, ...diagnostics].map(item => (_jsx("div", { "data-runtime-diagnostic-code": item.code, children: item.message }, `${item.code}:${item.path}:${item.message}`))) }));
|
|
23
|
+
};
|
|
24
|
+
export const RuntimeExecutorBoundary = ({ apiExecutor, children, }) => {
|
|
25
|
+
const boundaryConfig = {
|
|
26
|
+
apiExecutor,
|
|
27
|
+
getIcon: resolveRuntimeIcon,
|
|
28
|
+
notifier: undefined,
|
|
29
|
+
report: undefined,
|
|
30
|
+
root: undefined,
|
|
31
|
+
scope: {},
|
|
32
|
+
useLocation: () => ({
|
|
33
|
+
hash: '',
|
|
34
|
+
key: 'runtime-isolated',
|
|
35
|
+
pathname: '/',
|
|
36
|
+
search: '',
|
|
37
|
+
state: null,
|
|
38
|
+
}),
|
|
39
|
+
useNavigate: () => () => undefined,
|
|
40
|
+
useRouteParams: () => ({}),
|
|
41
|
+
};
|
|
42
|
+
return (_jsx(ConfigProvider, { inheritComponents: false, inheritScope: false, validateRequired: false, value: boundaryConfig, children: children }));
|
|
43
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type DynamicViewProps } from '@yimoka/react';
|
|
2
|
+
import React, { type ComponentType } from 'react';
|
|
3
|
+
import type { IPreviewWidgetProps } from "../types.js";
|
|
4
|
+
import type { RuntimeDiagnosticCode, RuntimeDocumentV1, RuntimeEnvironment } from "./contracts.js";
|
|
5
|
+
import { type IRuntimeDocumentValidationIssue } from "./document.js";
|
|
6
|
+
export type RuntimeDynamicViewProps = Pick<DynamicViewProps, 'components' | 'entity' | 'entityProps' | 'resetKey' | 'schema' | 'schemaKey' | 'scope' | 'store'>;
|
|
7
|
+
export interface IRuntimeDiagnostic {
|
|
8
|
+
code: RuntimeDiagnosticCode;
|
|
9
|
+
message: string;
|
|
10
|
+
path: string;
|
|
11
|
+
severity: 'warning';
|
|
12
|
+
}
|
|
13
|
+
export interface IRuntimeDynamicViewResolution {
|
|
14
|
+
apiExecutor?: RuntimeEnvironment['apiExecutor'];
|
|
15
|
+
diagnostics: IRuntimeDiagnostic[];
|
|
16
|
+
document?: RuntimeDocumentV1;
|
|
17
|
+
issues: IRuntimeDocumentValidationIssue[];
|
|
18
|
+
props?: RuntimeDynamicViewProps;
|
|
19
|
+
valid: boolean;
|
|
20
|
+
}
|
|
21
|
+
export interface IResolveRuntimeDynamicViewPropsOptions {
|
|
22
|
+
document: unknown;
|
|
23
|
+
environment?: RuntimeEnvironment;
|
|
24
|
+
runtimeComponents?: NonNullable<DynamicViewProps['components']>;
|
|
25
|
+
}
|
|
26
|
+
export interface IRuntimeDynamicViewPreviewProps extends IResolveRuntimeDynamicViewPropsOptions {
|
|
27
|
+
onResolution?: (resolution: IRuntimeDynamicViewResolution) => void;
|
|
28
|
+
}
|
|
29
|
+
export interface IRuntimeDynamicViewPreviewRendererProps extends IPreviewWidgetProps<RuntimeDocumentV1> {
|
|
30
|
+
environment?: RuntimeEnvironment;
|
|
31
|
+
onResolution?: (resolution: IRuntimeDynamicViewResolution) => void;
|
|
32
|
+
runtimeComponents?: NonNullable<DynamicViewProps['components']>;
|
|
33
|
+
}
|
|
34
|
+
export interface ICreateRuntimeDynamicViewPreviewRendererOptions {
|
|
35
|
+
environment?: RuntimeEnvironment;
|
|
36
|
+
onResolution?: (resolution: IRuntimeDynamicViewResolution) => void;
|
|
37
|
+
runtimeComponents?: NonNullable<DynamicViewProps['components']>;
|
|
38
|
+
}
|
|
39
|
+
export declare const resolveRuntimeDynamicViewProps: (options: IResolveRuntimeDynamicViewPropsOptions) => IRuntimeDynamicViewResolution;
|
|
40
|
+
export declare const RuntimeDynamicViewPreview: ({ document, environment, onResolution, runtimeComponents, }: IRuntimeDynamicViewPreviewProps) => React.JSX.Element;
|
|
41
|
+
export declare const RuntimeDynamicViewPreviewRenderer: ({ environment, onResolution, runtimeComponents, schema, }: IRuntimeDynamicViewPreviewRendererProps) => React.JSX.Element;
|
|
42
|
+
export declare const isRuntimeDynamicViewPreviewRenderer: (value: unknown) => boolean;
|
|
43
|
+
export declare const getRuntimeDynamicViewPreviewRendererOptions: (value: unknown) => ICreateRuntimeDynamicViewPreviewRendererOptions | undefined;
|
|
44
|
+
export declare const createRuntimeDynamicViewPreviewRenderer: (options: ICreateRuntimeDynamicViewPreviewRendererOptions) => ComponentType<IPreviewWidgetProps<RuntimeDocumentV1>>;
|