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

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