@bigbinary/neeto-fields-frontend 2.4.6 → 2.4.7-beta2

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