File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -338,12 +338,20 @@ class NestedSort {
338
338
let depth = 0
339
339
const list = this . getSortableList ( )
340
340
341
+ let selfDepth = 0
342
+ if ( this . draggedNode ) {
343
+ // the dragged node might be a nested list contributing to the final nesting levels
344
+ const depthUL = this . draggedNode . querySelectorAll ( 'ul' ) . length || 0
345
+ const depthOL = this . draggedNode . querySelectorAll ( 'ol' ) . length || 0
346
+ selfDepth = depthUL > depthOL ? depthUL : depthOL
347
+ }
348
+
341
349
while ( list !== el ?. parentElement ) {
342
350
if ( el ?. parentElement instanceof this . listInterface ) depth ++
343
351
el = el ?. parentElement as HTMLElement
344
352
}
345
353
346
- return depth
354
+ return depth + selfDepth
347
355
}
348
356
349
357
nestingThresholdReached ( el : HTMLElement , isPlaceHolderCheck = false ) : boolean {
Original file line number Diff line number Diff line change @@ -1193,6 +1193,26 @@ describe('NestedSort', () => {
1193
1193
expect ( depth ) . toBe ( id . toString ( ) . split ( '' ) . length - 1 )
1194
1194
} )
1195
1195
} )
1196
+
1197
+ it ( 'should take the depth of the dragged node into account' , ( ) => {
1198
+ const ns = initDataDrivenList ( {
1199
+ data : [
1200
+ { id : 1 , text : '1' } ,
1201
+ { id : 11 , text : '1-1' , parent : 1 } ,
1202
+ { id : 111 , text : '1-1-1' , parent : 11 } ,
1203
+ { id : 1111 , text : '1-1-1-1' , parent : 111 } ,
1204
+ { id : 2 , text : '2' } ,
1205
+ { id : 22 , text : '2-2' , parent : 2 } ,
1206
+ ] ,
1207
+ } )
1208
+
1209
+ const node = document . querySelector ( '[data-id="1111"]' ) // has 3 levels of nesting
1210
+ ns . draggedNode = document . querySelector ( '[data-id="2"]' ) // has 1 level of nesting since it includes the item with ID of 22
1211
+
1212
+ const depth = ns . getNodeDepth ( node )
1213
+
1214
+ expect ( depth ) . toBe ( 4 )
1215
+ } )
1196
1216
} )
1197
1217
1198
1218
describe ( 'nestingThresholdReached method' , ( ) => {
You can’t perform that action at this time.
0 commit comments