1111 * or the moving element by using data-dnd-dragging:... as Tailwind classes.
1212 */
1313
14+ import { Feedback , type FeedbackType } from "@dnd-kit/dom" ;
1415import type { DragDropEventHandlers } from "@dnd-kit/svelte" ;
1516import { createSortable as _createSortable , isSortable , type CreateSortableInput } from "@dnd-kit/svelte/sortable" ;
1617
17- export function createSortable ( input : CreateSortableInput ) {
18- return _createSortable ( { feedback : "clone" , ...input } ) ;
18+ export function createSortable ( input : CreateSortableInput , feedback : FeedbackType = "clone" ) {
19+ return _createSortable ( {
20+ ...input ,
21+ plugins : ( defaults ) => [ ...defaults , Feedback . configure ( { feedback } ) ]
22+ } ) ;
1923}
2024
2125type OnMove = ( oldIdx : number , newIdx : number ) => void ;
@@ -30,9 +34,9 @@ type DndEventHandlerParam = Pick<Parameters<DndEventHandler>[0], "operation">;
3034 *
3135 * ```svelte
3236 * <DragDropProvider
33- * onDragMove ={handleDrag(dndItems)}
37+ * onDragOver ={handleDrag(dndItems)}
3438 * onDragEnd={handleDrag(
35- * (oldIdx, newIdx ) => order = move( dndItems, oldIdx, newIdx) ,
39+ * () => order = dndItems,
3640 * { delay: 300 }
3741 * )}
3842 * >
@@ -66,12 +70,9 @@ export function handleDrag(
6670
6771 // Actual event handler, which finds the indexes and performs the move on the indices.
6872 return ( e : DndEventHandlerParam ) => {
69- const { source, canceled } = e . operation ;
70- if ( ! canceled && isSortable ( source ) ) {
71- const oldIdx = source . sortable . initialIndex ;
72- const newIdx = source . sortable . index ;
73-
74- callback ( oldIdx , newIdx ) ;
73+ const { source, target, canceled } = e . operation ;
74+ if ( ! canceled && isSortable ( source ) && isSortable ( target ) ) {
75+ callback ( source . index , target . index ) ;
7576 }
7677 } ;
7778}
0 commit comments