// — a flow drawn as boxes and lines: the source on the left, its // branches to the right. Pick a node to edit it; the inspector beside the // canvas does the editing. import { layoutFlow, NODE_HEIGHT, NODE_WIDTH } from "./FlowLayout.js"; import { describeNode, ellipsize, type Flow } from "./FlowTypes.js"; const TEXT_CHARS = 30; export function FlowCanvas({ flow, selected, onSelect, }: { flow: Flow; selected: string | null; onSelect: (id: string) => void; }) { const layout = layoutFlow(flow); const byId = new Map(flow.nodes.map((n) => [n.id, n])); return (
{layout.edges.map((e) => { const mid = (e.x1 + e.x2) / 2; return ( ${e.to}`} class="notify-edge" d={`M${e.x1} ${e.y1} C${mid} ${e.y1} ${mid} ${e.y2} ${e.x2} ${e.y2}`} /> ); })} {layout.nodes.map((p) => { const node = byId.get(p.id); if (!node) return null; const text = describeNode(node); return ( onSelect(p.id)} onKeyDown={(e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault(); onSelect(p.id); } }} > {text} {node.kind} {ellipsize(text, TEXT_CHARS)} ); })}
); }