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