@vue-dnd-kit/core 0.1.5-beta → 0.2.5-beta

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.
@@ -1,196 +1,85 @@
1
- import { effectScope as ge, getCurrentScope as me, onScopeDispose as he, isRef as pe, toValue as K, computed as P, shallowRef as ce, watch as ve, getCurrentInstance as Ee, onMounted as N, ref as D, onBeforeUnmount as W, defineComponent as de, createElementBlock as F, createCommentVNode as ye, unref as re, openBlock as H, normalizeStyle as oe, Fragment as we, renderList as Pe, createBlock as De, resolveDynamicComponent as _e, createVNode as xe, render as le, markRaw as Ie } from "vue";
2
- function Le(t) {
3
- return me() ? (he(t), !0) : !1;
1
+ import { effectScope as G, isRef as W, toValue as J, ref as y, computed as I, onMounted as V, onBeforeUnmount as H, defineComponent as q, createElementBlock as z, createCommentVNode as Q, unref as U, openBlock as k, normalizeStyle as Y, Fragment as B, renderList as ee, createBlock as te, resolveDynamicComponent as ne, createVNode as re, render as F, markRaw as le } from "vue";
2
+ function oe(e) {
3
+ let t = !1, n;
4
+ const i = G(!0);
5
+ return (...a) => (t || (n = i.run(() => e(...a)), t = !0), n);
4
6
  }
5
- function Se(t) {
6
- let e = !1, r;
7
- const o = ge(!0);
8
- return (...u) => (e || (r = o.run(() => t(...u)), e = !0), r);
9
- }
10
- const Me = typeof window < "u" && typeof document < "u";
11
7
  typeof WorkerGlobalScope < "u" && globalThis instanceof WorkerGlobalScope;
12
- const Ce = (t) => t != null, b = () => {
8
+ const N = () => {
13
9
  };
14
- function Oe(t, e) {
15
- function r(...o) {
16
- return new Promise((u, n) => {
17
- Promise.resolve(t(() => e.apply(this, o), { fn: e, thisArg: this, args: o })).then(u).catch(n);
10
+ function ie(e, t) {
11
+ function n(...i) {
12
+ return new Promise((a, l) => {
13
+ Promise.resolve(e(() => t.apply(this, i), { fn: t, thisArg: this, args: i })).then(a).catch(l);
18
14
  });
19
15
  }
20
- return r;
16
+ return n;
21
17
  }
22
- function Te(...t) {
23
- let e = 0, r, o = !0, u = b, n, s, g, v, y;
24
- !pe(t[0]) && typeof t[0] == "object" ? { delay: s, trailing: g = !0, leading: v = !0, rejectOnCancel: y = !1 } = t[0] : [s, g = !0, v = !0, y = !1] = t;
25
- const l = () => {
26
- r && (clearTimeout(r), r = void 0, u(), u = b);
18
+ function se(...e) {
19
+ let t = 0, n, i = !0, a = N, l, s, d, v, h;
20
+ !W(e[0]) && typeof e[0] == "object" ? { delay: s, trailing: d = !0, leading: v = !0, rejectOnCancel: h = !1 } = e[0] : [s, d = !0, v = !0, h = !1] = e;
21
+ const u = () => {
22
+ n && (clearTimeout(n), n = void 0, a(), a = N);
27
23
  };
28
- return (E) => {
29
- const m = K(s), w = Date.now() - e, i = () => n = E();
30
- return l(), m <= 0 ? (e = Date.now(), i()) : (w > m && (v || !o) ? (e = Date.now(), i()) : g && (n = new Promise((d, f) => {
31
- u = y ? f : d, r = setTimeout(() => {
32
- e = Date.now(), o = !0, d(i()), l();
33
- }, Math.max(0, m - w));
34
- })), !v && !r && (r = setTimeout(() => o = !0, m)), o = !1, n);
24
+ return (r) => {
25
+ const o = J(s), f = Date.now() - t, p = () => l = r();
26
+ return u(), o <= 0 ? (t = Date.now(), p()) : (f > o && (v || !i) ? (t = Date.now(), p()) : d && (l = new Promise((D, x) => {
27
+ a = h ? x : D, n = setTimeout(() => {
28
+ t = Date.now(), i = !0, D(p()), u();
29
+ }, Math.max(0, o - f));
30
+ })), !v && !n && (n = setTimeout(() => i = !0, o)), i = !1, l);
35
31
  };
36
32
  }
37
- function Ae(t) {
38
- return Array.isArray(t) ? t : [t];
39
- }
40
- function ke(t, e = 200, r = !1, o = !0, u = !1) {
41
- return Oe(
42
- Te(e, r, o, u),
43
- t
33
+ function ae(e, t = 200, n = !1, i = !0, a = !1) {
34
+ return ie(
35
+ se(t, n, i, a),
36
+ e
44
37
  );
45
38
  }
46
- const Re = Me ? window : void 0;
47
- function Z(t) {
48
- var e;
49
- const r = K(t);
50
- return (e = r == null ? void 0 : r.$el) != null ? e : r;
51
- }
52
- function Ve() {
53
- const t = ce(!1), e = Ee();
54
- return e && N(() => {
55
- t.value = !0;
56
- }, e), t;
57
- }
58
- function be(t) {
59
- const e = Ve();
60
- return P(() => (e.value, !!t()));
61
- }
62
- function ze(t, e, r = {}) {
63
- const {
64
- root: o,
65
- rootMargin: u = "0px",
66
- threshold: n = 0,
67
- window: s = Re,
68
- immediate: g = !0
69
- } = r, v = be(() => s && "IntersectionObserver" in s), y = P(() => {
70
- const w = K(t);
71
- return Ae(w).map(Z).filter(Ce);
72
- });
73
- let l = b;
74
- const p = ce(g), E = v.value ? ve(
75
- () => [y.value, Z(o), p.value],
76
- ([w, i]) => {
77
- if (l(), !p.value || !w.length)
78
- return;
79
- const d = new IntersectionObserver(
80
- e,
81
- {
82
- root: Z(i),
83
- rootMargin: u,
84
- threshold: n
85
- }
86
- );
87
- w.forEach((f) => f && d.observe(f)), l = () => {
88
- d.disconnect(), l = b;
89
- };
90
- },
91
- { immediate: g, flush: "post" }
92
- ) : b, m = () => {
93
- l(), E(), p.value = !1;
94
- };
95
- return Le(m), {
96
- isSupported: v,
97
- isActive: p,
98
- pause() {
99
- l(), p.value = !1;
100
- },
101
- resume() {
102
- p.value = !0;
103
- },
104
- stop: m
105
- };
106
- }
107
- const C = Se(() => {
108
- const t = D([]), e = P(() => t.value.length > 0), r = {
109
- component: D(null),
110
- ref: D(null)
111
- }, o = D([]), u = P(() => {
112
- const m = /* @__PURE__ */ new Map();
113
- return o.value.forEach((w, i) => {
114
- w.node && m.set(w.node, i);
115
- }), m;
116
- }), n = D(/* @__PURE__ */ new Set()), s = P(
117
- () => Array.from(n.value).sort((m, w) => m - w)
118
- ), g = P(
119
- () => o.value.filter((m) => m.node).map((m) => m.node)
120
- );
121
- ve(
122
- () => g.value.length,
123
- (m) => {
124
- if (m === 0) return;
125
- v && (v(), v = null);
126
- const { stop: w } = ze(
127
- g,
128
- (i) => {
129
- let d = !1;
130
- i.forEach((f) => {
131
- const h = f.target, _ = u.value.get(h);
132
- _ !== void 0 && o.value[_].isVisible !== f.isIntersecting && (o.value[_].isVisible = f.isIntersecting, d = !0, f.isIntersecting ? n.value.add(_) : n.value.delete(_));
133
- }), d && (n.value = new Set(n.value));
134
- },
135
- {
136
- threshold: 0.1,
137
- // Элемент считается видимым, если видно хотя бы 10%
138
- immediate: !0
139
- }
140
- );
141
- v = w;
142
- },
143
- { immediate: !0 }
144
- );
145
- let v = null;
146
- const y = D([]), l = D([]), p = {
147
- zone: D(null),
148
- element: D(null)
149
- }, E = {
150
- current: D(null),
151
- start: D(null),
39
+ const T = oe(() => {
40
+ const e = y([]), t = I(() => e.value.length > 0), n = {
41
+ component: y(null),
42
+ ref: y(null)
43
+ }, i = y([]), a = y([]), l = y([]), s = {
44
+ zone: y(null),
45
+ element: y(null)
46
+ }, d = {
47
+ current: y(null),
48
+ start: y(null),
152
49
  offset: {
153
- percent: D(null),
154
- pixel: D(null)
50
+ percent: y(null),
51
+ pixel: y(null)
155
52
  }
156
53
  };
157
54
  return {
158
- isDragging: e,
159
- activeContainer: r,
160
- elements: o,
161
- draggingElements: t,
162
- selectedElements: y,
55
+ isDragging: t,
56
+ activeContainer: n,
57
+ elements: i,
58
+ draggingElements: e,
59
+ selectedElements: a,
163
60
  zones: l,
164
- visibleElements: s,
165
- // Теперь это computed свойство
166
- hovered: p,
167
- pointerPosition: E,
168
- // Экспортируем Map для быстрого доступа
169
- elementNodeMap: u,
170
- // Добавляем метод для очистки ресурсов
171
- cleanup: () => {
172
- v && (v(), v = null);
173
- }
61
+ hovered: s,
62
+ pointerPosition: d
174
63
  };
175
- }), He = () => {
176
- const t = D(null), { draggingElements: e, pointerPosition: r, isDragging: o, activeContainer: u } = C();
177
- return N(() => {
178
- u.ref = t;
179
- }), W(() => {
180
- u.ref.value = null;
64
+ }), ue = () => {
65
+ const e = y(null), { draggingElements: t, pointerPosition: n, isDragging: i, activeContainer: a } = T();
66
+ return V(() => {
67
+ a.ref = e;
68
+ }), H(() => {
69
+ a.ref.value = null;
181
70
  }), {
182
- elementRef: t,
183
- draggingElements: e,
184
- pointerPosition: r,
185
- isDragging: o
71
+ elementRef: e,
72
+ draggingElements: t,
73
+ pointerPosition: n,
74
+ isDragging: i
186
75
  };
187
- }, Ne = ["innerHTML"], Ue = /* @__PURE__ */ de({
76
+ }, ce = ["innerHTML"], de = /* @__PURE__ */ q({
188
77
  __name: "DefaultOverlay",
189
- setup(t) {
190
- const { elementRef: e, pointerPosition: r, isDragging: o, draggingElements: u } = He(), n = P(() => {
191
- var s, g, v, y;
78
+ setup(e) {
79
+ const { elementRef: t, pointerPosition: n, isDragging: i, draggingElements: a } = ue(), l = I(() => {
80
+ var s, d, v, h;
192
81
  return {
193
- transform: `translate3d(${(((s = r.current.value) == null ? void 0 : s.x) ?? 0) - (((g = r.offset.pixel.value) == null ? void 0 : g.x) ?? 0)}px, ${(((v = r.current.value) == null ? void 0 : v.y) ?? 0) - (((y = r.offset.pixel.value) == null ? void 0 : y.y) ?? 0)}px, 0)`,
82
+ transform: `translate3d(${(((s = n.current.value) == null ? void 0 : s.x) ?? 0) - (((d = n.offset.pixel.value) == null ? void 0 : d.x) ?? 0)}px, ${(((v = n.current.value) == null ? void 0 : v.y) ?? 0) - (((h = n.offset.pixel.value) == null ? void 0 : h.y) ?? 0)}px, 0)`,
194
83
  zIndex: 1e3,
195
84
  position: "fixed",
196
85
  top: 0,
@@ -198,123 +87,122 @@ const C = Se(() => {
198
87
  transition: "0.3s cubic-bezier(0.165, 0.84, 0.44, 1)"
199
88
  };
200
89
  });
201
- return (s, g) => re(o) ? (H(), F("div", {
90
+ return (s, d) => U(i) ? (k(), z("div", {
202
91
  key: 0,
203
92
  ref_key: "elementRef",
204
- ref: e,
205
- style: oe(n.value)
93
+ ref: t,
94
+ style: Y(l.value)
206
95
  }, [
207
- (H(!0), F(we, null, Pe(re(u), (v, y) => {
208
- var l, p;
209
- return H(), F("div", {
210
- key: y,
96
+ (k(!0), z(B, null, ee(U(a), (v, h) => {
97
+ var u, E;
98
+ return k(), z("div", {
99
+ key: h,
211
100
  innerHTML: v.initialHTML,
212
- style: oe({
213
- width: `${(l = v.initialRect) == null ? void 0 : l.width}px`,
214
- height: `${(p = v.initialRect) == null ? void 0 : p.height}px`
101
+ style: Y({
102
+ width: `${(u = v.initialRect) == null ? void 0 : u.width}px`,
103
+ height: `${(E = v.initialRect) == null ? void 0 : E.height}px`
215
104
  })
216
- }, null, 12, Ne);
105
+ }, null, 12, ce);
217
106
  }), 128))
218
- ], 4)) : ye("", !0);
107
+ ], 4)) : Q("", !0);
219
108
  }
220
- }), ie = /* @__PURE__ */ de({
109
+ }), Z = /* @__PURE__ */ q({
221
110
  __name: "DragOverlay",
222
- setup(t) {
223
- const { activeContainer: e } = C(), r = P(
224
- () => e.component.value ?? Ue
111
+ setup(e) {
112
+ const { activeContainer: t } = T(), n = I(
113
+ () => t.component.value ?? de
225
114
  );
226
- return (o, u) => (H(), De(_e(r.value)));
115
+ return (i, a) => (k(), te(ne(n.value)));
227
116
  }
228
- }), qe = {
229
- install(t) {
230
- t.component("DragOverlay", ie);
231
- const e = t.mount;
232
- t.mount = function(o) {
233
- const u = e.call(this, o), n = typeof o == "string" ? document.querySelector(o) : o;
234
- if (n && n instanceof Element && !n.querySelector("#vue-dnd-kit-overlay")) {
117
+ }), Pe = {
118
+ install(e) {
119
+ e.component("DragOverlay", Z);
120
+ const t = e.mount;
121
+ e.mount = function(i) {
122
+ const a = t.call(this, i), l = typeof i == "string" ? document.querySelector(i) : i;
123
+ if (l && l instanceof Element && !l.querySelector("#vue-dnd-kit-overlay")) {
235
124
  const s = document.createElement("div");
236
- s.id = "vue-dnd-kit-overlay", s.style.pointerEvents = "none", n.appendChild(s);
237
- const g = xe(ie);
238
- le(g, s), t.__VUE_DND_KIT_OVERLAY__ = {
125
+ s.id = "vue-dnd-kit-overlay", s.style.pointerEvents = "none", l.appendChild(s);
126
+ const d = re(Z);
127
+ F(d, s), e.__VUE_DND_KIT_OVERLAY__ = {
239
128
  container: s,
240
- vnode: g
129
+ vnode: d
241
130
  };
242
131
  }
243
- return u;
132
+ return a;
244
133
  };
245
- const r = t.unmount;
246
- t.unmount = function() {
247
- return t.__VUE_DND_KIT_OVERLAY__ && (le(null, t.__VUE_DND_KIT_OVERLAY__.container), delete t.__VUE_DND_KIT_OVERLAY__), r.call(this);
134
+ const n = e.unmount;
135
+ e.unmount = function() {
136
+ return e.__VUE_DND_KIT_OVERLAY__ && (F(null, e.__VUE_DND_KIT_OVERLAY__.container), delete e.__VUE_DND_KIT_OVERLAY__), n.call(this);
248
137
  };
249
138
  }
250
- }, se = "data-vue-dnd-kit-draggable", I = (t) => {
251
- t.preventDefault();
252
- }, Ye = (t) => {
139
+ }, b = "data-vue-dnd-kit-draggable", L = (e) => {
140
+ e.preventDefault();
141
+ }, ve = (e) => {
253
142
  const {
254
- elements: e,
255
- draggingElements: r,
256
- hovered: o,
257
- selectedElements: u,
258
- isDragging: n
259
- } = C(), s = D(null), g = P(
143
+ elements: t,
144
+ draggingElements: n,
145
+ hovered: i,
146
+ selectedElements: a,
147
+ isDragging: l
148
+ } = T(), s = y(null), d = I(
260
149
  () => {
261
- var E;
262
- return ((E = o.element.value) == null ? void 0 : E.node) === s.value;
150
+ var r;
151
+ return ((r = i.element.value) == null ? void 0 : r.node) === s.value;
263
152
  }
264
- ), v = P(
265
- () => r.value.some((E) => E.node === s.value)
266
- ), y = P(() => {
267
- if (!s.value || !n.value) return !1;
268
- const E = e.value.find(
269
- (m) => m.node === s.value
153
+ ), v = I(
154
+ () => n.value.some((r) => r.node === s.value)
155
+ ), h = I(() => {
156
+ if (!s.value || !l.value) return !1;
157
+ const r = t.value.find(
158
+ (o) => o.node === s.value
270
159
  );
271
- return E != null && E.groups.length ? !r.value.some((m) => m.groups.length ? !m.groups.some(
272
- (w) => E.groups.includes(w)
160
+ return r != null && r.groups.length ? !n.value.some((o) => o.groups.length ? !o.groups.some(
161
+ (f) => r.groups.includes(f)
273
162
  ) : !1) : !0;
274
163
  });
275
164
  return {
276
165
  elementRef: s,
277
166
  registerElement: () => {
278
167
  if (!s.value) throw new Error("ElementRef is not set");
279
- e.value.push({
168
+ t.value.push({
280
169
  node: s.value,
281
- groups: (t == null ? void 0 : t.groups) ?? [],
282
- layer: (t == null ? void 0 : t.layer) ?? null,
283
- defaultLayer: (t == null ? void 0 : t.layer) ?? null,
284
- events: (t == null ? void 0 : t.events) ?? {},
285
- data: (t == null ? void 0 : t.data) ?? void 0,
286
- isVisible: !1
287
- }), s.value.addEventListener("dragstart", I), s.value.addEventListener("drag", I), s.value.setAttribute(se, "true"), s.value.setAttribute("draggable", "false");
170
+ groups: (e == null ? void 0 : e.groups) ?? [],
171
+ layer: (e == null ? void 0 : e.layer) ?? null,
172
+ defaultLayer: (e == null ? void 0 : e.layer) ?? null,
173
+ events: (e == null ? void 0 : e.events) ?? {},
174
+ data: (e == null ? void 0 : e.data) ?? void 0
175
+ }), s.value.addEventListener("dragstart", L), s.value.addEventListener("drag", L), s.value.setAttribute(b, "true"), s.value.setAttribute("draggable", "false"), s.value.style.touchAction = "none";
288
176
  },
289
177
  unregisterElement: () => {
290
- var w, i, d, f;
291
- const E = e.value.findIndex(
292
- (h) => h.node === s.value
178
+ var f, p, D, x;
179
+ const r = t.value.findIndex(
180
+ (c) => c.node === s.value
293
181
  );
294
- E !== -1 && e.value.splice(E, 1);
295
- const m = u.value.findIndex(
296
- (h) => h.node === s.value
182
+ r !== -1 && t.value.splice(r, 1);
183
+ const o = a.value.findIndex(
184
+ (c) => c.node === s.value
297
185
  );
298
- m !== -1 && u.value.splice(m, 1), (w = s.value) == null || w.removeEventListener("dragstart", I), (i = s.value) == null || i.removeEventListener("drag", I), (d = s.value) == null || d.removeAttribute(se), (f = s.value) == null || f.removeAttribute("draggable");
186
+ o !== -1 && a.value.splice(o, 1), (f = s.value) == null || f.removeEventListener("dragstart", L), (p = s.value) == null || p.removeEventListener("drag", L), (D = s.value) == null || D.removeAttribute(b), (x = s.value) == null || x.removeAttribute("draggable");
299
187
  },
300
188
  isDragging: v,
301
- isOvered: g,
302
- isAllowed: y
189
+ isOvered: d,
190
+ isAllowed: h
303
191
  };
304
- }, Fe = () => {
305
- let t = "", e = "", r = "";
192
+ }, ge = () => {
193
+ let e = "", t = "", n = "";
306
194
  return {
307
195
  disableInteractions: () => {
308
- const n = document.body;
309
- t = n.style.userSelect, e = n.style.touchAction, r = n.style.overscrollBehavior, n.style.userSelect = "none", n.style.touchAction = "none", n.style.overscrollBehavior = "none", window.addEventListener("contextmenu", I), window.addEventListener("selectstart", I), window.addEventListener("touchstart", I), window.addEventListener("touchmove", I);
196
+ const l = document.body;
197
+ e = l.style.userSelect, l.style.userSelect = "none", window.addEventListener("contextmenu", L), window.addEventListener("selectstart", L), window.addEventListener("touchstart", L), window.addEventListener("touchmove", L);
310
198
  },
311
199
  enableInteractions: () => {
312
- const n = document.body;
313
- n.style.userSelect = t, n.style.touchAction = e, n.style.overscrollBehavior = r, window.removeEventListener("contextmenu", I), window.removeEventListener("selectstart", I), window.removeEventListener("touchstart", I), window.removeEventListener("touchmove", I);
200
+ const l = document.body;
201
+ l.style.userSelect = e, l.style.touchAction = t, l.style.overscrollBehavior = n, window.removeEventListener("contextmenu", L), window.removeEventListener("selectstart", L), window.removeEventListener("touchstart", L), window.removeEventListener("touchmove", L);
314
202
  }
315
203
  };
316
- }, ae = (t, e) => t.x < e.x + e.width && t.x + t.width > e.x && t.y < e.y + e.height && t.y + t.height > e.y, k = (t) => {
317
- if (!t)
204
+ }, K = (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, R = (e) => {
205
+ if (!e)
318
206
  return {
319
207
  x: 0,
320
208
  y: 0,
@@ -325,277 +213,308 @@ const C = Se(() => {
325
213
  right: 0,
326
214
  top: 0
327
215
  };
328
- const e = t.getBoundingClientRect();
216
+ const t = e.getBoundingClientRect();
329
217
  return {
330
- bottom: e.bottom,
331
- left: e.left,
332
- right: e.right,
333
- top: e.top,
334
- x: e.x,
335
- y: e.y,
336
- width: e.width,
337
- height: e.height
218
+ bottom: t.bottom,
219
+ left: t.left,
220
+ right: t.right,
221
+ top: t.top,
222
+ x: t.x,
223
+ y: t.y,
224
+ width: t.width,
225
+ height: t.height
338
226
  };
339
- }, $ = (t) => ({
340
- x: t.x + t.width / 2,
341
- y: t.y + t.height / 2
342
- }), Ze = (t, e) => {
343
- const r = k(t);
227
+ }, A = (e) => ({
228
+ x: e.x + e.width / 2,
229
+ y: e.y + e.height / 2
230
+ }), fe = (e, t) => {
231
+ const n = R(e);
344
232
  return {
345
233
  pixel: {
346
- x: e.x - r.x,
347
- y: e.y - r.y
234
+ x: t.x - n.x,
235
+ y: t.y - n.y
348
236
  },
349
237
  percent: {
350
- x: (e.x - r.x) / r.width * 100,
351
- y: (e.y - r.y) / r.height * 100
238
+ x: (t.x - n.x) / n.width * 100,
239
+ y: (t.y - n.y) / n.height * 100
352
240
  }
353
241
  };
354
- }, ue = (t, e) => {
355
- const r = e.x - t.x, o = e.y - t.y;
356
- return Math.sqrt(r * r + o * o);
357
- }, M = (t, e) => t ? e.contains(t) : !1, $e = (t) => {
358
- const e = C();
242
+ }, X = (e, t) => {
243
+ const n = t.x - e.x, i = t.y - e.y;
244
+ return Math.sqrt(n * n + i * i);
245
+ }, $ = (e, t) => {
246
+ const n = Math.max(
247
+ 0,
248
+ Math.min(e.x + e.width, t.x + t.width) - Math.max(e.x, t.x)
249
+ ), i = Math.max(
250
+ 0,
251
+ Math.min(e.y + e.height, t.y + t.height) - Math.max(e.y, t.y)
252
+ ), a = n * i, l = e.width * e.height, s = t.width * t.height;
253
+ return (a / l * 100 + a / s * 100) / 2;
254
+ }, M = (e, t) => e ? t.contains(e) : !1, me = (e) => {
255
+ var u, E;
256
+ const t = R(e.activeContainer.ref.value), n = A(t), i = ((u = e.pointerPosition.current.value) == null ? void 0 : u.x) ?? 0, a = ((E = e.pointerPosition.current.value) == null ? void 0 : E.y) ?? 0, s = !(t && i >= t.x && i <= t.x + t.width && a >= t.y && a <= t.y + t.height), d = e.draggingElements.value.map((r) => r.node), v = e.elements.value.filter((r) => {
257
+ if (!r.node || d.some(
258
+ (f) => f && M(r.node, f)
259
+ ))
260
+ return !1;
261
+ const o = R(r.node);
262
+ return o && t && K(o, t);
263
+ }).map((r) => {
264
+ const o = R(r.node), f = A(o), p = i >= o.x && i <= o.x + o.width && a >= o.y && a <= o.y + o.height, D = $(o, t), x = X(n, f), c = e.elements.value.filter(
265
+ (g) => g !== r && g.node && r.node && M(r.node, g.node)
266
+ ).length;
267
+ return {
268
+ element: r,
269
+ node: r.node,
270
+ isPointerInElement: p,
271
+ overlapPercent: D,
272
+ depth: c,
273
+ centerDistance: x
274
+ };
275
+ }).sort((r, o) => {
276
+ if (!s) {
277
+ if (r.isPointerInElement && o.isPointerInElement)
278
+ return o.depth - r.depth;
279
+ if (r.isPointerInElement !== o.isPointerInElement)
280
+ return r.isPointerInElement ? -1 : 1;
281
+ }
282
+ return Math.abs(r.overlapPercent - o.overlapPercent) <= 1 ? r.centerDistance - o.centerDistance : o.overlapPercent - r.overlapPercent;
283
+ }), h = e.zones.value.filter((r) => {
284
+ if (!r.node || d.some(
285
+ (f) => f && M(r.node, f)
286
+ ))
287
+ return !1;
288
+ const o = R(r.node);
289
+ return o && t && K(o, t);
290
+ }).map((r) => {
291
+ const o = R(r.node), f = A(o), p = i >= o.x && i <= o.x + o.width && a >= o.y && a <= o.y + o.height, D = $(o, t), x = X(n, f), c = e.zones.value.filter(
292
+ (g) => g !== r && g.node && r.node && M(r.node, g.node)
293
+ ).length;
294
+ return {
295
+ zone: r,
296
+ node: r.node,
297
+ isPointerInElement: p,
298
+ overlapPercent: D,
299
+ depth: c,
300
+ centerDistance: x
301
+ };
302
+ }).sort((r, o) => {
303
+ if (!s) {
304
+ if (r.isPointerInElement && o.isPointerInElement)
305
+ return o.depth - r.depth;
306
+ if (r.isPointerInElement !== o.isPointerInElement)
307
+ return r.isPointerInElement ? -1 : 1;
308
+ }
309
+ return Math.abs(r.overlapPercent - o.overlapPercent) <= 1 ? r.centerDistance - o.centerDistance : o.overlapPercent - r.overlapPercent;
310
+ });
311
+ return [
312
+ ...v.map((r) => r.node),
313
+ ...h.map((r) => r.node)
314
+ ];
315
+ }, he = (e) => {
316
+ const t = T();
359
317
  return {
360
- onPointerStart: (n) => {
361
- e.pointerPosition.start.value = { x: n.clientX, y: n.clientY }, e.pointerPosition.current.value = {
362
- x: n.clientX,
363
- y: n.clientY
318
+ onPointerStart: (l) => {
319
+ t.pointerPosition.start.value = { x: l.clientX, y: l.clientY }, t.pointerPosition.current.value = {
320
+ x: l.clientX,
321
+ y: l.clientY
364
322
  };
365
- const { pixel: s, percent: g } = Ze(t.value, {
366
- x: n.clientX,
367
- y: n.clientY
323
+ const { pixel: s, percent: d } = fe(e.value, {
324
+ x: l.clientX,
325
+ y: l.clientY
368
326
  });
369
- e.pointerPosition.offset.pixel.value = s, e.pointerPosition.offset.percent.value = g;
327
+ t.pointerPosition.offset.pixel.value = s, t.pointerPosition.offset.percent.value = d;
370
328
  },
371
- onPointerMove: (n) => {
372
- e.pointerPosition.current.value = {
373
- x: n.clientX,
374
- y: n.clientY
329
+ onPointerMove: (l) => {
330
+ t.pointerPosition.current.value = {
331
+ x: l.clientX,
332
+ y: l.clientY
375
333
  };
376
334
  },
377
335
  onPointerEnd: () => {
378
- e.pointerPosition.current.value = null, e.pointerPosition.start.value = null, e.pointerPosition.offset.pixel.value = null, e.pointerPosition.offset.percent.value = null;
336
+ t.pointerPosition.current.value = null, t.pointerPosition.start.value = null, t.pointerPosition.offset.pixel.value = null, t.pointerPosition.offset.percent.value = null;
379
337
  }
380
338
  };
381
- }, Ke = (t) => {
382
- const e = C(), { onPointerStart: r, onPointerMove: o, onPointerEnd: u } = $e(t);
383
- let n = null;
384
- const s = (i) => {
385
- var h, _;
386
- const d = e.selectedElements.value.some(
387
- (x) => x.node === i
339
+ }, Ee = (e, t) => {
340
+ const n = T(), { onPointerStart: i, onPointerMove: a, onPointerEnd: l } = he(e);
341
+ let s = null;
342
+ const d = (c) => {
343
+ var C, S;
344
+ const g = n.selectedElements.value.some(
345
+ (m) => m.node === c
388
346
  );
389
- if (e.selectedElements.value.length && d)
390
- return e.selectedElements.value.map((x) => {
391
- var O, z;
347
+ if (n.selectedElements.value.length && g)
348
+ return n.selectedElements.value.map((m) => {
349
+ var _, w;
392
350
  return {
393
- ...x,
394
- initialHTML: ((O = x.node) == null ? void 0 : O.outerHTML) ?? "",
395
- initialRect: (z = x.node) == null ? void 0 : z.getBoundingClientRect()
351
+ ...m,
352
+ initialHTML: ((_ = m.node) == null ? void 0 : _.outerHTML) ?? "",
353
+ initialRect: (w = m.node) == null ? void 0 : w.getBoundingClientRect()
396
354
  };
397
355
  });
398
- e.selectedElements.value = [];
399
- const f = e.elements.value.find(
400
- (x) => x.node === i
356
+ n.selectedElements.value = [];
357
+ const P = n.elements.value.find(
358
+ (m) => m.node === c
401
359
  );
402
- return f ? [
360
+ return P ? [
403
361
  {
404
- ...f,
405
- initialHTML: ((h = f.node) == null ? void 0 : h.outerHTML) ?? "",
406
- initialRect: (_ = f.node) == null ? void 0 : _.getBoundingClientRect()
362
+ ...P,
363
+ initialHTML: ((C = P.node) == null ? void 0 : C.outerHTML) ?? "",
364
+ initialRect: (S = P.node) == null ? void 0 : S.getBoundingClientRect()
407
365
  }
408
366
  ] : [];
409
- }, g = (i, d) => {
410
- const f = Math.max(
411
- 0,
412
- Math.min(i.x + i.width, d.x + d.width) - Math.max(i.x, d.x)
413
- ), h = Math.max(
414
- 0,
415
- Math.min(i.y + i.height, d.y + d.height) - Math.max(i.y, d.y)
416
- ), _ = f * h, x = i.width * i.height, O = d.width * d.height;
417
- return (_ / x * 100 + _ / O * 100) / 2;
418
- }, v = ke(() => {
419
- var X, q, j, G, B, J, Q, ee, te, ne;
420
- const i = k(e.activeContainer.ref.value), d = $(i), f = ((X = e.pointerPosition.current.value) == null ? void 0 : X.x) ?? 0, h = ((q = e.pointerPosition.current.value) == null ? void 0 : q.y) ?? 0, x = !(i && f >= i.x && f <= i.x + i.width && h >= i.y && h <= i.y + i.height), O = e.draggingElements.value.map((a) => a.node), z = e.visibleElements.value.map((a) => e.elements.value[a]).filter((a) => {
421
- if (!a.node || O.some(
422
- (L) => L && M(a.node, L)
423
- ) || a.groups.length && !!e.draggingElements.value.some(
424
- (S) => S.groups.length ? !S.groups.some(
425
- (T) => a.groups.includes(T)
426
- ) : !1
427
- ))
428
- return !1;
429
- const c = k(a.node);
430
- return c && i && ae(c, i);
431
- }).map((a) => {
432
- const c = k(a.node), L = $(c), S = f >= c.x && f <= c.x + c.width && h >= c.y && h <= c.y + c.height, T = g(c, i), U = ue(d, L), Y = e.elements.value.filter(
433
- (A) => A !== a && A.node && a.node && M(
434
- a.node,
435
- A.node
436
- )
437
- ).length;
438
- return {
439
- element: a,
440
- isPointerInElement: S,
441
- overlapPercent: T,
442
- depth: Y,
443
- centerDistance: U
444
- };
445
- }).sort((a, c) => {
446
- if (!x) {
447
- if (a.isPointerInElement && c.isPointerInElement) return c.depth - a.depth;
448
- if (a.isPointerInElement !== c.isPointerInElement) return a.isPointerInElement ? -1 : 1;
449
- }
450
- return Math.abs(a.overlapPercent - c.overlapPercent) <= 1 ? a.centerDistance - c.centerDistance : c.overlapPercent - a.overlapPercent;
451
- }), fe = e.zones.value.filter((a) => {
452
- if (!a.node || O.some(
453
- (L) => L && M(a.node, L)
454
- ) || a.groups.length && !!e.draggingElements.value.some((S) => S.groups.length ? !S.groups.some((T) => a.groups.includes(T)) : !1))
455
- return !1;
456
- const c = k(a.node);
457
- return c && i && ae(c, i);
458
- }).map((a) => {
459
- const c = k(a.node), L = $(c), S = f >= c.x && f <= c.x + c.width && h >= c.y && h <= c.y + c.height, T = g(c, i), U = ue(d, L), Y = e.zones.value.filter(
460
- (A) => A !== a && A.node && a.node && M(a.node, A.node)
461
- ).length;
462
- return {
463
- zone: a,
464
- isPointerInElement: S,
465
- overlapPercent: T,
466
- depth: Y,
467
- centerDistance: U
468
- };
469
- }).sort((a, c) => {
470
- if (!x) {
471
- if (a.isPointerInElement && c.isPointerInElement) return c.depth - a.depth;
472
- if (a.isPointerInElement !== c.isPointerInElement) return a.isPointerInElement ? -1 : 1;
473
- }
474
- return Math.abs(a.overlapPercent - c.overlapPercent) <= 1 ? a.centerDistance - c.centerDistance : c.overlapPercent - a.overlapPercent;
475
- }), R = e.hovered.element.value, V = e.hovered.zone.value;
476
- e.hovered.element.value = ((j = z[0]) == null ? void 0 : j.element) ?? null, e.hovered.zone.value = ((G = fe[0]) == null ? void 0 : G.zone) ?? null, e.hovered.element.value !== R && ((B = R == null ? void 0 : R.events) != null && B.onLeave && R.events.onLeave(e), (Q = (J = e.hovered.element.value) == null ? void 0 : J.events) != null && Q.onHover && e.hovered.element.value.events.onHover(e)), e.hovered.zone.value !== V && ((ee = V == null ? void 0 : V.events) != null && ee.onLeave && V.events.onLeave(e), (ne = (te = e.hovered.zone.value) == null ? void 0 : te.events) != null && ne.onHover && e.hovered.zone.value.events.onHover(e));
477
- }, 1e3), y = () => {
478
- v(), n = requestAnimationFrame(y);
479
- }, l = () => {
480
- y();
481
- }, p = () => {
482
- n !== null && (cancelAnimationFrame(n), n = null);
367
+ }, v = (c) => {
368
+ if (!c)
369
+ return { element: null, zone: null };
370
+ const g = Array.isArray(c) ? c : [c], P = n.draggingElements.value.map(
371
+ (m) => m.node
372
+ ), [C] = g.map(
373
+ (m) => n.elements.value.find((_) => _.node === m)
374
+ ).filter((m) => m ? m.groups.length ? !n.draggingElements.value.some(
375
+ (w) => w.groups.length ? !w.groups.some(
376
+ (O) => m.groups.includes(O)
377
+ ) : !1
378
+ ) : !0 : !1), [S] = g.map((m) => {
379
+ const _ = n.zones.value.find((w) => w.node === m);
380
+ return !_ || P.some(
381
+ (w) => w && M(m, w)
382
+ ) || _.groups.length && !!n.draggingElements.value.some((O) => O.groups.length ? !O.groups.some((j) => _.groups.includes(j)) : !1) ? null : _;
383
+ });
384
+ return {
385
+ element: C ?? null,
386
+ zone: S ?? null
387
+ };
388
+ }, h = (t == null ? void 0 : t.sensor) || me, u = (c) => {
389
+ var C, S, m, _, w, O;
390
+ const g = n.hovered.element.value, P = n.hovered.zone.value;
391
+ n.hovered.element.value = c.element, n.hovered.zone.value = c.zone, n.hovered.element.value !== g && ((C = g == null ? void 0 : g.events) != null && C.onLeave && g.events.onLeave(n), (m = (S = n.hovered.element.value) == null ? void 0 : S.events) != null && m.onHover && n.hovered.element.value.events.onHover(n)), n.hovered.zone.value !== P && ((_ = P == null ? void 0 : P.events) != null && _.onLeave && P.events.onLeave(n), (O = (w = n.hovered.zone.value) == null ? void 0 : w.events) != null && O.onHover && n.hovered.zone.value.events.onHover(n));
392
+ }, E = ae(() => {
393
+ const c = h(n), g = v(c);
394
+ u(g);
395
+ }, (t == null ? void 0 : t.throttle) ?? 0), r = () => {
396
+ E(), s = requestAnimationFrame(r);
397
+ }, o = () => r(), f = () => {
398
+ s !== null && (cancelAnimationFrame(s), s = null);
483
399
  };
484
400
  return {
485
- activate: (i) => {
486
- e.draggingElements.value = s(t.value), r(i), l();
401
+ activate: (c) => {
402
+ n.draggingElements.value = d(e.value), i(c), o();
487
403
  },
488
- track: (i) => {
489
- o(i);
404
+ track: (c) => {
405
+ a(c);
490
406
  },
491
407
  deactivate: () => {
492
- var i, d;
493
- u(), e.hovered.zone.value ? (d = (i = e.hovered.zone.value.events).onDrop) == null || d.call(i, e) : e.draggingElements.value.forEach(
494
- (f) => {
495
- var h, _;
496
- return (_ = (h = f.events).onEnd) == null ? void 0 : _.call(h, e);
408
+ var c, g;
409
+ l(), n.hovered.zone.value ? (g = (c = n.hovered.zone.value.events).onDrop) == null || g.call(c, n) : n.draggingElements.value.forEach(
410
+ (P) => {
411
+ var C, S;
412
+ return (S = (C = P.events).onEnd) == null ? void 0 : S.call(C, n);
497
413
  }
498
- ), e.draggingElements.value = [], e.selectedElements.value = [], e.hovered.zone.value = null, e.hovered.element.value = null, p();
414
+ ), n.draggingElements.value = [], n.selectedElements.value = [], n.hovered.zone.value = null, n.hovered.element.value = null, f();
499
415
  }
500
416
  };
501
- }, je = (t) => {
417
+ }, we = (e) => {
502
418
  const {
503
- elementRef: e,
504
- registerElement: r,
505
- unregisterElement: o,
506
- isDragging: u,
507
- isOvered: n,
419
+ elementRef: t,
420
+ registerElement: n,
421
+ unregisterElement: i,
422
+ isDragging: a,
423
+ isOvered: l,
508
424
  isAllowed: s
509
- } = Ye(t), { disableInteractions: g, enableInteractions: v } = Fe(), { activeContainer: y, pointerPosition: l } = C(), { activate: p, track: E, deactivate: m } = Ke(e), w = (h) => {
510
- t != null && t.container && (y.component.value = Ie(t.container)), g(), p(h), document.addEventListener("pointermove", i), document.addEventListener("pointerup", f), document.addEventListener("wheel", d);
511
- }, i = (h) => E(h), d = (h) => E(h), f = () => {
512
- y.component.value = null, v(), m(), document.removeEventListener("pointermove", i), document.removeEventListener("pointerup", f), document.removeEventListener("wheel", d);
425
+ } = ve(e), { disableInteractions: d, enableInteractions: v } = ge(), { activeContainer: h, pointerPosition: u } = T(), { activate: E, track: r, deactivate: o } = Ee(t, {
426
+ throttle: e == null ? void 0 : e.throttle,
427
+ sensor: e == null ? void 0 : e.sensor
428
+ }), f = (c) => {
429
+ e != null && e.container && (h.component.value = le(e.container)), d(), E(c), document.addEventListener("pointermove", p), document.addEventListener("pointerup", x), document.addEventListener("wheel", D);
430
+ }, p = (c) => r(c), D = (c) => r(c), x = () => {
431
+ h.component.value = null, v(), o(), document.removeEventListener("pointermove", p), document.removeEventListener("pointerup", x), document.removeEventListener("wheel", D);
513
432
  };
514
- return N(r), W(o), {
515
- pointerPosition: l,
516
- elementRef: e,
517
- isDragging: u,
518
- isOvered: n,
433
+ return V(n), H(i), {
434
+ pointerPosition: u,
435
+ elementRef: t,
436
+ isDragging: a,
437
+ isOvered: l,
519
438
  isAllowed: s,
520
- handleDragStart: w
439
+ handleDragStart: f
521
440
  };
522
- }, We = (t) => {
523
- const { zones: e, hovered: r, draggingElements: o, isDragging: u } = C(), n = D(null), s = P(() => {
524
- var l;
525
- return ((l = r.zone.value) == null ? void 0 : l.node) === n.value;
526
- }), g = P(() => {
527
- if (!n.value || !u.value) return !1;
528
- const l = e.value.find(
529
- (p) => p.node === n.value
441
+ }, ye = (e) => {
442
+ const { zones: t, hovered: n, draggingElements: i, isDragging: a } = T(), l = y(null), s = I(() => {
443
+ var u;
444
+ return ((u = n.zone.value) == null ? void 0 : u.node) === l.value;
445
+ }), d = I(() => {
446
+ if (!l.value || !a.value) return !1;
447
+ const u = t.value.find(
448
+ (E) => E.node === l.value
530
449
  );
531
- return l != null && l.groups.length ? !o.value.some((p) => p.groups.length ? !p.groups.some(
532
- (E) => l.groups.includes(E)
450
+ return u != null && u.groups.length ? !i.value.some((E) => E.groups.length ? !E.groups.some(
451
+ (r) => u.groups.includes(r)
533
452
  ) : !1) : !0;
534
453
  });
535
- return { elementRef: n, registerZone: () => {
536
- if (!n.value) throw new Error("elementRef is not set");
537
- e.value.push({
538
- node: n.value,
539
- groups: (t == null ? void 0 : t.groups) ?? [],
540
- events: (t == null ? void 0 : t.events) ?? {},
541
- data: (t == null ? void 0 : t.data) ?? void 0
542
- }), n.value.setAttribute("data-dnd-droppable", "true");
454
+ return { elementRef: l, registerZone: () => {
455
+ if (!l.value) throw new Error("elementRef is not set");
456
+ t.value.push({
457
+ node: l.value,
458
+ groups: (e == null ? void 0 : e.groups) ?? [],
459
+ events: (e == null ? void 0 : e.events) ?? {},
460
+ data: (e == null ? void 0 : e.data) ?? void 0
461
+ }), l.value.setAttribute("data-dnd-droppable", "true");
543
462
  }, unregisterZone: () => {
544
- if (!n.value) throw new Error("elementRef is not set");
545
- const l = e.value.findIndex(
546
- (p) => p.node === n.value
463
+ if (!l.value) throw new Error("elementRef is not set");
464
+ const u = t.value.findIndex(
465
+ (E) => E.node === l.value
547
466
  );
548
- l !== -1 && e.value.splice(l, 1);
549
- }, isOvered: s, isAllowed: g };
550
- }, Ge = (t) => {
551
- const { elementRef: e, registerZone: r, unregisterZone: o, isOvered: u, isAllowed: n } = We(t);
552
- return N(r), W(o), { elementRef: e, isOvered: u, isAllowed: n };
553
- }, Be = (t) => {
554
- const { selectedElements: e, elements: r } = C(), o = P(
555
- () => r.value.find((l) => l.node === t.value)
556
- ), u = P(
557
- () => e.value.some((l) => l.node === t.value)
558
- ), n = P(() => t.value ? e.value.some(
559
- (l) => l.node && M(
560
- l.node,
561
- t.value
467
+ u !== -1 && t.value.splice(u, 1);
468
+ }, isOvered: s, isAllowed: d };
469
+ }, De = (e) => {
470
+ const { elementRef: t, registerZone: n, unregisterZone: i, isOvered: a, isAllowed: l } = ye(e);
471
+ return V(n), H(i), { elementRef: t, isOvered: a, isAllowed: l };
472
+ }, _e = (e) => {
473
+ const { selectedElements: t, elements: n } = T(), i = I(
474
+ () => n.value.find((u) => u.node === e.value)
475
+ ), a = I(
476
+ () => t.value.some((u) => u.node === e.value)
477
+ ), l = I(() => e.value ? t.value.some(
478
+ (u) => u.node && M(
479
+ u.node,
480
+ e.value
562
481
  )
563
- ) : !1), s = P(() => t.value ? e.value.some(
564
- (l) => l.node && M(
565
- t.value,
566
- l.node
482
+ ) : !1), s = I(() => e.value ? t.value.some(
483
+ (u) => u.node && M(
484
+ e.value,
485
+ u.node
567
486
  )
568
- ) : !1), g = () => {
569
- o.value && (e.value = e.value.filter(
570
- (l) => l.node !== t.value
487
+ ) : !1), d = () => {
488
+ i.value && (t.value = t.value.filter(
489
+ (u) => u.node !== e.value
571
490
  ));
572
491
  }, v = () => {
573
- o.value && (n.value && (e.value = e.value.filter(
574
- (l) => l.node && !M(
575
- l.node,
576
- t.value
492
+ i.value && (l.value && (t.value = t.value.filter(
493
+ (u) => u.node && !M(
494
+ u.node,
495
+ e.value
577
496
  )
578
- )), s.value && (e.value = e.value.filter(
579
- (l) => l.node && !M(
580
- t.value,
581
- l.node
497
+ )), s.value && (t.value = t.value.filter(
498
+ (u) => u.node && !M(
499
+ e.value,
500
+ u.node
582
501
  )
583
- )), e.value.push(o.value));
502
+ )), t.value.push(i.value));
584
503
  };
585
504
  return {
586
- handleUnselect: g,
505
+ handleUnselect: d,
587
506
  handleSelect: v,
588
507
  handleToggleSelect: () => {
589
- o.value && (e.value.some((l) => l.node === t.value) ? g() : v());
508
+ i.value && (t.value.some((u) => u.node === e.value) ? d() : v());
590
509
  },
591
- isSelected: u,
592
- isParentOfSelected: n
510
+ isSelected: a,
511
+ isParentOfSelected: l
593
512
  };
594
513
  };
595
514
  export {
596
- qe as default,
597
- C as useDnDStore,
598
- je as useDraggable,
599
- Ge as useDroppable,
600
- Be as useSelection
515
+ Pe as default,
516
+ T as useDnDStore,
517
+ we as useDraggable,
518
+ De as useDroppable,
519
+ _e as useSelection
601
520
  };