"use client"; import type { MouseEvent as ReactMouseEvent } from "react"; import type { CanvasConnection, CanvasNode, CanvasPosition } from "@/lib/canvas/types"; import { getActiveConnectionPath, getConnectionPath } from "@/lib/canvas/geometry"; type CanvasConnectionsProps = { connections: CanvasConnection[]; nodes: CanvasNode[]; selectedConnectionId: string | null; activeConnection?: { fromNodeId: string; mouseWorld: CanvasPosition; } | null; onSelectConnection: (id: string) => void; }; export function CanvasConnections({ connections, nodes, selectedConnectionId, activeConnection, onSelectConnection, }: CanvasConnectionsProps) { const byId = new Map(nodes.map((node) => [node.id, node])); const activeFrom = activeConnection ? byId.get(activeConnection.fromNodeId) : undefined; return ( {connections.map((connection) => { const from = byId.get(connection.fromNodeId); const to = byId.get(connection.toNodeId); if (!from || !to) return null; return ( onSelectConnection(connection.id)} /> ); })} {activeConnection && activeFrom ? ( ) : null} ); } function ConnectionPath({ connection, from, to, active, onSelect, }: { connection: CanvasConnection; from: CanvasNode; to: CanvasNode; active: boolean; onSelect: () => void; }) { const path = getConnectionPath(from, to); const stroke = active ? "#18181b" : "#a1a1aa"; function handleContextMenu(event: ReactMouseEvent) { event.preventDefault(); event.stopPropagation(); onSelect(); } return ( { event.stopPropagation(); onSelect(); }} onContextMenu={handleContextMenu} /> ); }