@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,304 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { GlobalRegistry, } from '@yimoka/designable-core';
|
|
3
|
+
import { Designer, Workbench, Viewport, } from '@yimoka/designable-react';
|
|
4
|
+
import { Layout } from 'antd';
|
|
5
|
+
import cls from 'classnames';
|
|
6
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
|
|
7
|
+
import { PlaygroundContext } from "./context.js";
|
|
8
|
+
import { usePlayground, useSchemaEditorDraft } from "./hooks/index.js";
|
|
9
|
+
import { createSchemaFingerprint } from "./shared/schema.js";
|
|
10
|
+
import { ComponentTreeWidget, PreviewWidget, SchemaEditorWidget, } from "./widgets/index.js";
|
|
11
|
+
import { SchemaCodeView } from "./widgets/SchemaCodeView/index.js";
|
|
12
|
+
const isSerializableSchema = (schema) => (typeof schema.serialize === 'function');
|
|
13
|
+
const toSchemaEditorValue = (tree) => (isSerializableSchema(tree) ? tree.serialize() : tree);
|
|
14
|
+
const getErrorMessage = (error) => {
|
|
15
|
+
if (error instanceof Error)
|
|
16
|
+
return error.message;
|
|
17
|
+
if (typeof error === 'string' && error.trim())
|
|
18
|
+
return error;
|
|
19
|
+
return '未知错误';
|
|
20
|
+
};
|
|
21
|
+
const viewRenderDependencyIdentities = new WeakMap();
|
|
22
|
+
let nextViewRenderDependencyIdentity = 1;
|
|
23
|
+
const getViewRenderDependencyIdentity = (value) => {
|
|
24
|
+
if ((typeof value !== 'object' || value === null) && typeof value !== 'function') {
|
|
25
|
+
return `${typeof value}:${String(value)}`;
|
|
26
|
+
}
|
|
27
|
+
const dependency = value;
|
|
28
|
+
const existing = viewRenderDependencyIdentities.get(dependency);
|
|
29
|
+
if (existing !== undefined)
|
|
30
|
+
return String(existing);
|
|
31
|
+
const identity = nextViewRenderDependencyIdentity;
|
|
32
|
+
nextViewRenderDependencyIdentity += 1;
|
|
33
|
+
viewRenderDependencyIdentities.set(dependency, identity);
|
|
34
|
+
return String(identity);
|
|
35
|
+
};
|
|
36
|
+
function createLivePlaygroundApi(apiRef) {
|
|
37
|
+
return {
|
|
38
|
+
get engine() {
|
|
39
|
+
return apiRef.current.engine;
|
|
40
|
+
},
|
|
41
|
+
setViewType: type => apiRef.current.setViewType(type),
|
|
42
|
+
getViewType: () => apiRef.current.getViewType(),
|
|
43
|
+
getSchema: () => apiRef.current.getSchema(),
|
|
44
|
+
setSchema: (schema, options) => apiRef.current.setSchema(schema, options),
|
|
45
|
+
get dirty() {
|
|
46
|
+
return apiRef.current.dirty;
|
|
47
|
+
},
|
|
48
|
+
isDirty: () => apiRef.current.isDirty(),
|
|
49
|
+
get lastChangeType() {
|
|
50
|
+
return apiRef.current.lastChangeType;
|
|
51
|
+
},
|
|
52
|
+
getLastChangeType: () => apiRef.current.getLastChangeType(),
|
|
53
|
+
markSaved: () => apiRef.current.markSaved(),
|
|
54
|
+
saveDesign: () => apiRef.current.saveDesign(),
|
|
55
|
+
loadDesign: () => apiRef.current.loadDesign(),
|
|
56
|
+
exportDesign: () => apiRef.current.exportDesign(),
|
|
57
|
+
tryExportDesign: () => apiRef.current.tryExportDesign(),
|
|
58
|
+
validateDesign: () => apiRef.current.validateDesign(),
|
|
59
|
+
importDesign: schema => apiRef.current.importDesign(schema),
|
|
60
|
+
getLastError: () => apiRef.current.getLastError?.() ?? null,
|
|
61
|
+
get storageEnabled() {
|
|
62
|
+
return apiRef.current.storageEnabled;
|
|
63
|
+
},
|
|
64
|
+
clearDesign: () => apiRef.current.clearDesign(),
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
class PlaygroundViewErrorBoundary extends React.Component {
|
|
68
|
+
static getDerivedStateFromError(error) {
|
|
69
|
+
return { error };
|
|
70
|
+
}
|
|
71
|
+
state = {
|
|
72
|
+
error: null,
|
|
73
|
+
};
|
|
74
|
+
componentDidCatch(error) {
|
|
75
|
+
this.props.onError?.(error);
|
|
76
|
+
}
|
|
77
|
+
componentDidUpdate(prevProps) {
|
|
78
|
+
if (!this.state.error)
|
|
79
|
+
return;
|
|
80
|
+
if (prevProps.resetKey === this.props.resetKey)
|
|
81
|
+
return;
|
|
82
|
+
this.setState({ error: null });
|
|
83
|
+
}
|
|
84
|
+
render() {
|
|
85
|
+
if (this.state.error) {
|
|
86
|
+
const message = getErrorMessage(this.state.error);
|
|
87
|
+
return (_jsxs("div", { role: "alert", style: {
|
|
88
|
+
alignItems: 'center',
|
|
89
|
+
background: '#fff1f0',
|
|
90
|
+
boxSizing: 'border-box',
|
|
91
|
+
color: '#a8071a',
|
|
92
|
+
display: 'flex',
|
|
93
|
+
flexDirection: 'column',
|
|
94
|
+
gap: 8,
|
|
95
|
+
height: '100%',
|
|
96
|
+
justifyContent: 'center',
|
|
97
|
+
padding: 24,
|
|
98
|
+
textAlign: 'center',
|
|
99
|
+
width: '100%',
|
|
100
|
+
}, children: [_jsx("div", { style: { fontSize: 14, fontWeight: 700 }, children: "\u5F53\u524D\u89C6\u56FE\u6E32\u67D3\u5931\u8D25" }), _jsx("div", { style: {
|
|
101
|
+
fontSize: 12,
|
|
102
|
+
lineHeight: '18px',
|
|
103
|
+
maxWidth: 560,
|
|
104
|
+
overflow: 'hidden',
|
|
105
|
+
textOverflow: 'ellipsis',
|
|
106
|
+
whiteSpace: 'nowrap',
|
|
107
|
+
}, title: message, children: message })] }));
|
|
108
|
+
}
|
|
109
|
+
return this.props.children;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const useDefaultDesignerLanguage = () => {
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
const currentLang = GlobalRegistry.getDesignerLanguage();
|
|
115
|
+
if (!currentLang || currentLang === 'en') {
|
|
116
|
+
GlobalRegistry.setDesignerLanguage('zh-CN');
|
|
117
|
+
}
|
|
118
|
+
}, []);
|
|
119
|
+
};
|
|
120
|
+
const renderLoadingState = (components, categories) => (_jsxs("div", { style: { padding: 20, background: '#fff' }, children: [_jsx("h2", { children: "\u6B63\u5728\u521D\u59CB\u5316\u8BBE\u8BA1\u5668\u5F15\u64CE..." }), _jsxs("p", { children: ["\u7EC4\u4EF6\u6570\u91CF: ", Object.keys(components).length] }), _jsxs("p", { children: ["\u5206\u7C7B\u6570\u91CF: ", categories?.length || 0] })] }));
|
|
121
|
+
const PlaygroundViewContent = ({ applySchemaEditorTree, children, getSchema, getTree, notifyNodeRenderError, schemaDraftValue, setSchemaDraftValue, viewType, }) => {
|
|
122
|
+
const isSchemaEditorActive = !children && viewType === 'json';
|
|
123
|
+
const [hasMountedSchemaEditor, setHasMountedSchemaEditor] = useState(isSchemaEditorActive);
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
if (isSchemaEditorActive) {
|
|
126
|
+
setHasMountedSchemaEditor(true);
|
|
127
|
+
}
|
|
128
|
+
}, [isSchemaEditorActive]);
|
|
129
|
+
if (children)
|
|
130
|
+
return children;
|
|
131
|
+
let activeContent = null;
|
|
132
|
+
switch (viewType) {
|
|
133
|
+
case 'design':
|
|
134
|
+
activeContent = (_jsx(Workbench, { children: _jsx(Viewport, { children: _jsx(ComponentTreeWidget, { onNodeRenderError: notifyNodeRenderError }) }) }));
|
|
135
|
+
break;
|
|
136
|
+
case 'preview':
|
|
137
|
+
activeContent = _jsx(PreviewWidget, {});
|
|
138
|
+
break;
|
|
139
|
+
case 'code':
|
|
140
|
+
activeContent = _jsx(SchemaCodeView, { getSchema: getSchema });
|
|
141
|
+
break;
|
|
142
|
+
case 'json':
|
|
143
|
+
break;
|
|
144
|
+
default:
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
return (_jsxs(_Fragment, { children: [(hasMountedSchemaEditor || isSchemaEditorActive) ? (_jsx("div", { style: {
|
|
148
|
+
display: isSchemaEditorActive ? 'block' : 'none',
|
|
149
|
+
height: '100%',
|
|
150
|
+
}, children: _jsx(SchemaEditorWidget, { draftValue: schemaDraftValue, tree: getTree(), onChange: applySchemaEditorTree, onDraftChange: setSchemaDraftValue }) })) : null, activeContent] }));
|
|
151
|
+
};
|
|
152
|
+
function PlaygroundComponent(props) {
|
|
153
|
+
const { components, categories, transformer, PreviewRenderer: previewRenderer, previewDataSourceLoader, engine: providedEngine, storageKey, schema, initialSchema, onSchemaChange, onError, onReady, defaultView = 'design', theme = 'light', prefixCls = 'dn-', className, style, children, validateSchemaEditorSchema, } = props;
|
|
154
|
+
useDefaultDesignerLanguage();
|
|
155
|
+
const playgroundState = usePlayground({
|
|
156
|
+
components,
|
|
157
|
+
categories,
|
|
158
|
+
transformer,
|
|
159
|
+
PreviewRenderer: previewRenderer,
|
|
160
|
+
engine: providedEngine,
|
|
161
|
+
storageKey,
|
|
162
|
+
schema,
|
|
163
|
+
initialSchema,
|
|
164
|
+
onSchemaChange,
|
|
165
|
+
onError,
|
|
166
|
+
defaultView,
|
|
167
|
+
});
|
|
168
|
+
const { engine, viewType, setViewType, getSchema, setSchema, isDirty, getLastChangeType, markSaved, saveDesign, loadDesign, exportDesign, tryExportDesign, validateDesign, importDesign, getLastError, storageEnabled, clearDesign, } = playgroundState;
|
|
169
|
+
const controlledSchemaFingerprint = schema === undefined
|
|
170
|
+
? undefined
|
|
171
|
+
: createSchemaFingerprint(() => schema);
|
|
172
|
+
const lastControlledSchemaFingerprintRef = useRef(controlledSchemaFingerprint);
|
|
173
|
+
const [controlledSchemaResetVersion, setControlledSchemaResetVersion] = useState(0);
|
|
174
|
+
const viewTypeRef = useRef(viewType);
|
|
175
|
+
const hasCustomLayout = children !== undefined && children !== null;
|
|
176
|
+
const { schemaDraftValue, setSchemaDraftValue } = useSchemaEditorDraft(getSchema, !hasCustomLayout && viewType === 'json', !hasCustomLayout);
|
|
177
|
+
const viewResetSchemaFingerprint = hasCustomLayout ? undefined : createSchemaFingerprint(getSchema);
|
|
178
|
+
const viewResetEngineIdentity = getViewRenderDependencyIdentity(engine);
|
|
179
|
+
const customLayoutResetIdentity = hasCustomLayout
|
|
180
|
+
? getViewRenderDependencyIdentity(children)
|
|
181
|
+
: 'default-layout';
|
|
182
|
+
const viewResetKey = [
|
|
183
|
+
viewType,
|
|
184
|
+
viewResetSchemaFingerprint ?? 'schema-unavailable',
|
|
185
|
+
viewResetEngineIdentity,
|
|
186
|
+
controlledSchemaResetVersion,
|
|
187
|
+
customLayoutResetIdentity,
|
|
188
|
+
].join(':');
|
|
189
|
+
useEffect(() => {
|
|
190
|
+
if (schema === undefined
|
|
191
|
+
|| controlledSchemaFingerprint === lastControlledSchemaFingerprintRef.current)
|
|
192
|
+
return;
|
|
193
|
+
lastControlledSchemaFingerprintRef.current = controlledSchemaFingerprint;
|
|
194
|
+
setControlledSchemaResetVersion(version => version + 1);
|
|
195
|
+
}, [controlledSchemaFingerprint, schema]);
|
|
196
|
+
const notifyViewRenderError = useCallback((error) => {
|
|
197
|
+
try {
|
|
198
|
+
onError?.(error, { engine, type: 'view:render' });
|
|
199
|
+
}
|
|
200
|
+
catch {
|
|
201
|
+
}
|
|
202
|
+
}, [engine, onError]);
|
|
203
|
+
const notifyNodeRenderError = useCallback((error, context) => {
|
|
204
|
+
try {
|
|
205
|
+
onError?.(error, {
|
|
206
|
+
engine,
|
|
207
|
+
type: 'component-node:render',
|
|
208
|
+
...context,
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
catch {
|
|
212
|
+
}
|
|
213
|
+
}, [engine, onError]);
|
|
214
|
+
useEffect(() => {
|
|
215
|
+
viewTypeRef.current = viewType;
|
|
216
|
+
}, [viewType]);
|
|
217
|
+
const playgroundApi = useMemo(() => ({
|
|
218
|
+
engine,
|
|
219
|
+
setViewType,
|
|
220
|
+
getViewType: () => viewTypeRef.current,
|
|
221
|
+
getSchema,
|
|
222
|
+
setSchema,
|
|
223
|
+
get dirty() {
|
|
224
|
+
return typeof isDirty === 'function' ? isDirty() : false;
|
|
225
|
+
},
|
|
226
|
+
isDirty,
|
|
227
|
+
get lastChangeType() {
|
|
228
|
+
return typeof getLastChangeType === 'function' ? getLastChangeType() : undefined;
|
|
229
|
+
},
|
|
230
|
+
getLastChangeType,
|
|
231
|
+
markSaved,
|
|
232
|
+
saveDesign,
|
|
233
|
+
loadDesign,
|
|
234
|
+
exportDesign,
|
|
235
|
+
tryExportDesign,
|
|
236
|
+
validateDesign,
|
|
237
|
+
importDesign,
|
|
238
|
+
getLastError,
|
|
239
|
+
storageEnabled,
|
|
240
|
+
clearDesign,
|
|
241
|
+
}), [
|
|
242
|
+
clearDesign,
|
|
243
|
+
engine,
|
|
244
|
+
exportDesign,
|
|
245
|
+
getLastChangeType,
|
|
246
|
+
getLastError,
|
|
247
|
+
getSchema,
|
|
248
|
+
importDesign,
|
|
249
|
+
isDirty,
|
|
250
|
+
loadDesign,
|
|
251
|
+
markSaved,
|
|
252
|
+
saveDesign,
|
|
253
|
+
setSchema,
|
|
254
|
+
setViewType,
|
|
255
|
+
storageEnabled,
|
|
256
|
+
tryExportDesign,
|
|
257
|
+
validateDesign,
|
|
258
|
+
]);
|
|
259
|
+
const playgroundApiRef = useRef(playgroundApi);
|
|
260
|
+
useEffect(() => {
|
|
261
|
+
playgroundApiRef.current = playgroundApi;
|
|
262
|
+
}, [playgroundApi]);
|
|
263
|
+
useEffect(() => {
|
|
264
|
+
if (!onReady)
|
|
265
|
+
return undefined;
|
|
266
|
+
return onReady(createLivePlaygroundApi(playgroundApiRef));
|
|
267
|
+
}, [engine, onReady]);
|
|
268
|
+
const applySchemaEditorTree = (tree) => {
|
|
269
|
+
const nextSchema = toSchemaEditorValue(tree);
|
|
270
|
+
try {
|
|
271
|
+
validateSchemaEditorSchema?.(nextSchema);
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
onError?.(error, {
|
|
275
|
+
engine,
|
|
276
|
+
type: 'update:tree:schema',
|
|
277
|
+
});
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
return setSchema(nextSchema, { snapshotType: 'update:tree:schema' });
|
|
281
|
+
};
|
|
282
|
+
if (!engine) {
|
|
283
|
+
return renderLoadingState(components, categories);
|
|
284
|
+
}
|
|
285
|
+
const playgroundContext = {
|
|
286
|
+
...playgroundApi,
|
|
287
|
+
viewType,
|
|
288
|
+
components,
|
|
289
|
+
categories: categories || [],
|
|
290
|
+
transformer,
|
|
291
|
+
PreviewRenderer: previewRenderer,
|
|
292
|
+
previewDataSourceLoader,
|
|
293
|
+
validateSchemaEditorSchema,
|
|
294
|
+
};
|
|
295
|
+
return (_jsx(PlaygroundContext.Provider, { value: playgroundContext, children: _jsx(Designer, { engine: engine, prefixCls: prefixCls, theme: theme, children: _jsx(Layout, { className: cls('playground', className), style: {
|
|
296
|
+
width: '100%',
|
|
297
|
+
height: '100%',
|
|
298
|
+
display: 'flex',
|
|
299
|
+
flexDirection: 'column',
|
|
300
|
+
...style,
|
|
301
|
+
}, children: _jsx(PlaygroundViewErrorBoundary, { resetKey: viewResetKey, onError: notifyViewRenderError, children: _jsx(PlaygroundViewContent, { applySchemaEditorTree: applySchemaEditorTree, getSchema: getSchema, getTree: () => engine.getCurrentTree(), notifyNodeRenderError: notifyNodeRenderError, schemaDraftValue: schemaDraftValue, setSchemaDraftValue: setSchemaDraftValue, viewType: viewType, children: children }) }) }) }) }));
|
|
302
|
+
}
|
|
303
|
+
PlaygroundComponent.displayName = 'Playground';
|
|
304
|
+
export const Playground = PlaygroundComponent;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type DnComponentRegistryItem } from '@yimoka/designable-react';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { type IPlaygroundScenarioValidationResources } from "../presets/scenarios.js";
|
|
4
|
+
import type { IPlaygroundScenarioPreset } from "../runtime/contracts.js";
|
|
5
|
+
import type { IFormilySchemaInput } from "../transformers/index.js";
|
|
6
|
+
import type { IComponentCategory, IPlaygroundLayoutProps } from "../types.js";
|
|
7
|
+
export type IAntdPlaygroundProps<S = IFormilySchemaInput> = Omit<IPlaygroundLayoutProps<S>, 'categories' | 'components' | 'settingsPanel' | 'transformer'> & Partial<Pick<IPlaygroundLayoutProps<S>, 'categories' | 'components' | 'settingsPanel' | 'transformer'>> & {
|
|
8
|
+
extraComponents?: Record<string, DnComponentRegistryItem>;
|
|
9
|
+
extraCategories?: IComponentCategory[];
|
|
10
|
+
scenarioPreset?: IPlaygroundScenarioPreset<S>;
|
|
11
|
+
scenarioValidationResources?: IPlaygroundScenarioValidationResources;
|
|
12
|
+
};
|
|
13
|
+
export declare const AntdPlayground: {
|
|
14
|
+
<S = IFormilySchemaInput>({ availableViews, categories, components, defaultView, extraCategories, extraComponents, leftPanelWidth, position, PreviewRenderer, resourcePanelProps, rightPanelWidth, scenarioPreset, scenarioValidationResources, schemaEditorReadonly, settingsPanel, showDesignerTools, showHistoryPanel, showNodeActions, showOutlinePanel, showResourcePanel, showSettingsPanel, showStorageActions, showViewTools, theme, transformer, variables, ...props }: IAntdPlaygroundProps<S>): React.JSX.Element;
|
|
15
|
+
displayName: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { antdAdapter, SettingsForm } from '@yimoka/designable-antd';
|
|
3
|
+
import { UIAdapterProvider } from '@yimoka/designable-react';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { PlaygroundLayout } from "../layouts/index.js";
|
|
6
|
+
import { createAntdPlaygroundPreset } from "../presets/antd.js";
|
|
7
|
+
import { assertPlaygroundScenarioPreset, pickScenarioLayoutProps, resolveAntdPlaygroundScenario, } from "../presets/scenarios.js";
|
|
8
|
+
const DEFAULT_EXTRA_CATEGORY_KEY = 'custom';
|
|
9
|
+
const collectCategorizedComponentNames = (categories) => (new Set(categories.flatMap(category => category.components)));
|
|
10
|
+
const filterCategoriesByComponents = (categories, components) => (categories
|
|
11
|
+
.map(category => ({
|
|
12
|
+
...category,
|
|
13
|
+
components: category.components.filter(componentName => components[componentName]),
|
|
14
|
+
}))
|
|
15
|
+
.filter(category => category.components.length > 0));
|
|
16
|
+
const createExtraCategoryKey = (categories) => {
|
|
17
|
+
const keys = new Set(categories.map(category => category.key));
|
|
18
|
+
if (!keys.has(DEFAULT_EXTRA_CATEGORY_KEY))
|
|
19
|
+
return DEFAULT_EXTRA_CATEGORY_KEY;
|
|
20
|
+
return '__extra_components';
|
|
21
|
+
};
|
|
22
|
+
export const AntdPlayground = ({ availableViews, categories, components, defaultView, extraCategories, extraComponents, leftPanelWidth, position, PreviewRenderer, resourcePanelProps, rightPanelWidth, scenarioPreset, scenarioValidationResources, schemaEditorReadonly, settingsPanel, showDesignerTools, showHistoryPanel, showNodeActions, showOutlinePanel, showResourcePanel, showSettingsPanel, showStorageActions, showViewTools, theme, transformer, variables, ...props }) => {
|
|
23
|
+
const preset = useMemo(() => createAntdPlaygroundPreset(), []);
|
|
24
|
+
const resolvedScenarioPreset = useMemo(() => (scenarioPreset
|
|
25
|
+
? assertPlaygroundScenarioPreset(scenarioPreset, scenarioValidationResources)
|
|
26
|
+
: undefined), [scenarioPreset, scenarioValidationResources]);
|
|
27
|
+
const resolvedScenario = useMemo(() => resolveAntdPlaygroundScenario({
|
|
28
|
+
defaults: {
|
|
29
|
+
categories: preset.categories,
|
|
30
|
+
components: preset.components,
|
|
31
|
+
transformer: preset.transformer,
|
|
32
|
+
},
|
|
33
|
+
explicit: {
|
|
34
|
+
PreviewRenderer,
|
|
35
|
+
categories,
|
|
36
|
+
components,
|
|
37
|
+
layoutProps: pickScenarioLayoutProps({
|
|
38
|
+
availableViews,
|
|
39
|
+
defaultView,
|
|
40
|
+
leftPanelWidth,
|
|
41
|
+
position,
|
|
42
|
+
resourcePanelProps,
|
|
43
|
+
rightPanelWidth,
|
|
44
|
+
schemaEditorReadonly,
|
|
45
|
+
showDesignerTools,
|
|
46
|
+
showHistoryPanel,
|
|
47
|
+
showNodeActions,
|
|
48
|
+
showOutlinePanel,
|
|
49
|
+
showResourcePanel,
|
|
50
|
+
showSettingsPanel,
|
|
51
|
+
showStorageActions,
|
|
52
|
+
showViewTools,
|
|
53
|
+
theme,
|
|
54
|
+
variables,
|
|
55
|
+
}),
|
|
56
|
+
settingsPanel,
|
|
57
|
+
transformer,
|
|
58
|
+
},
|
|
59
|
+
extraCategories,
|
|
60
|
+
extraComponents,
|
|
61
|
+
scenario: resolvedScenarioPreset
|
|
62
|
+
? {
|
|
63
|
+
PreviewRenderer: resolvedScenarioPreset.PreviewRenderer,
|
|
64
|
+
categories: resolvedScenarioPreset.categories,
|
|
65
|
+
components: resolvedScenarioPreset.designerComponents,
|
|
66
|
+
layoutProps: resolvedScenarioPreset.layoutProps,
|
|
67
|
+
settingsPanel: resolvedScenarioPreset.settingsPanel,
|
|
68
|
+
transformer: resolvedScenarioPreset.transformer,
|
|
69
|
+
}
|
|
70
|
+
: undefined,
|
|
71
|
+
}), [
|
|
72
|
+
PreviewRenderer,
|
|
73
|
+
categories,
|
|
74
|
+
components,
|
|
75
|
+
defaultView,
|
|
76
|
+
extraCategories,
|
|
77
|
+
extraComponents,
|
|
78
|
+
leftPanelWidth,
|
|
79
|
+
position,
|
|
80
|
+
preset.categories,
|
|
81
|
+
preset.components,
|
|
82
|
+
preset.transformer,
|
|
83
|
+
resourcePanelProps,
|
|
84
|
+
resolvedScenarioPreset,
|
|
85
|
+
rightPanelWidth,
|
|
86
|
+
schemaEditorReadonly,
|
|
87
|
+
settingsPanel,
|
|
88
|
+
showDesignerTools,
|
|
89
|
+
showHistoryPanel,
|
|
90
|
+
showNodeActions,
|
|
91
|
+
showOutlinePanel,
|
|
92
|
+
showResourcePanel,
|
|
93
|
+
showSettingsPanel,
|
|
94
|
+
showStorageActions,
|
|
95
|
+
showViewTools,
|
|
96
|
+
theme,
|
|
97
|
+
transformer,
|
|
98
|
+
variables,
|
|
99
|
+
availableViews,
|
|
100
|
+
]);
|
|
101
|
+
const mergedComponents = resolvedScenario.components;
|
|
102
|
+
const mergedCategories = resolvedScenario.categories;
|
|
103
|
+
const resolvedCategories = useMemo(() => {
|
|
104
|
+
const availableCategories = filterCategoriesByComponents(mergedCategories, mergedComponents);
|
|
105
|
+
const shouldAutoCategorizeAllComponents = (categories === undefined
|
|
106
|
+
&& (components !== undefined
|
|
107
|
+
|| resolvedScenarioPreset === undefined));
|
|
108
|
+
const componentNamesForAutoCategory = shouldAutoCategorizeAllComponents
|
|
109
|
+
? Object.keys(mergedComponents)
|
|
110
|
+
: Object.keys(extraComponents ?? {});
|
|
111
|
+
if (!componentNamesForAutoCategory.length)
|
|
112
|
+
return availableCategories;
|
|
113
|
+
const categorizedComponentNames = collectCategorizedComponentNames(availableCategories);
|
|
114
|
+
const uncategorizedComponentNames = componentNamesForAutoCategory
|
|
115
|
+
.filter(componentName => !categorizedComponentNames.has(componentName));
|
|
116
|
+
if (!uncategorizedComponentNames.length)
|
|
117
|
+
return availableCategories;
|
|
118
|
+
return [
|
|
119
|
+
...availableCategories,
|
|
120
|
+
{
|
|
121
|
+
key: createExtraCategoryKey(mergedCategories),
|
|
122
|
+
title: '业务组件',
|
|
123
|
+
components: uncategorizedComponentNames,
|
|
124
|
+
},
|
|
125
|
+
];
|
|
126
|
+
}, [
|
|
127
|
+
categories,
|
|
128
|
+
components,
|
|
129
|
+
extraComponents,
|
|
130
|
+
mergedCategories,
|
|
131
|
+
mergedComponents,
|
|
132
|
+
resolvedScenarioPreset,
|
|
133
|
+
]);
|
|
134
|
+
return (_jsx(UIAdapterProvider, { adapter: antdAdapter, children: _jsx(PlaygroundLayout, { ...props, ...resolvedScenario.layoutProps, PreviewRenderer: resolvedScenario.PreviewRenderer, categories: resolvedCategories, components: mergedComponents, settingsPanel: resolvedScenario.settingsPanel ?? SettingsForm, transformer: resolvedScenario.transformer }) }));
|
|
135
|
+
};
|
|
136
|
+
AntdPlayground.displayName = 'AntdPlayground';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./AntdPlayground.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./AntdPlayground.js";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { IPlaygroundContext } from "./types.js";
|
|
2
|
+
export declare const PlaygroundContext: import("react").Context<IPlaygroundContext<unknown> | null>;
|
|
3
|
+
export declare const usePlaygroundContext: <S = unknown>() => IPlaygroundContext<S>;
|
|
4
|
+
export declare const useMaybePlaygroundContext: <S = unknown>() => IPlaygroundContext<S> | null;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createContext, useContext } from 'react';
|
|
2
|
+
export const PlaygroundContext = createContext(null);
|
|
3
|
+
export const usePlaygroundContext = () => {
|
|
4
|
+
const context = useContext(PlaygroundContext);
|
|
5
|
+
if (!context) {
|
|
6
|
+
throw new Error('usePlaygroundContext must be used within a PlaygroundProvider');
|
|
7
|
+
}
|
|
8
|
+
return context;
|
|
9
|
+
};
|
|
10
|
+
export const useMaybePlaygroundContext = () => {
|
|
11
|
+
const context = useContext(PlaygroundContext);
|
|
12
|
+
return context;
|
|
13
|
+
};
|