/** * Proximity Connect Helper * * Provides type-aware proximity connect logic for the workflow editor. * When a node is dragged near another node, this helper finds the best * compatible port pair and creates a preview/permanent edge. */ import type { WorkflowNode as WorkflowNodeType, WorkflowEdge, NodePort, PortCoordinateMap } from '../types/index.js'; /** A candidate proximity edge before it is finalized */ export interface ProximityEdgeCandidate { id: string; source: string; target: string; sourceHandle: string; targetHandle: string; sourcePortDataType: string; targetPortDataType: string; } export declare class ProximityConnectHelper { /** * Get ALL ports (static + dynamic + gateway branches) for a node. * * Only reads `type` and `data`, so callers can pass a full node or a lighter * slice (e.g. a renderer that has metadata + config but no position/measured). */ static getAllPorts(node: Pick, direction: 'input' | 'output'): NodePort[]; /** * Build handle ID in the standard format. */ static buildHandleId(nodeId: string, direction: 'input' | 'output', portId: string): string; /** * Calculate center-to-center distance between two nodes. */ static getNodeDistance(nodeA: { position: { x: number; y: number; }; measured?: { width?: number; height?: number; }; }, nodeB: { position: { x: number; y: number; }; measured?: { width?: number; height?: number; }; }): number; /** * Find the single best compatible edge between a dragged node and nearby nodes. * * Algorithm: * 1. Find the closest node within minDistance (edge-to-edge) * 2. Check both directions (dragged->nearby and nearby->dragged) * 3. Return the first exact-type match, or first compatible match * 4. Skip pairs where an edge already exists * * @returns Array with at most ONE ProximityEdgeCandidate */ static findCompatibleEdges(draggedNode: WorkflowNodeType, allNodes: WorkflowNodeType[], existingEdges: WorkflowEdge[], minDistance: number): ProximityEdgeCandidate[]; /** * Find the single best compatible edge using port-to-port distance. * * Unlike findCompatibleEdges() which uses node center distance, * this method compares actual handle positions from the port coordinate store. * This is more accurate for large nodes or nodes with many ports. * * Algorithm: * 1. Partition ports by owner (dragged vs other) and direction (input vs output) * 2. Group other-node ports by dataType for O(1) lookup of compatible groups * 3. For each dragged port, only iterate compatible dataType groups * 4. Return the closest compatible pair (exact type match preferred) * * @returns Array with at most ONE ProximityEdgeCandidate */ static findCompatibleEdgesByPortCoordinates(draggedNodeId: string, portCoordinates: PortCoordinateMap, existingEdges: WorkflowEdge[], maxDistance: number): ProximityEdgeCandidate[]; /** * Convert candidates to temporary (preview) WorkflowEdge objects with dashed styling. */ static createPreviewEdges(candidates: ProximityEdgeCandidate[]): WorkflowEdge[]; /** * Convert candidates to permanent WorkflowEdge objects. */ static createPermanentEdges(candidates: ProximityEdgeCandidate[]): WorkflowEdge[]; /** * Check if an edge is a temporary proximity preview edge. */ static isProximityPreviewEdge(edge: WorkflowEdge): boolean; /** * Remove all proximity preview edges from an edge array. */ static removePreviewEdges(edges: WorkflowEdge[]): WorkflowEdge[]; }