dishui 0.0.55 → 0.0.57

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