@vielzeug/dnd 2.2.0 → 3.0.0
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/README.md +5 -21
- package/dist/_shared.cjs.map +1 -1
- package/dist/_shared.d.ts +1 -1
- package/dist/_shared.d.ts.map +1 -1
- package/dist/_shared.js.map +1 -1
- package/dist/_touch.cjs +1 -1
- package/dist/_touch.cjs.map +1 -1
- package/dist/_touch.d.ts +8 -3
- package/dist/_touch.d.ts.map +1 -1
- package/dist/_touch.js +113 -130
- package/dist/_touch.js.map +1 -1
- package/dist/dnd.cjs +1 -1
- package/dist/dnd.cjs.map +1 -1
- package/dist/dnd.iife.js +1 -1
- package/dist/dnd.iife.js.map +1 -1
- package/dist/dnd.js +1 -1
- package/dist/dnd.js.map +1 -1
- package/dist/drop-zone.cjs +1 -1
- package/dist/drop-zone.cjs.map +1 -1
- package/dist/drop-zone.d.ts +4 -4
- package/dist/drop-zone.d.ts.map +1 -1
- package/dist/drop-zone.js +79 -61
- package/dist/drop-zone.js.map +1 -1
- package/dist/drop.cjs +1 -0
- package/dist/drop.d.ts +4 -0
- package/dist/drop.d.ts.map +1 -0
- package/dist/drop.js +3 -0
- package/dist/errors.cjs +1 -1
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.d.ts +3 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +5 -3
- package/dist/errors.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/sortable.cjs +1 -1
- package/dist/sortable.cjs.map +1 -1
- package/dist/sortable.d.ts +40 -66
- package/dist/sortable.d.ts.map +1 -1
- package/dist/sortable.js +252 -188
- package/dist/sortable.js.map +1 -1
- package/package.json +32 -8
package/dist/sortable.js
CHANGED
|
@@ -1,80 +1,111 @@
|
|
|
1
|
-
import { createDisposable as e, resolveDisabled as t } from "./_shared.js";
|
|
2
|
-
import { DndScopeError as n } from "./errors.js";
|
|
3
1
|
import "./_dev.js";
|
|
4
|
-
import {
|
|
2
|
+
import { createDisposable as e, resolveDisabled as t } from "./_shared.js";
|
|
3
|
+
import { DndError as n, DndScopeError as r } from "./errors.js";
|
|
4
|
+
import { createScopeTouchController as i } from "./_touch.js";
|
|
5
5
|
//#region src/sortable.ts
|
|
6
|
-
var
|
|
6
|
+
var a = Symbol("SortableScope"), o = "data-dnd-handle", s = "data-dnd-item", c = /* @__PURE__ */ new WeakMap(), l = {
|
|
7
7
|
container: !0,
|
|
8
8
|
edgeThreshold: 32,
|
|
9
9
|
speed: 18,
|
|
10
10
|
viewport: !1
|
|
11
11
|
};
|
|
12
|
-
function
|
|
13
|
-
let t =
|
|
14
|
-
if (!t) throw new
|
|
12
|
+
function u(e) {
|
|
13
|
+
let t = c.get(e);
|
|
14
|
+
if (!t) throw new r();
|
|
15
|
+
if (e.disposed) throw new r("Cannot register a sortable with a disposed scope.");
|
|
15
16
|
return t;
|
|
16
17
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
18
|
+
function d(e) {
|
|
19
|
+
if (e === !1) return null;
|
|
20
|
+
if (e === !0 || e === void 0) return l;
|
|
21
|
+
if (!Number.isFinite(e.edgeThreshold ?? 32) || (e.edgeThreshold ?? 32) < 0 || !Number.isFinite(e.speed ?? 18) || (e.speed ?? 18) <= 0) throw new n("Auto-scroll edgeThreshold must be non-negative and speed must be positive");
|
|
22
|
+
return {
|
|
19
23
|
container: e.container ?? !0,
|
|
20
24
|
edgeThreshold: e.edgeThreshold ?? 32,
|
|
21
25
|
speed: e.speed ?? 18,
|
|
22
26
|
viewport: e.viewport ?? !1
|
|
23
27
|
};
|
|
24
28
|
}
|
|
25
|
-
function
|
|
29
|
+
function f(e, t) {
|
|
26
30
|
return t.length !== e.length || t.some((t, n) => t !== e[n]);
|
|
27
31
|
}
|
|
28
|
-
function
|
|
32
|
+
function p(e) {
|
|
29
33
|
return e.__dndTouch === !0;
|
|
30
34
|
}
|
|
31
|
-
function
|
|
35
|
+
function m(e) {
|
|
36
|
+
return Object.freeze([...e]);
|
|
37
|
+
}
|
|
38
|
+
function h(e, t, ...n) {
|
|
39
|
+
if (t) try {
|
|
40
|
+
t(...n);
|
|
41
|
+
} catch {
|
|
42
|
+
`${e}`;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function g(e) {
|
|
32
46
|
typeof requestAnimationFrame == "function" && (e.hideFrame = requestAnimationFrame(() => {
|
|
33
47
|
e.hideFrame = null, e.draggedEl.style.display = "none";
|
|
34
48
|
}));
|
|
35
49
|
}
|
|
36
|
-
function
|
|
50
|
+
function _(e) {
|
|
37
51
|
e.hideFrame !== null && (cancelAnimationFrame(e.hideFrame), e.hideFrame = null);
|
|
38
52
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
53
|
+
function v(e) {
|
|
54
|
+
_(e), e.draggedEl.style.display = e.originalDisplay, e.draggedEl.removeAttribute("data-dragging");
|
|
41
55
|
}
|
|
42
|
-
function
|
|
56
|
+
function y(e, t) {
|
|
43
57
|
e.initialOrders.has(t) || e.initialOrders.set(t, t.getOrderedIds());
|
|
44
58
|
}
|
|
45
|
-
function
|
|
59
|
+
function b(e) {
|
|
60
|
+
let t = e.target;
|
|
61
|
+
return [...e.initialOrders].flatMap(([n, r]) => {
|
|
62
|
+
let i = r.filter((t) => t !== e.draggedId);
|
|
63
|
+
if (n === t && e.placeholder.parentElement === n.element) {
|
|
64
|
+
let t = [...n.element.children], r = t.indexOf(e.placeholder), a = n.getOrderedItems().filter((n) => n !== e.draggedEl && t.indexOf(n) < r).length;
|
|
65
|
+
i.splice(a, 0, e.draggedId);
|
|
66
|
+
}
|
|
67
|
+
return f(r, i) ? [{
|
|
68
|
+
after: i,
|
|
69
|
+
before: r,
|
|
70
|
+
handle: n
|
|
71
|
+
}] : [];
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
function x(e, t) {
|
|
46
75
|
let n = e.active;
|
|
47
|
-
n && (
|
|
76
|
+
n && (v(n), n.originalParent.insertBefore(n.draggedEl, n.originalNextSibling?.parentNode === n.originalParent ? n.originalNextSibling : null), n.placeholder.remove(), e.active = null, n.source.notifyDragEnd(n.draggedId, t), n.source.notifyInteraction({
|
|
48
77
|
index: n.source.getOrderedIds().indexOf(n.draggedId),
|
|
49
78
|
itemId: n.draggedId,
|
|
50
79
|
total: n.source.getOrderedIds().length,
|
|
51
80
|
type: "cancel"
|
|
52
81
|
}));
|
|
53
82
|
}
|
|
54
|
-
function
|
|
83
|
+
function S(e, t) {
|
|
55
84
|
let n = e.active;
|
|
56
85
|
if (!n) return;
|
|
57
|
-
let r = n.target, i = n.placeholder.parentElement;
|
|
58
|
-
|
|
59
|
-
|
|
86
|
+
let r = n.target, i = n.placeholder.parentElement, a = b(n);
|
|
87
|
+
for (let { after: e, before: t, handle: n } of a) n.notifyBeforeReorder(m(t), m(e));
|
|
88
|
+
v(n), r && e.handles.has(r) && i ? i.insertBefore(n.draggedEl, n.placeholder) : n.originalParent.insertBefore(n.draggedEl, n.originalNextSibling?.parentNode === n.originalParent ? n.originalNextSibling : null), n.placeholder.remove(), e.active = null, n.source.notifyDragEnd(n.draggedId, t);
|
|
89
|
+
let o = [];
|
|
60
90
|
for (let [t, r] of n.initialOrders) {
|
|
61
91
|
if (!e.handles.has(t)) continue;
|
|
62
92
|
let n = t.getOrderedIds();
|
|
63
|
-
|
|
93
|
+
f(r, n) && o.push({
|
|
64
94
|
after: n,
|
|
65
95
|
before: r,
|
|
66
96
|
handle: t
|
|
67
97
|
});
|
|
68
98
|
}
|
|
69
|
-
for (let { after: e, before: t, handle: n } of a) n.notifyBeforeReorder(t, e);
|
|
70
99
|
if (r && r !== n.source) {
|
|
71
|
-
let t =
|
|
100
|
+
let t = o.find((e) => e.handle === n.source), i = o.find((e) => e.handle === r);
|
|
72
101
|
if (t && i) {
|
|
73
102
|
e.commitMove({
|
|
74
103
|
itemId: n.draggedId,
|
|
75
104
|
source: n.source.element,
|
|
105
|
+
sourceBeforeIds: t.before,
|
|
76
106
|
sourceIds: t.after,
|
|
77
107
|
target: r.element,
|
|
108
|
+
targetBeforeIds: i.before,
|
|
78
109
|
targetIds: i.after
|
|
79
110
|
});
|
|
80
111
|
let a = i.after.indexOf(n.draggedId), o = i.after.length;
|
|
@@ -92,21 +123,25 @@ function v(e, t) {
|
|
|
92
123
|
}
|
|
93
124
|
return;
|
|
94
125
|
}
|
|
95
|
-
for (let { after: e,
|
|
96
|
-
|
|
126
|
+
for (let { after: e, before: t, handle: r } of o) r.commitReorder({
|
|
127
|
+
after: e,
|
|
128
|
+
before: t,
|
|
129
|
+
item: n.draggedId
|
|
130
|
+
});
|
|
131
|
+
let s = o.find((e) => e.handle === n.source), c = s ? s.after : n.source.getOrderedIds(), l = c.indexOf(n.draggedId);
|
|
97
132
|
n.source.notifyInteraction({
|
|
98
|
-
index:
|
|
133
|
+
index: l,
|
|
99
134
|
itemId: n.draggedId,
|
|
100
|
-
total:
|
|
135
|
+
total: c.length,
|
|
101
136
|
type: "drop"
|
|
102
137
|
});
|
|
103
138
|
}
|
|
104
|
-
function
|
|
139
|
+
function C(e, t, n) {
|
|
105
140
|
if (!e.active) return;
|
|
106
141
|
let { active: r } = e;
|
|
107
|
-
n || !t.dataTransfer || t.dataTransfer.dropEffect === "none" || !r.target || !e.handles.has(r.target) || r.source.isDisabled() || r.target.isDisabled() ?
|
|
142
|
+
n || !t.dataTransfer || t.dataTransfer.dropEffect === "none" || !r.target || !e.handles.has(r.target) || r.source.isDisabled() || r.target.isDisabled() ? x(e, t) : S(e, t);
|
|
108
143
|
}
|
|
109
|
-
function
|
|
144
|
+
function w(e, t, n, r) {
|
|
110
145
|
if (!r) return;
|
|
111
146
|
let { container: i, edgeThreshold: a, speed: o, viewport: s } = r, c = t.getBoundingClientRect();
|
|
112
147
|
if (n === "vertical") {
|
|
@@ -127,55 +162,52 @@ function b(e, t, n, r) {
|
|
|
127
162
|
top: 0
|
|
128
163
|
});
|
|
129
164
|
}
|
|
130
|
-
function
|
|
131
|
-
let
|
|
132
|
-
if (
|
|
133
|
-
let
|
|
134
|
-
if (
|
|
135
|
-
else if (
|
|
136
|
-
else if (
|
|
137
|
-
else if (
|
|
165
|
+
function T(e, t, n, r) {
|
|
166
|
+
let i = e.indexOf(t);
|
|
167
|
+
if (i < 0) return null;
|
|
168
|
+
let a = r === "vertical" ? n === "ArrowDown" : n === "ArrowRight", o = r === "vertical" ? n === "ArrowUp" : n === "ArrowLeft", s;
|
|
169
|
+
if (a) s = Math.min(e.length - 1, i + 1);
|
|
170
|
+
else if (o) s = Math.max(0, i - 1);
|
|
171
|
+
else if (n === "Home") s = 0;
|
|
172
|
+
else if (n === "End") s = e.length - 1;
|
|
138
173
|
else return null;
|
|
139
|
-
|
|
140
|
-
let d = o[u];
|
|
141
|
-
return d ? (t.insertBefore(e, u > s ? d.nextSibling : d), e.focus(), r()) : null;
|
|
174
|
+
return s === i ? null : s;
|
|
142
175
|
}
|
|
143
|
-
function
|
|
176
|
+
function E(t = {}) {
|
|
144
177
|
let n = {
|
|
145
178
|
active: null,
|
|
146
179
|
commitMove(e) {
|
|
147
|
-
t.onMove
|
|
180
|
+
h("onMove", t.onMove, Object.freeze({
|
|
148
181
|
...e,
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
182
|
+
sourceBeforeIds: m(e.sourceBeforeIds),
|
|
183
|
+
sourceIds: m(e.sourceIds),
|
|
184
|
+
targetBeforeIds: m(e.targetBeforeIds),
|
|
185
|
+
targetIds: m(e.targetIds)
|
|
186
|
+
}));
|
|
153
187
|
},
|
|
154
188
|
disposables: /* @__PURE__ */ new Set(),
|
|
155
189
|
handles: /* @__PURE__ */ new Set(),
|
|
156
|
-
lastRevert: null,
|
|
157
190
|
touch: null
|
|
158
|
-
},
|
|
191
|
+
}, r = e(() => {
|
|
159
192
|
n.touch?.dispose();
|
|
160
|
-
for (let e of n.disposables) e();
|
|
193
|
+
for (let e of [...n.disposables]) e();
|
|
194
|
+
n.disposables.clear(), n.handles.clear();
|
|
161
195
|
}), o = {
|
|
162
196
|
get disposalSignal() {
|
|
163
|
-
return
|
|
197
|
+
return r.disposalSignal;
|
|
164
198
|
},
|
|
165
|
-
dispose:
|
|
199
|
+
dispose: r.dispose,
|
|
166
200
|
get disposed() {
|
|
167
|
-
return
|
|
201
|
+
return r.disposed;
|
|
168
202
|
},
|
|
169
203
|
get isDragging() {
|
|
170
204
|
return n.active !== null;
|
|
171
205
|
},
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
},
|
|
175
|
-
[i]: !0,
|
|
176
|
-
[Symbol.dispose]: a[Symbol.dispose]
|
|
206
|
+
[a]: !0,
|
|
207
|
+
[Symbol.dispose]: r[Symbol.dispose]
|
|
177
208
|
};
|
|
178
|
-
return
|
|
209
|
+
return c.set(o, n), t.touch && (n.touch = i(t.touch === !0 ? {} : t.touch, (e) => {
|
|
210
|
+
if (n.active) return null;
|
|
179
211
|
for (let t of n.handles) {
|
|
180
212
|
let n = t.resolveTouchTarget(e);
|
|
181
213
|
if (n) return n;
|
|
@@ -183,172 +215,204 @@ function S(t = {}) {
|
|
|
183
215
|
return null;
|
|
184
216
|
})), o;
|
|
185
217
|
}
|
|
186
|
-
function
|
|
187
|
-
let { autoScroll:
|
|
188
|
-
|
|
189
|
-
let
|
|
190
|
-
|
|
218
|
+
function D(r) {
|
|
219
|
+
let { autoScroll: i = !0, axis: a = "vertical", element: c, getKey: l, handle: f, keyboard: _ = !0, placeholderClass: v = "dnd-placeholder", scope: b = E() } = r;
|
|
220
|
+
if (a !== "vertical" && a !== "horizontal") throw new n("axis must be \"vertical\" or \"horizontal\"");
|
|
221
|
+
let x = f?.trim() || null;
|
|
222
|
+
if ((f === void 0 || x) && x) try {
|
|
223
|
+
c.querySelector(x);
|
|
224
|
+
} catch (e) {
|
|
225
|
+
throw new n(`Invalid handle selector: "${f}"`, { cause: e });
|
|
226
|
+
}
|
|
227
|
+
let S = d(i), D = u(b);
|
|
228
|
+
if ([...D.handles].some((e) => e.element === c)) throw new n("A sortable is already registered for this element in the selected scope.");
|
|
229
|
+
let O = () => (r.items ? r.items() : Array.from(c.children)).filter((e) => e.parentElement === c && e.hasAttribute(s)), k = () => O().map((e) => l(e)), A = /* @__PURE__ */ new Map(), j = c.getAttribute("role"), M = (e) => {
|
|
230
|
+
let t = A.get(e);
|
|
191
231
|
if (t) return t;
|
|
192
232
|
let n = {
|
|
193
|
-
dataDndHandle: e.getAttribute(
|
|
194
|
-
dataDndItem: e.getAttribute(
|
|
233
|
+
dataDndHandle: e.getAttribute(o),
|
|
234
|
+
dataDndItem: e.getAttribute(s),
|
|
195
235
|
draggable: e.getAttribute("draggable"),
|
|
196
236
|
role: e.getAttribute("role"),
|
|
197
237
|
tabIndex: e.getAttribute("tabindex"),
|
|
198
238
|
touchAction: e.style.touchAction
|
|
199
239
|
};
|
|
200
|
-
return
|
|
201
|
-
},
|
|
240
|
+
return A.set(e, n), n;
|
|
241
|
+
}, N = (e, t, n) => {
|
|
202
242
|
n === null ? e.removeAttribute(t) : e.setAttribute(t, n);
|
|
203
|
-
},
|
|
204
|
-
|
|
205
|
-
let t =
|
|
206
|
-
t.role === null && e.setAttribute("role", "listitem"), t.tabIndex === null && (e.tabIndex = 0),
|
|
207
|
-
|
|
208
|
-
})
|
|
243
|
+
}, P = (e = O()) => {
|
|
244
|
+
e.forEach((e) => {
|
|
245
|
+
let t = M(e);
|
|
246
|
+
t.role === null && e.setAttribute("role", "listitem"), t.tabIndex === null && (e.tabIndex = 0), f === void 0 ? (e.setAttribute("draggable", "true"), D.touch && (e.style.touchAction = "none")) : x && e.querySelectorAll(x).forEach((e) => {
|
|
247
|
+
M(e), e.setAttribute(o, ""), e.setAttribute("draggable", "true"), D.touch && (e.style.touchAction = "none");
|
|
248
|
+
});
|
|
209
249
|
});
|
|
210
|
-
},
|
|
211
|
-
let e = /* @__PURE__ */ new Set();
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
250
|
+
}, F = () => {
|
|
251
|
+
let e = /* @__PURE__ */ new Set(), t = r.items ? r.items() : Array.from(c.children), n = t.filter((e) => e instanceof HTMLElement && e.parentElement === c), i = [];
|
|
252
|
+
n.length, t.length;
|
|
253
|
+
for (let t of n) try {
|
|
254
|
+
let n = l(t);
|
|
255
|
+
if (n) {
|
|
256
|
+
if (e.has(n)) {
|
|
257
|
+
`${n}`;
|
|
258
|
+
continue;
|
|
259
|
+
}
|
|
260
|
+
e.add(n), i.push(t);
|
|
219
261
|
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
262
|
+
} catch (e) {
|
|
263
|
+
`${String(e)}`;
|
|
264
|
+
}
|
|
265
|
+
I();
|
|
266
|
+
for (let e of i) M(e), e.setAttribute(s, "");
|
|
267
|
+
P(i);
|
|
268
|
+
}, I = () => {
|
|
269
|
+
for (let [e, t] of A) N(e, o, t.dataDndHandle), N(e, s, t.dataDndItem), N(e, "draggable", t.draggable), N(e, "role", t.role), N(e, "tabindex", t.tabIndex), e.style.touchAction = t.touchAction;
|
|
270
|
+
A.clear();
|
|
271
|
+
}, L = (e) => {
|
|
225
272
|
let t = document.createElement("div");
|
|
226
|
-
return t.className =
|
|
227
|
-
},
|
|
228
|
-
commitReorder: (e) => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
notifyBeforeReorder: (e, t) => n.onBeforeReorder?.(e, t),
|
|
242
|
-
notifyDragEnd: (e, t) => n.onDragEnd?.(e, t),
|
|
243
|
-
notifyDragStart: (e, t) => n.onDragStart?.(e, t),
|
|
244
|
-
notifyInteraction: (e) => n.onInteraction?.(e),
|
|
273
|
+
return t.className = v, t.setAttribute("aria-hidden", "true"), a === "horizontal" ? t.style.width = `${e.offsetWidth}px` : t.style.height = `${e.offsetHeight}px`, t;
|
|
274
|
+
}, R = {
|
|
275
|
+
commitReorder: (e) => h("onReorder", r.onReorder, Object.freeze({
|
|
276
|
+
after: m(e.after),
|
|
277
|
+
before: m(e.before),
|
|
278
|
+
item: e.item
|
|
279
|
+
})),
|
|
280
|
+
element: c,
|
|
281
|
+
getOrderedIds: k,
|
|
282
|
+
getOrderedItems: O,
|
|
283
|
+
isDisabled: () => t(r.disabled),
|
|
284
|
+
notifyBeforeReorder: (e, t) => h("onBeforeReorder", r.onBeforeReorder, e, t),
|
|
285
|
+
notifyDragEnd: (e, t) => h("onDragEnd", r.onDragEnd, e, t),
|
|
286
|
+
notifyDragStart: (e, t) => h("onDragStart", r.onDragStart, e, t),
|
|
287
|
+
notifyInteraction: (e) => h("onInteraction", r.onInteraction, Object.freeze(e)),
|
|
245
288
|
resolveTouchTarget: (e) => {
|
|
246
|
-
if (t(
|
|
247
|
-
let
|
|
248
|
-
if (!
|
|
249
|
-
if (
|
|
250
|
-
|
|
251
|
-
|
|
289
|
+
if (t(r.disabled) || !c.contains(e)) return null;
|
|
290
|
+
let n = e.closest(`[${s}]`);
|
|
291
|
+
if (!n || !O().includes(n)) return null;
|
|
292
|
+
if (f === void 0) return n;
|
|
293
|
+
if (!x) return null;
|
|
294
|
+
let i = e.closest(x);
|
|
295
|
+
return i && n.contains(i) ? i : null;
|
|
252
296
|
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
297
|
+
}, z = (e) => {
|
|
298
|
+
if (D.active || R.isDisabled()) return;
|
|
299
|
+
let t = e.target, n = t.closest(`[${s}]`);
|
|
300
|
+
if (!n || !O().includes(n)) return;
|
|
301
|
+
if (f !== void 0) {
|
|
302
|
+
let e = x ? t.closest(x) : null;
|
|
303
|
+
if (!e || !n.contains(e)) return;
|
|
304
|
+
}
|
|
305
|
+
let i = n.parentElement;
|
|
260
306
|
if (!i) return;
|
|
261
|
-
let a =
|
|
262
|
-
u.set(
|
|
263
|
-
let
|
|
264
|
-
draggedEl:
|
|
265
|
-
draggedId:
|
|
307
|
+
let a = L(n), o = n.nextSibling, c = l(n), u = /* @__PURE__ */ new Map();
|
|
308
|
+
u.set(R, R.getOrderedIds()), n.setAttribute("data-dragging", ""), i.insertBefore(a, o);
|
|
309
|
+
let d = {
|
|
310
|
+
draggedEl: n,
|
|
311
|
+
draggedId: c,
|
|
266
312
|
hideFrame: null,
|
|
267
313
|
initialOrders: u,
|
|
268
|
-
originalDisplay:
|
|
269
|
-
originalNextSibling:
|
|
314
|
+
originalDisplay: n.style.display,
|
|
315
|
+
originalNextSibling: o,
|
|
270
316
|
originalParent: i,
|
|
271
317
|
placeholder: a,
|
|
272
|
-
source:
|
|
273
|
-
target:
|
|
318
|
+
source: R,
|
|
319
|
+
target: R
|
|
274
320
|
};
|
|
275
|
-
if ((!
|
|
276
|
-
|
|
277
|
-
|
|
321
|
+
if ((!p(e) || e.__dndTouchPreview) && g(d), D.active = d, e.dataTransfer) try {
|
|
322
|
+
if (e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/plain", c), r.dragImage) {
|
|
323
|
+
let t = typeof r.dragImage == "function" ? r.dragImage(c, n, e) : r.dragImage, [i, a] = r.dragImageOffset ?? [0, 0];
|
|
324
|
+
t && e.dataTransfer.setDragImage(t, i, a);
|
|
325
|
+
}
|
|
326
|
+
} catch (e) {
|
|
327
|
+
`${e instanceof Error ? e.message : String(e)}`;
|
|
278
328
|
}
|
|
279
|
-
|
|
280
|
-
index:
|
|
281
|
-
itemId:
|
|
282
|
-
total:
|
|
329
|
+
R.notifyDragStart(d.draggedId, e), R.notifyInteraction({
|
|
330
|
+
index: R.getOrderedIds().indexOf(c),
|
|
331
|
+
itemId: c,
|
|
332
|
+
total: R.getOrderedIds().length,
|
|
283
333
|
type: "pickup"
|
|
284
334
|
});
|
|
285
|
-
},
|
|
286
|
-
let t =
|
|
287
|
-
if (!t || t.source.isDisabled() ||
|
|
288
|
-
e.preventDefault(),
|
|
289
|
-
let { draggedEl: n, placeholder: r } = t,
|
|
290
|
-
if (!
|
|
291
|
-
|
|
335
|
+
}, B = (e) => {
|
|
336
|
+
let t = D.active;
|
|
337
|
+
if (!t || t.source.isDisabled() || R.isDisabled()) return;
|
|
338
|
+
e.preventDefault(), w(e, c, a, S), y(t, R);
|
|
339
|
+
let { draggedEl: n, placeholder: r } = t, i = e.target.closest(`[${s}]`);
|
|
340
|
+
if (i && !O().includes(i)) return;
|
|
341
|
+
if (!i) {
|
|
342
|
+
r.parentElement !== c && c.appendChild(r), t.target = R;
|
|
292
343
|
return;
|
|
293
344
|
}
|
|
294
|
-
if (
|
|
295
|
-
let
|
|
296
|
-
|
|
297
|
-
},
|
|
298
|
-
let t =
|
|
299
|
-
t && (t.source.isDisabled() ||
|
|
300
|
-
},
|
|
301
|
-
|
|
302
|
-
},
|
|
303
|
-
if (!
|
|
304
|
-
let t = e.target?.
|
|
305
|
-
if (t
|
|
306
|
-
let
|
|
307
|
-
if (!
|
|
308
|
-
let
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
345
|
+
if (i === n || i === r) return;
|
|
346
|
+
let o = i.getBoundingClientRect(), l = a === "vertical" ? e.clientY >= o.top + o.height / 2 : e.clientX >= o.left + o.width / 2;
|
|
347
|
+
c.insertBefore(r, l ? i.nextSibling : i), t.target = R;
|
|
348
|
+
}, V = (e) => {
|
|
349
|
+
let t = D.active;
|
|
350
|
+
t && (t.source.isDisabled() || R.isDisabled() || (e.preventDefault(), t.target = R));
|
|
351
|
+
}, H = (e) => {
|
|
352
|
+
D.active?.source === R && C(D, e, !1);
|
|
353
|
+
}, U = (e) => {
|
|
354
|
+
if (!_ || R.isDisabled()) return;
|
|
355
|
+
let t = e.target, n = t?.closest(`[${s}]`);
|
|
356
|
+
if (!t || !n || !O().includes(n)) return;
|
|
357
|
+
let r = t.closest("input, textarea, select, button, a[href], [contenteditable]:not([contenteditable=\"false\"]), [role=\"button\"], [role=\"link\"]"), i = x ? t.closest(x) : null;
|
|
358
|
+
if (r && (!i || !n.contains(i))) return;
|
|
359
|
+
let o = O(), u = o.indexOf(n), d = T(o, n, e.key, a);
|
|
360
|
+
if (d === null) return;
|
|
361
|
+
let f = o[d];
|
|
362
|
+
if (!f) return;
|
|
363
|
+
let p = o.map(l), h = [...o];
|
|
364
|
+
h.splice(u, 1), h.splice(d, 0, n);
|
|
365
|
+
let g = h.map(l), v = l(n);
|
|
366
|
+
e.preventDefault(), R.notifyBeforeReorder(m(p), m(g)), c.insertBefore(n, d > u ? f.nextSibling : f), n.focus(), R.commitReorder({
|
|
367
|
+
after: g,
|
|
368
|
+
before: p,
|
|
369
|
+
item: v
|
|
370
|
+
}), R.notifyInteraction({
|
|
371
|
+
index: d,
|
|
372
|
+
itemId: v,
|
|
373
|
+
previousIndex: u,
|
|
374
|
+
total: g.length,
|
|
314
375
|
type: "move"
|
|
315
|
-
})
|
|
376
|
+
});
|
|
316
377
|
};
|
|
317
|
-
|
|
318
|
-
let
|
|
319
|
-
|
|
378
|
+
F();
|
|
379
|
+
let W, G = e(() => {
|
|
380
|
+
D.disposables.delete(G.dispose), D.active && (D.active.source === R || D.active.target === R) && !D.touch?.cancel() && C(D, new Event("dragend"), !0), W?.(), D.handles.delete(R), N(c, "role", j), I();
|
|
320
381
|
});
|
|
321
|
-
return D === null &&
|
|
382
|
+
return D.handles.add(R), W = D.touch?.register(c), j === null && c.setAttribute("role", "list"), c.addEventListener("dragstart", z, { signal: G.disposalSignal }), c.addEventListener("dragover", B, { signal: G.disposalSignal }), c.addEventListener("drop", V, { signal: G.disposalSignal }), c.addEventListener("dragend", H, { signal: G.disposalSignal }), c.addEventListener("keydown", U, { signal: G.disposalSignal }), D.disposables.add(G.dispose), {
|
|
322
383
|
get disposalSignal() {
|
|
323
|
-
return
|
|
384
|
+
return G.disposalSignal;
|
|
324
385
|
},
|
|
325
|
-
dispose:
|
|
386
|
+
dispose: G.dispose,
|
|
326
387
|
get disposed() {
|
|
327
|
-
return
|
|
388
|
+
return G.disposed;
|
|
328
389
|
},
|
|
329
390
|
get isDragging() {
|
|
330
|
-
return
|
|
331
|
-
},
|
|
332
|
-
revert: () => {
|
|
333
|
-
P?.(), P = null;
|
|
391
|
+
return D.active?.source === R;
|
|
334
392
|
},
|
|
335
|
-
[Symbol.dispose]:
|
|
336
|
-
|
|
337
|
-
|
|
393
|
+
[Symbol.dispose]: G[Symbol.dispose],
|
|
394
|
+
refresh: () => {
|
|
395
|
+
F();
|
|
338
396
|
}
|
|
339
397
|
};
|
|
340
398
|
}
|
|
341
|
-
function
|
|
342
|
-
let
|
|
399
|
+
function O(e, t, r) {
|
|
400
|
+
let i = /* @__PURE__ */ new Map();
|
|
401
|
+
for (let t of e) {
|
|
402
|
+
let e = r(t);
|
|
403
|
+
if (i.has(e)) throw new n(`Duplicate item key: "${e}"`);
|
|
404
|
+
i.set(e, t);
|
|
405
|
+
}
|
|
406
|
+
let a = [];
|
|
343
407
|
for (let e of t) {
|
|
344
|
-
if (!
|
|
345
|
-
let t =
|
|
346
|
-
|
|
408
|
+
if (!i.has(e)) continue;
|
|
409
|
+
let t = i.get(e);
|
|
410
|
+
a.push(t), i.delete(e);
|
|
347
411
|
}
|
|
348
|
-
for (let e of
|
|
349
|
-
return
|
|
412
|
+
for (let e of i.values()) a.push(e);
|
|
413
|
+
return a;
|
|
350
414
|
}
|
|
351
415
|
//#endregion
|
|
352
|
-
export {
|
|
416
|
+
export { n as DndError, r as DndScopeError, O as applyReorder, D as createSortable, E as createSortableScope };
|
|
353
417
|
|
|
354
418
|
//# sourceMappingURL=sortable.js.map
|