@@ -47,10 +47,11 @@ function MultiDragPlugin() {
47
47
}
48
48
49
49
if ( sortable . options . group ) {
50
- if ( multiDragGroupMembers [ sortable . options . group . name ] === undefined ) {
51
- multiDragGroupMembers [ sortable . options . group . name ] = [ ] ;
50
+ const group = typeof sortable . options . group === 'string' ? { name : sortable . options . group } : sortable . options . group ;
51
+ if ( multiDragGroupMembers [ group . name ] === undefined ) {
52
+ multiDragGroupMembers [ group . name ] = [ ] ;
52
53
}
53
- multiDragGroupMembers [ sortable . options . group . name ] . push ( sortable ) ;
54
+ multiDragGroupMembers [ group . name ] . push ( sortable ) ;
54
55
}
55
56
56
57
on ( document , 'keydown' , this . _checkKeyDown ) ;
@@ -145,7 +146,7 @@ function MultiDragPlugin() {
145
146
146
147
dragStartGlobal ( { sortable } ) {
147
148
if ( ! this . isMultiDrag && multiDragSortable ) {
148
- multiDragSortable . multiDrag . _deselectMultiDrag ( ) ;
149
+ MultiDrag . utils . clear ( ) ;
149
150
}
150
151
151
152
multiDragElements . forEach ( multiDragElement => {
@@ -356,7 +357,7 @@ function MultiDragPlugin() {
356
357
// Multi-drag selection
357
358
if ( ! dragStarted ) {
358
359
if ( options . multiDragKey && ! this . multiDragKeyDown ) {
359
- this . _deselectMultiDrag ( ) ;
360
+ MultiDrag . utils . clear ( ) ;
360
361
}
361
362
toggleClass ( dragEl , options . selectedClass , ! ~ multiDragElements . indexOf ( dragEl ) ) ;
362
363
@@ -506,7 +507,8 @@ function MultiDragPlugin() {
506
507
} ,
507
508
508
509
destroyGlobal ( ) {
509
- this . _deselectMultiDrag ( ) ;
510
+ MultiDrag . utils . clear ( ) ;
511
+
510
512
off ( document , 'pointerup' , this . _deselectMultiDrag ) ;
511
513
off ( document , 'mouseup' , this . _deselectMultiDrag ) ;
512
514
off ( document , 'touchend' , this . _deselectMultiDrag ) ;
@@ -525,31 +527,18 @@ function MultiDragPlugin() {
525
527
} ,
526
528
527
529
_deselectMultiDrag ( evt ) {
528
- if ( typeof dragStarted !== "undefined" && dragStarted ) return ;
529
-
530
530
// Only deselect if selection is in this sortable
531
531
if ( multiDragSortable !== this . sortable ) return ;
532
532
533
- const groupSortables = findAllMembersInSortableGroup ( this . sortable ) || [ this . sortable ] ;
534
-
535
- // Only deselect if target is not item in any sortable in group (including this)
536
- if ( evt && ~ groupSortables . findIndex ( ( sortable ) => closest ( evt . target , this . options . draggable , sortable . el , false ) ) ) return ;
537
-
538
- // Only deselect if left click
539
- if ( evt && evt . button !== 0 ) return ;
533
+ if ( evt ) {
534
+ // Only deselect if left click
535
+ if ( evt . button !== 0 ) return ;
540
536
541
- while ( multiDragElements . length ) {
542
- let el = multiDragElements [ 0 ] ;
543
- toggleClass ( el , this . options . selectedClass , false ) ;
544
- multiDragElements . shift ( ) ;
545
- dispatchEvent ( {
546
- sortable : this . sortable ,
547
- rootEl : this . sortable . el ,
548
- name : 'deselect' ,
549
- targetEl : el ,
550
- originalEvent : evt
551
- } ) ;
537
+ // Only deselect if target is not item in any sortable in group (including this)
538
+ if ( itemElIsInSortableGroup ( evt . target , this . sortable ) ) return ;
552
539
}
540
+
541
+ MultiDrag . utils . clear ( evt ) ;
553
542
} ,
554
543
555
544
_checkKeyDown ( evt ) {
@@ -577,7 +566,9 @@ function MultiDragPlugin() {
577
566
let sortable = el . parentNode [ expando ] ;
578
567
if ( ! sortable || ! sortable . options . multiDrag || ~ multiDragElements . indexOf ( el ) ) return ;
579
568
if ( multiDragSortable && multiDragSortable !== sortable ) {
580
- multiDragSortable . multiDrag . _deselectMultiDrag ( ) ;
569
+ if ( ! itemElIsInSortableGroup ( el , multiDragSortable ) ) {
570
+ MultiDrag . utils . clear ( ) ;
571
+ }
581
572
multiDragSortable = sortable ;
582
573
}
583
574
toggleClass ( el , sortable . options . selectedClass , true ) ;
@@ -593,6 +584,24 @@ function MultiDragPlugin() {
593
584
if ( ! sortable || ! sortable . options . multiDrag || ! ~ index ) return ;
594
585
toggleClass ( el , sortable . options . selectedClass , false ) ;
595
586
multiDragElements . splice ( index , 1 ) ;
587
+ } ,
588
+ clear ( evt ) {
589
+ if ( typeof dragStarted !== "undefined" && dragStarted ) return ;
590
+
591
+ while ( multiDragElements . length ) {
592
+ const el = multiDragElements [ 0 ] ;
593
+ const sortableEl = getParentOrHost ( el ) ;
594
+ const sortable = sortableEl [ expando ] ;
595
+ toggleClass ( el , sortable . options . selectedClass , false ) ;
596
+ multiDragElements . shift ( ) ;
597
+ dispatchEvent ( {
598
+ sortable : sortable ,
599
+ rootEl : sortableEl ,
600
+ name : 'deselect' ,
601
+ targetEl : el ,
602
+ originalEvent : evt
603
+ } ) ;
604
+ }
596
605
}
597
606
} ,
598
607
eventProperties ( ) {
@@ -684,4 +693,8 @@ function findAllMembersInSortableGroup(sortable) {
684
693
return multiDragGroupMembers [ sortable . options . group . name ] || [ ] ;
685
694
}
686
695
696
+ function itemElIsInSortableGroup ( itemEl , sortable ) {
697
+ return ~ ( findAllMembersInSortableGroup ( sortable ) || [ sortable ] ) . findIndex ( ( sortable ) => closest ( itemEl , sortable . options . draggable , sortable . el , false ) ) ;
698
+ }
699
+
687
700
export default MultiDragPlugin ;
0 commit comments