@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,52 @@
1
+ import type { DnComponentRegistryItem } from '@yimoka/designable-react';
2
+ import type { ComponentType } from 'react';
3
+ import type { IPlaygroundScenarioPreset, ScenarioLayoutProps } from "../runtime/contracts.js";
4
+ import type { IComponentCategory, IPreviewWidgetProps, ISchemaTransformer } from "../types.js";
5
+ export declare const getBuiltInScenarioEngineKey: <S>(preset: IPlaygroundScenarioPreset<S>) => string | undefined;
6
+ export interface IPlaygroundScenarioValidationIssue {
7
+ code: 'invalid-playground-scenario-preset';
8
+ message: string;
9
+ path: string;
10
+ }
11
+ export interface IPlaygroundScenarioValidationResult {
12
+ issues: IPlaygroundScenarioValidationIssue[];
13
+ valid: boolean;
14
+ }
15
+ export interface IPlaygroundScenarioValidationResources {
16
+ examples?: Record<string, string>;
17
+ templates?: Record<string, string>;
18
+ }
19
+ export interface IAntdPlaygroundScenarioLayer<S> {
20
+ PreviewRenderer?: ComponentType<IPreviewWidgetProps<S>>;
21
+ categories?: IComponentCategory[];
22
+ components?: Record<string, DnComponentRegistryItem>;
23
+ layoutProps?: ScenarioLayoutProps;
24
+ settingsPanel?: ComponentType;
25
+ transformer?: ISchemaTransformer<S>;
26
+ }
27
+ export interface IResolveAntdPlaygroundScenarioOptions<S> {
28
+ defaults: IAntdPlaygroundScenarioLayer<S> & {
29
+ categories: IComponentCategory[];
30
+ components: Record<string, DnComponentRegistryItem>;
31
+ };
32
+ explicit?: IAntdPlaygroundScenarioLayer<S>;
33
+ extraCategories?: IComponentCategory[];
34
+ extraComponents?: Record<string, DnComponentRegistryItem>;
35
+ scenario?: IAntdPlaygroundScenarioLayer<S>;
36
+ }
37
+ export declare class PlaygroundScenarioPresetValidationError extends Error {
38
+ readonly code = "invalid-playground-scenario-preset";
39
+ readonly issues: IPlaygroundScenarioValidationIssue[];
40
+ constructor(issues: IPlaygroundScenarioValidationIssue[]);
41
+ }
42
+ export declare const validatePlaygroundScenarioPreset: (value: unknown, resources?: IPlaygroundScenarioValidationResources) => IPlaygroundScenarioValidationResult;
43
+ export declare const assertPlaygroundScenarioPreset: <S>(value: IPlaygroundScenarioPreset<S>, resources?: IPlaygroundScenarioValidationResources) => IPlaygroundScenarioPreset<S>;
44
+ export declare const assertRuntimeScenarioCompatibility: <S>(value: S, scenarioId: string) => S;
45
+ export declare const createFormPlaygroundPreset: () => IPlaygroundScenarioPreset;
46
+ export declare const createWebsitePlaygroundPreset: () => IPlaygroundScenarioPreset;
47
+ export declare const pickScenarioLayoutProps: (value: Record<string, unknown>) => ScenarioLayoutProps;
48
+ export declare const resolveAntdPlaygroundScenario: <S>({ defaults, explicit, extraCategories, extraComponents, scenario, }: IResolveAntdPlaygroundScenarioOptions<S>) => IAntdPlaygroundScenarioLayer<S> & {
49
+ categories: IComponentCategory[];
50
+ components: Record<string, DnComponentRegistryItem>;
51
+ layoutProps: ScenarioLayoutProps;
52
+ };
@@ -0,0 +1,603 @@
1
+ import { SettingsForm } from '@yimoka/designable-antd';
2
+ import { I18nEditor } from "../../demo/components/I18nEditor/index.js";
3
+ import { assertRuntimeDocument, createRuntimeDocumentTransformer, isRuntimeDocumentCandidate, RuntimeDocumentValidationError, } from "../runtime/document.js";
4
+ import { createRuntimeDynamicViewPreviewRenderer } from "../runtime/preview.js";
5
+ import { antdPlaygroundComponents, createAntdPlaygroundTransformer, } from "./antd.js";
6
+ import { createAntdRuntimeComponents, } from "./runtime-components.js";
7
+ import { FORM_CATEGORIES, FORM_EXAMPLE_IDS, WEBSITE_CATEGORIES, WEBSITE_EXAMPLE_IDS, WEBSITE_TEMPLATE_IDS, } from "./scenario-catalog.js";
8
+ const BUILT_IN_SCENARIO_ENGINE_KEYS = new WeakMap();
9
+ const registerBuiltInScenarioEngineKey = (preset, engineKey) => {
10
+ BUILT_IN_SCENARIO_ENGINE_KEYS.set(preset, engineKey);
11
+ return preset;
12
+ };
13
+ export const getBuiltInScenarioEngineKey = (preset) => BUILT_IN_SCENARIO_ENGINE_KEYS.get(preset);
14
+ const DEFAULT_SCENARIO_LAYOUT = {
15
+ availableViews: ['design', 'json', 'code', 'preview'],
16
+ defaultView: 'design',
17
+ schemaEditorReadonly: false,
18
+ showDesignerTools: true,
19
+ showHistoryPanel: true,
20
+ showNodeActions: true,
21
+ showOutlinePanel: true,
22
+ showResourcePanel: true,
23
+ showSettingsPanel: true,
24
+ showStorageActions: true,
25
+ showViewTools: true,
26
+ };
27
+ const SCENARIO_LAYOUT_KEYS = new Set([
28
+ 'availableViews',
29
+ 'defaultView',
30
+ 'leftPanelWidth',
31
+ 'position',
32
+ 'resourcePanelProps',
33
+ 'rightPanelWidth',
34
+ 'schemaEditorReadonly',
35
+ 'showDesignerTools',
36
+ 'showHistoryPanel',
37
+ 'showNodeActions',
38
+ 'showOutlinePanel',
39
+ 'showResourcePanel',
40
+ 'showSettingsPanel',
41
+ 'showStorageActions',
42
+ 'showViewTools',
43
+ 'theme',
44
+ 'variables',
45
+ ]);
46
+ const SCENARIO_RESOURCE_PANEL_KEYS = new Set([
47
+ 'className',
48
+ 'defaultExpandedCategoryKeys',
49
+ 'resourceKeywords',
50
+ 'searchPlaceholder',
51
+ 'searchable',
52
+ 'style',
53
+ ]);
54
+ const SCENARIO_KEYS = new Set([
55
+ 'PreviewRenderer',
56
+ 'categories',
57
+ 'designerComponents',
58
+ 'exampleIds',
59
+ 'id',
60
+ 'layoutProps',
61
+ 'runtimeComponents',
62
+ 'settingsPanel',
63
+ 'templateIds',
64
+ 'title',
65
+ 'transformer',
66
+ ]);
67
+ const PLAYGROUND_VIEW_TYPES = new Set([
68
+ 'code',
69
+ 'design',
70
+ 'json',
71
+ 'preview',
72
+ ]);
73
+ const SCENARIO_LAYOUT_BOOLEAN_KEYS = [
74
+ 'schemaEditorReadonly',
75
+ 'showDesignerTools',
76
+ 'showHistoryPanel',
77
+ 'showNodeActions',
78
+ 'showOutlinePanel',
79
+ 'showResourcePanel',
80
+ 'showSettingsPanel',
81
+ 'showStorageActions',
82
+ 'showViewTools',
83
+ ];
84
+ const SCENARIO_LAYOUT_POSITIONS = new Set(['absolute', 'fixed', 'relative']);
85
+ const REACT_COMPONENT_TYPE_SYMBOLS = new Set([
86
+ Symbol.for('react.forward_ref'),
87
+ Symbol.for('react.lazy'),
88
+ Symbol.for('react.memo'),
89
+ ]);
90
+ const BUILT_IN_EXAMPLE_SCENARIOS = {
91
+ 'data-manual': 'form',
92
+ 'data-store-catalog': 'form',
93
+ 'form-basic': 'form',
94
+ 'i18n-store-config': 'form',
95
+ 'official-formily-antd': 'form',
96
+ 'runtime-store-injection': 'form',
97
+ 'template-about': 'website',
98
+ 'template-contact': 'website',
99
+ 'template-landing-home': 'website',
100
+ 'template-news-detail': 'website',
101
+ 'template-news-index': 'website',
102
+ 'ui-json-roundtrip': 'form',
103
+ };
104
+ const BUILT_IN_TEMPLATE_SCENARIOS = {
105
+ about: 'website',
106
+ contact: 'website',
107
+ 'landing-home': 'website',
108
+ 'news-detail': 'website',
109
+ 'news-index': 'website',
110
+ };
111
+ export class PlaygroundScenarioPresetValidationError extends Error {
112
+ code = 'invalid-playground-scenario-preset';
113
+ issues;
114
+ constructor(issues) {
115
+ super(issues.map(issue => `${issue.path}: ${issue.message}`).join(';'));
116
+ this.name = 'PlaygroundScenarioPresetValidationError';
117
+ this.issues = issues;
118
+ }
119
+ }
120
+ const isRecord = (value) => (typeof value === 'object'
121
+ && value !== null
122
+ && !Array.isArray(value));
123
+ const pushScenarioIssue = (issues, path, message) => {
124
+ issues.push({
125
+ code: 'invalid-playground-scenario-preset',
126
+ message,
127
+ path,
128
+ });
129
+ };
130
+ const validateScenarioResourceIds = (value, path, scenarioId, scenarioIndex, issues) => {
131
+ if (!Array.isArray(value)) {
132
+ pushScenarioIssue(issues, path, '必须是 ID 数组');
133
+ return;
134
+ }
135
+ const seen = new Set();
136
+ value.forEach((item, index) => {
137
+ const itemPath = `${path}[${index}]`;
138
+ if (typeof item !== 'string' || !item.trim()) {
139
+ pushScenarioIssue(issues, itemPath, 'ID 必须是非空字符串');
140
+ return;
141
+ }
142
+ if (seen.has(item)) {
143
+ pushScenarioIssue(issues, itemPath, `ID ${item} 重复`);
144
+ return;
145
+ }
146
+ seen.add(item);
147
+ if (!scenarioIndex[item]) {
148
+ pushScenarioIssue(issues, itemPath, `资源 ${item} 不存在`);
149
+ }
150
+ else if (scenarioIndex[item] !== scenarioId) {
151
+ pushScenarioIssue(issues, itemPath, `资源 ${item} 属于场景 ${scenarioIndex[item]},不能用于 ${scenarioId}`);
152
+ }
153
+ });
154
+ };
155
+ const validateScenarioCategories = (value, designerComponents, runtimeComponents, issues) => {
156
+ if (!Array.isArray(value) || !value.length) {
157
+ pushScenarioIssue(issues, 'preset.categories', '至少需要一个组件分类');
158
+ return;
159
+ }
160
+ const categoryKeys = new Set();
161
+ value.forEach((item, categoryIndex) => {
162
+ const path = `preset.categories[${categoryIndex}]`;
163
+ if (!isRecord(item)) {
164
+ pushScenarioIssue(issues, path, '分类必须是对象');
165
+ return;
166
+ }
167
+ const { key } = item;
168
+ if (typeof item.title !== 'string' || !item.title.trim()) {
169
+ pushScenarioIssue(issues, `${path}.title`, '分类标题必须非空');
170
+ }
171
+ if (typeof key !== 'string' || !key.trim()) {
172
+ pushScenarioIssue(issues, `${path}.key`, '分类 key 必须非空');
173
+ }
174
+ else if (categoryKeys.has(key)) {
175
+ pushScenarioIssue(issues, `${path}.key`, `分类 key ${key} 重复`);
176
+ }
177
+ else {
178
+ categoryKeys.add(key);
179
+ }
180
+ if (!Array.isArray(item.components) || !item.components.length) {
181
+ pushScenarioIssue(issues, `${path}.components`, '分类至少需要一个组件');
182
+ return;
183
+ }
184
+ const componentNames = new Set();
185
+ item.components.forEach((componentName, componentIndex) => {
186
+ const componentPath = `${path}.components[${componentIndex}]`;
187
+ if (typeof componentName !== 'string' || !componentName.trim()) {
188
+ pushScenarioIssue(issues, componentPath, '组件名必须非空');
189
+ return;
190
+ }
191
+ if (componentNames.has(componentName)) {
192
+ pushScenarioIssue(issues, componentPath, `组件 ${componentName} 重复`);
193
+ }
194
+ componentNames.add(componentName);
195
+ if (!designerComponents[componentName]) {
196
+ pushScenarioIssue(issues, componentPath, `缺少设计物料 ${componentName}`);
197
+ }
198
+ else if (!hasScenarioDesignerResource(designerComponents[componentName])) {
199
+ pushScenarioIssue(issues, componentPath, `设计物料 ${componentName} 缺少可用 Resource`);
200
+ }
201
+ if (!runtimeComponents[componentName]) {
202
+ pushScenarioIssue(issues, componentPath, `缺少运行物料 ${componentName}`);
203
+ }
204
+ });
205
+ });
206
+ };
207
+ const validateScenarioResourcePanel = (value, issues) => {
208
+ if (value === undefined)
209
+ return;
210
+ const path = 'preset.layoutProps.resourcePanelProps';
211
+ if (!isRecord(value)) {
212
+ pushScenarioIssue(issues, path, 'resourcePanelProps 必须是对象');
213
+ return;
214
+ }
215
+ Object.keys(value).forEach((key) => {
216
+ if (!SCENARIO_RESOURCE_PANEL_KEYS.has(key)) {
217
+ pushScenarioIssue(issues, `${path}.${key}`, `资源面板字段 ${key} 不允许由场景接管`);
218
+ }
219
+ });
220
+ const stringFields = ['className', 'searchPlaceholder'];
221
+ stringFields.forEach((key) => {
222
+ if (value[key] !== undefined && typeof value[key] !== 'string') {
223
+ pushScenarioIssue(issues, `${path}.${key}`, `${key} 必须是字符串`);
224
+ }
225
+ });
226
+ if (value.searchable !== undefined && typeof value.searchable !== 'boolean') {
227
+ pushScenarioIssue(issues, `${path}.searchable`, 'searchable 必须是布尔值');
228
+ }
229
+ if (value.style !== undefined && !isRecord(value.style)) {
230
+ pushScenarioIssue(issues, `${path}.style`, 'style 必须是对象');
231
+ }
232
+ if (value.defaultExpandedCategoryKeys !== undefined) {
233
+ if (!Array.isArray(value.defaultExpandedCategoryKeys)) {
234
+ pushScenarioIssue(issues, `${path}.defaultExpandedCategoryKeys`, 'defaultExpandedCategoryKeys 必须是字符串数组');
235
+ }
236
+ else {
237
+ value.defaultExpandedCategoryKeys.forEach((key, index) => {
238
+ if (typeof key !== 'string' || !key.trim() || key !== key.trim()) {
239
+ pushScenarioIssue(issues, `${path}.defaultExpandedCategoryKeys[${index}]`, '展开分类 key 必须是无首尾空白的非空字符串');
240
+ }
241
+ });
242
+ }
243
+ }
244
+ if (value.resourceKeywords !== undefined) {
245
+ if (!isRecord(value.resourceKeywords)) {
246
+ pushScenarioIssue(issues, `${path}.resourceKeywords`, 'resourceKeywords 必须是映射对象');
247
+ }
248
+ else {
249
+ Object.entries(value.resourceKeywords).forEach(([componentName, keywords]) => {
250
+ if (!componentName.trim()
251
+ || componentName !== componentName.trim()
252
+ || !Array.isArray(keywords)
253
+ || keywords.some(keyword => typeof keyword !== 'string' || !keyword.trim())) {
254
+ pushScenarioIssue(issues, `${path}.resourceKeywords.${componentName}`, '资源关键词必须按合法组件名映射到非空字符串数组');
255
+ }
256
+ });
257
+ }
258
+ }
259
+ };
260
+ const validateScenarioLayout = (value, issues) => {
261
+ if (value === undefined)
262
+ return;
263
+ if (!isRecord(value)) {
264
+ pushScenarioIssue(issues, 'preset.layoutProps', '布局配置必须是对象');
265
+ return;
266
+ }
267
+ Object.keys(value).forEach((key) => {
268
+ if (!SCENARIO_LAYOUT_KEYS.has(key)) {
269
+ pushScenarioIssue(issues, `preset.layoutProps.${key}`, `布局字段 ${key} 不允许由场景接管`);
270
+ }
271
+ });
272
+ const { availableViews, defaultView } = value;
273
+ validateScenarioResourcePanel(value.resourcePanelProps, issues);
274
+ SCENARIO_LAYOUT_BOOLEAN_KEYS.forEach((key) => {
275
+ if (value[key] !== undefined && typeof value[key] !== 'boolean') {
276
+ pushScenarioIssue(issues, `preset.layoutProps.${key}`, `${key} 必须是布尔值`);
277
+ }
278
+ });
279
+ ['leftPanelWidth', 'rightPanelWidth'].forEach((key) => {
280
+ if (value[key] !== undefined
281
+ && (typeof value[key] !== 'number'
282
+ || !Number.isFinite(value[key])
283
+ || value[key] < 0)) {
284
+ pushScenarioIssue(issues, `preset.layoutProps.${key}`, `${key} 必须是非负有限数值`);
285
+ }
286
+ });
287
+ if (value.theme !== undefined
288
+ && (typeof value.theme !== 'string' || !value.theme.trim())) {
289
+ pushScenarioIssue(issues, 'preset.layoutProps.theme', 'theme 必须是非空字符串');
290
+ }
291
+ if (value.position !== undefined
292
+ && (typeof value.position !== 'string'
293
+ || !SCENARIO_LAYOUT_POSITIONS.has(value.position))) {
294
+ pushScenarioIssue(issues, 'preset.layoutProps.position', 'position 只允许 fixed、absolute 或 relative');
295
+ }
296
+ if (value.variables !== undefined) {
297
+ if (!isRecord(value.variables)) {
298
+ pushScenarioIssue(issues, 'preset.layoutProps.variables', 'variables 必须是字符串映射');
299
+ }
300
+ else {
301
+ Object.entries(value.variables).forEach(([key, variable]) => {
302
+ if (!key.trim() || typeof variable !== 'string') {
303
+ pushScenarioIssue(issues, `preset.layoutProps.variables.${key}`, 'CSS 变量名必须非空且值必须是字符串');
304
+ }
305
+ });
306
+ }
307
+ }
308
+ const effectiveAvailableViews = availableViews ?? DEFAULT_SCENARIO_LAYOUT.availableViews;
309
+ if (!Array.isArray(effectiveAvailableViews) || effectiveAvailableViews.length === 0) {
310
+ pushScenarioIssue(issues, 'preset.layoutProps.availableViews', 'availableViews 必须是非空数组');
311
+ return;
312
+ }
313
+ const seenViews = new Set();
314
+ effectiveAvailableViews.forEach((view, index) => {
315
+ if (typeof view !== 'string' || !PLAYGROUND_VIEW_TYPES.has(view)) {
316
+ pushScenarioIssue(issues, `preset.layoutProps.availableViews[${index}]`, 'availableViews 只允许 design、json、code 或 preview');
317
+ return;
318
+ }
319
+ if (seenViews.has(view)) {
320
+ pushScenarioIssue(issues, `preset.layoutProps.availableViews[${index}]`, `视图 ${view} 重复`);
321
+ }
322
+ seenViews.add(view);
323
+ });
324
+ const effectiveDefaultView = defaultView ?? DEFAULT_SCENARIO_LAYOUT.defaultView;
325
+ if (typeof effectiveDefaultView !== 'string'
326
+ || !PLAYGROUND_VIEW_TYPES.has(effectiveDefaultView)
327
+ || !effectiveAvailableViews.includes(effectiveDefaultView)) {
328
+ pushScenarioIssue(issues, 'preset.layoutProps.defaultView', 'defaultView 必须是 availableViews 中的有效视图');
329
+ }
330
+ };
331
+ const isValidScenarioComponentType = (value) => (typeof value === 'function'
332
+ || (isRecord(value)
333
+ && typeof value.$$typeof === 'symbol'
334
+ && REACT_COMPONENT_TYPE_SYMBOLS.has(value.$$typeof)));
335
+ const hasScenarioDesignerResource = (value) => {
336
+ if (typeof value !== 'function' && !isRecord(value))
337
+ return false;
338
+ const resource = value.Resource;
339
+ return Array.isArray(resource) && resource.some(item => isRecord(item) && Boolean(item.node));
340
+ };
341
+ const validateScenarioTransformer = (value, issues) => {
342
+ if (!isRecord(value)) {
343
+ pushScenarioIssue(issues, 'preset.transformer', '必须提供 Schema Transformer');
344
+ return;
345
+ }
346
+ ['toSchema', 'toTreeNode'].forEach((methodName) => {
347
+ if (typeof value[methodName] !== 'function') {
348
+ pushScenarioIssue(issues, `preset.transformer.${methodName}`, `${methodName} 必须是函数`);
349
+ }
350
+ });
351
+ ['createEmptySchema', 'prepareSchema'].forEach((methodName) => {
352
+ if (value[methodName] !== undefined && typeof value[methodName] !== 'function') {
353
+ pushScenarioIssue(issues, `preset.transformer.${methodName}`, `${methodName} 必须是函数`);
354
+ }
355
+ });
356
+ if (value.historySnapshotMode !== undefined
357
+ && value.historySnapshotMode !== 'atomic'
358
+ && value.historySnapshotMode !== 'deferred') {
359
+ pushScenarioIssue(issues, 'preset.transformer.historySnapshotMode', 'historySnapshotMode 只允许 atomic 或 deferred');
360
+ }
361
+ };
362
+ export const validatePlaygroundScenarioPreset = (value, resources = {}) => {
363
+ const issues = [];
364
+ if (!isRecord(value)) {
365
+ pushScenarioIssue(issues, 'preset', '场景预设必须是对象');
366
+ return { issues, valid: false };
367
+ }
368
+ Object.keys(value).forEach((key) => {
369
+ if (!SCENARIO_KEYS.has(key)) {
370
+ pushScenarioIssue(issues, `preset.${key}`, `未知场景字段 ${key}`);
371
+ }
372
+ });
373
+ const scenarioId = typeof value.id === 'string' ? value.id.trim() : '';
374
+ if (!scenarioId)
375
+ pushScenarioIssue(issues, 'preset.id', '场景 id 必须非空');
376
+ if (typeof value.id === 'string' && value.id !== scenarioId) {
377
+ pushScenarioIssue(issues, 'preset.id', '场景 id 不能包含首尾空白');
378
+ }
379
+ if (typeof value.title !== 'string' || !value.title.trim()) {
380
+ pushScenarioIssue(issues, 'preset.title', '场景标题必须非空');
381
+ }
382
+ const designerComponents = isRecord(value.designerComponents)
383
+ ? value.designerComponents
384
+ : {};
385
+ const runtimeComponents = isRecord(value.runtimeComponents)
386
+ ? value.runtimeComponents
387
+ : {};
388
+ if (!isRecord(value.designerComponents)) {
389
+ pushScenarioIssue(issues, 'preset.designerComponents', '设计物料表必须是对象');
390
+ }
391
+ else {
392
+ Object.entries(value.designerComponents).forEach(([componentName, component]) => {
393
+ if (!isValidScenarioComponentType(component)) {
394
+ pushScenarioIssue(issues, `preset.designerComponents.${componentName}`, `设计物料 ${componentName} 必须是可渲染的 React 组件类型`);
395
+ }
396
+ });
397
+ }
398
+ if (!isRecord(value.runtimeComponents)) {
399
+ pushScenarioIssue(issues, 'preset.runtimeComponents', '运行物料表必须是对象');
400
+ }
401
+ else {
402
+ Object.entries(value.runtimeComponents).forEach(([componentName, component]) => {
403
+ if (!isValidScenarioComponentType(component)) {
404
+ pushScenarioIssue(issues, `preset.runtimeComponents.${componentName}`, `运行物料 ${componentName} 必须是可渲染的 React 组件类型`);
405
+ }
406
+ });
407
+ }
408
+ ['PreviewRenderer', 'settingsPanel'].forEach((componentKey) => {
409
+ if (value[componentKey] !== undefined
410
+ && !isValidScenarioComponentType(value[componentKey])) {
411
+ pushScenarioIssue(issues, `preset.${componentKey}`, `${componentKey} 必须是可渲染的 React 组件类型`);
412
+ }
413
+ });
414
+ validateScenarioTransformer(value.transformer, issues);
415
+ validateScenarioCategories(value.categories, designerComponents, runtimeComponents, issues);
416
+ validateScenarioLayout(value.layoutProps, issues);
417
+ validateScenarioResourceIds(value.exampleIds, 'preset.exampleIds', scenarioId, {
418
+ ...(resources.examples ?? {}),
419
+ ...BUILT_IN_EXAMPLE_SCENARIOS,
420
+ }, issues);
421
+ validateScenarioResourceIds(value.templateIds, 'preset.templateIds', scenarioId, {
422
+ ...(resources.templates ?? {}),
423
+ ...BUILT_IN_TEMPLATE_SCENARIOS,
424
+ }, issues);
425
+ return {
426
+ issues,
427
+ valid: issues.length === 0,
428
+ };
429
+ };
430
+ export const assertPlaygroundScenarioPreset = (value, resources) => {
431
+ const result = validatePlaygroundScenarioPreset(value, resources);
432
+ if (!result.valid)
433
+ throw new PlaygroundScenarioPresetValidationError(result.issues);
434
+ return value;
435
+ };
436
+ export const assertRuntimeScenarioCompatibility = (value, scenarioId) => {
437
+ if (!isRuntimeDocumentCandidate(value))
438
+ return value;
439
+ const document = assertRuntimeDocument(value);
440
+ const documentScenarioId = document.metadata?.scenarioId;
441
+ if (documentScenarioId && documentScenarioId !== scenarioId) {
442
+ throw new RuntimeDocumentValidationError([
443
+ {
444
+ code: 'runtime-scenario-mismatch',
445
+ message: `Runtime 文档场景 ${documentScenarioId} 与当前场景 ${scenarioId} 不一致`,
446
+ path: 'document.metadata.scenarioId',
447
+ severity: 'error',
448
+ },
449
+ ]);
450
+ }
451
+ return document;
452
+ };
453
+ const cloneLegacySchema = (value) => JSON.parse(JSON.stringify(value));
454
+ const createScenarioTransformer = (scenarioId) => {
455
+ const baseTransformer = createAntdPlaygroundTransformer();
456
+ const runtimeTransformer = createRuntimeDocumentTransformer(baseTransformer);
457
+ return {
458
+ ...runtimeTransformer,
459
+ createEmptySchema: (value) => {
460
+ if (isRuntimeDocumentCandidate(value)) {
461
+ return runtimeTransformer.createEmptySchema(value);
462
+ }
463
+ if (isRecord(value)
464
+ && isRecord(value.schema)
465
+ && !Object.prototype.hasOwnProperty.call(value, 'kind')
466
+ && !Object.prototype.hasOwnProperty.call(value, 'version')) {
467
+ const emptyPackage = {
468
+ ...cloneLegacySchema(value),
469
+ schema: {
470
+ ...cloneLegacySchema(value.schema),
471
+ properties: {},
472
+ type: 'object',
473
+ },
474
+ };
475
+ return emptyPackage;
476
+ }
477
+ return {
478
+ properties: {},
479
+ type: 'object',
480
+ };
481
+ },
482
+ prepareSchema: (value) => {
483
+ if (!isRuntimeDocumentCandidate(value))
484
+ return cloneLegacySchema(value);
485
+ return assertRuntimeScenarioCompatibility(value, scenarioId);
486
+ },
487
+ };
488
+ };
489
+ const cloneCategories = (categories) => (categories.map(category => ({
490
+ ...category,
491
+ components: [...category.components],
492
+ })));
493
+ const createScenarioDesignerComponents = (categories, extraComponents = {}) => {
494
+ const componentNames = new Set([
495
+ 'FormItem',
496
+ ...categories.flatMap(category => category.components),
497
+ ]);
498
+ return {
499
+ ...Object.fromEntries([...componentNames].map(componentName => [
500
+ componentName,
501
+ antdPlaygroundComponents[componentName],
502
+ ])),
503
+ ...extraComponents,
504
+ };
505
+ };
506
+ const createScenarioRuntimeComponents = (categories, extraNames = []) => {
507
+ const allComponents = createAntdRuntimeComponents();
508
+ const componentNames = new Set([
509
+ 'FormItem',
510
+ ...extraNames,
511
+ ...categories.flatMap(category => category.components),
512
+ ]);
513
+ return Object.fromEntries([...componentNames].map(componentName => [
514
+ componentName,
515
+ allComponents[componentName],
516
+ ]));
517
+ };
518
+ export const createFormPlaygroundPreset = () => {
519
+ const categories = cloneCategories(FORM_CATEGORIES);
520
+ const runtimeComponents = createScenarioRuntimeComponents(categories, ['I18nEditor']);
521
+ return registerBuiltInScenarioEngineKey({
522
+ PreviewRenderer: createRuntimeDynamicViewPreviewRenderer({
523
+ runtimeComponents,
524
+ }),
525
+ categories,
526
+ designerComponents: createScenarioDesignerComponents(categories, { I18nEditor }),
527
+ exampleIds: [...FORM_EXAMPLE_IDS],
528
+ id: 'form',
529
+ layoutProps: {
530
+ ...DEFAULT_SCENARIO_LAYOUT,
531
+ leftPanelWidth: 240,
532
+ resourcePanelProps: {
533
+ defaultExpandedCategoryKeys: [
534
+ 'form-input',
535
+ 'form-choice',
536
+ 'form-layout',
537
+ ],
538
+ },
539
+ rightPanelWidth: 360,
540
+ },
541
+ runtimeComponents,
542
+ settingsPanel: SettingsForm,
543
+ templateIds: [],
544
+ title: '表单设计',
545
+ transformer: createScenarioTransformer('form'),
546
+ }, 'built-in:form@1');
547
+ };
548
+ export const createWebsitePlaygroundPreset = () => {
549
+ const categories = cloneCategories(WEBSITE_CATEGORIES);
550
+ const runtimeComponents = createScenarioRuntimeComponents(categories);
551
+ return registerBuiltInScenarioEngineKey({
552
+ PreviewRenderer: createRuntimeDynamicViewPreviewRenderer({
553
+ runtimeComponents,
554
+ }),
555
+ categories,
556
+ designerComponents: createScenarioDesignerComponents(categories),
557
+ exampleIds: [...WEBSITE_EXAMPLE_IDS],
558
+ id: 'website',
559
+ layoutProps: {
560
+ ...DEFAULT_SCENARIO_LAYOUT,
561
+ leftPanelWidth: 280,
562
+ resourcePanelProps: {
563
+ defaultExpandedCategoryKeys: [
564
+ 'website-content',
565
+ 'website-layout',
566
+ 'website-navigation',
567
+ ],
568
+ },
569
+ rightPanelWidth: 380,
570
+ },
571
+ runtimeComponents,
572
+ settingsPanel: SettingsForm,
573
+ templateIds: [...WEBSITE_TEMPLATE_IDS],
574
+ title: '官网设计',
575
+ transformer: createScenarioTransformer('website'),
576
+ }, 'built-in:website@1');
577
+ };
578
+ export const pickScenarioLayoutProps = (value) => Object.fromEntries([...SCENARIO_LAYOUT_KEYS]
579
+ .filter(key => value[key] !== undefined)
580
+ .map(key => [key, value[key]]));
581
+ const resolveScenarioLayerValue = (explicit, scenario, defaults) => explicit ?? scenario ?? defaults;
582
+ export const resolveAntdPlaygroundScenario = ({ defaults, explicit, extraCategories, extraComponents, scenario, }) => {
583
+ const baseCategories = resolveScenarioLayerValue(explicit?.categories, scenario?.categories, defaults.categories);
584
+ const baseComponents = resolveScenarioLayerValue(explicit?.components, scenario?.components, defaults.components);
585
+ return {
586
+ PreviewRenderer: resolveScenarioLayerValue(explicit?.PreviewRenderer, scenario?.PreviewRenderer, defaults.PreviewRenderer),
587
+ categories: [
588
+ ...baseCategories,
589
+ ...(extraCategories ?? []),
590
+ ],
591
+ components: {
592
+ ...baseComponents,
593
+ ...(extraComponents ?? {}),
594
+ },
595
+ layoutProps: {
596
+ ...(defaults.layoutProps ?? {}),
597
+ ...(scenario?.layoutProps ?? {}),
598
+ ...(explicit?.layoutProps ?? {}),
599
+ },
600
+ settingsPanel: resolveScenarioLayerValue(explicit?.settingsPanel, scenario?.settingsPanel, defaults.settingsPanel),
601
+ transformer: resolveScenarioLayerValue(explicit?.transformer, scenario?.transformer, defaults.transformer),
602
+ };
603
+ };
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import type { RuntimeEnvironment } from "./contracts.js";
3
+ import type { IRuntimePlaygroundApi } from "./playground.js";
4
+ import { type ReadonlyTemplateDescriptorV1, type RuntimeTemplateConfirm } from "./templates.js";
5
+ export interface IRuntimeSettingsActionProps {
6
+ api?: IRuntimePlaygroundApi | null;
7
+ environment?: RuntimeEnvironment;
8
+ onError?: (error: unknown) => void;
9
+ }
10
+ export interface IRuntimeTemplateSelectorActionProps {
11
+ api?: IRuntimePlaygroundApi | null;
12
+ confirm?: RuntimeTemplateConfirm;
13
+ onError?: (error: unknown) => void;
14
+ scenarioId: string;
15
+ templateIds: string[];
16
+ templates?: readonly ReadonlyTemplateDescriptorV1[];
17
+ }
18
+ export declare const RuntimeSettingsAction: ({ api, environment, onError, }: IRuntimeSettingsActionProps) => React.JSX.Element;
19
+ export declare const RuntimeTemplateSelectorAction: ({ api, confirm, onError, scenarioId, templateIds, templates: customTemplates, }: IRuntimeTemplateSelectorActionProps) => React.JSX.Element;