@dnd-kit/dom 0.1.10 → 0.1.11
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/index.cjs +99 -20
- package/index.cjs.map +1 -1
- package/index.d.cts +21 -0
- package/index.d.ts +21 -0
- package/index.js +100 -21
- package/index.js.map +1 -1
- package/package.json +5 -5
package/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var abstract = require('@dnd-kit/abstract');
|
|
4
|
-
var state = require('@dnd-kit/state');
|
|
5
4
|
var utilities = require('@dnd-kit/dom/utilities');
|
|
5
|
+
var state = require('@dnd-kit/state');
|
|
6
6
|
var geometry = require('@dnd-kit/geometry');
|
|
7
7
|
var collision = require('@dnd-kit/collision');
|
|
8
8
|
|
|
@@ -102,7 +102,7 @@ var defaultAnnouncements = {
|
|
|
102
102
|
return `Picked up draggable item ${source.id}.`;
|
|
103
103
|
},
|
|
104
104
|
dragover({ operation: { source, target } }) {
|
|
105
|
-
if (!source) return;
|
|
105
|
+
if (!source || source.id === (target == null ? void 0 : target.id)) return;
|
|
106
106
|
if (target) {
|
|
107
107
|
return `Draggable item ${source.id} was moved over droppable target ${target.id}.`;
|
|
108
108
|
}
|
|
@@ -156,6 +156,7 @@ function createLiveRegion(id) {
|
|
|
156
156
|
}
|
|
157
157
|
|
|
158
158
|
// src/core/plugins/accessibility/Accessibility.ts
|
|
159
|
+
var debouncedEvents = ["dragover", "dragmove"];
|
|
159
160
|
var Accessibility = class extends abstract.Plugin {
|
|
160
161
|
constructor(manager, options) {
|
|
161
162
|
super(manager);
|
|
@@ -166,20 +167,42 @@ var Accessibility = class extends abstract.Plugin {
|
|
|
166
167
|
announcement: announcementPrefix = defaultAnnouncementIdPrefix
|
|
167
168
|
} = {},
|
|
168
169
|
announcements = defaultAnnouncements,
|
|
169
|
-
screenReaderInstructions = defaultScreenReaderInstructions
|
|
170
|
+
screenReaderInstructions = defaultScreenReaderInstructions,
|
|
171
|
+
debounce: debounceMs = 500
|
|
170
172
|
} = options != null ? options : {};
|
|
171
173
|
const descriptionId = id ? `${descriptionPrefix}-${id}` : utilities.generateUniqueId(descriptionPrefix);
|
|
172
174
|
const announcementId = id ? `${announcementPrefix}-${id}` : utilities.generateUniqueId(announcementPrefix);
|
|
173
175
|
let hiddenTextElement;
|
|
174
176
|
let liveRegionElement;
|
|
177
|
+
let liveRegionTextNode;
|
|
178
|
+
let latestAnnouncement;
|
|
179
|
+
const updateAnnouncement = (value = latestAnnouncement) => {
|
|
180
|
+
if (!liveRegionTextNode || !value) return;
|
|
181
|
+
if ((liveRegionTextNode == null ? void 0 : liveRegionTextNode.nodeValue) !== value) {
|
|
182
|
+
liveRegionTextNode.nodeValue = value;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
const scheduleUpdateAnnouncement = () => utilities.scheduler.schedule(updateAnnouncement);
|
|
186
|
+
const debouncedUpdateAnnouncement = debounce(
|
|
187
|
+
scheduleUpdateAnnouncement,
|
|
188
|
+
debounceMs
|
|
189
|
+
);
|
|
175
190
|
const eventListeners = Object.entries(announcements).map(
|
|
176
191
|
([eventName, getAnnouncement]) => {
|
|
177
192
|
return this.manager.monitor.addEventListener(
|
|
178
193
|
eventName,
|
|
179
194
|
(event, manager2) => {
|
|
195
|
+
const element = liveRegionTextNode;
|
|
196
|
+
if (!element) return;
|
|
180
197
|
const announcement = getAnnouncement == null ? void 0 : getAnnouncement(event, manager2);
|
|
181
|
-
if (announcement &&
|
|
182
|
-
|
|
198
|
+
if (announcement && element.nodeValue !== announcement) {
|
|
199
|
+
latestAnnouncement = announcement;
|
|
200
|
+
if (debouncedEvents.includes(eventName)) {
|
|
201
|
+
debouncedUpdateAnnouncement();
|
|
202
|
+
} else {
|
|
203
|
+
scheduleUpdateAnnouncement();
|
|
204
|
+
debouncedUpdateAnnouncement.cancel();
|
|
205
|
+
}
|
|
183
206
|
}
|
|
184
207
|
}
|
|
185
208
|
);
|
|
@@ -191,12 +214,14 @@ var Accessibility = class extends abstract.Plugin {
|
|
|
191
214
|
screenReaderInstructions.draggable
|
|
192
215
|
);
|
|
193
216
|
liveRegionElement = createLiveRegion(announcementId);
|
|
217
|
+
liveRegionTextNode = document.createTextNode("");
|
|
218
|
+
liveRegionElement.appendChild(liveRegionTextNode);
|
|
194
219
|
document.body.append(hiddenTextElement, liveRegionElement);
|
|
195
220
|
};
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
const activator = handle != null ?
|
|
221
|
+
const updateAttributes = () => {
|
|
222
|
+
var _a4;
|
|
223
|
+
for (const draggable of this.manager.registry.draggables.value) {
|
|
224
|
+
const activator = (_a4 = draggable.handle) != null ? _a4 : draggable.element;
|
|
200
225
|
if (activator) {
|
|
201
226
|
if (!hiddenTextElement || !liveRegionElement) {
|
|
202
227
|
initialize();
|
|
@@ -222,15 +247,31 @@ var Accessibility = class extends abstract.Plugin {
|
|
|
222
247
|
activator.setAttribute("aria-disabled", String(draggable.disabled));
|
|
223
248
|
}
|
|
224
249
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
250
|
+
};
|
|
251
|
+
this.registerEffect(() => {
|
|
252
|
+
for (const draggable of this.manager.registry.draggables.value) {
|
|
253
|
+
void draggable.element;
|
|
254
|
+
void draggable.handle;
|
|
255
|
+
}
|
|
256
|
+
utilities.scheduler.schedule(updateAttributes);
|
|
231
257
|
});
|
|
258
|
+
this.destroy = () => {
|
|
259
|
+
super.destroy();
|
|
260
|
+
hiddenTextElement == null ? void 0 : hiddenTextElement.remove();
|
|
261
|
+
liveRegionElement == null ? void 0 : liveRegionElement.remove();
|
|
262
|
+
eventListeners.forEach((unsubscribe) => unsubscribe());
|
|
263
|
+
};
|
|
232
264
|
}
|
|
233
265
|
};
|
|
266
|
+
function debounce(fn, wait) {
|
|
267
|
+
let timeout;
|
|
268
|
+
const debounced = () => {
|
|
269
|
+
clearTimeout(timeout);
|
|
270
|
+
timeout = setTimeout(fn, wait);
|
|
271
|
+
};
|
|
272
|
+
debounced.cancel = () => clearTimeout(timeout);
|
|
273
|
+
return debounced;
|
|
274
|
+
}
|
|
234
275
|
var Cursor = class extends abstract.Plugin {
|
|
235
276
|
constructor(manager, options) {
|
|
236
277
|
super(manager, options);
|
|
@@ -1069,6 +1110,41 @@ function getScrollIntent(value) {
|
|
|
1069
1110
|
}
|
|
1070
1111
|
return utilities.ScrollDirection.Idle;
|
|
1071
1112
|
}
|
|
1113
|
+
|
|
1114
|
+
// src/utilities/scheduling/scheduler.ts
|
|
1115
|
+
var Scheduler = class {
|
|
1116
|
+
constructor(scheduler5) {
|
|
1117
|
+
this.scheduler = scheduler5;
|
|
1118
|
+
this.pending = false;
|
|
1119
|
+
this.tasks = /* @__PURE__ */ new Set();
|
|
1120
|
+
this.resolvers = /* @__PURE__ */ new Set();
|
|
1121
|
+
this.flush = () => {
|
|
1122
|
+
const { tasks, resolvers } = this;
|
|
1123
|
+
this.pending = false;
|
|
1124
|
+
this.tasks = /* @__PURE__ */ new Set();
|
|
1125
|
+
this.resolvers = /* @__PURE__ */ new Set();
|
|
1126
|
+
for (const task of tasks) {
|
|
1127
|
+
task();
|
|
1128
|
+
}
|
|
1129
|
+
for (const resolve of resolvers) {
|
|
1130
|
+
resolve();
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
schedule(task) {
|
|
1135
|
+
this.tasks.add(task);
|
|
1136
|
+
if (!this.pending) {
|
|
1137
|
+
this.pending = true;
|
|
1138
|
+
this.scheduler(this.flush);
|
|
1139
|
+
}
|
|
1140
|
+
return new Promise((resolve) => this.resolvers.add(resolve));
|
|
1141
|
+
}
|
|
1142
|
+
};
|
|
1143
|
+
var scheduler3 = new Scheduler(
|
|
1144
|
+
(callback) => requestAnimationFrame(callback)
|
|
1145
|
+
);
|
|
1146
|
+
|
|
1147
|
+
// src/core/plugins/scrolling/AutoScroller.ts
|
|
1072
1148
|
var AUTOSCROLL_INTERVAL = 10;
|
|
1073
1149
|
var AutoScroller = class extends abstract.Plugin {
|
|
1074
1150
|
constructor(manager, _options) {
|
|
@@ -1086,7 +1162,10 @@ var AutoScroller = class extends abstract.Plugin {
|
|
|
1086
1162
|
const canScroll2 = scroller.scroll();
|
|
1087
1163
|
if (canScroll2) {
|
|
1088
1164
|
scroller.autoScrolling = true;
|
|
1089
|
-
const interval = setInterval(
|
|
1165
|
+
const interval = setInterval(
|
|
1166
|
+
() => scheduler3.schedule(scroller.scroll),
|
|
1167
|
+
AUTOSCROLL_INTERVAL
|
|
1168
|
+
);
|
|
1090
1169
|
return () => {
|
|
1091
1170
|
clearInterval(interval);
|
|
1092
1171
|
};
|
|
@@ -1663,7 +1742,7 @@ var Draggable = class extends (_c = abstract.Draggable, _handle_dec = [state.rea
|
|
|
1663
1742
|
constructor(_a4, manager) {
|
|
1664
1743
|
var _b2 = _a4, {
|
|
1665
1744
|
element,
|
|
1666
|
-
effects
|
|
1745
|
+
effects = () => [],
|
|
1667
1746
|
handle,
|
|
1668
1747
|
feedback = "default"
|
|
1669
1748
|
} = _b2, input = __objRest(_b2, [
|
|
@@ -1675,7 +1754,7 @@ var Draggable = class extends (_c = abstract.Draggable, _handle_dec = [state.rea
|
|
|
1675
1754
|
super(
|
|
1676
1755
|
__spreadValues({
|
|
1677
1756
|
effects: () => [
|
|
1678
|
-
...
|
|
1757
|
+
...effects(),
|
|
1679
1758
|
() => {
|
|
1680
1759
|
var _a5, _b3;
|
|
1681
1760
|
const { manager: manager2 } = this;
|
|
@@ -1716,7 +1795,7 @@ __decoratorMetadata(_init4, Draggable);
|
|
|
1716
1795
|
var _proxy_dec, _element_dec2, _c2, _init5, _element2, _d, element_get, element_set, _Droppable_instances, _proxy;
|
|
1717
1796
|
var Droppable = class extends (_c2 = abstract.Droppable, _element_dec2 = [state.reactive], _proxy_dec = [state.reactive], _c2) {
|
|
1718
1797
|
constructor(_a4, manager) {
|
|
1719
|
-
var _b2 = _a4, { element, effects
|
|
1798
|
+
var _b2 = _a4, { element, effects = () => [] } = _b2, input = __objRest(_b2, ["element", "effects"]);
|
|
1720
1799
|
const { collisionDetector = collision.defaultCollisionDetection } = input;
|
|
1721
1800
|
const updateShape = (boundingClientRect) => {
|
|
1722
1801
|
const { manager: manager2, element: element2 } = this;
|
|
@@ -1738,7 +1817,7 @@ var Droppable = class extends (_c2 = abstract.Droppable, _element_dec2 = [state.
|
|
|
1738
1817
|
__spreadProps(__spreadValues({}, input), {
|
|
1739
1818
|
collisionDetector,
|
|
1740
1819
|
effects: () => [
|
|
1741
|
-
...
|
|
1820
|
+
...effects(),
|
|
1742
1821
|
() => {
|
|
1743
1822
|
const { element: element2, manager: manager2 } = this;
|
|
1744
1823
|
if (!manager2) return;
|