@scalar/draggable
Advanced tools
Comparing version 0.1.6 to 0.1.7
# @scalar/draggable | ||
## 0.1.7 | ||
### Patch Changes | ||
- a40999d: chore: added type safety rule noUncheckedIndexedAccess | ||
## 0.1.6 | ||
@@ -4,0 +10,0 @@ |
@@ -37,4 +37,10 @@ import { type DraggingItem, type HoveredItem } from './store'; | ||
declare function __VLS_template(): { | ||
default?(_: {}): any; | ||
attrs: Partial<{}>; | ||
slots: { | ||
default?(_: {}): any; | ||
}; | ||
refs: {}; | ||
rootEl: HTMLDivElement; | ||
}; | ||
type __VLS_TemplateResult = ReturnType<typeof __VLS_template>; | ||
declare const __VLS_component: import("vue").DefineComponent<DraggableProps, { | ||
@@ -68,6 +74,5 @@ draggingItem: import("vue").Ref<{ | ||
isDroppable: boolean | ((draggingItem: DraggingItem, hoveredItem: HoveredItem) => boolean); | ||
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>; | ||
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>; | ||
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, HTMLDivElement>; | ||
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>; | ||
export default _default; | ||
type __VLS_WithTemplateSlots<T, S> = T & { | ||
@@ -74,0 +79,0 @@ new (): { |
import { ref as b, defineComponent as S, computed as v, openBlock as T, createElementBlock as Y, normalizeClass as w, withModifiers as m, unref as D, renderSlot as B } from "vue"; | ||
const r = b(null), o = b(null), C = (s, d) => { | ||
let n = !1; | ||
const r = b(null), n = b(null), C = (s, d) => { | ||
let o = !1; | ||
return function(...t) { | ||
n || (s(...t), n = !0, setTimeout(() => n = !1, d)); | ||
o || (s(...t), o = !0, setTimeout(() => o = !1, d)); | ||
}; | ||
@@ -18,6 +18,4 @@ }, L = ["draggable"], k = /* @__PURE__ */ S({ | ||
emits: ["onDragEnd", "onDragStart"], | ||
setup(s, { expose: d, emit: n }) { | ||
const t = s, f = n, u = v( | ||
() => (t.parentIds.length ?? 0) > 0 ? t.parentIds[t.parentIds.length - 1] : null | ||
), I = (e) => { | ||
setup(s, { expose: d, emit: o }) { | ||
const t = s, f = o, u = v(() => t.parentIds.at(-1) ?? null), I = (e) => { | ||
!e.dataTransfer || !(e.target instanceof HTMLElement) || !t.isDraggable || (e.target.classList.add("dragging"), e.dataTransfer.dropEffect = "move", e.dataTransfer.effectAllowed = "move", r.value = { id: t.id, parentId: u.value }, f("onDragStart", { id: t.id, parentId: u.value })); | ||
@@ -28,19 +26,19 @@ }, _ = (e) => typeof t.isDroppable == "function" ? t.isDroppable(r.value, { | ||
offset: e | ||
}) : t.isDroppable, g = C((e) => { | ||
}) : t.isDroppable, c = C((e) => { | ||
if (!r.value || r.value.id === t.id || t.parentIds.includes(r.value?.id ?? "")) | ||
return; | ||
const a = o.value?.offset, l = e.target.offsetHeight, c = t.floor * l, p = t.ceiling * l; | ||
const a = n.value?.offset, l = e.target.offsetHeight, g = t.floor * l, p = t.ceiling * l; | ||
let i = 3; | ||
e.offsetY <= 0 && a && a !== 3 ? i = a : e.offsetY <= c ? i = 0 : e.offsetY >= p ? i = 1 : e.offsetY > c && e.offsetY < p && (i = 2), _(i) && (o.value = { id: t.id, parentId: u.value, offset: i }); | ||
e.offsetY <= 0 && a && a !== 3 ? i = a : e.offsetY <= g ? i = 0 : e.offsetY >= p ? i = 1 : e.offsetY > g && e.offsetY < p && (i = 2), _(i) && (n.value = { id: t.id, parentId: u.value, offset: i }); | ||
}, 25), h = ["above", "below", "asChild"], E = v(() => { | ||
let e = "sidebar-indent-nested"; | ||
return t.id === o.value?.id && (e += ` dragover-${h[o.value.offset]}`), e; | ||
return t.id === n.value?.id && (e += ` dragover-${h[n.value.offset]}`), e; | ||
}), y = () => { | ||
if (!o.value || !r.value) return; | ||
const e = { ...r.value }, a = { ...o.value }; | ||
r.value = null, o.value = null, document.querySelectorAll("div.dragging").forEach((l) => l.classList.remove("dragging")), e.id !== a.id && f("onDragEnd", e, a); | ||
if (!n.value || !r.value) return; | ||
const e = { ...r.value }, a = { ...n.value }; | ||
r.value = null, n.value = null, document.querySelectorAll("div.dragging").forEach((l) => l.classList.remove("dragging")), e.id !== a.id && f("onDragEnd", e, a); | ||
}; | ||
return d({ | ||
draggingItem: r, | ||
hoveredItem: o | ||
hoveredItem: n | ||
}), (e, a) => (T(), Y("div", { | ||
@@ -52,3 +50,3 @@ class: w(E.value), | ||
//@ts-ignore | ||
(...l) => D(g) && D(g)(...l), | ||
(...l) => D(c) && D(c)(...l), | ||
["prevent", "stop"] | ||
@@ -62,9 +60,9 @@ )), | ||
}), O = (s, d) => { | ||
const n = s.__vccOpts || s; | ||
const o = s.__vccOpts || s; | ||
for (const [t, f] of d) | ||
n[t] = f; | ||
return n; | ||
}, A = /* @__PURE__ */ O(k, [["__scopeId", "data-v-1c55d212"]]); | ||
o[t] = f; | ||
return o; | ||
}, A = /* @__PURE__ */ O(k, [["__scopeId", "data-v-1c336fff"]]); | ||
export { | ||
A as Draggable | ||
}; |
@@ -16,3 +16,3 @@ { | ||
], | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"engines": { | ||
@@ -41,3 +41,3 @@ "node": ">=18" | ||
"@vitejs/plugin-vue": "^5.0.4", | ||
"vite": "^5.2.10", | ||
"vite": "^5.4.9", | ||
"vite-plugin-dts": "^3.6.3", | ||
@@ -44,0 +44,0 @@ "vite-svg-loader": "^5.1.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
204
17774