@eightshift/ui-components 0.0.1

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