@octaviaflow/core 3.0.13 → 3.0.17-beta.0

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 (231) hide show
  1. package/dist/chunk-2AWVQFSC.js +2456 -0
  2. package/dist/chunk-2AWVQFSC.js.map +1 -0
  3. package/dist/chunk-2K7IQR2F.js +2432 -0
  4. package/dist/chunk-2K7IQR2F.js.map +1 -0
  5. package/dist/chunk-2YUWZPIT.js +2483 -0
  6. package/dist/chunk-2YUWZPIT.js.map +1 -0
  7. package/dist/chunk-4VCRGPYQ.js +2452 -0
  8. package/dist/chunk-4VCRGPYQ.js.map +1 -0
  9. package/dist/chunk-4WU5YAL2.js +2470 -0
  10. package/dist/chunk-4WU5YAL2.js.map +1 -0
  11. package/dist/chunk-5L4TGL74.js +2448 -0
  12. package/dist/chunk-5L4TGL74.js.map +1 -0
  13. package/dist/chunk-7M5HFY2J.js +2483 -0
  14. package/dist/chunk-7M5HFY2J.js.map +1 -0
  15. package/dist/chunk-AJ4556EH.js +2490 -0
  16. package/dist/chunk-AJ4556EH.js.map +1 -0
  17. package/dist/chunk-AOL365B3.js +2448 -0
  18. package/dist/chunk-AOL365B3.js.map +1 -0
  19. package/dist/chunk-D4X7RMGF.js +2481 -0
  20. package/dist/chunk-D4X7RMGF.js.map +1 -0
  21. package/dist/chunk-DCGXCPD4.js +2389 -0
  22. package/dist/chunk-DCGXCPD4.js.map +1 -0
  23. package/dist/chunk-DG35MIV3.js +2480 -0
  24. package/dist/chunk-DG35MIV3.js.map +1 -0
  25. package/dist/chunk-DRZ73Q5X.js +2503 -0
  26. package/dist/chunk-DRZ73Q5X.js.map +1 -0
  27. package/dist/chunk-DRZMET2G.js +2458 -0
  28. package/dist/chunk-DRZMET2G.js.map +1 -0
  29. package/dist/chunk-DYCW4TYB.js +2546 -0
  30. package/dist/chunk-DYCW4TYB.js.map +1 -0
  31. package/dist/chunk-E7WR7DMP.js +2451 -0
  32. package/dist/chunk-E7WR7DMP.js.map +1 -0
  33. package/dist/chunk-ELNQQAHD.js +2454 -0
  34. package/dist/chunk-ELNQQAHD.js.map +1 -0
  35. package/dist/chunk-FN3MFN6C.js +2389 -0
  36. package/dist/chunk-FN3MFN6C.js.map +1 -0
  37. package/dist/chunk-IBTEGHFT.js +10 -0
  38. package/dist/chunk-IBTEGHFT.js.map +1 -0
  39. package/dist/chunk-JCPM7YF2.js +2474 -0
  40. package/dist/chunk-JCPM7YF2.js.map +1 -0
  41. package/dist/chunk-JLPCCZKG.js +2459 -0
  42. package/dist/chunk-JLPCCZKG.js.map +1 -0
  43. package/dist/chunk-KY4JHPIE.js +2546 -0
  44. package/dist/chunk-KY4JHPIE.js.map +1 -0
  45. package/dist/chunk-LCQMQAWJ.js +2461 -0
  46. package/dist/chunk-LCQMQAWJ.js.map +1 -0
  47. package/dist/chunk-LSDAQCUJ.js +2546 -0
  48. package/dist/chunk-LSDAQCUJ.js.map +1 -0
  49. package/dist/chunk-LW4ZHQKL.js +2432 -0
  50. package/dist/chunk-LW4ZHQKL.js.map +1 -0
  51. package/dist/chunk-MMZW3Q26.js +2442 -0
  52. package/dist/chunk-MMZW3Q26.js.map +1 -0
  53. package/dist/chunk-MXJR2WHG.js +2470 -0
  54. package/dist/chunk-MXJR2WHG.js.map +1 -0
  55. package/dist/chunk-OK2CUIKQ.js +2447 -0
  56. package/dist/chunk-OK2CUIKQ.js.map +1 -0
  57. package/dist/chunk-OSOP2WPT.js +2456 -0
  58. package/dist/chunk-OSOP2WPT.js.map +1 -0
  59. package/dist/chunk-PNBZLLWT.js +2529 -0
  60. package/dist/chunk-PNBZLLWT.js.map +1 -0
  61. package/dist/chunk-PULX2GK5.js +2447 -0
  62. package/dist/chunk-PULX2GK5.js.map +1 -0
  63. package/dist/chunk-QDT45KF4.js +2480 -0
  64. package/dist/chunk-QDT45KF4.js.map +1 -0
  65. package/dist/chunk-QI3ITHAZ.js +2450 -0
  66. package/dist/chunk-QI3ITHAZ.js.map +1 -0
  67. package/dist/chunk-QSGJ3DNA.js +2475 -0
  68. package/dist/chunk-QSGJ3DNA.js.map +1 -0
  69. package/dist/chunk-RDGJWRHM.js +2490 -0
  70. package/dist/chunk-RDGJWRHM.js.map +1 -0
  71. package/dist/chunk-SDE3ARKY.js +2451 -0
  72. package/dist/chunk-SDE3ARKY.js.map +1 -0
  73. package/dist/chunk-SX7WRJGD.js +2441 -0
  74. package/dist/chunk-SX7WRJGD.js.map +1 -0
  75. package/dist/chunk-TZ56MSYM.js +2452 -0
  76. package/dist/chunk-TZ56MSYM.js.map +1 -0
  77. package/dist/chunk-UEQLKS2B.js +2445 -0
  78. package/dist/chunk-UEQLKS2B.js.map +1 -0
  79. package/dist/chunk-UNU6YNTL.js +2452 -0
  80. package/dist/chunk-UNU6YNTL.js.map +1 -0
  81. package/dist/chunk-UUG6XYUC.js +2482 -0
  82. package/dist/chunk-UUG6XYUC.js.map +1 -0
  83. package/dist/chunk-VEY3BP5E.js +2447 -0
  84. package/dist/chunk-VEY3BP5E.js.map +1 -0
  85. package/dist/chunk-WBTXV3Q2.js +2482 -0
  86. package/dist/chunk-WBTXV3Q2.js.map +1 -0
  87. package/dist/chunk-WILVB7XA.js +2512 -0
  88. package/dist/chunk-WILVB7XA.js.map +1 -0
  89. package/dist/chunk-WQCHABP3.js +2441 -0
  90. package/dist/chunk-WQCHABP3.js.map +1 -0
  91. package/dist/chunk-WUFAW3TB.js +2512 -0
  92. package/dist/chunk-WUFAW3TB.js.map +1 -0
  93. package/dist/chunk-WYBJKALZ.js +2458 -0
  94. package/dist/chunk-WYBJKALZ.js.map +1 -0
  95. package/dist/chunk-XZ7FELMT.js +2448 -0
  96. package/dist/chunk-XZ7FELMT.js.map +1 -0
  97. package/dist/chunk-YATCRJVF.js +2458 -0
  98. package/dist/chunk-YATCRJVF.js.map +1 -0
  99. package/dist/chunk-YSSD2T4M.js +2451 -0
  100. package/dist/chunk-YSSD2T4M.js.map +1 -0
  101. package/dist/chunk-YW6ZOYCG.js +2451 -0
  102. package/dist/chunk-YW6ZOYCG.js.map +1 -0
  103. package/dist/components/ActionsDrawer/ActionsDrawer.d.ts +89 -0
  104. package/dist/components/ActionsDrawer/ActionsDrawer.d.ts.map +1 -0
  105. package/dist/components/ActionsDrawer/index.d.ts +2 -0
  106. package/dist/components/ActionsDrawer/index.d.ts.map +1 -0
  107. package/dist/components/AgentCard/AgentCard.d.ts +1 -1
  108. package/dist/components/AgentCard/AgentCard.d.ts.map +1 -1
  109. package/dist/components/AuthCard/AuthCard.d.ts.map +1 -1
  110. package/dist/components/Button/Button.d.ts.map +1 -1
  111. package/dist/components/CodeEditor/CodeEditor.d.ts.map +1 -1
  112. package/dist/components/CodeEditor/index.d.ts +1 -1
  113. package/dist/components/CodeEditor/index.d.ts.map +1 -1
  114. package/dist/components/DataMapper/DataMapper.d.ts.map +1 -1
  115. package/dist/components/DataTable/DataTable.d.ts.map +1 -1
  116. package/dist/components/DataTable/index.d.ts +1 -1
  117. package/dist/components/DataTable/index.d.ts.map +1 -1
  118. package/dist/components/DropdownMenu/DropdownMenu.d.ts.map +1 -1
  119. package/dist/components/ExecutionConsole/ExecutionConsole.d.ts +29 -3
  120. package/dist/components/ExecutionConsole/ExecutionConsole.d.ts.map +1 -1
  121. package/dist/components/FileDropzone/FileDropzone.d.ts.map +1 -1
  122. package/dist/components/FlowEdge/FlowEdge.d.ts +15 -14
  123. package/dist/components/FlowEdge/FlowEdge.d.ts.map +1 -1
  124. package/dist/components/Input/Input.d.ts.map +1 -1
  125. package/dist/components/MonacoEditor/MonacoDiffEditor.d.ts.map +1 -1
  126. package/dist/components/MonacoEditor/MonacoEditor.d.ts.map +1 -1
  127. package/dist/components/MonacoEditor/index.d.ts +1 -1
  128. package/dist/components/MonacoEditor/index.d.ts.map +1 -1
  129. package/dist/components/PromptInput/PromptInput.d.ts.map +1 -1
  130. package/dist/components/Radio/Radio.d.ts.map +1 -1
  131. package/dist/components/Resizable/Resizable.d.ts.map +1 -1
  132. package/dist/components/Resizable/index.d.ts +1 -1
  133. package/dist/components/Resizable/index.d.ts.map +1 -1
  134. package/dist/components/Select/Select.d.ts +16 -1
  135. package/dist/components/Select/Select.d.ts.map +1 -1
  136. package/dist/components/Sortable/Sortable.d.ts.map +1 -1
  137. package/dist/components/Sortable/index.d.ts +1 -1
  138. package/dist/components/Sortable/index.d.ts.map +1 -1
  139. package/dist/components/Toast/Toast.d.ts.map +1 -1
  140. package/dist/components/ToolCard/ToolCard.d.ts +1 -1
  141. package/dist/components/ToolCard/ToolCard.d.ts.map +1 -1
  142. package/dist/components/TopBar/TopBar.d.ts +22 -1
  143. package/dist/components/TopBar/TopBar.d.ts.map +1 -1
  144. package/dist/components/TraceStep/TraceStep.d.ts.map +1 -1
  145. package/dist/components/TraceStep/index.d.ts +1 -1
  146. package/dist/components/TraceStep/index.d.ts.map +1 -1
  147. package/dist/components/WorkflowEditor/WorkflowEditor.d.ts +10 -2
  148. package/dist/components/WorkflowEditor/WorkflowEditor.d.ts.map +1 -1
  149. package/dist/components/XmlViewer/XmlViewer.d.ts.map +1 -1
  150. package/dist/components/YamlViewer/YamlViewer.d.ts.map +1 -1
  151. package/dist/index.cjs +6875 -3288
  152. package/dist/index.cjs.map +1 -1
  153. package/dist/index.d.ts +3 -3
  154. package/dist/index.d.ts.map +1 -1
  155. package/dist/index.js +3296 -2147
  156. package/dist/index.js.map +1 -1
  157. package/dist/monaco.cjs +344 -201
  158. package/dist/monaco.cjs.map +1 -1
  159. package/dist/monaco.js +348 -205
  160. package/dist/monaco.js.map +1 -1
  161. package/dist/stories/state-matrix.d.ts.map +1 -1
  162. package/dist/styles.css +1 -1
  163. package/dist/utils/a11y.d.ts.map +1 -1
  164. package/dist/utils/sanitizeUrl.d.ts.map +1 -1
  165. package/dist/workflow/components/ConfigPanel/ConfigPanel.d.ts +64 -0
  166. package/dist/workflow/components/ConfigPanel/ConfigPanel.d.ts.map +1 -0
  167. package/dist/workflow/components/FlowCanvas/FlowCanvas.d.ts +111 -0
  168. package/dist/workflow/components/FlowCanvas/FlowCanvas.d.ts.map +1 -0
  169. package/dist/workflow/components/FlowCanvas/FlowCanvasContext.d.ts +47 -0
  170. package/dist/workflow/components/FlowCanvas/FlowCanvasContext.d.ts.map +1 -0
  171. package/dist/workflow/components/FlowEdge/FlowEdge.d.ts +26 -0
  172. package/dist/workflow/components/FlowEdge/FlowEdge.d.ts.map +1 -0
  173. package/dist/workflow/components/FlowNode/FlowNode.d.ts +13 -0
  174. package/dist/workflow/components/FlowNode/FlowNode.d.ts.map +1 -0
  175. package/dist/workflow/components/FlowNode/FlowNodeContext.d.ts +9 -0
  176. package/dist/workflow/components/FlowNode/FlowNodeContext.d.ts.map +1 -0
  177. package/dist/workflow/components/FlowNode/nodeKinds.d.ts +25 -0
  178. package/dist/workflow/components/FlowNode/nodeKinds.d.ts.map +1 -0
  179. package/dist/workflow/components/Handle/Handle.d.ts +26 -0
  180. package/dist/workflow/components/Handle/Handle.d.ts.map +1 -0
  181. package/dist/workflow/components/Handle/handleRegistry.d.ts +32 -0
  182. package/dist/workflow/components/Handle/handleRegistry.d.ts.map +1 -0
  183. package/dist/workflow/components/NodeResizer/NodeResizer.d.ts +27 -0
  184. package/dist/workflow/components/NodeResizer/NodeResizer.d.ts.map +1 -0
  185. package/dist/workflow/components/NodeToolbar/NodeToolbar.d.ts +19 -0
  186. package/dist/workflow/components/NodeToolbar/NodeToolbar.d.ts.map +1 -0
  187. package/dist/workflow/components/kinds/BaseNode.d.ts +40 -0
  188. package/dist/workflow/components/kinds/BaseNode.d.ts.map +1 -0
  189. package/dist/workflow/components/kinds/index.d.ts +55 -0
  190. package/dist/workflow/components/kinds/index.d.ts.map +1 -0
  191. package/dist/workflow/editor.d.ts +181 -0
  192. package/dist/workflow/editor.d.ts.map +1 -0
  193. package/dist/workflow/hooks/useAutoLayout.d.ts +35 -0
  194. package/dist/workflow/hooks/useAutoLayout.d.ts.map +1 -0
  195. package/dist/workflow/hooks/useFlow.d.ts +61 -0
  196. package/dist/workflow/hooks/useFlow.d.ts.map +1 -0
  197. package/dist/workflow/hooks/useFlowState.d.ts +33 -0
  198. package/dist/workflow/hooks/useFlowState.d.ts.map +1 -0
  199. package/dist/workflow/index.d.ts +25 -0
  200. package/dist/workflow/index.d.ts.map +1 -0
  201. package/dist/workflow/layout/dagre.d.ts +24 -0
  202. package/dist/workflow/layout/dagre.d.ts.map +1 -0
  203. package/dist/workflow/layout/elk.d.ts +22 -0
  204. package/dist/workflow/layout/elk.d.ts.map +1 -0
  205. package/dist/workflow/layout/types.d.ts +55 -0
  206. package/dist/workflow/layout/types.d.ts.map +1 -0
  207. package/dist/workflow/store/changes.d.ts +34 -0
  208. package/dist/workflow/store/changes.d.ts.map +1 -0
  209. package/dist/workflow/store/context.d.ts +4 -0
  210. package/dist/workflow/store/context.d.ts.map +1 -0
  211. package/dist/workflow/store/createFlowStore.d.ts +27 -0
  212. package/dist/workflow/store/createFlowStore.d.ts.map +1 -0
  213. package/dist/workflow/store/selectors.d.ts +33 -0
  214. package/dist/workflow/store/selectors.d.ts.map +1 -0
  215. package/dist/workflow/types/index.d.ts +181 -0
  216. package/dist/workflow/types/index.d.ts.map +1 -0
  217. package/dist/workflow/utils/collapse.d.ts +26 -0
  218. package/dist/workflow/utils/collapse.d.ts.map +1 -0
  219. package/dist/workflow/utils/collision.d.ts +37 -0
  220. package/dist/workflow/utils/collision.d.ts.map +1 -0
  221. package/dist/workflow/utils/geometry.d.ts +46 -0
  222. package/dist/workflow/utils/geometry.d.ts.map +1 -0
  223. package/dist/workflow/utils/parenting.d.ts +28 -0
  224. package/dist/workflow/utils/parenting.d.ts.map +1 -0
  225. package/dist/workflow/utils/paths.d.ts +19 -0
  226. package/dist/workflow/utils/paths.d.ts.map +1 -0
  227. package/dist/workflow.cjs +3562 -0
  228. package/dist/workflow.cjs.map +1 -0
  229. package/dist/workflow.js +1029 -0
  230. package/dist/workflow.js.map +1 -0
  231. package/package.json +6 -1
@@ -0,0 +1,2451 @@
1
+ import {
2
+ cn
3
+ } from "./chunk-ZAUUGK2Y.js";
4
+
5
+ // src/workflow/hooks/useFlow.ts
6
+ import { createContext, useContext } from "react";
7
+ var FlowInstanceContext = createContext(null);
8
+ function useFlow() {
9
+ const instance = useContext(FlowInstanceContext);
10
+ if (!instance) {
11
+ throw new Error("[@octaviaflow/core/workflow] useFlow() must be called inside <FlowCanvas>.");
12
+ }
13
+ return instance;
14
+ }
15
+
16
+ // src/workflow/store/changes.ts
17
+ function applyNodeChanges(nodes, changes) {
18
+ if (changes.length === 0) return nodes;
19
+ const byId = /* @__PURE__ */ new Map();
20
+ const adds = [];
21
+ const removes = /* @__PURE__ */ new Set();
22
+ let touched = false;
23
+ for (const change2 of changes) {
24
+ switch (change2.type) {
25
+ case "add":
26
+ adds.push(change2.item);
27
+ touched = true;
28
+ break;
29
+ case "remove":
30
+ removes.add(change2.id);
31
+ touched = true;
32
+ break;
33
+ default: {
34
+ const id = change2.id;
35
+ const arr = byId.get(id);
36
+ if (arr) arr.push(change2);
37
+ else byId.set(id, [change2]);
38
+ touched = true;
39
+ break;
40
+ }
41
+ }
42
+ }
43
+ if (!touched) return nodes;
44
+ const next = [];
45
+ for (const node of nodes) {
46
+ if (removes.has(node.id)) continue;
47
+ const patches = byId.get(node.id);
48
+ if (!patches) {
49
+ next.push(node);
50
+ continue;
51
+ }
52
+ let n = node;
53
+ for (const patch of patches) {
54
+ switch (patch.type) {
55
+ case "position":
56
+ n = {
57
+ ...n,
58
+ position: patch.position,
59
+ dragging: patch.dragging
60
+ };
61
+ break;
62
+ case "dimensions":
63
+ n = {
64
+ ...n,
65
+ width: patch.dimensions.width,
66
+ height: patch.dimensions.height
67
+ };
68
+ break;
69
+ case "select":
70
+ if (n.selected === patch.selected) break;
71
+ n = { ...n, selected: patch.selected };
72
+ break;
73
+ case "replace":
74
+ n = patch.item;
75
+ break;
76
+ }
77
+ }
78
+ next.push(n);
79
+ }
80
+ for (const add of adds) next.push(add);
81
+ return next;
82
+ }
83
+ function applyEdgeChanges(edges, changes) {
84
+ if (changes.length === 0) return edges;
85
+ const byId = /* @__PURE__ */ new Map();
86
+ const adds = [];
87
+ const removes = /* @__PURE__ */ new Set();
88
+ let touched = false;
89
+ for (const change2 of changes) {
90
+ switch (change2.type) {
91
+ case "add":
92
+ adds.push(change2.item);
93
+ touched = true;
94
+ break;
95
+ case "remove":
96
+ removes.add(change2.id);
97
+ touched = true;
98
+ break;
99
+ default: {
100
+ const arr = byId.get(change2.id);
101
+ if (arr) arr.push(change2);
102
+ else byId.set(change2.id, [change2]);
103
+ touched = true;
104
+ break;
105
+ }
106
+ }
107
+ }
108
+ if (!touched) return edges;
109
+ const next = [];
110
+ for (const edge of edges) {
111
+ if (removes.has(edge.id)) continue;
112
+ const patches = byId.get(edge.id);
113
+ if (!patches) {
114
+ next.push(edge);
115
+ continue;
116
+ }
117
+ let e = edge;
118
+ for (const patch of patches) {
119
+ switch (patch.type) {
120
+ case "select":
121
+ if (e.selected === patch.selected) break;
122
+ e = { ...e, selected: patch.selected };
123
+ break;
124
+ case "replace":
125
+ e = patch.item;
126
+ break;
127
+ }
128
+ }
129
+ next.push(e);
130
+ }
131
+ for (const add of adds) next.push(add);
132
+ return next;
133
+ }
134
+ var change = {
135
+ node: {
136
+ add(item) {
137
+ return { type: "add", item };
138
+ },
139
+ remove(id) {
140
+ return { type: "remove", id };
141
+ },
142
+ position(id, position, dragging) {
143
+ return { type: "position", id, position, dragging };
144
+ },
145
+ dimensions(id, dimensions) {
146
+ return { type: "dimensions", id, dimensions };
147
+ },
148
+ select(id, selected) {
149
+ return { type: "select", id, selected };
150
+ },
151
+ replace(id, item) {
152
+ return { type: "replace", id, item };
153
+ }
154
+ },
155
+ edge: {
156
+ add(item) {
157
+ return { type: "add", item };
158
+ },
159
+ remove(id) {
160
+ return { type: "remove", id };
161
+ },
162
+ select(id, selected) {
163
+ return { type: "select", id, selected };
164
+ },
165
+ replace(id, item) {
166
+ return { type: "replace", id, item };
167
+ }
168
+ }
169
+ };
170
+
171
+ // src/workflow/utils/geometry.ts
172
+ var DEFAULT_NODE_WIDTH = 240;
173
+ var DEFAULT_NODE_HEIGHT = 96;
174
+ var COLLAPSED_GROUP_HEIGHT = 36;
175
+ var COLLAPSED_FOREACH_HEIGHT = 40;
176
+ function effectiveHeight(node) {
177
+ const data = node.data;
178
+ if (data?.collapsed) {
179
+ if (node.type === "group") return COLLAPSED_GROUP_HEIGHT;
180
+ if (node.type === "forEach") return COLLAPSED_FOREACH_HEIGHT;
181
+ }
182
+ return node.height ?? DEFAULT_NODE_HEIGHT;
183
+ }
184
+ function handleCentre(node, side, index, total) {
185
+ const w = node.width ?? DEFAULT_NODE_WIDTH;
186
+ const h = effectiveHeight(node);
187
+ const x0 = node.position.x;
188
+ const y0 = node.position.y;
189
+ const denom = total + 1;
190
+ const ratio = (index + 1) / denom;
191
+ switch (side) {
192
+ case "top":
193
+ return { x: x0 + w * ratio, y: y0 };
194
+ case "bottom":
195
+ return { x: x0 + w * ratio, y: y0 + h };
196
+ case "left":
197
+ return { x: x0, y: y0 + h * ratio };
198
+ case "right":
199
+ return { x: x0 + w, y: y0 + h * ratio };
200
+ }
201
+ }
202
+ function bezierPath(start, startSide, end, endSide) {
203
+ const distance2 = Math.hypot(end.x - start.x, end.y - start.y);
204
+ const magnitude = Math.max(40, Math.min(160, distance2 * 0.45));
205
+ const c1 = offsetBySide(start, startSide, magnitude);
206
+ const c2 = offsetBySide(end, endSide, magnitude);
207
+ const d = `M ${start.x},${start.y} C ${c1.x},${c1.y} ${c2.x},${c2.y} ${end.x},${end.y}`;
208
+ const midX = 0.125 * start.x + 0.375 * c1.x + 0.375 * c2.x + 0.125 * end.x;
209
+ const midY = 0.125 * start.y + 0.375 * c1.y + 0.375 * c2.y + 0.125 * end.y;
210
+ return { d, midX, midY };
211
+ }
212
+ function offsetBySide(p, side, m) {
213
+ switch (side) {
214
+ case "top":
215
+ return { x: p.x, y: p.y - m };
216
+ case "bottom":
217
+ return { x: p.x, y: p.y + m };
218
+ case "left":
219
+ return { x: p.x - m, y: p.y };
220
+ case "right":
221
+ return { x: p.x + m, y: p.y };
222
+ }
223
+ }
224
+ function screenToFlow(p, vp) {
225
+ return {
226
+ x: (p.x - vp.x) / vp.zoom,
227
+ y: (p.y - vp.y) / vp.zoom
228
+ };
229
+ }
230
+ function flowToScreen(p, vp) {
231
+ return {
232
+ x: p.x * vp.zoom + vp.x,
233
+ y: p.y * vp.zoom + vp.y
234
+ };
235
+ }
236
+
237
+ // src/workflow/utils/parenting.ts
238
+ function descendantsOf(nodeId, nodes) {
239
+ const childrenByParent = /* @__PURE__ */ new Map();
240
+ for (const n of nodes) {
241
+ if (!n.parentId) continue;
242
+ const arr = childrenByParent.get(n.parentId);
243
+ if (arr) arr.push(n);
244
+ else childrenByParent.set(n.parentId, [n]);
245
+ }
246
+ const out = [];
247
+ const stack = [nodeId];
248
+ const visited = /* @__PURE__ */ new Set([nodeId]);
249
+ while (stack.length) {
250
+ const cur = stack.pop();
251
+ if (cur === void 0) break;
252
+ const list = childrenByParent.get(cur);
253
+ if (!list) continue;
254
+ for (const c of list) {
255
+ if (visited.has(c.id)) continue;
256
+ visited.add(c.id);
257
+ out.push(c);
258
+ stack.push(c.id);
259
+ }
260
+ }
261
+ return out;
262
+ }
263
+ function findAncestor(node, nodes, predicate) {
264
+ let cursor = node;
265
+ const seen = /* @__PURE__ */ new Set();
266
+ while (cursor?.parentId) {
267
+ if (seen.has(cursor.parentId)) return void 0;
268
+ seen.add(cursor.parentId);
269
+ const parent = nodes.find((n) => n.id === cursor.parentId);
270
+ if (!parent) return void 0;
271
+ if (predicate(parent)) return parent;
272
+ cursor = parent;
273
+ }
274
+ return void 0;
275
+ }
276
+ function clampToParentExtent(node, proposed, nodes) {
277
+ if (node.extent !== "parent" || !node.parentId) return proposed;
278
+ const parent = nodes.find((n) => n.id === node.parentId);
279
+ if (!parent) return proposed;
280
+ const pw = parent.width ?? DEFAULT_NODE_WIDTH;
281
+ const ph = effectiveHeight(parent);
282
+ const w = node.width ?? DEFAULT_NODE_WIDTH;
283
+ const h = effectiveHeight(node);
284
+ const minX = parent.position.x;
285
+ const minY = parent.position.y;
286
+ const maxX = parent.position.x + pw - w;
287
+ const maxY = parent.position.y + ph - h;
288
+ return {
289
+ x: Math.max(minX, Math.min(maxX, proposed.x)),
290
+ y: Math.max(minY, Math.min(maxY, proposed.y))
291
+ };
292
+ }
293
+ function findContainingGroup(point, nodes, exclude = []) {
294
+ for (let i = nodes.length - 1; i >= 0; i--) {
295
+ const n = nodes[i];
296
+ if (exclude.includes(n.id)) continue;
297
+ if (n.type !== "group") continue;
298
+ if (n.data && typeof n.data === "object" && n.data.collapsed) {
299
+ continue;
300
+ }
301
+ const w = n.width ?? DEFAULT_NODE_WIDTH;
302
+ const h = effectiveHeight(n);
303
+ if (point.x >= n.position.x && point.y >= n.position.y && point.x <= n.position.x + w && point.y <= n.position.y + h) {
304
+ return n;
305
+ }
306
+ }
307
+ return void 0;
308
+ }
309
+
310
+ // src/workflow/utils/paths.ts
311
+ function buildEdgePath(routing, start, startSide, end, endSide, options = {}) {
312
+ switch (routing) {
313
+ case "step":
314
+ return stepPath(start, startSide, end, endSide);
315
+ case "smoothstep":
316
+ return smoothStepPath(start, startSide, end, endSide, options.borderRadius ?? 8);
317
+ case "straight":
318
+ return straightPath(start, end);
319
+ default:
320
+ return bezierPath2(start, startSide, end, endSide, options.curvature ?? 0.25);
321
+ }
322
+ }
323
+ function bezierPath2(start, startSide, end, endSide, curvature = 0.25) {
324
+ const sourceOffset = calcControlOffset(start, startSide, end, curvature);
325
+ const targetOffset = calcControlOffset(end, endSide, start, curvature);
326
+ const c1 = offsetAlongSide(start, startSide, sourceOffset);
327
+ const c2 = offsetAlongSide(end, endSide, targetOffset);
328
+ const d = `M ${start.x},${start.y} C ${c1.x},${c1.y} ${c2.x},${c2.y} ${end.x},${end.y}`;
329
+ const midX = 0.125 * start.x + 0.375 * c1.x + 0.375 * c2.x + 0.125 * end.x;
330
+ const midY = 0.125 * start.y + 0.375 * c1.y + 0.375 * c2.y + 0.125 * end.y;
331
+ const tx = 3 * ((1 - 0.5) ** 2 * (c1.x - start.x) + 2 * (1 - 0.5) * 0.5 * (c2.x - c1.x) + 0.5 ** 2 * (end.x - c2.x));
332
+ const ty = 3 * ((1 - 0.5) ** 2 * (c1.y - start.y) + 2 * (1 - 0.5) * 0.5 * (c2.y - c1.y) + 0.5 ** 2 * (end.y - c2.y));
333
+ const midAngle = Math.atan2(ty, tx);
334
+ return { d, midX, midY, midAngle };
335
+ }
336
+ function axisDistance(from, side, to) {
337
+ switch (side) {
338
+ case "top":
339
+ return from.y - to.y;
340
+ case "bottom":
341
+ return to.y - from.y;
342
+ case "left":
343
+ return from.x - to.x;
344
+ case "right":
345
+ return to.x - from.x;
346
+ }
347
+ }
348
+ function calcControlOffset(from, side, to, curvature) {
349
+ const distance2 = axisDistance(from, side, to);
350
+ if (distance2 >= 0) {
351
+ return distance2 * 0.5 * (1 + curvature);
352
+ }
353
+ return curvature * 25 * Math.sqrt(-distance2);
354
+ }
355
+ function offsetAlongSide(p, side, magnitude) {
356
+ switch (side) {
357
+ case "top":
358
+ return { x: p.x, y: p.y - magnitude };
359
+ case "bottom":
360
+ return { x: p.x, y: p.y + magnitude };
361
+ case "left":
362
+ return { x: p.x - magnitude, y: p.y };
363
+ case "right":
364
+ return { x: p.x + magnitude, y: p.y };
365
+ }
366
+ }
367
+ function stepPath(start, startSide, end, endSide) {
368
+ const corners = computeStepCorners(start, startSide, end, endSide);
369
+ const pts = [start, ...corners, end];
370
+ const d = pts.map((p, i) => `${i === 0 ? "M" : "L"} ${p.x},${p.y}`).join(" ");
371
+ const { midX, midY, midAngle } = midpointOnPolyline(pts);
372
+ return { d, midX, midY, midAngle };
373
+ }
374
+ function smoothStepPath(start, startSide, end, endSide, borderRadius = 8) {
375
+ const corners = computeStepCorners(start, startSide, end, endSide);
376
+ const pts = [start, ...corners, end];
377
+ if (corners.length === 0) {
378
+ return straightPath(start, end);
379
+ }
380
+ const segments = [`M ${pts[0].x},${pts[0].y}`];
381
+ for (let i = 1; i < pts.length - 1; i++) {
382
+ const prev = pts[i - 1];
383
+ const here = pts[i];
384
+ const next = pts[i + 1];
385
+ const r = Math.min(borderRadius, distance(prev, here) / 2, distance(here, next) / 2);
386
+ const enter = pointTowards(here, prev, r);
387
+ const exit = pointTowards(here, next, r);
388
+ segments.push(`L ${enter.x},${enter.y}`);
389
+ segments.push(`Q ${here.x},${here.y} ${exit.x},${exit.y}`);
390
+ }
391
+ const last = pts[pts.length - 1];
392
+ segments.push(`L ${last.x},${last.y}`);
393
+ const d = segments.join(" ");
394
+ const { midX, midY, midAngle } = midpointOnPolyline(pts);
395
+ return { d, midX, midY, midAngle };
396
+ }
397
+ function straightPath(start, end) {
398
+ const d = `M ${start.x},${start.y} L ${end.x},${end.y}`;
399
+ return {
400
+ d,
401
+ midX: (start.x + end.x) / 2,
402
+ midY: (start.y + end.y) / 2,
403
+ midAngle: Math.atan2(end.y - start.y, end.x - start.x)
404
+ };
405
+ }
406
+ function computeStepCorners(start, startSide, end, endSide) {
407
+ const sourceVertical = startSide === "top" || startSide === "bottom";
408
+ const targetVertical = endSide === "top" || endSide === "bottom";
409
+ if (sourceVertical && targetVertical) {
410
+ const midY = (start.y + end.y) / 2;
411
+ return [
412
+ { x: start.x, y: midY },
413
+ { x: end.x, y: midY }
414
+ ];
415
+ }
416
+ if (!sourceVertical && !targetVertical) {
417
+ const midX = (start.x + end.x) / 2;
418
+ return [
419
+ { x: midX, y: start.y },
420
+ { x: midX, y: end.y }
421
+ ];
422
+ }
423
+ if (sourceVertical) {
424
+ return [{ x: end.x, y: start.y }];
425
+ }
426
+ return [{ x: start.x, y: end.y }];
427
+ }
428
+ function midpointOnPolyline(pts) {
429
+ if (pts.length === 2) {
430
+ return {
431
+ midX: (pts[0].x + pts[1].x) / 2,
432
+ midY: (pts[0].y + pts[1].y) / 2,
433
+ midAngle: Math.atan2(pts[1].y - pts[0].y, pts[1].x - pts[0].x)
434
+ };
435
+ }
436
+ let totalLen = 0;
437
+ const lens = [];
438
+ for (let i = 0; i < pts.length - 1; i++) {
439
+ const l = distance(pts[i], pts[i + 1]);
440
+ lens.push(l);
441
+ totalLen += l;
442
+ }
443
+ const half = totalLen / 2;
444
+ let acc = 0;
445
+ for (let i = 0; i < lens.length; i++) {
446
+ if (acc + lens[i] >= half) {
447
+ const seg = lens[i];
448
+ const remaining = half - acc;
449
+ const t = seg === 0 ? 0 : remaining / seg;
450
+ const a = pts[i];
451
+ const b = pts[i + 1];
452
+ return {
453
+ midX: a.x + (b.x - a.x) * t,
454
+ midY: a.y + (b.y - a.y) * t,
455
+ midAngle: Math.atan2(b.y - a.y, b.x - a.x)
456
+ };
457
+ }
458
+ acc += lens[i];
459
+ }
460
+ return { midX: pts[0].x, midY: pts[0].y, midAngle: 0 };
461
+ }
462
+ function distance(a, b) {
463
+ return Math.hypot(b.x - a.x, b.y - a.y);
464
+ }
465
+ function pointTowards(from, to, dist) {
466
+ const d = distance(from, to);
467
+ if (d === 0) return from;
468
+ const t = dist / d;
469
+ return { x: from.x + (to.x - from.x) * t, y: from.y + (to.y - from.y) * t };
470
+ }
471
+
472
+ // src/workflow/components/FlowEdge/FlowEdge.tsx
473
+ import {
474
+ memo,
475
+ useEffect,
476
+ useId,
477
+ useRef,
478
+ useState
479
+ } from "react";
480
+
481
+ // src/workflow/components/Handle/handleRegistry.ts
482
+ import { createContext as createContext2, useContext as useContext2 } from "react";
483
+ var HandleRegistryContext = createContext2(null);
484
+ function useHandleRegistry() {
485
+ const r = useContext2(HandleRegistryContext);
486
+ if (!r) {
487
+ throw new Error("[@octaviaflow/core/workflow] Handle must be used inside <FlowCanvas>.");
488
+ }
489
+ return r;
490
+ }
491
+ function createHandleRegistry() {
492
+ const map = /* @__PURE__ */ new Map();
493
+ const key = (n, t, h) => `${n}::${t}::${h}`;
494
+ const listeners = /* @__PURE__ */ new Set();
495
+ const notify = () => {
496
+ for (const l of listeners) l();
497
+ };
498
+ return {
499
+ register(d) {
500
+ map.set(key(d.nodeId, d.type, d.handleId), d);
501
+ notify();
502
+ return () => {
503
+ const k = key(d.nodeId, d.type, d.handleId);
504
+ if (map.get(k) === d) {
505
+ map.delete(k);
506
+ notify();
507
+ }
508
+ };
509
+ },
510
+ resolve(nodeId, type, handleId) {
511
+ return map.get(key(nodeId, type, handleId));
512
+ },
513
+ subscribe(listener) {
514
+ listeners.add(listener);
515
+ return () => {
516
+ listeners.delete(listener);
517
+ };
518
+ }
519
+ };
520
+ }
521
+
522
+ // src/workflow/components/FlowEdge/FlowEdge.tsx
523
+ import { jsx, jsxs } from "react/jsx-runtime";
524
+ function FlowEdgeImpl({
525
+ edge,
526
+ nodes,
527
+ onSelect,
528
+ onDelete,
529
+ onLabelChange,
530
+ showDelete = true,
531
+ curvature = 0.25,
532
+ borderRadius = 8
533
+ }) {
534
+ const uid = useId();
535
+ const markerId = `ods-flow-edge-arrow-${uid.replace(/:/g, "")}`;
536
+ const registry = useHandleRegistry();
537
+ const [hovered, setHovered] = useState(false);
538
+ const [editing, setEditing] = useState(false);
539
+ const [draftLabel, setDraftLabel] = useState(edge.label ?? "");
540
+ const inputRef = useRef(null);
541
+ useEffect(() => {
542
+ if (!editing) setDraftLabel(edge.label ?? "");
543
+ }, [edge.label, editing]);
544
+ const sourceNode = nodes.find((n) => n.id === edge.source);
545
+ const targetNode = nodes.find((n) => n.id === edge.target);
546
+ if (!sourceNode || !targetNode) return null;
547
+ const sourceHandleId = edge.sourceHandle ?? "default";
548
+ const targetHandleId = edge.targetHandle ?? "default";
549
+ const sourceDesc = registry.resolve(sourceNode.id, "source", sourceHandleId);
550
+ const targetDesc = registry.resolve(targetNode.id, "target", targetHandleId);
551
+ const sourceSide = sourceDesc?.side ?? sourceNode.sourcePosition ?? "bottom";
552
+ const targetSide = targetDesc?.side ?? targetNode.targetPosition ?? "top";
553
+ const sourceIndex = sourceDesc?.index ?? 0;
554
+ const sourceTotal = sourceDesc?.total ?? 1;
555
+ const targetIndex = targetDesc?.index ?? 0;
556
+ const targetTotal = targetDesc?.total ?? 1;
557
+ const start = handleCentre(sourceNode, sourceSide, sourceIndex, sourceTotal);
558
+ const end = handleCentre(targetNode, targetSide, targetIndex, targetTotal);
559
+ const routing = edge.routing ?? "bezier";
560
+ const { d, midX, midY } = buildEdgePath(routing, start, sourceSide, end, targetSide, {
561
+ curvature,
562
+ borderRadius
563
+ });
564
+ const type = edge.type ?? "default";
565
+ const isHot = hovered || edge.selected;
566
+ const stroke = type === "error" ? "var(--ods-status-failed, #dc2626)" : isHot ? "var(--ods-accent, #4f46e5)" : "var(--ods-border-strong, #6b7280)";
567
+ const typeDash = type === "conditional" ? "6 4" : type === "loop" ? "4 4" : void 0;
568
+ const dash = edge.style?.strokeDasharray ?? typeDash;
569
+ const strokeWidth = edge.style?.strokeWidth ?? (isHot ? 2 : 1.4);
570
+ const animateDash = edge.animated === true;
571
+ const label = edge.label;
572
+ const hasDelete = showDelete && (isHot || edge.selected) && !!onDelete;
573
+ const showChrome = !!label || editing || hasDelete;
574
+ const commitLabel = (next) => {
575
+ setEditing(false);
576
+ if (next !== edge.label) onLabelChange?.(edge.id, next);
577
+ };
578
+ const onLabelKey = (e) => {
579
+ if (e.key === "Enter") {
580
+ e.preventDefault();
581
+ commitLabel(draftLabel);
582
+ } else if (e.key === "Escape") {
583
+ e.preventDefault();
584
+ setEditing(false);
585
+ setDraftLabel(edge.label ?? "");
586
+ }
587
+ };
588
+ return /* @__PURE__ */ jsxs(
589
+ "g",
590
+ {
591
+ className: cn(
592
+ "ods-flow-edge-v2",
593
+ `ods-flow-edge-v2--${type}`,
594
+ `ods-flow-edge-v2--routing-${routing}`,
595
+ edge.selected && "ods-flow-edge-v2--selected",
596
+ hovered && "ods-flow-edge-v2--hovered",
597
+ edge.className
598
+ ),
599
+ "data-edge-id": edge.id,
600
+ "data-edge-routing": routing,
601
+ onMouseEnter: () => setHovered(true),
602
+ onMouseLeave: () => setHovered(false),
603
+ onClick: (e) => {
604
+ e.stopPropagation();
605
+ onSelect?.(edge.id);
606
+ },
607
+ children: [
608
+ /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx(
609
+ "marker",
610
+ {
611
+ id: markerId,
612
+ viewBox: "0 0 10 10",
613
+ refX: "9",
614
+ refY: "5",
615
+ markerWidth: "7",
616
+ markerHeight: "7",
617
+ orient: "auto-start-reverse",
618
+ children: /* @__PURE__ */ jsx("path", { d: "M0 0L10 5L0 10z", fill: stroke })
619
+ }
620
+ ) }),
621
+ /* @__PURE__ */ jsx("path", { d, stroke: "transparent", strokeWidth: 20, fill: "none" }),
622
+ /* @__PURE__ */ jsx(
623
+ "path",
624
+ {
625
+ d,
626
+ stroke,
627
+ strokeWidth,
628
+ strokeDasharray: dash,
629
+ fill: "none",
630
+ markerEnd: `url(#${markerId})`,
631
+ style: animateDash ? {
632
+ strokeDasharray: dash ?? "6 4",
633
+ animation: "ods-flow-edge-flow 0.6s linear infinite"
634
+ } : void 0
635
+ }
636
+ ),
637
+ showChrome && /* @__PURE__ */ jsx(
638
+ "foreignObject",
639
+ {
640
+ x: midX - 140,
641
+ y: midY - 16,
642
+ width: 280,
643
+ height: 32,
644
+ style: { overflow: "visible", pointerEvents: "none" },
645
+ children: /* @__PURE__ */ jsxs("div", { className: "ods-flow-edge-v2__chrome", children: [
646
+ (label || editing) && (editing ? /* @__PURE__ */ jsx(
647
+ "input",
648
+ {
649
+ ref: inputRef,
650
+ className: "ods-flow-edge-v2__label-input",
651
+ value: draftLabel,
652
+ autoFocus: true,
653
+ onChange: (e) => setDraftLabel(e.target.value),
654
+ onBlur: () => commitLabel(draftLabel),
655
+ onKeyDown: onLabelKey,
656
+ onClick: (e) => e.stopPropagation(),
657
+ onMouseDown: (e) => e.stopPropagation(),
658
+ "aria-label": "Edit edge label"
659
+ }
660
+ ) : /* @__PURE__ */ jsx(
661
+ "button",
662
+ {
663
+ type: "button",
664
+ className: "ods-flow-edge-v2__label-chip",
665
+ onDoubleClick: (e) => {
666
+ if (!onLabelChange) return;
667
+ e.stopPropagation();
668
+ setDraftLabel(edge.label ?? "");
669
+ setEditing(true);
670
+ },
671
+ onClick: (e) => {
672
+ e.stopPropagation();
673
+ onSelect?.(edge.id);
674
+ },
675
+ title: onLabelChange ? "Double-click to edit" : void 0,
676
+ tabIndex: onLabelChange ? 0 : -1,
677
+ children: /* @__PURE__ */ jsx("span", { children: label })
678
+ }
679
+ )),
680
+ hasDelete && /* @__PURE__ */ jsx(
681
+ "button",
682
+ {
683
+ type: "button",
684
+ className: "ods-flow-edge-v2__delete-btn",
685
+ onClick: (e) => {
686
+ e.stopPropagation();
687
+ onDelete?.(edge.id);
688
+ },
689
+ "aria-label": "Delete edge",
690
+ children: /* @__PURE__ */ jsx("svg", { width: "10", height: "10", viewBox: "0 0 10 10", "aria-hidden": "true", children: /* @__PURE__ */ jsx(
691
+ "path",
692
+ {
693
+ d: "M2 2l6 6M8 2l-6 6",
694
+ stroke: "currentColor",
695
+ strokeWidth: 1.5,
696
+ strokeLinecap: "round"
697
+ }
698
+ ) })
699
+ }
700
+ )
701
+ ] })
702
+ }
703
+ )
704
+ ]
705
+ }
706
+ );
707
+ }
708
+ var FlowEdge = memo(FlowEdgeImpl, (prev, next) => {
709
+ if (prev.edge !== next.edge) return false;
710
+ if (prev.onSelect !== next.onSelect || prev.onDelete !== next.onDelete) return false;
711
+ if (prev.onLabelChange !== next.onLabelChange) return false;
712
+ if (prev.showDelete !== next.showDelete) return false;
713
+ if (prev.curvature !== next.curvature || prev.borderRadius !== next.borderRadius) return false;
714
+ if (prev.handleVersion !== next.handleVersion) return false;
715
+ const ps = prev.nodes.find((n) => n.id === prev.edge.source);
716
+ const pt = prev.nodes.find((n) => n.id === prev.edge.target);
717
+ const ns = next.nodes.find((n) => n.id === next.edge.source);
718
+ const nt = next.nodes.find((n) => n.id === next.edge.target);
719
+ if (ps !== ns || pt !== nt) return false;
720
+ return true;
721
+ });
722
+
723
+ // src/workflow/components/FlowNode/FlowNodeContext.tsx
724
+ import { createContext as createContext3, useContext as useContext3 } from "react";
725
+ var FlowNodeContext = createContext3(null);
726
+ function useFlowNodeContext() {
727
+ const v = useContext3(FlowNodeContext);
728
+ if (!v) {
729
+ throw new Error(
730
+ "[@octaviaflow/core/workflow] Handle / NodeToolbar must be inside a node renderer."
731
+ );
732
+ }
733
+ return v;
734
+ }
735
+
736
+ // src/workflow/components/FlowNode/FlowNode.tsx
737
+ import { useEffect as useEffect2, useMemo, useRef as useRef2 } from "react";
738
+
739
+ // src/workflow/components/FlowCanvas/FlowCanvasContext.tsx
740
+ import { createContext as createContext4, useContext as useContext4 } from "react";
741
+ var FlowDispatchContext = createContext4(null);
742
+ function useFlowDispatch() {
743
+ const dispatch = useContext4(FlowDispatchContext);
744
+ if (!dispatch) {
745
+ throw new Error(
746
+ "[@octaviaflow/core/workflow] useFlowDispatch must be called inside <FlowCanvas>."
747
+ );
748
+ }
749
+ return dispatch;
750
+ }
751
+ var FlowNodeBridgeContext = createContext4(null);
752
+ function useFlowNodeBridge() {
753
+ const b = useContext4(FlowNodeBridgeContext);
754
+ if (!b) {
755
+ throw new Error("[@octaviaflow/core/workflow] FlowNode must be a child of <FlowCanvas>.");
756
+ }
757
+ return b;
758
+ }
759
+
760
+ // src/workflow/components/FlowNode/FlowNode.tsx
761
+ import { jsx as jsx2 } from "react/jsx-runtime";
762
+ function FlowNode({
763
+ node,
764
+ selected,
765
+ dragging,
766
+ isConnecting,
767
+ Kind,
768
+ // Match the BaseNode body's fixed 368 px width so the wrapper bbox and
769
+ // the rendered card line up on the first paint — before the
770
+ // ResizeObserver has had a chance to write back the measured size.
771
+ // Container kinds (group / forEach) opt out by setting `node.width`.
772
+ defaultWidth = 368
773
+ }) {
774
+ const bridge = useFlowNodeBridge();
775
+ const wrapperRef = useRef2(null);
776
+ useEffect2(() => {
777
+ const el = wrapperRef.current;
778
+ if (!el || typeof ResizeObserver === "undefined") return;
779
+ if (node.type === "group" || node.type === "forEach") return;
780
+ const ro = new ResizeObserver(() => {
781
+ bridge.reportDimensions(node.id, el.offsetWidth, el.offsetHeight);
782
+ });
783
+ ro.observe(el);
784
+ return () => ro.disconnect();
785
+ }, [bridge, node.id, node.type]);
786
+ const ctx = useMemo(
787
+ () => ({ id: node.id, node, selected }),
788
+ [node, selected]
789
+ );
790
+ const handlePointerDown = (e) => {
791
+ if (e.target.closest("[data-handle-id]")) return;
792
+ if (e.target.closest("[data-flow-no-drag='true']")) return;
793
+ e.stopPropagation();
794
+ bridge.beginNodeDrag(node.id, e.pointerId, e.clientX, e.clientY, e.altKey);
795
+ };
796
+ const handleClick = (e) => {
797
+ if (e.target.closest("[data-handle-id]")) return;
798
+ e.stopPropagation();
799
+ bridge.selectNode(node.id, e.metaKey || e.ctrlKey || e.shiftKey);
800
+ };
801
+ return /* @__PURE__ */ jsx2(
802
+ "div",
803
+ {
804
+ ref: wrapperRef,
805
+ "data-node-id": node.id,
806
+ "data-node-type": node.type,
807
+ "data-node-selected": selected ? "true" : "false",
808
+ className: cn(
809
+ "ods-flow-node-v2",
810
+ `ods-flow-node-v2--kind-${node.type}`,
811
+ selected && "ods-flow-node-v2--selected",
812
+ dragging && "ods-flow-node-v2--dragging",
813
+ isConnecting && "ods-flow-node-v2--connecting",
814
+ node.className
815
+ ),
816
+ style: {
817
+ position: "absolute",
818
+ left: node.position.x,
819
+ top: node.position.y,
820
+ width: node.width ?? defaultWidth,
821
+ // Z-stack (per architecture doc): groups (20) sit below normal
822
+ // nodes (30) so children render visually on top of their parent
823
+ // frame. Selection raises by 10. Consumer override wins.
824
+ zIndex: node.zIndex ?? (selected ? node.type === "group" ? 35 : 40 : node.type === "group" ? 20 : 30),
825
+ ...node.style
826
+ },
827
+ onPointerDown: handlePointerDown,
828
+ onClick: handleClick,
829
+ children: /* @__PURE__ */ jsx2(FlowNodeContext.Provider, { value: ctx, children: /* @__PURE__ */ jsx2(Kind, { node, selected, dragging, isConnecting }) })
830
+ }
831
+ );
832
+ }
833
+
834
+ // src/workflow/components/FlowNode/nodeKinds.ts
835
+ function buildNodeKindRegistry(defaults, overrides) {
836
+ return Object.freeze({ ...defaults, ...overrides ?? {} });
837
+ }
838
+
839
+ // src/workflow/components/Handle/Handle.tsx
840
+ import { useEffect as useEffect3, useRef as useRef3 } from "react";
841
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
842
+ var DEFAULT_HANDLE_ID = "default";
843
+ function Handle({
844
+ type,
845
+ position,
846
+ id = DEFAULT_HANDLE_ID,
847
+ isConnectable = true,
848
+ isConnectableStart,
849
+ isConnectableEnd,
850
+ index = 0,
851
+ total = 1,
852
+ label,
853
+ className,
854
+ style
855
+ }) {
856
+ const registry = useHandleRegistry();
857
+ const node = useFlowNodeContext();
858
+ const dispatch = useFlowDispatch();
859
+ const ref = useRef3(null);
860
+ const canStart = isConnectableStart ?? isConnectable;
861
+ const canEnd = isConnectableEnd ?? isConnectable;
862
+ useEffect3(() => {
863
+ const dispose = registry.register({
864
+ nodeId: node.id,
865
+ handleId: id,
866
+ type,
867
+ side: position,
868
+ index,
869
+ total
870
+ });
871
+ return dispose;
872
+ }, [registry, node.id, id, type, position, index, total]);
873
+ const handlePointerDown = (e) => {
874
+ if (!canStart) return;
875
+ e.stopPropagation();
876
+ e.preventDefault();
877
+ dispatch({
878
+ type: "connection/start",
879
+ nodeId: node.id,
880
+ handleId: id,
881
+ handleType: type,
882
+ pointerId: e.pointerId,
883
+ clientX: e.clientX,
884
+ clientY: e.clientY
885
+ });
886
+ };
887
+ return /* @__PURE__ */ jsxs2(
888
+ "div",
889
+ {
890
+ ref,
891
+ "data-handle-id": id,
892
+ "data-handle-node-id": node.id,
893
+ "data-handle-type": type,
894
+ "data-handle-side": position,
895
+ "data-handle-connectable-end": canEnd ? "true" : "false",
896
+ className: cn(
897
+ "ods-flow-handle",
898
+ `ods-flow-handle--${type}`,
899
+ `ods-flow-handle--side-${position}`,
900
+ !isConnectable && "ods-flow-handle--disabled",
901
+ className
902
+ ),
903
+ style: {
904
+ ...handleSideStyle(position, index, total),
905
+ ...style
906
+ },
907
+ onPointerDown: handlePointerDown,
908
+ children: [
909
+ /* @__PURE__ */ jsx3("div", { className: "ods-flow-handle__dot" }),
910
+ label && /* @__PURE__ */ jsx3("span", { className: "ods-flow-handle__label", children: label })
911
+ ]
912
+ }
913
+ );
914
+ }
915
+ function handleSideStyle(side, index, total) {
916
+ const ratio = (index + 1) / (total + 1) * 100;
917
+ switch (side) {
918
+ case "top":
919
+ return { position: "absolute", top: -6, left: `${ratio}%`, transform: "translateX(-50%)" };
920
+ case "bottom":
921
+ return { position: "absolute", bottom: -6, left: `${ratio}%`, transform: "translateX(-50%)" };
922
+ case "left":
923
+ return { position: "absolute", left: -6, top: `${ratio}%`, transform: "translateY(-50%)" };
924
+ case "right":
925
+ return { position: "absolute", right: -6, top: `${ratio}%`, transform: "translateY(-50%)" };
926
+ }
927
+ }
928
+
929
+ // src/workflow/components/kinds/BaseNode.tsx
930
+ import { useContext as useContext5 } from "react";
931
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
932
+ function BaseNode({
933
+ kind,
934
+ kindIcon,
935
+ icon,
936
+ title,
937
+ chip,
938
+ description,
939
+ accent = "green",
940
+ status,
941
+ onDelete,
942
+ footer,
943
+ className,
944
+ children
945
+ }) {
946
+ const ctx = useContext5(FlowNodeContext);
947
+ const bridge = useContext5(FlowNodeBridgeContext);
948
+ const deleteHandler = onDelete === false ? void 0 : onDelete ?? (ctx && bridge ? () => bridge.deleteNode(ctx.id) : void 0);
949
+ return /* @__PURE__ */ jsxs3(
950
+ "div",
951
+ {
952
+ className: cn(
953
+ "ods-flow-base-node",
954
+ `ods-flow-base-node--accent-${accent}`,
955
+ status && `ods-flow-base-node--status-${status}`,
956
+ className
957
+ ),
958
+ children: [
959
+ /* @__PURE__ */ jsxs3("div", { className: "ods-flow-base-node__pill", children: [
960
+ kindIcon && /* @__PURE__ */ jsx4("span", { className: "ods-flow-base-node__pill-icon", "aria-hidden": "true", children: kindIcon }),
961
+ /* @__PURE__ */ jsx4("span", { className: "ods-flow-base-node__pill-label", children: kind })
962
+ ] }),
963
+ status && status !== "idle" && /* @__PURE__ */ jsx4(
964
+ "span",
965
+ {
966
+ className: cn("ods-flow-base-node__status", `ods-flow-base-node__status--${status}`),
967
+ "aria-hidden": "true"
968
+ }
969
+ ),
970
+ /* @__PURE__ */ jsxs3("div", { className: "ods-flow-base-node__body", children: [
971
+ /* @__PURE__ */ jsxs3("div", { className: "ods-flow-base-node__content", children: [
972
+ /* @__PURE__ */ jsx4("div", { className: "ods-flow-base-node__bubble", "aria-hidden": "true", children: icon }),
973
+ /* @__PURE__ */ jsxs3("div", { className: "ods-flow-base-node__content-text", children: [
974
+ /* @__PURE__ */ jsx4("div", { className: "ods-flow-base-node__content-title", children: title }),
975
+ (chip !== void 0 || description !== void 0) && /* @__PURE__ */ jsxs3("div", { className: "ods-flow-base-node__content-info", children: [
976
+ chip !== void 0 && /* @__PURE__ */ jsx4("span", { className: "ods-flow-base-node__chip", children: chip }),
977
+ description !== void 0 && /* @__PURE__ */ jsx4("span", { className: "ods-flow-base-node__description", children: description })
978
+ ] })
979
+ ] })
980
+ ] }),
981
+ footer && /* @__PURE__ */ jsx4("div", { className: "ods-flow-base-node__footer", children: footer }),
982
+ deleteHandler && /* @__PURE__ */ jsx4(
983
+ "button",
984
+ {
985
+ type: "button",
986
+ className: "ods-flow-base-node__delete",
987
+ onClick: (e) => {
988
+ e.stopPropagation();
989
+ deleteHandler();
990
+ },
991
+ "aria-label": "Delete node",
992
+ "data-flow-no-drag": "true",
993
+ title: "Delete node",
994
+ children: /* @__PURE__ */ jsx4(DeleteIcon, {})
995
+ }
996
+ )
997
+ ] }),
998
+ children
999
+ ]
1000
+ }
1001
+ );
1002
+ }
1003
+ function DeleteIcon() {
1004
+ return /* @__PURE__ */ jsxs3("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", "aria-hidden": "true", children: [
1005
+ /* @__PURE__ */ jsx4("title", { children: "Delete" }),
1006
+ /* @__PURE__ */ jsx4(
1007
+ "path",
1008
+ {
1009
+ d: "M3 4h10M6.5 4V2.5h3V4M5 4l.5 9h5l.5-9M6.5 6.5v4M9.5 6.5v4",
1010
+ stroke: "currentColor",
1011
+ strokeWidth: "1.4",
1012
+ strokeLinecap: "round",
1013
+ strokeLinejoin: "round"
1014
+ }
1015
+ )
1016
+ ] });
1017
+ }
1018
+
1019
+ // src/workflow/components/kinds/index.tsx
1020
+ import { Fragment, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
1021
+ var ActionNode = ({
1022
+ node
1023
+ }) => {
1024
+ const d = node.data ?? {};
1025
+ return /* @__PURE__ */ jsxs4(
1026
+ BaseNode,
1027
+ {
1028
+ kind: d.kind ?? "ACTION",
1029
+ icon: d.icon,
1030
+ title: d.title ?? "Action",
1031
+ chip: d.chip ?? d.badge,
1032
+ description: d.description ?? d.subtitle,
1033
+ status: d.status,
1034
+ accent: "green",
1035
+ children: [
1036
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" }),
1037
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom" })
1038
+ ]
1039
+ }
1040
+ );
1041
+ };
1042
+ var TriggerNode = ({
1043
+ node
1044
+ }) => {
1045
+ const d = node.data ?? {};
1046
+ return /* @__PURE__ */ jsx5(
1047
+ BaseNode,
1048
+ {
1049
+ kind: d.kind ?? "TRIGGER",
1050
+ icon: d.icon,
1051
+ title: d.title ?? "Trigger",
1052
+ chip: d.chip,
1053
+ description: d.description ?? "Manually triggered",
1054
+ status: d.status,
1055
+ accent: "green",
1056
+ children: /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom" })
1057
+ }
1058
+ );
1059
+ };
1060
+ var ConditionNode = ({
1061
+ node
1062
+ }) => {
1063
+ const d = node.data ?? {};
1064
+ const branches = d.branches ?? [
1065
+ { id: "true", label: "true" },
1066
+ { id: "false", label: "false" }
1067
+ ];
1068
+ return /* @__PURE__ */ jsxs4(
1069
+ BaseNode,
1070
+ {
1071
+ kind: d.kind ?? "CONDITION",
1072
+ icon: d.icon,
1073
+ title: d.title ?? "Condition",
1074
+ chip: d.chip ?? d.badge,
1075
+ description: d.description ?? d.subtitle,
1076
+ status: d.status,
1077
+ accent: "amber",
1078
+ children: [
1079
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" }),
1080
+ branches.map((b, i) => /* @__PURE__ */ jsx5(
1081
+ Handle,
1082
+ {
1083
+ type: "source",
1084
+ position: "bottom",
1085
+ id: b.id,
1086
+ index: i,
1087
+ total: branches.length,
1088
+ label: b.label
1089
+ },
1090
+ b.id
1091
+ ))
1092
+ ]
1093
+ }
1094
+ );
1095
+ };
1096
+ var GroupNode = ({
1097
+ node
1098
+ }) => {
1099
+ const d = node.data ?? {};
1100
+ const collapsed = !!d.collapsed;
1101
+ const hiddenCount = d.hiddenCount;
1102
+ return /* @__PURE__ */ jsxs4(
1103
+ "div",
1104
+ {
1105
+ className: "ods-flow-group",
1106
+ "data-collapsed": collapsed ? "true" : "false",
1107
+ style: {
1108
+ width: node.width ?? 360,
1109
+ height: collapsed ? 36 : node.height ?? 200
1110
+ },
1111
+ children: [
1112
+ /* @__PURE__ */ jsxs4("div", { className: "ods-flow-group__header", "data-flow-no-drag": "false", children: [
1113
+ /* @__PURE__ */ jsx5("span", { className: "ods-flow-group__chevron", "aria-hidden": "true", children: collapsed ? "\u25B8" : "\u25BE" }),
1114
+ /* @__PURE__ */ jsx5("span", { className: "ods-flow-group__title", children: d.title ?? "Group" }),
1115
+ d.subtitle && /* @__PURE__ */ jsx5("span", { className: "ods-flow-group__subtitle", children: d.subtitle }),
1116
+ collapsed && hiddenCount !== void 0 && hiddenCount > 0 && /* @__PURE__ */ jsxs4("span", { className: "ods-flow-group__count", "aria-label": `${hiddenCount} hidden steps`, children: [
1117
+ hiddenCount,
1118
+ " steps"
1119
+ ] })
1120
+ ] }),
1121
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top", id: "__group_in" }),
1122
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom", id: "__group_out" })
1123
+ ]
1124
+ }
1125
+ );
1126
+ };
1127
+ var ForEachNode = ({
1128
+ node
1129
+ }) => {
1130
+ const d = node.data ?? {};
1131
+ const iteratorExpr = d.iterator ?? d.description ?? "items[]";
1132
+ const collapsed = !!d.collapsed;
1133
+ const hiddenCount = d.hiddenCount;
1134
+ return /* @__PURE__ */ jsxs4(
1135
+ "div",
1136
+ {
1137
+ className: "ods-flow-foreach",
1138
+ "data-collapsed": collapsed ? "true" : "false",
1139
+ style: {
1140
+ width: node.width ?? 420,
1141
+ height: collapsed ? 40 : node.height ?? 260
1142
+ },
1143
+ children: [
1144
+ /* @__PURE__ */ jsxs4("div", { className: "ods-flow-foreach__header", children: [
1145
+ /* @__PURE__ */ jsx5("span", { className: "ods-flow-foreach__chevron", "aria-hidden": "true", children: collapsed ? "\u25B8" : "\u25BE" }),
1146
+ /* @__PURE__ */ jsx5("span", { className: "ods-flow-foreach__icon", "aria-hidden": "true", children: "\u21BB" }),
1147
+ /* @__PURE__ */ jsx5("span", { className: "ods-flow-foreach__title", children: d.title ?? "For each" }),
1148
+ /* @__PURE__ */ jsx5("code", { className: "ods-flow-foreach__iterator", children: iteratorExpr }),
1149
+ collapsed && hiddenCount !== void 0 && hiddenCount > 0 && /* @__PURE__ */ jsxs4("span", { className: "ods-flow-foreach__count", "aria-label": `${hiddenCount} hidden steps`, children: [
1150
+ hiddenCount,
1151
+ " steps"
1152
+ ] })
1153
+ ] }),
1154
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top", id: "__group_in" }),
1155
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom", id: "__group_out" }),
1156
+ !collapsed && // Expanded mode — full 3-handle iterator surface (in / item / done).
1157
+ // `in` shares the top edge with `__group_in`; consumers wiring an
1158
+ // explicit `targetHandle: "in"` get the labelled, visible variant.
1159
+ /* @__PURE__ */ jsxs4(Fragment, { children: [
1160
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top", id: "in", label: "in" }),
1161
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "right", id: "item", label: "item" }),
1162
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom", id: "done", label: "done" })
1163
+ ] })
1164
+ ]
1165
+ }
1166
+ );
1167
+ };
1168
+ var OutputNode = ({
1169
+ node
1170
+ }) => {
1171
+ const d = node.data ?? {};
1172
+ return /* @__PURE__ */ jsx5(
1173
+ BaseNode,
1174
+ {
1175
+ kind: d.kind ?? "OUTPUT",
1176
+ icon: d.icon,
1177
+ title: d.title ?? "Output",
1178
+ chip: d.chip ?? d.badge,
1179
+ description: d.description ?? d.subtitle,
1180
+ status: d.status,
1181
+ accent: "green",
1182
+ children: /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" })
1183
+ }
1184
+ );
1185
+ };
1186
+ var ErrorNode = ({
1187
+ node
1188
+ }) => {
1189
+ const d = node.data ?? {};
1190
+ return /* @__PURE__ */ jsxs4(
1191
+ BaseNode,
1192
+ {
1193
+ kind: d.kind ?? "ERROR",
1194
+ icon: d.icon,
1195
+ title: d.title ?? "On error",
1196
+ chip: d.chip ?? d.badge,
1197
+ description: d.description ?? d.subtitle,
1198
+ status: d.status ?? "error",
1199
+ accent: "red",
1200
+ children: [
1201
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" }),
1202
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom" })
1203
+ ]
1204
+ }
1205
+ );
1206
+ };
1207
+ var WaitNode = ({
1208
+ node
1209
+ }) => {
1210
+ const d = node.data ?? {};
1211
+ const waitMs = d.waitMs;
1212
+ const durationChip = waitMs ? `${Math.round(waitMs / 100) / 10}s` : void 0;
1213
+ return /* @__PURE__ */ jsxs4(
1214
+ BaseNode,
1215
+ {
1216
+ kind: d.kind ?? "WAIT",
1217
+ icon: d.icon,
1218
+ title: d.title ?? "Wait",
1219
+ chip: d.chip ?? durationChip,
1220
+ description: d.description ?? (durationChip ? "Pause execution" : void 0),
1221
+ status: d.status,
1222
+ accent: "violet",
1223
+ children: [
1224
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" }),
1225
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom" })
1226
+ ]
1227
+ }
1228
+ );
1229
+ };
1230
+ var ParallelNode = ({
1231
+ node
1232
+ }) => {
1233
+ const d = node.data ?? {};
1234
+ const branches = d.branches ?? [
1235
+ { id: "a", label: "a" },
1236
+ { id: "b", label: "b" }
1237
+ ];
1238
+ return /* @__PURE__ */ jsxs4(
1239
+ BaseNode,
1240
+ {
1241
+ kind: d.kind ?? "PARALLEL",
1242
+ icon: d.icon,
1243
+ title: d.title ?? "Parallel",
1244
+ chip: d.chip ?? `${branches.length}\xD7`,
1245
+ description: d.description ?? "Fan-out branches",
1246
+ status: d.status,
1247
+ accent: "blue",
1248
+ children: [
1249
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" }),
1250
+ branches.map((b, i) => /* @__PURE__ */ jsx5(
1251
+ Handle,
1252
+ {
1253
+ type: "source",
1254
+ position: "bottom",
1255
+ id: b.id,
1256
+ index: i,
1257
+ total: branches.length,
1258
+ label: b.label
1259
+ },
1260
+ b.id
1261
+ ))
1262
+ ]
1263
+ }
1264
+ );
1265
+ };
1266
+ var StickyNode = ({
1267
+ node
1268
+ }) => {
1269
+ const d = node.data ?? {};
1270
+ return /* @__PURE__ */ jsxs4(
1271
+ "div",
1272
+ {
1273
+ className: "ods-flow-sticky",
1274
+ style: {
1275
+ width: node.width ?? 240,
1276
+ minHeight: node.height ?? 120
1277
+ },
1278
+ children: [
1279
+ d.title && /* @__PURE__ */ jsx5("div", { className: "ods-flow-sticky__title", children: d.title }),
1280
+ d.description && /* @__PURE__ */ jsx5("div", { className: "ods-flow-sticky__body", children: d.description })
1281
+ ]
1282
+ }
1283
+ );
1284
+ };
1285
+ var WebhookNode = ({
1286
+ node
1287
+ }) => {
1288
+ const d = node.data ?? {};
1289
+ return /* @__PURE__ */ jsx5(
1290
+ BaseNode,
1291
+ {
1292
+ kind: d.kind ?? "WEBHOOK",
1293
+ icon: d.icon,
1294
+ title: d.title ?? "Webhook",
1295
+ chip: d.chip ?? d.method ?? "POST",
1296
+ description: d.description ?? d.path ?? "/hooks/incoming",
1297
+ status: d.status,
1298
+ accent: "blue",
1299
+ children: /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom" })
1300
+ }
1301
+ );
1302
+ };
1303
+ var HttpRequestNode = ({
1304
+ node
1305
+ }) => {
1306
+ const d = node.data ?? {};
1307
+ return /* @__PURE__ */ jsxs4(
1308
+ BaseNode,
1309
+ {
1310
+ kind: d.kind ?? "HTTP",
1311
+ icon: d.icon,
1312
+ title: d.title ?? "HTTP Request",
1313
+ chip: d.chip ?? d.method ?? "GET",
1314
+ description: d.description ?? d.url ?? "Call an API",
1315
+ status: d.status,
1316
+ accent: "blue",
1317
+ children: [
1318
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" }),
1319
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom" })
1320
+ ]
1321
+ }
1322
+ );
1323
+ };
1324
+ var DEFAULT_NODE_KINDS = {
1325
+ action: ActionNode,
1326
+ trigger: TriggerNode,
1327
+ condition: ConditionNode,
1328
+ group: GroupNode,
1329
+ forEach: ForEachNode,
1330
+ output: OutputNode,
1331
+ error: ErrorNode,
1332
+ wait: WaitNode,
1333
+ parallel: ParallelNode,
1334
+ sticky: StickyNode,
1335
+ webhook: WebhookNode,
1336
+ httpRequest: HttpRequestNode
1337
+ };
1338
+
1339
+ // src/workflow/components/FlowCanvas/FlowCanvas.tsx
1340
+ import {
1341
+ memo as memo2,
1342
+ useCallback,
1343
+ useEffect as useEffect4,
1344
+ useMemo as useMemo2,
1345
+ useRef as useRef4,
1346
+ useState as useState2
1347
+ } from "react";
1348
+
1349
+ // src/workflow/store/context.ts
1350
+ import { createContext as createContext5, useContext as useContext6 } from "react";
1351
+ var FlowStoreContext = createContext5(null);
1352
+ function useFlowStore() {
1353
+ const store = useContext6(FlowStoreContext);
1354
+ if (!store) {
1355
+ throw new Error(
1356
+ "[@octaviaflow/core/workflow] useFlowStore must be called inside a <FlowCanvas>."
1357
+ );
1358
+ }
1359
+ return store;
1360
+ }
1361
+
1362
+ // src/workflow/store/createFlowStore.ts
1363
+ var DEFAULT_VIEWPORT = { x: 0, y: 0, zoom: 1 };
1364
+ function createFlowStore({
1365
+ initialNodes = [],
1366
+ initialEdges = [],
1367
+ initialViewport = DEFAULT_VIEWPORT
1368
+ } = {}) {
1369
+ let snapshot = {
1370
+ nodes: initialNodes,
1371
+ edges: initialEdges,
1372
+ viewport: initialViewport,
1373
+ selectedNodeIds: EMPTY_SET,
1374
+ selectedEdgeIds: EMPTY_SET,
1375
+ connection: null
1376
+ };
1377
+ const listeners = /* @__PURE__ */ new Set();
1378
+ const emit = () => {
1379
+ for (const l of listeners) l();
1380
+ };
1381
+ const subscribe = (listener) => {
1382
+ listeners.add(listener);
1383
+ return () => {
1384
+ listeners.delete(listener);
1385
+ };
1386
+ };
1387
+ const replace = (patch) => {
1388
+ snapshot = { ...snapshot, ...patch };
1389
+ emit();
1390
+ };
1391
+ return {
1392
+ subscribe,
1393
+ getSnapshot: () => snapshot,
1394
+ setNodes(nodes) {
1395
+ if (nodes === snapshot.nodes) return;
1396
+ replace({ nodes });
1397
+ },
1398
+ setEdges(edges) {
1399
+ if (edges === snapshot.edges) return;
1400
+ replace({ edges });
1401
+ },
1402
+ setViewport(viewport) {
1403
+ if (viewport.x === snapshot.viewport.x && viewport.y === snapshot.viewport.y && viewport.zoom === snapshot.viewport.zoom) {
1404
+ return;
1405
+ }
1406
+ replace({ viewport });
1407
+ },
1408
+ setSelection(selectedNodeIds, selectedEdgeIds) {
1409
+ replace({ selectedNodeIds, selectedEdgeIds });
1410
+ },
1411
+ setConnection(connection) {
1412
+ if (connection === snapshot.connection) return;
1413
+ replace({ connection });
1414
+ }
1415
+ };
1416
+ }
1417
+ var EMPTY_SET = /* @__PURE__ */ new Set();
1418
+
1419
+ // src/workflow/utils/collision.ts
1420
+ function resolveNodeCollisions(node, proposed, others, opts) {
1421
+ const { gap, maxIterations = 8, exclude, scopeToSiblings = true } = opts;
1422
+ if (gap < 0 || others.length === 0) return proposed;
1423
+ const w = node.width ?? DEFAULT_NODE_WIDTH;
1424
+ const h = effectiveHeight(node);
1425
+ const parentId = node.parentId;
1426
+ const candidates = others.filter((o) => {
1427
+ if (o.id === node.id) return false;
1428
+ if (o.hidden) return false;
1429
+ if (exclude?.has(o.id)) return false;
1430
+ if (scopeToSiblings && (o.parentId ?? void 0) !== (parentId ?? void 0)) {
1431
+ return false;
1432
+ }
1433
+ return true;
1434
+ });
1435
+ if (candidates.length === 0) return proposed;
1436
+ let cur = proposed;
1437
+ for (let iter = 0; iter < maxIterations; iter++) {
1438
+ let bestOverlap = Number.POSITIVE_INFINITY;
1439
+ let bestPushX = 0;
1440
+ let bestPushY = 0;
1441
+ let hit = false;
1442
+ const aLeft = cur.x - gap;
1443
+ const aRight = cur.x + w + gap;
1444
+ const aTop = cur.y - gap;
1445
+ const aBottom = cur.y + h + gap;
1446
+ for (const o of candidates) {
1447
+ const ow = o.width ?? DEFAULT_NODE_WIDTH;
1448
+ const oh = effectiveHeight(o);
1449
+ const bLeft = o.position.x;
1450
+ const bRight = o.position.x + ow;
1451
+ const bTop = o.position.y;
1452
+ const bBottom = o.position.y + oh;
1453
+ const overlapX = Math.min(aRight, bRight) - Math.max(aLeft, bLeft);
1454
+ const overlapY = Math.min(aBottom, bBottom) - Math.max(aTop, bTop);
1455
+ if (overlapX <= 0 || overlapY <= 0) continue;
1456
+ let pushX = 0;
1457
+ let pushY = 0;
1458
+ let overlap;
1459
+ if (overlapX < overlapY) {
1460
+ const aCx = cur.x + w / 2;
1461
+ const bCx = o.position.x + ow / 2;
1462
+ pushX = aCx < bCx ? -overlapX : overlapX;
1463
+ overlap = overlapX;
1464
+ } else {
1465
+ const aCy = cur.y + h / 2;
1466
+ const bCy = o.position.y + oh / 2;
1467
+ pushY = aCy < bCy ? -overlapY : overlapY;
1468
+ overlap = overlapY;
1469
+ }
1470
+ if (overlap < bestOverlap) {
1471
+ bestOverlap = overlap;
1472
+ bestPushX = pushX;
1473
+ bestPushY = pushY;
1474
+ hit = true;
1475
+ }
1476
+ }
1477
+ if (!hit) break;
1478
+ cur = { x: cur.x + bestPushX, y: cur.y + bestPushY };
1479
+ }
1480
+ return cur;
1481
+ }
1482
+
1483
+ // src/workflow/components/FlowCanvas/FlowCanvas.tsx
1484
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
1485
+ var DEFAULT_VIEWPORT2 = { x: 0, y: 0, zoom: 1 };
1486
+ function FlowCanvas({
1487
+ nodes,
1488
+ edges,
1489
+ onNodesChange,
1490
+ onEdgesChange,
1491
+ viewport: controlledViewport,
1492
+ defaultViewport = DEFAULT_VIEWPORT2,
1493
+ onViewportChange,
1494
+ minZoom = 0.25,
1495
+ maxZoom = 2,
1496
+ nodeKinds,
1497
+ onConnect,
1498
+ onConnectStart,
1499
+ onConnectEnd,
1500
+ isValidConnection,
1501
+ onSelectionChange,
1502
+ onPaneClick,
1503
+ onNodeClick,
1504
+ onEdgeClick,
1505
+ onEdgeLabelChange,
1506
+ onInit,
1507
+ onBeforeDelete,
1508
+ onNodeContextMenu,
1509
+ onEdgeContextMenu,
1510
+ onPaneContextMenu,
1511
+ nodesDraggable = true,
1512
+ nodesConnectable = true,
1513
+ panOnDrag: panOnDragProp,
1514
+ zoomOnScroll: zoomOnScrollProp,
1515
+ preset = "mouse",
1516
+ paneClickDistance = 4,
1517
+ background = "dots",
1518
+ gridSize = 20,
1519
+ snapToGrid = false,
1520
+ nodeCollisionGap = -1,
1521
+ subflowCollisionGap,
1522
+ height = "100%",
1523
+ width = "100%",
1524
+ className,
1525
+ style,
1526
+ children,
1527
+ emptyState
1528
+ }) {
1529
+ const presetDefaults = {
1530
+ mouse: { panOnDrag: true, zoomOnScroll: true },
1531
+ trackpad: { panOnDrag: true, zoomOnScroll: true },
1532
+ touch: { panOnDrag: false, zoomOnScroll: true }
1533
+ };
1534
+ const panOnDrag = panOnDragProp ?? presetDefaults[preset].panOnDrag;
1535
+ const zoomOnScroll = zoomOnScrollProp ?? presetDefaults[preset].zoomOnScroll;
1536
+ const store = useState2(
1537
+ () => createFlowStore({
1538
+ initialNodes: nodes,
1539
+ initialEdges: edges,
1540
+ initialViewport: controlledViewport ?? defaultViewport
1541
+ })
1542
+ )[0];
1543
+ const handleRegistry = useState2(() => createHandleRegistry())[0];
1544
+ const [handleVersion, setHandleVersion] = useState2(0);
1545
+ useEffect4(() => {
1546
+ const unsub = handleRegistry.subscribe(() => {
1547
+ setHandleVersion((v) => v + 1);
1548
+ });
1549
+ return unsub;
1550
+ }, [handleRegistry]);
1551
+ const kinds = useMemo2(() => buildNodeKindRegistry(DEFAULT_NODE_KINDS, nodeKinds), [nodeKinds]);
1552
+ const containerRef = useRef4(null);
1553
+ useEffect4(() => store.setNodes(nodes), [store, nodes]);
1554
+ useEffect4(() => store.setEdges(edges), [store, edges]);
1555
+ const [uncontrolledVp, setUncontrolledVp] = useState2(controlledViewport ?? defaultViewport);
1556
+ const viewport = controlledViewport ?? uncontrolledVp;
1557
+ useEffect4(() => store.setViewport(viewport), [store, viewport]);
1558
+ const setViewport = useCallback(
1559
+ (next) => {
1560
+ if (controlledViewport === void 0) setUncontrolledVp(next);
1561
+ onViewportChange?.(next);
1562
+ },
1563
+ [controlledViewport, onViewportChange]
1564
+ );
1565
+ const selectedNodeIds = useMemo2(() => {
1566
+ const s = /* @__PURE__ */ new Set();
1567
+ for (const n of nodes) if (n.selected) s.add(n.id);
1568
+ return s;
1569
+ }, [nodes]);
1570
+ const selectedEdgeIds = useMemo2(() => {
1571
+ const s = /* @__PURE__ */ new Set();
1572
+ for (const e of edges) if (e.selected) s.add(e.id);
1573
+ return s;
1574
+ }, [edges]);
1575
+ useEffect4(() => {
1576
+ store.setSelection(selectedNodeIds, selectedEdgeIds);
1577
+ if (onSelectionChange) {
1578
+ onSelectionChange({
1579
+ nodes: nodes.filter((n) => selectedNodeIds.has(n.id)),
1580
+ edges: edges.filter((e) => selectedEdgeIds.has(e.id))
1581
+ });
1582
+ }
1583
+ }, [store, selectedNodeIds, selectedEdgeIds, nodes, edges, onSelectionChange]);
1584
+ const selectNode = useCallback(
1585
+ (id, additive) => {
1586
+ const next = [];
1587
+ const nextEdges = [];
1588
+ if (!additive) {
1589
+ for (const n of nodes) {
1590
+ if (n.selected && n.id !== id) next.push(change.node.select(n.id, false));
1591
+ }
1592
+ for (const e of edges) {
1593
+ if (e.selected) nextEdges.push(change.edge.select(e.id, false));
1594
+ }
1595
+ }
1596
+ const isSelected = selectedNodeIds.has(id);
1597
+ if (additive && isSelected) {
1598
+ next.push(change.node.select(id, false));
1599
+ } else if (!isSelected) {
1600
+ next.push(change.node.select(id, true));
1601
+ }
1602
+ if (next.length) onNodesChange?.(next);
1603
+ if (nextEdges.length) onEdgesChange?.(nextEdges);
1604
+ const node = nodes.find((n) => n.id === id);
1605
+ if (node) onNodeClick?.(node);
1606
+ },
1607
+ [nodes, edges, selectedNodeIds, onNodesChange, onEdgesChange, onNodeClick]
1608
+ );
1609
+ const selectEdge = useCallback(
1610
+ (id, additive) => {
1611
+ const next = [];
1612
+ const nextNodes = [];
1613
+ if (!additive) {
1614
+ for (const e of edges) {
1615
+ if (e.selected && e.id !== id) next.push(change.edge.select(e.id, false));
1616
+ }
1617
+ for (const n of nodes) {
1618
+ if (n.selected) nextNodes.push(change.node.select(n.id, false));
1619
+ }
1620
+ }
1621
+ const isSelected = selectedEdgeIds.has(id);
1622
+ if (additive && isSelected) {
1623
+ next.push(change.edge.select(id, false));
1624
+ } else if (!isSelected) {
1625
+ next.push(change.edge.select(id, true));
1626
+ }
1627
+ if (next.length) onEdgesChange?.(next);
1628
+ if (nextNodes.length) onNodesChange?.(nextNodes);
1629
+ const edge = edges.find((e) => e.id === id);
1630
+ if (edge) onEdgeClick?.(edge);
1631
+ },
1632
+ [nodes, edges, selectedEdgeIds, onEdgesChange, onNodesChange, onEdgeClick]
1633
+ );
1634
+ const clearSelection = useCallback(() => {
1635
+ const ns = [];
1636
+ const es = [];
1637
+ for (const n of nodes) if (n.selected) ns.push(change.node.select(n.id, false));
1638
+ for (const e of edges) if (e.selected) es.push(change.edge.select(e.id, false));
1639
+ if (ns.length) onNodesChange?.(ns);
1640
+ if (es.length) onEdgesChange?.(es);
1641
+ }, [nodes, edges, onNodesChange, onEdgesChange]);
1642
+ const dragRef = useRef4(null);
1643
+ const [draggingId, setDraggingId] = useState2(null);
1644
+ const beginNodeDrag = useCallback(
1645
+ (nodeId, pointerId, clientX, clientY, altKey = false) => {
1646
+ if (!nodesDraggable) return;
1647
+ const node = nodes.find((n) => n.id === nodeId);
1648
+ if (!node) return;
1649
+ const kids = descendantsOf(nodeId, nodes).map((d) => ({
1650
+ id: d.id,
1651
+ startPosition: d.position
1652
+ }));
1653
+ dragRef.current = {
1654
+ pointerId,
1655
+ nodeId,
1656
+ startClientX: clientX,
1657
+ startClientY: clientY,
1658
+ startPosition: node.position,
1659
+ descendants: kids,
1660
+ altDetach: altKey && !!node.parentId,
1661
+ rafScheduled: false,
1662
+ nextDelta: null
1663
+ };
1664
+ setDraggingId(nodeId);
1665
+ selectNode(nodeId, false);
1666
+ },
1667
+ [nodes, nodesDraggable, selectNode]
1668
+ );
1669
+ const [conn, setConn] = useState2(null);
1670
+ const connRef = useRef4(null);
1671
+ useEffect4(() => {
1672
+ connRef.current = conn;
1673
+ }, [conn]);
1674
+ const beginConnection = useCallback(
1675
+ (nodeId, handleId, handleType, pointerId, clientX, clientY) => {
1676
+ if (!nodesConnectable) return;
1677
+ const node = nodes.find((n) => n.id === nodeId);
1678
+ if (!node) return;
1679
+ const desc = handleRegistry.resolve(nodeId, handleType, handleId);
1680
+ const side = desc?.side ?? (handleType === "source" ? "bottom" : "top");
1681
+ const index = desc?.index ?? 0;
1682
+ const total = desc?.total ?? 1;
1683
+ const ratio = (index + 1) / (total + 1);
1684
+ const w = node.width ?? 240;
1685
+ const h = effectiveHeight(node);
1686
+ const start = (() => {
1687
+ switch (side) {
1688
+ case "top":
1689
+ return { x: node.position.x + w * ratio, y: node.position.y };
1690
+ case "bottom":
1691
+ return { x: node.position.x + w * ratio, y: node.position.y + h };
1692
+ case "left":
1693
+ return { x: node.position.x, y: node.position.y + h * ratio };
1694
+ case "right":
1695
+ return { x: node.position.x + w, y: node.position.y + h * ratio };
1696
+ }
1697
+ })();
1698
+ const from = { nodeId, handleId, handleType };
1699
+ const rect = containerRef.current?.getBoundingClientRect();
1700
+ const end = rect ? screenToFlow({ x: clientX - rect.left, y: clientY - rect.top }, viewport) : start;
1701
+ setConn({ pointerId, from, start, end });
1702
+ store.setConnection(from);
1703
+ onConnectStart?.({ clientX, clientY, pointerId }, from);
1704
+ },
1705
+ [nodes, nodesConnectable, handleRegistry, viewport, store, onConnectStart]
1706
+ );
1707
+ const viewportRef = useRef4(viewport);
1708
+ const nodesRef = useRef4(nodes);
1709
+ const edgesRef = useRef4(edges);
1710
+ const onNodesChangeRefForInstance = useRef4(onNodesChange);
1711
+ const onEdgesChangeRefForInstance = useRef4(onEdgesChange);
1712
+ const onBeforeDeleteRef = useRef4(onBeforeDelete);
1713
+ const snapToGridRef = useRef4(snapToGrid);
1714
+ const gridSizeRef = useRef4(gridSize);
1715
+ const nodeCollisionGapRef = useRef4(nodeCollisionGap);
1716
+ const subflowCollisionGapRef = useRef4(subflowCollisionGap ?? nodeCollisionGap);
1717
+ useEffect4(() => {
1718
+ edgesRef.current = edges;
1719
+ }, [edges]);
1720
+ useEffect4(() => {
1721
+ onNodesChangeRefForInstance.current = onNodesChange;
1722
+ }, [onNodesChange]);
1723
+ useEffect4(() => {
1724
+ onEdgesChangeRefForInstance.current = onEdgesChange;
1725
+ }, [onEdgesChange]);
1726
+ useEffect4(() => {
1727
+ onBeforeDeleteRef.current = onBeforeDelete;
1728
+ }, [onBeforeDelete]);
1729
+ useEffect4(() => {
1730
+ snapToGridRef.current = snapToGrid;
1731
+ }, [snapToGrid]);
1732
+ useEffect4(() => {
1733
+ gridSizeRef.current = gridSize;
1734
+ }, [gridSize]);
1735
+ useEffect4(() => {
1736
+ nodeCollisionGapRef.current = nodeCollisionGap;
1737
+ }, [nodeCollisionGap]);
1738
+ useEffect4(() => {
1739
+ subflowCollisionGapRef.current = subflowCollisionGap ?? nodeCollisionGap;
1740
+ }, [subflowCollisionGap, nodeCollisionGap]);
1741
+ const onNodesChangeRef = useRef4(onNodesChange);
1742
+ const onConnectRef = useRef4(onConnect);
1743
+ const onConnectEndRef = useRef4(onConnectEnd);
1744
+ const isValidConnectionRef = useRef4(isValidConnection);
1745
+ useEffect4(() => {
1746
+ viewportRef.current = viewport;
1747
+ }, [viewport]);
1748
+ useEffect4(() => {
1749
+ nodesRef.current = nodes;
1750
+ }, [nodes]);
1751
+ useEffect4(() => {
1752
+ onNodesChangeRef.current = onNodesChange;
1753
+ }, [onNodesChange]);
1754
+ useEffect4(() => {
1755
+ onConnectRef.current = onConnect;
1756
+ }, [onConnect]);
1757
+ useEffect4(() => {
1758
+ onConnectEndRef.current = onConnectEnd;
1759
+ }, [onConnectEnd]);
1760
+ useEffect4(() => {
1761
+ isValidConnectionRef.current = isValidConnection;
1762
+ }, [isValidConnection]);
1763
+ useEffect4(() => {
1764
+ const onPointerMove = (e) => {
1765
+ const vp = viewportRef.current;
1766
+ const drag = dragRef.current;
1767
+ if (drag && drag.pointerId === e.pointerId) {
1768
+ const dx = (e.clientX - drag.startClientX) / vp.zoom;
1769
+ const dy = (e.clientY - drag.startClientY) / vp.zoom;
1770
+ drag.nextDelta = { dx, dy };
1771
+ if (!drag.rafScheduled) {
1772
+ drag.rafScheduled = true;
1773
+ requestAnimationFrame(() => {
1774
+ const d = dragRef.current;
1775
+ if (!d) return;
1776
+ d.rafScheduled = false;
1777
+ const delta = d.nextDelta;
1778
+ if (!delta) return;
1779
+ const dragNode = nodesRef.current.find((n) => n.id === d.nodeId);
1780
+ if (!dragNode) return;
1781
+ const proposed = {
1782
+ x: d.startPosition.x + delta.dx,
1783
+ y: d.startPosition.y + delta.dy
1784
+ };
1785
+ const clamped = d.altDetach ? proposed : clampToParentExtent(dragNode, proposed, nodesRef.current);
1786
+ const isContainer = dragNode.type === "group" || dragNode.type === "forEach";
1787
+ const gap = isContainer ? subflowCollisionGapRef.current : nodeCollisionGapRef.current;
1788
+ const excludeIds = /* @__PURE__ */ new Set([d.nodeId, ...d.descendants.map((kid) => kid.id)]);
1789
+ const finalPos = resolveNodeCollisions(dragNode, clamped, nodesRef.current, {
1790
+ gap,
1791
+ exclude: excludeIds
1792
+ });
1793
+ const realDx = finalPos.x - d.startPosition.x;
1794
+ const realDy = finalPos.y - d.startPosition.y;
1795
+ const changes = [change.node.position(d.nodeId, finalPos, true)];
1796
+ for (const kid of d.descendants) {
1797
+ changes.push(
1798
+ change.node.position(
1799
+ kid.id,
1800
+ { x: kid.startPosition.x + realDx, y: kid.startPosition.y + realDy },
1801
+ true
1802
+ )
1803
+ );
1804
+ }
1805
+ onNodesChangeRef.current?.(changes);
1806
+ });
1807
+ }
1808
+ }
1809
+ const c = connRef.current;
1810
+ if (c && c.pointerId === e.pointerId) {
1811
+ const rect = containerRef.current?.getBoundingClientRect();
1812
+ if (rect) {
1813
+ const end = screenToFlow({ x: e.clientX - rect.left, y: e.clientY - rect.top }, vp);
1814
+ setConn({ ...c, end });
1815
+ }
1816
+ }
1817
+ };
1818
+ const onPointerUp = (e) => {
1819
+ const vp = viewportRef.current;
1820
+ const drag = dragRef.current;
1821
+ if (drag && drag.pointerId === e.pointerId) {
1822
+ const dx = (e.clientX - drag.startClientX) / vp.zoom;
1823
+ const dy = (e.clientY - drag.startClientY) / vp.zoom;
1824
+ const dragNode = nodesRef.current.find((n) => n.id === drag.nodeId);
1825
+ if (dragNode) {
1826
+ let proposed = {
1827
+ x: drag.startPosition.x + dx,
1828
+ y: drag.startPosition.y + dy
1829
+ };
1830
+ if (snapToGridRef.current) {
1831
+ const g = gridSizeRef.current;
1832
+ proposed = {
1833
+ x: Math.round(proposed.x / g) * g,
1834
+ y: Math.round(proposed.y / g) * g
1835
+ };
1836
+ }
1837
+ const clamped = drag.altDetach ? proposed : clampToParentExtent(dragNode, proposed, nodesRef.current);
1838
+ const isContainer = dragNode.type === "group" || dragNode.type === "forEach";
1839
+ const gap = isContainer ? subflowCollisionGapRef.current : nodeCollisionGapRef.current;
1840
+ const excludeIds = /* @__PURE__ */ new Set([
1841
+ drag.nodeId,
1842
+ ...drag.descendants.map((kid) => kid.id)
1843
+ ]);
1844
+ const finalPos = resolveNodeCollisions(dragNode, clamped, nodesRef.current, {
1845
+ gap,
1846
+ exclude: excludeIds
1847
+ });
1848
+ const realDx = finalPos.x - drag.startPosition.x;
1849
+ const realDy = finalPos.y - drag.startPosition.y;
1850
+ const changes = [change.node.position(drag.nodeId, finalPos, false)];
1851
+ for (const kid of drag.descendants) {
1852
+ changes.push(
1853
+ change.node.position(
1854
+ kid.id,
1855
+ { x: kid.startPosition.x + realDx, y: kid.startPosition.y + realDy },
1856
+ false
1857
+ )
1858
+ );
1859
+ }
1860
+ if (drag.altDetach && dragNode.parentId) {
1861
+ const targetGroup = findContainingGroup(
1862
+ {
1863
+ x: finalPos.x + (dragNode.width ?? 0) / 2,
1864
+ y: finalPos.y + (dragNode.height ?? 0) / 2
1865
+ },
1866
+ nodesRef.current,
1867
+ [drag.nodeId, ...drag.descendants.map((d) => d.id)]
1868
+ );
1869
+ const nextParentId = targetGroup?.id;
1870
+ const updated = {
1871
+ ...dragNode,
1872
+ position: finalPos,
1873
+ parentId: nextParentId,
1874
+ // Preserve extent only when staying in a group.
1875
+ extent: nextParentId ? dragNode.extent : void 0
1876
+ };
1877
+ changes.push(change.node.replace(drag.nodeId, updated));
1878
+ }
1879
+ onNodesChangeRef.current?.(changes);
1880
+ }
1881
+ dragRef.current = null;
1882
+ setDraggingId(null);
1883
+ }
1884
+ const c = connRef.current;
1885
+ if (c && c.pointerId === e.pointerId) {
1886
+ const target = e.target;
1887
+ const handleEl = target?.closest("[data-handle-id]");
1888
+ let connection = null;
1889
+ let connectedTo;
1890
+ if (handleEl) {
1891
+ const targetNodeId = handleEl.dataset.handleNodeId;
1892
+ const targetHandleId = handleEl.dataset.handleId;
1893
+ const targetType = handleEl.dataset.handleType;
1894
+ const connectableEnd = handleEl.dataset.handleConnectableEnd === "true";
1895
+ if (connectableEnd && (targetNodeId !== c.from.nodeId || targetHandleId !== c.from.handleId) && targetType !== c.from.handleType) {
1896
+ const source = c.from.handleType === "source" ? c.from : { nodeId: targetNodeId, handleId: targetHandleId, handleType: "source" };
1897
+ const target2 = c.from.handleType === "target" ? c.from : { nodeId: targetNodeId, handleId: targetHandleId, handleType: "target" };
1898
+ connection = {
1899
+ source: source.nodeId,
1900
+ sourceHandle: source.handleId,
1901
+ target: target2.nodeId,
1902
+ targetHandle: target2.handleId
1903
+ };
1904
+ connectedTo = {
1905
+ nodeId: targetNodeId,
1906
+ handleId: targetHandleId,
1907
+ handleType: targetType
1908
+ };
1909
+ const validator = isValidConnectionRef.current;
1910
+ if (validator && !validator(connection)) {
1911
+ connection = null;
1912
+ connectedTo = void 0;
1913
+ }
1914
+ }
1915
+ }
1916
+ const rect = containerRef.current?.getBoundingClientRect();
1917
+ const flowPos = rect ? screenToFlow({ x: e.clientX - rect.left, y: e.clientY - rect.top }, vp) : { x: 0, y: 0 };
1918
+ const endState = {
1919
+ cancelled: !connection,
1920
+ position: { x: e.clientX, y: e.clientY },
1921
+ flowPosition: flowPos,
1922
+ from: c.from,
1923
+ to: connectedTo
1924
+ };
1925
+ if (connection) onConnectRef.current?.(connection);
1926
+ onConnectEndRef.current?.(e, endState);
1927
+ setConn(null);
1928
+ store.setConnection(null);
1929
+ }
1930
+ };
1931
+ const onPointerCancel = () => {
1932
+ if (dragRef.current) {
1933
+ dragRef.current = null;
1934
+ setDraggingId(null);
1935
+ }
1936
+ if (connRef.current) {
1937
+ setConn(null);
1938
+ store.setConnection(null);
1939
+ }
1940
+ };
1941
+ window.addEventListener("pointermove", onPointerMove);
1942
+ window.addEventListener("pointerup", onPointerUp);
1943
+ window.addEventListener("pointercancel", onPointerCancel);
1944
+ return () => {
1945
+ window.removeEventListener("pointermove", onPointerMove);
1946
+ window.removeEventListener("pointerup", onPointerUp);
1947
+ window.removeEventListener("pointercancel", onPointerCancel);
1948
+ };
1949
+ }, [store]);
1950
+ const panRef = useRef4(null);
1951
+ const onCanvasPointerDown = (e) => {
1952
+ if (e.button !== 0) return;
1953
+ const t = e.target;
1954
+ if (t.closest("[data-node-id]") || t.closest("[data-edge-id]") || t.closest("[data-handle-id]")) {
1955
+ return;
1956
+ }
1957
+ if (!panOnDrag) {
1958
+ panRef.current = {
1959
+ pointerId: e.pointerId,
1960
+ startClientX: e.clientX,
1961
+ startClientY: e.clientY,
1962
+ startVp: viewport,
1963
+ moved: false
1964
+ };
1965
+ return;
1966
+ }
1967
+ panRef.current = {
1968
+ pointerId: e.pointerId,
1969
+ startClientX: e.clientX,
1970
+ startClientY: e.clientY,
1971
+ startVp: viewport,
1972
+ moved: false
1973
+ };
1974
+ };
1975
+ useEffect4(() => {
1976
+ const onMove = (e) => {
1977
+ const pan = panRef.current;
1978
+ if (!pan || pan.pointerId !== e.pointerId) return;
1979
+ const dx = e.clientX - pan.startClientX;
1980
+ const dy = e.clientY - pan.startClientY;
1981
+ if (Math.abs(dx) > paneClickDistance || Math.abs(dy) > paneClickDistance) {
1982
+ if (!pan.moved) setPanGesture(true);
1983
+ pan.moved = true;
1984
+ }
1985
+ if (pan.moved && panOnDrag) {
1986
+ setViewport({ ...pan.startVp, x: pan.startVp.x + dx, y: pan.startVp.y + dy });
1987
+ }
1988
+ };
1989
+ const onUp = () => {
1990
+ const pan = panRef.current;
1991
+ if (!pan) return;
1992
+ if (!pan.moved) {
1993
+ onPaneClick?.();
1994
+ clearSelection();
1995
+ }
1996
+ panRef.current = null;
1997
+ setPanGesture(false);
1998
+ };
1999
+ window.addEventListener("pointermove", onMove);
2000
+ window.addEventListener("pointerup", onUp);
2001
+ window.addEventListener("pointercancel", onUp);
2002
+ return () => {
2003
+ window.removeEventListener("pointermove", onMove);
2004
+ window.removeEventListener("pointerup", onUp);
2005
+ window.removeEventListener("pointercancel", onUp);
2006
+ };
2007
+ }, [setViewport, paneClickDistance, panOnDrag, onPaneClick, clearSelection]);
2008
+ const handleWheel = (e) => {
2009
+ if (!zoomOnScroll) return;
2010
+ e.preventDefault();
2011
+ const rect = containerRef.current?.getBoundingClientRect();
2012
+ if (!rect) return;
2013
+ const px = e.clientX - rect.left;
2014
+ const py = e.clientY - rect.top;
2015
+ const factor = Math.exp(-e.deltaY * 1e-3);
2016
+ const nextZoom = Math.max(minZoom, Math.min(maxZoom, viewport.zoom * factor));
2017
+ const k = nextZoom / viewport.zoom;
2018
+ setViewport({
2019
+ zoom: nextZoom,
2020
+ x: px - (px - viewport.x) * k,
2021
+ y: py - (py - viewport.y) * k
2022
+ });
2023
+ };
2024
+ const dispatch = useCallback(
2025
+ (a) => {
2026
+ if (a.type === "connection/start") {
2027
+ beginConnection(a.nodeId, a.handleId, a.handleType, a.pointerId, a.clientX, a.clientY);
2028
+ }
2029
+ },
2030
+ [beginConnection]
2031
+ );
2032
+ const reportDimensions = useCallback(
2033
+ (nodeId, width2, height2) => {
2034
+ const node = nodes.find((n) => n.id === nodeId);
2035
+ if (!node) return;
2036
+ if (node.width === width2 && node.height === height2) return;
2037
+ onNodesChange?.([change.node.dimensions(nodeId, { width: width2, height: height2 })]);
2038
+ },
2039
+ [nodes, onNodesChange]
2040
+ );
2041
+ const deleteNodeImpl = useCallback(
2042
+ (nodeId) => {
2043
+ const incidentEdgeIds = edgesRef.current.filter((e) => e.source === nodeId || e.target === nodeId).map((e) => e.id);
2044
+ if (incidentEdgeIds.length > 0) {
2045
+ onEdgesChange?.(incidentEdgeIds.map((id) => change.edge.remove(id)));
2046
+ }
2047
+ onNodesChange?.([change.node.remove(nodeId)]);
2048
+ },
2049
+ [onNodesChange, onEdgesChange]
2050
+ );
2051
+ const instance = useMemo2(
2052
+ () => ({
2053
+ // viewport
2054
+ getViewport: () => viewportRef.current,
2055
+ setViewport: (vp) => setViewport(vp),
2056
+ setCenter: (x, y, opts) => {
2057
+ const z = opts?.zoom ?? viewportRef.current.zoom;
2058
+ const rect = containerRef.current?.getBoundingClientRect();
2059
+ if (!rect) return;
2060
+ setViewport({
2061
+ zoom: z,
2062
+ x: rect.width / 2 - x * z,
2063
+ y: rect.height / 2 - y * z
2064
+ });
2065
+ },
2066
+ fitView: async (opts) => {
2067
+ const rect = containerRef.current?.getBoundingClientRect();
2068
+ if (!rect) return false;
2069
+ const padding = opts?.padding ?? 80;
2070
+ const targetNodes = opts?.nodes ? nodesRef.current.filter((n) => opts.nodes.some((x) => x.id === n.id)) : nodesRef.current.filter((n) => !n.hidden);
2071
+ if (targetNodes.length === 0) return false;
2072
+ let minX = Number.POSITIVE_INFINITY;
2073
+ let minY = Number.POSITIVE_INFINITY;
2074
+ let maxX = Number.NEGATIVE_INFINITY;
2075
+ let maxY = Number.NEGATIVE_INFINITY;
2076
+ for (const n of targetNodes) {
2077
+ const w = n.width ?? DEFAULT_NODE_WIDTH;
2078
+ const h = effectiveHeight(n);
2079
+ if (n.position.x < minX) minX = n.position.x;
2080
+ if (n.position.y < minY) minY = n.position.y;
2081
+ if (n.position.x + w > maxX) maxX = n.position.x + w;
2082
+ if (n.position.y + h > maxY) maxY = n.position.y + h;
2083
+ }
2084
+ const cw = maxX - minX;
2085
+ const ch = maxY - minY;
2086
+ const zx = (rect.width - padding * 2) / cw;
2087
+ const zy = (rect.height - padding * 2) / ch;
2088
+ const zoom = Math.max(
2089
+ opts?.minZoom ?? 0.25,
2090
+ Math.min(opts?.maxZoom ?? 1.5, Math.min(zx, zy))
2091
+ );
2092
+ setViewport({
2093
+ zoom,
2094
+ x: rect.width / 2 - (minX + maxX) / 2 * zoom,
2095
+ y: rect.height / 2 - (minY + maxY) / 2 * zoom
2096
+ });
2097
+ return true;
2098
+ },
2099
+ zoomIn: (opts) => {
2100
+ const step = opts?.step ?? 0.2;
2101
+ const next = Math.min(maxZoom, viewportRef.current.zoom * (1 + step));
2102
+ setViewport({ ...viewportRef.current, zoom: next });
2103
+ },
2104
+ zoomOut: (opts) => {
2105
+ const step = opts?.step ?? 0.2;
2106
+ const next = Math.max(minZoom, viewportRef.current.zoom / (1 + step));
2107
+ setViewport({ ...viewportRef.current, zoom: next });
2108
+ },
2109
+ zoomTo: (level) => {
2110
+ setViewport({
2111
+ ...viewportRef.current,
2112
+ zoom: Math.max(minZoom, Math.min(maxZoom, level))
2113
+ });
2114
+ },
2115
+ // transforms
2116
+ screenToFlowPosition: (p) => screenToFlow(p, viewportRef.current),
2117
+ flowToScreenPosition: (p) => flowToScreen(p, viewportRef.current),
2118
+ // reads
2119
+ getNodes: () => nodesRef.current.slice(),
2120
+ getEdges: () => edgesRef.current.slice(),
2121
+ getNode: (id) => nodesRef.current.find((n) => n.id === id),
2122
+ getEdge: (id) => edgesRef.current.find((e) => e.id === id),
2123
+ getNodesBounds: (subset) => {
2124
+ const pool = subset ? nodesRef.current.filter((n) => subset.some((x) => x.id === n.id)) : nodesRef.current.filter((n) => !n.hidden);
2125
+ if (pool.length === 0) return { x: 0, y: 0, width: 0, height: 0 };
2126
+ let minX = Number.POSITIVE_INFINITY;
2127
+ let minY = Number.POSITIVE_INFINITY;
2128
+ let maxX = Number.NEGATIVE_INFINITY;
2129
+ let maxY = Number.NEGATIVE_INFINITY;
2130
+ for (const n of pool) {
2131
+ const w = n.width ?? DEFAULT_NODE_WIDTH;
2132
+ const h = effectiveHeight(n);
2133
+ minX = Math.min(minX, n.position.x);
2134
+ minY = Math.min(minY, n.position.y);
2135
+ maxX = Math.max(maxX, n.position.x + w);
2136
+ maxY = Math.max(maxY, n.position.y + h);
2137
+ }
2138
+ return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
2139
+ },
2140
+ getIntersectingNodes: (area, partially = true) => {
2141
+ return nodesRef.current.filter((n) => {
2142
+ if (n.hidden) return false;
2143
+ const w = n.width ?? DEFAULT_NODE_WIDTH;
2144
+ const h = effectiveHeight(n);
2145
+ if (partially) {
2146
+ return n.position.x < area.x + area.width && n.position.x + w > area.x && n.position.y < area.y + area.height && n.position.y + h > area.y;
2147
+ }
2148
+ return n.position.x >= area.x && n.position.y >= area.y && n.position.x + w <= area.x + area.width && n.position.y + h <= area.y + area.height;
2149
+ });
2150
+ },
2151
+ // mutations
2152
+ addNodes: (nodes2) => {
2153
+ const arr = Array.isArray(nodes2) ? nodes2 : [nodes2];
2154
+ onNodesChangeRefForInstance.current?.(arr.map((item) => change.node.add(item)));
2155
+ },
2156
+ addEdges: (edges2) => {
2157
+ const arr = Array.isArray(edges2) ? edges2 : [edges2];
2158
+ onEdgesChangeRefForInstance.current?.(arr.map((item) => change.edge.add(item)));
2159
+ },
2160
+ updateNodeData: (id, partial) => {
2161
+ const cur = nodesRef.current.find((n) => n.id === id);
2162
+ if (!cur) return;
2163
+ const nextData = { ...cur.data ?? {}, ...partial };
2164
+ onNodesChangeRefForInstance.current?.([
2165
+ change.node.replace(id, { ...cur, data: nextData })
2166
+ ]);
2167
+ },
2168
+ updateNode: (id, partial) => {
2169
+ const cur = nodesRef.current.find((n) => n.id === id);
2170
+ if (!cur) return;
2171
+ onNodesChangeRefForInstance.current?.([change.node.replace(id, { ...cur, ...partial })]);
2172
+ },
2173
+ deleteElements: async ({ nodes: ns, edges: es }) => {
2174
+ const nodesToDelete = (ns ?? []).map((x) => nodesRef.current.find((n) => n.id === x.id)).filter((n) => !!n);
2175
+ const edgesToDelete = (es ?? []).map((x) => edgesRef.current.find((e) => e.id === x.id)).filter((e) => !!e);
2176
+ const before = onBeforeDeleteRef.current;
2177
+ if (before) {
2178
+ const ok = await before({ nodes: nodesToDelete, edges: edgesToDelete });
2179
+ if (!ok) return false;
2180
+ }
2181
+ if (nodesToDelete.length > 0) {
2182
+ onNodesChangeRefForInstance.current?.(nodesToDelete.map((n) => change.node.remove(n.id)));
2183
+ }
2184
+ if (edgesToDelete.length > 0) {
2185
+ onEdgesChangeRefForInstance.current?.(edgesToDelete.map((e) => change.edge.remove(e.id)));
2186
+ }
2187
+ return true;
2188
+ }
2189
+ }),
2190
+ [setViewport, minZoom, maxZoom]
2191
+ );
2192
+ const initFiredRef = useRef4(false);
2193
+ useEffect4(() => {
2194
+ if (initFiredRef.current) return;
2195
+ initFiredRef.current = true;
2196
+ onInit?.(instance);
2197
+ }, [instance, onInit]);
2198
+ useEffect4(() => {
2199
+ const onKey = (e) => {
2200
+ if (e.key !== "Backspace" && e.key !== "Delete") return;
2201
+ const target = e.target;
2202
+ if (target && (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.tagName === "SELECT" || target.isContentEditable)) {
2203
+ return;
2204
+ }
2205
+ if (!containerRef.current?.contains(target) && document.activeElement !== document.body) {
2206
+ return;
2207
+ }
2208
+ const sel = store.getSnapshot();
2209
+ if (sel.selectedNodeIds.size === 0 && sel.selectedEdgeIds.size === 0) return;
2210
+ e.preventDefault();
2211
+ void instance.deleteElements({
2212
+ nodes: Array.from(sel.selectedNodeIds, (id) => ({ id })),
2213
+ edges: Array.from(sel.selectedEdgeIds, (id) => ({ id }))
2214
+ });
2215
+ };
2216
+ window.addEventListener("keydown", onKey);
2217
+ return () => window.removeEventListener("keydown", onKey);
2218
+ }, [instance, store]);
2219
+ const bridge = useMemo2(
2220
+ () => ({
2221
+ beginNodeDrag,
2222
+ selectNode,
2223
+ selectEdge,
2224
+ reportDimensions,
2225
+ deleteNode: deleteNodeImpl
2226
+ }),
2227
+ [beginNodeDrag, selectNode, selectEdge, reportDimensions, deleteNodeImpl]
2228
+ );
2229
+ const [panGesture, setPanGesture] = useState2(false);
2230
+ const isEmpty = nodes.length === 0 && edges.length === 0;
2231
+ const isConnecting = conn !== null;
2232
+ const visibleNodes = useMemo2(() => nodes.filter((n) => !n.hidden), [nodes]);
2233
+ const visibleEdges = useMemo2(() => {
2234
+ if (visibleNodes.length === nodes.length) return edges;
2235
+ const visibleIds = new Set(visibleNodes.map((n) => n.id));
2236
+ return edges.filter((e) => visibleIds.has(e.source) && visibleIds.has(e.target));
2237
+ }, [edges, nodes, visibleNodes]);
2238
+ const orderedNodes = useMemo2(() => {
2239
+ const isContainer = (n) => n.type === "group" || n.type === "forEach";
2240
+ const depth = (n) => {
2241
+ let d = 0;
2242
+ let cursor = n.parentId;
2243
+ const seen = /* @__PURE__ */ new Set();
2244
+ while (cursor) {
2245
+ if (seen.has(cursor)) return Number.POSITIVE_INFINITY;
2246
+ seen.add(cursor);
2247
+ d++;
2248
+ cursor = visibleNodes.find((x) => x.id === cursor)?.parentId;
2249
+ }
2250
+ return d;
2251
+ };
2252
+ const containers = visibleNodes.filter(isContainer);
2253
+ const others = visibleNodes.filter((n) => !isContainer(n));
2254
+ containers.sort((a, b) => depth(a) - depth(b));
2255
+ return [...containers, ...others];
2256
+ }, [visibleNodes]);
2257
+ return /* @__PURE__ */ jsx6(FlowStoreContext.Provider, { value: store, children: /* @__PURE__ */ jsx6(FlowInstanceContext.Provider, { value: instance, children: /* @__PURE__ */ jsx6(HandleRegistryContext.Provider, { value: handleRegistry, children: /* @__PURE__ */ jsx6(FlowDispatchContext.Provider, { value: dispatch, children: /* @__PURE__ */ jsx6(FlowNodeBridgeContext.Provider, { value: bridge, children: /* @__PURE__ */ jsxs5(
2258
+ "div",
2259
+ {
2260
+ ref: containerRef,
2261
+ className: cn(
2262
+ "ods-flow-canvas-v2",
2263
+ panGesture && "ods-flow-canvas-v2--panning",
2264
+ isConnecting && "ods-flow-canvas-v2--connecting",
2265
+ draggingId && "ods-flow-canvas-v2--dragging",
2266
+ className
2267
+ ),
2268
+ style: {
2269
+ position: "relative",
2270
+ width,
2271
+ height,
2272
+ overflow: "hidden",
2273
+ userSelect: "none",
2274
+ touchAction: "none",
2275
+ // Cursor: state-driven so it flips instantly with the
2276
+ // gesture. CSS `:active` would lag behind pointer-capture.
2277
+ cursor: panGesture ? "grabbing" : isConnecting ? "crosshair" : panOnDrag ? "grab" : "default",
2278
+ ...style
2279
+ },
2280
+ onPointerDown: onCanvasPointerDown,
2281
+ onWheel: handleWheel,
2282
+ onContextMenu: (e) => {
2283
+ const t = e.target;
2284
+ const nodeEl = t.closest("[data-node-id]");
2285
+ if (nodeEl && onNodeContextMenu) {
2286
+ const id = nodeEl.dataset.nodeId;
2287
+ const node = nodes.find((n) => n.id === id);
2288
+ if (node) onNodeContextMenu(e, node);
2289
+ return;
2290
+ }
2291
+ const edgeEl = t.closest("[data-edge-id]");
2292
+ if (edgeEl && onEdgeContextMenu) {
2293
+ const id = edgeEl.dataset.edgeId;
2294
+ const edge = edges.find((x) => x.id === id);
2295
+ if (edge) onEdgeContextMenu(e, edge);
2296
+ return;
2297
+ }
2298
+ onPaneContextMenu?.(e);
2299
+ },
2300
+ "data-empty": isEmpty ? "true" : void 0,
2301
+ children: [
2302
+ background !== "none" && /* @__PURE__ */ jsx6(
2303
+ "div",
2304
+ {
2305
+ className: cn(
2306
+ "ods-flow-canvas-v2__grid",
2307
+ `ods-flow-canvas-v2__grid--${background}`
2308
+ ),
2309
+ style: {
2310
+ // Custom property drives the four variants' SCSS.
2311
+ "--ods-flow-grid-size": `${gridSize * viewport.zoom}px`,
2312
+ backgroundPosition: `${viewport.x}px ${viewport.y}px`
2313
+ }
2314
+ }
2315
+ ),
2316
+ /* @__PURE__ */ jsxs5(
2317
+ "div",
2318
+ {
2319
+ className: "ods-flow-canvas-v2__viewport",
2320
+ style: {
2321
+ position: "absolute",
2322
+ inset: 0,
2323
+ transform: `translate(${viewport.x}px, ${viewport.y}px) scale(${viewport.zoom})`,
2324
+ transformOrigin: "0 0"
2325
+ },
2326
+ children: [
2327
+ /* @__PURE__ */ jsx6(
2328
+ EdgesLayer,
2329
+ {
2330
+ edges: visibleEdges,
2331
+ nodes: visibleNodes,
2332
+ onSelect: (id) => bridge.selectEdge(id, false),
2333
+ onDelete: (id) => onEdgesChangeRef(id, onEdgesChange),
2334
+ onLabelChange: onEdgeLabelChange,
2335
+ ghost: conn ? { start: conn.start, end: conn.end } : null,
2336
+ handleVersion
2337
+ }
2338
+ ),
2339
+ orderedNodes.map((node) => {
2340
+ const Kind = kinds[node.type] ?? kinds.action;
2341
+ if (!Kind) return null;
2342
+ return /* @__PURE__ */ jsx6(
2343
+ FlowNode,
2344
+ {
2345
+ node,
2346
+ selected: selectedNodeIds.has(node.id),
2347
+ dragging: draggingId === node.id,
2348
+ isConnecting,
2349
+ Kind
2350
+ },
2351
+ node.id
2352
+ );
2353
+ })
2354
+ ]
2355
+ }
2356
+ ),
2357
+ isEmpty && emptyState && /* @__PURE__ */ jsx6("div", { className: "ods-flow-canvas-v2__empty", children: emptyState }),
2358
+ children
2359
+ ]
2360
+ }
2361
+ ) }) }) }) }) });
2362
+ }
2363
+ function onEdgesChangeRef(id, cb) {
2364
+ cb?.([change.edge.remove(id)]);
2365
+ }
2366
+ var EdgesLayer = memo2(function EdgesLayer2({
2367
+ edges,
2368
+ nodes,
2369
+ onSelect,
2370
+ onDelete,
2371
+ onLabelChange,
2372
+ ghost,
2373
+ handleVersion: _handleVersion
2374
+ }) {
2375
+ return /* @__PURE__ */ jsxs5(
2376
+ "svg",
2377
+ {
2378
+ className: "ods-flow-canvas-v2__edges",
2379
+ style: { position: "absolute", inset: 0, overflow: "visible", pointerEvents: "none" },
2380
+ width: "100%",
2381
+ height: "100%",
2382
+ children: [
2383
+ /* @__PURE__ */ jsx6("g", { style: { pointerEvents: "auto" }, children: edges.map((edge) => /* @__PURE__ */ jsx6(
2384
+ FlowEdge,
2385
+ {
2386
+ edge,
2387
+ nodes,
2388
+ onSelect,
2389
+ onDelete,
2390
+ onLabelChange,
2391
+ handleVersion: _handleVersion
2392
+ },
2393
+ edge.id
2394
+ )) }),
2395
+ ghost && /* @__PURE__ */ jsx6(
2396
+ "path",
2397
+ {
2398
+ d: `M ${ghost.start.x} ${ghost.start.y} L ${ghost.end.x} ${ghost.end.y}`,
2399
+ stroke: "var(--ods-accent, #4f46e5)",
2400
+ strokeWidth: 1.5,
2401
+ strokeDasharray: "4 4",
2402
+ fill: "none"
2403
+ }
2404
+ )
2405
+ ]
2406
+ }
2407
+ );
2408
+ });
2409
+
2410
+ export {
2411
+ useFlow,
2412
+ applyNodeChanges,
2413
+ applyEdgeChanges,
2414
+ change,
2415
+ useFlowStore,
2416
+ DEFAULT_NODE_WIDTH,
2417
+ DEFAULT_NODE_HEIGHT,
2418
+ handleCentre,
2419
+ bezierPath,
2420
+ screenToFlow,
2421
+ flowToScreen,
2422
+ descendantsOf,
2423
+ findAncestor,
2424
+ clampToParentExtent,
2425
+ findContainingGroup,
2426
+ buildEdgePath,
2427
+ bezierPath2,
2428
+ stepPath,
2429
+ smoothStepPath,
2430
+ straightPath,
2431
+ FlowEdge,
2432
+ useFlowNodeContext,
2433
+ FlowNode,
2434
+ buildNodeKindRegistry,
2435
+ Handle,
2436
+ ActionNode,
2437
+ TriggerNode,
2438
+ ConditionNode,
2439
+ GroupNode,
2440
+ ForEachNode,
2441
+ OutputNode,
2442
+ ErrorNode,
2443
+ WaitNode,
2444
+ ParallelNode,
2445
+ StickyNode,
2446
+ WebhookNode,
2447
+ HttpRequestNode,
2448
+ DEFAULT_NODE_KINDS,
2449
+ FlowCanvas
2450
+ };
2451
+ //# sourceMappingURL=chunk-YW6ZOYCG.js.map