@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,284 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { CopyOutlined, DeleteOutlined, DownloadOutlined, FolderOpenOutlined, SaveOutlined, SnippetsOutlined, UploadOutlined, } from '@ant-design/icons';
|
|
3
|
+
import { observer } from '@formily/reactive-react';
|
|
4
|
+
import { IconWidget, usePrefix, useUIAdapter, } from '@yimoka/designable-react';
|
|
5
|
+
import cls from 'classnames';
|
|
6
|
+
import React, { useRef, useState } from 'react';
|
|
7
|
+
import { usePlaygroundContext } from "../../context.js";
|
|
8
|
+
import { copyTextToClipboard, readTextFromClipboard } from "../../shared/clipboard.js";
|
|
9
|
+
const readFileAsText = (file) => new Promise((resolve, reject) => {
|
|
10
|
+
if (typeof FileReader === 'undefined') {
|
|
11
|
+
reject(new Error('当前浏览器不支持读取本地文件'));
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const reader = new FileReader();
|
|
15
|
+
reader.onerror = () => reject(reader.error ?? new Error('读取文件失败'));
|
|
16
|
+
reader.onload = () => resolve(String(reader.result ?? ''));
|
|
17
|
+
try {
|
|
18
|
+
reader.readAsText(file);
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
reject(error);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
25
|
+
const createExportFileName = (date = new Date()) => (`designable-schema-${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}-${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}.json`);
|
|
26
|
+
const isJsonFile = (file) => (file.type === 'application/json'
|
|
27
|
+
|| file.name.toLowerCase().endsWith('.json'));
|
|
28
|
+
const getErrorText = (error) => {
|
|
29
|
+
if (error instanceof Error)
|
|
30
|
+
return error.message;
|
|
31
|
+
if (typeof error === 'string')
|
|
32
|
+
return error;
|
|
33
|
+
return '未知错误';
|
|
34
|
+
};
|
|
35
|
+
const createFailureStatus = (fallback, lastError) => {
|
|
36
|
+
if (!lastError)
|
|
37
|
+
return fallback;
|
|
38
|
+
const message = getErrorText(lastError.error).trim();
|
|
39
|
+
if (!message)
|
|
40
|
+
return fallback;
|
|
41
|
+
return `${fallback}:${message}`;
|
|
42
|
+
};
|
|
43
|
+
const CLEAR_CONFIRM_TIMEOUT = 4000;
|
|
44
|
+
const MAX_IMPORT_CONTENT_LENGTH = 5 * 1024 * 1024;
|
|
45
|
+
const MAX_IMPORT_FILE_SIZE_TEXT = '5MB';
|
|
46
|
+
const revokeObjectUrlSoon = (url) => {
|
|
47
|
+
if (typeof URL.revokeObjectURL !== 'function')
|
|
48
|
+
return;
|
|
49
|
+
window.setTimeout(() => {
|
|
50
|
+
URL.revokeObjectURL(url);
|
|
51
|
+
}, 0);
|
|
52
|
+
};
|
|
53
|
+
const isImportContentTooLarge = (content) => content.length > MAX_IMPORT_CONTENT_LENGTH;
|
|
54
|
+
const getImportTooLargeMessage = () => (`JSON 内容超过 ${MAX_IMPORT_FILE_SIZE_TEXT},请拆分或精简后再导入`);
|
|
55
|
+
export const StorageActionsWidget = observer((props) => {
|
|
56
|
+
const { Button, ButtonGroup, Tooltip } = useUIAdapter();
|
|
57
|
+
const { tryExportDesign, importDesign, loadDesign, saveDesign, clearDesign, getLastError, storageEnabled = true, } = usePlaygroundContext();
|
|
58
|
+
const prefix = usePrefix('storage-actions');
|
|
59
|
+
const inputRef = useRef(null);
|
|
60
|
+
const clearConfirmTimerRef = useRef(null);
|
|
61
|
+
const importTaskIdRef = useRef(0);
|
|
62
|
+
const copyTaskIdRef = useRef(0);
|
|
63
|
+
const mountedRef = useRef(true);
|
|
64
|
+
const [status, setStatus] = useState('');
|
|
65
|
+
const [pendingClear, setPendingClear] = useState(false);
|
|
66
|
+
const resetClearConfirmTimer = () => {
|
|
67
|
+
if (clearConfirmTimerRef.current === null)
|
|
68
|
+
return;
|
|
69
|
+
window.clearTimeout(clearConfirmTimerRef.current);
|
|
70
|
+
clearConfirmTimerRef.current = null;
|
|
71
|
+
};
|
|
72
|
+
React.useEffect(() => () => {
|
|
73
|
+
mountedRef.current = false;
|
|
74
|
+
importTaskIdRef.current += 1;
|
|
75
|
+
copyTaskIdRef.current += 1;
|
|
76
|
+
resetClearConfirmTimer();
|
|
77
|
+
}, []);
|
|
78
|
+
const isCurrentImportTask = (importTaskId) => (mountedRef.current && importTaskIdRef.current === importTaskId);
|
|
79
|
+
const isCurrentCopyTask = (copyTaskId) => (mountedRef.current && copyTaskIdRef.current === copyTaskId);
|
|
80
|
+
const cancelCopyTask = () => {
|
|
81
|
+
copyTaskIdRef.current += 1;
|
|
82
|
+
};
|
|
83
|
+
const cancelImportTask = () => {
|
|
84
|
+
importTaskIdRef.current += 1;
|
|
85
|
+
};
|
|
86
|
+
const exitClearConfirm = () => {
|
|
87
|
+
resetClearConfirmTimer();
|
|
88
|
+
setPendingClear(false);
|
|
89
|
+
};
|
|
90
|
+
const handleSave = () => {
|
|
91
|
+
cancelCopyTask();
|
|
92
|
+
cancelImportTask();
|
|
93
|
+
exitClearConfirm();
|
|
94
|
+
setStatus(saveDesign() ? '已保存' : createFailureStatus('保存失败', getLastError?.()));
|
|
95
|
+
};
|
|
96
|
+
const handleLoad = () => {
|
|
97
|
+
cancelCopyTask();
|
|
98
|
+
cancelImportTask();
|
|
99
|
+
exitClearConfirm();
|
|
100
|
+
const loaded = loadDesign();
|
|
101
|
+
if (loaded) {
|
|
102
|
+
setStatus('已加载');
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const lastError = getLastError?.();
|
|
106
|
+
setStatus(lastError ? createFailureStatus('加载失败', lastError) : '没有可加载的设计');
|
|
107
|
+
};
|
|
108
|
+
const handleClear = () => {
|
|
109
|
+
cancelCopyTask();
|
|
110
|
+
cancelImportTask();
|
|
111
|
+
if (!pendingClear) {
|
|
112
|
+
setPendingClear(true);
|
|
113
|
+
setStatus('再次点击确认清空画布');
|
|
114
|
+
resetClearConfirmTimer();
|
|
115
|
+
clearConfirmTimerRef.current = window.setTimeout(() => {
|
|
116
|
+
clearConfirmTimerRef.current = null;
|
|
117
|
+
setPendingClear(false);
|
|
118
|
+
setStatus('');
|
|
119
|
+
}, CLEAR_CONFIRM_TIMEOUT);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
exitClearConfirm();
|
|
123
|
+
setStatus(clearDesign() ? '已清空画布' : createFailureStatus('清空失败', getLastError?.()));
|
|
124
|
+
};
|
|
125
|
+
const handleExport = () => {
|
|
126
|
+
try {
|
|
127
|
+
cancelCopyTask();
|
|
128
|
+
cancelImportTask();
|
|
129
|
+
exitClearConfirm();
|
|
130
|
+
const exported = tryExportDesign();
|
|
131
|
+
if (exported === null) {
|
|
132
|
+
setStatus(createFailureStatus('导出失败', getLastError?.()));
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
let url = null;
|
|
136
|
+
let anchor = null;
|
|
137
|
+
const blob = new Blob([exported], { type: 'application/json' });
|
|
138
|
+
try {
|
|
139
|
+
url = URL.createObjectURL(blob);
|
|
140
|
+
anchor = document.createElement('a');
|
|
141
|
+
anchor.download = createExportFileName();
|
|
142
|
+
anchor.href = url;
|
|
143
|
+
anchor.style.display = 'none';
|
|
144
|
+
document.body.append(anchor);
|
|
145
|
+
anchor.click();
|
|
146
|
+
}
|
|
147
|
+
finally {
|
|
148
|
+
anchor?.remove();
|
|
149
|
+
if (url) {
|
|
150
|
+
revokeObjectUrlSoon(url);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
setStatus('已导出 JSON');
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
setStatus(`导出失败:${getErrorText(error)}`);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
const handleCopyExport = async () => {
|
|
160
|
+
cancelImportTask();
|
|
161
|
+
exitClearConfirm();
|
|
162
|
+
const copyTaskId = copyTaskIdRef.current + 1;
|
|
163
|
+
copyTaskIdRef.current = copyTaskId;
|
|
164
|
+
try {
|
|
165
|
+
const exported = tryExportDesign();
|
|
166
|
+
if (exported === null) {
|
|
167
|
+
setStatus(createFailureStatus('复制失败', getLastError?.()));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
setStatus('正在复制 JSON...');
|
|
171
|
+
await copyTextToClipboard(exported);
|
|
172
|
+
if (!isCurrentCopyTask(copyTaskId))
|
|
173
|
+
return;
|
|
174
|
+
setStatus('已复制 JSON');
|
|
175
|
+
}
|
|
176
|
+
catch (error) {
|
|
177
|
+
if (!isCurrentCopyTask(copyTaskId))
|
|
178
|
+
return;
|
|
179
|
+
setStatus(`复制失败:${getErrorText(error)}`);
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
const handleImport = (event) => {
|
|
183
|
+
cancelCopyTask();
|
|
184
|
+
exitClearConfirm();
|
|
185
|
+
const input = event.currentTarget;
|
|
186
|
+
const file = input.files?.[0];
|
|
187
|
+
input.value = '';
|
|
188
|
+
if (!file)
|
|
189
|
+
return;
|
|
190
|
+
const importTaskId = importTaskIdRef.current + 1;
|
|
191
|
+
importTaskIdRef.current = importTaskId;
|
|
192
|
+
if (!isJsonFile(file)) {
|
|
193
|
+
setStatus('请选择 JSON 文件');
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (file.size > MAX_IMPORT_CONTENT_LENGTH) {
|
|
197
|
+
setStatus(getImportTooLargeMessage());
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
setStatus('正在读取 JSON...');
|
|
201
|
+
readFileAsText(file)
|
|
202
|
+
.then((content) => {
|
|
203
|
+
if (!isCurrentImportTask(importTaskId))
|
|
204
|
+
return;
|
|
205
|
+
if (!content.trim()) {
|
|
206
|
+
setStatus('JSON 文件为空');
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
if (isImportContentTooLarge(content)) {
|
|
210
|
+
setStatus(getImportTooLargeMessage());
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
setStatus(importDesign(content) ? '已导入 JSON' : createFailureStatus('导入失败', getLastError?.()));
|
|
214
|
+
})
|
|
215
|
+
.catch((error) => {
|
|
216
|
+
if (!isCurrentImportTask(importTaskId))
|
|
217
|
+
return;
|
|
218
|
+
setStatus(`导入失败:${getErrorText(error)}`);
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
const handleImportClick = () => {
|
|
222
|
+
cancelCopyTask();
|
|
223
|
+
exitClearConfirm();
|
|
224
|
+
cancelImportTask();
|
|
225
|
+
setStatus('');
|
|
226
|
+
if (inputRef.current) {
|
|
227
|
+
inputRef.current.value = '';
|
|
228
|
+
}
|
|
229
|
+
inputRef.current?.click();
|
|
230
|
+
};
|
|
231
|
+
const handlePasteImport = async () => {
|
|
232
|
+
cancelCopyTask();
|
|
233
|
+
exitClearConfirm();
|
|
234
|
+
const importTaskId = importTaskIdRef.current + 1;
|
|
235
|
+
importTaskIdRef.current = importTaskId;
|
|
236
|
+
setStatus('正在读取剪贴板...');
|
|
237
|
+
try {
|
|
238
|
+
const content = await readTextFromClipboard();
|
|
239
|
+
if (!isCurrentImportTask(importTaskId))
|
|
240
|
+
return;
|
|
241
|
+
if (!content.trim()) {
|
|
242
|
+
setStatus('剪贴板为空');
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (isImportContentTooLarge(content)) {
|
|
246
|
+
setStatus(getImportTooLargeMessage());
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
setStatus(importDesign(content) ? '已从剪贴板导入 JSON' : createFailureStatus('导入失败', getLastError?.()));
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
if (!isCurrentImportTask(importTaskId))
|
|
253
|
+
return;
|
|
254
|
+
setStatus(`导入失败:${getErrorText(error)}`);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
return (_jsxs("div", { className: cls(prefix, props.className), style: {
|
|
258
|
+
alignItems: 'center',
|
|
259
|
+
display: 'inline-flex',
|
|
260
|
+
gap: 8,
|
|
261
|
+
minWidth: 0,
|
|
262
|
+
...props.style,
|
|
263
|
+
}, children: [_jsxs(ButtonGroup, { size: "small", style: {
|
|
264
|
+
flex: '0 0 auto',
|
|
265
|
+
}, children: [_jsx(Tooltip, { title: "\u4FDD\u5B58", children: _jsx(Button, { ariaLabel: "\u4FDD\u5B58\u8BBE\u8BA1", disabled: !storageEnabled, onClick: handleSave, children: _jsx(IconWidget, { infer: _jsx(SaveOutlined, {}) }) }) }), _jsx(Tooltip, { title: "\u52A0\u8F7D", children: _jsx(Button, { ariaLabel: "\u52A0\u8F7D\u8BBE\u8BA1", disabled: !storageEnabled, onClick: handleLoad, children: _jsx(IconWidget, { infer: _jsx(FolderOpenOutlined, {}) }) }) }), _jsx(Tooltip, { title: pendingClear ? '确认清空画布' : '清空画布', children: _jsx(Button, { ariaLabel: pendingClear ? '确认清空画布' : '清空画布', onClick: handleClear, children: _jsx(IconWidget, { infer: _jsx(DeleteOutlined, {}) }) }) }), _jsx(Tooltip, { title: "\u5BFC\u51FA JSON", children: _jsx(Button, { ariaLabel: "\u5BFC\u51FA JSON", onClick: handleExport, children: _jsx(IconWidget, { infer: _jsx(DownloadOutlined, {}) }) }) }), _jsx(Tooltip, { title: "\u590D\u5236 JSON", children: _jsx(Button, { ariaLabel: "\u590D\u5236 JSON", onClick: handleCopyExport, children: _jsx(IconWidget, { infer: _jsx(CopyOutlined, {}) }) }) }), _jsx(Tooltip, { title: "\u7C98\u8D34\u5BFC\u5165 JSON", children: _jsx(Button, { ariaLabel: "\u7C98\u8D34\u5BFC\u5165 JSON", onClick: handlePasteImport, children: _jsx(IconWidget, { infer: _jsx(SnippetsOutlined, {}) }) }) }), _jsx(Tooltip, { title: "\u5BFC\u5165 JSON", children: _jsx(Button, { ariaLabel: "\u5BFC\u5165 JSON", onClick: handleImportClick, children: _jsx(IconWidget, { infer: _jsx(UploadOutlined, {}) }) }) })] }), _jsx("input", { ref: inputRef, accept: "application/json,.json", style: { display: 'none' }, type: "file", onChange: handleImport }), _jsx("span", { "aria-live": "polite", className: `${prefix}-status`, role: "status", style: {
|
|
266
|
+
background: status ? '#f6faff' : 'transparent',
|
|
267
|
+
border: `1px solid ${status ? '#d6e8ff' : 'transparent'}`,
|
|
268
|
+
borderRadius: 999,
|
|
269
|
+
boxSizing: 'border-box',
|
|
270
|
+
color: status ? '#31506f' : '#8c98a8',
|
|
271
|
+
display: 'inline-block',
|
|
272
|
+
flex: '0 1 150px',
|
|
273
|
+
fontSize: 11,
|
|
274
|
+
lineHeight: '20px',
|
|
275
|
+
maxWidth: 150,
|
|
276
|
+
minHeight: 22,
|
|
277
|
+
minWidth: 92,
|
|
278
|
+
overflow: 'hidden',
|
|
279
|
+
padding: status ? '0 8px' : '0',
|
|
280
|
+
textOverflow: 'ellipsis',
|
|
281
|
+
whiteSpace: 'nowrap',
|
|
282
|
+
}, title: status || undefined, children: status })] }));
|
|
283
|
+
});
|
|
284
|
+
StorageActionsWidget.displayName = 'StorageActionsWidget';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./ResourceWidget/index.js";
|
|
2
|
+
export * from "./ComponentTreeWidget/index.js";
|
|
3
|
+
export * from "./OutlineTreeWidget/index.js";
|
|
4
|
+
export * from "./SettingsPanelWidget/index.js";
|
|
5
|
+
export * from "./SchemaEditorWidget/index.js";
|
|
6
|
+
export * from "./SchemaCodeView/index.js";
|
|
7
|
+
export * from "./PreviewWidget/index.js";
|
|
8
|
+
export * from "./ActionsWidget/index.js";
|
|
9
|
+
export * from "./NodeActionsWidget/index.js";
|
|
10
|
+
export * from "./StorageActionsWidget/index.js";
|
|
11
|
+
export * from "./RemotePersistenceStatusWidget/index.js";
|
|
12
|
+
export * from "./RemoteVersionHistoryWidget/index.js";
|
|
13
|
+
export * from "./ProductionReadinessWidget/index.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export * from "./ResourceWidget/index.js";
|
|
2
|
+
export * from "./ComponentTreeWidget/index.js";
|
|
3
|
+
export * from "./OutlineTreeWidget/index.js";
|
|
4
|
+
export * from "./SettingsPanelWidget/index.js";
|
|
5
|
+
export * from "./SchemaEditorWidget/index.js";
|
|
6
|
+
export * from "./SchemaCodeView/index.js";
|
|
7
|
+
export * from "./PreviewWidget/index.js";
|
|
8
|
+
export * from "./ActionsWidget/index.js";
|
|
9
|
+
export * from "./NodeActionsWidget/index.js";
|
|
10
|
+
export * from "./StorageActionsWidget/index.js";
|
|
11
|
+
export * from "./RemotePersistenceStatusWidget/index.js";
|
|
12
|
+
export * from "./RemoteVersionHistoryWidget/index.js";
|
|
13
|
+
export * from "./ProductionReadinessWidget/index.js";
|
package/package.json
CHANGED
|
@@ -1,6 +1,102 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yimoka/designable-playground",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "通用的可视化设计器 Playground,支持组件注入",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "ickeep <i@ickeep.com>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/zhixingdx/oipivot.git",
|
|
10
|
+
"directory": "frontend/packages/designable-playground"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"designable",
|
|
14
|
+
"playground",
|
|
15
|
+
"low-code",
|
|
16
|
+
"visual-editor",
|
|
17
|
+
"component-injection"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"@ant-design/icons": "^6.2.5",
|
|
23
|
+
"@formily/react": "^2.3.7",
|
|
24
|
+
"@formily/reactive": "^2.3.7",
|
|
25
|
+
"@formily/reactive-react": "^2.3.7",
|
|
26
|
+
"@monaco-editor/loader": "^1.7.0",
|
|
27
|
+
"@monaco-editor/react": "^4.7.0",
|
|
28
|
+
"@yimoka/antd": "0.1.1",
|
|
29
|
+
"@yimoka/designable-antd": "0.1.1",
|
|
30
|
+
"@yimoka/designable-core": "0.1.1",
|
|
31
|
+
"@yimoka/designable-react": "0.1.1",
|
|
32
|
+
"@yimoka/react": "0.1.1",
|
|
33
|
+
"@yimoka/store": "0.1.1",
|
|
34
|
+
"antd": "^6.4.5",
|
|
35
|
+
"classnames": "^2.5.1",
|
|
36
|
+
"lodash-es": "^4.18.1"
|
|
37
|
+
},
|
|
38
|
+
"peerDependencies": {
|
|
39
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
40
|
+
"react-dom": "^18.0.0 || ^19.0.0"
|
|
41
|
+
},
|
|
42
|
+
"exports": {
|
|
43
|
+
".": {
|
|
44
|
+
"types": "./dist/src/index.d.ts",
|
|
45
|
+
"import": "./dist/src/index.js",
|
|
46
|
+
"default": "./dist/src/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./antd": {
|
|
49
|
+
"types": "./dist/src/antd/index.d.ts",
|
|
50
|
+
"import": "./dist/src/antd/index.js",
|
|
51
|
+
"default": "./dist/src/antd/index.js"
|
|
52
|
+
},
|
|
53
|
+
"./examples": {
|
|
54
|
+
"types": "./dist/src/examples/index.d.ts",
|
|
55
|
+
"import": "./dist/src/examples/index.js",
|
|
56
|
+
"default": "./dist/src/examples/index.js"
|
|
57
|
+
},
|
|
58
|
+
"./hooks": {
|
|
59
|
+
"types": "./dist/src/hooks/index.d.ts",
|
|
60
|
+
"import": "./dist/src/hooks/index.js",
|
|
61
|
+
"default": "./dist/src/hooks/index.js"
|
|
62
|
+
},
|
|
63
|
+
"./layouts": {
|
|
64
|
+
"types": "./dist/src/layouts/index.d.ts",
|
|
65
|
+
"import": "./dist/src/layouts/index.js",
|
|
66
|
+
"default": "./dist/src/layouts/index.js"
|
|
67
|
+
},
|
|
68
|
+
"./panels": {
|
|
69
|
+
"types": "./dist/src/panels/index.d.ts",
|
|
70
|
+
"import": "./dist/src/panels/index.js",
|
|
71
|
+
"default": "./dist/src/panels/index.js"
|
|
72
|
+
},
|
|
73
|
+
"./presets": {
|
|
74
|
+
"types": "./dist/src/presets/index.d.ts",
|
|
75
|
+
"import": "./dist/src/presets/index.js",
|
|
76
|
+
"default": "./dist/src/presets/index.js"
|
|
77
|
+
},
|
|
78
|
+
"./runtime": {
|
|
79
|
+
"types": "./dist/src/runtime/index.d.ts",
|
|
80
|
+
"import": "./dist/src/runtime/index.js",
|
|
81
|
+
"default": "./dist/src/runtime/index.js"
|
|
82
|
+
},
|
|
83
|
+
"./shared": {
|
|
84
|
+
"types": "./dist/src/shared/index.d.ts",
|
|
85
|
+
"import": "./dist/src/shared/index.js",
|
|
86
|
+
"default": "./dist/src/shared/index.js"
|
|
87
|
+
},
|
|
88
|
+
"./transformers": {
|
|
89
|
+
"types": "./dist/src/transformers/index.d.ts",
|
|
90
|
+
"import": "./dist/src/transformers/index.js",
|
|
91
|
+
"default": "./dist/src/transformers/index.js"
|
|
92
|
+
},
|
|
93
|
+
"./widgets": {
|
|
94
|
+
"types": "./dist/src/widgets/index.d.ts",
|
|
95
|
+
"import": "./dist/src/widgets/index.js",
|
|
96
|
+
"default": "./dist/src/widgets/index.js"
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"main": "./dist/src/index.js",
|
|
100
|
+
"module": "./dist/src/index.js",
|
|
101
|
+
"types": "./dist/src/index.d.ts"
|
|
102
|
+
}
|