@dartcom/ui-kit 2.5.1 → 2.7.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/dist/cjs/components/checkbox/checkbox.js +12 -5
- package/dist/cjs/components/checkbox/checkbox.js.map +1 -1
- package/dist/cjs/components/drag-list/drag-list.js +30 -0
- package/dist/cjs/components/drag-list/drag-list.js.map +1 -0
- package/dist/cjs/components/drag-list/draggable/draggable.js +33 -0
- package/dist/cjs/components/drag-list/draggable/draggable.js.map +1 -0
- package/dist/cjs/components/list/list.js +3 -4
- package/dist/cjs/components/list/list.js.map +1 -1
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/node_modules/@dnd-kit/accessibility/dist/accessibility.esm.js +71 -0
- package/dist/cjs/node_modules/@dnd-kit/accessibility/dist/accessibility.esm.js.map +1 -0
- package/dist/cjs/node_modules/@dnd-kit/core/dist/core.esm.js +3467 -0
- package/dist/cjs/node_modules/@dnd-kit/core/dist/core.esm.js.map +1 -0
- package/dist/cjs/node_modules/@dnd-kit/sortable/dist/sortable.esm.js +541 -0
- package/dist/cjs/node_modules/@dnd-kit/sortable/dist/sortable.esm.js.map +1 -0
- package/dist/cjs/node_modules/@dnd-kit/utilities/dist/utilities.esm.js +361 -0
- package/dist/cjs/node_modules/@dnd-kit/utilities/dist/utilities.esm.js.map +1 -0
- package/dist/esm/components/checkbox/checkbox.js +1 -1
- package/dist/esm/components/checkbox/checkbox.js.map +1 -1
- package/dist/esm/components/drag-list/drag-list.js +2 -0
- package/dist/esm/components/drag-list/drag-list.js.map +1 -0
- package/dist/esm/components/drag-list/draggable/draggable.js +2 -0
- package/dist/esm/components/drag-list/draggable/draggable.js.map +1 -0
- package/dist/esm/components/list/list.js +1 -1
- package/dist/esm/components/list/list.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/node_modules/@dnd-kit/accessibility/dist/accessibility.esm.js +2 -0
- package/dist/esm/node_modules/@dnd-kit/accessibility/dist/accessibility.esm.js.map +1 -0
- package/dist/esm/node_modules/@dnd-kit/core/dist/core.esm.js +2 -0
- package/dist/esm/node_modules/@dnd-kit/core/dist/core.esm.js.map +1 -0
- package/dist/esm/node_modules/@dnd-kit/sortable/dist/sortable.esm.js +2 -0
- package/dist/esm/node_modules/@dnd-kit/sortable/dist/sortable.esm.js.map +1 -0
- package/dist/esm/node_modules/@dnd-kit/utilities/dist/utilities.esm.js +2 -0
- package/dist/esm/node_modules/@dnd-kit/utilities/dist/utilities.esm.js.map +1 -0
- package/dist/esm/types/components/checkbox/checkbox.d.ts +1 -1
- package/dist/esm/types/components/checkbox/checkbox.d.ts.map +1 -1
- package/dist/esm/types/components/checkbox/checkbox.stories.d.ts +1 -0
- package/dist/esm/types/components/checkbox/checkbox.stories.d.ts.map +1 -1
- package/dist/esm/types/components/drag-list/drag-list.d.ts +4 -0
- package/dist/esm/types/components/drag-list/drag-list.d.ts.map +1 -0
- package/dist/esm/types/components/drag-list/drag-list.stories.d.ts +8 -0
- package/dist/esm/types/components/drag-list/drag-list.stories.d.ts.map +1 -0
- package/dist/esm/types/components/drag-list/draggable/draggable.d.ts +5 -0
- package/dist/esm/types/components/drag-list/draggable/draggable.d.ts.map +1 -0
- package/dist/esm/types/components/drag-list/draggable/index.d.ts +2 -0
- package/dist/esm/types/components/drag-list/draggable/index.d.ts.map +1 -0
- package/dist/esm/types/components/drag-list/draggable/types.d.ts +10 -0
- package/dist/esm/types/components/drag-list/draggable/types.d.ts.map +1 -0
- package/dist/esm/types/components/drag-list/droppable/droppable.d.ts +5 -0
- package/dist/esm/types/components/drag-list/droppable/droppable.d.ts.map +1 -0
- package/dist/esm/types/components/drag-list/droppable/index.d.ts +2 -0
- package/dist/esm/types/components/drag-list/droppable/index.d.ts.map +1 -0
- package/dist/esm/types/components/drag-list/droppable/types.d.ts +5 -0
- package/dist/esm/types/components/drag-list/droppable/types.d.ts.map +1 -0
- package/dist/esm/types/components/drag-list/index.d.ts +2 -0
- package/dist/esm/types/components/drag-list/index.d.ts.map +1 -0
- package/dist/esm/types/components/drag-list/types.d.ts +11 -0
- package/dist/esm/types/components/drag-list/types.d.ts.map +1 -0
- package/dist/esm/types/components/index.d.ts +1 -0
- package/dist/esm/types/components/index.d.ts.map +1 -1
- package/dist/esm/types/components/list/list.d.ts +6 -1
- package/dist/esm/types/components/list/list.d.ts.map +1 -1
- package/dist/esm/types/components/list/list.stories.d.ts.map +1 -1
- package/dist/esm/types/types/__test__.d.ts +5 -0
- package/dist/esm/types/types/__test__.d.ts.map +1 -0
- package/package.json +4 -1
- package/dist/cjs/node_modules/tslib/tslib.es6.js +0 -49
- package/dist/cjs/node_modules/tslib/tslib.es6.js.map +0 -1
- package/dist/esm/node_modules/tslib/tslib.es6.js +0 -2
- package/dist/esm/node_modules/tslib/tslib.es6.js.map +0 -1
- package/dist/esm/types/components/buttons/delete/stories/delete.stories.d.ts +0 -8
- package/dist/esm/types/components/buttons/delete/stories/delete.stories.d.ts.map +0 -1
- package/dist/esm/types/components/list/stories/list.stories.d.ts +0 -9
- package/dist/esm/types/components/list/stories/list.stories.d.ts.map +0 -1
|
@@ -0,0 +1,3467 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var ReactDOM = require('react-dom');
|
|
7
|
+
var utilities_esm = require('../../utilities/dist/utilities.esm.js');
|
|
8
|
+
var accessibility_esm = require('../../accessibility/dist/accessibility.esm.js');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
13
|
+
|
|
14
|
+
const DndMonitorContext = /*#__PURE__*/React.createContext(null);
|
|
15
|
+
|
|
16
|
+
function useDndMonitor(listener) {
|
|
17
|
+
const registerListener = React.useContext(DndMonitorContext);
|
|
18
|
+
React.useEffect(() => {
|
|
19
|
+
if (!registerListener) {
|
|
20
|
+
throw new Error('useDndMonitor must be used within a children of <DndContext>');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const unsubscribe = registerListener(listener);
|
|
24
|
+
return unsubscribe;
|
|
25
|
+
}, [listener, registerListener]);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function useDndMonitorProvider() {
|
|
29
|
+
const [listeners] = React.useState(() => new Set());
|
|
30
|
+
const registerListener = React.useCallback(listener => {
|
|
31
|
+
listeners.add(listener);
|
|
32
|
+
return () => listeners.delete(listener);
|
|
33
|
+
}, [listeners]);
|
|
34
|
+
const dispatch = React.useCallback(_ref => {
|
|
35
|
+
let {
|
|
36
|
+
type,
|
|
37
|
+
event
|
|
38
|
+
} = _ref;
|
|
39
|
+
listeners.forEach(listener => {
|
|
40
|
+
var _listener$type;
|
|
41
|
+
|
|
42
|
+
return (_listener$type = listener[type]) == null ? void 0 : _listener$type.call(listener, event);
|
|
43
|
+
});
|
|
44
|
+
}, [listeners]);
|
|
45
|
+
return [dispatch, registerListener];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const defaultScreenReaderInstructions = {
|
|
49
|
+
draggable: "\n To pick up a draggable item, press the space bar.\n While dragging, use the arrow keys to move the item.\n Press space again to drop the item in its new position, or press escape to cancel.\n "
|
|
50
|
+
};
|
|
51
|
+
const defaultAnnouncements = {
|
|
52
|
+
onDragStart(_ref) {
|
|
53
|
+
let {
|
|
54
|
+
active
|
|
55
|
+
} = _ref;
|
|
56
|
+
return "Picked up draggable item " + active.id + ".";
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
onDragOver(_ref2) {
|
|
60
|
+
let {
|
|
61
|
+
active,
|
|
62
|
+
over
|
|
63
|
+
} = _ref2;
|
|
64
|
+
|
|
65
|
+
if (over) {
|
|
66
|
+
return "Draggable item " + active.id + " was moved over droppable area " + over.id + ".";
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return "Draggable item " + active.id + " is no longer over a droppable area.";
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
onDragEnd(_ref3) {
|
|
73
|
+
let {
|
|
74
|
+
active,
|
|
75
|
+
over
|
|
76
|
+
} = _ref3;
|
|
77
|
+
|
|
78
|
+
if (over) {
|
|
79
|
+
return "Draggable item " + active.id + " was dropped over droppable area " + over.id;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return "Draggable item " + active.id + " was dropped.";
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
onDragCancel(_ref4) {
|
|
86
|
+
let {
|
|
87
|
+
active
|
|
88
|
+
} = _ref4;
|
|
89
|
+
return "Dragging was cancelled. Draggable item " + active.id + " was dropped.";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
function Accessibility(_ref) {
|
|
95
|
+
let {
|
|
96
|
+
announcements = defaultAnnouncements,
|
|
97
|
+
container,
|
|
98
|
+
hiddenTextDescribedById,
|
|
99
|
+
screenReaderInstructions = defaultScreenReaderInstructions
|
|
100
|
+
} = _ref;
|
|
101
|
+
const {
|
|
102
|
+
announce,
|
|
103
|
+
announcement
|
|
104
|
+
} = accessibility_esm.useAnnouncement();
|
|
105
|
+
const liveRegionId = utilities_esm.useUniqueId("DndLiveRegion");
|
|
106
|
+
const [mounted, setMounted] = React.useState(false);
|
|
107
|
+
React.useEffect(() => {
|
|
108
|
+
setMounted(true);
|
|
109
|
+
}, []);
|
|
110
|
+
useDndMonitor(React.useMemo(() => ({
|
|
111
|
+
onDragStart(_ref2) {
|
|
112
|
+
let {
|
|
113
|
+
active
|
|
114
|
+
} = _ref2;
|
|
115
|
+
announce(announcements.onDragStart({
|
|
116
|
+
active
|
|
117
|
+
}));
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
onDragMove(_ref3) {
|
|
121
|
+
let {
|
|
122
|
+
active,
|
|
123
|
+
over
|
|
124
|
+
} = _ref3;
|
|
125
|
+
|
|
126
|
+
if (announcements.onDragMove) {
|
|
127
|
+
announce(announcements.onDragMove({
|
|
128
|
+
active,
|
|
129
|
+
over
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
|
|
134
|
+
onDragOver(_ref4) {
|
|
135
|
+
let {
|
|
136
|
+
active,
|
|
137
|
+
over
|
|
138
|
+
} = _ref4;
|
|
139
|
+
announce(announcements.onDragOver({
|
|
140
|
+
active,
|
|
141
|
+
over
|
|
142
|
+
}));
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
onDragEnd(_ref5) {
|
|
146
|
+
let {
|
|
147
|
+
active,
|
|
148
|
+
over
|
|
149
|
+
} = _ref5;
|
|
150
|
+
announce(announcements.onDragEnd({
|
|
151
|
+
active,
|
|
152
|
+
over
|
|
153
|
+
}));
|
|
154
|
+
},
|
|
155
|
+
|
|
156
|
+
onDragCancel(_ref6) {
|
|
157
|
+
let {
|
|
158
|
+
active,
|
|
159
|
+
over
|
|
160
|
+
} = _ref6;
|
|
161
|
+
announce(announcements.onDragCancel({
|
|
162
|
+
active,
|
|
163
|
+
over
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
}), [announce, announcements]));
|
|
168
|
+
|
|
169
|
+
if (!mounted) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const markup = React__default["default"].createElement(React__default["default"].Fragment, null, React__default["default"].createElement(accessibility_esm.HiddenText, {
|
|
174
|
+
id: hiddenTextDescribedById,
|
|
175
|
+
value: screenReaderInstructions.draggable
|
|
176
|
+
}), React__default["default"].createElement(accessibility_esm.LiveRegion, {
|
|
177
|
+
id: liveRegionId,
|
|
178
|
+
announcement: announcement
|
|
179
|
+
}));
|
|
180
|
+
return container ? ReactDOM.createPortal(markup, container) : markup;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
var Action;
|
|
184
|
+
|
|
185
|
+
(function (Action) {
|
|
186
|
+
Action["DragStart"] = "dragStart";
|
|
187
|
+
Action["DragMove"] = "dragMove";
|
|
188
|
+
Action["DragEnd"] = "dragEnd";
|
|
189
|
+
Action["DragCancel"] = "dragCancel";
|
|
190
|
+
Action["DragOver"] = "dragOver";
|
|
191
|
+
Action["RegisterDroppable"] = "registerDroppable";
|
|
192
|
+
Action["SetDroppableDisabled"] = "setDroppableDisabled";
|
|
193
|
+
Action["UnregisterDroppable"] = "unregisterDroppable";
|
|
194
|
+
})(Action || (Action = {}));
|
|
195
|
+
|
|
196
|
+
function noop() {}
|
|
197
|
+
|
|
198
|
+
function useSensor(sensor, options) {
|
|
199
|
+
return React.useMemo(() => ({
|
|
200
|
+
sensor,
|
|
201
|
+
options: options != null ? options : {}
|
|
202
|
+
}), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
203
|
+
[sensor, options]);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function useSensors() {
|
|
207
|
+
for (var _len = arguments.length, sensors = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
208
|
+
sensors[_key] = arguments[_key];
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return React.useMemo(() => [...sensors].filter(sensor => sensor != null), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
212
|
+
[...sensors]);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const defaultCoordinates = /*#__PURE__*/Object.freeze({
|
|
216
|
+
x: 0,
|
|
217
|
+
y: 0
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Returns the distance between two points
|
|
222
|
+
*/
|
|
223
|
+
function distanceBetween(p1, p2) {
|
|
224
|
+
return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Sort collisions from smallest to greatest value
|
|
229
|
+
*/
|
|
230
|
+
function sortCollisionsAsc(_ref, _ref2) {
|
|
231
|
+
let {
|
|
232
|
+
data: {
|
|
233
|
+
value: a
|
|
234
|
+
}
|
|
235
|
+
} = _ref;
|
|
236
|
+
let {
|
|
237
|
+
data: {
|
|
238
|
+
value: b
|
|
239
|
+
}
|
|
240
|
+
} = _ref2;
|
|
241
|
+
return a - b;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Sort collisions from greatest to smallest value
|
|
245
|
+
*/
|
|
246
|
+
|
|
247
|
+
function sortCollisionsDesc(_ref3, _ref4) {
|
|
248
|
+
let {
|
|
249
|
+
data: {
|
|
250
|
+
value: a
|
|
251
|
+
}
|
|
252
|
+
} = _ref3;
|
|
253
|
+
let {
|
|
254
|
+
data: {
|
|
255
|
+
value: b
|
|
256
|
+
}
|
|
257
|
+
} = _ref4;
|
|
258
|
+
return b - a;
|
|
259
|
+
}
|
|
260
|
+
function getFirstCollision(collisions, property) {
|
|
261
|
+
if (!collisions || collisions.length === 0) {
|
|
262
|
+
return null;
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const [firstCollision] = collisions;
|
|
266
|
+
return property ? firstCollision[property] : firstCollision;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Returns the coordinates of the center of a given ClientRect
|
|
271
|
+
*/
|
|
272
|
+
|
|
273
|
+
function centerOfRectangle(rect, left, top) {
|
|
274
|
+
if (left === void 0) {
|
|
275
|
+
left = rect.left;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (top === void 0) {
|
|
279
|
+
top = rect.top;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
x: left + rect.width * 0.5,
|
|
284
|
+
y: top + rect.height * 0.5
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Returns the closest rectangles from an array of rectangles to the center of a given
|
|
289
|
+
* rectangle.
|
|
290
|
+
*/
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
const closestCenter = _ref => {
|
|
294
|
+
let {
|
|
295
|
+
collisionRect,
|
|
296
|
+
droppableRects,
|
|
297
|
+
droppableContainers
|
|
298
|
+
} = _ref;
|
|
299
|
+
const centerRect = centerOfRectangle(collisionRect, collisionRect.left, collisionRect.top);
|
|
300
|
+
const collisions = [];
|
|
301
|
+
|
|
302
|
+
for (const droppableContainer of droppableContainers) {
|
|
303
|
+
const {
|
|
304
|
+
id
|
|
305
|
+
} = droppableContainer;
|
|
306
|
+
const rect = droppableRects.get(id);
|
|
307
|
+
|
|
308
|
+
if (rect) {
|
|
309
|
+
const distBetween = distanceBetween(centerOfRectangle(rect), centerRect);
|
|
310
|
+
collisions.push({
|
|
311
|
+
id,
|
|
312
|
+
data: {
|
|
313
|
+
droppableContainer,
|
|
314
|
+
value: distBetween
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return collisions.sort(sortCollisionsAsc);
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Returns the intersecting rectangle area between two rectangles
|
|
325
|
+
*/
|
|
326
|
+
|
|
327
|
+
function getIntersectionRatio(entry, target) {
|
|
328
|
+
const top = Math.max(target.top, entry.top);
|
|
329
|
+
const left = Math.max(target.left, entry.left);
|
|
330
|
+
const right = Math.min(target.left + target.width, entry.left + entry.width);
|
|
331
|
+
const bottom = Math.min(target.top + target.height, entry.top + entry.height);
|
|
332
|
+
const width = right - left;
|
|
333
|
+
const height = bottom - top;
|
|
334
|
+
|
|
335
|
+
if (left < right && top < bottom) {
|
|
336
|
+
const targetArea = target.width * target.height;
|
|
337
|
+
const entryArea = entry.width * entry.height;
|
|
338
|
+
const intersectionArea = width * height;
|
|
339
|
+
const intersectionRatio = intersectionArea / (targetArea + entryArea - intersectionArea);
|
|
340
|
+
return Number(intersectionRatio.toFixed(4));
|
|
341
|
+
} // Rectangles do not overlap, or overlap has an area of zero (edge/corner overlap)
|
|
342
|
+
|
|
343
|
+
|
|
344
|
+
return 0;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Returns the rectangles that has the greatest intersection area with a given
|
|
348
|
+
* rectangle in an array of rectangles.
|
|
349
|
+
*/
|
|
350
|
+
|
|
351
|
+
const rectIntersection = _ref => {
|
|
352
|
+
let {
|
|
353
|
+
collisionRect,
|
|
354
|
+
droppableRects,
|
|
355
|
+
droppableContainers
|
|
356
|
+
} = _ref;
|
|
357
|
+
const collisions = [];
|
|
358
|
+
|
|
359
|
+
for (const droppableContainer of droppableContainers) {
|
|
360
|
+
const {
|
|
361
|
+
id
|
|
362
|
+
} = droppableContainer;
|
|
363
|
+
const rect = droppableRects.get(id);
|
|
364
|
+
|
|
365
|
+
if (rect) {
|
|
366
|
+
const intersectionRatio = getIntersectionRatio(rect, collisionRect);
|
|
367
|
+
|
|
368
|
+
if (intersectionRatio > 0) {
|
|
369
|
+
collisions.push({
|
|
370
|
+
id,
|
|
371
|
+
data: {
|
|
372
|
+
droppableContainer,
|
|
373
|
+
value: intersectionRatio
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
return collisions.sort(sortCollisionsDesc);
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
function adjustScale(transform, rect1, rect2) {
|
|
384
|
+
return { ...transform,
|
|
385
|
+
scaleX: rect1 && rect2 ? rect1.width / rect2.width : 1,
|
|
386
|
+
scaleY: rect1 && rect2 ? rect1.height / rect2.height : 1
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
function getRectDelta(rect1, rect2) {
|
|
391
|
+
return rect1 && rect2 ? {
|
|
392
|
+
x: rect1.left - rect2.left,
|
|
393
|
+
y: rect1.top - rect2.top
|
|
394
|
+
} : defaultCoordinates;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function createRectAdjustmentFn(modifier) {
|
|
398
|
+
return function adjustClientRect(rect) {
|
|
399
|
+
for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
400
|
+
adjustments[_key - 1] = arguments[_key];
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return adjustments.reduce((acc, adjustment) => ({ ...acc,
|
|
404
|
+
top: acc.top + modifier * adjustment.y,
|
|
405
|
+
bottom: acc.bottom + modifier * adjustment.y,
|
|
406
|
+
left: acc.left + modifier * adjustment.x,
|
|
407
|
+
right: acc.right + modifier * adjustment.x
|
|
408
|
+
}), { ...rect
|
|
409
|
+
});
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
const getAdjustedRect = /*#__PURE__*/createRectAdjustmentFn(1);
|
|
413
|
+
|
|
414
|
+
function parseTransform(transform) {
|
|
415
|
+
if (transform.startsWith('matrix3d(')) {
|
|
416
|
+
const transformArray = transform.slice(9, -1).split(/, /);
|
|
417
|
+
return {
|
|
418
|
+
x: +transformArray[12],
|
|
419
|
+
y: +transformArray[13],
|
|
420
|
+
scaleX: +transformArray[0],
|
|
421
|
+
scaleY: +transformArray[5]
|
|
422
|
+
};
|
|
423
|
+
} else if (transform.startsWith('matrix(')) {
|
|
424
|
+
const transformArray = transform.slice(7, -1).split(/, /);
|
|
425
|
+
return {
|
|
426
|
+
x: +transformArray[4],
|
|
427
|
+
y: +transformArray[5],
|
|
428
|
+
scaleX: +transformArray[0],
|
|
429
|
+
scaleY: +transformArray[3]
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function inverseTransform(rect, transform, transformOrigin) {
|
|
437
|
+
const parsedTransform = parseTransform(transform);
|
|
438
|
+
|
|
439
|
+
if (!parsedTransform) {
|
|
440
|
+
return rect;
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
const {
|
|
444
|
+
scaleX,
|
|
445
|
+
scaleY,
|
|
446
|
+
x: translateX,
|
|
447
|
+
y: translateY
|
|
448
|
+
} = parsedTransform;
|
|
449
|
+
const x = rect.left - translateX - (1 - scaleX) * parseFloat(transformOrigin);
|
|
450
|
+
const y = rect.top - translateY - (1 - scaleY) * parseFloat(transformOrigin.slice(transformOrigin.indexOf(' ') + 1));
|
|
451
|
+
const w = scaleX ? rect.width / scaleX : rect.width;
|
|
452
|
+
const h = scaleY ? rect.height / scaleY : rect.height;
|
|
453
|
+
return {
|
|
454
|
+
width: w,
|
|
455
|
+
height: h,
|
|
456
|
+
top: y,
|
|
457
|
+
right: x + w,
|
|
458
|
+
bottom: y + h,
|
|
459
|
+
left: x
|
|
460
|
+
};
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
const defaultOptions = {
|
|
464
|
+
ignoreTransform: false
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
467
|
+
* Returns the bounding client rect of an element relative to the viewport.
|
|
468
|
+
*/
|
|
469
|
+
|
|
470
|
+
function getClientRect(element, options) {
|
|
471
|
+
if (options === void 0) {
|
|
472
|
+
options = defaultOptions;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
let rect = element.getBoundingClientRect();
|
|
476
|
+
|
|
477
|
+
if (options.ignoreTransform) {
|
|
478
|
+
const {
|
|
479
|
+
transform,
|
|
480
|
+
transformOrigin
|
|
481
|
+
} = utilities_esm.getWindow(element).getComputedStyle(element);
|
|
482
|
+
|
|
483
|
+
if (transform) {
|
|
484
|
+
rect = inverseTransform(rect, transform, transformOrigin);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const {
|
|
489
|
+
top,
|
|
490
|
+
left,
|
|
491
|
+
width,
|
|
492
|
+
height,
|
|
493
|
+
bottom,
|
|
494
|
+
right
|
|
495
|
+
} = rect;
|
|
496
|
+
return {
|
|
497
|
+
top,
|
|
498
|
+
left,
|
|
499
|
+
width,
|
|
500
|
+
height,
|
|
501
|
+
bottom,
|
|
502
|
+
right
|
|
503
|
+
};
|
|
504
|
+
}
|
|
505
|
+
/**
|
|
506
|
+
* Returns the bounding client rect of an element relative to the viewport.
|
|
507
|
+
*
|
|
508
|
+
* @remarks
|
|
509
|
+
* The ClientRect returned by this method does not take into account transforms
|
|
510
|
+
* applied to the element it measures.
|
|
511
|
+
*
|
|
512
|
+
*/
|
|
513
|
+
|
|
514
|
+
function getTransformAgnosticClientRect(element) {
|
|
515
|
+
return getClientRect(element, {
|
|
516
|
+
ignoreTransform: true
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
function getWindowClientRect(element) {
|
|
521
|
+
const width = element.innerWidth;
|
|
522
|
+
const height = element.innerHeight;
|
|
523
|
+
return {
|
|
524
|
+
top: 0,
|
|
525
|
+
left: 0,
|
|
526
|
+
right: width,
|
|
527
|
+
bottom: height,
|
|
528
|
+
width,
|
|
529
|
+
height
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
function isFixed(node, computedStyle) {
|
|
534
|
+
if (computedStyle === void 0) {
|
|
535
|
+
computedStyle = utilities_esm.getWindow(node).getComputedStyle(node);
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
return computedStyle.position === 'fixed';
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
function isScrollable(element, computedStyle) {
|
|
542
|
+
if (computedStyle === void 0) {
|
|
543
|
+
computedStyle = utilities_esm.getWindow(element).getComputedStyle(element);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
const overflowRegex = /(auto|scroll|overlay)/;
|
|
547
|
+
const properties = ['overflow', 'overflowX', 'overflowY'];
|
|
548
|
+
return properties.some(property => {
|
|
549
|
+
const value = computedStyle[property];
|
|
550
|
+
return typeof value === 'string' ? overflowRegex.test(value) : false;
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
function getScrollableAncestors(element, limit) {
|
|
555
|
+
const scrollParents = [];
|
|
556
|
+
|
|
557
|
+
function findScrollableAncestors(node) {
|
|
558
|
+
if (limit != null && scrollParents.length >= limit) {
|
|
559
|
+
return scrollParents;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
if (!node) {
|
|
563
|
+
return scrollParents;
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
if (utilities_esm.isDocument(node) && node.scrollingElement != null && !scrollParents.includes(node.scrollingElement)) {
|
|
567
|
+
scrollParents.push(node.scrollingElement);
|
|
568
|
+
return scrollParents;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
if (!utilities_esm.isHTMLElement(node) || utilities_esm.isSVGElement(node)) {
|
|
572
|
+
return scrollParents;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
if (scrollParents.includes(node)) {
|
|
576
|
+
return scrollParents;
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const computedStyle = utilities_esm.getWindow(element).getComputedStyle(node);
|
|
580
|
+
|
|
581
|
+
if (node !== element) {
|
|
582
|
+
if (isScrollable(node, computedStyle)) {
|
|
583
|
+
scrollParents.push(node);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
if (isFixed(node, computedStyle)) {
|
|
588
|
+
return scrollParents;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
return findScrollableAncestors(node.parentNode);
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
if (!element) {
|
|
595
|
+
return scrollParents;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
return findScrollableAncestors(element);
|
|
599
|
+
}
|
|
600
|
+
function getFirstScrollableAncestor(node) {
|
|
601
|
+
const [firstScrollableAncestor] = getScrollableAncestors(node, 1);
|
|
602
|
+
return firstScrollableAncestor != null ? firstScrollableAncestor : null;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
function getScrollableElement(element) {
|
|
606
|
+
if (!utilities_esm.canUseDOM || !element) {
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
if (utilities_esm.isWindow(element)) {
|
|
611
|
+
return element;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
if (!utilities_esm.isNode(element)) {
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
if (utilities_esm.isDocument(element) || element === utilities_esm.getOwnerDocument(element).scrollingElement) {
|
|
619
|
+
return window;
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if (utilities_esm.isHTMLElement(element)) {
|
|
623
|
+
return element;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
return null;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
function getScrollXCoordinate(element) {
|
|
630
|
+
if (utilities_esm.isWindow(element)) {
|
|
631
|
+
return element.scrollX;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
return element.scrollLeft;
|
|
635
|
+
}
|
|
636
|
+
function getScrollYCoordinate(element) {
|
|
637
|
+
if (utilities_esm.isWindow(element)) {
|
|
638
|
+
return element.scrollY;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
return element.scrollTop;
|
|
642
|
+
}
|
|
643
|
+
function getScrollCoordinates(element) {
|
|
644
|
+
return {
|
|
645
|
+
x: getScrollXCoordinate(element),
|
|
646
|
+
y: getScrollYCoordinate(element)
|
|
647
|
+
};
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
var Direction;
|
|
651
|
+
|
|
652
|
+
(function (Direction) {
|
|
653
|
+
Direction[Direction["Forward"] = 1] = "Forward";
|
|
654
|
+
Direction[Direction["Backward"] = -1] = "Backward";
|
|
655
|
+
})(Direction || (Direction = {}));
|
|
656
|
+
|
|
657
|
+
function isDocumentScrollingElement(element) {
|
|
658
|
+
if (!utilities_esm.canUseDOM || !element) {
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
return element === document.scrollingElement;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
function getScrollPosition(scrollingContainer) {
|
|
666
|
+
const minScroll = {
|
|
667
|
+
x: 0,
|
|
668
|
+
y: 0
|
|
669
|
+
};
|
|
670
|
+
const dimensions = isDocumentScrollingElement(scrollingContainer) ? {
|
|
671
|
+
height: window.innerHeight,
|
|
672
|
+
width: window.innerWidth
|
|
673
|
+
} : {
|
|
674
|
+
height: scrollingContainer.clientHeight,
|
|
675
|
+
width: scrollingContainer.clientWidth
|
|
676
|
+
};
|
|
677
|
+
const maxScroll = {
|
|
678
|
+
x: scrollingContainer.scrollWidth - dimensions.width,
|
|
679
|
+
y: scrollingContainer.scrollHeight - dimensions.height
|
|
680
|
+
};
|
|
681
|
+
const isTop = scrollingContainer.scrollTop <= minScroll.y;
|
|
682
|
+
const isLeft = scrollingContainer.scrollLeft <= minScroll.x;
|
|
683
|
+
const isBottom = scrollingContainer.scrollTop >= maxScroll.y;
|
|
684
|
+
const isRight = scrollingContainer.scrollLeft >= maxScroll.x;
|
|
685
|
+
return {
|
|
686
|
+
isTop,
|
|
687
|
+
isLeft,
|
|
688
|
+
isBottom,
|
|
689
|
+
isRight,
|
|
690
|
+
maxScroll,
|
|
691
|
+
minScroll
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
const defaultThreshold = {
|
|
696
|
+
x: 0.2,
|
|
697
|
+
y: 0.2
|
|
698
|
+
};
|
|
699
|
+
function getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, _ref, acceleration, thresholdPercentage) {
|
|
700
|
+
let {
|
|
701
|
+
top,
|
|
702
|
+
left,
|
|
703
|
+
right,
|
|
704
|
+
bottom
|
|
705
|
+
} = _ref;
|
|
706
|
+
|
|
707
|
+
if (acceleration === void 0) {
|
|
708
|
+
acceleration = 10;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
if (thresholdPercentage === void 0) {
|
|
712
|
+
thresholdPercentage = defaultThreshold;
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
const {
|
|
716
|
+
isTop,
|
|
717
|
+
isBottom,
|
|
718
|
+
isLeft,
|
|
719
|
+
isRight
|
|
720
|
+
} = getScrollPosition(scrollContainer);
|
|
721
|
+
const direction = {
|
|
722
|
+
x: 0,
|
|
723
|
+
y: 0
|
|
724
|
+
};
|
|
725
|
+
const speed = {
|
|
726
|
+
x: 0,
|
|
727
|
+
y: 0
|
|
728
|
+
};
|
|
729
|
+
const threshold = {
|
|
730
|
+
height: scrollContainerRect.height * thresholdPercentage.y,
|
|
731
|
+
width: scrollContainerRect.width * thresholdPercentage.x
|
|
732
|
+
};
|
|
733
|
+
|
|
734
|
+
if (!isTop && top <= scrollContainerRect.top + threshold.height) {
|
|
735
|
+
// Scroll Up
|
|
736
|
+
direction.y = Direction.Backward;
|
|
737
|
+
speed.y = acceleration * Math.abs((scrollContainerRect.top + threshold.height - top) / threshold.height);
|
|
738
|
+
} else if (!isBottom && bottom >= scrollContainerRect.bottom - threshold.height) {
|
|
739
|
+
// Scroll Down
|
|
740
|
+
direction.y = Direction.Forward;
|
|
741
|
+
speed.y = acceleration * Math.abs((scrollContainerRect.bottom - threshold.height - bottom) / threshold.height);
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
if (!isRight && right >= scrollContainerRect.right - threshold.width) {
|
|
745
|
+
// Scroll Right
|
|
746
|
+
direction.x = Direction.Forward;
|
|
747
|
+
speed.x = acceleration * Math.abs((scrollContainerRect.right - threshold.width - right) / threshold.width);
|
|
748
|
+
} else if (!isLeft && left <= scrollContainerRect.left + threshold.width) {
|
|
749
|
+
// Scroll Left
|
|
750
|
+
direction.x = Direction.Backward;
|
|
751
|
+
speed.x = acceleration * Math.abs((scrollContainerRect.left + threshold.width - left) / threshold.width);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
return {
|
|
755
|
+
direction,
|
|
756
|
+
speed
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
|
|
760
|
+
function getScrollElementRect(element) {
|
|
761
|
+
if (element === document.scrollingElement) {
|
|
762
|
+
const {
|
|
763
|
+
innerWidth,
|
|
764
|
+
innerHeight
|
|
765
|
+
} = window;
|
|
766
|
+
return {
|
|
767
|
+
top: 0,
|
|
768
|
+
left: 0,
|
|
769
|
+
right: innerWidth,
|
|
770
|
+
bottom: innerHeight,
|
|
771
|
+
width: innerWidth,
|
|
772
|
+
height: innerHeight
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
const {
|
|
777
|
+
top,
|
|
778
|
+
left,
|
|
779
|
+
right,
|
|
780
|
+
bottom
|
|
781
|
+
} = element.getBoundingClientRect();
|
|
782
|
+
return {
|
|
783
|
+
top,
|
|
784
|
+
left,
|
|
785
|
+
right,
|
|
786
|
+
bottom,
|
|
787
|
+
width: element.clientWidth,
|
|
788
|
+
height: element.clientHeight
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
function getScrollOffsets(scrollableAncestors) {
|
|
793
|
+
return scrollableAncestors.reduce((acc, node) => {
|
|
794
|
+
return utilities_esm.add(acc, getScrollCoordinates(node));
|
|
795
|
+
}, defaultCoordinates);
|
|
796
|
+
}
|
|
797
|
+
function getScrollXOffset(scrollableAncestors) {
|
|
798
|
+
return scrollableAncestors.reduce((acc, node) => {
|
|
799
|
+
return acc + getScrollXCoordinate(node);
|
|
800
|
+
}, 0);
|
|
801
|
+
}
|
|
802
|
+
function getScrollYOffset(scrollableAncestors) {
|
|
803
|
+
return scrollableAncestors.reduce((acc, node) => {
|
|
804
|
+
return acc + getScrollYCoordinate(node);
|
|
805
|
+
}, 0);
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
function scrollIntoViewIfNeeded(element, measure) {
|
|
809
|
+
if (measure === void 0) {
|
|
810
|
+
measure = getClientRect;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
if (!element) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
const {
|
|
818
|
+
top,
|
|
819
|
+
left,
|
|
820
|
+
bottom,
|
|
821
|
+
right
|
|
822
|
+
} = measure(element);
|
|
823
|
+
const firstScrollableAncestor = getFirstScrollableAncestor(element);
|
|
824
|
+
|
|
825
|
+
if (!firstScrollableAncestor) {
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
if (bottom <= 0 || right <= 0 || top >= window.innerHeight || left >= window.innerWidth) {
|
|
830
|
+
element.scrollIntoView({
|
|
831
|
+
block: 'center',
|
|
832
|
+
inline: 'center'
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
const properties = [['x', ['left', 'right'], getScrollXOffset], ['y', ['top', 'bottom'], getScrollYOffset]];
|
|
838
|
+
class Rect {
|
|
839
|
+
constructor(rect, element) {
|
|
840
|
+
this.rect = void 0;
|
|
841
|
+
this.width = void 0;
|
|
842
|
+
this.height = void 0;
|
|
843
|
+
this.top = void 0;
|
|
844
|
+
this.bottom = void 0;
|
|
845
|
+
this.right = void 0;
|
|
846
|
+
this.left = void 0;
|
|
847
|
+
const scrollableAncestors = getScrollableAncestors(element);
|
|
848
|
+
const scrollOffsets = getScrollOffsets(scrollableAncestors);
|
|
849
|
+
this.rect = { ...rect
|
|
850
|
+
};
|
|
851
|
+
this.width = rect.width;
|
|
852
|
+
this.height = rect.height;
|
|
853
|
+
|
|
854
|
+
for (const [axis, keys, getScrollOffset] of properties) {
|
|
855
|
+
for (const key of keys) {
|
|
856
|
+
Object.defineProperty(this, key, {
|
|
857
|
+
get: () => {
|
|
858
|
+
const currentOffsets = getScrollOffset(scrollableAncestors);
|
|
859
|
+
const scrollOffsetsDeltla = scrollOffsets[axis] - currentOffsets;
|
|
860
|
+
return this.rect[key] + scrollOffsetsDeltla;
|
|
861
|
+
},
|
|
862
|
+
enumerable: true
|
|
863
|
+
});
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
Object.defineProperty(this, 'rect', {
|
|
868
|
+
enumerable: false
|
|
869
|
+
});
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
class Listeners {
|
|
875
|
+
constructor(target) {
|
|
876
|
+
this.target = void 0;
|
|
877
|
+
this.listeners = [];
|
|
878
|
+
|
|
879
|
+
this.removeAll = () => {
|
|
880
|
+
this.listeners.forEach(listener => {
|
|
881
|
+
var _this$target;
|
|
882
|
+
|
|
883
|
+
return (_this$target = this.target) == null ? void 0 : _this$target.removeEventListener(...listener);
|
|
884
|
+
});
|
|
885
|
+
};
|
|
886
|
+
|
|
887
|
+
this.target = target;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
add(eventName, handler, options) {
|
|
891
|
+
var _this$target2;
|
|
892
|
+
|
|
893
|
+
(_this$target2 = this.target) == null ? void 0 : _this$target2.addEventListener(eventName, handler, options);
|
|
894
|
+
this.listeners.push([eventName, handler, options]);
|
|
895
|
+
}
|
|
896
|
+
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
function getEventListenerTarget(target) {
|
|
900
|
+
// If the `event.target` element is removed from the document events will still be targeted
|
|
901
|
+
// at it, and hence won't always bubble up to the window or document anymore.
|
|
902
|
+
// If there is any risk of an element being removed while it is being dragged,
|
|
903
|
+
// the best practice is to attach the event listeners directly to the target.
|
|
904
|
+
// https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
|
|
905
|
+
const {
|
|
906
|
+
EventTarget
|
|
907
|
+
} = utilities_esm.getWindow(target);
|
|
908
|
+
return target instanceof EventTarget ? target : utilities_esm.getOwnerDocument(target);
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
function hasExceededDistance(delta, measurement) {
|
|
912
|
+
const dx = Math.abs(delta.x);
|
|
913
|
+
const dy = Math.abs(delta.y);
|
|
914
|
+
|
|
915
|
+
if (typeof measurement === 'number') {
|
|
916
|
+
return Math.sqrt(dx ** 2 + dy ** 2) > measurement;
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
if ('x' in measurement && 'y' in measurement) {
|
|
920
|
+
return dx > measurement.x && dy > measurement.y;
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
if ('x' in measurement) {
|
|
924
|
+
return dx > measurement.x;
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
if ('y' in measurement) {
|
|
928
|
+
return dy > measurement.y;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
return false;
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
var EventName;
|
|
935
|
+
|
|
936
|
+
(function (EventName) {
|
|
937
|
+
EventName["Click"] = "click";
|
|
938
|
+
EventName["DragStart"] = "dragstart";
|
|
939
|
+
EventName["Keydown"] = "keydown";
|
|
940
|
+
EventName["ContextMenu"] = "contextmenu";
|
|
941
|
+
EventName["Resize"] = "resize";
|
|
942
|
+
EventName["SelectionChange"] = "selectionchange";
|
|
943
|
+
EventName["VisibilityChange"] = "visibilitychange";
|
|
944
|
+
})(EventName || (EventName = {}));
|
|
945
|
+
|
|
946
|
+
function preventDefault(event) {
|
|
947
|
+
event.preventDefault();
|
|
948
|
+
}
|
|
949
|
+
function stopPropagation(event) {
|
|
950
|
+
event.stopPropagation();
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
exports.KeyboardCode = void 0;
|
|
954
|
+
|
|
955
|
+
(function (KeyboardCode) {
|
|
956
|
+
KeyboardCode["Space"] = "Space";
|
|
957
|
+
KeyboardCode["Down"] = "ArrowDown";
|
|
958
|
+
KeyboardCode["Right"] = "ArrowRight";
|
|
959
|
+
KeyboardCode["Left"] = "ArrowLeft";
|
|
960
|
+
KeyboardCode["Up"] = "ArrowUp";
|
|
961
|
+
KeyboardCode["Esc"] = "Escape";
|
|
962
|
+
KeyboardCode["Enter"] = "Enter";
|
|
963
|
+
KeyboardCode["Tab"] = "Tab";
|
|
964
|
+
})(exports.KeyboardCode || (exports.KeyboardCode = {}));
|
|
965
|
+
|
|
966
|
+
const defaultKeyboardCodes = {
|
|
967
|
+
start: [exports.KeyboardCode.Space, exports.KeyboardCode.Enter],
|
|
968
|
+
cancel: [exports.KeyboardCode.Esc],
|
|
969
|
+
end: [exports.KeyboardCode.Space, exports.KeyboardCode.Enter, exports.KeyboardCode.Tab]
|
|
970
|
+
};
|
|
971
|
+
const defaultKeyboardCoordinateGetter = (event, _ref) => {
|
|
972
|
+
let {
|
|
973
|
+
currentCoordinates
|
|
974
|
+
} = _ref;
|
|
975
|
+
|
|
976
|
+
switch (event.code) {
|
|
977
|
+
case exports.KeyboardCode.Right:
|
|
978
|
+
return { ...currentCoordinates,
|
|
979
|
+
x: currentCoordinates.x + 25
|
|
980
|
+
};
|
|
981
|
+
|
|
982
|
+
case exports.KeyboardCode.Left:
|
|
983
|
+
return { ...currentCoordinates,
|
|
984
|
+
x: currentCoordinates.x - 25
|
|
985
|
+
};
|
|
986
|
+
|
|
987
|
+
case exports.KeyboardCode.Down:
|
|
988
|
+
return { ...currentCoordinates,
|
|
989
|
+
y: currentCoordinates.y + 25
|
|
990
|
+
};
|
|
991
|
+
|
|
992
|
+
case exports.KeyboardCode.Up:
|
|
993
|
+
return { ...currentCoordinates,
|
|
994
|
+
y: currentCoordinates.y - 25
|
|
995
|
+
};
|
|
996
|
+
}
|
|
997
|
+
|
|
998
|
+
return undefined;
|
|
999
|
+
};
|
|
1000
|
+
|
|
1001
|
+
class KeyboardSensor {
|
|
1002
|
+
constructor(props) {
|
|
1003
|
+
this.props = void 0;
|
|
1004
|
+
this.autoScrollEnabled = false;
|
|
1005
|
+
this.referenceCoordinates = void 0;
|
|
1006
|
+
this.listeners = void 0;
|
|
1007
|
+
this.windowListeners = void 0;
|
|
1008
|
+
this.props = props;
|
|
1009
|
+
const {
|
|
1010
|
+
event: {
|
|
1011
|
+
target
|
|
1012
|
+
}
|
|
1013
|
+
} = props;
|
|
1014
|
+
this.props = props;
|
|
1015
|
+
this.listeners = new Listeners(utilities_esm.getOwnerDocument(target));
|
|
1016
|
+
this.windowListeners = new Listeners(utilities_esm.getWindow(target));
|
|
1017
|
+
this.handleKeyDown = this.handleKeyDown.bind(this);
|
|
1018
|
+
this.handleCancel = this.handleCancel.bind(this);
|
|
1019
|
+
this.attach();
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
attach() {
|
|
1023
|
+
this.handleStart();
|
|
1024
|
+
this.windowListeners.add(EventName.Resize, this.handleCancel);
|
|
1025
|
+
this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
|
|
1026
|
+
setTimeout(() => this.listeners.add(EventName.Keydown, this.handleKeyDown));
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
handleStart() {
|
|
1030
|
+
const {
|
|
1031
|
+
activeNode,
|
|
1032
|
+
onStart
|
|
1033
|
+
} = this.props;
|
|
1034
|
+
const node = activeNode.node.current;
|
|
1035
|
+
|
|
1036
|
+
if (node) {
|
|
1037
|
+
scrollIntoViewIfNeeded(node);
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
onStart(defaultCoordinates);
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
handleKeyDown(event) {
|
|
1044
|
+
if (utilities_esm.isKeyboardEvent(event)) {
|
|
1045
|
+
const {
|
|
1046
|
+
active,
|
|
1047
|
+
context,
|
|
1048
|
+
options
|
|
1049
|
+
} = this.props;
|
|
1050
|
+
const {
|
|
1051
|
+
keyboardCodes = defaultKeyboardCodes,
|
|
1052
|
+
coordinateGetter = defaultKeyboardCoordinateGetter,
|
|
1053
|
+
scrollBehavior = 'smooth'
|
|
1054
|
+
} = options;
|
|
1055
|
+
const {
|
|
1056
|
+
code
|
|
1057
|
+
} = event;
|
|
1058
|
+
|
|
1059
|
+
if (keyboardCodes.end.includes(code)) {
|
|
1060
|
+
this.handleEnd(event);
|
|
1061
|
+
return;
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
if (keyboardCodes.cancel.includes(code)) {
|
|
1065
|
+
this.handleCancel(event);
|
|
1066
|
+
return;
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
const {
|
|
1070
|
+
collisionRect
|
|
1071
|
+
} = context.current;
|
|
1072
|
+
const currentCoordinates = collisionRect ? {
|
|
1073
|
+
x: collisionRect.left,
|
|
1074
|
+
y: collisionRect.top
|
|
1075
|
+
} : defaultCoordinates;
|
|
1076
|
+
|
|
1077
|
+
if (!this.referenceCoordinates) {
|
|
1078
|
+
this.referenceCoordinates = currentCoordinates;
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
const newCoordinates = coordinateGetter(event, {
|
|
1082
|
+
active,
|
|
1083
|
+
context: context.current,
|
|
1084
|
+
currentCoordinates
|
|
1085
|
+
});
|
|
1086
|
+
|
|
1087
|
+
if (newCoordinates) {
|
|
1088
|
+
const coordinatesDelta = utilities_esm.subtract(newCoordinates, currentCoordinates);
|
|
1089
|
+
const scrollDelta = {
|
|
1090
|
+
x: 0,
|
|
1091
|
+
y: 0
|
|
1092
|
+
};
|
|
1093
|
+
const {
|
|
1094
|
+
scrollableAncestors
|
|
1095
|
+
} = context.current;
|
|
1096
|
+
|
|
1097
|
+
for (const scrollContainer of scrollableAncestors) {
|
|
1098
|
+
const direction = event.code;
|
|
1099
|
+
const {
|
|
1100
|
+
isTop,
|
|
1101
|
+
isRight,
|
|
1102
|
+
isLeft,
|
|
1103
|
+
isBottom,
|
|
1104
|
+
maxScroll,
|
|
1105
|
+
minScroll
|
|
1106
|
+
} = getScrollPosition(scrollContainer);
|
|
1107
|
+
const scrollElementRect = getScrollElementRect(scrollContainer);
|
|
1108
|
+
const clampedCoordinates = {
|
|
1109
|
+
x: Math.min(direction === exports.KeyboardCode.Right ? scrollElementRect.right - scrollElementRect.width / 2 : scrollElementRect.right, Math.max(direction === exports.KeyboardCode.Right ? scrollElementRect.left : scrollElementRect.left + scrollElementRect.width / 2, newCoordinates.x)),
|
|
1110
|
+
y: Math.min(direction === exports.KeyboardCode.Down ? scrollElementRect.bottom - scrollElementRect.height / 2 : scrollElementRect.bottom, Math.max(direction === exports.KeyboardCode.Down ? scrollElementRect.top : scrollElementRect.top + scrollElementRect.height / 2, newCoordinates.y))
|
|
1111
|
+
};
|
|
1112
|
+
const canScrollX = direction === exports.KeyboardCode.Right && !isRight || direction === exports.KeyboardCode.Left && !isLeft;
|
|
1113
|
+
const canScrollY = direction === exports.KeyboardCode.Down && !isBottom || direction === exports.KeyboardCode.Up && !isTop;
|
|
1114
|
+
|
|
1115
|
+
if (canScrollX && clampedCoordinates.x !== newCoordinates.x) {
|
|
1116
|
+
const newScrollCoordinates = scrollContainer.scrollLeft + coordinatesDelta.x;
|
|
1117
|
+
const canScrollToNewCoordinates = direction === exports.KeyboardCode.Right && newScrollCoordinates <= maxScroll.x || direction === exports.KeyboardCode.Left && newScrollCoordinates >= minScroll.x;
|
|
1118
|
+
|
|
1119
|
+
if (canScrollToNewCoordinates && !coordinatesDelta.y) {
|
|
1120
|
+
// We don't need to update coordinates, the scroll adjustment alone will trigger
|
|
1121
|
+
// logic to auto-detect the new container we are over
|
|
1122
|
+
scrollContainer.scrollTo({
|
|
1123
|
+
left: newScrollCoordinates,
|
|
1124
|
+
behavior: scrollBehavior
|
|
1125
|
+
});
|
|
1126
|
+
return;
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
if (canScrollToNewCoordinates) {
|
|
1130
|
+
scrollDelta.x = scrollContainer.scrollLeft - newScrollCoordinates;
|
|
1131
|
+
} else {
|
|
1132
|
+
scrollDelta.x = direction === exports.KeyboardCode.Right ? scrollContainer.scrollLeft - maxScroll.x : scrollContainer.scrollLeft - minScroll.x;
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
if (scrollDelta.x) {
|
|
1136
|
+
scrollContainer.scrollBy({
|
|
1137
|
+
left: -scrollDelta.x,
|
|
1138
|
+
behavior: scrollBehavior
|
|
1139
|
+
});
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
break;
|
|
1143
|
+
} else if (canScrollY && clampedCoordinates.y !== newCoordinates.y) {
|
|
1144
|
+
const newScrollCoordinates = scrollContainer.scrollTop + coordinatesDelta.y;
|
|
1145
|
+
const canScrollToNewCoordinates = direction === exports.KeyboardCode.Down && newScrollCoordinates <= maxScroll.y || direction === exports.KeyboardCode.Up && newScrollCoordinates >= minScroll.y;
|
|
1146
|
+
|
|
1147
|
+
if (canScrollToNewCoordinates && !coordinatesDelta.x) {
|
|
1148
|
+
// We don't need to update coordinates, the scroll adjustment alone will trigger
|
|
1149
|
+
// logic to auto-detect the new container we are over
|
|
1150
|
+
scrollContainer.scrollTo({
|
|
1151
|
+
top: newScrollCoordinates,
|
|
1152
|
+
behavior: scrollBehavior
|
|
1153
|
+
});
|
|
1154
|
+
return;
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
if (canScrollToNewCoordinates) {
|
|
1158
|
+
scrollDelta.y = scrollContainer.scrollTop - newScrollCoordinates;
|
|
1159
|
+
} else {
|
|
1160
|
+
scrollDelta.y = direction === exports.KeyboardCode.Down ? scrollContainer.scrollTop - maxScroll.y : scrollContainer.scrollTop - minScroll.y;
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
if (scrollDelta.y) {
|
|
1164
|
+
scrollContainer.scrollBy({
|
|
1165
|
+
top: -scrollDelta.y,
|
|
1166
|
+
behavior: scrollBehavior
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
break;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
|
|
1174
|
+
this.handleMove(event, utilities_esm.add(utilities_esm.subtract(newCoordinates, this.referenceCoordinates), scrollDelta));
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
handleMove(event, coordinates) {
|
|
1180
|
+
const {
|
|
1181
|
+
onMove
|
|
1182
|
+
} = this.props;
|
|
1183
|
+
event.preventDefault();
|
|
1184
|
+
onMove(coordinates);
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
handleEnd(event) {
|
|
1188
|
+
const {
|
|
1189
|
+
onEnd
|
|
1190
|
+
} = this.props;
|
|
1191
|
+
event.preventDefault();
|
|
1192
|
+
this.detach();
|
|
1193
|
+
onEnd();
|
|
1194
|
+
}
|
|
1195
|
+
|
|
1196
|
+
handleCancel(event) {
|
|
1197
|
+
const {
|
|
1198
|
+
onCancel
|
|
1199
|
+
} = this.props;
|
|
1200
|
+
event.preventDefault();
|
|
1201
|
+
this.detach();
|
|
1202
|
+
onCancel();
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
detach() {
|
|
1206
|
+
this.listeners.removeAll();
|
|
1207
|
+
this.windowListeners.removeAll();
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1210
|
+
}
|
|
1211
|
+
KeyboardSensor.activators = [{
|
|
1212
|
+
eventName: 'onKeyDown',
|
|
1213
|
+
handler: (event, _ref, _ref2) => {
|
|
1214
|
+
let {
|
|
1215
|
+
keyboardCodes = defaultKeyboardCodes,
|
|
1216
|
+
onActivation
|
|
1217
|
+
} = _ref;
|
|
1218
|
+
let {
|
|
1219
|
+
active
|
|
1220
|
+
} = _ref2;
|
|
1221
|
+
const {
|
|
1222
|
+
code
|
|
1223
|
+
} = event.nativeEvent;
|
|
1224
|
+
|
|
1225
|
+
if (keyboardCodes.start.includes(code)) {
|
|
1226
|
+
const activator = active.activatorNode.current;
|
|
1227
|
+
|
|
1228
|
+
if (activator && event.target !== activator) {
|
|
1229
|
+
return false;
|
|
1230
|
+
}
|
|
1231
|
+
|
|
1232
|
+
event.preventDefault();
|
|
1233
|
+
onActivation == null ? void 0 : onActivation({
|
|
1234
|
+
event: event.nativeEvent
|
|
1235
|
+
});
|
|
1236
|
+
return true;
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
return false;
|
|
1240
|
+
}
|
|
1241
|
+
}];
|
|
1242
|
+
|
|
1243
|
+
function isDistanceConstraint(constraint) {
|
|
1244
|
+
return Boolean(constraint && 'distance' in constraint);
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
function isDelayConstraint(constraint) {
|
|
1248
|
+
return Boolean(constraint && 'delay' in constraint);
|
|
1249
|
+
}
|
|
1250
|
+
|
|
1251
|
+
class AbstractPointerSensor {
|
|
1252
|
+
constructor(props, events, listenerTarget) {
|
|
1253
|
+
var _getEventCoordinates;
|
|
1254
|
+
|
|
1255
|
+
if (listenerTarget === void 0) {
|
|
1256
|
+
listenerTarget = getEventListenerTarget(props.event.target);
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
this.props = void 0;
|
|
1260
|
+
this.events = void 0;
|
|
1261
|
+
this.autoScrollEnabled = true;
|
|
1262
|
+
this.document = void 0;
|
|
1263
|
+
this.activated = false;
|
|
1264
|
+
this.initialCoordinates = void 0;
|
|
1265
|
+
this.timeoutId = null;
|
|
1266
|
+
this.listeners = void 0;
|
|
1267
|
+
this.documentListeners = void 0;
|
|
1268
|
+
this.windowListeners = void 0;
|
|
1269
|
+
this.props = props;
|
|
1270
|
+
this.events = events;
|
|
1271
|
+
const {
|
|
1272
|
+
event
|
|
1273
|
+
} = props;
|
|
1274
|
+
const {
|
|
1275
|
+
target
|
|
1276
|
+
} = event;
|
|
1277
|
+
this.props = props;
|
|
1278
|
+
this.events = events;
|
|
1279
|
+
this.document = utilities_esm.getOwnerDocument(target);
|
|
1280
|
+
this.documentListeners = new Listeners(this.document);
|
|
1281
|
+
this.listeners = new Listeners(listenerTarget);
|
|
1282
|
+
this.windowListeners = new Listeners(utilities_esm.getWindow(target));
|
|
1283
|
+
this.initialCoordinates = (_getEventCoordinates = utilities_esm.getEventCoordinates(event)) != null ? _getEventCoordinates : defaultCoordinates;
|
|
1284
|
+
this.handleStart = this.handleStart.bind(this);
|
|
1285
|
+
this.handleMove = this.handleMove.bind(this);
|
|
1286
|
+
this.handleEnd = this.handleEnd.bind(this);
|
|
1287
|
+
this.handleCancel = this.handleCancel.bind(this);
|
|
1288
|
+
this.handleKeydown = this.handleKeydown.bind(this);
|
|
1289
|
+
this.removeTextSelection = this.removeTextSelection.bind(this);
|
|
1290
|
+
this.attach();
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
attach() {
|
|
1294
|
+
const {
|
|
1295
|
+
events,
|
|
1296
|
+
props: {
|
|
1297
|
+
options: {
|
|
1298
|
+
activationConstraint,
|
|
1299
|
+
bypassActivationConstraint
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
} = this;
|
|
1303
|
+
this.listeners.add(events.move.name, this.handleMove, {
|
|
1304
|
+
passive: false
|
|
1305
|
+
});
|
|
1306
|
+
this.listeners.add(events.end.name, this.handleEnd);
|
|
1307
|
+
|
|
1308
|
+
if (events.cancel) {
|
|
1309
|
+
this.listeners.add(events.cancel.name, this.handleCancel);
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
this.windowListeners.add(EventName.Resize, this.handleCancel);
|
|
1313
|
+
this.windowListeners.add(EventName.DragStart, preventDefault);
|
|
1314
|
+
this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
|
|
1315
|
+
this.windowListeners.add(EventName.ContextMenu, preventDefault);
|
|
1316
|
+
this.documentListeners.add(EventName.Keydown, this.handleKeydown);
|
|
1317
|
+
|
|
1318
|
+
if (activationConstraint) {
|
|
1319
|
+
if (bypassActivationConstraint != null && bypassActivationConstraint({
|
|
1320
|
+
event: this.props.event,
|
|
1321
|
+
activeNode: this.props.activeNode,
|
|
1322
|
+
options: this.props.options
|
|
1323
|
+
})) {
|
|
1324
|
+
return this.handleStart();
|
|
1325
|
+
}
|
|
1326
|
+
|
|
1327
|
+
if (isDelayConstraint(activationConstraint)) {
|
|
1328
|
+
this.timeoutId = setTimeout(this.handleStart, activationConstraint.delay);
|
|
1329
|
+
this.handlePending(activationConstraint);
|
|
1330
|
+
return;
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
if (isDistanceConstraint(activationConstraint)) {
|
|
1334
|
+
this.handlePending(activationConstraint);
|
|
1335
|
+
return;
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
this.handleStart();
|
|
1340
|
+
}
|
|
1341
|
+
|
|
1342
|
+
detach() {
|
|
1343
|
+
this.listeners.removeAll();
|
|
1344
|
+
this.windowListeners.removeAll(); // Wait until the next event loop before removing document listeners
|
|
1345
|
+
// This is necessary because we listen for `click` and `selection` events on the document
|
|
1346
|
+
|
|
1347
|
+
setTimeout(this.documentListeners.removeAll, 50);
|
|
1348
|
+
|
|
1349
|
+
if (this.timeoutId !== null) {
|
|
1350
|
+
clearTimeout(this.timeoutId);
|
|
1351
|
+
this.timeoutId = null;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
|
|
1355
|
+
handlePending(constraint, offset) {
|
|
1356
|
+
const {
|
|
1357
|
+
active,
|
|
1358
|
+
onPending
|
|
1359
|
+
} = this.props;
|
|
1360
|
+
onPending(active, constraint, this.initialCoordinates, offset);
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
handleStart() {
|
|
1364
|
+
const {
|
|
1365
|
+
initialCoordinates
|
|
1366
|
+
} = this;
|
|
1367
|
+
const {
|
|
1368
|
+
onStart
|
|
1369
|
+
} = this.props;
|
|
1370
|
+
|
|
1371
|
+
if (initialCoordinates) {
|
|
1372
|
+
this.activated = true; // Stop propagation of click events once activation constraints are met
|
|
1373
|
+
|
|
1374
|
+
this.documentListeners.add(EventName.Click, stopPropagation, {
|
|
1375
|
+
capture: true
|
|
1376
|
+
}); // Remove any text selection from the document
|
|
1377
|
+
|
|
1378
|
+
this.removeTextSelection(); // Prevent further text selection while dragging
|
|
1379
|
+
|
|
1380
|
+
this.documentListeners.add(EventName.SelectionChange, this.removeTextSelection);
|
|
1381
|
+
onStart(initialCoordinates);
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
handleMove(event) {
|
|
1386
|
+
var _getEventCoordinates2;
|
|
1387
|
+
|
|
1388
|
+
const {
|
|
1389
|
+
activated,
|
|
1390
|
+
initialCoordinates,
|
|
1391
|
+
props
|
|
1392
|
+
} = this;
|
|
1393
|
+
const {
|
|
1394
|
+
onMove,
|
|
1395
|
+
options: {
|
|
1396
|
+
activationConstraint
|
|
1397
|
+
}
|
|
1398
|
+
} = props;
|
|
1399
|
+
|
|
1400
|
+
if (!initialCoordinates) {
|
|
1401
|
+
return;
|
|
1402
|
+
}
|
|
1403
|
+
|
|
1404
|
+
const coordinates = (_getEventCoordinates2 = utilities_esm.getEventCoordinates(event)) != null ? _getEventCoordinates2 : defaultCoordinates;
|
|
1405
|
+
const delta = utilities_esm.subtract(initialCoordinates, coordinates); // Constraint validation
|
|
1406
|
+
|
|
1407
|
+
if (!activated && activationConstraint) {
|
|
1408
|
+
if (isDistanceConstraint(activationConstraint)) {
|
|
1409
|
+
if (activationConstraint.tolerance != null && hasExceededDistance(delta, activationConstraint.tolerance)) {
|
|
1410
|
+
return this.handleCancel();
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
if (hasExceededDistance(delta, activationConstraint.distance)) {
|
|
1414
|
+
return this.handleStart();
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
|
|
1418
|
+
if (isDelayConstraint(activationConstraint)) {
|
|
1419
|
+
if (hasExceededDistance(delta, activationConstraint.tolerance)) {
|
|
1420
|
+
return this.handleCancel();
|
|
1421
|
+
}
|
|
1422
|
+
}
|
|
1423
|
+
|
|
1424
|
+
this.handlePending(activationConstraint, delta);
|
|
1425
|
+
return;
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
if (event.cancelable) {
|
|
1429
|
+
event.preventDefault();
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
onMove(coordinates);
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
handleEnd() {
|
|
1436
|
+
const {
|
|
1437
|
+
onAbort,
|
|
1438
|
+
onEnd
|
|
1439
|
+
} = this.props;
|
|
1440
|
+
this.detach();
|
|
1441
|
+
|
|
1442
|
+
if (!this.activated) {
|
|
1443
|
+
onAbort(this.props.active);
|
|
1444
|
+
}
|
|
1445
|
+
|
|
1446
|
+
onEnd();
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
handleCancel() {
|
|
1450
|
+
const {
|
|
1451
|
+
onAbort,
|
|
1452
|
+
onCancel
|
|
1453
|
+
} = this.props;
|
|
1454
|
+
this.detach();
|
|
1455
|
+
|
|
1456
|
+
if (!this.activated) {
|
|
1457
|
+
onAbort(this.props.active);
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
onCancel();
|
|
1461
|
+
}
|
|
1462
|
+
|
|
1463
|
+
handleKeydown(event) {
|
|
1464
|
+
if (event.code === exports.KeyboardCode.Esc) {
|
|
1465
|
+
this.handleCancel();
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
removeTextSelection() {
|
|
1470
|
+
var _this$document$getSel;
|
|
1471
|
+
|
|
1472
|
+
(_this$document$getSel = this.document.getSelection()) == null ? void 0 : _this$document$getSel.removeAllRanges();
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
const events = {
|
|
1478
|
+
cancel: {
|
|
1479
|
+
name: 'pointercancel'
|
|
1480
|
+
},
|
|
1481
|
+
move: {
|
|
1482
|
+
name: 'pointermove'
|
|
1483
|
+
},
|
|
1484
|
+
end: {
|
|
1485
|
+
name: 'pointerup'
|
|
1486
|
+
}
|
|
1487
|
+
};
|
|
1488
|
+
class PointerSensor extends AbstractPointerSensor {
|
|
1489
|
+
constructor(props) {
|
|
1490
|
+
const {
|
|
1491
|
+
event
|
|
1492
|
+
} = props; // Pointer events stop firing if the target is unmounted while dragging
|
|
1493
|
+
// Therefore we attach listeners to the owner document instead
|
|
1494
|
+
|
|
1495
|
+
const listenerTarget = utilities_esm.getOwnerDocument(event.target);
|
|
1496
|
+
super(props, events, listenerTarget);
|
|
1497
|
+
}
|
|
1498
|
+
|
|
1499
|
+
}
|
|
1500
|
+
PointerSensor.activators = [{
|
|
1501
|
+
eventName: 'onPointerDown',
|
|
1502
|
+
handler: (_ref, _ref2) => {
|
|
1503
|
+
let {
|
|
1504
|
+
nativeEvent: event
|
|
1505
|
+
} = _ref;
|
|
1506
|
+
let {
|
|
1507
|
+
onActivation
|
|
1508
|
+
} = _ref2;
|
|
1509
|
+
|
|
1510
|
+
if (!event.isPrimary || event.button !== 0) {
|
|
1511
|
+
return false;
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
onActivation == null ? void 0 : onActivation({
|
|
1515
|
+
event
|
|
1516
|
+
});
|
|
1517
|
+
return true;
|
|
1518
|
+
}
|
|
1519
|
+
}];
|
|
1520
|
+
|
|
1521
|
+
const events$1 = {
|
|
1522
|
+
move: {
|
|
1523
|
+
name: 'mousemove'
|
|
1524
|
+
},
|
|
1525
|
+
end: {
|
|
1526
|
+
name: 'mouseup'
|
|
1527
|
+
}
|
|
1528
|
+
};
|
|
1529
|
+
var MouseButton;
|
|
1530
|
+
|
|
1531
|
+
(function (MouseButton) {
|
|
1532
|
+
MouseButton[MouseButton["RightClick"] = 2] = "RightClick";
|
|
1533
|
+
})(MouseButton || (MouseButton = {}));
|
|
1534
|
+
|
|
1535
|
+
class MouseSensor extends AbstractPointerSensor {
|
|
1536
|
+
constructor(props) {
|
|
1537
|
+
super(props, events$1, utilities_esm.getOwnerDocument(props.event.target));
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
}
|
|
1541
|
+
MouseSensor.activators = [{
|
|
1542
|
+
eventName: 'onMouseDown',
|
|
1543
|
+
handler: (_ref, _ref2) => {
|
|
1544
|
+
let {
|
|
1545
|
+
nativeEvent: event
|
|
1546
|
+
} = _ref;
|
|
1547
|
+
let {
|
|
1548
|
+
onActivation
|
|
1549
|
+
} = _ref2;
|
|
1550
|
+
|
|
1551
|
+
if (event.button === MouseButton.RightClick) {
|
|
1552
|
+
return false;
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
onActivation == null ? void 0 : onActivation({
|
|
1556
|
+
event
|
|
1557
|
+
});
|
|
1558
|
+
return true;
|
|
1559
|
+
}
|
|
1560
|
+
}];
|
|
1561
|
+
|
|
1562
|
+
const events$2 = {
|
|
1563
|
+
cancel: {
|
|
1564
|
+
name: 'touchcancel'
|
|
1565
|
+
},
|
|
1566
|
+
move: {
|
|
1567
|
+
name: 'touchmove'
|
|
1568
|
+
},
|
|
1569
|
+
end: {
|
|
1570
|
+
name: 'touchend'
|
|
1571
|
+
}
|
|
1572
|
+
};
|
|
1573
|
+
class TouchSensor extends AbstractPointerSensor {
|
|
1574
|
+
constructor(props) {
|
|
1575
|
+
super(props, events$2);
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
static setup() {
|
|
1579
|
+
// Adding a non-capture and non-passive `touchmove` listener in order
|
|
1580
|
+
// to force `event.preventDefault()` calls to work in dynamically added
|
|
1581
|
+
// touchmove event handlers. This is required for iOS Safari.
|
|
1582
|
+
window.addEventListener(events$2.move.name, noop, {
|
|
1583
|
+
capture: false,
|
|
1584
|
+
passive: false
|
|
1585
|
+
});
|
|
1586
|
+
return function teardown() {
|
|
1587
|
+
window.removeEventListener(events$2.move.name, noop);
|
|
1588
|
+
}; // We create a new handler because the teardown function of another sensor
|
|
1589
|
+
// could remove our event listener if we use a referentially equal listener.
|
|
1590
|
+
|
|
1591
|
+
function noop() {}
|
|
1592
|
+
}
|
|
1593
|
+
|
|
1594
|
+
}
|
|
1595
|
+
TouchSensor.activators = [{
|
|
1596
|
+
eventName: 'onTouchStart',
|
|
1597
|
+
handler: (_ref, _ref2) => {
|
|
1598
|
+
let {
|
|
1599
|
+
nativeEvent: event
|
|
1600
|
+
} = _ref;
|
|
1601
|
+
let {
|
|
1602
|
+
onActivation
|
|
1603
|
+
} = _ref2;
|
|
1604
|
+
const {
|
|
1605
|
+
touches
|
|
1606
|
+
} = event;
|
|
1607
|
+
|
|
1608
|
+
if (touches.length > 1) {
|
|
1609
|
+
return false;
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
onActivation == null ? void 0 : onActivation({
|
|
1613
|
+
event
|
|
1614
|
+
});
|
|
1615
|
+
return true;
|
|
1616
|
+
}
|
|
1617
|
+
}];
|
|
1618
|
+
|
|
1619
|
+
exports.AutoScrollActivator = void 0;
|
|
1620
|
+
|
|
1621
|
+
(function (AutoScrollActivator) {
|
|
1622
|
+
AutoScrollActivator[AutoScrollActivator["Pointer"] = 0] = "Pointer";
|
|
1623
|
+
AutoScrollActivator[AutoScrollActivator["DraggableRect"] = 1] = "DraggableRect";
|
|
1624
|
+
})(exports.AutoScrollActivator || (exports.AutoScrollActivator = {}));
|
|
1625
|
+
|
|
1626
|
+
exports.TraversalOrder = void 0;
|
|
1627
|
+
|
|
1628
|
+
(function (TraversalOrder) {
|
|
1629
|
+
TraversalOrder[TraversalOrder["TreeOrder"] = 0] = "TreeOrder";
|
|
1630
|
+
TraversalOrder[TraversalOrder["ReversedTreeOrder"] = 1] = "ReversedTreeOrder";
|
|
1631
|
+
})(exports.TraversalOrder || (exports.TraversalOrder = {}));
|
|
1632
|
+
|
|
1633
|
+
function useAutoScroller(_ref) {
|
|
1634
|
+
let {
|
|
1635
|
+
acceleration,
|
|
1636
|
+
activator = exports.AutoScrollActivator.Pointer,
|
|
1637
|
+
canScroll,
|
|
1638
|
+
draggingRect,
|
|
1639
|
+
enabled,
|
|
1640
|
+
interval = 5,
|
|
1641
|
+
order = exports.TraversalOrder.TreeOrder,
|
|
1642
|
+
pointerCoordinates,
|
|
1643
|
+
scrollableAncestors,
|
|
1644
|
+
scrollableAncestorRects,
|
|
1645
|
+
delta,
|
|
1646
|
+
threshold
|
|
1647
|
+
} = _ref;
|
|
1648
|
+
const scrollIntent = useScrollIntent({
|
|
1649
|
+
delta,
|
|
1650
|
+
disabled: !enabled
|
|
1651
|
+
});
|
|
1652
|
+
const [setAutoScrollInterval, clearAutoScrollInterval] = utilities_esm.useInterval();
|
|
1653
|
+
const scrollSpeed = React.useRef({
|
|
1654
|
+
x: 0,
|
|
1655
|
+
y: 0
|
|
1656
|
+
});
|
|
1657
|
+
const scrollDirection = React.useRef({
|
|
1658
|
+
x: 0,
|
|
1659
|
+
y: 0
|
|
1660
|
+
});
|
|
1661
|
+
const rect = React.useMemo(() => {
|
|
1662
|
+
switch (activator) {
|
|
1663
|
+
case exports.AutoScrollActivator.Pointer:
|
|
1664
|
+
return pointerCoordinates ? {
|
|
1665
|
+
top: pointerCoordinates.y,
|
|
1666
|
+
bottom: pointerCoordinates.y,
|
|
1667
|
+
left: pointerCoordinates.x,
|
|
1668
|
+
right: pointerCoordinates.x
|
|
1669
|
+
} : null;
|
|
1670
|
+
|
|
1671
|
+
case exports.AutoScrollActivator.DraggableRect:
|
|
1672
|
+
return draggingRect;
|
|
1673
|
+
}
|
|
1674
|
+
}, [activator, draggingRect, pointerCoordinates]);
|
|
1675
|
+
const scrollContainerRef = React.useRef(null);
|
|
1676
|
+
const autoScroll = React.useCallback(() => {
|
|
1677
|
+
const scrollContainer = scrollContainerRef.current;
|
|
1678
|
+
|
|
1679
|
+
if (!scrollContainer) {
|
|
1680
|
+
return;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
const scrollLeft = scrollSpeed.current.x * scrollDirection.current.x;
|
|
1684
|
+
const scrollTop = scrollSpeed.current.y * scrollDirection.current.y;
|
|
1685
|
+
scrollContainer.scrollBy(scrollLeft, scrollTop);
|
|
1686
|
+
}, []);
|
|
1687
|
+
const sortedScrollableAncestors = React.useMemo(() => order === exports.TraversalOrder.TreeOrder ? [...scrollableAncestors].reverse() : scrollableAncestors, [order, scrollableAncestors]);
|
|
1688
|
+
React.useEffect(() => {
|
|
1689
|
+
if (!enabled || !scrollableAncestors.length || !rect) {
|
|
1690
|
+
clearAutoScrollInterval();
|
|
1691
|
+
return;
|
|
1692
|
+
}
|
|
1693
|
+
|
|
1694
|
+
for (const scrollContainer of sortedScrollableAncestors) {
|
|
1695
|
+
if ((canScroll == null ? void 0 : canScroll(scrollContainer)) === false) {
|
|
1696
|
+
continue;
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
const index = scrollableAncestors.indexOf(scrollContainer);
|
|
1700
|
+
const scrollContainerRect = scrollableAncestorRects[index];
|
|
1701
|
+
|
|
1702
|
+
if (!scrollContainerRect) {
|
|
1703
|
+
continue;
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1706
|
+
const {
|
|
1707
|
+
direction,
|
|
1708
|
+
speed
|
|
1709
|
+
} = getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, rect, acceleration, threshold);
|
|
1710
|
+
|
|
1711
|
+
for (const axis of ['x', 'y']) {
|
|
1712
|
+
if (!scrollIntent[axis][direction[axis]]) {
|
|
1713
|
+
speed[axis] = 0;
|
|
1714
|
+
direction[axis] = 0;
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
|
|
1718
|
+
if (speed.x > 0 || speed.y > 0) {
|
|
1719
|
+
clearAutoScrollInterval();
|
|
1720
|
+
scrollContainerRef.current = scrollContainer;
|
|
1721
|
+
setAutoScrollInterval(autoScroll, interval);
|
|
1722
|
+
scrollSpeed.current = speed;
|
|
1723
|
+
scrollDirection.current = direction;
|
|
1724
|
+
return;
|
|
1725
|
+
}
|
|
1726
|
+
}
|
|
1727
|
+
|
|
1728
|
+
scrollSpeed.current = {
|
|
1729
|
+
x: 0,
|
|
1730
|
+
y: 0
|
|
1731
|
+
};
|
|
1732
|
+
scrollDirection.current = {
|
|
1733
|
+
x: 0,
|
|
1734
|
+
y: 0
|
|
1735
|
+
};
|
|
1736
|
+
clearAutoScrollInterval();
|
|
1737
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1738
|
+
[acceleration, autoScroll, canScroll, clearAutoScrollInterval, enabled, interval, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1739
|
+
JSON.stringify(rect), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1740
|
+
JSON.stringify(scrollIntent), setAutoScrollInterval, scrollableAncestors, sortedScrollableAncestors, scrollableAncestorRects, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1741
|
+
JSON.stringify(threshold)]);
|
|
1742
|
+
}
|
|
1743
|
+
const defaultScrollIntent = {
|
|
1744
|
+
x: {
|
|
1745
|
+
[Direction.Backward]: false,
|
|
1746
|
+
[Direction.Forward]: false
|
|
1747
|
+
},
|
|
1748
|
+
y: {
|
|
1749
|
+
[Direction.Backward]: false,
|
|
1750
|
+
[Direction.Forward]: false
|
|
1751
|
+
}
|
|
1752
|
+
};
|
|
1753
|
+
|
|
1754
|
+
function useScrollIntent(_ref2) {
|
|
1755
|
+
let {
|
|
1756
|
+
delta,
|
|
1757
|
+
disabled
|
|
1758
|
+
} = _ref2;
|
|
1759
|
+
const previousDelta = utilities_esm.usePrevious(delta);
|
|
1760
|
+
return utilities_esm.useLazyMemo(previousIntent => {
|
|
1761
|
+
if (disabled || !previousDelta || !previousIntent) {
|
|
1762
|
+
// Reset scroll intent tracking when auto-scrolling is disabled
|
|
1763
|
+
return defaultScrollIntent;
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
const direction = {
|
|
1767
|
+
x: Math.sign(delta.x - previousDelta.x),
|
|
1768
|
+
y: Math.sign(delta.y - previousDelta.y)
|
|
1769
|
+
}; // Keep track of the user intent to scroll in each direction for both axis
|
|
1770
|
+
|
|
1771
|
+
return {
|
|
1772
|
+
x: {
|
|
1773
|
+
[Direction.Backward]: previousIntent.x[Direction.Backward] || direction.x === -1,
|
|
1774
|
+
[Direction.Forward]: previousIntent.x[Direction.Forward] || direction.x === 1
|
|
1775
|
+
},
|
|
1776
|
+
y: {
|
|
1777
|
+
[Direction.Backward]: previousIntent.y[Direction.Backward] || direction.y === -1,
|
|
1778
|
+
[Direction.Forward]: previousIntent.y[Direction.Forward] || direction.y === 1
|
|
1779
|
+
}
|
|
1780
|
+
};
|
|
1781
|
+
}, [disabled, delta, previousDelta]);
|
|
1782
|
+
}
|
|
1783
|
+
|
|
1784
|
+
function useCachedNode(draggableNodes, id) {
|
|
1785
|
+
const draggableNode = id != null ? draggableNodes.get(id) : undefined;
|
|
1786
|
+
const node = draggableNode ? draggableNode.node.current : null;
|
|
1787
|
+
return utilities_esm.useLazyMemo(cachedNode => {
|
|
1788
|
+
var _ref;
|
|
1789
|
+
|
|
1790
|
+
if (id == null) {
|
|
1791
|
+
return null;
|
|
1792
|
+
} // In some cases, the draggable node can unmount while dragging
|
|
1793
|
+
// This is the case for virtualized lists. In those situations,
|
|
1794
|
+
// we fall back to the last known value for that node.
|
|
1795
|
+
|
|
1796
|
+
|
|
1797
|
+
return (_ref = node != null ? node : cachedNode) != null ? _ref : null;
|
|
1798
|
+
}, [node, id]);
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
function useCombineActivators(sensors, getSyntheticHandler) {
|
|
1802
|
+
return React.useMemo(() => sensors.reduce((accumulator, sensor) => {
|
|
1803
|
+
const {
|
|
1804
|
+
sensor: Sensor
|
|
1805
|
+
} = sensor;
|
|
1806
|
+
const sensorActivators = Sensor.activators.map(activator => ({
|
|
1807
|
+
eventName: activator.eventName,
|
|
1808
|
+
handler: getSyntheticHandler(activator.handler, sensor)
|
|
1809
|
+
}));
|
|
1810
|
+
return [...accumulator, ...sensorActivators];
|
|
1811
|
+
}, []), [sensors, getSyntheticHandler]);
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
exports.MeasuringStrategy = void 0;
|
|
1815
|
+
|
|
1816
|
+
(function (MeasuringStrategy) {
|
|
1817
|
+
MeasuringStrategy[MeasuringStrategy["Always"] = 0] = "Always";
|
|
1818
|
+
MeasuringStrategy[MeasuringStrategy["BeforeDragging"] = 1] = "BeforeDragging";
|
|
1819
|
+
MeasuringStrategy[MeasuringStrategy["WhileDragging"] = 2] = "WhileDragging";
|
|
1820
|
+
})(exports.MeasuringStrategy || (exports.MeasuringStrategy = {}));
|
|
1821
|
+
|
|
1822
|
+
exports.MeasuringFrequency = void 0;
|
|
1823
|
+
|
|
1824
|
+
(function (MeasuringFrequency) {
|
|
1825
|
+
MeasuringFrequency["Optimized"] = "optimized";
|
|
1826
|
+
})(exports.MeasuringFrequency || (exports.MeasuringFrequency = {}));
|
|
1827
|
+
|
|
1828
|
+
const defaultValue = /*#__PURE__*/new Map();
|
|
1829
|
+
function useDroppableMeasuring(containers, _ref) {
|
|
1830
|
+
let {
|
|
1831
|
+
dragging,
|
|
1832
|
+
dependencies,
|
|
1833
|
+
config
|
|
1834
|
+
} = _ref;
|
|
1835
|
+
const [queue, setQueue] = React.useState(null);
|
|
1836
|
+
const {
|
|
1837
|
+
frequency,
|
|
1838
|
+
measure,
|
|
1839
|
+
strategy
|
|
1840
|
+
} = config;
|
|
1841
|
+
const containersRef = React.useRef(containers);
|
|
1842
|
+
const disabled = isDisabled();
|
|
1843
|
+
const disabledRef = utilities_esm.useLatestValue(disabled);
|
|
1844
|
+
const measureDroppableContainers = React.useCallback(function (ids) {
|
|
1845
|
+
if (ids === void 0) {
|
|
1846
|
+
ids = [];
|
|
1847
|
+
}
|
|
1848
|
+
|
|
1849
|
+
if (disabledRef.current) {
|
|
1850
|
+
return;
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
setQueue(value => {
|
|
1854
|
+
if (value === null) {
|
|
1855
|
+
return ids;
|
|
1856
|
+
}
|
|
1857
|
+
|
|
1858
|
+
return value.concat(ids.filter(id => !value.includes(id)));
|
|
1859
|
+
});
|
|
1860
|
+
}, [disabledRef]);
|
|
1861
|
+
const timeoutId = React.useRef(null);
|
|
1862
|
+
const droppableRects = utilities_esm.useLazyMemo(previousValue => {
|
|
1863
|
+
if (disabled && !dragging) {
|
|
1864
|
+
return defaultValue;
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
if (!previousValue || previousValue === defaultValue || containersRef.current !== containers || queue != null) {
|
|
1868
|
+
const map = new Map();
|
|
1869
|
+
|
|
1870
|
+
for (let container of containers) {
|
|
1871
|
+
if (!container) {
|
|
1872
|
+
continue;
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
if (queue && queue.length > 0 && !queue.includes(container.id) && container.rect.current) {
|
|
1876
|
+
// This container does not need to be re-measured
|
|
1877
|
+
map.set(container.id, container.rect.current);
|
|
1878
|
+
continue;
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
const node = container.node.current;
|
|
1882
|
+
const rect = node ? new Rect(measure(node), node) : null;
|
|
1883
|
+
container.rect.current = rect;
|
|
1884
|
+
|
|
1885
|
+
if (rect) {
|
|
1886
|
+
map.set(container.id, rect);
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
return map;
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
return previousValue;
|
|
1894
|
+
}, [containers, queue, dragging, disabled, measure]);
|
|
1895
|
+
React.useEffect(() => {
|
|
1896
|
+
containersRef.current = containers;
|
|
1897
|
+
}, [containers]);
|
|
1898
|
+
React.useEffect(() => {
|
|
1899
|
+
if (disabled) {
|
|
1900
|
+
return;
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
measureDroppableContainers();
|
|
1904
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1905
|
+
[dragging, disabled]);
|
|
1906
|
+
React.useEffect(() => {
|
|
1907
|
+
if (queue && queue.length > 0) {
|
|
1908
|
+
setQueue(null);
|
|
1909
|
+
}
|
|
1910
|
+
}, //eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1911
|
+
[JSON.stringify(queue)]);
|
|
1912
|
+
React.useEffect(() => {
|
|
1913
|
+
if (disabled || typeof frequency !== 'number' || timeoutId.current !== null) {
|
|
1914
|
+
return;
|
|
1915
|
+
}
|
|
1916
|
+
|
|
1917
|
+
timeoutId.current = setTimeout(() => {
|
|
1918
|
+
measureDroppableContainers();
|
|
1919
|
+
timeoutId.current = null;
|
|
1920
|
+
}, frequency);
|
|
1921
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1922
|
+
[frequency, disabled, measureDroppableContainers, ...dependencies]);
|
|
1923
|
+
return {
|
|
1924
|
+
droppableRects,
|
|
1925
|
+
measureDroppableContainers,
|
|
1926
|
+
measuringScheduled: queue != null
|
|
1927
|
+
};
|
|
1928
|
+
|
|
1929
|
+
function isDisabled() {
|
|
1930
|
+
switch (strategy) {
|
|
1931
|
+
case exports.MeasuringStrategy.Always:
|
|
1932
|
+
return false;
|
|
1933
|
+
|
|
1934
|
+
case exports.MeasuringStrategy.BeforeDragging:
|
|
1935
|
+
return dragging;
|
|
1936
|
+
|
|
1937
|
+
default:
|
|
1938
|
+
return !dragging;
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
function useInitialValue(value, computeFn) {
|
|
1944
|
+
return utilities_esm.useLazyMemo(previousValue => {
|
|
1945
|
+
if (!value) {
|
|
1946
|
+
return null;
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1949
|
+
if (previousValue) {
|
|
1950
|
+
return previousValue;
|
|
1951
|
+
}
|
|
1952
|
+
|
|
1953
|
+
return typeof computeFn === 'function' ? computeFn(value) : value;
|
|
1954
|
+
}, [computeFn, value]);
|
|
1955
|
+
}
|
|
1956
|
+
|
|
1957
|
+
function useInitialRect(node, measure) {
|
|
1958
|
+
return useInitialValue(node, measure);
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
/**
|
|
1962
|
+
* Returns a new MutationObserver instance.
|
|
1963
|
+
* If `MutationObserver` is undefined in the execution environment, returns `undefined`.
|
|
1964
|
+
*/
|
|
1965
|
+
|
|
1966
|
+
function useMutationObserver(_ref) {
|
|
1967
|
+
let {
|
|
1968
|
+
callback,
|
|
1969
|
+
disabled
|
|
1970
|
+
} = _ref;
|
|
1971
|
+
const handleMutations = utilities_esm.useEvent(callback);
|
|
1972
|
+
const mutationObserver = React.useMemo(() => {
|
|
1973
|
+
if (disabled || typeof window === 'undefined' || typeof window.MutationObserver === 'undefined') {
|
|
1974
|
+
return undefined;
|
|
1975
|
+
}
|
|
1976
|
+
|
|
1977
|
+
const {
|
|
1978
|
+
MutationObserver
|
|
1979
|
+
} = window;
|
|
1980
|
+
return new MutationObserver(handleMutations);
|
|
1981
|
+
}, [handleMutations, disabled]);
|
|
1982
|
+
React.useEffect(() => {
|
|
1983
|
+
return () => mutationObserver == null ? void 0 : mutationObserver.disconnect();
|
|
1984
|
+
}, [mutationObserver]);
|
|
1985
|
+
return mutationObserver;
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
/**
|
|
1989
|
+
* Returns a new ResizeObserver instance bound to the `onResize` callback.
|
|
1990
|
+
* If `ResizeObserver` is undefined in the execution environment, returns `undefined`.
|
|
1991
|
+
*/
|
|
1992
|
+
|
|
1993
|
+
function useResizeObserver(_ref) {
|
|
1994
|
+
let {
|
|
1995
|
+
callback,
|
|
1996
|
+
disabled
|
|
1997
|
+
} = _ref;
|
|
1998
|
+
const handleResize = utilities_esm.useEvent(callback);
|
|
1999
|
+
const resizeObserver = React.useMemo(() => {
|
|
2000
|
+
if (disabled || typeof window === 'undefined' || typeof window.ResizeObserver === 'undefined') {
|
|
2001
|
+
return undefined;
|
|
2002
|
+
}
|
|
2003
|
+
|
|
2004
|
+
const {
|
|
2005
|
+
ResizeObserver
|
|
2006
|
+
} = window;
|
|
2007
|
+
return new ResizeObserver(handleResize);
|
|
2008
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2009
|
+
[disabled]);
|
|
2010
|
+
React.useEffect(() => {
|
|
2011
|
+
return () => resizeObserver == null ? void 0 : resizeObserver.disconnect();
|
|
2012
|
+
}, [resizeObserver]);
|
|
2013
|
+
return resizeObserver;
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
function defaultMeasure(element) {
|
|
2017
|
+
return new Rect(getClientRect(element), element);
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
function useRect(element, measure, fallbackRect) {
|
|
2021
|
+
if (measure === void 0) {
|
|
2022
|
+
measure = defaultMeasure;
|
|
2023
|
+
}
|
|
2024
|
+
|
|
2025
|
+
const [rect, setRect] = React.useState(null);
|
|
2026
|
+
|
|
2027
|
+
function measureRect() {
|
|
2028
|
+
setRect(currentRect => {
|
|
2029
|
+
if (!element) {
|
|
2030
|
+
return null;
|
|
2031
|
+
}
|
|
2032
|
+
|
|
2033
|
+
if (element.isConnected === false) {
|
|
2034
|
+
var _ref;
|
|
2035
|
+
|
|
2036
|
+
// Fall back to last rect we measured if the element is
|
|
2037
|
+
// no longer connected to the DOM.
|
|
2038
|
+
return (_ref = currentRect != null ? currentRect : fallbackRect) != null ? _ref : null;
|
|
2039
|
+
}
|
|
2040
|
+
|
|
2041
|
+
const newRect = measure(element);
|
|
2042
|
+
|
|
2043
|
+
if (JSON.stringify(currentRect) === JSON.stringify(newRect)) {
|
|
2044
|
+
return currentRect;
|
|
2045
|
+
}
|
|
2046
|
+
|
|
2047
|
+
return newRect;
|
|
2048
|
+
});
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
const mutationObserver = useMutationObserver({
|
|
2052
|
+
callback(records) {
|
|
2053
|
+
if (!element) {
|
|
2054
|
+
return;
|
|
2055
|
+
}
|
|
2056
|
+
|
|
2057
|
+
for (const record of records) {
|
|
2058
|
+
const {
|
|
2059
|
+
type,
|
|
2060
|
+
target
|
|
2061
|
+
} = record;
|
|
2062
|
+
|
|
2063
|
+
if (type === 'childList' && target instanceof HTMLElement && target.contains(element)) {
|
|
2064
|
+
measureRect();
|
|
2065
|
+
break;
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
|
|
2070
|
+
});
|
|
2071
|
+
const resizeObserver = useResizeObserver({
|
|
2072
|
+
callback: measureRect
|
|
2073
|
+
});
|
|
2074
|
+
utilities_esm.useIsomorphicLayoutEffect(() => {
|
|
2075
|
+
measureRect();
|
|
2076
|
+
|
|
2077
|
+
if (element) {
|
|
2078
|
+
resizeObserver == null ? void 0 : resizeObserver.observe(element);
|
|
2079
|
+
mutationObserver == null ? void 0 : mutationObserver.observe(document.body, {
|
|
2080
|
+
childList: true,
|
|
2081
|
+
subtree: true
|
|
2082
|
+
});
|
|
2083
|
+
} else {
|
|
2084
|
+
resizeObserver == null ? void 0 : resizeObserver.disconnect();
|
|
2085
|
+
mutationObserver == null ? void 0 : mutationObserver.disconnect();
|
|
2086
|
+
}
|
|
2087
|
+
}, [element]);
|
|
2088
|
+
return rect;
|
|
2089
|
+
}
|
|
2090
|
+
|
|
2091
|
+
function useRectDelta(rect) {
|
|
2092
|
+
const initialRect = useInitialValue(rect);
|
|
2093
|
+
return getRectDelta(rect, initialRect);
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
const defaultValue$1 = [];
|
|
2097
|
+
function useScrollableAncestors(node) {
|
|
2098
|
+
const previousNode = React.useRef(node);
|
|
2099
|
+
const ancestors = utilities_esm.useLazyMemo(previousValue => {
|
|
2100
|
+
if (!node) {
|
|
2101
|
+
return defaultValue$1;
|
|
2102
|
+
}
|
|
2103
|
+
|
|
2104
|
+
if (previousValue && previousValue !== defaultValue$1 && node && previousNode.current && node.parentNode === previousNode.current.parentNode) {
|
|
2105
|
+
return previousValue;
|
|
2106
|
+
}
|
|
2107
|
+
|
|
2108
|
+
return getScrollableAncestors(node);
|
|
2109
|
+
}, [node]);
|
|
2110
|
+
React.useEffect(() => {
|
|
2111
|
+
previousNode.current = node;
|
|
2112
|
+
}, [node]);
|
|
2113
|
+
return ancestors;
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
function useScrollOffsets(elements) {
|
|
2117
|
+
const [scrollCoordinates, setScrollCoordinates] = React.useState(null);
|
|
2118
|
+
const prevElements = React.useRef(elements); // To-do: Throttle the handleScroll callback
|
|
2119
|
+
|
|
2120
|
+
const handleScroll = React.useCallback(event => {
|
|
2121
|
+
const scrollingElement = getScrollableElement(event.target);
|
|
2122
|
+
|
|
2123
|
+
if (!scrollingElement) {
|
|
2124
|
+
return;
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
setScrollCoordinates(scrollCoordinates => {
|
|
2128
|
+
if (!scrollCoordinates) {
|
|
2129
|
+
return null;
|
|
2130
|
+
}
|
|
2131
|
+
|
|
2132
|
+
scrollCoordinates.set(scrollingElement, getScrollCoordinates(scrollingElement));
|
|
2133
|
+
return new Map(scrollCoordinates);
|
|
2134
|
+
});
|
|
2135
|
+
}, []);
|
|
2136
|
+
React.useEffect(() => {
|
|
2137
|
+
const previousElements = prevElements.current;
|
|
2138
|
+
|
|
2139
|
+
if (elements !== previousElements) {
|
|
2140
|
+
cleanup(previousElements);
|
|
2141
|
+
const entries = elements.map(element => {
|
|
2142
|
+
const scrollableElement = getScrollableElement(element);
|
|
2143
|
+
|
|
2144
|
+
if (scrollableElement) {
|
|
2145
|
+
scrollableElement.addEventListener('scroll', handleScroll, {
|
|
2146
|
+
passive: true
|
|
2147
|
+
});
|
|
2148
|
+
return [scrollableElement, getScrollCoordinates(scrollableElement)];
|
|
2149
|
+
}
|
|
2150
|
+
|
|
2151
|
+
return null;
|
|
2152
|
+
}).filter(entry => entry != null);
|
|
2153
|
+
setScrollCoordinates(entries.length ? new Map(entries) : null);
|
|
2154
|
+
prevElements.current = elements;
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
return () => {
|
|
2158
|
+
cleanup(elements);
|
|
2159
|
+
cleanup(previousElements);
|
|
2160
|
+
};
|
|
2161
|
+
|
|
2162
|
+
function cleanup(elements) {
|
|
2163
|
+
elements.forEach(element => {
|
|
2164
|
+
const scrollableElement = getScrollableElement(element);
|
|
2165
|
+
scrollableElement == null ? void 0 : scrollableElement.removeEventListener('scroll', handleScroll);
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2168
|
+
}, [handleScroll, elements]);
|
|
2169
|
+
return React.useMemo(() => {
|
|
2170
|
+
if (elements.length) {
|
|
2171
|
+
return scrollCoordinates ? Array.from(scrollCoordinates.values()).reduce((acc, coordinates) => utilities_esm.add(acc, coordinates), defaultCoordinates) : getScrollOffsets(elements);
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
return defaultCoordinates;
|
|
2175
|
+
}, [elements, scrollCoordinates]);
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
function useScrollOffsetsDelta(scrollOffsets, dependencies) {
|
|
2179
|
+
if (dependencies === void 0) {
|
|
2180
|
+
dependencies = [];
|
|
2181
|
+
}
|
|
2182
|
+
|
|
2183
|
+
const initialScrollOffsets = React.useRef(null);
|
|
2184
|
+
React.useEffect(() => {
|
|
2185
|
+
initialScrollOffsets.current = null;
|
|
2186
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2187
|
+
dependencies);
|
|
2188
|
+
React.useEffect(() => {
|
|
2189
|
+
const hasScrollOffsets = scrollOffsets !== defaultCoordinates;
|
|
2190
|
+
|
|
2191
|
+
if (hasScrollOffsets && !initialScrollOffsets.current) {
|
|
2192
|
+
initialScrollOffsets.current = scrollOffsets;
|
|
2193
|
+
}
|
|
2194
|
+
|
|
2195
|
+
if (!hasScrollOffsets && initialScrollOffsets.current) {
|
|
2196
|
+
initialScrollOffsets.current = null;
|
|
2197
|
+
}
|
|
2198
|
+
}, [scrollOffsets]);
|
|
2199
|
+
return initialScrollOffsets.current ? utilities_esm.subtract(scrollOffsets, initialScrollOffsets.current) : defaultCoordinates;
|
|
2200
|
+
}
|
|
2201
|
+
|
|
2202
|
+
function useSensorSetup(sensors) {
|
|
2203
|
+
React.useEffect(() => {
|
|
2204
|
+
if (!utilities_esm.canUseDOM) {
|
|
2205
|
+
return;
|
|
2206
|
+
}
|
|
2207
|
+
|
|
2208
|
+
const teardownFns = sensors.map(_ref => {
|
|
2209
|
+
let {
|
|
2210
|
+
sensor
|
|
2211
|
+
} = _ref;
|
|
2212
|
+
return sensor.setup == null ? void 0 : sensor.setup();
|
|
2213
|
+
});
|
|
2214
|
+
return () => {
|
|
2215
|
+
for (const teardown of teardownFns) {
|
|
2216
|
+
teardown == null ? void 0 : teardown();
|
|
2217
|
+
}
|
|
2218
|
+
};
|
|
2219
|
+
}, // TO-DO: Sensors length could theoretically change which would not be a valid dependency
|
|
2220
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2221
|
+
sensors.map(_ref2 => {
|
|
2222
|
+
let {
|
|
2223
|
+
sensor
|
|
2224
|
+
} = _ref2;
|
|
2225
|
+
return sensor;
|
|
2226
|
+
}));
|
|
2227
|
+
}
|
|
2228
|
+
|
|
2229
|
+
function useSyntheticListeners(listeners, id) {
|
|
2230
|
+
return React.useMemo(() => {
|
|
2231
|
+
return listeners.reduce((acc, _ref) => {
|
|
2232
|
+
let {
|
|
2233
|
+
eventName,
|
|
2234
|
+
handler
|
|
2235
|
+
} = _ref;
|
|
2236
|
+
|
|
2237
|
+
acc[eventName] = event => {
|
|
2238
|
+
handler(event, id);
|
|
2239
|
+
};
|
|
2240
|
+
|
|
2241
|
+
return acc;
|
|
2242
|
+
}, {});
|
|
2243
|
+
}, [listeners, id]);
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
function useWindowRect(element) {
|
|
2247
|
+
return React.useMemo(() => element ? getWindowClientRect(element) : null, [element]);
|
|
2248
|
+
}
|
|
2249
|
+
|
|
2250
|
+
const defaultValue$2 = [];
|
|
2251
|
+
function useRects(elements, measure) {
|
|
2252
|
+
if (measure === void 0) {
|
|
2253
|
+
measure = getClientRect;
|
|
2254
|
+
}
|
|
2255
|
+
|
|
2256
|
+
const [firstElement] = elements;
|
|
2257
|
+
const windowRect = useWindowRect(firstElement ? utilities_esm.getWindow(firstElement) : null);
|
|
2258
|
+
const [rects, setRects] = React.useState(defaultValue$2);
|
|
2259
|
+
|
|
2260
|
+
function measureRects() {
|
|
2261
|
+
setRects(() => {
|
|
2262
|
+
if (!elements.length) {
|
|
2263
|
+
return defaultValue$2;
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
return elements.map(element => isDocumentScrollingElement(element) ? windowRect : new Rect(measure(element), element));
|
|
2267
|
+
});
|
|
2268
|
+
}
|
|
2269
|
+
|
|
2270
|
+
const resizeObserver = useResizeObserver({
|
|
2271
|
+
callback: measureRects
|
|
2272
|
+
});
|
|
2273
|
+
utilities_esm.useIsomorphicLayoutEffect(() => {
|
|
2274
|
+
resizeObserver == null ? void 0 : resizeObserver.disconnect();
|
|
2275
|
+
measureRects();
|
|
2276
|
+
elements.forEach(element => resizeObserver == null ? void 0 : resizeObserver.observe(element));
|
|
2277
|
+
}, [elements]);
|
|
2278
|
+
return rects;
|
|
2279
|
+
}
|
|
2280
|
+
|
|
2281
|
+
function getMeasurableNode(node) {
|
|
2282
|
+
if (!node) {
|
|
2283
|
+
return null;
|
|
2284
|
+
}
|
|
2285
|
+
|
|
2286
|
+
if (node.children.length > 1) {
|
|
2287
|
+
return node;
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
const firstChild = node.children[0];
|
|
2291
|
+
return utilities_esm.isHTMLElement(firstChild) ? firstChild : node;
|
|
2292
|
+
}
|
|
2293
|
+
|
|
2294
|
+
function useDragOverlayMeasuring(_ref) {
|
|
2295
|
+
let {
|
|
2296
|
+
measure
|
|
2297
|
+
} = _ref;
|
|
2298
|
+
const [rect, setRect] = React.useState(null);
|
|
2299
|
+
const handleResize = React.useCallback(entries => {
|
|
2300
|
+
for (const {
|
|
2301
|
+
target
|
|
2302
|
+
} of entries) {
|
|
2303
|
+
if (utilities_esm.isHTMLElement(target)) {
|
|
2304
|
+
setRect(rect => {
|
|
2305
|
+
const newRect = measure(target);
|
|
2306
|
+
return rect ? { ...rect,
|
|
2307
|
+
width: newRect.width,
|
|
2308
|
+
height: newRect.height
|
|
2309
|
+
} : newRect;
|
|
2310
|
+
});
|
|
2311
|
+
break;
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
}, [measure]);
|
|
2315
|
+
const resizeObserver = useResizeObserver({
|
|
2316
|
+
callback: handleResize
|
|
2317
|
+
});
|
|
2318
|
+
const handleNodeChange = React.useCallback(element => {
|
|
2319
|
+
const node = getMeasurableNode(element);
|
|
2320
|
+
resizeObserver == null ? void 0 : resizeObserver.disconnect();
|
|
2321
|
+
|
|
2322
|
+
if (node) {
|
|
2323
|
+
resizeObserver == null ? void 0 : resizeObserver.observe(node);
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
setRect(node ? measure(node) : null);
|
|
2327
|
+
}, [measure, resizeObserver]);
|
|
2328
|
+
const [nodeRef, setRef] = utilities_esm.useNodeRef(handleNodeChange);
|
|
2329
|
+
return React.useMemo(() => ({
|
|
2330
|
+
nodeRef,
|
|
2331
|
+
rect,
|
|
2332
|
+
setRef
|
|
2333
|
+
}), [rect, nodeRef, setRef]);
|
|
2334
|
+
}
|
|
2335
|
+
|
|
2336
|
+
const defaultSensors = [{
|
|
2337
|
+
sensor: PointerSensor,
|
|
2338
|
+
options: {}
|
|
2339
|
+
}, {
|
|
2340
|
+
sensor: KeyboardSensor,
|
|
2341
|
+
options: {}
|
|
2342
|
+
}];
|
|
2343
|
+
const defaultData = {
|
|
2344
|
+
current: {}
|
|
2345
|
+
};
|
|
2346
|
+
const defaultMeasuringConfiguration = {
|
|
2347
|
+
draggable: {
|
|
2348
|
+
measure: getTransformAgnosticClientRect
|
|
2349
|
+
},
|
|
2350
|
+
droppable: {
|
|
2351
|
+
measure: getTransformAgnosticClientRect,
|
|
2352
|
+
strategy: exports.MeasuringStrategy.WhileDragging,
|
|
2353
|
+
frequency: exports.MeasuringFrequency.Optimized
|
|
2354
|
+
},
|
|
2355
|
+
dragOverlay: {
|
|
2356
|
+
measure: getClientRect
|
|
2357
|
+
}
|
|
2358
|
+
};
|
|
2359
|
+
|
|
2360
|
+
class DroppableContainersMap extends Map {
|
|
2361
|
+
get(id) {
|
|
2362
|
+
var _super$get;
|
|
2363
|
+
|
|
2364
|
+
return id != null ? (_super$get = super.get(id)) != null ? _super$get : undefined : undefined;
|
|
2365
|
+
}
|
|
2366
|
+
|
|
2367
|
+
toArray() {
|
|
2368
|
+
return Array.from(this.values());
|
|
2369
|
+
}
|
|
2370
|
+
|
|
2371
|
+
getEnabled() {
|
|
2372
|
+
return this.toArray().filter(_ref => {
|
|
2373
|
+
let {
|
|
2374
|
+
disabled
|
|
2375
|
+
} = _ref;
|
|
2376
|
+
return !disabled;
|
|
2377
|
+
});
|
|
2378
|
+
}
|
|
2379
|
+
|
|
2380
|
+
getNodeFor(id) {
|
|
2381
|
+
var _this$get$node$curren, _this$get;
|
|
2382
|
+
|
|
2383
|
+
return (_this$get$node$curren = (_this$get = this.get(id)) == null ? void 0 : _this$get.node.current) != null ? _this$get$node$curren : undefined;
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
}
|
|
2387
|
+
|
|
2388
|
+
const defaultPublicContext = {
|
|
2389
|
+
activatorEvent: null,
|
|
2390
|
+
active: null,
|
|
2391
|
+
activeNode: null,
|
|
2392
|
+
activeNodeRect: null,
|
|
2393
|
+
collisions: null,
|
|
2394
|
+
containerNodeRect: null,
|
|
2395
|
+
draggableNodes: /*#__PURE__*/new Map(),
|
|
2396
|
+
droppableRects: /*#__PURE__*/new Map(),
|
|
2397
|
+
droppableContainers: /*#__PURE__*/new DroppableContainersMap(),
|
|
2398
|
+
over: null,
|
|
2399
|
+
dragOverlay: {
|
|
2400
|
+
nodeRef: {
|
|
2401
|
+
current: null
|
|
2402
|
+
},
|
|
2403
|
+
rect: null,
|
|
2404
|
+
setRef: noop
|
|
2405
|
+
},
|
|
2406
|
+
scrollableAncestors: [],
|
|
2407
|
+
scrollableAncestorRects: [],
|
|
2408
|
+
measuringConfiguration: defaultMeasuringConfiguration,
|
|
2409
|
+
measureDroppableContainers: noop,
|
|
2410
|
+
windowRect: null,
|
|
2411
|
+
measuringScheduled: false
|
|
2412
|
+
};
|
|
2413
|
+
const defaultInternalContext = {
|
|
2414
|
+
activatorEvent: null,
|
|
2415
|
+
activators: [],
|
|
2416
|
+
active: null,
|
|
2417
|
+
activeNodeRect: null,
|
|
2418
|
+
ariaDescribedById: {
|
|
2419
|
+
draggable: ''
|
|
2420
|
+
},
|
|
2421
|
+
dispatch: noop,
|
|
2422
|
+
draggableNodes: /*#__PURE__*/new Map(),
|
|
2423
|
+
over: null,
|
|
2424
|
+
measureDroppableContainers: noop
|
|
2425
|
+
};
|
|
2426
|
+
const InternalContext = /*#__PURE__*/React.createContext(defaultInternalContext);
|
|
2427
|
+
const PublicContext = /*#__PURE__*/React.createContext(defaultPublicContext);
|
|
2428
|
+
|
|
2429
|
+
function getInitialState() {
|
|
2430
|
+
return {
|
|
2431
|
+
draggable: {
|
|
2432
|
+
active: null,
|
|
2433
|
+
initialCoordinates: {
|
|
2434
|
+
x: 0,
|
|
2435
|
+
y: 0
|
|
2436
|
+
},
|
|
2437
|
+
nodes: new Map(),
|
|
2438
|
+
translate: {
|
|
2439
|
+
x: 0,
|
|
2440
|
+
y: 0
|
|
2441
|
+
}
|
|
2442
|
+
},
|
|
2443
|
+
droppable: {
|
|
2444
|
+
containers: new DroppableContainersMap()
|
|
2445
|
+
}
|
|
2446
|
+
};
|
|
2447
|
+
}
|
|
2448
|
+
function reducer(state, action) {
|
|
2449
|
+
switch (action.type) {
|
|
2450
|
+
case Action.DragStart:
|
|
2451
|
+
return { ...state,
|
|
2452
|
+
draggable: { ...state.draggable,
|
|
2453
|
+
initialCoordinates: action.initialCoordinates,
|
|
2454
|
+
active: action.active
|
|
2455
|
+
}
|
|
2456
|
+
};
|
|
2457
|
+
|
|
2458
|
+
case Action.DragMove:
|
|
2459
|
+
if (state.draggable.active == null) {
|
|
2460
|
+
return state;
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
return { ...state,
|
|
2464
|
+
draggable: { ...state.draggable,
|
|
2465
|
+
translate: {
|
|
2466
|
+
x: action.coordinates.x - state.draggable.initialCoordinates.x,
|
|
2467
|
+
y: action.coordinates.y - state.draggable.initialCoordinates.y
|
|
2468
|
+
}
|
|
2469
|
+
}
|
|
2470
|
+
};
|
|
2471
|
+
|
|
2472
|
+
case Action.DragEnd:
|
|
2473
|
+
case Action.DragCancel:
|
|
2474
|
+
return { ...state,
|
|
2475
|
+
draggable: { ...state.draggable,
|
|
2476
|
+
active: null,
|
|
2477
|
+
initialCoordinates: {
|
|
2478
|
+
x: 0,
|
|
2479
|
+
y: 0
|
|
2480
|
+
},
|
|
2481
|
+
translate: {
|
|
2482
|
+
x: 0,
|
|
2483
|
+
y: 0
|
|
2484
|
+
}
|
|
2485
|
+
}
|
|
2486
|
+
};
|
|
2487
|
+
|
|
2488
|
+
case Action.RegisterDroppable:
|
|
2489
|
+
{
|
|
2490
|
+
const {
|
|
2491
|
+
element
|
|
2492
|
+
} = action;
|
|
2493
|
+
const {
|
|
2494
|
+
id
|
|
2495
|
+
} = element;
|
|
2496
|
+
const containers = new DroppableContainersMap(state.droppable.containers);
|
|
2497
|
+
containers.set(id, element);
|
|
2498
|
+
return { ...state,
|
|
2499
|
+
droppable: { ...state.droppable,
|
|
2500
|
+
containers
|
|
2501
|
+
}
|
|
2502
|
+
};
|
|
2503
|
+
}
|
|
2504
|
+
|
|
2505
|
+
case Action.SetDroppableDisabled:
|
|
2506
|
+
{
|
|
2507
|
+
const {
|
|
2508
|
+
id,
|
|
2509
|
+
key,
|
|
2510
|
+
disabled
|
|
2511
|
+
} = action;
|
|
2512
|
+
const element = state.droppable.containers.get(id);
|
|
2513
|
+
|
|
2514
|
+
if (!element || key !== element.key) {
|
|
2515
|
+
return state;
|
|
2516
|
+
}
|
|
2517
|
+
|
|
2518
|
+
const containers = new DroppableContainersMap(state.droppable.containers);
|
|
2519
|
+
containers.set(id, { ...element,
|
|
2520
|
+
disabled
|
|
2521
|
+
});
|
|
2522
|
+
return { ...state,
|
|
2523
|
+
droppable: { ...state.droppable,
|
|
2524
|
+
containers
|
|
2525
|
+
}
|
|
2526
|
+
};
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
case Action.UnregisterDroppable:
|
|
2530
|
+
{
|
|
2531
|
+
const {
|
|
2532
|
+
id,
|
|
2533
|
+
key
|
|
2534
|
+
} = action;
|
|
2535
|
+
const element = state.droppable.containers.get(id);
|
|
2536
|
+
|
|
2537
|
+
if (!element || key !== element.key) {
|
|
2538
|
+
return state;
|
|
2539
|
+
}
|
|
2540
|
+
|
|
2541
|
+
const containers = new DroppableContainersMap(state.droppable.containers);
|
|
2542
|
+
containers.delete(id);
|
|
2543
|
+
return { ...state,
|
|
2544
|
+
droppable: { ...state.droppable,
|
|
2545
|
+
containers
|
|
2546
|
+
}
|
|
2547
|
+
};
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
default:
|
|
2551
|
+
{
|
|
2552
|
+
return state;
|
|
2553
|
+
}
|
|
2554
|
+
}
|
|
2555
|
+
}
|
|
2556
|
+
|
|
2557
|
+
function RestoreFocus(_ref) {
|
|
2558
|
+
let {
|
|
2559
|
+
disabled
|
|
2560
|
+
} = _ref;
|
|
2561
|
+
const {
|
|
2562
|
+
active,
|
|
2563
|
+
activatorEvent,
|
|
2564
|
+
draggableNodes
|
|
2565
|
+
} = React.useContext(InternalContext);
|
|
2566
|
+
const previousActivatorEvent = utilities_esm.usePrevious(activatorEvent);
|
|
2567
|
+
const previousActiveId = utilities_esm.usePrevious(active == null ? void 0 : active.id); // Restore keyboard focus on the activator node
|
|
2568
|
+
|
|
2569
|
+
React.useEffect(() => {
|
|
2570
|
+
if (disabled) {
|
|
2571
|
+
return;
|
|
2572
|
+
}
|
|
2573
|
+
|
|
2574
|
+
if (!activatorEvent && previousActivatorEvent && previousActiveId != null) {
|
|
2575
|
+
if (!utilities_esm.isKeyboardEvent(previousActivatorEvent)) {
|
|
2576
|
+
return;
|
|
2577
|
+
}
|
|
2578
|
+
|
|
2579
|
+
if (document.activeElement === previousActivatorEvent.target) {
|
|
2580
|
+
// No need to restore focus
|
|
2581
|
+
return;
|
|
2582
|
+
}
|
|
2583
|
+
|
|
2584
|
+
const draggableNode = draggableNodes.get(previousActiveId);
|
|
2585
|
+
|
|
2586
|
+
if (!draggableNode) {
|
|
2587
|
+
return;
|
|
2588
|
+
}
|
|
2589
|
+
|
|
2590
|
+
const {
|
|
2591
|
+
activatorNode,
|
|
2592
|
+
node
|
|
2593
|
+
} = draggableNode;
|
|
2594
|
+
|
|
2595
|
+
if (!activatorNode.current && !node.current) {
|
|
2596
|
+
return;
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
requestAnimationFrame(() => {
|
|
2600
|
+
for (const element of [activatorNode.current, node.current]) {
|
|
2601
|
+
if (!element) {
|
|
2602
|
+
continue;
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2605
|
+
const focusableNode = utilities_esm.findFirstFocusableNode(element);
|
|
2606
|
+
|
|
2607
|
+
if (focusableNode) {
|
|
2608
|
+
focusableNode.focus();
|
|
2609
|
+
break;
|
|
2610
|
+
}
|
|
2611
|
+
}
|
|
2612
|
+
});
|
|
2613
|
+
}
|
|
2614
|
+
}, [activatorEvent, disabled, draggableNodes, previousActiveId, previousActivatorEvent]);
|
|
2615
|
+
return null;
|
|
2616
|
+
}
|
|
2617
|
+
|
|
2618
|
+
function applyModifiers(modifiers, _ref) {
|
|
2619
|
+
let {
|
|
2620
|
+
transform,
|
|
2621
|
+
...args
|
|
2622
|
+
} = _ref;
|
|
2623
|
+
return modifiers != null && modifiers.length ? modifiers.reduce((accumulator, modifier) => {
|
|
2624
|
+
return modifier({
|
|
2625
|
+
transform: accumulator,
|
|
2626
|
+
...args
|
|
2627
|
+
});
|
|
2628
|
+
}, transform) : transform;
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2631
|
+
function useMeasuringConfiguration(config) {
|
|
2632
|
+
return React.useMemo(() => ({
|
|
2633
|
+
draggable: { ...defaultMeasuringConfiguration.draggable,
|
|
2634
|
+
...(config == null ? void 0 : config.draggable)
|
|
2635
|
+
},
|
|
2636
|
+
droppable: { ...defaultMeasuringConfiguration.droppable,
|
|
2637
|
+
...(config == null ? void 0 : config.droppable)
|
|
2638
|
+
},
|
|
2639
|
+
dragOverlay: { ...defaultMeasuringConfiguration.dragOverlay,
|
|
2640
|
+
...(config == null ? void 0 : config.dragOverlay)
|
|
2641
|
+
}
|
|
2642
|
+
}), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2643
|
+
[config == null ? void 0 : config.draggable, config == null ? void 0 : config.droppable, config == null ? void 0 : config.dragOverlay]);
|
|
2644
|
+
}
|
|
2645
|
+
|
|
2646
|
+
function useLayoutShiftScrollCompensation(_ref) {
|
|
2647
|
+
let {
|
|
2648
|
+
activeNode,
|
|
2649
|
+
measure,
|
|
2650
|
+
initialRect,
|
|
2651
|
+
config = true
|
|
2652
|
+
} = _ref;
|
|
2653
|
+
const initialized = React.useRef(false);
|
|
2654
|
+
const {
|
|
2655
|
+
x,
|
|
2656
|
+
y
|
|
2657
|
+
} = typeof config === 'boolean' ? {
|
|
2658
|
+
x: config,
|
|
2659
|
+
y: config
|
|
2660
|
+
} : config;
|
|
2661
|
+
utilities_esm.useIsomorphicLayoutEffect(() => {
|
|
2662
|
+
const disabled = !x && !y;
|
|
2663
|
+
|
|
2664
|
+
if (disabled || !activeNode) {
|
|
2665
|
+
initialized.current = false;
|
|
2666
|
+
return;
|
|
2667
|
+
}
|
|
2668
|
+
|
|
2669
|
+
if (initialized.current || !initialRect) {
|
|
2670
|
+
// Return early if layout shift scroll compensation was already attempted
|
|
2671
|
+
// or if there is no initialRect to compare to.
|
|
2672
|
+
return;
|
|
2673
|
+
} // Get the most up to date node ref for the active draggable
|
|
2674
|
+
|
|
2675
|
+
|
|
2676
|
+
const node = activeNode == null ? void 0 : activeNode.node.current;
|
|
2677
|
+
|
|
2678
|
+
if (!node || node.isConnected === false) {
|
|
2679
|
+
// Return early if there is no attached node ref or if the node is
|
|
2680
|
+
// disconnected from the document.
|
|
2681
|
+
return;
|
|
2682
|
+
}
|
|
2683
|
+
|
|
2684
|
+
const rect = measure(node);
|
|
2685
|
+
const rectDelta = getRectDelta(rect, initialRect);
|
|
2686
|
+
|
|
2687
|
+
if (!x) {
|
|
2688
|
+
rectDelta.x = 0;
|
|
2689
|
+
}
|
|
2690
|
+
|
|
2691
|
+
if (!y) {
|
|
2692
|
+
rectDelta.y = 0;
|
|
2693
|
+
} // Only perform layout shift scroll compensation once
|
|
2694
|
+
|
|
2695
|
+
|
|
2696
|
+
initialized.current = true;
|
|
2697
|
+
|
|
2698
|
+
if (Math.abs(rectDelta.x) > 0 || Math.abs(rectDelta.y) > 0) {
|
|
2699
|
+
const firstScrollableAncestor = getFirstScrollableAncestor(node);
|
|
2700
|
+
|
|
2701
|
+
if (firstScrollableAncestor) {
|
|
2702
|
+
firstScrollableAncestor.scrollBy({
|
|
2703
|
+
top: rectDelta.y,
|
|
2704
|
+
left: rectDelta.x
|
|
2705
|
+
});
|
|
2706
|
+
}
|
|
2707
|
+
}
|
|
2708
|
+
}, [activeNode, x, y, initialRect, measure]);
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
const ActiveDraggableContext = /*#__PURE__*/React.createContext({ ...defaultCoordinates,
|
|
2712
|
+
scaleX: 1,
|
|
2713
|
+
scaleY: 1
|
|
2714
|
+
});
|
|
2715
|
+
var Status;
|
|
2716
|
+
|
|
2717
|
+
(function (Status) {
|
|
2718
|
+
Status[Status["Uninitialized"] = 0] = "Uninitialized";
|
|
2719
|
+
Status[Status["Initializing"] = 1] = "Initializing";
|
|
2720
|
+
Status[Status["Initialized"] = 2] = "Initialized";
|
|
2721
|
+
})(Status || (Status = {}));
|
|
2722
|
+
|
|
2723
|
+
const DndContext = /*#__PURE__*/React.memo(function DndContext(_ref) {
|
|
2724
|
+
var _sensorContext$curren, _dragOverlay$nodeRef$, _dragOverlay$rect, _over$rect;
|
|
2725
|
+
|
|
2726
|
+
let {
|
|
2727
|
+
id,
|
|
2728
|
+
accessibility,
|
|
2729
|
+
autoScroll = true,
|
|
2730
|
+
children,
|
|
2731
|
+
sensors = defaultSensors,
|
|
2732
|
+
collisionDetection = rectIntersection,
|
|
2733
|
+
measuring,
|
|
2734
|
+
modifiers,
|
|
2735
|
+
...props
|
|
2736
|
+
} = _ref;
|
|
2737
|
+
const store = React.useReducer(reducer, undefined, getInitialState);
|
|
2738
|
+
const [state, dispatch] = store;
|
|
2739
|
+
const [dispatchMonitorEvent, registerMonitorListener] = useDndMonitorProvider();
|
|
2740
|
+
const [status, setStatus] = React.useState(Status.Uninitialized);
|
|
2741
|
+
const isInitialized = status === Status.Initialized;
|
|
2742
|
+
const {
|
|
2743
|
+
draggable: {
|
|
2744
|
+
active: activeId,
|
|
2745
|
+
nodes: draggableNodes,
|
|
2746
|
+
translate
|
|
2747
|
+
},
|
|
2748
|
+
droppable: {
|
|
2749
|
+
containers: droppableContainers
|
|
2750
|
+
}
|
|
2751
|
+
} = state;
|
|
2752
|
+
const node = activeId != null ? draggableNodes.get(activeId) : null;
|
|
2753
|
+
const activeRects = React.useRef({
|
|
2754
|
+
initial: null,
|
|
2755
|
+
translated: null
|
|
2756
|
+
});
|
|
2757
|
+
const active = React.useMemo(() => {
|
|
2758
|
+
var _node$data;
|
|
2759
|
+
|
|
2760
|
+
return activeId != null ? {
|
|
2761
|
+
id: activeId,
|
|
2762
|
+
// It's possible for the active node to unmount while dragging
|
|
2763
|
+
data: (_node$data = node == null ? void 0 : node.data) != null ? _node$data : defaultData,
|
|
2764
|
+
rect: activeRects
|
|
2765
|
+
} : null;
|
|
2766
|
+
}, [activeId, node]);
|
|
2767
|
+
const activeRef = React.useRef(null);
|
|
2768
|
+
const [activeSensor, setActiveSensor] = React.useState(null);
|
|
2769
|
+
const [activatorEvent, setActivatorEvent] = React.useState(null);
|
|
2770
|
+
const latestProps = utilities_esm.useLatestValue(props, Object.values(props));
|
|
2771
|
+
const draggableDescribedById = utilities_esm.useUniqueId("DndDescribedBy", id);
|
|
2772
|
+
const enabledDroppableContainers = React.useMemo(() => droppableContainers.getEnabled(), [droppableContainers]);
|
|
2773
|
+
const measuringConfiguration = useMeasuringConfiguration(measuring);
|
|
2774
|
+
const {
|
|
2775
|
+
droppableRects,
|
|
2776
|
+
measureDroppableContainers,
|
|
2777
|
+
measuringScheduled
|
|
2778
|
+
} = useDroppableMeasuring(enabledDroppableContainers, {
|
|
2779
|
+
dragging: isInitialized,
|
|
2780
|
+
dependencies: [translate.x, translate.y],
|
|
2781
|
+
config: measuringConfiguration.droppable
|
|
2782
|
+
});
|
|
2783
|
+
const activeNode = useCachedNode(draggableNodes, activeId);
|
|
2784
|
+
const activationCoordinates = React.useMemo(() => activatorEvent ? utilities_esm.getEventCoordinates(activatorEvent) : null, [activatorEvent]);
|
|
2785
|
+
const autoScrollOptions = getAutoScrollerOptions();
|
|
2786
|
+
const initialActiveNodeRect = useInitialRect(activeNode, measuringConfiguration.draggable.measure);
|
|
2787
|
+
useLayoutShiftScrollCompensation({
|
|
2788
|
+
activeNode: activeId != null ? draggableNodes.get(activeId) : null,
|
|
2789
|
+
config: autoScrollOptions.layoutShiftCompensation,
|
|
2790
|
+
initialRect: initialActiveNodeRect,
|
|
2791
|
+
measure: measuringConfiguration.draggable.measure
|
|
2792
|
+
});
|
|
2793
|
+
const activeNodeRect = useRect(activeNode, measuringConfiguration.draggable.measure, initialActiveNodeRect);
|
|
2794
|
+
const containerNodeRect = useRect(activeNode ? activeNode.parentElement : null);
|
|
2795
|
+
const sensorContext = React.useRef({
|
|
2796
|
+
activatorEvent: null,
|
|
2797
|
+
active: null,
|
|
2798
|
+
activeNode,
|
|
2799
|
+
collisionRect: null,
|
|
2800
|
+
collisions: null,
|
|
2801
|
+
droppableRects,
|
|
2802
|
+
draggableNodes,
|
|
2803
|
+
draggingNode: null,
|
|
2804
|
+
draggingNodeRect: null,
|
|
2805
|
+
droppableContainers,
|
|
2806
|
+
over: null,
|
|
2807
|
+
scrollableAncestors: [],
|
|
2808
|
+
scrollAdjustedTranslate: null
|
|
2809
|
+
});
|
|
2810
|
+
const overNode = droppableContainers.getNodeFor((_sensorContext$curren = sensorContext.current.over) == null ? void 0 : _sensorContext$curren.id);
|
|
2811
|
+
const dragOverlay = useDragOverlayMeasuring({
|
|
2812
|
+
measure: measuringConfiguration.dragOverlay.measure
|
|
2813
|
+
}); // Use the rect of the drag overlay if it is mounted
|
|
2814
|
+
|
|
2815
|
+
const draggingNode = (_dragOverlay$nodeRef$ = dragOverlay.nodeRef.current) != null ? _dragOverlay$nodeRef$ : activeNode;
|
|
2816
|
+
const draggingNodeRect = isInitialized ? (_dragOverlay$rect = dragOverlay.rect) != null ? _dragOverlay$rect : activeNodeRect : null;
|
|
2817
|
+
const usesDragOverlay = Boolean(dragOverlay.nodeRef.current && dragOverlay.rect); // The delta between the previous and new position of the draggable node
|
|
2818
|
+
// is only relevant when there is no drag overlay
|
|
2819
|
+
|
|
2820
|
+
const nodeRectDelta = useRectDelta(usesDragOverlay ? null : activeNodeRect); // Get the window rect of the dragging node
|
|
2821
|
+
|
|
2822
|
+
const windowRect = useWindowRect(draggingNode ? utilities_esm.getWindow(draggingNode) : null); // Get scrollable ancestors of the dragging node
|
|
2823
|
+
|
|
2824
|
+
const scrollableAncestors = useScrollableAncestors(isInitialized ? overNode != null ? overNode : activeNode : null);
|
|
2825
|
+
const scrollableAncestorRects = useRects(scrollableAncestors); // Apply modifiers
|
|
2826
|
+
|
|
2827
|
+
const modifiedTranslate = applyModifiers(modifiers, {
|
|
2828
|
+
transform: {
|
|
2829
|
+
x: translate.x - nodeRectDelta.x,
|
|
2830
|
+
y: translate.y - nodeRectDelta.y,
|
|
2831
|
+
scaleX: 1,
|
|
2832
|
+
scaleY: 1
|
|
2833
|
+
},
|
|
2834
|
+
activatorEvent,
|
|
2835
|
+
active,
|
|
2836
|
+
activeNodeRect,
|
|
2837
|
+
containerNodeRect,
|
|
2838
|
+
draggingNodeRect,
|
|
2839
|
+
over: sensorContext.current.over,
|
|
2840
|
+
overlayNodeRect: dragOverlay.rect,
|
|
2841
|
+
scrollableAncestors,
|
|
2842
|
+
scrollableAncestorRects,
|
|
2843
|
+
windowRect
|
|
2844
|
+
});
|
|
2845
|
+
const pointerCoordinates = activationCoordinates ? utilities_esm.add(activationCoordinates, translate) : null;
|
|
2846
|
+
const scrollOffsets = useScrollOffsets(scrollableAncestors); // Represents the scroll delta since dragging was initiated
|
|
2847
|
+
|
|
2848
|
+
const scrollAdjustment = useScrollOffsetsDelta(scrollOffsets); // Represents the scroll delta since the last time the active node rect was measured
|
|
2849
|
+
|
|
2850
|
+
const activeNodeScrollDelta = useScrollOffsetsDelta(scrollOffsets, [activeNodeRect]);
|
|
2851
|
+
const scrollAdjustedTranslate = utilities_esm.add(modifiedTranslate, scrollAdjustment);
|
|
2852
|
+
const collisionRect = draggingNodeRect ? getAdjustedRect(draggingNodeRect, modifiedTranslate) : null;
|
|
2853
|
+
const collisions = active && collisionRect ? collisionDetection({
|
|
2854
|
+
active,
|
|
2855
|
+
collisionRect,
|
|
2856
|
+
droppableRects,
|
|
2857
|
+
droppableContainers: enabledDroppableContainers,
|
|
2858
|
+
pointerCoordinates
|
|
2859
|
+
}) : null;
|
|
2860
|
+
const overId = getFirstCollision(collisions, 'id');
|
|
2861
|
+
const [over, setOver] = React.useState(null); // When there is no drag overlay used, we need to account for the
|
|
2862
|
+
// window scroll delta
|
|
2863
|
+
|
|
2864
|
+
const appliedTranslate = usesDragOverlay ? modifiedTranslate : utilities_esm.add(modifiedTranslate, activeNodeScrollDelta);
|
|
2865
|
+
const transform = adjustScale(appliedTranslate, (_over$rect = over == null ? void 0 : over.rect) != null ? _over$rect : null, activeNodeRect);
|
|
2866
|
+
const activeSensorRef = React.useRef(null);
|
|
2867
|
+
const instantiateSensor = React.useCallback((event, _ref2) => {
|
|
2868
|
+
let {
|
|
2869
|
+
sensor: Sensor,
|
|
2870
|
+
options
|
|
2871
|
+
} = _ref2;
|
|
2872
|
+
|
|
2873
|
+
if (activeRef.current == null) {
|
|
2874
|
+
return;
|
|
2875
|
+
}
|
|
2876
|
+
|
|
2877
|
+
const activeNode = draggableNodes.get(activeRef.current);
|
|
2878
|
+
|
|
2879
|
+
if (!activeNode) {
|
|
2880
|
+
return;
|
|
2881
|
+
}
|
|
2882
|
+
|
|
2883
|
+
const activatorEvent = event.nativeEvent;
|
|
2884
|
+
const sensorInstance = new Sensor({
|
|
2885
|
+
active: activeRef.current,
|
|
2886
|
+
activeNode,
|
|
2887
|
+
event: activatorEvent,
|
|
2888
|
+
options,
|
|
2889
|
+
// Sensors need to be instantiated with refs for arguments that change over time
|
|
2890
|
+
// otherwise they are frozen in time with the stale arguments
|
|
2891
|
+
context: sensorContext,
|
|
2892
|
+
|
|
2893
|
+
onAbort(id) {
|
|
2894
|
+
const draggableNode = draggableNodes.get(id);
|
|
2895
|
+
|
|
2896
|
+
if (!draggableNode) {
|
|
2897
|
+
return;
|
|
2898
|
+
}
|
|
2899
|
+
|
|
2900
|
+
const {
|
|
2901
|
+
onDragAbort
|
|
2902
|
+
} = latestProps.current;
|
|
2903
|
+
const event = {
|
|
2904
|
+
id
|
|
2905
|
+
};
|
|
2906
|
+
onDragAbort == null ? void 0 : onDragAbort(event);
|
|
2907
|
+
dispatchMonitorEvent({
|
|
2908
|
+
type: 'onDragAbort',
|
|
2909
|
+
event
|
|
2910
|
+
});
|
|
2911
|
+
},
|
|
2912
|
+
|
|
2913
|
+
onPending(id, constraint, initialCoordinates, offset) {
|
|
2914
|
+
const draggableNode = draggableNodes.get(id);
|
|
2915
|
+
|
|
2916
|
+
if (!draggableNode) {
|
|
2917
|
+
return;
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
const {
|
|
2921
|
+
onDragPending
|
|
2922
|
+
} = latestProps.current;
|
|
2923
|
+
const event = {
|
|
2924
|
+
id,
|
|
2925
|
+
constraint,
|
|
2926
|
+
initialCoordinates,
|
|
2927
|
+
offset
|
|
2928
|
+
};
|
|
2929
|
+
onDragPending == null ? void 0 : onDragPending(event);
|
|
2930
|
+
dispatchMonitorEvent({
|
|
2931
|
+
type: 'onDragPending',
|
|
2932
|
+
event
|
|
2933
|
+
});
|
|
2934
|
+
},
|
|
2935
|
+
|
|
2936
|
+
onStart(initialCoordinates) {
|
|
2937
|
+
const id = activeRef.current;
|
|
2938
|
+
|
|
2939
|
+
if (id == null) {
|
|
2940
|
+
return;
|
|
2941
|
+
}
|
|
2942
|
+
|
|
2943
|
+
const draggableNode = draggableNodes.get(id);
|
|
2944
|
+
|
|
2945
|
+
if (!draggableNode) {
|
|
2946
|
+
return;
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
const {
|
|
2950
|
+
onDragStart
|
|
2951
|
+
} = latestProps.current;
|
|
2952
|
+
const event = {
|
|
2953
|
+
activatorEvent,
|
|
2954
|
+
active: {
|
|
2955
|
+
id,
|
|
2956
|
+
data: draggableNode.data,
|
|
2957
|
+
rect: activeRects
|
|
2958
|
+
}
|
|
2959
|
+
};
|
|
2960
|
+
ReactDOM.unstable_batchedUpdates(() => {
|
|
2961
|
+
onDragStart == null ? void 0 : onDragStart(event);
|
|
2962
|
+
setStatus(Status.Initializing);
|
|
2963
|
+
dispatch({
|
|
2964
|
+
type: Action.DragStart,
|
|
2965
|
+
initialCoordinates,
|
|
2966
|
+
active: id
|
|
2967
|
+
});
|
|
2968
|
+
dispatchMonitorEvent({
|
|
2969
|
+
type: 'onDragStart',
|
|
2970
|
+
event
|
|
2971
|
+
});
|
|
2972
|
+
setActiveSensor(activeSensorRef.current);
|
|
2973
|
+
setActivatorEvent(activatorEvent);
|
|
2974
|
+
});
|
|
2975
|
+
},
|
|
2976
|
+
|
|
2977
|
+
onMove(coordinates) {
|
|
2978
|
+
dispatch({
|
|
2979
|
+
type: Action.DragMove,
|
|
2980
|
+
coordinates
|
|
2981
|
+
});
|
|
2982
|
+
},
|
|
2983
|
+
|
|
2984
|
+
onEnd: createHandler(Action.DragEnd),
|
|
2985
|
+
onCancel: createHandler(Action.DragCancel)
|
|
2986
|
+
});
|
|
2987
|
+
activeSensorRef.current = sensorInstance;
|
|
2988
|
+
|
|
2989
|
+
function createHandler(type) {
|
|
2990
|
+
return async function handler() {
|
|
2991
|
+
const {
|
|
2992
|
+
active,
|
|
2993
|
+
collisions,
|
|
2994
|
+
over,
|
|
2995
|
+
scrollAdjustedTranslate
|
|
2996
|
+
} = sensorContext.current;
|
|
2997
|
+
let event = null;
|
|
2998
|
+
|
|
2999
|
+
if (active && scrollAdjustedTranslate) {
|
|
3000
|
+
const {
|
|
3001
|
+
cancelDrop
|
|
3002
|
+
} = latestProps.current;
|
|
3003
|
+
event = {
|
|
3004
|
+
activatorEvent,
|
|
3005
|
+
active: active,
|
|
3006
|
+
collisions,
|
|
3007
|
+
delta: scrollAdjustedTranslate,
|
|
3008
|
+
over
|
|
3009
|
+
};
|
|
3010
|
+
|
|
3011
|
+
if (type === Action.DragEnd && typeof cancelDrop === 'function') {
|
|
3012
|
+
const shouldCancel = await Promise.resolve(cancelDrop(event));
|
|
3013
|
+
|
|
3014
|
+
if (shouldCancel) {
|
|
3015
|
+
type = Action.DragCancel;
|
|
3016
|
+
}
|
|
3017
|
+
}
|
|
3018
|
+
}
|
|
3019
|
+
|
|
3020
|
+
activeRef.current = null;
|
|
3021
|
+
ReactDOM.unstable_batchedUpdates(() => {
|
|
3022
|
+
dispatch({
|
|
3023
|
+
type
|
|
3024
|
+
});
|
|
3025
|
+
setStatus(Status.Uninitialized);
|
|
3026
|
+
setOver(null);
|
|
3027
|
+
setActiveSensor(null);
|
|
3028
|
+
setActivatorEvent(null);
|
|
3029
|
+
activeSensorRef.current = null;
|
|
3030
|
+
const eventName = type === Action.DragEnd ? 'onDragEnd' : 'onDragCancel';
|
|
3031
|
+
|
|
3032
|
+
if (event) {
|
|
3033
|
+
const handler = latestProps.current[eventName];
|
|
3034
|
+
handler == null ? void 0 : handler(event);
|
|
3035
|
+
dispatchMonitorEvent({
|
|
3036
|
+
type: eventName,
|
|
3037
|
+
event
|
|
3038
|
+
});
|
|
3039
|
+
}
|
|
3040
|
+
});
|
|
3041
|
+
};
|
|
3042
|
+
}
|
|
3043
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3044
|
+
[draggableNodes]);
|
|
3045
|
+
const bindActivatorToSensorInstantiator = React.useCallback((handler, sensor) => {
|
|
3046
|
+
return (event, active) => {
|
|
3047
|
+
const nativeEvent = event.nativeEvent;
|
|
3048
|
+
const activeDraggableNode = draggableNodes.get(active);
|
|
3049
|
+
|
|
3050
|
+
if ( // Another sensor is already instantiating
|
|
3051
|
+
activeRef.current !== null || // No active draggable
|
|
3052
|
+
!activeDraggableNode || // Event has already been captured
|
|
3053
|
+
nativeEvent.dndKit || nativeEvent.defaultPrevented) {
|
|
3054
|
+
return;
|
|
3055
|
+
}
|
|
3056
|
+
|
|
3057
|
+
const activationContext = {
|
|
3058
|
+
active: activeDraggableNode
|
|
3059
|
+
};
|
|
3060
|
+
const shouldActivate = handler(event, sensor.options, activationContext);
|
|
3061
|
+
|
|
3062
|
+
if (shouldActivate === true) {
|
|
3063
|
+
nativeEvent.dndKit = {
|
|
3064
|
+
capturedBy: sensor.sensor
|
|
3065
|
+
};
|
|
3066
|
+
activeRef.current = active;
|
|
3067
|
+
instantiateSensor(event, sensor);
|
|
3068
|
+
}
|
|
3069
|
+
};
|
|
3070
|
+
}, [draggableNodes, instantiateSensor]);
|
|
3071
|
+
const activators = useCombineActivators(sensors, bindActivatorToSensorInstantiator);
|
|
3072
|
+
useSensorSetup(sensors);
|
|
3073
|
+
utilities_esm.useIsomorphicLayoutEffect(() => {
|
|
3074
|
+
if (activeNodeRect && status === Status.Initializing) {
|
|
3075
|
+
setStatus(Status.Initialized);
|
|
3076
|
+
}
|
|
3077
|
+
}, [activeNodeRect, status]);
|
|
3078
|
+
React.useEffect(() => {
|
|
3079
|
+
const {
|
|
3080
|
+
onDragMove
|
|
3081
|
+
} = latestProps.current;
|
|
3082
|
+
const {
|
|
3083
|
+
active,
|
|
3084
|
+
activatorEvent,
|
|
3085
|
+
collisions,
|
|
3086
|
+
over
|
|
3087
|
+
} = sensorContext.current;
|
|
3088
|
+
|
|
3089
|
+
if (!active || !activatorEvent) {
|
|
3090
|
+
return;
|
|
3091
|
+
}
|
|
3092
|
+
|
|
3093
|
+
const event = {
|
|
3094
|
+
active,
|
|
3095
|
+
activatorEvent,
|
|
3096
|
+
collisions,
|
|
3097
|
+
delta: {
|
|
3098
|
+
x: scrollAdjustedTranslate.x,
|
|
3099
|
+
y: scrollAdjustedTranslate.y
|
|
3100
|
+
},
|
|
3101
|
+
over
|
|
3102
|
+
};
|
|
3103
|
+
ReactDOM.unstable_batchedUpdates(() => {
|
|
3104
|
+
onDragMove == null ? void 0 : onDragMove(event);
|
|
3105
|
+
dispatchMonitorEvent({
|
|
3106
|
+
type: 'onDragMove',
|
|
3107
|
+
event
|
|
3108
|
+
});
|
|
3109
|
+
});
|
|
3110
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3111
|
+
[scrollAdjustedTranslate.x, scrollAdjustedTranslate.y]);
|
|
3112
|
+
React.useEffect(() => {
|
|
3113
|
+
const {
|
|
3114
|
+
active,
|
|
3115
|
+
activatorEvent,
|
|
3116
|
+
collisions,
|
|
3117
|
+
droppableContainers,
|
|
3118
|
+
scrollAdjustedTranslate
|
|
3119
|
+
} = sensorContext.current;
|
|
3120
|
+
|
|
3121
|
+
if (!active || activeRef.current == null || !activatorEvent || !scrollAdjustedTranslate) {
|
|
3122
|
+
return;
|
|
3123
|
+
}
|
|
3124
|
+
|
|
3125
|
+
const {
|
|
3126
|
+
onDragOver
|
|
3127
|
+
} = latestProps.current;
|
|
3128
|
+
const overContainer = droppableContainers.get(overId);
|
|
3129
|
+
const over = overContainer && overContainer.rect.current ? {
|
|
3130
|
+
id: overContainer.id,
|
|
3131
|
+
rect: overContainer.rect.current,
|
|
3132
|
+
data: overContainer.data,
|
|
3133
|
+
disabled: overContainer.disabled
|
|
3134
|
+
} : null;
|
|
3135
|
+
const event = {
|
|
3136
|
+
active,
|
|
3137
|
+
activatorEvent,
|
|
3138
|
+
collisions,
|
|
3139
|
+
delta: {
|
|
3140
|
+
x: scrollAdjustedTranslate.x,
|
|
3141
|
+
y: scrollAdjustedTranslate.y
|
|
3142
|
+
},
|
|
3143
|
+
over
|
|
3144
|
+
};
|
|
3145
|
+
ReactDOM.unstable_batchedUpdates(() => {
|
|
3146
|
+
setOver(over);
|
|
3147
|
+
onDragOver == null ? void 0 : onDragOver(event);
|
|
3148
|
+
dispatchMonitorEvent({
|
|
3149
|
+
type: 'onDragOver',
|
|
3150
|
+
event
|
|
3151
|
+
});
|
|
3152
|
+
});
|
|
3153
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3154
|
+
[overId]);
|
|
3155
|
+
utilities_esm.useIsomorphicLayoutEffect(() => {
|
|
3156
|
+
sensorContext.current = {
|
|
3157
|
+
activatorEvent,
|
|
3158
|
+
active,
|
|
3159
|
+
activeNode,
|
|
3160
|
+
collisionRect,
|
|
3161
|
+
collisions,
|
|
3162
|
+
droppableRects,
|
|
3163
|
+
draggableNodes,
|
|
3164
|
+
draggingNode,
|
|
3165
|
+
draggingNodeRect,
|
|
3166
|
+
droppableContainers,
|
|
3167
|
+
over,
|
|
3168
|
+
scrollableAncestors,
|
|
3169
|
+
scrollAdjustedTranslate
|
|
3170
|
+
};
|
|
3171
|
+
activeRects.current = {
|
|
3172
|
+
initial: draggingNodeRect,
|
|
3173
|
+
translated: collisionRect
|
|
3174
|
+
};
|
|
3175
|
+
}, [active, activeNode, collisions, collisionRect, draggableNodes, draggingNode, draggingNodeRect, droppableRects, droppableContainers, over, scrollableAncestors, scrollAdjustedTranslate]);
|
|
3176
|
+
useAutoScroller({ ...autoScrollOptions,
|
|
3177
|
+
delta: translate,
|
|
3178
|
+
draggingRect: collisionRect,
|
|
3179
|
+
pointerCoordinates,
|
|
3180
|
+
scrollableAncestors,
|
|
3181
|
+
scrollableAncestorRects
|
|
3182
|
+
});
|
|
3183
|
+
const publicContext = React.useMemo(() => {
|
|
3184
|
+
const context = {
|
|
3185
|
+
active,
|
|
3186
|
+
activeNode,
|
|
3187
|
+
activeNodeRect,
|
|
3188
|
+
activatorEvent,
|
|
3189
|
+
collisions,
|
|
3190
|
+
containerNodeRect,
|
|
3191
|
+
dragOverlay,
|
|
3192
|
+
draggableNodes,
|
|
3193
|
+
droppableContainers,
|
|
3194
|
+
droppableRects,
|
|
3195
|
+
over,
|
|
3196
|
+
measureDroppableContainers,
|
|
3197
|
+
scrollableAncestors,
|
|
3198
|
+
scrollableAncestorRects,
|
|
3199
|
+
measuringConfiguration,
|
|
3200
|
+
measuringScheduled,
|
|
3201
|
+
windowRect
|
|
3202
|
+
};
|
|
3203
|
+
return context;
|
|
3204
|
+
}, [active, activeNode, activeNodeRect, activatorEvent, collisions, containerNodeRect, dragOverlay, draggableNodes, droppableContainers, droppableRects, over, measureDroppableContainers, scrollableAncestors, scrollableAncestorRects, measuringConfiguration, measuringScheduled, windowRect]);
|
|
3205
|
+
const internalContext = React.useMemo(() => {
|
|
3206
|
+
const context = {
|
|
3207
|
+
activatorEvent,
|
|
3208
|
+
activators,
|
|
3209
|
+
active,
|
|
3210
|
+
activeNodeRect,
|
|
3211
|
+
ariaDescribedById: {
|
|
3212
|
+
draggable: draggableDescribedById
|
|
3213
|
+
},
|
|
3214
|
+
dispatch,
|
|
3215
|
+
draggableNodes,
|
|
3216
|
+
over,
|
|
3217
|
+
measureDroppableContainers
|
|
3218
|
+
};
|
|
3219
|
+
return context;
|
|
3220
|
+
}, [activatorEvent, activators, active, activeNodeRect, dispatch, draggableDescribedById, draggableNodes, over, measureDroppableContainers]);
|
|
3221
|
+
return React__default["default"].createElement(DndMonitorContext.Provider, {
|
|
3222
|
+
value: registerMonitorListener
|
|
3223
|
+
}, React__default["default"].createElement(InternalContext.Provider, {
|
|
3224
|
+
value: internalContext
|
|
3225
|
+
}, React__default["default"].createElement(PublicContext.Provider, {
|
|
3226
|
+
value: publicContext
|
|
3227
|
+
}, React__default["default"].createElement(ActiveDraggableContext.Provider, {
|
|
3228
|
+
value: transform
|
|
3229
|
+
}, children)), React__default["default"].createElement(RestoreFocus, {
|
|
3230
|
+
disabled: (accessibility == null ? void 0 : accessibility.restoreFocus) === false
|
|
3231
|
+
})), React__default["default"].createElement(Accessibility, { ...accessibility,
|
|
3232
|
+
hiddenTextDescribedById: draggableDescribedById
|
|
3233
|
+
}));
|
|
3234
|
+
|
|
3235
|
+
function getAutoScrollerOptions() {
|
|
3236
|
+
const activeSensorDisablesAutoscroll = (activeSensor == null ? void 0 : activeSensor.autoScrollEnabled) === false;
|
|
3237
|
+
const autoScrollGloballyDisabled = typeof autoScroll === 'object' ? autoScroll.enabled === false : autoScroll === false;
|
|
3238
|
+
const enabled = isInitialized && !activeSensorDisablesAutoscroll && !autoScrollGloballyDisabled;
|
|
3239
|
+
|
|
3240
|
+
if (typeof autoScroll === 'object') {
|
|
3241
|
+
return { ...autoScroll,
|
|
3242
|
+
enabled
|
|
3243
|
+
};
|
|
3244
|
+
}
|
|
3245
|
+
|
|
3246
|
+
return {
|
|
3247
|
+
enabled
|
|
3248
|
+
};
|
|
3249
|
+
}
|
|
3250
|
+
});
|
|
3251
|
+
|
|
3252
|
+
const NullContext = /*#__PURE__*/React.createContext(null);
|
|
3253
|
+
const defaultRole = 'button';
|
|
3254
|
+
const ID_PREFIX = 'Draggable';
|
|
3255
|
+
function useDraggable(_ref) {
|
|
3256
|
+
let {
|
|
3257
|
+
id,
|
|
3258
|
+
data,
|
|
3259
|
+
disabled = false,
|
|
3260
|
+
attributes
|
|
3261
|
+
} = _ref;
|
|
3262
|
+
const key = utilities_esm.useUniqueId(ID_PREFIX);
|
|
3263
|
+
const {
|
|
3264
|
+
activators,
|
|
3265
|
+
activatorEvent,
|
|
3266
|
+
active,
|
|
3267
|
+
activeNodeRect,
|
|
3268
|
+
ariaDescribedById,
|
|
3269
|
+
draggableNodes,
|
|
3270
|
+
over
|
|
3271
|
+
} = React.useContext(InternalContext);
|
|
3272
|
+
const {
|
|
3273
|
+
role = defaultRole,
|
|
3274
|
+
roleDescription = 'draggable',
|
|
3275
|
+
tabIndex = 0
|
|
3276
|
+
} = attributes != null ? attributes : {};
|
|
3277
|
+
const isDragging = (active == null ? void 0 : active.id) === id;
|
|
3278
|
+
const transform = React.useContext(isDragging ? ActiveDraggableContext : NullContext);
|
|
3279
|
+
const [node, setNodeRef] = utilities_esm.useNodeRef();
|
|
3280
|
+
const [activatorNode, setActivatorNodeRef] = utilities_esm.useNodeRef();
|
|
3281
|
+
const listeners = useSyntheticListeners(activators, id);
|
|
3282
|
+
const dataRef = utilities_esm.useLatestValue(data);
|
|
3283
|
+
utilities_esm.useIsomorphicLayoutEffect(() => {
|
|
3284
|
+
draggableNodes.set(id, {
|
|
3285
|
+
id,
|
|
3286
|
+
key,
|
|
3287
|
+
node,
|
|
3288
|
+
activatorNode,
|
|
3289
|
+
data: dataRef
|
|
3290
|
+
});
|
|
3291
|
+
return () => {
|
|
3292
|
+
const node = draggableNodes.get(id);
|
|
3293
|
+
|
|
3294
|
+
if (node && node.key === key) {
|
|
3295
|
+
draggableNodes.delete(id);
|
|
3296
|
+
}
|
|
3297
|
+
};
|
|
3298
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3299
|
+
[draggableNodes, id]);
|
|
3300
|
+
const memoizedAttributes = React.useMemo(() => ({
|
|
3301
|
+
role,
|
|
3302
|
+
tabIndex,
|
|
3303
|
+
'aria-disabled': disabled,
|
|
3304
|
+
'aria-pressed': isDragging && role === defaultRole ? true : undefined,
|
|
3305
|
+
'aria-roledescription': roleDescription,
|
|
3306
|
+
'aria-describedby': ariaDescribedById.draggable
|
|
3307
|
+
}), [disabled, role, tabIndex, isDragging, roleDescription, ariaDescribedById.draggable]);
|
|
3308
|
+
return {
|
|
3309
|
+
active,
|
|
3310
|
+
activatorEvent,
|
|
3311
|
+
activeNodeRect,
|
|
3312
|
+
attributes: memoizedAttributes,
|
|
3313
|
+
isDragging,
|
|
3314
|
+
listeners: disabled ? undefined : listeners,
|
|
3315
|
+
node,
|
|
3316
|
+
over,
|
|
3317
|
+
setNodeRef,
|
|
3318
|
+
setActivatorNodeRef,
|
|
3319
|
+
transform
|
|
3320
|
+
};
|
|
3321
|
+
}
|
|
3322
|
+
|
|
3323
|
+
function useDndContext() {
|
|
3324
|
+
return React.useContext(PublicContext);
|
|
3325
|
+
}
|
|
3326
|
+
|
|
3327
|
+
const ID_PREFIX$1 = 'Droppable';
|
|
3328
|
+
const defaultResizeObserverConfig = {
|
|
3329
|
+
timeout: 25
|
|
3330
|
+
};
|
|
3331
|
+
function useDroppable(_ref) {
|
|
3332
|
+
let {
|
|
3333
|
+
data,
|
|
3334
|
+
disabled = false,
|
|
3335
|
+
id,
|
|
3336
|
+
resizeObserverConfig
|
|
3337
|
+
} = _ref;
|
|
3338
|
+
const key = utilities_esm.useUniqueId(ID_PREFIX$1);
|
|
3339
|
+
const {
|
|
3340
|
+
active,
|
|
3341
|
+
dispatch,
|
|
3342
|
+
over,
|
|
3343
|
+
measureDroppableContainers
|
|
3344
|
+
} = React.useContext(InternalContext);
|
|
3345
|
+
const previous = React.useRef({
|
|
3346
|
+
disabled
|
|
3347
|
+
});
|
|
3348
|
+
const resizeObserverConnected = React.useRef(false);
|
|
3349
|
+
const rect = React.useRef(null);
|
|
3350
|
+
const callbackId = React.useRef(null);
|
|
3351
|
+
const {
|
|
3352
|
+
disabled: resizeObserverDisabled,
|
|
3353
|
+
updateMeasurementsFor,
|
|
3354
|
+
timeout: resizeObserverTimeout
|
|
3355
|
+
} = { ...defaultResizeObserverConfig,
|
|
3356
|
+
...resizeObserverConfig
|
|
3357
|
+
};
|
|
3358
|
+
const ids = utilities_esm.useLatestValue(updateMeasurementsFor != null ? updateMeasurementsFor : id);
|
|
3359
|
+
const handleResize = React.useCallback(() => {
|
|
3360
|
+
if (!resizeObserverConnected.current) {
|
|
3361
|
+
// ResizeObserver invokes the `handleResize` callback as soon as `observe` is called,
|
|
3362
|
+
// assuming the element is rendered and displayed.
|
|
3363
|
+
resizeObserverConnected.current = true;
|
|
3364
|
+
return;
|
|
3365
|
+
}
|
|
3366
|
+
|
|
3367
|
+
if (callbackId.current != null) {
|
|
3368
|
+
clearTimeout(callbackId.current);
|
|
3369
|
+
}
|
|
3370
|
+
|
|
3371
|
+
callbackId.current = setTimeout(() => {
|
|
3372
|
+
measureDroppableContainers(Array.isArray(ids.current) ? ids.current : [ids.current]);
|
|
3373
|
+
callbackId.current = null;
|
|
3374
|
+
}, resizeObserverTimeout);
|
|
3375
|
+
}, //eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3376
|
+
[resizeObserverTimeout]);
|
|
3377
|
+
const resizeObserver = useResizeObserver({
|
|
3378
|
+
callback: handleResize,
|
|
3379
|
+
disabled: resizeObserverDisabled || !active
|
|
3380
|
+
});
|
|
3381
|
+
const handleNodeChange = React.useCallback((newElement, previousElement) => {
|
|
3382
|
+
if (!resizeObserver) {
|
|
3383
|
+
return;
|
|
3384
|
+
}
|
|
3385
|
+
|
|
3386
|
+
if (previousElement) {
|
|
3387
|
+
resizeObserver.unobserve(previousElement);
|
|
3388
|
+
resizeObserverConnected.current = false;
|
|
3389
|
+
}
|
|
3390
|
+
|
|
3391
|
+
if (newElement) {
|
|
3392
|
+
resizeObserver.observe(newElement);
|
|
3393
|
+
}
|
|
3394
|
+
}, [resizeObserver]);
|
|
3395
|
+
const [nodeRef, setNodeRef] = utilities_esm.useNodeRef(handleNodeChange);
|
|
3396
|
+
const dataRef = utilities_esm.useLatestValue(data);
|
|
3397
|
+
React.useEffect(() => {
|
|
3398
|
+
if (!resizeObserver || !nodeRef.current) {
|
|
3399
|
+
return;
|
|
3400
|
+
}
|
|
3401
|
+
|
|
3402
|
+
resizeObserver.disconnect();
|
|
3403
|
+
resizeObserverConnected.current = false;
|
|
3404
|
+
resizeObserver.observe(nodeRef.current);
|
|
3405
|
+
}, [nodeRef, resizeObserver]);
|
|
3406
|
+
React.useEffect(() => {
|
|
3407
|
+
dispatch({
|
|
3408
|
+
type: Action.RegisterDroppable,
|
|
3409
|
+
element: {
|
|
3410
|
+
id,
|
|
3411
|
+
key,
|
|
3412
|
+
disabled,
|
|
3413
|
+
node: nodeRef,
|
|
3414
|
+
rect,
|
|
3415
|
+
data: dataRef
|
|
3416
|
+
}
|
|
3417
|
+
});
|
|
3418
|
+
return () => dispatch({
|
|
3419
|
+
type: Action.UnregisterDroppable,
|
|
3420
|
+
key,
|
|
3421
|
+
id
|
|
3422
|
+
});
|
|
3423
|
+
}, // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
3424
|
+
[id]);
|
|
3425
|
+
React.useEffect(() => {
|
|
3426
|
+
if (disabled !== previous.current.disabled) {
|
|
3427
|
+
dispatch({
|
|
3428
|
+
type: Action.SetDroppableDisabled,
|
|
3429
|
+
id,
|
|
3430
|
+
key,
|
|
3431
|
+
disabled
|
|
3432
|
+
});
|
|
3433
|
+
previous.current.disabled = disabled;
|
|
3434
|
+
}
|
|
3435
|
+
}, [id, key, disabled, dispatch]);
|
|
3436
|
+
return {
|
|
3437
|
+
active,
|
|
3438
|
+
rect,
|
|
3439
|
+
isOver: (over == null ? void 0 : over.id) === id,
|
|
3440
|
+
node: nodeRef,
|
|
3441
|
+
over,
|
|
3442
|
+
setNodeRef
|
|
3443
|
+
};
|
|
3444
|
+
}
|
|
3445
|
+
|
|
3446
|
+
exports.DndContext = DndContext;
|
|
3447
|
+
exports.KeyboardSensor = KeyboardSensor;
|
|
3448
|
+
exports.MouseSensor = MouseSensor;
|
|
3449
|
+
exports.PointerSensor = PointerSensor;
|
|
3450
|
+
exports.TouchSensor = TouchSensor;
|
|
3451
|
+
exports.applyModifiers = applyModifiers;
|
|
3452
|
+
exports.closestCenter = closestCenter;
|
|
3453
|
+
exports.defaultAnnouncements = defaultAnnouncements;
|
|
3454
|
+
exports.defaultCoordinates = defaultCoordinates;
|
|
3455
|
+
exports.defaultKeyboardCoordinateGetter = defaultKeyboardCoordinateGetter;
|
|
3456
|
+
exports.defaultScreenReaderInstructions = defaultScreenReaderInstructions;
|
|
3457
|
+
exports.getClientRect = getClientRect;
|
|
3458
|
+
exports.getFirstCollision = getFirstCollision;
|
|
3459
|
+
exports.getScrollableAncestors = getScrollableAncestors;
|
|
3460
|
+
exports.rectIntersection = rectIntersection;
|
|
3461
|
+
exports.useDndContext = useDndContext;
|
|
3462
|
+
exports.useDndMonitor = useDndMonitor;
|
|
3463
|
+
exports.useDraggable = useDraggable;
|
|
3464
|
+
exports.useDroppable = useDroppable;
|
|
3465
|
+
exports.useSensor = useSensor;
|
|
3466
|
+
exports.useSensors = useSensors;
|
|
3467
|
+
//# sourceMappingURL=core.esm.js.map
|