@@ -330,7 +330,7 @@ const mutations = {
330
330
}
331
331
}
332
332
}
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
334
334
for ( const item of Object . values ( state . componentMap ) ) {
335
335
if ( item . htmlList ) {
336
336
const newArray = [ ...item . htmlList ] ;
@@ -495,25 +495,26 @@ const mutations = {
495
495
}
496
496
state . activeHTML = "" ;
497
497
} ,
498
-
498
+ //Drag-andDrop
499
+ //store id of dragged html element in activeComponent
499
500
[ types . SET_ID_DRAG ] : ( state , payload ) => {
500
501
const componentName = state . activeComponent ;
501
502
state . componentMap [ componentName ] . idDrag = payload ;
502
503
} ,
503
-
504
+ //store id of html element whose place the dragged html element is dropped on in activeComponent
504
505
[ types . SET_ID_DROP ] : ( state , payload ) => {
505
506
const componentName = state . activeComponent ;
506
507
state . componentMap [ componentName ] . idDrop = payload ;
507
508
} ,
508
-
509
+ //store id of dragged selected html element when creating a component
509
510
[ types . SET_SELECTED_ID_DRAG ] : ( state , payload ) => {
510
511
state . selectedIdDrag = payload ;
511
512
} ,
512
-
513
+ //store id of html element whose place the dragged selected html element will be dropped when creating a component
513
514
[ types . SET_SELECTED_ID_DROP ] : ( state , payload ) => {
514
515
state . selectedIdDrop = payload ;
515
516
} ,
516
-
517
+ // use idDrag and idDrop to rearrange the htmlList of the activeComponent to perform drag-and-drop functionality
517
518
[ types . DRAG_DROP_SORT_HTML_ELEMENTS ] : ( state ) => {
518
519
const componentName = state . activeComponent ;
519
520
const idDrag = state . componentMap [ componentName ] . idDrag ;
@@ -525,27 +526,32 @@ const mutations = {
525
526
const htmlList = state . componentMap [ componentName ] . htmlList . slice ( 0 )
526
527
527
528
if ( state . activeLayer . id === "" ) {
529
+ //find the indexes belonging to the html elements with idDrag and idDrop
528
530
htmlList . forEach ( ( el , i ) => {
529
531
if ( el . id === idDrag ) {
530
532
indexDrag = i ;
531
533
} else if ( el . id === idDrop ) {
532
534
indexDrop = i ;
533
535
}
534
536
} )
537
+ //use the indexes to rearrange htmlList
535
538
const draggedEl = htmlList . splice ( indexDrag , 1 ) [ 0 ]
536
539
htmlList . splice ( indexDrop , 0 , draggedEl )
537
540
} else {
541
+ //Use breadFirstSearchParent to find the parent and indexes of nested html elements with idDrag and idDrop
538
542
const nestedDrag = breadthFirstSearchParent ( htmlList , idDrag ) ;
539
543
const nestedDrop = breadthFirstSearchParent ( htmlList , idDrop ) ;
544
+ //use the indexes and parents to rearrange htmlList
540
545
let nestedEl = nestedDrag . evaluated . children . splice ( nestedDrag . index , 1 ) [ 0 ]
541
546
nestedDrop . evaluated . children . splice ( nestedDrop . index , 0 , nestedEl )
542
547
}
543
548
state . componentMap [ componentName ] . htmlList = htmlList ;
544
549
}
550
+ //reset the ids
545
551
state . componentMap [ componentName ] . idDrag = '' ;
546
552
state . componentMap [ componentName ] . idDrop = '' ;
547
553
} ,
548
-
554
+ // use selectedIdDrag and selectedIdDrop to rearrange the selectedElementList to perform drag-and-drop functionality
549
555
[ types . DRAG_DROP_SORT_SELECTED_HTML_ELEMENTS ] : ( state ) => {
550
556
const selectedIdDrag = state . selectedIdDrag ;
551
557
const selectedIdDrop = state . selectedIdDrop ;
@@ -555,19 +561,20 @@ const mutations = {
555
561
556
562
let indexDrag ;
557
563
let indexDrop ;
558
-
564
+ //find the indexes belonging to the html elements with the selectedIdDrag and selectedIdDrop
559
565
htmlList . forEach ( ( el , i ) => {
560
566
if ( el . id === selectedIdDrag ) {
561
567
indexDrag = i ;
562
568
} else if ( el . id === selectedIdDrop ) {
563
569
indexDrop = i ;
564
570
}
565
571
} )
566
-
572
+ //use the indexes to delete the dragged element and place them into the new location
567
573
const draggedEl = htmlList . splice ( indexDrag , 1 ) [ 0 ]
568
574
htmlList . splice ( indexDrop , 0 , draggedEl )
569
575
state . selectedElementList = htmlList ;
570
576
}
577
+ //reset the ids
571
578
state . selectedIdDrag = '' ;
572
579
state . selectedIdDrop = '' ;
573
580
} ,
0 commit comments