@@ -331,3 +331,47 @@ export function syncPortNamesFromLabels(
331331 updateNodeById ( nodeId , ( ) => updated ) ;
332332 }
333333}
334+
335+ /**
336+ * Rename a single port. For regular nodes this writes the new name into
337+ * `node.{inputs|outputs}[index].name`. For Interface nodes, port names are
338+ * derived from the parent Subsystem at read time, so we write to the parent
339+ * instead (with the direction flipped, because Interface input ↔ Subsystem
340+ * output).
341+ */
342+ export function updateNodePortName (
343+ nodeId : string ,
344+ direction : PortDirection ,
345+ index : number ,
346+ name : string
347+ ) : void {
348+ const currentGraph = getCurrentGraph ( ) ;
349+ const node = currentGraph . nodes . get ( nodeId ) ;
350+ if ( ! node ) return ;
351+
352+ const path = get ( currentPath ) ;
353+
354+ if ( node . type === NODE_TYPES . INTERFACE && path . length > 0 ) {
355+ const parentId = path [ path . length - 1 ] ;
356+ const parentPath = path . slice ( 0 , - 1 ) ;
357+ const parentPortsKey = direction === 'input' ? 'outputs' : 'inputs' ;
358+
359+ updateParentSubsystem ( parentPath , parentId , ( parent ) => {
360+ const ports = parent [ parentPortsKey ] as PortInstance [ ] ;
361+ if ( index < 0 || index >= ports . length ) return parent ;
362+ if ( ports [ index ] . name === name ) return parent ;
363+ const newPorts = ports . map ( ( p , i ) => ( i === index ? { ...p , name } : p ) ) ;
364+ return { ...parent , [ parentPortsKey ] : newPorts } ;
365+ } ) ;
366+ return ;
367+ }
368+
369+ updateNodeById ( nodeId , ( n ) => {
370+ const portsKey = direction === 'input' ? 'inputs' : 'outputs' ;
371+ const ports = n [ portsKey ] as PortInstance [ ] ;
372+ if ( index < 0 || index >= ports . length ) return n ;
373+ if ( ports [ index ] . name === name ) return n ;
374+ const newPorts = ports . map ( ( p , i ) => ( i === index ? { ...p , name } : p ) ) ;
375+ return { ...n , [ portsKey ] : newPorts } ;
376+ } ) ;
377+ }
0 commit comments