@xbeeant/form-engine-designer 0.0.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 (117) hide show
  1. package/README.md +69 -0
  2. package/dist/es/Canvas.js +636 -0
  3. package/dist/es/Canvas.js.map +1 -0
  4. package/dist/es/Designer.js +162 -0
  5. package/dist/es/Designer.js.map +1 -0
  6. package/dist/es/DesignerContext.js +97 -0
  7. package/dist/es/DesignerContext.js.map +1 -0
  8. package/dist/es/Palette.js +148 -0
  9. package/dist/es/Palette.js.map +1 -0
  10. package/dist/es/PropertyPanel.js +294 -0
  11. package/dist/es/PropertyPanel.js.map +1 -0
  12. package/dist/es/ResizablePanel.js +103 -0
  13. package/dist/es/ResizablePanel.js.map +1 -0
  14. package/dist/es/catalog.js +514 -0
  15. package/dist/es/catalog.js.map +1 -0
  16. package/dist/es/form-engine-designer.css +1 -0
  17. package/dist/es/index.js +20 -0
  18. package/dist/es/index.js.map +1 -0
  19. package/dist/es/property/basic-property.js +115 -0
  20. package/dist/es/property/basic-property.js.map +1 -0
  21. package/dist/es/react/src/components/FormController.js +154 -0
  22. package/dist/es/react/src/components/FormController.js.map +1 -0
  23. package/dist/es/react/src/components/NexusField.js +99 -0
  24. package/dist/es/react/src/components/NexusField.js.map +1 -0
  25. package/dist/es/react/src/components/NexusForm.js +121 -0
  26. package/dist/es/react/src/components/NexusForm.js.map +1 -0
  27. package/dist/es/react/src/components/NexusFormProvider.js +19 -0
  28. package/dist/es/react/src/components/NexusFormProvider.js.map +1 -0
  29. package/dist/es/react/src/components/NexusLayout.js +49 -0
  30. package/dist/es/react/src/components/NexusLayout.js.map +1 -0
  31. package/dist/es/react/src/components/NexusObject.js +65 -0
  32. package/dist/es/react/src/components/NexusObject.js.map +1 -0
  33. package/dist/es/react/src/contexts/FieldInheritContext.js +6 -0
  34. package/dist/es/react/src/contexts/FieldInheritContext.js.map +1 -0
  35. package/dist/es/react/src/contexts/GridContext.js +6 -0
  36. package/dist/es/react/src/contexts/GridContext.js.map +1 -0
  37. package/dist/es/react/src/contexts/LayoutConfigContext.js +6 -0
  38. package/dist/es/react/src/contexts/LayoutConfigContext.js.map +1 -0
  39. package/dist/es/react/src/contexts/NexusContext.js +13 -0
  40. package/dist/es/react/src/contexts/NexusContext.js.map +1 -0
  41. package/dist/es/react/src/hooks/useForm.js +10 -0
  42. package/dist/es/react/src/hooks/useForm.js.map +1 -0
  43. package/dist/es/react/src/utils/renderTreeNode.js +18 -0
  44. package/dist/es/react/src/utils/renderTreeNode.js.map +1 -0
  45. package/dist/es/react/src/utils/resolveColSpan.js +10 -0
  46. package/dist/es/react/src/utils/resolveColSpan.js.map +1 -0
  47. package/dist/es/schemaUtils.js +286 -0
  48. package/dist/es/schemaUtils.js.map +1 -0
  49. package/dist/es/schemaUtils.test.js +188 -0
  50. package/dist/es/schemaUtils.test.js.map +1 -0
  51. package/dist/es/types.js +2 -0
  52. package/dist/es/types.js.map +1 -0
  53. package/dist/es/vite-env.d.js +2 -0
  54. package/dist/es/vite-env.d.js.map +1 -0
  55. package/dist/es/widgets/BindEditor.js +67 -0
  56. package/dist/es/widgets/BindEditor.js.map +1 -0
  57. package/dist/es/widgets/CodeEditor.js +84 -0
  58. package/dist/es/widgets/CodeEditor.js.map +1 -0
  59. package/dist/es/widgets/DefaultEditor.js +55 -0
  60. package/dist/es/widgets/DefaultEditor.js.map +1 -0
  61. package/dist/es/widgets/DependenciesEditor.js +36 -0
  62. package/dist/es/widgets/DependenciesEditor.js.map +1 -0
  63. package/dist/es/widgets/EnumEditor.js +49 -0
  64. package/dist/es/widgets/EnumEditor.js.map +1 -0
  65. package/dist/es/widgets/ExpressionBuilder.js +367 -0
  66. package/dist/es/widgets/ExpressionBuilder.js.map +1 -0
  67. package/dist/es/widgets/ExpressionSwitch.js +47 -0
  68. package/dist/es/widgets/ExpressionSwitch.js.map +1 -0
  69. package/dist/es/widgets/OptionsEditor.js +102 -0
  70. package/dist/es/widgets/OptionsEditor.js.map +1 -0
  71. package/dist/es/widgets/ReactionsEditor.js +401 -0
  72. package/dist/es/widgets/ReactionsEditor.js.map +1 -0
  73. package/dist/es/widgets/RemoteDataEditor.js +314 -0
  74. package/dist/es/widgets/RemoteDataEditor.js.map +1 -0
  75. package/dist/es/widgets/ValidateEditor.js +118 -0
  76. package/dist/es/widgets/ValidateEditor.js.map +1 -0
  77. package/dist/es/widgets/expressionModel.js +340 -0
  78. package/dist/es/widgets/expressionModel.js.map +1 -0
  79. package/dist/es/widgets/expressionModel.test.js +193 -0
  80. package/dist/es/widgets/expressionModel.test.js.map +1 -0
  81. package/dist/es/widgets/index.js +57 -0
  82. package/dist/es/widgets/index.js.map +1 -0
  83. package/dist/es/widgets/reactionsModel.js +107 -0
  84. package/dist/es/widgets/reactionsModel.js.map +1 -0
  85. package/dist/es/widgets/useFormDataFields.js +16 -0
  86. package/dist/es/widgets/useFormDataFields.js.map +1 -0
  87. package/package.json +62 -0
  88. package/src/Canvas.tsx +1111 -0
  89. package/src/Designer.css +206 -0
  90. package/src/Designer.tsx +254 -0
  91. package/src/DesignerContext.tsx +192 -0
  92. package/src/Palette.tsx +261 -0
  93. package/src/PropertyPanel.tsx +486 -0
  94. package/src/ResizablePanel.tsx +210 -0
  95. package/src/catalog.ts +526 -0
  96. package/src/index.ts +25 -0
  97. package/src/property/basic-property.ts +126 -0
  98. package/src/schemaUtils.test.ts +261 -0
  99. package/src/schemaUtils.ts +627 -0
  100. package/src/types.ts +38 -0
  101. package/src/vite-env.d.ts +1 -0
  102. package/src/widgets/BindEditor.tsx +105 -0
  103. package/src/widgets/CodeEditor.tsx +114 -0
  104. package/src/widgets/DefaultEditor.tsx +73 -0
  105. package/src/widgets/DependenciesEditor.tsx +56 -0
  106. package/src/widgets/EnumEditor.tsx +66 -0
  107. package/src/widgets/ExpressionBuilder.tsx +509 -0
  108. package/src/widgets/ExpressionSwitch.tsx +62 -0
  109. package/src/widgets/OptionsEditor.tsx +141 -0
  110. package/src/widgets/ReactionsEditor.tsx +532 -0
  111. package/src/widgets/RemoteDataEditor.tsx +382 -0
  112. package/src/widgets/ValidateEditor.tsx +162 -0
  113. package/src/widgets/expressionModel.test.ts +262 -0
  114. package/src/widgets/expressionModel.ts +573 -0
  115. package/src/widgets/index.ts +45 -0
  116. package/src/widgets/reactionsModel.ts +190 -0
  117. package/src/widgets/useFormDataFields.ts +21 -0
package/README.md ADDED
@@ -0,0 +1,69 @@
1
+ # React + TypeScript + Vite
2
+
3
+ This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
4
+
5
+ Currently, two official plugins are available:
6
+
7
+ - [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Babel](https://babeljs.io/) for Fast Refresh
8
+ - [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
9
+
10
+ ## Expanding the ESLint configuration
11
+
12
+ If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
13
+
14
+ ```js
15
+ export default tseslint.config([
16
+ globalIgnores(['dist']),
17
+ {
18
+ files: ['**/*.{ts,tsx}'],
19
+ extends: [
20
+ // Other configs...
21
+
22
+ // Remove tseslint.configs.recommended and replace with this
23
+ ...tseslint.configs.recommendedTypeChecked,
24
+ // Alternatively, use this for stricter rules
25
+ ...tseslint.configs.strictTypeChecked,
26
+ // Optionally, add this for stylistic rules
27
+ ...tseslint.configs.stylisticTypeChecked,
28
+
29
+ // Other configs...
30
+ ],
31
+ languageOptions: {
32
+ parserOptions: {
33
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
34
+ tsconfigRootDir: import.meta.dirname,
35
+ },
36
+ // other options...
37
+ },
38
+ },
39
+ ])
40
+ ```
41
+
42
+ You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
43
+
44
+ ```js
45
+ // eslint.config.js
46
+ import reactX from 'eslint-plugin-react-x'
47
+ import reactDom from 'eslint-plugin-react-dom'
48
+
49
+ export default tseslint.config([
50
+ globalIgnores(['dist']),
51
+ {
52
+ files: ['**/*.{ts,tsx}'],
53
+ extends: [
54
+ // Other configs...
55
+ // Enable lint rules for React
56
+ reactX.configs['recommended-typescript'],
57
+ // Enable lint rules for React DOM
58
+ reactDom.configs.recommended,
59
+ ],
60
+ languageOptions: {
61
+ parserOptions: {
62
+ project: ['./tsconfig.node.json', './tsconfig.app.json'],
63
+ tsconfigRootDir: import.meta.dirname,
64
+ },
65
+ // other options...
66
+ },
67
+ },
68
+ ])
69
+ ```
@@ -0,0 +1,636 @@
1
+ import { jsxs as F, jsx as s, Fragment as Ee } from "react/jsx-runtime";
2
+ import { isLayoutNode as Oe, isDataField as Se } from "@xbeeant/form-engine";
3
+ import { NexusField as Ie } from "./react/src/components/NexusField.js";
4
+ import { NexusForm as ke } from "./react/src/components/NexusForm.js";
5
+ import { NexusFormProvider as Fe } from "./react/src/components/NexusFormProvider.js";
6
+ import { GridContext as Ae } from "./react/src/contexts/GridContext.js";
7
+ import { useForm as pe } from "./react/src/hooks/useForm.js";
8
+ import { Tag as _e, Typography as de, Button as J, Space as je, Modal as Ke, Empty as Re } from "antd";
9
+ import { memo as Le, useMemo as ie, useState as ue, useEffect as re, useCallback as w } from "react";
10
+ import { useDesigner as ze } from "./DesignerContext.js";
11
+ import { getPropertiesOf as ee, getNodeLabel as Je, getNodeAtProperties as M, moveNodeInSchema as B, removeNodeFromSchema as fe, generateKey as G } from "./schemaUtils.js";
12
+ const he = "application/json";
13
+ function le(e, t) {
14
+ return !e || e.length !== t.length ? !1 : e.every((r, o) => r === t[o]);
15
+ }
16
+ function Me(e, t) {
17
+ return e === null && t === null ? !0 : e === null || t === null ? !1 : e.type === t.type && le(e.path, t.path);
18
+ }
19
+ const Pe = {
20
+ tabPane: "tabs",
21
+ collapsePanel: "collapse",
22
+ step: "steps"
23
+ }, be = {
24
+ tabs: "tabPane",
25
+ collapse: "collapsePanel",
26
+ steps: "step"
27
+ }, xe = {
28
+ tabPane: "标签页",
29
+ collapsePanel: "折叠面板",
30
+ step: "步骤"
31
+ };
32
+ function De(e, t) {
33
+ if (t.length === 0)
34
+ return;
35
+ const r = M(e.properties, t);
36
+ return r ? r.type : void 0;
37
+ }
38
+ function ge(e, t, r, o, p) {
39
+ const P = De(e, t), d = Pe[o];
40
+ if (d)
41
+ return P === d ? r : null;
42
+ const f = P ? be[P] : void 0;
43
+ return f ? () => ({
44
+ type: f,
45
+ title: xe[f],
46
+ properties: {
47
+ [p ?? G({})]: r()
48
+ }
49
+ }) : r;
50
+ }
51
+ function ye(e, t, r) {
52
+ const o = M(e.properties, t);
53
+ if (!o)
54
+ return null;
55
+ const p = De(e, r), P = o.type, d = Pe[P];
56
+ if (d)
57
+ return p === d ? { node: o, wrapped: !1 } : null;
58
+ const f = p ? be[p] : void 0;
59
+ return f ? {
60
+ wrapped: !0,
61
+ node: {
62
+ type: f,
63
+ title: xe[f],
64
+ properties: {
65
+ [t[t.length - 1]]: o
66
+ }
67
+ }
68
+ } : { node: o, wrapped: !1 };
69
+ }
70
+ function $e(e, t) {
71
+ return e.length <= t.length ? t.slice(0, e.length).every((r, o) => r === e[o]) : !1;
72
+ }
73
+ function me(e, t) {
74
+ if ($e(e, t))
75
+ return !1;
76
+ const r = e.slice(0, -1);
77
+ return !(r.length === t.length && r.every((o, p) => o === t[p]));
78
+ }
79
+ function ve(e, t) {
80
+ if (!e || e.type === "inside")
81
+ return null;
82
+ const r = we(t, e.path);
83
+ if (r === -1)
84
+ return null;
85
+ const o = e.path.slice(0, -1);
86
+ return e.type === "before" ? { toParentPath: o, insertIndex: r } : { toParentPath: o, insertIndex: r + 1 };
87
+ }
88
+ function qe(e, t, r) {
89
+ return e.category === "widget" ? t.find((o) => o.widget === e.widget) : r.find((o) => o.layoutType === e.layoutType);
90
+ }
91
+ function We(e) {
92
+ return ["checkbox", "switch"].includes(e) ? "boolean" : ["number", "slider"].includes(e) ? "number" : ["checkboxes", "multiSelect"].includes(e) ? "array" : e === "object" ? "object" : "string";
93
+ }
94
+ function we(e, t) {
95
+ const r = t.slice(0, -1), o = t[t.length - 1], p = r.length === 0 ? e : M(e, r) && ee(M(e, r));
96
+ return p ? Object.keys(p).indexOf(o) : -1;
97
+ }
98
+ function oe(e, t) {
99
+ if (t.length === 0)
100
+ return e.properties;
101
+ const r = M(e.properties, t);
102
+ return r ? ee(r) : void 0;
103
+ }
104
+ function Ye(e, t) {
105
+ const r = e.currentTarget.getBoundingClientRect();
106
+ return { type: e.clientY - r.top < r.height / 2 ? "before" : "after", path: t };
107
+ }
108
+ function U(e) {
109
+ return JSON.stringify(e);
110
+ }
111
+ const Be = Le(
112
+ function e({
113
+ node: t,
114
+ pathKey: r,
115
+ depth: o,
116
+ parentDataPath: p,
117
+ isSelected: P,
118
+ dropTargetType: d,
119
+ selectedPathKey: f,
120
+ dropTarget: N,
121
+ actions: h
122
+ }) {
123
+ const a = ie(() => JSON.parse(r), [r]), T = ee(t), C = T !== void 0, V = Je(t, a[a.length - 1]), O = t.widget || t.type, A = Oe(t), $ = A ? p : p ? `${p}.${a[a.length - 1]}` : a[a.length - 1], j = T ? Object.entries(T) : [], H = Se(t);
124
+ return /* @__PURE__ */ F(
125
+ "div",
126
+ {
127
+ className: "mb-1.5 relative",
128
+ style: { marginLeft: o },
129
+ children: [
130
+ d === "before" && /* @__PURE__ */ s("div", { className: "drop-indicator-line relative h-1 pointer-events-none z-10 -mt-0.5" }),
131
+ /* @__PURE__ */ F(
132
+ "div",
133
+ {
134
+ className: `relative rounded border bg-white transition-all ${P ? "border-[#1677ff] bg-[#e6f4ff] shadow-[0_0_0_2px_rgba(22,119,255,0.1)]" : "border-[#e8e8e8] hover:border-[#1677ff]"}`,
135
+ children: [
136
+ /* @__PURE__ */ F(
137
+ "div",
138
+ {
139
+ className: "flex items-center gap-1.5 px-2 py-1.5 cursor-grab",
140
+ draggable: !0,
141
+ onDragStart: (c) => h.onDragStart(c, a),
142
+ onDragOver: (c) => h.onDragOver(c, a),
143
+ onDragLeave: (c) => {
144
+ c.stopPropagation();
145
+ },
146
+ onDrop: (c) => h.onNodeDrop(c, a),
147
+ onClick: (c) => {
148
+ c.stopPropagation(), h.onSelect(a);
149
+ },
150
+ children: [
151
+ /* @__PURE__ */ s(
152
+ _e,
153
+ {
154
+ color: C || A ? "blue" : void 0,
155
+ className: "m-0! shrink-0",
156
+ children: O
157
+ }
158
+ ),
159
+ /* @__PURE__ */ s(de.Text, { className: "flex-1 overflow-hidden text-ellipsis whitespace-nowrap", children: V }),
160
+ /* @__PURE__ */ s(de.Text, { className: "text-[#bfbfbf] text-[11px] font-mono shrink-0", children: a[a.length - 1] }),
161
+ P && /* @__PURE__ */ F("span", { className: "inline-flex gap-1", children: [
162
+ /* @__PURE__ */ s(
163
+ J,
164
+ {
165
+ size: "small",
166
+ onClick: (c) => {
167
+ c.stopPropagation(), h.onReorder(a, "up");
168
+ },
169
+ children: "↑"
170
+ }
171
+ ),
172
+ /* @__PURE__ */ s(
173
+ J,
174
+ {
175
+ size: "small",
176
+ onClick: (c) => {
177
+ c.stopPropagation(), h.onReorder(a, "down");
178
+ },
179
+ children: "↓"
180
+ }
181
+ ),
182
+ /* @__PURE__ */ s(
183
+ J,
184
+ {
185
+ size: "small",
186
+ danger: !0,
187
+ onClick: (c) => {
188
+ c.stopPropagation(), h.onDelete(a);
189
+ },
190
+ children: "×"
191
+ }
192
+ )
193
+ ] })
194
+ ]
195
+ }
196
+ ),
197
+ H && /* @__PURE__ */ s("div", { className: "px-2 pb-2", children: /* @__PURE__ */ s(
198
+ Ie,
199
+ {
200
+ dataPath: $,
201
+ layoutKey: a[a.length - 1]
202
+ }
203
+ ) }),
204
+ !H && C && (() => {
205
+ const c = t.type === "grid", K = t.type === "flex";
206
+ let R, L = null;
207
+ if (c) {
208
+ const g = Math.max(1, t.column ?? 2), S = t.gap ?? 12;
209
+ R = {
210
+ display: "grid",
211
+ gridTemplateColumns: `repeat(${g}, 1fr)`,
212
+ gap: `${S}px`
213
+ }, L = { column: g };
214
+ } else if (K) {
215
+ const g = t.gap ?? 8, S = t.direction ?? "row", b = t.align ?? "flex-start", _ = t.justify ?? "flex-start", W = t.wrap ?? !1;
216
+ R = {
217
+ display: "flex",
218
+ flexDirection: S === "column" ? "column" : "row",
219
+ alignItems: b,
220
+ justifyContent: _,
221
+ flexWrap: W ? "wrap" : "nowrap",
222
+ gap: `${g}px`
223
+ };
224
+ }
225
+ const Q = /* @__PURE__ */ F(Ee, { children: [
226
+ j.map(([g, S]) => {
227
+ const b = U([...a, g]), _ = f === b, W = N && (N.type === "before" || N.type === "after") && Ge(N) === b ? N.type : null;
228
+ return /* @__PURE__ */ s(
229
+ e,
230
+ {
231
+ node: S,
232
+ pathKey: b,
233
+ depth: o + 1,
234
+ parentDataPath: $,
235
+ isSelected: _,
236
+ dropTargetType: W,
237
+ selectedPathKey: f,
238
+ dropTarget: N,
239
+ actions: h
240
+ },
241
+ b
242
+ );
243
+ }),
244
+ j.length === 0 && /* @__PURE__ */ s("div", { className: "text-[#bfbfbf] text-xs text-center py-2", children: "拖拽组件到此处" })
245
+ ] }), q = /* @__PURE__ */ s(
246
+ "div",
247
+ {
248
+ className: "mx-2 mb-2 p-2 border border-dashed rounded min-h-8 bg-[rgba(250,250,250,0.6)] border-[#d9d9d9]",
249
+ style: R,
250
+ onClick: (g) => {
251
+ g.stopPropagation();
252
+ },
253
+ onDragOver: h.onContainerDragOver,
254
+ onDrop: (g) => h.onContainerDrop(g, a),
255
+ children: Q
256
+ }
257
+ );
258
+ return L ? /* @__PURE__ */ s(Ae.Provider, { value: L, children: q }) : q;
259
+ })()
260
+ ]
261
+ }
262
+ ),
263
+ d === "after" && /* @__PURE__ */ s("div", { className: "drop-indicator-line relative h-1 pointer-events-none z-10 -mb-0.5" })
264
+ ]
265
+ },
266
+ r
267
+ );
268
+ },
269
+ (e, t) => e.node === t.node && e.pathKey === t.pathKey && e.depth === t.depth && e.parentDataPath === t.parentDataPath && e.isSelected === t.isSelected && e.dropTargetType === t.dropTargetType && e.actions === t.actions
270
+ );
271
+ function Ge(e) {
272
+ return e === null || e.type === "inside" ? null : U(e.path);
273
+ }
274
+ function it() {
275
+ const {
276
+ schema: e,
277
+ selectedPath: t,
278
+ mode: r,
279
+ selectNode: o,
280
+ addNode: p,
281
+ removeNode: P,
282
+ setSchema: d,
283
+ registerUI: f,
284
+ widgetCatalog: N,
285
+ layoutCatalog: h
286
+ } = ze(), [a] = pe(), [T] = pe(), C = a._getEngine(), V = T._getEngine(), [O, A] = ue(null), [$, j] = ue(null);
287
+ re(() => {
288
+ f?.(C), f?.(V);
289
+ }, [f, C, V]), re(() => {
290
+ if (r === "preview")
291
+ return;
292
+ const n = C.getFormData();
293
+ C.init(
294
+ e,
295
+ Object.keys(n).length > 0 ? n : void 0
296
+ );
297
+ }, [C, e, r]);
298
+ const H = ie(
299
+ () => ({
300
+ displayType: e.displayType ?? "row",
301
+ labelWidth: e.labelWidth,
302
+ colon: e.colon,
303
+ label: e.label ?? !0,
304
+ readOnly: e.readOnly ?? !1,
305
+ column: e.column
306
+ }),
307
+ [e]
308
+ );
309
+ re(() => {
310
+ const n = () => A(null);
311
+ return window.addEventListener("dragend", n), () => window.removeEventListener("dragend", n);
312
+ }, []);
313
+ const c = w(
314
+ (n) => {
315
+ if (n.length === 0)
316
+ return e.properties;
317
+ const i = M(e.properties, n);
318
+ return i ? ee(i) : void 0;
319
+ },
320
+ [e]
321
+ ), K = w(
322
+ (n, i) => {
323
+ if (n.preventDefault(), n.stopPropagation(), A(null), !i)
324
+ return;
325
+ const m = n.dataTransfer.getData(he);
326
+ if (!m)
327
+ return;
328
+ let E;
329
+ try {
330
+ E = JSON.parse(m);
331
+ } catch {
332
+ return;
333
+ }
334
+ if (E.source === "canvas") {
335
+ const l = E.fromPath;
336
+ if (i.type === "inside") {
337
+ if (!me(l, i.path))
338
+ return;
339
+ const y = ye(e, l, i.path);
340
+ if (!y)
341
+ return;
342
+ if (!y.wrapped)
343
+ d(B(e, l, i.path));
344
+ else {
345
+ let D = structuredClone(e);
346
+ const z = oe(D, i.path);
347
+ if (!z)
348
+ return;
349
+ const Ce = G(z);
350
+ z[Ce] = y.node, D = fe(D, l), d(D);
351
+ }
352
+ o(null);
353
+ return;
354
+ }
355
+ if (!me(l, i.path))
356
+ return;
357
+ const v = ve(i, e.properties);
358
+ if (!v)
359
+ return;
360
+ const Y = l.slice(0, -1), Te = Y.length === v.toParentPath.length && Y.every((y, D) => y === v.toParentPath[D]);
361
+ let Z = v.insertIndex;
362
+ if (Te) {
363
+ const y = we(e.properties, l);
364
+ y !== -1 && y < Z && (Z -= 1);
365
+ }
366
+ const ne = ye(e, l, v.toParentPath);
367
+ if (!ne)
368
+ return;
369
+ if (!ne.wrapped)
370
+ d(
371
+ B(
372
+ e,
373
+ l,
374
+ v.toParentPath,
375
+ Z
376
+ )
377
+ );
378
+ else {
379
+ let y = structuredClone(e);
380
+ const D = oe(y, v.toParentPath);
381
+ if (!D)
382
+ return;
383
+ const z = G(D);
384
+ D[z] = ne.node, y = fe(y, l), d(
385
+ B(
386
+ y,
387
+ [...v.toParentPath, z],
388
+ v.toParentPath,
389
+ Z
390
+ )
391
+ );
392
+ }
393
+ o(null);
394
+ return;
395
+ }
396
+ let I, x, u;
397
+ if (E.source === "fieldDef") {
398
+ const l = E.fieldDef;
399
+ I = l.widget, u = l.id, x = () => ({
400
+ type: We(l.widget),
401
+ widget: l.widget,
402
+ title: l.name,
403
+ // 锁定标记:禁止在设计器中修改 key 和 title
404
+ _lockedKey: !0,
405
+ _lockedTitle: !0
406
+ });
407
+ } else {
408
+ const l = qe(
409
+ E.catalogItem,
410
+ N,
411
+ h
412
+ );
413
+ if (!l)
414
+ return;
415
+ I = l.widget || l.layoutType || "field", x = () => l.createNode();
416
+ }
417
+ if (i.type === "inside") {
418
+ const l = c(i.path);
419
+ if (!l)
420
+ return;
421
+ const v = ge(
422
+ e,
423
+ i.path,
424
+ x,
425
+ I,
426
+ u
427
+ );
428
+ if (!v)
429
+ return;
430
+ const Y = u ?? G(l);
431
+ if (u && Y in l)
432
+ return;
433
+ p(i.path, Y, v());
434
+ return;
435
+ }
436
+ const k = ve(i, e.properties);
437
+ if (!k)
438
+ return;
439
+ const ae = ge(
440
+ e,
441
+ k.toParentPath,
442
+ x,
443
+ I,
444
+ u
445
+ );
446
+ if (!ae)
447
+ return;
448
+ const ce = structuredClone(e), X = oe(ce, k.toParentPath);
449
+ if (!X)
450
+ return;
451
+ const te = u ?? G(X);
452
+ if (u && te in X)
453
+ return;
454
+ X[te] = ae();
455
+ const Ne = [...k.toParentPath, te];
456
+ d(
457
+ B(
458
+ ce,
459
+ Ne,
460
+ k.toParentPath,
461
+ k.insertIndex
462
+ )
463
+ );
464
+ },
465
+ [
466
+ e,
467
+ N,
468
+ h,
469
+ p,
470
+ c,
471
+ d,
472
+ o
473
+ ]
474
+ ), R = w(
475
+ (n, i) => {
476
+ n.stopPropagation();
477
+ const m = { source: "canvas", fromPath: i };
478
+ n.dataTransfer.setData(he, JSON.stringify(m)), n.dataTransfer.effectAllowed = "move";
479
+ },
480
+ []
481
+ ), L = w(
482
+ (n, i) => {
483
+ n.preventDefault(), n.stopPropagation();
484
+ const m = n.currentTarget.getBoundingClientRect(), x = { type: n.clientY - m.top < m.height / 2 ? "before" : "after", path: i };
485
+ n.dataTransfer.dropEffect = n.dataTransfer.effectAllowed === "copy" ? "copy" : "move", A((u) => Me(u, x) ? u : x);
486
+ },
487
+ []
488
+ ), Q = w(
489
+ (n, i) => {
490
+ n.stopPropagation();
491
+ const m = Ye(n, i);
492
+ K(n, m);
493
+ },
494
+ [K]
495
+ ), q = w(
496
+ (n) => {
497
+ P(n);
498
+ },
499
+ [P]
500
+ ), g = w(
501
+ (n) => {
502
+ o(n);
503
+ },
504
+ [o]
505
+ ), S = w(
506
+ (n, i) => {
507
+ const m = n.slice(0, -1), E = n[n.length - 1], I = c(m);
508
+ if (!I)
509
+ return;
510
+ const x = Object.keys(I), u = x.indexOf(E);
511
+ if (u < 0 || i === "up" && u === 0 || i === "down" && u === x.length - 1)
512
+ return;
513
+ const k = i === "up" ? u - 1 : u + 1;
514
+ d(B(e, n, m, k)), o(n);
515
+ },
516
+ [c, e, d, o]
517
+ ), b = w((n) => {
518
+ n.preventDefault(), n.dataTransfer.dropEffect = n.dataTransfer.effectAllowed === "copy" ? "copy" : "move", A((i) => i === null ? i : null);
519
+ }, []), _ = w(
520
+ (n, i) => {
521
+ n.stopPropagation(), K(n, { type: "inside", path: i });
522
+ },
523
+ [K]
524
+ ), W = ie(
525
+ () => ({
526
+ onSelect: g,
527
+ onDelete: q,
528
+ onReorder: S,
529
+ onDragStart: R,
530
+ onDragOver: L,
531
+ onNodeDrop: Q,
532
+ onContainerDragOver: b,
533
+ onContainerDrop: _
534
+ }),
535
+ [
536
+ g,
537
+ q,
538
+ S,
539
+ R,
540
+ L,
541
+ Q,
542
+ b,
543
+ _
544
+ ]
545
+ );
546
+ if (r === "preview")
547
+ return /* @__PURE__ */ F("div", { className: "flex-1 overflow-y-auto p-4 bg-[#f5f5f5] min-h-full border border-transparent box-border", children: [
548
+ /* @__PURE__ */ s(ke, { form: T, schema: e }),
549
+ /* @__PURE__ */ s("div", { style: { marginTop: 16, textAlign: "center" }, children: /* @__PURE__ */ F(je, { children: [
550
+ /* @__PURE__ */ s(
551
+ J,
552
+ {
553
+ type: "primary",
554
+ onClick: async () => {
555
+ try {
556
+ if ((await T.validateFields()).size > 0)
557
+ return;
558
+ const i = T.getValues();
559
+ j(i);
560
+ } catch {
561
+ }
562
+ },
563
+ children: "提交"
564
+ }
565
+ ),
566
+ /* @__PURE__ */ s(J, { onClick: () => T.resetFields(), children: "重置" })
567
+ ] }) }),
568
+ /* @__PURE__ */ s(
569
+ Ke,
570
+ {
571
+ title: "表单数据",
572
+ open: $ !== null,
573
+ onCancel: () => j(null),
574
+ footer: [
575
+ /* @__PURE__ */ s(J, { onClick: () => j(null), children: "关闭" }, "close")
576
+ ],
577
+ width: 600,
578
+ children: /* @__PURE__ */ s(
579
+ "pre",
580
+ {
581
+ style: {
582
+ maxHeight: 400,
583
+ overflow: "auto",
584
+ background: "#f5f5f5",
585
+ padding: 12,
586
+ borderRadius: 6,
587
+ fontSize: 13,
588
+ margin: 0
589
+ },
590
+ children: JSON.stringify($, null, 2)
591
+ }
592
+ )
593
+ }
594
+ )
595
+ ] });
596
+ const se = Object.entries(e.properties);
597
+ return /* @__PURE__ */ s(
598
+ Fe,
599
+ {
600
+ form: a,
601
+ engine: C,
602
+ config: H,
603
+ children: /* @__PURE__ */ s(
604
+ "div",
605
+ {
606
+ className: "flex-1 overflow-y-auto p-4 bg-[#f5f5f5] min-h-full border border-transparent box-border",
607
+ onClick: () => o(null),
608
+ onDragOver: b,
609
+ onDrop: (n) => _(n, []),
610
+ children: /* @__PURE__ */ F("div", { children: [
611
+ se.map(([n, i]) => /* @__PURE__ */ s(
612
+ Be,
613
+ {
614
+ node: i,
615
+ pathKey: U([n]),
616
+ depth: 0,
617
+ parentDataPath: "",
618
+ isSelected: le(t, [n]),
619
+ dropTargetType: O && (O.type === "before" || O.type === "after") && le(O.path, [n]) ? O.type : null,
620
+ selectedPathKey: t ? U(t) : null,
621
+ dropTarget: O,
622
+ actions: W
623
+ },
624
+ U([n])
625
+ )),
626
+ se.length === 0 && /* @__PURE__ */ s(Re, { description: "拖拽组件到此处开始设计" })
627
+ ] })
628
+ }
629
+ )
630
+ }
631
+ );
632
+ }
633
+ export {
634
+ it as Canvas
635
+ };
636
+ //# sourceMappingURL=Canvas.js.map