@@ -330,7 +330,7 @@ const mutations = {
330330 }
331331 }
332332 }
333- //update the component name in the htmlList of all components if it is a child component
333+ //update the the htmlList, find child components within the htmlLists with the old value, update it to the new value
334334 for ( const item of Object . values ( state . componentMap ) ) {
335335 if ( item . htmlList ) {
336336 const newArray = [ ...item . htmlList ] ;
@@ -495,25 +495,26 @@ const mutations = {
495495 }
496496 state . activeHTML = "" ;
497497 } ,
498-
498+ //Drag-andDrop
499+ //store id of dragged html element in activeComponent
499500 [ types . SET_ID_DRAG ] : ( state , payload ) => {
500501 const componentName = state . activeComponent ;
501502 state . componentMap [ componentName ] . idDrag = payload ;
502503 } ,
503-
504+ //store id of html element whose place the dragged html element is dropped on in activeComponent
504505 [ types . SET_ID_DROP ] : ( state , payload ) => {
505506 const componentName = state . activeComponent ;
506507 state . componentMap [ componentName ] . idDrop = payload ;
507508 } ,
508-
509+ //store id of dragged selected html element when creating a component
509510 [ types . SET_SELECTED_ID_DRAG ] : ( state , payload ) => {
510511 state . selectedIdDrag = payload ;
511512 } ,
512-
513+ //store id of html element whose place the dragged selected html element will be dropped when creating a component
513514 [ types . SET_SELECTED_ID_DROP ] : ( state , payload ) => {
514515 state . selectedIdDrop = payload ;
515516 } ,
516-
517+ // use idDrag and idDrop to rearrange the htmlList of the activeComponent to perform drag-and-drop functionality
517518 [ types . DRAG_DROP_SORT_HTML_ELEMENTS ] : ( state ) => {
518519 const componentName = state . activeComponent ;
519520 const idDrag = state . componentMap [ componentName ] . idDrag ;
@@ -525,27 +526,32 @@ const mutations = {
525526 const htmlList = state . componentMap [ componentName ] . htmlList . slice ( 0 )
526527
527528 if ( state . activeLayer . id === "" ) {
529+ //find the indexes belonging to the html elements with idDrag and idDrop
528530 htmlList . forEach ( ( el , i ) => {
529531 if ( el . id === idDrag ) {
530532 indexDrag = i ;
531533 } else if ( el . id === idDrop ) {
532534 indexDrop = i ;
533535 }
534536 } )
537+ //use the indexes to rearrange htmlList
535538 const draggedEl = htmlList . splice ( indexDrag , 1 ) [ 0 ]
536539 htmlList . splice ( indexDrop , 0 , draggedEl )
537540 } else {
541+ //Use breadFirstSearchParent to find the parent and indexes of nested html elements with idDrag and idDrop
538542 const nestedDrag = breadthFirstSearchParent ( htmlList , idDrag ) ;
539543 const nestedDrop = breadthFirstSearchParent ( htmlList , idDrop ) ;
544+ //use the indexes and parents to rearrange htmlList
540545 let nestedEl = nestedDrag . evaluated . children . splice ( nestedDrag . index , 1 ) [ 0 ]
541546 nestedDrop . evaluated . children . splice ( nestedDrop . index , 0 , nestedEl )
542547 }
543548 state . componentMap [ componentName ] . htmlList = htmlList ;
544549 }
550+ //reset the ids
545551 state . componentMap [ componentName ] . idDrag = '' ;
546552 state . componentMap [ componentName ] . idDrop = '' ;
547553 } ,
548-
554+ // use selectedIdDrag and selectedIdDrop to rearrange the selectedElementList to perform drag-and-drop functionality
549555 [ types . DRAG_DROP_SORT_SELECTED_HTML_ELEMENTS ] : ( state ) => {
550556 const selectedIdDrag = state . selectedIdDrag ;
551557 const selectedIdDrop = state . selectedIdDrop ;
@@ -555,19 +561,20 @@ const mutations = {
555561
556562 let indexDrag ;
557563 let indexDrop ;
558-
564+ //find the indexes belonging to the html elements with the selectedIdDrag and selectedIdDrop
559565 htmlList . forEach ( ( el , i ) => {
560566 if ( el . id === selectedIdDrag ) {
561567 indexDrag = i ;
562568 } else if ( el . id === selectedIdDrop ) {
563569 indexDrop = i ;
564570 }
565571 } )
566-
572+ //use the indexes to delete the dragged element and place them into the new location
567573 const draggedEl = htmlList . splice ( indexDrag , 1 ) [ 0 ]
568574 htmlList . splice ( indexDrop , 0 , draggedEl )
569575 state . selectedElementList = htmlList ;
570576 }
577+ //reset the ids
571578 state . selectedIdDrag = '' ;
572579 state . selectedIdDrop = '' ;
573580 } ,
0 commit comments