@@ -330,6 +330,34 @@ const mutations = {
330330 }
331331 }
332332 }
333+ //update the component name in the htmlList of all components if it is a child component
334+ for ( const item of Object . values ( state . componentMap ) ) {
335+ if ( item . htmlList ) {
336+ const newArray = [ ...item . htmlList ] ;
337+
338+ const changeAllChildComponents = ( array , name ) => {
339+ const queue = [ ...array . filter ( el => typeof el === 'object' ) ] ;
340+ while ( queue . length ) {
341+ const evaluate = queue . shift ( ) ;
342+ if ( evaluate . text === name ) {
343+ evaluate . text = payload ;
344+ }
345+ for ( let i = 0 ; i < evaluate . children . length ; i ++ ) {
346+ if ( evaluate . children [ i ] . text === name ) {
347+ evaluate . children [ i ] . text = payload ;
348+ }
349+ if ( evaluate . children . length ) {
350+ queue . push ( ...evaluate . children )
351+ }
352+ }
353+ }
354+ }
355+
356+ changeAllChildComponents ( newArray , temp )
357+ item . htmlList = newArray
358+ }
359+ }
360+
333361 } ,
334362
335363 // *** HTML ELEMENTS *** //////////////////////////////////////////////
@@ -759,7 +787,32 @@ const mutations = {
759787 // state.componentMap[state.activeComponent].htmlList = newHTMLList;
760788 // const newMap = { ...state.componentMap };
761789 // state.componentMap = { ...newMap };
790+
791+ //delete the instances of the Child Component in the activeComponent's htmlList
792+ const componentName = state . activeComponent ;
793+ const htmlList = state . componentMap [ componentName ] . htmlList . slice ( 0 ) ;
794+
795+ // splice out child componenets even if nested
796+ function deleteChildFromHtmlList ( array , payload ) {
797+ for ( let i = array . length ; i -- ; ) {
798+
799+ if ( array [ i ] . children . length ) {
800+ deleteChildFromHtmlList ( array [ i ] . children , payload )
801+ }
802+ if ( array [ i ] . text === payload ) {
803+ array . splice ( i , 1 )
804+ }
805+
806+ }
807+ }
808+ deleteChildFromHtmlList ( htmlList , payload ) ;
809+
810+ //updates the htmlList with the child components deleted
811+ state . componentMap [ componentName ] . htmlList = htmlList ;
812+
813+ //delete the parent because the payload is no longer a child to the acitive component
762814 delete state . componentMap [ payload ] . parent [ state . activeComponent ] ;
815+
763816 // add block
764817 } else {
765818 const child = temp ;
0 commit comments