@vielzeug/dnd 1.2.3 → 2.0.1

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,17 +1,23 @@
1
- import { type Disposable } from './types';
1
+ import { type TouchInputOptions } from './_touch';
2
+ import type { Disposable } from './types';
2
3
  declare const SCOPE_BRAND: unique symbol;
3
4
  export interface SortableScope extends Disposable {
4
5
  /** `true` while any sortable in this scope is actively dragging. */
5
6
  readonly isDragging: boolean;
7
+ /**
8
+ * Calls the revert function registered for the most recent cross-container move.
9
+ * A no-op when no move registered a revert function.
10
+ */
11
+ revert(): void;
6
12
  readonly [SCOPE_BRAND]: true;
7
13
  }
8
14
  export interface AutoScrollOptions {
15
+ /** Scroll the sortable container while dragging near its edges. @default true */
16
+ container?: boolean;
9
17
  /** Distance in pixels from an edge that triggers auto-scroll. @default 32 */
10
18
  edgeThreshold?: number;
11
19
  /** Pixels scrolled per dragover frame while near an edge. @default 18 */
12
20
  speed?: number;
13
- /** Scroll the sortable container while dragging near its edges. @default true */
14
- container?: boolean;
15
21
  /** Scroll the viewport while dragging near the window edges. @default false */
16
22
  viewport?: boolean;
17
23
  }
@@ -37,21 +43,57 @@ export interface ReorderEvent {
37
43
  */
38
44
  setRevert(fn: () => void): void;
39
45
  }
46
+ /** A single committed move between two containers in the same sortable scope. */
47
+ export interface SortableMoveEvent {
48
+ /** Stable identity of the moved item. */
49
+ readonly itemId: string;
50
+ /** Registers a rollback for the most recent scope move. */
51
+ setRevert(fn: () => void): void;
52
+ /** Source container before the move. */
53
+ readonly source: HTMLElement;
54
+ /** Ordered source item IDs after the move. */
55
+ readonly sourceIds: string[];
56
+ /** Target container after the move. */
57
+ readonly target: HTMLElement;
58
+ /** Ordered target item IDs after the move. */
59
+ readonly targetIds: string[];
60
+ }
61
+ export interface SortableScopeOptions {
62
+ /**
63
+ * Called exactly once for every successful cross-container move.
64
+ * Local reorders continue to use each sortable's `onReorder` callback.
65
+ */
66
+ onMove?: (event: SortableMoveEvent) => void;
67
+ /**
68
+ * Enables touch input for sortable items registered to this scope.
69
+ * The controller ignores unrelated document draggables.
70
+ */
71
+ touch?: boolean | TouchInputOptions;
72
+ }
73
+ export type SortableTouchOptions = TouchInputOptions;
40
74
  export interface SortableOptions {
41
- /** Container element whose direct-child items are sortable. */
42
- element: HTMLElement;
43
- /** Shared scope for connected sortable containers. Containers only exchange items within the same scope. */
44
- scope?: SortableScope;
75
+ /** Auto-scrolls the container (and viewport) near edges while dragging. @default true */
76
+ autoScroll?: boolean | AutoScrollOptions;
77
+ /** Sorting axis used to compute insertion position. @default 'vertical' */
78
+ axis?: 'vertical' | 'horizontal';
45
79
  /**
46
- * Selector for the drag handle inside each item.
47
- * When omitted the whole item is the handle.
80
+ * When `true`, drag interactions are ignored.
81
+ *
82
+ * Note: if `disabled` transitions to `true` while a drag is in progress the
83
+ * drag is treated as a cancellation — the item snaps back to its original
84
+ * position rather than committing the last placeholder location.
48
85
  */
49
- handle?: string;
86
+ disabled?: boolean;
87
+ /** Optional custom drag preview element. */
88
+ dragImage?: HTMLElement | ((id: string, item: HTMLElement, event: DragEvent) => HTMLElement | null | undefined);
50
89
  /**
51
- * Enables keyboard-based reordering using arrow keys plus Home/End.
52
- * @default true
90
+ * Hotspot offset `[x, y]` passed to `setDragImage`.
91
+ * Controls which point of the preview image follows the cursor.
92
+ * @default [0, 0]
53
93
  */
54
- keyboard?: boolean;
94
+ dragImageOffset?: [number, number];
95
+ /** Container element whose direct-child items are sortable. */
96
+ element: HTMLElement;
55
97
  /**
56
98
  * Returns the identity key for a given item element.
57
99
  * This separates the "what is this item?" concern (yours) from the "which children
@@ -63,27 +105,16 @@ export interface SortableOptions {
63
105
  * ```
64
106
  */
65
107
  getKey: (element: HTMLElement) => string;
66
- /** Sorting axis used to compute insertion position. @default 'vertical' */
67
- axis?: 'vertical' | 'horizontal';
68
- /** Auto-scrolls the container (and viewport) near edges while dragging. @default true */
69
- autoScroll?: boolean | AutoScrollOptions;
70
- /** Optional custom drag preview element. */
71
- dragImage?: HTMLElement | ((id: string, item: HTMLElement, event: DragEvent) => HTMLElement | null | undefined);
72
- /** CSS class applied to the placeholder element. @default 'dnd-placeholder' */
73
- placeholderClass?: string;
74
108
  /**
75
- * Called with a {@link ReorderEvent} after a successful reorder, only when the order changed.
76
- *
77
- * @example
78
- * ```ts
79
- * onReorder: ({ ids, setRevert }) => {
80
- * const prev = order;
81
- * setOrder(ids);
82
- * setRevert(() => setOrder(prev));
83
- * },
84
- * ```
109
+ * Selector for the drag handle inside each item.
110
+ * When omitted the whole item is the handle.
85
111
  */
86
- onReorder?: (event: ReorderEvent) => void;
112
+ handle?: string;
113
+ /**
114
+ * Enables keyboard-based reordering using arrow keys plus Home/End.
115
+ * @default true
116
+ */
117
+ keyboard?: boolean;
87
118
  /**
88
119
  * Called just before a successful drag commit with the before and after order snapshots.
89
120
  * Use this hook to set up FLIP animations — the source items are still in their
@@ -97,24 +128,27 @@ export interface SortableOptions {
97
128
  * ```
98
129
  */
99
130
  onBeforeReorder?: (from: string[], to: string[]) => void;
100
- /**
101
- * When `true`, drag interactions are ignored.
102
- *
103
- * Note: if `disabled` transitions to `true` while a drag is in progress the
104
- * drag is treated as a cancellation — the item snaps back to its original
105
- * position rather than committing the last placeholder location.
106
- */
107
- disabled?: boolean;
108
- /** Called when the user starts dragging an item. */
109
- onDragStart?: (id: string, event: DragEvent) => void;
110
131
  /** Called when a drag ends (whether dropped or cancelled). */
111
132
  onDragEnd?: (id: string, event: DragEvent) => void;
133
+ /** Called when the user starts dragging an item. */
134
+ onDragStart?: (id: string, event: DragEvent) => void;
112
135
  /**
113
- * Hotspot offset `[x, y]` passed to `setDragImage`.
114
- * Controls which point of the preview image follows the cursor.
115
- * @default [0, 0]
136
+ * Called with a {@link ReorderEvent} after a successful reorder, only when the order changed.
137
+ *
138
+ * @example
139
+ * ```ts
140
+ * onReorder: ({ ids, setRevert }) => {
141
+ * const prev = order;
142
+ * setOrder(ids);
143
+ * setRevert(() => setOrder(prev));
144
+ * },
145
+ * ```
116
146
  */
117
- dragImageOffset?: [number, number];
147
+ onReorder?: (event: ReorderEvent) => void;
148
+ /** CSS class applied to the placeholder element. @default 'dnd-placeholder' */
149
+ placeholderClass?: string;
150
+ /** Shared scope for connected sortable containers. Containers only exchange items within the same scope. */
151
+ scope?: SortableScope;
118
152
  }
119
153
  export interface Sortable extends Disposable {
120
154
  readonly isDragging: boolean;
@@ -163,7 +197,7 @@ export interface Sortable extends Disposable {
163
197
  * scope.dispose();
164
198
  * ```
165
199
  */
166
- export declare function createSortableScope(): SortableScope;
200
+ export declare function createSortableScope(options?: SortableScopeOptions): SortableScope;
167
201
  /**
168
202
  * Makes a list of items sortable via native HTML drag interactions.
169
203
  *
@@ -1 +1 @@
1
- {"version":3,"file":"sortable.d.ts","sourceRoot":"","sources":["../src/sortable.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,SAAS,CAAC;AAI1C,QAAA,MAAM,WAAW,eAA0B,CAAC;AAE5C,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C,oEAAoE;IACpE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,CAAC,WAAW,CAAC,EAAE,IAAI,CAAC;CAC9B;AAID,MAAM,WAAW,iBAAiB;IAChC,6EAA6E;IAC7E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,yEAAyE;IACzE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,+EAA+E;IAC/E,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,2DAA2D;IAC3D,GAAG,EAAE,MAAM,EAAE,CAAC;IACd;;;;;;;;;;;;;OAaG;IACH,SAAS,CAAC,EAAE,EAAE,MAAM,IAAI,GAAG,IAAI,CAAC;CACjC;AAED,MAAM,W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AAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GAAG,CAAC,EAAE,CAgB3F"}
package/dist/sortable.js CHANGED
@@ -1,69 +1,86 @@
1
1
  import { createDisposable as e, resolveDisabled as t } from "./_shared.js";
2
2
  import { DndScopeError as n } from "./errors.js";
3
3
  import "./_dev.js";
4
+ import { createScopeTouchController as r } from "./_touch.js";
4
5
  //#region src/sortable.ts
5
- var r = Symbol("SortableScope"), i = "data-dnd-handle", a = "data-dnd-item", o = /* @__PURE__ */ new WeakMap(), s = {
6
+ var i = Symbol("SortableScope"), a = "data-dnd-handle", o = "data-dnd-item", s = /* @__PURE__ */ new WeakMap(), c = {
6
7
  container: !0,
7
8
  edgeThreshold: 32,
8
9
  speed: 18,
9
10
  viewport: !1
10
11
  };
11
- function c(e) {
12
- let t = o.get(e);
12
+ function l(e) {
13
+ let t = s.get(e);
13
14
  if (!t) throw new n();
14
15
  return t;
15
16
  }
16
- function l(e) {
17
- return e === !1 ? null : e === !0 || e === void 0 ? s : {
17
+ function u(e) {
18
+ return e === !1 ? null : e === !0 || e === void 0 ? c : {
18
19
  container: e.container ?? !0,
19
20
  edgeThreshold: e.edgeThreshold ?? 32,
20
21
  speed: e.speed ?? 18,
21
22
  viewport: e.viewport ?? !1
22
23
  };
23
24
  }
24
- function u(e, t) {
25
+ function d(e, t) {
25
26
  return t.length !== e.length || t.some((t, n) => t !== e[n]);
26
27
  }
27
- function d(e) {
28
- e.querySelectorAll(`[${i}]`).forEach((e) => {
29
- e.removeAttribute(i), e.removeAttribute("draggable"), e.style.touchAction = "";
30
- });
31
- }
32
28
  function f(e) {
29
+ return e.__dndTouch === !0;
30
+ }
31
+ function p(e) {
33
32
  typeof requestAnimationFrame == "function" && (e.hideFrame = requestAnimationFrame(() => {
34
33
  e.hideFrame = null, e.draggedEl.style.display = "none";
35
34
  }));
36
35
  }
37
- function p(e) {
36
+ function m(e) {
38
37
  e.hideFrame !== null && (cancelAnimationFrame(e.hideFrame), e.hideFrame = null);
39
38
  }
40
- function m(e) {
41
- p(e), e.draggedEl.style.display = e.originalDisplay, e.draggedEl.removeAttribute("data-dragging");
39
+ function h(e) {
40
+ m(e), e.draggedEl.style.display = e.originalDisplay, e.draggedEl.removeAttribute("data-dragging");
42
41
  }
43
- function h(e, t) {
42
+ function g(e, t) {
44
43
  e.initialOrders.has(t) || e.initialOrders.set(t, t.getOrderedIds());
45
44
  }
46
- function g(e, t) {
45
+ function _(e, t) {
47
46
  let n = e.active;
48
- n && (m(n), n.originalParent.insertBefore(n.draggedEl, n.originalNextSibling), n.placeholder.remove(), e.active = null, n.source.notifyDragEnd(n.draggedId, t));
47
+ n && (h(n), n.originalParent.insertBefore(n.draggedEl, n.originalNextSibling), n.placeholder.remove(), e.active = null, n.source.notifyDragEnd(n.draggedId, t));
49
48
  }
50
- function _(e, t) {
49
+ function v(e, t) {
51
50
  let n = e.active;
52
51
  if (!n) return;
53
52
  let r = n.target, i = n.placeholder.parentElement;
54
- m(n), r && e.handles.has(r) && i ? i.insertBefore(n.draggedEl, n.placeholder) : n.originalParent.insertBefore(n.draggedEl, n.originalNextSibling), n.placeholder.remove(), e.active = null, n.source.notifyDragEnd(n.draggedId, t);
53
+ h(n), r && e.handles.has(r) && i ? i.insertBefore(n.draggedEl, n.placeholder) : n.originalParent.insertBefore(n.draggedEl, n.originalNextSibling), n.placeholder.remove(), e.active = null, n.source.notifyDragEnd(n.draggedId, t);
54
+ let a = [];
55
55
  for (let [t, r] of n.initialOrders) {
56
56
  if (!e.handles.has(t)) continue;
57
57
  let n = t.getOrderedIds();
58
- u(r, n) && (t.notifyBeforeReorder(r, n), t.commitReorder(n));
58
+ d(r, n) && a.push({
59
+ after: n,
60
+ before: r,
61
+ handle: t
62
+ });
59
63
  }
64
+ for (let { after: e, before: t, handle: n } of a) n.notifyBeforeReorder(t, e);
65
+ if (r && r !== n.source) {
66
+ let t = a.find((e) => e.handle === n.source), i = a.find((e) => e.handle === r);
67
+ t && i && e.commitMove({
68
+ itemId: n.draggedId,
69
+ source: n.source.element,
70
+ sourceIds: t.after,
71
+ target: r.element,
72
+ targetIds: i.after
73
+ });
74
+ return;
75
+ }
76
+ for (let { after: e, handle: t } of a) t.commitReorder(e);
60
77
  }
61
- function v(e, t, n) {
78
+ function y(e, t, n) {
62
79
  if (!e.active) return;
63
80
  let { active: r } = e;
64
- n || !t.dataTransfer || t.dataTransfer.dropEffect === "none" || !r.target || !e.handles.has(r.target) || r.source.isDisabled() || r.target.isDisabled() ? g(e, t) : _(e, t);
81
+ n || !t.dataTransfer || t.dataTransfer.dropEffect === "none" || !r.target || !e.handles.has(r.target) || r.source.isDisabled() || r.target.isDisabled() ? _(e, t) : v(e, t);
65
82
  }
66
- function y(e, t, n, r) {
83
+ function b(e, t, n, r) {
67
84
  if (!r) return;
68
85
  let { container: i, edgeThreshold: a, speed: o, viewport: s } = r, c = t.getBoundingClientRect();
69
86
  if (n === "vertical") {
@@ -84,7 +101,7 @@ function y(e, t, n, r) {
84
101
  top: 0
85
102
  });
86
103
  }
87
- function b(e, t, n, r, i, a) {
104
+ function x(e, t, n, r, i, a) {
88
105
  let o = n(), s = o.indexOf(e);
89
106
  if (s < 0) return null;
90
107
  let c = a === "vertical" ? i === "ArrowDown" : i === "ArrowRight", l = a === "vertical" ? i === "ArrowUp" : i === "ArrowLeft", u;
@@ -97,150 +114,193 @@ function b(e, t, n, r, i, a) {
97
114
  let d = o[u];
98
115
  return d ? (t.insertBefore(e, u > s ? d.nextSibling : d), e.focus(), r()) : null;
99
116
  }
100
- function x() {
101
- let t = {
117
+ function S(t = {}) {
118
+ let n = {
102
119
  active: null,
120
+ commitMove(e) {
121
+ t.onMove?.({
122
+ ...e,
123
+ setRevert(e) {
124
+ n.lastRevert = e;
125
+ }
126
+ });
127
+ },
103
128
  disposables: /* @__PURE__ */ new Set(),
104
- handles: /* @__PURE__ */ new Set()
105
- }, n = e(() => {
106
- for (let e of t.disposables) e();
107
- }), i = {
129
+ handles: /* @__PURE__ */ new Set(),
130
+ lastRevert: null,
131
+ touch: null
132
+ }, a = e(() => {
133
+ n.touch?.dispose();
134
+ for (let e of n.disposables) e();
135
+ }), o = {
108
136
  get disposalSignal() {
109
- return n.disposalSignal;
137
+ return a.disposalSignal;
110
138
  },
111
- dispose: n.dispose,
139
+ dispose: a.dispose,
112
140
  get disposed() {
113
- return n.disposed;
141
+ return a.disposed;
114
142
  },
115
143
  get isDragging() {
116
- return t.active !== null;
144
+ return n.active !== null;
145
+ },
146
+ revert() {
147
+ n.lastRevert?.(), n.lastRevert = null;
117
148
  },
118
- [r]: !0,
119
- [Symbol.dispose]: n[Symbol.dispose]
149
+ [i]: !0,
150
+ [Symbol.dispose]: a[Symbol.dispose]
120
151
  };
121
- return o.set(i, t), i;
152
+ return s.set(o, n), t.touch && (n.touch = r(t.touch === !0 ? {} : t.touch, (e) => {
153
+ for (let t of n.handles) {
154
+ let n = t.resolveTouchTarget(e);
155
+ if (n) return n;
156
+ }
157
+ return null;
158
+ })), o;
122
159
  }
123
- function S(n) {
124
- let { autoScroll: r = !0, axis: o = "vertical", element: s, getKey: u, handle: p, keyboard: m = !0, placeholderClass: g = "dnd-placeholder", scope: _ = x() } = n, S = l(r), C = c(_);
125
- p !== void 0 && p.trim();
126
- let w = () => Array.from(s.children).filter((e) => e.hasAttribute(a)), T = () => w().map((e) => u(e)), E = () => {
127
- d(s), w().forEach((e) => {
128
- e.setAttribute("role", "listitem"), e.tabIndex = 0, p ? (e.removeAttribute("draggable"), e.style.touchAction = "", e.querySelectorAll(p).forEach((e) => {
129
- e.setAttribute(i, ""), e.setAttribute("draggable", "true"), e.style.touchAction = "none";
130
- })) : (e.setAttribute("draggable", "true"), e.style.touchAction = "none");
160
+ function C(n) {
161
+ let { autoScroll: r = !0, axis: i = "vertical", element: s, getKey: c, handle: d, keyboard: m = !0, placeholderClass: h = "dnd-placeholder", scope: _ = S() } = n, v = u(r), C = l(_);
162
+ d !== void 0 && d.trim();
163
+ let w = () => Array.from(s.children).filter((e) => e.hasAttribute(o)), T = () => w().map((e) => c(e)), E = /* @__PURE__ */ new Map(), D = s.getAttribute("role"), O = (e) => {
164
+ let t = E.get(e);
165
+ if (t) return t;
166
+ let n = {
167
+ dataDndHandle: e.getAttribute(a),
168
+ dataDndItem: e.getAttribute(o),
169
+ draggable: e.getAttribute("draggable"),
170
+ role: e.getAttribute("role"),
171
+ tabIndex: e.getAttribute("tabindex"),
172
+ touchAction: e.style.touchAction
173
+ };
174
+ return E.set(e, n), n;
175
+ }, k = (e, t, n) => {
176
+ n === null ? e.removeAttribute(t) : e.setAttribute(t, n);
177
+ }, A = () => {
178
+ w().forEach((e) => {
179
+ let t = O(e);
180
+ t.role === null && e.setAttribute("role", "listitem"), t.tabIndex === null && (e.tabIndex = 0), d ? e.querySelectorAll(d).forEach((e) => {
181
+ O(e), e.setAttribute(a, ""), e.setAttribute("draggable", "true"), e.style.touchAction = "none";
182
+ }) : (e.setAttribute("draggable", "true"), e.style.touchAction = "none");
131
183
  });
132
- }, D = () => {
184
+ }, j = () => {
133
185
  let e = /* @__PURE__ */ new Set();
134
186
  Array.from(s.children).forEach((t) => {
135
187
  let n = t;
136
188
  try {
137
- let t = u(n);
138
- t && (e.has(t) ? `${t}` : e.add(t), n.setAttribute(a, ""));
189
+ let t = c(n);
190
+ t && (O(n), e.has(t) ? `${t}` : e.add(t), n.setAttribute(o, ""));
139
191
  } catch (e) {
140
192
  `${String(e)}`;
141
193
  }
142
- }), E();
143
- }, O = () => {
144
- d(s), s.querySelectorAll(`[${a}]`).forEach((e) => {
145
- e.removeAttribute(a), e.removeAttribute("draggable"), e.removeAttribute("role"), e.removeAttribute("tabindex"), e.style.touchAction = "";
146
- });
147
- }, k = (e) => {
194
+ }), A();
195
+ }, M = () => {
196
+ for (let [e, t] of E) k(e, a, t.dataDndHandle), k(e, o, t.dataDndItem), k(e, "draggable", t.draggable), k(e, "role", t.role), k(e, "tabindex", t.tabIndex), e.style.touchAction = t.touchAction;
197
+ E.clear();
198
+ }, N = (e) => {
148
199
  let t = document.createElement("div");
149
- return t.className = g, t.setAttribute("aria-hidden", "true"), o === "horizontal" ? t.style.width = `${e.offsetWidth}px` : t.style.height = `${e.offsetHeight}px`, t;
150
- }, A = null, j = {
200
+ return t.className = h, t.setAttribute("aria-hidden", "true"), i === "horizontal" ? t.style.width = `${e.offsetWidth}px` : t.style.height = `${e.offsetHeight}px`, t;
201
+ }, P = null, F = {
151
202
  commitReorder: (e) => {
152
203
  if (!n.onReorder) return;
153
204
  let t = {
154
205
  ids: e,
155
206
  setRevert(e) {
156
- A = e;
207
+ P = e;
157
208
  }
158
209
  };
159
210
  n.onReorder(t);
160
211
  },
212
+ element: s,
161
213
  getOrderedIds: T,
162
214
  isDisabled: () => t(n.disabled),
163
215
  notifyBeforeReorder: (e, t) => n.onBeforeReorder?.(e, t),
164
216
  notifyDragEnd: (e, t) => n.onDragEnd?.(e, t),
165
- notifyDragStart: (e, t) => n.onDragStart?.(e, t)
217
+ notifyDragStart: (e, t) => n.onDragStart?.(e, t),
218
+ resolveTouchTarget: (e) => {
219
+ if (t(n.disabled) || !s.contains(e)) return null;
220
+ let r = e.closest(`[${o}]`);
221
+ if (!r || !s.contains(r)) return null;
222
+ if (!d) return r;
223
+ let i = e.closest(d);
224
+ return i && r.contains(i) ? i : null;
225
+ }
166
226
  };
167
- C.handles.add(j);
168
- let M = (e) => {
169
- if (C.active || j.isDisabled()) return;
170
- let t = e.target, r = t.closest(`[${a}]`);
171
- if (!r || p && !t.closest(p)) return;
227
+ C.handles.add(F);
228
+ let I = (e) => {
229
+ if (C.active || F.isDisabled()) return;
230
+ let t = e.target, r = t.closest(`[${o}]`);
231
+ if (!r || d && !t.closest(d)) return;
172
232
  let i = r.parentElement;
173
233
  if (!i) return;
174
- let o = k(r), s = r.nextSibling, c = u(r), l = /* @__PURE__ */ new Map();
175
- l.set(j, j.getOrderedIds()), r.setAttribute("data-dragging", ""), i.insertBefore(o, s);
176
- let d = {
234
+ let a = N(r), s = r.nextSibling, l = c(r), u = /* @__PURE__ */ new Map();
235
+ u.set(F, F.getOrderedIds()), r.setAttribute("data-dragging", ""), i.insertBefore(a, s);
236
+ let m = {
177
237
  draggedEl: r,
178
- draggedId: c,
238
+ draggedId: l,
179
239
  hideFrame: null,
180
- initialOrders: l,
240
+ initialOrders: u,
181
241
  originalDisplay: r.style.display,
182
242
  originalNextSibling: s,
183
243
  originalParent: i,
184
- placeholder: o,
185
- source: j,
186
- target: j
244
+ placeholder: a,
245
+ source: F,
246
+ target: F
187
247
  };
188
- if (f(d), C.active = d, e.dataTransfer && (e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/plain", c), n.dragImage)) {
189
- let t = typeof n.dragImage == "function" ? n.dragImage(c, r, e) : n.dragImage, [i, a] = n.dragImageOffset ?? [0, 0];
248
+ if ((!f(e) || e.__dndTouchPreview) && p(m), C.active = m, e.dataTransfer && (e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/plain", l), n.dragImage)) {
249
+ let t = typeof n.dragImage == "function" ? n.dragImage(l, r, e) : n.dragImage, [i, a] = n.dragImageOffset ?? [0, 0];
190
250
  t && e.dataTransfer.setDragImage(t, i, a);
191
251
  }
192
- j.notifyDragStart(d.draggedId, e);
193
- }, N = (e) => {
252
+ F.notifyDragStart(m.draggedId, e);
253
+ }, L = (e) => {
194
254
  let t = C.active;
195
- if (!t || t.source.isDisabled() || j.isDisabled()) return;
196
- e.preventDefault(), y(e, s, o, S), h(t, j);
197
- let { draggedEl: n, placeholder: r } = t, i = e.target.closest(`[${a}]`);
198
- if (!i) {
199
- r.parentElement !== s && s.appendChild(r), t.target = j;
255
+ if (!t || t.source.isDisabled() || F.isDisabled()) return;
256
+ e.preventDefault(), b(e, s, i, v), g(t, F);
257
+ let { draggedEl: n, placeholder: r } = t, a = e.target.closest(`[${o}]`);
258
+ if (!a) {
259
+ r.parentElement !== s && s.appendChild(r), t.target = F;
200
260
  return;
201
261
  }
202
- if (i === n || i === r) return;
203
- let c = i.getBoundingClientRect(), l = o === "vertical" ? e.clientY >= c.top + c.height / 2 : e.clientX >= c.left + c.width / 2;
204
- s.insertBefore(r, l ? i.nextSibling : i), t.target = j;
205
- }, P = (e) => {
262
+ if (a === n || a === r) return;
263
+ let c = a.getBoundingClientRect(), l = i === "vertical" ? e.clientY >= c.top + c.height / 2 : e.clientX >= c.left + c.width / 2;
264
+ s.insertBefore(r, l ? a.nextSibling : a), t.target = F;
265
+ }, R = (e) => {
206
266
  let t = C.active;
207
- t && (t.source.isDisabled() || j.isDisabled() || (e.preventDefault(), t.target = j));
208
- }, F = (e) => {
209
- C.active?.source === j && v(C, e, !1);
210
- }, I = (e) => {
211
- if (!m || j.isDisabled()) return;
267
+ t && (t.source.isDisabled() || F.isDisabled() || (e.preventDefault(), t.target = F));
268
+ }, z = (e) => {
269
+ C.active?.source === F && y(C, e, !1);
270
+ }, B = (e) => {
271
+ if (!m || F.isDisabled()) return;
212
272
  let t = e.target?.tagName;
213
273
  if (t === "INPUT" || t === "TEXTAREA" || t === "SELECT") return;
214
- let n = e.target.closest(`[${a}]`);
274
+ let n = e.target.closest(`[${o}]`);
215
275
  if (!n || !s.contains(n)) return;
216
- let r = T(), i = b(n, s, w, T, e.key, o);
217
- i !== null && (e.preventDefault(), j.notifyBeforeReorder(r, i), j.commitReorder(i));
276
+ let r = T(), a = x(n, s, w, T, e.key, i);
277
+ a !== null && (e.preventDefault(), F.notifyBeforeReorder(r, a), F.commitReorder(a));
218
278
  };
219
- D();
220
- let L = e(() => {
221
- C.disposables.delete(L.dispose), C.active && (C.active.source === j || C.active.target === j) && v(C, new Event("dragend"), !0), C.handles.delete(j), s.removeAttribute("role"), O();
279
+ j();
280
+ let V = e(() => {
281
+ C.disposables.delete(V.dispose), C.active && (C.active.source === F || C.active.target === F) && y(C, new Event("dragend"), !0), C.handles.delete(F), k(s, "role", D), M();
222
282
  });
223
- return s.setAttribute("role", "list"), s.addEventListener("dragstart", M, { signal: L.disposalSignal }), s.addEventListener("dragover", N, { signal: L.disposalSignal }), s.addEventListener("drop", P, { signal: L.disposalSignal }), s.addEventListener("dragend", F, { signal: L.disposalSignal }), s.addEventListener("keydown", I, { signal: L.disposalSignal }), C.disposables.add(L.dispose), {
283
+ return D === null && s.setAttribute("role", "list"), s.addEventListener("dragstart", I, { signal: V.disposalSignal }), s.addEventListener("dragover", L, { signal: V.disposalSignal }), s.addEventListener("drop", R, { signal: V.disposalSignal }), s.addEventListener("dragend", z, { signal: V.disposalSignal }), s.addEventListener("keydown", B, { signal: V.disposalSignal }), C.disposables.add(V.dispose), {
224
284
  get disposalSignal() {
225
- return L.disposalSignal;
285
+ return V.disposalSignal;
226
286
  },
227
- dispose: L.dispose,
287
+ dispose: V.dispose,
228
288
  get disposed() {
229
- return L.disposed;
289
+ return V.disposed;
230
290
  },
231
291
  get isDragging() {
232
- return C.active?.source === j;
292
+ return C.active?.source === F;
233
293
  },
234
294
  revert: () => {
235
- A?.(), A = null;
295
+ P?.(), P = null;
236
296
  },
237
- [Symbol.dispose]: L[Symbol.dispose],
297
+ [Symbol.dispose]: V[Symbol.dispose],
238
298
  sync: () => {
239
- D();
299
+ j();
240
300
  }
241
301
  };
242
302
  }
243
- function C(e, t, n) {
303
+ function w(e, t, n) {
244
304
  let r = new Map(e.map((e) => [n(e), e])), i = [];
245
305
  for (let e of t) {
246
306
  if (!r.has(e)) continue;
@@ -251,6 +311,6 @@ function C(e, t, n) {
251
311
  return i;
252
312
  }
253
313
  //#endregion
254
- export { C as applyReorder, S as createSortable, x as createSortableScope };
314
+ export { w as applyReorder, C as createSortable, S as createSortableScope };
255
315
 
256
316
  //# sourceMappingURL=sortable.js.map