@pnkx-lib/ui 1.9.536 → 1.9.539

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4784 +0,0 @@
1
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
- import React__default, { useLayoutEffect, useEffect, useRef, useMemo, useCallback, useState, memo, useReducer, createContext, useContext } from 'react';
3
- import { u as useForm } from '../../chunks/index.esm-Dr5ZHcf7.js';
4
- import { Checkbox } from '../../fields/Checkbox.js';
5
- import { PnkxField } from '../../fields/PnkxField.js';
6
- import { unstable_batchedUpdates, createPortal } from 'react-dom';
7
- import { t as twMerge } from '../../chunks/bundle-mjs-BME7zF0Z.js';
8
- import { Modal } from '../Modal.js';
9
- import { Button } from '../Button.js';
10
- import { L as ListStatusApproved, d as TypeBulkActions } from '../../chunks/table-Btvh90Co.js';
11
- import { isBoolean, isEmpty } from 'lodash';
12
- import { Badge } from '../Badge.js';
13
- import { Tooltip } from '../Tooltip.js';
14
- import { Heading } from '../Heading.js';
15
- import { Table } from '../Table/index.js';
16
- import { BulkActions } from '../BulkActions/index.js';
17
- import { I as ID_TABLE_WRAPPER } from '../../chunks/common-BcURBmQ-.js';
18
-
19
- const SettingIcon = ({
20
- size = 24,
21
- color = "currentColor",
22
- className,
23
- style,
24
- onClick,
25
- "aria-label": ariaLabel,
26
- title,
27
- ...props
28
- }) => /* @__PURE__ */ jsx(
29
- "div",
30
- {
31
- className,
32
- style: {
33
- width: size,
34
- height: size,
35
- cursor: onClick ? "pointer" : "default",
36
- ...style
37
- },
38
- onClick,
39
- role: onClick ? "button" : void 0,
40
- "aria-label": ariaLabel,
41
- title,
42
- ...props,
43
- children: /* @__PURE__ */ jsx(
44
- "svg",
45
- {
46
- width: "100%",
47
- height: "100%",
48
- viewBox: "0 0 24 24",
49
- fill: "none",
50
- xmlns: "http://www.w3.org/2000/svg",
51
- children: /* @__PURE__ */ jsx(
52
- "path",
53
- {
54
- d: "M11.9997 7.49998C11.1097 7.49998 10.2396 7.7639 9.49962 8.25837C8.7596 8.75284 8.18283 9.45564 7.84223 10.2779C7.50164 11.1002 7.41252 12.005 7.58616 12.8779C7.75979 13.7508 8.18837 14.5526 8.81771 15.182C9.44705 15.8113 10.2489 16.2399 11.1218 16.4135C11.9947 16.5872 12.8995 16.498 13.7218 16.1574C14.544 15.8168 15.2468 15.2401 15.7413 14.5C16.2358 13.76 16.4997 12.89 16.4997 12C16.4984 10.8069 16.0239 9.66302 15.1803 8.81937C14.3367 7.97573 13.1928 7.50122 11.9997 7.49998ZM11.9997 15C11.4063 15 10.8263 14.824 10.333 14.4944C9.83963 14.1647 9.45511 13.6962 9.22805 13.148C9.00099 12.5999 8.94158 11.9967 9.05733 11.4147C9.17309 10.8328 9.45881 10.2982 9.87837 9.87866C10.2979 9.45911 10.8325 9.17338 11.4144 9.05763C11.9964 8.94187 12.5996 9.00128 13.1477 9.22834C13.6959 9.45541 14.1645 9.83993 14.4941 10.3333C14.8237 10.8266 14.9997 11.4066 14.9997 12C14.9997 12.7956 14.6836 13.5587 14.121 14.1213C13.5584 14.6839 12.7953 15 11.9997 15ZM22.3066 10.0509C22.2857 9.94531 22.2423 9.84543 22.1794 9.75807C22.1164 9.67072 22.0354 9.59793 21.9419 9.54467L19.1453 7.95092L19.1341 4.79904C19.1337 4.6905 19.1098 4.58331 19.064 4.4849C19.0182 4.38649 18.9516 4.29919 18.8688 4.22904C17.8543 3.37095 16.6861 2.71336 15.4263 2.29123C15.327 2.25765 15.2219 2.24522 15.1176 2.25475C15.0133 2.26428 14.9121 2.29555 14.8206 2.34654L11.9997 3.92342L9.17594 2.34373C9.0844 2.29245 8.98311 2.26094 8.87863 2.25125C8.77414 2.24156 8.66879 2.2539 8.56938 2.28748C7.31045 2.71269 6.14359 3.37279 5.13063 4.23279C5.04791 4.30284 4.98136 4.38999 4.93556 4.48823C4.88975 4.58647 4.86579 4.69347 4.86532 4.80186L4.85125 7.95655L2.05469 9.5503C1.96113 9.60356 1.88013 9.67634 1.8172 9.7637C1.75428 9.85105 1.71089 9.95093 1.69 10.0565C1.43406 11.3427 1.43406 12.6667 1.69 13.9528C1.71089 14.0584 1.75428 14.1583 1.8172 14.2456C1.88013 14.333 1.96113 14.4058 2.05469 14.459L4.85125 16.0528L4.8625 19.2047C4.86284 19.3132 4.88674 19.4204 4.93255 19.5188C4.97835 19.6172 5.04498 19.7045 5.12782 19.7747C6.14226 20.6328 7.31046 21.2904 8.57031 21.7125C8.66953 21.7461 8.77468 21.7585 8.87899 21.749C8.98329 21.7394 9.08445 21.7082 9.17594 21.6572L11.9997 20.0765L14.8234 21.6562C14.9352 21.7185 15.0611 21.7508 15.1891 21.75C15.271 21.75 15.3523 21.7367 15.43 21.7106C16.6888 21.286 17.8556 20.6265 18.8688 19.7672C18.9515 19.6971 19.018 19.61 19.0638 19.5117C19.1096 19.4135 19.1336 19.3065 19.1341 19.1981L19.1481 16.0434L21.9447 14.4497C22.0383 14.3964 22.1192 14.3236 22.1822 14.2363C22.2451 14.1489 22.2885 14.049 22.3094 13.9434C22.5639 12.6583 22.5629 11.3357 22.3066 10.0509ZM20.9003 13.3237L18.2219 14.8472C18.1045 14.9139 18.0074 15.0111 17.9406 15.1284C17.8863 15.2222 17.8291 15.3215 17.7709 15.4153C17.6965 15.5335 17.6569 15.6703 17.6566 15.81L17.6425 18.8334C16.9226 19.3988 16.1205 19.8509 15.2641 20.174L12.5622 18.6684C12.45 18.6064 12.3238 18.5741 12.1956 18.5747H12.1778C12.0644 18.5747 11.95 18.5747 11.8366 18.5747C11.7024 18.5713 11.5697 18.6037 11.4522 18.6684L8.74844 20.1778C7.89017 19.8571 7.0859 19.4072 6.36344 18.8437L6.35313 15.825C6.35266 15.685 6.31305 15.548 6.23875 15.4294C6.18063 15.3356 6.12344 15.2419 6.07 15.1425C6.00374 15.0233 5.90659 14.9242 5.78875 14.8556L3.1075 13.3284C2.96875 12.4507 2.96875 11.5567 3.1075 10.679L5.78125 9.1528C5.89861 9.08607 5.99577 8.9889 6.0625 8.87155C6.11688 8.7778 6.17407 8.67842 6.23219 8.58467C6.30659 8.46645 6.34623 8.32967 6.34656 8.18998L6.36063 5.16654C7.08056 4.60118 7.88262 4.14909 8.73907 3.82592L11.4372 5.33154C11.5546 5.39664 11.6874 5.42901 11.8216 5.42529C11.935 5.42529 12.0494 5.42529 12.1628 5.42529C12.297 5.42865 12.4296 5.39629 12.5472 5.33154L15.2509 3.82217C16.1092 4.14286 16.9135 4.59274 17.6359 5.15623L17.6463 8.17498C17.6467 8.31495 17.6863 8.45199 17.7606 8.57061C17.8188 8.66436 17.8759 8.75811 17.9294 8.85748C17.9956 8.97665 18.0928 9.07575 18.2106 9.14436L20.8919 10.6715C21.0325 11.5499 21.0341 12.4449 20.8966 13.3237H20.9003Z",
55
- fill: color
56
- }
57
- )
58
- }
59
- )
60
- }
61
- );
62
-
63
- const DragIcon = ({
64
- size = 24,
65
- color = "currentColor",
66
- className,
67
- style,
68
- onClick,
69
- "aria-label": ariaLabel,
70
- title,
71
- fill,
72
- stroke,
73
- ...props
74
- }) => /* @__PURE__ */ jsx(
75
- "div",
76
- {
77
- className,
78
- style: {
79
- width: size,
80
- height: size,
81
- cursor: onClick ? "pointer" : "default",
82
- ...style
83
- },
84
- onClick,
85
- role: onClick ? "button" : void 0,
86
- "aria-label": ariaLabel,
87
- title,
88
- ...props,
89
- children: /* @__PURE__ */ jsx(
90
- "svg",
91
- {
92
- width: "100%",
93
- height: "100%",
94
- viewBox: "0 0 24 24",
95
- fill: "none",
96
- xmlns: "http://www.w3.org/2000/svg",
97
- children: /* @__PURE__ */ jsx(
98
- "path",
99
- {
100
- fill: fill || "#116DFF",
101
- stroke,
102
- fillRule: "evenodd",
103
- d: "M6 1h2v2H6V1Zm0 5h2v2H6V6Zm4-5h2v2h-2V1Zm0 5h2v2h-2V6Zm-4 5h2v2H6v-2Zm4 0h2v2h-2v-2Zm-4 5h2v2H6v-2Zm4 0h2v2h-2v-2Zm-4 5h2v2H6v-2Zm4 0h2v2h-2v-2Z",
104
- clipRule: "evenodd"
105
- }
106
- )
107
- }
108
- )
109
- }
110
- );
111
-
112
- const SettingColumnItem = ({ lable, name, control }) => {
113
- return /* @__PURE__ */ jsx("div", { className: "settingColumnItem", children: /* @__PURE__ */ jsx(
114
- PnkxField,
115
- {
116
- label: lable,
117
- component: Checkbox,
118
- name,
119
- control,
120
- afterOnChange: () => {
121
- }
122
- }
123
- ) }, name);
124
- };
125
-
126
- function useCombinedRefs() {
127
- for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
128
- refs[_key] = arguments[_key];
129
- }
130
-
131
- return useMemo(() => node => {
132
- refs.forEach(ref => ref(node));
133
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
134
- refs);
135
- }
136
-
137
- // https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
138
- const canUseDOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
139
-
140
- function isWindow(element) {
141
- const elementString = Object.prototype.toString.call(element);
142
- return elementString === '[object Window]' || // In Electron context the Window object serializes to [object global]
143
- elementString === '[object global]';
144
- }
145
-
146
- function isNode(node) {
147
- return 'nodeType' in node;
148
- }
149
-
150
- function getWindow(target) {
151
- var _target$ownerDocument, _target$ownerDocument2;
152
-
153
- if (!target) {
154
- return window;
155
- }
156
-
157
- if (isWindow(target)) {
158
- return target;
159
- }
160
-
161
- if (!isNode(target)) {
162
- return window;
163
- }
164
-
165
- return (_target$ownerDocument = (_target$ownerDocument2 = target.ownerDocument) == null ? void 0 : _target$ownerDocument2.defaultView) != null ? _target$ownerDocument : window;
166
- }
167
-
168
- function isDocument(node) {
169
- const {
170
- Document
171
- } = getWindow(node);
172
- return node instanceof Document;
173
- }
174
-
175
- function isHTMLElement(node) {
176
- if (isWindow(node)) {
177
- return false;
178
- }
179
-
180
- return node instanceof getWindow(node).HTMLElement;
181
- }
182
-
183
- function isSVGElement(node) {
184
- return node instanceof getWindow(node).SVGElement;
185
- }
186
-
187
- function getOwnerDocument(target) {
188
- if (!target) {
189
- return document;
190
- }
191
-
192
- if (isWindow(target)) {
193
- return target.document;
194
- }
195
-
196
- if (!isNode(target)) {
197
- return document;
198
- }
199
-
200
- if (isDocument(target)) {
201
- return target;
202
- }
203
-
204
- if (isHTMLElement(target) || isSVGElement(target)) {
205
- return target.ownerDocument;
206
- }
207
-
208
- return document;
209
- }
210
-
211
- /**
212
- * A hook that resolves to useEffect on the server and useLayoutEffect on the client
213
- * @param callback {function} Callback function that is invoked when the dependencies of the hook change
214
- */
215
-
216
- const useIsomorphicLayoutEffect = canUseDOM ? useLayoutEffect : useEffect;
217
-
218
- function useEvent(handler) {
219
- const handlerRef = useRef(handler);
220
- useIsomorphicLayoutEffect(() => {
221
- handlerRef.current = handler;
222
- });
223
- return useCallback(function () {
224
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
225
- args[_key] = arguments[_key];
226
- }
227
-
228
- return handlerRef.current == null ? void 0 : handlerRef.current(...args);
229
- }, []);
230
- }
231
-
232
- function useInterval() {
233
- const intervalRef = useRef(null);
234
- const set = useCallback((listener, duration) => {
235
- intervalRef.current = setInterval(listener, duration);
236
- }, []);
237
- const clear = useCallback(() => {
238
- if (intervalRef.current !== null) {
239
- clearInterval(intervalRef.current);
240
- intervalRef.current = null;
241
- }
242
- }, []);
243
- return [set, clear];
244
- }
245
-
246
- function useLatestValue(value, dependencies) {
247
- if (dependencies === void 0) {
248
- dependencies = [value];
249
- }
250
-
251
- const valueRef = useRef(value);
252
- useIsomorphicLayoutEffect(() => {
253
- if (valueRef.current !== value) {
254
- valueRef.current = value;
255
- }
256
- }, dependencies);
257
- return valueRef;
258
- }
259
-
260
- function useLazyMemo(callback, dependencies) {
261
- const valueRef = useRef();
262
- return useMemo(() => {
263
- const newValue = callback(valueRef.current);
264
- valueRef.current = newValue;
265
- return newValue;
266
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
267
- [...dependencies]);
268
- }
269
-
270
- function useNodeRef(onChange) {
271
- const onChangeHandler = useEvent(onChange);
272
- const node = useRef(null);
273
- const setNodeRef = useCallback(element => {
274
- if (element !== node.current) {
275
- onChangeHandler == null ? void 0 : onChangeHandler(element, node.current);
276
- }
277
-
278
- node.current = element;
279
- }, //eslint-disable-next-line
280
- []);
281
- return [node, setNodeRef];
282
- }
283
-
284
- function usePrevious(value) {
285
- const ref = useRef();
286
- useEffect(() => {
287
- ref.current = value;
288
- }, [value]);
289
- return ref.current;
290
- }
291
-
292
- let ids = {};
293
- function useUniqueId(prefix, value) {
294
- return useMemo(() => {
295
- if (value) {
296
- return value;
297
- }
298
-
299
- const id = ids[prefix] == null ? 0 : ids[prefix] + 1;
300
- ids[prefix] = id;
301
- return prefix + "-" + id;
302
- }, [prefix, value]);
303
- }
304
-
305
- function createAdjustmentFn(modifier) {
306
- return function (object) {
307
- for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
308
- adjustments[_key - 1] = arguments[_key];
309
- }
310
-
311
- return adjustments.reduce((accumulator, adjustment) => {
312
- const entries = Object.entries(adjustment);
313
-
314
- for (const [key, valueAdjustment] of entries) {
315
- const value = accumulator[key];
316
-
317
- if (value != null) {
318
- accumulator[key] = value + modifier * valueAdjustment;
319
- }
320
- }
321
-
322
- return accumulator;
323
- }, { ...object
324
- });
325
- };
326
- }
327
-
328
- const add = /*#__PURE__*/createAdjustmentFn(1);
329
- const subtract = /*#__PURE__*/createAdjustmentFn(-1);
330
-
331
- function hasViewportRelativeCoordinates(event) {
332
- return 'clientX' in event && 'clientY' in event;
333
- }
334
-
335
- function isKeyboardEvent(event) {
336
- if (!event) {
337
- return false;
338
- }
339
-
340
- const {
341
- KeyboardEvent
342
- } = getWindow(event.target);
343
- return KeyboardEvent && event instanceof KeyboardEvent;
344
- }
345
-
346
- function isTouchEvent(event) {
347
- if (!event) {
348
- return false;
349
- }
350
-
351
- const {
352
- TouchEvent
353
- } = getWindow(event.target);
354
- return TouchEvent && event instanceof TouchEvent;
355
- }
356
-
357
- /**
358
- * Returns the normalized x and y coordinates for mouse and touch events.
359
- */
360
-
361
- function getEventCoordinates(event) {
362
- if (isTouchEvent(event)) {
363
- if (event.touches && event.touches.length) {
364
- const {
365
- clientX: x,
366
- clientY: y
367
- } = event.touches[0];
368
- return {
369
- x,
370
- y
371
- };
372
- } else if (event.changedTouches && event.changedTouches.length) {
373
- const {
374
- clientX: x,
375
- clientY: y
376
- } = event.changedTouches[0];
377
- return {
378
- x,
379
- y
380
- };
381
- }
382
- }
383
-
384
- if (hasViewportRelativeCoordinates(event)) {
385
- return {
386
- x: event.clientX,
387
- y: event.clientY
388
- };
389
- }
390
-
391
- return null;
392
- }
393
-
394
- const CSS = /*#__PURE__*/Object.freeze({
395
- Translate: {
396
- toString(transform) {
397
- if (!transform) {
398
- return;
399
- }
400
-
401
- const {
402
- x,
403
- y
404
- } = transform;
405
- return "translate3d(" + (x ? Math.round(x) : 0) + "px, " + (y ? Math.round(y) : 0) + "px, 0)";
406
- }
407
-
408
- },
409
- Scale: {
410
- toString(transform) {
411
- if (!transform) {
412
- return;
413
- }
414
-
415
- const {
416
- scaleX,
417
- scaleY
418
- } = transform;
419
- return "scaleX(" + scaleX + ") scaleY(" + scaleY + ")";
420
- }
421
-
422
- },
423
- Transform: {
424
- toString(transform) {
425
- if (!transform) {
426
- return;
427
- }
428
-
429
- return [CSS.Translate.toString(transform), CSS.Scale.toString(transform)].join(' ');
430
- }
431
-
432
- },
433
- Transition: {
434
- toString(_ref) {
435
- let {
436
- property,
437
- duration,
438
- easing
439
- } = _ref;
440
- return property + " " + duration + "ms " + easing;
441
- }
442
-
443
- }
444
- });
445
-
446
- const SELECTOR = 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';
447
- function findFirstFocusableNode(element) {
448
- if (element.matches(SELECTOR)) {
449
- return element;
450
- }
451
-
452
- return element.querySelector(SELECTOR);
453
- }
454
-
455
- const hiddenStyles = {
456
- display: 'none'
457
- };
458
- function HiddenText(_ref) {
459
- let {
460
- id,
461
- value
462
- } = _ref;
463
- return React__default.createElement("div", {
464
- id: id,
465
- style: hiddenStyles
466
- }, value);
467
- }
468
-
469
- function LiveRegion(_ref) {
470
- let {
471
- id,
472
- announcement,
473
- ariaLiveType = "assertive"
474
- } = _ref;
475
- // Hide element visually but keep it readable by screen readers
476
- const visuallyHidden = {
477
- position: 'fixed',
478
- top: 0,
479
- left: 0,
480
- width: 1,
481
- height: 1,
482
- margin: -1,
483
- border: 0,
484
- padding: 0,
485
- overflow: 'hidden',
486
- clip: 'rect(0 0 0 0)',
487
- clipPath: 'inset(100%)',
488
- whiteSpace: 'nowrap'
489
- };
490
- return React__default.createElement("div", {
491
- id: id,
492
- style: visuallyHidden,
493
- role: "status",
494
- "aria-live": ariaLiveType,
495
- "aria-atomic": true
496
- }, announcement);
497
- }
498
-
499
- function useAnnouncement() {
500
- const [announcement, setAnnouncement] = useState('');
501
- const announce = useCallback(value => {
502
- if (value != null) {
503
- setAnnouncement(value);
504
- }
505
- }, []);
506
- return {
507
- announce,
508
- announcement
509
- };
510
- }
511
-
512
- const DndMonitorContext = /*#__PURE__*/createContext(null);
513
-
514
- function useDndMonitor(listener) {
515
- const registerListener = useContext(DndMonitorContext);
516
- useEffect(() => {
517
- if (!registerListener) {
518
- throw new Error('useDndMonitor must be used within a children of <DndContext>');
519
- }
520
-
521
- const unsubscribe = registerListener(listener);
522
- return unsubscribe;
523
- }, [listener, registerListener]);
524
- }
525
-
526
- function useDndMonitorProvider() {
527
- const [listeners] = useState(() => new Set());
528
- const registerListener = useCallback(listener => {
529
- listeners.add(listener);
530
- return () => listeners.delete(listener);
531
- }, [listeners]);
532
- const dispatch = useCallback(_ref => {
533
- let {
534
- type,
535
- event
536
- } = _ref;
537
- listeners.forEach(listener => {
538
- var _listener$type;
539
-
540
- return (_listener$type = listener[type]) == null ? void 0 : _listener$type.call(listener, event);
541
- });
542
- }, [listeners]);
543
- return [dispatch, registerListener];
544
- }
545
-
546
- const defaultScreenReaderInstructions = {
547
- 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 "
548
- };
549
- const defaultAnnouncements = {
550
- onDragStart(_ref) {
551
- let {
552
- active
553
- } = _ref;
554
- return "Picked up draggable item " + active.id + ".";
555
- },
556
-
557
- onDragOver(_ref2) {
558
- let {
559
- active,
560
- over
561
- } = _ref2;
562
-
563
- if (over) {
564
- return "Draggable item " + active.id + " was moved over droppable area " + over.id + ".";
565
- }
566
-
567
- return "Draggable item " + active.id + " is no longer over a droppable area.";
568
- },
569
-
570
- onDragEnd(_ref3) {
571
- let {
572
- active,
573
- over
574
- } = _ref3;
575
-
576
- if (over) {
577
- return "Draggable item " + active.id + " was dropped over droppable area " + over.id;
578
- }
579
-
580
- return "Draggable item " + active.id + " was dropped.";
581
- },
582
-
583
- onDragCancel(_ref4) {
584
- let {
585
- active
586
- } = _ref4;
587
- return "Dragging was cancelled. Draggable item " + active.id + " was dropped.";
588
- }
589
-
590
- };
591
-
592
- function Accessibility(_ref) {
593
- let {
594
- announcements = defaultAnnouncements,
595
- container,
596
- hiddenTextDescribedById,
597
- screenReaderInstructions = defaultScreenReaderInstructions
598
- } = _ref;
599
- const {
600
- announce,
601
- announcement
602
- } = useAnnouncement();
603
- const liveRegionId = useUniqueId("DndLiveRegion");
604
- const [mounted, setMounted] = useState(false);
605
- useEffect(() => {
606
- setMounted(true);
607
- }, []);
608
- useDndMonitor(useMemo(() => ({
609
- onDragStart(_ref2) {
610
- let {
611
- active
612
- } = _ref2;
613
- announce(announcements.onDragStart({
614
- active
615
- }));
616
- },
617
-
618
- onDragMove(_ref3) {
619
- let {
620
- active,
621
- over
622
- } = _ref3;
623
-
624
- if (announcements.onDragMove) {
625
- announce(announcements.onDragMove({
626
- active,
627
- over
628
- }));
629
- }
630
- },
631
-
632
- onDragOver(_ref4) {
633
- let {
634
- active,
635
- over
636
- } = _ref4;
637
- announce(announcements.onDragOver({
638
- active,
639
- over
640
- }));
641
- },
642
-
643
- onDragEnd(_ref5) {
644
- let {
645
- active,
646
- over
647
- } = _ref5;
648
- announce(announcements.onDragEnd({
649
- active,
650
- over
651
- }));
652
- },
653
-
654
- onDragCancel(_ref6) {
655
- let {
656
- active,
657
- over
658
- } = _ref6;
659
- announce(announcements.onDragCancel({
660
- active,
661
- over
662
- }));
663
- }
664
-
665
- }), [announce, announcements]));
666
-
667
- if (!mounted) {
668
- return null;
669
- }
670
-
671
- const markup = React__default.createElement(React__default.Fragment, null, React__default.createElement(HiddenText, {
672
- id: hiddenTextDescribedById,
673
- value: screenReaderInstructions.draggable
674
- }), React__default.createElement(LiveRegion, {
675
- id: liveRegionId,
676
- announcement: announcement
677
- }));
678
- return container ? createPortal(markup, container) : markup;
679
- }
680
-
681
- var Action;
682
-
683
- (function (Action) {
684
- Action["DragStart"] = "dragStart";
685
- Action["DragMove"] = "dragMove";
686
- Action["DragEnd"] = "dragEnd";
687
- Action["DragCancel"] = "dragCancel";
688
- Action["DragOver"] = "dragOver";
689
- Action["RegisterDroppable"] = "registerDroppable";
690
- Action["SetDroppableDisabled"] = "setDroppableDisabled";
691
- Action["UnregisterDroppable"] = "unregisterDroppable";
692
- })(Action || (Action = {}));
693
-
694
- function noop() {}
695
-
696
- const defaultCoordinates = /*#__PURE__*/Object.freeze({
697
- x: 0,
698
- y: 0
699
- });
700
-
701
- /**
702
- * Returns the distance between two points
703
- */
704
- function distanceBetween(p1, p2) {
705
- return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
706
- }
707
-
708
- /**
709
- * Sort collisions from smallest to greatest value
710
- */
711
- function sortCollisionsAsc(_ref, _ref2) {
712
- let {
713
- data: {
714
- value: a
715
- }
716
- } = _ref;
717
- let {
718
- data: {
719
- value: b
720
- }
721
- } = _ref2;
722
- return a - b;
723
- }
724
- /**
725
- * Sort collisions from greatest to smallest value
726
- */
727
-
728
- function sortCollisionsDesc(_ref3, _ref4) {
729
- let {
730
- data: {
731
- value: a
732
- }
733
- } = _ref3;
734
- let {
735
- data: {
736
- value: b
737
- }
738
- } = _ref4;
739
- return b - a;
740
- }
741
- function getFirstCollision(collisions, property) {
742
- if (!collisions || collisions.length === 0) {
743
- return null;
744
- }
745
-
746
- const [firstCollision] = collisions;
747
- return firstCollision[property] ;
748
- }
749
-
750
- /**
751
- * Returns the coordinates of the center of a given ClientRect
752
- */
753
-
754
- function centerOfRectangle(rect, left, top) {
755
- if (left === void 0) {
756
- left = rect.left;
757
- }
758
-
759
- if (top === void 0) {
760
- top = rect.top;
761
- }
762
-
763
- return {
764
- x: left + rect.width * 0.5,
765
- y: top + rect.height * 0.5
766
- };
767
- }
768
- /**
769
- * Returns the closest rectangles from an array of rectangles to the center of a given
770
- * rectangle.
771
- */
772
-
773
-
774
- const closestCenter = _ref => {
775
- let {
776
- collisionRect,
777
- droppableRects,
778
- droppableContainers
779
- } = _ref;
780
- const centerRect = centerOfRectangle(collisionRect, collisionRect.left, collisionRect.top);
781
- const collisions = [];
782
-
783
- for (const droppableContainer of droppableContainers) {
784
- const {
785
- id
786
- } = droppableContainer;
787
- const rect = droppableRects.get(id);
788
-
789
- if (rect) {
790
- const distBetween = distanceBetween(centerOfRectangle(rect), centerRect);
791
- collisions.push({
792
- id,
793
- data: {
794
- droppableContainer,
795
- value: distBetween
796
- }
797
- });
798
- }
799
- }
800
-
801
- return collisions.sort(sortCollisionsAsc);
802
- };
803
-
804
- /**
805
- * Returns the intersecting rectangle area between two rectangles
806
- */
807
-
808
- function getIntersectionRatio(entry, target) {
809
- const top = Math.max(target.top, entry.top);
810
- const left = Math.max(target.left, entry.left);
811
- const right = Math.min(target.left + target.width, entry.left + entry.width);
812
- const bottom = Math.min(target.top + target.height, entry.top + entry.height);
813
- const width = right - left;
814
- const height = bottom - top;
815
-
816
- if (left < right && top < bottom) {
817
- const targetArea = target.width * target.height;
818
- const entryArea = entry.width * entry.height;
819
- const intersectionArea = width * height;
820
- const intersectionRatio = intersectionArea / (targetArea + entryArea - intersectionArea);
821
- return Number(intersectionRatio.toFixed(4));
822
- } // Rectangles do not overlap, or overlap has an area of zero (edge/corner overlap)
823
-
824
-
825
- return 0;
826
- }
827
- /**
828
- * Returns the rectangles that has the greatest intersection area with a given
829
- * rectangle in an array of rectangles.
830
- */
831
-
832
- const rectIntersection = _ref => {
833
- let {
834
- collisionRect,
835
- droppableRects,
836
- droppableContainers
837
- } = _ref;
838
- const collisions = [];
839
-
840
- for (const droppableContainer of droppableContainers) {
841
- const {
842
- id
843
- } = droppableContainer;
844
- const rect = droppableRects.get(id);
845
-
846
- if (rect) {
847
- const intersectionRatio = getIntersectionRatio(rect, collisionRect);
848
-
849
- if (intersectionRatio > 0) {
850
- collisions.push({
851
- id,
852
- data: {
853
- droppableContainer,
854
- value: intersectionRatio
855
- }
856
- });
857
- }
858
- }
859
- }
860
-
861
- return collisions.sort(sortCollisionsDesc);
862
- };
863
-
864
- function adjustScale(transform, rect1, rect2) {
865
- return { ...transform,
866
- scaleX: rect1 && rect2 ? rect1.width / rect2.width : 1,
867
- scaleY: rect1 && rect2 ? rect1.height / rect2.height : 1
868
- };
869
- }
870
-
871
- function getRectDelta(rect1, rect2) {
872
- return rect1 && rect2 ? {
873
- x: rect1.left - rect2.left,
874
- y: rect1.top - rect2.top
875
- } : defaultCoordinates;
876
- }
877
-
878
- function createRectAdjustmentFn(modifier) {
879
- return function adjustClientRect(rect) {
880
- for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
881
- adjustments[_key - 1] = arguments[_key];
882
- }
883
-
884
- return adjustments.reduce((acc, adjustment) => ({ ...acc,
885
- top: acc.top + modifier * adjustment.y,
886
- bottom: acc.bottom + modifier * adjustment.y,
887
- left: acc.left + modifier * adjustment.x,
888
- right: acc.right + modifier * adjustment.x
889
- }), { ...rect
890
- });
891
- };
892
- }
893
- const getAdjustedRect = /*#__PURE__*/createRectAdjustmentFn(1);
894
-
895
- function parseTransform(transform) {
896
- if (transform.startsWith('matrix3d(')) {
897
- const transformArray = transform.slice(9, -1).split(/, /);
898
- return {
899
- x: +transformArray[12],
900
- y: +transformArray[13],
901
- scaleX: +transformArray[0],
902
- scaleY: +transformArray[5]
903
- };
904
- } else if (transform.startsWith('matrix(')) {
905
- const transformArray = transform.slice(7, -1).split(/, /);
906
- return {
907
- x: +transformArray[4],
908
- y: +transformArray[5],
909
- scaleX: +transformArray[0],
910
- scaleY: +transformArray[3]
911
- };
912
- }
913
-
914
- return null;
915
- }
916
-
917
- function inverseTransform(rect, transform, transformOrigin) {
918
- const parsedTransform = parseTransform(transform);
919
-
920
- if (!parsedTransform) {
921
- return rect;
922
- }
923
-
924
- const {
925
- scaleX,
926
- scaleY,
927
- x: translateX,
928
- y: translateY
929
- } = parsedTransform;
930
- const x = rect.left - translateX - (1 - scaleX) * parseFloat(transformOrigin);
931
- const y = rect.top - translateY - (1 - scaleY) * parseFloat(transformOrigin.slice(transformOrigin.indexOf(' ') + 1));
932
- const w = scaleX ? rect.width / scaleX : rect.width;
933
- const h = scaleY ? rect.height / scaleY : rect.height;
934
- return {
935
- width: w,
936
- height: h,
937
- top: y,
938
- right: x + w,
939
- bottom: y + h,
940
- left: x
941
- };
942
- }
943
-
944
- const defaultOptions = {
945
- ignoreTransform: false
946
- };
947
- /**
948
- * Returns the bounding client rect of an element relative to the viewport.
949
- */
950
-
951
- function getClientRect(element, options) {
952
- if (options === void 0) {
953
- options = defaultOptions;
954
- }
955
-
956
- let rect = element.getBoundingClientRect();
957
-
958
- if (options.ignoreTransform) {
959
- const {
960
- transform,
961
- transformOrigin
962
- } = getWindow(element).getComputedStyle(element);
963
-
964
- if (transform) {
965
- rect = inverseTransform(rect, transform, transformOrigin);
966
- }
967
- }
968
-
969
- const {
970
- top,
971
- left,
972
- width,
973
- height,
974
- bottom,
975
- right
976
- } = rect;
977
- return {
978
- top,
979
- left,
980
- width,
981
- height,
982
- bottom,
983
- right
984
- };
985
- }
986
- /**
987
- * Returns the bounding client rect of an element relative to the viewport.
988
- *
989
- * @remarks
990
- * The ClientRect returned by this method does not take into account transforms
991
- * applied to the element it measures.
992
- *
993
- */
994
-
995
- function getTransformAgnosticClientRect(element) {
996
- return getClientRect(element, {
997
- ignoreTransform: true
998
- });
999
- }
1000
-
1001
- function getWindowClientRect(element) {
1002
- const width = element.innerWidth;
1003
- const height = element.innerHeight;
1004
- return {
1005
- top: 0,
1006
- left: 0,
1007
- right: width,
1008
- bottom: height,
1009
- width,
1010
- height
1011
- };
1012
- }
1013
-
1014
- function isFixed(node, computedStyle) {
1015
- if (computedStyle === void 0) {
1016
- computedStyle = getWindow(node).getComputedStyle(node);
1017
- }
1018
-
1019
- return computedStyle.position === 'fixed';
1020
- }
1021
-
1022
- function isScrollable(element, computedStyle) {
1023
- if (computedStyle === void 0) {
1024
- computedStyle = getWindow(element).getComputedStyle(element);
1025
- }
1026
-
1027
- const overflowRegex = /(auto|scroll|overlay)/;
1028
- const properties = ['overflow', 'overflowX', 'overflowY'];
1029
- return properties.some(property => {
1030
- const value = computedStyle[property];
1031
- return typeof value === 'string' ? overflowRegex.test(value) : false;
1032
- });
1033
- }
1034
-
1035
- function getScrollableAncestors(element, limit) {
1036
- const scrollParents = [];
1037
-
1038
- function findScrollableAncestors(node) {
1039
- if (limit != null && scrollParents.length >= limit) {
1040
- return scrollParents;
1041
- }
1042
-
1043
- if (!node) {
1044
- return scrollParents;
1045
- }
1046
-
1047
- if (isDocument(node) && node.scrollingElement != null && !scrollParents.includes(node.scrollingElement)) {
1048
- scrollParents.push(node.scrollingElement);
1049
- return scrollParents;
1050
- }
1051
-
1052
- if (!isHTMLElement(node) || isSVGElement(node)) {
1053
- return scrollParents;
1054
- }
1055
-
1056
- if (scrollParents.includes(node)) {
1057
- return scrollParents;
1058
- }
1059
-
1060
- const computedStyle = getWindow(element).getComputedStyle(node);
1061
-
1062
- if (node !== element) {
1063
- if (isScrollable(node, computedStyle)) {
1064
- scrollParents.push(node);
1065
- }
1066
- }
1067
-
1068
- if (isFixed(node, computedStyle)) {
1069
- return scrollParents;
1070
- }
1071
-
1072
- return findScrollableAncestors(node.parentNode);
1073
- }
1074
-
1075
- if (!element) {
1076
- return scrollParents;
1077
- }
1078
-
1079
- return findScrollableAncestors(element);
1080
- }
1081
- function getFirstScrollableAncestor(node) {
1082
- const [firstScrollableAncestor] = getScrollableAncestors(node, 1);
1083
- return firstScrollableAncestor != null ? firstScrollableAncestor : null;
1084
- }
1085
-
1086
- function getScrollableElement(element) {
1087
- if (!canUseDOM || !element) {
1088
- return null;
1089
- }
1090
-
1091
- if (isWindow(element)) {
1092
- return element;
1093
- }
1094
-
1095
- if (!isNode(element)) {
1096
- return null;
1097
- }
1098
-
1099
- if (isDocument(element) || element === getOwnerDocument(element).scrollingElement) {
1100
- return window;
1101
- }
1102
-
1103
- if (isHTMLElement(element)) {
1104
- return element;
1105
- }
1106
-
1107
- return null;
1108
- }
1109
-
1110
- function getScrollXCoordinate(element) {
1111
- if (isWindow(element)) {
1112
- return element.scrollX;
1113
- }
1114
-
1115
- return element.scrollLeft;
1116
- }
1117
- function getScrollYCoordinate(element) {
1118
- if (isWindow(element)) {
1119
- return element.scrollY;
1120
- }
1121
-
1122
- return element.scrollTop;
1123
- }
1124
- function getScrollCoordinates(element) {
1125
- return {
1126
- x: getScrollXCoordinate(element),
1127
- y: getScrollYCoordinate(element)
1128
- };
1129
- }
1130
-
1131
- var Direction;
1132
-
1133
- (function (Direction) {
1134
- Direction[Direction["Forward"] = 1] = "Forward";
1135
- Direction[Direction["Backward"] = -1] = "Backward";
1136
- })(Direction || (Direction = {}));
1137
-
1138
- function isDocumentScrollingElement(element) {
1139
- if (!canUseDOM || !element) {
1140
- return false;
1141
- }
1142
-
1143
- return element === document.scrollingElement;
1144
- }
1145
-
1146
- function getScrollPosition(scrollingContainer) {
1147
- const minScroll = {
1148
- x: 0,
1149
- y: 0
1150
- };
1151
- const dimensions = isDocumentScrollingElement(scrollingContainer) ? {
1152
- height: window.innerHeight,
1153
- width: window.innerWidth
1154
- } : {
1155
- height: scrollingContainer.clientHeight,
1156
- width: scrollingContainer.clientWidth
1157
- };
1158
- const maxScroll = {
1159
- x: scrollingContainer.scrollWidth - dimensions.width,
1160
- y: scrollingContainer.scrollHeight - dimensions.height
1161
- };
1162
- const isTop = scrollingContainer.scrollTop <= minScroll.y;
1163
- const isLeft = scrollingContainer.scrollLeft <= minScroll.x;
1164
- const isBottom = scrollingContainer.scrollTop >= maxScroll.y;
1165
- const isRight = scrollingContainer.scrollLeft >= maxScroll.x;
1166
- return {
1167
- isTop,
1168
- isLeft,
1169
- isBottom,
1170
- isRight,
1171
- maxScroll,
1172
- minScroll
1173
- };
1174
- }
1175
-
1176
- const defaultThreshold = {
1177
- x: 0.2,
1178
- y: 0.2
1179
- };
1180
- function getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, _ref, acceleration, thresholdPercentage) {
1181
- let {
1182
- top,
1183
- left,
1184
- right,
1185
- bottom
1186
- } = _ref;
1187
-
1188
- if (acceleration === void 0) {
1189
- acceleration = 10;
1190
- }
1191
-
1192
- if (thresholdPercentage === void 0) {
1193
- thresholdPercentage = defaultThreshold;
1194
- }
1195
-
1196
- const {
1197
- isTop,
1198
- isBottom,
1199
- isLeft,
1200
- isRight
1201
- } = getScrollPosition(scrollContainer);
1202
- const direction = {
1203
- x: 0,
1204
- y: 0
1205
- };
1206
- const speed = {
1207
- x: 0,
1208
- y: 0
1209
- };
1210
- const threshold = {
1211
- height: scrollContainerRect.height * thresholdPercentage.y,
1212
- width: scrollContainerRect.width * thresholdPercentage.x
1213
- };
1214
-
1215
- if (!isTop && top <= scrollContainerRect.top + threshold.height) {
1216
- // Scroll Up
1217
- direction.y = Direction.Backward;
1218
- speed.y = acceleration * Math.abs((scrollContainerRect.top + threshold.height - top) / threshold.height);
1219
- } else if (!isBottom && bottom >= scrollContainerRect.bottom - threshold.height) {
1220
- // Scroll Down
1221
- direction.y = Direction.Forward;
1222
- speed.y = acceleration * Math.abs((scrollContainerRect.bottom - threshold.height - bottom) / threshold.height);
1223
- }
1224
-
1225
- if (!isRight && right >= scrollContainerRect.right - threshold.width) {
1226
- // Scroll Right
1227
- direction.x = Direction.Forward;
1228
- speed.x = acceleration * Math.abs((scrollContainerRect.right - threshold.width - right) / threshold.width);
1229
- } else if (!isLeft && left <= scrollContainerRect.left + threshold.width) {
1230
- // Scroll Left
1231
- direction.x = Direction.Backward;
1232
- speed.x = acceleration * Math.abs((scrollContainerRect.left + threshold.width - left) / threshold.width);
1233
- }
1234
-
1235
- return {
1236
- direction,
1237
- speed
1238
- };
1239
- }
1240
-
1241
- function getScrollElementRect(element) {
1242
- if (element === document.scrollingElement) {
1243
- const {
1244
- innerWidth,
1245
- innerHeight
1246
- } = window;
1247
- return {
1248
- top: 0,
1249
- left: 0,
1250
- right: innerWidth,
1251
- bottom: innerHeight,
1252
- width: innerWidth,
1253
- height: innerHeight
1254
- };
1255
- }
1256
-
1257
- const {
1258
- top,
1259
- left,
1260
- right,
1261
- bottom
1262
- } = element.getBoundingClientRect();
1263
- return {
1264
- top,
1265
- left,
1266
- right,
1267
- bottom,
1268
- width: element.clientWidth,
1269
- height: element.clientHeight
1270
- };
1271
- }
1272
-
1273
- function getScrollOffsets(scrollableAncestors) {
1274
- return scrollableAncestors.reduce((acc, node) => {
1275
- return add(acc, getScrollCoordinates(node));
1276
- }, defaultCoordinates);
1277
- }
1278
- function getScrollXOffset(scrollableAncestors) {
1279
- return scrollableAncestors.reduce((acc, node) => {
1280
- return acc + getScrollXCoordinate(node);
1281
- }, 0);
1282
- }
1283
- function getScrollYOffset(scrollableAncestors) {
1284
- return scrollableAncestors.reduce((acc, node) => {
1285
- return acc + getScrollYCoordinate(node);
1286
- }, 0);
1287
- }
1288
-
1289
- function scrollIntoViewIfNeeded(element, measure) {
1290
- if (measure === void 0) {
1291
- measure = getClientRect;
1292
- }
1293
-
1294
- if (!element) {
1295
- return;
1296
- }
1297
-
1298
- const {
1299
- top,
1300
- left,
1301
- bottom,
1302
- right
1303
- } = measure(element);
1304
- const firstScrollableAncestor = getFirstScrollableAncestor(element);
1305
-
1306
- if (!firstScrollableAncestor) {
1307
- return;
1308
- }
1309
-
1310
- if (bottom <= 0 || right <= 0 || top >= window.innerHeight || left >= window.innerWidth) {
1311
- element.scrollIntoView({
1312
- block: 'center',
1313
- inline: 'center'
1314
- });
1315
- }
1316
- }
1317
-
1318
- const properties = [['x', ['left', 'right'], getScrollXOffset], ['y', ['top', 'bottom'], getScrollYOffset]];
1319
- class Rect {
1320
- constructor(rect, element) {
1321
- this.rect = void 0;
1322
- this.width = void 0;
1323
- this.height = void 0;
1324
- this.top = void 0;
1325
- this.bottom = void 0;
1326
- this.right = void 0;
1327
- this.left = void 0;
1328
- const scrollableAncestors = getScrollableAncestors(element);
1329
- const scrollOffsets = getScrollOffsets(scrollableAncestors);
1330
- this.rect = { ...rect
1331
- };
1332
- this.width = rect.width;
1333
- this.height = rect.height;
1334
-
1335
- for (const [axis, keys, getScrollOffset] of properties) {
1336
- for (const key of keys) {
1337
- Object.defineProperty(this, key, {
1338
- get: () => {
1339
- const currentOffsets = getScrollOffset(scrollableAncestors);
1340
- const scrollOffsetsDeltla = scrollOffsets[axis] - currentOffsets;
1341
- return this.rect[key] + scrollOffsetsDeltla;
1342
- },
1343
- enumerable: true
1344
- });
1345
- }
1346
- }
1347
-
1348
- Object.defineProperty(this, 'rect', {
1349
- enumerable: false
1350
- });
1351
- }
1352
-
1353
- }
1354
-
1355
- class Listeners {
1356
- constructor(target) {
1357
- this.target = void 0;
1358
- this.listeners = [];
1359
-
1360
- this.removeAll = () => {
1361
- this.listeners.forEach(listener => {
1362
- var _this$target;
1363
-
1364
- return (_this$target = this.target) == null ? void 0 : _this$target.removeEventListener(...listener);
1365
- });
1366
- };
1367
-
1368
- this.target = target;
1369
- }
1370
-
1371
- add(eventName, handler, options) {
1372
- var _this$target2;
1373
-
1374
- (_this$target2 = this.target) == null ? void 0 : _this$target2.addEventListener(eventName, handler, options);
1375
- this.listeners.push([eventName, handler, options]);
1376
- }
1377
-
1378
- }
1379
-
1380
- function getEventListenerTarget(target) {
1381
- // If the `event.target` element is removed from the document events will still be targeted
1382
- // at it, and hence won't always bubble up to the window or document anymore.
1383
- // If there is any risk of an element being removed while it is being dragged,
1384
- // the best practice is to attach the event listeners directly to the target.
1385
- // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
1386
- const {
1387
- EventTarget
1388
- } = getWindow(target);
1389
- return target instanceof EventTarget ? target : getOwnerDocument(target);
1390
- }
1391
-
1392
- function hasExceededDistance(delta, measurement) {
1393
- const dx = Math.abs(delta.x);
1394
- const dy = Math.abs(delta.y);
1395
-
1396
- if (typeof measurement === 'number') {
1397
- return Math.sqrt(dx ** 2 + dy ** 2) > measurement;
1398
- }
1399
-
1400
- if ('x' in measurement && 'y' in measurement) {
1401
- return dx > measurement.x && dy > measurement.y;
1402
- }
1403
-
1404
- if ('x' in measurement) {
1405
- return dx > measurement.x;
1406
- }
1407
-
1408
- if ('y' in measurement) {
1409
- return dy > measurement.y;
1410
- }
1411
-
1412
- return false;
1413
- }
1414
-
1415
- var EventName;
1416
-
1417
- (function (EventName) {
1418
- EventName["Click"] = "click";
1419
- EventName["DragStart"] = "dragstart";
1420
- EventName["Keydown"] = "keydown";
1421
- EventName["ContextMenu"] = "contextmenu";
1422
- EventName["Resize"] = "resize";
1423
- EventName["SelectionChange"] = "selectionchange";
1424
- EventName["VisibilityChange"] = "visibilitychange";
1425
- })(EventName || (EventName = {}));
1426
-
1427
- function preventDefault(event) {
1428
- event.preventDefault();
1429
- }
1430
- function stopPropagation(event) {
1431
- event.stopPropagation();
1432
- }
1433
-
1434
- var KeyboardCode;
1435
-
1436
- (function (KeyboardCode) {
1437
- KeyboardCode["Space"] = "Space";
1438
- KeyboardCode["Down"] = "ArrowDown";
1439
- KeyboardCode["Right"] = "ArrowRight";
1440
- KeyboardCode["Left"] = "ArrowLeft";
1441
- KeyboardCode["Up"] = "ArrowUp";
1442
- KeyboardCode["Esc"] = "Escape";
1443
- KeyboardCode["Enter"] = "Enter";
1444
- KeyboardCode["Tab"] = "Tab";
1445
- })(KeyboardCode || (KeyboardCode = {}));
1446
-
1447
- const defaultKeyboardCodes = {
1448
- start: [KeyboardCode.Space, KeyboardCode.Enter],
1449
- cancel: [KeyboardCode.Esc],
1450
- end: [KeyboardCode.Space, KeyboardCode.Enter, KeyboardCode.Tab]
1451
- };
1452
- const defaultKeyboardCoordinateGetter = (event, _ref) => {
1453
- let {
1454
- currentCoordinates
1455
- } = _ref;
1456
-
1457
- switch (event.code) {
1458
- case KeyboardCode.Right:
1459
- return { ...currentCoordinates,
1460
- x: currentCoordinates.x + 25
1461
- };
1462
-
1463
- case KeyboardCode.Left:
1464
- return { ...currentCoordinates,
1465
- x: currentCoordinates.x - 25
1466
- };
1467
-
1468
- case KeyboardCode.Down:
1469
- return { ...currentCoordinates,
1470
- y: currentCoordinates.y + 25
1471
- };
1472
-
1473
- case KeyboardCode.Up:
1474
- return { ...currentCoordinates,
1475
- y: currentCoordinates.y - 25
1476
- };
1477
- }
1478
-
1479
- return undefined;
1480
- };
1481
-
1482
- class KeyboardSensor {
1483
- constructor(props) {
1484
- this.props = void 0;
1485
- this.autoScrollEnabled = false;
1486
- this.referenceCoordinates = void 0;
1487
- this.listeners = void 0;
1488
- this.windowListeners = void 0;
1489
- this.props = props;
1490
- const {
1491
- event: {
1492
- target
1493
- }
1494
- } = props;
1495
- this.props = props;
1496
- this.listeners = new Listeners(getOwnerDocument(target));
1497
- this.windowListeners = new Listeners(getWindow(target));
1498
- this.handleKeyDown = this.handleKeyDown.bind(this);
1499
- this.handleCancel = this.handleCancel.bind(this);
1500
- this.attach();
1501
- }
1502
-
1503
- attach() {
1504
- this.handleStart();
1505
- this.windowListeners.add(EventName.Resize, this.handleCancel);
1506
- this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
1507
- setTimeout(() => this.listeners.add(EventName.Keydown, this.handleKeyDown));
1508
- }
1509
-
1510
- handleStart() {
1511
- const {
1512
- activeNode,
1513
- onStart
1514
- } = this.props;
1515
- const node = activeNode.node.current;
1516
-
1517
- if (node) {
1518
- scrollIntoViewIfNeeded(node);
1519
- }
1520
-
1521
- onStart(defaultCoordinates);
1522
- }
1523
-
1524
- handleKeyDown(event) {
1525
- if (isKeyboardEvent(event)) {
1526
- const {
1527
- active,
1528
- context,
1529
- options
1530
- } = this.props;
1531
- const {
1532
- keyboardCodes = defaultKeyboardCodes,
1533
- coordinateGetter = defaultKeyboardCoordinateGetter,
1534
- scrollBehavior = 'smooth'
1535
- } = options;
1536
- const {
1537
- code
1538
- } = event;
1539
-
1540
- if (keyboardCodes.end.includes(code)) {
1541
- this.handleEnd(event);
1542
- return;
1543
- }
1544
-
1545
- if (keyboardCodes.cancel.includes(code)) {
1546
- this.handleCancel(event);
1547
- return;
1548
- }
1549
-
1550
- const {
1551
- collisionRect
1552
- } = context.current;
1553
- const currentCoordinates = collisionRect ? {
1554
- x: collisionRect.left,
1555
- y: collisionRect.top
1556
- } : defaultCoordinates;
1557
-
1558
- if (!this.referenceCoordinates) {
1559
- this.referenceCoordinates = currentCoordinates;
1560
- }
1561
-
1562
- const newCoordinates = coordinateGetter(event, {
1563
- active,
1564
- context: context.current,
1565
- currentCoordinates
1566
- });
1567
-
1568
- if (newCoordinates) {
1569
- const coordinatesDelta = subtract(newCoordinates, currentCoordinates);
1570
- const scrollDelta = {
1571
- x: 0,
1572
- y: 0
1573
- };
1574
- const {
1575
- scrollableAncestors
1576
- } = context.current;
1577
-
1578
- for (const scrollContainer of scrollableAncestors) {
1579
- const direction = event.code;
1580
- const {
1581
- isTop,
1582
- isRight,
1583
- isLeft,
1584
- isBottom,
1585
- maxScroll,
1586
- minScroll
1587
- } = getScrollPosition(scrollContainer);
1588
- const scrollElementRect = getScrollElementRect(scrollContainer);
1589
- const clampedCoordinates = {
1590
- 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)),
1591
- 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))
1592
- };
1593
- const canScrollX = direction === KeyboardCode.Right && !isRight || direction === KeyboardCode.Left && !isLeft;
1594
- const canScrollY = direction === KeyboardCode.Down && !isBottom || direction === KeyboardCode.Up && !isTop;
1595
-
1596
- if (canScrollX && clampedCoordinates.x !== newCoordinates.x) {
1597
- const newScrollCoordinates = scrollContainer.scrollLeft + coordinatesDelta.x;
1598
- const canScrollToNewCoordinates = direction === KeyboardCode.Right && newScrollCoordinates <= maxScroll.x || direction === KeyboardCode.Left && newScrollCoordinates >= minScroll.x;
1599
-
1600
- if (canScrollToNewCoordinates && !coordinatesDelta.y) {
1601
- // We don't need to update coordinates, the scroll adjustment alone will trigger
1602
- // logic to auto-detect the new container we are over
1603
- scrollContainer.scrollTo({
1604
- left: newScrollCoordinates,
1605
- behavior: scrollBehavior
1606
- });
1607
- return;
1608
- }
1609
-
1610
- if (canScrollToNewCoordinates) {
1611
- scrollDelta.x = scrollContainer.scrollLeft - newScrollCoordinates;
1612
- } else {
1613
- scrollDelta.x = direction === KeyboardCode.Right ? scrollContainer.scrollLeft - maxScroll.x : scrollContainer.scrollLeft - minScroll.x;
1614
- }
1615
-
1616
- if (scrollDelta.x) {
1617
- scrollContainer.scrollBy({
1618
- left: -scrollDelta.x,
1619
- behavior: scrollBehavior
1620
- });
1621
- }
1622
-
1623
- break;
1624
- } else if (canScrollY && clampedCoordinates.y !== newCoordinates.y) {
1625
- const newScrollCoordinates = scrollContainer.scrollTop + coordinatesDelta.y;
1626
- const canScrollToNewCoordinates = direction === KeyboardCode.Down && newScrollCoordinates <= maxScroll.y || direction === KeyboardCode.Up && newScrollCoordinates >= minScroll.y;
1627
-
1628
- if (canScrollToNewCoordinates && !coordinatesDelta.x) {
1629
- // We don't need to update coordinates, the scroll adjustment alone will trigger
1630
- // logic to auto-detect the new container we are over
1631
- scrollContainer.scrollTo({
1632
- top: newScrollCoordinates,
1633
- behavior: scrollBehavior
1634
- });
1635
- return;
1636
- }
1637
-
1638
- if (canScrollToNewCoordinates) {
1639
- scrollDelta.y = scrollContainer.scrollTop - newScrollCoordinates;
1640
- } else {
1641
- scrollDelta.y = direction === KeyboardCode.Down ? scrollContainer.scrollTop - maxScroll.y : scrollContainer.scrollTop - minScroll.y;
1642
- }
1643
-
1644
- if (scrollDelta.y) {
1645
- scrollContainer.scrollBy({
1646
- top: -scrollDelta.y,
1647
- behavior: scrollBehavior
1648
- });
1649
- }
1650
-
1651
- break;
1652
- }
1653
- }
1654
-
1655
- this.handleMove(event, add(subtract(newCoordinates, this.referenceCoordinates), scrollDelta));
1656
- }
1657
- }
1658
- }
1659
-
1660
- handleMove(event, coordinates) {
1661
- const {
1662
- onMove
1663
- } = this.props;
1664
- event.preventDefault();
1665
- onMove(coordinates);
1666
- }
1667
-
1668
- handleEnd(event) {
1669
- const {
1670
- onEnd
1671
- } = this.props;
1672
- event.preventDefault();
1673
- this.detach();
1674
- onEnd();
1675
- }
1676
-
1677
- handleCancel(event) {
1678
- const {
1679
- onCancel
1680
- } = this.props;
1681
- event.preventDefault();
1682
- this.detach();
1683
- onCancel();
1684
- }
1685
-
1686
- detach() {
1687
- this.listeners.removeAll();
1688
- this.windowListeners.removeAll();
1689
- }
1690
-
1691
- }
1692
- KeyboardSensor.activators = [{
1693
- eventName: 'onKeyDown',
1694
- handler: (event, _ref, _ref2) => {
1695
- let {
1696
- keyboardCodes = defaultKeyboardCodes,
1697
- onActivation
1698
- } = _ref;
1699
- let {
1700
- active
1701
- } = _ref2;
1702
- const {
1703
- code
1704
- } = event.nativeEvent;
1705
-
1706
- if (keyboardCodes.start.includes(code)) {
1707
- const activator = active.activatorNode.current;
1708
-
1709
- if (activator && event.target !== activator) {
1710
- return false;
1711
- }
1712
-
1713
- event.preventDefault();
1714
- onActivation == null ? void 0 : onActivation({
1715
- event: event.nativeEvent
1716
- });
1717
- return true;
1718
- }
1719
-
1720
- return false;
1721
- }
1722
- }];
1723
-
1724
- function isDistanceConstraint(constraint) {
1725
- return Boolean(constraint && 'distance' in constraint);
1726
- }
1727
-
1728
- function isDelayConstraint(constraint) {
1729
- return Boolean(constraint && 'delay' in constraint);
1730
- }
1731
-
1732
- class AbstractPointerSensor {
1733
- constructor(props, events, listenerTarget) {
1734
- var _getEventCoordinates;
1735
-
1736
- if (listenerTarget === void 0) {
1737
- listenerTarget = getEventListenerTarget(props.event.target);
1738
- }
1739
-
1740
- this.props = void 0;
1741
- this.events = void 0;
1742
- this.autoScrollEnabled = true;
1743
- this.document = void 0;
1744
- this.activated = false;
1745
- this.initialCoordinates = void 0;
1746
- this.timeoutId = null;
1747
- this.listeners = void 0;
1748
- this.documentListeners = void 0;
1749
- this.windowListeners = void 0;
1750
- this.props = props;
1751
- this.events = events;
1752
- const {
1753
- event
1754
- } = props;
1755
- const {
1756
- target
1757
- } = event;
1758
- this.props = props;
1759
- this.events = events;
1760
- this.document = getOwnerDocument(target);
1761
- this.documentListeners = new Listeners(this.document);
1762
- this.listeners = new Listeners(listenerTarget);
1763
- this.windowListeners = new Listeners(getWindow(target));
1764
- this.initialCoordinates = (_getEventCoordinates = getEventCoordinates(event)) != null ? _getEventCoordinates : defaultCoordinates;
1765
- this.handleStart = this.handleStart.bind(this);
1766
- this.handleMove = this.handleMove.bind(this);
1767
- this.handleEnd = this.handleEnd.bind(this);
1768
- this.handleCancel = this.handleCancel.bind(this);
1769
- this.handleKeydown = this.handleKeydown.bind(this);
1770
- this.removeTextSelection = this.removeTextSelection.bind(this);
1771
- this.attach();
1772
- }
1773
-
1774
- attach() {
1775
- const {
1776
- events,
1777
- props: {
1778
- options: {
1779
- activationConstraint,
1780
- bypassActivationConstraint
1781
- }
1782
- }
1783
- } = this;
1784
- this.listeners.add(events.move.name, this.handleMove, {
1785
- passive: false
1786
- });
1787
- this.listeners.add(events.end.name, this.handleEnd);
1788
-
1789
- if (events.cancel) {
1790
- this.listeners.add(events.cancel.name, this.handleCancel);
1791
- }
1792
-
1793
- this.windowListeners.add(EventName.Resize, this.handleCancel);
1794
- this.windowListeners.add(EventName.DragStart, preventDefault);
1795
- this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
1796
- this.windowListeners.add(EventName.ContextMenu, preventDefault);
1797
- this.documentListeners.add(EventName.Keydown, this.handleKeydown);
1798
-
1799
- if (activationConstraint) {
1800
- if (bypassActivationConstraint != null && bypassActivationConstraint({
1801
- event: this.props.event,
1802
- activeNode: this.props.activeNode,
1803
- options: this.props.options
1804
- })) {
1805
- return this.handleStart();
1806
- }
1807
-
1808
- if (isDelayConstraint(activationConstraint)) {
1809
- this.timeoutId = setTimeout(this.handleStart, activationConstraint.delay);
1810
- this.handlePending(activationConstraint);
1811
- return;
1812
- }
1813
-
1814
- if (isDistanceConstraint(activationConstraint)) {
1815
- this.handlePending(activationConstraint);
1816
- return;
1817
- }
1818
- }
1819
-
1820
- this.handleStart();
1821
- }
1822
-
1823
- detach() {
1824
- this.listeners.removeAll();
1825
- this.windowListeners.removeAll(); // Wait until the next event loop before removing document listeners
1826
- // This is necessary because we listen for `click` and `selection` events on the document
1827
-
1828
- setTimeout(this.documentListeners.removeAll, 50);
1829
-
1830
- if (this.timeoutId !== null) {
1831
- clearTimeout(this.timeoutId);
1832
- this.timeoutId = null;
1833
- }
1834
- }
1835
-
1836
- handlePending(constraint, offset) {
1837
- const {
1838
- active,
1839
- onPending
1840
- } = this.props;
1841
- onPending(active, constraint, this.initialCoordinates, offset);
1842
- }
1843
-
1844
- handleStart() {
1845
- const {
1846
- initialCoordinates
1847
- } = this;
1848
- const {
1849
- onStart
1850
- } = this.props;
1851
-
1852
- if (initialCoordinates) {
1853
- this.activated = true; // Stop propagation of click events once activation constraints are met
1854
-
1855
- this.documentListeners.add(EventName.Click, stopPropagation, {
1856
- capture: true
1857
- }); // Remove any text selection from the document
1858
-
1859
- this.removeTextSelection(); // Prevent further text selection while dragging
1860
-
1861
- this.documentListeners.add(EventName.SelectionChange, this.removeTextSelection);
1862
- onStart(initialCoordinates);
1863
- }
1864
- }
1865
-
1866
- handleMove(event) {
1867
- var _getEventCoordinates2;
1868
-
1869
- const {
1870
- activated,
1871
- initialCoordinates,
1872
- props
1873
- } = this;
1874
- const {
1875
- onMove,
1876
- options: {
1877
- activationConstraint
1878
- }
1879
- } = props;
1880
-
1881
- if (!initialCoordinates) {
1882
- return;
1883
- }
1884
-
1885
- const coordinates = (_getEventCoordinates2 = getEventCoordinates(event)) != null ? _getEventCoordinates2 : defaultCoordinates;
1886
- const delta = subtract(initialCoordinates, coordinates); // Constraint validation
1887
-
1888
- if (!activated && activationConstraint) {
1889
- if (isDistanceConstraint(activationConstraint)) {
1890
- if (activationConstraint.tolerance != null && hasExceededDistance(delta, activationConstraint.tolerance)) {
1891
- return this.handleCancel();
1892
- }
1893
-
1894
- if (hasExceededDistance(delta, activationConstraint.distance)) {
1895
- return this.handleStart();
1896
- }
1897
- }
1898
-
1899
- if (isDelayConstraint(activationConstraint)) {
1900
- if (hasExceededDistance(delta, activationConstraint.tolerance)) {
1901
- return this.handleCancel();
1902
- }
1903
- }
1904
-
1905
- this.handlePending(activationConstraint, delta);
1906
- return;
1907
- }
1908
-
1909
- if (event.cancelable) {
1910
- event.preventDefault();
1911
- }
1912
-
1913
- onMove(coordinates);
1914
- }
1915
-
1916
- handleEnd() {
1917
- const {
1918
- onAbort,
1919
- onEnd
1920
- } = this.props;
1921
- this.detach();
1922
-
1923
- if (!this.activated) {
1924
- onAbort(this.props.active);
1925
- }
1926
-
1927
- onEnd();
1928
- }
1929
-
1930
- handleCancel() {
1931
- const {
1932
- onAbort,
1933
- onCancel
1934
- } = this.props;
1935
- this.detach();
1936
-
1937
- if (!this.activated) {
1938
- onAbort(this.props.active);
1939
- }
1940
-
1941
- onCancel();
1942
- }
1943
-
1944
- handleKeydown(event) {
1945
- if (event.code === KeyboardCode.Esc) {
1946
- this.handleCancel();
1947
- }
1948
- }
1949
-
1950
- removeTextSelection() {
1951
- var _this$document$getSel;
1952
-
1953
- (_this$document$getSel = this.document.getSelection()) == null ? void 0 : _this$document$getSel.removeAllRanges();
1954
- }
1955
-
1956
- }
1957
-
1958
- const events = {
1959
- cancel: {
1960
- name: 'pointercancel'
1961
- },
1962
- move: {
1963
- name: 'pointermove'
1964
- },
1965
- end: {
1966
- name: 'pointerup'
1967
- }
1968
- };
1969
- class PointerSensor extends AbstractPointerSensor {
1970
- constructor(props) {
1971
- const {
1972
- event
1973
- } = props; // Pointer events stop firing if the target is unmounted while dragging
1974
- // Therefore we attach listeners to the owner document instead
1975
-
1976
- const listenerTarget = getOwnerDocument(event.target);
1977
- super(props, events, listenerTarget);
1978
- }
1979
-
1980
- }
1981
- PointerSensor.activators = [{
1982
- eventName: 'onPointerDown',
1983
- handler: (_ref, _ref2) => {
1984
- let {
1985
- nativeEvent: event
1986
- } = _ref;
1987
- let {
1988
- onActivation
1989
- } = _ref2;
1990
-
1991
- if (!event.isPrimary || event.button !== 0) {
1992
- return false;
1993
- }
1994
-
1995
- onActivation == null ? void 0 : onActivation({
1996
- event
1997
- });
1998
- return true;
1999
- }
2000
- }];
2001
-
2002
- const events$1 = {
2003
- move: {
2004
- name: 'mousemove'
2005
- },
2006
- end: {
2007
- name: 'mouseup'
2008
- }
2009
- };
2010
- var MouseButton;
2011
-
2012
- (function (MouseButton) {
2013
- MouseButton[MouseButton["RightClick"] = 2] = "RightClick";
2014
- })(MouseButton || (MouseButton = {}));
2015
-
2016
- class MouseSensor extends AbstractPointerSensor {
2017
- constructor(props) {
2018
- super(props, events$1, getOwnerDocument(props.event.target));
2019
- }
2020
-
2021
- }
2022
- MouseSensor.activators = [{
2023
- eventName: 'onMouseDown',
2024
- handler: (_ref, _ref2) => {
2025
- let {
2026
- nativeEvent: event
2027
- } = _ref;
2028
- let {
2029
- onActivation
2030
- } = _ref2;
2031
-
2032
- if (event.button === MouseButton.RightClick) {
2033
- return false;
2034
- }
2035
-
2036
- onActivation == null ? void 0 : onActivation({
2037
- event
2038
- });
2039
- return true;
2040
- }
2041
- }];
2042
-
2043
- const events$2 = {
2044
- cancel: {
2045
- name: 'touchcancel'
2046
- },
2047
- move: {
2048
- name: 'touchmove'
2049
- },
2050
- end: {
2051
- name: 'touchend'
2052
- }
2053
- };
2054
- class TouchSensor extends AbstractPointerSensor {
2055
- constructor(props) {
2056
- super(props, events$2);
2057
- }
2058
-
2059
- static setup() {
2060
- // Adding a non-capture and non-passive `touchmove` listener in order
2061
- // to force `event.preventDefault()` calls to work in dynamically added
2062
- // touchmove event handlers. This is required for iOS Safari.
2063
- window.addEventListener(events$2.move.name, noop, {
2064
- capture: false,
2065
- passive: false
2066
- });
2067
- return function teardown() {
2068
- window.removeEventListener(events$2.move.name, noop);
2069
- }; // We create a new handler because the teardown function of another sensor
2070
- // could remove our event listener if we use a referentially equal listener.
2071
-
2072
- function noop() {}
2073
- }
2074
-
2075
- }
2076
- TouchSensor.activators = [{
2077
- eventName: 'onTouchStart',
2078
- handler: (_ref, _ref2) => {
2079
- let {
2080
- nativeEvent: event
2081
- } = _ref;
2082
- let {
2083
- onActivation
2084
- } = _ref2;
2085
- const {
2086
- touches
2087
- } = event;
2088
-
2089
- if (touches.length > 1) {
2090
- return false;
2091
- }
2092
-
2093
- onActivation == null ? void 0 : onActivation({
2094
- event
2095
- });
2096
- return true;
2097
- }
2098
- }];
2099
-
2100
- var AutoScrollActivator;
2101
-
2102
- (function (AutoScrollActivator) {
2103
- AutoScrollActivator[AutoScrollActivator["Pointer"] = 0] = "Pointer";
2104
- AutoScrollActivator[AutoScrollActivator["DraggableRect"] = 1] = "DraggableRect";
2105
- })(AutoScrollActivator || (AutoScrollActivator = {}));
2106
-
2107
- var TraversalOrder;
2108
-
2109
- (function (TraversalOrder) {
2110
- TraversalOrder[TraversalOrder["TreeOrder"] = 0] = "TreeOrder";
2111
- TraversalOrder[TraversalOrder["ReversedTreeOrder"] = 1] = "ReversedTreeOrder";
2112
- })(TraversalOrder || (TraversalOrder = {}));
2113
-
2114
- function useAutoScroller(_ref) {
2115
- let {
2116
- acceleration,
2117
- activator = AutoScrollActivator.Pointer,
2118
- canScroll,
2119
- draggingRect,
2120
- enabled,
2121
- interval = 5,
2122
- order = TraversalOrder.TreeOrder,
2123
- pointerCoordinates,
2124
- scrollableAncestors,
2125
- scrollableAncestorRects,
2126
- delta,
2127
- threshold
2128
- } = _ref;
2129
- const scrollIntent = useScrollIntent({
2130
- delta,
2131
- disabled: !enabled
2132
- });
2133
- const [setAutoScrollInterval, clearAutoScrollInterval] = useInterval();
2134
- const scrollSpeed = useRef({
2135
- x: 0,
2136
- y: 0
2137
- });
2138
- const scrollDirection = useRef({
2139
- x: 0,
2140
- y: 0
2141
- });
2142
- const rect = useMemo(() => {
2143
- switch (activator) {
2144
- case AutoScrollActivator.Pointer:
2145
- return pointerCoordinates ? {
2146
- top: pointerCoordinates.y,
2147
- bottom: pointerCoordinates.y,
2148
- left: pointerCoordinates.x,
2149
- right: pointerCoordinates.x
2150
- } : null;
2151
-
2152
- case AutoScrollActivator.DraggableRect:
2153
- return draggingRect;
2154
- }
2155
- }, [activator, draggingRect, pointerCoordinates]);
2156
- const scrollContainerRef = useRef(null);
2157
- const autoScroll = useCallback(() => {
2158
- const scrollContainer = scrollContainerRef.current;
2159
-
2160
- if (!scrollContainer) {
2161
- return;
2162
- }
2163
-
2164
- const scrollLeft = scrollSpeed.current.x * scrollDirection.current.x;
2165
- const scrollTop = scrollSpeed.current.y * scrollDirection.current.y;
2166
- scrollContainer.scrollBy(scrollLeft, scrollTop);
2167
- }, []);
2168
- const sortedScrollableAncestors = useMemo(() => order === TraversalOrder.TreeOrder ? [...scrollableAncestors].reverse() : scrollableAncestors, [order, scrollableAncestors]);
2169
- useEffect(() => {
2170
- if (!enabled || !scrollableAncestors.length || !rect) {
2171
- clearAutoScrollInterval();
2172
- return;
2173
- }
2174
-
2175
- for (const scrollContainer of sortedScrollableAncestors) {
2176
- if ((canScroll == null ? void 0 : canScroll(scrollContainer)) === false) {
2177
- continue;
2178
- }
2179
-
2180
- const index = scrollableAncestors.indexOf(scrollContainer);
2181
- const scrollContainerRect = scrollableAncestorRects[index];
2182
-
2183
- if (!scrollContainerRect) {
2184
- continue;
2185
- }
2186
-
2187
- const {
2188
- direction,
2189
- speed
2190
- } = getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, rect, acceleration, threshold);
2191
-
2192
- for (const axis of ['x', 'y']) {
2193
- if (!scrollIntent[axis][direction[axis]]) {
2194
- speed[axis] = 0;
2195
- direction[axis] = 0;
2196
- }
2197
- }
2198
-
2199
- if (speed.x > 0 || speed.y > 0) {
2200
- clearAutoScrollInterval();
2201
- scrollContainerRef.current = scrollContainer;
2202
- setAutoScrollInterval(autoScroll, interval);
2203
- scrollSpeed.current = speed;
2204
- scrollDirection.current = direction;
2205
- return;
2206
- }
2207
- }
2208
-
2209
- scrollSpeed.current = {
2210
- x: 0,
2211
- y: 0
2212
- };
2213
- scrollDirection.current = {
2214
- x: 0,
2215
- y: 0
2216
- };
2217
- clearAutoScrollInterval();
2218
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
2219
- [acceleration, autoScroll, canScroll, clearAutoScrollInterval, enabled, interval, // eslint-disable-next-line react-hooks/exhaustive-deps
2220
- JSON.stringify(rect), // eslint-disable-next-line react-hooks/exhaustive-deps
2221
- JSON.stringify(scrollIntent), setAutoScrollInterval, scrollableAncestors, sortedScrollableAncestors, scrollableAncestorRects, // eslint-disable-next-line react-hooks/exhaustive-deps
2222
- JSON.stringify(threshold)]);
2223
- }
2224
- const defaultScrollIntent = {
2225
- x: {
2226
- [Direction.Backward]: false,
2227
- [Direction.Forward]: false
2228
- },
2229
- y: {
2230
- [Direction.Backward]: false,
2231
- [Direction.Forward]: false
2232
- }
2233
- };
2234
-
2235
- function useScrollIntent(_ref2) {
2236
- let {
2237
- delta,
2238
- disabled
2239
- } = _ref2;
2240
- const previousDelta = usePrevious(delta);
2241
- return useLazyMemo(previousIntent => {
2242
- if (disabled || !previousDelta || !previousIntent) {
2243
- // Reset scroll intent tracking when auto-scrolling is disabled
2244
- return defaultScrollIntent;
2245
- }
2246
-
2247
- const direction = {
2248
- x: Math.sign(delta.x - previousDelta.x),
2249
- y: Math.sign(delta.y - previousDelta.y)
2250
- }; // Keep track of the user intent to scroll in each direction for both axis
2251
-
2252
- return {
2253
- x: {
2254
- [Direction.Backward]: previousIntent.x[Direction.Backward] || direction.x === -1,
2255
- [Direction.Forward]: previousIntent.x[Direction.Forward] || direction.x === 1
2256
- },
2257
- y: {
2258
- [Direction.Backward]: previousIntent.y[Direction.Backward] || direction.y === -1,
2259
- [Direction.Forward]: previousIntent.y[Direction.Forward] || direction.y === 1
2260
- }
2261
- };
2262
- }, [disabled, delta, previousDelta]);
2263
- }
2264
-
2265
- function useCachedNode(draggableNodes, id) {
2266
- const draggableNode = id != null ? draggableNodes.get(id) : undefined;
2267
- const node = draggableNode ? draggableNode.node.current : null;
2268
- return useLazyMemo(cachedNode => {
2269
- var _ref;
2270
-
2271
- if (id == null) {
2272
- return null;
2273
- } // In some cases, the draggable node can unmount while dragging
2274
- // This is the case for virtualized lists. In those situations,
2275
- // we fall back to the last known value for that node.
2276
-
2277
-
2278
- return (_ref = node != null ? node : cachedNode) != null ? _ref : null;
2279
- }, [node, id]);
2280
- }
2281
-
2282
- function useCombineActivators(sensors, getSyntheticHandler) {
2283
- return useMemo(() => sensors.reduce((accumulator, sensor) => {
2284
- const {
2285
- sensor: Sensor
2286
- } = sensor;
2287
- const sensorActivators = Sensor.activators.map(activator => ({
2288
- eventName: activator.eventName,
2289
- handler: getSyntheticHandler(activator.handler, sensor)
2290
- }));
2291
- return [...accumulator, ...sensorActivators];
2292
- }, []), [sensors, getSyntheticHandler]);
2293
- }
2294
-
2295
- var MeasuringStrategy;
2296
-
2297
- (function (MeasuringStrategy) {
2298
- MeasuringStrategy[MeasuringStrategy["Always"] = 0] = "Always";
2299
- MeasuringStrategy[MeasuringStrategy["BeforeDragging"] = 1] = "BeforeDragging";
2300
- MeasuringStrategy[MeasuringStrategy["WhileDragging"] = 2] = "WhileDragging";
2301
- })(MeasuringStrategy || (MeasuringStrategy = {}));
2302
-
2303
- var MeasuringFrequency;
2304
-
2305
- (function (MeasuringFrequency) {
2306
- MeasuringFrequency["Optimized"] = "optimized";
2307
- })(MeasuringFrequency || (MeasuringFrequency = {}));
2308
-
2309
- const defaultValue = /*#__PURE__*/new Map();
2310
- function useDroppableMeasuring(containers, _ref) {
2311
- let {
2312
- dragging,
2313
- dependencies,
2314
- config
2315
- } = _ref;
2316
- const [queue, setQueue] = useState(null);
2317
- const {
2318
- frequency,
2319
- measure,
2320
- strategy
2321
- } = config;
2322
- const containersRef = useRef(containers);
2323
- const disabled = isDisabled();
2324
- const disabledRef = useLatestValue(disabled);
2325
- const measureDroppableContainers = useCallback(function (ids) {
2326
- if (ids === void 0) {
2327
- ids = [];
2328
- }
2329
-
2330
- if (disabledRef.current) {
2331
- return;
2332
- }
2333
-
2334
- setQueue(value => {
2335
- if (value === null) {
2336
- return ids;
2337
- }
2338
-
2339
- return value.concat(ids.filter(id => !value.includes(id)));
2340
- });
2341
- }, [disabledRef]);
2342
- const timeoutId = useRef(null);
2343
- const droppableRects = useLazyMemo(previousValue => {
2344
- if (disabled && !dragging) {
2345
- return defaultValue;
2346
- }
2347
-
2348
- if (!previousValue || previousValue === defaultValue || containersRef.current !== containers || queue != null) {
2349
- const map = new Map();
2350
-
2351
- for (let container of containers) {
2352
- if (!container) {
2353
- continue;
2354
- }
2355
-
2356
- if (queue && queue.length > 0 && !queue.includes(container.id) && container.rect.current) {
2357
- // This container does not need to be re-measured
2358
- map.set(container.id, container.rect.current);
2359
- continue;
2360
- }
2361
-
2362
- const node = container.node.current;
2363
- const rect = node ? new Rect(measure(node), node) : null;
2364
- container.rect.current = rect;
2365
-
2366
- if (rect) {
2367
- map.set(container.id, rect);
2368
- }
2369
- }
2370
-
2371
- return map;
2372
- }
2373
-
2374
- return previousValue;
2375
- }, [containers, queue, dragging, disabled, measure]);
2376
- useEffect(() => {
2377
- containersRef.current = containers;
2378
- }, [containers]);
2379
- useEffect(() => {
2380
- if (disabled) {
2381
- return;
2382
- }
2383
-
2384
- measureDroppableContainers();
2385
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
2386
- [dragging, disabled]);
2387
- useEffect(() => {
2388
- if (queue && queue.length > 0) {
2389
- setQueue(null);
2390
- }
2391
- }, //eslint-disable-next-line react-hooks/exhaustive-deps
2392
- [JSON.stringify(queue)]);
2393
- useEffect(() => {
2394
- if (disabled || typeof frequency !== 'number' || timeoutId.current !== null) {
2395
- return;
2396
- }
2397
-
2398
- timeoutId.current = setTimeout(() => {
2399
- measureDroppableContainers();
2400
- timeoutId.current = null;
2401
- }, frequency);
2402
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
2403
- [frequency, disabled, measureDroppableContainers, ...dependencies]);
2404
- return {
2405
- droppableRects,
2406
- measureDroppableContainers,
2407
- measuringScheduled: queue != null
2408
- };
2409
-
2410
- function isDisabled() {
2411
- switch (strategy) {
2412
- case MeasuringStrategy.Always:
2413
- return false;
2414
-
2415
- case MeasuringStrategy.BeforeDragging:
2416
- return dragging;
2417
-
2418
- default:
2419
- return !dragging;
2420
- }
2421
- }
2422
- }
2423
-
2424
- function useInitialValue(value, computeFn) {
2425
- return useLazyMemo(previousValue => {
2426
- if (!value) {
2427
- return null;
2428
- }
2429
-
2430
- if (previousValue) {
2431
- return previousValue;
2432
- }
2433
-
2434
- return typeof computeFn === 'function' ? computeFn(value) : value;
2435
- }, [computeFn, value]);
2436
- }
2437
-
2438
- function useInitialRect(node, measure) {
2439
- return useInitialValue(node, measure);
2440
- }
2441
-
2442
- /**
2443
- * Returns a new MutationObserver instance.
2444
- * If `MutationObserver` is undefined in the execution environment, returns `undefined`.
2445
- */
2446
-
2447
- function useMutationObserver(_ref) {
2448
- let {
2449
- callback,
2450
- disabled
2451
- } = _ref;
2452
- const handleMutations = useEvent(callback);
2453
- const mutationObserver = useMemo(() => {
2454
- if (disabled || typeof window === 'undefined' || typeof window.MutationObserver === 'undefined') {
2455
- return undefined;
2456
- }
2457
-
2458
- const {
2459
- MutationObserver
2460
- } = window;
2461
- return new MutationObserver(handleMutations);
2462
- }, [handleMutations, disabled]);
2463
- useEffect(() => {
2464
- return () => mutationObserver == null ? void 0 : mutationObserver.disconnect();
2465
- }, [mutationObserver]);
2466
- return mutationObserver;
2467
- }
2468
-
2469
- /**
2470
- * Returns a new ResizeObserver instance bound to the `onResize` callback.
2471
- * If `ResizeObserver` is undefined in the execution environment, returns `undefined`.
2472
- */
2473
-
2474
- function useResizeObserver(_ref) {
2475
- let {
2476
- callback,
2477
- disabled
2478
- } = _ref;
2479
- const handleResize = useEvent(callback);
2480
- const resizeObserver = useMemo(() => {
2481
- if (disabled || typeof window === 'undefined' || typeof window.ResizeObserver === 'undefined') {
2482
- return undefined;
2483
- }
2484
-
2485
- const {
2486
- ResizeObserver
2487
- } = window;
2488
- return new ResizeObserver(handleResize);
2489
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
2490
- [disabled]);
2491
- useEffect(() => {
2492
- return () => resizeObserver == null ? void 0 : resizeObserver.disconnect();
2493
- }, [resizeObserver]);
2494
- return resizeObserver;
2495
- }
2496
-
2497
- function defaultMeasure(element) {
2498
- return new Rect(getClientRect(element), element);
2499
- }
2500
-
2501
- function useRect(element, measure, fallbackRect) {
2502
- if (measure === void 0) {
2503
- measure = defaultMeasure;
2504
- }
2505
-
2506
- const [rect, setRect] = useState(null);
2507
-
2508
- function measureRect() {
2509
- setRect(currentRect => {
2510
- if (!element) {
2511
- return null;
2512
- }
2513
-
2514
- if (element.isConnected === false) {
2515
- var _ref;
2516
-
2517
- // Fall back to last rect we measured if the element is
2518
- // no longer connected to the DOM.
2519
- return (_ref = currentRect != null ? currentRect : fallbackRect) != null ? _ref : null;
2520
- }
2521
-
2522
- const newRect = measure(element);
2523
-
2524
- if (JSON.stringify(currentRect) === JSON.stringify(newRect)) {
2525
- return currentRect;
2526
- }
2527
-
2528
- return newRect;
2529
- });
2530
- }
2531
-
2532
- const mutationObserver = useMutationObserver({
2533
- callback(records) {
2534
- if (!element) {
2535
- return;
2536
- }
2537
-
2538
- for (const record of records) {
2539
- const {
2540
- type,
2541
- target
2542
- } = record;
2543
-
2544
- if (type === 'childList' && target instanceof HTMLElement && target.contains(element)) {
2545
- measureRect();
2546
- break;
2547
- }
2548
- }
2549
- }
2550
-
2551
- });
2552
- const resizeObserver = useResizeObserver({
2553
- callback: measureRect
2554
- });
2555
- useIsomorphicLayoutEffect(() => {
2556
- measureRect();
2557
-
2558
- if (element) {
2559
- resizeObserver == null ? void 0 : resizeObserver.observe(element);
2560
- mutationObserver == null ? void 0 : mutationObserver.observe(document.body, {
2561
- childList: true,
2562
- subtree: true
2563
- });
2564
- } else {
2565
- resizeObserver == null ? void 0 : resizeObserver.disconnect();
2566
- mutationObserver == null ? void 0 : mutationObserver.disconnect();
2567
- }
2568
- }, [element]);
2569
- return rect;
2570
- }
2571
-
2572
- function useRectDelta(rect) {
2573
- const initialRect = useInitialValue(rect);
2574
- return getRectDelta(rect, initialRect);
2575
- }
2576
-
2577
- const defaultValue$1 = [];
2578
- function useScrollableAncestors(node) {
2579
- const previousNode = useRef(node);
2580
- const ancestors = useLazyMemo(previousValue => {
2581
- if (!node) {
2582
- return defaultValue$1;
2583
- }
2584
-
2585
- if (previousValue && previousValue !== defaultValue$1 && node && previousNode.current && node.parentNode === previousNode.current.parentNode) {
2586
- return previousValue;
2587
- }
2588
-
2589
- return getScrollableAncestors(node);
2590
- }, [node]);
2591
- useEffect(() => {
2592
- previousNode.current = node;
2593
- }, [node]);
2594
- return ancestors;
2595
- }
2596
-
2597
- function useScrollOffsets(elements) {
2598
- const [scrollCoordinates, setScrollCoordinates] = useState(null);
2599
- const prevElements = useRef(elements); // To-do: Throttle the handleScroll callback
2600
-
2601
- const handleScroll = useCallback(event => {
2602
- const scrollingElement = getScrollableElement(event.target);
2603
-
2604
- if (!scrollingElement) {
2605
- return;
2606
- }
2607
-
2608
- setScrollCoordinates(scrollCoordinates => {
2609
- if (!scrollCoordinates) {
2610
- return null;
2611
- }
2612
-
2613
- scrollCoordinates.set(scrollingElement, getScrollCoordinates(scrollingElement));
2614
- return new Map(scrollCoordinates);
2615
- });
2616
- }, []);
2617
- useEffect(() => {
2618
- const previousElements = prevElements.current;
2619
-
2620
- if (elements !== previousElements) {
2621
- cleanup(previousElements);
2622
- const entries = elements.map(element => {
2623
- const scrollableElement = getScrollableElement(element);
2624
-
2625
- if (scrollableElement) {
2626
- scrollableElement.addEventListener('scroll', handleScroll, {
2627
- passive: true
2628
- });
2629
- return [scrollableElement, getScrollCoordinates(scrollableElement)];
2630
- }
2631
-
2632
- return null;
2633
- }).filter(entry => entry != null);
2634
- setScrollCoordinates(entries.length ? new Map(entries) : null);
2635
- prevElements.current = elements;
2636
- }
2637
-
2638
- return () => {
2639
- cleanup(elements);
2640
- cleanup(previousElements);
2641
- };
2642
-
2643
- function cleanup(elements) {
2644
- elements.forEach(element => {
2645
- const scrollableElement = getScrollableElement(element);
2646
- scrollableElement == null ? void 0 : scrollableElement.removeEventListener('scroll', handleScroll);
2647
- });
2648
- }
2649
- }, [handleScroll, elements]);
2650
- return useMemo(() => {
2651
- if (elements.length) {
2652
- return scrollCoordinates ? Array.from(scrollCoordinates.values()).reduce((acc, coordinates) => add(acc, coordinates), defaultCoordinates) : getScrollOffsets(elements);
2653
- }
2654
-
2655
- return defaultCoordinates;
2656
- }, [elements, scrollCoordinates]);
2657
- }
2658
-
2659
- function useScrollOffsetsDelta(scrollOffsets, dependencies) {
2660
- if (dependencies === void 0) {
2661
- dependencies = [];
2662
- }
2663
-
2664
- const initialScrollOffsets = useRef(null);
2665
- useEffect(() => {
2666
- initialScrollOffsets.current = null;
2667
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
2668
- dependencies);
2669
- useEffect(() => {
2670
- const hasScrollOffsets = scrollOffsets !== defaultCoordinates;
2671
-
2672
- if (hasScrollOffsets && !initialScrollOffsets.current) {
2673
- initialScrollOffsets.current = scrollOffsets;
2674
- }
2675
-
2676
- if (!hasScrollOffsets && initialScrollOffsets.current) {
2677
- initialScrollOffsets.current = null;
2678
- }
2679
- }, [scrollOffsets]);
2680
- return initialScrollOffsets.current ? subtract(scrollOffsets, initialScrollOffsets.current) : defaultCoordinates;
2681
- }
2682
-
2683
- function useSensorSetup(sensors) {
2684
- useEffect(() => {
2685
- if (!canUseDOM) {
2686
- return;
2687
- }
2688
-
2689
- const teardownFns = sensors.map(_ref => {
2690
- let {
2691
- sensor
2692
- } = _ref;
2693
- return sensor.setup == null ? void 0 : sensor.setup();
2694
- });
2695
- return () => {
2696
- for (const teardown of teardownFns) {
2697
- teardown == null ? void 0 : teardown();
2698
- }
2699
- };
2700
- }, // TO-DO: Sensors length could theoretically change which would not be a valid dependency
2701
- // eslint-disable-next-line react-hooks/exhaustive-deps
2702
- sensors.map(_ref2 => {
2703
- let {
2704
- sensor
2705
- } = _ref2;
2706
- return sensor;
2707
- }));
2708
- }
2709
-
2710
- function useSyntheticListeners(listeners, id) {
2711
- return useMemo(() => {
2712
- return listeners.reduce((acc, _ref) => {
2713
- let {
2714
- eventName,
2715
- handler
2716
- } = _ref;
2717
-
2718
- acc[eventName] = event => {
2719
- handler(event, id);
2720
- };
2721
-
2722
- return acc;
2723
- }, {});
2724
- }, [listeners, id]);
2725
- }
2726
-
2727
- function useWindowRect(element) {
2728
- return useMemo(() => element ? getWindowClientRect(element) : null, [element]);
2729
- }
2730
-
2731
- const defaultValue$2 = [];
2732
- function useRects(elements, measure) {
2733
- if (measure === void 0) {
2734
- measure = getClientRect;
2735
- }
2736
-
2737
- const [firstElement] = elements;
2738
- const windowRect = useWindowRect(firstElement ? getWindow(firstElement) : null);
2739
- const [rects, setRects] = useState(defaultValue$2);
2740
-
2741
- function measureRects() {
2742
- setRects(() => {
2743
- if (!elements.length) {
2744
- return defaultValue$2;
2745
- }
2746
-
2747
- return elements.map(element => isDocumentScrollingElement(element) ? windowRect : new Rect(measure(element), element));
2748
- });
2749
- }
2750
-
2751
- const resizeObserver = useResizeObserver({
2752
- callback: measureRects
2753
- });
2754
- useIsomorphicLayoutEffect(() => {
2755
- resizeObserver == null ? void 0 : resizeObserver.disconnect();
2756
- measureRects();
2757
- elements.forEach(element => resizeObserver == null ? void 0 : resizeObserver.observe(element));
2758
- }, [elements]);
2759
- return rects;
2760
- }
2761
-
2762
- function getMeasurableNode(node) {
2763
- if (!node) {
2764
- return null;
2765
- }
2766
-
2767
- if (node.children.length > 1) {
2768
- return node;
2769
- }
2770
-
2771
- const firstChild = node.children[0];
2772
- return isHTMLElement(firstChild) ? firstChild : node;
2773
- }
2774
-
2775
- function useDragOverlayMeasuring(_ref) {
2776
- let {
2777
- measure
2778
- } = _ref;
2779
- const [rect, setRect] = useState(null);
2780
- const handleResize = useCallback(entries => {
2781
- for (const {
2782
- target
2783
- } of entries) {
2784
- if (isHTMLElement(target)) {
2785
- setRect(rect => {
2786
- const newRect = measure(target);
2787
- return rect ? { ...rect,
2788
- width: newRect.width,
2789
- height: newRect.height
2790
- } : newRect;
2791
- });
2792
- break;
2793
- }
2794
- }
2795
- }, [measure]);
2796
- const resizeObserver = useResizeObserver({
2797
- callback: handleResize
2798
- });
2799
- const handleNodeChange = useCallback(element => {
2800
- const node = getMeasurableNode(element);
2801
- resizeObserver == null ? void 0 : resizeObserver.disconnect();
2802
-
2803
- if (node) {
2804
- resizeObserver == null ? void 0 : resizeObserver.observe(node);
2805
- }
2806
-
2807
- setRect(node ? measure(node) : null);
2808
- }, [measure, resizeObserver]);
2809
- const [nodeRef, setRef] = useNodeRef(handleNodeChange);
2810
- return useMemo(() => ({
2811
- nodeRef,
2812
- rect,
2813
- setRef
2814
- }), [rect, nodeRef, setRef]);
2815
- }
2816
-
2817
- const defaultSensors = [{
2818
- sensor: PointerSensor,
2819
- options: {}
2820
- }, {
2821
- sensor: KeyboardSensor,
2822
- options: {}
2823
- }];
2824
- const defaultData = {
2825
- current: {}
2826
- };
2827
- const defaultMeasuringConfiguration = {
2828
- draggable: {
2829
- measure: getTransformAgnosticClientRect
2830
- },
2831
- droppable: {
2832
- measure: getTransformAgnosticClientRect,
2833
- strategy: MeasuringStrategy.WhileDragging,
2834
- frequency: MeasuringFrequency.Optimized
2835
- },
2836
- dragOverlay: {
2837
- measure: getClientRect
2838
- }
2839
- };
2840
-
2841
- class DroppableContainersMap extends Map {
2842
- get(id) {
2843
- var _super$get;
2844
-
2845
- return id != null ? (_super$get = super.get(id)) != null ? _super$get : undefined : undefined;
2846
- }
2847
-
2848
- toArray() {
2849
- return Array.from(this.values());
2850
- }
2851
-
2852
- getEnabled() {
2853
- return this.toArray().filter(_ref => {
2854
- let {
2855
- disabled
2856
- } = _ref;
2857
- return !disabled;
2858
- });
2859
- }
2860
-
2861
- getNodeFor(id) {
2862
- var _this$get$node$curren, _this$get;
2863
-
2864
- return (_this$get$node$curren = (_this$get = this.get(id)) == null ? void 0 : _this$get.node.current) != null ? _this$get$node$curren : undefined;
2865
- }
2866
-
2867
- }
2868
-
2869
- const defaultPublicContext = {
2870
- activatorEvent: null,
2871
- active: null,
2872
- activeNode: null,
2873
- activeNodeRect: null,
2874
- collisions: null,
2875
- containerNodeRect: null,
2876
- draggableNodes: /*#__PURE__*/new Map(),
2877
- droppableRects: /*#__PURE__*/new Map(),
2878
- droppableContainers: /*#__PURE__*/new DroppableContainersMap(),
2879
- over: null,
2880
- dragOverlay: {
2881
- nodeRef: {
2882
- current: null
2883
- },
2884
- rect: null,
2885
- setRef: noop
2886
- },
2887
- scrollableAncestors: [],
2888
- scrollableAncestorRects: [],
2889
- measuringConfiguration: defaultMeasuringConfiguration,
2890
- measureDroppableContainers: noop,
2891
- windowRect: null,
2892
- measuringScheduled: false
2893
- };
2894
- const defaultInternalContext = {
2895
- activatorEvent: null,
2896
- activators: [],
2897
- active: null,
2898
- activeNodeRect: null,
2899
- ariaDescribedById: {
2900
- draggable: ''
2901
- },
2902
- dispatch: noop,
2903
- draggableNodes: /*#__PURE__*/new Map(),
2904
- over: null,
2905
- measureDroppableContainers: noop
2906
- };
2907
- const InternalContext = /*#__PURE__*/createContext(defaultInternalContext);
2908
- const PublicContext = /*#__PURE__*/createContext(defaultPublicContext);
2909
-
2910
- function getInitialState() {
2911
- return {
2912
- draggable: {
2913
- active: null,
2914
- initialCoordinates: {
2915
- x: 0,
2916
- y: 0
2917
- },
2918
- nodes: new Map(),
2919
- translate: {
2920
- x: 0,
2921
- y: 0
2922
- }
2923
- },
2924
- droppable: {
2925
- containers: new DroppableContainersMap()
2926
- }
2927
- };
2928
- }
2929
- function reducer(state, action) {
2930
- switch (action.type) {
2931
- case Action.DragStart:
2932
- return { ...state,
2933
- draggable: { ...state.draggable,
2934
- initialCoordinates: action.initialCoordinates,
2935
- active: action.active
2936
- }
2937
- };
2938
-
2939
- case Action.DragMove:
2940
- if (state.draggable.active == null) {
2941
- return state;
2942
- }
2943
-
2944
- return { ...state,
2945
- draggable: { ...state.draggable,
2946
- translate: {
2947
- x: action.coordinates.x - state.draggable.initialCoordinates.x,
2948
- y: action.coordinates.y - state.draggable.initialCoordinates.y
2949
- }
2950
- }
2951
- };
2952
-
2953
- case Action.DragEnd:
2954
- case Action.DragCancel:
2955
- return { ...state,
2956
- draggable: { ...state.draggable,
2957
- active: null,
2958
- initialCoordinates: {
2959
- x: 0,
2960
- y: 0
2961
- },
2962
- translate: {
2963
- x: 0,
2964
- y: 0
2965
- }
2966
- }
2967
- };
2968
-
2969
- case Action.RegisterDroppable:
2970
- {
2971
- const {
2972
- element
2973
- } = action;
2974
- const {
2975
- id
2976
- } = element;
2977
- const containers = new DroppableContainersMap(state.droppable.containers);
2978
- containers.set(id, element);
2979
- return { ...state,
2980
- droppable: { ...state.droppable,
2981
- containers
2982
- }
2983
- };
2984
- }
2985
-
2986
- case Action.SetDroppableDisabled:
2987
- {
2988
- const {
2989
- id,
2990
- key,
2991
- disabled
2992
- } = action;
2993
- const element = state.droppable.containers.get(id);
2994
-
2995
- if (!element || key !== element.key) {
2996
- return state;
2997
- }
2998
-
2999
- const containers = new DroppableContainersMap(state.droppable.containers);
3000
- containers.set(id, { ...element,
3001
- disabled
3002
- });
3003
- return { ...state,
3004
- droppable: { ...state.droppable,
3005
- containers
3006
- }
3007
- };
3008
- }
3009
-
3010
- case Action.UnregisterDroppable:
3011
- {
3012
- const {
3013
- id,
3014
- key
3015
- } = action;
3016
- const element = state.droppable.containers.get(id);
3017
-
3018
- if (!element || key !== element.key) {
3019
- return state;
3020
- }
3021
-
3022
- const containers = new DroppableContainersMap(state.droppable.containers);
3023
- containers.delete(id);
3024
- return { ...state,
3025
- droppable: { ...state.droppable,
3026
- containers
3027
- }
3028
- };
3029
- }
3030
-
3031
- default:
3032
- {
3033
- return state;
3034
- }
3035
- }
3036
- }
3037
-
3038
- function RestoreFocus(_ref) {
3039
- let {
3040
- disabled
3041
- } = _ref;
3042
- const {
3043
- active,
3044
- activatorEvent,
3045
- draggableNodes
3046
- } = useContext(InternalContext);
3047
- const previousActivatorEvent = usePrevious(activatorEvent);
3048
- const previousActiveId = usePrevious(active == null ? void 0 : active.id); // Restore keyboard focus on the activator node
3049
-
3050
- useEffect(() => {
3051
- if (disabled) {
3052
- return;
3053
- }
3054
-
3055
- if (!activatorEvent && previousActivatorEvent && previousActiveId != null) {
3056
- if (!isKeyboardEvent(previousActivatorEvent)) {
3057
- return;
3058
- }
3059
-
3060
- if (document.activeElement === previousActivatorEvent.target) {
3061
- // No need to restore focus
3062
- return;
3063
- }
3064
-
3065
- const draggableNode = draggableNodes.get(previousActiveId);
3066
-
3067
- if (!draggableNode) {
3068
- return;
3069
- }
3070
-
3071
- const {
3072
- activatorNode,
3073
- node
3074
- } = draggableNode;
3075
-
3076
- if (!activatorNode.current && !node.current) {
3077
- return;
3078
- }
3079
-
3080
- requestAnimationFrame(() => {
3081
- for (const element of [activatorNode.current, node.current]) {
3082
- if (!element) {
3083
- continue;
3084
- }
3085
-
3086
- const focusableNode = findFirstFocusableNode(element);
3087
-
3088
- if (focusableNode) {
3089
- focusableNode.focus();
3090
- break;
3091
- }
3092
- }
3093
- });
3094
- }
3095
- }, [activatorEvent, disabled, draggableNodes, previousActiveId, previousActivatorEvent]);
3096
- return null;
3097
- }
3098
-
3099
- function applyModifiers(modifiers, _ref) {
3100
- let {
3101
- transform,
3102
- ...args
3103
- } = _ref;
3104
- return modifiers != null && modifiers.length ? modifiers.reduce((accumulator, modifier) => {
3105
- return modifier({
3106
- transform: accumulator,
3107
- ...args
3108
- });
3109
- }, transform) : transform;
3110
- }
3111
-
3112
- function useMeasuringConfiguration(config) {
3113
- return useMemo(() => ({
3114
- draggable: { ...defaultMeasuringConfiguration.draggable,
3115
- ...(config == null ? void 0 : config.draggable)
3116
- },
3117
- droppable: { ...defaultMeasuringConfiguration.droppable,
3118
- ...(config == null ? void 0 : config.droppable)
3119
- },
3120
- dragOverlay: { ...defaultMeasuringConfiguration.dragOverlay,
3121
- ...(config == null ? void 0 : config.dragOverlay)
3122
- }
3123
- }), // eslint-disable-next-line react-hooks/exhaustive-deps
3124
- [config == null ? void 0 : config.draggable, config == null ? void 0 : config.droppable, config == null ? void 0 : config.dragOverlay]);
3125
- }
3126
-
3127
- function useLayoutShiftScrollCompensation(_ref) {
3128
- let {
3129
- activeNode,
3130
- measure,
3131
- initialRect,
3132
- config = true
3133
- } = _ref;
3134
- const initialized = useRef(false);
3135
- const {
3136
- x,
3137
- y
3138
- } = typeof config === 'boolean' ? {
3139
- x: config,
3140
- y: config
3141
- } : config;
3142
- useIsomorphicLayoutEffect(() => {
3143
- const disabled = !x && !y;
3144
-
3145
- if (disabled || !activeNode) {
3146
- initialized.current = false;
3147
- return;
3148
- }
3149
-
3150
- if (initialized.current || !initialRect) {
3151
- // Return early if layout shift scroll compensation was already attempted
3152
- // or if there is no initialRect to compare to.
3153
- return;
3154
- } // Get the most up to date node ref for the active draggable
3155
-
3156
-
3157
- const node = activeNode == null ? void 0 : activeNode.node.current;
3158
-
3159
- if (!node || node.isConnected === false) {
3160
- // Return early if there is no attached node ref or if the node is
3161
- // disconnected from the document.
3162
- return;
3163
- }
3164
-
3165
- const rect = measure(node);
3166
- const rectDelta = getRectDelta(rect, initialRect);
3167
-
3168
- if (!x) {
3169
- rectDelta.x = 0;
3170
- }
3171
-
3172
- if (!y) {
3173
- rectDelta.y = 0;
3174
- } // Only perform layout shift scroll compensation once
3175
-
3176
-
3177
- initialized.current = true;
3178
-
3179
- if (Math.abs(rectDelta.x) > 0 || Math.abs(rectDelta.y) > 0) {
3180
- const firstScrollableAncestor = getFirstScrollableAncestor(node);
3181
-
3182
- if (firstScrollableAncestor) {
3183
- firstScrollableAncestor.scrollBy({
3184
- top: rectDelta.y,
3185
- left: rectDelta.x
3186
- });
3187
- }
3188
- }
3189
- }, [activeNode, x, y, initialRect, measure]);
3190
- }
3191
-
3192
- const ActiveDraggableContext = /*#__PURE__*/createContext({ ...defaultCoordinates,
3193
- scaleX: 1,
3194
- scaleY: 1
3195
- });
3196
- var Status;
3197
-
3198
- (function (Status) {
3199
- Status[Status["Uninitialized"] = 0] = "Uninitialized";
3200
- Status[Status["Initializing"] = 1] = "Initializing";
3201
- Status[Status["Initialized"] = 2] = "Initialized";
3202
- })(Status || (Status = {}));
3203
-
3204
- const DndContext = /*#__PURE__*/memo(function DndContext(_ref) {
3205
- var _sensorContext$curren, _dragOverlay$nodeRef$, _dragOverlay$rect, _over$rect;
3206
-
3207
- let {
3208
- id,
3209
- accessibility,
3210
- autoScroll = true,
3211
- children,
3212
- sensors = defaultSensors,
3213
- collisionDetection = rectIntersection,
3214
- measuring,
3215
- modifiers,
3216
- ...props
3217
- } = _ref;
3218
- const store = useReducer(reducer, undefined, getInitialState);
3219
- const [state, dispatch] = store;
3220
- const [dispatchMonitorEvent, registerMonitorListener] = useDndMonitorProvider();
3221
- const [status, setStatus] = useState(Status.Uninitialized);
3222
- const isInitialized = status === Status.Initialized;
3223
- const {
3224
- draggable: {
3225
- active: activeId,
3226
- nodes: draggableNodes,
3227
- translate
3228
- },
3229
- droppable: {
3230
- containers: droppableContainers
3231
- }
3232
- } = state;
3233
- const node = activeId != null ? draggableNodes.get(activeId) : null;
3234
- const activeRects = useRef({
3235
- initial: null,
3236
- translated: null
3237
- });
3238
- const active = useMemo(() => {
3239
- var _node$data;
3240
-
3241
- return activeId != null ? {
3242
- id: activeId,
3243
- // It's possible for the active node to unmount while dragging
3244
- data: (_node$data = node == null ? void 0 : node.data) != null ? _node$data : defaultData,
3245
- rect: activeRects
3246
- } : null;
3247
- }, [activeId, node]);
3248
- const activeRef = useRef(null);
3249
- const [activeSensor, setActiveSensor] = useState(null);
3250
- const [activatorEvent, setActivatorEvent] = useState(null);
3251
- const latestProps = useLatestValue(props, Object.values(props));
3252
- const draggableDescribedById = useUniqueId("DndDescribedBy", id);
3253
- const enabledDroppableContainers = useMemo(() => droppableContainers.getEnabled(), [droppableContainers]);
3254
- const measuringConfiguration = useMeasuringConfiguration(measuring);
3255
- const {
3256
- droppableRects,
3257
- measureDroppableContainers,
3258
- measuringScheduled
3259
- } = useDroppableMeasuring(enabledDroppableContainers, {
3260
- dragging: isInitialized,
3261
- dependencies: [translate.x, translate.y],
3262
- config: measuringConfiguration.droppable
3263
- });
3264
- const activeNode = useCachedNode(draggableNodes, activeId);
3265
- const activationCoordinates = useMemo(() => activatorEvent ? getEventCoordinates(activatorEvent) : null, [activatorEvent]);
3266
- const autoScrollOptions = getAutoScrollerOptions();
3267
- const initialActiveNodeRect = useInitialRect(activeNode, measuringConfiguration.draggable.measure);
3268
- useLayoutShiftScrollCompensation({
3269
- activeNode: activeId != null ? draggableNodes.get(activeId) : null,
3270
- config: autoScrollOptions.layoutShiftCompensation,
3271
- initialRect: initialActiveNodeRect,
3272
- measure: measuringConfiguration.draggable.measure
3273
- });
3274
- const activeNodeRect = useRect(activeNode, measuringConfiguration.draggable.measure, initialActiveNodeRect);
3275
- const containerNodeRect = useRect(activeNode ? activeNode.parentElement : null);
3276
- const sensorContext = useRef({
3277
- activatorEvent: null,
3278
- active: null,
3279
- activeNode,
3280
- collisionRect: null,
3281
- collisions: null,
3282
- droppableRects,
3283
- draggableNodes,
3284
- draggingNode: null,
3285
- draggingNodeRect: null,
3286
- droppableContainers,
3287
- over: null,
3288
- scrollableAncestors: [],
3289
- scrollAdjustedTranslate: null
3290
- });
3291
- const overNode = droppableContainers.getNodeFor((_sensorContext$curren = sensorContext.current.over) == null ? void 0 : _sensorContext$curren.id);
3292
- const dragOverlay = useDragOverlayMeasuring({
3293
- measure: measuringConfiguration.dragOverlay.measure
3294
- }); // Use the rect of the drag overlay if it is mounted
3295
-
3296
- const draggingNode = (_dragOverlay$nodeRef$ = dragOverlay.nodeRef.current) != null ? _dragOverlay$nodeRef$ : activeNode;
3297
- const draggingNodeRect = isInitialized ? (_dragOverlay$rect = dragOverlay.rect) != null ? _dragOverlay$rect : activeNodeRect : null;
3298
- const usesDragOverlay = Boolean(dragOverlay.nodeRef.current && dragOverlay.rect); // The delta between the previous and new position of the draggable node
3299
- // is only relevant when there is no drag overlay
3300
-
3301
- const nodeRectDelta = useRectDelta(usesDragOverlay ? null : activeNodeRect); // Get the window rect of the dragging node
3302
-
3303
- const windowRect = useWindowRect(draggingNode ? getWindow(draggingNode) : null); // Get scrollable ancestors of the dragging node
3304
-
3305
- const scrollableAncestors = useScrollableAncestors(isInitialized ? overNode != null ? overNode : activeNode : null);
3306
- const scrollableAncestorRects = useRects(scrollableAncestors); // Apply modifiers
3307
-
3308
- const modifiedTranslate = applyModifiers(modifiers, {
3309
- transform: {
3310
- x: translate.x - nodeRectDelta.x,
3311
- y: translate.y - nodeRectDelta.y,
3312
- scaleX: 1,
3313
- scaleY: 1
3314
- },
3315
- activatorEvent,
3316
- active,
3317
- activeNodeRect,
3318
- containerNodeRect,
3319
- draggingNodeRect,
3320
- over: sensorContext.current.over,
3321
- overlayNodeRect: dragOverlay.rect,
3322
- scrollableAncestors,
3323
- scrollableAncestorRects,
3324
- windowRect
3325
- });
3326
- const pointerCoordinates = activationCoordinates ? add(activationCoordinates, translate) : null;
3327
- const scrollOffsets = useScrollOffsets(scrollableAncestors); // Represents the scroll delta since dragging was initiated
3328
-
3329
- const scrollAdjustment = useScrollOffsetsDelta(scrollOffsets); // Represents the scroll delta since the last time the active node rect was measured
3330
-
3331
- const activeNodeScrollDelta = useScrollOffsetsDelta(scrollOffsets, [activeNodeRect]);
3332
- const scrollAdjustedTranslate = add(modifiedTranslate, scrollAdjustment);
3333
- const collisionRect = draggingNodeRect ? getAdjustedRect(draggingNodeRect, modifiedTranslate) : null;
3334
- const collisions = active && collisionRect ? collisionDetection({
3335
- active,
3336
- collisionRect,
3337
- droppableRects,
3338
- droppableContainers: enabledDroppableContainers,
3339
- pointerCoordinates
3340
- }) : null;
3341
- const overId = getFirstCollision(collisions, 'id');
3342
- const [over, setOver] = useState(null); // When there is no drag overlay used, we need to account for the
3343
- // window scroll delta
3344
-
3345
- const appliedTranslate = usesDragOverlay ? modifiedTranslate : add(modifiedTranslate, activeNodeScrollDelta);
3346
- const transform = adjustScale(appliedTranslate, (_over$rect = over == null ? void 0 : over.rect) != null ? _over$rect : null, activeNodeRect);
3347
- const activeSensorRef = useRef(null);
3348
- const instantiateSensor = useCallback((event, _ref2) => {
3349
- let {
3350
- sensor: Sensor,
3351
- options
3352
- } = _ref2;
3353
-
3354
- if (activeRef.current == null) {
3355
- return;
3356
- }
3357
-
3358
- const activeNode = draggableNodes.get(activeRef.current);
3359
-
3360
- if (!activeNode) {
3361
- return;
3362
- }
3363
-
3364
- const activatorEvent = event.nativeEvent;
3365
- const sensorInstance = new Sensor({
3366
- active: activeRef.current,
3367
- activeNode,
3368
- event: activatorEvent,
3369
- options,
3370
- // Sensors need to be instantiated with refs for arguments that change over time
3371
- // otherwise they are frozen in time with the stale arguments
3372
- context: sensorContext,
3373
-
3374
- onAbort(id) {
3375
- const draggableNode = draggableNodes.get(id);
3376
-
3377
- if (!draggableNode) {
3378
- return;
3379
- }
3380
-
3381
- const {
3382
- onDragAbort
3383
- } = latestProps.current;
3384
- const event = {
3385
- id
3386
- };
3387
- onDragAbort == null ? void 0 : onDragAbort(event);
3388
- dispatchMonitorEvent({
3389
- type: 'onDragAbort',
3390
- event
3391
- });
3392
- },
3393
-
3394
- onPending(id, constraint, initialCoordinates, offset) {
3395
- const draggableNode = draggableNodes.get(id);
3396
-
3397
- if (!draggableNode) {
3398
- return;
3399
- }
3400
-
3401
- const {
3402
- onDragPending
3403
- } = latestProps.current;
3404
- const event = {
3405
- id,
3406
- constraint,
3407
- initialCoordinates,
3408
- offset
3409
- };
3410
- onDragPending == null ? void 0 : onDragPending(event);
3411
- dispatchMonitorEvent({
3412
- type: 'onDragPending',
3413
- event
3414
- });
3415
- },
3416
-
3417
- onStart(initialCoordinates) {
3418
- const id = activeRef.current;
3419
-
3420
- if (id == null) {
3421
- return;
3422
- }
3423
-
3424
- const draggableNode = draggableNodes.get(id);
3425
-
3426
- if (!draggableNode) {
3427
- return;
3428
- }
3429
-
3430
- const {
3431
- onDragStart
3432
- } = latestProps.current;
3433
- const event = {
3434
- activatorEvent,
3435
- active: {
3436
- id,
3437
- data: draggableNode.data,
3438
- rect: activeRects
3439
- }
3440
- };
3441
- unstable_batchedUpdates(() => {
3442
- onDragStart == null ? void 0 : onDragStart(event);
3443
- setStatus(Status.Initializing);
3444
- dispatch({
3445
- type: Action.DragStart,
3446
- initialCoordinates,
3447
- active: id
3448
- });
3449
- dispatchMonitorEvent({
3450
- type: 'onDragStart',
3451
- event
3452
- });
3453
- setActiveSensor(activeSensorRef.current);
3454
- setActivatorEvent(activatorEvent);
3455
- });
3456
- },
3457
-
3458
- onMove(coordinates) {
3459
- dispatch({
3460
- type: Action.DragMove,
3461
- coordinates
3462
- });
3463
- },
3464
-
3465
- onEnd: createHandler(Action.DragEnd),
3466
- onCancel: createHandler(Action.DragCancel)
3467
- });
3468
- activeSensorRef.current = sensorInstance;
3469
-
3470
- function createHandler(type) {
3471
- return async function handler() {
3472
- const {
3473
- active,
3474
- collisions,
3475
- over,
3476
- scrollAdjustedTranslate
3477
- } = sensorContext.current;
3478
- let event = null;
3479
-
3480
- if (active && scrollAdjustedTranslate) {
3481
- const {
3482
- cancelDrop
3483
- } = latestProps.current;
3484
- event = {
3485
- activatorEvent,
3486
- active: active,
3487
- collisions,
3488
- delta: scrollAdjustedTranslate,
3489
- over
3490
- };
3491
-
3492
- if (type === Action.DragEnd && typeof cancelDrop === 'function') {
3493
- const shouldCancel = await Promise.resolve(cancelDrop(event));
3494
-
3495
- if (shouldCancel) {
3496
- type = Action.DragCancel;
3497
- }
3498
- }
3499
- }
3500
-
3501
- activeRef.current = null;
3502
- unstable_batchedUpdates(() => {
3503
- dispatch({
3504
- type
3505
- });
3506
- setStatus(Status.Uninitialized);
3507
- setOver(null);
3508
- setActiveSensor(null);
3509
- setActivatorEvent(null);
3510
- activeSensorRef.current = null;
3511
- const eventName = type === Action.DragEnd ? 'onDragEnd' : 'onDragCancel';
3512
-
3513
- if (event) {
3514
- const handler = latestProps.current[eventName];
3515
- handler == null ? void 0 : handler(event);
3516
- dispatchMonitorEvent({
3517
- type: eventName,
3518
- event
3519
- });
3520
- }
3521
- });
3522
- };
3523
- }
3524
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
3525
- [draggableNodes]);
3526
- const bindActivatorToSensorInstantiator = useCallback((handler, sensor) => {
3527
- return (event, active) => {
3528
- const nativeEvent = event.nativeEvent;
3529
- const activeDraggableNode = draggableNodes.get(active);
3530
-
3531
- if ( // Another sensor is already instantiating
3532
- activeRef.current !== null || // No active draggable
3533
- !activeDraggableNode || // Event has already been captured
3534
- nativeEvent.dndKit || nativeEvent.defaultPrevented) {
3535
- return;
3536
- }
3537
-
3538
- const activationContext = {
3539
- active: activeDraggableNode
3540
- };
3541
- const shouldActivate = handler(event, sensor.options, activationContext);
3542
-
3543
- if (shouldActivate === true) {
3544
- nativeEvent.dndKit = {
3545
- capturedBy: sensor.sensor
3546
- };
3547
- activeRef.current = active;
3548
- instantiateSensor(event, sensor);
3549
- }
3550
- };
3551
- }, [draggableNodes, instantiateSensor]);
3552
- const activators = useCombineActivators(sensors, bindActivatorToSensorInstantiator);
3553
- useSensorSetup(sensors);
3554
- useIsomorphicLayoutEffect(() => {
3555
- if (activeNodeRect && status === Status.Initializing) {
3556
- setStatus(Status.Initialized);
3557
- }
3558
- }, [activeNodeRect, status]);
3559
- useEffect(() => {
3560
- const {
3561
- onDragMove
3562
- } = latestProps.current;
3563
- const {
3564
- active,
3565
- activatorEvent,
3566
- collisions,
3567
- over
3568
- } = sensorContext.current;
3569
-
3570
- if (!active || !activatorEvent) {
3571
- return;
3572
- }
3573
-
3574
- const event = {
3575
- active,
3576
- activatorEvent,
3577
- collisions,
3578
- delta: {
3579
- x: scrollAdjustedTranslate.x,
3580
- y: scrollAdjustedTranslate.y
3581
- },
3582
- over
3583
- };
3584
- unstable_batchedUpdates(() => {
3585
- onDragMove == null ? void 0 : onDragMove(event);
3586
- dispatchMonitorEvent({
3587
- type: 'onDragMove',
3588
- event
3589
- });
3590
- });
3591
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
3592
- [scrollAdjustedTranslate.x, scrollAdjustedTranslate.y]);
3593
- useEffect(() => {
3594
- const {
3595
- active,
3596
- activatorEvent,
3597
- collisions,
3598
- droppableContainers,
3599
- scrollAdjustedTranslate
3600
- } = sensorContext.current;
3601
-
3602
- if (!active || activeRef.current == null || !activatorEvent || !scrollAdjustedTranslate) {
3603
- return;
3604
- }
3605
-
3606
- const {
3607
- onDragOver
3608
- } = latestProps.current;
3609
- const overContainer = droppableContainers.get(overId);
3610
- const over = overContainer && overContainer.rect.current ? {
3611
- id: overContainer.id,
3612
- rect: overContainer.rect.current,
3613
- data: overContainer.data,
3614
- disabled: overContainer.disabled
3615
- } : null;
3616
- const event = {
3617
- active,
3618
- activatorEvent,
3619
- collisions,
3620
- delta: {
3621
- x: scrollAdjustedTranslate.x,
3622
- y: scrollAdjustedTranslate.y
3623
- },
3624
- over
3625
- };
3626
- unstable_batchedUpdates(() => {
3627
- setOver(over);
3628
- onDragOver == null ? void 0 : onDragOver(event);
3629
- dispatchMonitorEvent({
3630
- type: 'onDragOver',
3631
- event
3632
- });
3633
- });
3634
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
3635
- [overId]);
3636
- useIsomorphicLayoutEffect(() => {
3637
- sensorContext.current = {
3638
- activatorEvent,
3639
- active,
3640
- activeNode,
3641
- collisionRect,
3642
- collisions,
3643
- droppableRects,
3644
- draggableNodes,
3645
- draggingNode,
3646
- draggingNodeRect,
3647
- droppableContainers,
3648
- over,
3649
- scrollableAncestors,
3650
- scrollAdjustedTranslate
3651
- };
3652
- activeRects.current = {
3653
- initial: draggingNodeRect,
3654
- translated: collisionRect
3655
- };
3656
- }, [active, activeNode, collisions, collisionRect, draggableNodes, draggingNode, draggingNodeRect, droppableRects, droppableContainers, over, scrollableAncestors, scrollAdjustedTranslate]);
3657
- useAutoScroller({ ...autoScrollOptions,
3658
- delta: translate,
3659
- draggingRect: collisionRect,
3660
- pointerCoordinates,
3661
- scrollableAncestors,
3662
- scrollableAncestorRects
3663
- });
3664
- const publicContext = useMemo(() => {
3665
- const context = {
3666
- active,
3667
- activeNode,
3668
- activeNodeRect,
3669
- activatorEvent,
3670
- collisions,
3671
- containerNodeRect,
3672
- dragOverlay,
3673
- draggableNodes,
3674
- droppableContainers,
3675
- droppableRects,
3676
- over,
3677
- measureDroppableContainers,
3678
- scrollableAncestors,
3679
- scrollableAncestorRects,
3680
- measuringConfiguration,
3681
- measuringScheduled,
3682
- windowRect
3683
- };
3684
- return context;
3685
- }, [active, activeNode, activeNodeRect, activatorEvent, collisions, containerNodeRect, dragOverlay, draggableNodes, droppableContainers, droppableRects, over, measureDroppableContainers, scrollableAncestors, scrollableAncestorRects, measuringConfiguration, measuringScheduled, windowRect]);
3686
- const internalContext = useMemo(() => {
3687
- const context = {
3688
- activatorEvent,
3689
- activators,
3690
- active,
3691
- activeNodeRect,
3692
- ariaDescribedById: {
3693
- draggable: draggableDescribedById
3694
- },
3695
- dispatch,
3696
- draggableNodes,
3697
- over,
3698
- measureDroppableContainers
3699
- };
3700
- return context;
3701
- }, [activatorEvent, activators, active, activeNodeRect, dispatch, draggableDescribedById, draggableNodes, over, measureDroppableContainers]);
3702
- return React__default.createElement(DndMonitorContext.Provider, {
3703
- value: registerMonitorListener
3704
- }, React__default.createElement(InternalContext.Provider, {
3705
- value: internalContext
3706
- }, React__default.createElement(PublicContext.Provider, {
3707
- value: publicContext
3708
- }, React__default.createElement(ActiveDraggableContext.Provider, {
3709
- value: transform
3710
- }, children)), React__default.createElement(RestoreFocus, {
3711
- disabled: (accessibility == null ? void 0 : accessibility.restoreFocus) === false
3712
- })), React__default.createElement(Accessibility, { ...accessibility,
3713
- hiddenTextDescribedById: draggableDescribedById
3714
- }));
3715
-
3716
- function getAutoScrollerOptions() {
3717
- const activeSensorDisablesAutoscroll = (activeSensor == null ? void 0 : activeSensor.autoScrollEnabled) === false;
3718
- const autoScrollGloballyDisabled = typeof autoScroll === 'object' ? autoScroll.enabled === false : autoScroll === false;
3719
- const enabled = isInitialized && !activeSensorDisablesAutoscroll && !autoScrollGloballyDisabled;
3720
-
3721
- if (typeof autoScroll === 'object') {
3722
- return { ...autoScroll,
3723
- enabled
3724
- };
3725
- }
3726
-
3727
- return {
3728
- enabled
3729
- };
3730
- }
3731
- });
3732
-
3733
- const NullContext = /*#__PURE__*/createContext(null);
3734
- const defaultRole = 'button';
3735
- const ID_PREFIX$1 = 'Draggable';
3736
- function useDraggable(_ref) {
3737
- let {
3738
- id,
3739
- data,
3740
- disabled = false,
3741
- attributes
3742
- } = _ref;
3743
- const key = useUniqueId(ID_PREFIX$1);
3744
- const {
3745
- activators,
3746
- activatorEvent,
3747
- active,
3748
- activeNodeRect,
3749
- ariaDescribedById,
3750
- draggableNodes,
3751
- over
3752
- } = useContext(InternalContext);
3753
- const {
3754
- role = defaultRole,
3755
- roleDescription = 'draggable',
3756
- tabIndex = 0
3757
- } = attributes != null ? attributes : {};
3758
- const isDragging = (active == null ? void 0 : active.id) === id;
3759
- const transform = useContext(isDragging ? ActiveDraggableContext : NullContext);
3760
- const [node, setNodeRef] = useNodeRef();
3761
- const [activatorNode, setActivatorNodeRef] = useNodeRef();
3762
- const listeners = useSyntheticListeners(activators, id);
3763
- const dataRef = useLatestValue(data);
3764
- useIsomorphicLayoutEffect(() => {
3765
- draggableNodes.set(id, {
3766
- id,
3767
- key,
3768
- node,
3769
- activatorNode,
3770
- data: dataRef
3771
- });
3772
- return () => {
3773
- const node = draggableNodes.get(id);
3774
-
3775
- if (node && node.key === key) {
3776
- draggableNodes.delete(id);
3777
- }
3778
- };
3779
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
3780
- [draggableNodes, id]);
3781
- const memoizedAttributes = useMemo(() => ({
3782
- role,
3783
- tabIndex,
3784
- 'aria-disabled': disabled,
3785
- 'aria-pressed': isDragging && role === defaultRole ? true : undefined,
3786
- 'aria-roledescription': roleDescription,
3787
- 'aria-describedby': ariaDescribedById.draggable
3788
- }), [disabled, role, tabIndex, isDragging, roleDescription, ariaDescribedById.draggable]);
3789
- return {
3790
- active,
3791
- activatorEvent,
3792
- activeNodeRect,
3793
- attributes: memoizedAttributes,
3794
- isDragging,
3795
- listeners: disabled ? undefined : listeners,
3796
- node,
3797
- over,
3798
- setNodeRef,
3799
- setActivatorNodeRef,
3800
- transform
3801
- };
3802
- }
3803
-
3804
- function useDndContext() {
3805
- return useContext(PublicContext);
3806
- }
3807
-
3808
- const ID_PREFIX$1$1 = 'Droppable';
3809
- const defaultResizeObserverConfig = {
3810
- timeout: 25
3811
- };
3812
- function useDroppable(_ref) {
3813
- let {
3814
- data,
3815
- disabled = false,
3816
- id,
3817
- resizeObserverConfig
3818
- } = _ref;
3819
- const key = useUniqueId(ID_PREFIX$1$1);
3820
- const {
3821
- active,
3822
- dispatch,
3823
- over,
3824
- measureDroppableContainers
3825
- } = useContext(InternalContext);
3826
- const previous = useRef({
3827
- disabled
3828
- });
3829
- const resizeObserverConnected = useRef(false);
3830
- const rect = useRef(null);
3831
- const callbackId = useRef(null);
3832
- const {
3833
- disabled: resizeObserverDisabled,
3834
- updateMeasurementsFor,
3835
- timeout: resizeObserverTimeout
3836
- } = { ...defaultResizeObserverConfig,
3837
- ...resizeObserverConfig
3838
- };
3839
- const ids = useLatestValue(updateMeasurementsFor != null ? updateMeasurementsFor : id);
3840
- const handleResize = useCallback(() => {
3841
- if (!resizeObserverConnected.current) {
3842
- // ResizeObserver invokes the `handleResize` callback as soon as `observe` is called,
3843
- // assuming the element is rendered and displayed.
3844
- resizeObserverConnected.current = true;
3845
- return;
3846
- }
3847
-
3848
- if (callbackId.current != null) {
3849
- clearTimeout(callbackId.current);
3850
- }
3851
-
3852
- callbackId.current = setTimeout(() => {
3853
- measureDroppableContainers(Array.isArray(ids.current) ? ids.current : [ids.current]);
3854
- callbackId.current = null;
3855
- }, resizeObserverTimeout);
3856
- }, //eslint-disable-next-line react-hooks/exhaustive-deps
3857
- [resizeObserverTimeout]);
3858
- const resizeObserver = useResizeObserver({
3859
- callback: handleResize,
3860
- disabled: resizeObserverDisabled || !active
3861
- });
3862
- const handleNodeChange = useCallback((newElement, previousElement) => {
3863
- if (!resizeObserver) {
3864
- return;
3865
- }
3866
-
3867
- if (previousElement) {
3868
- resizeObserver.unobserve(previousElement);
3869
- resizeObserverConnected.current = false;
3870
- }
3871
-
3872
- if (newElement) {
3873
- resizeObserver.observe(newElement);
3874
- }
3875
- }, [resizeObserver]);
3876
- const [nodeRef, setNodeRef] = useNodeRef(handleNodeChange);
3877
- const dataRef = useLatestValue(data);
3878
- useEffect(() => {
3879
- if (!resizeObserver || !nodeRef.current) {
3880
- return;
3881
- }
3882
-
3883
- resizeObserver.disconnect();
3884
- resizeObserverConnected.current = false;
3885
- resizeObserver.observe(nodeRef.current);
3886
- }, [nodeRef, resizeObserver]);
3887
- useEffect(() => {
3888
- dispatch({
3889
- type: Action.RegisterDroppable,
3890
- element: {
3891
- id,
3892
- key,
3893
- disabled,
3894
- node: nodeRef,
3895
- rect,
3896
- data: dataRef
3897
- }
3898
- });
3899
- return () => dispatch({
3900
- type: Action.UnregisterDroppable,
3901
- key,
3902
- id
3903
- });
3904
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
3905
- [id]);
3906
- useEffect(() => {
3907
- if (disabled !== previous.current.disabled) {
3908
- dispatch({
3909
- type: Action.SetDroppableDisabled,
3910
- id,
3911
- key,
3912
- disabled
3913
- });
3914
- previous.current.disabled = disabled;
3915
- }
3916
- }, [id, key, disabled, dispatch]);
3917
- return {
3918
- active,
3919
- rect,
3920
- isOver: (over == null ? void 0 : over.id) === id,
3921
- node: nodeRef,
3922
- over,
3923
- setNodeRef
3924
- };
3925
- }
3926
-
3927
- /**
3928
- * Move an array item to a different position. Returns a new array with the item moved to the new position.
3929
- */
3930
- function arrayMove(array, from, to) {
3931
- const newArray = array.slice();
3932
- newArray.splice(to < 0 ? newArray.length + to : to, 0, newArray.splice(from, 1)[0]);
3933
- return newArray;
3934
- }
3935
-
3936
- function getSortedRects(items, rects) {
3937
- return items.reduce((accumulator, id, index) => {
3938
- const rect = rects.get(id);
3939
-
3940
- if (rect) {
3941
- accumulator[index] = rect;
3942
- }
3943
-
3944
- return accumulator;
3945
- }, Array(items.length));
3946
- }
3947
-
3948
- function isValidIndex(index) {
3949
- return index !== null && index >= 0;
3950
- }
3951
-
3952
- function itemsEqual(a, b) {
3953
- if (a === b) {
3954
- return true;
3955
- }
3956
-
3957
- if (a.length !== b.length) {
3958
- return false;
3959
- }
3960
-
3961
- for (let i = 0; i < a.length; i++) {
3962
- if (a[i] !== b[i]) {
3963
- return false;
3964
- }
3965
- }
3966
-
3967
- return true;
3968
- }
3969
-
3970
- function normalizeDisabled(disabled) {
3971
- if (typeof disabled === 'boolean') {
3972
- return {
3973
- draggable: disabled,
3974
- droppable: disabled
3975
- };
3976
- }
3977
-
3978
- return disabled;
3979
- }
3980
-
3981
- const rectSortingStrategy = _ref => {
3982
- let {
3983
- rects,
3984
- activeIndex,
3985
- overIndex,
3986
- index
3987
- } = _ref;
3988
- const newRects = arrayMove(rects, overIndex, activeIndex);
3989
- const oldRect = rects[index];
3990
- const newRect = newRects[index];
3991
-
3992
- if (!newRect || !oldRect) {
3993
- return null;
3994
- }
3995
-
3996
- return {
3997
- x: newRect.left - oldRect.left,
3998
- y: newRect.top - oldRect.top,
3999
- scaleX: newRect.width / oldRect.width,
4000
- scaleY: newRect.height / oldRect.height
4001
- };
4002
- };
4003
-
4004
- // To-do: We should be calculating scale transformation
4005
- const defaultScale$1 = {
4006
- scaleX: 1,
4007
- scaleY: 1
4008
- };
4009
- const verticalListSortingStrategy = _ref => {
4010
- var _rects$activeIndex;
4011
-
4012
- let {
4013
- activeIndex,
4014
- activeNodeRect: fallbackActiveRect,
4015
- index,
4016
- rects,
4017
- overIndex
4018
- } = _ref;
4019
- const activeNodeRect = (_rects$activeIndex = rects[activeIndex]) != null ? _rects$activeIndex : fallbackActiveRect;
4020
-
4021
- if (!activeNodeRect) {
4022
- return null;
4023
- }
4024
-
4025
- if (index === activeIndex) {
4026
- const overIndexRect = rects[overIndex];
4027
-
4028
- if (!overIndexRect) {
4029
- return null;
4030
- }
4031
-
4032
- return {
4033
- x: 0,
4034
- y: activeIndex < overIndex ? overIndexRect.top + overIndexRect.height - (activeNodeRect.top + activeNodeRect.height) : overIndexRect.top - activeNodeRect.top,
4035
- ...defaultScale$1
4036
- };
4037
- }
4038
-
4039
- const itemGap = getItemGap$1(rects, index, activeIndex);
4040
-
4041
- if (index > activeIndex && index <= overIndex) {
4042
- return {
4043
- x: 0,
4044
- y: -activeNodeRect.height - itemGap,
4045
- ...defaultScale$1
4046
- };
4047
- }
4048
-
4049
- if (index < activeIndex && index >= overIndex) {
4050
- return {
4051
- x: 0,
4052
- y: activeNodeRect.height + itemGap,
4053
- ...defaultScale$1
4054
- };
4055
- }
4056
-
4057
- return {
4058
- x: 0,
4059
- y: 0,
4060
- ...defaultScale$1
4061
- };
4062
- };
4063
-
4064
- function getItemGap$1(clientRects, index, activeIndex) {
4065
- const currentRect = clientRects[index];
4066
- const previousRect = clientRects[index - 1];
4067
- const nextRect = clientRects[index + 1];
4068
-
4069
- if (!currentRect) {
4070
- return 0;
4071
- }
4072
-
4073
- if (activeIndex < index) {
4074
- return previousRect ? currentRect.top - (previousRect.top + previousRect.height) : nextRect ? nextRect.top - (currentRect.top + currentRect.height) : 0;
4075
- }
4076
-
4077
- return nextRect ? nextRect.top - (currentRect.top + currentRect.height) : previousRect ? currentRect.top - (previousRect.top + previousRect.height) : 0;
4078
- }
4079
-
4080
- const ID_PREFIX = 'Sortable';
4081
- const Context = /*#__PURE__*/React__default.createContext({
4082
- activeIndex: -1,
4083
- containerId: ID_PREFIX,
4084
- disableTransforms: false,
4085
- items: [],
4086
- overIndex: -1,
4087
- useDragOverlay: false,
4088
- sortedRects: [],
4089
- strategy: rectSortingStrategy,
4090
- disabled: {
4091
- draggable: false,
4092
- droppable: false
4093
- }
4094
- });
4095
- function SortableContext(_ref) {
4096
- let {
4097
- children,
4098
- id,
4099
- items: userDefinedItems,
4100
- strategy = rectSortingStrategy,
4101
- disabled: disabledProp = false
4102
- } = _ref;
4103
- const {
4104
- active,
4105
- dragOverlay,
4106
- droppableRects,
4107
- over,
4108
- measureDroppableContainers
4109
- } = useDndContext();
4110
- const containerId = useUniqueId(ID_PREFIX, id);
4111
- const useDragOverlay = Boolean(dragOverlay.rect !== null);
4112
- const items = useMemo(() => userDefinedItems.map(item => typeof item === 'object' && 'id' in item ? item.id : item), [userDefinedItems]);
4113
- const isDragging = active != null;
4114
- const activeIndex = active ? items.indexOf(active.id) : -1;
4115
- const overIndex = over ? items.indexOf(over.id) : -1;
4116
- const previousItemsRef = useRef(items);
4117
- const itemsHaveChanged = !itemsEqual(items, previousItemsRef.current);
4118
- const disableTransforms = overIndex !== -1 && activeIndex === -1 || itemsHaveChanged;
4119
- const disabled = normalizeDisabled(disabledProp);
4120
- useIsomorphicLayoutEffect(() => {
4121
- if (itemsHaveChanged && isDragging) {
4122
- measureDroppableContainers(items);
4123
- }
4124
- }, [itemsHaveChanged, items, isDragging, measureDroppableContainers]);
4125
- useEffect(() => {
4126
- previousItemsRef.current = items;
4127
- }, [items]);
4128
- const contextValue = useMemo(() => ({
4129
- activeIndex,
4130
- containerId,
4131
- disabled,
4132
- disableTransforms,
4133
- items,
4134
- overIndex,
4135
- useDragOverlay,
4136
- sortedRects: getSortedRects(items, droppableRects),
4137
- strategy
4138
- }), // eslint-disable-next-line react-hooks/exhaustive-deps
4139
- [activeIndex, containerId, disabled.draggable, disabled.droppable, disableTransforms, items, overIndex, droppableRects, useDragOverlay, strategy]);
4140
- return React__default.createElement(Context.Provider, {
4141
- value: contextValue
4142
- }, children);
4143
- }
4144
-
4145
- const defaultNewIndexGetter = _ref => {
4146
- let {
4147
- id,
4148
- items,
4149
- activeIndex,
4150
- overIndex
4151
- } = _ref;
4152
- return arrayMove(items, activeIndex, overIndex).indexOf(id);
4153
- };
4154
- const defaultAnimateLayoutChanges = _ref2 => {
4155
- let {
4156
- containerId,
4157
- isSorting,
4158
- wasDragging,
4159
- index,
4160
- items,
4161
- newIndex,
4162
- previousItems,
4163
- previousContainerId,
4164
- transition
4165
- } = _ref2;
4166
-
4167
- if (!transition || !wasDragging) {
4168
- return false;
4169
- }
4170
-
4171
- if (previousItems !== items && index === newIndex) {
4172
- return false;
4173
- }
4174
-
4175
- if (isSorting) {
4176
- return true;
4177
- }
4178
-
4179
- return newIndex !== index && containerId === previousContainerId;
4180
- };
4181
- const defaultTransition = {
4182
- duration: 200,
4183
- easing: 'ease'
4184
- };
4185
- const transitionProperty = 'transform';
4186
- const disabledTransition = /*#__PURE__*/CSS.Transition.toString({
4187
- property: transitionProperty,
4188
- duration: 0,
4189
- easing: 'linear'
4190
- });
4191
- const defaultAttributes = {
4192
- roleDescription: 'sortable'
4193
- };
4194
-
4195
- /*
4196
- * When the index of an item changes while sorting,
4197
- * we need to temporarily disable the transforms
4198
- */
4199
-
4200
- function useDerivedTransform(_ref) {
4201
- let {
4202
- disabled,
4203
- index,
4204
- node,
4205
- rect
4206
- } = _ref;
4207
- const [derivedTransform, setDerivedtransform] = useState(null);
4208
- const previousIndex = useRef(index);
4209
- useIsomorphicLayoutEffect(() => {
4210
- if (!disabled && index !== previousIndex.current && node.current) {
4211
- const initial = rect.current;
4212
-
4213
- if (initial) {
4214
- const current = getClientRect(node.current, {
4215
- ignoreTransform: true
4216
- });
4217
- const delta = {
4218
- x: initial.left - current.left,
4219
- y: initial.top - current.top,
4220
- scaleX: initial.width / current.width,
4221
- scaleY: initial.height / current.height
4222
- };
4223
-
4224
- if (delta.x || delta.y) {
4225
- setDerivedtransform(delta);
4226
- }
4227
- }
4228
- }
4229
-
4230
- if (index !== previousIndex.current) {
4231
- previousIndex.current = index;
4232
- }
4233
- }, [disabled, index, node, rect]);
4234
- useEffect(() => {
4235
- if (derivedTransform) {
4236
- setDerivedtransform(null);
4237
- }
4238
- }, [derivedTransform]);
4239
- return derivedTransform;
4240
- }
4241
-
4242
- function useSortable(_ref) {
4243
- let {
4244
- animateLayoutChanges = defaultAnimateLayoutChanges,
4245
- attributes: userDefinedAttributes,
4246
- disabled: localDisabled,
4247
- data: customData,
4248
- getNewIndex = defaultNewIndexGetter,
4249
- id,
4250
- strategy: localStrategy,
4251
- resizeObserverConfig,
4252
- transition = defaultTransition
4253
- } = _ref;
4254
- const {
4255
- items,
4256
- containerId,
4257
- activeIndex,
4258
- disabled: globalDisabled,
4259
- disableTransforms,
4260
- sortedRects,
4261
- overIndex,
4262
- useDragOverlay,
4263
- strategy: globalStrategy
4264
- } = useContext(Context);
4265
- const disabled = normalizeLocalDisabled(localDisabled, globalDisabled);
4266
- const index = items.indexOf(id);
4267
- const data = useMemo(() => ({
4268
- sortable: {
4269
- containerId,
4270
- index,
4271
- items
4272
- },
4273
- ...customData
4274
- }), [containerId, customData, index, items]);
4275
- const itemsAfterCurrentSortable = useMemo(() => items.slice(items.indexOf(id)), [items, id]);
4276
- const {
4277
- rect,
4278
- node,
4279
- isOver,
4280
- setNodeRef: setDroppableNodeRef
4281
- } = useDroppable({
4282
- id,
4283
- data,
4284
- disabled: disabled.droppable,
4285
- resizeObserverConfig: {
4286
- updateMeasurementsFor: itemsAfterCurrentSortable,
4287
- ...resizeObserverConfig
4288
- }
4289
- });
4290
- const {
4291
- active,
4292
- activatorEvent,
4293
- activeNodeRect,
4294
- attributes,
4295
- setNodeRef: setDraggableNodeRef,
4296
- listeners,
4297
- isDragging,
4298
- over,
4299
- setActivatorNodeRef,
4300
- transform
4301
- } = useDraggable({
4302
- id,
4303
- data,
4304
- attributes: { ...defaultAttributes,
4305
- ...userDefinedAttributes
4306
- },
4307
- disabled: disabled.draggable
4308
- });
4309
- const setNodeRef = useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
4310
- const isSorting = Boolean(active);
4311
- const displaceItem = isSorting && !disableTransforms && isValidIndex(activeIndex) && isValidIndex(overIndex);
4312
- const shouldDisplaceDragSource = !useDragOverlay && isDragging;
4313
- const dragSourceDisplacement = shouldDisplaceDragSource && displaceItem ? transform : null;
4314
- const strategy = localStrategy != null ? localStrategy : globalStrategy;
4315
- const finalTransform = displaceItem ? dragSourceDisplacement != null ? dragSourceDisplacement : strategy({
4316
- rects: sortedRects,
4317
- activeNodeRect,
4318
- activeIndex,
4319
- overIndex,
4320
- index
4321
- }) : null;
4322
- const newIndex = isValidIndex(activeIndex) && isValidIndex(overIndex) ? getNewIndex({
4323
- id,
4324
- items,
4325
- activeIndex,
4326
- overIndex
4327
- }) : index;
4328
- const activeId = active == null ? void 0 : active.id;
4329
- const previous = useRef({
4330
- activeId,
4331
- items,
4332
- newIndex,
4333
- containerId
4334
- });
4335
- const itemsHaveChanged = items !== previous.current.items;
4336
- const shouldAnimateLayoutChanges = animateLayoutChanges({
4337
- active,
4338
- containerId,
4339
- isDragging,
4340
- isSorting,
4341
- id,
4342
- index,
4343
- items,
4344
- newIndex: previous.current.newIndex,
4345
- previousItems: previous.current.items,
4346
- previousContainerId: previous.current.containerId,
4347
- transition,
4348
- wasDragging: previous.current.activeId != null
4349
- });
4350
- const derivedTransform = useDerivedTransform({
4351
- disabled: !shouldAnimateLayoutChanges,
4352
- index,
4353
- node,
4354
- rect
4355
- });
4356
- useEffect(() => {
4357
- if (isSorting && previous.current.newIndex !== newIndex) {
4358
- previous.current.newIndex = newIndex;
4359
- }
4360
-
4361
- if (containerId !== previous.current.containerId) {
4362
- previous.current.containerId = containerId;
4363
- }
4364
-
4365
- if (items !== previous.current.items) {
4366
- previous.current.items = items;
4367
- }
4368
- }, [isSorting, newIndex, containerId, items]);
4369
- useEffect(() => {
4370
- if (activeId === previous.current.activeId) {
4371
- return;
4372
- }
4373
-
4374
- if (activeId != null && previous.current.activeId == null) {
4375
- previous.current.activeId = activeId;
4376
- return;
4377
- }
4378
-
4379
- const timeoutId = setTimeout(() => {
4380
- previous.current.activeId = activeId;
4381
- }, 50);
4382
- return () => clearTimeout(timeoutId);
4383
- }, [activeId]);
4384
- return {
4385
- active,
4386
- activeIndex,
4387
- attributes,
4388
- data,
4389
- rect,
4390
- index,
4391
- newIndex,
4392
- items,
4393
- isOver,
4394
- isSorting,
4395
- isDragging,
4396
- listeners,
4397
- node,
4398
- overIndex,
4399
- over,
4400
- setNodeRef,
4401
- setActivatorNodeRef,
4402
- setDroppableNodeRef,
4403
- setDraggableNodeRef,
4404
- transform: derivedTransform != null ? derivedTransform : finalTransform,
4405
- transition: getTransition()
4406
- };
4407
-
4408
- function getTransition() {
4409
- if ( // Temporarily disable transitions for a single frame to set up derived transforms
4410
- derivedTransform || // Or to prevent items jumping to back to their "new" position when items change
4411
- itemsHaveChanged && previous.current.newIndex === index) {
4412
- return disabledTransition;
4413
- }
4414
-
4415
- if (shouldDisplaceDragSource && !isKeyboardEvent(activatorEvent) || !transition) {
4416
- return undefined;
4417
- }
4418
-
4419
- if (isSorting || shouldAnimateLayoutChanges) {
4420
- return CSS.Transition.toString({ ...transition,
4421
- property: transitionProperty
4422
- });
4423
- }
4424
-
4425
- return undefined;
4426
- }
4427
- }
4428
-
4429
- function normalizeLocalDisabled(localDisabled, globalDisabled) {
4430
- var _localDisabled$dragga, _localDisabled$droppa;
4431
-
4432
- if (typeof localDisabled === 'boolean') {
4433
- return {
4434
- draggable: localDisabled,
4435
- // Backwards compatibility
4436
- droppable: false
4437
- };
4438
- }
4439
-
4440
- return {
4441
- draggable: (_localDisabled$dragga = localDisabled == null ? void 0 : localDisabled.draggable) != null ? _localDisabled$dragga : globalDisabled.draggable,
4442
- droppable: (_localDisabled$droppa = localDisabled == null ? void 0 : localDisabled.droppable) != null ? _localDisabled$droppa : globalDisabled.droppable
4443
- };
4444
- }
4445
-
4446
- const SortTableItem = ({
4447
- id,
4448
- children,
4449
- isLastIndex,
4450
- index
4451
- }) => {
4452
- const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id });
4453
- const style = {
4454
- transform: CSS.Transform.toString(transform),
4455
- transition
4456
- };
4457
- return /* @__PURE__ */ jsxs(
4458
- "div",
4459
- {
4460
- ref: setNodeRef,
4461
- style,
4462
- className: twMerge(
4463
- "sortTableItem",
4464
- index !== 0 ? "indexNotEqualZerosortTableItem " : "",
4465
- isLastIndex ? "lastIndexZerosortTableItem" : ""
4466
- ),
4467
- children: [
4468
- /* @__PURE__ */ jsx("span", { className: "dragIconContainer", ...attributes, ...listeners, children: /* @__PURE__ */ jsx(DragIcon, { className: "dragIcon" }) }),
4469
- /* @__PURE__ */ jsx("div", { className: "childrenSortTableItem", children })
4470
- ]
4471
- }
4472
- );
4473
- };
4474
-
4475
- const SettingTable = (props) => {
4476
- const {
4477
- open,
4478
- setOpen,
4479
- title,
4480
- showSetting,
4481
- setDefaultSettingColumnItems,
4482
- defaultSettingColumnItems
4483
- } = props;
4484
- const { handleSubmit, control } = useForm();
4485
- const [columns, setColumns] = useState([]);
4486
- const handleCloseModal = () => {
4487
- setOpen(false);
4488
- };
4489
- const handleOkModal = () => {
4490
- setOpen(false);
4491
- };
4492
- const onSubmit = () => {
4493
- setOpen(false);
4494
- if (setDefaultSettingColumnItems) {
4495
- setDefaultSettingColumnItems(columns);
4496
- }
4497
- };
4498
- const handleDragEnd = (event) => {
4499
- const { active, over } = event;
4500
- if (!over || active.id === over.id) return;
4501
- const oldIndex = columns.findIndex((col) => col.key === active.id);
4502
- const newIndex = columns.findIndex((col) => col.key === over.id);
4503
- const newColumns = arrayMove(columns, oldIndex, newIndex);
4504
- setColumns(newColumns);
4505
- };
4506
- useEffect(() => {
4507
- setColumns(defaultSettingColumnItems);
4508
- }, [defaultSettingColumnItems]);
4509
- const titleHeader = () => {
4510
- return /* @__PURE__ */ jsxs("div", { className: "titleHeaderModalSettingTableContainer", children: [
4511
- /* @__PURE__ */ jsx("p", { children: "Cài đặt hiển thị bảng" }),
4512
- /* @__PURE__ */ jsx("p", { className: "descriptionHeaderModalSettingTable", children: "Chọn cột muốn hiển thị và kéo thả vị trí muốn hiển thị" })
4513
- ] });
4514
- };
4515
- const footer = () => {
4516
- const handleCancel = () => {
4517
- if (setDefaultSettingColumnItems) {
4518
- setDefaultSettingColumnItems(defaultSettingColumnItems);
4519
- }
4520
- setColumns(defaultSettingColumnItems);
4521
- setOpen(false);
4522
- };
4523
- return /* @__PURE__ */ jsxs("div", { className: "footerModalSettingTable", children: [
4524
- /* @__PURE__ */ jsx(
4525
- Button,
4526
- {
4527
- className: "backToDefaultButtonSettingTable",
4528
- onClick: handleCancel,
4529
- children: "Về chế độ mặc định"
4530
- }
4531
- ),
4532
- /* @__PURE__ */ jsx(Button, { className: "submitButtonSettingTable", htmlType: "submit", children: "Xác nhận" })
4533
- ] });
4534
- };
4535
- if (!showSetting) return /* @__PURE__ */ jsx(Fragment, {});
4536
- return /* @__PURE__ */ jsx(
4537
- Modal,
4538
- {
4539
- open,
4540
- title: title || titleHeader(),
4541
- closable: true,
4542
- onOk: handleOkModal,
4543
- className: "setting-table-modal",
4544
- footer: null,
4545
- onCancel: handleCloseModal,
4546
- children: /* @__PURE__ */ jsxs("form", { onSubmit: handleSubmit(onSubmit), className: "formSettingTable", children: [
4547
- /* @__PURE__ */ jsx("div", { className: "content-setting-table-modal", children: /* @__PURE__ */ jsx(
4548
- DndContext,
4549
- {
4550
- collisionDetection: closestCenter,
4551
- onDragEnd: handleDragEnd,
4552
- children: /* @__PURE__ */ jsx(
4553
- SortableContext,
4554
- {
4555
- items: columns.map((item) => String(item.key)),
4556
- strategy: verticalListSortingStrategy,
4557
- children: columns.filter((i) => i.key).map((item, index) => {
4558
- return /* @__PURE__ */ jsx(
4559
- SortTableItem,
4560
- {
4561
- id: String(item.key),
4562
- isLastIndex: index === columns.length - 1,
4563
- index,
4564
- children: /* @__PURE__ */ jsx(
4565
- SettingColumnItem,
4566
- {
4567
- lable: String(item.title),
4568
- control,
4569
- name: item.key
4570
- }
4571
- )
4572
- },
4573
- item.key
4574
- );
4575
- })
4576
- }
4577
- )
4578
- }
4579
- ) }),
4580
- footer()
4581
- ] })
4582
- }
4583
- );
4584
- };
4585
-
4586
- const ButtonBadge = (props) => {
4587
- const { buttonItem, active, setFilters, filters } = props;
4588
- const handleClick = () => {
4589
- setFilters({ ...filters, status: buttonItem?.status });
4590
- if (props.setRowsSelected) {
4591
- props.setRowsSelected([]);
4592
- }
4593
- };
4594
- return /* @__PURE__ */ jsxs(
4595
- Button,
4596
- {
4597
- className: twMerge(
4598
- "customGroupTextButton",
4599
- active ? "customGroupButtonActive" : "customGroupButtonInactive"
4600
- ),
4601
- onClick: handleClick,
4602
- children: [
4603
- buttonItem.label,
4604
- /* @__PURE__ */ jsx(
4605
- Badge,
4606
- {
4607
- showZero: true,
4608
- overflowCount: buttonItem?.quantity + 9999,
4609
- count: buttonItem?.quantity || 0,
4610
- color: `${active ? "#BDE3FF]" : "#EEEEF0"}`,
4611
- className: twMerge(
4612
- "customBadgeText",
4613
- active ? "customBadgeActive" : "customBadge"
4614
- )
4615
- }
4616
- )
4617
- ]
4618
- }
4619
- );
4620
- };
4621
- const GroupHeadingButton = (props) => {
4622
- const {
4623
- groupHeadingButtonItems,
4624
- setFilters,
4625
- filters,
4626
- setRowsSelected,
4627
- isApproved
4628
- } = props;
4629
- const dataStatusApproved = groupHeadingButtonItems?.filter(
4630
- (item) => ListStatusApproved.includes(item?.status)
4631
- );
4632
- const dataStatusTable = isBoolean(isApproved) && !isApproved ? dataStatusApproved : groupHeadingButtonItems;
4633
- return /* @__PURE__ */ jsx("div", { className: "buttonBadgeContainer", children: dataStatusTable?.map((i, index) => /* @__PURE__ */ jsx(
4634
- ButtonBadge,
4635
- {
4636
- buttonItem: i,
4637
- active: i?.status === filters?.status,
4638
- setFilters,
4639
- filters,
4640
- setRowsSelected
4641
- },
4642
- index
4643
- )) });
4644
- };
4645
-
4646
- const IconSettingTable = (props) => {
4647
- const { showSetting, setOpenStting } = props;
4648
- if (showSetting) {
4649
- return /* @__PURE__ */ jsx("span", { className: "bodysettingTableIconContainer", children: /* @__PURE__ */ jsx(Tooltip, { title: "Cài đặt hiển thị bảng", children: /* @__PURE__ */ jsx(SettingIcon, { onClick: () => setOpenStting(true) }) }) });
4650
- }
4651
- return null;
4652
- };
4653
-
4654
- const HeadingTable = (props) => {
4655
- const {
4656
- setOpenStting,
4657
- showSetting,
4658
- renderHeadingSearch,
4659
- rightHeadingContent,
4660
- menu,
4661
- groupHeadingButtonItems,
4662
- setFilters,
4663
- filters,
4664
- noBreadcum,
4665
- setRowsSelected,
4666
- isApproved
4667
- } = props;
4668
- return /* @__PURE__ */ jsxs(
4669
- Heading,
4670
- {
4671
- menu,
4672
- classNameWrapHeading: "wrapHeading",
4673
- rightContent: rightHeadingContent && rightHeadingContent,
4674
- noBreadcum,
4675
- children: [
4676
- renderHeadingSearch && renderHeadingSearch(),
4677
- /* @__PURE__ */ jsx("div", { className: "dividerHeading" }),
4678
- /* @__PURE__ */ jsx("div", { id: "filter_content", className: "filterContentHeading", children: /* @__PURE__ */ jsxs("div", { className: "bodyFilterContentHeading", children: [
4679
- /* @__PURE__ */ jsx(
4680
- GroupHeadingButton,
4681
- {
4682
- groupHeadingButtonItems,
4683
- setFilters,
4684
- setRowsSelected,
4685
- filters,
4686
- isApproved
4687
- }
4688
- ),
4689
- /* @__PURE__ */ jsx("div", { className: "settingTableIconContainer", children: /* @__PURE__ */ jsx(
4690
- IconSettingTable,
4691
- {
4692
- setOpenStting,
4693
- showSetting
4694
- }
4695
- ) })
4696
- ] }) })
4697
- ]
4698
- }
4699
- );
4700
- };
4701
-
4702
- const TableCategory = ({
4703
- columns,
4704
- filters,
4705
- rowsSelected,
4706
- titleSettingTableModal,
4707
- showSetting,
4708
- setColumns,
4709
- renderHeadingSearch,
4710
- rightHeadingContent,
4711
- menu,
4712
- groupHeadingButtonItems,
4713
- setFilters,
4714
- noBreadcum,
4715
- bulkActionHandlers,
4716
- setRowsSelected,
4717
- isApproved,
4718
- showBulkAction = true,
4719
- ...rest
4720
- }) => {
4721
- const status = filters?.status;
4722
- //! State
4723
- const [openSetting, setOpenStting] = useState(false);
4724
- //! Function
4725
- const tableContent = /* @__PURE__ */ jsxs(
4726
- "div",
4727
- {
4728
- id: ID_TABLE_WRAPPER,
4729
- className: twMerge(showSetting ? "tableContent" : ""),
4730
- children: [
4731
- /* @__PURE__ */ jsx(
4732
- HeadingTable,
4733
- {
4734
- rightHeadingContent,
4735
- renderHeadingSearch,
4736
- setOpenStting,
4737
- showSetting,
4738
- menu,
4739
- groupHeadingButtonItems,
4740
- setFilters,
4741
- filters,
4742
- noBreadcum,
4743
- setRowsSelected,
4744
- isApproved
4745
- }
4746
- ),
4747
- /* @__PURE__ */ jsx(
4748
- Table,
4749
- {
4750
- columns,
4751
- rowsSelected,
4752
- filters,
4753
- ...rest
4754
- }
4755
- ),
4756
- /* @__PURE__ */ jsx(
4757
- SettingTable,
4758
- {
4759
- open: openSetting,
4760
- setOpen: setOpenStting,
4761
- title: titleSettingTableModal,
4762
- showSetting,
4763
- defaultSettingColumnItems: columns,
4764
- setDefaultSettingColumnItems: setColumns
4765
- }
4766
- ),
4767
- showBulkAction && rowsSelected && !isEmpty(rowsSelected) && /* @__PURE__ */ jsx("div", { id: "bulkaction_table", className: "bulkActionsContainer", children: /* @__PURE__ */ jsx(
4768
- BulkActions,
4769
- {
4770
- typeBulkaction: TypeBulkActions.BULKACTION,
4771
- quantity: rowsSelected?.length,
4772
- status,
4773
- isApproved,
4774
- ...bulkActionHandlers
4775
- }
4776
- ) })
4777
- ]
4778
- }
4779
- );
4780
- //! Render
4781
- return tableContent;
4782
- };
4783
-
4784
- export { TableCategory };