@scalar/draggable
Advanced tools
Comparing version 0.0.6 to 0.0.7
# @scalar/draggable | ||
## 0.0.7 | ||
### Patch Changes | ||
- 453b297: fix: drag and dropping of draggable | ||
## 0.0.6 | ||
@@ -4,0 +10,0 @@ |
@@ -1,8 +0,8 @@ | ||
import { ref as v, defineComponent as E, computed as p, openBlock as S, createElementBlock as T, normalizeClass as Y, withModifiers as c, unref as w, renderSlot as B } from "vue"; | ||
const o = v(null), n = v(null), C = (i, d) => { | ||
import { ref as D, defineComponent as _, computed as p, openBlock as S, createElementBlock as T, normalizeClass as Y, withModifiers as v, unref as m, renderSlot as w } from "vue"; | ||
const o = D(null), r = D(null), B = (i, d) => { | ||
let t = !1; | ||
return function(...s) { | ||
t || (i(...s), t = !0, setTimeout(() => t = !1, d)); | ||
return function(...l) { | ||
t || (i(...l), t = !0, setTimeout(() => t = !1, d)); | ||
}; | ||
}, L = ["draggable"], y = /* @__PURE__ */ E({ | ||
}, C = ["draggable"], y = /* @__PURE__ */ _({ | ||
__name: "Draggable", | ||
@@ -19,30 +19,34 @@ props: { | ||
setup(i, { emit: d }) { | ||
const t = i, s = d, f = p( | ||
const t = i, l = d, f = p( | ||
() => (t.parentIds.length ?? 0) > 0 ? t.parentIds[t.parentIds.length - 1] : null | ||
), m = (e) => { | ||
!e.dataTransfer || !(e.target instanceof HTMLDivElement) || (e.target.classList.add("dragging"), e.dataTransfer.dropEffect = "move", e.dataTransfer.effectAllowed = "move", o.value = { id: t.id, parentId: f.value }, s("onDragStart", { id: t.id, parentId: f.value })); | ||
}, D = C((e) => { | ||
if (o.value?.id === t.id || t.parentIds.includes(o.value?.id ?? "")) | ||
), b = (e) => { | ||
!e.dataTransfer || !(e.target instanceof HTMLDivElement) || !t.isDraggable || (e.target.classList.add("dragging"), e.dataTransfer.dropEffect = "move", e.dataTransfer.effectAllowed = "move", o.value = { id: t.id, parentId: f.value }, l("onDragStart", { id: t.id, parentId: f.value })); | ||
}, g = B((e) => { | ||
if (o.value?.id === t.id || t.parentIds.includes(o.value?.id ?? "") || !t.isDroppable) | ||
return; | ||
const a = n.value?.offset, r = e.target.offsetHeight, g = t.floor * r, u = t.ceiling * r; | ||
let l = 3; | ||
e.offsetY <= 0 && a && a !== 3 ? l = a : e.offsetY <= g ? l = 0 : e.offsetY >= u ? l = 1 : e.offsetY > g && e.offsetY < u && (l = 2), n.value = { id: t.id, parentId: f.value, offset: l }; | ||
}, 25), b = ["above", "below", "asChild"], I = p(() => { | ||
const a = r.value?.offset, n = e.target.offsetHeight, u = t.floor * n, c = t.ceiling * n; | ||
let s = 3; | ||
e.offsetY <= 0 && a && a !== 3 ? s = a : e.offsetY <= u ? s = 0 : e.offsetY >= c ? s = 1 : e.offsetY > u && e.offsetY < c && (s = 2), r.value = { id: t.id, parentId: f.value, offset: s }; | ||
}, 25), I = ["above", "below", "asChild"], h = p(() => { | ||
let e = "sidebar-indent-nested"; | ||
return t.isDroppable && t.id === n.value?.id && (e += ` dragover-${b[n.value.offset]}`), e; | ||
}), h = () => { | ||
if (!n.value || !o.value) | ||
return t.isDroppable && t.id === r.value?.id && (e += ` dragover-${I[r.value.offset]}`), e; | ||
}), E = () => { | ||
if (!r.value || !o.value) | ||
return; | ||
const e = { ...o.value }, a = { ...n.value }; | ||
o.value = null, n.value = null, document.querySelectorAll("div.dragging").forEach((r) => r.classList.remove("dragging")), e.id !== a.id && s("onDragEnd", e, a); | ||
const e = { ...o.value }, a = { ...r.value }; | ||
o.value = null, r.value = null, document.querySelectorAll("div.dragging").forEach((n) => n.classList.remove("dragging")), e.id !== a.id && l("onDragEnd", e, a); | ||
}; | ||
return (e, a) => (S(), T("div", { | ||
class: Y(I.value), | ||
class: Y(h.value), | ||
draggable: e.isDraggable, | ||
onDragend: h, | ||
onDragover: a[0] || (a[0] = c((r) => e.isDroppable ? w(D) : () => null, ["prevent", "stop"])), | ||
onDragstart: a[1] || (a[1] = c((r) => e.isDraggable ? m : () => null, ["stop"])) | ||
onDragend: E, | ||
onDragover: a[0] || (a[0] = v( | ||
//@ts-ignore | ||
(...n) => m(g) && m(g)(...n), | ||
["prevent", "stop"] | ||
)), | ||
onDragstart: v(b, ["stop"]) | ||
}, [ | ||
B(e.$slots, "default") | ||
], 42, L)); | ||
w(e.$slots, "default") | ||
], 42, C)); | ||
} | ||
@@ -49,0 +53,0 @@ }); |
@@ -16,3 +16,3 @@ { | ||
], | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"engines": { | ||
@@ -19,0 +19,0 @@ "node": ">=18" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
16443
189