@@ -13,6 +13,12 @@ import DFlexScrollableElement from "./DFlexScrollableElement";
13
13
export function isIDEligible ( elmID : string , draggedID : string ) : boolean {
14
14
const { registry } = store ;
15
15
16
+ if ( __DEV__ ) {
17
+ if ( ! elmID ) {
18
+ throw new Error ( "isIDEligible: received undefined elmID" ) ;
19
+ }
20
+ }
21
+
16
22
return (
17
23
elmID . length > 0 &&
18
24
elmID !== draggedID &&
@@ -21,6 +27,23 @@ export function isIDEligible(elmID: string, draggedID: string): boolean {
21
27
) ;
22
28
}
23
29
30
+ // eslint-disable-next-line no-unused-vars
31
+ type ForEachSiblingsCB = ( elmID : string , index : number ) => boolean ;
32
+
33
+ function forEachDraggedSiblings ( cb : ForEachSiblingsCB ) {
34
+ const { SK } = store . migration . latest ( ) ;
35
+
36
+ const siblings = store . getElmSiblingsByKey ( SK ) ;
37
+
38
+ for ( let i = 0 ; i < siblings . length ; i += 1 ) {
39
+ const id = siblings [ i ] ;
40
+
41
+ if ( cb ( id , i ) ) {
42
+ break ;
43
+ }
44
+ }
45
+ }
46
+
24
47
class DFlexMechanismController extends DFlexScrollableElement {
25
48
private isOnDragOutThresholdEvtEmitted : boolean ;
26
49
@@ -71,27 +94,27 @@ class DFlexMechanismController extends DFlexScrollableElement {
71
94
72
95
const { draggedElm } = this . draggable ;
73
96
74
- const { SK } = store . migration . latest ( ) ;
75
-
76
- const siblings = store . getElmSiblingsByKey ( SK ) ;
97
+ forEachDraggedSiblings ( ( id , i ) => {
98
+ if ( ! isIDEligible ( id , draggedElm . id ) ) {
99
+ return false ;
100
+ }
77
101
78
- for ( let i = 0 ; i < siblings . length ; i += 1 ) {
79
- const id = siblings [ i ] ;
102
+ let isQualified = false ;
80
103
81
- if ( isIDEligible ( id , draggedElm . id ) ) {
82
- const element = store . registry . get ( id ) ! ;
104
+ const dflexElm = store . registry . get ( id ) ! ;
83
105
84
- const isQualified = element . rect . isIntersect (
85
- this . draggable . getAbsoluteCurrentPosition ( )
86
- ) ;
106
+ isQualified = dflexElm . rect . isIntersect (
107
+ this . draggable . getAbsoluteCurrentPosition ( )
108
+ ) ;
87
109
88
- if ( isQualified ) {
89
- droppableIndex = i ;
110
+ if ( isQualified ) {
111
+ droppableIndex = i ;
90
112
91
- break ;
92
- }
113
+ return true ;
93
114
}
94
- }
115
+
116
+ return false ;
117
+ } ) ;
95
118
96
119
return droppableIndex ;
97
120
}
@@ -109,7 +132,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
109
132
* If tempIndex is zero, the dragged is coming from the top. So, move them
110
133
* down all: to=0
111
134
*/
112
- let hasToMoveSiblingsDown = true ;
135
+ let hasToShiftSiblings = true ;
113
136
114
137
const isEmpty = isEmptyBranch ( siblings ) ;
115
138
@@ -129,7 +152,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
129
152
130
153
insertAt = siblings . length - 1 ;
131
154
132
- hasToMoveSiblingsDown = false ;
155
+ hasToShiftSiblings = false ;
133
156
}
134
157
135
158
this . draggable . setDraggedTempIndex ( insertAt ) ;
@@ -144,15 +167,15 @@ class DFlexMechanismController extends DFlexScrollableElement {
144
167
this . getComposedOccupiedTranslateAndGrid (
145
168
SK ,
146
169
insertAt ,
147
- hasToMoveSiblingsDown ,
170
+ hasToShiftSiblings ,
148
171
"y"
149
172
) ) ;
150
173
}
151
174
152
175
// If it has solo empty id then there's no need to move down. Because it's
153
176
// empty branch.
154
- if ( hasToMoveSiblingsDown && ! isEmpty ) {
155
- this . _moveDown ( insertAt ) ;
177
+ if ( hasToShiftSiblings && ! isEmpty ) {
178
+ this . _shiftSiblings ( insertAt ) ;
156
179
}
157
180
158
181
draggedElm . removeAttribute ( this . draggable . draggedDOM , "OUT_CONTAINER" ) ;
@@ -372,7 +395,7 @@ class DFlexMechanismController extends DFlexScrollableElement {
372
395
*
373
396
* @param to - index
374
397
*/
375
- private _moveDown ( to : number ) : void {
398
+ private _shiftSiblings ( to : number ) : void {
376
399
const { events, draggedElm } = this . draggable ;
377
400
const { migration } = store ;
378
401
0 commit comments