@vue-dnd-kit/core 1.7.0 → 2.0.0-alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/README.md +5 -305
  2. package/dist/core.css +1 -0
  3. package/dist/external/components/DefaultOverlay.vue.d.ts +3 -0
  4. package/dist/external/components/DefaultOverlay.vue.d.ts.map +1 -0
  5. package/dist/external/components/DnDProvider.vue.d.ts +25 -0
  6. package/dist/external/components/DnDProvider.vue.d.ts.map +1 -0
  7. package/dist/external/composables/makeBoundingBox.d.ts +8 -0
  8. package/dist/external/composables/makeBoundingBox.d.ts.map +1 -0
  9. package/dist/external/composables/makeCustomOverlay.d.ts +2 -0
  10. package/dist/external/composables/makeCustomOverlay.d.ts.map +1 -0
  11. package/dist/external/composables/makeDraggable.d.ts +17 -0
  12. package/dist/external/composables/makeDraggable.d.ts.map +1 -0
  13. package/dist/external/composables/makeDroppable.d.ts +7 -0
  14. package/dist/external/composables/makeDroppable.d.ts.map +1 -0
  15. package/dist/external/composables/makeSelectableArea.d.ts +15 -0
  16. package/dist/external/composables/makeSelectableArea.d.ts.map +1 -0
  17. package/dist/external/composables/useDnDProvider.d.ts +3 -0
  18. package/dist/external/composables/useDnDProvider.d.ts.map +1 -0
  19. package/dist/external/index.d.ts +12 -0
  20. package/dist/external/index.d.ts.map +1 -0
  21. package/dist/external/types/entities.d.ts +144 -0
  22. package/dist/external/types/index.d.ts +4 -0
  23. package/dist/external/types/placement.d.ts +15 -0
  24. package/dist/external/types/pointer.d.ts +10 -0
  25. package/dist/external/types/provider.d.ts +64 -0
  26. package/dist/index.d.ts +2 -2141
  27. package/dist/internal/composables/useDnDProviderEvents.d.ts +3 -0
  28. package/dist/internal/composables/useDnDProviderEvents.d.ts.map +1 -0
  29. package/dist/internal/composables/useDnDProviderInternal.d.ts +3 -0
  30. package/dist/internal/composables/useDnDProviderInternal.d.ts.map +1 -0
  31. package/dist/internal/composables/useDnDProviderState.d.ts +4 -0
  32. package/dist/internal/composables/useDnDProviderState.d.ts.map +1 -0
  33. package/dist/internal/composables/useSizeObserver.d.ts +34 -0
  34. package/dist/internal/composables/useSizeObserver.d.ts.map +1 -0
  35. package/dist/internal/logic/hover.d.ts +8 -0
  36. package/dist/internal/logic/hover.d.ts.map +1 -0
  37. package/dist/internal/logic/keyboard.d.ts +7 -0
  38. package/dist/internal/logic/keyboard.d.ts.map +1 -0
  39. package/dist/internal/logic/payload.d.ts +8 -0
  40. package/dist/internal/logic/payload.d.ts.map +1 -0
  41. package/dist/internal/logic/pointer.d.ts +10 -0
  42. package/dist/internal/logic/pointer.d.ts.map +1 -0
  43. package/dist/internal/logic/scroll.d.ts +3 -0
  44. package/dist/internal/logic/scroll.d.ts.map +1 -0
  45. package/dist/internal/sensors/defaultCollision.d.ts +8 -0
  46. package/dist/internal/sensors/defaultCollision.d.ts.map +1 -0
  47. package/dist/internal/sensors/index.d.ts +3 -0
  48. package/dist/internal/sensors/index.d.ts.map +1 -0
  49. package/dist/internal/sensors/sensor.d.ts +53 -0
  50. package/dist/internal/sensors/sensor.d.ts.map +1 -0
  51. package/dist/internal/sensors/steps.d.ts +27 -0
  52. package/dist/internal/sensors/steps.d.ts.map +1 -0
  53. package/dist/internal/types/observer.d.ts +11 -0
  54. package/dist/internal/types/provider.d.ts +29 -0
  55. package/dist/internal/utils/constraints.d.ts +41 -0
  56. package/dist/internal/utils/constraints.d.ts.map +1 -0
  57. package/dist/internal/utils/disabled.d.ts +10 -0
  58. package/dist/internal/utils/disabled.d.ts.map +1 -0
  59. package/dist/internal/utils/dom.d.ts +45 -0
  60. package/dist/internal/utils/dom.d.ts.map +1 -0
  61. package/dist/internal/utils/drag-activation.d.ts +30 -0
  62. package/dist/internal/utils/drag-activation.d.ts.map +1 -0
  63. package/dist/internal/utils/events.d.ts +22 -0
  64. package/dist/internal/utils/events.d.ts.map +1 -0
  65. package/dist/internal/utils/geometry.d.ts +24 -0
  66. package/dist/internal/utils/geometry.d.ts.map +1 -0
  67. package/dist/internal/utils/groups.d.ts +9 -0
  68. package/dist/internal/utils/groups.d.ts.map +1 -0
  69. package/dist/internal/utils/keyboard.d.ts +6 -0
  70. package/dist/internal/utils/keyboard.d.ts.map +1 -0
  71. package/dist/internal/utils/namespaces.d.ts +19 -0
  72. package/dist/internal/utils/namespaces.d.ts.map +1 -0
  73. package/dist/internal/utils/observer.d.ts +28 -0
  74. package/dist/internal/utils/observer.d.ts.map +1 -0
  75. package/dist/internal/utils/placement.d.ts +29 -0
  76. package/dist/internal/utils/placement.d.ts.map +1 -0
  77. package/dist/internal/utils/pointer.d.ts +34 -0
  78. package/dist/internal/utils/pointer.d.ts.map +1 -0
  79. package/dist/internal/utils/provider.d.ts +13 -0
  80. package/dist/internal/utils/provider.d.ts.map +1 -0
  81. package/dist/internal/utils/selection.d.ts +28 -0
  82. package/dist/internal/utils/selection.d.ts.map +1 -0
  83. package/dist/internal/utils/session.d.ts +6 -0
  84. package/dist/internal/utils/session.d.ts.map +1 -0
  85. package/dist/vite.svg +1 -0
  86. package/dist/vue-dnd-kit-core.cjs.js +1 -1
  87. package/dist/vue-dnd-kit-core.cjs.js.map +1 -1
  88. package/dist/vue-dnd-kit-core.es.js +885 -857
  89. package/dist/vue-dnd-kit-core.es.js.map +1 -1
  90. package/package.json +74 -73
  91. package/LICENSE +0 -21
@@ -1,900 +1,928 @@
1
- var he = Object.defineProperty;
2
- var pe = (n, e, t) => e in n ? he(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var V = (n, e, t) => pe(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { shallowRef as C, ref as F, computed as O, onMounted as te, onUnmounted as ye, defineComponent as fe, createElementBlock as j, createCommentVNode as Ee, unref as P, openBlock as X, normalizeStyle as re, Fragment as ae, renderList as we, createBlock as J, resolveDynamicComponent as ee, Transition as Pe, withCtx as xe, normalizeProps as le, guardReactiveProps as Me, mergeProps as Ae, createVNode as Le, render as se, useId as be, onBeforeUnmount as ge } from "vue";
5
- import { createGlobalState as me, useMagicKeys as Ie, useThrottleFn as ze } from "@vueuse/core";
6
- const M = class M {
1
+ import { ref as F, watch as Ae, shallowRef as ne, reactive as _, computed as E, onMounted as R, onBeforeUnmount as P, inject as de, defineComponent as ye, unref as A, openBlock as p, createElementBlock as K, normalizeStyle as se, Fragment as X, renderList as we, createBlock as V, resolveDynamicComponent as q, createCommentVNode as xe, useTemplateRef as Le, provide as Ce, renderSlot as ie, createElementVNode as ke } from "vue";
2
+ const v = {
3
+ SELECT_AREA: "data-dnd-kit-select-area",
4
+ DRAGGABLE: "data-dnd-kit-draggable",
5
+ DROPPABLE: "data-dnd-kit-droppable",
6
+ CONSTRAINT_AREA: "data-dnd-kit-constraint-area"
7
+ }, k = {
8
+ SELECT_AREA: `[${v.SELECT_AREA}]`,
9
+ DRAGGABLE: `[${v.DRAGGABLE}]`,
10
+ CONSTRAINT_AREA: `[${v.CONSTRAINT_AREA}]`
11
+ }, te = "VueDnDKitProvider", ae = (e, t, n, s) => {
12
+ const i = /* @__PURE__ */ new Set();
13
+ return t.forEach((a) => {
14
+ const o = e.get(a), r = s ? s(a) : o?.disabled;
15
+ if (!o || r) return;
16
+ const l = o.modifier?.keys, c = o.modifier?.method;
17
+ if (!l || !c || l.length === 0) {
18
+ i.add(a);
19
+ return;
20
+ }
21
+ l[c]((u) => n.value.has(u)) && i.add(a);
22
+ }), i;
7
23
  };
8
- V(M, "remove", (e, t) => {
9
- if (!e || t === void 0) return;
10
- const [a] = e.splice(t, 1);
11
- return a;
12
- }), V(M, "insert", (e, t, a) => {
13
- !e || t === void 0 || e.splice(t, 0, a);
14
- }), V(M, "move", (e, t, a, l) => {
15
- if (!e || !a || t === void 0 || l === void 0)
16
- return;
17
- const s = M.remove(e, t);
18
- M.insert(a, l, s);
19
- }), V(M, "swap", (e, t, a, l) => {
20
- if (!e || !a || t === void 0 || l === void 0)
21
- return;
22
- const s = e[t], o = a[l];
23
- e[t] = o, a[l] = s;
24
- }), V(M, "copy", (e, t, a, l) => {
25
- if (!e || t === void 0 || !a || l === void 0)
26
- return;
27
- const s = e[t];
28
- M.insert(a, l, s);
29
- }), V(M, "applyTransfer", (e) => {
30
- var l, s, o, g, i, c, d;
31
- const t = e.hovered.element.value, a = e.hovered.zone.value;
32
- if (t) {
33
- const f = (s = (l = e.elementsMap.value.get(t)) == null ? void 0 : l.data) == null ? void 0 : s.source, r = (g = (o = e.elementsMap.value.get(t)) == null ? void 0 : o.data) == null ? void 0 : g.index, v = e.draggingElements.value.values().next().value, u = (i = v == null ? void 0 : v.data) == null ? void 0 : i.index, m = u !== void 0 && r !== void 0 && u > r ? 1 : -1;
34
- Array.from(
35
- e.draggingElements.value.values()
36
- ).sort(
37
- (h, L) => {
38
- var b, z;
39
- return m * ((((b = h.data) == null ? void 0 : b.index) || 0) - (((z = L.data) == null ? void 0 : z.index) || 0));
40
- }
41
- ).forEach(
42
- (h) => {
43
- var L, b;
44
- return M.move(
45
- (L = h.data) == null ? void 0 : L.source,
46
- (b = h.data) == null ? void 0 : b.index,
47
- f,
48
- r
49
- );
50
- }
51
- );
52
- } else if (a) {
53
- const f = (d = (c = e.zonesMap.value.get(a)) == null ? void 0 : c.data) == null ? void 0 : d.source, r = f == null ? void 0 : f.length;
54
- Array.from(
55
- e.draggingElements.value.values()
56
- ).sort((u, m) => {
57
- var p, h;
58
- return (((p = m.data) == null ? void 0 : p.index) || 0) - (((h = u.data) == null ? void 0 : h.index) || 0);
59
- }).forEach(
60
- (u) => {
61
- var m, p;
62
- return M.move(
63
- (m = u.data) == null ? void 0 : m.source,
64
- (p = u.data) == null ? void 0 : p.index,
65
- f,
66
- r
67
- );
68
- }
69
- );
70
- }
71
- }), V(M, "applyCopy", (e) => {
72
- var l, s, o, g, i, c;
73
- const t = e.hovered.element.value, a = e.hovered.zone.value;
74
- if (t) {
75
- const d = (s = (l = e.elementsMap.value.get(t)) == null ? void 0 : l.data) == null ? void 0 : s.source, f = (g = (o = e.elementsMap.value.get(t)) == null ? void 0 : o.data) == null ? void 0 : g.index;
76
- Array.from(
77
- e.draggingElements.value.values()
78
- ).sort((v, u) => {
79
- var m, p;
80
- return (((m = u.data) == null ? void 0 : m.index) || 0) - (((p = v.data) == null ? void 0 : p.index) || 0);
81
- }).forEach(
82
- (v) => {
83
- var u, m;
84
- return M.copy(
85
- (u = v.data) == null ? void 0 : u.source,
86
- (m = v.data) == null ? void 0 : m.index,
87
- d,
88
- f
89
- );
90
- }
91
- );
92
- } else if (a) {
93
- const d = (c = (i = e.zonesMap.value.get(a)) == null ? void 0 : i.data) == null ? void 0 : c.source, f = d == null ? void 0 : d.length;
94
- Array.from(
95
- e.draggingElements.value.values()
96
- ).sort((v, u) => {
97
- var m, p;
98
- return (((m = u.data) == null ? void 0 : m.index) || 0) - (((p = v.data) == null ? void 0 : p.index) || 0);
99
- }).forEach(
100
- (v) => {
101
- var u, m;
102
- return M.copy(
103
- (u = v.data) == null ? void 0 : u.source,
104
- (m = v.data) == null ? void 0 : m.index,
105
- d,
106
- f
107
- );
108
- }
109
- );
110
- }
111
- }), V(M, "applySwap", (e) => {
112
- var l, s, o, g, i, c, d, f;
113
- const t = e.hovered.element.value, a = e.hovered.zone.value;
114
- if (t && e.draggingElements.value.size === 1) {
115
- const r = e.draggingElements.value.values().next().value;
116
- M.swap(
117
- (l = r == null ? void 0 : r.data) == null ? void 0 : l.source,
118
- (s = r == null ? void 0 : r.data) == null ? void 0 : s.index,
119
- (g = (o = e.elementsMap.value.get(t)) == null ? void 0 : o.data) == null ? void 0 : g.source,
120
- (c = (i = e.elementsMap.value.get(t)) == null ? void 0 : i.data) == null ? void 0 : c.index
121
- );
122
- } else if (a) {
123
- const r = (f = (d = e.zonesMap.value.get(a)) == null ? void 0 : d.data) == null ? void 0 : f.source, v = r == null ? void 0 : r.length;
124
- Array.from(
125
- e.draggingElements.value.values()
126
- ).sort((m, p) => {
127
- var h, L;
128
- return (((h = p.data) == null ? void 0 : h.index) || 0) - (((L = m.data) == null ? void 0 : L.index) || 0);
129
- }).forEach(
130
- (m) => {
131
- var p, h;
132
- return M.move(
133
- (p = m.data) == null ? void 0 : p.source,
134
- (h = m.data) == null ? void 0 : h.index,
135
- r,
136
- v
137
- );
138
- }
139
- );
140
- }
141
- }), V(M, "applyRemove", (e) => {
142
- Array.from(
143
- e.draggingElements.value.values()
144
- ).sort((a, l) => {
145
- var s, o;
146
- return (((s = l.data) == null ? void 0 : s.index) || 0) - (((o = a.data) == null ? void 0 : o.index) || 0);
147
- }).forEach((a) => {
148
- var l, s;
149
- (l = a.data) != null && l.source && ((s = a.data) == null ? void 0 : s.index) !== void 0 && M.remove(a.data.source, a.data.index);
150
- });
151
- }), V(M, "applyInsert", (e, t) => {
152
- var s, o, g, i, c, d;
153
- const a = e.hovered.element.value, l = e.hovered.zone.value;
154
- if (a && t.length > 0) {
155
- const f = (o = (s = e.elementsMap.value.get(a)) == null ? void 0 : s.data) == null ? void 0 : o.source, r = (i = (g = e.elementsMap.value.get(a)) == null ? void 0 : g.data) == null ? void 0 : i.index;
156
- t.forEach((v) => {
157
- M.insert(f, r, v);
158
- });
159
- } else if (l) {
160
- const f = (d = (c = e.zonesMap.value.get(l)) == null ? void 0 : c.data) == null ? void 0 : d.source, r = f == null ? void 0 : f.length;
161
- t.forEach((v) => {
162
- M.insert(f, r, v);
24
+ let be = "", Re = "", Pe = "";
25
+ const N = (e) => e.value ? e.value instanceof HTMLElement ? e.value : e.value.$el : null, B = (e, t) => e !== t && e.contains(t), Be = (e, t) => !(e.right < t.left || e.left > t.right || e.bottom < t.top || e.top > t.bottom), W = () => {
26
+ const e = document.body;
27
+ be = e.style.userSelect, e.style.userSelect = "none", window.addEventListener("contextmenu", m), window.addEventListener("selectstart", m), window.addEventListener("touchstart", m), window.addEventListener("touchmove", m);
28
+ }, j = () => {
29
+ const e = document.body;
30
+ e.style.userSelect = be, e.style.touchAction = Re, e.style.overscrollBehavior = Pe, window.removeEventListener("contextmenu", m), window.removeEventListener("selectstart", m), window.removeEventListener("touchstart", m), window.removeEventListener("touchmove", m);
31
+ }, m = (e) => e.preventDefault(), M = (e, t) => {
32
+ if (t.entities.draggableMap.get(e)?.disabled) return !0;
33
+ for (const [s, i] of t.entities.draggableMap)
34
+ if (i.disabled && B(s, e)) return !0;
35
+ return !1;
36
+ }, L = (e, t) => {
37
+ if (t.entities.droppableMap.get(e)?.disabled) return !0;
38
+ for (const [s, i] of t.entities.droppableMap)
39
+ if (i.disabled && B(s, e)) return !0;
40
+ return !1;
41
+ }, Y = (e) => {
42
+ const t = new IntersectionObserver((n) => {
43
+ n.forEach((s) => {
44
+ const i = s.target;
45
+ e[s.isIntersecting ? "add" : "delete"](i);
163
46
  });
47
+ });
48
+ return {
49
+ observe: (n) => t.observe(n),
50
+ unobserve: (n) => t.unobserve(n),
51
+ disconnect: () => t.disconnect()
52
+ };
53
+ }, Oe = (e) => {
54
+ const t = new ResizeObserver((n) => {
55
+ const s = n[0];
56
+ if (!s) return;
57
+ const { width: i, height: a } = s.contentRect;
58
+ e.value = { width: i, height: a };
59
+ });
60
+ return {
61
+ observe: (n) => t.observe(n),
62
+ unobserve: (n) => t.unobserve(n),
63
+ disconnect: () => t.disconnect()
64
+ };
65
+ }, Te = (e) => {
66
+ const t = F(null), n = Oe(t), s = Ae(
67
+ e,
68
+ (a) => {
69
+ n.disconnect(), a && n.observe(a);
70
+ },
71
+ { immediate: !0 }
72
+ );
73
+ return { overlaySize: t, overlaySizeObserver: {
74
+ disconnect: () => {
75
+ s(), n.disconnect();
76
+ }
77
+ } };
78
+ };
79
+ function J(e, t = 0, n = 0) {
80
+ return {
81
+ start: { x: e.clientX, y: e.clientY },
82
+ current: { x: e.clientX, y: e.clientY },
83
+ offset: { x: t, y: n }
84
+ };
85
+ }
86
+ function me(e, t) {
87
+ const n = t.getBoundingClientRect(), s = n.width > 0 ? (e.clientX - n.left) / n.width : 0.5, i = n.height > 0 ? (e.clientY - n.top) / n.height : 0.5;
88
+ return { x: s, y: i };
89
+ }
90
+ function he(e, t) {
91
+ return {
92
+ ...t,
93
+ initialHTML: e.innerHTML,
94
+ initialRect: e.getBoundingClientRect()
95
+ };
96
+ }
97
+ function ze(e, t, n) {
98
+ e.forEach((s) => {
99
+ const i = t.get(s);
100
+ n.set(s, he(s, i));
101
+ }), e.clear();
102
+ }
103
+ function _e(e, t, n) {
104
+ n.clear();
105
+ const s = t.get(e);
106
+ n.set(e, he(e, s));
107
+ }
108
+ function G(e) {
109
+ e.entities.initiatingDraggable && (e.state.value = "dragging", Ie(
110
+ e.entities.initiatingDraggable,
111
+ e.entities.selectedSet,
112
+ e.entities.draggableMap,
113
+ e.entities.draggingMap
114
+ ));
115
+ }
116
+ function Ie(e, t, n, s) {
117
+ t.has(e) ? ze(t, n, s) : (t.clear(), _e(e, n, s));
118
+ }
119
+ function De(e, t, n, s) {
120
+ if (s || !n) return !0;
121
+ const i = e.closest(n);
122
+ return i ? t.contains(i) : !1;
123
+ }
124
+ function Fe(e, t) {
125
+ if (!e || !t) return 1;
126
+ const n = Math.abs(e.current.x - e.start.x), s = Math.abs(e.current.y - e.start.y);
127
+ if (typeof t == "number") {
128
+ const c = Math.sqrt(n * n + s * s);
129
+ return Math.min(c / t, 1);
164
130
  }
165
- });
166
- let oe = M;
167
- const Y = me(() => {
168
- const n = C(!1), e = F(
169
- /* @__PURE__ */ new Map()
170
- ), t = O(() => e.value.size > 0), a = {
171
- component: F(null),
172
- ref: C(null),
173
- options: C(null),
174
- props: C(null),
175
- animating: {
176
- enter: C(!1),
177
- leave: C(!1),
178
- appear: C(!1)
131
+ const {
132
+ x: i = 0,
133
+ y: a = 0,
134
+ condition: o = "any"
135
+ } = t;
136
+ if (i === 0 && a === 0) return 1;
137
+ const r = i > 0 ? Math.min(n / i, 1) : 1, l = a > 0 ? Math.min(s / a, 1) : 1;
138
+ return o === "both" ? Math.min(r, l) : Math.max(r, l);
139
+ }
140
+ function pe(e, t, n) {
141
+ if (!n) return !0;
142
+ const s = n.distance != null, i = n.delay != null;
143
+ return !s && !i ? !0 : s && !i ? e >= 1 : !s && i ? t >= 1 : (n.condition ?? "both") === "both" ? e >= 1 && t >= 1 : e >= 1 || t >= 1;
144
+ }
145
+ function Ke(e) {
146
+ if (e.state.value !== "activating" || !e.entities.initiatingDraggable)
147
+ return !1;
148
+ const t = e.entities.draggableMap.get(
149
+ e.entities.initiatingDraggable
150
+ );
151
+ return pe(
152
+ e.distanceProgress.value,
153
+ e.delay.progress,
154
+ t?.activation
155
+ ) ? (G(e), !0) : !1;
156
+ }
157
+ function Ge(e, t) {
158
+ let n = null;
159
+ const s = () => {
160
+ if (e.state.value !== "activating" || !e.entities.initiatingDraggable) {
161
+ n = null;
162
+ return;
179
163
  }
180
- }, l = F(/* @__PURE__ */ new Map()), s = F(/* @__PURE__ */ new Set()), o = F(/* @__PURE__ */ new Map()), g = C(/* @__PURE__ */ new Set()), i = C(/* @__PURE__ */ new Set()), c = typeof window < "u" && "IntersectionObserver" in window, d = c ? new IntersectionObserver((x) => {
181
- x.forEach(
182
- (y) => i.value[y.isIntersecting ? "add" : "delete"](
183
- y.target
184
- )
185
- );
186
- }) : null, f = c ? new IntersectionObserver((x) => {
187
- x.forEach(
188
- (y) => g.value[y.isIntersecting ? "add" : "delete"](
189
- y.target
190
- )
191
- );
192
- }) : null, r = (x, y) => {
193
- d && (x === "add" ? d.observe(y) : (d.unobserve(y), i.value.delete(y)));
194
- }, v = (x, y) => {
195
- f && (x === "add" ? f.observe(y) : (f.unobserve(y), g.value.delete(y)));
196
- }, u = {
197
- start: C(null),
198
- current: C(null),
199
- offset: {
200
- percent: C(null),
201
- pixel: C(null)
164
+ const i = e.entities.draggableMap.get(
165
+ e.entities.initiatingDraggable
166
+ ), a = i?.activation?.delay;
167
+ if (!a) {
168
+ n = null;
169
+ return;
170
+ }
171
+ e.delay.progress = Math.min(
172
+ (Date.now() - e.delay.startTime) / (a * 1e3),
173
+ 1
174
+ ), pe(
175
+ e.distanceProgress.value,
176
+ e.delay.progress,
177
+ i?.activation
178
+ ) ? (t(), n = null) : n = requestAnimationFrame(s);
179
+ };
180
+ return n = requestAnimationFrame(s), {
181
+ cancel: () => {
182
+ n !== null && (cancelAnimationFrame(n), n = null);
202
183
  }
203
- }, { KeyW: m, KeyS: p, KeyA: h, KeyD: L, ctrl: b, shift: z, alt: B, meta: D } = Ie(), w = {
204
- zone: C(null),
205
- element: C(null)
206
184
  };
185
+ }
186
+ function He(e, t) {
187
+ const n = e.closest(
188
+ k.CONSTRAINT_AREA
189
+ );
190
+ return !n || !t.has(n) ? null : {
191
+ element: n,
192
+ entity: t.get(n)
193
+ };
194
+ }
195
+ function Ne(e, t, n, s) {
196
+ return n === "x" ? { x: e, y: s.top } : n === "y" ? { x: s.left, y: t } : { x: e, y: t };
197
+ }
198
+ function Ue(e, t, n, s, i) {
199
+ let a = e, o = t;
200
+ return n !== "y" && (a = Math.max(
201
+ s.left,
202
+ Math.min(s.right - i.width, e)
203
+ )), n !== "x" && (o = Math.max(
204
+ s.top,
205
+ Math.min(s.bottom - i.height, t)
206
+ )), { x: a, y: o };
207
+ }
208
+ function Ye(e, t, n, s, i) {
209
+ if (!e || !t)
210
+ return { x: 0, y: 0 };
211
+ const a = t.getBoundingClientRect(), o = a.width || i?.width || 0, r = a.height || i?.height || 0;
212
+ let l = e.current.x - o * e.offset.x, c = e.current.y - r * e.offset.y;
213
+ if (!n)
214
+ return { x: l, y: c };
215
+ const f = He(n, s);
216
+ if (!f)
217
+ return { x: l, y: c };
218
+ const { element: u, entity: d } = f, g = u.getBoundingClientRect(), y = n.getBoundingClientRect(), b = Ne(
219
+ l,
220
+ c,
221
+ d.axis || "both",
222
+ y
223
+ );
224
+ return d.restrictToArea ? Ue(
225
+ b.x,
226
+ b.y,
227
+ d.axis || "both",
228
+ g,
229
+ a
230
+ ) : b;
231
+ }
232
+ const C = {
233
+ forDrag: ["Enter", "Space"],
234
+ forCancel: ["Escape"],
235
+ forDrop: ["Enter", "Space"],
236
+ forMove: [
237
+ "ArrowUp",
238
+ "ArrowDown",
239
+ "ArrowLeft",
240
+ "ArrowRight",
241
+ "KeyW",
242
+ "KeyA",
243
+ "KeyS",
244
+ "KeyD"
245
+ ],
246
+ forMoveFaster: ["ShiftLeft", "ShiftRight"]
247
+ };
248
+ function Ze(e) {
249
+ const t = ne(), n = F(), i = {
250
+ keys: {
251
+ pressedKeys: F(/* @__PURE__ */ new Set()),
252
+ forDrag: [...C.forDrag],
253
+ forCancel: [...C.forCancel],
254
+ forDrop: [...C.forDrop],
255
+ forMove: [...C.forMove],
256
+ forMoveFaster: [...C.forMoveFaster]
257
+ },
258
+ step: 8,
259
+ moveFaster: 4
260
+ }, a = _({
261
+ draggableMap: /* @__PURE__ */ new Map(),
262
+ droppableMap: /* @__PURE__ */ new Map(),
263
+ selectableAreaMap: /* @__PURE__ */ new Map(),
264
+ constraintsAreaMap: /* @__PURE__ */ new Map(),
265
+ initiatingDraggable: void 0,
266
+ selectingArea: void 0,
267
+ draggingMap: /* @__PURE__ */ new Map(),
268
+ selectedSet: /* @__PURE__ */ new Set(),
269
+ modifiersSelectableAreaSet: E(() => ae(
270
+ a.selectableAreaMap,
271
+ a.visibleSelectableAreaSet,
272
+ i.keys.pressedKeys
273
+ )),
274
+ modifiersDraggableSet: E(() => ae(
275
+ a.draggableMap,
276
+ a.visibleDraggableSet,
277
+ i.keys.pressedKeys,
278
+ (z) => M(z, { entities: a })
279
+ )),
280
+ visibleDraggableSet: /* @__PURE__ */ new Set(),
281
+ visibleDroppableSet: /* @__PURE__ */ new Set(),
282
+ visibleSelectableAreaSet: /* @__PURE__ */ new Set()
283
+ }), o = _({
284
+ x: window.scrollX,
285
+ y: window.scrollY
286
+ }), r = _({
287
+ progress: 0,
288
+ startTime: 0
289
+ }), l = E(() => {
290
+ if (!n.value || !a.initiatingDraggable) return 0;
291
+ const z = a.draggableMap.get(a.initiatingDraggable)?.activation?.distance;
292
+ return z ? Fe(n.value, z) : 1;
293
+ }), c = Y(
294
+ a.visibleDraggableSet
295
+ ), f = Y(
296
+ a.visibleDroppableSet
297
+ ), u = Y(
298
+ a.visibleSelectableAreaSet
299
+ ), { overlaySize: d, overlaySizeObserver: g } = Te(e), y = F(), b = _({
300
+ draggable: /* @__PURE__ */ new Map(),
301
+ droppable: /* @__PURE__ */ new Map()
302
+ }), D = {
303
+ throttle: ne(0)
304
+ }, O = E(() => {
305
+ o.y, o.x;
306
+ const T = a.initiatingDraggable;
307
+ return Ye(
308
+ n.value,
309
+ e.value,
310
+ T || null,
311
+ a.constraintsAreaMap,
312
+ d.value
313
+ );
314
+ });
207
315
  return {
208
- draggingElements: e,
209
- isDragging: t,
210
- activeContainer: a,
211
- elementsMap: l,
212
- selectedElements: s,
213
- zonesMap: o,
214
- visibleZones: g,
215
- visibleElements: i,
216
- pointerPosition: u,
217
- keyboard: {
218
- w: m,
219
- s: p,
220
- a: h,
221
- d: L,
222
- ctrl: b,
223
- shift: z,
224
- alt: B,
225
- meta: D
316
+ state: t,
317
+ pointer: n,
318
+ entities: a,
319
+ keyboard: i,
320
+ scrollPosition: o,
321
+ delay: r,
322
+ distanceProgress: l,
323
+ hovered: b,
324
+ collision: D,
325
+ overlay: {
326
+ size: d,
327
+ style: O,
328
+ render: y,
329
+ ref: e
226
330
  },
227
- hovered: w,
228
- isPending: n,
229
- handleDragElementIntersection: r,
230
- handleDropZoneIntersection: v
331
+ lib: {
332
+ draggableObserver: c,
333
+ droppableObserver: f,
334
+ selectableAreaObserver: u,
335
+ overlaySizeObserver: g
336
+ }
231
337
  };
232
- }), Ce = (n) => {
233
- const e = F(null), { draggingElements: t, pointerPosition: a, isDragging: l, activeContainer: s } = Y();
234
- return te(() => {
235
- s.ref = e, s.options.value = n ?? null;
236
- }), ye(() => {
237
- s.ref.value = null, s.options.value = null;
238
- }), {
239
- elementRef: e,
240
- draggingElements: t,
241
- pointerPosition: a,
242
- isDragging: l,
243
- animating: s.animating
338
+ }
339
+ const H = (e) => {
340
+ e.pointer.value = void 0, e.state.value = void 0, e.entities.selectingArea = void 0, e.entities.initiatingDraggable = void 0, e.delay.progress = 0, e.delay.startTime = 0, e.entities.draggingMap.clear(), e.hovered.draggable.clear(), e.hovered.droppable.clear();
341
+ }, Ee = (e) => {
342
+ const t = e.entities.initiatingDraggable;
343
+ if (!t) return;
344
+ const s = e.entities.draggableMap.get(t)?.payload;
345
+ if (!s) return;
346
+ const i = s();
347
+ if (!Array.isArray(i) || i.length < 2) return;
348
+ const [a, o, r] = i;
349
+ return {
350
+ index: Number(a),
351
+ items: Array.isArray(o) ? o : [],
352
+ dropData: r
244
353
  };
245
- }, Se = ["innerHTML"], De = /* @__PURE__ */ fe({
246
- __name: "DefaultOverlay",
247
- props: {
248
- styles: {}
249
- },
250
- setup(n) {
251
- const { elementRef: e, pointerPosition: t, isDragging: a, draggingElements: l } = Ce(), s = O(() => {
252
- var o, g, i, c;
253
- return {
254
- 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) - (((c = t.offset.pixel.value) == null ? void 0 : c.y) ?? 0)}px, 0)`,
255
- zIndex: 1e3,
256
- position: "fixed",
257
- top: 0,
258
- left: 0,
259
- transition: "0.3s cubic-bezier(0.165, 0.84, 0.44, 1)",
260
- ...n.styles
261
- };
262
- });
263
- return (o, g) => P(a) ? (X(), j("div", {
264
- key: 0,
265
- ref_key: "elementRef",
266
- ref: e,
267
- style: re(s.value)
268
- }, [
269
- (X(!0), j(ae, null, we(P(l), ([i, c]) => {
270
- var d, f;
271
- return X(), j(ae, {
272
- key: c.id
273
- }, [
274
- c.layer ? (X(), J(ee(c.layer), {
275
- key: 0,
276
- node: i,
277
- data: c.data,
278
- id: c.id,
279
- groups: c.groups
280
- }, null, 8, ["node", "data", "id", "groups"])) : (X(), j("div", {
281
- key: 1,
282
- innerHTML: c.initialHTML,
283
- style: re({
284
- width: `${(d = c.initialRect) == null ? void 0 : d.width}px`,
285
- height: `${(f = c.initialRect) == null ? void 0 : f.height}px`
286
- })
287
- }, null, 12, Se))
288
- ], 64);
289
- }), 128))
290
- ], 4)) : Ee("", !0);
354
+ }, w = (e) => e.keys().next().value, $e = (e) => e.target.closest(k.DRAGGABLE), S = (e) => ({
355
+ payload: Ee(e),
356
+ provider: e
357
+ }), Z = (e, t, n) => {
358
+ const s = $e(t);
359
+ if (!s || !e.entities.draggingMap.has(s)) return;
360
+ const i = S(e);
361
+ e.entities.draggingMap.get(s)?.events?.[n]?.(i);
362
+ }, x = (e, t, n) => {
363
+ if (!t || M(t, e)) return;
364
+ const s = S(e);
365
+ e.entities.draggableMap.get(t)?.events?.[n]?.(s);
366
+ }, h = (e, t) => {
367
+ const n = S(e);
368
+ e.entities.draggableMap.forEach((s, i) => {
369
+ M(i, e) || s.events?.[t]?.(n);
370
+ });
371
+ }, Xe = (e, t, n) => {
372
+ if (t !== n) {
373
+ const s = S(e);
374
+ t && !L(t, e) && e.entities.droppableMap.get(t)?.events?.onLeave?.(s), n && !L(n, e) && e.entities.droppableMap.get(n)?.events?.onEnter?.(s);
291
375
  }
292
- }), ie = /* @__PURE__ */ fe({
293
- __name: "DragOverlay",
294
- props: {
295
- styles: {}
296
- },
297
- setup(n) {
298
- const e = n, { activeContainer: t } = Y(), a = O(() => ({
299
- component: t.component.value ?? De,
300
- props: {
301
- ...e,
302
- ...t.props.value
303
- }
304
- }));
305
- return (l, s) => P(t).options.value ? (X(), J(Pe, {
306
- key: 0,
307
- name: P(t).options.value.name,
308
- duration: P(t).options.value.duration,
309
- "enter-from-class": P(t).options.value.enterFromClass,
310
- "enter-to-class": P(t).options.value.enterToClass,
311
- "enter-active-class": P(t).options.value.enterActiveClass,
312
- "leave-from-class": P(t).options.value.leaveFromClass,
313
- "leave-to-class": P(t).options.value.leaveToClass,
314
- "leave-active-class": P(t).options.value.leaveActiveClass,
315
- "appear-active-class": P(t).options.value.appearActiveClass,
316
- "appear-from-class": P(t).options.value.appearFromClass,
317
- "appear-to-class": P(t).options.value.appearToClass,
318
- mode: P(t).options.value.mode,
319
- type: P(t).options.value.type,
320
- css: P(t).options.value.css,
321
- appear: !0,
322
- persisted: P(t).options.value.persisted,
323
- onEnter: P(t).options.value.onEnter,
324
- onLeave: P(t).options.value.onLeave,
325
- onBeforeEnter: P(t).options.value.onBeforeEnter,
326
- onBeforeLeave: P(t).options.value.onBeforeLeave,
327
- onBeforeAppear: P(t).options.value.onBeforeAppear,
328
- onAfterEnter: P(t).options.value.onAfterEnter,
329
- onAfterLeave: P(t).options.value.onAfterLeave,
330
- onAfterAppear: P(t).options.value.onAfterAppear
331
- }, {
332
- default: xe(() => [
333
- (X(), J(ee(a.value.component || a.value), le(Me(a.value.props || {})), null, 16))
334
- ]),
335
- _: 1
336
- }, 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"])) : (X(), J(ee(a.value.component || a.value), le(Ae({ key: 1 }, a.value.props || {})), null, 16));
376
+ }, Ve = (e, t, n) => {
377
+ if (t !== n) {
378
+ const s = S(e);
379
+ t && !M(t, e) && e.entities.draggableMap.get(t)?.events?.onLeave?.(s), n && !M(n, e) && e.entities.draggableMap.get(n)?.events?.onHover?.(s);
337
380
  }
338
- }), He = {
339
- install(n, e) {
340
- n.component("DragOverlay", ie);
341
- const t = n.mount;
342
- n.mount = function(l) {
343
- var g, i, c, d, f, r, v;
344
- const s = t.call(this, l), o = typeof l == "string" ? document.querySelector(l) : l;
345
- if (o && o instanceof Element && !o.querySelector("#vue-dnd-kit-overlay")) {
346
- const u = document.createElement("div");
347
- u.id = "vue-dnd-kit-overlay", u.style.pointerEvents = "none", (g = e == null ? void 0 : e.overlayPosition) != null && g.zIndex && (u.style.zIndex = e.overlayPosition.zIndex.toString()), (i = e == null ? void 0 : e.overlayPosition) != null && i.className && (u.className = e.overlayPosition.className);
348
- const m = ((c = e == null ? void 0 : e.overlayPosition) == null ? void 0 : c.method) || "append", p = (d = e == null ? void 0 : e.overlayPosition) != null && d.target ? typeof e.overlayPosition.target == "string" ? document.querySelector(e.overlayPosition.target) : e.overlayPosition.target : o;
349
- if (p && p instanceof Element)
350
- switch (m) {
351
- case "prepend":
352
- p.insertBefore(
353
- u,
354
- p.firstChild
355
- );
356
- break;
357
- case "after":
358
- (f = p.parentNode) == null || f.insertBefore(
359
- u,
360
- p.nextSibling
361
- );
362
- break;
363
- case "before":
364
- (r = p.parentNode) == null || r.insertBefore(
365
- u,
366
- p
367
- );
368
- break;
369
- case "append":
370
- default:
371
- p.appendChild(u);
372
- break;
373
- }
374
- else
375
- o.appendChild(u);
376
- const h = Le(ie, {
377
- styles: (v = e == null ? void 0 : e.defaultOverlay) == null ? void 0 : v.styles
378
- });
379
- se(h, u), n.__VUE_DND_KIT_OVERLAY__ = {
380
- container: u,
381
- vnode: h,
382
- options: (e == null ? void 0 : e.defaultOverlay) || {}
383
- };
384
- const L = Y();
385
- n.__VUE_DND_KIT_STORE__ = L;
386
- }
387
- return s;
388
- };
389
- const a = n.unmount;
390
- n.unmount = function() {
391
- return n.__VUE_DND_KIT_OVERLAY__ && (se(null, n.__VUE_DND_KIT_OVERLAY__.container), delete n.__VUE_DND_KIT_OVERLAY__), a.call(this);
392
- };
381
+ }, qe = (e, t) => {
382
+ const n = w(t.droppable);
383
+ if (n && !L(n, e)) {
384
+ const s = S(e);
385
+ e.entities.droppableMap.get(n)?.events?.onLeave?.(s);
393
386
  }
394
- }, ue = (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, $ = (n) => {
395
- if (!n)
396
- return {
397
- x: 0,
398
- y: 0,
399
- width: 0,
400
- height: 0,
401
- bottom: 0,
402
- left: 0,
403
- right: 0,
404
- top: 0
405
- };
406
- const e = n.getBoundingClientRect();
387
+ }, ve = (e, t) => {
388
+ const n = w(t.droppable);
389
+ if (n && !L(n, e)) {
390
+ const s = S(e);
391
+ e.entities.droppableMap.get(n)?.events?.onLeave?.(s);
392
+ }
393
+ }, We = (e, t) => !e.length || !t.length ? !0 : e.some((n) => t.includes(n)), je = (e, t, n) => {
394
+ if (!n) return {};
395
+ const s = n.getBoundingClientRect(), i = Math.max(s.left, Math.min(e.x, t.x)), a = Math.max(s.top, Math.min(e.y, t.y)), o = Math.min(s.right, Math.max(e.x, t.x)), r = Math.min(s.bottom, Math.max(e.y, t.y)), l = Math.max(0, o - i), c = Math.max(0, r - a);
407
396
  return {
408
- bottom: e.bottom,
409
- left: e.left,
410
- right: e.right,
411
- top: e.top,
412
- x: e.x,
413
- y: e.y,
414
- width: e.width,
415
- height: e.height
397
+ left: `${i}px`,
398
+ top: `${a}px`,
399
+ width: `${l}px`,
400
+ height: `${c}px`,
401
+ position: "fixed",
402
+ pointerEvents: "none",
403
+ border: "1px solid #3b82f6",
404
+ backgroundColor: "#3b82f61a"
416
405
  };
417
- }, Q = (n) => ({
418
- x: n.x + n.width / 2,
419
- y: n.y + n.height / 2
420
- }), _e = (n, e) => {
421
- const t = $(n);
422
- return {
423
- pixel: {
424
- x: e.x - t.x,
425
- y: e.y - t.y
426
- },
427
- percent: {
428
- x: (e.x - t.x) / t.width * 100,
429
- y: (e.y - t.y) / t.height * 100
406
+ }, Je = (e) => {
407
+ if (!e.pointer.value || !e.entities.selectingArea) return;
408
+ const { selectingArea: t } = e.entities, n = Qe(
409
+ e.pointer.value.start,
410
+ e.pointer.value.current
411
+ ), s = e.entities.selectableAreaMap.get(t)?.groups ?? [];
412
+ e.entities.visibleDraggableSet.forEach((i) => {
413
+ if (!t.contains(i)) return;
414
+ if (M(i, e)) {
415
+ e.entities.selectedSet.delete(i);
416
+ return;
430
417
  }
431
- };
432
- }, ce = (n, e) => {
433
- const t = e.x - n.x, a = e.y - n.y;
434
- return Math.sqrt(t * t + a * a);
435
- }, ve = (n, e) => {
436
- const t = Math.max(
437
- 0,
438
- Math.min(n.x + n.width, e.x + e.width) - Math.max(n.x, e.x)
439
- ), a = Math.max(
440
- 0,
441
- Math.min(n.y + n.height, e.y + e.height) - Math.max(n.y, e.y)
442
- ), l = t * a, s = n.width * n.height, o = e.width * e.height;
443
- return (l / s * 100 + l / o * 100) / 2;
444
- }, de = "data-vue-dnd-kit-draggable", Z = (n) => {
445
- n.preventDefault();
446
- }, R = (n) => ({
447
- items: Array.from(n.draggingElements.value.values())
448
- }), ke = (n) => {
449
- const {
450
- elementsMap: e,
451
- draggingElements: t,
452
- hovered: a,
453
- selectedElements: l,
454
- isDragging: s,
455
- visibleElements: o,
456
- handleDragElementIntersection: g
457
- } = Y(), i = F(null), c = O(() => a.element.value === i.value), d = C((n == null ? void 0 : n.id) || be()), f = C((n == null ? void 0 : n.disabled) ?? !1), r = O(() => f.value || !i.value || !e.value.has(i.value) ? !1 : t.value.has(i.value)), v = O(() => {
458
- if (f.value || !i.value || !s.value || !o.value.has(i.value)) return !1;
459
- const h = e.value.get(i.value);
460
- return h != null && h.groups.length ? !Array.from(t.value.entries()).some(
461
- ([L, b]) => b.groups.length ? !b.groups.some(
462
- (z) => h.groups.includes(z)
463
- ) : !1
464
- ) : !0;
465
- }), u = O(() => {
466
- if (f.value || !i.value || !s.value || !o.value.has(i.value) || a.element.value !== i.value) return !1;
467
- const h = e.value.get(i.value);
468
- return h != null && h.groups.length ? !Array.from(t.value.entries()).some(
469
- ([L, b]) => b.groups.length ? !b.groups.some(
470
- (z) => h.groups.includes(z)
471
- ) : !1
472
- ) : !0;
418
+ const o = e.entities.draggableMap.get(i)?.groups ?? [];
419
+ if (!We(s, o)) {
420
+ e.entities.selectedSet.delete(i);
421
+ return;
422
+ }
423
+ Be(n, i.getBoundingClientRect()) ? e.entities.selectedSet.add(i) : e.entities.selectedSet.delete(i);
473
424
  });
425
+ }, Qe = (e, t) => {
426
+ const n = Math.min(e.x, t.x), s = Math.min(e.y, t.y), i = Math.max(e.x, t.x), a = Math.max(e.y, t.y), o = i - n, r = a - s;
427
+ return new DOMRect(n, s, o, r);
428
+ }, et = (e, t, n = 5) => {
429
+ const s = n / 2;
474
430
  return {
475
- elementRef: i,
476
- registerElement: () => {
477
- if (!i.value) throw new Error("ElementRef is not set");
478
- e.value.set(i.value, {
479
- node: i.value,
480
- groups: (n == null ? void 0 : n.groups) ?? [],
481
- layer: (n == null ? void 0 : n.layer) ?? null,
482
- defaultLayer: (n == null ? void 0 : n.layer) ?? null,
483
- events: (n == null ? void 0 : n.events) ?? {},
484
- data: (n == null ? void 0 : n.data) ?? null,
485
- id: d.value,
486
- disabled: f ?? !1
487
- }), g("add", i.value), i.value.addEventListener("dragstart", Z), i.value.addEventListener("drag", Z), i.value.setAttribute(de, "true"), i.value.setAttribute("draggable", "false");
488
- },
489
- unregisterElement: () => {
490
- i.value && (e.value.delete(i.value), l.value.delete(i.value), i.value.removeEventListener("dragstart", Z), i.value.removeEventListener("drag", Z), i.value.removeAttribute(de), i.value.removeAttribute("draggable"));
491
- },
492
- isDragging: r,
493
- isOvered: c,
494
- isAllowed: v,
495
- isLazyAllowed: u,
496
- id: d
431
+ left: e - s,
432
+ top: t - s,
433
+ width: n,
434
+ height: n
497
435
  };
498
- }, k = (n, e) => n ? e.contains(n) : !1, Ke = (n) => {
499
- var d, f;
500
- const e = $(n.activeContainer.ref.value), t = Q(e), a = ((d = n.pointerPosition.current.value) == null ? void 0 : d.x) ?? 0, l = ((f = n.pointerPosition.current.value) == null ? void 0 : f.y) ?? 0, o = !(e && a >= e.x && a <= 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(([r, v]) => {
501
- if (!r) return !1;
502
- const u = $(r);
503
- return u && e && ue(u, e);
504
- }).map(([r, v]) => {
505
- const u = $(r), m = Q(u), p = a >= u.x && a <= u.x + u.width && l >= u.y && l <= u.y + u.height, h = ve(u, e), L = ce(t, m);
506
- let b = 0;
507
- for (const [z, B] of n.visibleElements.value.entries())
508
- z !== r && z && r && k(r, z) && b++;
509
- return {
510
- element: v,
511
- node: r,
512
- isPointerInElement: p,
513
- overlapPercent: h,
514
- depth: b,
515
- centerDistance: L
516
- };
517
- }).sort((r, v) => {
518
- if (!o) {
519
- if (r.isPointerInElement && v.isPointerInElement)
520
- return v.depth - r.depth;
521
- if (r.isPointerInElement !== v.isPointerInElement)
522
- return r.isPointerInElement ? -1 : 1;
436
+ }, tt = (e) => {
437
+ const t = e.pointer.value?.current, n = t?.x ?? 0, s = t?.y ?? 0;
438
+ return et(n, s, 5);
439
+ }, I = (e, t, n) => {
440
+ const s = e.left + e.width / 2, i = e.top + e.height / 2;
441
+ if (n) {
442
+ const f = n.top ?? 0, u = n.right ?? 0, d = n.bottom ?? 0, g = n.left ?? 0, y = t.left + g, b = t.right - u, D = t.top + f, O = t.bottom - d;
443
+ if (y < b && D < O && s >= y && s <= b && i >= D && i <= O)
444
+ return { top: !1, right: !1, bottom: !1, left: !1, center: !0 };
445
+ }
446
+ const a = i - t.top, o = t.bottom - i, r = s - t.left, l = t.right - s, c = Math.min(a, o, r, l);
447
+ return {
448
+ top: a === c,
449
+ bottom: o === c,
450
+ left: r === c,
451
+ right: l === c
452
+ };
453
+ }, nt = (e, t) => e.find((n) => n !== t && B(t, n)), Q = (e, t, n) => {
454
+ const s = w(t.droppable), i = w(t.draggable);
455
+ t.draggable.clear(), t.droppable.clear();
456
+ const a = tt(e), o = n.zones[0], r = n.elements[0];
457
+ if (o && r && o === r && e.entities.droppableMap.has(o) && o) {
458
+ const u = o.getBoundingClientRect(), d = e.entities.draggableMap.get(o)?.placementMargins, g = I(a, u, d);
459
+ if (g.center) {
460
+ t.droppable.set(o, g);
461
+ const y = nt(n.elements, o);
462
+ if (y) {
463
+ const b = y.getBoundingClientRect();
464
+ t.draggable.set(
465
+ y,
466
+ I(a, b, void 0)
467
+ );
468
+ }
469
+ } else
470
+ t.draggable.set(r, g), t.droppable.set(o, g);
471
+ } else {
472
+ if (o) {
473
+ const u = o.getBoundingClientRect();
474
+ t.droppable.set(o, I(a, u));
523
475
  }
524
- return Math.abs(r.overlapPercent - v.overlapPercent) <= 1 ? r.centerDistance - v.centerDistance : v.overlapPercent - r.overlapPercent;
525
- }), c = Array.from(n.visibleZones.value.entries()).filter(([r, v]) => {
526
- if (!r || g.some(
527
- (m) => m && k(r, m)
528
- ))
529
- return !1;
530
- const u = $(r);
531
- return u && e && ue(u, e);
532
- }).map(([r, v]) => {
533
- const u = $(r), m = Q(u), p = a >= u.x && a <= u.x + u.width && l >= u.y && l <= u.y + u.height, h = ve(u, e), L = ce(t, m);
534
- let b = 0;
535
- for (const [z, B] of n.visibleZones.value.entries())
536
- z !== r && z && r && k(r, z) && b++;
537
- return {
538
- zone: v,
539
- node: r,
540
- isPointerInElement: p,
541
- overlapPercent: h,
542
- depth: b,
543
- centerDistance: L
544
- };
545
- }).sort((r, v) => {
546
- if (!o) {
547
- if (r.isPointerInElement && v.isPointerInElement)
548
- return v.depth - r.depth;
549
- if (r.isPointerInElement !== v.isPointerInElement)
550
- return r.isPointerInElement ? -1 : 1;
476
+ if (r) {
477
+ const u = r.getBoundingClientRect(), d = e.entities.draggableMap.get(r)?.placementMargins;
478
+ t.draggable.set(
479
+ r,
480
+ I(a, u, d)
481
+ );
551
482
  }
552
- return Math.abs(r.overlapPercent - v.overlapPercent) <= 1 ? r.centerDistance - v.centerDistance : v.overlapPercent - r.overlapPercent;
553
- });
554
- return [
555
- ...i.map((r) => r.node),
556
- ...c.map((r) => r.node)
557
- ];
558
- }, Te = (n, e) => {
559
- const { pointerPosition: t, keyboard: a } = Y(), l = (e == null ? void 0 : e.moveStep) || 10;
483
+ }
484
+ const c = w(t.droppable), f = w(t.draggable);
485
+ Xe(e, s, c), Ve(e, i, f);
486
+ }, st = (e, t) => e.x < t.x + t.width && e.x + e.width > t.x && e.y < t.y + t.height && e.y + e.height > t.y, oe = (e) => {
487
+ if (!e)
488
+ return { x: 0, y: 0, width: 0, height: 0, top: 0, left: 0, right: 0, bottom: 0 };
489
+ const t = e.getBoundingClientRect();
560
490
  return {
561
- onKeyboardStart: (i) => {
562
- var r;
563
- Z(i);
564
- const c = $(n.value);
565
- (r = n.value) == null || r.blur();
566
- const d = c.x + c.width / 2, f = c.y + c.height / 2;
567
- t.start.value = {
568
- x: d,
569
- y: f
570
- }, t.current.value = {
571
- x: d,
572
- y: f
573
- }, t.offset.pixel.value = {
574
- x: c.width / 2,
575
- y: c.height / 2
576
- }, t.offset.percent.value = {
577
- x: 50,
578
- y: 50
491
+ x: t.x,
492
+ y: t.y,
493
+ width: t.width,
494
+ height: t.height,
495
+ top: t.top,
496
+ left: t.left,
497
+ right: t.right,
498
+ bottom: t.bottom
499
+ };
500
+ }, re = (e) => ({
501
+ x: e.x + e.width / 2,
502
+ y: e.y + e.height / 2
503
+ }), it = (e, t) => Math.hypot(t.x - e.x, t.y - e.y), at = (e, t) => {
504
+ const n = Math.max(
505
+ 0,
506
+ Math.min(e.x + e.width, t.x + t.width) - Math.max(e.x, t.x)
507
+ ), s = Math.max(
508
+ 0,
509
+ Math.min(e.y + e.height, t.y + t.height) - Math.max(e.y, t.y)
510
+ ), i = n * s, a = e.width * e.height, o = t.width * t.height;
511
+ return a === 0 || o === 0 ? 0 : (i / a * 100 + i / o * 100) / 2;
512
+ }, ot = (e, t, n) => t >= e.x && t <= e.x + e.width && n >= e.y && n <= e.y + e.height, le = () => !0, ce = () => 0, rt = () => {
513
+ const e = {
514
+ filterElements: le,
515
+ filterZones: le,
516
+ sortElements: ce,
517
+ sortZones: ce
518
+ }, t = (s, i, a, o, r, l, c) => {
519
+ const f = new Set(o), u = { containerBox: i, pointer: a }, d = [...o].filter((g) => r(g, s)).map((g) => {
520
+ const y = oe(g);
521
+ if (!c(y, u)) return null;
522
+ let b = 0;
523
+ for (const D of f)
524
+ D !== g && B(D, g) && b++;
525
+ return {
526
+ node: g,
527
+ box: y,
528
+ meta: {
529
+ isPointerInElement: ot(y, a.x, a.y),
530
+ overlapPercent: at(y, i),
531
+ depth: b,
532
+ centerDistance: it(re(i), re(y))
533
+ }
579
534
  };
535
+ }).filter((g) => g !== null);
536
+ return d.sort((g, y) => l(g, y, u)), d.map((g) => g.node);
537
+ }, n = {
538
+ container(s) {
539
+ return e.container = s, n;
580
540
  },
581
- onKeyboardMove: () => {
582
- if (!t.current.value) return;
583
- const i = t.current.value.x, c = t.current.value.y;
584
- let d = i, f = c;
585
- a.w.value && (f -= l), a.s.value && (f += l), a.a.value && (d -= l), a.d.value && (d += l), t.current.value = {
586
- x: d,
587
- y: f
588
- };
541
+ containerBox(s) {
542
+ return e.containerBox = s, n;
589
543
  },
590
- onKeyboardEnd: () => {
591
- t.current.value = null, t.start.value = null, t.offset.pixel.value = null, t.offset.percent.value = null;
592
- }
593
- };
594
- }, Ze = (n) => {
595
- const e = Y();
596
- return {
597
- onPointerStart: (s) => {
598
- e.pointerPosition.start.value = { x: s.clientX, y: s.clientY }, e.pointerPosition.current.value = {
599
- x: s.clientX,
600
- y: s.clientY
601
- };
602
- const { pixel: o, percent: g } = _e(n.value, {
603
- x: s.clientX,
604
- y: s.clientY
605
- });
606
- e.pointerPosition.offset.pixel.value = o, e.pointerPosition.offset.percent.value = g;
544
+ elements(s) {
545
+ return e.elements = s, n;
607
546
  },
608
- onPointerMove: (s) => {
609
- e.isPending.value || (e.pointerPosition.current.value = {
610
- x: s.clientX,
611
- y: s.clientY
612
- });
547
+ zones(s) {
548
+ return e.zones = s, n;
613
549
  },
614
- onPointerEnd: () => {
615
- e.pointerPosition.current.value = null, e.pointerPosition.start.value = null, e.pointerPosition.offset.pixel.value = null, e.pointerPosition.offset.percent.value = null;
616
- }
617
- };
618
- }, Oe = (n, e) => {
619
- var B, D;
620
- const t = Y(), { onPointerStart: a, onPointerMove: l, onPointerEnd: s } = Ze(n), { onKeyboardStart: o, onKeyboardMove: g, onKeyboardEnd: i } = Te(
621
- n,
622
- e == null ? void 0 : e.keyboard
623
- );
624
- let c = null;
625
- const d = (w) => {
626
- var _, S;
627
- if (!w) return /* @__PURE__ */ new Map();
628
- const x = t.selectedElements.value.has(w);
629
- if (t.selectedElements.value.size > 0 && x) {
630
- const U = /* @__PURE__ */ new Map();
631
- return t.selectedElements.value.forEach((G) => {
632
- var A, K;
633
- const E = t.elementsMap.value.get(G);
634
- E && U.set(G, {
635
- ...E,
636
- initialHTML: ((A = E.node) == null ? void 0 : A.outerHTML) ?? "",
637
- initialRect: (K = E.node) == null ? void 0 : K.getBoundingClientRect()
638
- });
639
- }), U;
640
- }
641
- t.selectedElements.value.clear();
642
- const y = t.elementsMap.value.get(w);
643
- if (!y) return /* @__PURE__ */ new Map();
644
- const I = /* @__PURE__ */ new Map();
645
- return I.set(w, {
646
- ...y,
647
- initialHTML: ((_ = y.node) == null ? void 0 : _.outerHTML) ?? "",
648
- initialRect: (S = y.node) == null ? void 0 : S.getBoundingClientRect()
649
- }), I;
650
- }, f = (w) => {
651
- if (!w)
652
- return { element: null, zone: null };
653
- const x = Array.isArray(w) ? w : [w], y = Array.from(t.draggingElements.value.keys()), I = Array.from(t.zonesMap.value.entries()).flatMap(
654
- ([E, A]) => A.disabled ? [E] : []
655
- ), _ = Array.from(
656
- t.elementsMap.value.entries()
657
- ).flatMap(([E, A]) => A.disabled ? [E] : []), S = x.find((E) => {
658
- if (!t.visibleZones.value.has(E)) return !1;
659
- const A = t.zonesMap.value.get(E);
660
- return !(!A || A.disabled || I.some(
661
- (N) => E === N || k(E, N)
662
- ) || y.some(
663
- (N) => N && (N === A.node || k(A.node, N))
664
- ) || A.groups.length && !!Array.from(
665
- t.draggingElements.value.values()
666
- ).some((H) => H.groups.length ? !H.groups.some((T) => A.groups.includes(T)) : !1));
667
- });
668
- return S ? {
669
- element: x.filter((E) => {
670
- if (!t.visibleElements.value.has(E) || !t.elementsMap.value.has(E)) return !1;
671
- const A = t.elementsMap.value.get(E);
672
- if (A != null && A.disabled) return !1;
673
- const K = I.some(
674
- (T) => E === T || k(E, T)
675
- ), N = _.some(
676
- (T) => E === T || k(
677
- E,
678
- T
679
- )
680
- );
681
- return K || N ? !1 : !Array.from(
682
- t.draggingElements.value.values()
683
- ).some((T) => T.groups.length ? !T.groups.some(
684
- (W) => {
685
- var q;
686
- return (q = t.elementsMap.value.get(E)) == null ? void 0 : q.groups.includes(W);
687
- }
688
- ) : !1);
689
- }).find((E) => y.some(
690
- (K) => K && (K === E || k(E, K) || k(K, E))
691
- ) ? !1 : E === S || k(
692
- E,
693
- S
694
- )) || null,
695
- zone: S
696
- } : { element: null, zone: null };
697
- }, r = ((B = e == null ? void 0 : e.sensor) == null ? void 0 : B.setup) || Ke, v = (w) => {
698
- var S, U, G, E, A, K, N, H, T, W, q, ne;
699
- const x = t.hovered.element.value, y = t.hovered.zone.value, I = w.element, _ = w.zone;
700
- t.hovered.element.value = I, t.hovered.zone.value = _, x !== I && (x && ((G = (U = (S = t.elementsMap.value.get(x)) == null ? void 0 : S.events) == null ? void 0 : U.onLeave) == null || G.call(U, t, R(t))), I && ((K = (A = (E = t.elementsMap.value.get(I)) == null ? void 0 : E.events) == null ? void 0 : A.onHover) == null || K.call(A, t, R(t)))), y !== _ && (y && ((T = (H = (N = t.zonesMap.value.get(y)) == null ? void 0 : N.events) == null ? void 0 : H.onLeave) == null || T.call(H, t, R(t))), _ && ((ne = (q = (W = t.zonesMap.value.get(_)) == null ? void 0 : W.events) == null ? void 0 : q.onHover) == null || ne.call(q, t, R(t))));
701
- }, u = ze(() => {
702
- const w = r(t), x = f(w);
703
- v(x);
704
- }, ((D = e == null ? void 0 : e.sensor) == null ? void 0 : D.throttle) ?? 0), m = () => {
705
- u(), c = requestAnimationFrame(m);
706
- }, p = () => m(), h = () => {
707
- c !== null && (s(), i(), cancelAnimationFrame(c), c = null);
708
- };
709
- return {
710
- activate: (w) => {
711
- t.draggingElements.value = d(n.value), t.draggingElements.value.forEach(
712
- (x) => {
713
- var y, I;
714
- return (I = (y = x.events).onStart) == null ? void 0 : I.call(y, t, R(t));
715
- }
716
- ), w instanceof PointerEvent ? a(w) : o(w), p();
550
+ filterElements(s) {
551
+ return e.filterElements = s, n;
717
552
  },
718
- track: (w) => {
719
- t.draggingElements.value.forEach(
720
- (x) => {
721
- var y, I;
722
- return (I = (y = x.events).onMove) == null ? void 0 : I.call(y, t, R(t));
723
- }
724
- ), w instanceof KeyboardEvent ? g() : l(w);
553
+ filterZones(s) {
554
+ return e.filterZones = s, n;
725
555
  },
726
- deactivate: async (w = !0) => {
727
- var x, y;
728
- if (t.hovered.zone.value) {
729
- const I = t.zonesMap.value.get(t.hovered.zone.value), _ = (y = I == null ? void 0 : (x = I.events).onDrop) == null ? void 0 : y.call(x, t, R(t));
730
- if (_ instanceof Promise)
731
- try {
732
- t.isPending.value = !0;
733
- const S = await _;
734
- return S && (w && t.selectedElements.value.clear(), t.draggingElements.value.clear(), t.hovered.zone.value = null, t.hovered.element.value = null, h()), S;
735
- } catch {
736
- return !1;
737
- } finally {
738
- t.isPending.value = !1;
739
- }
740
- else
741
- w && t.selectedElements.value.clear(), t.draggingElements.value.clear(), t.hovered.zone.value = null, t.hovered.element.value = null, h();
742
- } else
743
- t.draggingElements.value.forEach(
744
- (I) => {
745
- var _, S;
746
- return (S = (_ = I.events).onEnd) == null ? void 0 : S.call(_, t, R(t));
747
- }
748
- ), w && t.selectedElements.value.clear(), t.draggingElements.value.clear(), t.hovered.zone.value = null, t.hovered.element.value = null, h();
556
+ collision(s) {
557
+ return e.collision = s, n;
558
+ },
559
+ sortElements(s) {
560
+ return e.sortElements = s, n;
561
+ },
562
+ sortZones(s) {
563
+ return e.sortZones = s, n;
564
+ },
565
+ build() {
566
+ const s = e;
567
+ if (!s.container || !s.elements || !s.zones || !s.collision)
568
+ throw new Error("sensor: container, elements, zones, collision are required");
569
+ return (i) => {
570
+ const a = s.container(i);
571
+ if (!a) return { elements: [], zones: [] };
572
+ const o = s.containerBox ? s.containerBox(i) : oe(a), r = i.pointer.value?.current ?? { x: 0, y: 0 };
573
+ return {
574
+ elements: t(
575
+ i,
576
+ o,
577
+ r,
578
+ s.elements(i),
579
+ s.filterElements,
580
+ s.sortElements,
581
+ s.collision
582
+ ),
583
+ zones: t(
584
+ i,
585
+ o,
586
+ r,
587
+ s.zones(i),
588
+ s.filterZones,
589
+ s.sortZones,
590
+ s.collision
591
+ )
592
+ };
593
+ };
749
594
  }
750
595
  };
751
- }, Ne = me(() => {
752
- let n = "", e = "", t = "", a = null, l = null, s = null, o = null, g = null;
753
- const { activeContainer: i, isPending: c, elementsMap: d } = Y(), f = () => {
754
- const m = document.body;
755
- n = m.style.userSelect, m.style.userSelect = "none", window.addEventListener("contextmenu", Z), window.addEventListener("selectstart", Z), window.addEventListener("touchstart", Z), window.addEventListener("touchmove", Z);
756
- }, r = () => {
757
- const m = document.body;
758
- m.style.userSelect = n, m.style.touchAction = e, m.style.overscrollBehavior = t, window.removeEventListener("contextmenu", Z), window.removeEventListener("selectstart", Z), window.removeEventListener("touchstart", Z), window.removeEventListener("touchmove", Z);
759
- }, v = () => {
760
- a && (document.removeEventListener("pointermove", a), a = 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);
761
- };
596
+ return n;
597
+ }, lt = () => rt(), ct = (e) => e.overlay.ref?.value ?? null, gt = (e) => {
598
+ const t = e.overlay.style?.value ?? { x: 0, y: 0 }, n = e.overlay.size?.value ?? null, { x: s, y: i } = t, a = n?.width ?? 0, o = n?.height ?? 0;
762
599
  return {
763
- handleDragStart: (m, p, h) => {
764
- if (!p.value || c.value) return;
765
- const L = d.value.get(p.value);
766
- if (L != null && L.disabled) return;
767
- v(), m.target.blur(), h != null && h.container && (i.component.value = h.container), h != null && h.containerProps && (i.props.value = h.containerProps);
768
- const { activate: b, track: z, deactivate: B } = Oe(p, h);
769
- l = () => {
770
- B(!0).then((D) => {
771
- D !== !1 && (i.component.value = null, r(), B(!0), v());
772
- });
773
- }, s = () => {
774
- i.component.value = null, r(), B(!1), v();
775
- }, a = (D) => z(D), o = (D) => z(D), g = (D) => {
776
- D.type === "keyup" && (D.code === "Escape" && (s == null || s()), D.code === "Enter" && (l == null || l())), z(D);
777
- }, f(), b(m), document.addEventListener("pointermove", a), document.addEventListener("pointerup", l), document.addEventListener("wheel", o), document.addEventListener("keydown", g), document.addEventListener("keypress", g), document.addEventListener("keyup", g);
778
- }
600
+ x: s,
601
+ y: i,
602
+ width: a,
603
+ height: o,
604
+ top: i,
605
+ left: s,
606
+ right: s + a,
607
+ bottom: i + o
779
608
  };
780
- }), Re = (n) => {
781
- const {
782
- id: e,
783
- elementRef: t,
784
- isDragging: a,
785
- isOvered: l,
786
- isAllowed: s,
787
- isLazyAllowed: o,
788
- registerElement: g,
789
- unregisterElement: i
790
- } = ke(n), { pointerPosition: c } = Y(), { handleDragStart: d } = Ne(), f = (r) => d(r, t, n);
791
- return te(g), ge(i), {
792
- pointerPosition: c,
793
- elementRef: t,
794
- isDragging: a,
795
- isOvered: l,
796
- isAllowed: s,
797
- isLazyAllowed: o,
798
- handleDragStart: f,
799
- id: e
609
+ }, ut = (e) => e.entities.visibleDraggableSet, ft = (e) => e.entities.visibleDroppableSet, dt = (e, t) => !t.entities.draggingMap.has(e), yt = (e, t) => ![...t.entities.draggingMap.keys()].some(
610
+ (n) => B(n, e)
611
+ ), bt = (e, t) => t.entities.draggableMap.has(e) ? !M(e, t) : t.entities.droppableMap.has(e) ? !L(e, t) : !0, ge = (e, t) => dt(e, t) && yt(e, t) && bt(e, t), mt = (e, t) => st(e, t.containerBox), ue = (e, t, n) => {
612
+ if (n.pointer.x >= n.containerBox.x && n.pointer.x <= n.containerBox.x + n.containerBox.width && n.pointer.y >= n.containerBox.y && n.pointer.y <= n.containerBox.y + n.containerBox.height) {
613
+ if (e.meta.isPointerInElement && t.meta.isPointerInElement)
614
+ return t.meta.depth - e.meta.depth;
615
+ if (e.meta.isPointerInElement !== t.meta.isPointerInElement)
616
+ return e.meta.isPointerInElement ? -1 : 1;
617
+ }
618
+ return Math.abs(e.meta.overlapPercent - t.meta.overlapPercent) <= 1 ? e.meta.centerDistance - t.meta.centerDistance : t.meta.overlapPercent - e.meta.overlapPercent;
619
+ }, ee = lt().container(ct).containerBox(gt).elements(ut).zones(ft).filterElements(ge).filterZones(ge).collision(mt).sortElements(ue).sortZones(ue).build();
620
+ function fe(e) {
621
+ const n = (e.collision?.run ?? ee)(e);
622
+ Q(e, e.hovered, n);
623
+ }
624
+ function ht(e, t) {
625
+ const n = e.collision?.throttle?.value ?? 0;
626
+ if (n <= 0) {
627
+ fe(e);
628
+ return;
629
+ }
630
+ const s = Date.now();
631
+ s - t.value >= n && (t.value = s, fe(e));
632
+ }
633
+ async function Me(e) {
634
+ const t = e.hovered.droppable.keys().next().value;
635
+ if (!t || L(t, e)) return !0;
636
+ const n = e.entities.droppableMap.get(t), s = {
637
+ payload: Ee(e),
638
+ provider: e
639
+ }, i = n?.events?.onDrop?.(s);
640
+ if (i != null && typeof i.then == "function")
641
+ try {
642
+ return await i, !0;
643
+ } catch {
644
+ const o = e.entities.initiatingDraggable;
645
+ return x(e, o, "onSelfDragCancel"), h(e, "onDragCancel"), ve(e, e.hovered), !1;
646
+ }
647
+ return !0;
648
+ }
649
+ function Se(e) {
650
+ const t = e.entities.initiatingDraggable;
651
+ x(e, t, "onSelfDragEnd"), h(e, "onDragEnd"), qe(e, e.hovered);
652
+ }
653
+ function Dt(e) {
654
+ const t = e.entities.selectingArea;
655
+ if (!t) return;
656
+ const n = e.entities.selectableAreaMap.get(t), s = [...e.entities.selectedSet];
657
+ n?.events?.onSelected?.(s);
658
+ }
659
+ const pt = (e) => {
660
+ const t = {
661
+ current: null
662
+ }, n = { value: 0 }, s = async () => {
663
+ j(), t.current?.cancel(), t.current = null;
664
+ const r = e.state.value;
665
+ if (r === "dragging") {
666
+ if (!await Me(e)) {
667
+ H(e), document.removeEventListener("pointerup", s), document.removeEventListener("pointermove", i);
668
+ return;
669
+ }
670
+ Se(e);
671
+ } else r === "selecting" && Dt(e);
672
+ H(e), document.removeEventListener("pointerup", s), document.removeEventListener("pointermove", i);
673
+ }, i = (r) => {
674
+ if (e.pointer.value) {
675
+ if (e.pointer.value.current = { x: r.clientX, y: r.clientY }, Ke(e)) {
676
+ Z(e, r, "onSelfDragStart"), h(e, "onDragStart");
677
+ return;
678
+ }
679
+ if (e.state.value === "dragging") {
680
+ ht(e, n);
681
+ const l = e.entities.initiatingDraggable;
682
+ x(e, l, "onSelfDragMove"), h(e, "onDragMove");
683
+ }
684
+ e.state.value === "selecting" && Je(e);
685
+ }
800
686
  };
801
- }, Ve = (n) => {
802
- const {
803
- zonesMap: e,
804
- hovered: t,
805
- draggingElements: a,
806
- isDragging: l,
807
- handleDropZoneIntersection: s
808
- } = Y(), o = F(null), g = O(
809
- () => t.zone.value === o.value
810
- ), i = O(() => {
811
- if (!o.value || !l.value) return !1;
812
- const r = e.value.get(o.value);
813
- return r != null && r.groups.length ? !Array.from(a.value.values()).some((v) => v.groups.length ? !v.groups.some(
814
- (u) => r.groups.includes(u)
815
- ) : !1) : !0;
816
- }), c = O(() => {
817
- if (!o.value || !l.value || t.zone.value !== o.value) return !1;
818
- const r = e.value.get(o.value);
819
- return r != null && r.groups.length ? !Array.from(a.value.values()).some((v) => !v.groups.some(
820
- (u) => r.groups.includes(u)
821
- )) : !0;
687
+ return { pointerDown: (r) => {
688
+ document.addEventListener("pointerup", s), document.addEventListener("pointermove", i);
689
+ const l = r.target, c = l.closest(
690
+ k.SELECT_AREA
691
+ ), f = l.closest(
692
+ k.DRAGGABLE
693
+ );
694
+ if (e.entities.modifiersSelectableAreaSet.size > 0 && e.entities.modifiersSelectableAreaSet.has(c)) {
695
+ W(), e.pointer.value = J(r), e.state.value = "selecting", e.entities.selectingArea = c;
696
+ return;
697
+ }
698
+ if (e.entities.modifiersDraggableSet.size > 0 && e.entities.modifiersDraggableSet.has(f)) {
699
+ const u = e.entities.draggableMap.get(f);
700
+ if (!De(l, f, u?.dragHandle))
701
+ return;
702
+ W(), e.entities.initiatingDraggable = f;
703
+ const d = me(r, f);
704
+ e.pointer.value = J(r, d.x, d.y), u?.activation?.distance || u?.activation?.delay ? (e.state.value = "activating", u?.activation?.delay && (e.delay.startTime = Date.now(), t.current = Ge(e, () => {
705
+ G(e), Z(e, r, "onSelfDragStart"), h(e, "onDragStart");
706
+ }))) : (G(e), Z(e, r, "onSelfDragStart"), h(e, "onDragStart"));
707
+ }
708
+ }, pointerUp: s, pointerMove: i, cleanup: () => {
709
+ t.current?.cancel(), document.removeEventListener("pointerup", s), document.removeEventListener("pointermove", i), e.lib.draggableObserver.disconnect(), e.lib.droppableObserver.disconnect(), e.lib.selectableAreaObserver.disconnect(), e.lib.overlaySizeObserver.disconnect();
710
+ } };
711
+ }, Et = {
712
+ ArrowUp: { dx: 0, dy: -1 },
713
+ ArrowDown: { dx: 0, dy: 1 },
714
+ ArrowLeft: { dx: -1, dy: 0 },
715
+ ArrowRight: { dx: 1, dy: 0 },
716
+ KeyW: { dx: 0, dy: -1 },
717
+ KeyA: { dx: -1, dy: 0 },
718
+ KeyS: { dx: 0, dy: 1 },
719
+ KeyD: { dx: 1, dy: 0 }
720
+ }, vt = (e) => (t) => {
721
+ const { keys: n } = e.keyboard;
722
+ if (n.pressedKeys.value.add(t.code), e.state.value === "dragging") {
723
+ if (n.forCancel.includes(t.code)) {
724
+ t.preventDefault(), j(), x(e, e.entities.initiatingDraggable, "onSelfDragCancel"), h(e, "onDragCancel"), ve(e, e.hovered), H(e);
725
+ return;
726
+ }
727
+ if (n.forDrop.includes(t.code)) {
728
+ t.preventDefault(), (async () => (await Me(e) && Se(e), j(), H(e)))();
729
+ return;
730
+ }
731
+ const i = Et[t.code];
732
+ if (i && n.forMove.includes(t.code) && e.pointer.value) {
733
+ t.preventDefault();
734
+ const a = n.forMoveFaster.some((c) => n.pressedKeys.value.has(c)), o = e.keyboard.step * (a ? e.keyboard.moveFaster : 1);
735
+ e.pointer.value.current = {
736
+ x: e.pointer.value.current.x + i.dx * o,
737
+ y: e.pointer.value.current.y + i.dy * o
738
+ };
739
+ const l = (e.collision?.run ?? ee)(e);
740
+ Q(e, e.hovered, l), x(e, e.entities.initiatingDraggable, "onSelfDragMove"), h(e, "onDragMove");
741
+ return;
742
+ }
743
+ return;
744
+ }
745
+ if (n.forDrag.includes(t.code)) {
746
+ const i = document.activeElement;
747
+ if (!i) return;
748
+ const a = i.closest(k.DRAGGABLE);
749
+ if (!a || e.entities.modifiersDraggableSet.size === 0 || !e.entities.modifiersDraggableSet.has(a))
750
+ return;
751
+ const o = e.entities.draggableMap.get(a);
752
+ if (!De(i, a, o?.dragHandle, !0)) return;
753
+ t.preventDefault(), W();
754
+ const r = a.getBoundingClientRect(), l = r.left + r.width / 2, c = r.top + r.height / 2, f = {
755
+ clientX: l,
756
+ clientY: c
757
+ };
758
+ e.entities.initiatingDraggable = a;
759
+ const u = me(f, a);
760
+ e.pointer.value = J(f, u.x, u.y), G(e);
761
+ const g = (e.collision?.run ?? ee)(e);
762
+ Q(e, e.hovered, g), x(e, a, "onSelfDragStart"), h(e, "onDragStart");
763
+ }
764
+ }, Mt = (e) => (t) => {
765
+ e.keyboard.keys.pressedKeys.value.delete(t.code);
766
+ }, St = (e) => () => {
767
+ e.keyboard.keys.pressedKeys.value.clear();
768
+ }, $ = {
769
+ keyDown: vt,
770
+ keyUp: Mt,
771
+ clear: St
772
+ }, At = (e) => () => {
773
+ e.state.value && (e.scrollPosition.x = window.scrollX, e.scrollPosition.y = window.scrollY);
774
+ }, wt = (e) => {
775
+ const t = pt(e), n = $.keyDown(e), s = $.keyUp(e), i = $.clear(e), a = At(e);
776
+ R(() => {
777
+ document.addEventListener("pointerdown", t.pointerDown), document.addEventListener("keydown", n), document.addEventListener("keyup", s), document.addEventListener("blur", i), document.addEventListener("scroll", a, !0);
778
+ }), P(() => {
779
+ document.removeEventListener("pointerdown", t.pointerDown), document.removeEventListener("pointerup", t.pointerUp), document.removeEventListener("pointermove", t.pointerMove), document.removeEventListener("keydown", n), document.removeEventListener("keyup", s), document.removeEventListener("blur", i), document.removeEventListener("scroll", a, !0), t.cleanup();
822
780
  });
781
+ }, U = () => {
782
+ const e = de(te);
783
+ if (!e) throw Error("DnD provider not found");
784
+ return e;
785
+ }, xt = () => {
786
+ const e = U();
823
787
  return {
824
- elementRef: o,
825
- registerZone: () => {
826
- if (!o.value) throw new Error("elementRef is not set");
827
- s("add", o.value), e.value.set(o.value, {
828
- node: o.value,
829
- groups: (n == null ? void 0 : n.groups) ?? [],
830
- events: (n == null ? void 0 : n.events) ?? {},
831
- data: (n == null ? void 0 : n.data) ?? void 0,
832
- disabled: (n == null ? void 0 : n.disabled) ?? !1
833
- }), o.value.setAttribute("data-dnd-droppable", "true");
834
- },
835
- unregisterZone: () => {
836
- o.value && (s("remove", o.value), e.value.delete(o.value));
837
- },
838
- isOvered: g,
839
- isAllowed: i,
840
- isLazyAllowed: c
841
- };
842
- }, Fe = (n) => {
843
- const {
844
- elementRef: e,
845
- registerZone: t,
846
- unregisterZone: a,
847
- isOvered: l,
848
- isAllowed: s,
849
- isLazyAllowed: o
850
- } = Ve(n);
851
- return te(t), ge(a), { elementRef: e, isOvered: l, isAllowed: s, isLazyAllowed: o };
852
- }, Xe = (n) => {
853
- const { selectedElements: e, elementsMap: t } = Y(), a = O(
854
- () => n.value ? e.value.has(n.value) : !1
855
- ), l = O(() => {
856
- if (!n.value) return !1;
857
- for (const c of e.value)
858
- if (c && k(c, n.value))
859
- return !0;
860
- return !1;
861
- }), s = O(() => {
862
- if (!n.value) return !1;
863
- for (const c of e.value)
864
- if (c && k(n.value, c))
865
- return !0;
866
- return !1;
867
- }), o = () => {
868
- n.value && e.value.delete(n.value);
869
- }, g = () => {
870
- if (!(!n.value || !t.value.get(n.value))) {
871
- if (l.value)
872
- for (const d of e.value)
873
- d && k(d, n.value) && e.value.delete(d);
874
- if (s.value)
875
- for (const d of e.value)
876
- d && k(n.value, d) && e.value.delete(d);
877
- e.value.add(n.value);
878
- }
788
+ overlay: e.overlay,
789
+ delay: e.delay,
790
+ distanceProgress: e.distanceProgress,
791
+ entities: e.entities,
792
+ pointer: e.pointer,
793
+ state: e.state,
794
+ scrollPosition: e.scrollPosition,
795
+ keyboard: e.keyboard,
796
+ hovered: e.hovered,
797
+ collision: e.collision
879
798
  };
799
+ }, Lt = /* @__PURE__ */ ye({
800
+ __name: "DefaultOverlay",
801
+ setup(e) {
802
+ const { entities: t, state: n, overlay: s } = xt();
803
+ return (i, a) => A(n) === "dragging" ? (p(), K("div", {
804
+ key: 0,
805
+ class: "dnd-kit-default-overlay",
806
+ style: se({
807
+ "--position-x": A(s).style.value.x + "px",
808
+ "--position-y": A(s).style.value.y + "px"
809
+ })
810
+ }, [
811
+ (p(!0), K(X, null, we(A(t).draggingMap, ([o, r]) => (p(), K(X, null, [
812
+ A(t).draggableMap.get(o)?.render ? (p(), V(q(A(t).draggableMap.get(o)?.render), {
813
+ key: 0,
814
+ class: "test"
815
+ })) : (p(), V(q(o.tagName), {
816
+ key: 1,
817
+ innerHTML: r.initialHTML,
818
+ class: "test",
819
+ style: se({
820
+ width: r.initialRect.width + "px",
821
+ height: r.initialRect.height + "px"
822
+ })
823
+ }, null, 8, ["innerHTML", "style"]))
824
+ ], 64))), 256))
825
+ ], 4)) : xe("", !0);
826
+ }
827
+ }), kt = /* @__PURE__ */ ye({
828
+ __name: "DnDProvider",
829
+ setup(e) {
830
+ const t = Le("overlayRef"), n = Ze(t);
831
+ wt(n);
832
+ const s = E(
833
+ () => n.overlay.render.value ?? Lt
834
+ );
835
+ return Ce(te, n), (i, a) => (p(), K(X, null, [
836
+ ie(i.$slots, "default"),
837
+ ke("div", {
838
+ ref_key: "overlayRef",
839
+ ref: t,
840
+ class: "dnd-kit-overlay-container"
841
+ }, [
842
+ ie(i.$slots, "overlay", { overlay: s.value }, () => [
843
+ (p(), V(q(s.value)))
844
+ ])
845
+ ], 512)
846
+ ], 64));
847
+ }
848
+ });
849
+ function Rt(e, t, n) {
850
+ const s = U();
851
+ let i, a, o;
852
+ return typeof t == "function" ? (i = {}, a = t) : (i = t ?? {}, a = n), R(() => {
853
+ o = N(e), o && (o.addEventListener("dragstart", m), o.addEventListener("drag", m), o.addEventListener("dragend", m), o.setAttribute(v.DRAGGABLE, ""), s.lib.draggableObserver.observe(o), s.entities.draggableMap.set(o, {
854
+ render: i.render,
855
+ disabled: i.disabled ?? !1,
856
+ groups: i.groups ?? [],
857
+ modifier: i.modifier,
858
+ events: i.events,
859
+ payload: a,
860
+ dragHandle: i.dragHandle,
861
+ activation: i.activation,
862
+ placementMargins: i.placementMargins
863
+ }));
864
+ }), P(() => {
865
+ o && (s.lib.draggableObserver.unobserve(o), s.entities.visibleDraggableSet.delete(o), s.entities.draggableMap.delete(o), s.entities.modifiersDraggableSet.delete(o));
866
+ }), {};
867
+ }
868
+ const Pt = (e, t) => {
869
+ const n = U(), s = E(() => e.value === n.entities.selectingArea);
870
+ let i = null;
871
+ R(() => {
872
+ i = N(e), i && (i.setAttribute(v.SELECT_AREA, ""), n.lib.selectableAreaObserver.observe(i), n.entities.selectableAreaMap.set(i, {
873
+ modifier: t?.modifier ?? {
874
+ keys: ["ControlLeft"],
875
+ method: "every"
876
+ },
877
+ events: t?.events,
878
+ disabled: t?.disabled ?? !1,
879
+ groups: t?.groups ?? []
880
+ }));
881
+ }), P(() => {
882
+ i && (n.lib.selectableAreaObserver.unobserve(i), n.entities.visibleSelectableAreaSet.delete(i), n.entities.modifiersSelectableAreaSet.delete(i), n.entities.selectableAreaMap.delete(i));
883
+ });
884
+ const a = E(() => {
885
+ n.scrollPosition.x, n.scrollPosition.y;
886
+ const o = n.pointer.value;
887
+ return !o || n.state.value !== "selecting" || !i ? {} : je(o.start, o.current, i);
888
+ });
880
889
  return {
881
- handleUnselect: o,
882
- handleSelect: g,
883
- handleToggleSelect: () => {
884
- n.value && (e.value.has(n.value) ? o() : g());
885
- },
886
- isSelected: a,
887
- isParentOfSelected: l
890
+ isSelecting: s,
891
+ style: a
888
892
  };
889
893
  };
894
+ function Bt(e, t) {
895
+ const n = de(te);
896
+ if (!n) throw Error("DnD provider not found");
897
+ let s = null;
898
+ return R(() => {
899
+ s = N(e), s && (s.setAttribute(v.CONSTRAINT_AREA, ""), n.entities.constraintsAreaMap.set(s, {
900
+ axis: t?.axis || "both",
901
+ restrictToArea: t?.restrictToArea || !1
902
+ }));
903
+ }), P(() => {
904
+ s && n.entities.constraintsAreaMap.delete(s);
905
+ }), {};
906
+ }
907
+ function Ot(e, t = {}) {
908
+ const n = U();
909
+ let s = null;
910
+ R(() => {
911
+ s = N(e), s && (s.setAttribute(v.DROPPABLE, ""), n.lib.droppableObserver.observe(s), n.entities.droppableMap.set(s, {
912
+ disabled: t.disabled ?? !1,
913
+ groups: t.groups ?? [],
914
+ events: t.events
915
+ }));
916
+ }), P(() => {
917
+ s && (n.lib.droppableObserver.unobserve(s), n.entities.visibleDroppableSet.delete(s), n.entities.droppableMap.delete(s));
918
+ });
919
+ }
890
920
  export {
891
- oe as DnDOperations,
892
- He as default,
893
- $ as getBoundingBox,
894
- Y as useDnDStore,
895
- Ce as useDragContainer,
896
- Re as useDraggable,
897
- Fe as useDroppable,
898
- Xe as useSelection
921
+ kt as DnDProvider,
922
+ Bt as makeBoundingBox,
923
+ Rt as makeDraggable,
924
+ Ot as makeDroppable,
925
+ Pt as makeSelectableArea,
926
+ xt as useDnDProvider
899
927
  };
900
928
  //# sourceMappingURL=vue-dnd-kit-core.es.js.map