adverich-kun-ui 0.1.640 → 0.1.641

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.
package/AGENTS.md CHANGED
@@ -677,7 +677,11 @@ const items = ref([
677
677
  | dragHandle | String | null | Selector del handle (`null` = ítem completo) |
678
678
  | itemDraggable | Function | null | `(item) => boolean` |
679
679
  | layout | String | `'list'` | `'list'` \| `'grid'` (solo CSS) |
680
- | draggingClass | String | `'opacity-50'` | Clase mientras se arrastra |
680
+ | draggingClass | String | `''` | Clase extra mientras se arrastra |
681
+ | dropZoneClass | String | `'kun-dnd-drop-zone'` | Placeholder in-list |
682
+ | autoScroll | Boolean | true | Auto-scroll por bordes del ancestro overflow |
683
+ | scrollSensitivity | Number | 50 | Distancia (px) al borde para iniciar scroll |
684
+ | scrollSpeed | Number | 12 | Velocidad de scroll por frame |
681
685
  | tag | String | `'div'` | Tag del contenedor |
682
686
 
683
687
  **Eventos:** `update:modelValue`, `update:items`, `drag-start`, `drag-end`, `sort`, `transfer`
@@ -686,6 +690,8 @@ const items = ref([
686
690
 
687
691
  **Subcomponentes:** `KunDragAndDropItem`, `KunDragAndDropHandle`
688
692
 
693
+ **Scroll durante drag:** HTML5 DnD bloquea la rueda del mouse. Con `autoScroll` (default), acercar el puntero al borde superior/inferior (o laterales) del contenedor `overflow: auto|scroll` más cercano desplaza la vista. No depende de la rueda.
694
+
689
695
  **Composable headless:**
690
696
 
691
697
  ```js
package/dist/AGENTS.md CHANGED
@@ -677,7 +677,11 @@ const items = ref([
677
677
  | dragHandle | String | null | Selector del handle (`null` = ítem completo) |
678
678
  | itemDraggable | Function | null | `(item) => boolean` |
679
679
  | layout | String | `'list'` | `'list'` \| `'grid'` (solo CSS) |
680
- | draggingClass | String | `'opacity-50'` | Clase mientras se arrastra |
680
+ | draggingClass | String | `''` | Clase extra mientras se arrastra |
681
+ | dropZoneClass | String | `'kun-dnd-drop-zone'` | Placeholder in-list |
682
+ | autoScroll | Boolean | true | Auto-scroll por bordes del ancestro overflow |
683
+ | scrollSensitivity | Number | 50 | Distancia (px) al borde para iniciar scroll |
684
+ | scrollSpeed | Number | 12 | Velocidad de scroll por frame |
681
685
  | tag | String | `'div'` | Tag del contenedor |
682
686
 
683
687
  **Eventos:** `update:modelValue`, `update:items`, `drag-start`, `drag-end`, `sort`, `transfer`
@@ -686,6 +690,8 @@ const items = ref([
686
690
 
687
691
  **Subcomponentes:** `KunDragAndDropItem`, `KunDragAndDropHandle`
688
692
 
693
+ **Scroll durante drag:** HTML5 DnD bloquea la rueda del mouse. Con `autoScroll` (default), acercar el puntero al borde superior/inferior (o laterales) del contenedor `overflow: auto|scroll` más cercano desplaza la vista. No depende de la rueda.
694
+
689
695
  **Composable headless:**
690
696
 
691
697
  ```js
@@ -45,6 +45,9 @@ var T = /* @__PURE__ */ e({ default: () => O }), E = { class: "flex items-center
45
45
  orientation: T.orientation || (T.layout === "grid" ? "grid" : "vertical"),
46
46
  itemDraggable: T.itemDraggable,
47
47
  dragHandle: N.value,
48
+ autoScroll: T.autoScroll,
49
+ scrollSensitivity: T.scrollSensitivity,
50
+ scrollSpeed: T.scrollSpeed,
48
51
  onDragstart: (e) => O("drag-start", e),
49
52
  onDragend: (e) => O("drag-end", e),
50
53
  onSort: (e) => {
@@ -74,6 +77,9 @@ var T = /* @__PURE__ */ e({ default: () => O }), E = { class: "flex items-center
74
77
  T.orientation,
75
78
  T.layout,
76
79
  T.itemDraggable,
80
+ T.autoScroll,
81
+ T.scrollSensitivity,
82
+ T.scrollSpeed,
77
83
  N.value
78
84
  ], () => {
79
85
  I(F());
@@ -76,6 +76,18 @@ var e = {
76
76
  listClass: {
77
77
  type: String,
78
78
  default: "flex flex-col gap-2"
79
+ },
80
+ autoScroll: {
81
+ type: Boolean,
82
+ default: !0
83
+ },
84
+ scrollSensitivity: {
85
+ type: Number,
86
+ default: 50
87
+ },
88
+ scrollSpeed: {
89
+ type: Number,
90
+ default: 12
79
91
  }
80
92
  };
81
93
  //#endregion
@@ -1,15 +1,16 @@
1
1
  import { getIncomingDirection as e, getInsertIndexFromPoint as t, getTargetItemFromPoint as n, passesSortThreshold as r, performSort as i, performTransfer as a, resolveItemKey as o } from "../utils/kunDragAndDropMath.js";
2
- import { activeDragRef as s, clearActiveDrag as c, getActiveDrag as l, getGroupParents as u, registerParent as d, setActiveDrag as f, unregisterParent as p } from "./kunDragAndDropRegistry.js";
3
- import { computed as m, isRef as h, onBeforeUnmount as g, onMounted as _, ref as v, unref as y, watch as b } from "vue";
2
+ import { findScrollParent as s, getAutoScrollDelta as c } from "../utils/kunDragAndDropScroll.js";
3
+ import { activeDragRef as l, clearActiveDrag as u, getActiveDrag as d, getGroupParents as f, registerParent as p, setActiveDrag as m, unregisterParent as h } from "./kunDragAndDropRegistry.js";
4
+ import { computed as g, isRef as _, onBeforeUnmount as ee, onMounted as te, ref as v, unref as y, watch as b } from "vue";
4
5
  //#region src/components/KunDragAndDrop/src/composables/useKunDragAndDrop.js
5
- var x = "data-kun-dnd-item", S = "data-kun-dnd-key", ee = "input,textarea,select,button,a,[role=\"button\"],[data-no-drag]", C = 0;
6
- function te() {
6
+ var x = "data-kun-dnd-item", S = "data-kun-dnd-key", ne = "input,textarea,select,button,a,[role=\"button\"],[data-no-drag]", C = 0;
7
+ function re() {
7
8
  return C += 1, `kun-dnd-${C}`;
8
9
  }
9
- function ne(e) {
10
+ function ie(e) {
10
11
  return typeof e == "object" && !!e && !Array.isArray(e) && ("parent" in e || "values" in e);
11
12
  }
12
- function w(e = {}) {
13
+ function ae(e = {}) {
13
14
  return {
14
15
  group: e.group ?? null,
15
16
  dragHandle: e.dragHandle ?? null,
@@ -28,19 +29,22 @@ function w(e = {}) {
28
29
  onTransfer: typeof e.onTransfer == "function" ? e.onTransfer : null,
29
30
  onDragstart: typeof e.onDragstart == "function" ? e.onDragstart : null,
30
31
  onDragend: typeof e.onDragend == "function" ? e.onDragend : null,
31
- onValuesChange: typeof e.onValuesChange == "function" ? e.onValuesChange : null
32
+ onValuesChange: typeof e.onValuesChange == "function" ? e.onValuesChange : null,
33
+ autoScroll: e.autoScroll !== !1,
34
+ scrollSensitivity: Number.isFinite(e.scrollSensitivity) ? e.scrollSensitivity : 50,
35
+ scrollSpeed: Number.isFinite(e.scrollSpeed) ? e.scrollSpeed : 12
32
36
  };
33
37
  }
34
- function re(e, t, n) {
38
+ function oe(e, t, n) {
35
39
  if (e === t) return !0;
36
40
  if (!e || !t || e.length !== t.length) return !1;
37
41
  for (let r = 0; r < e.length; r++) if (o(e[r], n, r) !== o(t[r], n, r)) return !1;
38
42
  return !0;
39
43
  }
40
- function ie(e) {
44
+ function se(e) {
41
45
  return typeof CSS < "u" && typeof CSS.escape == "function" ? CSS.escape(String(e)) : String(e).replace(/"/g, "\\\"");
42
46
  }
43
- function T(e, t, n) {
47
+ function w(e, t, n) {
44
48
  if (!n) return !0;
45
49
  let r = typeof e.composedPath == "function" ? e.composedPath() : [], i = r.indexOf(t), a = i === -1 ? [] : r.slice(0, i);
46
50
  for (let e of a) if (e instanceof Element && e.matches(n)) return !0;
@@ -49,139 +53,176 @@ function T(e, t, n) {
49
53
  for (let e of o) if (s === e || e.contains(s)) return !0;
50
54
  return !1;
51
55
  }
52
- function E(C, E) {
53
- let D = ne(C), O = D ? C : {}, ae = w(D ? O : E || {}), k = te(), A = v({ ...ae }), j = D && O.parent ? O.parent : v(null), M = D && O.values ? O.values : v(Array.isArray(C) ? [...C] : []), N = m(() => s.value?.itemKey ?? null), P = v(null), F = null, I = null, L = null, R = null, z = null, B = 0, V = null;
54
- function H() {
55
- return y(M) || [];
56
+ function ce(C, ce) {
57
+ let T = ie(C), E = T ? C : {}, le = ae(T ? E : ce || {}), D = re(), O = v({ ...le }), k = T && E.parent ? E.parent : v(null), A = T && E.values ? E.values : v(Array.isArray(C) ? [...C] : []), j = g(() => l.value?.itemKey ?? null), M = v(null), N = null, P = null, F = null, I = null, L = null, R = 0, z = null, B = null, V = 0, H = 0, U = null, W = !1;
58
+ function G() {
59
+ return y(A) || [];
56
60
  }
57
- function U(e, t = {}) {
61
+ function K(e, t = {}) {
58
62
  let n = Array.isArray(e) ? e : [];
59
- h(M) && (M.value = n), G().onValuesChange?.(n, t);
63
+ _(A) && (A.value = n), J().onValuesChange?.(n, t);
60
64
  }
61
- function W() {
62
- return y(j) || null;
65
+ function q() {
66
+ return y(k) || null;
63
67
  }
64
- function G() {
65
- return A.value;
68
+ function J() {
69
+ return O.value;
66
70
  }
67
- function oe(e = {}) {
68
- A.value = w({
69
- ...A.value,
71
+ function ue(e = {}) {
72
+ O.value = ae({
73
+ ...O.value,
70
74
  ...e
71
- }), K();
72
- }
73
- function K() {
74
- F && p(F), F = {
75
- id: k,
76
- group: A.value.group,
77
- getParentEl: W,
78
- getValues: H,
79
- setValues: U,
80
- getConfig: G
81
- }, d(F);
82
- }
83
- function q(e) {
84
- let t = G();
85
- return H().findIndex((n, r) => String(o(n, t.itemKey, r)) === String(e));
86
- }
87
- function J(e) {
88
- let t = W();
75
+ }), de();
76
+ }
77
+ function de() {
78
+ N && h(N), N = {
79
+ id: D,
80
+ group: O.value.group,
81
+ getParentEl: q,
82
+ getValues: G,
83
+ setValues: K,
84
+ getConfig: J
85
+ }, p(N);
86
+ }
87
+ function Y(e) {
88
+ let t = J();
89
+ return G().findIndex((n, r) => String(o(n, t.itemKey, r)) === String(e));
90
+ }
91
+ function fe(e) {
92
+ let t = q();
89
93
  if (!t || !e?.target?.closest) return null;
90
94
  let n = e.target.closest(`[${x}="true"]`);
91
95
  return !n || !t.contains(n) ? null : n;
92
96
  }
93
- function Y(e) {
94
- let t = W();
95
- return !t || e == null ? null : t.querySelector(`[${S}="${ie(e)}"]`);
97
+ function X(e) {
98
+ let t = q();
99
+ return !t || e == null ? null : t.querySelector(`[${S}="${se(e)}"]`);
96
100
  }
97
- function se() {
98
- let e = W(), t = G();
101
+ function pe() {
102
+ let e = q(), t = J();
99
103
  if (!e) return;
100
104
  let n = [...(t.draggingClass || "").split(/\s+/), ...(t.dropZoneClass || "").split(/\s+/)].filter(Boolean);
101
105
  n.length && e.querySelectorAll(`[${x}="true"]`).forEach((e) => {
102
106
  n.forEach((t) => e.classList.remove(t));
103
107
  });
104
108
  }
105
- function ce() {
106
- let e = l(), t = e?.group ? u(e.group) : [];
109
+ function me() {
110
+ let e = d(), t = e?.group ? f(e.group) : [];
107
111
  t.length ? t.forEach((e) => {
108
- let t = e.getParentEl?.(), n = e.getConfig?.() || G();
112
+ let t = e.getParentEl?.(), n = e.getConfig?.() || J();
109
113
  if (!t) return;
110
114
  let r = [...(n.draggingClass || "").split(/\s+/), ...(n.dropZoneClass || "").split(/\s+/)].filter(Boolean);
111
115
  t.querySelectorAll(`[${x}="true"]`).forEach((e) => {
112
116
  r.forEach((t) => e.classList.remove(t));
113
117
  });
114
- }) : se();
118
+ }) : pe();
119
+ }
120
+ function he() {
121
+ me(), M.value = null, I = null, R = 0, z = null, Z(), L?.parentNode && L.parentNode.removeChild(L), L = null;
122
+ }
123
+ function Z() {
124
+ V = 0, H = 0, U = null, B != null && (cancelAnimationFrame(B), B = null);
115
125
  }
116
- function le() {
117
- ce(), P.value = null, R = null, B = 0, V = null, z?.parentNode && z.parentNode.removeChild(z), z = null;
126
+ function ge() {
127
+ if (B = null, !d() || !U) {
128
+ Z();
129
+ return;
130
+ }
131
+ (V !== 0 || H !== 0) && (H !== 0 && (U.scrollTop += H), V !== 0 && (U.scrollLeft += V), B = requestAnimationFrame(ge));
118
132
  }
119
- function X() {
133
+ function _e(e, t) {
134
+ let n = J();
135
+ if (!n.autoScroll || !d()) {
136
+ Z();
137
+ return;
138
+ }
139
+ let r = null;
140
+ try {
141
+ r = document.elementFromPoint(e, t);
142
+ } catch {}
143
+ let i = s(r) || s(q());
144
+ U = i;
145
+ let { dx: a, dy: o } = c(e, t, i, {
146
+ sensitivity: n.scrollSensitivity,
147
+ speed: n.scrollSpeed
148
+ });
149
+ V = a, H = o, (a !== 0 || o !== 0) && B == null && (B = requestAnimationFrame(ge)), a === 0 && o === 0 && B != null && (cancelAnimationFrame(B), B = null);
150
+ }
151
+ function ve(e) {
152
+ !W || !d() || (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "move"), _e(e.clientX, e.clientY));
153
+ }
154
+ function ye() {
155
+ W || (W = !0, document.addEventListener("dragover", ve, !0), document.addEventListener("dragend", Ae, !0));
156
+ }
157
+ function Q() {
158
+ W && (W = !1, document.removeEventListener("dragover", ve, !0), document.removeEventListener("dragend", Ae, !0));
159
+ }
160
+ function be() {
120
161
  try {
121
162
  return;
122
163
  } catch {}
123
- let e = W();
164
+ let e = q();
124
165
  if (!e) return;
125
- let t = [...e.children].filter((e) => e.getAttribute?.("data-kun-dnd-item") === "true" && !e.hasAttribute?.("data-kun-dnd-placeholder")).length, n = H().length;
166
+ let t = [...e.children].filter((e) => e.getAttribute?.("data-kun-dnd-item") === "true" && !e.hasAttribute?.("data-kun-dnd-placeholder")).length, n = G().length;
126
167
  t !== n && console.warn("[KunDragAndDrop] The number of draggable items in the parent does not match the number of values, which may lead to unexpected behavior.", {
127
168
  childCount: t,
128
169
  valueCount: n
129
170
  });
130
171
  }
131
- function ue(e) {
132
- let t = G();
172
+ function xe(e) {
173
+ let t = J();
133
174
  if (t.disabled || !t.sortable) return;
134
- let n = J(e);
175
+ let n = fe(e);
135
176
  if (!n) {
136
- P.value = null;
177
+ M.value = null;
137
178
  return;
138
179
  }
139
180
  if (t.dragHandle) {
140
- if (!T(e, n, t.dragHandle)) {
141
- P.value = null, n.draggable = !1;
181
+ if (!w(e, n, t.dragHandle)) {
182
+ M.value = null, n.draggable = !1;
142
183
  return;
143
184
  }
144
185
  let r = n.getAttribute(S);
145
- P.value = r, n.draggable = !0;
186
+ M.value = r, n.draggable = !0;
146
187
  return;
147
188
  }
148
- if (e.target?.closest?.(ee)) {
149
- n.draggable = !1, P.value = null;
189
+ if (e.target?.closest?.(ne)) {
190
+ n.draggable = !1, M.value = null;
150
191
  return;
151
192
  }
152
- n.draggable = !0, P.value = n.getAttribute(S);
193
+ n.draggable = !0, M.value = n.getAttribute(S);
153
194
  }
154
- function Z() {
155
- if (!G().dragHandle) return;
156
- let e = Y(P.value);
157
- e && !N.value && (e.draggable = !1, P.value = null);
195
+ function $() {
196
+ if (!J().dragHandle) return;
197
+ let e = X(M.value);
198
+ e && !j.value && (e.draggable = !1, M.value = null);
158
199
  }
159
- function de(e) {
160
- let t = G();
200
+ function Se(e) {
201
+ let t = J();
161
202
  if (t.disabled || !t.sortable) {
162
203
  e.preventDefault();
163
204
  return;
164
205
  }
165
- let n = J(e);
206
+ let n = fe(e);
166
207
  if (!n) {
167
208
  e.preventDefault();
168
209
  return;
169
210
  }
170
211
  if (t.dragHandle) {
171
- if (!T(e, n, t.dragHandle)) {
212
+ if (!w(e, n, t.dragHandle)) {
172
213
  e.preventDefault(), n.draggable = !1;
173
214
  return;
174
215
  }
175
- } else if (e.target?.closest?.(ee)) {
216
+ } else if (e.target?.closest?.(ne)) {
176
217
  e.preventDefault();
177
218
  return;
178
219
  }
179
- let r = n.getAttribute(S), i = q(r);
220
+ let r = n.getAttribute(S), i = Y(r);
180
221
  if (i < 0) {
181
222
  e.preventDefault();
182
223
  return;
183
224
  }
184
- let a = H()[i];
225
+ let a = G()[i];
185
226
  if (t.itemDraggable && !t.itemDraggable(a)) {
186
227
  e.preventDefault();
187
228
  return;
@@ -202,13 +243,13 @@ function E(C, E) {
202
243
  opacity: "1",
203
244
  zIndex: "9999",
204
245
  transform: "none"
205
- }), i.classList.remove(...(t.draggingClass || "").split(/\s+/).filter(Boolean), ...(t.dropZoneClass || "").split(/\s+/).filter(Boolean)), document.body.appendChild(i), z = i;
246
+ }), i.classList.remove(...(t.draggingClass || "").split(/\s+/).filter(Boolean), ...(t.dropZoneClass || "").split(/\s+/).filter(Boolean)), document.body.appendChild(i), L = i;
206
247
  let a = typeof e.offsetX == "number" ? e.offsetX : r.width / 2, o = typeof e.offsetY == "number" ? e.offsetY : r.height / 2;
207
248
  e.dataTransfer.setDragImage(i, a, o);
208
249
  } catch {}
209
250
  }
210
- P.value = r, R = null, V = null, f({
211
- sourceId: k,
251
+ M.value = r, I = null, z = null, m({
252
+ sourceId: D,
212
253
  group: t.group,
213
254
  itemKey: r,
214
255
  item: a,
@@ -220,11 +261,11 @@ function E(C, E) {
220
261
  event: e
221
262
  });
222
263
  }
223
- function fe(t, n, i, a, o, s) {
264
+ function Ce(t, n, i, a, o, s) {
224
265
  if (!t || !n || t === n || o < 0 || s < 0 || o === s) return !1;
225
266
  let c = t.getAttribute(S);
226
- if (c == null || String(c) === String(R)) return !1;
227
- let l = G(), u = t.getBoundingClientRect(), d = l.threshold || {
267
+ if (c == null || String(c) === String(I)) return !1;
268
+ let l = J(), u = t.getBoundingClientRect(), d = l.threshold || {
228
269
  horizontal: 0,
229
270
  vertical: 0
230
271
  }, f = l.orientation || "vertical", p = o < s;
@@ -245,139 +286,133 @@ function E(C, E) {
245
286
  let m = n.getBoundingClientRect(), h = e(m, u);
246
287
  return r(h, u, i, a, d);
247
288
  }
248
- function pe(e, t) {
249
- let n = G(), r = l();
250
- if (!r || r.sourceId !== k) return;
251
- let a = e.getAttribute(S), s = q(r.itemKey), c = q(a);
252
- if (s < 0 || c < 0 || s === c || !fe(e, Y(r.itemKey), t.clientX, t.clientY, s, c)) return;
253
- let u = H(), d = i(u, s, c);
254
- if (re(d, u, n.itemKey)) return;
255
- R = a, B = performance.now() + 80;
256
- let p = d.findIndex((e, t) => String(o(e, n.itemKey, t)) === String(r.itemKey));
257
- U(d, { reason: "sort" }), f({
289
+ function we(e, t) {
290
+ let n = J(), r = d();
291
+ if (!r || r.sourceId !== D) return;
292
+ let a = e.getAttribute(S), s = Y(r.itemKey), c = Y(a);
293
+ if (s < 0 || c < 0 || s === c || !Ce(e, X(r.itemKey), t.clientX, t.clientY, s, c)) return;
294
+ let l = G(), u = i(l, s, c);
295
+ if (oe(u, l, n.itemKey)) return;
296
+ I = a, R = performance.now() + 80;
297
+ let f = u.findIndex((e, t) => String(o(e, n.itemKey, t)) === String(r.itemKey));
298
+ K(u, { reason: "sort" }), m({
258
299
  ...r,
259
- fromIndex: p
300
+ fromIndex: f
260
301
  }), n.onSort?.({
261
302
  item: r.item,
262
303
  fromIndex: s,
263
- toIndex: p,
304
+ toIndex: f,
264
305
  previousPosition: s,
265
- position: p,
266
- items: d,
306
+ position: f,
307
+ items: u,
267
308
  event: t
268
309
  });
269
310
  }
270
- function me(e) {
271
- let n = G(), r = l();
272
- if (!r || r.sourceId === k || !n.group || n.group !== r.group || performance.now() < B) return;
273
- let i = u(r.group).find((e) => e.id === r.sourceId);
311
+ function Te(e) {
312
+ let n = J(), r = d();
313
+ if (!r || r.sourceId === D || !n.group || n.group !== r.group || performance.now() < R) return;
314
+ let i = f(r.group).find((e) => e.id === r.sourceId);
274
315
  if (!i) return;
275
- let s = W(), c = Y(r.itemKey), d = t(s, e.clientX, e.clientY, n.orientation || "vertical", c), p = `${r.sourceId}:${d}:${r.itemKey}`;
276
- if (p === V) return;
277
- let m = i.getValues().findIndex((e, t) => {
316
+ let s = q(), c = X(r.itemKey), l = t(s, e.clientX, e.clientY, n.orientation || "vertical", c), u = `${r.sourceId}:${l}:${r.itemKey}`;
317
+ if (u === z) return;
318
+ let p = i.getValues().findIndex((e, t) => {
278
319
  let n = o(e, i.getConfig().itemKey, t);
279
320
  return String(n) === String(r.itemKey);
280
321
  });
281
- if (m < 0) return;
282
- let { source: h, target: g, item: _ } = a(i.getValues(), m, H(), d);
283
- _ !== void 0 && (V = p, R = null, B = performance.now() + 80, i.setValues(h, { reason: "transfer-out" }), U(g, { reason: "transfer-in" }), f({
322
+ if (p < 0) return;
323
+ let { source: h, target: g, item: _ } = a(i.getValues(), p, G(), l);
324
+ _ !== void 0 && (z = u, I = null, R = performance.now() + 80, i.setValues(h, { reason: "transfer-out" }), K(g, { reason: "transfer-in" }), m({
284
325
  ...r,
285
- sourceId: k,
286
- fromIndex: d,
326
+ sourceId: D,
327
+ fromIndex: l,
287
328
  item: _
288
329
  }), n.onTransfer?.({
289
330
  item: _,
290
- fromIndex: m,
291
- toIndex: d,
331
+ fromIndex: p,
332
+ toIndex: l,
292
333
  sourceItems: h,
293
334
  targetItems: g,
294
335
  event: e
295
336
  }));
296
337
  }
297
- function Q(e) {
298
- let t = G(), r = l();
338
+ function Ee(e) {
339
+ let t = J(), r = d();
299
340
  if (!r || t.disabled) return;
300
- let i = r.sourceId === k, a = !!t.group && t.group === r.group;
301
- !i && !a || (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "move"), !L && (L = requestAnimationFrame(() => {
302
- L = null;
303
- let r = l();
341
+ let i = r.sourceId === D, a = !!t.group && t.group === r.group;
342
+ !i && !a || (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "move"), _e(e.clientX, e.clientY), !F && (F = requestAnimationFrame(() => {
343
+ F = null;
344
+ let r = d();
304
345
  if (!r) return;
305
- let i = r.sourceId === k, a = !!t.group && t.group === r.group;
346
+ let i = r.sourceId === D, a = !!t.group && t.group === r.group;
306
347
  if (i && t.sortable) {
307
- let t = W(), i = Y(r.itemKey), a = n(t, e.clientX, e.clientY, i);
348
+ let t = q(), i = X(r.itemKey), a = n(t, e.clientX, e.clientY, i);
308
349
  if (!a) {
309
- R = null;
350
+ I = null;
310
351
  return;
311
352
  }
312
- if (performance.now() < B) {
313
- R = a.getAttribute(S);
353
+ if (performance.now() < R) {
354
+ I = a.getAttribute(S);
314
355
  return;
315
356
  }
316
- pe(a, e);
357
+ we(a, e);
317
358
  return;
318
359
  }
319
- !i && a && me(e);
360
+ !i && a && Te(e);
320
361
  })));
321
362
  }
322
- function he(e) {
363
+ function De(e) {
323
364
  e.preventDefault();
324
- let t = G(), n = l();
325
- !n || t.disabled || n.sourceId !== k && me(e);
365
+ let t = J(), n = d();
366
+ !n || t.disabled || n.sourceId !== D && Te(e);
326
367
  }
327
- function ge(e) {
328
- let t = l();
329
- if (!t && !z) {
330
- P.value = null, $();
368
+ function Oe(e) {
369
+ let t = d();
370
+ if (!t && !L) {
371
+ M.value = null, Z(), Q();
331
372
  return;
332
373
  }
333
- let n = G(), r = t?.itemKey ?? N.value, i = r == null ? -1 : q(r), a = i >= 0 ? H()[i] : t?.item, o = r == null ? null : Y(r);
334
- n.dragHandle && o && (o.draggable = !1), le(), c(), $(), n.onDragend?.({
374
+ let n = J(), r = t?.itemKey ?? j.value, i = r == null ? -1 : Y(r), a = i >= 0 ? G()[i] : t?.item, o = r == null ? null : X(r);
375
+ n.dragHandle && o && (o.draggable = !1), he(), u(), Q(), n.onDragend?.({
335
376
  item: a,
336
377
  index: i,
337
378
  key: r,
338
379
  event: e
339
380
  });
340
381
  }
341
- function _e(e) {
342
- ge(e);
382
+ function ke(e) {
383
+ Oe(e);
343
384
  }
344
- function ve(e) {
345
- ge(e);
385
+ function Ae(e) {
386
+ Oe(e);
346
387
  }
347
- function ye() {
348
- document.addEventListener("dragend", ve, !0);
388
+ function je(e) {
389
+ P !== e && (Me(), P = e, e && (e.addEventListener("pointerdown", xe, !0), e.addEventListener("pointerup", $, !0), e.addEventListener("pointercancel", $, !0), e.addEventListener("dragstart", Se), e.addEventListener("dragover", Ee), e.addEventListener("drop", De), e.addEventListener("dragend", ke)));
349
390
  }
350
- function $() {
351
- document.removeEventListener("dragend", ve, !0);
352
- }
353
- function be(e) {
354
- I !== e && (xe(), I = e, e && (e.addEventListener("pointerdown", ue, !0), e.addEventListener("pointerup", Z, !0), e.addEventListener("pointercancel", Z, !0), e.addEventListener("dragstart", de), e.addEventListener("dragover", Q), e.addEventListener("drop", he), e.addEventListener("dragend", _e)));
355
- }
356
- function xe() {
357
- I &&= (I.removeEventListener("pointerdown", ue, !0), I.removeEventListener("pointerup", Z, !0), I.removeEventListener("pointercancel", Z, !0), I.removeEventListener("dragstart", de), I.removeEventListener("dragover", Q), I.removeEventListener("drop", he), I.removeEventListener("dragend", _e), null);
358
- }
359
- b(() => y(j), (e) => {
360
- be(e), e && X();
361
- }, { flush: "post" }), b(() => H().length, () => {
362
- X();
363
- }), _(() => {
364
- K(), be(W()), X();
365
- }), g(() => {
366
- L && cancelAnimationFrame(L), $(), xe(), F && p(F), F = null, l()?.sourceId === k && c();
391
+ function Me() {
392
+ P &&= (P.removeEventListener("pointerdown", xe, !0), P.removeEventListener("pointerup", $, !0), P.removeEventListener("pointercancel", $, !0), P.removeEventListener("dragstart", Se), P.removeEventListener("dragover", Ee), P.removeEventListener("drop", De), P.removeEventListener("dragend", ke), null);
393
+ }
394
+ b(() => y(k), (e) => {
395
+ je(e), e && be();
396
+ }, { flush: "post" }), b(() => G().length, () => {
397
+ be();
398
+ }), te(() => {
399
+ de(), je(q()), be();
400
+ }), ee(() => {
401
+ F && cancelAnimationFrame(F), Z(), Q(), Me(), N && h(N), N = null, d()?.sourceId === D && u();
367
402
  });
368
- let Se = v(!!ae.dragHandle);
369
- return b(() => !!G().dragHandle, (e) => {
370
- Se.value = e;
403
+ let Ne = v(!!le.dragHandle);
404
+ return b(() => !!J().dragHandle, (e) => {
405
+ Ne.value = e;
371
406
  }), [
372
- j,
373
- M,
374
- oe,
407
+ k,
408
+ A,
409
+ ue,
375
410
  {
376
- draggingKey: N,
377
- armedKey: P,
378
- hasDragHandle: Se
411
+ draggingKey: j,
412
+ armedKey: M,
413
+ hasDragHandle: Ne
379
414
  }
380
415
  ];
381
416
  }
382
417
  //#endregion
383
- export { x as KUN_DND_ITEM_ATTR, S as KUN_DND_KEY_ATTR, o as resolveItemKey, E as useKunDragAndDrop, T as validateDragHandle };
418
+ export { x as KUN_DND_ITEM_ATTR, S as KUN_DND_KEY_ATTR, o as resolveItemKey, ce as useKunDragAndDrop, w as validateDragHandle };
@@ -0,0 +1,46 @@
1
+ //#region src/components/KunDragAndDrop/src/utils/kunDragAndDropScroll.js
2
+ function e(e) {
3
+ if (!e || e.nodeType !== 1) return !1;
4
+ let t = window.getComputedStyle(e), n = t.overflowY, r = t.overflowX, i = (n === "auto" || n === "scroll" || n === "overlay") && e.scrollHeight > e.clientHeight + 1, a = (r === "auto" || r === "scroll" || r === "overlay") && e.scrollWidth > e.clientWidth + 1;
5
+ return i || a;
6
+ }
7
+ function t(t) {
8
+ let n = t?.nodeType === 1 ? t : t?.parentElement;
9
+ for (; n && n !== document.body && n !== document.documentElement;) {
10
+ if (e(n)) return n;
11
+ n = n.parentElement;
12
+ }
13
+ return document.scrollingElement || document.documentElement || null;
14
+ }
15
+ function n(e, t, n, r = {}) {
16
+ let i = Math.max(0, Number(r.sensitivity ?? 50)), a = Math.max(0, Number(r.speed ?? 12));
17
+ if (!n || a === 0 || i === 0) return {
18
+ dx: 0,
19
+ dy: 0
20
+ };
21
+ let o = n.getBoundingClientRect(), s = 0, c = 0, l = n.scrollHeight - n.clientHeight, u = n.scrollWidth - n.clientWidth;
22
+ if (l > 0) {
23
+ if (t < o.top + i) {
24
+ let e = 1 - Math.max(0, t - o.top) / i;
25
+ c = -Math.ceil(a * e);
26
+ } else if (t > o.bottom - i) {
27
+ let e = 1 - Math.max(0, o.bottom - t) / i;
28
+ c = Math.ceil(a * e);
29
+ }
30
+ }
31
+ if (u > 0) {
32
+ if (e < o.left + i) {
33
+ let t = 1 - Math.max(0, e - o.left) / i;
34
+ s = -Math.ceil(a * t);
35
+ } else if (e > o.right - i) {
36
+ let t = 1 - Math.max(0, o.right - e) / i;
37
+ s = Math.ceil(a * t);
38
+ }
39
+ }
40
+ return {
41
+ dx: s,
42
+ dy: c
43
+ };
44
+ }
45
+ //#endregion
46
+ export { t as findScrollParent, n as getAutoScrollDelta };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "adverich-kun-ui",
3
- "version": "0.1.640",
3
+ "version": "0.1.641",
4
4
  "type": "module",
5
5
  "description": "Una librería de componentes Vue.js con Tailwind CSS",
6
6
  "main": "dist/index.js",