@umodeapporg/ui 0.22.3 → 0.23.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 (63) hide show
  1. package/dist/assets/umode-ui.css +105 -0
  2. package/dist/components/UI/Flow/FlowBlockNode.d.ts +35 -0
  3. package/dist/components/UI/Flow/FlowBlockNode.js +84 -0
  4. package/dist/components/UI/Flow/FlowBlockNode.js.map +1 -0
  5. package/dist/components/UI/Flow/FlowCanvas.d.ts +22 -0
  6. package/dist/components/UI/Flow/FlowCanvas.js +263 -0
  7. package/dist/components/UI/Flow/FlowCanvas.js.map +1 -0
  8. package/dist/components/UI/Flow/FlowConnectionEdge.d.ts +10 -0
  9. package/dist/components/UI/Flow/FlowConnectionEdge.js +54 -0
  10. package/dist/components/UI/Flow/FlowConnectionEdge.js.map +1 -0
  11. package/dist/components/UI/Flow/FlowEditorProvider.d.ts +17 -0
  12. package/dist/components/UI/Flow/FlowEditorProvider.js +27 -0
  13. package/dist/components/UI/Flow/FlowEditorProvider.js.map +1 -0
  14. package/dist/components/UI/Flow/FlowInspector.d.ts +11 -0
  15. package/dist/components/UI/Flow/FlowInspector.js +124 -0
  16. package/dist/components/UI/Flow/FlowInspector.js.map +1 -0
  17. package/dist/components/UI/Flow/FlowIssueList.d.ts +8 -0
  18. package/dist/components/UI/Flow/FlowIssueList.js +55 -0
  19. package/dist/components/UI/Flow/FlowIssueList.js.map +1 -0
  20. package/dist/components/UI/Flow/FlowLaneMap.d.ts +30 -0
  21. package/dist/components/UI/Flow/FlowLaneMap.js +206 -0
  22. package/dist/components/UI/Flow/FlowLaneMap.js.map +1 -0
  23. package/dist/components/UI/Flow/FlowNodeShell.d.ts +20 -0
  24. package/dist/components/UI/Flow/FlowNodeShell.js +81 -0
  25. package/dist/components/UI/Flow/FlowNodeShell.js.map +1 -0
  26. package/dist/components/UI/Flow/FlowPalette.d.ts +7 -0
  27. package/dist/components/UI/Flow/FlowPalette.js +90 -0
  28. package/dist/components/UI/Flow/FlowPalette.js.map +1 -0
  29. package/dist/components/UI/Flow/FlowResizablePanel.d.ts +20 -0
  30. package/dist/components/UI/Flow/FlowResizablePanel.js +117 -0
  31. package/dist/components/UI/Flow/FlowResizablePanel.js.map +1 -0
  32. package/dist/components/UI/Flow/FlowZoomControls.d.ts +12 -0
  33. package/dist/components/UI/Flow/FlowZoomControls.js +53 -0
  34. package/dist/components/UI/Flow/FlowZoomControls.js.map +1 -0
  35. package/dist/components/UI/Flow/flowBlockRegistry.d.ts +12 -0
  36. package/dist/components/UI/Flow/flowBlockRegistry.js +15 -0
  37. package/dist/components/UI/Flow/flowBlockRegistry.js.map +1 -0
  38. package/dist/components/UI/Flow/flowConstants.d.ts +2 -0
  39. package/dist/components/UI/Flow/flowConstants.js +5 -0
  40. package/dist/components/UI/Flow/flowConstants.js.map +1 -0
  41. package/dist/components/UI/Flow/flowEditorStore.d.ts +44 -0
  42. package/dist/components/UI/Flow/flowEditorStore.js +258 -0
  43. package/dist/components/UI/Flow/flowEditorStore.js.map +1 -0
  44. package/dist/components/UI/Flow/flowGraph.d.ts +32 -0
  45. package/dist/components/UI/Flow/flowGraph.js +156 -0
  46. package/dist/components/UI/Flow/flowGraph.js.map +1 -0
  47. package/dist/components/UI/Flow/flowTypes.d.ts +74 -0
  48. package/dist/components/UI/Flow/flowTypes.js +2 -0
  49. package/dist/components/UI/Flow/flowTypes.js.map +1 -0
  50. package/dist/components/UI/Flow/index.d.ts +14 -0
  51. package/dist/components/UI/Flow/index.js +43 -0
  52. package/dist/components/UI/Flow/index.js.map +1 -0
  53. package/dist/components/UI/Flow/useFlowLabels.d.ts +10 -0
  54. package/dist/components/UI/Flow/useFlowLabels.js +51 -0
  55. package/dist/components/UI/Flow/useFlowLabels.js.map +1 -0
  56. package/dist/locales/en/ui.json.d.ts +67 -0
  57. package/dist/locales/en/ui.json.js +3 -0
  58. package/dist/locales/en/ui.json.js.map +1 -1
  59. package/dist/locales/index.d.ts +134 -0
  60. package/dist/locales/pt/ui.json.d.ts +67 -0
  61. package/dist/locales/pt/ui.json.js +3 -0
  62. package/dist/locales/pt/ui.json.js.map +1 -1
  63. package/package.json +10 -1
@@ -0,0 +1,258 @@
1
+ import { createStore } from "zustand/vanilla";
2
+ import { generateUUID } from "../../../helpers/utilityHelpers.js";
3
+ import { canConnect, FLOW_SIBLING_GAP, FLOW_LEVEL_GAP, layoutFlowByLevels } from "./flowGraph.js";
4
+ const HISTORY_LIMIT = 50;
5
+ const PASTE_OFFSET = 32;
6
+ const COALESCE_WINDOW_MS = 1e3;
7
+ const isPosition = (position) => typeof position?.x === "number" && typeof position?.y === "number";
8
+ const normalizeGraph = (graph, registry) => {
9
+ const normalized = {
10
+ nodes: Array.isArray(graph?.nodes) ? graph.nodes : [],
11
+ edges: Array.isArray(graph?.edges) ? graph.edges : []
12
+ };
13
+ if (normalized.nodes.every((node) => isPosition(node.position))) return normalized;
14
+ const layout = layoutFlowByLevels(normalized, registry);
15
+ return {
16
+ ...normalized,
17
+ nodes: normalized.nodes.map(
18
+ (node) => isPosition(node.position) ? node : { ...node, position: layout[node.nodeId] ?? { x: 0, y: 0 } }
19
+ )
20
+ };
21
+ };
22
+ const withoutNodes = (graph, nodeIds) => ({
23
+ nodes: graph.nodes.filter((node) => !nodeIds.has(node.nodeId)),
24
+ edges: graph.edges.filter((edge) => !nodeIds.has(edge.source) && !nodeIds.has(edge.target))
25
+ });
26
+ const isPositionTaken = (graph, position) => graph.nodes.some(
27
+ (node) => Math.abs(node.position.x - position.x) < FLOW_LEVEL_GAP && Math.abs(node.position.y - position.y) < FLOW_SIBLING_GAP
28
+ );
29
+ const nextFreePosition = (graph, selectedNodeIds) => {
30
+ if (graph.nodes.length === 0) return { x: 0, y: 0 };
31
+ const anchor = graph.nodes.find((node) => node.nodeId === selectedNodeIds[0]) ?? graph.nodes.reduce((current, node) => node.position.x > current.position.x ? node : current);
32
+ let candidate = { x: anchor.position.x + FLOW_LEVEL_GAP, y: anchor.position.y };
33
+ while (isPositionTaken(graph, candidate)) candidate = { x: candidate.x, y: candidate.y + FLOW_SIBLING_GAP };
34
+ return candidate;
35
+ };
36
+ const createFlowEditorStore = (initialGraph, registry) => createStore()((set, get) => {
37
+ let currentRegistry = registry;
38
+ let lastCoalesce = null;
39
+ const commit = (next, selection, coalesceKey) => {
40
+ const { graph, past } = get();
41
+ const now = Date.now();
42
+ const extendsLastStep = coalesceKey !== void 0 && lastCoalesce?.key === coalesceKey && now - lastCoalesce.at < COALESCE_WINDOW_MS;
43
+ lastCoalesce = coalesceKey === void 0 ? null : { key: coalesceKey, at: now };
44
+ set({
45
+ graph: next,
46
+ past: extendsLastStep ? past : [...past, graph].slice(-HISTORY_LIMIT),
47
+ future: [],
48
+ isDirty: true,
49
+ ...selection?.nodeIds ? { selectedNodeIds: selection.nodeIds } : {},
50
+ ...selection?.edgeIds ? { selectedEdgeIds: selection.edgeIds } : {}
51
+ });
52
+ };
53
+ const cloneNodes = (nodes, offset) => {
54
+ const instancesByType = /* @__PURE__ */ new Map();
55
+ get().graph.nodes.forEach((node) => instancesByType.set(node.type, (instancesByType.get(node.type) ?? 0) + 1));
56
+ return nodes.filter((node) => {
57
+ const definition = currentRegistry.get(node.type);
58
+ if (!definition || definition.category === "trigger") return false;
59
+ const instances = instancesByType.get(node.type) ?? 0;
60
+ if (definition.maxInstances !== void 0 && instances >= definition.maxInstances) return false;
61
+ instancesByType.set(node.type, instances + 1);
62
+ return true;
63
+ }).map((node) => ({
64
+ ...node,
65
+ nodeId: generateUUID(),
66
+ config: structuredClone(node.config),
67
+ position: { x: node.position.x + offset, y: node.position.y + offset }
68
+ }));
69
+ };
70
+ return {
71
+ graph: normalizeGraph(initialGraph, registry),
72
+ selectedNodeIds: [],
73
+ selectedEdgeIds: [],
74
+ past: [],
75
+ future: [],
76
+ clipboard: [],
77
+ isDirty: false,
78
+ replaceGraph: (graph, options) => {
79
+ set((state) => ({
80
+ graph: normalizeGraph(graph, currentRegistry),
81
+ past: options?.keepHistory ? [...state.past, state.graph].slice(-HISTORY_LIMIT) : [],
82
+ future: [],
83
+ selectedNodeIds: [],
84
+ selectedEdgeIds: [],
85
+ isDirty: Boolean(options?.keepHistory)
86
+ }));
87
+ },
88
+ markClean: () => set({ isDirty: false }),
89
+ recordHistory: () => {
90
+ const { graph, past } = get();
91
+ set({ past: [...past, graph].slice(-HISTORY_LIMIT), future: [] });
92
+ },
93
+ addNode: (type, position) => {
94
+ const definition = currentRegistry.get(type);
95
+ if (!definition) return null;
96
+ const { graph, selectedNodeIds } = get();
97
+ const instances = graph.nodes.filter((node2) => node2.type === type).length;
98
+ if (definition.maxInstances !== void 0 && instances >= definition.maxInstances) return null;
99
+ const node = {
100
+ nodeId: generateUUID(),
101
+ type,
102
+ typeVersion: definition.typeVersion,
103
+ config: definition.createDefaultConfig(),
104
+ position: position ?? nextFreePosition(graph, selectedNodeIds)
105
+ };
106
+ commit({ ...graph, nodes: [...graph.nodes, node] }, { nodeIds: [node.nodeId], edgeIds: [] });
107
+ return node.nodeId;
108
+ },
109
+ addNodeFromPort: (type, sourceNodeId, sourcePort) => {
110
+ const definition = currentRegistry.get(type);
111
+ const { graph } = get();
112
+ const source = graph.nodes.find((node2) => node2.nodeId === sourceNodeId);
113
+ if (!definition || !source) return null;
114
+ const instances = graph.nodes.filter((node2) => node2.type === type).length;
115
+ if (definition.maxInstances !== void 0 && instances >= definition.maxInstances) return null;
116
+ if (graph.edges.some((edge) => edge.source === sourceNodeId && edge.sourcePort === sourcePort)) return null;
117
+ const outputs = currentRegistry.get(source.type)?.outputs ?? [];
118
+ const portIndex = Math.max(0, outputs.indexOf(sourcePort));
119
+ let position = {
120
+ x: source.position.x + FLOW_LEVEL_GAP,
121
+ y: source.position.y + (portIndex - (outputs.length - 1) / 2) * FLOW_SIBLING_GAP
122
+ };
123
+ while (isPositionTaken(graph, position)) position = { x: position.x, y: position.y + FLOW_SIBLING_GAP };
124
+ const node = {
125
+ nodeId: generateUUID(),
126
+ type,
127
+ typeVersion: definition.typeVersion,
128
+ config: definition.createDefaultConfig(),
129
+ position
130
+ };
131
+ const nodes = [...graph.nodes, node];
132
+ const wires = canConnect({ ...graph, nodes }, currentRegistry, { source: sourceNodeId, sourcePort, target: node.nodeId });
133
+ const edges = wires ? [...graph.edges, { edgeId: generateUUID(), source: sourceNodeId, sourcePort, target: node.nodeId }] : graph.edges;
134
+ commit({ nodes, edges }, { nodeIds: [node.nodeId], edgeIds: [] });
135
+ return node.nodeId;
136
+ },
137
+ updateNodeConfig: (nodeId, config) => {
138
+ const { graph } = get();
139
+ commit(
140
+ { ...graph, nodes: graph.nodes.map((node) => node.nodeId === nodeId ? { ...node, config } : node) },
141
+ void 0,
142
+ `config:${nodeId}`
143
+ );
144
+ },
145
+ updateNodeLabel: (nodeId, label) => {
146
+ const { graph } = get();
147
+ const hasText = label.trim().length > 0;
148
+ commit(
149
+ {
150
+ ...graph,
151
+ nodes: graph.nodes.map(
152
+ (node) => node.nodeId === nodeId ? { ...node, label: hasText ? label : void 0 } : node
153
+ )
154
+ },
155
+ void 0,
156
+ `label:${nodeId}`
157
+ );
158
+ },
159
+ moveNodes: (positions) => {
160
+ const { graph } = get();
161
+ set({
162
+ graph: {
163
+ ...graph,
164
+ nodes: graph.nodes.map(
165
+ (node) => positions[node.nodeId] ? { ...node, position: positions[node.nodeId] } : node
166
+ )
167
+ },
168
+ isDirty: true
169
+ });
170
+ },
171
+ connect: (source, sourcePort, target) => {
172
+ const { graph } = get();
173
+ if (!canConnect(graph, currentRegistry, { source, sourcePort, target })) return false;
174
+ const edge = { edgeId: generateUUID(), source, sourcePort, target };
175
+ commit({ ...graph, edges: [...graph.edges, edge] });
176
+ return true;
177
+ },
178
+ removeEdges: (edgeIds) => {
179
+ if (edgeIds.length === 0) return;
180
+ const { graph } = get();
181
+ const removed = new Set(edgeIds);
182
+ commit({ ...graph, edges: graph.edges.filter((edge) => !removed.has(edge.edgeId)) }, { edgeIds: [] });
183
+ },
184
+ removeSelected: () => {
185
+ const { graph, selectedNodeIds, selectedEdgeIds } = get();
186
+ if (selectedNodeIds.length === 0 && selectedEdgeIds.length === 0) return;
187
+ const removedEdges = new Set(selectedEdgeIds);
188
+ const next = withoutNodes(
189
+ { ...graph, edges: graph.edges.filter((edge) => !removedEdges.has(edge.edgeId)) },
190
+ new Set(selectedNodeIds)
191
+ );
192
+ commit(next, { nodeIds: [], edgeIds: [] });
193
+ },
194
+ duplicateSelected: () => {
195
+ const { graph, selectedNodeIds } = get();
196
+ const selected = graph.nodes.filter((node) => selectedNodeIds.includes(node.nodeId));
197
+ const copies = cloneNodes(selected, PASTE_OFFSET);
198
+ if (copies.length === 0) return;
199
+ commit(
200
+ { ...graph, nodes: [...graph.nodes, ...copies] },
201
+ { nodeIds: copies.map((node) => node.nodeId), edgeIds: [] }
202
+ );
203
+ },
204
+ copySelected: () => {
205
+ const { graph, selectedNodeIds } = get();
206
+ set({ clipboard: graph.nodes.filter((node) => selectedNodeIds.includes(node.nodeId)) });
207
+ },
208
+ paste: () => {
209
+ const { graph, clipboard } = get();
210
+ const copies = cloneNodes(clipboard, PASTE_OFFSET);
211
+ if (copies.length === 0) return;
212
+ commit(
213
+ { ...graph, nodes: [...graph.nodes, ...copies] },
214
+ { nodeIds: copies.map((node) => node.nodeId), edgeIds: [] }
215
+ );
216
+ set({ clipboard: copies });
217
+ },
218
+ setSelection: ({ nodeIds, edgeIds }) => {
219
+ set((state) => ({
220
+ selectedNodeIds: nodeIds ?? state.selectedNodeIds,
221
+ selectedEdgeIds: edgeIds ?? state.selectedEdgeIds
222
+ }));
223
+ },
224
+ undo: () => {
225
+ const { graph, past, future } = get();
226
+ const previous = past[past.length - 1];
227
+ if (!previous) return;
228
+ set({
229
+ graph: previous,
230
+ past: past.slice(0, -1),
231
+ future: [graph, ...future].slice(0, HISTORY_LIMIT),
232
+ selectedNodeIds: [],
233
+ selectedEdgeIds: [],
234
+ isDirty: true
235
+ });
236
+ },
237
+ redo: () => {
238
+ const { graph, past, future } = get();
239
+ const following = future[0];
240
+ if (!following) return;
241
+ set({
242
+ graph: following,
243
+ past: [...past, graph].slice(-HISTORY_LIMIT),
244
+ future: future.slice(1),
245
+ selectedNodeIds: [],
246
+ selectedEdgeIds: [],
247
+ isDirty: true
248
+ });
249
+ },
250
+ setRegistry: (nextRegistry) => {
251
+ currentRegistry = nextRegistry;
252
+ }
253
+ };
254
+ });
255
+ export {
256
+ createFlowEditorStore
257
+ };
258
+ //# sourceMappingURL=flowEditorStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flowEditorStore.js","sources":["../../../../src/components/UI/Flow/flowEditorStore.ts"],"sourcesContent":["import { createStore, type StoreApi } from 'zustand/vanilla';\n\nimport { generateUUID } from '@/helpers/utilityHelpers';\n\nimport type { IFlowBlockRegistry } from './flowBlockRegistry';\nimport { canConnect, FLOW_LEVEL_GAP, FLOW_SIBLING_GAP, layoutFlowByLevels } from './flowGraph';\nimport type { IFlowEdge, IFlowGraph, IFlowNode, IFlowPosition, TFlowPortId } from './flowTypes';\n\nconst HISTORY_LIMIT = 50;\nconst PASTE_OFFSET = 32;\n/** Edits to the same field within this window share one undo step (typing a name is one change). */\nconst COALESCE_WINDOW_MS = 1000;\n\nexport interface IFlowEditorState {\n graph: IFlowGraph;\n selectedNodeIds: Array<string>;\n selectedEdgeIds: Array<string>;\n past: Array<IFlowGraph>;\n future: Array<IFlowGraph>;\n clipboard: Array<IFlowNode>;\n isDirty: boolean;\n\n replaceGraph: (graph: IFlowGraph, options?: { keepHistory?: boolean }) => void;\n markClean: () => void;\n /** Snapshot before a gesture that changes the graph in many small steps (a drag). */\n recordHistory: () => void;\n addNode: (type: string, position?: IFlowPosition) => string | null;\n /** Adds a block right of `sourceNodeId` and wires `sourcePort` to it in one undo step. */\n addNodeFromPort: (type: string, sourceNodeId: string, sourcePort: TFlowPortId) => string | null;\n updateNodeConfig: (nodeId: string, config: unknown) => void;\n updateNodeLabel: (nodeId: string, label: string) => void;\n moveNodes: (positions: Record<string, IFlowPosition>) => void;\n connect: (source: string, sourcePort: TFlowPortId, target: string) => boolean;\n removeEdges: (edgeIds: Array<string>) => void;\n removeSelected: () => void;\n duplicateSelected: () => void;\n copySelected: () => void;\n paste: () => void;\n setSelection: (selection: { nodeIds?: Array<string>; edgeIds?: Array<string> }) => void;\n undo: () => void;\n redo: () => void;\n /** The host may rebuild its registry (labels after a language switch); gestures always read the latest. */\n setRegistry: (registry: IFlowBlockRegistry) => void;\n}\n\nexport type TFlowEditorStore = StoreApi<IFlowEditorState>;\n\nconst isPosition = (position: unknown): position is IFlowPosition =>\n typeof (position as IFlowPosition | undefined)?.x === 'number' &&\n typeof (position as IFlowPosition | undefined)?.y === 'number';\n\n/** Coerces a stored graph; a block saved without a position is placed by the automatic layout. */\nconst normalizeGraph = (graph: IFlowGraph | null | undefined, registry: IFlowBlockRegistry): IFlowGraph => {\n const normalized: IFlowGraph = {\n nodes: Array.isArray(graph?.nodes) ? graph.nodes : [],\n edges: Array.isArray(graph?.edges) ? graph.edges : [],\n };\n if (normalized.nodes.every((node) => isPosition(node.position))) return normalized;\n\n const layout = layoutFlowByLevels(normalized, registry);\n return {\n ...normalized,\n nodes: normalized.nodes.map((node) =>\n isPosition(node.position) ? node : { ...node, position: layout[node.nodeId] ?? { x: 0, y: 0 } },\n ),\n };\n};\n\nconst withoutNodes = (graph: IFlowGraph, nodeIds: Set<string>): IFlowGraph => ({\n nodes: graph.nodes.filter((node) => !nodeIds.has(node.nodeId)),\n edges: graph.edges.filter((edge) => !nodeIds.has(edge.source) && !nodeIds.has(edge.target)),\n});\n\nconst isPositionTaken = (graph: IFlowGraph, position: IFlowPosition): boolean =>\n graph.nodes.some(\n (node) =>\n Math.abs(node.position.x - position.x) < FLOW_LEVEL_GAP &&\n Math.abs(node.position.y - position.y) < FLOW_SIBLING_GAP,\n );\n\n/** Right of the selected block (or the rightmost one), stepping down the column until the slot is free. */\nconst nextFreePosition = (graph: IFlowGraph, selectedNodeIds: Array<string>): IFlowPosition => {\n if (graph.nodes.length === 0) return { x: 0, y: 0 };\n const anchor =\n graph.nodes.find((node) => node.nodeId === selectedNodeIds[0]) ??\n graph.nodes.reduce((current, node) => (node.position.x > current.position.x ? node : current));\n let candidate = { x: anchor.position.x + FLOW_LEVEL_GAP, y: anchor.position.y };\n while (isPositionTaken(graph, candidate)) candidate = { x: candidate.x, y: candidate.y + FLOW_SIBLING_GAP };\n return candidate;\n};\n\n/**\n * One store per editor instance (two canvases on a page never share state). The graph\n * is the source of truth; the canvas only renders it and reports gestures back.\n */\nexport const createFlowEditorStore = (initialGraph: IFlowGraph, registry: IFlowBlockRegistry): TFlowEditorStore =>\n createStore<IFlowEditorState>()((set, get) => {\n let currentRegistry = registry;\n let lastCoalesce: { key: string; at: number } | null = null;\n\n const commit = (\n next: IFlowGraph,\n selection?: { nodeIds?: Array<string>; edgeIds?: Array<string> },\n coalesceKey?: string,\n ) => {\n const { graph, past } = get();\n const now = Date.now();\n const extendsLastStep =\n coalesceKey !== undefined && lastCoalesce?.key === coalesceKey && now - lastCoalesce.at < COALESCE_WINDOW_MS;\n lastCoalesce = coalesceKey === undefined ? null : { key: coalesceKey, at: now };\n set({\n graph: next,\n past: extendsLastStep ? past : [...past, graph].slice(-HISTORY_LIMIT),\n future: [],\n isDirty: true,\n ...(selection?.nodeIds ? { selectedNodeIds: selection.nodeIds } : {}),\n ...(selection?.edgeIds ? { selectedEdgeIds: selection.edgeIds } : {}),\n });\n };\n\n const cloneNodes = (nodes: Array<IFlowNode>, offset: number): Array<IFlowNode> => {\n const instancesByType = new Map<string, number>();\n get().graph.nodes.forEach((node) => instancesByType.set(node.type, (instancesByType.get(node.type) ?? 0) + 1));\n return nodes\n .filter((node) => {\n const definition = currentRegistry.get(node.type);\n if (!definition || definition.category === 'trigger') return false;\n const instances = instancesByType.get(node.type) ?? 0;\n if (definition.maxInstances !== undefined && instances >= definition.maxInstances) return false;\n instancesByType.set(node.type, instances + 1);\n return true;\n })\n .map((node) => ({\n ...node,\n nodeId: generateUUID(),\n config: structuredClone(node.config),\n position: { x: node.position.x + offset, y: node.position.y + offset },\n }));\n };\n\n return {\n graph: normalizeGraph(initialGraph, registry),\n selectedNodeIds: [],\n selectedEdgeIds: [],\n past: [],\n future: [],\n clipboard: [],\n isDirty: false,\n\n replaceGraph: (graph, options) => {\n set((state) => ({\n graph: normalizeGraph(graph, currentRegistry),\n past: options?.keepHistory ? [...state.past, state.graph].slice(-HISTORY_LIMIT) : [],\n future: [],\n selectedNodeIds: [],\n selectedEdgeIds: [],\n isDirty: Boolean(options?.keepHistory),\n }));\n },\n\n markClean: () => set({ isDirty: false }),\n\n recordHistory: () => {\n const { graph, past } = get();\n set({ past: [...past, graph].slice(-HISTORY_LIMIT), future: [] });\n },\n\n addNode: (type, position) => {\n const definition = currentRegistry.get(type);\n if (!definition) return null;\n\n const { graph, selectedNodeIds } = get();\n const instances = graph.nodes.filter((node) => node.type === type).length;\n if (definition.maxInstances !== undefined && instances >= definition.maxInstances) return null;\n\n const node: IFlowNode = {\n nodeId: generateUUID(),\n type,\n typeVersion: definition.typeVersion,\n config: definition.createDefaultConfig(),\n position: position ?? nextFreePosition(graph, selectedNodeIds),\n };\n commit({ ...graph, nodes: [...graph.nodes, node] }, { nodeIds: [node.nodeId], edgeIds: [] });\n return node.nodeId;\n },\n\n addNodeFromPort: (type, sourceNodeId, sourcePort) => {\n const definition = currentRegistry.get(type);\n const { graph } = get();\n const source = graph.nodes.find((node) => node.nodeId === sourceNodeId);\n if (!definition || !source) return null;\n\n const instances = graph.nodes.filter((node) => node.type === type).length;\n if (definition.maxInstances !== undefined && instances >= definition.maxInstances) return null;\n if (graph.edges.some((edge) => edge.source === sourceNodeId && edge.sourcePort === sourcePort)) return null;\n\n const outputs = currentRegistry.get(source.type)?.outputs ?? [];\n const portIndex = Math.max(0, outputs.indexOf(sourcePort));\n let position = {\n x: source.position.x + FLOW_LEVEL_GAP,\n y: source.position.y + (portIndex - (outputs.length - 1) / 2) * FLOW_SIBLING_GAP,\n };\n while (isPositionTaken(graph, position)) position = { x: position.x, y: position.y + FLOW_SIBLING_GAP };\n\n const node: IFlowNode = {\n nodeId: generateUUID(),\n type,\n typeVersion: definition.typeVersion,\n config: definition.createDefaultConfig(),\n position,\n };\n const nodes = [...graph.nodes, node];\n const wires = canConnect({ ...graph, nodes }, currentRegistry, { source: sourceNodeId, sourcePort, target: node.nodeId });\n const edges = wires\n ? [...graph.edges, { edgeId: generateUUID(), source: sourceNodeId, sourcePort, target: node.nodeId }]\n : graph.edges;\n commit({ nodes, edges }, { nodeIds: [node.nodeId], edgeIds: [] });\n return node.nodeId;\n },\n\n updateNodeConfig: (nodeId, config) => {\n const { graph } = get();\n commit(\n { ...graph, nodes: graph.nodes.map((node) => (node.nodeId === nodeId ? { ...node, config } : node)) },\n undefined,\n `config:${nodeId}`,\n );\n },\n\n updateNodeLabel: (nodeId, label) => {\n const { graph } = get();\n const hasText = label.trim().length > 0;\n commit(\n {\n ...graph,\n nodes: graph.nodes.map((node) =>\n node.nodeId === nodeId ? { ...node, label: hasText ? label : undefined } : node,\n ),\n },\n undefined,\n `label:${nodeId}`,\n );\n },\n\n moveNodes: (positions) => {\n const { graph } = get();\n set({\n graph: {\n ...graph,\n nodes: graph.nodes.map((node) =>\n positions[node.nodeId] ? { ...node, position: positions[node.nodeId] } : node,\n ),\n },\n isDirty: true,\n });\n },\n\n connect: (source, sourcePort, target) => {\n const { graph } = get();\n if (!canConnect(graph, currentRegistry, { source, sourcePort, target })) return false;\n const edge: IFlowEdge = { edgeId: generateUUID(), source, sourcePort, target };\n commit({ ...graph, edges: [...graph.edges, edge] });\n return true;\n },\n\n removeEdges: (edgeIds) => {\n if (edgeIds.length === 0) return;\n const { graph } = get();\n const removed = new Set(edgeIds);\n commit({ ...graph, edges: graph.edges.filter((edge) => !removed.has(edge.edgeId)) }, { edgeIds: [] });\n },\n\n removeSelected: () => {\n const { graph, selectedNodeIds, selectedEdgeIds } = get();\n if (selectedNodeIds.length === 0 && selectedEdgeIds.length === 0) return;\n const removedEdges = new Set(selectedEdgeIds);\n const next = withoutNodes(\n { ...graph, edges: graph.edges.filter((edge) => !removedEdges.has(edge.edgeId)) },\n new Set(selectedNodeIds),\n );\n commit(next, { nodeIds: [], edgeIds: [] });\n },\n\n duplicateSelected: () => {\n const { graph, selectedNodeIds } = get();\n const selected = graph.nodes.filter((node) => selectedNodeIds.includes(node.nodeId));\n const copies = cloneNodes(selected, PASTE_OFFSET);\n if (copies.length === 0) return;\n commit(\n { ...graph, nodes: [...graph.nodes, ...copies] },\n { nodeIds: copies.map((node) => node.nodeId), edgeIds: [] },\n );\n },\n\n copySelected: () => {\n const { graph, selectedNodeIds } = get();\n set({ clipboard: graph.nodes.filter((node) => selectedNodeIds.includes(node.nodeId)) });\n },\n\n paste: () => {\n const { graph, clipboard } = get();\n const copies = cloneNodes(clipboard, PASTE_OFFSET);\n if (copies.length === 0) return;\n commit(\n { ...graph, nodes: [...graph.nodes, ...copies] },\n { nodeIds: copies.map((node) => node.nodeId), edgeIds: [] },\n );\n set({ clipboard: copies });\n },\n\n setSelection: ({ nodeIds, edgeIds }) => {\n set((state) => ({\n selectedNodeIds: nodeIds ?? state.selectedNodeIds,\n selectedEdgeIds: edgeIds ?? state.selectedEdgeIds,\n }));\n },\n\n undo: () => {\n const { graph, past, future } = get();\n const previous = past[past.length - 1];\n if (!previous) return;\n set({\n graph: previous,\n past: past.slice(0, -1),\n future: [graph, ...future].slice(0, HISTORY_LIMIT),\n selectedNodeIds: [],\n selectedEdgeIds: [],\n isDirty: true,\n });\n },\n\n redo: () => {\n const { graph, past, future } = get();\n const following = future[0];\n if (!following) return;\n set({\n graph: following,\n past: [...past, graph].slice(-HISTORY_LIMIT),\n future: future.slice(1),\n selectedNodeIds: [],\n selectedEdgeIds: [],\n isDirty: true,\n });\n },\n\n setRegistry: (nextRegistry) => {\n currentRegistry = nextRegistry;\n },\n };\n });\n"],"names":["node"],"mappings":";;;AAQA,MAAM,gBAAgB;AACtB,MAAM,e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;AACtC,UAAI,CAAC,WAAW;AAAA,QACd,iBAAiB,WAAW,MAAM;AAAA,QAClC,iBAAiB,WAAW,MAAM;AAAA,MAAA,EAClC;AAAA,IACJ;AAAA,IAEA,MAAM,MAAM;AACV,YAAM,EAAE,OAAO,MAAM,OAAA,IAAW,IAAA;AAChC,YAAM,WAAW,KAAK,KAAK,SAAS,CAAC;AACrC,UAAI,CAAC,SAAU;AACf,UAAI;AAAA,QACF,OAAO;AAAA,QACP,MAAM,KAAK,MAAM,GAAG,EAAE;AAAA,QACtB,QAAQ,CAAC,OAAO,GAAG,MAAM,EAAE,MAAM,GAAG,aAAa;AAAA,QACjD,iBAAiB,CAAA;AAAA,QACjB,iBAAiB,CAAA;AAAA,QACjB,SAAS;AAAA,MAAA,CACV;AAAA,IACH;AAAA,IAEA,MAAM,MAAM;AACV,YAAM,EAAE,OAAO,MAAM,OAAA,IAAW,IAAA;AAChC,YAAM,YAAY,OAAO,CAAC;AAC1B,UAAI,CAAC,UAAW;AAChB,UAAI;AAAA,QACF,OAAO;AAAA,QACP,MAAM,CAAC,GAAG,MAAM,KAAK,EAAE,MAAM,CAAC,aAAa;AAAA,QAC3C,QAAQ,OAAO,MAAM,CAAC;AAAA,QACtB,iBAAiB,CAAA;AAAA,QACjB,iBAAiB,CAAA;AAAA,QACjB,SAAS;AAAA,MAAA,CACV;AAAA,IACH;AAAA,IAEA,aAAa,CAAC,iBAAiB;AAC7B,wBAAkB;AAAA,IACpB;AAAA,EAAA;AAEJ,CAAC;"}
@@ -0,0 +1,32 @@
1
+ import { IFlowBlockRegistry } from './flowBlockRegistry';
2
+ import { IFlowGraph, IFlowIssue, IFlowNode, IFlowPosition, TFlowPortId } from './flowTypes';
3
+ /** The flow reads left to right: one level per column, siblings stacked in the column. */
4
+ export declare const FLOW_LEVEL_GAP = 336;
5
+ export declare const FLOW_SIBLING_GAP = 176;
6
+ export declare const triggerNodesOf: (graph: IFlowGraph, registry: IFlowBlockRegistry) => Array<IFlowNode>;
7
+ /** Node ids reachable from `startNodeId` following edges, the start included. */
8
+ export declare const reachableFrom: (graph: IFlowGraph, startNodeId: string) => Set<string>;
9
+ /** The node ids of the first cycle found, in order, or null when the graph has none. */
10
+ export declare const findCycle: (graph: IFlowGraph) => Array<string> | null;
11
+ export interface IFlowConnectionCandidate {
12
+ source: string;
13
+ sourcePort: TFlowPortId;
14
+ target: string;
15
+ }
16
+ /**
17
+ * The V0 shape is a tree with no fan-out: one input per block, one edge per output
18
+ * port, no edge into a trigger and no cycle. Keeping this rule here lets the canvas
19
+ * refuse a bad connection while it is being drawn, not only when publishing.
20
+ */
21
+ export declare const canConnect: (graph: IFlowGraph, registry: IFlowBlockRegistry, candidate: IFlowConnectionCandidate) => boolean;
22
+ /** The structural rules of the V0 shape, plus each block's own `validate`. */
23
+ export declare const validateFlowGraph: (graph: IFlowGraph, registry: IFlowBlockRegistry) => Array<IFlowIssue>;
24
+ export declare const hasBlockingIssues: (issues: Array<IFlowIssue>) => boolean;
25
+ /**
26
+ * Lays the tree out by levels from the trigger: each level one column to the right,
27
+ * siblings stacked in the column. Used only for a flow with no saved positions (one born from a rule) or when
28
+ * the user asks for it; a position the user arranged is data and is never overwritten
29
+ * implicitly.
30
+ */
31
+ export declare const layoutFlowByLevels: (graph: IFlowGraph, registry: IFlowBlockRegistry) => Record<string, IFlowPosition>;
32
+ export declare const hasSavedPositions: (graph: IFlowGraph) => boolean;
@@ -0,0 +1,156 @@
1
+ const FLOW_LEVEL_GAP = 336;
2
+ const FLOW_SIBLING_GAP = 176;
3
+ const nodesOf = (graph) => Array.isArray(graph?.nodes) ? graph.nodes : [];
4
+ const edgesOf = (graph) => Array.isArray(graph?.edges) ? graph.edges : [];
5
+ const outgoingByNode = (graph) => {
6
+ const outgoing = /* @__PURE__ */ new Map();
7
+ for (const edge of edgesOf(graph)) {
8
+ outgoing.set(edge.source, [...outgoing.get(edge.source) ?? [], edge]);
9
+ }
10
+ return outgoing;
11
+ };
12
+ const triggerNodesOf = (graph, registry) => nodesOf(graph).filter((node) => registry.get(node.type)?.category === "trigger");
13
+ const reachableFrom = (graph, startNodeId) => {
14
+ const outgoing = outgoingByNode(graph);
15
+ const visited = /* @__PURE__ */ new Set();
16
+ const pending = [startNodeId];
17
+ while (pending.length > 0) {
18
+ const nodeId = pending.pop();
19
+ if (nodeId === void 0 || visited.has(nodeId)) continue;
20
+ visited.add(nodeId);
21
+ for (const edge of outgoing.get(nodeId) ?? []) pending.push(edge.target);
22
+ }
23
+ return visited;
24
+ };
25
+ const findCycle = (graph) => {
26
+ const outgoing = outgoingByNode(graph);
27
+ const state = /* @__PURE__ */ new Map();
28
+ const path = [];
29
+ const visit = (nodeId) => {
30
+ state.set(nodeId, "visiting");
31
+ path.push(nodeId);
32
+ for (const edge of outgoing.get(nodeId) ?? []) {
33
+ const targetState = state.get(edge.target);
34
+ if (targetState === "visiting") return path.slice(path.indexOf(edge.target));
35
+ if (targetState === void 0) {
36
+ const cycle = visit(edge.target);
37
+ if (cycle) return cycle;
38
+ }
39
+ }
40
+ path.pop();
41
+ state.set(nodeId, "done");
42
+ return null;
43
+ };
44
+ for (const node of nodesOf(graph)) {
45
+ if (state.has(node.nodeId)) continue;
46
+ const cycle = visit(node.nodeId);
47
+ if (cycle) return cycle;
48
+ }
49
+ return null;
50
+ };
51
+ const canConnect = (graph, registry, candidate) => {
52
+ const { source, sourcePort, target } = candidate;
53
+ if (!source || !target || source === target) return false;
54
+ const nodes = nodesOf(graph);
55
+ const sourceNode = nodes.find((node) => node.nodeId === source);
56
+ const targetNode = nodes.find((node) => node.nodeId === target);
57
+ if (!sourceNode || !targetNode) return false;
58
+ const sourceDefinition = registry.get(sourceNode.type);
59
+ const targetDefinition = registry.get(targetNode.type);
60
+ if (!sourceDefinition?.outputs.includes(sourcePort)) return false;
61
+ if (!targetDefinition || targetDefinition.category === "trigger") return false;
62
+ const edges = edgesOf(graph);
63
+ if (edges.some((edge) => edge.source === source && edge.sourcePort === sourcePort)) return false;
64
+ if (edges.some((edge) => edge.target === target)) return false;
65
+ return !reachableFrom(graph, target).has(source);
66
+ };
67
+ const validateFlowGraph = (graph, registry) => {
68
+ const issues = [];
69
+ const nodes = nodesOf(graph);
70
+ const edges = edgesOf(graph);
71
+ for (const node of nodes) {
72
+ const definition = registry.get(node.type);
73
+ if (!definition) {
74
+ issues.push({ code: "unknownBlock", severity: "error", nodeId: node.nodeId });
75
+ continue;
76
+ }
77
+ for (const blockIssue of definition.validate(node.config) ?? []) {
78
+ issues.push({ ...blockIssue, nodeId: node.nodeId });
79
+ }
80
+ }
81
+ const triggers = triggerNodesOf(graph, registry);
82
+ if (triggers.length === 0) issues.push({ code: "missingTrigger", severity: "error" });
83
+ triggers.slice(1).forEach((trigger) => {
84
+ issues.push({ code: "multipleTriggers", severity: "error", nodeId: trigger.nodeId });
85
+ });
86
+ const firstTrigger = triggers[0];
87
+ if (firstTrigger) {
88
+ const reachable = reachableFrom(graph, firstTrigger.nodeId);
89
+ nodes.filter((node) => !reachable.has(node.nodeId) && registry.get(node.type)?.category !== "trigger").forEach((node) => issues.push({ code: "unreachableNode", severity: "error", nodeId: node.nodeId }));
90
+ }
91
+ const inputCount = /* @__PURE__ */ new Map();
92
+ const portCount = /* @__PURE__ */ new Map();
93
+ for (const edge of edges) {
94
+ inputCount.set(edge.target, (inputCount.get(edge.target) ?? 0) + 1);
95
+ const portKey = `${edge.source}|${edge.sourcePort}`;
96
+ portCount.set(portKey, (portCount.get(portKey) ?? 0) + 1);
97
+ }
98
+ inputCount.forEach((count, nodeId) => {
99
+ if (count > 1) issues.push({ code: "multipleInputs", severity: "error", nodeId });
100
+ });
101
+ edges.filter((edge) => (portCount.get(`${edge.source}|${edge.sourcePort}`) ?? 0) > 1).forEach(
102
+ (edge) => issues.push({ code: "portFanOut", severity: "error", edgeId: edge.edgeId, nodeId: edge.source })
103
+ );
104
+ const cycle = findCycle(graph);
105
+ if (cycle) cycle.forEach((nodeId) => issues.push({ code: "cycle", severity: "error", nodeId }));
106
+ nodes.filter((node) => registry.get(node.type)?.outputs.includes("true")).filter((node) => !edges.some((edge) => edge.source === node.nodeId && edge.sourcePort === "true")).forEach((node) => issues.push({ code: "missingTrueBranch", severity: "warning", nodeId: node.nodeId }));
107
+ return issues;
108
+ };
109
+ const hasBlockingIssues = (issues) => (issues ?? []).some((issue) => issue.severity === "error");
110
+ const layoutFlowByLevels = (graph, registry) => {
111
+ const nodes = nodesOf(graph);
112
+ const outgoing = outgoingByNode(graph);
113
+ const levelOf = /* @__PURE__ */ new Map();
114
+ const roots = triggerNodesOf(graph, registry);
115
+ const queue = roots.map((root) => root.nodeId);
116
+ roots.forEach((root) => levelOf.set(root.nodeId, 0));
117
+ while (queue.length > 0) {
118
+ const nodeId = queue.shift();
119
+ if (nodeId === void 0) continue;
120
+ const level = levelOf.get(nodeId) ?? 0;
121
+ for (const edge of outgoing.get(nodeId) ?? []) {
122
+ if (levelOf.has(edge.target)) continue;
123
+ levelOf.set(edge.target, level + 1);
124
+ queue.push(edge.target);
125
+ }
126
+ }
127
+ const deepestLevel = Math.max(-1, ...Array.from(levelOf.values()));
128
+ nodes.filter((node) => !levelOf.has(node.nodeId)).forEach((node) => levelOf.set(node.nodeId, deepestLevel + 1));
129
+ const nodesByLevel = /* @__PURE__ */ new Map();
130
+ nodes.forEach((node) => {
131
+ const level = levelOf.get(node.nodeId) ?? 0;
132
+ nodesByLevel.set(level, [...nodesByLevel.get(level) ?? [], node.nodeId]);
133
+ });
134
+ const positions = {};
135
+ nodesByLevel.forEach((nodeIds, level) => {
136
+ const columnHeight = (nodeIds.length - 1) * FLOW_SIBLING_GAP;
137
+ nodeIds.forEach((nodeId, index) => {
138
+ positions[nodeId] = { x: level * FLOW_LEVEL_GAP, y: index * FLOW_SIBLING_GAP - columnHeight / 2 };
139
+ });
140
+ });
141
+ return positions;
142
+ };
143
+ const hasSavedPositions = (graph) => nodesOf(graph).some((node) => node.position && (node.position.x !== 0 || node.position.y !== 0));
144
+ export {
145
+ FLOW_LEVEL_GAP,
146
+ FLOW_SIBLING_GAP,
147
+ canConnect,
148
+ findCycle,
149
+ hasBlockingIssues,
150
+ hasSavedPositions,
151
+ layoutFlowByLevels,
152
+ reachableFrom,
153
+ triggerNodesOf,
154
+ validateFlowGraph
155
+ };
156
+ //# sourceMappingURL=flowGraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flowGraph.js","sources":["../../../../src/components/UI/Flow/flowGraph.ts"],"sourcesContent":["import type { IFlowBlockRegistry } from './flowBlockRegistry';\nimport type { IFlowEdge, IFlowGraph, IFlowIssue, IFlowNode, IFlowPosition, TFlowPortId } from './flowTypes';\n\n/** The flow reads left to right: one level per column, siblings stacked in the column. */\nexport const FLOW_LEVEL_GAP = 336;\nexport const FLOW_SIBLING_GAP = 176;\n\nconst nodesOf = (graph: IFlowGraph): Array<IFlowNode> => (Array.isArray(graph?.nodes) ? graph.nodes : []);\nconst edgesOf = (graph: IFlowGraph): Array<IFlowEdge> => (Array.isArray(graph?.edges) ? graph.edges : []);\n\nconst outgoingByNode = (graph: IFlowGraph): Map<string, Array<IFlowEdge>> => {\n const outgoing = new Map<string, Array<IFlowEdge>>();\n for (const edge of edgesOf(graph)) {\n outgoing.set(edge.source, [...(outgoing.get(edge.source) ?? []), edge]);\n }\n return outgoing;\n};\n\nexport const triggerNodesOf = (graph: IFlowGraph, registry: IFlowBlockRegistry): Array<IFlowNode> =>\n nodesOf(graph).filter((node) => registry.get(node.type)?.category === 'trigger');\n\n/** Node ids reachable from `startNodeId` following edges, the start included. */\nexport const reachableFrom = (graph: IFlowGraph, startNodeId: string): Set<string> => {\n const outgoing = outgoingByNode(graph);\n const visited = new Set<string>();\n const pending = [startNodeId];\n while (pending.length > 0) {\n const nodeId = pending.pop();\n if (nodeId === undefined || visited.has(nodeId)) continue;\n visited.add(nodeId);\n for (const edge of outgoing.get(nodeId) ?? []) pending.push(edge.target);\n }\n return visited;\n};\n\n/** The node ids of the first cycle found, in order, or null when the graph has none. */\nexport const findCycle = (graph: IFlowGraph): Array<string> | null => {\n const outgoing = outgoingByNode(graph);\n const state = new Map<string, 'visiting' | 'done'>();\n const path: Array<string> = [];\n\n const visit = (nodeId: string): Array<string> | null => {\n state.set(nodeId, 'visiting');\n path.push(nodeId);\n for (const edge of outgoing.get(nodeId) ?? []) {\n const targetState = state.get(edge.target);\n if (targetState === 'visiting') return path.slice(path.indexOf(edge.target));\n if (targetState === undefined) {\n const cycle = visit(edge.target);\n if (cycle) return cycle;\n }\n }\n path.pop();\n state.set(nodeId, 'done');\n return null;\n };\n\n for (const node of nodesOf(graph)) {\n if (state.has(node.nodeId)) continue;\n const cycle = visit(node.nodeId);\n if (cycle) return cycle;\n }\n return null;\n};\n\nexport interface IFlowConnectionCandidate {\n source: string;\n sourcePort: TFlowPortId;\n target: string;\n}\n\n/**\n * The V0 shape is a tree with no fan-out: one input per block, one edge per output\n * port, no edge into a trigger and no cycle. Keeping this rule here lets the canvas\n * refuse a bad connection while it is being drawn, not only when publishing.\n */\nexport const canConnect = (\n graph: IFlowGraph,\n registry: IFlowBlockRegistry,\n candidate: IFlowConnectionCandidate,\n): boolean => {\n const { source, sourcePort, target } = candidate;\n if (!source || !target || source === target) return false;\n\n const nodes = nodesOf(graph);\n const sourceNode = nodes.find((node) => node.nodeId === source);\n const targetNode = nodes.find((node) => node.nodeId === target);\n if (!sourceNode || !targetNode) return false;\n\n const sourceDefinition = registry.get(sourceNode.type);\n const targetDefinition = registry.get(targetNode.type);\n if (!sourceDefinition?.outputs.includes(sourcePort)) return false;\n if (!targetDefinition || targetDefinition.category === 'trigger') return false;\n\n const edges = edgesOf(graph);\n if (edges.some((edge) => edge.source === source && edge.sourcePort === sourcePort)) return false;\n if (edges.some((edge) => edge.target === target)) return false;\n\n return !reachableFrom(graph, target).has(source);\n};\n\n/** The structural rules of the V0 shape, plus each block's own `validate`. */\nexport const validateFlowGraph = (graph: IFlowGraph, registry: IFlowBlockRegistry): Array<IFlowIssue> => {\n const issues: Array<IFlowIssue> = [];\n const nodes = nodesOf(graph);\n const edges = edgesOf(graph);\n\n for (const node of nodes) {\n const definition = registry.get(node.type);\n if (!definition) {\n issues.push({ code: 'unknownBlock', severity: 'error', nodeId: node.nodeId });\n continue;\n }\n for (const blockIssue of definition.validate(node.config) ?? []) {\n issues.push({ ...blockIssue, nodeId: node.nodeId });\n }\n }\n\n const triggers = triggerNodesOf(graph, registry);\n if (triggers.length === 0) issues.push({ code: 'missingTrigger', severity: 'error' });\n triggers.slice(1).forEach((trigger) => {\n issues.push({ code: 'multipleTriggers', severity: 'error', nodeId: trigger.nodeId });\n });\n\n const firstTrigger = triggers[0];\n if (firstTrigger) {\n const reachable = reachableFrom(graph, firstTrigger.nodeId);\n nodes\n .filter((node) => !reachable.has(node.nodeId) && registry.get(node.type)?.category !== 'trigger')\n .forEach((node) => issues.push({ code: 'unreachableNode', severity: 'error', nodeId: node.nodeId }));\n }\n\n const inputCount = new Map<string, number>();\n const portCount = new Map<string, number>();\n for (const edge of edges) {\n inputCount.set(edge.target, (inputCount.get(edge.target) ?? 0) + 1);\n const portKey = `${edge.source}|${edge.sourcePort}`;\n portCount.set(portKey, (portCount.get(portKey) ?? 0) + 1);\n }\n inputCount.forEach((count, nodeId) => {\n if (count > 1) issues.push({ code: 'multipleInputs', severity: 'error', nodeId });\n });\n edges\n .filter((edge) => (portCount.get(`${edge.source}|${edge.sourcePort}`) ?? 0) > 1)\n .forEach((edge) =>\n issues.push({ code: 'portFanOut', severity: 'error', edgeId: edge.edgeId, nodeId: edge.source }),\n );\n\n const cycle = findCycle(graph);\n if (cycle) cycle.forEach((nodeId) => issues.push({ code: 'cycle', severity: 'error', nodeId }));\n\n nodes\n .filter((node) => registry.get(node.type)?.outputs.includes('true'))\n .filter((node) => !edges.some((edge) => edge.source === node.nodeId && edge.sourcePort === 'true'))\n .forEach((node) => issues.push({ code: 'missingTrueBranch', severity: 'warning', nodeId: node.nodeId }));\n\n return issues;\n};\n\nexport const hasBlockingIssues = (issues: Array<IFlowIssue>): boolean =>\n (issues ?? []).some((issue) => issue.severity === 'error');\n\n/**\n * Lays the tree out by levels from the trigger: each level one column to the right,\n * siblings stacked in the column. Used only for a flow with no saved positions (one born from a rule) or when\n * the user asks for it; a position the user arranged is data and is never overwritten\n * implicitly.\n */\nexport const layoutFlowByLevels = (graph: IFlowGraph, registry: IFlowBlockRegistry): Record<string, IFlowPosition> => {\n const nodes = nodesOf(graph);\n const outgoing = outgoingByNode(graph);\n const levelOf = new Map<string, number>();\n const roots = triggerNodesOf(graph, registry);\n const queue: Array<string> = roots.map((root) => root.nodeId);\n roots.forEach((root) => levelOf.set(root.nodeId, 0));\n\n while (queue.length > 0) {\n const nodeId = queue.shift();\n if (nodeId === undefined) continue;\n const level = levelOf.get(nodeId) ?? 0;\n for (const edge of outgoing.get(nodeId) ?? []) {\n if (levelOf.has(edge.target)) continue;\n levelOf.set(edge.target, level + 1);\n queue.push(edge.target);\n }\n }\n\n const deepestLevel = Math.max(-1, ...Array.from(levelOf.values()));\n nodes.filter((node) => !levelOf.has(node.nodeId)).forEach((node) => levelOf.set(node.nodeId, deepestLevel + 1));\n\n const nodesByLevel = new Map<number, Array<string>>();\n nodes.forEach((node) => {\n const level = levelOf.get(node.nodeId) ?? 0;\n nodesByLevel.set(level, [...(nodesByLevel.get(level) ?? []), node.nodeId]);\n });\n\n const positions: Record<string, IFlowPosition> = {};\n nodesByLevel.forEach((nodeIds, level) => {\n const columnHeight = (nodeIds.length - 1) * FLOW_SIBLING_GAP;\n nodeIds.forEach((nodeId, index) => {\n positions[nodeId] = { x: level * FLOW_LEVEL_GAP, y: index * FLOW_SIBLING_GAP - columnHeight / 2 };\n });\n });\n return positions;\n};\n\nexport const hasSavedPositions = (graph: IFlowGraph): boolean =>\n nodesOf(graph).some((node) => node.position && (node.position.x !== 0 || node.position.y !== 0));\n"],"names":[],"mappings":"AAIO,MAAM,iBAAiB;AACvB,MAAM,mBAAmB;AAEhC,MAAM,UAAU,CAAC,UAAyC,MAAM,QAAQ,OA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ory = 'trigger' | 'condition' | 'action';
5
+ export interface IFlowPosition {
6
+ x: number;
7
+ y: number;
8
+ }
9
+ export interface IFlowNode<TConfig = unknown> {
10
+ nodeId: string;
11
+ type: string;
12
+ typeVersion: number;
13
+ config: TConfig;
14
+ position: IFlowPosition;
15
+ label?: string;
16
+ disabled?: boolean;
17
+ }
18
+ export interface IFlowEdge {
19
+ edgeId: string;
20
+ source: string;
21
+ sourcePort: TFlowPortId;
22
+ target: string;
23
+ }
24
+ export interface IFlowGraph {
25
+ nodes: Array<IFlowNode>;
26
+ edges: Array<IFlowEdge>;
27
+ }
28
+ export type TFlowIssueSeverity = 'error' | 'warning';
29
+ export type TFlowGraphIssueCode = 'missingTrigger' | 'multipleTriggers' | 'unknownBlock' | 'unreachableNode' | 'multipleInputs' | 'portFanOut' | 'cycle' | 'missingTrueBranch';
30
+ export interface IFlowIssue {
31
+ /** A graph rule from `TFlowGraphIssueCode`, or a block-specific code from its `validate`. */
32
+ code: string;
33
+ severity: TFlowIssueSeverity;
34
+ /** Already translated by the block. Graph issues leave it empty and the UI names them. */
35
+ message?: string;
36
+ nodeId?: string;
37
+ edgeId?: string;
38
+ }
39
+ export type TFlowRunStepStatus = 'passed' | 'failed' | 'skipped' | 'wouldRun' | 'error' | 'blocked';
40
+ /** The result of one run (real or simulated) painted over the canvas. */
41
+ export interface IFlowRunOverlay {
42
+ steps: Record<string, TFlowRunStepStatus>;
43
+ traversedEdgeIds: Array<string>;
44
+ }
45
+ export interface IFlowBlockConfigPanelProps<TConfig> {
46
+ config: TConfig;
47
+ onChange: (next: TConfig) => void;
48
+ readOnly?: boolean;
49
+ }
50
+ export type TFlowBlockIssue = Omit<IFlowIssue, 'nodeId' | 'edgeId'>;
51
+ export interface IFlowBlockDefinition<TConfig = unknown> {
52
+ /** Namespaced and stable: `trigger.recordEvent`, `action.moveWorkflowCard`. */
53
+ type: string;
54
+ typeVersion: number;
55
+ category: TFlowBlockCategory;
56
+ icon: SymbolCodepoints;
57
+ /** Translated by the host. */
58
+ label: string;
59
+ description?: string;
60
+ outputs: Array<TFlowPortId>;
61
+ /** How many of this block a flow may hold; omit for no limit. */
62
+ maxInstances?: number;
63
+ createDefaultConfig: () => TConfig;
64
+ migrateConfig?: (config: unknown, fromVersion: number) => TConfig;
65
+ ConfigPanel: ComponentType<IFlowBlockConfigPanelProps<TConfig>>;
66
+ /** When one block stands for several kinds (chosen inside it), the icon and name of the chosen kind. */
67
+ resolveIcon?: (config: TConfig) => SymbolCodepoints | undefined;
68
+ resolveLabel?: (config: TConfig) => string | undefined;
69
+ /** One line inside the block on the canvas. */
70
+ renderSummary: (config: TConfig) => ReactNode;
71
+ /** This block's piece of the "When..., if..., then..." sentence. */
72
+ describe: (config: TConfig) => string;
73
+ validate: (config: TConfig) => Array<TFlowBlockIssue>;
74
+ }
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=flowTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flowTypes.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -0,0 +1,14 @@
1
+ export { createFlowBlockRegistry, defineFlowBlock, type IFlowBlockRegistry } from './flowBlockRegistry';
2
+ export { default as FlowCanvas, type IFlowCanvasProps } from './FlowCanvas';
3
+ export { FLOW_BLOCK_DRAG_TYPE } from './flowConstants';
4
+ export { default as FlowEditorProvider, useFlowBlockRegistry, useFlowEditor, useFlowEditorStore, } from './FlowEditorProvider';
5
+ export { createFlowEditorStore, type IFlowEditorState, type TFlowEditorStore } from './flowEditorStore';
6
+ export { canConnect, findCycle, FLOW_LEVEL_GAP, FLOW_SIBLING_GAP, hasBlockingIssues, hasSavedPositions, layoutFlowByLevels, reachableFrom, triggerNodesOf, validateFlowGraph, } from './flowGraph';
7
+ export { default as FlowInspector } from './FlowInspector';
8
+ export { default as FlowIssueList } from './FlowIssueList';
9
+ export { default as FlowLaneMap, type IFlowArc, type IFlowLane, type TFlowArcTone } from './FlowLaneMap';
10
+ export { default as FlowNodeShell, type IFlowNodeShellProps } from './FlowNodeShell';
11
+ export { default as FlowPalette } from './FlowPalette';
12
+ export { default as FlowResizablePanel, type IFlowResizablePanelProps } from './FlowResizablePanel';
13
+ export type * from './flowTypes';
14
+ export { FLOW_RUN_STATUS_TONE, useFlowLabels } from './useFlowLabels';