Build in/out edge maps. Outgoing stored with sourceHandle so we can put "next" (main flow) first.
( nodes: FlowNode[], edges: FlowEdge[] )
| 377 | |
| 378 | /** Build in/out edge maps. Outgoing stored with sourceHandle so we can put "next" (main flow) first. */ |
| 379 | function buildGraph( |
| 380 | nodes: FlowNode[], |
| 381 | edges: FlowEdge[] |
| 382 | ): { |
| 383 | inEdges: Map<string, string[]>; |
| 384 | outEdgesWithHandle: Map<string, { target: string; sourceHandle?: string }[]>; |
| 385 | idSet: Set<string>; |
| 386 | } { |
| 387 | const idSet = new Set(nodes.map((n) => n.id)); |
| 388 | const inEdges = new Map<string, string[]>(); |
| 389 | const outEdgesWithHandle = new Map<string, { target: string; sourceHandle?: string }[]>(); |
| 390 | nodes.forEach((n) => { |
| 391 | inEdges.set(n.id, []); |
| 392 | outEdgesWithHandle.set(n.id, []); |
| 393 | }); |
| 394 | edges.forEach((e) => { |
| 395 | if (!idSet.has(e.source) || !idSet.has(e.target)) return; |
| 396 | inEdges.get(e.target)!.push(e.source); |
| 397 | outEdgesWithHandle.get(e.source)!.push({ |
| 398 | target: e.target, |
| 399 | sourceHandle: e.sourceHandle ?? undefined, |
| 400 | }); |
| 401 | }); |
| 402 | return { inEdges, outEdgesWithHandle, idSet }; |
| 403 | } |
| 404 | |
| 405 | /** Main-flow handle first (next/bottom), then branch handles. */ |
| 406 | function nextFlowPriority(handle: string | undefined): number { |