11/**
2- * Connection validation and utilities for SvelteFlow canvas
2+ * Connection utilities for SvelteFlow canvas
33 */
44
55import { get } from 'svelte/store' ;
66import { graphStore } from '$lib/stores/graph' ;
7- import { nodeRegistry } from '$lib/nodes' ;
8- import { HANDLE_ID } from '$lib/constants/handles' ;
97
108/**
119 * Find the first available (unconnected) input port for a node
@@ -30,65 +28,3 @@ export function findFirstAvailableInputPort(nodeId: string): number | null {
3028
3129 return null ;
3230}
33-
34- /**
35- * Check if a target port is already connected
36- */
37- export function isPortOccupied ( nodeId : string , portIndex : number ) : boolean {
38- const currentConnections = get ( graphStore . connections ) ;
39- return currentConnections . some (
40- ( c ) => c . targetNodeId === nodeId && c . targetPortIndex === portIndex
41- ) ;
42- }
43-
44- /**
45- * Check if a node can accept more input ports
46- */
47- export function canAddInputPort ( nodeId : string ) : boolean {
48- const graphNodes = get ( graphStore . nodesArray ) ;
49- const node = graphNodes . find ( ( n ) => n . id === nodeId ) ;
50- if ( ! node ) return false ;
51-
52- const typeDef = nodeRegistry . get ( node . type ) ;
53- if ( ! typeDef ) return false ;
54-
55- // Check if maxInputs allows more ports
56- return typeDef . ports . maxInputs === null || node . inputs . length < typeDef . ports . maxInputs ;
57- }
58-
59- /**
60- * Find a connection by edge properties (source, target, handles)
61- */
62- export function findConnectionByEdge (
63- source : string ,
64- target : string ,
65- sourceHandle : string | null ,
66- targetHandle : string | null
67- ) : { id : string ; sourcePortIndex : number ; targetPortIndex : number } | null {
68- const currentConnections = get ( graphStore . connections ) ;
69-
70- // Try to parse port indices from handles
71- if ( sourceHandle && targetHandle ) {
72- const { sourceIndex, targetIndex } = HANDLE_ID . parseConnection ( sourceHandle , targetHandle ) ;
73-
74- if ( sourceIndex !== null && targetIndex !== null ) {
75- const conn = currentConnections . find (
76- ( c ) =>
77- c . sourceNodeId === source &&
78- c . sourcePortIndex === sourceIndex &&
79- c . targetNodeId === target &&
80- c . targetPortIndex === targetIndex
81- ) ;
82-
83- if ( conn ) {
84- return {
85- id : conn . id ,
86- sourcePortIndex : sourceIndex ,
87- targetPortIndex : targetIndex
88- } ;
89- }
90- }
91- }
92-
93- return null ;
94- }
0 commit comments