@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,443 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { observer } from '@formily/reactive-react';
|
|
3
|
+
import { CursorStatus, CursorType, resetDragDropState, } from '@yimoka/designable-core';
|
|
4
|
+
import { DesignerToolsWidget, HistoryWidget, NodePathWidget, Simulator, useDesigner, useOperation, useTree, Viewport, ViewToolsWidget, Workbench, } from '@yimoka/designable-react';
|
|
5
|
+
import { Flex, Layout } from 'antd';
|
|
6
|
+
import React, { useEffect, useRef } from 'react';
|
|
7
|
+
import { usePlaygroundContext } from "../../context.js";
|
|
8
|
+
import { useSchemaEditorDraft } from "../../hooks/index.js";
|
|
9
|
+
import { CompositePanel } from "../../panels/index.js";
|
|
10
|
+
import { Playground } from "../../Playground.js";
|
|
11
|
+
import { createSchemaFingerprint } from "../../shared/schema.js";
|
|
12
|
+
import { ComponentTreeWidget, NodeActionsWidget, OutlineTreeWidget, PreviewWidget, ResourceWidget, SchemaEditorWidget, SettingsPanelWidget, StorageActionsWidget, } from "../../widgets/index.js";
|
|
13
|
+
import { SchemaCodeView } from "../../widgets/SchemaCodeView/index.js";
|
|
14
|
+
import { SidePanelErrorBoundary, ToolbarItemErrorBoundary, WorkbenchViewErrorBoundary, } from "./ErrorBoundaries.js";
|
|
15
|
+
const { Header, Sider, Content } = Layout;
|
|
16
|
+
const LEFT_PANEL_MIN_WIDTH = 180;
|
|
17
|
+
const LEFT_PANEL_MAX_WIDTH = 420;
|
|
18
|
+
const RIGHT_PANEL_MIN_WIDTH = 260;
|
|
19
|
+
const RIGHT_PANEL_MAX_WIDTH = 560;
|
|
20
|
+
const PANEL_KEYBOARD_RESIZE_STEP = 16;
|
|
21
|
+
const clampPanelWidth = (width, minWidth, maxWidth) => (Math.min(Math.max(width, minWidth), maxWidth));
|
|
22
|
+
const playgroundViewToWorkbenchType = (viewType) => {
|
|
23
|
+
switch (viewType) {
|
|
24
|
+
case 'json':
|
|
25
|
+
return 'JSONTREE';
|
|
26
|
+
case 'preview':
|
|
27
|
+
return 'PREVIEW';
|
|
28
|
+
case 'code':
|
|
29
|
+
return 'MARKUP';
|
|
30
|
+
case 'design':
|
|
31
|
+
default:
|
|
32
|
+
return 'DESIGNABLE';
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const playgroundViewsToWorkbenchTypes = (views) => (views.map(playgroundViewToWorkbenchType));
|
|
36
|
+
const getAllowedViews = (views) => (views?.length ? views : undefined);
|
|
37
|
+
const getResolvedView = (view, availableViews) => {
|
|
38
|
+
const allowedViews = getAllowedViews(availableViews);
|
|
39
|
+
if (!allowedViews)
|
|
40
|
+
return view;
|
|
41
|
+
if (view && allowedViews.includes(view))
|
|
42
|
+
return view;
|
|
43
|
+
return allowedViews[0];
|
|
44
|
+
};
|
|
45
|
+
const workbenchTypeToPlaygroundView = (workbenchType) => {
|
|
46
|
+
switch (workbenchType) {
|
|
47
|
+
case 'JSONTREE':
|
|
48
|
+
return 'json';
|
|
49
|
+
case 'PREVIEW':
|
|
50
|
+
return 'preview';
|
|
51
|
+
case 'MARKUP':
|
|
52
|
+
return 'code';
|
|
53
|
+
case 'DESIGNABLE':
|
|
54
|
+
default:
|
|
55
|
+
return 'design';
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
const isSerializableSchema = (schema) => (typeof schema.serialize === 'function');
|
|
59
|
+
const toSchemaEditorValue = (tree) => (isSerializableSchema(tree) ? tree.serialize() : tree);
|
|
60
|
+
const WorkbenchMainContent = ({ getSchema, onNodeRenderError, onSchemaDraftChange, onSchemaTreeChange, schemaEditorReadonly, schemaDraftValue, tree, workbenchType, }) => {
|
|
61
|
+
const isSchemaEditorActive = workbenchType === 'JSONTREE';
|
|
62
|
+
const [hasMountedSchemaEditor, setHasMountedSchemaEditor] = React.useState(isSchemaEditorActive);
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
if (isSchemaEditorActive) {
|
|
65
|
+
setHasMountedSchemaEditor(true);
|
|
66
|
+
}
|
|
67
|
+
}, [isSchemaEditorActive]);
|
|
68
|
+
let activeContent = null;
|
|
69
|
+
switch (workbenchType) {
|
|
70
|
+
case 'PREVIEW':
|
|
71
|
+
activeContent = _jsx(PreviewWidget, {});
|
|
72
|
+
break;
|
|
73
|
+
case 'MARKUP':
|
|
74
|
+
activeContent = _jsx(SchemaCodeView, { getSchema: getSchema });
|
|
75
|
+
break;
|
|
76
|
+
case 'JSONTREE':
|
|
77
|
+
break;
|
|
78
|
+
case 'DESIGNABLE':
|
|
79
|
+
default:
|
|
80
|
+
activeContent = (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', height: '100%' }, children: [_jsx("div", { "aria-label": "\u8282\u70B9\u8DEF\u5F84", style: {
|
|
81
|
+
alignItems: 'center',
|
|
82
|
+
borderBottom: '1px solid #f0f0f0',
|
|
83
|
+
display: 'flex',
|
|
84
|
+
minHeight: 32,
|
|
85
|
+
padding: '0 12px',
|
|
86
|
+
}, children: _jsx(NodePathWidget, { maxItems: 5 }) }), _jsx(Simulator, { style: { flex: 1, minHeight: 0 }, children: _jsx(Viewport, { style: { height: '100%' }, children: _jsx(ComponentTreeWidget, { onNodeRenderError: onNodeRenderError }) }, "design-viewport") })] }));
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
return (_jsxs(_Fragment, { children: [(hasMountedSchemaEditor || isSchemaEditorActive) ? (_jsx("div", { style: {
|
|
90
|
+
display: isSchemaEditorActive ? 'block' : 'none',
|
|
91
|
+
height: '100%',
|
|
92
|
+
}, children: _jsx(SchemaEditorWidget, { draftValue: schemaDraftValue, readonly: schemaEditorReadonly, tree: tree, onChange: onSchemaTreeChange, onDraftChange: onSchemaDraftChange }) })) : null, activeContent] }));
|
|
93
|
+
};
|
|
94
|
+
const getDefaultLeftPanelKey = ({ showHistoryPanel, showOutlinePanel, showResourcePanel, }) => {
|
|
95
|
+
if (showResourcePanel)
|
|
96
|
+
return 'resources';
|
|
97
|
+
if (showOutlinePanel)
|
|
98
|
+
return 'outline';
|
|
99
|
+
if (showHistoryPanel)
|
|
100
|
+
return 'history';
|
|
101
|
+
return 'resources';
|
|
102
|
+
};
|
|
103
|
+
const shouldResetDesignableDragState = (previousWorkbenchType, workbenchType) => workbenchType === 'DESIGNABLE' && previousWorkbenchType !== 'DESIGNABLE';
|
|
104
|
+
const resetDesignableDragState = (designer, operation) => {
|
|
105
|
+
resetDragDropState();
|
|
106
|
+
operation?.dragClean();
|
|
107
|
+
operation?.hover?.clear?.();
|
|
108
|
+
designer?.cursor?.setStatus(CursorStatus.Normal);
|
|
109
|
+
designer?.cursor?.setType(CursorType.Move);
|
|
110
|
+
};
|
|
111
|
+
const useDesignableDragReset = ({ designer, operation, workbenchType, }) => {
|
|
112
|
+
const previousWorkbenchTypeRef = useRef(undefined);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
const previousWorkbenchType = previousWorkbenchTypeRef.current;
|
|
115
|
+
previousWorkbenchTypeRef.current = workbenchType;
|
|
116
|
+
if (!shouldResetDesignableDragState(previousWorkbenchType, workbenchType))
|
|
117
|
+
return;
|
|
118
|
+
resetDesignableDragState(designer, operation);
|
|
119
|
+
}, [designer, operation, workbenchType]);
|
|
120
|
+
};
|
|
121
|
+
const useResizablePanelWidth = ({ direction, initialWidth, maxWidth, minWidth, }) => {
|
|
122
|
+
const baseWidth = clampPanelWidth(initialWidth, minWidth, maxWidth);
|
|
123
|
+
const [manualWidth, setManualWidth] = React.useState(null);
|
|
124
|
+
const cleanupRef = React.useRef(null);
|
|
125
|
+
const width = manualWidth?.baseWidth === baseWidth ? manualWidth.value : baseWidth;
|
|
126
|
+
React.useEffect(() => () => {
|
|
127
|
+
cleanupRef.current?.();
|
|
128
|
+
}, []);
|
|
129
|
+
const startResize = React.useCallback((event) => {
|
|
130
|
+
event.preventDefault();
|
|
131
|
+
event.stopPropagation();
|
|
132
|
+
cleanupRef.current?.();
|
|
133
|
+
const startX = event.clientX;
|
|
134
|
+
const startWidth = width;
|
|
135
|
+
const handlePointerMove = (moveEvent) => {
|
|
136
|
+
const delta = direction === 'left'
|
|
137
|
+
? moveEvent.clientX - startX
|
|
138
|
+
: startX - moveEvent.clientX;
|
|
139
|
+
setManualWidth({
|
|
140
|
+
baseWidth,
|
|
141
|
+
value: clampPanelWidth(startWidth + delta, minWidth, maxWidth),
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
const handlePointerUp = () => {
|
|
145
|
+
cleanupRef.current?.();
|
|
146
|
+
};
|
|
147
|
+
const cleanup = () => {
|
|
148
|
+
window.removeEventListener('pointermove', handlePointerMove);
|
|
149
|
+
window.removeEventListener('pointerup', handlePointerUp);
|
|
150
|
+
cleanupRef.current = null;
|
|
151
|
+
};
|
|
152
|
+
cleanupRef.current = cleanup;
|
|
153
|
+
window.addEventListener('pointermove', handlePointerMove);
|
|
154
|
+
window.addEventListener('pointerup', handlePointerUp);
|
|
155
|
+
}, [baseWidth, direction, maxWidth, minWidth, width]);
|
|
156
|
+
const resizeByKeyboard = React.useCallback((delta) => {
|
|
157
|
+
setManualWidth({
|
|
158
|
+
baseWidth,
|
|
159
|
+
value: clampPanelWidth(width + delta, minWidth, maxWidth),
|
|
160
|
+
});
|
|
161
|
+
}, [baseWidth, maxWidth, minWidth, width]);
|
|
162
|
+
return {
|
|
163
|
+
resizeByKeyboard,
|
|
164
|
+
startResize,
|
|
165
|
+
width,
|
|
166
|
+
};
|
|
167
|
+
};
|
|
168
|
+
const PanelResizeHandle = ({ label, onKeyboardResize, side, onResizeStart, }) => {
|
|
169
|
+
const handleKeyDown = (event) => {
|
|
170
|
+
const directionFactor = side === 'right' ? 1 : -1;
|
|
171
|
+
if (event.key === 'ArrowRight') {
|
|
172
|
+
event.preventDefault();
|
|
173
|
+
onKeyboardResize(PANEL_KEYBOARD_RESIZE_STEP * directionFactor);
|
|
174
|
+
}
|
|
175
|
+
else if (event.key === 'ArrowLeft') {
|
|
176
|
+
event.preventDefault();
|
|
177
|
+
onKeyboardResize(-PANEL_KEYBOARD_RESIZE_STEP * directionFactor);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
return (_jsx("div", { "aria-label": label, "aria-orientation": "vertical", role: "separator", style: {
|
|
181
|
+
bottom: 0,
|
|
182
|
+
cursor: 'col-resize',
|
|
183
|
+
position: 'absolute',
|
|
184
|
+
top: 0,
|
|
185
|
+
width: 8,
|
|
186
|
+
zIndex: 20,
|
|
187
|
+
...(side === 'left' ? { left: -4 } : { right: -4 }),
|
|
188
|
+
}, tabIndex: 0, onKeyDown: handleKeyDown, onPointerDown: onResizeStart }));
|
|
189
|
+
};
|
|
190
|
+
PanelResizeHandle.displayName = 'PanelResizeHandle';
|
|
191
|
+
const useWorkbenchPanelState = (props, workbenchType) => {
|
|
192
|
+
const showResourcePanel = props.showResourcePanel !== false;
|
|
193
|
+
const showOutlinePanel = props.showOutlinePanel !== false;
|
|
194
|
+
const showHistoryPanel = props.showHistoryPanel !== false;
|
|
195
|
+
const showSettingsPanel = props.showSettingsPanel !== false;
|
|
196
|
+
const showSidePanels = workbenchType === 'DESIGNABLE';
|
|
197
|
+
const defaultLeftPanelKey = getDefaultLeftPanelKey({
|
|
198
|
+
showHistoryPanel,
|
|
199
|
+
showOutlinePanel,
|
|
200
|
+
showResourcePanel,
|
|
201
|
+
});
|
|
202
|
+
const availableLeftPanelKeys = React.useMemo(() => [
|
|
203
|
+
showResourcePanel ? 'resources' : undefined,
|
|
204
|
+
showOutlinePanel ? 'outline' : undefined,
|
|
205
|
+
showHistoryPanel ? 'history' : undefined,
|
|
206
|
+
].filter((key) => Boolean(key)), [
|
|
207
|
+
showHistoryPanel,
|
|
208
|
+
showOutlinePanel,
|
|
209
|
+
showResourcePanel,
|
|
210
|
+
]);
|
|
211
|
+
return {
|
|
212
|
+
availableLeftPanelKeys,
|
|
213
|
+
defaultLeftPanelKey,
|
|
214
|
+
leftPanelWidth: props.leftPanelWidth ?? 220,
|
|
215
|
+
rightPanelWidth: props.rightPanelWidth ?? 320,
|
|
216
|
+
showHistoryPanel,
|
|
217
|
+
showLeftPanel: showSidePanels && Boolean(availableLeftPanelKeys.length),
|
|
218
|
+
showOutlinePanel,
|
|
219
|
+
showResourcePanel,
|
|
220
|
+
showRightPanel: showSidePanels && showSettingsPanel,
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
const WorkbenchLeftPanel = ({ activeKey, defaultActiveKey, onError, onChange, onKeyboardResize, onResizeStart, panelState, resourcePanelProps, width, workbenchType, }) => {
|
|
224
|
+
if (!panelState.showLeftPanel)
|
|
225
|
+
return null;
|
|
226
|
+
return (_jsxs(Sider, { "aria-label": "\u8BBE\u8BA1\u5668\u5DE6\u4FA7\u9762\u677F", "data-testid": "designable-left-panel", style: {
|
|
227
|
+
background: '#fff',
|
|
228
|
+
borderRight: '1px solid #dfe7f1',
|
|
229
|
+
boxShadow: '1px 0 0 rgba(15, 23, 42, 0.02)',
|
|
230
|
+
height: '100%',
|
|
231
|
+
overflow: 'hidden',
|
|
232
|
+
position: 'relative',
|
|
233
|
+
}, theme: "light", width: width, children: [_jsxs(CompositePanel, { activeKey: activeKey, defaultActiveKey: defaultActiveKey, onChange: onChange, children: [panelState.showResourcePanel && (_jsx(CompositePanel.Item, { title: "\u7EC4\u4EF6", children: _jsx(SidePanelErrorBoundary, { panelTitle: "\u7EC4\u4EF6\u9762\u677F", resetKey: `${workbenchType}:resources`, onError: error => onError?.(error, 'layout:resource-panel:render'), children: _jsx(ResourceWidget, { ...resourcePanelProps }) }) }, "resources")), panelState.showOutlinePanel && (_jsx(CompositePanel.Item, { title: "\u5927\u7EB2", children: _jsx(SidePanelErrorBoundary, { panelTitle: "\u5927\u7EB2\u9762\u677F", resetKey: `${workbenchType}:outline`, onError: error => onError?.(error, 'layout:outline-panel:render'), children: _jsx(OutlineTreeWidget, {}) }) }, "outline")), panelState.showHistoryPanel && (_jsx(CompositePanel.Item, { title: "\u5386\u53F2", children: _jsx(SidePanelErrorBoundary, { panelTitle: "\u5386\u53F2\u9762\u677F", resetKey: `${workbenchType}:history`, onError: error => onError?.(error, 'layout:history-panel:render'), children: _jsx(HistoryWidget, {}) }) }, "history"))] }), _jsx(PanelResizeHandle, { label: "\u8C03\u6574\u5DE6\u4FA7\u9762\u677F\u5BBD\u5EA6", side: "right", onKeyboardResize: onKeyboardResize, onResizeStart: onResizeStart })] }));
|
|
234
|
+
};
|
|
235
|
+
const WorkbenchRightPanel = ({ children, onError, onKeyboardResize, onResizeStart, panelState, width, }) => {
|
|
236
|
+
if (!panelState.showRightPanel)
|
|
237
|
+
return null;
|
|
238
|
+
return (_jsxs(Sider, { "aria-label": "\u8BBE\u8BA1\u5668\u5C5E\u6027\u9762\u677F", "data-testid": "designable-right-panel", style: {
|
|
239
|
+
background: '#fff',
|
|
240
|
+
borderLeft: '1px solid #dfe7f1',
|
|
241
|
+
height: '100%',
|
|
242
|
+
overflow: 'hidden',
|
|
243
|
+
position: 'relative',
|
|
244
|
+
}, theme: "light", width: width, children: [_jsx(PanelResizeHandle, { label: "\u8C03\u6574\u53F3\u4FA7\u9762\u677F\u5BBD\u5EA6", side: "left", onKeyboardResize: onKeyboardResize, onResizeStart: onResizeStart }), _jsx(SettingsPanelWidget, { title: "\u5C5E\u6027\u8BBE\u7F6E", onError: onError, children: children })] }));
|
|
245
|
+
};
|
|
246
|
+
const getResolvedLeftPanelActiveKey = (activeKey, panelState) => {
|
|
247
|
+
if (panelState.availableLeftPanelKeys.includes(activeKey))
|
|
248
|
+
return activeKey;
|
|
249
|
+
return panelState.defaultLeftPanelKey;
|
|
250
|
+
};
|
|
251
|
+
const getSettingsPanelContent = (props) => {
|
|
252
|
+
if (props.SettingsPanel)
|
|
253
|
+
return React.createElement(props.SettingsPanel);
|
|
254
|
+
return props.children;
|
|
255
|
+
};
|
|
256
|
+
const getWorkbenchContentStyle = (workbenchType) => ({
|
|
257
|
+
background: workbenchType === 'JSONTREE' ? '#1e1e1e' : '#f4f7fb',
|
|
258
|
+
minHeight: 0,
|
|
259
|
+
minWidth: 0,
|
|
260
|
+
overflow: 'hidden',
|
|
261
|
+
padding: workbenchType === 'DESIGNABLE' ? 12 : 0,
|
|
262
|
+
});
|
|
263
|
+
const getWorkbenchViewportShellStyle = (workbenchType) => {
|
|
264
|
+
const isDesignView = workbenchType === 'DESIGNABLE';
|
|
265
|
+
return {
|
|
266
|
+
background: isDesignView ? '#fff' : 'transparent',
|
|
267
|
+
border: isDesignView ? '1px solid #dfe7f1' : 0,
|
|
268
|
+
borderRadius: isDesignView ? 10 : 0,
|
|
269
|
+
boxShadow: isDesignView ? '0 10px 28px rgba(15, 23, 42, 0.06)' : 'none',
|
|
270
|
+
height: '100%',
|
|
271
|
+
minHeight: 0,
|
|
272
|
+
overflow: 'hidden',
|
|
273
|
+
};
|
|
274
|
+
};
|
|
275
|
+
const WorkbenchContent = observer((props) => {
|
|
276
|
+
const { onError, } = props;
|
|
277
|
+
const tree = useTree();
|
|
278
|
+
const operation = useOperation();
|
|
279
|
+
const designer = useDesigner();
|
|
280
|
+
const { engine, getSchema, setSchema, validateSchemaEditorSchema, viewType, } = usePlaygroundContext();
|
|
281
|
+
const workbenchType = playgroundViewToWorkbenchType(viewType);
|
|
282
|
+
const { schemaDraftValue, setSchemaDraftValue } = useSchemaEditorDraft(getSchema, workbenchType === 'JSONTREE');
|
|
283
|
+
const workbenchResetSchemaFingerprint = createSchemaFingerprint(getSchema);
|
|
284
|
+
const workbenchResetKey = `${workbenchType}:${workbenchResetSchemaFingerprint ?? 'schema-unavailable'}`;
|
|
285
|
+
const notifyWorkbenchRenderError = React.useCallback((error) => {
|
|
286
|
+
try {
|
|
287
|
+
onError?.(error, { engine, type: 'layout:workbench:render' });
|
|
288
|
+
}
|
|
289
|
+
catch {
|
|
290
|
+
}
|
|
291
|
+
}, [engine, onError]);
|
|
292
|
+
const notifyNodeRenderError = React.useCallback((error, context) => {
|
|
293
|
+
try {
|
|
294
|
+
onError?.(error, {
|
|
295
|
+
engine,
|
|
296
|
+
type: 'layout:component-node:render',
|
|
297
|
+
...context,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
}
|
|
302
|
+
}, [engine, onError]);
|
|
303
|
+
const applySchemaEditorTree = (newTree) => {
|
|
304
|
+
const nextSchema = toSchemaEditorValue(newTree);
|
|
305
|
+
try {
|
|
306
|
+
validateSchemaEditorSchema?.(nextSchema);
|
|
307
|
+
}
|
|
308
|
+
catch (error) {
|
|
309
|
+
try {
|
|
310
|
+
onError?.(error, { engine, type: 'update:tree:schema' });
|
|
311
|
+
}
|
|
312
|
+
catch {
|
|
313
|
+
}
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
return setSchema(nextSchema, { snapshotType: 'update:tree:schema' });
|
|
317
|
+
};
|
|
318
|
+
useDesignableDragReset({
|
|
319
|
+
designer,
|
|
320
|
+
operation,
|
|
321
|
+
workbenchType,
|
|
322
|
+
});
|
|
323
|
+
const panelState = useWorkbenchPanelState(props, workbenchType);
|
|
324
|
+
const { resizeByKeyboard: resizeLeftPanelByKeyboard, startResize: startLeftPanelResize, width: leftPanelWidth, } = useResizablePanelWidth({
|
|
325
|
+
direction: 'left',
|
|
326
|
+
initialWidth: panelState.leftPanelWidth,
|
|
327
|
+
maxWidth: LEFT_PANEL_MAX_WIDTH,
|
|
328
|
+
minWidth: LEFT_PANEL_MIN_WIDTH,
|
|
329
|
+
});
|
|
330
|
+
const { resizeByKeyboard: resizeRightPanelByKeyboard, startResize: startRightPanelResize, width: rightPanelWidth, } = useResizablePanelWidth({
|
|
331
|
+
direction: 'right',
|
|
332
|
+
initialWidth: panelState.rightPanelWidth,
|
|
333
|
+
maxWidth: RIGHT_PANEL_MAX_WIDTH,
|
|
334
|
+
minWidth: RIGHT_PANEL_MIN_WIDTH,
|
|
335
|
+
});
|
|
336
|
+
const [leftPanelActiveKey, setLeftPanelActiveKey] = React.useState(panelState.defaultLeftPanelKey);
|
|
337
|
+
const resolvedLeftPanelActiveKey = getResolvedLeftPanelActiveKey(leftPanelActiveKey, panelState);
|
|
338
|
+
const settingsPanelContent = getSettingsPanelContent(props);
|
|
339
|
+
React.useEffect(() => {
|
|
340
|
+
if (panelState.availableLeftPanelKeys.includes(leftPanelActiveKey))
|
|
341
|
+
return;
|
|
342
|
+
setLeftPanelActiveKey(panelState.defaultLeftPanelKey);
|
|
343
|
+
}, [panelState.availableLeftPanelKeys, panelState.defaultLeftPanelKey, leftPanelActiveKey]);
|
|
344
|
+
return (_jsxs(Layout, { "aria-label": "Designable \u5DE5\u4F5C\u533A", "data-testid": "designable-workspace", style: {
|
|
345
|
+
background: '#f4f7fb',
|
|
346
|
+
flex: 1,
|
|
347
|
+
minHeight: 0,
|
|
348
|
+
overflow: 'hidden',
|
|
349
|
+
}, children: [_jsx(WorkbenchLeftPanel, { activeKey: resolvedLeftPanelActiveKey, defaultActiveKey: panelState.defaultLeftPanelKey, panelState: panelState, resourcePanelProps: props.resourcePanelProps, width: leftPanelWidth, workbenchType: workbenchType, onChange: setLeftPanelActiveKey, onError: (error, type) => {
|
|
350
|
+
try {
|
|
351
|
+
onError?.(error, { engine, type });
|
|
352
|
+
}
|
|
353
|
+
catch {
|
|
354
|
+
}
|
|
355
|
+
}, onKeyboardResize: resizeLeftPanelByKeyboard, onResizeStart: startLeftPanelResize }), _jsx(Content, { "aria-label": "\u8BBE\u8BA1\u5668\u753B\u5E03\u533A\u57DF", "data-testid": "designable-center-panel", style: getWorkbenchContentStyle(workbenchType), children: _jsx("div", { style: getWorkbenchViewportShellStyle(workbenchType), children: _jsx(WorkbenchViewErrorBoundary, { resetKey: workbenchResetKey, onError: notifyWorkbenchRenderError, children: _jsx(WorkbenchMainContent, { getSchema: getSchema, schemaDraftValue: schemaDraftValue, schemaEditorReadonly: props.schemaEditorReadonly, tree: tree, workbenchType: workbenchType, onNodeRenderError: notifyNodeRenderError, onSchemaDraftChange: setSchemaDraftValue, onSchemaTreeChange: applySchemaEditorTree }) }) }) }), _jsx(WorkbenchRightPanel, { panelState: panelState, width: rightPanelWidth, onError: (error) => {
|
|
356
|
+
try {
|
|
357
|
+
onError?.(error, { engine, type: 'layout:settings-panel:render' });
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
}
|
|
361
|
+
}, onKeyboardResize: resizeRightPanelByKeyboard, onResizeStart: startRightPanelResize, children: settingsPanelContent })] }));
|
|
362
|
+
});
|
|
363
|
+
WorkbenchContent.displayName = 'WorkbenchContent';
|
|
364
|
+
const SyncedViewToolsWidget = ({ availableViews }) => {
|
|
365
|
+
const { setViewType, viewType } = usePlaygroundContext();
|
|
366
|
+
const allowedViews = getAllowedViews(availableViews);
|
|
367
|
+
const use = React.useMemo(() => (allowedViews
|
|
368
|
+
? playgroundViewsToWorkbenchTypes(allowedViews)
|
|
369
|
+
: ['DESIGNABLE', 'JSONTREE', 'MARKUP', 'PREVIEW']), [allowedViews]);
|
|
370
|
+
const activeType = playgroundViewToWorkbenchType(viewType);
|
|
371
|
+
return (_jsx(ViewToolsWidget, { activeType: activeType, syncWorkbench: false, use: use, onChange: (type) => {
|
|
372
|
+
const nextViewType = workbenchTypeToPlaygroundView(type);
|
|
373
|
+
if (allowedViews && !allowedViews.includes(nextViewType))
|
|
374
|
+
return;
|
|
375
|
+
setViewType(nextViewType);
|
|
376
|
+
} }));
|
|
377
|
+
};
|
|
378
|
+
SyncedViewToolsWidget.displayName = 'SyncedViewToolsWidget';
|
|
379
|
+
const RestrictedViewGuard = ({ availableViews }) => {
|
|
380
|
+
const { setViewType, viewType } = usePlaygroundContext();
|
|
381
|
+
const resolvedView = getResolvedView(viewType, availableViews);
|
|
382
|
+
React.useEffect(() => {
|
|
383
|
+
if (!resolvedView || resolvedView === viewType)
|
|
384
|
+
return;
|
|
385
|
+
setViewType(resolvedView);
|
|
386
|
+
}, [resolvedView, setViewType, viewType]);
|
|
387
|
+
return null;
|
|
388
|
+
};
|
|
389
|
+
const ReportedToolbarItemErrorBoundary = ({ children, label, onError, resetKey, type, }) => {
|
|
390
|
+
const { engine } = usePlaygroundContext();
|
|
391
|
+
const notifyToolbarError = React.useCallback((error) => {
|
|
392
|
+
try {
|
|
393
|
+
onError?.(error, { engine, type });
|
|
394
|
+
}
|
|
395
|
+
catch {
|
|
396
|
+
}
|
|
397
|
+
}, [engine, onError, type]);
|
|
398
|
+
return (_jsx(ToolbarItemErrorBoundary, { label: label, resetKey: resetKey, onError: notifyToolbarError, children: children }));
|
|
399
|
+
};
|
|
400
|
+
ReportedToolbarItemErrorBoundary.displayName = 'ReportedToolbarItemErrorBoundary';
|
|
401
|
+
const ToolbarPrimaryGroup = ({ logo, onError, visibility }) => {
|
|
402
|
+
if (!logo
|
|
403
|
+
&& !visibility.showDesignerTools
|
|
404
|
+
&& !visibility.showNodeActions
|
|
405
|
+
&& !visibility.showStorageActions) {
|
|
406
|
+
return _jsx("div", {});
|
|
407
|
+
}
|
|
408
|
+
return (_jsxs(Flex, { align: "center", gap: 14, style: { flex: '0 0 auto', minWidth: 'max-content' }, wrap: false, children: [logo && (_jsx(ReportedToolbarItemErrorBoundary, { label: "Logo", resetKey: "toolbar-logo", type: "layout:toolbar-logo:render", onError: onError, children: logo })), visibility.showDesignerTools && (_jsx(ReportedToolbarItemErrorBoundary, { label: "\u8BBE\u8BA1\u5668\u5DE5\u5177", resetKey: "designer-tools", type: "layout:designer-tools:render", onError: onError, children: _jsx(DesignerToolsWidget, { style: { display: 'flex', flex: '0 0 auto' }, use: ['HISTORY', 'CURSOR', 'SCREEN_TYPE'] }) })), visibility.showNodeActions && (_jsx(ReportedToolbarItemErrorBoundary, { label: "\u8282\u70B9\u64CD\u4F5C", resetKey: "node-actions", type: "layout:node-actions:render", onError: onError, children: _jsx(NodeActionsWidget, {}) })), visibility.showStorageActions && (_jsx(ReportedToolbarItemErrorBoundary, { label: "\u5B58\u50A8\u64CD\u4F5C", resetKey: "storage-actions", type: "layout:storage-actions:render", onError: onError, children: _jsx(StorageActionsWidget, {}) }))] }));
|
|
409
|
+
};
|
|
410
|
+
ToolbarPrimaryGroup.displayName = 'ToolbarPrimaryGroup';
|
|
411
|
+
const ToolbarSecondaryGroup = ({ actions, onError, visibility }) => {
|
|
412
|
+
if (!actions && !visibility.showViewTools)
|
|
413
|
+
return _jsx("div", {});
|
|
414
|
+
return (_jsx(ReportedToolbarItemErrorBoundary, { label: "\u89C6\u56FE\u5207\u6362", resetKey: "view-tools", type: "layout:view-tools:render", onError: onError, children: _jsxs(Flex, { align: "center", gap: 10, style: { flex: '0 0 auto' }, wrap: false, children: [actions && (_jsx(ReportedToolbarItemErrorBoundary, { label: "\u6269\u5C55\u64CD\u4F5C", resetKey: "toolbar-actions", type: "layout:toolbar-actions:render", onError: onError, children: actions })), visibility.showViewTools && _jsx(SyncedViewToolsWidget, { availableViews: visibility.availableViews })] }) }));
|
|
415
|
+
};
|
|
416
|
+
ToolbarSecondaryGroup.displayName = 'ToolbarSecondaryGroup';
|
|
417
|
+
const PlaygroundToolbar = ({ actions, logo, onError, visibility, }) => (_jsx(Header, { "aria-label": "\u8BBE\u8BA1\u5668\u5DE5\u5177\u680F", "data-testid": "designable-toolbar", style: {
|
|
418
|
+
background: 'linear-gradient(180deg, #ffffff 0%, #f8fbff 100%)',
|
|
419
|
+
borderBottom: '1px solid #dfe7f1',
|
|
420
|
+
boxShadow: '0 1px 3px rgba(15, 23, 42, 0.04)',
|
|
421
|
+
height: 54,
|
|
422
|
+
lineHeight: 'normal',
|
|
423
|
+
minHeight: 54,
|
|
424
|
+
overflowX: 'auto',
|
|
425
|
+
overflowY: 'hidden',
|
|
426
|
+
padding: '6px 18px',
|
|
427
|
+
zIndex: 2,
|
|
428
|
+
}, children: _jsxs(Flex, { align: "center", gap: 8, justify: "space-between", style: { height: 42, minWidth: 'max-content', width: '100%' }, wrap: false, children: [_jsx(ToolbarPrimaryGroup, { logo: logo, visibility: visibility, onError: onError }), _jsx(ToolbarSecondaryGroup, { actions: actions, visibility: visibility, onError: onError })] }) }));
|
|
429
|
+
PlaygroundToolbar.displayName = 'PlaygroundToolbar';
|
|
430
|
+
function PlaygroundLayoutComponent({ actions, availableViews, defaultView, leftPanelWidth, logo, onError, resourcePanelProps, rightPanelWidth, settingsPanel, showDesignerTools = true, showHistoryPanel, showNodeActions = true, showOutlinePanel, showResourcePanel, showSettingsPanel, showStorageActions = true, showViewTools = true, schemaEditorReadonly, ...props }) {
|
|
431
|
+
const resolvedDefaultView = getResolvedView(defaultView, availableViews);
|
|
432
|
+
const toolbarVisibility = {
|
|
433
|
+
availableViews,
|
|
434
|
+
showDesignerTools,
|
|
435
|
+
showNodeActions,
|
|
436
|
+
showStorageActions,
|
|
437
|
+
showViewTools,
|
|
438
|
+
};
|
|
439
|
+
return (_jsx(Playground, { ...props, defaultView: resolvedDefaultView, onError: onError, children: _jsx(Workbench, { children: _jsxs(Layout, { style: { background: '#f4f7fb', height: '100%', minHeight: 0 }, children: [_jsx(RestrictedViewGuard, { availableViews: availableViews }), _jsx(PlaygroundToolbar, { actions: actions, logo: logo, visibility: toolbarVisibility, onError: onError }), _jsx(WorkbenchContent, { SettingsPanel: settingsPanel, leftPanelWidth: leftPanelWidth, resourcePanelProps: resourcePanelProps, rightPanelWidth: rightPanelWidth, schemaEditorReadonly: schemaEditorReadonly, showHistoryPanel: showHistoryPanel, showOutlinePanel: showOutlinePanel, showResourcePanel: showResourcePanel, showSettingsPanel: showSettingsPanel, onError: onError, children: props.children })] }) }) }));
|
|
440
|
+
}
|
|
441
|
+
export const PlaygroundLayout = Object.assign(PlaygroundLayoutComponent, {
|
|
442
|
+
displayName: 'PlaygroundLayout',
|
|
443
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./PlaygroundLayout/index.js";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./PlaygroundLayout/index.js";
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { observer } from '@formily/reactive-react';
|
|
3
|
+
import { IconWidget, TextWidget } from '@yimoka/designable-react';
|
|
4
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
5
|
+
const CompositePanelItem = () => _jsx(React.Fragment, {});
|
|
6
|
+
CompositePanelItem.displayName = 'CompositePanel.Item';
|
|
7
|
+
const parseItems = (children) => {
|
|
8
|
+
const items = [];
|
|
9
|
+
React.Children.forEach(children, (child, index) => {
|
|
10
|
+
if (React.isValidElement(child) && child.type === CompositePanelItem) {
|
|
11
|
+
items.push({
|
|
12
|
+
...child.props,
|
|
13
|
+
key: child.key ?? String(index),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return items;
|
|
18
|
+
};
|
|
19
|
+
const getDefaultKey = (children) => {
|
|
20
|
+
const items = parseItems(children);
|
|
21
|
+
return items?.[0]?.key;
|
|
22
|
+
};
|
|
23
|
+
const CompositePanelComponent = observer((props) => {
|
|
24
|
+
const [activeKey, setActiveKey] = useState(props.defaultActiveKey ?? getDefaultKey(props.children) ?? '');
|
|
25
|
+
const activeKeyRef = useRef(activeKey);
|
|
26
|
+
const items = useMemo(() => parseItems(props.children), [props.children]);
|
|
27
|
+
const tabItems = useMemo(() => items.map((item) => {
|
|
28
|
+
let iconElement = null;
|
|
29
|
+
if (React.isValidElement(item.icon)) {
|
|
30
|
+
iconElement = item.icon;
|
|
31
|
+
}
|
|
32
|
+
else if (item.icon) {
|
|
33
|
+
iconElement = _jsx(IconWidget, { infer: item.icon });
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
key: String(item.key),
|
|
37
|
+
label: (_jsxs("span", { style: { alignItems: 'center', display: 'inline-flex', gap: 5 }, children: [iconElement, _jsx(TextWidget, { children: item.title })] })),
|
|
38
|
+
children: item.children,
|
|
39
|
+
};
|
|
40
|
+
}), [items]);
|
|
41
|
+
const activeItem = tabItems.find(item => item.key === activeKey) ?? tabItems[0];
|
|
42
|
+
activeKeyRef.current = activeKey;
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
if (props.activeKey !== undefined) {
|
|
45
|
+
if (props.activeKey !== activeKeyRef.current) {
|
|
46
|
+
setActiveKey(props.activeKey);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, [props.activeKey]);
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (props.activeKey !== undefined)
|
|
52
|
+
return;
|
|
53
|
+
if (!tabItems.length) {
|
|
54
|
+
if (activeKeyRef.current) {
|
|
55
|
+
setActiveKey('');
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (tabItems.some(item => item.key === activeKeyRef.current))
|
|
60
|
+
return;
|
|
61
|
+
setActiveKey(tabItems[0].key);
|
|
62
|
+
}, [props.activeKey, tabItems]);
|
|
63
|
+
const handleChange = (key) => {
|
|
64
|
+
if (props.activeKey === undefined) {
|
|
65
|
+
setActiveKey(key);
|
|
66
|
+
}
|
|
67
|
+
props.onChange?.(key);
|
|
68
|
+
};
|
|
69
|
+
const handleTabKeyDown = (event, key) => {
|
|
70
|
+
const currentIndex = tabItems.findIndex(item => item.key === key);
|
|
71
|
+
if (currentIndex < 0)
|
|
72
|
+
return;
|
|
73
|
+
let nextIndex;
|
|
74
|
+
if (event.key === 'ArrowRight') {
|
|
75
|
+
nextIndex = (currentIndex + 1) % tabItems.length;
|
|
76
|
+
}
|
|
77
|
+
else if (event.key === 'ArrowLeft') {
|
|
78
|
+
nextIndex = (currentIndex - 1 + tabItems.length) % tabItems.length;
|
|
79
|
+
}
|
|
80
|
+
else if (event.key === 'Home') {
|
|
81
|
+
nextIndex = 0;
|
|
82
|
+
}
|
|
83
|
+
else if (event.key === 'End') {
|
|
84
|
+
nextIndex = tabItems.length - 1;
|
|
85
|
+
}
|
|
86
|
+
if (nextIndex === undefined)
|
|
87
|
+
return;
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
handleChange(tabItems[nextIndex].key);
|
|
90
|
+
};
|
|
91
|
+
return (_jsxs("div", { className: props.className, style: {
|
|
92
|
+
background: '#fff',
|
|
93
|
+
display: 'flex',
|
|
94
|
+
flexDirection: 'column',
|
|
95
|
+
height: '100%',
|
|
96
|
+
minHeight: 0,
|
|
97
|
+
...props.style,
|
|
98
|
+
}, children: [_jsx("div", { role: "tablist", style: {
|
|
99
|
+
alignItems: 'center',
|
|
100
|
+
borderBottom: '1px solid #e6ebf2',
|
|
101
|
+
display: 'flex',
|
|
102
|
+
flex: '0 0 auto',
|
|
103
|
+
gap: 2,
|
|
104
|
+
justifyContent: 'flex-start',
|
|
105
|
+
overflowX: 'auto',
|
|
106
|
+
padding: '4px 4px 0',
|
|
107
|
+
scrollbarWidth: 'none',
|
|
108
|
+
}, children: tabItems.map((item) => {
|
|
109
|
+
const selected = item.key === activeItem?.key;
|
|
110
|
+
return (_jsx("button", { "aria-selected": selected, role: "tab", style: {
|
|
111
|
+
alignItems: 'center',
|
|
112
|
+
background: selected ? '#eef6ff' : 'transparent',
|
|
113
|
+
border: 0,
|
|
114
|
+
borderBottom: selected ? '2px solid #1677ff' : '2px solid transparent',
|
|
115
|
+
borderRadius: '8px 8px 0 0',
|
|
116
|
+
color: selected ? '#0958d9' : '#5f6b7a',
|
|
117
|
+
cursor: 'pointer',
|
|
118
|
+
display: 'inline-flex',
|
|
119
|
+
flex: '0 0 auto',
|
|
120
|
+
fontSize: 13,
|
|
121
|
+
fontWeight: selected ? 600 : 500,
|
|
122
|
+
height: 30,
|
|
123
|
+
justifyContent: 'center',
|
|
124
|
+
minWidth: 54,
|
|
125
|
+
padding: '0 8px',
|
|
126
|
+
transition: 'all 0.16s ease',
|
|
127
|
+
}, type: "button", onClick: () => handleChange(item.key), onKeyDown: event => handleTabKeyDown(event, item.key), children: item.label }, item.key));
|
|
128
|
+
}) }), _jsx("div", { role: "tabpanel", style: {
|
|
129
|
+
flex: 1,
|
|
130
|
+
minHeight: 0,
|
|
131
|
+
overflow: 'auto',
|
|
132
|
+
overscrollBehavior: 'contain',
|
|
133
|
+
padding: '3px 0 8px',
|
|
134
|
+
}, children: activeItem?.children })] }));
|
|
135
|
+
});
|
|
136
|
+
export const CompositePanel = Object.assign(CompositePanelComponent, {
|
|
137
|
+
Item: CompositePanelItem,
|
|
138
|
+
displayName: 'CompositePanel',
|
|
139
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { observer } from '@formily/reactive-react';
|
|
3
|
+
import { usePrefix } from '@yimoka/designable-react';
|
|
4
|
+
import cls from 'classnames';
|
|
5
|
+
export const ToolbarPanel = observer((props) => {
|
|
6
|
+
const prefix = usePrefix('toolbar-panel');
|
|
7
|
+
return (_jsx("div", { "aria-label": "\u8BBE\u8BA1\u5668\u5DE5\u5177\u680F", className: cls(prefix, props.className), role: "toolbar", style: {
|
|
8
|
+
alignItems: 'center',
|
|
9
|
+
background: 'linear-gradient(180deg, #ffffff 0%, #f8fbff 100%)',
|
|
10
|
+
borderBottom: '1px solid #dfe7f1',
|
|
11
|
+
boxSizing: 'border-box',
|
|
12
|
+
display: 'flex',
|
|
13
|
+
gap: 12,
|
|
14
|
+
justifyContent: 'space-between',
|
|
15
|
+
minHeight: 54,
|
|
16
|
+
minWidth: 0,
|
|
17
|
+
overflowX: 'auto',
|
|
18
|
+
overflowY: 'hidden',
|
|
19
|
+
padding: '0 18px',
|
|
20
|
+
whiteSpace: 'nowrap',
|
|
21
|
+
...props.style,
|
|
22
|
+
}, children: props.children }));
|
|
23
|
+
});
|
|
24
|
+
ToolbarPanel.displayName = 'ToolbarPanel';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { DnComponentRegistryItem } from '@yimoka/designable-react';
|
|
2
|
+
import { type IFormilySchemaInput } from "../transformers/index.js";
|
|
3
|
+
import type { IComponentCategory, ISchemaTransformer } from "../types.js";
|
|
4
|
+
export declare const antdPlaygroundComponents: Record<string, DnComponentRegistryItem>;
|
|
5
|
+
declare const ANTD_PLAYGROUND_CATEGORIES: IComponentCategory[];
|
|
6
|
+
export { ANTD_PLAYGROUND_CATEGORIES as antdPlaygroundCategories };
|
|
7
|
+
export declare const createAntdPlaygroundTransformer: () => ISchemaTransformer<IFormilySchemaInput>;
|
|
8
|
+
export declare const createAntdPlaygroundPreset: () => {
|
|
9
|
+
categories: {
|
|
10
|
+
components: string[];
|
|
11
|
+
key: string;
|
|
12
|
+
title: string;
|
|
13
|
+
icon?: import("react").ReactNode;
|
|
14
|
+
}[];
|
|
15
|
+
components: {
|
|
16
|
+
[x: string]: DnComponentRegistryItem;
|
|
17
|
+
};
|
|
18
|
+
transformer: ISchemaTransformer<IFormilySchemaInput>;
|
|
19
|
+
};
|