import { EditorState , NodeEventTypes } from '@craftjs/core' ; export default function deleteNodes ( state , nodesToDelete ) { nodesToDelete . reverse ( ) . forEach ( ( [ deletedNodeId , replacedNodeId ] ) => { const deletedNode = state . nodes [ deletedNodeId ] ; if ( ! deletedNode ) { return ; } Object . keys ( state . events ) . forEach ( ( key ) => { if ( state . events [ key ] && state . events [ key ] . has ( deletedNodeId ) ) { state . events [ key ] = new Set ( ) ; if ( replacedNodeId && state . nodes [ replacedNodeId ] ) { state . events [ key ] . add ( replacedNodeId ) ; state . nodes [ replacedNodeId ] . events [ key ] = true ; } else { const parentId = state . nodes [ deletedNodeId ] . data . parent ; if ( state . nodes [ parentId ] ) { state . events [ key ] . add ( parentId ) ; } } } } ) ; const parent = state . nodes [ deletedNode . data . parent ] ; if ( parent && parent . data . nodes ) { const deletedNodeIndex = parent . data . nodes . indexOf ( deletedNodeId ) ; if ( deletedNodeIndex > - 1 ) { parent . data . nodes . splice ( deletedNodeIndex , 1 ) ; } } delete state . nodes [ deletedNodeId ] ; } ) ; }