dishui 0.0.55 → 0.0.56

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.
@@ -1,37 +1,37 @@
1
- import ue from "../CodeEditor/editors/CodeEditor.js";
2
- import { DEFAULT_NODE_DATA as oe, ROOT_CANVAS_ID as fe, createEmptyDocument as he } from "./constants.js";
3
- import { FlowProvider as pe, useFlowContext as Q } from "./context/FlowContext.js";
4
- import { FlowUIProvider as me, useFlowUI as X } from "./context/FlowUIContext.js";
5
- import { FlowAIProvider as ge } from "./context/FlowAIContext.js";
6
- import { generateId as q } from "./nodes/nodeUtils.js";
7
- import { normalizeEdgeHandles as we } from "./edges/edgePaths.js";
8
- import Ie from "./FlowCanvas.js";
9
- import { downloadDataURL as ve, safeFileBaseName as ye } from "./hooks/useFlowImportExport.js";
10
- import xe, { FlowZoomControls as be } from "./panels/FlowToolbar.js";
11
- import { MediaStampContent as Se, ShapePaletteContent as Ce, SvgStampContent as Me } from "./panels/ShapePalette.js";
12
- import { InspectorPanelContent as Pe } from "./panels/InspectorPanel.js";
13
- import { OutlinePanelContent as ze } from "./panels/OutlinePanel.js";
14
- import { AIPanelContent as Ee } from "./panels/AIPanel.js";
15
- import { PresentationMode as De } from "./panels/PresentationMode.js";
16
- import { MediaOverlay as Ae } from "./nodes/MediaOverlay.js";
17
- import j from "./panels/FlowPanelGroup.js";
18
- import Ne from "./panels/Breadcrumb.js";
19
- import Te from "./panels/ContextMenu.js";
20
- import { MiniMapRenderer as Re } from "./canvas/MiniMapRenderer.js";
21
- import { useUndoRedo as Le } from "./hooks/useUndoRedo.js";
1
+ import he from "../CodeEditor/editors/CodeEditor.js";
2
+ import { DEFAULT_NODE_DATA as oe, ROOT_CANVAS_ID as pe, createEmptyDocument as me } from "./constants.js";
3
+ import { FlowProvider as ge, useFlowContext as ee } from "./context/FlowContext.js";
4
+ import { FlowUIProvider as we, useFlowUI as Y } from "./context/FlowUIContext.js";
5
+ import { FlowAIProvider as Ie } from "./context/FlowAIContext.js";
6
+ import { generateId as Q } from "./nodes/nodeUtils.js";
7
+ import { normalizeEdgeHandles as ve } from "./edges/edgePaths.js";
8
+ import ye from "./FlowCanvas.js";
9
+ import { downloadDataURL as xe, safeFileBaseName as be } from "./hooks/useFlowImportExport.js";
10
+ import Se, { FlowZoomControls as Ce } from "./panels/FlowToolbar.js";
11
+ import { MediaStampContent as Me, ShapePaletteContent as Pe, SvgStampContent as ze } from "./panels/ShapePalette.js";
12
+ import { InspectorPanelContent as Ee } from "./panels/InspectorPanel.js";
13
+ import { OutlinePanelContent as De } from "./panels/OutlinePanel.js";
14
+ import { AIPanelContent as Ae } from "./panels/AIPanel.js";
15
+ import { PresentationMode as Ne } from "./panels/PresentationMode.js";
16
+ import { MediaOverlay as Te } from "./nodes/MediaOverlay.js";
17
+ import q from "./panels/FlowPanelGroup.js";
18
+ import Re from "./panels/Breadcrumb.js";
19
+ import Le from "./panels/ContextMenu.js";
20
+ import { MiniMapRenderer as ke } from "./canvas/MiniMapRenderer.js";
21
+ import { useUndoRedo as Fe } from "./hooks/useUndoRedo.js";
22
22
  import { useClipboard as re } from "./hooks/useClipboard.js";
23
- import { usePdfExport as ke } from "./hooks/usePdfExport.js";
24
- import { useKeyboardShortcuts as Fe } from "./hooks/useKeyboardShortcuts.js";
25
- import { useMindMap as Ge } from "./hooks/useMindMap.js";
23
+ import { usePdfExport as Ge } from "./hooks/usePdfExport.js";
24
+ import { useKeyboardShortcuts as We } from "./hooks/useKeyboardShortcuts.js";
25
+ import { useMindMap as Ke } from "./hooks/useMindMap.js";
26
26
  /* empty css */
27
- import { forwardRef as Oe, useCallback as A, useEffect as Y, useImperativeHandle as We, useMemo as ie, useRef as G, useState as $ } from "react";
28
- import { jsx as h, jsxs as V } from "react/jsx-runtime";
29
- import { EditorView as Ke } from "@codemirror/view";
30
- function Ue(n) {
27
+ import { forwardRef as Ue, useCallback as D, useEffect as $, useImperativeHandle as He, useMemo as ae, useRef as G, useState as j } from "react";
28
+ import { jsx as h, jsxs as X } from "react/jsx-runtime";
29
+ import { EditorView as Ze } from "@codemirror/view";
30
+ function Be(s) {
31
31
  let p = !1;
32
- const u = { ...n.canvases };
33
- for (const [I, s] of Object.entries(u)) {
34
- const r = s.nodes.map((d) => {
32
+ const l = { ...s.canvases };
33
+ for (const [w, i] of Object.entries(l)) {
34
+ const t = i.nodes.map((d) => {
35
35
  if (d.type !== "shapeSvg") return d;
36
36
  const o = d.data.labelPlacement, g = o === "above" ? "top" : o === "center" ? "middle" : o === "below" ? "bottom" : d.data.labelPlacement;
37
37
  return g === d.data.labelPlacement ? d : (p = !0, {
@@ -42,238 +42,238 @@ function Ue(n) {
42
42
  }
43
43
  });
44
44
  }), f = /* @__PURE__ */ new Map();
45
- for (const d of r) f.set(d.id, d);
46
- const e = we(s.edges, f);
47
- (r !== s.nodes || e !== s.edges) && (u[I] = {
48
- ...s,
49
- nodes: r,
45
+ for (const d of t) f.set(d.id, d);
46
+ const e = ve(i.edges, f);
47
+ (t !== i.nodes || e !== i.edges) && (l[w] = {
48
+ ...i,
49
+ nodes: t,
50
50
  edges: e
51
- }, e !== s.edges && (p = !0));
51
+ }, e !== i.edges && (p = !0));
52
52
  }
53
53
  return p ? {
54
- ...n,
55
- canvases: u
56
- } : n;
54
+ ...s,
55
+ canvases: l
56
+ } : s;
57
57
  }
58
- var ae = {
58
+ var ce = {
59
59
  nodeIds: /* @__PURE__ */ new Set(),
60
60
  edgeIds: /* @__PURE__ */ new Set(),
61
61
  lineIds: /* @__PURE__ */ new Set()
62
62
  };
63
- function He({ onUndo: n, onRedo: p, groupRef: u, geoGroupRef: I, ungroupRef: s }) {
64
- const { selection: r, setSelection: f, currentCanvas: e, setDoc: d, currentCanvasId: o } = Q(), { viewport: g } = X(), { copy: l, cut: P, paste: t, duplicate: w } = re(), S = A(() => {
65
- const { nodeIds: c, edgeIds: m, lineIds: C } = r;
66
- c.size === 0 && m.size === 0 && C.size === 0 || c.size > 1 && !window.confirm(`确定要删除选中的 ${c.size} 个节点吗?`) || (d((M) => {
67
- const i = M.canvases[o];
68
- return i ? {
69
- ...M,
63
+ function Je({ onUndo: s, onRedo: p, groupRef: l, geoGroupRef: w, ungroupRef: i }) {
64
+ const { selection: t, setSelection: f, currentCanvas: e, setDoc: d, currentCanvasId: o } = ee(), { viewport: g } = Y(), { copy: u, cut: M, paste: b, duplicate: n } = re(), v = D(() => {
65
+ const { nodeIds: c, edgeIds: m, lineIds: C } = t;
66
+ c.size === 0 && m.size === 0 && C.size === 0 || c.size > 1 && !window.confirm(`确定要删除选中的 ${c.size} 个节点吗?`) || (d((P) => {
67
+ const r = P.canvases[o];
68
+ return r ? {
69
+ ...P,
70
70
  canvases: {
71
- ...M.canvases,
71
+ ...P.canvases,
72
72
  [o]: {
73
- ...i,
74
- nodes: i.nodes.filter((a) => !c.has(a.id)).map((a) => a.parentId && c.has(a.parentId) ? {
73
+ ...r,
74
+ nodes: r.nodes.filter((a) => !c.has(a.id)).map((a) => a.parentId && c.has(a.parentId) ? {
75
75
  ...a,
76
76
  parentId: void 0
77
77
  } : a),
78
- edges: i.edges.filter((a) => !m.has(a.id) && !c.has(a.source) && !c.has(a.target)),
79
- lines: i.lines.filter((a) => !C.has(a.id)).map((a) => a.parentId && c.has(a.parentId) ? {
78
+ edges: r.edges.filter((a) => !m.has(a.id) && !c.has(a.source) && !c.has(a.target)),
79
+ lines: r.lines.filter((a) => !C.has(a.id)).map((a) => a.parentId && c.has(a.parentId) ? {
80
80
  ...a,
81
81
  parentId: void 0
82
82
  } : a)
83
83
  }
84
84
  }
85
- } : M;
86
- }), f(ae));
85
+ } : P;
86
+ }), f(ce));
87
87
  }, [
88
- r,
88
+ t,
89
89
  d,
90
90
  o,
91
91
  f
92
- ]), v = A(() => {
92
+ ]), I = D(() => {
93
93
  f({
94
94
  nodeIds: new Set(e.nodes.map((c) => c.id)),
95
95
  edgeIds: new Set(e.edges.map((c) => c.id)),
96
96
  lineIds: new Set(e.lines.map((c) => c.id))
97
97
  });
98
- }, [e, f]), z = A((c) => {
99
- const m = r.nodeIds, C = r.lineIds;
98
+ }, [e, f]), z = D((c) => {
99
+ const m = t.nodeIds, C = t.lineIds;
100
100
  if (m.size + C.size < 2) return;
101
- const M = e.nodes.filter((b) => m.has(b.id)), i = e.lines.filter((b) => C.has(b.id)), a = 20;
102
- let y = 1 / 0, L = 1 / 0, R = -1 / 0, k = -1 / 0;
103
- for (const b of M)
104
- y = Math.min(y, b.position.x), L = Math.min(L, b.position.y), R = Math.max(R, b.position.x + b.width), k = Math.max(k, b.position.y + b.height);
105
- for (const b of i) for (const N of b.points)
106
- y = Math.min(y, N.x), L = Math.min(L, N.y), R = Math.max(R, N.x), k = Math.max(k, N.y);
107
- const W = c === "geometryGroup", K = q("group"), x = {
108
- id: K,
101
+ const P = e.nodes.filter((S) => m.has(S.id)), r = e.lines.filter((S) => C.has(S.id)), a = 20;
102
+ let y = 1 / 0, L = 1 / 0, T = -1 / 0, F = -1 / 0;
103
+ for (const S of P)
104
+ y = Math.min(y, S.position.x), L = Math.min(L, S.position.y), T = Math.max(T, S.position.x + S.width), F = Math.max(F, S.position.y + S.height);
105
+ for (const S of r) for (const A of S.points)
106
+ y = Math.min(y, A.x), L = Math.min(L, A.y), T = Math.max(T, A.x), F = Math.max(F, A.y);
107
+ const K = c === "geometryGroup", U = Q("group"), x = {
108
+ id: U,
109
109
  type: c,
110
110
  position: {
111
111
  x: y - a,
112
112
  y: L - a
113
113
  },
114
- width: R - y + a * 2,
115
- height: k - L + a * 2,
114
+ width: T - y + a * 2,
115
+ height: F - L + a * 2,
116
116
  data: {
117
117
  ...oe,
118
- label: W ? "Geo Group" : "Group",
119
- fill: W ? "#fefce8" : "#f0f9ff",
118
+ label: K ? "Geo Group" : "Group",
119
+ fill: K ? "#fefce8" : "#f0f9ff",
120
120
  stroke: "#9ca3af",
121
121
  strokeWidth: 1.5,
122
- borderStyle: W ? "dashed" : "dotted",
122
+ borderStyle: K ? "dashed" : "dotted",
123
123
  isGroup: !0
124
124
  }
125
125
  };
126
- d((b) => {
127
- const N = b.canvases[o];
128
- return N ? {
129
- ...b,
126
+ d((S) => {
127
+ const A = S.canvases[o];
128
+ return A ? {
129
+ ...S,
130
130
  canvases: {
131
- ...b.canvases,
131
+ ...S.canvases,
132
132
  [o]: {
133
- ...N,
134
- nodes: W ? [x, ...N.nodes] : [x, ...N.nodes.map((H) => m.has(H.id) ? {
133
+ ...A,
134
+ nodes: K ? [x, ...A.nodes] : [x, ...A.nodes.map((H) => m.has(H.id) ? {
135
135
  ...H,
136
- parentId: K
136
+ parentId: U
137
137
  } : H)],
138
- lines: W ? N.lines : N.lines.map((H) => C.has(H.id) ? {
138
+ lines: K ? A.lines : A.lines.map((H) => C.has(H.id) ? {
139
139
  ...H,
140
- parentId: K
140
+ parentId: U
141
141
  } : H)
142
142
  }
143
143
  }
144
- } : b;
144
+ } : S;
145
145
  }), f({
146
- nodeIds: /* @__PURE__ */ new Set([K]),
146
+ nodeIds: /* @__PURE__ */ new Set([U]),
147
147
  edgeIds: /* @__PURE__ */ new Set(),
148
148
  lineIds: /* @__PURE__ */ new Set()
149
149
  });
150
150
  }, [
151
- r,
151
+ t,
152
152
  e,
153
153
  d,
154
154
  o,
155
155
  f
156
- ]), Z = A(() => z("flowGroup"), [z]), O = A(() => z("geometryGroup"), [z]), B = A(() => {
157
- const c = r.nodeIds;
156
+ ]), B = D(() => z("flowGroup"), [z]), W = D(() => z("geometryGroup"), [z]), J = D(() => {
157
+ const c = t.nodeIds;
158
158
  if (c.size === 0) return;
159
- const m = /* @__PURE__ */ new Set(), C = /* @__PURE__ */ new Set(), M = /* @__PURE__ */ new Set();
160
- for (const i of e.nodes) c.has(i.id) && (i.type === "flowGroup" || i.type === "geometryGroup" || i.data.isGroup) && m.add(i.id);
159
+ const m = /* @__PURE__ */ new Set(), C = /* @__PURE__ */ new Set(), P = /* @__PURE__ */ new Set();
160
+ for (const r of e.nodes) c.has(r.id) && (r.type === "flowGroup" || r.type === "geometryGroup" || r.data.isGroup) && m.add(r.id);
161
161
  if (m.size !== 0) {
162
- for (const i of e.nodes) i.parentId && m.has(i.parentId) && C.add(i.id);
163
- for (const i of e.lines) i.parentId && m.has(i.parentId) && M.add(i.id);
164
- d((i) => {
165
- const a = i.canvases[o];
162
+ for (const r of e.nodes) r.parentId && m.has(r.parentId) && C.add(r.id);
163
+ for (const r of e.lines) r.parentId && m.has(r.parentId) && P.add(r.id);
164
+ d((r) => {
165
+ const a = r.canvases[o];
166
166
  return a ? {
167
- ...i,
167
+ ...r,
168
168
  canvases: {
169
- ...i.canvases,
169
+ ...r.canvases,
170
170
  [o]: {
171
171
  ...a,
172
172
  nodes: a.nodes.filter((y) => !m.has(y.id)).map((y) => C.has(y.id) ? {
173
173
  ...y,
174
174
  parentId: void 0
175
175
  } : y),
176
- lines: a.lines.map((y) => M.has(y.id) ? {
176
+ lines: a.lines.map((y) => P.has(y.id) ? {
177
177
  ...y,
178
178
  parentId: void 0
179
179
  } : y)
180
180
  }
181
181
  }
182
- } : i;
182
+ } : r;
183
183
  }), f({
184
184
  nodeIds: C,
185
185
  edgeIds: /* @__PURE__ */ new Set(),
186
- lineIds: M
186
+ lineIds: P
187
187
  });
188
188
  }
189
189
  }, [
190
- r,
190
+ t,
191
191
  e,
192
192
  d,
193
193
  o,
194
194
  f
195
195
  ]);
196
- u.current = Z, I.current = O, s.current = B;
197
- const E = A((c) => {
198
- const m = r.nodeIds, C = r.lineIds;
199
- m.size === 0 && C.size === 0 || d((M) => {
200
- const i = M.canvases[o];
201
- if (!i) return M;
202
- const a = i.nodes.map((x) => x.zIndex ?? 0), y = a.length > 0 ? Math.max(...a) : 0, L = a.length > 0 ? Math.min(...a) : 0, R = i.lines.map((x) => x.zIndex ?? 0), k = R.length > 0 ? Math.max(...R) : 0, W = R.length > 0 ? Math.min(...R) : 0, K = (x, b, N) => c === "front" ? b + 1 : c === "back" ? N - 1 : c === "up" ? x + 1 : x - 1;
196
+ l.current = B, w.current = W, i.current = J;
197
+ const E = D((c) => {
198
+ const m = t.nodeIds, C = t.lineIds;
199
+ m.size === 0 && C.size === 0 || d((P) => {
200
+ const r = P.canvases[o];
201
+ if (!r) return P;
202
+ const a = r.nodes.map((x) => x.zIndex ?? 0), y = a.length > 0 ? Math.max(...a) : 0, L = a.length > 0 ? Math.min(...a) : 0, T = r.lines.map((x) => x.zIndex ?? 0), F = T.length > 0 ? Math.max(...T) : 0, K = T.length > 0 ? Math.min(...T) : 0, U = (x, S, A) => c === "front" ? S + 1 : c === "back" ? A - 1 : c === "up" ? x + 1 : x - 1;
203
203
  return {
204
- ...M,
204
+ ...P,
205
205
  canvases: {
206
- ...M.canvases,
206
+ ...P.canvases,
207
207
  [o]: {
208
- ...i,
209
- nodes: i.nodes.map((x) => m.has(x.id) ? {
208
+ ...r,
209
+ nodes: r.nodes.map((x) => m.has(x.id) ? {
210
210
  ...x,
211
- zIndex: K(x.zIndex ?? 0, y, L)
211
+ zIndex: U(x.zIndex ?? 0, y, L)
212
212
  } : x),
213
- lines: i.lines.map((x) => C.has(x.id) ? {
213
+ lines: r.lines.map((x) => C.has(x.id) ? {
214
214
  ...x,
215
- zIndex: K(x.zIndex ?? 0, k, W)
215
+ zIndex: U(x.zIndex ?? 0, F, K)
216
216
  } : x)
217
217
  }
218
218
  }
219
219
  };
220
220
  });
221
221
  }, [
222
- r,
222
+ t,
223
223
  d,
224
224
  o
225
225
  ]);
226
- return Y(() => {
226
+ return $(() => {
227
227
  const c = (m) => {
228
228
  const C = m.target;
229
229
  if (C?.tagName === "INPUT" || C?.tagName === "TEXTAREA" || C?.isContentEditable) return;
230
- const M = Array.from(m.clipboardData?.items ?? []).find((y) => y.type.startsWith("image/"));
231
- if (!M) {
232
- m.preventDefault(), t();
230
+ const P = Array.from(m.clipboardData?.items ?? []).find((y) => y.type.startsWith("image/"));
231
+ if (!P) {
232
+ m.preventDefault(), b();
233
233
  return;
234
234
  }
235
- const i = M.getAsFile();
236
- if (!i) return;
235
+ const r = P.getAsFile();
236
+ if (!r) return;
237
237
  m.preventDefault();
238
238
  const a = new FileReader();
239
239
  a.onload = () => {
240
240
  if (typeof a.result != "string") return;
241
- const y = r.nodeIds.size === 1 ? e.nodes.find((T) => r.nodeIds.has(T.id) && T.type === "mediaNode" && T.data.mediaKind === "image") : void 0;
241
+ const y = t.nodeIds.size === 1 ? e.nodes.find((N) => t.nodeIds.has(N.id) && N.type === "mediaNode" && N.data.mediaKind === "image") : void 0;
242
242
  if (y) {
243
- d((T) => {
244
- const J = T.canvases[o];
245
- return J ? {
246
- ...T,
243
+ d((N) => {
244
+ const O = N.canvases[o];
245
+ return O ? {
246
+ ...N,
247
247
  canvases: {
248
- ...T.canvases,
248
+ ...N.canvases,
249
249
  [o]: {
250
- ...J,
251
- nodes: J.nodes.map((D) => D.id === y.id ? {
252
- ...D,
250
+ ...O,
251
+ nodes: O.nodes.map((_) => _.id === y.id ? {
252
+ ..._,
253
253
  data: {
254
- ...D.data,
254
+ ..._.data,
255
255
  mediaContent: a.result
256
256
  }
257
- } : D)
257
+ } : _)
258
258
  }
259
259
  }
260
- } : T;
260
+ } : N;
261
261
  });
262
262
  return;
263
263
  }
264
- const L = q("node"), R = 320, k = 220, W = window.innerWidth, K = window.innerHeight, x = (W / 2 - g.x) / g.zoom, b = (K / 2 - g.y) / g.zoom, N = Math.max(0, ...e.nodes.map((T) => T.zIndex ?? 0)), H = {
264
+ const L = Q("node"), T = 320, F = 220, K = window.innerWidth, U = window.innerHeight, x = (K / 2 - g.x) / g.zoom, S = (U / 2 - g.y) / g.zoom, A = Math.max(0, ...e.nodes.map((N) => N.zIndex ?? 0)), H = {
265
265
  id: L,
266
266
  type: "mediaNode",
267
267
  position: {
268
- x: x - R / 2,
269
- y: b - k / 2
268
+ x: x - T / 2,
269
+ y: S - F / 2
270
270
  },
271
- width: R,
272
- height: k,
273
- zIndex: N + 1,
271
+ width: T,
272
+ height: F,
273
+ zIndex: A + 1,
274
274
  data: {
275
275
  ...oe,
276
- label: i.name || "Image",
276
+ label: r.name || "Image",
277
277
  fill: "theme:base-100",
278
278
  stroke: "theme:base-content",
279
279
  strokeWidth: 1.5,
@@ -284,172 +284,177 @@ function He({ onUndo: n, onRedo: p, groupRef: u, geoGroupRef: I, ungroupRef: s }
284
284
  mediaContent: a.result
285
285
  }
286
286
  };
287
- d((T) => {
288
- const J = T.canvases[o];
289
- return J ? {
290
- ...T,
287
+ d((N) => {
288
+ const O = N.canvases[o];
289
+ return O ? {
290
+ ...N,
291
291
  canvases: {
292
- ...T.canvases,
292
+ ...N.canvases,
293
293
  [o]: {
294
- ...J,
295
- nodes: [...J.nodes, H]
294
+ ...O,
295
+ nodes: [...O.nodes, H]
296
296
  }
297
297
  }
298
- } : T;
298
+ } : N;
299
299
  }), f({
300
300
  nodeIds: /* @__PURE__ */ new Set([L]),
301
301
  edgeIds: /* @__PURE__ */ new Set(),
302
302
  lineIds: /* @__PURE__ */ new Set()
303
303
  });
304
- }, a.readAsDataURL(i);
304
+ }, a.readAsDataURL(r);
305
305
  };
306
306
  return window.addEventListener("paste", c), () => window.removeEventListener("paste", c);
307
307
  }, [
308
308
  e,
309
309
  o,
310
+ b,
310
311
  t,
311
- r,
312
312
  d,
313
313
  f,
314
314
  g
315
- ]), Fe(ie(() => ({
316
- undo: n,
315
+ ]), We(ae(() => ({
316
+ undo: s,
317
317
  redo: p,
318
- copy: l,
319
- cut: P,
320
- paste: t,
321
- duplicate: w,
322
- deleteSelected: S,
323
- selectAll: v,
324
- group: Z,
325
- geoGroup: O,
326
- ungroup: B,
318
+ copy: u,
319
+ cut: M,
320
+ paste: b,
321
+ duplicate: n,
322
+ deleteSelected: v,
323
+ selectAll: I,
324
+ group: B,
325
+ geoGroup: W,
326
+ ungroup: J,
327
327
  bringToFront: () => E("front"),
328
328
  bringForward: () => E("up"),
329
329
  sendBackward: () => E("down"),
330
330
  sendToBack: () => E("back")
331
331
  }), [
332
- n,
332
+ s,
333
333
  p,
334
- l,
335
- P,
336
- t,
337
- w,
338
- S,
334
+ u,
335
+ M,
336
+ b,
337
+ n,
339
338
  v,
340
- Z,
341
- O,
339
+ I,
342
340
  B,
341
+ W,
342
+ J,
343
343
  E
344
- ])), Ge(), null;
344
+ ])), Ke(), null;
345
345
  }
346
- function Ze({ pixiRef: n, exportPdfRef: p }) {
347
- return p.current = ke(n), null;
346
+ function Oe({ pixiRef: s, exportPdfRef: p }) {
347
+ return p.current = Ge(s), null;
348
348
  }
349
- var An = Oe(function({ initialDocument: p, onChange: u, width: I, height: s, readOnly: r = !1, onBack: f, onExportPNG: e, onPublish: d, showMiniMap: o = !0, showGrid: g = !0, gridSize: l = 20, className: P, showAI: t = !0, showAIConfig: w = !0, aiConfig: S }, v) {
350
- const [z, Z] = $(() => Ue(p ?? he())), [O, B] = $(ae), E = G(null), c = G(null), m = G(null), { wrappedSetDoc: C, undo: M, redo: i, canUndo: a, canRedo: y } = Le(z, Z), L = G(null), R = G(null), k = G(null), W = G(null), K = G(u);
351
- K.current = u;
349
+ var Nt = Ue(function({ initialDocument: p, onChange: l, width: w, height: i, readOnly: t = !1, onBack: f, onExportPNG: e, onPublish: d, showMiniMap: o = !0, showGrid: g = !0, gridSize: u = 20, className: M, showAI: b = !0, showAIConfig: n = !0, aiConfig: v }, I) {
350
+ const [z, B] = j(() => Be(p ?? me())), [W, J] = j(ce), E = G(null), c = G(null), m = G(null), { wrappedSetDoc: C, undo: P, redo: r, canUndo: a, canRedo: y } = Fe(z, B), L = G(null), T = G(null), F = G(null), K = G(null), U = G(l);
351
+ U.current = l;
352
352
  const x = G(z);
353
- x.current = z, We(v, () => ({
354
- exportPNG: async (D) => {
355
- const F = E.current;
356
- return !F || F.destroyed ? null : F.exportPNG(D);
353
+ x.current = z, He(I, () => ({
354
+ exportPNG: async (k) => {
355
+ const R = E.current;
356
+ return !R || R.destroyed ? null : R.exportPNG(k);
357
357
  },
358
358
  getDocument: () => x.current
359
359
  }), []);
360
- const b = A((D) => {
361
- C((F) => {
362
- const _ = typeof D == "function" ? D(F) : D;
363
- return queueMicrotask(() => K.current?.(_)), _;
360
+ const S = D((k) => {
361
+ C((R) => {
362
+ const V = typeof k == "function" ? k(R) : k;
363
+ return t ? V.canvases === R.canvases && V.title === R.title ? V : R : (queueMicrotask(() => U.current?.(V)), V);
364
364
  });
365
- }, [C]), N = A((D) => {
366
- E.current = D, c.current && !m.current && (m.current = new Re(c.current));
367
- }, []), H = A(async () => {
365
+ }, [C, t]), A = D(() => {
366
+ t || P();
367
+ }, [t, P]), H = D(() => {
368
+ t || r();
369
+ }, [t, r]), N = D((k) => {
370
+ E.current = k, c.current && !m.current && (m.current = new ke(c.current));
371
+ }, []), O = D(async () => {
368
372
  if (e) return void e();
369
- const D = E.current;
370
- if (!D || D.destroyed) return;
371
- const F = await D.exportPNG(16777215);
372
- F && ve(F, `${ye(x.current.title)}.png`);
373
- }, [e]), T = A(async () => {
374
- await W.current?.();
373
+ const k = E.current;
374
+ if (!k || k.destroyed) return;
375
+ const R = await k.exportPNG(16777215);
376
+ R && xe(R, `${be(x.current.title)}.png`);
377
+ }, [e]), _ = D(async () => {
378
+ await K.current?.();
375
379
  }, []);
376
- Y(() => {
377
- let D = !1, F = null;
378
- const _ = () => {
379
- const U = E.current, ne = m.current;
380
- if (!U || U.destroyed || !ne) return;
381
- const de = {
382
- x: U.world.position.x,
383
- y: U.world.position.y,
384
- zoom: U.world.scale.x
385
- }, le = z.stack[z.stack.length - 1] ?? "root", te = z.canvases[le];
386
- te && ne.update(te.nodes, de, U.app.screen.width, U.app.screen.height);
387
- }, ee = () => {
388
- if (D) return;
389
- const U = E.current;
390
- U && !U.destroyed && m.current ? (U.app.ticker.add(_), F = U) : requestAnimationFrame(ee);
380
+ $(() => {
381
+ let k = !1, R = null;
382
+ const V = () => {
383
+ const Z = E.current, ne = m.current;
384
+ if (!Z || Z.destroyed || !ne) return;
385
+ const ue = {
386
+ x: Z.world.position.x,
387
+ y: Z.world.position.y,
388
+ zoom: Z.world.scale.x
389
+ }, fe = z.stack[z.stack.length - 1] ?? "root", se = z.canvases[fe];
390
+ se && ne.update(se.nodes, ue, Z.app.screen.width, Z.app.screen.height);
391
+ }, te = () => {
392
+ if (k) return;
393
+ const Z = E.current;
394
+ Z && !Z.destroyed && m.current ? (Z.app.ticker.add(V), R = Z) : requestAnimationFrame(te);
391
395
  };
392
- return ee(), () => {
393
- D = !0, F && !F.destroyed && F.app.ticker.remove(_);
396
+ return te(), () => {
397
+ k = !0, R && !R.destroyed && R.app.ticker.remove(V);
394
398
  };
395
399
  }, [z]);
396
- const J = {
397
- width: I ?? "100%",
398
- height: s ?? "100%"
400
+ const le = {
401
+ width: w ?? "100%",
402
+ height: i ?? "100%"
399
403
  };
400
404
  return /* @__PURE__ */ h("div", {
401
- className: `flow-container ${P ?? ""}`,
402
- style: J,
403
- children: /* @__PURE__ */ h(pe, {
405
+ className: `flow-container ${M ?? ""}`,
406
+ style: le,
407
+ children: /* @__PURE__ */ h(ge, {
404
408
  doc: z,
405
- setDoc: b,
406
- selection: O,
407
- setSelection: B,
408
- children: /* @__PURE__ */ h(me, {
409
+ setDoc: S,
410
+ selection: W,
411
+ setSelection: J,
412
+ children: /* @__PURE__ */ h(we, {
409
413
  showMiniMap: o,
410
414
  showGrid: g,
411
- gridSize: l,
412
- showAI: t,
413
- children: /* @__PURE__ */ V(ge, {
414
- initialConfig: S,
415
- showAIConfig: w,
415
+ gridSize: u,
416
+ showAI: b,
417
+ readOnly: t,
418
+ children: /* @__PURE__ */ X(Ie, {
419
+ initialConfig: v,
420
+ showAIConfig: n,
416
421
  children: [
417
- /* @__PURE__ */ h(He, {
418
- onUndo: M,
419
- onRedo: i,
422
+ /* @__PURE__ */ h(Je, {
423
+ onUndo: A,
424
+ onRedo: H,
420
425
  groupRef: L,
421
- geoGroupRef: R,
422
- ungroupRef: k
426
+ geoGroupRef: T,
427
+ ungroupRef: F
423
428
  }),
424
- /* @__PURE__ */ h(Ze, {
429
+ /* @__PURE__ */ h(Oe, {
425
430
  pixiRef: E,
426
- exportPdfRef: W
431
+ exportPdfRef: K
427
432
  }),
428
- /* @__PURE__ */ V(_e, {
429
- toolbar: r ? null : /* @__PURE__ */ h(xe, {
433
+ /* @__PURE__ */ X(Ye, {
434
+ toolbar: t ? null : /* @__PURE__ */ h(Se, {
430
435
  onBack: f,
431
- onUndo: M,
432
- onRedo: i,
436
+ onUndo: A,
437
+ onRedo: H,
433
438
  canUndo: a,
434
439
  canRedo: y,
435
440
  onGroup: () => L.current?.(),
436
- onGeoGroup: () => R.current?.(),
437
- onUngroup: () => k.current?.(),
438
- onExportPNG: H,
439
- onExportPDF: T,
441
+ onGeoGroup: () => T.current?.(),
442
+ onUngroup: () => F.current?.(),
443
+ onExportPNG: O,
444
+ onExportPDF: _,
440
445
  onPublish: d
441
446
  }),
442
447
  children: [
443
- /* @__PURE__ */ h(Ie, { onPixiReady: N }),
444
- /* @__PURE__ */ h(Ae, {}),
445
- /* @__PURE__ */ V(Be, { children: [!r && /* @__PURE__ */ h(be, {}), /* @__PURE__ */ h(Ne, {})] }),
446
- /* @__PURE__ */ h(qe, {}),
447
- /* @__PURE__ */ h(Xe, {
448
+ /* @__PURE__ */ h(ye, { onPixiReady: N }),
449
+ /* @__PURE__ */ h(Te, {}),
450
+ /* @__PURE__ */ X(Ve, { children: [!t && /* @__PURE__ */ h(Ce, {}), /* @__PURE__ */ h(Re, {})] }),
451
+ !t && /* @__PURE__ */ h(et, {}),
452
+ /* @__PURE__ */ h($e, {
448
453
  canvasRef: c,
449
454
  pixiRef: E,
450
455
  miniMapRef: m
451
456
  }),
452
- /* @__PURE__ */ h(De, {})
457
+ /* @__PURE__ */ h(Ne, {})
453
458
  ]
454
459
  })
455
460
  ]
@@ -458,15 +463,15 @@ var An = Oe(function({ initialDocument: p, onChange: u, width: I, height: s, rea
458
463
  })
459
464
  });
460
465
  });
461
- function Be({ children: n }) {
462
- const { presentation: p } = X();
466
+ function Ve({ children: s }) {
467
+ const { presentation: p } = Y();
463
468
  return /* @__PURE__ */ h("div", {
464
469
  className: "flow-overlay",
465
470
  style: { display: p ? "none" : void 0 },
466
- children: n
471
+ children: s
467
472
  });
468
473
  }
469
- var Je = [
474
+ var _e = [
470
475
  {
471
476
  id: "shapes",
472
477
  label: "Shapes",
@@ -517,105 +522,105 @@ var Je = [
517
522
  showKey: "showAI"
518
523
  }
519
524
  ];
520
- function Ve(n) {
521
- switch (n) {
525
+ function Xe(s) {
526
+ switch (s) {
522
527
  case "shapes":
523
- return /* @__PURE__ */ h(Ce, {});
528
+ return /* @__PURE__ */ h(Pe, {});
524
529
  case "icons":
525
- return /* @__PURE__ */ h(Me, {});
530
+ return /* @__PURE__ */ h(ze, {});
526
531
  case "media":
527
- return /* @__PURE__ */ h(Se, {});
532
+ return /* @__PURE__ */ h(Me, {});
528
533
  case "inspector":
529
- return /* @__PURE__ */ h(Pe, {});
534
+ return /* @__PURE__ */ h(Ee, {});
530
535
  case "outline":
531
- return /* @__PURE__ */ h(ze, {});
536
+ return /* @__PURE__ */ h(De, {});
532
537
  case "json":
533
- return /* @__PURE__ */ h(je, {});
538
+ return /* @__PURE__ */ h(Qe, {});
534
539
  case "ai":
535
- return /* @__PURE__ */ h(Ee, {});
540
+ return /* @__PURE__ */ h(Ae, {});
536
541
  default:
537
542
  return null;
538
543
  }
539
544
  }
540
- function _e({ children: n, toolbar: p }) {
541
- const u = X(), { detachedTabs: I, toggleDetach: s, presentation: r } = u, f = Je.filter((t) => !t.showKey || u[t.showKey]), e = (t) => ({
542
- id: t.id,
543
- label: t.label,
544
- icon: t.icon,
545
- content: Ve(t.id)
546
- }), d = f.filter((t) => t.side === "left" && !I.has(t.id)).map(e), o = f.filter((t) => t.side === "right" && !I.has(t.id)).map(e), g = f.filter((t) => I.has(t.id)), l = A((t) => s(t), [s]), P = A((t) => s(t), [s]);
547
- return /* @__PURE__ */ V("div", {
545
+ function Ye({ children: s, toolbar: p }) {
546
+ const l = Y(), { detachedTabs: w, toggleDetach: i, presentation: t, readOnly: f } = l, e = f ? [] : _e.filter((n) => !n.showKey || l[n.showKey]), d = (n) => ({
547
+ id: n.id,
548
+ label: n.label,
549
+ icon: n.icon,
550
+ content: Xe(n.id)
551
+ }), o = e.filter((n) => n.side === "left" && !w.has(n.id)).map(d), g = e.filter((n) => n.side === "right" && !w.has(n.id)).map(d), u = e.filter((n) => w.has(n.id)), M = D((n) => i(n), [i]), b = D((n) => i(n), [i]);
552
+ return /* @__PURE__ */ X("div", {
548
553
  className: "flow-workspace",
549
- children: [!r && p, /* @__PURE__ */ V("div", {
554
+ children: [!t && p, /* @__PURE__ */ X("div", {
550
555
  className: "flow-workspace-main",
551
556
  children: [
552
- !r && d.length > 0 && /* @__PURE__ */ h(j, {
553
- tabs: d,
554
- defaultTab: d[0]?.id,
557
+ !t && o.length > 0 && /* @__PURE__ */ h(q, {
558
+ tabs: o,
559
+ defaultTab: o[0]?.id,
555
560
  resizeEdge: "right",
556
561
  defaultWidth: 132,
557
- onDetach: l
562
+ onDetach: M
558
563
  }),
559
564
  /* @__PURE__ */ h("div", {
560
565
  className: "flow-stage",
561
- children: n
566
+ children: s
562
567
  }),
563
- !r && o.length > 0 && /* @__PURE__ */ h(j, {
564
- tabs: o,
565
- defaultTab: o[0]?.id,
568
+ !t && g.length > 0 && /* @__PURE__ */ h(q, {
569
+ tabs: g,
570
+ defaultTab: g[0]?.id,
566
571
  resizeEdge: "left",
567
572
  defaultWidth: 220,
568
- onDetach: l
573
+ onDetach: M
569
574
  }),
570
- !r && g.map((t, w) => /* @__PURE__ */ h(j, {
571
- tabs: [e(t)],
575
+ !t && u.map((n, v) => /* @__PURE__ */ h(q, {
576
+ tabs: [d(n)],
572
577
  resizeEdge: "right",
573
578
  defaultWidth: 220,
574
579
  style: {
575
- top: 48 + w * 40,
576
- left: 24 + w * 30
580
+ top: 48 + v * 40,
581
+ left: 24 + v * 30
577
582
  },
578
583
  isDetached: !0,
579
- onAttach: P
580
- }, t.id))
584
+ onAttach: b
585
+ }, n.id))
581
586
  ]
582
587
  })]
583
588
  });
584
589
  }
585
- function Xe({ canvasRef: n, pixiRef: p, miniMapRef: u }) {
586
- const { showMiniMap: I, setViewport: s, presentation: r } = X(), f = G(!1), e = A((l, P) => {
587
- const t = n.current, w = p.current, S = u.current;
588
- if (!t || !w || w.destroyed || !S) return;
589
- const v = t.getBoundingClientRect();
590
- if (v.width === 0 || v.height === 0) return;
591
- const { width: z, height: Z } = S.size, O = (l - v.left) / v.width * z, B = (P - v.top) / v.height * Z, E = S.minimapToWorld(O, B);
590
+ function $e({ canvasRef: s, pixiRef: p, miniMapRef: l }) {
591
+ const { showMiniMap: w, setViewport: i, presentation: t } = Y(), f = G(!1), e = D((u, M) => {
592
+ const b = s.current, n = p.current, v = l.current;
593
+ if (!b || !n || n.destroyed || !v) return;
594
+ const I = b.getBoundingClientRect();
595
+ if (I.width === 0 || I.height === 0) return;
596
+ const { width: z, height: B } = v.size, W = (u - I.left) / I.width * z, J = (M - I.top) / I.height * B, E = v.minimapToWorld(W, J);
592
597
  if (!E) return;
593
- const c = w.world.scale.x || 1, m = w.app.screen.width, C = w.app.screen.height;
594
- s({
598
+ const c = n.world.scale.x || 1, m = n.app.screen.width, C = n.app.screen.height;
599
+ i({
595
600
  x: m / 2 - E.x * c,
596
601
  y: C / 2 - E.y * c,
597
602
  zoom: c
598
603
  });
599
604
  }, [
600
- n,
605
+ s,
601
606
  p,
602
- u,
603
- s
604
- ]), d = A((l) => {
605
- l.preventDefault(), l.currentTarget.setPointerCapture(l.pointerId), f.current = !0, e(l.clientX, l.clientY);
606
- }, [e]), o = A((l) => {
607
- f.current && e(l.clientX, l.clientY);
608
- }, [e]), g = A((l) => {
607
+ l,
608
+ i
609
+ ]), d = D((u) => {
610
+ u.preventDefault(), u.currentTarget.setPointerCapture(u.pointerId), f.current = !0, e(u.clientX, u.clientY);
611
+ }, [e]), o = D((u) => {
612
+ f.current && e(u.clientX, u.clientY);
613
+ }, [e]), g = D((u) => {
609
614
  f.current = !1;
610
615
  try {
611
- l.currentTarget.releasePointerCapture(l.pointerId);
616
+ u.currentTarget.releasePointerCapture(u.pointerId);
612
617
  } catch {
613
618
  }
614
619
  }, []);
615
620
  return /* @__PURE__ */ h("div", {
616
621
  className: "flow-minimap",
617
622
  style: {
618
- display: I && !r ? void 0 : "none",
623
+ display: w && !t ? void 0 : "none",
619
624
  cursor: "pointer"
620
625
  },
621
626
  onPointerDown: d,
@@ -623,7 +628,7 @@ function Xe({ canvasRef: n, pixiRef: p, miniMapRef: u }) {
623
628
  onPointerUp: g,
624
629
  title: "点击或拖动以移动画布",
625
630
  children: /* @__PURE__ */ h("canvas", {
626
- ref: n,
631
+ ref: s,
627
632
  width: 180,
628
633
  height: 120,
629
634
  style: {
@@ -634,97 +639,97 @@ function Xe({ canvasRef: n, pixiRef: p, miniMapRef: u }) {
634
639
  })
635
640
  });
636
641
  }
637
- function Ye(n, p) {
638
- const u = `"id": "${p}"`, I = n.indexOf(u);
639
- if (I === -1) return null;
640
- let s = 0, r = -1;
641
- for (let e = I; e >= 0; e--)
642
- if (n[e] === "}" && s++, n[e] === "{") {
643
- if (s === 0) {
644
- r = e;
642
+ function je(s, p) {
643
+ const l = `"id": "${p}"`, w = s.indexOf(l);
644
+ if (w === -1) return null;
645
+ let i = 0, t = -1;
646
+ for (let e = w; e >= 0; e--)
647
+ if (s[e] === "}" && i++, s[e] === "{") {
648
+ if (i === 0) {
649
+ t = e;
645
650
  break;
646
651
  }
647
- s--;
652
+ i--;
648
653
  }
649
- if (r === -1) return null;
650
- s = 0;
654
+ if (t === -1) return null;
655
+ i = 0;
651
656
  let f = -1;
652
- for (let e = r; e < n.length; e++)
653
- if (n[e] === "{" && s++, n[e] === "}" && (s--, s === 0)) {
657
+ for (let e = t; e < s.length; e++)
658
+ if (s[e] === "{" && i++, s[e] === "}" && (i--, i === 0)) {
654
659
  f = e;
655
660
  break;
656
661
  }
657
662
  return f === -1 ? null : {
658
- startLine: n.slice(0, r).split(`
663
+ startLine: s.slice(0, t).split(`
659
664
  `).length,
660
- endLine: n.slice(0, f + 1).split(`
665
+ endLine: s.slice(0, f + 1).split(`
661
666
  `).length
662
667
  };
663
668
  }
664
- function se(n) {
665
- n.querySelectorAll(".cm-line.flow-json-hl").forEach((p) => p.classList.remove("flow-json-hl"));
669
+ function ie(s) {
670
+ s.querySelectorAll(".cm-line.flow-json-hl").forEach((p) => p.classList.remove("flow-json-hl"));
666
671
  }
667
- function $e(n, p, u) {
668
- const I = n.getView();
669
- if (I)
670
- for (let s = p; s <= u; s++) try {
671
- const r = I.state.doc.line(s), f = I.domAtPos(r.from), e = f.node instanceof HTMLElement ? f.node.closest(".cm-line") : f.node.parentElement?.closest(".cm-line");
672
+ function qe(s, p, l) {
673
+ const w = s.getView();
674
+ if (w)
675
+ for (let i = p; i <= l; i++) try {
676
+ const t = w.state.doc.line(i), f = w.domAtPos(t.from), e = f.node instanceof HTMLElement ? f.node.closest(".cm-line") : f.node.parentElement?.closest(".cm-line");
672
677
  e && e.classList.add("flow-json-hl");
673
678
  } catch {
674
679
  }
675
680
  }
676
- function je() {
677
- const { setDoc: n, currentCanvasId: p, selection: u, currentCanvas: I } = Q(), [s, r] = $(""), [f, e] = $(null), d = G(!1), o = G(null), g = G(null), l = ie(() => u.nodeIds.size + u.edgeIds.size + u.lineIds.size !== 1 ? null : u.nodeIds.size === 1 ? [...u.nodeIds][0] : u.edgeIds.size === 1 ? [...u.edgeIds][0] : u.lineIds.size === 1 ? [...u.lineIds][0] : null, [u]);
678
- Y(() => {
681
+ function Qe() {
682
+ const { setDoc: s, currentCanvasId: p, selection: l, currentCanvas: w } = ee(), [i, t] = j(""), [f, e] = j(null), d = G(!1), o = G(null), g = G(null), u = ae(() => l.nodeIds.size + l.edgeIds.size + l.lineIds.size !== 1 ? null : l.nodeIds.size === 1 ? [...l.nodeIds][0] : l.edgeIds.size === 1 ? [...l.edgeIds][0] : l.lineIds.size === 1 ? [...l.lineIds][0] : null, [l]);
683
+ $(() => {
679
684
  if (d.current) {
680
685
  d.current = !1;
681
686
  return;
682
687
  }
683
- r(JSON.stringify(I, null, 2)), e(null);
684
- }, [I]), Y(() => {
685
- const w = g.current;
686
- if (w && se(w), !l) return;
687
- const S = setTimeout(() => {
688
- const v = Ye(s, l);
689
- if (!v || !g.current) return;
688
+ t(JSON.stringify(w, null, 2)), e(null);
689
+ }, [w]), $(() => {
690
+ const n = g.current;
691
+ if (n && ie(n), !u) return;
692
+ const v = setTimeout(() => {
693
+ const I = je(i, u);
694
+ if (!I || !g.current) return;
690
695
  const z = o.current?.getView();
691
696
  if (!z) return;
692
- const Z = g.current, O = z.scrollDOM;
693
- O.style.scrollBehavior = "smooth";
694
- const B = z.state.doc.line(v.startLine);
695
- z.dispatch({ effects: Ke.scrollIntoView(B.from, {
697
+ const B = g.current, W = z.scrollDOM;
698
+ W.style.scrollBehavior = "smooth";
699
+ const J = z.state.doc.line(I.startLine);
700
+ z.dispatch({ effects: Ze.scrollIntoView(J.from, {
696
701
  y: "start",
697
702
  yMargin: 0
698
703
  }) });
699
704
  const E = () => {
700
- O.style.scrollBehavior = "", se(Z), $e(o.current, v.startLine, v.endLine);
705
+ W.style.scrollBehavior = "", ie(B), qe(o.current, I.startLine, I.endLine);
701
706
  };
702
707
  let c;
703
708
  const m = () => {
704
709
  clearTimeout(c), c = setTimeout(E, 100);
705
710
  };
706
- O.addEventListener("scroll", m), c = setTimeout(() => {
707
- O.removeEventListener("scroll", m), E();
711
+ W.addEventListener("scroll", m), c = setTimeout(() => {
712
+ W.removeEventListener("scroll", m), E();
708
713
  }, 800);
709
714
  }, 120);
710
- return () => clearTimeout(S);
711
- }, [l, s]);
712
- const P = A((w) => {
713
- r(w);
715
+ return () => clearTimeout(v);
716
+ }, [u, i]);
717
+ const M = D((n) => {
718
+ t(n);
714
719
  try {
715
- const S = JSON.parse(w);
716
- S && Array.isArray(S.nodes) && Array.isArray(S.edges) && Array.isArray(S.lines) ? (e(null), d.current = !0, n((v) => ({
717
- ...v,
720
+ const v = JSON.parse(n);
721
+ v && Array.isArray(v.nodes) && Array.isArray(v.edges) && Array.isArray(v.lines) ? (e(null), d.current = !0, s((I) => ({
722
+ ...I,
718
723
  canvases: {
719
- ...v.canvases,
720
- [p]: S
724
+ ...I.canvases,
725
+ [p]: v
721
726
  }
722
727
  }))) : e("JSON must have nodes, edges, lines arrays");
723
- } catch (S) {
724
- e(S.message?.slice(0, 60) ?? "Invalid JSON");
728
+ } catch (v) {
729
+ e(v.message?.slice(0, 60) ?? "Invalid JSON");
725
730
  }
726
- }, [n, p]), t = l ? u.nodeIds.has(l) ? "Node" : u.edgeIds.has(l) ? "Edge" : "Line" : null;
727
- return /* @__PURE__ */ V("div", {
731
+ }, [s, p]), b = u ? l.nodeIds.has(u) ? "Node" : l.edgeIds.has(u) ? "Edge" : "Line" : null;
732
+ return /* @__PURE__ */ X("div", {
728
733
  style: {
729
734
  display: "flex",
730
735
  flexDirection: "column",
@@ -736,7 +741,7 @@ function je() {
736
741
  className: "flow-json-header",
737
742
  children: /* @__PURE__ */ h("span", {
738
743
  className: "flow-json-scope",
739
- children: t ? `${t}: ${l.slice(0, 8)}` : "Canvas"
744
+ children: b ? `${b}: ${u.slice(0, 8)}` : "Canvas"
740
745
  })
741
746
  }),
742
747
  f && /* @__PURE__ */ h("div", {
@@ -754,10 +759,10 @@ function je() {
754
759
  flex: 1,
755
760
  minHeight: 0
756
761
  },
757
- children: /* @__PURE__ */ h(ue, {
762
+ children: /* @__PURE__ */ h(he, {
758
763
  ref: o,
759
- value: s,
760
- onChange: P,
764
+ value: i,
765
+ onChange: M,
761
766
  language: "json",
762
767
  lineNumbers: !1,
763
768
  height: "100%",
@@ -767,13 +772,13 @@ function je() {
767
772
  ]
768
773
  });
769
774
  }
770
- function qe() {
771
- const { contextMenu: n, setContextMenu: p } = X(), { doc: u, setDoc: I, currentCanvasId: s, pushCanvas: r, setSelection: f } = Q(), { duplicate: e } = re();
772
- if (!n) return null;
773
- const d = u.canvases[s];
775
+ function et() {
776
+ const { contextMenu: s, setContextMenu: p } = Y(), { doc: l, setDoc: w, currentCanvasId: i, pushCanvas: t, setSelection: f } = ee(), { duplicate: e } = re();
777
+ if (!s) return null;
778
+ const d = l.canvases[i];
774
779
  if (!d)
775
780
  return p(null), null;
776
- const o = n.nodeId ? d.nodes.find((l) => l.id === n.nodeId) : null, g = [];
781
+ const o = s.nodeId ? d.nodes.find((u) => u.id === s.nodeId) : null, g = [];
777
782
  return o && (g.push({
778
783
  label: "Duplicate",
779
784
  icon: "⧉",
@@ -788,7 +793,7 @@ function qe() {
788
793
  label: "Enter Sub-canvas",
789
794
  icon: "↓",
790
795
  action: () => {
791
- r(o.data.childCanvasId), f({
796
+ t(o.data.childCanvasId), f({
792
797
  nodeIds: /* @__PURE__ */ new Set(),
793
798
  edgeIds: /* @__PURE__ */ new Set(),
794
799
  lineIds: /* @__PURE__ */ new Set()
@@ -803,27 +808,27 @@ function qe() {
803
808
  icon: "🗑",
804
809
  danger: !0,
805
810
  action: () => {
806
- const l = o.data.childCanvasId;
807
- I((P) => {
808
- const t = { ...P.canvases };
809
- ce(t, l);
810
- const w = t[s];
811
- if (!w) return P;
812
- t[s] = {
813
- ...w,
814
- nodes: w.nodes.map((v) => v.id === o.id ? {
815
- ...v,
811
+ const u = o.data.childCanvasId;
812
+ w((M) => {
813
+ const b = { ...M.canvases };
814
+ de(b, u);
815
+ const n = b[i];
816
+ if (!n) return M;
817
+ b[i] = {
818
+ ...n,
819
+ nodes: n.nodes.map((I) => I.id === o.id ? {
820
+ ...I,
816
821
  data: {
817
- ...v.data,
822
+ ...I.data,
818
823
  childCanvasId: void 0
819
824
  }
820
- } : v)
825
+ } : I)
821
826
  };
822
- const S = P.stack.filter((v) => t[v]);
823
- return S.length === 0 && S.push(fe), {
824
- ...P,
825
- canvases: t,
826
- stack: S
827
+ const v = M.stack.filter((I) => b[I]);
828
+ return v.length === 0 && v.push(pe), {
829
+ ...M,
830
+ canvases: b,
831
+ stack: v
827
832
  };
828
833
  });
829
834
  }
@@ -831,48 +836,48 @@ function qe() {
831
836
  label: "Create Sub-canvas",
832
837
  icon: "⊞",
833
838
  action: () => {
834
- const l = q("canvas");
835
- I((P) => {
836
- const t = P.canvases[s];
837
- return t ? {
838
- ...P,
839
+ const u = Q("canvas");
840
+ w((M) => {
841
+ const b = M.canvases[i];
842
+ return b ? {
843
+ ...M,
839
844
  canvases: {
840
- ...P.canvases,
841
- [s]: {
842
- ...t,
843
- nodes: t.nodes.map((w) => w.id === o.id ? {
844
- ...w,
845
+ ...M.canvases,
846
+ [i]: {
847
+ ...b,
848
+ nodes: b.nodes.map((n) => n.id === o.id ? {
849
+ ...n,
845
850
  data: {
846
- ...w.data,
847
- childCanvasId: l
851
+ ...n.data,
852
+ childCanvasId: u
848
853
  }
849
- } : w)
854
+ } : n)
850
855
  },
851
- [l]: {
856
+ [u]: {
852
857
  nodes: [],
853
858
  edges: [],
854
859
  lines: []
855
860
  }
856
861
  }
857
- } : P;
858
- }), r(l);
862
+ } : M;
863
+ }), t(u);
859
864
  }
860
- })), g.length === 0 ? null : /* @__PURE__ */ h(Te, {
861
- x: n.x,
862
- y: n.y,
865
+ })), g.length === 0 ? null : /* @__PURE__ */ h(Le, {
866
+ x: s.x,
867
+ y: s.y,
863
868
  items: g,
864
869
  onClose: () => p(null)
865
870
  });
866
871
  }
867
- function ce(n, p) {
868
- const u = n[p];
869
- if (u) {
870
- for (const I of u.nodes) I.data.childCanvasId && ce(n, I.data.childCanvasId);
871
- delete n[p];
872
+ function de(s, p) {
873
+ const l = s[p];
874
+ if (l) {
875
+ for (const w of l.nodes) w.data.childCanvasId && de(s, w.data.childCanvasId);
876
+ delete s[p];
872
877
  }
873
878
  }
874
879
  export {
875
- An as default
880
+ Nt as default
876
881
  };
877
882
 
878
883
  //# sourceMappingURL=Flow.js.map