Skip to content

Commit 4b75f0b

Browse files
feat(useDraggable): add current drag value
1 parent 3456a76 commit 4b75f0b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/useDraggable.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ function tryOnMounted(fn: Fn) {
5353

5454
const CLONE_ELEMENT_KEY = Symbol('cloneElement')
5555

56-
interface DraggableEvent extends SortableEvent {
56+
interface DraggableEvent<T = any> extends SortableEvent {
5757
item: HTMLElement & { [CLONE_ELEMENT_KEY]: any }
58+
data: T
59+
clonedData: T
5860
}
5961
type SortableMethod = 'closest' | 'save' | 'toArray' | 'destroy' | 'option'
6062

@@ -131,7 +133,11 @@ export function useDraggable<T>(...args: any[]): UseDraggableReturn {
131133
* @param {DraggableEvent} evt - DraggableEvent
132134
*/
133135
function onStart(evt: DraggableEvent) {
134-
evt.item[CLONE_ELEMENT_KEY] = clone(unref(unref(list)?.[evt.oldIndex!]))
136+
const data = unref(unref(list)?.[evt.oldIndex!])
137+
const clonedData = clone(data)
138+
evt.data = data
139+
evt.clonedData = clonedData
140+
evt.item[CLONE_ELEMENT_KEY] = clonedData
135141
}
136142

137143
/**

0 commit comments

Comments
 (0)