import { BuilderCanvasData , BuilderRuntimeEdge } from "../interfaces" ; export function deleteNodeFromTree ( nodeUid , { rootId , nodes , edges } ) { const idsToDelete = new Set < number > ( ) ; collectIdsToDelete ( nodeUid , edges , idsToDelete ) ; return { rootId , nodes : nodes . filter ( ( node ) => ! idsToDelete . has ( node . $$uid ) ) , edges : edges . filter ( ( edge ) => ! idsToDelete . has ( edge . parent ) && ! idsToDelete . has ( edge . child ) ) , } ; } function collectIdsToDelete ( nodeUid , edges , idsToDelete ) { idsToDelete . add ( nodeUid ) ; const ids = new Set < number > ( ) ; for ( const edge of edges ) { if ( edge . parent === nodeUid ) { ids . add ( edge . child ) ; } } for ( const id of ids ) { collectIdsToDelete ( id , edges , idsToDelete ) ; } }