@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.
Files changed (262) hide show
  1. package/README.md +8 -2
  2. package/dist/demo/components/Alert/index.d.ts +4 -0
  3. package/dist/demo/components/Alert/index.js +41 -0
  4. package/dist/demo/components/ArrayCards/index.d.ts +17 -0
  5. package/dist/demo/components/ArrayCards/index.js +62 -0
  6. package/dist/demo/components/ArrayList/index.d.ts +25 -0
  7. package/dist/demo/components/ArrayList/index.js +143 -0
  8. package/dist/demo/components/ArrayTable/index.d.ts +39 -0
  9. package/dist/demo/components/ArrayTable/index.js +247 -0
  10. package/dist/demo/components/AutoComplete/index.d.ts +4 -0
  11. package/dist/demo/components/AutoComplete/index.js +52 -0
  12. package/dist/demo/components/Avatar/index.d.ts +4 -0
  13. package/dist/demo/components/Avatar/index.js +34 -0
  14. package/dist/demo/components/Badge/index.d.ts +4 -0
  15. package/dist/demo/components/Badge/index.js +35 -0
  16. package/dist/demo/components/Button/index.d.ts +4 -0
  17. package/dist/demo/components/Button/index.js +86 -0
  18. package/dist/demo/components/Card/index.d.ts +4 -0
  19. package/dist/demo/components/Card/index.js +72 -0
  20. package/dist/demo/components/Carousel/index.d.ts +4 -0
  21. package/dist/demo/components/Carousel/index.js +33 -0
  22. package/dist/demo/components/Cascader/index.d.ts +4 -0
  23. package/dist/demo/components/Cascader/index.js +60 -0
  24. package/dist/demo/components/Checkbox/index.d.ts +8 -0
  25. package/dist/demo/components/Checkbox/index.js +55 -0
  26. package/dist/demo/components/ColorPicker/index.d.ts +4 -0
  27. package/dist/demo/components/ColorPicker/index.js +38 -0
  28. package/dist/demo/components/DatePicker/index.d.ts +4 -0
  29. package/dist/demo/components/DatePicker/index.js +61 -0
  30. package/dist/demo/components/DateRangePicker/index.d.ts +4 -0
  31. package/dist/demo/components/DateRangePicker/index.js +58 -0
  32. package/dist/demo/components/Divider/index.d.ts +4 -0
  33. package/dist/demo/components/Divider/index.js +39 -0
  34. package/dist/demo/components/Empty/index.d.ts +4 -0
  35. package/dist/demo/components/Empty/index.js +29 -0
  36. package/dist/demo/components/Flex/index.d.ts +4 -0
  37. package/dist/demo/components/Flex/index.js +51 -0
  38. package/dist/demo/components/Form/index.d.ts +21 -0
  39. package/dist/demo/components/Form/index.js +116 -0
  40. package/dist/demo/components/FormCollapse/index.d.ts +28 -0
  41. package/dist/demo/components/FormCollapse/index.js +164 -0
  42. package/dist/demo/components/FormGrid/index.d.ts +22 -0
  43. package/dist/demo/components/FormGrid/index.js +134 -0
  44. package/dist/demo/components/FormItem/index.d.ts +14 -0
  45. package/dist/demo/components/FormItem/index.js +33 -0
  46. package/dist/demo/components/FormLayout/index.d.ts +26 -0
  47. package/dist/demo/components/FormLayout/index.js +260 -0
  48. package/dist/demo/components/FormTab/index.d.ts +15 -0
  49. package/dist/demo/components/FormTab/index.js +186 -0
  50. package/dist/demo/components/GridCol/index.d.ts +4 -0
  51. package/dist/demo/components/GridCol/index.js +53 -0
  52. package/dist/demo/components/GridRow/index.d.ts +4 -0
  53. package/dist/demo/components/GridRow/index.js +70 -0
  54. package/dist/demo/components/HTMLContent/index.d.ts +4 -0
  55. package/dist/demo/components/HTMLContent/index.js +34 -0
  56. package/dist/demo/components/I18nEditor/index.d.ts +8 -0
  57. package/dist/demo/components/I18nEditor/index.js +64 -0
  58. package/dist/demo/components/Image/index.d.ts +4 -0
  59. package/dist/demo/components/Image/index.js +36 -0
  60. package/dist/demo/components/Input/index.d.ts +4 -0
  61. package/dist/demo/components/Input/index.js +36 -0
  62. package/dist/demo/components/InputSearch/index.d.ts +4 -0
  63. package/dist/demo/components/InputSearch/index.js +40 -0
  64. package/dist/demo/components/Link/index.d.ts +4 -0
  65. package/dist/demo/components/Link/index.js +37 -0
  66. package/dist/demo/components/Mentions/index.d.ts +4 -0
  67. package/dist/demo/components/Mentions/index.js +41 -0
  68. package/dist/demo/components/NumberPicker/index.d.ts +6 -0
  69. package/dist/demo/components/NumberPicker/index.js +63 -0
  70. package/dist/demo/components/ObjectContainer/index.d.ts +14 -0
  71. package/dist/demo/components/ObjectContainer/index.js +46 -0
  72. package/dist/demo/components/Password/index.d.ts +6 -0
  73. package/dist/demo/components/Password/index.js +44 -0
  74. package/dist/demo/components/QRCode/index.d.ts +4 -0
  75. package/dist/demo/components/QRCode/index.js +34 -0
  76. package/dist/demo/components/Radio/index.d.ts +6 -0
  77. package/dist/demo/components/Radio/index.js +49 -0
  78. package/dist/demo/components/Rate/index.d.ts +6 -0
  79. package/dist/demo/components/Rate/index.js +43 -0
  80. package/dist/demo/components/Search/index.d.ts +4 -0
  81. package/dist/demo/components/Search/index.js +42 -0
  82. package/dist/demo/components/SearchSelect/index.d.ts +4 -0
  83. package/dist/demo/components/SearchSelect/index.js +53 -0
  84. package/dist/demo/components/Select/index.d.ts +4 -0
  85. package/dist/demo/components/Select/index.js +59 -0
  86. package/dist/demo/components/Slider/index.d.ts +6 -0
  87. package/dist/demo/components/Slider/index.js +61 -0
  88. package/dist/demo/components/Space/index.d.ts +9 -0
  89. package/dist/demo/components/Space/index.js +61 -0
  90. package/dist/demo/components/Statistic/index.d.ts +4 -0
  91. package/dist/demo/components/Statistic/index.js +33 -0
  92. package/dist/demo/components/Switch/index.d.ts +4 -0
  93. package/dist/demo/components/Switch/index.js +49 -0
  94. package/dist/demo/components/Tabs/index.d.ts +10 -0
  95. package/dist/demo/components/Tabs/index.js +181 -0
  96. package/dist/demo/components/Tag/index.d.ts +4 -0
  97. package/dist/demo/components/Tag/index.js +33 -0
  98. package/dist/demo/components/Text/index.d.ts +11 -0
  99. package/dist/demo/components/Text/index.js +64 -0
  100. package/dist/demo/components/TextArea/index.d.ts +6 -0
  101. package/dist/demo/components/TextArea/index.js +43 -0
  102. package/dist/demo/components/TimePicker/index.d.ts +4 -0
  103. package/dist/demo/components/TimePicker/index.js +69 -0
  104. package/dist/demo/components/TimeRangePicker/index.d.ts +4 -0
  105. package/dist/demo/components/TimeRangePicker/index.js +68 -0
  106. package/dist/demo/components/Transfer/index.d.ts +6 -0
  107. package/dist/demo/components/Transfer/index.js +59 -0
  108. package/dist/demo/components/TreeSelect/index.d.ts +4 -0
  109. package/dist/demo/components/TreeSelect/index.js +63 -0
  110. package/dist/demo/components/Upload/index.d.ts +8 -0
  111. package/dist/demo/components/Upload/index.js +64 -0
  112. package/dist/demo/components/index.d.ts +55 -0
  113. package/dist/demo/components/index.js +55 -0
  114. package/dist/demo/components/shared.d.ts +143 -0
  115. package/dist/demo/components/shared.js +315 -0
  116. package/dist/src/Playground.d.ts +3 -0
  117. package/dist/src/Playground.js +304 -0
  118. package/dist/src/antd/AntdPlayground.d.ts +16 -0
  119. package/dist/src/antd/AntdPlayground.js +136 -0
  120. package/dist/src/antd/index.d.ts +1 -0
  121. package/dist/src/antd/index.js +1 -0
  122. package/dist/src/context.d.ts +4 -0
  123. package/dist/src/context.js +13 -0
  124. package/dist/src/examples/index.d.ts +267 -0
  125. package/dist/src/examples/index.js +824 -0
  126. package/dist/src/hooks/index.d.ts +4 -0
  127. package/dist/src/hooks/index.js +4 -0
  128. package/dist/src/hooks/remoteSchemaAdapter.d.ts +53 -0
  129. package/dist/src/hooks/remoteSchemaAdapter.js +262 -0
  130. package/dist/src/hooks/usePlayground.d.ts +38 -0
  131. package/dist/src/hooks/usePlayground.js +642 -0
  132. package/dist/src/hooks/usePlaygroundRemotePersistence.d.ts +135 -0
  133. package/dist/src/hooks/usePlaygroundRemotePersistence.js +736 -0
  134. package/dist/src/hooks/useSchemaEditorDraft.d.ts +4 -0
  135. package/dist/src/hooks/useSchemaEditorDraft.js +44 -0
  136. package/dist/src/index.d.ts +14 -0
  137. package/dist/src/index.js +14 -0
  138. package/dist/src/layouts/PlaygroundLayout/ErrorBoundaries.d.ts +59 -0
  139. package/dist/src/layouts/PlaygroundLayout/ErrorBoundaries.js +161 -0
  140. package/dist/src/layouts/PlaygroundLayout/index.d.ts +7 -0
  141. package/dist/src/layouts/PlaygroundLayout/index.js +443 -0
  142. package/dist/src/layouts/index.d.ts +1 -0
  143. package/dist/src/layouts/index.js +1 -0
  144. package/dist/src/panels/CompositePanel/index.d.ts +6 -0
  145. package/dist/src/panels/CompositePanel/index.js +139 -0
  146. package/dist/src/panels/ToolbarPanel/index.d.ts +3 -0
  147. package/dist/src/panels/ToolbarPanel/index.js +24 -0
  148. package/dist/src/panels/index.d.ts +2 -0
  149. package/dist/src/panels/index.js +2 -0
  150. package/dist/src/presets/antd.d.ts +19 -0
  151. package/dist/src/presets/antd.js +112 -0
  152. package/dist/src/presets/index.d.ts +4 -0
  153. package/dist/src/presets/index.js +3 -0
  154. package/dist/src/presets/runtime-array-helpers.d.ts +8 -0
  155. package/dist/src/presets/runtime-array-helpers.js +147 -0
  156. package/dist/src/presets/runtime-component-props.d.ts +3 -0
  157. package/dist/src/presets/runtime-component-props.js +5 -0
  158. package/dist/src/presets/runtime-components.d.ts +5 -0
  159. package/dist/src/presets/runtime-components.js +419 -0
  160. package/dist/src/presets/runtime-form-components.d.ts +9 -0
  161. package/dist/src/presets/runtime-form-components.js +94 -0
  162. package/dist/src/presets/scenario-catalog.d.ts +6 -0
  163. package/dist/src/presets/scenario-catalog.js +128 -0
  164. package/dist/src/presets/scenarios.d.ts +52 -0
  165. package/dist/src/presets/scenarios.js +603 -0
  166. package/dist/src/runtime/actions.d.ts +19 -0
  167. package/dist/src/runtime/actions.js +307 -0
  168. package/dist/src/runtime/contracts.d.ts +149 -0
  169. package/dist/src/runtime/contracts.js +1 -0
  170. package/dist/src/runtime/document-bindings.d.ts +3 -0
  171. package/dist/src/runtime/document-bindings.js +101 -0
  172. package/dist/src/runtime/document-core.d.ts +57 -0
  173. package/dist/src/runtime/document-core.js +379 -0
  174. package/dist/src/runtime/document-entity.d.ts +12 -0
  175. package/dist/src/runtime/document-entity.js +351 -0
  176. package/dist/src/runtime/document-expressions.d.ts +35 -0
  177. package/dist/src/runtime/document-expressions.js +346 -0
  178. package/dist/src/runtime/document-security.d.ts +34 -0
  179. package/dist/src/runtime/document-security.js +538 -0
  180. package/dist/src/runtime/document.d.ts +16 -0
  181. package/dist/src/runtime/document.js +212 -0
  182. package/dist/src/runtime/environment.d.ts +16 -0
  183. package/dist/src/runtime/environment.js +76 -0
  184. package/dist/src/runtime/i18n-schema.d.ts +36 -0
  185. package/dist/src/runtime/i18n-schema.js +338 -0
  186. package/dist/src/runtime/i18n.d.ts +25 -0
  187. package/dist/src/runtime/i18n.js +447 -0
  188. package/dist/src/runtime/index.d.ts +8 -0
  189. package/dist/src/runtime/index.js +8 -0
  190. package/dist/src/runtime/navigation.d.ts +5 -0
  191. package/dist/src/runtime/navigation.js +43 -0
  192. package/dist/src/runtime/playground.d.ts +30 -0
  193. package/dist/src/runtime/playground.js +243 -0
  194. package/dist/src/runtime/preview-boundaries.d.ts +13 -0
  195. package/dist/src/runtime/preview-boundaries.js +43 -0
  196. package/dist/src/runtime/preview.d.ts +44 -0
  197. package/dist/src/runtime/preview.js +574 -0
  198. package/dist/src/runtime/settings/RuntimeJsonEditor.d.ts +10 -0
  199. package/dist/src/runtime/settings/RuntimeJsonEditor.js +21 -0
  200. package/dist/src/runtime/settings/RuntimeStoreEntitySettings.d.ts +15 -0
  201. package/dist/src/runtime/settings/RuntimeStoreEntitySettings.js +65 -0
  202. package/dist/src/runtime/templates.d.ts +1560 -0
  203. package/dist/src/runtime/templates.js +508 -0
  204. package/dist/src/runtime/website-contact-template.d.ts +1 -0
  205. package/dist/src/runtime/website-contact-template.js +66 -0
  206. package/dist/src/runtime/website-template-shared.d.ts +14 -0
  207. package/dist/src/runtime/website-template-shared.js +210 -0
  208. package/dist/src/runtime/website-templates.d.ts +5 -0
  209. package/dist/src/runtime/website-templates.js +976 -0
  210. package/dist/src/shared/clipboard.d.ts +4 -0
  211. package/dist/src/shared/clipboard.js +56 -0
  212. package/dist/src/shared/componentRegistry.d.ts +133 -0
  213. package/dist/src/shared/componentRegistry.js +381 -0
  214. package/dist/src/shared/formilyCompatibility.d.ts +8 -0
  215. package/dist/src/shared/formilyCompatibility.js +40 -0
  216. package/dist/src/shared/index.d.ts +6 -0
  217. package/dist/src/shared/index.js +6 -0
  218. package/dist/src/shared/productionAcceptance.d.ts +63 -0
  219. package/dist/src/shared/productionAcceptance.js +201 -0
  220. package/dist/src/shared/schema-options.d.ts +16 -0
  221. package/dist/src/shared/schema-options.js +138 -0
  222. package/dist/src/shared/schema.d.ts +63 -0
  223. package/dist/src/shared/schema.js +627 -0
  224. package/dist/src/shared/styleSecurity.d.ts +2 -0
  225. package/dist/src/shared/styleSecurity.js +35 -0
  226. package/dist/src/transformers/formily.d.ts +34 -0
  227. package/dist/src/transformers/formily.js +943 -0
  228. package/dist/src/transformers/index.d.ts +1 -0
  229. package/dist/src/transformers/index.js +1 -0
  230. package/dist/src/types.d.ts +186 -0
  231. package/dist/src/types.js +1 -0
  232. package/dist/src/widgets/ActionsWidget/index.d.ts +3 -0
  233. package/dist/src/widgets/ActionsWidget/index.js +10 -0
  234. package/dist/src/widgets/ComponentTreeWidget/index.d.ts +3 -0
  235. package/dist/src/widgets/ComponentTreeWidget/index.js +333 -0
  236. package/dist/src/widgets/NodeActionsWidget/index.d.ts +2 -0
  237. package/dist/src/widgets/NodeActionsWidget/index.js +125 -0
  238. package/dist/src/widgets/OutlineTreeWidget/index.d.ts +3 -0
  239. package/dist/src/widgets/OutlineTreeWidget/index.js +432 -0
  240. package/dist/src/widgets/OutlineTreeWidget/shared.d.ts +32 -0
  241. package/dist/src/widgets/OutlineTreeWidget/shared.js +79 -0
  242. package/dist/src/widgets/PreviewWidget/index.d.ts +2 -0
  243. package/dist/src/widgets/PreviewWidget/index.js +1566 -0
  244. package/dist/src/widgets/ProductionReadinessWidget/index.d.ts +18 -0
  245. package/dist/src/widgets/ProductionReadinessWidget/index.js +356 -0
  246. package/dist/src/widgets/RemotePersistenceStatusWidget/index.d.ts +18 -0
  247. package/dist/src/widgets/RemotePersistenceStatusWidget/index.js +438 -0
  248. package/dist/src/widgets/RemoteVersionHistoryWidget/index.d.ts +39 -0
  249. package/dist/src/widgets/RemoteVersionHistoryWidget/index.js +475 -0
  250. package/dist/src/widgets/ResourceWidget/index.d.ts +3 -0
  251. package/dist/src/widgets/ResourceWidget/index.js +491 -0
  252. package/dist/src/widgets/SchemaCodeView/index.d.ts +7 -0
  253. package/dist/src/widgets/SchemaCodeView/index.js +225 -0
  254. package/dist/src/widgets/SchemaEditorWidget/index.d.ts +10 -0
  255. package/dist/src/widgets/SchemaEditorWidget/index.js +484 -0
  256. package/dist/src/widgets/SettingsPanelWidget/index.d.ts +3 -0
  257. package/dist/src/widgets/SettingsPanelWidget/index.js +190 -0
  258. package/dist/src/widgets/StorageActionsWidget/index.d.ts +2 -0
  259. package/dist/src/widgets/StorageActionsWidget/index.js +284 -0
  260. package/dist/src/widgets/index.d.ts +13 -0
  261. package/dist/src/widgets/index.js +13 -0
  262. package/package.json +100 -4
@@ -0,0 +1,484 @@
1
+ import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { observer } from '@formily/reactive-react';
3
+ import Editor from '@monaco-editor/react';
4
+ import { usePrefix } from '@yimoka/designable-react';
5
+ import { useConfigComponents } from '@yimoka/react';
6
+ import cls from 'classnames';
7
+ import React, { useEffect, useRef, useState } from 'react';
8
+ import { usePlaygroundContext } from "../../context.js";
9
+ import { copyTextToClipboard } from "../../shared/clipboard.js";
10
+ import { normalizeHistoricalFormilyTreeSchema } from "../../shared/formilyCompatibility.js";
11
+ import { assertTreeSchema, isUnsafeSchemaObjectKeyError, parseSchemaJSON, stringifySchemaForExport, } from "../../shared/schema.js";
12
+ const DESIGNABLE_E2E_FLAG_KEY = '__designableE2E__';
13
+ const DESIGNABLE_SCHEMA_EDITOR_GETTER_KEY = '__designableGetSchemaEditorValue';
14
+ const DESIGNABLE_SCHEMA_EDITOR_SETTER_KEY = '__designableSetSchemaEditorValue';
15
+ const MAX_SCHEMA_DRAFT_LENGTH = 5 * 1024 * 1024;
16
+ const MAX_SCHEMA_DRAFT_SIZE_TEXT = '5MB';
17
+ const getErrorMessage = (error, fallback) => {
18
+ if (error instanceof Error)
19
+ return error.message;
20
+ if (typeof error === 'string' && error.trim())
21
+ return error;
22
+ return fallback;
23
+ };
24
+ const isTreeSchema = (schema) => (typeof schema === 'object'
25
+ && schema !== null
26
+ && typeof schema.componentName === 'string');
27
+ const isSerializableSchema = (schema) => (typeof schema === 'object'
28
+ && schema !== null
29
+ && typeof schema.serialize === 'function');
30
+ const toDraftSchemaValue = (schema) => (isSerializableSchema(schema) ? schema.serialize() : schema);
31
+ const getCurrentSchemaDraft = (tree, transformer) => {
32
+ if (!tree)
33
+ return { error: null, value: '{}' };
34
+ try {
35
+ const schema = transformer
36
+ ? transformer.toSchema(tree)
37
+ : tree.serialize();
38
+ return { error: null, value: stringifySchemaForExport(schema) };
39
+ }
40
+ catch (error) {
41
+ return {
42
+ error: `当前 Schema 生成失败:${getErrorMessage(error, '无法读取当前画布 Schema')}`,
43
+ value: '{}',
44
+ };
45
+ }
46
+ };
47
+ const applySchemaChange = (schema, options) => {
48
+ if (options.onChange) {
49
+ if (options.onChange(schema) === false) {
50
+ throw new Error('外部应用 Schema 失败');
51
+ }
52
+ return;
53
+ }
54
+ options.tree?.from(schema);
55
+ };
56
+ const applyTreeDraftSchema = (schema, options) => {
57
+ assertTreeSchema(schema);
58
+ const nextTree = normalizeHistoricalFormilyTreeSchema(schema, options.transformer);
59
+ applySchemaChange(nextTree, options);
60
+ return { appliedSchema: nextTree };
61
+ };
62
+ const applyTransformedDraftSchema = (schema, options) => {
63
+ if (!options.transformer)
64
+ return applyTreeDraftSchema(schema, options);
65
+ const nextTree = options.transformer.toTreeNode(schema);
66
+ applySchemaChange(nextTree, options);
67
+ return { appliedSchema: nextTree };
68
+ };
69
+ const applyDraftSchemaToTree = (schema, options) => {
70
+ if (isTreeSchema(schema))
71
+ return applyTreeDraftSchema(schema, options);
72
+ return applyTransformedDraftSchema(schema, options);
73
+ };
74
+ const getLineColumnFromPosition = (text, position) => {
75
+ const safePosition = Math.max(0, Math.min(position, text.length));
76
+ const lines = text.slice(0, safePosition).split('\n');
77
+ return {
78
+ column: lines[lines.length - 1].length + 1,
79
+ line: lines.length,
80
+ };
81
+ };
82
+ const getJsonErrorLocation = (text, error) => {
83
+ const message = getErrorMessage(error, '');
84
+ const positionMatched = message.match(/position\s+(\d+)/i);
85
+ if (positionMatched) {
86
+ return getLineColumnFromPosition(text, Number(positionMatched[1]));
87
+ }
88
+ if (message.includes('Unexpected end')) {
89
+ return getLineColumnFromPosition(text, text.length);
90
+ }
91
+ return null;
92
+ };
93
+ const formatJsonErrorMessage = (text, error) => {
94
+ const message = getErrorMessage(error, 'JSON 格式不合法');
95
+ const location = getJsonErrorLocation(text, error);
96
+ if (!location)
97
+ return `JSON 格式错误:${message}`;
98
+ return `JSON 格式错误(第 ${location.line} 行,第 ${location.column} 列):${message}`;
99
+ };
100
+ const getSchemaDraftTooLargeMessage = () => (`JSON 内容超过 ${MAX_SCHEMA_DRAFT_SIZE_TEXT},请拆分或精简后再应用`);
101
+ class SchemaEditorBoundary extends React.Component {
102
+ static getDerivedStateFromError(error) {
103
+ return { error };
104
+ }
105
+ state = {
106
+ error: null,
107
+ };
108
+ componentDidUpdate(prevProps) {
109
+ if (!this.state.error)
110
+ return;
111
+ if (prevProps.resetKey === this.props.resetKey)
112
+ return;
113
+ this.setState({ error: null });
114
+ }
115
+ render() {
116
+ if (!this.state.error)
117
+ return this.props.children;
118
+ return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', height: '100%' }, children: [_jsxs("div", { role: "alert", style: {
119
+ background: '#fff7e6',
120
+ borderBottom: '1px solid #ffd591',
121
+ color: '#ad6800',
122
+ flex: '0 0 auto',
123
+ fontSize: 12,
124
+ lineHeight: 1.5,
125
+ maxHeight: 72,
126
+ overflow: 'auto',
127
+ padding: '6px 12px',
128
+ }, children: ["Schema \u7F16\u8F91\u5668\u52A0\u8F7D\u5931\u8D25\uFF0C\u5DF2\u5207\u6362\u5230\u57FA\u7840\u7F16\u8F91\u5668\uFF1A", getErrorMessage(this.state.error, '编辑器运行异常')] }), _jsx("div", { style: { flex: 1, minHeight: 0 }, children: this.props.fallback })] }));
129
+ }
130
+ }
131
+ const SchemaFallbackEditor = ({ draftValue, readonly, onChange, }) => (_jsx("textarea", { "aria-label": "JSON Schema", readOnly: readonly, spellCheck: false, style: {
132
+ background: '#1e1e1e',
133
+ border: 0,
134
+ boxSizing: 'border-box',
135
+ color: '#d4d4d4',
136
+ fontFamily: 'Menlo, Monaco, Consolas, monospace',
137
+ fontSize: 14,
138
+ height: '100%',
139
+ lineHeight: 1.6,
140
+ outline: 'none',
141
+ padding: 16,
142
+ resize: 'none',
143
+ width: '100%',
144
+ }, value: draftValue, onChange: event => onChange(event.currentTarget.value) }));
145
+ const schemaEditorButtonStyle = {
146
+ background: '#fff',
147
+ border: '1px solid #d9d9d9',
148
+ borderRadius: 4,
149
+ color: '#4b5563',
150
+ cursor: 'pointer',
151
+ fontSize: 12,
152
+ height: 28,
153
+ padding: '0 10px',
154
+ };
155
+ const getApplyButtonStyle = (disabled) => ({
156
+ background: disabled ? '#f5f5f5' : '#1677ff',
157
+ border: `1px solid ${disabled ? '#d9d9d9' : '#1677ff'}`,
158
+ borderRadius: 4,
159
+ color: disabled ? '#bfbfbf' : '#fff',
160
+ cursor: disabled ? 'not-allowed' : 'pointer',
161
+ fontSize: 12,
162
+ height: 28,
163
+ padding: '0 12px',
164
+ });
165
+ const SchemaEditorStatus = ({ hasPendingChanges, statusMessage, }) => (_jsxs("span", { "aria-live": "polite", role: "status", style: {
166
+ alignItems: 'center',
167
+ display: 'inline-flex',
168
+ flexWrap: 'wrap',
169
+ gap: 8,
170
+ marginRight: 'auto',
171
+ minWidth: 0,
172
+ }, children: [statusMessage ? (_jsx("span", { style: { color: '#237804', fontSize: 12 }, children: statusMessage })) : null, hasPendingChanges ? (_jsx("span", { style: { color: '#8c8c8c', fontSize: 12 }, children: "\u6709\u672A\u5E94\u7528\u7684 Schema \u8349\u7A3F" })) : null] }));
173
+ const SchemaEditorToolbar = ({ hasPendingChanges, onApply, onCopy, onDiscard, onFormat, parseError, readonly, statusMessage, }) => {
174
+ const applyDisabled = !hasPendingChanges || Boolean(parseError);
175
+ return (_jsxs("div", { style: {
176
+ alignItems: 'center',
177
+ background: '#fff',
178
+ borderBottom: '1px solid #f0f0f0',
179
+ display: 'flex',
180
+ gap: 8,
181
+ justifyContent: 'flex-end',
182
+ minHeight: 40,
183
+ padding: '0 12px',
184
+ }, children: [_jsx(SchemaEditorStatus, { hasPendingChanges: hasPendingChanges, statusMessage: statusMessage }), _jsx("button", { style: schemaEditorButtonStyle, type: "button", onClick: onCopy, children: "\u590D\u5236\u8349\u7A3F" }), readonly ? (_jsx("span", { style: { color: '#8c8c8c', fontSize: 12 }, children: "\u53EA\u8BFB" })) : (_jsxs(_Fragment, { children: [_jsx("button", { "aria-keyshortcuts": "Control+Shift+F Meta+Shift+F", style: schemaEditorButtonStyle, type: "button", onClick: onFormat, children: "\u683C\u5F0F\u5316" }), hasPendingChanges ? (_jsx("button", { style: schemaEditorButtonStyle, type: "button", onClick: onDiscard, children: "\u4E22\u5F03\u8349\u7A3F" })) : null, _jsx("button", { "aria-keyshortcuts": "Control+S Meta+S", disabled: applyDisabled, style: getApplyButtonStyle(applyDisabled), type: "button", onClick: onApply, children: "\u5E94\u7528 Schema" })] }))] }));
185
+ };
186
+ const SchemaEditorErrorBanner = ({ parseError, visibleError, }) => {
187
+ if (!visibleError)
188
+ return null;
189
+ return (_jsx("div", { role: "alert", style: {
190
+ background: parseError ? '#fff1f0' : '#fff7e6',
191
+ borderBottom: `1px solid ${parseError ? '#ffccc7' : '#ffd591'}`,
192
+ color: parseError ? '#cf1322' : '#ad6800',
193
+ flex: '0 0 auto',
194
+ fontSize: 12,
195
+ lineHeight: 1.5,
196
+ maxHeight: 72,
197
+ overflow: 'auto',
198
+ padding: '6px 12px',
199
+ }, children: visibleError }));
200
+ };
201
+ const SchemaEditorLoading = () => (_jsx("div", { style: {
202
+ alignItems: 'center',
203
+ color: '#999',
204
+ display: 'flex',
205
+ height: '100%',
206
+ justifyContent: 'center',
207
+ }, children: "\u52A0\u8F7D\u7F16\u8F91\u5668..." }));
208
+ export const SchemaEditorWidget = observer((props) => {
209
+ const { transformer } = usePlaygroundContext();
210
+ const loading = useConfigComponents()?.Loading ?? SchemaEditorLoading;
211
+ const prefix = usePrefix('schema-editor');
212
+ const { autoApply: autoApplyProp, className, draftValue: controlledDraftValue, onApply, onChange, onDraftChange, readonly, style, tree, } = props;
213
+ const autoApply = autoApplyProp === true && !readonly;
214
+ const [useFallbackEditor, setUseFallbackEditor] = useState(false);
215
+ const [monacoMounted, setMonacoMounted] = useState(false);
216
+ const [parseError, setParseError] = useState(null);
217
+ const [statusMessage, setStatusMessage] = useState(null);
218
+ const editorRef = useRef(null);
219
+ const editorHostRef = useRef(null);
220
+ const copyActionIdRef = useRef(0);
221
+ const mountedRef = useRef(true);
222
+ const fallbackTimerRef = useRef(null);
223
+ const layoutFrameRef = useRef(null);
224
+ const layoutTimerRefs = useRef([]);
225
+ const schemaResult = getCurrentSchemaDraft(tree, transformer);
226
+ const schemaValue = schemaResult.value;
227
+ const schemaBuildError = schemaResult.error;
228
+ const [innerDraftValue, setInnerDraftValue] = useState(schemaValue);
229
+ const lastSchemaValueRef = useRef(schemaValue);
230
+ const preserveNextSchemaSyncStatusRef = useRef(false);
231
+ const isDraftControlled = controlledDraftValue !== undefined;
232
+ const draftValue = isDraftControlled ? controlledDraftValue ?? '' : innerDraftValue;
233
+ const setDraftValue = React.useCallback((nextValue) => {
234
+ if (!isDraftControlled) {
235
+ setInnerDraftValue(nextValue);
236
+ }
237
+ onDraftChange?.(nextValue);
238
+ }, [isDraftControlled, onDraftChange]);
239
+ const hasPendingChanges = draftValue !== lastSchemaValueRef.current;
240
+ useEffect(() => {
241
+ if (schemaBuildError)
242
+ return;
243
+ if (schemaValue === lastSchemaValueRef.current)
244
+ return;
245
+ copyActionIdRef.current += 1;
246
+ lastSchemaValueRef.current = schemaValue;
247
+ setDraftValue(schemaValue);
248
+ setParseError(null);
249
+ if (preserveNextSchemaSyncStatusRef.current) {
250
+ preserveNextSchemaSyncStatusRef.current = false;
251
+ }
252
+ else {
253
+ setStatusMessage(null);
254
+ }
255
+ }, [schemaBuildError, schemaValue, setDraftValue]);
256
+ const visibleError = parseError ?? schemaBuildError;
257
+ const fallbackEditor = (_jsx(SchemaFallbackEditor, { draftValue: draftValue, readonly: readonly, onChange: value => handleChange(value) }));
258
+ const parseDraftSchema = React.useCallback((nextValue) => {
259
+ if (nextValue.length > MAX_SCHEMA_DRAFT_LENGTH) {
260
+ setParseError(getSchemaDraftTooLargeMessage());
261
+ setStatusMessage(null);
262
+ preserveNextSchemaSyncStatusRef.current = false;
263
+ return { success: false };
264
+ }
265
+ let schema;
266
+ try {
267
+ schema = parseSchemaJSON(nextValue);
268
+ }
269
+ catch (error) {
270
+ setParseError(isUnsafeSchemaObjectKeyError(error)
271
+ ? getErrorMessage(error, 'Schema 包含不安全字段')
272
+ : formatJsonErrorMessage(nextValue, error));
273
+ setStatusMessage(null);
274
+ preserveNextSchemaSyncStatusRef.current = false;
275
+ return { success: false };
276
+ }
277
+ setParseError(null);
278
+ return { schema, success: true };
279
+ }, []);
280
+ useEffect(() => {
281
+ if (!isDraftControlled)
282
+ return;
283
+ if (draftValue === lastSchemaValueRef.current) {
284
+ setParseError(null);
285
+ return;
286
+ }
287
+ parseDraftSchema(draftValue);
288
+ }, [draftValue, isDraftControlled, parseDraftSchema]);
289
+ const applySchema = (schema) => {
290
+ copyActionIdRef.current += 1;
291
+ try {
292
+ const { appliedSchema } = applyDraftSchemaToTree(schema, {
293
+ onChange,
294
+ transformer,
295
+ tree,
296
+ });
297
+ onApply?.();
298
+ setParseError(null);
299
+ lastSchemaValueRef.current = stringifySchemaForExport(toDraftSchemaValue(appliedSchema));
300
+ setDraftValue(lastSchemaValueRef.current);
301
+ preserveNextSchemaSyncStatusRef.current = true;
302
+ }
303
+ catch (error) {
304
+ setParseError(`Schema 应用错误:${getErrorMessage(error, '无法应用当前 Schema')}`);
305
+ setStatusMessage(null);
306
+ preserveNextSchemaSyncStatusRef.current = false;
307
+ return;
308
+ }
309
+ setStatusMessage('Schema 已应用');
310
+ };
311
+ const handleChange = (value) => {
312
+ if (readonly)
313
+ return;
314
+ const nextValue = value ?? '';
315
+ copyActionIdRef.current += 1;
316
+ setDraftValue(nextValue);
317
+ setStatusMessage(null);
318
+ preserveNextSchemaSyncStatusRef.current = false;
319
+ const parsed = parseDraftSchema(nextValue);
320
+ if (!parsed.success || !autoApply)
321
+ return;
322
+ applySchema(parsed.schema);
323
+ };
324
+ useEffect(() => {
325
+ if (typeof window === 'undefined'
326
+ || (!window[DESIGNABLE_E2E_FLAG_KEY] && window.navigator.webdriver !== true)) {
327
+ return undefined;
328
+ }
329
+ window[DESIGNABLE_SCHEMA_EDITOR_SETTER_KEY] = (value) => {
330
+ handleChange(value);
331
+ };
332
+ window[DESIGNABLE_SCHEMA_EDITOR_GETTER_KEY] = () => draftValue;
333
+ return () => {
334
+ if (window[DESIGNABLE_SCHEMA_EDITOR_GETTER_KEY]) {
335
+ delete window[DESIGNABLE_SCHEMA_EDITOR_GETTER_KEY];
336
+ }
337
+ if (window[DESIGNABLE_SCHEMA_EDITOR_SETTER_KEY]) {
338
+ delete window[DESIGNABLE_SCHEMA_EDITOR_SETTER_KEY];
339
+ }
340
+ };
341
+ });
342
+ const handleApply = () => {
343
+ const parsed = parseDraftSchema(draftValue);
344
+ if (!parsed.success)
345
+ return;
346
+ applySchema(parsed.schema);
347
+ };
348
+ const handleDiscardDraft = () => {
349
+ copyActionIdRef.current += 1;
350
+ setDraftValue(lastSchemaValueRef.current);
351
+ setParseError(null);
352
+ setStatusMessage('已恢复当前 Schema');
353
+ preserveNextSchemaSyncStatusRef.current = false;
354
+ };
355
+ const handleFormatDraft = () => {
356
+ copyActionIdRef.current += 1;
357
+ const parsed = parseDraftSchema(draftValue);
358
+ if (!parsed.success)
359
+ return;
360
+ setDraftValue(stringifySchemaForExport(parsed.schema));
361
+ setStatusMessage('Schema 已格式化');
362
+ preserveNextSchemaSyncStatusRef.current = false;
363
+ };
364
+ const isCurrentCopyAction = (actionId) => (mountedRef.current && copyActionIdRef.current === actionId);
365
+ const handleCopyDraft = async () => {
366
+ const actionId = copyActionIdRef.current + 1;
367
+ copyActionIdRef.current = actionId;
368
+ setStatusMessage('正在复制草稿...');
369
+ try {
370
+ await copyTextToClipboard(draftValue);
371
+ if (isCurrentCopyAction(actionId)) {
372
+ setStatusMessage('已复制草稿');
373
+ }
374
+ }
375
+ catch (error) {
376
+ if (isCurrentCopyAction(actionId)) {
377
+ setStatusMessage(`复制失败:${getErrorMessage(error, '无法写入剪贴板')}`);
378
+ }
379
+ }
380
+ };
381
+ const handleEditorKeyDown = (event) => {
382
+ const isCommand = event.metaKey || event.ctrlKey;
383
+ if (!isCommand)
384
+ return;
385
+ const key = event.key.toLowerCase();
386
+ if (key === 's') {
387
+ event.preventDefault();
388
+ if (readonly)
389
+ return;
390
+ if (!hasPendingChanges || parseError)
391
+ return;
392
+ handleApply();
393
+ return;
394
+ }
395
+ if (event.shiftKey && key === 'f') {
396
+ event.preventDefault();
397
+ if (readonly)
398
+ return;
399
+ handleFormatDraft();
400
+ }
401
+ };
402
+ useEffect(() => {
403
+ setUseFallbackEditor(false);
404
+ setMonacoMounted(false);
405
+ fallbackTimerRef.current = window.setTimeout(() => {
406
+ setUseFallbackEditor(true);
407
+ fallbackTimerRef.current = null;
408
+ }, 1500);
409
+ return () => {
410
+ if (fallbackTimerRef.current !== null) {
411
+ window.clearTimeout(fallbackTimerRef.current);
412
+ fallbackTimerRef.current = null;
413
+ }
414
+ };
415
+ }, []);
416
+ const scheduleEditorLayout = React.useCallback(() => {
417
+ if (!editorRef.current)
418
+ return;
419
+ if (layoutFrameRef.current !== null && typeof cancelAnimationFrame === 'function') {
420
+ cancelAnimationFrame(layoutFrameRef.current);
421
+ }
422
+ layoutFrameRef.current = null;
423
+ layoutTimerRefs.current.forEach(timer => window.clearTimeout(timer));
424
+ layoutTimerRefs.current = [];
425
+ const runLayout = () => {
426
+ layoutFrameRef.current = null;
427
+ const host = editorHostRef.current;
428
+ if (host && host.clientWidth > 0 && host.clientHeight > 0) {
429
+ editorRef.current?.layout({
430
+ height: host.clientHeight,
431
+ width: host.clientWidth,
432
+ });
433
+ return;
434
+ }
435
+ editorRef.current?.layout();
436
+ };
437
+ if (typeof requestAnimationFrame !== 'function') {
438
+ runLayout();
439
+ return;
440
+ }
441
+ layoutFrameRef.current = requestAnimationFrame(runLayout);
442
+ [50, 150, 300].forEach((delay) => {
443
+ const timer = window.setTimeout(runLayout, delay);
444
+ layoutTimerRefs.current.push(timer);
445
+ });
446
+ }, []);
447
+ useEffect(() => () => {
448
+ mountedRef.current = false;
449
+ copyActionIdRef.current += 1;
450
+ if (layoutFrameRef.current !== null && typeof cancelAnimationFrame === 'function') {
451
+ cancelAnimationFrame(layoutFrameRef.current);
452
+ }
453
+ layoutFrameRef.current = null;
454
+ layoutTimerRefs.current.forEach(timer => window.clearTimeout(timer));
455
+ layoutTimerRefs.current = [];
456
+ }, []);
457
+ return (_jsxs("div", { className: cls(prefix, className), style: {
458
+ display: 'flex',
459
+ flexDirection: 'column',
460
+ height: '100%',
461
+ position: 'relative',
462
+ ...style,
463
+ }, onKeyDown: handleEditorKeyDown, children: [_jsx(SchemaEditorToolbar, { hasPendingChanges: hasPendingChanges, parseError: parseError, readonly: readonly, statusMessage: statusMessage, onApply: handleApply, onCopy: handleCopyDraft, onDiscard: handleDiscardDraft, onFormat: handleFormatDraft }), _jsx(SchemaEditorErrorBanner, { parseError: parseError, visibleError: visibleError }), _jsx("div", { ref: editorHostRef, style: { flex: 1, minHeight: 0 }, children: useFallbackEditor && !monacoMounted ? (fallbackEditor) : (_jsx(SchemaEditorBoundary, { fallback: fallbackEditor, resetKey: `${schemaBuildError ?? 'ok'}:${lastSchemaValueRef.current}`, children: _jsx(Editor, { height: "100%", language: "json", loading: React.createElement(loading), options: {
464
+ ariaLabel: 'JSON Schema',
465
+ automaticLayout: true,
466
+ fontSize: 14,
467
+ formatOnPaste: true,
468
+ formatOnType: true,
469
+ lineNumbers: 'on',
470
+ minimap: { enabled: false },
471
+ scrollBeyondLastLine: false,
472
+ readOnly: readonly,
473
+ wordWrap: 'on',
474
+ }, theme: "vs-dark", value: draftValue, width: "100%", onChange: handleChange, onMount: (editor) => {
475
+ editorRef.current = editor;
476
+ setMonacoMounted(true);
477
+ if (fallbackTimerRef.current !== null) {
478
+ window.clearTimeout(fallbackTimerRef.current);
479
+ fallbackTimerRef.current = null;
480
+ }
481
+ scheduleEditorLayout();
482
+ } }) })) })] }));
483
+ });
484
+ SchemaEditorWidget.displayName = 'SchemaEditorWidget';
@@ -0,0 +1,3 @@
1
+ import React from 'react';
2
+ import type { ISettingsPanelWidgetProps } from "../../types.js";
3
+ export declare const SettingsPanelWidget: React.FC<React.PropsWithChildren<ISettingsPanelWidgetProps>>;
@@ -0,0 +1,190 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CloseOutlined, PushpinFilled, PushpinOutlined, SettingOutlined } from '@ant-design/icons';
3
+ import { observer } from '@formily/reactive-react';
4
+ import { cancelIdle, requestIdle } from '@yimoka/designable-core';
5
+ import { IconWidget, TextWidget, useCurrentNode, usePrefix, useWorkbench } from '@yimoka/designable-react';
6
+ import cls from 'classnames';
7
+ import React from 'react';
8
+ const handleKeyboardActivate = (event, callback) => {
9
+ if (event.key !== 'Enter' && event.key !== ' ')
10
+ return;
11
+ event.preventDefault();
12
+ callback();
13
+ };
14
+ const getErrorMessage = (error) => {
15
+ if (error instanceof Error)
16
+ return error.message;
17
+ if (typeof error === 'string' && error.trim())
18
+ return error;
19
+ return '未知错误';
20
+ };
21
+ const createSettingsResetPart = (value) => {
22
+ try {
23
+ return JSON.stringify(value) ?? '';
24
+ }
25
+ catch {
26
+ return String(value);
27
+ }
28
+ };
29
+ const getWorkbenchResetPart = (workbenchType) => (workbenchType ?? 'UNKNOWN');
30
+ const getCurrentNodeResetParts = (currentNode) => [
31
+ currentNode?.id ?? 'none',
32
+ currentNode?.componentName ?? 'NO_COMPONENT',
33
+ createSettingsResetPart(currentNode?.props),
34
+ currentNode?.children?.length ?? 0,
35
+ ];
36
+ const createSettingsResetKey = ({ currentNode, innerVisible, visible, workbenchType, }) => [
37
+ getWorkbenchResetPart(workbenchType),
38
+ ...getCurrentNodeResetParts(currentNode),
39
+ visible ? 'open' : 'closed',
40
+ innerVisible ? 'visible' : 'hidden',
41
+ ].join(':');
42
+ const useDeferredPanelBodyVisible = (shouldMountBody) => {
43
+ const [innerVisible, setInnerVisible] = React.useState(true);
44
+ React.useEffect(() => {
45
+ if (!shouldMountBody) {
46
+ if (!innerVisible)
47
+ return undefined;
48
+ const idleId = requestIdle(() => {
49
+ setInnerVisible(false);
50
+ });
51
+ return () => {
52
+ cancelIdle(idleId);
53
+ };
54
+ }
55
+ if (!innerVisible) {
56
+ let animationId;
57
+ const idleId = requestIdle(() => {
58
+ if (typeof requestAnimationFrame !== 'function') {
59
+ setInnerVisible(true);
60
+ return;
61
+ }
62
+ animationId = requestAnimationFrame(() => {
63
+ setInnerVisible(true);
64
+ });
65
+ });
66
+ return () => {
67
+ cancelIdle(idleId);
68
+ if (animationId !== undefined && typeof cancelAnimationFrame === 'function') {
69
+ cancelAnimationFrame(animationId);
70
+ }
71
+ };
72
+ }
73
+ return undefined;
74
+ }, [shouldMountBody, innerVisible]);
75
+ return innerVisible;
76
+ };
77
+ const SettingsPanelOpener = ({ prefix, setVisible }) => {
78
+ const openPanel = () => {
79
+ setVisible(true);
80
+ };
81
+ return (_jsx("div", { "aria-label": "\u6253\u5F00\u5C5E\u6027\u9762\u677F", className: `${prefix}-opener`, role: "button", tabIndex: 0, onClick: openPanel, onKeyDown: event => handleKeyboardActivate(event, openPanel), children: _jsx(IconWidget, { infer: _jsx(SettingOutlined, {}), size: 20 }) }));
82
+ };
83
+ const SettingsPanelHeaderActions = ({ pinning, prefix, setPinning, setVisible, }) => {
84
+ const pinPanel = () => {
85
+ setPinning(true);
86
+ };
87
+ const unpinPanel = () => {
88
+ setPinning(false);
89
+ };
90
+ const closePanel = () => {
91
+ setVisible(false);
92
+ };
93
+ return (_jsxs("div", { className: `${prefix}-header-actions`, style: {
94
+ alignItems: 'center',
95
+ color: '#8a96a8',
96
+ display: 'flex',
97
+ gap: 10,
98
+ }, children: [!pinning && (_jsx(IconWidget, { "aria-label": "\u56FA\u5B9A\u5C5E\u6027\u9762\u677F", "aria-pressed": false, className: `${prefix}-header-pin`, infer: _jsx(PushpinOutlined, {}), role: "button", tabIndex: 0, tooltip: "\u56FA\u5B9A\u5C5E\u6027\u9762\u677F", onClick: pinPanel, onKeyDown: event => handleKeyboardActivate(event, pinPanel) })), pinning && (_jsx(IconWidget, { "aria-pressed": true, "aria-label": "\u53D6\u6D88\u56FA\u5B9A\u5C5E\u6027\u9762\u677F", className: `${prefix}-pin-filled`, infer: _jsx(PushpinFilled, {}), role: "button", tabIndex: 0, tooltip: "\u53D6\u6D88\u56FA\u5B9A\u5C5E\u6027\u9762\u677F", onClick: unpinPanel, onKeyDown: event => handleKeyboardActivate(event, unpinPanel) })), !pinning && (_jsx(IconWidget, { "aria-label": "\u5173\u95ED\u5C5E\u6027\u9762\u677F", className: `${prefix}-header-close`, infer: _jsx(CloseOutlined, {}), role: "button", tabIndex: 0, tooltip: "\u5173\u95ED\u5C5E\u6027\u9762\u677F", onClick: closePanel, onKeyDown: event => handleKeyboardActivate(event, closePanel) }))] }));
99
+ };
100
+ class SettingsPanelErrorBoundary extends React.Component {
101
+ static getDerivedStateFromError(error) {
102
+ return { error };
103
+ }
104
+ state = {
105
+ error: null,
106
+ };
107
+ componentDidCatch(error) {
108
+ try {
109
+ this.props.onError?.(error);
110
+ }
111
+ catch {
112
+ }
113
+ }
114
+ componentDidUpdate(prevProps) {
115
+ if (!this.state.error)
116
+ return;
117
+ if (prevProps.resetKey === this.props.resetKey)
118
+ return;
119
+ this.setState({ error: null });
120
+ }
121
+ render() {
122
+ if (this.state.error) {
123
+ const message = getErrorMessage(this.state.error);
124
+ return (_jsxs("div", { role: "alert", style: {
125
+ background: '#fff1f0',
126
+ border: '1px solid #ffccc7',
127
+ borderRadius: 6,
128
+ color: '#a8071a',
129
+ fontSize: 12,
130
+ lineHeight: '18px',
131
+ margin: 8,
132
+ padding: 10,
133
+ }, children: [_jsx("div", { style: { fontWeight: 700 }, children: "\u5C5E\u6027\u9762\u677F\u6E32\u67D3\u5931\u8D25" }), _jsx("div", { style: {
134
+ marginTop: 4,
135
+ overflow: 'hidden',
136
+ textOverflow: 'ellipsis',
137
+ whiteSpace: 'nowrap',
138
+ }, title: message, children: message })] }));
139
+ }
140
+ return this.props.children;
141
+ }
142
+ }
143
+ export const SettingsPanelWidget = observer((props) => {
144
+ const prefix = usePrefix('settings-panel');
145
+ const workbench = useWorkbench();
146
+ const currentNode = useCurrentNode();
147
+ const [pinning, setPinning] = React.useState(false);
148
+ const [visible, setVisible] = React.useState(true);
149
+ const isDesignable = workbench?.type === 'DESIGNABLE';
150
+ const shouldMountBody = isDesignable && visible;
151
+ const innerVisible = useDeferredPanelBodyVisible(shouldMountBody);
152
+ const resetKey = createSettingsResetKey({
153
+ currentNode,
154
+ innerVisible,
155
+ visible,
156
+ workbenchType: workbench?.type,
157
+ });
158
+ if (!isDesignable) {
159
+ return null;
160
+ }
161
+ if (!visible) {
162
+ return _jsx(SettingsPanelOpener, { prefix: prefix, setVisible: setVisible });
163
+ }
164
+ return (_jsxs("div", { className: cls(prefix, { pinning }), style: {
165
+ background: '#fff',
166
+ display: 'flex',
167
+ flexDirection: 'column',
168
+ height: '100%',
169
+ minHeight: 0,
170
+ ...props.style,
171
+ }, children: [_jsxs("div", { className: `${prefix}-header`, style: {
172
+ alignItems: 'center',
173
+ borderBottom: '1px solid #e6ebf2',
174
+ display: 'flex',
175
+ flex: '0 0 auto',
176
+ height: 40,
177
+ justifyContent: 'space-between',
178
+ padding: '0 12px',
179
+ }, children: [_jsx("div", { className: `${prefix}-header-title`, style: {
180
+ color: '#1f2a37',
181
+ fontSize: 14,
182
+ fontWeight: 600,
183
+ }, children: _jsx(TextWidget, { children: props.title || '属性设置' }) }), _jsx(SettingsPanelHeaderActions, { pinning: pinning, prefix: prefix, setPinning: setPinning, setVisible: setVisible })] }), _jsx("div", { className: `${prefix}-body`, style: {
184
+ flex: 1,
185
+ minHeight: 0,
186
+ overflow: 'auto',
187
+ padding: 0,
188
+ }, children: _jsx(SettingsPanelErrorBoundary, { resetKey: resetKey, onError: props.onError, children: innerVisible && props.children }) })] }));
189
+ });
190
+ SettingsPanelWidget.displayName = 'SettingsPanelWidget';
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export declare const StorageActionsWidget: React.FC<React.HTMLAttributes<HTMLDivElement>>;