UNPKG

@vue-dnd-kit/core

Version:

Core functionality for Vue DnD Kit - a lightweight Vue 3 library for building performant and accessible drag and drop interfaces

788 lines (787 loc) 29.1 kB
var me = Object.defineProperty; var he = (n, e, t) => e in n ? me(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; var k = (n, e, t) => he(n, typeof e != "symbol" ? e + "" : e, t); import { ref as O, computed as T, shallowRef as D, onMounted as Q, onUnmounted as pe, defineComponent as de, createElementBlock as q, createCommentVNode as Ee, unref as y, openBlock as R, normalizeStyle as re, Fragment as ae, renderList as ye, createBlock as G, resolveDynamicComponent as J, Transition as we, withCtx as xe, createVNode as Me, render as le, useId as Pe, onBeforeUnmount as fe } from "vue"; import { createGlobalState as ge, useMagicKeys as Le, useThrottleFn as Ae } from "@vueuse/core"; const x = class x { }; k(x, "remove", (e, t) => { if (!e || t === void 0) return; const [r] = e.splice(t, 1); return r; }), k(x, "insert", (e, t, r) => { !e || t === void 0 || e.splice(t, 0, r); }), k(x, "move", (e, t, r, l) => { if (!e || !r || t === void 0 || l === void 0) return; const s = x.remove(e, t); x.insert(r, l, s); }), k(x, "swap", (e, t, r, l) => { if (!e || !r || t === void 0 || l === void 0) return; const s = e[t], o = r[l]; e[t] = o, r[l] = s; }), k(x, "copy", (e, t, r, l) => { if (!e || t === void 0 || !r || l === void 0) return; const s = e[t]; x.insert(r, l, s); }), k(x, "applyTransfer", (e) => { var l, s, o, g, i, u, d; const t = e.hovered.element.value, r = e.hovered.zone.value; if (t) { const v = (s = (l = e.elementsMap.value.get(t)) == null ? void 0 : l.data) == null ? void 0 : s.source, a = (g = (o = e.elementsMap.value.get(t)) == null ? void 0 : o.data) == null ? void 0 : g.index, c = e.draggingElements.value.values().next().value, f = (i = c == null ? void 0 : c.data) == null ? void 0 : i.index, m = f !== void 0 && a !== void 0 && f > a ? 1 : -1; Array.from( e.draggingElements.value.values() ).sort( (E, L) => { var M, I; return m * ((((M = E.data) == null ? void 0 : M.index) || 0) - (((I = L.data) == null ? void 0 : I.index) || 0)); } ).forEach( (E) => { var L, M; return x.move( (L = E.data) == null ? void 0 : L.source, (M = E.data) == null ? void 0 : M.index, v, a ); } ); } else if (r) { const v = (d = (u = e.zonesMap.value.get(r)) == null ? void 0 : u.data) == null ? void 0 : d.source, a = v == null ? void 0 : v.length; Array.from( e.draggingElements.value.values() ).sort((f, m) => { var p, E; return (((p = m.data) == null ? void 0 : p.index) || 0) - (((E = f.data) == null ? void 0 : E.index) || 0); }).forEach( (f) => { var m, p; return x.move( (m = f.data) == null ? void 0 : m.source, (p = f.data) == null ? void 0 : p.index, v, a ); } ); } }), k(x, "applyCopy", (e) => { var l, s, o, g, i, u; const t = e.hovered.element.value, r = e.hovered.zone.value; if (t) { const d = (s = (l = e.elementsMap.value.get(t)) == null ? void 0 : l.data) == null ? void 0 : s.source, v = (g = (o = e.elementsMap.value.get(t)) == null ? void 0 : o.data) == null ? void 0 : g.index; Array.from( e.draggingElements.value.values() ).sort((c, f) => { var m, p; return (((m = f.data) == null ? void 0 : m.index) || 0) - (((p = c.data) == null ? void 0 : p.index) || 0); }).forEach( (c) => { var f, m; return x.copy( (f = c.data) == null ? void 0 : f.source, (m = c.data) == null ? void 0 : m.index, d, v ); } ); } else if (r) { const d = (u = (i = e.zonesMap.value.get(r)) == null ? void 0 : i.data) == null ? void 0 : u.source, v = d == null ? void 0 : d.length; Array.from( e.draggingElements.value.values() ).sort((c, f) => { var m, p; return (((m = f.data) == null ? void 0 : m.index) || 0) - (((p = c.data) == null ? void 0 : p.index) || 0); }).forEach( (c) => { var f, m; return x.copy( (f = c.data) == null ? void 0 : f.source, (m = c.data) == null ? void 0 : m.index, d, v ); } ); } }), k(x, "applySwap", (e) => { var l, s, o, g, i, u, d, v; const t = e.hovered.element.value, r = e.hovered.zone.value; if (t && e.draggingElements.value.size === 1) { const a = e.draggingElements.value.values().next().value; x.swap( (l = a == null ? void 0 : a.data) == null ? void 0 : l.source, (s = a == null ? void 0 : a.data) == null ? void 0 : s.index, (g = (o = e.elementsMap.value.get(t)) == null ? void 0 : o.data) == null ? void 0 : g.source, (u = (i = e.elementsMap.value.get(t)) == null ? void 0 : i.data) == null ? void 0 : u.index ); } else if (r) { const a = (v = (d = e.zonesMap.value.get(r)) == null ? void 0 : d.data) == null ? void 0 : v.source, c = a == null ? void 0 : a.length; Array.from( e.draggingElements.value.values() ).sort((m, p) => { var E, L; return (((E = p.data) == null ? void 0 : E.index) || 0) - (((L = m.data) == null ? void 0 : L.index) || 0); }).forEach( (m) => { var p, E; return x.move( (p = m.data) == null ? void 0 : p.source, (E = m.data) == null ? void 0 : E.index, a, c ); } ); } }), k(x, "applyRemove", (e) => { Array.from( e.draggingElements.value.values() ).sort((r, l) => { var s, o; return (((s = l.data) == null ? void 0 : s.index) || 0) - (((o = r.data) == null ? void 0 : o.index) || 0); }).forEach((r) => { var l, s; (l = r.data) != null && l.source && ((s = r.data) == null ? void 0 : s.index) !== void 0 && x.remove(r.data.source, r.data.index); }); }), k(x, "applyInsert", (e, t) => { var s, o, g, i, u, d; const r = e.hovered.element.value, l = e.hovered.zone.value; if (r && t.length > 0) { const v = (o = (s = e.elementsMap.value.get(r)) == null ? void 0 : s.data) == null ? void 0 : o.source, a = (i = (g = e.elementsMap.value.get(r)) == null ? void 0 : g.data) == null ? void 0 : i.index; t.forEach((c) => { x.insert(v, a, c); }); } else if (l) { const v = (d = (u = e.zonesMap.value.get(l)) == null ? void 0 : u.data) == null ? void 0 : d.source, a = v == null ? void 0 : v.length; t.forEach((c) => { x.insert(v, a, c); }); } }); let se = x; const Z = ge(() => { const n = O( /* @__PURE__ */ new Map() ), e = T(() => n.value.size > 0), t = { component: O(null), ref: D(null), options: D(null), animating: { enter: D(!1), leave: D(!1), appear: D(!1) } }, r = O(/* @__PURE__ */ new Map()), l = O(/* @__PURE__ */ new Set()), s = O(/* @__PURE__ */ new Map()), o = O(/* @__PURE__ */ new Set()), g = O(/* @__PURE__ */ new Set()), i = new IntersectionObserver((K) => { K.forEach( (h) => g.value[h.isIntersecting ? "add" : "delete"]( h.target ) ); }), u = new IntersectionObserver((K) => { K.forEach( (h) => o.value[h.isIntersecting ? "add" : "delete"](h.target) ); }), d = (K, h) => { K === "add" ? i.observe(h) : (i.unobserve(h), g.value.delete(h)); }, v = (K, h) => { K === "add" ? u.observe(h) : (u.unobserve(h), o.value.delete(h)); }, a = { start: D(null), current: D(null), offset: { percent: D(null), pixel: D(null) } }, { w: c, s: f, a: m, d: p, ctrl: E, shift: L, alt: M, meta: I } = Le(), F = { zone: D(null), element: D(null) }; return { draggingElements: n, isDragging: e, activeContainer: t, elementsMap: r, selectedElements: l, zonesMap: s, visibleZones: o, visibleElements: g, pointerPosition: a, keyboard: { w: c, s: f, a: m, d: p, ctrl: E, shift: L, alt: M, meta: I }, hovered: F, handleDragElementIntersection: d, handleDropZoneIntersection: v }; }), Se = (n) => { const e = O(null), { draggingElements: t, pointerPosition: r, isDragging: l, activeContainer: s } = Z(); return Q(() => { s.ref = e, s.options.value = n ?? null; }), pe(() => { s.ref.value = null, s.options.value = null; }), { elementRef: e, draggingElements: t, pointerPosition: r, isDragging: l, animating: s.animating }; }, _e = ["innerHTML"], Ie = /* @__PURE__ */ de({ __name: "DefaultOverlay", setup(n) { const { elementRef: e, pointerPosition: t, isDragging: r, draggingElements: l } = Se(), s = T(() => { var o, g, i, u; return { transform: `translate3d(${(((o = t.current.value) == null ? void 0 : o.x) ?? 0) - (((g = t.offset.pixel.value) == null ? void 0 : g.x) ?? 0)}px, ${(((i = t.current.value) == null ? void 0 : i.y) ?? 0) - (((u = t.offset.pixel.value) == null ? void 0 : u.y) ?? 0)}px, 0)`, zIndex: 1e3, position: "fixed", top: 0, left: 0, transition: "0.3s cubic-bezier(0.165, 0.84, 0.44, 1)" }; }); return (o, g) => y(r) ? (R(), q("div", { key: 0, ref_key: "elementRef", ref: e, style: re(s.value) }, [ (R(!0), q(ae, null, ye(y(l), ([i, u]) => { var d, v; return R(), q(ae, { key: u.id }, [ u.layer ? (R(), G(J(u.layer), { key: 0, node: i, data: u.data, id: u.id, groups: u.groups }, null, 8, ["node", "data", "id", "groups"])) : (R(), q("div", { key: 1, innerHTML: u.initialHTML, style: re({ width: `${(d = u.initialRect) == null ? void 0 : d.width}px`, height: `${(v = u.initialRect) == null ? void 0 : v.height}px` }) }, null, 12, _e)) ], 64); }), 128)) ], 4)) : Ee("", !0); } }), oe = /* @__PURE__ */ de({ __name: "DragOverlay", setup(n) { const { activeContainer: e } = Z(), t = T( () => e.component.value ?? Ie ); return (r, l) => y(e).options.value ? (R(), G(we, { key: 0, name: y(e).options.value.name, duration: y(e).options.value.duration, "enter-from-class": y(e).options.value.enterFromClass, "enter-to-class": y(e).options.value.enterToClass, "enter-active-class": y(e).options.value.enterActiveClass, "leave-from-class": y(e).options.value.leaveFromClass, "leave-to-class": y(e).options.value.leaveToClass, "leave-active-class": y(e).options.value.leaveActiveClass, "appear-active-class": y(e).options.value.appearActiveClass, "appear-from-class": y(e).options.value.appearFromClass, "appear-to-class": y(e).options.value.appearToClass, mode: y(e).options.value.mode, type: y(e).options.value.type, css: y(e).options.value.css, appear: !0, persisted: y(e).options.value.persisted, onEnter: y(e).options.value.onEnter, onLeave: y(e).options.value.onLeave, onBeforeEnter: y(e).options.value.onBeforeEnter, onBeforeLeave: y(e).options.value.onBeforeLeave, onBeforeAppear: y(e).options.value.onBeforeAppear, onAfterEnter: y(e).options.value.onAfterEnter, onAfterLeave: y(e).options.value.onAfterLeave, onAfterAppear: y(e).options.value.onAfterAppear }, { default: xe(() => [ (R(), G(J(t.value))) ]), _: 1 }, 8, ["name", "duration", "enter-from-class", "enter-to-class", "enter-active-class", "leave-from-class", "leave-to-class", "leave-active-class", "appear-active-class", "appear-from-class", "appear-to-class", "mode", "type", "css", "persisted", "onEnter", "onLeave", "onBeforeEnter", "onBeforeLeave", "onBeforeAppear", "onAfterEnter", "onAfterLeave", "onAfterAppear"])) : (R(), G(J(t.value), { key: 1 })); } }), Ue = { install(n) { n.component("DragOverlay", oe); const e = n.mount; n.mount = function(r) { const l = e.call(this, r), s = typeof r == "string" ? document.querySelector(r) : r; if (s && s instanceof Element && !s.querySelector("#vue-dnd-kit-overlay")) { const o = document.createElement("div"); o.id = "vue-dnd-kit-overlay", o.style.pointerEvents = "none", s.appendChild(o); const g = Me(oe); le(g, o), n.__VUE_DND_KIT_OVERLAY__ = { container: o, vnode: g }; const i = Z(); n.__VUE_DND_KIT_STORE__ = i; } return l; }; const t = n.unmount; n.unmount = function() { return n.__VUE_DND_KIT_OVERLAY__ && (le(null, n.__VUE_DND_KIT_OVERLAY__.container), delete n.__VUE_DND_KIT_OVERLAY__), t.call(this); }; } }, ie = (n, e) => n.x < e.x + e.width && n.x + n.width > e.x && n.y < e.y + e.height && n.y + n.height > e.y, B = (n) => { if (!n) return { x: 0, y: 0, width: 0, height: 0, bottom: 0, left: 0, right: 0, top: 0 }; const e = n.getBoundingClientRect(); return { bottom: e.bottom, left: e.left, right: e.right, top: e.top, x: e.x, y: e.y, width: e.width, height: e.height }; }, j = (n) => ({ x: n.x + n.width / 2, y: n.y + n.height / 2 }), Ce = (n, e) => { const t = B(n); return { pixel: { x: e.x - t.x, y: e.y - t.y }, percent: { x: (e.x - t.x) / t.width * 100, y: (e.y - t.y) / t.height * 100 } }; }, ue = (n, e) => { const t = e.x - n.x, r = e.y - n.y; return Math.sqrt(t * t + r * r); }, ce = (n, e) => { const t = Math.max( 0, Math.min(n.x + n.width, e.x + e.width) - Math.max(n.x, e.x) ), r = Math.max( 0, Math.min(n.y + n.height, e.y + e.height) - Math.max(n.y, e.y) ), l = t * r, s = n.width * n.height, o = e.width * e.height; return (l / s * 100 + l / o * 100) / 2; }, ve = "data-vue-dnd-kit-draggable", C = (n) => { n.preventDefault(); }, H = (n) => ({ items: Array.from(n.draggingElements.value.values()) }), De = (n) => { const { elementsMap: e, draggingElements: t, hovered: r, selectedElements: l, isDragging: s, visibleElements: o, handleDragElementIntersection: g } = Z(), i = O(null), u = T( () => o.value.has(i.value) && r.element.value === i.value ), d = D((n == null ? void 0 : n.id) || Pe()), v = T(() => !i.value || !e.value.has(i.value) ? !1 : t.value.has(i.value)), a = T(() => { if (!i.value || !s.value || !o.value.has(i.value)) return !1; const m = e.value.get(i.value); return m != null && m.groups.length ? !Array.from(t.value.entries()).some( ([p, E]) => E.groups.length ? !E.groups.some( (L) => m.groups.includes(L) ) : !1 ) : !0; }); return { elementRef: i, registerElement: () => { if (!i.value) throw new Error("ElementRef is not set"); e.value.set(i.value, { node: i.value, groups: (n == null ? void 0 : n.groups) ?? [], layer: (n == null ? void 0 : n.layer) ?? null, defaultLayer: (n == null ? void 0 : n.layer) ?? null, events: (n == null ? void 0 : n.events) ?? {}, data: (n == null ? void 0 : n.data) ?? null, id: d.value }), g("add", i.value), i.value.addEventListener("dragstart", C), i.value.addEventListener("drag", C), i.value.setAttribute(ve, "true"), i.value.setAttribute("draggable", "false"); }, unregisterElement: () => { i.value && (e.value.delete(i.value), l.value.delete(i.value), i.value.removeEventListener("dragstart", C), i.value.removeEventListener("drag", C), i.value.removeAttribute(ve), i.value.removeAttribute("draggable")); }, isDragging: v, isOvered: u, isAllowed: a, id: d }; }, b = (n, e) => n ? e.contains(n) : !1, ze = (n) => { var d, v; const e = B(n.activeContainer.ref.value), t = j(e), r = ((d = n.pointerPosition.current.value) == null ? void 0 : d.x) ?? 0, l = ((v = n.pointerPosition.current.value) == null ? void 0 : v.y) ?? 0, o = !(e && r >= e.x && r <= e.x + e.width && l >= e.y && l <= e.y + e.height), g = Array.from(n.draggingElements.value.keys()), i = Array.from(n.visibleElements.value.entries()).filter(([a, c]) => { if (!a) return !1; const f = B(a); return f && e && ie(f, e); }).map(([a, c]) => { const f = B(a), m = j(f), p = r >= f.x && r <= f.x + f.width && l >= f.y && l <= f.y + f.height, E = ce(f, e), L = ue(t, m); let M = 0; for (const [I, F] of n.visibleElements.value.entries()) I !== a && I && a && b(a, I) && M++; return { element: c, node: a, isPointerInElement: p, overlapPercent: E, depth: M, centerDistance: L }; }).sort((a, c) => { if (!o) { if (a.isPointerInElement && c.isPointerInElement) return c.depth - a.depth; if (a.isPointerInElement !== c.isPointerInElement) return a.isPointerInElement ? -1 : 1; } return Math.abs(a.overlapPercent - c.overlapPercent) <= 1 ? a.centerDistance - c.centerDistance : c.overlapPercent - a.overlapPercent; }), u = Array.from(n.visibleZones.value.entries()).filter(([a, c]) => { if (!a || g.some( (m) => m && b(a, m) )) return !1; const f = B(a); return f && e && ie(f, e); }).map(([a, c]) => { const f = B(a), m = j(f), p = r >= f.x && r <= f.x + f.width && l >= f.y && l <= f.y + f.height, E = ce(f, e), L = ue(t, m); let M = 0; for (const [I, F] of n.visibleZones.value.entries()) I !== a && I && a && b(a, I) && M++; return { zone: c, node: a, isPointerInElement: p, overlapPercent: E, depth: M, centerDistance: L }; }).sort((a, c) => { if (!o) { if (a.isPointerInElement && c.isPointerInElement) return c.depth - a.depth; if (a.isPointerInElement !== c.isPointerInElement) return a.isPointerInElement ? -1 : 1; } return Math.abs(a.overlapPercent - c.overlapPercent) <= 1 ? a.centerDistance - c.centerDistance : c.overlapPercent - a.overlapPercent; }); return [ ...i.map((a) => a.node), ...u.map((a) => a.node) ]; }, ke = (n, e) => { const { pointerPosition: t, keyboard: r } = Z(), l = (e == null ? void 0 : e.moveStep) || 10; return { onKeyboardStart: (i) => { var a; C(i); const u = B(n.value); (a = n.value) == null || a.blur(); const d = u.x + u.width / 2, v = u.y + u.height / 2; t.start.value = { x: d, y: v }, t.current.value = { x: d, y: v }, t.offset.pixel.value = { x: u.width / 2, y: u.height / 2 }, t.offset.percent.value = { x: 50, y: 50 }; }, onKeyboardMove: () => { if (!t.current.value) return; const i = t.current.value.x, u = t.current.value.y; let d = i, v = u; r.w.value && (v -= l), r.s.value && (v += l), r.a.value && (d -= l), r.d.value && (d += l), t.current.value = { x: d, y: v }; }, onKeyboardEnd: () => { t.current.value = null, t.start.value = null, t.offset.pixel.value = null, t.offset.percent.value = null; } }; }, be = (n) => { const e = Z(); return { onPointerStart: (s) => { e.pointerPosition.start.value = { x: s.clientX, y: s.clientY }, e.pointerPosition.current.value = { x: s.clientX, y: s.clientY }; const { pixel: o, percent: g } = Ce(n.value, { x: s.clientX, y: s.clientY }); e.pointerPosition.offset.pixel.value = o, e.pointerPosition.offset.percent.value = g; }, onPointerMove: (s) => { e.pointerPosition.current.value = { x: s.clientX, y: s.clientY }; }, onPointerEnd: () => { e.pointerPosition.current.value = null, e.pointerPosition.start.value = null, e.pointerPosition.offset.pixel.value = null, e.pointerPosition.offset.percent.value = null; } }; }, Te = (n, e) => { var F, K; const t = Z(), { onPointerStart: r, onPointerMove: l, onPointerEnd: s } = be(n), { onKeyboardStart: o, onKeyboardMove: g, onKeyboardEnd: i } = ke( n, e == null ? void 0 : e.keyboard ); let u = null; const d = (h) => { var z, A; if (!h) return /* @__PURE__ */ new Map(); const _ = t.selectedElements.value.has(h); if (t.selectedElements.value.size > 0 && _) { const S = /* @__PURE__ */ new Map(); return t.selectedElements.value.forEach((V) => { var U, X; const Y = t.elementsMap.value.get(V); Y && S.set(V, { ...Y, initialHTML: ((U = Y.node) == null ? void 0 : U.outerHTML) ?? "", initialRect: (X = Y.node) == null ? void 0 : X.getBoundingClientRect() }); }), S; } t.selectedElements.value.clear(); const P = t.elementsMap.value.get(h); if (!P) return /* @__PURE__ */ new Map(); const w = /* @__PURE__ */ new Map(); return w.set(h, { ...P, initialHTML: ((z = P.node) == null ? void 0 : z.outerHTML) ?? "", initialRect: (A = P.node) == null ? void 0 : A.getBoundingClientRect() }), w; }, v = (h) => { if (!h) return { element: null, zone: null }; const _ = Array.isArray(h) ? h : [h], P = Array.from(t.draggingElements.value.keys()), w = _.find((A) => { if (!t.visibleZones.value.has(A)) return !1; const S = t.zonesMap.value.get(A); return !(!S || P.some( (V) => V && (V === S.node || b(S.node, V)) ) || S.groups.length && !!Array.from( t.draggingElements.value.values() ).some((Y) => Y.groups.length ? !Y.groups.some((U) => S.groups.includes(U)) : !1)); }); return w ? { element: _.find( (A) => t.visibleElements.value.has(A) && t.elementsMap.value.has(A) && !P.some( (S) => S && (S === A || b( A, S ) || b(S, A)) ) && (A === w || b( A, w )) ) || null, zone: w } : { element: null, zone: null }; }, a = ((F = e == null ? void 0 : e.sensor) == null ? void 0 : F.setup) || ze, c = (h) => { var A, S, V, Y, U, X, W, N, ee, te, $, ne; const _ = t.hovered.element.value, P = t.hovered.zone.value, w = h.element, z = h.zone; t.hovered.element.value = w, t.hovered.zone.value = z, _ !== w && (_ && ((V = (S = (A = t.elementsMap.value.get(_)) == null ? void 0 : A.events) == null ? void 0 : S.onLeave) == null || V.call(S, t, H(t))), w && ((X = (U = (Y = t.elementsMap.value.get(w)) == null ? void 0 : Y.events) == null ? void 0 : U.onHover) == null || X.call(U, t, H(t)))), P !== z && (P && ((ee = (N = (W = t.zonesMap.value.get(P)) == null ? void 0 : W.events) == null ? void 0 : N.onLeave) == null || ee.call(N, t, H(t))), z && ((ne = ($ = (te = t.zonesMap.value.get(z)) == null ? void 0 : te.events) == null ? void 0 : $.onHover) == null || ne.call($, t, H(t)))); }, f = Ae(() => { const h = a(t), _ = v(h); c(_); }, ((K = e == null ? void 0 : e.sensor) == null ? void 0 : K.throttle) ?? 0), m = () => { f(), u = requestAnimationFrame(m); }, p = () => m(), E = () => { u !== null && (cancelAnimationFrame(u), u = null); }; return { activate: (h) => { t.draggingElements.value = d(n.value), t.draggingElements.value.forEach( (_) => { var P, w; return (w = (P = _.events).onStart) == null ? void 0 : w.call(P, t, H(t)); } ), h instanceof PointerEvent ? r(h) : o(h), p(); }, track: (h) => { t.draggingElements.value.forEach( (_) => { var P, w; return (w = (P = _.events).onMove) == null ? void 0 : w.call(P, t, H(t)); } ), h instanceof KeyboardEvent ? g() : l(h); }, deactivate: (h = !0) => { var _, P; if (s(), i(), h) { if (t.hovered.zone.value) { const w = t.zonesMap.value.get(t.hovered.zone.value); (P = w == null ? void 0 : (_ = w.events).onDrop) == null || P.call(_, t, H(t)); } else t.draggingElements.value.forEach( (w) => { var z, A; return (A = (z = w.events).onEnd) == null ? void 0 : A.call(z, t, H(t)); } ); t.selectedElements.value.clear(); } t.draggingElements.value.clear(), t.hovered.zone.value = null, t.hovered.element.value = null, E(); } }; }, Ze = ge(() => { let n = "", e = "", t = "", r = null, l = null, s = null, o = null, g = null; const { activeContainer: i } = Z(), u = () => { const c = document.body; n = c.style.userSelect, c.style.userSelect = "none", window.addEventListener("contextmenu", C), window.addEventListener("selectstart", C), window.addEventListener("touchstart", C), window.addEventListener("touchmove", C); }, d = () => { const c = document.body; c.style.userSelect = n, c.style.touchAction = e, c.style.overscrollBehavior = t, window.removeEventListener("contextmenu", C), window.removeEventListener("selectstart", C), window.removeEventListener("touchstart", C), window.removeEventListener("touchmove", C); }, v = () => { r && (document.removeEventListener("pointermove", r), r = null), l && (document.removeEventListener("pointerup", l), l = null), s && (s = null), o && (document.removeEventListener("wheel", o), o = null), g && (document.removeEventListener("keydown", g), document.removeEventListener("keypress", g), document.removeEventListener("keyup", g), g = null); }; return { handleDragStart: (c, f, m) => { v(), c.target.blur(), m != null && m.container && (i.component.value = m.container); const { activate: p, track: E, deactivate: L } = Te(f, m); l = () => { i.component.value = null, d(), L(!0), v(); }, s = () => { i.component.value = null, d(), L(!1), v(); }, r = (M) => E(M), o = (M) => E(M), g = (M) => { M.type === "keyup" && (M.code === "Escape" && (s == null || s()), M.code === "Enter" && (l == null || l())), E(M); }, u(), p(c), document.addEventListener("pointermove", r), document.addEventListener("pointerup", l), document.addEventListener("wheel", o), document.addEventListener("keydown", g), document.addEventListener("keypress", g), document.addEventListener("keyup", g); } }; }), He = (n) => { const { id: e, elementRef: t, isDragging: r, isOvered: l, isAllowed: s, registerElement: o, unregisterElement: g } = De(n), { pointerPosition: i } = Z(), { handleDragStart: u } = Ze(), d = (v) => u(v, t, n); return Q(o), fe(g), { pointerPosition: i, elementRef: t, isDragging: r, isOvered: l, isAllowed: s, handleDragStart: d, id: e }; }, Ke = (n) => { const { zonesMap: e, hovered: t, draggingElements: r, isDragging: l, handleDropZoneIntersection: s } = Z(), o = O(null), g = T(() => t.zone.value === o.value), i = T(() => { if (!o.value || !l.value) return !1; const v = e.value.get(o.value); return v != null && v.groups.length ? !Array.from(r.value.values()).some((a) => a.groups.length ? !a.groups.some( (c) => v.groups.includes(c) ) : !1) : !0; }); return { elementRef: o, registerZone: () => { if (!o.value) throw new Error("elementRef is not set"); s("add", o.value), e.value.set(o.value, { node: o.value, groups: (n == null ? void 0 : n.groups) ?? [], events: (n == null ? void 0 : n.events) ?? {}, data: (n == null ? void 0 : n.data) ?? void 0 }), o.value.setAttribute("data-dnd-droppable", "true"); }, unregisterZone: () => { o.value && (s("remove", o.value), e.value.delete(o.value)); }, isOvered: g, isAllowed: i }; }, Re = (n) => { const { elementRef: e, registerZone: t, unregisterZone: r, isOvered: l, isAllowed: s } = Ke(n); return Q(t), fe(r), { elementRef: e, isOvered: l, isAllowed: s }; }, Be = (n) => { const { selectedElements: e, elementsMap: t } = Z(), r = T( () => n.value ? e.value.has(n.value) : !1 ), l = T(() => { if (!n.value) return !1; for (const u of e.value) if (u && b(u, n.value)) return !0; return !1; }), s = T(() => { if (!n.value) return !1; for (const u of e.value) if (u && b(n.value, u)) return !0; return !1; }), o = () => { n.value && e.value.delete(n.value); }, g = () => { if (!(!n.value || !t.value.get(n.value))) { if (l.value) for (const d of e.value) d && b(d, n.value) && e.value.delete(d); if (s.value) for (const d of e.value) d && b(n.value, d) && e.value.delete(d); e.value.add(n.value); } }; return { handleUnselect: o, handleSelect: g, handleToggleSelect: () => { n.value && (e.value.has(n.value) ? o() : g()); }, isSelected: r, isParentOfSelected: l }; }; export { se as DnDOperations, Ue as default, B as getBoundingBox, Z as useDnDStore, Se as useDragContainer, He as useDraggable, Re as useDroppable, Be as useSelection }; //# sourceMappingURL=vue-dnd-kit-core.es.js.map