dishui 0.0.49 → 0.0.50

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 (52) hide show
  1. package/dist/components/pro/Flow/Flow.js +419 -407
  2. package/dist/components/pro/Flow/Flow.js.map +1 -1
  3. package/dist/components/pro/Flow/archify/build.d.ts +74 -0
  4. package/dist/components/pro/Flow/archify/build.js +103 -0
  5. package/dist/components/pro/Flow/archify/build.js.map +1 -0
  6. package/dist/components/pro/Flow/archify/convert.d.ts +14 -0
  7. package/dist/components/pro/Flow/archify/convert.js +534 -0
  8. package/dist/components/pro/Flow/archify/convert.js.map +1 -0
  9. package/dist/components/pro/Flow/archify/index.d.ts +12 -0
  10. package/dist/components/pro/Flow/archify/palette.d.ts +64 -0
  11. package/dist/components/pro/Flow/archify/palette.js +112 -0
  12. package/dist/components/pro/Flow/archify/palette.js.map +1 -0
  13. package/dist/components/pro/Flow/archify/presets.d.ts +26 -0
  14. package/dist/components/pro/Flow/archify/presets.js +43 -0
  15. package/dist/components/pro/Flow/archify/presets.js.map +1 -0
  16. package/dist/components/pro/Flow/archify/spec.d.ts +283 -0
  17. package/dist/components/pro/Flow/archify/spec.js +10 -0
  18. package/dist/components/pro/Flow/archify/spec.js.map +1 -0
  19. package/dist/components/pro/Flow/constants.js +14 -0
  20. package/dist/components/pro/Flow/constants.js.map +1 -1
  21. package/dist/components/pro/Flow/hooks/useClipboard.d.ts +5 -0
  22. package/dist/components/pro/Flow/hooks/useClipboard.js +129 -73
  23. package/dist/components/pro/Flow/hooks/useClipboard.js.map +1 -1
  24. package/dist/components/pro/Flow/hooks/useFlowImportExport.d.ts +1 -0
  25. package/dist/components/pro/Flow/hooks/useFlowImportExport.js +108 -93
  26. package/dist/components/pro/Flow/hooks/useFlowImportExport.js.map +1 -1
  27. package/dist/components/pro/Flow/hooks/useKeyboardShortcuts.d.ts +1 -0
  28. package/dist/components/pro/Flow/hooks/useKeyboardShortcuts.js +7 -7
  29. package/dist/components/pro/Flow/hooks/useKeyboardShortcuts.js.map +1 -1
  30. package/dist/components/pro/Flow/index.d.ts +2 -0
  31. package/dist/components/pro/Flow/nodes/DataNodeView.d.ts +4 -1
  32. package/dist/components/pro/Flow/nodes/DataNodeView.js +127 -115
  33. package/dist/components/pro/Flow/nodes/DataNodeView.js.map +1 -1
  34. package/dist/components/pro/Flow/nodes/MediaContent.js +72 -67
  35. package/dist/components/pro/Flow/nodes/MediaContent.js.map +1 -1
  36. package/dist/components/pro/Flow/nodes/NodeRenderer.d.ts +5 -0
  37. package/dist/components/pro/Flow/nodes/NodeRenderer.js +216 -115
  38. package/dist/components/pro/Flow/nodes/NodeRenderer.js.map +1 -1
  39. package/dist/components/pro/Flow/panels/FlowToolbar.js +208 -169
  40. package/dist/components/pro/Flow/panels/FlowToolbar.js.map +1 -1
  41. package/dist/components/pro/Flow/panels/InspectorPanel.js +602 -369
  42. package/dist/components/pro/Flow/panels/InspectorPanel.js.map +1 -1
  43. package/dist/components/pro/Flow/panels/ShapePalette.js +50 -39
  44. package/dist/components/pro/Flow/panels/ShapePalette.js.map +1 -1
  45. package/dist/components/pro/Flow/panels/toolbarIcons.d.ts +1 -0
  46. package/dist/components/pro/Flow/panels/toolbarIcons.js +36 -8
  47. package/dist/components/pro/Flow/panels/toolbarIcons.js.map +1 -1
  48. package/dist/components/pro/Flow/types.d.ts +30 -0
  49. package/dist/components/pro/Flow/types.js.map +1 -1
  50. package/dist/dishui.css +1 -1
  51. package/dist/flow.js +73 -56
  52. package/package.json +18 -17
@@ -1,101 +1,157 @@
1
- import { useFlowContext as w } from "../context/FlowContext.js";
2
- import { generateId as h } from "../nodes/nodeUtils.js";
3
- import { useCallback as m, useRef as S } from "react";
4
- function y() {
5
- const { currentCanvas: c, selection: t, setDoc: l, currentCanvasId: r, setSelection: g } = w(), I = S(null), p = m(() => {
6
- const a = c.nodes.filter((n) => t.nodeIds.has(n.id)), o = c.edges.filter((n) => t.edgeIds.has(n.id)), s = c.lines.filter((n) => t.lineIds.has(n.id)), i = new Set(a.map((n) => n.id)), u = c.edges.filter((n) => i.has(n.source) && i.has(n.target) && !t.edgeIds.has(n.id));
7
- I.current = {
8
- nodes: [...a],
9
- edges: [...o, ...u],
10
- lines: [...s]
1
+ import { useFlowContext as N } from "../context/FlowContext.js";
2
+ import { generateId as w } from "../nodes/nodeUtils.js";
3
+ import { useCallback as f, useRef as R } from "react";
4
+ function j() {
5
+ const { currentCanvas: l, selection: d, setDoc: I, currentCanvasId: g, setSelection: p } = N(), S = R(null), x = f(() => {
6
+ const o = l.nodes.filter((t) => d.nodeIds.has(t.id)), i = l.edges.filter((t) => d.edgeIds.has(t.id)), n = l.lines.filter((t) => d.lineIds.has(t.id)), r = new Set(o.map((t) => t.id)), h = l.edges.filter((t) => r.has(t.source) && r.has(t.target) && !d.edgeIds.has(t.id));
7
+ S.current = {
8
+ nodes: [...o],
9
+ edges: [...i, ...h],
10
+ lines: [...n]
11
11
  };
12
- }, [c, t]);
13
- return {
14
- copy: p,
15
- cut: m(() => {
16
- p(), l((a) => {
17
- const o = a.canvases[r];
18
- return o ? {
19
- ...a,
20
- canvases: {
21
- ...a.canvases,
22
- [r]: {
23
- ...o,
24
- nodes: o.nodes.filter((s) => !t.nodeIds.has(s.id)),
25
- edges: o.edges.filter((s) => !t.edgeIds.has(s.id) && !t.nodeIds.has(s.source) && !t.nodeIds.has(s.target)),
26
- lines: o.lines.filter((s) => !t.lineIds.has(s.id))
27
- }
12
+ }, [l, d]), M = f(() => {
13
+ x(), I((o) => {
14
+ const i = o.canvases[g];
15
+ return i ? {
16
+ ...o,
17
+ canvases: {
18
+ ...o.canvases,
19
+ [g]: {
20
+ ...i,
21
+ nodes: i.nodes.filter((n) => !d.nodeIds.has(n.id)),
22
+ edges: i.edges.filter((n) => !d.edgeIds.has(n.id) && !d.nodeIds.has(n.source) && !d.nodeIds.has(n.target)),
23
+ lines: i.lines.filter((n) => !d.lineIds.has(n.id))
28
24
  }
29
- } : a;
30
- }), g({
31
- nodeIds: /* @__PURE__ */ new Set(),
32
- edgeIds: /* @__PURE__ */ new Set(),
33
- lineIds: /* @__PURE__ */ new Set()
34
- });
35
- }, [
36
- p,
37
- l,
38
- r,
39
- t,
40
- g
41
- ]),
42
- paste: m((a = 20, o = 20) => {
43
- const s = I.current;
44
- if (!s) return;
45
- const i = /* @__PURE__ */ new Map(), u = s.nodes.map((e) => {
46
- const d = h("node");
47
- return i.set(e.id, d), {
25
+ }
26
+ } : o;
27
+ }), p({
28
+ nodeIds: /* @__PURE__ */ new Set(),
29
+ edgeIds: /* @__PURE__ */ new Set(),
30
+ lineIds: /* @__PURE__ */ new Set()
31
+ });
32
+ }, [
33
+ x,
34
+ I,
35
+ g,
36
+ d,
37
+ p
38
+ ]), E = f((o = 20, i = 20) => {
39
+ const n = S.current;
40
+ if (!n) return;
41
+ const r = /* @__PURE__ */ new Map(), h = n.nodes.map((s) => {
42
+ const a = w("node");
43
+ return r.set(s.id, a), {
44
+ ...s,
45
+ id: a,
46
+ position: {
47
+ x: s.position.x + o,
48
+ y: s.position.y + i
49
+ },
50
+ data: { ...s.data }
51
+ };
52
+ }), t = n.edges.filter((s) => r.has(s.source) && r.has(s.target)).map((s) => ({
53
+ ...s,
54
+ id: w("edge"),
55
+ source: r.get(s.source),
56
+ target: r.get(s.target),
57
+ data: { ...s.data }
58
+ })), m = n.lines.map((s) => ({
59
+ ...s,
60
+ id: w("line"),
61
+ points: s.points.map((a) => ({
62
+ x: a.x + o,
63
+ y: a.y + i
64
+ }))
65
+ }));
66
+ I((s) => {
67
+ const a = s.canvases[g];
68
+ return a ? {
69
+ ...s,
70
+ canvases: {
71
+ ...s.canvases,
72
+ [g]: {
73
+ ...a,
74
+ nodes: [...a.nodes, ...h],
75
+ edges: [...a.edges, ...t],
76
+ lines: [...a.lines, ...m]
77
+ }
78
+ }
79
+ } : s;
80
+ }), p({
81
+ nodeIds: new Set(h.map((s) => s.id)),
82
+ edgeIds: new Set(t.map((s) => s.id)),
83
+ lineIds: new Set(m.map((s) => s.id))
84
+ });
85
+ }, [
86
+ I,
87
+ g,
88
+ p
89
+ ]), L = S.current !== null;
90
+ return {
91
+ copy: x,
92
+ cut: M,
93
+ paste: E,
94
+ duplicate: f((o = 24, i = 24, n) => {
95
+ const r = n?.nodeIds ?? d.nodeIds, h = n?.edgeIds ?? d.edgeIds, t = n?.lineIds ?? d.lineIds, m = l.nodes.filter((e) => r.has(e.id)), s = l.lines.filter((e) => t.has(e.id)), a = new Set(m.map((e) => e.id)), C = l.edges.filter((e) => h.has(e.id) || a.has(e.source) && a.has(e.target));
96
+ if (m.length === 0 && s.length === 0 && C.length === 0) return;
97
+ const u = /* @__PURE__ */ new Map(), y = m.map((e) => {
98
+ const c = w("node");
99
+ return u.set(e.id, c), {
48
100
  ...e,
49
- id: d,
101
+ id: c,
50
102
  position: {
51
- x: e.position.x + a,
52
- y: e.position.y + o
103
+ x: e.position.x + o,
104
+ y: e.position.y + i
53
105
  },
54
106
  data: { ...e.data }
55
107
  };
56
- }), n = s.edges.filter((e) => i.has(e.source) && i.has(e.target)).map((e) => ({
108
+ });
109
+ for (const e of y) e.parentId && u.has(e.parentId) && (e.parentId = u.get(e.parentId));
110
+ const b = C.filter((e) => u.has(e.source) && u.has(e.target)).map((e) => ({
57
111
  ...e,
58
- id: h("edge"),
59
- source: i.get(e.source),
60
- target: i.get(e.target),
112
+ id: w("edge"),
113
+ source: u.get(e.source),
114
+ target: u.get(e.target),
61
115
  data: { ...e.data }
62
- })), f = s.lines.map((e) => ({
116
+ })), v = s.map((e) => ({
63
117
  ...e,
64
- id: h("line"),
65
- points: e.points.map((d) => ({
66
- x: d.x + a,
67
- y: d.y + o
118
+ id: w("line"),
119
+ points: e.points.map((c) => ({
120
+ x: c.x + o,
121
+ y: c.y + i
68
122
  }))
69
123
  }));
70
- l((e) => {
71
- const d = e.canvases[r];
72
- return d ? {
124
+ I((e) => {
125
+ const c = e.canvases[g];
126
+ return c ? {
73
127
  ...e,
74
128
  canvases: {
75
129
  ...e.canvases,
76
- [r]: {
77
- ...d,
78
- nodes: [...d.nodes, ...u],
79
- edges: [...d.edges, ...n],
80
- lines: [...d.lines, ...f]
130
+ [g]: {
131
+ ...c,
132
+ nodes: [...c.nodes, ...y],
133
+ edges: [...c.edges, ...b],
134
+ lines: [...c.lines, ...v]
81
135
  }
82
136
  }
83
137
  } : e;
84
- }), g({
85
- nodeIds: new Set(u.map((e) => e.id)),
86
- edgeIds: new Set(n.map((e) => e.id)),
87
- lineIds: new Set(f.map((e) => e.id))
138
+ }), p({
139
+ nodeIds: new Set(y.map((e) => e.id)),
140
+ edgeIds: new Set(b.map((e) => e.id)),
141
+ lineIds: new Set(v.map((e) => e.id))
88
142
  });
89
143
  }, [
90
144
  l,
91
- r,
92
- g
145
+ d,
146
+ I,
147
+ g,
148
+ p
93
149
  ]),
94
- hasClipboard: I.current !== null
150
+ hasClipboard: L
95
151
  };
96
152
  }
97
153
  export {
98
- y as useClipboard
154
+ j as useClipboard
99
155
  };
100
156
 
101
157
  //# sourceMappingURL=useClipboard.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useClipboard.js","names":[],"sources":["../../../../../src/components/pro/Flow/hooks/useClipboard.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport { useFlowContext } from '../context/FlowContext';\nimport { generateId } from '../nodes/nodeUtils';\nimport type { FlowNode, FlowEdge, FlowLine } from '../types';\n\ninterface ClipboardData {\n nodes: FlowNode[];\n edges: FlowEdge[];\n lines: FlowLine[];\n}\n\n/**\n * Copy/paste/cut for selected flow elements.\n * Uses internal clipboard (not system clipboard) for structured data.\n */\nexport function useClipboard() {\n const { currentCanvas, selection, setDoc, currentCanvasId, setSelection } = useFlowContext();\n const clipboardRef = useRef<ClipboardData | null>(null);\n\n const copy = useCallback(() => {\n const nodes = currentCanvas.nodes.filter(n => selection.nodeIds.has(n.id));\n const edges = currentCanvas.edges.filter(e => selection.edgeIds.has(e.id));\n const lines = currentCanvas.lines.filter(l => selection.lineIds.has(l.id));\n\n // Also include edges that connect selected nodes\n const nodeIds = new Set(nodes.map(n => n.id));\n const connectedEdges = currentCanvas.edges.filter(\n e => nodeIds.has(e.source) && nodeIds.has(e.target) && !selection.edgeIds.has(e.id),\n );\n\n clipboardRef.current = {\n nodes: [...nodes],\n edges: [...edges, ...connectedEdges],\n lines: [...lines],\n };\n }, [currentCanvas, selection]);\n\n const cut = useCallback(() => {\n copy();\n setDoc(prev => {\n const canvas = prev.canvases[currentCanvasId];\n if (!canvas) return prev;\n return {\n ...prev,\n canvases: {\n ...prev.canvases,\n [currentCanvasId]: {\n ...canvas,\n nodes: canvas.nodes.filter(n => !selection.nodeIds.has(n.id)),\n edges: canvas.edges.filter(e =>\n !selection.edgeIds.has(e.id) &&\n !selection.nodeIds.has(e.source) &&\n !selection.nodeIds.has(e.target),\n ),\n lines: canvas.lines.filter(l => !selection.lineIds.has(l.id)),\n },\n },\n };\n });\n setSelection({ nodeIds: new Set(), edgeIds: new Set(), lineIds: new Set() });\n }, [copy, setDoc, currentCanvasId, selection, setSelection]);\n\n const paste = useCallback((offsetX = 20, offsetY = 20) => {\n const cb = clipboardRef.current;\n if (!cb) return;\n\n const idMap = new Map<string, string>();\n const newNodes: FlowNode[] = cb.nodes.map(n => {\n const newId = generateId('node');\n idMap.set(n.id, newId);\n return {\n ...n,\n id: newId,\n position: { x: n.position.x + offsetX, y: n.position.y + offsetY },\n data: { ...n.data },\n };\n });\n\n const newEdges: FlowEdge[] = cb.edges\n .filter(e => idMap.has(e.source) && idMap.has(e.target))\n .map(e => ({\n ...e,\n id: generateId('edge'),\n source: idMap.get(e.source)!,\n target: idMap.get(e.target)!,\n data: { ...e.data },\n }));\n\n const newLines: FlowLine[] = cb.lines.map(l => ({\n ...l,\n id: generateId('line'),\n points: l.points.map(p => ({ x: p.x + offsetX, y: p.y + offsetY })),\n }));\n\n setDoc(prev => {\n const canvas = prev.canvases[currentCanvasId];\n if (!canvas) return prev;\n return {\n ...prev,\n canvases: {\n ...prev.canvases,\n [currentCanvasId]: {\n ...canvas,\n nodes: [...canvas.nodes, ...newNodes],\n edges: [...canvas.edges, ...newEdges],\n lines: [...canvas.lines, ...newLines],\n },\n },\n };\n });\n\n setSelection({\n nodeIds: new Set(newNodes.map(n => n.id)),\n edgeIds: new Set(newEdges.map(e => e.id)),\n lineIds: new Set(newLines.map(l => l.id)),\n });\n }, [setDoc, currentCanvasId, setSelection]);\n\n const hasClipboard = clipboardRef.current !== null;\n\n return { copy, cut, paste, hasClipboard };\n}\n"],"mappings":";;;AAeA,SAAgB,IAAe;AAC7B,QAAM,EAAE,eAAA,GAAe,WAAA,GAAW,QAAA,GAAQ,iBAAA,GAAiB,cAAA,EAAA,IAAiB,EAAe,GACrF,IAAe,EAA6B,IAAI,GAEhD,IAAO,EAAA,MAAkB;AAC7B,UAAM,IAAQ,EAAc,MAAM,OAAA,CAAO,MAAK,EAAU,QAAQ,IAAI,EAAE,EAAE,CAAC,GACnE,IAAQ,EAAc,MAAM,OAAA,CAAO,MAAK,EAAU,QAAQ,IAAI,EAAE,EAAE,CAAC,GACnE,IAAQ,EAAc,MAAM,OAAA,CAAO,MAAK,EAAU,QAAQ,IAAI,EAAE,EAAE,CAAC,GAGnE,IAAU,IAAI,IAAI,EAAM,IAAA,CAAI,MAAK,EAAE,EAAE,CAAC,GACtC,IAAiB,EAAc,MAAM,OAAA,CACzC,MAAK,EAAQ,IAAI,EAAE,MAAM,KAAK,EAAQ,IAAI,EAAE,MAAM,KAAK,CAAC,EAAU,QAAQ,IAAI,EAAE,EAAE,CACpF;AAEA,IAAA,EAAa,UAAU;AAAA,MACrB,OAAO,CAAC,GAAG,CAAK;AAAA,MAChB,OAAO,CAAC,GAAG,GAAO,GAAG,CAAc;AAAA,MACnC,OAAO,CAAC,GAAG,CAAK;AAAA,IAClB;AAAA,EACF,GAAG,CAAC,GAAe,CAAS,CAAC;AAqF7B,SAAO;AAAA,IAAE,MAAA;AAAA,IAAM,KAnFH,EAAA,M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I,IAAI,EAAS,IAAA,CAAI,MAAK,EAAE,EAAE,CAAC;AAAA,MAC1C,CAAC;AAAA,IACH,GAAG;AAAA,MAAC;AAAA,MAAQ;AAAA,MAAiB;AAAA,IAAY,CAIrB;AAAA,IAAO,cAFN,EAAa,YAAY;AAAA,EAEN;AAC1C"}
1
+ {"version":3,"file":"useClipboard.js","names":[],"sources":["../../../../../src/components/pro/Flow/hooks/useClipboard.ts"],"sourcesContent":["import { useCallback, useRef } from 'react';\nimport { useFlowContext } from '../context/FlowContext';\nimport { generateId } from '../nodes/nodeUtils';\nimport type { FlowNode, FlowEdge, FlowLine } from '../types';\n\ninterface ClipboardData {\n nodes: FlowNode[];\n edges: FlowEdge[];\n lines: FlowLine[];\n}\n\n/**\n * Copy/paste/cut for selected flow elements.\n * Uses internal clipboard (not system clipboard) for structured data.\n */\nexport function useClipboard() {\n const { currentCanvas, selection, setDoc, currentCanvasId, setSelection } = useFlowContext();\n const clipboardRef = useRef<ClipboardData | null>(null);\n\n const copy = useCallback(() => {\n const nodes = currentCanvas.nodes.filter(n => selection.nodeIds.has(n.id));\n const edges = currentCanvas.edges.filter(e => selection.edgeIds.has(e.id));\n const lines = currentCanvas.lines.filter(l => selection.lineIds.has(l.id));\n\n // Also include edges that connect selected nodes\n const nodeIds = new Set(nodes.map(n => n.id));\n const connectedEdges = currentCanvas.edges.filter(\n e => nodeIds.has(e.source) && nodeIds.has(e.target) && !selection.edgeIds.has(e.id),\n );\n\n clipboardRef.current = {\n nodes: [...nodes],\n edges: [...edges, ...connectedEdges],\n lines: [...lines],\n };\n }, [currentCanvas, selection]);\n\n const cut = useCallback(() => {\n copy();\n setDoc(prev => {\n const canvas = prev.canvases[currentCanvasId];\n if (!canvas) return prev;\n return {\n ...prev,\n canvases: {\n ...prev.canvases,\n [currentCanvasId]: {\n ...canvas,\n nodes: canvas.nodes.filter(n => !selection.nodeIds.has(n.id)),\n edges: canvas.edges.filter(e =>\n !selection.edgeIds.has(e.id) &&\n !selection.nodeIds.has(e.source) &&\n !selection.nodeIds.has(e.target),\n ),\n lines: canvas.lines.filter(l => !selection.lineIds.has(l.id)),\n },\n },\n };\n });\n setSelection({ nodeIds: new Set(), edgeIds: new Set(), lineIds: new Set() });\n }, [copy, setDoc, currentCanvasId, selection, setSelection]);\n\n const paste = useCallback((offsetX = 20, offsetY = 20) => {\n const cb = clipboardRef.current;\n if (!cb) return;\n\n const idMap = new Map<string, string>();\n const newNodes: FlowNode[] = cb.nodes.map(n => {\n const newId = generateId('node');\n idMap.set(n.id, newId);\n return {\n ...n,\n id: newId,\n position: { x: n.position.x + offsetX, y: n.position.y + offsetY },\n data: { ...n.data },\n };\n });\n\n const newEdges: FlowEdge[] = cb.edges\n .filter(e => idMap.has(e.source) && idMap.has(e.target))\n .map(e => ({\n ...e,\n id: generateId('edge'),\n source: idMap.get(e.source)!,\n target: idMap.get(e.target)!,\n data: { ...e.data },\n }));\n\n const newLines: FlowLine[] = cb.lines.map(l => ({\n ...l,\n id: generateId('line'),\n points: l.points.map(p => ({ x: p.x + offsetX, y: p.y + offsetY })),\n }));\n\n setDoc(prev => {\n const canvas = prev.canvases[currentCanvasId];\n if (!canvas) return prev;\n return {\n ...prev,\n canvases: {\n ...prev.canvases,\n [currentCanvasId]: {\n ...canvas,\n nodes: [...canvas.nodes, ...newNodes],\n edges: [...canvas.edges, ...newEdges],\n lines: [...canvas.lines, ...newLines],\n },\n },\n };\n });\n\n setSelection({\n nodeIds: new Set(newNodes.map(n => n.id)),\n edgeIds: new Set(newEdges.map(e => e.id)),\n lineIds: new Set(newLines.map(l => l.id)),\n });\n }, [setDoc, currentCanvasId, setSelection]);\n\n const hasClipboard = clipboardRef.current !== null;\n\n /**\n * Duplicate the current selection in place (Cmd/Ctrl+D). Unlike copy+paste\n * this does NOT touch the clipboard, so a prior copy stays intact. Clones the\n * selected nodes (plus edges wholly between them) and lines with a small\n * offset, then selects the clones.\n */\n const duplicate = useCallback((\n offsetX = 24,\n offsetY = 24,\n targets?: { nodeIds?: Set<string>; edgeIds?: Set<string>; lineIds?: Set<string> },\n ) => {\n const nodeSel = targets?.nodeIds ?? selection.nodeIds;\n const edgeSel = targets?.edgeIds ?? selection.edgeIds;\n const lineSel = targets?.lineIds ?? selection.lineIds;\n const nodes = currentCanvas.nodes.filter(n => nodeSel.has(n.id));\n const lines = currentCanvas.lines.filter(l => lineSel.has(l.id));\n const nodeIdSet = new Set(nodes.map(n => n.id));\n const edges = currentCanvas.edges.filter(e =>\n edgeSel.has(e.id) ||\n (nodeIdSet.has(e.source) && nodeIdSet.has(e.target)),\n );\n if (nodes.length === 0 && lines.length === 0 && edges.length === 0) return;\n\n const idMap = new Map<string, string>();\n // Assign fresh ids to nodes first so intra-selection edges can be remapped.\n const newNodes: FlowNode[] = nodes.map(n => {\n const newId = generateId('node');\n idMap.set(n.id, newId);\n return { ...n, id: newId, position: { x: n.position.x + offsetX, y: n.position.y + offsetY }, data: { ...n.data } };\n });\n // Re-parent cloned children onto cloned groups when both were duplicated.\n for (const n of newNodes) {\n if (n.parentId && idMap.has(n.parentId)) n.parentId = idMap.get(n.parentId);\n }\n\n const newEdges: FlowEdge[] = edges\n .filter(e => idMap.has(e.source) && idMap.has(e.target))\n .map(e => ({\n ...e,\n id: generateId('edge'),\n source: idMap.get(e.source)!,\n target: idMap.get(e.target)!,\n data: { ...e.data },\n }));\n\n const newLines: FlowLine[] = lines.map(l => ({\n ...l,\n id: generateId('line'),\n points: l.points.map(p => ({ x: p.x + offsetX, y: p.y + offsetY })),\n }));\n\n setDoc(prev => {\n const canvas = prev.canvases[currentCanvasId];\n if (!canvas) return prev;\n return {\n ...prev,\n canvases: {\n ...prev.canvases,\n [currentCanvasId]: {\n ...canvas,\n nodes: [...canvas.nodes, ...newNodes],\n edges: [...canvas.edges, ...newEdges],\n lines: [...canvas.lines, ...newLines],\n },\n },\n };\n });\n\n setSelection({\n nodeIds: new Set(newNodes.map(n => n.id)),\n edgeIds: new Set(newEdges.map(e => e.id)),\n lineIds: new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,QAAQ,EAAM,IAAI,EAAE,MAAM;AAAA,QAC1B,MAAM,EAAE,GAAG,EAAE,KAAK;AAAA,MACpB,EAAE,GAEE,IAAuB,EAAM,IAAA,CAAI,OAAM;AAAA,QAC3C,GAAG;AAAA,QACH,IAAI,EAAW,MAAM;AAAA,QACrB,QAAQ,EAAE,OAAO,IAAA,CAAI,OAAM;AAAA,UAAE,GAAG,EAAE,IAAI;AAAA,UAAS,GAAG,EAAE,IAAI;AAAA,QAAQ,EAAE;AAAA,MACpE,EAAE;AAEF,MAAA,EAAA,CAAO,MAAQ;AACb,cAAM,IAAS,EAAK,SAAS,CAAA;AAC7B,eAAK,IACE;AAAA,UACL,GAAG;AAAA,UACH,UAAU;AAAA,YACR,GAAG,EAAK;AAAA,aACP,CAAA,GAAkB;AAAA,cACjB,GAAG;AAAA,cACH,OAAO,CAAC,GAAG,EAAO,OAAO,GAAG,CAAQ;AAAA,cACpC,OAAO,CAAC,GAAG,EAAO,OAAO,GAAG,CAAQ;AAAA,cACpC,OAAO,CAAC,GAAG,EAAO,OAAO,GAAG,CAAQ;AAAA,YACtC;AAAA,UACF;AAAA,QACF,IAZoB;AAAA,MAatB,CAAC,GAED,EAAa;AAAA,QACX,SAAS,IAAI,IAAI,EAAS,IAAA,CAAI,MAAK,EAAE,EAAE,CAAC;AAAA,QACxC,SAAS,IAAI,IAAI,EAAS,IAAA,CAAI,MAAK,EAAE,EAAE,CAAC;AAAA,QACxC,SAAS,IAAI,IAAI,EAAS,IAAA,CAAI,MAAK,EAAE,EAAE,CAAC;AAAA,MAC1C,CAAC;AAAA,IACH,GAAG;AAAA,MAAC;AAAA,MAAe;AAAA,MAAW;AAAA,MAAQ;AAAA,MAAiB;AAAA,IAAY,CAExC;AAAA,IAAW,cAAA;AAAA,EAAa;AACrD"}
@@ -10,6 +10,7 @@ export declare function safeFileBaseName(title: string | undefined, fallback?: s
10
10
  export declare function useFlowImportExport(): {
11
11
  exportJSON: () => string;
12
12
  importJSON: (json: string) => void;
13
+ importArchify: (input: string | object) => boolean;
13
14
  importMermaid: (mermaidCode: string) => void;
14
15
  exportMarkdown: () => string;
15
16
  clearDocument: () => void;
@@ -1,129 +1,144 @@
1
1
  import { ROOT_CANVAS_ID as $, createEmptyDocument as x } from "../constants.js";
2
2
  import { useFlowContext as C } from "../context/FlowContext.js";
3
- import { generateId as N } from "../nodes/nodeUtils.js";
4
- import { useCallback as k } from "react";
5
- var S = 1;
6
- function F(s, a = "flowchart") {
7
- return (s ?? "").trim().replace(/[\\/:*?"<>|]+/g, "-").replace(/\s+/g, " ").trim() || a;
3
+ import { generateId as O } from "../nodes/nodeUtils.js";
4
+ import { isArchifySpec as M } from "../archify/spec.js";
5
+ import { archifyToFlowDocument as S } from "../archify/convert.js";
6
+ import { useCallback as b } from "react";
7
+ var R = 1;
8
+ function j(n, o = "flowchart") {
9
+ return (n ?? "").trim().replace(/[\\/:*?"<>|]+/g, "-").replace(/\s+/g, " ").trim() || o;
8
10
  }
9
- function J() {
10
- const { doc: s, setDoc: a } = C();
11
+ function z() {
12
+ const { doc: n, setDoc: o } = C();
11
13
  return {
12
- exportJSON: k(() => {
14
+ exportJSON: b(() => {
13
15
  const e = {
14
- version: S,
15
- canvases: s.canvases,
16
- stack: s.stack,
17
- title: s.title
16
+ version: R,
17
+ canvases: n.canvases,
18
+ stack: n.stack,
19
+ title: n.title
18
20
  };
19
21
  return JSON.stringify(e, null, 2);
20
- }, [s]),
21
- importJSON: k((e) => {
22
+ }, [n]),
23
+ importJSON: b((e) => {
22
24
  try {
23
- const n = JSON.parse(e);
24
- if (!n.canvases || !n.stack) throw new Error("Invalid document format");
25
- a({
26
- canvases: n.canvases,
27
- stack: n.stack,
28
- title: n.title
25
+ const s = JSON.parse(e);
26
+ if (M(s)) {
27
+ o(S(s));
28
+ return;
29
+ }
30
+ const i = s;
31
+ if (!i.canvases || !i.stack) throw new Error("Invalid document format");
32
+ o({
33
+ canvases: i.canvases,
34
+ stack: i.stack,
35
+ title: i.title
29
36
  });
30
- } catch (n) {
31
- console.error("Failed to import JSON:", n);
37
+ } catch (s) {
38
+ console.error("Failed to import JSON:", s);
39
+ }
40
+ }, [o]),
41
+ importArchify: b((e) => {
42
+ try {
43
+ const s = typeof e == "string" ? JSON.parse(e) : e;
44
+ return M(s) ? (o(S(s)), !0) : !1;
45
+ } catch (s) {
46
+ return console.error("Failed to import Archify spec:", s), !1;
32
47
  }
33
- }, [a]),
34
- importMermaid: k((e) => {
35
- const n = R(e);
36
- a(n);
37
- }, [a]),
38
- exportMarkdown: k(() => O(s), [s]),
39
- clearDocument: k(() => {
40
- a(x());
41
- }, [a])
48
+ }, [o]),
49
+ importMermaid: b((e) => {
50
+ const s = L(e);
51
+ o(s);
52
+ }, [o]),
53
+ exportMarkdown: b(() => E(n), [n]),
54
+ clearDocument: b(() => {
55
+ o(x());
56
+ }, [o])
42
57
  };
43
58
  }
44
- function O(s) {
45
- const a = [], e = (i) => {
46
- const l = (i.data.label ?? "").trim();
47
- return l ? l.replace(/\s+/g, " ") : i.type === "mediaNode" ? `(${i.data.mediaKind ?? "media"})` : `(${i.type})`;
48
- }, n = (i, l, h) => {
49
- const m = s.canvases[i];
59
+ function E(n) {
60
+ const o = [], e = (c) => {
61
+ const f = (c.data.label ?? "").trim();
62
+ return f ? f.replace(/\s+/g, " ") : c.type === "mediaNode" ? `(${c.data.mediaKind ?? "media"})` : `(${c.type})`;
63
+ }, s = (c, f, h) => {
64
+ const m = n.canvases[c];
50
65
  if (!m) return;
51
- const b = new Map(m.nodes.map((t) => [t.id, t])), o = /* @__PURE__ */ new Map();
66
+ const y = new Map(m.nodes.map((t) => [t.id, t])), a = /* @__PURE__ */ new Map();
52
67
  for (const t of m.nodes) {
53
- const r = t.parentId && b.has(t.parentId) ? t.parentId : void 0, d = o.get(r) ?? [];
54
- d.push(t), o.set(r, d);
68
+ const r = t.parentId && y.has(t.parentId) ? t.parentId : void 0, d = a.get(r) ?? [];
69
+ d.push(t), a.set(r, d);
55
70
  }
56
71
  const p = (t, r) => {
57
- const d = " ".repeat(r), c = t.data.isGroup || t.type === "flowGroup" || t.type === "geometryGroup" ? `**${e(t)}**` : e(t);
58
- if (a.push(`${d}- ${c}`), t.type === "mediaNode" && t.data.mediaKind) {
72
+ const d = " ".repeat(r), l = t.data.isGroup || t.type === "flowGroup" || t.type === "geometryGroup" ? `**${e(t)}**` : e(t);
73
+ if (o.push(`${d}- ${l}`), t.type === "mediaNode" && t.data.mediaKind) {
59
74
  const g = t.data.mediaKind;
60
75
  if (g === "data" && t.data.dataConfig) {
61
- const y = t.data.dataConfig, M = y.columns.map((I) => I.label ?? I.key).join(", ");
62
- a.push(`${d} - 数据表:${y.rows.length} 行 · 列(${M})`);
76
+ const k = t.data.dataConfig, N = k.columns.map((I) => I.label ?? I.key).join(", ");
77
+ o.push(`${d} - 数据表:${k.rows.length} 行 · 列(${N})`);
63
78
  } else if (t.data.mediaContent && g !== "image" && g !== "model3d") {
64
- const y = t.data.mediaContent.trim().split(`
79
+ const k = t.data.mediaContent.trim().split(`
65
80
  `)[0].slice(0, 80);
66
- y && a.push(`${d} - ${g}: ${y}`);
81
+ k && o.push(`${d} - ${g}: ${k}`);
67
82
  }
68
83
  }
69
- const v = o.get(t.id) ?? [];
84
+ const v = a.get(t.id) ?? [];
70
85
  for (const g of v) p(g, r + 1);
71
86
  const w = t.data.childCanvasId;
72
- w && s.canvases[w] && !h.has(w) && (h.add(w), n(w, l + 1, h));
73
- }, u = o.get(void 0) ?? [];
87
+ w && n.canvases[w] && !h.has(w) && (h.add(w), s(w, f + 1, h));
88
+ }, u = a.get(void 0) ?? [];
74
89
  for (const t of u) p(t, 0);
75
90
  if (m.edges.length > 0) {
76
- a.push(""), a.push(`${"#".repeat(Math.min(6, l + 1))} 连接关系`);
91
+ o.push(""), o.push(`${"#".repeat(Math.min(6, f + 1))} 连接关系`);
77
92
  for (const t of m.edges) {
78
- const r = b.get(t.source), d = b.get(t.target);
93
+ const r = y.get(t.source), d = y.get(t.target);
79
94
  if (!r || !d) continue;
80
- const c = t.data.labelText ? ` (${t.data.labelText})` : "";
81
- a.push(`- ${e(r)} → ${e(d)}${c}`);
95
+ const l = t.data.labelText ? ` (${t.data.labelText})` : "";
96
+ o.push(`- ${e(r)} → ${e(d)}${l}`);
82
97
  }
83
98
  }
84
- }, f = /* @__PURE__ */ new Set([$]);
85
- a.push("# 流程图"), a.push(""), n($, 1, f);
86
- for (const i of Object.keys(s.canvases))
87
- f.has(i) || (f.add(i), a.push(""), a.push(`## 画布 ${i}`), a.push(""), n(i, 2, f));
88
- return a.join(`
99
+ }, i = /* @__PURE__ */ new Set([$]);
100
+ o.push("# 流程图"), o.push(""), s($, 1, i);
101
+ for (const c of Object.keys(n.canvases))
102
+ i.has(c) || (i.add(c), o.push(""), o.push(`## 画布 ${c}`), o.push(""), s(c, 2, i));
103
+ return o.join(`
89
104
  `).replace(/\n{3,}/g, `
90
105
 
91
106
  `).trim() + `
92
107
  `;
93
108
  }
94
- function R(s) {
95
- const a = s.split(`
96
- `).map((o) => o.trim()).filter((o) => o && !o.startsWith("%%")), e = /* @__PURE__ */ new Map(), n = [];
97
- let f = !1;
98
- for (const o of a) {
99
- if (/^(graph|flowchart)\s+(LR|RL)/i.test(o)) {
100
- f = !0;
109
+ function L(n) {
110
+ const o = n.split(`
111
+ `).map((a) => a.trim()).filter((a) => a && !a.startsWith("%%")), e = /* @__PURE__ */ new Map(), s = [];
112
+ let i = !1;
113
+ for (const a of o) {
114
+ if (/^(graph|flowchart)\s+(LR|RL)/i.test(a)) {
115
+ i = !0;
101
116
  continue;
102
117
  }
103
- if (/^(graph|flowchart)\s+/i.test(o)) continue;
104
- const p = o.match(/^(\w+)(?:\[([^\]]*)\])?\s*(-->|---|-\.->|==>)(?:\|([^|]*)\|)?\s*(\w+)(?:\[([^\]]*)\])?/);
118
+ if (/^(graph|flowchart)\s+/i.test(a)) continue;
119
+ const p = a.match(/^(\w+)(?:\[([^\]]*)\])?\s*(-->|---|-\.->|==>)(?:\|([^|]*)\|)?\s*(\w+)(?:\[([^\]]*)\])?/);
105
120
  if (p) {
106
- const [, t, r, , d, c, v] = p;
121
+ const [, t, r, , d, l, v] = p;
107
122
  r && !e.has(t) && e.set(t, {
108
123
  id: t,
109
124
  label: r
110
- }), v && !e.has(c) && e.set(c, {
111
- id: c,
125
+ }), v && !e.has(l) && e.set(l, {
126
+ id: l,
112
127
  label: v
113
128
  }), e.has(t) || e.set(t, {
114
129
  id: t,
115
130
  label: t
116
- }), e.has(c) || e.set(c, {
117
- id: c,
118
- label: c
119
- }), n.push({
131
+ }), e.has(l) || e.set(l, {
132
+ id: l,
133
+ label: l
134
+ }), s.push({
120
135
  from: t,
121
- to: c,
136
+ to: l,
122
137
  label: d?.trim()
123
138
  });
124
139
  continue;
125
140
  }
126
- const u = o.match(/^(\w+)\[([^\]]*)\]/);
141
+ const u = a.match(/^(\w+)\[([^\]]*)\]/);
127
142
  if (u) {
128
143
  const [, t, r] = u;
129
144
  e.has(t) || e.set(t, {
@@ -132,11 +147,11 @@ function R(s) {
132
147
  });
133
148
  }
134
149
  }
135
- const i = [...e.keys()], l = f ? i.length : Math.ceil(Math.sqrt(i.length)), h = {
150
+ const c = [...e.keys()], f = i ? c.length : Math.ceil(Math.sqrt(c.length)), h = {
136
151
  x: 200,
137
152
  y: 120
138
- }, m = i.map((o, p) => {
139
- const u = p % l, t = Math.floor(p / l), r = e.get(o);
153
+ }, m = c.map((a, p) => {
154
+ const u = p % f, t = Math.floor(p / f), r = e.get(a);
140
155
  return {
141
156
  id: r.id,
142
157
  type: "shapeRoundRect",
@@ -155,40 +170,40 @@ function R(s) {
155
170
  fontSize: 14
156
171
  }
157
172
  };
158
- }), b = n.map((o) => ({
159
- id: N("edge"),
160
- source: o.from,
161
- target: o.to,
173
+ }), y = s.map((a) => ({
174
+ id: O("edge"),
175
+ source: a.from,
176
+ target: a.to,
162
177
  type: "smoothstep",
163
178
  data: {
164
179
  strokeColor: "theme:base-content",
165
180
  strokeWidth: 2,
166
181
  lineStyle: "solid",
167
182
  markerEnd: "arrowclosed",
168
- labelText: o.label
183
+ labelText: a.label
169
184
  }
170
185
  }));
171
186
  return {
172
187
  canvases: { [$]: {
173
188
  nodes: m,
174
- edges: b,
189
+ edges: y,
175
190
  lines: []
176
191
  } },
177
192
  stack: [$]
178
193
  };
179
194
  }
180
- async function G(s) {
181
- return s.toDataURL("image/png");
195
+ async function K(n) {
196
+ return n.toDataURL("image/png");
182
197
  }
183
- function j(s, a) {
198
+ function W(n, o) {
184
199
  const e = document.createElement("a");
185
- e.href = s, e.download = a, document.body.appendChild(e), e.click(), document.body.removeChild(e);
200
+ e.href = n, e.download = o, document.body.appendChild(e), e.click(), document.body.removeChild(e);
186
201
  }
187
202
  export {
188
- j as downloadDataURL,
189
- G as exportCanvasToPNG,
190
- F as safeFileBaseName,
191
- J as useFlowImportExport
203
+ W as downloadDataURL,
204
+ K as exportCanvasToPNG,
205
+ j as safeFileBaseName,
206
+ z as useFlowImportExport
192
207
  };
193
208
 
194
209
  //# sourceMappingURL=useFlowImportExport.js.map