@solidxai/core-ui 0.1.13 → 0.1.14-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 (147) hide show
  1. package/dist/components/common/SolidPopupContainer.d.ts.map +1 -1
  2. package/dist/components/common/SolidPopupContainer.js +68 -5
  3. package/dist/components/common/SolidPopupContainer.js.map +1 -1
  4. package/dist/components/common/SolidPopupContainer.tsx +50 -4
  5. package/dist/components/core/card/SolidCardViewConfigure.d.ts.map +1 -1
  6. package/dist/components/core/card/SolidCardViewConfigure.js +1 -1
  7. package/dist/components/core/card/SolidCardViewConfigure.js.map +1 -1
  8. package/dist/components/core/card/SolidCardViewConfigure.tsx +3 -1
  9. package/dist/components/core/extension/solid-core/workflowDefinition/list/openWorkflowDefinitionEditorHeaderAction.d.ts +2 -0
  10. package/dist/components/core/extension/solid-core/workflowDefinition/list/openWorkflowDefinitionEditorHeaderAction.d.ts.map +1 -0
  11. package/dist/components/core/extension/solid-core/workflowDefinition/list/openWorkflowDefinitionEditorHeaderAction.js +4 -0
  12. package/dist/components/core/extension/solid-core/workflowDefinition/list/openWorkflowDefinitionEditorHeaderAction.js.map +1 -0
  13. package/dist/components/core/extension/solid-core/workflowDefinition/list/openWorkflowDefinitionEditorHeaderAction.ts +3 -0
  14. package/dist/components/core/extension/solid-core/workflowDefinition/list/openWorkflowDefinitionEditorRowAction.d.ts +8 -0
  15. package/dist/components/core/extension/solid-core/workflowDefinition/list/openWorkflowDefinitionEditorRowAction.d.ts.map +1 -0
  16. package/dist/components/core/extension/solid-core/workflowDefinition/list/openWorkflowDefinitionEditorRowAction.js +9 -0
  17. package/dist/components/core/extension/solid-core/workflowDefinition/list/openWorkflowDefinitionEditorRowAction.js.map +1 -0
  18. package/dist/components/core/extension/solid-core/workflowDefinition/list/openWorkflowDefinitionEditorRowAction.ts +17 -0
  19. package/dist/components/core/form/SolidFormView.d.ts.map +1 -1
  20. package/dist/components/core/form/SolidFormView.js +52 -22
  21. package/dist/components/core/form/SolidFormView.js.map +1 -1
  22. package/dist/components/core/form/SolidFormView.tsx +49 -9
  23. package/dist/components/core/kanban/SolidKanbanViewConfigure.d.ts.map +1 -1
  24. package/dist/components/core/kanban/SolidKanbanViewConfigure.js +1 -1
  25. package/dist/components/core/kanban/SolidKanbanViewConfigure.js.map +1 -1
  26. package/dist/components/core/kanban/SolidKanbanViewConfigure.tsx +3 -1
  27. package/dist/components/core/list/SolidCustomListViewColumn.d.ts +2 -1
  28. package/dist/components/core/list/SolidCustomListViewColumn.d.ts.map +1 -1
  29. package/dist/components/core/list/SolidCustomListViewColumn.js +3 -2
  30. package/dist/components/core/list/SolidCustomListViewColumn.js.map +1 -1
  31. package/dist/components/core/list/SolidCustomListViewColumn.tsx +4 -1
  32. package/dist/components/core/list/SolidListView.d.ts.map +1 -1
  33. package/dist/components/core/list/SolidListView.js +75 -71
  34. package/dist/components/core/list/SolidListView.js.map +1 -1
  35. package/dist/components/core/list/SolidListView.tsx +25 -10
  36. package/dist/components/core/list/SolidListViewColumn.d.ts +3 -1
  37. package/dist/components/core/list/SolidListViewColumn.d.ts.map +1 -1
  38. package/dist/components/core/list/SolidListViewColumn.js +81 -42
  39. package/dist/components/core/list/SolidListViewColumn.js.map +1 -1
  40. package/dist/components/core/list/SolidListViewColumn.tsx +93 -44
  41. package/dist/components/core/list/SolidListViewConfigure.d.ts.map +1 -1
  42. package/dist/components/core/list/SolidListViewConfigure.js +2 -2
  43. package/dist/components/core/list/SolidListViewConfigure.js.map +1 -1
  44. package/dist/components/core/list/SolidListViewConfigure.tsx +4 -2
  45. package/dist/components/core/list/widgets/PillWidget.d.ts +3 -0
  46. package/dist/components/core/list/widgets/PillWidget.d.ts.map +1 -0
  47. package/dist/components/core/list/widgets/PillWidget.js +95 -0
  48. package/dist/components/core/list/widgets/PillWidget.js.map +1 -0
  49. package/dist/components/core/list/widgets/PillWidget.tsx +127 -0
  50. package/dist/components/shad-cn-ui/SolidDialog.js +1 -1
  51. package/dist/components/shad-cn-ui/SolidDialog.js.map +1 -1
  52. package/dist/components/shad-cn-ui/SolidDialog.tsx +1 -1
  53. package/dist/components/shad-cn-ui/SolidDropdownMenu.d.ts +3 -1
  54. package/dist/components/shad-cn-ui/SolidDropdownMenu.d.ts.map +1 -1
  55. package/dist/components/shad-cn-ui/SolidDropdownMenu.js +2 -2
  56. package/dist/components/shad-cn-ui/SolidDropdownMenu.js.map +1 -1
  57. package/dist/components/shad-cn-ui/SolidDropdownMenu.tsx +11 -5
  58. package/dist/components/shad-cn-ui/SolidIcon.d.ts +2 -1
  59. package/dist/components/shad-cn-ui/SolidIcon.d.ts.map +1 -1
  60. package/dist/components/shad-cn-ui/SolidIcon.js +2 -1
  61. package/dist/components/shad-cn-ui/SolidIcon.js.map +1 -1
  62. package/dist/components/shad-cn-ui/SolidIcon.tsx +2 -0
  63. package/dist/components/workflow/WorkflowFlowCanvas.css +454 -0
  64. package/dist/components/workflow/WorkflowFlowCanvas.d.ts +40 -0
  65. package/dist/components/workflow/WorkflowFlowCanvas.d.ts.map +1 -0
  66. package/dist/components/workflow/WorkflowFlowCanvas.js +861 -0
  67. package/dist/components/workflow/WorkflowFlowCanvas.js.map +1 -0
  68. package/dist/components/workflow/WorkflowFlowCanvas.tsx +1522 -0
  69. package/dist/components/workflow/WorkflowNodeDocsPanel.css +247 -0
  70. package/dist/components/workflow/WorkflowNodeDocsPanel.d.ts +22 -0
  71. package/dist/components/workflow/WorkflowNodeDocsPanel.d.ts.map +1 -0
  72. package/dist/components/workflow/WorkflowNodeDocsPanel.js +97 -0
  73. package/dist/components/workflow/WorkflowNodeDocsPanel.js.map +1 -0
  74. package/dist/components/workflow/WorkflowNodeDocsPanel.tsx +363 -0
  75. package/dist/components/workflow/WorkflowNodeSchemaEditor.css +802 -0
  76. package/dist/components/workflow/WorkflowNodeSchemaEditor.d.ts +72 -0
  77. package/dist/components/workflow/WorkflowNodeSchemaEditor.d.ts.map +1 -0
  78. package/dist/components/workflow/WorkflowNodeSchemaEditor.js +1107 -0
  79. package/dist/components/workflow/WorkflowNodeSchemaEditor.js.map +1 -0
  80. package/dist/components/workflow/WorkflowNodeSchemaEditor.tsx +2347 -0
  81. package/dist/helpers/registry.d.ts.map +1 -1
  82. package/dist/helpers/registry.js +7 -0
  83. package/dist/helpers/registry.js.map +1 -1
  84. package/dist/helpers/registry.ts +8 -0
  85. package/dist/index.d.ts +6 -0
  86. package/dist/index.d.ts.map +1 -1
  87. package/dist/index.js +5 -0
  88. package/dist/index.js.map +1 -1
  89. package/dist/index.ts +37 -0
  90. package/dist/redux/api/workflowDefinitionEditorApi.d.ts +17 -0
  91. package/dist/redux/api/workflowDefinitionEditorApi.d.ts.map +1 -0
  92. package/dist/redux/api/workflowDefinitionEditorApi.js +38 -0
  93. package/dist/redux/api/workflowDefinitionEditorApi.js.map +1 -0
  94. package/dist/redux/api/workflowDefinitionEditorApi.ts +40 -0
  95. package/dist/redux/api/workflowNodeApi.d.ts +6 -0
  96. package/dist/redux/api/workflowNodeApi.d.ts.map +1 -0
  97. package/dist/redux/api/workflowNodeApi.js +14 -0
  98. package/dist/redux/api/workflowNodeApi.js.map +1 -0
  99. package/dist/redux/api/workflowNodeApi.ts +18 -0
  100. package/dist/redux/features/popupSlice.d.ts +17 -2
  101. package/dist/redux/features/popupSlice.d.ts.map +1 -1
  102. package/dist/redux/features/popupSlice.js.map +1 -1
  103. package/dist/redux/features/popupSlice.ts +19 -3
  104. package/dist/redux/store/defaultStoreConfig.d.ts +13 -0
  105. package/dist/redux/store/defaultStoreConfig.d.ts.map +1 -1
  106. package/dist/redux/store/defaultStoreConfig.js +4 -0
  107. package/dist/redux/store/defaultStoreConfig.js.map +1 -1
  108. package/dist/redux/store/defaultStoreConfig.ts +4 -0
  109. package/dist/redux/store/solidEntityApiPool.d.ts.map +1 -1
  110. package/dist/redux/store/solidEntityApiPool.js +1 -0
  111. package/dist/redux/store/solidEntityApiPool.js.map +1 -1
  112. package/dist/redux/store/solidEntityApiPool.ts +1 -0
  113. package/dist/resources/solid-custom.css +16 -0
  114. package/dist/resources/solid-tailwind-generated.css +1 -1
  115. package/dist/routes/pages/admin/core/WorkflowDefinitionEditorPage.css +3194 -0
  116. package/dist/routes/pages/admin/core/WorkflowDefinitionEditorPage.d.ts +3 -0
  117. package/dist/routes/pages/admin/core/WorkflowDefinitionEditorPage.d.ts.map +1 -0
  118. package/dist/routes/pages/admin/core/WorkflowDefinitionEditorPage.js +3371 -0
  119. package/dist/routes/pages/admin/core/WorkflowDefinitionEditorPage.js.map +1 -0
  120. package/dist/routes/pages/admin/core/WorkflowDefinitionEditorPage.tsx +6215 -0
  121. package/dist/routes/pages/admin/core/WorkflowDefinitionListPage.css +217 -0
  122. package/dist/routes/pages/admin/core/WorkflowDefinitionListPage.d.ts +3 -0
  123. package/dist/routes/pages/admin/core/WorkflowDefinitionListPage.d.ts.map +1 -0
  124. package/dist/routes/pages/admin/core/WorkflowDefinitionListPage.js +268 -0
  125. package/dist/routes/pages/admin/core/WorkflowDefinitionListPage.js.map +1 -0
  126. package/dist/routes/pages/admin/core/WorkflowDefinitionListPage.tsx +510 -0
  127. package/dist/routes/pages/admin/core/WorkflowExecutionDetailPage.d.ts +3 -0
  128. package/dist/routes/pages/admin/core/WorkflowExecutionDetailPage.d.ts.map +1 -0
  129. package/dist/routes/pages/admin/core/WorkflowExecutionDetailPage.js +618 -0
  130. package/dist/routes/pages/admin/core/WorkflowExecutionDetailPage.js.map +1 -0
  131. package/dist/routes/pages/admin/core/WorkflowExecutionDetailPage.tsx +1322 -0
  132. package/dist/routes/solidRoutes.d.ts.map +1 -1
  133. package/dist/routes/solidRoutes.js +6 -0
  134. package/dist/routes/solidRoutes.js.map +1 -1
  135. package/dist/routes/solidRoutes.tsx +6 -0
  136. package/dist/types/extension-registry.d.ts +4 -0
  137. package/dist/types/extension-registry.d.ts.map +1 -1
  138. package/dist/types/extension-registry.js +5 -1
  139. package/dist/types/extension-registry.js.map +1 -1
  140. package/dist/types/extension-registry.ts +5 -1
  141. package/dist/types/solid-core.d.ts +32 -0
  142. package/dist/types/workflow-node.d.ts +142 -0
  143. package/dist/types/workflow-node.d.ts.map +1 -0
  144. package/dist/types/workflow-node.js +2 -0
  145. package/dist/types/workflow-node.js.map +1 -0
  146. package/dist/types/workflow-node.ts +179 -0
  147. package/package.json +3 -1
@@ -0,0 +1,1522 @@
1
+ import React from "react";
2
+ import {
3
+ Background,
4
+ BackgroundVariant,
5
+ BaseEdge,
6
+ Controls,
7
+ type EdgeProps,
8
+ type Edge,
9
+ Handle,
10
+ MarkerType,
11
+ type Node,
12
+ Position,
13
+ ReactFlow,
14
+ ReactFlowProvider,
15
+ } from "@xyflow/react";
16
+ import { CircleHelp, Pencil, Plus, Trash2 } from "lucide-react";
17
+ import type {
18
+ WorkflowNodeChildSlotDefinition,
19
+ WorkflowNodeMetadataResponse,
20
+ } from "../../types/workflow-node";
21
+ import { normalizeSolidIconName, SolidIcon } from "../shad-cn-ui";
22
+ import "@xyflow/react/dist/style.css";
23
+ import "./WorkflowFlowCanvas.css";
24
+
25
+ type WorkflowNodeRecord = Record<string, any>;
26
+ type WorkflowTriggerRecord = Record<string, any>;
27
+ type WorkflowSequenceSlotKey = "tasks" | "then" | "else" | "defaults";
28
+
29
+ type WorkflowInsertScope =
30
+ | { scope: "root" }
31
+ | {
32
+ scope: "slot";
33
+ parentNodeId: string;
34
+ slotKey: WorkflowSequenceSlotKey;
35
+ }
36
+ | {
37
+ scope: "case";
38
+ parentNodeId: string;
39
+ caseKey: string;
40
+ };
41
+
42
+ export type WorkflowInsertTarget =
43
+ | {
44
+ scope: "root";
45
+ index: number;
46
+ }
47
+ | {
48
+ scope: "slot";
49
+ parentNodeId: string;
50
+ slotKey: WorkflowSequenceSlotKey;
51
+ index: number;
52
+ }
53
+ | {
54
+ scope: "case";
55
+ parentNodeId: string;
56
+ caseKey: string;
57
+ index: number;
58
+ };
59
+
60
+ type WorkflowCanvasNodeData =
61
+ | {
62
+ kind: "group";
63
+ label: string;
64
+ tone?: "control" | "loop" | "trigger";
65
+ workflowNode?: WorkflowNodeRecord;
66
+ nodeType?: WorkflowNodeMetadataResponse;
67
+ onViewDocs?: (nodeId: string) => void;
68
+ }
69
+ | {
70
+ kind: "workflow-node";
71
+ workflowNode: WorkflowNodeRecord;
72
+ nodeType?: WorkflowNodeMetadataResponse;
73
+ selected?: boolean;
74
+ onSelectNode: (nodeId: string) => void;
75
+ onEditNode: (nodeId: string) => void;
76
+ onDeleteNode: (nodeId: string) => void;
77
+ onViewDocs: (nodeId: string) => void;
78
+ }
79
+ | {
80
+ kind: "workflow-trigger";
81
+ trigger: WorkflowTriggerRecord;
82
+ selected?: boolean;
83
+ onSelectTrigger: (triggerId: string) => void;
84
+ onViewDocs: (triggerId: string) => void;
85
+ }
86
+ | {
87
+ kind: "insert";
88
+ enabled?: boolean;
89
+ selectedTypeLabel?: string;
90
+ onInsert: () => void;
91
+ }
92
+ | {
93
+ kind: "junction";
94
+ }
95
+ | {
96
+ kind: "section-label";
97
+ label: string;
98
+ };
99
+
100
+ type WorkflowFlowCanvasProps = {
101
+ definition: { nodes: WorkflowNodeRecord[]; triggers?: WorkflowTriggerRecord[] };
102
+ nodeTypes: WorkflowNodeMetadataResponse[];
103
+ selectedNodeId?: string;
104
+ selectedTriggerId?: string;
105
+ activePaletteNodeType?: WorkflowNodeMetadataResponse;
106
+ onSelectNode: (nodeId: string) => void;
107
+ onSelectTrigger: (triggerId: string) => void;
108
+ onEditNode: (nodeId: string) => void;
109
+ onDeleteNode: (nodeId: string) => void;
110
+ onViewDocs: (nodeId: string) => void;
111
+ onViewTriggerDocs: (triggerId: string) => void;
112
+ onInsertNode: (target: WorkflowInsertTarget) => void;
113
+ };
114
+
115
+ const DIMENSIONS = {
116
+ workflowWidth: 300,
117
+ workflowHeight: 136,
118
+ triggerWidth: 280,
119
+ triggerHeight: 108,
120
+ triggerGap: 34,
121
+ insertWidth: 40,
122
+ insertHeight: 40,
123
+ junctionWidth: 8,
124
+ junctionHeight: 8,
125
+ sectionLabelWidth: 104,
126
+ sectionLabelHeight: 28,
127
+ groupPaddingX: 36,
128
+ groupPaddingTop: 58,
129
+ groupPaddingBottom: 36,
130
+ loopGroupPaddingX: 70,
131
+ loopGroupPaddingTop: 62,
132
+ loopGroupPaddingBottom: 44,
133
+ sequenceInsertToNodeGap: 88,
134
+ sequenceNodeToInsertGap: 48,
135
+ controlNodeToChildGap: 78,
136
+ controlBranchLabelGap: 42,
137
+ controlBranchGap: 120,
138
+ controlJoinGap: 92,
139
+ groupExteriorEdgeGap: 44,
140
+ };
141
+
142
+ const DEFAULT_WORKFLOW_VIEWPORT = {
143
+ x: 360,
144
+ y: 56,
145
+ zoom: 0.82,
146
+ };
147
+
148
+ type WorkflowLayoutResult = {
149
+ entryIds: string[];
150
+ exitIds: string[];
151
+ endY: number;
152
+ width: number;
153
+ };
154
+
155
+ type GraphBuildContext = {
156
+ backgroundNodes: Node<WorkflowCanvasNodeData>[];
157
+ nodes: Node<WorkflowCanvasNodeData>[];
158
+ edges: Edge[];
159
+ nodeTypeMap: Map<string, WorkflowNodeMetadataResponse>;
160
+ activePaletteNodeType?: WorkflowNodeMetadataResponse;
161
+ selectedNodeId?: string;
162
+ selectedTriggerId?: string;
163
+ onSelectNode: (nodeId: string) => void;
164
+ onSelectTrigger: (triggerId: string) => void;
165
+ onEditNode: (nodeId: string) => void;
166
+ onDeleteNode: (nodeId: string) => void;
167
+ onViewDocs: (nodeId: string) => void;
168
+ onViewTriggerDocs: (triggerId: string) => void;
169
+ onInsertNode: (target: WorkflowInsertTarget) => void;
170
+ };
171
+
172
+ function normalizeChildSlots(
173
+ node: WorkflowNodeRecord,
174
+ nodeType?: WorkflowNodeMetadataResponse,
175
+ ): WorkflowNodeChildSlotDefinition[] {
176
+ if (nodeType?.authoring?.childSlots?.length) {
177
+ return nodeType.authoring.childSlots;
178
+ }
179
+
180
+ const slots: WorkflowNodeChildSlotDefinition[] = [];
181
+ if (node.cases && typeof node.cases === "object" && !Array.isArray(node.cases)) {
182
+ slots.push({ key: "cases", label: "Cases", kind: "case-collection" });
183
+ if (Array.isArray(node.defaults)) {
184
+ slots.push({ key: "defaults", label: "Default", kind: "sequence" });
185
+ }
186
+ } else if (Array.isArray(node.then) || Array.isArray(node.else)) {
187
+ slots.push({ key: "then", label: "Then", kind: "sequence" });
188
+ slots.push({ key: "else", label: "Else", kind: "sequence" });
189
+ } else if (Array.isArray(node.tasks)) {
190
+ slots.push({ key: "tasks", label: "Tasks", kind: "sequence" });
191
+ }
192
+
193
+ return slots;
194
+ }
195
+
196
+ function isLoopNode(
197
+ workflowNode: WorkflowNodeRecord,
198
+ nodeType?: WorkflowNodeMetadataResponse,
199
+ ) {
200
+ const nodeTypeId = String(workflowNode.type ?? nodeType?.type ?? "").toLowerCase();
201
+ const category = String(nodeType?.category ?? "").toLowerCase();
202
+ const nodeTypeTags = nodeType?.tags;
203
+ const tags = Array.isArray(nodeTypeTags)
204
+ ? nodeTypeTags.map((tag) => String(tag).toLowerCase())
205
+ : [];
206
+
207
+ return (
208
+ nodeTypeId === "foreach" ||
209
+ nodeTypeId === "for.each" ||
210
+ nodeTypeId === "loopuntil" ||
211
+ nodeTypeId === "loop.until" ||
212
+ category.includes("loop") ||
213
+ tags.includes("loop") ||
214
+ tags.includes("iteration")
215
+ );
216
+ }
217
+
218
+ function getSequenceSlotNodes(
219
+ workflowNode: WorkflowNodeRecord,
220
+ slotKey: string,
221
+ ): WorkflowNodeRecord[] {
222
+ if (Array.isArray(workflowNode[slotKey])) {
223
+ return workflowNode[slotKey];
224
+ }
225
+
226
+ if (slotKey === "tasks") {
227
+ return [];
228
+ }
229
+
230
+ return [];
231
+ }
232
+
233
+ function getSwitchCaseEntries(
234
+ workflowNode: WorkflowNodeRecord,
235
+ ): Array<{ key: string; label: string; nodes: WorkflowNodeRecord[]; scope: WorkflowInsertScope }> {
236
+ const cases =
237
+ workflowNode.cases &&
238
+ typeof workflowNode.cases === "object" &&
239
+ !Array.isArray(workflowNode.cases)
240
+ ? workflowNode.cases
241
+ : {};
242
+
243
+ const entries: Array<{
244
+ key: string;
245
+ label: string;
246
+ nodes: WorkflowNodeRecord[];
247
+ scope: WorkflowInsertScope;
248
+ }> = Object.entries(cases).map(([caseKey, nodes]) => ({
249
+ key: `case-${caseKey}`,
250
+ label: caseKey,
251
+ nodes: Array.isArray(nodes) ? nodes : [],
252
+ scope: {
253
+ scope: "case" as const,
254
+ parentNodeId: String(workflowNode.id),
255
+ caseKey,
256
+ },
257
+ }));
258
+
259
+ if (Array.isArray(workflowNode.defaults)) {
260
+ entries.push({
261
+ key: "default",
262
+ label: "Default",
263
+ nodes: workflowNode.defaults,
264
+ scope: {
265
+ scope: "slot" as const,
266
+ parentNodeId: String(workflowNode.id),
267
+ slotKey: "defaults" as const,
268
+ },
269
+ });
270
+ }
271
+
272
+ return entries;
273
+ }
274
+
275
+ function getNodeRect(node: Node<WorkflowCanvasNodeData>) {
276
+ let width = Number(node.style?.width ?? 0);
277
+ let height = Number(node.style?.height ?? 0);
278
+
279
+ if (node.type === "workflow") {
280
+ width = DIMENSIONS.workflowWidth;
281
+ height = DIMENSIONS.workflowHeight;
282
+ } else if (node.type === "trigger") {
283
+ width = DIMENSIONS.triggerWidth;
284
+ height = DIMENSIONS.triggerHeight;
285
+ } else if (node.type === "insert") {
286
+ width = DIMENSIONS.insertWidth;
287
+ height = DIMENSIONS.insertHeight;
288
+ } else if (node.type === "junction") {
289
+ width = DIMENSIONS.junctionWidth;
290
+ height = DIMENSIONS.junctionHeight;
291
+ } else if (node.type === "sectionLabel") {
292
+ width = DIMENSIONS.sectionLabelWidth;
293
+ height = DIMENSIONS.sectionLabelHeight;
294
+ }
295
+
296
+ return {
297
+ left: node.position.x,
298
+ top: node.position.y,
299
+ right: node.position.x + width,
300
+ bottom: node.position.y + height,
301
+ };
302
+ }
303
+
304
+ function createEdge(
305
+ source: string,
306
+ target: string,
307
+ options: {
308
+ marker?: boolean;
309
+ kind?: "default" | "merge" | "split";
310
+ busY?: number;
311
+ splitMode?: "fromJunction";
312
+ } = {},
313
+ ): Edge {
314
+ const edgeKind = options.kind ?? (options.marker === false ? "merge" : "default");
315
+ const data =
316
+ options.busY == null && options.splitMode == null
317
+ ? undefined
318
+ : {
319
+ busY: options.busY,
320
+ splitMode: options.splitMode,
321
+ };
322
+
323
+ return {
324
+ id: `${source}->${target}`,
325
+ source,
326
+ target,
327
+ type:
328
+ edgeKind === "merge"
329
+ ? "workflowMerge"
330
+ : edgeKind === "split"
331
+ ? "workflowSplit"
332
+ : "smoothstep",
333
+ data,
334
+ markerEnd:
335
+ options.marker === false
336
+ ? undefined
337
+ : {
338
+ type: MarkerType.ArrowClosed,
339
+ width: 12,
340
+ height: 12,
341
+ color: "rgba(203, 213, 225, 0.94)",
342
+ },
343
+ style: {
344
+ stroke: "rgba(203, 213, 225, 0.94)",
345
+ strokeWidth: 2,
346
+ strokeDasharray: "6 7",
347
+ },
348
+ animated: true,
349
+ zIndex: 1,
350
+ };
351
+ }
352
+
353
+ function WorkflowMergeEdge({
354
+ id,
355
+ sourceX,
356
+ sourceY,
357
+ targetX,
358
+ targetY,
359
+ style,
360
+ }: EdgeProps) {
361
+ const mergeY = targetY;
362
+ const path = `M ${sourceX} ${sourceY} V ${mergeY} H ${targetX}`;
363
+
364
+ return (
365
+ <BaseEdge
366
+ id={id}
367
+ path={path}
368
+ style={style}
369
+ interactionWidth={18}
370
+ />
371
+ );
372
+ }
373
+
374
+ function WorkflowSplitEdge({
375
+ id,
376
+ sourceX,
377
+ sourceY,
378
+ targetX,
379
+ targetY,
380
+ markerEnd,
381
+ style,
382
+ data,
383
+ }: EdgeProps) {
384
+ if (data?.splitMode === "fromJunction") {
385
+ const path = `M ${sourceX} ${sourceY} H ${targetX} V ${targetY}`;
386
+
387
+ return (
388
+ <BaseEdge
389
+ id={id}
390
+ path={path}
391
+ markerEnd={markerEnd}
392
+ style={style}
393
+ interactionWidth={18}
394
+ />
395
+ );
396
+ }
397
+
398
+ const requestedBusY =
399
+ typeof data?.busY === "number"
400
+ ? data.busY
401
+ : sourceY + Math.max(24, (targetY - sourceY) * 0.42);
402
+ const minBusY = Math.min(sourceY, targetY) + 12;
403
+ const maxBusY = Math.max(sourceY, targetY) - 12;
404
+ const busY =
405
+ maxBusY > minBusY
406
+ ? Math.min(maxBusY, Math.max(minBusY, requestedBusY))
407
+ : (sourceY + targetY) / 2;
408
+ const path = `M ${sourceX} ${sourceY} V ${busY} H ${targetX} V ${targetY}`;
409
+
410
+ return (
411
+ <BaseEdge
412
+ id={id}
413
+ path={path}
414
+ markerEnd={markerEnd}
415
+ style={style}
416
+ interactionWidth={18}
417
+ />
418
+ );
419
+ }
420
+
421
+ function resolveWorkflowNodeIcon(nodeType?: WorkflowNodeMetadataResponse) {
422
+ return normalizeSolidIconName(nodeType?.ui?.icon ?? nodeType?.icon) ?? "si-th-large";
423
+ }
424
+
425
+ function getWorkflowNodeIconStyle(
426
+ nodeType?: WorkflowNodeMetadataResponse,
427
+ ): React.CSSProperties | undefined {
428
+ const backgroundColor = nodeType?.ui?.iconBackgroundColor;
429
+ const color = nodeType?.ui?.iconColor;
430
+ const borderColor = nodeType?.ui?.iconBorderColor;
431
+
432
+ if (!backgroundColor && !color && !borderColor) {
433
+ return undefined;
434
+ }
435
+
436
+ return {
437
+ ...(backgroundColor ? { backgroundColor } : null),
438
+ ...(color ? { color } : null),
439
+ ...(borderColor ? { borderColor } : null),
440
+ };
441
+ }
442
+
443
+ function estimateSequenceWidth(
444
+ sequence: WorkflowNodeRecord[],
445
+ nodeTypeMap: Map<string, WorkflowNodeMetadataResponse>,
446
+ ): number {
447
+ if (!sequence.length) {
448
+ return DIMENSIONS.insertWidth;
449
+ }
450
+
451
+ return sequence.reduce((maxWidth, workflowNode) => {
452
+ const nodeType = nodeTypeMap.get(String(workflowNode.type));
453
+ const nodeWidth = estimateWorkflowNodeWidth(workflowNode, nodeTypeMap, nodeType);
454
+ return Math.max(maxWidth, nodeWidth);
455
+ }, DIMENSIONS.workflowWidth);
456
+ }
457
+
458
+ function estimateWorkflowNodeWidth(
459
+ workflowNode: WorkflowNodeRecord,
460
+ nodeTypeMap: Map<string, WorkflowNodeMetadataResponse>,
461
+ nodeType?: WorkflowNodeMetadataResponse,
462
+ ): number {
463
+ const slotDefinitions = normalizeChildSlots(workflowNode, nodeType);
464
+
465
+ const branchSlots = slotDefinitions.filter(
466
+ (slot) => slot.key === "then" || slot.key === "else",
467
+ );
468
+ if (branchSlots.length >= 2) {
469
+ const branchGap = DIMENSIONS.controlBranchGap;
470
+ const branchWidths = branchSlots.map((slot) =>
471
+ estimateSequenceWidth(
472
+ Array.isArray(workflowNode[slot.key]) ? workflowNode[slot.key] : [],
473
+ nodeTypeMap,
474
+ ),
475
+ );
476
+ const totalBranchWidth =
477
+ branchWidths.reduce((sum, width) => sum + width, 0) +
478
+ branchGap * Math.max(branchWidths.length - 1, 0);
479
+ return Math.max(DIMENSIONS.workflowWidth, totalBranchWidth);
480
+ }
481
+
482
+ if (slotDefinitions.some((slot) => slot.kind === "case-collection")) {
483
+ const caseEntries = getSwitchCaseEntries(workflowNode);
484
+ const branchGap = DIMENSIONS.controlBranchGap;
485
+ const branchWidths = caseEntries.map((entry) =>
486
+ estimateSequenceWidth(entry.nodes, nodeTypeMap),
487
+ );
488
+ const totalBranchWidth =
489
+ branchWidths.reduce((sum, width) => sum + width, 0) +
490
+ branchGap * Math.max(branchWidths.length - 1, 0);
491
+ return Math.max(DIMENSIONS.workflowWidth, totalBranchWidth);
492
+ }
493
+
494
+ if (slotDefinitions.length === 1 && slotDefinitions[0].kind === "sequence") {
495
+ const slot = slotDefinitions[0];
496
+ const slotKey = slot.key as WorkflowSequenceSlotKey;
497
+ const childNodes = getSequenceSlotNodes(workflowNode, slotKey);
498
+ if (slot.layout === "parallel") {
499
+ const childWidths = childNodes.map((childNode: WorkflowNodeRecord) =>
500
+ estimateWorkflowNodeWidth(
501
+ childNode,
502
+ nodeTypeMap,
503
+ nodeTypeMap.get(String(childNode.type)),
504
+ ),
505
+ );
506
+ const totalChildWidth =
507
+ childWidths.reduce((sum, width) => sum + width, 0) +
508
+ DIMENSIONS.controlBranchGap * Math.max(childWidths.length - 1, 0);
509
+ return Math.max(DIMENSIONS.workflowWidth, totalChildWidth);
510
+ }
511
+
512
+ return Math.max(
513
+ DIMENSIONS.workflowWidth,
514
+ estimateSequenceWidth(childNodes, nodeTypeMap),
515
+ );
516
+ }
517
+
518
+ return DIMENSIONS.workflowWidth;
519
+ }
520
+
521
+ function WorkflowCanvasNodeRenderer({ data }: { data: WorkflowCanvasNodeData }) {
522
+ if (data.kind === "group") {
523
+ return (
524
+ <div
525
+ className={`workflow-flow-group-node workflow-flow-group-node--${data.tone ?? "control"}`}
526
+ >
527
+ <div className="workflow-flow-group-node__header">
528
+ <span>{data.label}</span>
529
+ {data.workflowNode ? (
530
+ <button
531
+ type="button"
532
+ className="workflow-flow-help-button nodrag nopan nowheel"
533
+ aria-label={`Open ${data.nodeType?.label ?? data.label} documentation`}
534
+ title="Documentation"
535
+ onPointerDown={(event) => {
536
+ event.stopPropagation();
537
+ }}
538
+ onClick={(event) => {
539
+ event.stopPropagation();
540
+ data.onViewDocs?.(String(data.workflowNode?.id));
541
+ }}
542
+ >
543
+ <CircleHelp size={12} />
544
+ </button>
545
+ ) : null}
546
+ </div>
547
+ </div>
548
+ );
549
+ }
550
+
551
+ if (data.kind === "insert") {
552
+ return (
553
+ <div className="workflow-flow-insert-node">
554
+ <button
555
+ type="button"
556
+ onPointerDown={(event) => {
557
+ event.stopPropagation();
558
+ }}
559
+ onClick={(event) => {
560
+ event.stopPropagation();
561
+ data.onInsert();
562
+ }}
563
+ className="workflow-flow-insert-node__button nodrag nopan nowheel"
564
+ aria-label={
565
+ data.enabled
566
+ ? `Add ${data.selectedTypeLabel ?? "node"}`
567
+ : "Add node"
568
+ }
569
+ title={
570
+ data.enabled
571
+ ? `Add ${data.selectedTypeLabel ?? "node"}`
572
+ : "Add node"
573
+ }
574
+ >
575
+ <Plus size={16} />
576
+ </button>
577
+ <Handle
578
+ type="target"
579
+ position={Position.Top}
580
+ className="workflow-flow-insert-node__handle workflow-flow-insert-node__handle--top"
581
+ isConnectable={false}
582
+ />
583
+ <Handle
584
+ type="source"
585
+ position={Position.Bottom}
586
+ className="workflow-flow-insert-node__handle workflow-flow-insert-node__handle--bottom"
587
+ isConnectable={false}
588
+ />
589
+ </div>
590
+ );
591
+ }
592
+
593
+ if (data.kind === "junction") {
594
+ return (
595
+ <div className="workflow-flow-junction-node">
596
+ <Handle
597
+ type="target"
598
+ position={Position.Top}
599
+ className="workflow-flow-junction-node__handle workflow-flow-junction-node__handle--top"
600
+ isConnectable={false}
601
+ />
602
+ <Handle
603
+ type="source"
604
+ position={Position.Bottom}
605
+ className="workflow-flow-junction-node__handle workflow-flow-junction-node__handle--bottom"
606
+ isConnectable={false}
607
+ />
608
+ </div>
609
+ );
610
+ }
611
+
612
+ if (data.kind === "section-label") {
613
+ return <div className="workflow-flow-section-label">{data.label}</div>;
614
+ }
615
+
616
+ if (data.kind === "workflow-trigger") {
617
+ const triggerTitle = data.trigger.name ?? data.trigger.label ?? data.trigger.id;
618
+
619
+ return (
620
+ <div
621
+ className={`workflow-flow-node-card workflow-flow-node-card--trigger ${data.selected ? "is-selected" : ""}`}
622
+ onClick={() => data.onSelectTrigger(String(data.trigger.id))}
623
+ role="button"
624
+ tabIndex={0}
625
+ onKeyDown={(event) => {
626
+ if (event.key === "Enter" || event.key === " ") {
627
+ event.preventDefault();
628
+ data.onSelectTrigger(String(data.trigger.id));
629
+ }
630
+ }}
631
+ >
632
+ <div className="workflow-flow-node-card__typebar">
633
+ <span>{data.trigger.disabled ? "disabled trigger" : "trigger"}</span>
634
+ <span className="workflow-flow-node-card__quick-actions">
635
+ <button
636
+ type="button"
637
+ className="workflow-flow-icon-button nodrag nopan nowheel"
638
+ aria-label={`Open ${triggerTitle} documentation`}
639
+ title="Documentation"
640
+ onPointerDown={(event) => {
641
+ event.stopPropagation();
642
+ }}
643
+ onClick={(event) => {
644
+ event.stopPropagation();
645
+ data.onViewDocs(String(data.trigger.id));
646
+ }}
647
+ >
648
+ <CircleHelp size={12} />
649
+ </button>
650
+ </span>
651
+ </div>
652
+ <div className="workflow-flow-node-card__body">
653
+ <div className="workflow-flow-node-card__header-main">
654
+ <div className="workflow-flow-node-card__icon-shell">
655
+ <SolidIcon name="si-calendar" size={16} aria-hidden />
656
+ </div>
657
+ <div>
658
+ <div className="workflow-flow-node-card__title" title={String(triggerTitle)}>
659
+ {triggerTitle}
660
+ </div>
661
+ <div className="workflow-flow-node-card__subtitle">
662
+ {data.trigger.type ?? "Trigger"}
663
+ </div>
664
+ </div>
665
+ </div>
666
+ </div>
667
+ {data.trigger.description ? (
668
+ <div className="workflow-flow-node-card__description">
669
+ {data.trigger.description}
670
+ </div>
671
+ ) : null}
672
+ <Handle
673
+ type="target"
674
+ position={Position.Top}
675
+ className="workflow-flow-node-card__handle workflow-flow-node-card__handle--top"
676
+ isConnectable={false}
677
+ />
678
+ <Handle
679
+ type="source"
680
+ position={Position.Bottom}
681
+ className="workflow-flow-node-card__handle workflow-flow-node-card__handle--bottom"
682
+ isConnectable={false}
683
+ />
684
+ </div>
685
+ );
686
+ }
687
+
688
+ const { workflowNode, nodeType, selected } = data;
689
+ const iconName = resolveWorkflowNodeIcon(nodeType);
690
+ const nodeTitle = workflowNode.name ?? workflowNode.id;
691
+ const nodeTypeLabel = nodeType?.label ?? workflowNode.type ?? workflowNode.kind ?? "node";
692
+
693
+ return (
694
+ <div
695
+ className={`workflow-flow-node-card ${selected ? "is-selected" : ""}`}
696
+ onClick={() => data.onSelectNode(String(workflowNode.id))}
697
+ role="button"
698
+ tabIndex={0}
699
+ onKeyDown={(event) => {
700
+ if (event.key === "Enter" || event.key === " ") {
701
+ event.preventDefault();
702
+ data.onSelectNode(String(workflowNode.id));
703
+ }
704
+ }}
705
+ >
706
+ <div className="workflow-flow-node-card__typebar">
707
+ <span>{nodeTypeLabel}</span>
708
+ <span className="workflow-flow-node-card__quick-actions">
709
+ <button
710
+ type="button"
711
+ className="workflow-flow-icon-button nodrag nopan nowheel"
712
+ aria-label={`Edit ${nodeTitle}`}
713
+ title="Edit"
714
+ onPointerDown={(event) => {
715
+ event.stopPropagation();
716
+ }}
717
+ onClick={(event) => {
718
+ event.stopPropagation();
719
+ data.onEditNode(String(workflowNode.id));
720
+ }}
721
+ >
722
+ <Pencil size={12} />
723
+ </button>
724
+ <button
725
+ type="button"
726
+ className="workflow-flow-icon-button workflow-flow-icon-button--danger nodrag nopan nowheel"
727
+ aria-label={`Delete ${nodeTitle}`}
728
+ title="Delete"
729
+ onPointerDown={(event) => {
730
+ event.stopPropagation();
731
+ }}
732
+ onClick={(event) => {
733
+ event.stopPropagation();
734
+ data.onDeleteNode(String(workflowNode.id));
735
+ }}
736
+ >
737
+ <Trash2 size={12} />
738
+ </button>
739
+ <button
740
+ type="button"
741
+ className="workflow-flow-icon-button nodrag nopan nowheel"
742
+ aria-label={`Open ${nodeTypeLabel} documentation`}
743
+ title="Documentation"
744
+ onPointerDown={(event) => {
745
+ event.stopPropagation();
746
+ }}
747
+ onClick={(event) => {
748
+ event.stopPropagation();
749
+ data.onViewDocs(String(workflowNode.id));
750
+ }}
751
+ >
752
+ <CircleHelp size={12} />
753
+ </button>
754
+ </span>
755
+ </div>
756
+ <div className="workflow-flow-node-card__body">
757
+ <div className="workflow-flow-node-card__header-main">
758
+ <div
759
+ className="workflow-flow-node-card__icon-shell"
760
+ style={getWorkflowNodeIconStyle(nodeType)}
761
+ >
762
+ <SolidIcon name={iconName} size={16} aria-hidden />
763
+ </div>
764
+ <div>
765
+ <div className="workflow-flow-node-card__title" title={String(nodeTitle)}>
766
+ {nodeTitle}
767
+ </div>
768
+ </div>
769
+ </div>
770
+ </div>
771
+
772
+ {workflowNode.description ? (
773
+ <div className="workflow-flow-node-card__description">
774
+ {workflowNode.description}
775
+ </div>
776
+ ) : null}
777
+
778
+ <Handle
779
+ type="target"
780
+ position={Position.Top}
781
+ className="workflow-flow-node-card__handle workflow-flow-node-card__handle--top"
782
+ isConnectable={false}
783
+ />
784
+ <Handle
785
+ type="source"
786
+ position={Position.Bottom}
787
+ className="workflow-flow-node-card__handle workflow-flow-node-card__handle--bottom"
788
+ isConnectable={false}
789
+ />
790
+ </div>
791
+ );
792
+ }
793
+
794
+ const canvasNodeTypes: any = {
795
+ group: WorkflowCanvasNodeRenderer,
796
+ workflow: WorkflowCanvasNodeRenderer,
797
+ trigger: WorkflowCanvasNodeRenderer,
798
+ insert: WorkflowCanvasNodeRenderer,
799
+ junction: WorkflowCanvasNodeRenderer,
800
+ sectionLabel: WorkflowCanvasNodeRenderer,
801
+ };
802
+
803
+ const canvasEdgeTypes = {
804
+ workflowMerge: WorkflowMergeEdge,
805
+ workflowSplit: WorkflowSplitEdge,
806
+ };
807
+
808
+ function pushGroupNode(
809
+ ctx: GraphBuildContext,
810
+ id: string,
811
+ label: string,
812
+ tone: "control" | "loop" | "trigger",
813
+ subset: Node<WorkflowCanvasNodeData>[],
814
+ workflowNode?: WorkflowNodeRecord,
815
+ nodeType?: WorkflowNodeMetadataResponse,
816
+ ) {
817
+ if (!subset.length) {
818
+ return undefined;
819
+ }
820
+
821
+ const bounds = subset.reduce(
822
+ (acc, node) => {
823
+ const rect = getNodeRect(node);
824
+ return {
825
+ left: Math.min(acc.left, rect.left),
826
+ top: Math.min(acc.top, rect.top),
827
+ right: Math.max(acc.right, rect.right),
828
+ bottom: Math.max(acc.bottom, rect.bottom),
829
+ };
830
+ },
831
+ {
832
+ left: Number.POSITIVE_INFINITY,
833
+ top: Number.POSITIVE_INFINITY,
834
+ right: Number.NEGATIVE_INFINITY,
835
+ bottom: Number.NEGATIVE_INFINITY,
836
+ },
837
+ );
838
+
839
+ const paddingX =
840
+ tone === "loop" ? DIMENSIONS.loopGroupPaddingX : DIMENSIONS.groupPaddingX;
841
+ const paddingTop =
842
+ tone === "loop" ? DIMENSIONS.loopGroupPaddingTop : DIMENSIONS.groupPaddingTop;
843
+ const paddingBottom =
844
+ tone === "loop" ? DIMENSIONS.loopGroupPaddingBottom : DIMENSIONS.groupPaddingBottom;
845
+
846
+ const groupTop = bounds.top - paddingTop;
847
+ const groupBottom = bounds.bottom + paddingBottom;
848
+
849
+ ctx.backgroundNodes.push({
850
+ id,
851
+ type: "group",
852
+ position: {
853
+ x: bounds.left - paddingX,
854
+ y: groupTop,
855
+ },
856
+ draggable: false,
857
+ selectable: false,
858
+ style: {
859
+ width: bounds.right - bounds.left + paddingX * 2,
860
+ height: bounds.bottom - bounds.top + paddingTop + paddingBottom,
861
+ zIndex: 0,
862
+ },
863
+ data: {
864
+ kind: "group",
865
+ label,
866
+ tone,
867
+ workflowNode,
868
+ nodeType,
869
+ onViewDocs: ctx.onViewDocs,
870
+ },
871
+ });
872
+
873
+ return {
874
+ top: groupTop,
875
+ bottom: groupBottom,
876
+ };
877
+ }
878
+
879
+ function pushInsertNode(
880
+ ctx: GraphBuildContext,
881
+ id: string,
882
+ x: number,
883
+ y: number,
884
+ target: WorkflowInsertTarget,
885
+ ) {
886
+ ctx.nodes.push({
887
+ id,
888
+ type: "insert",
889
+ position: {
890
+ x: x - DIMENSIONS.insertWidth / 2,
891
+ y,
892
+ },
893
+ draggable: false,
894
+ selectable: false,
895
+ style: {
896
+ zIndex: 5,
897
+ },
898
+ data: {
899
+ kind: "insert",
900
+ enabled: true,
901
+ selectedTypeLabel: ctx.activePaletteNodeType?.label,
902
+ onInsert: () => ctx.onInsertNode(target),
903
+ },
904
+ sourcePosition: Position.Bottom,
905
+ targetPosition: Position.Top,
906
+ });
907
+ }
908
+
909
+ function pushJunctionNode(
910
+ ctx: GraphBuildContext,
911
+ id: string,
912
+ x: number,
913
+ y: number,
914
+ ) {
915
+ ctx.nodes.push({
916
+ id,
917
+ type: "junction",
918
+ position: {
919
+ x: x - DIMENSIONS.junctionWidth / 2,
920
+ y: y - DIMENSIONS.junctionHeight / 2,
921
+ },
922
+ draggable: false,
923
+ selectable: false,
924
+ style: {
925
+ zIndex: 2,
926
+ },
927
+ data: {
928
+ kind: "junction",
929
+ },
930
+ sourcePosition: Position.Bottom,
931
+ targetPosition: Position.Top,
932
+ });
933
+ }
934
+
935
+ function pushWorkflowNode(
936
+ ctx: GraphBuildContext,
937
+ workflowNode: WorkflowNodeRecord,
938
+ x: number,
939
+ y: number,
940
+ ) {
941
+ const nodeType = ctx.nodeTypeMap.get(String(workflowNode.type));
942
+ ctx.nodes.push({
943
+ id: String(workflowNode.id),
944
+ type: "workflow",
945
+ position: { x, y },
946
+ draggable: false,
947
+ style: {
948
+ zIndex: 4,
949
+ },
950
+ data: {
951
+ kind: "workflow-node",
952
+ workflowNode,
953
+ nodeType,
954
+ selected: ctx.selectedNodeId === String(workflowNode.id),
955
+ onSelectNode: ctx.onSelectNode,
956
+ onEditNode: ctx.onEditNode,
957
+ onDeleteNode: ctx.onDeleteNode,
958
+ onViewDocs: ctx.onViewDocs,
959
+ },
960
+ sourcePosition: Position.Bottom,
961
+ targetPosition: Position.Top,
962
+ });
963
+ }
964
+
965
+ function pushTriggerNode(
966
+ ctx: GraphBuildContext,
967
+ trigger: WorkflowTriggerRecord,
968
+ x: number,
969
+ y: number,
970
+ ) {
971
+ ctx.nodes.push({
972
+ id: `trigger-${String(trigger.id)}`,
973
+ type: "trigger",
974
+ position: { x, y },
975
+ draggable: false,
976
+ selectable: false,
977
+ style: {
978
+ zIndex: 4,
979
+ },
980
+ sourcePosition: Position.Bottom,
981
+ targetPosition: Position.Top,
982
+ data: {
983
+ kind: "workflow-trigger",
984
+ trigger,
985
+ selected: ctx.selectedTriggerId === String(trigger.id),
986
+ onSelectTrigger: ctx.onSelectTrigger,
987
+ onViewDocs: ctx.onViewTriggerDocs,
988
+ },
989
+ });
990
+ }
991
+
992
+ function pushSectionLabelNode(
993
+ ctx: GraphBuildContext,
994
+ id: string,
995
+ x: number,
996
+ y: number,
997
+ label: string,
998
+ ) {
999
+ ctx.nodes.push({
1000
+ id,
1001
+ type: "sectionLabel",
1002
+ position: { x, y },
1003
+ draggable: false,
1004
+ selectable: false,
1005
+ style: {
1006
+ zIndex: 5,
1007
+ },
1008
+ data: {
1009
+ kind: "section-label",
1010
+ label,
1011
+ },
1012
+ });
1013
+ }
1014
+
1015
+ function buildSequenceGraph(
1016
+ sequence: WorkflowNodeRecord[],
1017
+ ctx: GraphBuildContext,
1018
+ laneX: number,
1019
+ startY: number,
1020
+ scope: WorkflowInsertScope,
1021
+ options: {
1022
+ idSuffix?: string;
1023
+ indexOffset?: number;
1024
+ boundaryInserts?: boolean;
1025
+ } = {},
1026
+ ): WorkflowLayoutResult {
1027
+ let cursorY = startY;
1028
+ let maxWidth = DIMENSIONS.workflowWidth;
1029
+ const indexOffset = options.indexOffset ?? 0;
1030
+ const idSuffix = options.idSuffix ? `-${options.idSuffix}` : "";
1031
+ const boundaryInserts = options.boundaryInserts ?? true;
1032
+
1033
+ const entryIds: string[] = [];
1034
+ let previousExitIds: string[] = [];
1035
+
1036
+ if (boundaryInserts) {
1037
+ const initialInsertId = `insert-${JSON.stringify(scope)}-${indexOffset}${idSuffix}`;
1038
+ pushInsertNode(ctx, initialInsertId, laneX, cursorY, {
1039
+ ...scope,
1040
+ index: indexOffset,
1041
+ } as WorkflowInsertTarget);
1042
+ entryIds.push(initialInsertId);
1043
+ previousExitIds = [initialInsertId];
1044
+ }
1045
+
1046
+ for (let index = 0; index < sequence.length; index += 1) {
1047
+ const workflowNode = sequence[index];
1048
+ const nodeType = ctx.nodeTypeMap.get(String(workflowNode.type));
1049
+ const slotDefinitions = normalizeChildSlots(workflowNode, nodeType);
1050
+ const isControlNode = nodeType?.kind === "control" || slotDefinitions.length > 0;
1051
+ const estimatedNodeWidth = estimateWorkflowNodeWidth(
1052
+ workflowNode,
1053
+ ctx.nodeTypeMap,
1054
+ nodeType,
1055
+ );
1056
+ maxWidth = Math.max(maxWidth, estimatedNodeWidth);
1057
+ const subtreeStartIndex = ctx.nodes.length;
1058
+ const groupTone = isLoopNode(workflowNode, nodeType) ? "loop" : "control";
1059
+ const controlTopPadding =
1060
+ groupTone === "loop" ? DIMENSIONS.loopGroupPaddingTop : DIMENSIONS.groupPaddingTop;
1061
+ const nodeGap = isControlNode
1062
+ ? controlTopPadding + DIMENSIONS.insertHeight + DIMENSIONS.groupExteriorEdgeGap
1063
+ : DIMENSIONS.sequenceInsertToNodeGap;
1064
+
1065
+ cursorY += nodeGap;
1066
+ pushWorkflowNode(
1067
+ ctx,
1068
+ workflowNode,
1069
+ laneX - DIMENSIONS.workflowWidth / 2,
1070
+ cursorY,
1071
+ );
1072
+ if (!entryIds.length) {
1073
+ entryIds.push(String(workflowNode.id));
1074
+ }
1075
+ previousExitIds.forEach((sourceId) => {
1076
+ ctx.edges.push(createEdge(sourceId, String(workflowNode.id)));
1077
+ });
1078
+
1079
+ let deepestY = cursorY;
1080
+ const childStartY =
1081
+ cursorY + DIMENSIONS.workflowHeight + DIMENSIONS.controlNodeToChildGap;
1082
+ let exitIds: string[] = [String(workflowNode.id)];
1083
+ let usesMergeJunction = false;
1084
+
1085
+ const branchSlots = slotDefinitions.filter(
1086
+ (slot) => slot.key === "then" || slot.key === "else",
1087
+ );
1088
+ const caseEntries = slotDefinitions.some((slot) => slot.kind === "case-collection")
1089
+ ? getSwitchCaseEntries(workflowNode)
1090
+ : [];
1091
+
1092
+ if (caseEntries.length > 0) {
1093
+ const branchGap = DIMENSIONS.controlBranchGap;
1094
+ const branchWidths = caseEntries.map((entry) =>
1095
+ estimateSequenceWidth(entry.nodes, ctx.nodeTypeMap),
1096
+ );
1097
+ const totalBranchWidth =
1098
+ branchWidths.reduce((sum, width) => sum + width, 0) +
1099
+ branchGap * Math.max(branchWidths.length - 1, 0);
1100
+ const branchStartX = laneX - totalBranchWidth / 2;
1101
+ const branchLayouts = caseEntries.map((entry, branchIndex) => {
1102
+ const beforeWidth = branchWidths
1103
+ .slice(0, branchIndex)
1104
+ .reduce((sum, width) => sum + width, 0);
1105
+ const branchLaneX =
1106
+ branchStartX +
1107
+ beforeWidth +
1108
+ branchGap * branchIndex +
1109
+ branchWidths[branchIndex] / 2;
1110
+ const labelX = branchLaneX - DIMENSIONS.sectionLabelWidth / 2;
1111
+ const labelY = childStartY - DIMENSIONS.controlBranchLabelGap;
1112
+ pushSectionLabelNode(
1113
+ ctx,
1114
+ `${workflowNode.id}-${entry.key}-label`,
1115
+ labelX,
1116
+ labelY,
1117
+ entry.label,
1118
+ );
1119
+ const childLayout = buildSequenceGraph(
1120
+ entry.nodes,
1121
+ ctx,
1122
+ branchLaneX,
1123
+ childStartY,
1124
+ entry.scope,
1125
+ );
1126
+ childLayout.entryIds.forEach((entryId) => {
1127
+ ctx.edges.push(createEdge(String(workflowNode.id), entryId));
1128
+ });
1129
+ deepestY = Math.max(deepestY, childLayout.endY);
1130
+ maxWidth = Math.max(maxWidth, childLayout.width);
1131
+ return childLayout;
1132
+ });
1133
+
1134
+ const branchExitIds = branchLayouts.flatMap((layout) => layout.exitIds);
1135
+ exitIds = branchExitIds.length ? branchExitIds : [String(workflowNode.id)];
1136
+ } else if (branchSlots.length >= 2) {
1137
+ const branchGap = DIMENSIONS.controlBranchGap;
1138
+ const branchWidths = branchSlots.map((slot) =>
1139
+ estimateSequenceWidth(
1140
+ Array.isArray(workflowNode[slot.key]) ? workflowNode[slot.key] : [],
1141
+ ctx.nodeTypeMap,
1142
+ ),
1143
+ );
1144
+ const totalBranchWidth =
1145
+ branchWidths.reduce((sum, width) => sum + width, 0) +
1146
+ branchGap * Math.max(branchWidths.length - 1, 0);
1147
+ const branchStartX = laneX - totalBranchWidth / 2;
1148
+ const branchLayouts = branchSlots.map((slot, branchIndex) => {
1149
+ const slotKey = slot.key as "then" | "else";
1150
+ const childNodes = Array.isArray(workflowNode[slotKey]) ? workflowNode[slotKey] : [];
1151
+ const beforeWidth = branchWidths
1152
+ .slice(0, branchIndex)
1153
+ .reduce((sum, width) => sum + width, 0);
1154
+ const branchLaneX =
1155
+ branchStartX +
1156
+ beforeWidth +
1157
+ branchGap * branchIndex +
1158
+ branchWidths[branchIndex] / 2;
1159
+ const labelX = branchLaneX - DIMENSIONS.sectionLabelWidth / 2;
1160
+ const labelY = childStartY - DIMENSIONS.controlBranchLabelGap;
1161
+ pushSectionLabelNode(
1162
+ ctx,
1163
+ `${workflowNode.id}-${slotKey}-label`,
1164
+ labelX,
1165
+ labelY,
1166
+ slot.label ?? slotKey,
1167
+ );
1168
+ const childLayout = buildSequenceGraph(
1169
+ childNodes,
1170
+ ctx,
1171
+ branchLaneX,
1172
+ childStartY,
1173
+ {
1174
+ scope: "slot",
1175
+ parentNodeId: String(workflowNode.id),
1176
+ slotKey,
1177
+ },
1178
+ );
1179
+ childLayout.entryIds.forEach((entryId) => {
1180
+ ctx.edges.push(createEdge(String(workflowNode.id), entryId));
1181
+ });
1182
+ deepestY = Math.max(deepestY, childLayout.endY);
1183
+ maxWidth = Math.max(maxWidth, childLayout.width);
1184
+ return childLayout;
1185
+ });
1186
+
1187
+ const branchExitIds = branchLayouts.flatMap((layout) => layout.exitIds);
1188
+ exitIds = branchExitIds.length ? branchExitIds : [String(workflowNode.id)];
1189
+ } else if (slotDefinitions.length === 1 && slotDefinitions[0].kind === "sequence") {
1190
+ const slot = slotDefinitions[0];
1191
+ const slotKey = slot.key as WorkflowSequenceSlotKey;
1192
+ const childNodes = getSequenceSlotNodes(workflowNode, slotKey);
1193
+ if (slot.label && slotKey !== "tasks") {
1194
+ pushSectionLabelNode(
1195
+ ctx,
1196
+ `${workflowNode.id}-${slotKey}-label`,
1197
+ laneX - DIMENSIONS.sectionLabelWidth / 2,
1198
+ childStartY - DIMENSIONS.controlBranchLabelGap,
1199
+ slot.label,
1200
+ );
1201
+ }
1202
+ if (slot.layout === "parallel") {
1203
+ const childWidths = childNodes.map((childNode: WorkflowNodeRecord) =>
1204
+ estimateWorkflowNodeWidth(
1205
+ childNode,
1206
+ ctx.nodeTypeMap,
1207
+ ctx.nodeTypeMap.get(String(childNode.type)),
1208
+ ),
1209
+ );
1210
+ const totalChildWidth =
1211
+ childWidths.reduce((sum, width) => sum + width, 0) +
1212
+ DIMENSIONS.controlBranchGap * Math.max(childWidths.length - 1, 0);
1213
+ const childStartX = laneX - totalChildWidth / 2;
1214
+ const collectionInsertId = `insert-${JSON.stringify({
1215
+ scope: "slot",
1216
+ parentNodeId: String(workflowNode.id),
1217
+ slotKey,
1218
+ })}-${childNodes.length}-${workflowNode.id}-${slotKey}-collection`;
1219
+ const collectionInsertY =
1220
+ cursorY +
1221
+ DIMENSIONS.workflowHeight +
1222
+ Math.round(DIMENSIONS.controlNodeToChildGap * 0.22);
1223
+ pushInsertNode(
1224
+ ctx,
1225
+ collectionInsertId,
1226
+ laneX,
1227
+ collectionInsertY,
1228
+ {
1229
+ scope: "slot",
1230
+ parentNodeId: String(workflowNode.id),
1231
+ slotKey,
1232
+ index: childNodes.length,
1233
+ },
1234
+ );
1235
+ maxWidth = Math.max(maxWidth, totalChildWidth);
1236
+ const splitJunctionY =
1237
+ cursorY +
1238
+ DIMENSIONS.workflowHeight +
1239
+ Math.round(DIMENSIONS.controlNodeToChildGap * 0.78);
1240
+ const splitJunctionId = `${workflowNode.id}-${slotKey}-split`;
1241
+ if (childNodes.length > 1) {
1242
+ pushJunctionNode(ctx, splitJunctionId, laneX, splitJunctionY);
1243
+ ctx.edges.push(createEdge(String(workflowNode.id), collectionInsertId));
1244
+ ctx.edges.push(createEdge(collectionInsertId, splitJunctionId, { marker: false }));
1245
+ deepestY = Math.max(deepestY, splitJunctionY);
1246
+ } else if (childNodes.length === 0) {
1247
+ ctx.edges.push(createEdge(String(workflowNode.id), collectionInsertId));
1248
+ exitIds = [collectionInsertId];
1249
+ deepestY = Math.max(deepestY, collectionInsertY + DIMENSIONS.insertHeight);
1250
+ }
1251
+ const childLayouts = childNodes.map((childNode: WorkflowNodeRecord, childIndex: number) => {
1252
+ const beforeWidth = childWidths
1253
+ .slice(0, childIndex)
1254
+ .reduce((sum, width) => sum + width, 0);
1255
+ const childLaneX =
1256
+ childStartX +
1257
+ beforeWidth +
1258
+ DIMENSIONS.controlBranchGap * childIndex +
1259
+ childWidths[childIndex] / 2;
1260
+ const childLayout = buildSequenceGraph(
1261
+ [childNode],
1262
+ ctx,
1263
+ childLaneX,
1264
+ childStartY,
1265
+ {
1266
+ scope: "slot",
1267
+ parentNodeId: String(workflowNode.id),
1268
+ slotKey,
1269
+ },
1270
+ {
1271
+ idSuffix: `${workflowNode.id}-${slotKey}-${childIndex}`,
1272
+ indexOffset: childIndex,
1273
+ boundaryInserts: false,
1274
+ },
1275
+ );
1276
+ childLayout.entryIds.forEach((entryId) => {
1277
+ if (childNodes.length > 1) {
1278
+ ctx.edges.push(
1279
+ createEdge(splitJunctionId, entryId, {
1280
+ kind: "split",
1281
+ splitMode: "fromJunction",
1282
+ }),
1283
+ );
1284
+ return;
1285
+ }
1286
+
1287
+ ctx.edges.push(createEdge(String(workflowNode.id), collectionInsertId));
1288
+ ctx.edges.push(createEdge(collectionInsertId, entryId));
1289
+ });
1290
+ deepestY = Math.max(deepestY, childLayout.endY);
1291
+ maxWidth = Math.max(maxWidth, childLayout.width);
1292
+ return childLayout;
1293
+ });
1294
+ const childExitIds = childLayouts.flatMap((layout: WorkflowLayoutResult) => layout.exitIds);
1295
+ exitIds = childExitIds.length ? childExitIds : exitIds;
1296
+ } else {
1297
+ const childLayout = buildSequenceGraph(
1298
+ childNodes,
1299
+ ctx,
1300
+ laneX,
1301
+ childStartY,
1302
+ {
1303
+ scope: "slot",
1304
+ parentNodeId: String(workflowNode.id),
1305
+ slotKey,
1306
+ },
1307
+ );
1308
+ childLayout.entryIds.forEach((entryId) => {
1309
+ ctx.edges.push(createEdge(String(workflowNode.id), entryId));
1310
+ });
1311
+ deepestY = Math.max(deepestY, childLayout.endY);
1312
+ maxWidth = Math.max(maxWidth, childLayout.width);
1313
+ exitIds = childLayout.exitIds.length ? childLayout.exitIds : [String(workflowNode.id)];
1314
+ }
1315
+ }
1316
+
1317
+ if (isControlNode && exitIds.length > 1) {
1318
+ const junctionY = Math.max(
1319
+ cursorY + DIMENSIONS.workflowHeight + DIMENSIONS.sequenceNodeToInsertGap,
1320
+ deepestY + DIMENSIONS.controlJoinGap,
1321
+ );
1322
+ const junctionId = `junction-${String(workflowNode.id)}`;
1323
+ pushJunctionNode(ctx, junctionId, laneX, junctionY);
1324
+ exitIds.forEach((sourceId) => {
1325
+ ctx.edges.push(createEdge(sourceId, junctionId, { marker: false }));
1326
+ });
1327
+ exitIds = [junctionId];
1328
+ deepestY = Math.max(deepestY, junctionY);
1329
+ usesMergeJunction = true;
1330
+ }
1331
+
1332
+ const groupBounds = isControlNode
1333
+ ? pushGroupNode(
1334
+ ctx,
1335
+ `group-${String(workflowNode.id)}`,
1336
+ workflowNode.name ?? workflowNode.id,
1337
+ groupTone,
1338
+ ctx.nodes.slice(subtreeStartIndex),
1339
+ workflowNode,
1340
+ nodeType,
1341
+ )
1342
+ : undefined;
1343
+
1344
+ const nextInsertY = usesMergeJunction
1345
+ ? deepestY + DIMENSIONS.sequenceNodeToInsertGap
1346
+ : deepestY + (isControlNode ? DIMENSIONS.sequenceNodeToInsertGap : 0);
1347
+ const afterGroupInsertY =
1348
+ groupBounds == null
1349
+ ? nextInsertY
1350
+ : groupBounds.bottom + DIMENSIONS.groupExteriorEdgeGap;
1351
+ cursorY = Math.max(
1352
+ cursorY + DIMENSIONS.workflowHeight + DIMENSIONS.sequenceNodeToInsertGap,
1353
+ afterGroupInsertY,
1354
+ );
1355
+ if (boundaryInserts) {
1356
+ const afterInsertIndex = indexOffset + index + 1;
1357
+ const afterInsertId = `insert-${JSON.stringify(scope)}-${afterInsertIndex}-${workflowNode.id}${idSuffix}`;
1358
+ pushInsertNode(ctx, afterInsertId, laneX, cursorY, {
1359
+ ...scope,
1360
+ index: afterInsertIndex,
1361
+ } as WorkflowInsertTarget);
1362
+ exitIds.forEach((sourceId) => {
1363
+ ctx.edges.push(createEdge(sourceId, afterInsertId));
1364
+ });
1365
+ previousExitIds = [afterInsertId];
1366
+ } else {
1367
+ previousExitIds = exitIds;
1368
+ }
1369
+ }
1370
+
1371
+ return {
1372
+ entryIds: entryIds.length ? entryIds : previousExitIds,
1373
+ exitIds: previousExitIds,
1374
+ endY: cursorY,
1375
+ width: maxWidth,
1376
+ };
1377
+ }
1378
+
1379
+
1380
+ function buildGraph(
1381
+ definition: { nodes: WorkflowNodeRecord[]; triggers?: WorkflowTriggerRecord[] },
1382
+ nodeTypes: WorkflowNodeMetadataResponse[],
1383
+ props: Omit<WorkflowFlowCanvasProps, "definition" | "nodeTypes">,
1384
+ ) {
1385
+ const ctx: GraphBuildContext = {
1386
+ backgroundNodes: [],
1387
+ nodes: [],
1388
+ edges: [],
1389
+ nodeTypeMap: new Map(nodeTypes.map((item) => [item.type, item])),
1390
+ activePaletteNodeType: props.activePaletteNodeType,
1391
+ selectedNodeId: props.selectedNodeId,
1392
+ selectedTriggerId: props.selectedTriggerId,
1393
+ onSelectNode: props.onSelectNode,
1394
+ onSelectTrigger: props.onSelectTrigger,
1395
+ onEditNode: props.onEditNode,
1396
+ onDeleteNode: props.onDeleteNode,
1397
+ onViewDocs: props.onViewDocs,
1398
+ onViewTriggerDocs: props.onViewTriggerDocs,
1399
+ onInsertNode: props.onInsertNode,
1400
+ };
1401
+
1402
+ const triggers = Array.isArray(definition.triggers) ? definition.triggers : [];
1403
+ const rootLaneX = 80;
1404
+ let startY = 0;
1405
+ let previousTriggerId: string | null = null;
1406
+
1407
+ if (triggers.length) {
1408
+ const triggerStartIndex = ctx.nodes.length;
1409
+ let triggerY = 60;
1410
+ triggers.forEach((trigger) => {
1411
+ const triggerNodeId = `trigger-${String(trigger.id)}`;
1412
+ pushTriggerNode(
1413
+ ctx,
1414
+ trigger,
1415
+ rootLaneX - DIMENSIONS.triggerWidth / 2,
1416
+ triggerY,
1417
+ );
1418
+ if (previousTriggerId) {
1419
+ ctx.edges.push(createEdge(previousTriggerId, triggerNodeId));
1420
+ }
1421
+ previousTriggerId = triggerNodeId;
1422
+ triggerY += DIMENSIONS.triggerHeight + DIMENSIONS.triggerGap;
1423
+ });
1424
+ const triggerGroupBounds = pushGroupNode(
1425
+ ctx,
1426
+ "group-triggers",
1427
+ "Triggers",
1428
+ "trigger",
1429
+ ctx.nodes.slice(triggerStartIndex),
1430
+ );
1431
+ startY =
1432
+ (triggerGroupBounds?.bottom ?? triggerY) + DIMENSIONS.groupExteriorEdgeGap;
1433
+ }
1434
+
1435
+ const layout = buildSequenceGraph(
1436
+ definition.nodes ?? [],
1437
+ ctx,
1438
+ rootLaneX,
1439
+ startY,
1440
+ { scope: "root" },
1441
+ );
1442
+ if (previousTriggerId) {
1443
+ const triggerSourceId = previousTriggerId;
1444
+ layout.entryIds.forEach((entryId) => {
1445
+ ctx.edges.push(createEdge(triggerSourceId, entryId));
1446
+ });
1447
+ }
1448
+
1449
+ return {
1450
+ nodes: [...ctx.backgroundNodes, ...ctx.nodes],
1451
+ edges: ctx.edges,
1452
+ };
1453
+ }
1454
+
1455
+ function WorkflowFlowCanvasInner(props: WorkflowFlowCanvasProps) {
1456
+ const graph = React.useMemo(
1457
+ () =>
1458
+ buildGraph(props.definition, props.nodeTypes, {
1459
+ selectedNodeId: props.selectedNodeId,
1460
+ selectedTriggerId: props.selectedTriggerId,
1461
+ activePaletteNodeType: props.activePaletteNodeType,
1462
+ onSelectNode: props.onSelectNode,
1463
+ onSelectTrigger: props.onSelectTrigger,
1464
+ onEditNode: props.onEditNode,
1465
+ onDeleteNode: props.onDeleteNode,
1466
+ onViewDocs: props.onViewDocs,
1467
+ onViewTriggerDocs: props.onViewTriggerDocs,
1468
+ onInsertNode: props.onInsertNode,
1469
+ }),
1470
+ [
1471
+ props.activePaletteNodeType,
1472
+ props.definition,
1473
+ props.nodeTypes,
1474
+ props.onDeleteNode,
1475
+ props.onEditNode,
1476
+ props.onInsertNode,
1477
+ props.onSelectNode,
1478
+ props.onSelectTrigger,
1479
+ props.onViewDocs,
1480
+ props.onViewTriggerDocs,
1481
+ props.selectedNodeId,
1482
+ props.selectedTriggerId,
1483
+ ],
1484
+ );
1485
+
1486
+ return (
1487
+ <div className="workflow-flow-canvas">
1488
+ <ReactFlow
1489
+ nodes={graph.nodes}
1490
+ edges={graph.edges}
1491
+ nodeTypes={canvasNodeTypes}
1492
+ edgeTypes={canvasEdgeTypes}
1493
+ defaultViewport={DEFAULT_WORKFLOW_VIEWPORT}
1494
+ minZoom={0.25}
1495
+ maxZoom={1.6}
1496
+ proOptions={{ hideAttribution: true }}
1497
+ defaultEdgeOptions={{ zIndex: 1 }}
1498
+ nodesDraggable={false}
1499
+ nodesConnectable={false}
1500
+ elementsSelectable
1501
+ panOnDrag
1502
+ zoomOnDoubleClick={false}
1503
+ >
1504
+ <Controls showInteractive={false} />
1505
+ <Background
1506
+ variant={BackgroundVariant.Dots}
1507
+ gap={18}
1508
+ size={1.45}
1509
+ color="rgba(148, 163, 184, 0.34)"
1510
+ />
1511
+ </ReactFlow>
1512
+ </div>
1513
+ );
1514
+ }
1515
+
1516
+ export function WorkflowFlowCanvas(props: WorkflowFlowCanvasProps) {
1517
+ return (
1518
+ <ReactFlowProvider>
1519
+ <WorkflowFlowCanvasInner {...props} />
1520
+ </ReactFlowProvider>
1521
+ );
1522
+ }