@@ -11,28 +11,25 @@ import { isReadOnlyEvent } from "./core/sortableEvents";
11
11
12
12
import { h , defineComponent , nextTick , resolveComponent } from "vue" ;
13
13
14
- function computeVmIndex ( vnodes , element , mainNode ) {
15
- const index = vnodes . map ( ( { el } ) => el ) . indexOf ( element ) ;
14
+ function computeVmIndex ( vNodes , element ) {
15
+ const domElements = vNodes . map ( ( { el } ) => el ) ;
16
+ const index = domElements . indexOf ( element ) ;
16
17
if ( index === - 1 ) {
17
18
throw new Error ( "node not found" , {
18
- nodes : vnodes . map ( ( { el } ) => el ) ,
19
+ nodes : domElements ,
19
20
element,
20
- index,
21
- mainNode
22
21
} ) ;
23
22
}
24
23
return index ;
25
24
}
26
25
27
- function computeIndexes ( slots , children , isTransition , footerOffset ) {
28
- if ( ! slots ) {
29
- return [ ] ;
30
- }
31
-
32
- const elmFromNodes = slots . map ( ( { el } ) => el ) ;
33
- const footerIndex = children . length - footerOffset ;
34
- const rawIndexes = [ ...children ] . map ( ( elt , idx ) =>
35
- idx >= footerIndex ? elmFromNodes . length : elmFromNodes . indexOf ( elt )
26
+ function computeIndexes ( vNodes , domChildren , isTransition , footerOffset ) {
27
+ const domChildrenFromNodes = vNodes . map ( ( { el } ) => el ) ;
28
+ const footerIndex = domChildren . length - footerOffset ;
29
+ const rawIndexes = [ ...domChildren ] . map ( ( elt , idx ) =>
30
+ idx >= footerIndex
31
+ ? domChildrenFromNodes . length
32
+ : domChildrenFromNodes . indexOf ( elt )
36
33
) ;
37
34
return isTransition ? rawIndexes . filter ( ind => ind !== - 1 ) : rawIndexes ;
38
35
}
@@ -281,11 +278,7 @@ const draggableComponent = defineComponent({
281
278
} ,
282
279
283
280
getUnderlyingVm ( htmlElt ) {
284
- const index = computeVmIndex (
285
- this . getChildrenNodes ( ) || [ ] ,
286
- htmlElt ,
287
- this . mainNode
288
- ) ;
281
+ const index = computeVmIndex ( this . getChildrenNodes ( ) || [ ] , htmlElt ) ;
289
282
if ( index === - 1 ) {
290
283
//Edge case during move callback: related element might be
291
284
//an element different from collection
@@ -343,7 +336,7 @@ const draggableComponent = defineComponent({
343
336
return context ;
344
337
} ,
345
338
346
- getVmIndex ( domIndex ) {
339
+ getVmIndexFromDomIndex ( domIndex ) {
347
340
const indexes = this . visibleIndexes ;
348
341
const numberIndexes = indexes . length ;
349
342
return domIndex > numberIndexes - 1 ? numberIndexes : indexes [ domIndex ] ;
@@ -365,7 +358,7 @@ const draggableComponent = defineComponent({
365
358
return ;
366
359
}
367
360
removeNode ( evt . item ) ;
368
- const newIndex = this . getVmIndex ( evt . newIndex ) ;
361
+ const newIndex = this . getVmIndexFromDomIndex ( evt . newIndex ) ;
369
362
this . spliceList ( newIndex , 0 , element ) ;
370
363
this . computeIndexes ( ) ;
371
364
const added = { element, newIndex } ;
@@ -388,7 +381,7 @@ const draggableComponent = defineComponent({
388
381
removeNode ( evt . item ) ;
389
382
insertNodeAt ( evt . from , evt . item , evt . oldIndex ) ;
390
383
const oldIndex = this . context . index ;
391
- const newIndex = this . getVmIndex ( evt . newIndex ) ;
384
+ const newIndex = this . getVmIndexFromDomIndex ( evt . newIndex ) ;
392
385
this . updatePosition ( oldIndex , newIndex ) ;
393
386
const moved = { element : this . context . element , oldIndex, newIndex } ;
394
387
this . emitChanges ( { moved } ) ;
@@ -401,8 +394,10 @@ const draggableComponent = defineComponent({
401
394
const domChildren = [ ...evt . to . children ] . filter (
402
395
el => el . style [ "display" ] !== "none"
403
396
) ;
404
- const currentDOMIndex = domChildren . indexOf ( evt . related ) ;
405
- const currentIndex = relatedContext . component . getVmIndex ( currentDOMIndex ) ;
397
+ const currentDomIndex = domChildren . indexOf ( evt . related ) ;
398
+ const currentIndex = relatedContext . component . getVmIndexFromDomIndex (
399
+ currentDomIndex
400
+ ) ;
406
401
const draggedInList = domChildren . indexOf ( draggingElement ) !== - 1 ;
407
402
return draggedInList || ! evt . willInsertAfter
408
403
? currentIndex
0 commit comments