@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,2546 @@
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 = 368;
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 rawStart = handleCentre(sourceNode, sourceSide, sourceIndex, sourceTotal);
558
+ const rawEnd = handleCentre(targetNode, targetSide, targetIndex, targetTotal);
559
+ const HANDLE_GAP = 8;
560
+ const start = offsetAlongSide2(rawStart, sourceSide, HANDLE_GAP);
561
+ const end = offsetAlongSide2(rawEnd, targetSide, HANDLE_GAP);
562
+ const routing = edge.routing ?? "bezier";
563
+ const { d, midX, midY } = buildEdgePath(routing, start, sourceSide, end, targetSide, {
564
+ curvature,
565
+ borderRadius
566
+ });
567
+ const { d: hitD } = buildEdgePath(routing, rawStart, sourceSide, rawEnd, targetSide, {
568
+ curvature,
569
+ borderRadius
570
+ });
571
+ const type = edge.type ?? "default";
572
+ const isHot = hovered || edge.selected;
573
+ const stroke = type === "error" ? "var(--ods-status-failed, #dc2626)" : isHot ? "var(--ods-accent, #4f46e5)" : "var(--ods-border-strong, #6b7280)";
574
+ const typeDash = type === "conditional" ? "6 4" : type === "loop" ? "4 4" : void 0;
575
+ const dash = edge.style?.strokeDasharray ?? typeDash;
576
+ const strokeWidth = edge.style?.strokeWidth ?? (isHot ? 2 : 1.4);
577
+ const animateDash = edge.animated === true;
578
+ const label = edge.label;
579
+ const hasDelete = showDelete && (isHot || edge.selected) && !!onDelete;
580
+ const showChrome = !!label || editing || hasDelete;
581
+ const commitLabel = (next) => {
582
+ setEditing(false);
583
+ if (next !== edge.label) onLabelChange?.(edge.id, next);
584
+ };
585
+ const onLabelKey = (e) => {
586
+ if (e.key === "Enter") {
587
+ e.preventDefault();
588
+ commitLabel(draftLabel);
589
+ } else if (e.key === "Escape") {
590
+ e.preventDefault();
591
+ setEditing(false);
592
+ setDraftLabel(edge.label ?? "");
593
+ }
594
+ };
595
+ return /* @__PURE__ */ jsxs(
596
+ "g",
597
+ {
598
+ className: cn(
599
+ "ods-flow-edge-v2",
600
+ `ods-flow-edge-v2--${type}`,
601
+ `ods-flow-edge-v2--routing-${routing}`,
602
+ edge.selected && "ods-flow-edge-v2--selected",
603
+ hovered && "ods-flow-edge-v2--hovered",
604
+ edge.className
605
+ ),
606
+ "data-edge-id": edge.id,
607
+ "data-edge-routing": routing,
608
+ onMouseEnter: () => setHovered(true),
609
+ onMouseLeave: () => setHovered(false),
610
+ onClick: (e) => {
611
+ e.stopPropagation();
612
+ onSelect?.(edge.id);
613
+ },
614
+ children: [
615
+ /* @__PURE__ */ jsx("defs", { children: /* @__PURE__ */ jsx(
616
+ "marker",
617
+ {
618
+ id: markerId,
619
+ viewBox: "0 0 10 10",
620
+ refX: "9",
621
+ refY: "5",
622
+ markerWidth: "7",
623
+ markerHeight: "7",
624
+ orient: "auto-start-reverse",
625
+ children: /* @__PURE__ */ jsx("path", { d: "M0 0L10 5L0 10z", fill: stroke })
626
+ }
627
+ ) }),
628
+ /* @__PURE__ */ jsx("path", { d: hitD, stroke: "transparent", strokeWidth: 20, fill: "none" }),
629
+ /* @__PURE__ */ jsx(
630
+ "path",
631
+ {
632
+ d,
633
+ stroke,
634
+ strokeWidth,
635
+ strokeDasharray: dash,
636
+ fill: "none",
637
+ markerEnd: `url(#${markerId})`,
638
+ style: animateDash ? {
639
+ strokeDasharray: dash ?? "6 4",
640
+ animation: "ods-flow-edge-flow 0.6s linear infinite"
641
+ } : void 0
642
+ }
643
+ ),
644
+ showChrome && /* @__PURE__ */ jsx(
645
+ "foreignObject",
646
+ {
647
+ x: midX - 140,
648
+ y: midY - 16,
649
+ width: 280,
650
+ height: 32,
651
+ style: { overflow: "visible", pointerEvents: "none" },
652
+ children: /* @__PURE__ */ jsxs("div", { className: "ods-flow-edge-v2__chrome", children: [
653
+ (label || editing) && (editing ? /* @__PURE__ */ jsx(
654
+ "input",
655
+ {
656
+ ref: inputRef,
657
+ className: "ods-flow-edge-v2__label-input",
658
+ value: draftLabel,
659
+ autoFocus: true,
660
+ onChange: (e) => setDraftLabel(e.target.value),
661
+ onBlur: () => commitLabel(draftLabel),
662
+ onKeyDown: onLabelKey,
663
+ onClick: (e) => e.stopPropagation(),
664
+ onMouseDown: (e) => e.stopPropagation(),
665
+ "aria-label": "Edit edge label"
666
+ }
667
+ ) : /* @__PURE__ */ jsx(
668
+ "button",
669
+ {
670
+ type: "button",
671
+ className: "ods-flow-edge-v2__label-chip",
672
+ onDoubleClick: (e) => {
673
+ if (!onLabelChange) return;
674
+ e.stopPropagation();
675
+ setDraftLabel(edge.label ?? "");
676
+ setEditing(true);
677
+ },
678
+ onClick: (e) => {
679
+ e.stopPropagation();
680
+ onSelect?.(edge.id);
681
+ },
682
+ title: onLabelChange ? "Double-click to edit" : void 0,
683
+ tabIndex: onLabelChange ? 0 : -1,
684
+ children: /* @__PURE__ */ jsx("span", { children: label })
685
+ }
686
+ )),
687
+ hasDelete && /* @__PURE__ */ jsx(
688
+ "button",
689
+ {
690
+ type: "button",
691
+ className: "ods-flow-edge-v2__delete-btn",
692
+ onClick: (e) => {
693
+ e.stopPropagation();
694
+ onDelete?.(edge.id);
695
+ },
696
+ "aria-label": "Delete edge",
697
+ children: /* @__PURE__ */ jsx("svg", { width: "10", height: "10", viewBox: "0 0 10 10", "aria-hidden": "true", children: /* @__PURE__ */ jsx(
698
+ "path",
699
+ {
700
+ d: "M2 2l6 6M8 2l-6 6",
701
+ stroke: "currentColor",
702
+ strokeWidth: 1.5,
703
+ strokeLinecap: "round"
704
+ }
705
+ ) })
706
+ }
707
+ )
708
+ ] })
709
+ }
710
+ )
711
+ ]
712
+ }
713
+ );
714
+ }
715
+ function offsetAlongSide2(p, side, gap) {
716
+ switch (side) {
717
+ case "top":
718
+ return { x: p.x, y: p.y - gap };
719
+ case "bottom":
720
+ return { x: p.x, y: p.y + gap };
721
+ case "left":
722
+ return { x: p.x - gap, y: p.y };
723
+ case "right":
724
+ return { x: p.x + gap, y: p.y };
725
+ }
726
+ }
727
+ var FlowEdge = memo(FlowEdgeImpl, (prev, next) => {
728
+ if (prev.edge !== next.edge) return false;
729
+ if (prev.onSelect !== next.onSelect || prev.onDelete !== next.onDelete) return false;
730
+ if (prev.onLabelChange !== next.onLabelChange) return false;
731
+ if (prev.showDelete !== next.showDelete) return false;
732
+ if (prev.curvature !== next.curvature || prev.borderRadius !== next.borderRadius) return false;
733
+ if (prev.handleVersion !== next.handleVersion) return false;
734
+ const ps = prev.nodes.find((n) => n.id === prev.edge.source);
735
+ const pt = prev.nodes.find((n) => n.id === prev.edge.target);
736
+ const ns = next.nodes.find((n) => n.id === next.edge.source);
737
+ const nt = next.nodes.find((n) => n.id === next.edge.target);
738
+ if (ps !== ns || pt !== nt) return false;
739
+ return true;
740
+ });
741
+
742
+ // src/workflow/components/FlowNode/FlowNodeContext.tsx
743
+ import { createContext as createContext3, useContext as useContext3 } from "react";
744
+ var FlowNodeContext = createContext3(null);
745
+ function useFlowNodeContext() {
746
+ const v = useContext3(FlowNodeContext);
747
+ if (!v) {
748
+ throw new Error(
749
+ "[@octaviaflow/core/workflow] Handle / NodeToolbar must be inside a node renderer."
750
+ );
751
+ }
752
+ return v;
753
+ }
754
+
755
+ // src/workflow/components/FlowNode/FlowNode.tsx
756
+ import { useEffect as useEffect2, useMemo, useRef as useRef2 } from "react";
757
+
758
+ // src/workflow/components/FlowCanvas/FlowCanvasContext.tsx
759
+ import { createContext as createContext4, useContext as useContext4 } from "react";
760
+ var FlowDispatchContext = createContext4(null);
761
+ function useFlowDispatch() {
762
+ const dispatch = useContext4(FlowDispatchContext);
763
+ if (!dispatch) {
764
+ throw new Error(
765
+ "[@octaviaflow/core/workflow] useFlowDispatch must be called inside <FlowCanvas>."
766
+ );
767
+ }
768
+ return dispatch;
769
+ }
770
+ var FlowNodeBridgeContext = createContext4(null);
771
+ function useFlowNodeBridge() {
772
+ const b = useContext4(FlowNodeBridgeContext);
773
+ if (!b) {
774
+ throw new Error("[@octaviaflow/core/workflow] FlowNode must be a child of <FlowCanvas>.");
775
+ }
776
+ return b;
777
+ }
778
+
779
+ // src/workflow/components/FlowNode/FlowNode.tsx
780
+ import { jsx as jsx2 } from "react/jsx-runtime";
781
+ function FlowNode({
782
+ node,
783
+ selected,
784
+ dragging,
785
+ isConnecting,
786
+ Kind,
787
+ // Match the BaseNode body's fixed 368 px width so the wrapper bbox and
788
+ // the rendered card line up on the first paint — before the
789
+ // ResizeObserver has had a chance to write back the measured size.
790
+ // Container kinds (group / forEach) opt out by setting `node.width`.
791
+ defaultWidth = 368
792
+ }) {
793
+ const bridge = useFlowNodeBridge();
794
+ const wrapperRef = useRef2(null);
795
+ useEffect2(() => {
796
+ const el = wrapperRef.current;
797
+ if (!el || typeof ResizeObserver === "undefined") return;
798
+ if (node.type === "group" || node.type === "forEach") return;
799
+ const ro = new ResizeObserver(() => {
800
+ bridge.reportDimensions(node.id, el.offsetWidth, el.offsetHeight);
801
+ });
802
+ ro.observe(el);
803
+ return () => ro.disconnect();
804
+ }, [bridge, node.id, node.type]);
805
+ const ctx = useMemo(
806
+ () => ({ id: node.id, node, selected }),
807
+ [node, selected]
808
+ );
809
+ const downPosRef = useRef2(null);
810
+ const draggedRef = useRef2(false);
811
+ const CLICK_VS_DRAG_PX = 5;
812
+ const handlePointerDown = (e) => {
813
+ if (e.target.closest("[data-handle-id]")) return;
814
+ if (e.target.closest("[data-flow-no-drag='true']")) return;
815
+ e.stopPropagation();
816
+ downPosRef.current = { x: e.clientX, y: e.clientY };
817
+ draggedRef.current = false;
818
+ bridge.beginNodeDrag(node.id, e.pointerId, e.clientX, e.clientY, e.altKey);
819
+ };
820
+ const handlePointerMove = (e) => {
821
+ const start = downPosRef.current;
822
+ if (!start || draggedRef.current) return;
823
+ if (Math.abs(e.clientX - start.x) > CLICK_VS_DRAG_PX || Math.abs(e.clientY - start.y) > CLICK_VS_DRAG_PX) {
824
+ draggedRef.current = true;
825
+ }
826
+ };
827
+ const handleClick = (e) => {
828
+ if (e.target.closest("[data-handle-id]")) return;
829
+ e.stopPropagation();
830
+ if (draggedRef.current) {
831
+ draggedRef.current = false;
832
+ downPosRef.current = null;
833
+ return;
834
+ }
835
+ downPosRef.current = null;
836
+ bridge.selectNode(node.id, e.metaKey || e.ctrlKey || e.shiftKey);
837
+ bridge.notifyNodeClick(node.id);
838
+ };
839
+ return /* @__PURE__ */ jsx2(
840
+ "div",
841
+ {
842
+ ref: wrapperRef,
843
+ "data-node-id": node.id,
844
+ "data-node-type": node.type,
845
+ "data-node-selected": selected ? "true" : "false",
846
+ className: cn(
847
+ "ods-flow-node-v2",
848
+ `ods-flow-node-v2--kind-${node.type}`,
849
+ selected && "ods-flow-node-v2--selected",
850
+ dragging && "ods-flow-node-v2--dragging",
851
+ isConnecting && "ods-flow-node-v2--connecting",
852
+ node.className
853
+ ),
854
+ style: {
855
+ position: "absolute",
856
+ left: node.position.x,
857
+ top: node.position.y,
858
+ width: node.width ?? defaultWidth,
859
+ // Z-stack (per architecture doc): groups (20) sit below normal
860
+ // nodes (30) so children render visually on top of their parent
861
+ // frame. Selection raises by 10. Consumer override wins.
862
+ zIndex: node.zIndex ?? (selected ? node.type === "group" ? 35 : 40 : node.type === "group" ? 20 : 30),
863
+ ...node.style
864
+ },
865
+ onPointerDown: handlePointerDown,
866
+ onPointerMove: handlePointerMove,
867
+ onClick: handleClick,
868
+ children: /* @__PURE__ */ jsx2(FlowNodeContext.Provider, { value: ctx, children: /* @__PURE__ */ jsx2(Kind, { node, selected, dragging, isConnecting }) })
869
+ }
870
+ );
871
+ }
872
+
873
+ // src/workflow/components/FlowNode/nodeKinds.ts
874
+ function buildNodeKindRegistry(defaults, overrides) {
875
+ return Object.freeze({ ...defaults, ...overrides ?? {} });
876
+ }
877
+
878
+ // src/workflow/components/Handle/Handle.tsx
879
+ import { useEffect as useEffect3, useRef as useRef3 } from "react";
880
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
881
+ var DEFAULT_HANDLE_ID = "default";
882
+ function Handle({
883
+ type,
884
+ position,
885
+ id = DEFAULT_HANDLE_ID,
886
+ isConnectable = true,
887
+ isConnectableStart,
888
+ isConnectableEnd,
889
+ index = 0,
890
+ total = 1,
891
+ label,
892
+ className,
893
+ style
894
+ }) {
895
+ const registry = useHandleRegistry();
896
+ const node = useFlowNodeContext();
897
+ const dispatch = useFlowDispatch();
898
+ const ref = useRef3(null);
899
+ const canStart = isConnectableStart ?? isConnectable;
900
+ const canEnd = isConnectableEnd ?? isConnectable;
901
+ useEffect3(() => {
902
+ const dispose = registry.register({
903
+ nodeId: node.id,
904
+ handleId: id,
905
+ type,
906
+ side: position,
907
+ index,
908
+ total
909
+ });
910
+ return dispose;
911
+ }, [registry, node.id, id, type, position, index, total]);
912
+ const handlePointerDown = (e) => {
913
+ if (!canStart) return;
914
+ e.stopPropagation();
915
+ e.preventDefault();
916
+ dispatch({
917
+ type: "connection/start",
918
+ nodeId: node.id,
919
+ handleId: id,
920
+ handleType: type,
921
+ pointerId: e.pointerId,
922
+ clientX: e.clientX,
923
+ clientY: e.clientY
924
+ });
925
+ };
926
+ return /* @__PURE__ */ jsxs2(
927
+ "div",
928
+ {
929
+ ref,
930
+ "data-handle-id": id,
931
+ "data-handle-node-id": node.id,
932
+ "data-handle-type": type,
933
+ "data-handle-side": position,
934
+ "data-handle-connectable-end": canEnd ? "true" : "false",
935
+ className: cn(
936
+ "ods-flow-handle",
937
+ `ods-flow-handle--${type}`,
938
+ `ods-flow-handle--side-${position}`,
939
+ !isConnectable && "ods-flow-handle--disabled",
940
+ className
941
+ ),
942
+ style: {
943
+ ...handleSideStyle(position, index, total),
944
+ ...style
945
+ },
946
+ onPointerDown: handlePointerDown,
947
+ children: [
948
+ /* @__PURE__ */ jsx3("div", { className: "ods-flow-handle__dot" }),
949
+ label && /* @__PURE__ */ jsx3("span", { className: "ods-flow-handle__label", children: label })
950
+ ]
951
+ }
952
+ );
953
+ }
954
+ function handleSideStyle(side, index, total) {
955
+ const ratio = (index + 1) / (total + 1) * 100;
956
+ switch (side) {
957
+ case "top":
958
+ return { position: "absolute", top: -6, left: `${ratio}%`, transform: "translateX(-50%)" };
959
+ case "bottom":
960
+ return { position: "absolute", bottom: -6, left: `${ratio}%`, transform: "translateX(-50%)" };
961
+ case "left":
962
+ return { position: "absolute", left: -6, top: `${ratio}%`, transform: "translateY(-50%)" };
963
+ case "right":
964
+ return { position: "absolute", right: -6, top: `${ratio}%`, transform: "translateY(-50%)" };
965
+ }
966
+ }
967
+
968
+ // src/workflow/components/kinds/BaseNode.tsx
969
+ import { TrashCanIcon } from "@octaviaflow/icons";
970
+ import { useContext as useContext5 } from "react";
971
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
972
+ function BaseNode({
973
+ kind,
974
+ kindIcon,
975
+ icon,
976
+ title,
977
+ chip,
978
+ description,
979
+ accent = "green",
980
+ status,
981
+ onDelete,
982
+ footer,
983
+ className,
984
+ children
985
+ }) {
986
+ const ctx = useContext5(FlowNodeContext);
987
+ const bridge = useContext5(FlowNodeBridgeContext);
988
+ const deleteHandler = onDelete === false ? void 0 : onDelete ?? (ctx && bridge ? () => bridge.deleteNode(ctx.id) : void 0);
989
+ return /* @__PURE__ */ jsxs3(
990
+ "div",
991
+ {
992
+ className: cn(
993
+ "ods-flow-base-node",
994
+ `ods-flow-base-node--accent-${accent}`,
995
+ status && `ods-flow-base-node--status-${status}`,
996
+ className
997
+ ),
998
+ children: [
999
+ /* @__PURE__ */ jsxs3("div", { className: "ods-flow-base-node__pill", children: [
1000
+ kindIcon && /* @__PURE__ */ jsx4("span", { className: "ods-flow-base-node__pill-icon", "aria-hidden": "true", children: kindIcon }),
1001
+ /* @__PURE__ */ jsx4("span", { className: "ods-flow-base-node__pill-label", children: kind })
1002
+ ] }),
1003
+ status && status !== "idle" && /* @__PURE__ */ jsx4(
1004
+ "span",
1005
+ {
1006
+ className: cn("ods-flow-base-node__status", `ods-flow-base-node__status--${status}`),
1007
+ "aria-hidden": "true"
1008
+ }
1009
+ ),
1010
+ /* @__PURE__ */ jsxs3("div", { className: "ods-flow-base-node__body", children: [
1011
+ /* @__PURE__ */ jsxs3("div", { className: "ods-flow-base-node__content", children: [
1012
+ /* @__PURE__ */ jsx4("div", { className: "ods-flow-base-node__bubble", "aria-hidden": "true", children: icon }),
1013
+ /* @__PURE__ */ jsxs3("div", { className: "ods-flow-base-node__content-text", children: [
1014
+ /* @__PURE__ */ jsx4("div", { className: "ods-flow-base-node__content-title", children: title }),
1015
+ (chip !== void 0 || description !== void 0) && /* @__PURE__ */ jsxs3("div", { className: "ods-flow-base-node__content-info", children: [
1016
+ chip !== void 0 && /* @__PURE__ */ jsx4("span", { className: "ods-flow-base-node__chip", children: chip }),
1017
+ description !== void 0 && /* @__PURE__ */ jsx4("span", { className: "ods-flow-base-node__description", children: description })
1018
+ ] })
1019
+ ] })
1020
+ ] }),
1021
+ footer && /* @__PURE__ */ jsx4("div", { className: "ods-flow-base-node__footer", children: footer }),
1022
+ deleteHandler && /* @__PURE__ */ jsx4(
1023
+ "button",
1024
+ {
1025
+ type: "button",
1026
+ className: "ods-flow-base-node__delete",
1027
+ onClick: (e) => {
1028
+ e.stopPropagation();
1029
+ deleteHandler();
1030
+ },
1031
+ "aria-label": "Delete node",
1032
+ "data-flow-no-drag": "true",
1033
+ title: "Delete node",
1034
+ children: /* @__PURE__ */ jsx4(TrashCanIcon, { size: 16, "aria-hidden": true })
1035
+ }
1036
+ )
1037
+ ] }),
1038
+ children
1039
+ ]
1040
+ }
1041
+ );
1042
+ }
1043
+
1044
+ // src/workflow/components/kinds/index.tsx
1045
+ import { Fragment, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
1046
+ var ActionNode = ({
1047
+ node
1048
+ }) => {
1049
+ const d = node.data ?? {};
1050
+ return /* @__PURE__ */ jsxs4(
1051
+ BaseNode,
1052
+ {
1053
+ kind: d.kind ?? "ACTION",
1054
+ icon: d.icon,
1055
+ title: d.title ?? "Action",
1056
+ chip: d.chip ?? d.badge,
1057
+ description: d.description ?? d.subtitle,
1058
+ status: d.status,
1059
+ accent: "green",
1060
+ children: [
1061
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" }),
1062
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom" })
1063
+ ]
1064
+ }
1065
+ );
1066
+ };
1067
+ var TriggerNode = ({
1068
+ node
1069
+ }) => {
1070
+ const d = node.data ?? {};
1071
+ return /* @__PURE__ */ jsx5(
1072
+ BaseNode,
1073
+ {
1074
+ kind: d.kind ?? "TRIGGER",
1075
+ icon: d.icon,
1076
+ title: d.title ?? "Trigger",
1077
+ chip: d.chip,
1078
+ description: d.description ?? "Manually triggered",
1079
+ status: d.status,
1080
+ accent: "green",
1081
+ children: /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom" })
1082
+ }
1083
+ );
1084
+ };
1085
+ var ConditionNode = ({
1086
+ node
1087
+ }) => {
1088
+ const d = node.data ?? {};
1089
+ const branches = d.branches ?? [
1090
+ { id: "true", label: "true" },
1091
+ { id: "false", label: "false" }
1092
+ ];
1093
+ return /* @__PURE__ */ jsxs4(
1094
+ BaseNode,
1095
+ {
1096
+ kind: d.kind ?? "CONDITION",
1097
+ icon: d.icon,
1098
+ title: d.title ?? "Condition",
1099
+ chip: d.chip ?? d.badge,
1100
+ description: d.description ?? d.subtitle,
1101
+ status: d.status,
1102
+ accent: "amber",
1103
+ children: [
1104
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" }),
1105
+ branches.map((b, i) => /* @__PURE__ */ jsx5(
1106
+ Handle,
1107
+ {
1108
+ type: "source",
1109
+ position: "bottom",
1110
+ id: b.id,
1111
+ index: i,
1112
+ total: branches.length,
1113
+ label: b.label
1114
+ },
1115
+ b.id
1116
+ ))
1117
+ ]
1118
+ }
1119
+ );
1120
+ };
1121
+ var GroupNode = ({
1122
+ node
1123
+ }) => {
1124
+ const d = node.data ?? {};
1125
+ const collapsed = !!d.collapsed;
1126
+ const hiddenCount = d.hiddenCount;
1127
+ const bridge = useFlowNodeBridge();
1128
+ const onChevronClick = (e) => {
1129
+ e.stopPropagation();
1130
+ bridge.toggleNodeCollapse(node.id);
1131
+ };
1132
+ return /* @__PURE__ */ jsxs4(
1133
+ "div",
1134
+ {
1135
+ className: "ods-flow-group",
1136
+ "data-collapsed": collapsed ? "true" : "false",
1137
+ style: {
1138
+ width: node.width ?? 360,
1139
+ height: collapsed ? 36 : node.height ?? 200
1140
+ },
1141
+ children: [
1142
+ /* @__PURE__ */ jsxs4("div", { className: "ods-flow-group__header", "data-flow-no-drag": "false", children: [
1143
+ /* @__PURE__ */ jsx5(
1144
+ "button",
1145
+ {
1146
+ type: "button",
1147
+ className: "ods-flow-group__chevron",
1148
+ "data-flow-no-drag": "true",
1149
+ "aria-label": collapsed ? "Expand group" : "Collapse group",
1150
+ "aria-expanded": !collapsed,
1151
+ onClick: onChevronClick,
1152
+ onPointerDown: (e) => e.stopPropagation(),
1153
+ children: collapsed ? "\u25B8" : "\u25BE"
1154
+ }
1155
+ ),
1156
+ /* @__PURE__ */ jsx5("span", { className: "ods-flow-group__title", children: d.title ?? "Group" }),
1157
+ d.subtitle && /* @__PURE__ */ jsx5("span", { className: "ods-flow-group__subtitle", children: d.subtitle }),
1158
+ collapsed && hiddenCount !== void 0 && hiddenCount > 0 && /* @__PURE__ */ jsxs4("span", { className: "ods-flow-group__count", "aria-label": `${hiddenCount} hidden steps`, children: [
1159
+ hiddenCount,
1160
+ " steps"
1161
+ ] })
1162
+ ] }),
1163
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top", id: "__group_in" }),
1164
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom", id: "__group_out" })
1165
+ ]
1166
+ }
1167
+ );
1168
+ };
1169
+ var ForEachNode = ({
1170
+ node
1171
+ }) => {
1172
+ const d = node.data ?? {};
1173
+ const iteratorExpr = d.iterator ?? d.description ?? "items[]";
1174
+ const collapsed = !!d.collapsed;
1175
+ const hiddenCount = d.hiddenCount;
1176
+ const bridge = useFlowNodeBridge();
1177
+ const onChevronClick = (e) => {
1178
+ e.stopPropagation();
1179
+ bridge.toggleNodeCollapse(node.id);
1180
+ };
1181
+ return /* @__PURE__ */ jsxs4(
1182
+ "div",
1183
+ {
1184
+ className: "ods-flow-foreach",
1185
+ "data-collapsed": collapsed ? "true" : "false",
1186
+ style: {
1187
+ width: node.width ?? 420,
1188
+ height: collapsed ? 40 : node.height ?? 260
1189
+ },
1190
+ children: [
1191
+ /* @__PURE__ */ jsxs4("div", { className: "ods-flow-foreach__header", children: [
1192
+ /* @__PURE__ */ jsx5(
1193
+ "button",
1194
+ {
1195
+ type: "button",
1196
+ className: "ods-flow-foreach__chevron",
1197
+ "data-flow-no-drag": "true",
1198
+ "aria-label": collapsed ? "Expand iterator" : "Collapse iterator",
1199
+ "aria-expanded": !collapsed,
1200
+ onClick: onChevronClick,
1201
+ onPointerDown: (e) => e.stopPropagation(),
1202
+ children: collapsed ? "\u25B8" : "\u25BE"
1203
+ }
1204
+ ),
1205
+ /* @__PURE__ */ jsx5("span", { className: "ods-flow-foreach__icon", "aria-hidden": "true", children: "\u21BB" }),
1206
+ /* @__PURE__ */ jsx5("span", { className: "ods-flow-foreach__title", children: d.title ?? "For each" }),
1207
+ /* @__PURE__ */ jsx5("code", { className: "ods-flow-foreach__iterator", children: iteratorExpr }),
1208
+ collapsed && hiddenCount !== void 0 && hiddenCount > 0 && /* @__PURE__ */ jsxs4("span", { className: "ods-flow-foreach__count", "aria-label": `${hiddenCount} hidden steps`, children: [
1209
+ hiddenCount,
1210
+ " steps"
1211
+ ] })
1212
+ ] }),
1213
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top", id: "__group_in" }),
1214
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom", id: "__group_out" }),
1215
+ !collapsed && // Expanded mode — full 3-handle iterator surface (in / item / done).
1216
+ // `in` shares the top edge with `__group_in`; consumers wiring an
1217
+ // explicit `targetHandle: "in"` get the labelled, visible variant.
1218
+ /* @__PURE__ */ jsxs4(Fragment, { children: [
1219
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top", id: "in", label: "in" }),
1220
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "right", id: "item", label: "item" }),
1221
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom", id: "done", label: "done" })
1222
+ ] })
1223
+ ]
1224
+ }
1225
+ );
1226
+ };
1227
+ var OutputNode = ({
1228
+ node
1229
+ }) => {
1230
+ const d = node.data ?? {};
1231
+ return /* @__PURE__ */ jsx5(
1232
+ BaseNode,
1233
+ {
1234
+ kind: d.kind ?? "OUTPUT",
1235
+ icon: d.icon,
1236
+ title: d.title ?? "Output",
1237
+ chip: d.chip ?? d.badge,
1238
+ description: d.description ?? d.subtitle,
1239
+ status: d.status,
1240
+ accent: "green",
1241
+ children: /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" })
1242
+ }
1243
+ );
1244
+ };
1245
+ var ErrorNode = ({
1246
+ node
1247
+ }) => {
1248
+ const d = node.data ?? {};
1249
+ return /* @__PURE__ */ jsxs4(
1250
+ BaseNode,
1251
+ {
1252
+ kind: d.kind ?? "ERROR",
1253
+ icon: d.icon,
1254
+ title: d.title ?? "On error",
1255
+ chip: d.chip ?? d.badge,
1256
+ description: d.description ?? d.subtitle,
1257
+ status: d.status ?? "error",
1258
+ accent: "red",
1259
+ children: [
1260
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" }),
1261
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom" })
1262
+ ]
1263
+ }
1264
+ );
1265
+ };
1266
+ var WaitNode = ({
1267
+ node
1268
+ }) => {
1269
+ const d = node.data ?? {};
1270
+ const waitMs = d.waitMs;
1271
+ const durationChip = waitMs ? `${Math.round(waitMs / 100) / 10}s` : void 0;
1272
+ return /* @__PURE__ */ jsxs4(
1273
+ BaseNode,
1274
+ {
1275
+ kind: d.kind ?? "WAIT",
1276
+ icon: d.icon,
1277
+ title: d.title ?? "Wait",
1278
+ chip: d.chip ?? durationChip,
1279
+ description: d.description ?? (durationChip ? "Pause execution" : void 0),
1280
+ status: d.status,
1281
+ accent: "violet",
1282
+ children: [
1283
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" }),
1284
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom" })
1285
+ ]
1286
+ }
1287
+ );
1288
+ };
1289
+ var ParallelNode = ({
1290
+ node
1291
+ }) => {
1292
+ const d = node.data ?? {};
1293
+ const branches = d.branches ?? [
1294
+ { id: "a", label: "a" },
1295
+ { id: "b", label: "b" }
1296
+ ];
1297
+ return /* @__PURE__ */ jsxs4(
1298
+ BaseNode,
1299
+ {
1300
+ kind: d.kind ?? "PARALLEL",
1301
+ icon: d.icon,
1302
+ title: d.title ?? "Parallel",
1303
+ chip: d.chip ?? `${branches.length}\xD7`,
1304
+ description: d.description ?? "Fan-out branches",
1305
+ status: d.status,
1306
+ accent: "blue",
1307
+ children: [
1308
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" }),
1309
+ branches.map((b, i) => /* @__PURE__ */ jsx5(
1310
+ Handle,
1311
+ {
1312
+ type: "source",
1313
+ position: "bottom",
1314
+ id: b.id,
1315
+ index: i,
1316
+ total: branches.length,
1317
+ label: b.label
1318
+ },
1319
+ b.id
1320
+ ))
1321
+ ]
1322
+ }
1323
+ );
1324
+ };
1325
+ var StickyNode = ({
1326
+ node
1327
+ }) => {
1328
+ const d = node.data ?? {};
1329
+ return /* @__PURE__ */ jsxs4(
1330
+ "div",
1331
+ {
1332
+ className: "ods-flow-sticky",
1333
+ style: {
1334
+ width: node.width ?? 240,
1335
+ minHeight: node.height ?? 120
1336
+ },
1337
+ children: [
1338
+ d.title && /* @__PURE__ */ jsx5("div", { className: "ods-flow-sticky__title", children: d.title }),
1339
+ d.description && /* @__PURE__ */ jsx5("div", { className: "ods-flow-sticky__body", children: d.description })
1340
+ ]
1341
+ }
1342
+ );
1343
+ };
1344
+ var WebhookNode = ({
1345
+ node
1346
+ }) => {
1347
+ const d = node.data ?? {};
1348
+ return /* @__PURE__ */ jsx5(
1349
+ BaseNode,
1350
+ {
1351
+ kind: d.kind ?? "WEBHOOK",
1352
+ icon: d.icon,
1353
+ title: d.title ?? "Webhook",
1354
+ chip: d.chip ?? d.method ?? "POST",
1355
+ description: d.description ?? d.path ?? "/hooks/incoming",
1356
+ status: d.status,
1357
+ accent: "blue",
1358
+ children: /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom" })
1359
+ }
1360
+ );
1361
+ };
1362
+ var HttpRequestNode = ({
1363
+ node
1364
+ }) => {
1365
+ const d = node.data ?? {};
1366
+ return /* @__PURE__ */ jsxs4(
1367
+ BaseNode,
1368
+ {
1369
+ kind: d.kind ?? "HTTP",
1370
+ icon: d.icon,
1371
+ title: d.title ?? "HTTP Request",
1372
+ chip: d.chip ?? d.method ?? "GET",
1373
+ description: d.description ?? d.url ?? "Call an API",
1374
+ status: d.status,
1375
+ accent: "blue",
1376
+ children: [
1377
+ /* @__PURE__ */ jsx5(Handle, { type: "target", position: "top" }),
1378
+ /* @__PURE__ */ jsx5(Handle, { type: "source", position: "bottom" })
1379
+ ]
1380
+ }
1381
+ );
1382
+ };
1383
+ var DEFAULT_NODE_KINDS = {
1384
+ action: ActionNode,
1385
+ trigger: TriggerNode,
1386
+ condition: ConditionNode,
1387
+ group: GroupNode,
1388
+ forEach: ForEachNode,
1389
+ output: OutputNode,
1390
+ error: ErrorNode,
1391
+ wait: WaitNode,
1392
+ parallel: ParallelNode,
1393
+ sticky: StickyNode,
1394
+ webhook: WebhookNode,
1395
+ httpRequest: HttpRequestNode
1396
+ };
1397
+
1398
+ // src/workflow/components/FlowCanvas/FlowCanvas.tsx
1399
+ import {
1400
+ memo as memo2,
1401
+ useCallback,
1402
+ useEffect as useEffect4,
1403
+ useMemo as useMemo2,
1404
+ useRef as useRef4,
1405
+ useState as useState2
1406
+ } from "react";
1407
+
1408
+ // src/workflow/store/context.ts
1409
+ import { createContext as createContext5, useContext as useContext6 } from "react";
1410
+ var FlowStoreContext = createContext5(null);
1411
+ function useFlowStore() {
1412
+ const store = useContext6(FlowStoreContext);
1413
+ if (!store) {
1414
+ throw new Error(
1415
+ "[@octaviaflow/core/workflow] useFlowStore must be called inside a <FlowCanvas>."
1416
+ );
1417
+ }
1418
+ return store;
1419
+ }
1420
+
1421
+ // src/workflow/store/createFlowStore.ts
1422
+ var DEFAULT_VIEWPORT = { x: 0, y: 0, zoom: 1 };
1423
+ function createFlowStore({
1424
+ initialNodes = [],
1425
+ initialEdges = [],
1426
+ initialViewport = DEFAULT_VIEWPORT
1427
+ } = {}) {
1428
+ let snapshot = {
1429
+ nodes: initialNodes,
1430
+ edges: initialEdges,
1431
+ viewport: initialViewport,
1432
+ selectedNodeIds: EMPTY_SET,
1433
+ selectedEdgeIds: EMPTY_SET,
1434
+ connection: null
1435
+ };
1436
+ const listeners = /* @__PURE__ */ new Set();
1437
+ const emit = () => {
1438
+ for (const l of listeners) l();
1439
+ };
1440
+ const subscribe = (listener) => {
1441
+ listeners.add(listener);
1442
+ return () => {
1443
+ listeners.delete(listener);
1444
+ };
1445
+ };
1446
+ const replace = (patch) => {
1447
+ snapshot = { ...snapshot, ...patch };
1448
+ emit();
1449
+ };
1450
+ return {
1451
+ subscribe,
1452
+ getSnapshot: () => snapshot,
1453
+ setNodes(nodes) {
1454
+ if (nodes === snapshot.nodes) return;
1455
+ replace({ nodes });
1456
+ },
1457
+ setEdges(edges) {
1458
+ if (edges === snapshot.edges) return;
1459
+ replace({ edges });
1460
+ },
1461
+ setViewport(viewport) {
1462
+ if (viewport.x === snapshot.viewport.x && viewport.y === snapshot.viewport.y && viewport.zoom === snapshot.viewport.zoom) {
1463
+ return;
1464
+ }
1465
+ replace({ viewport });
1466
+ },
1467
+ setSelection(selectedNodeIds, selectedEdgeIds) {
1468
+ replace({ selectedNodeIds, selectedEdgeIds });
1469
+ },
1470
+ setConnection(connection) {
1471
+ if (connection === snapshot.connection) return;
1472
+ replace({ connection });
1473
+ }
1474
+ };
1475
+ }
1476
+ var EMPTY_SET = /* @__PURE__ */ new Set();
1477
+
1478
+ // src/workflow/utils/collision.ts
1479
+ function resolveNodeCollisions(node, proposed, others, opts) {
1480
+ const { gap, maxIterations = 8, exclude, scopeToSiblings = true } = opts;
1481
+ if (gap < 0 || others.length === 0) return proposed;
1482
+ const w = node.width ?? DEFAULT_NODE_WIDTH;
1483
+ const h = effectiveHeight(node);
1484
+ const parentId = node.parentId;
1485
+ const candidates = others.filter((o) => {
1486
+ if (o.id === node.id) return false;
1487
+ if (o.hidden) return false;
1488
+ if (exclude?.has(o.id)) return false;
1489
+ if (scopeToSiblings && (o.parentId ?? void 0) !== (parentId ?? void 0)) {
1490
+ return false;
1491
+ }
1492
+ return true;
1493
+ });
1494
+ if (candidates.length === 0) return proposed;
1495
+ let cur = proposed;
1496
+ for (let iter = 0; iter < maxIterations; iter++) {
1497
+ let bestOverlap = Number.POSITIVE_INFINITY;
1498
+ let bestPushX = 0;
1499
+ let bestPushY = 0;
1500
+ let hit = false;
1501
+ const aLeft = cur.x - gap;
1502
+ const aRight = cur.x + w + gap;
1503
+ const aTop = cur.y - gap;
1504
+ const aBottom = cur.y + h + gap;
1505
+ for (const o of candidates) {
1506
+ const ow = o.width ?? DEFAULT_NODE_WIDTH;
1507
+ const oh = effectiveHeight(o);
1508
+ const bLeft = o.position.x;
1509
+ const bRight = o.position.x + ow;
1510
+ const bTop = o.position.y;
1511
+ const bBottom = o.position.y + oh;
1512
+ const overlapX = Math.min(aRight, bRight) - Math.max(aLeft, bLeft);
1513
+ const overlapY = Math.min(aBottom, bBottom) - Math.max(aTop, bTop);
1514
+ if (overlapX <= 0 || overlapY <= 0) continue;
1515
+ let pushX = 0;
1516
+ let pushY = 0;
1517
+ let overlap;
1518
+ if (overlapX < overlapY) {
1519
+ const aCx = cur.x + w / 2;
1520
+ const bCx = o.position.x + ow / 2;
1521
+ pushX = aCx < bCx ? -overlapX : overlapX;
1522
+ overlap = overlapX;
1523
+ } else {
1524
+ const aCy = cur.y + h / 2;
1525
+ const bCy = o.position.y + oh / 2;
1526
+ pushY = aCy < bCy ? -overlapY : overlapY;
1527
+ overlap = overlapY;
1528
+ }
1529
+ if (overlap < bestOverlap) {
1530
+ bestOverlap = overlap;
1531
+ bestPushX = pushX;
1532
+ bestPushY = pushY;
1533
+ hit = true;
1534
+ }
1535
+ }
1536
+ if (!hit) break;
1537
+ cur = { x: cur.x + bestPushX, y: cur.y + bestPushY };
1538
+ }
1539
+ return cur;
1540
+ }
1541
+
1542
+ // src/workflow/components/FlowCanvas/FlowCanvas.tsx
1543
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
1544
+ var DEFAULT_VIEWPORT2 = { x: 0, y: 0, zoom: 1 };
1545
+ function FlowCanvas({
1546
+ nodes,
1547
+ edges,
1548
+ onNodesChange,
1549
+ onEdgesChange,
1550
+ viewport: controlledViewport,
1551
+ defaultViewport = DEFAULT_VIEWPORT2,
1552
+ onViewportChange,
1553
+ minZoom = 0.25,
1554
+ maxZoom = 2,
1555
+ nodeKinds,
1556
+ onConnect,
1557
+ onConnectStart,
1558
+ onConnectEnd,
1559
+ isValidConnection,
1560
+ onSelectionChange,
1561
+ onPaneClick,
1562
+ onNodeClick,
1563
+ onEdgeClick,
1564
+ onEdgeLabelChange,
1565
+ onInit,
1566
+ onBeforeDelete,
1567
+ onNodeContextMenu,
1568
+ onEdgeContextMenu,
1569
+ onPaneContextMenu,
1570
+ nodesDraggable = true,
1571
+ nodesConnectable = true,
1572
+ panOnDrag: panOnDragProp,
1573
+ zoomOnScroll: zoomOnScrollProp,
1574
+ preset = "mouse",
1575
+ paneClickDistance = 4,
1576
+ paneClickClearsSelection = true,
1577
+ background = "dots",
1578
+ gridSize = 20,
1579
+ snapToGrid = false,
1580
+ nodeCollisionGap = -1,
1581
+ subflowCollisionGap,
1582
+ height = "100%",
1583
+ width = "100%",
1584
+ className,
1585
+ style,
1586
+ children,
1587
+ emptyState
1588
+ }) {
1589
+ const presetDefaults = {
1590
+ mouse: { panOnDrag: true, zoomOnScroll: true },
1591
+ trackpad: { panOnDrag: true, zoomOnScroll: true },
1592
+ touch: { panOnDrag: false, zoomOnScroll: true }
1593
+ };
1594
+ const panOnDrag = panOnDragProp ?? presetDefaults[preset].panOnDrag;
1595
+ const zoomOnScroll = zoomOnScrollProp ?? presetDefaults[preset].zoomOnScroll;
1596
+ const store = useState2(
1597
+ () => createFlowStore({
1598
+ initialNodes: nodes,
1599
+ initialEdges: edges,
1600
+ initialViewport: controlledViewport ?? defaultViewport
1601
+ })
1602
+ )[0];
1603
+ const handleRegistry = useState2(() => createHandleRegistry())[0];
1604
+ const [handleVersion, setHandleVersion] = useState2(0);
1605
+ useEffect4(() => {
1606
+ const unsub = handleRegistry.subscribe(() => {
1607
+ setHandleVersion((v) => v + 1);
1608
+ });
1609
+ return unsub;
1610
+ }, [handleRegistry]);
1611
+ const kinds = useMemo2(() => buildNodeKindRegistry(DEFAULT_NODE_KINDS, nodeKinds), [nodeKinds]);
1612
+ const containerRef = useRef4(null);
1613
+ useEffect4(() => store.setNodes(nodes), [store, nodes]);
1614
+ useEffect4(() => store.setEdges(edges), [store, edges]);
1615
+ const [uncontrolledVp, setUncontrolledVp] = useState2(controlledViewport ?? defaultViewport);
1616
+ const viewport = controlledViewport ?? uncontrolledVp;
1617
+ useEffect4(() => store.setViewport(viewport), [store, viewport]);
1618
+ const setViewport = useCallback(
1619
+ (next) => {
1620
+ if (controlledViewport === void 0) setUncontrolledVp(next);
1621
+ onViewportChange?.(next);
1622
+ },
1623
+ [controlledViewport, onViewportChange]
1624
+ );
1625
+ const selectedNodeIds = useMemo2(() => {
1626
+ const s = /* @__PURE__ */ new Set();
1627
+ for (const n of nodes) if (n.selected) s.add(n.id);
1628
+ return s;
1629
+ }, [nodes]);
1630
+ const selectedEdgeIds = useMemo2(() => {
1631
+ const s = /* @__PURE__ */ new Set();
1632
+ for (const e of edges) if (e.selected) s.add(e.id);
1633
+ return s;
1634
+ }, [edges]);
1635
+ useEffect4(() => {
1636
+ store.setSelection(selectedNodeIds, selectedEdgeIds);
1637
+ if (onSelectionChange) {
1638
+ onSelectionChange({
1639
+ nodes: nodes.filter((n) => selectedNodeIds.has(n.id)),
1640
+ edges: edges.filter((e) => selectedEdgeIds.has(e.id))
1641
+ });
1642
+ }
1643
+ }, [store, selectedNodeIds, selectedEdgeIds, nodes, edges, onSelectionChange]);
1644
+ const selectNode = useCallback(
1645
+ (id, additive) => {
1646
+ const next = [];
1647
+ const nextEdges = [];
1648
+ if (!additive) {
1649
+ for (const n of nodes) {
1650
+ if (n.selected && n.id !== id) next.push(change.node.select(n.id, false));
1651
+ }
1652
+ for (const e of edges) {
1653
+ if (e.selected) nextEdges.push(change.edge.select(e.id, false));
1654
+ }
1655
+ }
1656
+ const isSelected = selectedNodeIds.has(id);
1657
+ if (additive && isSelected) {
1658
+ next.push(change.node.select(id, false));
1659
+ } else if (!isSelected) {
1660
+ next.push(change.node.select(id, true));
1661
+ }
1662
+ if (next.length) onNodesChange?.(next);
1663
+ if (nextEdges.length) onEdgesChange?.(nextEdges);
1664
+ },
1665
+ [nodes, edges, selectedNodeIds, onNodesChange, onEdgesChange]
1666
+ );
1667
+ const notifyNodeClick = useCallback(
1668
+ (id) => {
1669
+ const node = nodes.find((n) => n.id === id);
1670
+ if (node) onNodeClick?.(node);
1671
+ },
1672
+ [nodes, onNodeClick]
1673
+ );
1674
+ const selectEdge = useCallback(
1675
+ (id, additive) => {
1676
+ const next = [];
1677
+ const nextNodes = [];
1678
+ if (!additive) {
1679
+ for (const e of edges) {
1680
+ if (e.selected && e.id !== id) next.push(change.edge.select(e.id, false));
1681
+ }
1682
+ for (const n of nodes) {
1683
+ if (n.selected) nextNodes.push(change.node.select(n.id, false));
1684
+ }
1685
+ }
1686
+ const isSelected = selectedEdgeIds.has(id);
1687
+ if (additive && isSelected) {
1688
+ next.push(change.edge.select(id, false));
1689
+ } else if (!isSelected) {
1690
+ next.push(change.edge.select(id, true));
1691
+ }
1692
+ if (next.length) onEdgesChange?.(next);
1693
+ if (nextNodes.length) onNodesChange?.(nextNodes);
1694
+ const edge = edges.find((e) => e.id === id);
1695
+ if (edge) onEdgeClick?.(edge);
1696
+ },
1697
+ [nodes, edges, selectedEdgeIds, onEdgesChange, onNodesChange, onEdgeClick]
1698
+ );
1699
+ const clearSelection = useCallback(() => {
1700
+ const ns = [];
1701
+ const es = [];
1702
+ for (const n of nodes) if (n.selected) ns.push(change.node.select(n.id, false));
1703
+ for (const e of edges) if (e.selected) es.push(change.edge.select(e.id, false));
1704
+ if (ns.length) onNodesChange?.(ns);
1705
+ if (es.length) onEdgesChange?.(es);
1706
+ }, [nodes, edges, onNodesChange, onEdgesChange]);
1707
+ const dragRef = useRef4(null);
1708
+ const [draggingId, setDraggingId] = useState2(null);
1709
+ const beginNodeDrag = useCallback(
1710
+ (nodeId, pointerId, clientX, clientY, altKey = false) => {
1711
+ if (!nodesDraggable) return;
1712
+ const node = nodes.find((n) => n.id === nodeId);
1713
+ if (!node) return;
1714
+ const kids = descendantsOf(nodeId, nodes).map((d) => ({
1715
+ id: d.id,
1716
+ startPosition: d.position
1717
+ }));
1718
+ dragRef.current = {
1719
+ pointerId,
1720
+ nodeId,
1721
+ startClientX: clientX,
1722
+ startClientY: clientY,
1723
+ startPosition: node.position,
1724
+ descendants: kids,
1725
+ altDetach: altKey && !!node.parentId,
1726
+ rafScheduled: false,
1727
+ nextDelta: null
1728
+ };
1729
+ setDraggingId(nodeId);
1730
+ selectNode(nodeId, false);
1731
+ },
1732
+ [nodes, nodesDraggable, selectNode]
1733
+ );
1734
+ const [conn, setConn] = useState2(null);
1735
+ const connRef = useRef4(null);
1736
+ useEffect4(() => {
1737
+ connRef.current = conn;
1738
+ }, [conn]);
1739
+ const beginConnection = useCallback(
1740
+ (nodeId, handleId, handleType, pointerId, clientX, clientY) => {
1741
+ if (!nodesConnectable) return;
1742
+ const node = nodes.find((n) => n.id === nodeId);
1743
+ if (!node) return;
1744
+ const desc = handleRegistry.resolve(nodeId, handleType, handleId);
1745
+ const side = desc?.side ?? (handleType === "source" ? "bottom" : "top");
1746
+ const index = desc?.index ?? 0;
1747
+ const total = desc?.total ?? 1;
1748
+ const ratio = (index + 1) / (total + 1);
1749
+ const w = node.width ?? 368;
1750
+ const h = effectiveHeight(node);
1751
+ const start = (() => {
1752
+ switch (side) {
1753
+ case "top":
1754
+ return { x: node.position.x + w * ratio, y: node.position.y };
1755
+ case "bottom":
1756
+ return { x: node.position.x + w * ratio, y: node.position.y + h };
1757
+ case "left":
1758
+ return { x: node.position.x, y: node.position.y + h * ratio };
1759
+ case "right":
1760
+ return { x: node.position.x + w, y: node.position.y + h * ratio };
1761
+ }
1762
+ })();
1763
+ const from = { nodeId, handleId, handleType };
1764
+ const rect = containerRef.current?.getBoundingClientRect();
1765
+ const end = rect ? screenToFlow({ x: clientX - rect.left, y: clientY - rect.top }, viewport) : start;
1766
+ setConn({ pointerId, from, start, end });
1767
+ store.setConnection(from);
1768
+ onConnectStart?.({ clientX, clientY, pointerId }, from);
1769
+ },
1770
+ [nodes, nodesConnectable, handleRegistry, viewport, store, onConnectStart]
1771
+ );
1772
+ const viewportRef = useRef4(viewport);
1773
+ const nodesRef = useRef4(nodes);
1774
+ const edgesRef = useRef4(edges);
1775
+ const onNodesChangeRefForInstance = useRef4(onNodesChange);
1776
+ const onEdgesChangeRefForInstance = useRef4(onEdgesChange);
1777
+ const onBeforeDeleteRef = useRef4(onBeforeDelete);
1778
+ const snapToGridRef = useRef4(snapToGrid);
1779
+ const gridSizeRef = useRef4(gridSize);
1780
+ const nodeCollisionGapRef = useRef4(nodeCollisionGap);
1781
+ const subflowCollisionGapRef = useRef4(subflowCollisionGap ?? nodeCollisionGap);
1782
+ useEffect4(() => {
1783
+ edgesRef.current = edges;
1784
+ }, [edges]);
1785
+ useEffect4(() => {
1786
+ onNodesChangeRefForInstance.current = onNodesChange;
1787
+ }, [onNodesChange]);
1788
+ useEffect4(() => {
1789
+ onEdgesChangeRefForInstance.current = onEdgesChange;
1790
+ }, [onEdgesChange]);
1791
+ useEffect4(() => {
1792
+ onBeforeDeleteRef.current = onBeforeDelete;
1793
+ }, [onBeforeDelete]);
1794
+ useEffect4(() => {
1795
+ snapToGridRef.current = snapToGrid;
1796
+ }, [snapToGrid]);
1797
+ useEffect4(() => {
1798
+ gridSizeRef.current = gridSize;
1799
+ }, [gridSize]);
1800
+ useEffect4(() => {
1801
+ nodeCollisionGapRef.current = nodeCollisionGap;
1802
+ }, [nodeCollisionGap]);
1803
+ useEffect4(() => {
1804
+ subflowCollisionGapRef.current = subflowCollisionGap ?? nodeCollisionGap;
1805
+ }, [subflowCollisionGap, nodeCollisionGap]);
1806
+ const onNodesChangeRef = useRef4(onNodesChange);
1807
+ const onConnectRef = useRef4(onConnect);
1808
+ const onConnectEndRef = useRef4(onConnectEnd);
1809
+ const isValidConnectionRef = useRef4(isValidConnection);
1810
+ useEffect4(() => {
1811
+ viewportRef.current = viewport;
1812
+ }, [viewport]);
1813
+ useEffect4(() => {
1814
+ nodesRef.current = nodes;
1815
+ }, [nodes]);
1816
+ useEffect4(() => {
1817
+ onNodesChangeRef.current = onNodesChange;
1818
+ }, [onNodesChange]);
1819
+ useEffect4(() => {
1820
+ onConnectRef.current = onConnect;
1821
+ }, [onConnect]);
1822
+ useEffect4(() => {
1823
+ onConnectEndRef.current = onConnectEnd;
1824
+ }, [onConnectEnd]);
1825
+ useEffect4(() => {
1826
+ isValidConnectionRef.current = isValidConnection;
1827
+ }, [isValidConnection]);
1828
+ useEffect4(() => {
1829
+ const onPointerMove = (e) => {
1830
+ const vp = viewportRef.current;
1831
+ const drag = dragRef.current;
1832
+ if (drag && drag.pointerId === e.pointerId) {
1833
+ const dx = (e.clientX - drag.startClientX) / vp.zoom;
1834
+ const dy = (e.clientY - drag.startClientY) / vp.zoom;
1835
+ drag.nextDelta = { dx, dy };
1836
+ if (!drag.rafScheduled) {
1837
+ drag.rafScheduled = true;
1838
+ requestAnimationFrame(() => {
1839
+ const d = dragRef.current;
1840
+ if (!d) return;
1841
+ d.rafScheduled = false;
1842
+ const delta = d.nextDelta;
1843
+ if (!delta) return;
1844
+ const dragNode = nodesRef.current.find((n) => n.id === d.nodeId);
1845
+ if (!dragNode) return;
1846
+ const proposed = {
1847
+ x: d.startPosition.x + delta.dx,
1848
+ y: d.startPosition.y + delta.dy
1849
+ };
1850
+ const clamped = d.altDetach ? proposed : clampToParentExtent(dragNode, proposed, nodesRef.current);
1851
+ const isContainer = dragNode.type === "group" || dragNode.type === "forEach";
1852
+ const gap = isContainer ? subflowCollisionGapRef.current : nodeCollisionGapRef.current;
1853
+ const excludeIds = /* @__PURE__ */ new Set([d.nodeId, ...d.descendants.map((kid) => kid.id)]);
1854
+ const finalPos = resolveNodeCollisions(dragNode, clamped, nodesRef.current, {
1855
+ gap,
1856
+ exclude: excludeIds
1857
+ });
1858
+ const realDx = finalPos.x - d.startPosition.x;
1859
+ const realDy = finalPos.y - d.startPosition.y;
1860
+ const changes = [change.node.position(d.nodeId, finalPos, true)];
1861
+ for (const kid of d.descendants) {
1862
+ changes.push(
1863
+ change.node.position(
1864
+ kid.id,
1865
+ { x: kid.startPosition.x + realDx, y: kid.startPosition.y + realDy },
1866
+ true
1867
+ )
1868
+ );
1869
+ }
1870
+ onNodesChangeRef.current?.(changes);
1871
+ });
1872
+ }
1873
+ }
1874
+ const c = connRef.current;
1875
+ if (c && c.pointerId === e.pointerId) {
1876
+ const rect = containerRef.current?.getBoundingClientRect();
1877
+ if (rect) {
1878
+ const end = screenToFlow({ x: e.clientX - rect.left, y: e.clientY - rect.top }, vp);
1879
+ setConn({ ...c, end });
1880
+ }
1881
+ }
1882
+ };
1883
+ const onPointerUp = (e) => {
1884
+ const vp = viewportRef.current;
1885
+ const drag = dragRef.current;
1886
+ if (drag && drag.pointerId === e.pointerId) {
1887
+ const dx = (e.clientX - drag.startClientX) / vp.zoom;
1888
+ const dy = (e.clientY - drag.startClientY) / vp.zoom;
1889
+ const dragNode = nodesRef.current.find((n) => n.id === drag.nodeId);
1890
+ if (dragNode) {
1891
+ let proposed = {
1892
+ x: drag.startPosition.x + dx,
1893
+ y: drag.startPosition.y + dy
1894
+ };
1895
+ if (snapToGridRef.current) {
1896
+ const g = gridSizeRef.current;
1897
+ proposed = {
1898
+ x: Math.round(proposed.x / g) * g,
1899
+ y: Math.round(proposed.y / g) * g
1900
+ };
1901
+ }
1902
+ const clamped = drag.altDetach ? proposed : clampToParentExtent(dragNode, proposed, nodesRef.current);
1903
+ const isContainer = dragNode.type === "group" || dragNode.type === "forEach";
1904
+ const gap = isContainer ? subflowCollisionGapRef.current : nodeCollisionGapRef.current;
1905
+ const excludeIds = /* @__PURE__ */ new Set([
1906
+ drag.nodeId,
1907
+ ...drag.descendants.map((kid) => kid.id)
1908
+ ]);
1909
+ const finalPos = resolveNodeCollisions(dragNode, clamped, nodesRef.current, {
1910
+ gap,
1911
+ exclude: excludeIds
1912
+ });
1913
+ const realDx = finalPos.x - drag.startPosition.x;
1914
+ const realDy = finalPos.y - drag.startPosition.y;
1915
+ const changes = [change.node.position(drag.nodeId, finalPos, false)];
1916
+ for (const kid of drag.descendants) {
1917
+ changes.push(
1918
+ change.node.position(
1919
+ kid.id,
1920
+ { x: kid.startPosition.x + realDx, y: kid.startPosition.y + realDy },
1921
+ false
1922
+ )
1923
+ );
1924
+ }
1925
+ if (drag.altDetach && dragNode.parentId) {
1926
+ const targetGroup = findContainingGroup(
1927
+ {
1928
+ x: finalPos.x + (dragNode.width ?? 0) / 2,
1929
+ y: finalPos.y + (dragNode.height ?? 0) / 2
1930
+ },
1931
+ nodesRef.current,
1932
+ [drag.nodeId, ...drag.descendants.map((d) => d.id)]
1933
+ );
1934
+ const nextParentId = targetGroup?.id;
1935
+ const updated = {
1936
+ ...dragNode,
1937
+ position: finalPos,
1938
+ parentId: nextParentId,
1939
+ // Preserve extent only when staying in a group.
1940
+ extent: nextParentId ? dragNode.extent : void 0
1941
+ };
1942
+ changes.push(change.node.replace(drag.nodeId, updated));
1943
+ }
1944
+ onNodesChangeRef.current?.(changes);
1945
+ }
1946
+ dragRef.current = null;
1947
+ setDraggingId(null);
1948
+ }
1949
+ const c = connRef.current;
1950
+ if (c && c.pointerId === e.pointerId) {
1951
+ const target = e.target;
1952
+ const handleEl = target?.closest("[data-handle-id]");
1953
+ let connection = null;
1954
+ let connectedTo;
1955
+ if (handleEl) {
1956
+ const targetNodeId = handleEl.dataset.handleNodeId;
1957
+ const targetHandleId = handleEl.dataset.handleId;
1958
+ const targetType = handleEl.dataset.handleType;
1959
+ const connectableEnd = handleEl.dataset.handleConnectableEnd === "true";
1960
+ if (connectableEnd && (targetNodeId !== c.from.nodeId || targetHandleId !== c.from.handleId) && targetType !== c.from.handleType) {
1961
+ const source = c.from.handleType === "source" ? c.from : { nodeId: targetNodeId, handleId: targetHandleId, handleType: "source" };
1962
+ const target2 = c.from.handleType === "target" ? c.from : { nodeId: targetNodeId, handleId: targetHandleId, handleType: "target" };
1963
+ connection = {
1964
+ source: source.nodeId,
1965
+ sourceHandle: source.handleId,
1966
+ target: target2.nodeId,
1967
+ targetHandle: target2.handleId
1968
+ };
1969
+ connectedTo = {
1970
+ nodeId: targetNodeId,
1971
+ handleId: targetHandleId,
1972
+ handleType: targetType
1973
+ };
1974
+ const validator = isValidConnectionRef.current;
1975
+ if (validator && !validator(connection)) {
1976
+ connection = null;
1977
+ connectedTo = void 0;
1978
+ }
1979
+ }
1980
+ }
1981
+ const rect = containerRef.current?.getBoundingClientRect();
1982
+ const flowPos = rect ? screenToFlow({ x: e.clientX - rect.left, y: e.clientY - rect.top }, vp) : { x: 0, y: 0 };
1983
+ const endState = {
1984
+ cancelled: !connection,
1985
+ position: { x: e.clientX, y: e.clientY },
1986
+ flowPosition: flowPos,
1987
+ from: c.from,
1988
+ to: connectedTo
1989
+ };
1990
+ if (connection) onConnectRef.current?.(connection);
1991
+ onConnectEndRef.current?.(e, endState);
1992
+ setConn(null);
1993
+ store.setConnection(null);
1994
+ }
1995
+ };
1996
+ const onPointerCancel = () => {
1997
+ if (dragRef.current) {
1998
+ dragRef.current = null;
1999
+ setDraggingId(null);
2000
+ }
2001
+ if (connRef.current) {
2002
+ setConn(null);
2003
+ store.setConnection(null);
2004
+ }
2005
+ };
2006
+ window.addEventListener("pointermove", onPointerMove);
2007
+ window.addEventListener("pointerup", onPointerUp);
2008
+ window.addEventListener("pointercancel", onPointerCancel);
2009
+ return () => {
2010
+ window.removeEventListener("pointermove", onPointerMove);
2011
+ window.removeEventListener("pointerup", onPointerUp);
2012
+ window.removeEventListener("pointercancel", onPointerCancel);
2013
+ };
2014
+ }, [store]);
2015
+ const panRef = useRef4(null);
2016
+ const onCanvasPointerDown = (e) => {
2017
+ if (e.button !== 0) return;
2018
+ const t = e.target;
2019
+ if (t.closest("[data-node-id]") || t.closest("[data-edge-id]") || t.closest("[data-handle-id]")) {
2020
+ return;
2021
+ }
2022
+ if (!panOnDrag) {
2023
+ panRef.current = {
2024
+ pointerId: e.pointerId,
2025
+ startClientX: e.clientX,
2026
+ startClientY: e.clientY,
2027
+ startVp: viewport,
2028
+ moved: false
2029
+ };
2030
+ return;
2031
+ }
2032
+ panRef.current = {
2033
+ pointerId: e.pointerId,
2034
+ startClientX: e.clientX,
2035
+ startClientY: e.clientY,
2036
+ startVp: viewport,
2037
+ moved: false
2038
+ };
2039
+ };
2040
+ useEffect4(() => {
2041
+ const onMove = (e) => {
2042
+ const pan = panRef.current;
2043
+ if (!pan || pan.pointerId !== e.pointerId) return;
2044
+ const dx = e.clientX - pan.startClientX;
2045
+ const dy = e.clientY - pan.startClientY;
2046
+ if (Math.abs(dx) > paneClickDistance || Math.abs(dy) > paneClickDistance) {
2047
+ if (!pan.moved) setPanGesture(true);
2048
+ pan.moved = true;
2049
+ }
2050
+ if (pan.moved && panOnDrag) {
2051
+ setViewport({ ...pan.startVp, x: pan.startVp.x + dx, y: pan.startVp.y + dy });
2052
+ }
2053
+ };
2054
+ const onUp = () => {
2055
+ const pan = panRef.current;
2056
+ if (!pan) return;
2057
+ if (!pan.moved) {
2058
+ onPaneClick?.();
2059
+ if (paneClickClearsSelection) clearSelection();
2060
+ }
2061
+ panRef.current = null;
2062
+ setPanGesture(false);
2063
+ };
2064
+ window.addEventListener("pointermove", onMove);
2065
+ window.addEventListener("pointerup", onUp);
2066
+ window.addEventListener("pointercancel", onUp);
2067
+ return () => {
2068
+ window.removeEventListener("pointermove", onMove);
2069
+ window.removeEventListener("pointerup", onUp);
2070
+ window.removeEventListener("pointercancel", onUp);
2071
+ };
2072
+ }, [
2073
+ setViewport,
2074
+ paneClickDistance,
2075
+ panOnDrag,
2076
+ onPaneClick,
2077
+ clearSelection,
2078
+ paneClickClearsSelection
2079
+ ]);
2080
+ const handleWheel = (e) => {
2081
+ if (!zoomOnScroll) return;
2082
+ e.preventDefault();
2083
+ const rect = containerRef.current?.getBoundingClientRect();
2084
+ if (!rect) return;
2085
+ const px = e.clientX - rect.left;
2086
+ const py = e.clientY - rect.top;
2087
+ const factor = Math.exp(-e.deltaY * 1e-3);
2088
+ const nextZoom = Math.max(minZoom, Math.min(maxZoom, viewport.zoom * factor));
2089
+ const k = nextZoom / viewport.zoom;
2090
+ setViewport({
2091
+ zoom: nextZoom,
2092
+ x: px - (px - viewport.x) * k,
2093
+ y: py - (py - viewport.y) * k
2094
+ });
2095
+ };
2096
+ const dispatch = useCallback(
2097
+ (a) => {
2098
+ if (a.type === "connection/start") {
2099
+ beginConnection(a.nodeId, a.handleId, a.handleType, a.pointerId, a.clientX, a.clientY);
2100
+ }
2101
+ },
2102
+ [beginConnection]
2103
+ );
2104
+ const reportDimensions = useCallback(
2105
+ (nodeId, width2, height2) => {
2106
+ const node = nodes.find((n) => n.id === nodeId);
2107
+ if (!node) return;
2108
+ if (node.width === width2 && node.height === height2) return;
2109
+ onNodesChange?.([change.node.dimensions(nodeId, { width: width2, height: height2 })]);
2110
+ },
2111
+ [nodes, onNodesChange]
2112
+ );
2113
+ const toggleNodeCollapseImpl = useCallback(
2114
+ (nodeId) => {
2115
+ const node = nodes.find((n) => n.id === nodeId);
2116
+ if (!node) return;
2117
+ const prevData = node.data ?? {};
2118
+ const nextNode = {
2119
+ ...node,
2120
+ data: { ...prevData, collapsed: !prevData.collapsed }
2121
+ };
2122
+ onNodesChange?.([change.node.replace(nodeId, nextNode)]);
2123
+ },
2124
+ [nodes, onNodesChange]
2125
+ );
2126
+ const deleteNodeImpl = useCallback(
2127
+ (nodeId) => {
2128
+ const incidentEdgeIds = edgesRef.current.filter((e) => e.source === nodeId || e.target === nodeId).map((e) => e.id);
2129
+ if (incidentEdgeIds.length > 0) {
2130
+ onEdgesChange?.(incidentEdgeIds.map((id) => change.edge.remove(id)));
2131
+ }
2132
+ onNodesChange?.([change.node.remove(nodeId)]);
2133
+ },
2134
+ [onNodesChange, onEdgesChange]
2135
+ );
2136
+ const instance = useMemo2(
2137
+ () => ({
2138
+ // viewport
2139
+ getViewport: () => viewportRef.current,
2140
+ setViewport: (vp) => setViewport(vp),
2141
+ setCenter: (x, y, opts) => {
2142
+ const z = opts?.zoom ?? viewportRef.current.zoom;
2143
+ const rect = containerRef.current?.getBoundingClientRect();
2144
+ if (!rect) return;
2145
+ setViewport({
2146
+ zoom: z,
2147
+ x: rect.width / 2 - x * z,
2148
+ y: rect.height / 2 - y * z
2149
+ });
2150
+ },
2151
+ fitView: async (opts) => {
2152
+ const rect = containerRef.current?.getBoundingClientRect();
2153
+ if (!rect) return false;
2154
+ const padding = opts?.padding ?? 80;
2155
+ const targetNodes = opts?.nodes ? nodesRef.current.filter((n) => opts.nodes.some((x) => x.id === n.id)) : nodesRef.current.filter((n) => !n.hidden);
2156
+ if (targetNodes.length === 0) return false;
2157
+ let minX = Number.POSITIVE_INFINITY;
2158
+ let minY = Number.POSITIVE_INFINITY;
2159
+ let maxX = Number.NEGATIVE_INFINITY;
2160
+ let maxY = Number.NEGATIVE_INFINITY;
2161
+ for (const n of targetNodes) {
2162
+ const w = n.width ?? DEFAULT_NODE_WIDTH;
2163
+ const h = effectiveHeight(n);
2164
+ if (n.position.x < minX) minX = n.position.x;
2165
+ if (n.position.y < minY) minY = n.position.y;
2166
+ if (n.position.x + w > maxX) maxX = n.position.x + w;
2167
+ if (n.position.y + h > maxY) maxY = n.position.y + h;
2168
+ }
2169
+ const cw = maxX - minX;
2170
+ const ch = maxY - minY;
2171
+ const zx = (rect.width - padding * 2) / cw;
2172
+ const zy = (rect.height - padding * 2) / ch;
2173
+ const zoom = Math.max(
2174
+ opts?.minZoom ?? 0.25,
2175
+ Math.min(opts?.maxZoom ?? 1.5, Math.min(zx, zy))
2176
+ );
2177
+ setViewport({
2178
+ zoom,
2179
+ x: rect.width / 2 - (minX + maxX) / 2 * zoom,
2180
+ y: rect.height / 2 - (minY + maxY) / 2 * zoom
2181
+ });
2182
+ return true;
2183
+ },
2184
+ zoomIn: (opts) => {
2185
+ const step = opts?.step ?? 0.2;
2186
+ const next = Math.min(maxZoom, viewportRef.current.zoom * (1 + step));
2187
+ setViewport({ ...viewportRef.current, zoom: next });
2188
+ },
2189
+ zoomOut: (opts) => {
2190
+ const step = opts?.step ?? 0.2;
2191
+ const next = Math.max(minZoom, viewportRef.current.zoom / (1 + step));
2192
+ setViewport({ ...viewportRef.current, zoom: next });
2193
+ },
2194
+ zoomTo: (level) => {
2195
+ setViewport({
2196
+ ...viewportRef.current,
2197
+ zoom: Math.max(minZoom, Math.min(maxZoom, level))
2198
+ });
2199
+ },
2200
+ // transforms
2201
+ screenToFlowPosition: (p) => screenToFlow(p, viewportRef.current),
2202
+ flowToScreenPosition: (p) => flowToScreen(p, viewportRef.current),
2203
+ // reads
2204
+ getNodes: () => nodesRef.current.slice(),
2205
+ getEdges: () => edgesRef.current.slice(),
2206
+ getNode: (id) => nodesRef.current.find((n) => n.id === id),
2207
+ getEdge: (id) => edgesRef.current.find((e) => e.id === id),
2208
+ getNodesBounds: (subset) => {
2209
+ const pool = subset ? nodesRef.current.filter((n) => subset.some((x) => x.id === n.id)) : nodesRef.current.filter((n) => !n.hidden);
2210
+ if (pool.length === 0) return { x: 0, y: 0, width: 0, height: 0 };
2211
+ let minX = Number.POSITIVE_INFINITY;
2212
+ let minY = Number.POSITIVE_INFINITY;
2213
+ let maxX = Number.NEGATIVE_INFINITY;
2214
+ let maxY = Number.NEGATIVE_INFINITY;
2215
+ for (const n of pool) {
2216
+ const w = n.width ?? DEFAULT_NODE_WIDTH;
2217
+ const h = effectiveHeight(n);
2218
+ minX = Math.min(minX, n.position.x);
2219
+ minY = Math.min(minY, n.position.y);
2220
+ maxX = Math.max(maxX, n.position.x + w);
2221
+ maxY = Math.max(maxY, n.position.y + h);
2222
+ }
2223
+ return { x: minX, y: minY, width: maxX - minX, height: maxY - minY };
2224
+ },
2225
+ getIntersectingNodes: (area, partially = true) => {
2226
+ return nodesRef.current.filter((n) => {
2227
+ if (n.hidden) return false;
2228
+ const w = n.width ?? DEFAULT_NODE_WIDTH;
2229
+ const h = effectiveHeight(n);
2230
+ if (partially) {
2231
+ 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;
2232
+ }
2233
+ 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;
2234
+ });
2235
+ },
2236
+ // mutations
2237
+ addNodes: (nodes2) => {
2238
+ const arr = Array.isArray(nodes2) ? nodes2 : [nodes2];
2239
+ onNodesChangeRefForInstance.current?.(arr.map((item) => change.node.add(item)));
2240
+ },
2241
+ addEdges: (edges2) => {
2242
+ const arr = Array.isArray(edges2) ? edges2 : [edges2];
2243
+ onEdgesChangeRefForInstance.current?.(arr.map((item) => change.edge.add(item)));
2244
+ },
2245
+ updateNodeData: (id, partial) => {
2246
+ const cur = nodesRef.current.find((n) => n.id === id);
2247
+ if (!cur) return;
2248
+ const nextData = { ...cur.data ?? {}, ...partial };
2249
+ onNodesChangeRefForInstance.current?.([
2250
+ change.node.replace(id, { ...cur, data: nextData })
2251
+ ]);
2252
+ },
2253
+ updateNode: (id, partial) => {
2254
+ const cur = nodesRef.current.find((n) => n.id === id);
2255
+ if (!cur) return;
2256
+ onNodesChangeRefForInstance.current?.([change.node.replace(id, { ...cur, ...partial })]);
2257
+ },
2258
+ deleteElements: async ({ nodes: ns, edges: es }) => {
2259
+ const nodesToDelete = (ns ?? []).map((x) => nodesRef.current.find((n) => n.id === x.id)).filter((n) => !!n);
2260
+ const edgesToDelete = (es ?? []).map((x) => edgesRef.current.find((e) => e.id === x.id)).filter((e) => !!e);
2261
+ const before = onBeforeDeleteRef.current;
2262
+ if (before) {
2263
+ const ok = await before({ nodes: nodesToDelete, edges: edgesToDelete });
2264
+ if (!ok) return false;
2265
+ }
2266
+ if (nodesToDelete.length > 0) {
2267
+ onNodesChangeRefForInstance.current?.(nodesToDelete.map((n) => change.node.remove(n.id)));
2268
+ }
2269
+ if (edgesToDelete.length > 0) {
2270
+ onEdgesChangeRefForInstance.current?.(edgesToDelete.map((e) => change.edge.remove(e.id)));
2271
+ }
2272
+ return true;
2273
+ }
2274
+ }),
2275
+ [setViewport, minZoom, maxZoom]
2276
+ );
2277
+ const initFiredRef = useRef4(false);
2278
+ useEffect4(() => {
2279
+ if (initFiredRef.current) return;
2280
+ initFiredRef.current = true;
2281
+ onInit?.(instance);
2282
+ }, [instance, onInit]);
2283
+ useEffect4(() => {
2284
+ const onKey = (e) => {
2285
+ if (e.key !== "Backspace" && e.key !== "Delete") return;
2286
+ const target = e.target;
2287
+ if (target && (target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.tagName === "SELECT" || target.isContentEditable)) {
2288
+ return;
2289
+ }
2290
+ if (!containerRef.current?.contains(target) && document.activeElement !== document.body) {
2291
+ return;
2292
+ }
2293
+ const sel = store.getSnapshot();
2294
+ if (sel.selectedNodeIds.size === 0 && sel.selectedEdgeIds.size === 0) return;
2295
+ e.preventDefault();
2296
+ void instance.deleteElements({
2297
+ nodes: Array.from(sel.selectedNodeIds, (id) => ({ id })),
2298
+ edges: Array.from(sel.selectedEdgeIds, (id) => ({ id }))
2299
+ });
2300
+ };
2301
+ window.addEventListener("keydown", onKey);
2302
+ return () => window.removeEventListener("keydown", onKey);
2303
+ }, [instance, store]);
2304
+ const bridge = useMemo2(
2305
+ () => ({
2306
+ beginNodeDrag,
2307
+ selectNode,
2308
+ notifyNodeClick,
2309
+ selectEdge,
2310
+ reportDimensions,
2311
+ deleteNode: deleteNodeImpl,
2312
+ toggleNodeCollapse: toggleNodeCollapseImpl
2313
+ }),
2314
+ [
2315
+ beginNodeDrag,
2316
+ selectNode,
2317
+ notifyNodeClick,
2318
+ selectEdge,
2319
+ reportDimensions,
2320
+ deleteNodeImpl,
2321
+ toggleNodeCollapseImpl
2322
+ ]
2323
+ );
2324
+ const [panGesture, setPanGesture] = useState2(false);
2325
+ const isEmpty = nodes.length === 0 && edges.length === 0;
2326
+ const isConnecting = conn !== null;
2327
+ const visibleNodes = useMemo2(() => nodes.filter((n) => !n.hidden), [nodes]);
2328
+ const visibleEdges = useMemo2(() => {
2329
+ if (visibleNodes.length === nodes.length) return edges;
2330
+ const visibleIds = new Set(visibleNodes.map((n) => n.id));
2331
+ return edges.filter((e) => visibleIds.has(e.source) && visibleIds.has(e.target));
2332
+ }, [edges, nodes, visibleNodes]);
2333
+ const orderedNodes = useMemo2(() => {
2334
+ const isContainer = (n) => n.type === "group" || n.type === "forEach";
2335
+ const depth = (n) => {
2336
+ let d = 0;
2337
+ let cursor = n.parentId;
2338
+ const seen = /* @__PURE__ */ new Set();
2339
+ while (cursor) {
2340
+ if (seen.has(cursor)) return Number.POSITIVE_INFINITY;
2341
+ seen.add(cursor);
2342
+ d++;
2343
+ cursor = visibleNodes.find((x) => x.id === cursor)?.parentId;
2344
+ }
2345
+ return d;
2346
+ };
2347
+ const containers = visibleNodes.filter(isContainer);
2348
+ const others = visibleNodes.filter((n) => !isContainer(n));
2349
+ containers.sort((a, b) => depth(a) - depth(b));
2350
+ return [...containers, ...others];
2351
+ }, [visibleNodes]);
2352
+ 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(
2353
+ "div",
2354
+ {
2355
+ ref: containerRef,
2356
+ className: cn(
2357
+ "ods-flow-canvas-v2",
2358
+ panGesture && "ods-flow-canvas-v2--panning",
2359
+ isConnecting && "ods-flow-canvas-v2--connecting",
2360
+ draggingId && "ods-flow-canvas-v2--dragging",
2361
+ className
2362
+ ),
2363
+ style: {
2364
+ position: "relative",
2365
+ width,
2366
+ height,
2367
+ overflow: "hidden",
2368
+ userSelect: "none",
2369
+ touchAction: "none",
2370
+ // Cursor: state-driven so it flips instantly with the
2371
+ // gesture. CSS `:active` would lag behind pointer-capture.
2372
+ cursor: panGesture ? "grabbing" : isConnecting ? "crosshair" : panOnDrag ? "grab" : "default",
2373
+ ...style
2374
+ },
2375
+ onPointerDown: onCanvasPointerDown,
2376
+ onWheel: handleWheel,
2377
+ onContextMenu: (e) => {
2378
+ const t = e.target;
2379
+ const nodeEl = t.closest("[data-node-id]");
2380
+ if (nodeEl && onNodeContextMenu) {
2381
+ const id = nodeEl.dataset.nodeId;
2382
+ const node = nodes.find((n) => n.id === id);
2383
+ if (node) onNodeContextMenu(e, node);
2384
+ return;
2385
+ }
2386
+ const edgeEl = t.closest("[data-edge-id]");
2387
+ if (edgeEl && onEdgeContextMenu) {
2388
+ const id = edgeEl.dataset.edgeId;
2389
+ const edge = edges.find((x) => x.id === id);
2390
+ if (edge) onEdgeContextMenu(e, edge);
2391
+ return;
2392
+ }
2393
+ onPaneContextMenu?.(e);
2394
+ },
2395
+ "data-empty": isEmpty ? "true" : void 0,
2396
+ children: [
2397
+ background !== "none" && /* @__PURE__ */ jsx6(
2398
+ "div",
2399
+ {
2400
+ className: cn(
2401
+ "ods-flow-canvas-v2__grid",
2402
+ `ods-flow-canvas-v2__grid--${background}`
2403
+ ),
2404
+ style: {
2405
+ // Custom property drives the four variants' SCSS.
2406
+ "--ods-flow-grid-size": `${gridSize * viewport.zoom}px`,
2407
+ backgroundPosition: `${viewport.x}px ${viewport.y}px`
2408
+ }
2409
+ }
2410
+ ),
2411
+ /* @__PURE__ */ jsxs5(
2412
+ "div",
2413
+ {
2414
+ className: "ods-flow-canvas-v2__viewport",
2415
+ style: {
2416
+ position: "absolute",
2417
+ inset: 0,
2418
+ transform: `translate(${viewport.x}px, ${viewport.y}px) scale(${viewport.zoom})`,
2419
+ transformOrigin: "0 0"
2420
+ },
2421
+ children: [
2422
+ /* @__PURE__ */ jsx6(
2423
+ EdgesLayer,
2424
+ {
2425
+ edges: visibleEdges,
2426
+ nodes: visibleNodes,
2427
+ onSelect: (id) => bridge.selectEdge(id, false),
2428
+ onDelete: (id) => onEdgesChangeRef(id, onEdgesChange),
2429
+ onLabelChange: onEdgeLabelChange,
2430
+ ghost: conn ? { start: conn.start, end: conn.end } : null,
2431
+ handleVersion
2432
+ }
2433
+ ),
2434
+ orderedNodes.map((node) => {
2435
+ const Kind = kinds[node.type] ?? kinds.action;
2436
+ if (!Kind) return null;
2437
+ return /* @__PURE__ */ jsx6(
2438
+ FlowNode,
2439
+ {
2440
+ node,
2441
+ selected: selectedNodeIds.has(node.id),
2442
+ dragging: draggingId === node.id,
2443
+ isConnecting,
2444
+ Kind
2445
+ },
2446
+ node.id
2447
+ );
2448
+ })
2449
+ ]
2450
+ }
2451
+ ),
2452
+ isEmpty && emptyState && /* @__PURE__ */ jsx6("div", { className: "ods-flow-canvas-v2__empty", children: emptyState }),
2453
+ children
2454
+ ]
2455
+ }
2456
+ ) }) }) }) }) });
2457
+ }
2458
+ function onEdgesChangeRef(id, cb) {
2459
+ cb?.([change.edge.remove(id)]);
2460
+ }
2461
+ var EdgesLayer = memo2(function EdgesLayer2({
2462
+ edges,
2463
+ nodes,
2464
+ onSelect,
2465
+ onDelete,
2466
+ onLabelChange,
2467
+ ghost,
2468
+ handleVersion: _handleVersion
2469
+ }) {
2470
+ return /* @__PURE__ */ jsxs5(
2471
+ "svg",
2472
+ {
2473
+ className: "ods-flow-canvas-v2__edges",
2474
+ style: { position: "absolute", inset: 0, overflow: "visible", pointerEvents: "none" },
2475
+ width: "100%",
2476
+ height: "100%",
2477
+ children: [
2478
+ /* @__PURE__ */ jsx6("g", { style: { pointerEvents: "auto" }, children: edges.map((edge) => /* @__PURE__ */ jsx6(
2479
+ FlowEdge,
2480
+ {
2481
+ edge,
2482
+ nodes,
2483
+ onSelect,
2484
+ onDelete,
2485
+ onLabelChange,
2486
+ handleVersion: _handleVersion
2487
+ },
2488
+ edge.id
2489
+ )) }),
2490
+ ghost && /* @__PURE__ */ jsx6(
2491
+ "path",
2492
+ {
2493
+ d: `M ${ghost.start.x} ${ghost.start.y} L ${ghost.end.x} ${ghost.end.y}`,
2494
+ stroke: "var(--ods-accent, #4f46e5)",
2495
+ strokeWidth: 1.5,
2496
+ strokeDasharray: "4 4",
2497
+ fill: "none"
2498
+ }
2499
+ )
2500
+ ]
2501
+ }
2502
+ );
2503
+ });
2504
+
2505
+ export {
2506
+ useFlow,
2507
+ applyNodeChanges,
2508
+ applyEdgeChanges,
2509
+ change,
2510
+ useFlowStore,
2511
+ DEFAULT_NODE_WIDTH,
2512
+ DEFAULT_NODE_HEIGHT,
2513
+ handleCentre,
2514
+ bezierPath,
2515
+ screenToFlow,
2516
+ flowToScreen,
2517
+ descendantsOf,
2518
+ findAncestor,
2519
+ clampToParentExtent,
2520
+ findContainingGroup,
2521
+ buildEdgePath,
2522
+ bezierPath2,
2523
+ stepPath,
2524
+ smoothStepPath,
2525
+ straightPath,
2526
+ FlowEdge,
2527
+ useFlowNodeContext,
2528
+ FlowNode,
2529
+ buildNodeKindRegistry,
2530
+ Handle,
2531
+ ActionNode,
2532
+ TriggerNode,
2533
+ ConditionNode,
2534
+ GroupNode,
2535
+ ForEachNode,
2536
+ OutputNode,
2537
+ ErrorNode,
2538
+ WaitNode,
2539
+ ParallelNode,
2540
+ StickyNode,
2541
+ WebhookNode,
2542
+ HttpRequestNode,
2543
+ DEFAULT_NODE_KINDS,
2544
+ FlowCanvas
2545
+ };
2546
+ //# sourceMappingURL=chunk-DYCW4TYB.js.map