@@ -256,14 +256,16 @@ const draggableComponent = defineComponent({
256
256
updatePositions ( oldIndicies , newIndex ) {
257
257
/** @type {<T = any>(list: T[]) => T[] } */
258
258
const updatePosition = list => {
259
- // get selected items with correct order
260
- // sort -> reverse (for prevent Array.splice side effect) -> splice -> reverse
259
+ // Get selected items in the correct order
261
260
const items = oldIndicies
262
- . sort ( )
263
- . reverse ( )
264
- . flatMap ( oldIndex => list . splice ( oldIndex , 1 ) )
265
- . reverse ( ) ;
266
- return list . splice ( newIndex , 0 , ...items ) ;
261
+ . sort ( ( a , b ) => b - a ) // Sort in descending order
262
+ . map ( oldIndex => list . splice ( oldIndex , 1 ) [ 0 ] )
263
+ . reverse ( ) ; // Remove the items
264
+
265
+ // Insert the items at the new index
266
+ list . splice ( newIndex , 0 , ...items ) ;
267
+
268
+ return list ; // Return the updated list
267
269
} ;
268
270
this . alterList ( updatePosition ) ;
269
271
} ,
@@ -318,7 +320,7 @@ const draggableComponent = defineComponent({
318
320
// remove nodes
319
321
evt . items . forEach ( e => removeNode ( e ) ) ;
320
322
// insert elements
321
- const newIndex = this . getVmIndexFromDomIndex ( evt . newIndex ) ;
323
+ const newIndex = this . getVmIndexFromDomIndex ( evt . newIndicies [ 0 ] . index ) ;
322
324
this . spliceList ( newIndex , 0 , ...elements ) ;
323
325
// emit change
324
326
const added = elements . map ( ( element , index ) => ( {
@@ -441,7 +443,7 @@ const draggableComponent = defineComponent({
441
443
) ;
442
444
// move items
443
445
const oldIndicies = itemsWithIndex . map ( ( { index } ) => index - headerSize ) ;
444
- const newIndex = this . getVmIndexFromDomIndex ( evt . newIndex ) ;
446
+ const newIndex = this . getVmIndexFromDomIndex ( evt . newIndicies [ 0 ] . index ) ;
445
447
// note: Array.from = prevent sort change side effect
446
448
this . updatePositions ( Array . from ( oldIndicies ) , newIndex ) ;
447
449
// emit change
0 commit comments