@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,225 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { copyTextToClipboard } from "../../shared/clipboard.js";
|
|
4
|
+
import { stringifySchemaForExport } from "../../shared/schema.js";
|
|
5
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
6
|
+
const createSchemaFileName = (date = new Date()) => (`designable-schema-${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}-${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}.json`);
|
|
7
|
+
const getErrorMessage = (error, fallback = '未知错误') => {
|
|
8
|
+
if (error instanceof Error)
|
|
9
|
+
return error.message;
|
|
10
|
+
if (typeof error === 'string' && error.trim())
|
|
11
|
+
return error;
|
|
12
|
+
return fallback;
|
|
13
|
+
};
|
|
14
|
+
const revokeObjectUrlSoon = (url) => {
|
|
15
|
+
if (typeof URL.revokeObjectURL !== 'function')
|
|
16
|
+
return;
|
|
17
|
+
window.setTimeout(() => {
|
|
18
|
+
URL.revokeObjectURL(url);
|
|
19
|
+
}, 0);
|
|
20
|
+
};
|
|
21
|
+
const createSchemaViewState = (getSchema) => {
|
|
22
|
+
try {
|
|
23
|
+
const schemaText = stringifySchemaForExport(getSchema());
|
|
24
|
+
return {
|
|
25
|
+
canUseSchema: true,
|
|
26
|
+
errorMessage: undefined,
|
|
27
|
+
lineNumberWidth: Math.max(38, String(schemaText.split('\n').length).length * 10 + 20),
|
|
28
|
+
schemaLines: schemaText.split('\n'),
|
|
29
|
+
schemaText,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
const errorMessage = `Schema 生成失败:${getErrorMessage(error)}`;
|
|
34
|
+
return {
|
|
35
|
+
canUseSchema: false,
|
|
36
|
+
errorMessage,
|
|
37
|
+
lineNumberWidth: 38,
|
|
38
|
+
schemaLines: [errorMessage],
|
|
39
|
+
schemaText: errorMessage,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const downloadTextFile = (text, downloadFileName) => {
|
|
44
|
+
let url = null;
|
|
45
|
+
let anchor = null;
|
|
46
|
+
const blob = new Blob([text], { type: 'application/json' });
|
|
47
|
+
try {
|
|
48
|
+
url = URL.createObjectURL(blob);
|
|
49
|
+
anchor = document.createElement('a');
|
|
50
|
+
anchor.download = downloadFileName;
|
|
51
|
+
anchor.href = url;
|
|
52
|
+
anchor.style.display = 'none';
|
|
53
|
+
document.body.append(anchor);
|
|
54
|
+
anchor.click();
|
|
55
|
+
}
|
|
56
|
+
finally {
|
|
57
|
+
anchor?.remove();
|
|
58
|
+
if (url) {
|
|
59
|
+
revokeObjectUrlSoon(url);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
const useSchemaCodeActions = ({ canUseSchema, downloadFileName, errorMessage, schemaText, }) => {
|
|
64
|
+
const statusKey = `${errorMessage ?? ''}\u0000${schemaText}`;
|
|
65
|
+
const [statusState, setStatusState] = React.useState({ key: statusKey, value: '' });
|
|
66
|
+
const actionIdRef = React.useRef(0);
|
|
67
|
+
const mountedRef = React.useRef(true);
|
|
68
|
+
React.useEffect(() => {
|
|
69
|
+
actionIdRef.current += 1;
|
|
70
|
+
}, [errorMessage, schemaText]);
|
|
71
|
+
React.useEffect(() => () => {
|
|
72
|
+
mountedRef.current = false;
|
|
73
|
+
actionIdRef.current += 1;
|
|
74
|
+
}, []);
|
|
75
|
+
const isCurrentAction = React.useCallback((actionId) => (mountedRef.current && actionIdRef.current === actionId), []);
|
|
76
|
+
const createActionId = React.useCallback(() => {
|
|
77
|
+
const actionId = actionIdRef.current + 1;
|
|
78
|
+
actionIdRef.current = actionId;
|
|
79
|
+
return actionId;
|
|
80
|
+
}, []);
|
|
81
|
+
const setCurrentStatus = React.useCallback((value) => {
|
|
82
|
+
setStatusState({ key: statusKey, value });
|
|
83
|
+
}, [statusKey]);
|
|
84
|
+
const copySchema = React.useCallback(async () => {
|
|
85
|
+
if (!canUseSchema)
|
|
86
|
+
return;
|
|
87
|
+
const actionId = createActionId();
|
|
88
|
+
try {
|
|
89
|
+
setCurrentStatus('正在复制 Schema...');
|
|
90
|
+
await copyTextToClipboard(schemaText);
|
|
91
|
+
if (isCurrentAction(actionId)) {
|
|
92
|
+
setCurrentStatus('已复制 Schema');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (isCurrentAction(actionId)) {
|
|
97
|
+
setCurrentStatus(`复制失败:${getErrorMessage(error)}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}, [canUseSchema, createActionId, isCurrentAction, schemaText, setCurrentStatus]);
|
|
101
|
+
const downloadSchema = React.useCallback(() => {
|
|
102
|
+
if (!canUseSchema)
|
|
103
|
+
return;
|
|
104
|
+
const actionId = createActionId();
|
|
105
|
+
try {
|
|
106
|
+
downloadTextFile(schemaText, downloadFileName);
|
|
107
|
+
if (isCurrentAction(actionId)) {
|
|
108
|
+
setCurrentStatus('已下载 JSON');
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (error) {
|
|
112
|
+
if (isCurrentAction(actionId)) {
|
|
113
|
+
setCurrentStatus(`下载失败:${getErrorMessage(error)}`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}, [canUseSchema, createActionId, downloadFileName, isCurrentAction, schemaText, setCurrentStatus]);
|
|
117
|
+
return {
|
|
118
|
+
copySchema,
|
|
119
|
+
downloadSchema,
|
|
120
|
+
status: statusState.key === statusKey ? statusState.value : '',
|
|
121
|
+
};
|
|
122
|
+
};
|
|
123
|
+
const getDisabledDescriptionId = (canUseSchema, errorDescriptionId) => (canUseSchema ? undefined : errorDescriptionId);
|
|
124
|
+
const getStatusColor = (errorMessage) => (errorMessage ? '#cf1322' : '#237804');
|
|
125
|
+
const getCopyButtonStyle = (canUseSchema) => ({
|
|
126
|
+
background: canUseSchema ? '#fff' : '#f5f5f5',
|
|
127
|
+
border: '1px solid #d9d9d9',
|
|
128
|
+
borderRadius: 4,
|
|
129
|
+
color: canUseSchema ? '#4b5563' : '#bfbfbf',
|
|
130
|
+
cursor: canUseSchema ? 'pointer' : 'not-allowed',
|
|
131
|
+
fontSize: 12,
|
|
132
|
+
height: 28,
|
|
133
|
+
padding: '0 10px',
|
|
134
|
+
});
|
|
135
|
+
const getDownloadButtonStyle = (canUseSchema) => ({
|
|
136
|
+
background: canUseSchema ? '#1677ff' : '#f5f5f5',
|
|
137
|
+
border: `1px solid ${canUseSchema ? '#1677ff' : '#d9d9d9'}`,
|
|
138
|
+
borderRadius: 4,
|
|
139
|
+
color: canUseSchema ? '#fff' : '#bfbfbf',
|
|
140
|
+
cursor: canUseSchema ? 'pointer' : 'not-allowed',
|
|
141
|
+
fontSize: 12,
|
|
142
|
+
height: 28,
|
|
143
|
+
padding: '0 10px',
|
|
144
|
+
});
|
|
145
|
+
const SchemaCodeToolbar = ({ canUseSchema, copySchema, downloadSchema, errorDescriptionId, errorMessage, status, }) => (_jsxs("div", { style: {
|
|
146
|
+
alignItems: 'center',
|
|
147
|
+
background: '#fff',
|
|
148
|
+
borderBottom: '1px solid #e6ebf2',
|
|
149
|
+
display: 'flex',
|
|
150
|
+
flex: '0 0 auto',
|
|
151
|
+
gap: 8,
|
|
152
|
+
minHeight: 40,
|
|
153
|
+
padding: '0 12px',
|
|
154
|
+
}, children: [_jsx("span", { style: {
|
|
155
|
+
color: '#4b5563',
|
|
156
|
+
flex: 1,
|
|
157
|
+
fontSize: 12,
|
|
158
|
+
minWidth: 0,
|
|
159
|
+
overflow: 'hidden',
|
|
160
|
+
textOverflow: 'ellipsis',
|
|
161
|
+
whiteSpace: 'nowrap',
|
|
162
|
+
}, children: "\u5F53\u524D\u753B\u5E03 Schema" }), _jsx("span", { "aria-live": "polite", role: "status", style: {
|
|
163
|
+
color: getStatusColor(errorMessage),
|
|
164
|
+
flex: '0 1 auto',
|
|
165
|
+
fontSize: 12,
|
|
166
|
+
minWidth: 0,
|
|
167
|
+
overflow: 'hidden',
|
|
168
|
+
textOverflow: 'ellipsis',
|
|
169
|
+
whiteSpace: 'nowrap',
|
|
170
|
+
}, children: status }), _jsx("button", { "aria-describedby": getDisabledDescriptionId(canUseSchema, errorDescriptionId), disabled: !canUseSchema, style: getCopyButtonStyle(canUseSchema), type: "button", onClick: copySchema, children: "\u590D\u5236" }), _jsx("button", { "aria-describedby": getDisabledDescriptionId(canUseSchema, errorDescriptionId), disabled: !canUseSchema, style: getDownloadButtonStyle(canUseSchema), type: "button", onClick: downloadSchema, children: "\u4E0B\u8F7D JSON" })] }));
|
|
171
|
+
const SchemaCodePanel = ({ errorDescriptionId, errorMessage, lineNumberWidth, schemaLines, }) => (_jsx("div", { "data-testid": "schema-code-panel", id: errorMessage ? errorDescriptionId : undefined, role: errorMessage ? 'alert' : undefined, style: {
|
|
172
|
+
background: '#f8fafc',
|
|
173
|
+
boxSizing: 'border-box',
|
|
174
|
+
flex: 1,
|
|
175
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace',
|
|
176
|
+
fontSize: 12,
|
|
177
|
+
lineHeight: '20px',
|
|
178
|
+
margin: 0,
|
|
179
|
+
minHeight: 0,
|
|
180
|
+
overflow: 'auto',
|
|
181
|
+
padding: '12px 0',
|
|
182
|
+
}, children: _jsx("code", { "data-testid": "schema-code-content", style: {
|
|
183
|
+
color: errorMessage ? '#cf1322' : '#1f2937',
|
|
184
|
+
display: 'grid',
|
|
185
|
+
gridTemplateColumns: `${lineNumberWidth}px max-content`,
|
|
186
|
+
minWidth: '100%',
|
|
187
|
+
whiteSpace: 'pre',
|
|
188
|
+
}, children: schemaLines.map((line, index) => (_jsxs(React.Fragment, { children: [_jsx("span", { "aria-hidden": "true", "data-testid": "schema-code-line-number", style: {
|
|
189
|
+
background: '#f8fafc',
|
|
190
|
+
borderRight: '1px solid #e2e8f0',
|
|
191
|
+
boxSizing: 'border-box',
|
|
192
|
+
color: '#94a3b8',
|
|
193
|
+
padding: '0 10px 0 8px',
|
|
194
|
+
position: 'sticky',
|
|
195
|
+
left: 0,
|
|
196
|
+
textAlign: 'right',
|
|
197
|
+
userSelect: 'none',
|
|
198
|
+
zIndex: 1,
|
|
199
|
+
}, children: index + 1 }), _jsx("span", { "data-testid": "schema-code-line", style: {
|
|
200
|
+
boxSizing: 'border-box',
|
|
201
|
+
minHeight: 20,
|
|
202
|
+
padding: '0 16px',
|
|
203
|
+
whiteSpace: 'pre',
|
|
204
|
+
}, children: line || ' ' })] }, `${index}-${line}`))) }) }));
|
|
205
|
+
export const SchemaCodeView = ({ className, 'data-testid': dataTestId = 'schema-code-view', fileName, getSchema, style, ...props }) => {
|
|
206
|
+
const [defaultFileName] = React.useState(() => createSchemaFileName());
|
|
207
|
+
const errorDescriptionId = React.useId();
|
|
208
|
+
const downloadFileName = fileName ?? defaultFileName;
|
|
209
|
+
const { canUseSchema, errorMessage, lineNumberWidth, schemaLines, schemaText, } = createSchemaViewState(getSchema);
|
|
210
|
+
const { copySchema, downloadSchema, status, } = useSchemaCodeActions({
|
|
211
|
+
canUseSchema,
|
|
212
|
+
downloadFileName,
|
|
213
|
+
errorMessage,
|
|
214
|
+
schemaText,
|
|
215
|
+
});
|
|
216
|
+
return (_jsxs("div", { ...props, "aria-label": "Schema \u4EE3\u7801\u89C6\u56FE", className: className, "data-testid": dataTestId, style: {
|
|
217
|
+
boxSizing: 'border-box',
|
|
218
|
+
display: 'flex',
|
|
219
|
+
flexDirection: 'column',
|
|
220
|
+
height: '100%',
|
|
221
|
+
overflow: 'hidden',
|
|
222
|
+
...style,
|
|
223
|
+
}, children: [_jsx(SchemaCodeToolbar, { canUseSchema: canUseSchema, copySchema: copySchema, downloadSchema: downloadSchema, errorDescriptionId: errorDescriptionId, errorMessage: errorMessage, status: status }), _jsx(SchemaCodePanel, { errorDescriptionId: errorDescriptionId, errorMessage: errorMessage, lineNumberWidth: lineNumberWidth, schemaLines: schemaLines })] }));
|
|
224
|
+
};
|
|
225
|
+
SchemaCodeView.displayName = 'SchemaCodeView';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { ISchemaEditorWidgetProps } from "../../types.js";
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
__designableE2E__?: boolean;
|
|
6
|
+
__designableGetSchemaEditorValue?: () => string;
|
|
7
|
+
__designableSetSchemaEditorValue?: (value: string) => void;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare const SchemaEditorWidget: React.FC<ISchemaEditorWidgetProps>;
|