trotl-filter 1.0.49 → 1.0.51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -2541,7 +2541,7 @@ function hasWindow() {
2541
2541
  return typeof window !== 'undefined';
2542
2542
  }
2543
2543
  function getNodeName(node) {
2544
- if (isNode(node)) {
2544
+ if (isNode$1(node)) {
2545
2545
  return (node.nodeName || '').toLowerCase();
2546
2546
  }
2547
2547
  // Mocked nodes in testing environments may not be instances of Node. By
@@ -2549,37 +2549,37 @@ function getNodeName(node) {
2549
2549
  // https://github.com/floating-ui/floating-ui/issues/2317
2550
2550
  return '#document';
2551
2551
  }
2552
- function getWindow(node) {
2552
+ function getWindow$1(node) {
2553
2553
  var _node$ownerDocument;
2554
2554
  return (node == null || (_node$ownerDocument = node.ownerDocument) == null ? void 0 : _node$ownerDocument.defaultView) || window;
2555
2555
  }
2556
2556
  function getDocumentElement(node) {
2557
2557
  var _ref;
2558
- return (_ref = (isNode(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
2558
+ return (_ref = (isNode$1(node) ? node.ownerDocument : node.document) || window.document) == null ? void 0 : _ref.documentElement;
2559
2559
  }
2560
- function isNode(value) {
2560
+ function isNode$1(value) {
2561
2561
  if (!hasWindow()) {
2562
2562
  return false;
2563
2563
  }
2564
- return value instanceof Node || value instanceof getWindow(value).Node;
2564
+ return value instanceof Node || value instanceof getWindow$1(value).Node;
2565
2565
  }
2566
2566
  function isElement(value) {
2567
2567
  if (!hasWindow()) {
2568
2568
  return false;
2569
2569
  }
2570
- return value instanceof Element || value instanceof getWindow(value).Element;
2570
+ return value instanceof Element || value instanceof getWindow$1(value).Element;
2571
2571
  }
2572
- function isHTMLElement(value) {
2572
+ function isHTMLElement$1(value) {
2573
2573
  if (!hasWindow()) {
2574
2574
  return false;
2575
2575
  }
2576
- return value instanceof HTMLElement || value instanceof getWindow(value).HTMLElement;
2576
+ return value instanceof HTMLElement || value instanceof getWindow$1(value).HTMLElement;
2577
2577
  }
2578
2578
  function isShadowRoot(value) {
2579
2579
  if (!hasWindow() || typeof ShadowRoot === 'undefined') {
2580
2580
  return false;
2581
2581
  }
2582
- return value instanceof ShadowRoot || value instanceof getWindow(value).ShadowRoot;
2582
+ return value instanceof ShadowRoot || value instanceof getWindow$1(value).ShadowRoot;
2583
2583
  }
2584
2584
  const invalidOverflowDisplayValues = /*#__PURE__*/new Set(['inline', 'contents']);
2585
2585
  function isOverflowElement(element) {
@@ -2600,7 +2600,7 @@ function isLastTraversableNode(node) {
2600
2600
  return lastTraversableNodeNames.has(getNodeName(node));
2601
2601
  }
2602
2602
  function getComputedStyle$1(element) {
2603
- return getWindow(element).getComputedStyle(element);
2603
+ return getWindow$1(element).getComputedStyle(element);
2604
2604
  }
2605
2605
  function getParentNode(node) {
2606
2606
  if (getNodeName(node) === 'html') {
@@ -2622,7 +2622,7 @@ function getNearestOverflowAncestor(node) {
2622
2622
  if (isLastTraversableNode(parentNode)) {
2623
2623
  return node.ownerDocument ? node.ownerDocument.body : node.body;
2624
2624
  }
2625
- if (isHTMLElement(parentNode) && isOverflowElement(parentNode)) {
2625
+ if (isHTMLElement$1(parentNode) && isOverflowElement(parentNode)) {
2626
2626
  return parentNode;
2627
2627
  }
2628
2628
  return getNearestOverflowAncestor(parentNode);
@@ -2637,7 +2637,7 @@ function getOverflowAncestors(node, list, traverseIframes) {
2637
2637
  }
2638
2638
  const scrollableAncestor = getNearestOverflowAncestor(node);
2639
2639
  const isBody = scrollableAncestor === ((_node$ownerDocument2 = node.ownerDocument) == null ? void 0 : _node$ownerDocument2.body);
2640
- const win = getWindow(scrollableAncestor);
2640
+ const win = getWindow$1(scrollableAncestor);
2641
2641
  if (isBody) {
2642
2642
  const frameElement = getFrameElement(win);
2643
2643
  return list.concat(win, win.visualViewport || [], isOverflowElement(scrollableAncestor) ? scrollableAncestor : [], frameElement && traverseIframes ? getOverflowAncestors(frameElement) : []);
@@ -2654,7 +2654,7 @@ function getCssDimensions(element) {
2654
2654
  // strings for SVG elements, returning NaN. Fallback to `0` in this case.
2655
2655
  let width = parseFloat(css.width) || 0;
2656
2656
  let height = parseFloat(css.height) || 0;
2657
- const hasOffset = isHTMLElement(element);
2657
+ const hasOffset = isHTMLElement$1(element);
2658
2658
  const offsetWidth = hasOffset ? element.offsetWidth : width;
2659
2659
  const offsetHeight = hasOffset ? element.offsetHeight : height;
2660
2660
  const shouldFallback = round(width) !== offsetWidth || round(height) !== offsetHeight;
@@ -2675,7 +2675,7 @@ function unwrapElement(element) {
2675
2675
 
2676
2676
  function getScale(element) {
2677
2677
  const domElement = unwrapElement(element);
2678
- if (!isHTMLElement(domElement)) {
2678
+ if (!isHTMLElement$1(domElement)) {
2679
2679
  return createCoords(1);
2680
2680
  }
2681
2681
  const rect = domElement.getBoundingClientRect();
@@ -2703,7 +2703,7 @@ function getScale(element) {
2703
2703
 
2704
2704
  const noOffsets = /*#__PURE__*/createCoords(0);
2705
2705
  function getVisualOffsets(element) {
2706
- const win = getWindow(element);
2706
+ const win = getWindow$1(element);
2707
2707
  if (!isWebKit() || !win.visualViewport) {
2708
2708
  return noOffsets;
2709
2709
  }
@@ -2736,7 +2736,7 @@ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetPar
2736
2736
  let width = clientRect.width / scale.x;
2737
2737
  let height = clientRect.height / scale.y;
2738
2738
  if (domElement) {
2739
- const win = getWindow(domElement);
2739
+ const win = getWindow$1(domElement);
2740
2740
  const offsetWin = offsetParent;
2741
2741
  let currentWin = win;
2742
2742
  let currentIFrame = getFrameElement(currentWin);
@@ -2752,7 +2752,7 @@ function getBoundingClientRect(element, includeScale, isFixedStrategy, offsetPar
2752
2752
  height *= iframeScale.y;
2753
2753
  x += left;
2754
2754
  y += top;
2755
- currentWin = getWindow(currentIFrame);
2755
+ currentWin = getWindow$1(currentIFrame);
2756
2756
  currentIFrame = getFrameElement(currentWin);
2757
2757
  }
2758
2758
  }
@@ -2937,15 +2937,15 @@ function autoUpdate(reference, floating, update, options) {
2937
2937
 
2938
2938
  var isClient = typeof document !== 'undefined';
2939
2939
 
2940
- var noop$1 = function noop() {};
2941
- var index = isClient ? React.useLayoutEffect : noop$1;
2940
+ var noop$2 = function noop() {};
2941
+ var index = isClient ? React.useLayoutEffect : noop$2;
2942
2942
 
2943
2943
  var _excluded$4 = ["className", "clearValue", "cx", "getStyles", "getClassNames", "getValue", "hasValue", "isMulti", "isRtl", "options", "selectOption", "selectProps", "setValue", "theme"];
2944
2944
  // ==============================
2945
2945
  // NO OP
2946
2946
  // ==============================
2947
2947
 
2948
- var noop = function noop() {};
2948
+ var noop$1 = function noop() {};
2949
2949
 
2950
2950
  // ==============================
2951
2951
  // Class Name Prefixer
@@ -3106,7 +3106,7 @@ function easeOutCubic(t, b, c, d) {
3106
3106
  }
3107
3107
  function animatedScrollTo(element, to) {
3108
3108
  var duration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 200;
3109
- var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : noop;
3109
+ var callback = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : noop$1;
3110
3110
  var start = getScrollTop(element);
3111
3111
  var change = to - start;
3112
3112
  var increment = 10;
@@ -3194,8 +3194,8 @@ var options = {
3194
3194
  // check for SSR
3195
3195
  var w = typeof window !== 'undefined' ? window : {};
3196
3196
  if (w.addEventListener && w.removeEventListener) {
3197
- w.addEventListener('p', noop, options);
3198
- w.removeEventListener('p', noop, false);
3197
+ w.addEventListener('p', noop$1, options);
3198
+ w.removeEventListener('p', noop$1, false);
3199
3199
  }
3200
3200
  var supportsPassiveEvents = passiveOptionAccessed;
3201
3201
  function notNullish(item) {
@@ -4447,7 +4447,7 @@ var defaultAriaLiveMessages = {
4447
4447
  }
4448
4448
  };
4449
4449
 
4450
- var LiveRegion = function LiveRegion(props) {
4450
+ var LiveRegion$1 = function LiveRegion(props) {
4451
4451
  var ariaSelection = props.ariaSelection,
4452
4452
  focusedOption = props.focusedOption,
4453
4453
  focusedValue = props.focusedValue,
@@ -4575,7 +4575,7 @@ var LiveRegion = function LiveRegion(props) {
4575
4575
  role: "log"
4576
4576
  }, isFocused && !isInitialFocus && ScreenReaderText));
4577
4577
  };
4578
- var LiveRegion$1 = LiveRegion;
4578
+ var LiveRegion$1$1 = LiveRegion$1;
4579
4579
 
4580
4580
  var diacritics = [{
4581
4581
  base: 'A',
@@ -5046,7 +5046,7 @@ function preventInertiaScroll() {
5046
5046
  function isTouchDevice() {
5047
5047
  return 'ontouchstart' in window || navigator.maxTouchPoints;
5048
5048
  }
5049
- var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
5049
+ var canUseDOM$1 = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
5050
5050
  var activeScrollLocks = 0;
5051
5051
  var listenerOptions = {
5052
5052
  capture: false,
@@ -5059,7 +5059,7 @@ function useScrollLock(_ref) {
5059
5059
  var originalStyles = React.useRef({});
5060
5060
  var scrollTarget = React.useRef(null);
5061
5061
  var addScrollLock = React.useCallback(function (touchScrollTarget) {
5062
- if (!canUseDOM) return;
5062
+ if (!canUseDOM$1) return;
5063
5063
  var target = document.body;
5064
5064
  var targetStyle = target && target.style;
5065
5065
  if (accountForScrollbars) {
@@ -5102,7 +5102,7 @@ function useScrollLock(_ref) {
5102
5102
  activeScrollLocks += 1;
5103
5103
  }, [accountForScrollbars]);
5104
5104
  var removeScrollLock = React.useCallback(function (touchScrollTarget) {
5105
- if (!canUseDOM) return;
5105
+ if (!canUseDOM$1) return;
5106
5106
  var target = document.body;
5107
5107
  var targetStyle = target && target.style;
5108
5108
 
@@ -6475,7 +6475,7 @@ var Select = /*#__PURE__*/function (_Component) {
6475
6475
  id: id,
6476
6476
  innerRef: this.getInputRef,
6477
6477
  onBlur: this.onInputBlur,
6478
- onChange: noop,
6478
+ onChange: noop$1,
6479
6479
  onFocus: this.onInputFocus,
6480
6480
  disabled: isDisabled,
6481
6481
  tabIndex: tabIndex,
@@ -6879,7 +6879,7 @@ var Select = /*#__PURE__*/function (_Component) {
6879
6879
  isFocused = _this$state6.isFocused,
6880
6880
  selectValue = _this$state6.selectValue;
6881
6881
  var focusableOptions = this.getFocusableOptions();
6882
- return /*#__PURE__*/React__namespace.createElement(LiveRegion$1, _extends({}, commonProps, {
6882
+ return /*#__PURE__*/React__namespace.createElement(LiveRegion$1$1, _extends({}, commonProps, {
6883
6883
  id: this.getElementId('live-region'),
6884
6884
  ariaSelection: ariaSelection,
6885
6885
  focusedOption: focusedOption,
@@ -9075,10 +9075,13 @@ const DebounceSelect = ({
9075
9075
  setInput(e.target.value);
9076
9076
  setOpen(true);
9077
9077
  },
9078
- placeholder: placeholder,
9079
- onFocus: () => setOpen(true),
9080
- onBlur: () => setTimeout(() => setOpen(false), 200),
9081
- onDoubleClick: handleDoubleClick,
9078
+ placeholder: placeholder
9079
+ // onFocus={() => setOpen(true)}
9080
+ ,
9081
+ onFocus: handleDoubleClick,
9082
+ onBlur: () => setTimeout(() => setOpen(false), 200)
9083
+ // onDoubleClick={handleDoubleClick}
9084
+ ,
9082
9085
  disabled: disabled,
9083
9086
  style: style
9084
9087
  }), showSpinner && /*#__PURE__*/React.createElement("div", {
@@ -9590,6 +9593,22 @@ function DateTimeInput({
9590
9593
  return toInputString(d.getTime());
9591
9594
  });
9592
9595
 
9596
+ // internal value for the time input. Previously the <input> read
9597
+ // directly from `value` which meant that when the component was
9598
+ // controlled the field could never update until the parent passed a
9599
+ // new prop. By keeping a separate `timeValue` that syncs from `value` but
9600
+ // is mutated as the user types we allow the time field to stay responsive
9601
+ // even in controlled scenarios.
9602
+ const [timeValue, setTimeValue] = React.useState(() => {
9603
+ if (value) {
9604
+ const d = new Date(value);
9605
+ const hh = String(d.getHours()).padStart(2, '0');
9606
+ const mm = String(d.getMinutes()).padStart(2, '0');
9607
+ return `${hh}:${mm}`;
9608
+ }
9609
+ return timeStart || "";
9610
+ });
9611
+
9593
9612
  // Dropdown state & positioning
9594
9613
  const [open, setOpen] = React.useState(false);
9595
9614
  const dropdownRef = React.useRef(null);
@@ -9843,6 +9862,18 @@ function DateTimeInput({
9843
9862
  }
9844
9863
  }, [isControlled, normalizedControlledValue]);
9845
9864
 
9865
+ // keep the timeValue in sync whenever the effective value or start time changes
9866
+ React.useEffect(() => {
9867
+ if (value) {
9868
+ const d = new Date(value);
9869
+ const hh = String(d.getHours()).padStart(2, '0');
9870
+ const mm = String(d.getMinutes()).padStart(2, '0');
9871
+ setTimeValue(`${hh}:${mm}`);
9872
+ } else {
9873
+ setTimeValue(timeStart || '');
9874
+ }
9875
+ }, [value, timeStart]);
9876
+
9846
9877
  // Formatting display (similar to RangePicker)
9847
9878
  const formatDisplay = () => {
9848
9879
  if (!value) return "";
@@ -9939,12 +9970,18 @@ function DateTimeInput({
9939
9970
  };
9940
9971
  const handleTimeChange = e => {
9941
9972
  const t = e.target.value; // HH:mm
9942
- if (!value) return;
9943
- const d = new Date(value);
9973
+ setTimeValue(t);
9974
+ // determine base date: prefer current value, fall back to now
9975
+ const baseDate = value ? new Date(value) : new Date();
9944
9976
  const [h, m] = t.split(":");
9945
- d.setHours(Number(h), Number(m), 0, 0);
9946
- const str = toInputString(d.getTime());
9947
- if (!isControlled) setValue(str);
9977
+ baseDate.setHours(Number(h), Number(m), 0, 0);
9978
+ const str = toInputString(baseDate.getTime());
9979
+ // always update local `value` so the dropdown display keeps up
9980
+ if (!isControlled) {
9981
+ setValue(str);
9982
+ } else {
9983
+ setValue(str);
9984
+ }
9948
9985
  setUrlParam(str);
9949
9986
  onChange?.(str);
9950
9987
  };
@@ -10122,13 +10159,7 @@ function DateTimeInput({
10122
10159
  }
10123
10160
  }, "Time:"), /*#__PURE__*/React.createElement("input", {
10124
10161
  type: "time",
10125
- value: (() => {
10126
- if (!value) return '';
10127
- const d = new Date(value);
10128
- const hh = String(d.getHours()).padStart(2, '0');
10129
- const mm = String(d.getMinutes()).padStart(2, '0');
10130
- return `${hh}:${mm}`;
10131
- })(),
10162
+ value: timeValue,
10132
10163
  onChange: handleTimeChange,
10133
10164
  className: "basic-input",
10134
10165
  disabled: disabled,
@@ -11935,12 +11966,4549 @@ const CardSelect = ({
11935
11966
  })));
11936
11967
  };
11937
11968
 
11969
+ function useCombinedRefs() {
11970
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
11971
+ refs[_key] = arguments[_key];
11972
+ }
11973
+
11974
+ return React.useMemo(() => node => {
11975
+ refs.forEach(ref => ref(node));
11976
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
11977
+ refs);
11978
+ }
11979
+
11980
+ // https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
11981
+ const canUseDOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
11982
+
11983
+ function isWindow(element) {
11984
+ const elementString = Object.prototype.toString.call(element);
11985
+ return elementString === '[object Window]' || // In Electron context the Window object serializes to [object global]
11986
+ elementString === '[object global]';
11987
+ }
11988
+
11989
+ function isNode(node) {
11990
+ return 'nodeType' in node;
11991
+ }
11992
+
11993
+ function getWindow(target) {
11994
+ var _target$ownerDocument, _target$ownerDocument2;
11995
+
11996
+ if (!target) {
11997
+ return window;
11998
+ }
11999
+
12000
+ if (isWindow(target)) {
12001
+ return target;
12002
+ }
12003
+
12004
+ if (!isNode(target)) {
12005
+ return window;
12006
+ }
12007
+
12008
+ return (_target$ownerDocument = (_target$ownerDocument2 = target.ownerDocument) == null ? void 0 : _target$ownerDocument2.defaultView) != null ? _target$ownerDocument : window;
12009
+ }
12010
+
12011
+ function isDocument(node) {
12012
+ const {
12013
+ Document
12014
+ } = getWindow(node);
12015
+ return node instanceof Document;
12016
+ }
12017
+
12018
+ function isHTMLElement(node) {
12019
+ if (isWindow(node)) {
12020
+ return false;
12021
+ }
12022
+
12023
+ return node instanceof getWindow(node).HTMLElement;
12024
+ }
12025
+
12026
+ function isSVGElement(node) {
12027
+ return node instanceof getWindow(node).SVGElement;
12028
+ }
12029
+
12030
+ function getOwnerDocument(target) {
12031
+ if (!target) {
12032
+ return document;
12033
+ }
12034
+
12035
+ if (isWindow(target)) {
12036
+ return target.document;
12037
+ }
12038
+
12039
+ if (!isNode(target)) {
12040
+ return document;
12041
+ }
12042
+
12043
+ if (isDocument(target)) {
12044
+ return target;
12045
+ }
12046
+
12047
+ if (isHTMLElement(target) || isSVGElement(target)) {
12048
+ return target.ownerDocument;
12049
+ }
12050
+
12051
+ return document;
12052
+ }
12053
+
12054
+ /**
12055
+ * A hook that resolves to useEffect on the server and useLayoutEffect on the client
12056
+ * @param callback {function} Callback function that is invoked when the dependencies of the hook change
12057
+ */
12058
+
12059
+ const useIsomorphicLayoutEffect = canUseDOM ? React.useLayoutEffect : React.useEffect;
12060
+
12061
+ function useEvent(handler) {
12062
+ const handlerRef = React.useRef(handler);
12063
+ useIsomorphicLayoutEffect(() => {
12064
+ handlerRef.current = handler;
12065
+ });
12066
+ return React.useCallback(function () {
12067
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12068
+ args[_key] = arguments[_key];
12069
+ }
12070
+
12071
+ return handlerRef.current == null ? void 0 : handlerRef.current(...args);
12072
+ }, []);
12073
+ }
12074
+
12075
+ function useInterval() {
12076
+ const intervalRef = React.useRef(null);
12077
+ const set = React.useCallback((listener, duration) => {
12078
+ intervalRef.current = setInterval(listener, duration);
12079
+ }, []);
12080
+ const clear = React.useCallback(() => {
12081
+ if (intervalRef.current !== null) {
12082
+ clearInterval(intervalRef.current);
12083
+ intervalRef.current = null;
12084
+ }
12085
+ }, []);
12086
+ return [set, clear];
12087
+ }
12088
+
12089
+ function useLatestValue(value, dependencies) {
12090
+ if (dependencies === void 0) {
12091
+ dependencies = [value];
12092
+ }
12093
+
12094
+ const valueRef = React.useRef(value);
12095
+ useIsomorphicLayoutEffect(() => {
12096
+ if (valueRef.current !== value) {
12097
+ valueRef.current = value;
12098
+ }
12099
+ }, dependencies);
12100
+ return valueRef;
12101
+ }
12102
+
12103
+ function useLazyMemo(callback, dependencies) {
12104
+ const valueRef = React.useRef();
12105
+ return React.useMemo(() => {
12106
+ const newValue = callback(valueRef.current);
12107
+ valueRef.current = newValue;
12108
+ return newValue;
12109
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
12110
+ [...dependencies]);
12111
+ }
12112
+
12113
+ function useNodeRef(onChange) {
12114
+ const onChangeHandler = useEvent(onChange);
12115
+ const node = React.useRef(null);
12116
+ const setNodeRef = React.useCallback(element => {
12117
+ if (element !== node.current) {
12118
+ onChangeHandler == null ? void 0 : onChangeHandler(element, node.current);
12119
+ }
12120
+
12121
+ node.current = element;
12122
+ }, //eslint-disable-next-line
12123
+ []);
12124
+ return [node, setNodeRef];
12125
+ }
12126
+
12127
+ function usePrevious(value) {
12128
+ const ref = React.useRef();
12129
+ React.useEffect(() => {
12130
+ ref.current = value;
12131
+ }, [value]);
12132
+ return ref.current;
12133
+ }
12134
+
12135
+ let ids = {};
12136
+ function useUniqueId(prefix, value) {
12137
+ return React.useMemo(() => {
12138
+ if (value) {
12139
+ return value;
12140
+ }
12141
+
12142
+ const id = ids[prefix] == null ? 0 : ids[prefix] + 1;
12143
+ ids[prefix] = id;
12144
+ return prefix + "-" + id;
12145
+ }, [prefix, value]);
12146
+ }
12147
+
12148
+ function createAdjustmentFn(modifier) {
12149
+ return function (object) {
12150
+ for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
12151
+ adjustments[_key - 1] = arguments[_key];
12152
+ }
12153
+
12154
+ return adjustments.reduce((accumulator, adjustment) => {
12155
+ const entries = Object.entries(adjustment);
12156
+
12157
+ for (const [key, valueAdjustment] of entries) {
12158
+ const value = accumulator[key];
12159
+
12160
+ if (value != null) {
12161
+ accumulator[key] = value + modifier * valueAdjustment;
12162
+ }
12163
+ }
12164
+
12165
+ return accumulator;
12166
+ }, { ...object
12167
+ });
12168
+ };
12169
+ }
12170
+
12171
+ const add = /*#__PURE__*/createAdjustmentFn(1);
12172
+ const subtract = /*#__PURE__*/createAdjustmentFn(-1);
12173
+
12174
+ function hasViewportRelativeCoordinates(event) {
12175
+ return 'clientX' in event && 'clientY' in event;
12176
+ }
12177
+
12178
+ function isKeyboardEvent(event) {
12179
+ if (!event) {
12180
+ return false;
12181
+ }
12182
+
12183
+ const {
12184
+ KeyboardEvent
12185
+ } = getWindow(event.target);
12186
+ return KeyboardEvent && event instanceof KeyboardEvent;
12187
+ }
12188
+
12189
+ function isTouchEvent(event) {
12190
+ if (!event) {
12191
+ return false;
12192
+ }
12193
+
12194
+ const {
12195
+ TouchEvent
12196
+ } = getWindow(event.target);
12197
+ return TouchEvent && event instanceof TouchEvent;
12198
+ }
12199
+
12200
+ /**
12201
+ * Returns the normalized x and y coordinates for mouse and touch events.
12202
+ */
12203
+
12204
+ function getEventCoordinates(event) {
12205
+ if (isTouchEvent(event)) {
12206
+ if (event.touches && event.touches.length) {
12207
+ const {
12208
+ clientX: x,
12209
+ clientY: y
12210
+ } = event.touches[0];
12211
+ return {
12212
+ x,
12213
+ y
12214
+ };
12215
+ } else if (event.changedTouches && event.changedTouches.length) {
12216
+ const {
12217
+ clientX: x,
12218
+ clientY: y
12219
+ } = event.changedTouches[0];
12220
+ return {
12221
+ x,
12222
+ y
12223
+ };
12224
+ }
12225
+ }
12226
+
12227
+ if (hasViewportRelativeCoordinates(event)) {
12228
+ return {
12229
+ x: event.clientX,
12230
+ y: event.clientY
12231
+ };
12232
+ }
12233
+
12234
+ return null;
12235
+ }
12236
+
12237
+ const CSS$1 = /*#__PURE__*/Object.freeze({
12238
+ Translate: {
12239
+ toString(transform) {
12240
+ if (!transform) {
12241
+ return;
12242
+ }
12243
+
12244
+ const {
12245
+ x,
12246
+ y
12247
+ } = transform;
12248
+ return "translate3d(" + (x ? Math.round(x) : 0) + "px, " + (y ? Math.round(y) : 0) + "px, 0)";
12249
+ }
12250
+
12251
+ },
12252
+ Scale: {
12253
+ toString(transform) {
12254
+ if (!transform) {
12255
+ return;
12256
+ }
12257
+
12258
+ const {
12259
+ scaleX,
12260
+ scaleY
12261
+ } = transform;
12262
+ return "scaleX(" + scaleX + ") scaleY(" + scaleY + ")";
12263
+ }
12264
+
12265
+ },
12266
+ Transform: {
12267
+ toString(transform) {
12268
+ if (!transform) {
12269
+ return;
12270
+ }
12271
+
12272
+ return [CSS$1.Translate.toString(transform), CSS$1.Scale.toString(transform)].join(' ');
12273
+ }
12274
+
12275
+ },
12276
+ Transition: {
12277
+ toString(_ref) {
12278
+ let {
12279
+ property,
12280
+ duration,
12281
+ easing
12282
+ } = _ref;
12283
+ return property + " " + duration + "ms " + easing;
12284
+ }
12285
+
12286
+ }
12287
+ });
12288
+
12289
+ const SELECTOR = 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';
12290
+ function findFirstFocusableNode(element) {
12291
+ if (element.matches(SELECTOR)) {
12292
+ return element;
12293
+ }
12294
+
12295
+ return element.querySelector(SELECTOR);
12296
+ }
12297
+
12298
+ const hiddenStyles = {
12299
+ display: 'none'
12300
+ };
12301
+ function HiddenText(_ref) {
12302
+ let {
12303
+ id,
12304
+ value
12305
+ } = _ref;
12306
+ return React.createElement("div", {
12307
+ id: id,
12308
+ style: hiddenStyles
12309
+ }, value);
12310
+ }
12311
+
12312
+ function LiveRegion(_ref) {
12313
+ let {
12314
+ id,
12315
+ announcement,
12316
+ ariaLiveType = "assertive"
12317
+ } = _ref;
12318
+ // Hide element visually but keep it readable by screen readers
12319
+ const visuallyHidden = {
12320
+ position: 'fixed',
12321
+ top: 0,
12322
+ left: 0,
12323
+ width: 1,
12324
+ height: 1,
12325
+ margin: -1,
12326
+ border: 0,
12327
+ padding: 0,
12328
+ overflow: 'hidden',
12329
+ clip: 'rect(0 0 0 0)',
12330
+ clipPath: 'inset(100%)',
12331
+ whiteSpace: 'nowrap'
12332
+ };
12333
+ return React.createElement("div", {
12334
+ id: id,
12335
+ style: visuallyHidden,
12336
+ role: "status",
12337
+ "aria-live": ariaLiveType,
12338
+ "aria-atomic": true
12339
+ }, announcement);
12340
+ }
12341
+
12342
+ function useAnnouncement() {
12343
+ const [announcement, setAnnouncement] = React.useState('');
12344
+ const announce = React.useCallback(value => {
12345
+ if (value != null) {
12346
+ setAnnouncement(value);
12347
+ }
12348
+ }, []);
12349
+ return {
12350
+ announce,
12351
+ announcement
12352
+ };
12353
+ }
12354
+
12355
+ const DndMonitorContext = /*#__PURE__*/React.createContext(null);
12356
+
12357
+ function useDndMonitor(listener) {
12358
+ const registerListener = React.useContext(DndMonitorContext);
12359
+ React.useEffect(() => {
12360
+ if (!registerListener) {
12361
+ throw new Error('useDndMonitor must be used within a children of <DndContext>');
12362
+ }
12363
+
12364
+ const unsubscribe = registerListener(listener);
12365
+ return unsubscribe;
12366
+ }, [listener, registerListener]);
12367
+ }
12368
+
12369
+ function useDndMonitorProvider() {
12370
+ const [listeners] = React.useState(() => new Set());
12371
+ const registerListener = React.useCallback(listener => {
12372
+ listeners.add(listener);
12373
+ return () => listeners.delete(listener);
12374
+ }, [listeners]);
12375
+ const dispatch = React.useCallback(_ref => {
12376
+ let {
12377
+ type,
12378
+ event
12379
+ } = _ref;
12380
+ listeners.forEach(listener => {
12381
+ var _listener$type;
12382
+
12383
+ return (_listener$type = listener[type]) == null ? void 0 : _listener$type.call(listener, event);
12384
+ });
12385
+ }, [listeners]);
12386
+ return [dispatch, registerListener];
12387
+ }
12388
+
12389
+ const defaultScreenReaderInstructions = {
12390
+ 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 "
12391
+ };
12392
+ const defaultAnnouncements = {
12393
+ onDragStart(_ref) {
12394
+ let {
12395
+ active
12396
+ } = _ref;
12397
+ return "Picked up draggable item " + active.id + ".";
12398
+ },
12399
+
12400
+ onDragOver(_ref2) {
12401
+ let {
12402
+ active,
12403
+ over
12404
+ } = _ref2;
12405
+
12406
+ if (over) {
12407
+ return "Draggable item " + active.id + " was moved over droppable area " + over.id + ".";
12408
+ }
12409
+
12410
+ return "Draggable item " + active.id + " is no longer over a droppable area.";
12411
+ },
12412
+
12413
+ onDragEnd(_ref3) {
12414
+ let {
12415
+ active,
12416
+ over
12417
+ } = _ref3;
12418
+
12419
+ if (over) {
12420
+ return "Draggable item " + active.id + " was dropped over droppable area " + over.id;
12421
+ }
12422
+
12423
+ return "Draggable item " + active.id + " was dropped.";
12424
+ },
12425
+
12426
+ onDragCancel(_ref4) {
12427
+ let {
12428
+ active
12429
+ } = _ref4;
12430
+ return "Dragging was cancelled. Draggable item " + active.id + " was dropped.";
12431
+ }
12432
+
12433
+ };
12434
+
12435
+ function Accessibility(_ref) {
12436
+ let {
12437
+ announcements = defaultAnnouncements,
12438
+ container,
12439
+ hiddenTextDescribedById,
12440
+ screenReaderInstructions = defaultScreenReaderInstructions
12441
+ } = _ref;
12442
+ const {
12443
+ announce,
12444
+ announcement
12445
+ } = useAnnouncement();
12446
+ const liveRegionId = useUniqueId("DndLiveRegion");
12447
+ const [mounted, setMounted] = React.useState(false);
12448
+ React.useEffect(() => {
12449
+ setMounted(true);
12450
+ }, []);
12451
+ useDndMonitor(React.useMemo(() => ({
12452
+ onDragStart(_ref2) {
12453
+ let {
12454
+ active
12455
+ } = _ref2;
12456
+ announce(announcements.onDragStart({
12457
+ active
12458
+ }));
12459
+ },
12460
+
12461
+ onDragMove(_ref3) {
12462
+ let {
12463
+ active,
12464
+ over
12465
+ } = _ref3;
12466
+
12467
+ if (announcements.onDragMove) {
12468
+ announce(announcements.onDragMove({
12469
+ active,
12470
+ over
12471
+ }));
12472
+ }
12473
+ },
12474
+
12475
+ onDragOver(_ref4) {
12476
+ let {
12477
+ active,
12478
+ over
12479
+ } = _ref4;
12480
+ announce(announcements.onDragOver({
12481
+ active,
12482
+ over
12483
+ }));
12484
+ },
12485
+
12486
+ onDragEnd(_ref5) {
12487
+ let {
12488
+ active,
12489
+ over
12490
+ } = _ref5;
12491
+ announce(announcements.onDragEnd({
12492
+ active,
12493
+ over
12494
+ }));
12495
+ },
12496
+
12497
+ onDragCancel(_ref6) {
12498
+ let {
12499
+ active,
12500
+ over
12501
+ } = _ref6;
12502
+ announce(announcements.onDragCancel({
12503
+ active,
12504
+ over
12505
+ }));
12506
+ }
12507
+
12508
+ }), [announce, announcements]));
12509
+
12510
+ if (!mounted) {
12511
+ return null;
12512
+ }
12513
+
12514
+ const markup = React.createElement(React.Fragment, null, React.createElement(HiddenText, {
12515
+ id: hiddenTextDescribedById,
12516
+ value: screenReaderInstructions.draggable
12517
+ }), React.createElement(LiveRegion, {
12518
+ id: liveRegionId,
12519
+ announcement: announcement
12520
+ }));
12521
+ return container ? reactDom.createPortal(markup, container) : markup;
12522
+ }
12523
+
12524
+ var Action;
12525
+
12526
+ (function (Action) {
12527
+ Action["DragStart"] = "dragStart";
12528
+ Action["DragMove"] = "dragMove";
12529
+ Action["DragEnd"] = "dragEnd";
12530
+ Action["DragCancel"] = "dragCancel";
12531
+ Action["DragOver"] = "dragOver";
12532
+ Action["RegisterDroppable"] = "registerDroppable";
12533
+ Action["SetDroppableDisabled"] = "setDroppableDisabled";
12534
+ Action["UnregisterDroppable"] = "unregisterDroppable";
12535
+ })(Action || (Action = {}));
12536
+
12537
+ function noop() {}
12538
+
12539
+ function useSensor(sensor, options) {
12540
+ return React.useMemo(() => ({
12541
+ sensor,
12542
+ options: {}
12543
+ }), // eslint-disable-next-line react-hooks/exhaustive-deps
12544
+ [sensor, options]);
12545
+ }
12546
+
12547
+ function useSensors() {
12548
+ for (var _len = arguments.length, sensors = new Array(_len), _key = 0; _key < _len; _key++) {
12549
+ sensors[_key] = arguments[_key];
12550
+ }
12551
+
12552
+ return React.useMemo(() => [...sensors].filter(sensor => sensor != null), // eslint-disable-next-line react-hooks/exhaustive-deps
12553
+ [...sensors]);
12554
+ }
12555
+
12556
+ const defaultCoordinates = /*#__PURE__*/Object.freeze({
12557
+ x: 0,
12558
+ y: 0
12559
+ });
12560
+
12561
+ /**
12562
+ * Returns the distance between two points
12563
+ */
12564
+ function distanceBetween(p1, p2) {
12565
+ return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
12566
+ }
12567
+
12568
+ /**
12569
+ * Sort collisions from smallest to greatest value
12570
+ */
12571
+ function sortCollisionsAsc(_ref, _ref2) {
12572
+ let {
12573
+ data: {
12574
+ value: a
12575
+ }
12576
+ } = _ref;
12577
+ let {
12578
+ data: {
12579
+ value: b
12580
+ }
12581
+ } = _ref2;
12582
+ return a - b;
12583
+ }
12584
+ /**
12585
+ * Sort collisions from greatest to smallest value
12586
+ */
12587
+
12588
+ function sortCollisionsDesc(_ref3, _ref4) {
12589
+ let {
12590
+ data: {
12591
+ value: a
12592
+ }
12593
+ } = _ref3;
12594
+ let {
12595
+ data: {
12596
+ value: b
12597
+ }
12598
+ } = _ref4;
12599
+ return b - a;
12600
+ }
12601
+ function getFirstCollision(collisions, property) {
12602
+ if (!collisions || collisions.length === 0) {
12603
+ return null;
12604
+ }
12605
+
12606
+ const [firstCollision] = collisions;
12607
+ return firstCollision[property] ;
12608
+ }
12609
+
12610
+ /**
12611
+ * Returns the coordinates of the center of a given ClientRect
12612
+ */
12613
+
12614
+ function centerOfRectangle(rect, left, top) {
12615
+ if (left === void 0) {
12616
+ left = rect.left;
12617
+ }
12618
+
12619
+ if (top === void 0) {
12620
+ top = rect.top;
12621
+ }
12622
+
12623
+ return {
12624
+ x: left + rect.width * 0.5,
12625
+ y: top + rect.height * 0.5
12626
+ };
12627
+ }
12628
+ /**
12629
+ * Returns the closest rectangles from an array of rectangles to the center of a given
12630
+ * rectangle.
12631
+ */
12632
+
12633
+
12634
+ const closestCenter = _ref => {
12635
+ let {
12636
+ collisionRect,
12637
+ droppableRects,
12638
+ droppableContainers
12639
+ } = _ref;
12640
+ const centerRect = centerOfRectangle(collisionRect, collisionRect.left, collisionRect.top);
12641
+ const collisions = [];
12642
+
12643
+ for (const droppableContainer of droppableContainers) {
12644
+ const {
12645
+ id
12646
+ } = droppableContainer;
12647
+ const rect = droppableRects.get(id);
12648
+
12649
+ if (rect) {
12650
+ const distBetween = distanceBetween(centerOfRectangle(rect), centerRect);
12651
+ collisions.push({
12652
+ id,
12653
+ data: {
12654
+ droppableContainer,
12655
+ value: distBetween
12656
+ }
12657
+ });
12658
+ }
12659
+ }
12660
+
12661
+ return collisions.sort(sortCollisionsAsc);
12662
+ };
12663
+
12664
+ /**
12665
+ * Returns the intersecting rectangle area between two rectangles
12666
+ */
12667
+
12668
+ function getIntersectionRatio(entry, target) {
12669
+ const top = Math.max(target.top, entry.top);
12670
+ const left = Math.max(target.left, entry.left);
12671
+ const right = Math.min(target.left + target.width, entry.left + entry.width);
12672
+ const bottom = Math.min(target.top + target.height, entry.top + entry.height);
12673
+ const width = right - left;
12674
+ const height = bottom - top;
12675
+
12676
+ if (left < right && top < bottom) {
12677
+ const targetArea = target.width * target.height;
12678
+ const entryArea = entry.width * entry.height;
12679
+ const intersectionArea = width * height;
12680
+ const intersectionRatio = intersectionArea / (targetArea + entryArea - intersectionArea);
12681
+ return Number(intersectionRatio.toFixed(4));
12682
+ } // Rectangles do not overlap, or overlap has an area of zero (edge/corner overlap)
12683
+
12684
+
12685
+ return 0;
12686
+ }
12687
+ /**
12688
+ * Returns the rectangles that has the greatest intersection area with a given
12689
+ * rectangle in an array of rectangles.
12690
+ */
12691
+
12692
+ const rectIntersection = _ref => {
12693
+ let {
12694
+ collisionRect,
12695
+ droppableRects,
12696
+ droppableContainers
12697
+ } = _ref;
12698
+ const collisions = [];
12699
+
12700
+ for (const droppableContainer of droppableContainers) {
12701
+ const {
12702
+ id
12703
+ } = droppableContainer;
12704
+ const rect = droppableRects.get(id);
12705
+
12706
+ if (rect) {
12707
+ const intersectionRatio = getIntersectionRatio(rect, collisionRect);
12708
+
12709
+ if (intersectionRatio > 0) {
12710
+ collisions.push({
12711
+ id,
12712
+ data: {
12713
+ droppableContainer,
12714
+ value: intersectionRatio
12715
+ }
12716
+ });
12717
+ }
12718
+ }
12719
+ }
12720
+
12721
+ return collisions.sort(sortCollisionsDesc);
12722
+ };
12723
+
12724
+ function adjustScale(transform, rect1, rect2) {
12725
+ return { ...transform,
12726
+ scaleX: rect1 && rect2 ? rect1.width / rect2.width : 1,
12727
+ scaleY: rect1 && rect2 ? rect1.height / rect2.height : 1
12728
+ };
12729
+ }
12730
+
12731
+ function getRectDelta(rect1, rect2) {
12732
+ return rect1 && rect2 ? {
12733
+ x: rect1.left - rect2.left,
12734
+ y: rect1.top - rect2.top
12735
+ } : defaultCoordinates;
12736
+ }
12737
+
12738
+ function createRectAdjustmentFn(modifier) {
12739
+ return function adjustClientRect(rect) {
12740
+ for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
12741
+ adjustments[_key - 1] = arguments[_key];
12742
+ }
12743
+
12744
+ return adjustments.reduce((acc, adjustment) => ({ ...acc,
12745
+ top: acc.top + modifier * adjustment.y,
12746
+ bottom: acc.bottom + modifier * adjustment.y,
12747
+ left: acc.left + modifier * adjustment.x,
12748
+ right: acc.right + modifier * adjustment.x
12749
+ }), { ...rect
12750
+ });
12751
+ };
12752
+ }
12753
+ const getAdjustedRect = /*#__PURE__*/createRectAdjustmentFn(1);
12754
+
12755
+ function parseTransform(transform) {
12756
+ if (transform.startsWith('matrix3d(')) {
12757
+ const transformArray = transform.slice(9, -1).split(/, /);
12758
+ return {
12759
+ x: +transformArray[12],
12760
+ y: +transformArray[13],
12761
+ scaleX: +transformArray[0],
12762
+ scaleY: +transformArray[5]
12763
+ };
12764
+ } else if (transform.startsWith('matrix(')) {
12765
+ const transformArray = transform.slice(7, -1).split(/, /);
12766
+ return {
12767
+ x: +transformArray[4],
12768
+ y: +transformArray[5],
12769
+ scaleX: +transformArray[0],
12770
+ scaleY: +transformArray[3]
12771
+ };
12772
+ }
12773
+
12774
+ return null;
12775
+ }
12776
+
12777
+ function inverseTransform(rect, transform, transformOrigin) {
12778
+ const parsedTransform = parseTransform(transform);
12779
+
12780
+ if (!parsedTransform) {
12781
+ return rect;
12782
+ }
12783
+
12784
+ const {
12785
+ scaleX,
12786
+ scaleY,
12787
+ x: translateX,
12788
+ y: translateY
12789
+ } = parsedTransform;
12790
+ const x = rect.left - translateX - (1 - scaleX) * parseFloat(transformOrigin);
12791
+ const y = rect.top - translateY - (1 - scaleY) * parseFloat(transformOrigin.slice(transformOrigin.indexOf(' ') + 1));
12792
+ const w = scaleX ? rect.width / scaleX : rect.width;
12793
+ const h = scaleY ? rect.height / scaleY : rect.height;
12794
+ return {
12795
+ width: w,
12796
+ height: h,
12797
+ top: y,
12798
+ right: x + w,
12799
+ bottom: y + h,
12800
+ left: x
12801
+ };
12802
+ }
12803
+
12804
+ const defaultOptions = {
12805
+ ignoreTransform: false
12806
+ };
12807
+ /**
12808
+ * Returns the bounding client rect of an element relative to the viewport.
12809
+ */
12810
+
12811
+ function getClientRect(element, options) {
12812
+ if (options === void 0) {
12813
+ options = defaultOptions;
12814
+ }
12815
+
12816
+ let rect = element.getBoundingClientRect();
12817
+
12818
+ if (options.ignoreTransform) {
12819
+ const {
12820
+ transform,
12821
+ transformOrigin
12822
+ } = getWindow(element).getComputedStyle(element);
12823
+
12824
+ if (transform) {
12825
+ rect = inverseTransform(rect, transform, transformOrigin);
12826
+ }
12827
+ }
12828
+
12829
+ const {
12830
+ top,
12831
+ left,
12832
+ width,
12833
+ height,
12834
+ bottom,
12835
+ right
12836
+ } = rect;
12837
+ return {
12838
+ top,
12839
+ left,
12840
+ width,
12841
+ height,
12842
+ bottom,
12843
+ right
12844
+ };
12845
+ }
12846
+ /**
12847
+ * Returns the bounding client rect of an element relative to the viewport.
12848
+ *
12849
+ * @remarks
12850
+ * The ClientRect returned by this method does not take into account transforms
12851
+ * applied to the element it measures.
12852
+ *
12853
+ */
12854
+
12855
+ function getTransformAgnosticClientRect(element) {
12856
+ return getClientRect(element, {
12857
+ ignoreTransform: true
12858
+ });
12859
+ }
12860
+
12861
+ function getWindowClientRect(element) {
12862
+ const width = element.innerWidth;
12863
+ const height = element.innerHeight;
12864
+ return {
12865
+ top: 0,
12866
+ left: 0,
12867
+ right: width,
12868
+ bottom: height,
12869
+ width,
12870
+ height
12871
+ };
12872
+ }
12873
+
12874
+ function isFixed(node, computedStyle) {
12875
+ if (computedStyle === void 0) {
12876
+ computedStyle = getWindow(node).getComputedStyle(node);
12877
+ }
12878
+
12879
+ return computedStyle.position === 'fixed';
12880
+ }
12881
+
12882
+ function isScrollable(element, computedStyle) {
12883
+ if (computedStyle === void 0) {
12884
+ computedStyle = getWindow(element).getComputedStyle(element);
12885
+ }
12886
+
12887
+ const overflowRegex = /(auto|scroll|overlay)/;
12888
+ const properties = ['overflow', 'overflowX', 'overflowY'];
12889
+ return properties.some(property => {
12890
+ const value = computedStyle[property];
12891
+ return typeof value === 'string' ? overflowRegex.test(value) : false;
12892
+ });
12893
+ }
12894
+
12895
+ function getScrollableAncestors(element, limit) {
12896
+ const scrollParents = [];
12897
+
12898
+ function findScrollableAncestors(node) {
12899
+ if (limit != null && scrollParents.length >= limit) {
12900
+ return scrollParents;
12901
+ }
12902
+
12903
+ if (!node) {
12904
+ return scrollParents;
12905
+ }
12906
+
12907
+ if (isDocument(node) && node.scrollingElement != null && !scrollParents.includes(node.scrollingElement)) {
12908
+ scrollParents.push(node.scrollingElement);
12909
+ return scrollParents;
12910
+ }
12911
+
12912
+ if (!isHTMLElement(node) || isSVGElement(node)) {
12913
+ return scrollParents;
12914
+ }
12915
+
12916
+ if (scrollParents.includes(node)) {
12917
+ return scrollParents;
12918
+ }
12919
+
12920
+ const computedStyle = getWindow(element).getComputedStyle(node);
12921
+
12922
+ if (node !== element) {
12923
+ if (isScrollable(node, computedStyle)) {
12924
+ scrollParents.push(node);
12925
+ }
12926
+ }
12927
+
12928
+ if (isFixed(node, computedStyle)) {
12929
+ return scrollParents;
12930
+ }
12931
+
12932
+ return findScrollableAncestors(node.parentNode);
12933
+ }
12934
+
12935
+ if (!element) {
12936
+ return scrollParents;
12937
+ }
12938
+
12939
+ return findScrollableAncestors(element);
12940
+ }
12941
+ function getFirstScrollableAncestor(node) {
12942
+ const [firstScrollableAncestor] = getScrollableAncestors(node, 1);
12943
+ return firstScrollableAncestor != null ? firstScrollableAncestor : null;
12944
+ }
12945
+
12946
+ function getScrollableElement(element) {
12947
+ if (!canUseDOM || !element) {
12948
+ return null;
12949
+ }
12950
+
12951
+ if (isWindow(element)) {
12952
+ return element;
12953
+ }
12954
+
12955
+ if (!isNode(element)) {
12956
+ return null;
12957
+ }
12958
+
12959
+ if (isDocument(element) || element === getOwnerDocument(element).scrollingElement) {
12960
+ return window;
12961
+ }
12962
+
12963
+ if (isHTMLElement(element)) {
12964
+ return element;
12965
+ }
12966
+
12967
+ return null;
12968
+ }
12969
+
12970
+ function getScrollXCoordinate(element) {
12971
+ if (isWindow(element)) {
12972
+ return element.scrollX;
12973
+ }
12974
+
12975
+ return element.scrollLeft;
12976
+ }
12977
+ function getScrollYCoordinate(element) {
12978
+ if (isWindow(element)) {
12979
+ return element.scrollY;
12980
+ }
12981
+
12982
+ return element.scrollTop;
12983
+ }
12984
+ function getScrollCoordinates(element) {
12985
+ return {
12986
+ x: getScrollXCoordinate(element),
12987
+ y: getScrollYCoordinate(element)
12988
+ };
12989
+ }
12990
+
12991
+ var Direction;
12992
+
12993
+ (function (Direction) {
12994
+ Direction[Direction["Forward"] = 1] = "Forward";
12995
+ Direction[Direction["Backward"] = -1] = "Backward";
12996
+ })(Direction || (Direction = {}));
12997
+
12998
+ function isDocumentScrollingElement(element) {
12999
+ if (!canUseDOM || !element) {
13000
+ return false;
13001
+ }
13002
+
13003
+ return element === document.scrollingElement;
13004
+ }
13005
+
13006
+ function getScrollPosition(scrollingContainer) {
13007
+ const minScroll = {
13008
+ x: 0,
13009
+ y: 0
13010
+ };
13011
+ const dimensions = isDocumentScrollingElement(scrollingContainer) ? {
13012
+ height: window.innerHeight,
13013
+ width: window.innerWidth
13014
+ } : {
13015
+ height: scrollingContainer.clientHeight,
13016
+ width: scrollingContainer.clientWidth
13017
+ };
13018
+ const maxScroll = {
13019
+ x: scrollingContainer.scrollWidth - dimensions.width,
13020
+ y: scrollingContainer.scrollHeight - dimensions.height
13021
+ };
13022
+ const isTop = scrollingContainer.scrollTop <= minScroll.y;
13023
+ const isLeft = scrollingContainer.scrollLeft <= minScroll.x;
13024
+ const isBottom = scrollingContainer.scrollTop >= maxScroll.y;
13025
+ const isRight = scrollingContainer.scrollLeft >= maxScroll.x;
13026
+ return {
13027
+ isTop,
13028
+ isLeft,
13029
+ isBottom,
13030
+ isRight,
13031
+ maxScroll,
13032
+ minScroll
13033
+ };
13034
+ }
13035
+
13036
+ const defaultThreshold = {
13037
+ x: 0.2,
13038
+ y: 0.2
13039
+ };
13040
+ function getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, _ref, acceleration, thresholdPercentage) {
13041
+ let {
13042
+ top,
13043
+ left,
13044
+ right,
13045
+ bottom
13046
+ } = _ref;
13047
+
13048
+ if (acceleration === void 0) {
13049
+ acceleration = 10;
13050
+ }
13051
+
13052
+ if (thresholdPercentage === void 0) {
13053
+ thresholdPercentage = defaultThreshold;
13054
+ }
13055
+
13056
+ const {
13057
+ isTop,
13058
+ isBottom,
13059
+ isLeft,
13060
+ isRight
13061
+ } = getScrollPosition(scrollContainer);
13062
+ const direction = {
13063
+ x: 0,
13064
+ y: 0
13065
+ };
13066
+ const speed = {
13067
+ x: 0,
13068
+ y: 0
13069
+ };
13070
+ const threshold = {
13071
+ height: scrollContainerRect.height * thresholdPercentage.y,
13072
+ width: scrollContainerRect.width * thresholdPercentage.x
13073
+ };
13074
+
13075
+ if (!isTop && top <= scrollContainerRect.top + threshold.height) {
13076
+ // Scroll Up
13077
+ direction.y = Direction.Backward;
13078
+ speed.y = acceleration * Math.abs((scrollContainerRect.top + threshold.height - top) / threshold.height);
13079
+ } else if (!isBottom && bottom >= scrollContainerRect.bottom - threshold.height) {
13080
+ // Scroll Down
13081
+ direction.y = Direction.Forward;
13082
+ speed.y = acceleration * Math.abs((scrollContainerRect.bottom - threshold.height - bottom) / threshold.height);
13083
+ }
13084
+
13085
+ if (!isRight && right >= scrollContainerRect.right - threshold.width) {
13086
+ // Scroll Right
13087
+ direction.x = Direction.Forward;
13088
+ speed.x = acceleration * Math.abs((scrollContainerRect.right - threshold.width - right) / threshold.width);
13089
+ } else if (!isLeft && left <= scrollContainerRect.left + threshold.width) {
13090
+ // Scroll Left
13091
+ direction.x = Direction.Backward;
13092
+ speed.x = acceleration * Math.abs((scrollContainerRect.left + threshold.width - left) / threshold.width);
13093
+ }
13094
+
13095
+ return {
13096
+ direction,
13097
+ speed
13098
+ };
13099
+ }
13100
+
13101
+ function getScrollElementRect(element) {
13102
+ if (element === document.scrollingElement) {
13103
+ const {
13104
+ innerWidth,
13105
+ innerHeight
13106
+ } = window;
13107
+ return {
13108
+ top: 0,
13109
+ left: 0,
13110
+ right: innerWidth,
13111
+ bottom: innerHeight,
13112
+ width: innerWidth,
13113
+ height: innerHeight
13114
+ };
13115
+ }
13116
+
13117
+ const {
13118
+ top,
13119
+ left,
13120
+ right,
13121
+ bottom
13122
+ } = element.getBoundingClientRect();
13123
+ return {
13124
+ top,
13125
+ left,
13126
+ right,
13127
+ bottom,
13128
+ width: element.clientWidth,
13129
+ height: element.clientHeight
13130
+ };
13131
+ }
13132
+
13133
+ function getScrollOffsets(scrollableAncestors) {
13134
+ return scrollableAncestors.reduce((acc, node) => {
13135
+ return add(acc, getScrollCoordinates(node));
13136
+ }, defaultCoordinates);
13137
+ }
13138
+ function getScrollXOffset(scrollableAncestors) {
13139
+ return scrollableAncestors.reduce((acc, node) => {
13140
+ return acc + getScrollXCoordinate(node);
13141
+ }, 0);
13142
+ }
13143
+ function getScrollYOffset(scrollableAncestors) {
13144
+ return scrollableAncestors.reduce((acc, node) => {
13145
+ return acc + getScrollYCoordinate(node);
13146
+ }, 0);
13147
+ }
13148
+
13149
+ function scrollIntoViewIfNeeded(element, measure) {
13150
+ if (measure === void 0) {
13151
+ measure = getClientRect;
13152
+ }
13153
+
13154
+ if (!element) {
13155
+ return;
13156
+ }
13157
+
13158
+ const {
13159
+ top,
13160
+ left,
13161
+ bottom,
13162
+ right
13163
+ } = measure(element);
13164
+ const firstScrollableAncestor = getFirstScrollableAncestor(element);
13165
+
13166
+ if (!firstScrollableAncestor) {
13167
+ return;
13168
+ }
13169
+
13170
+ if (bottom <= 0 || right <= 0 || top >= window.innerHeight || left >= window.innerWidth) {
13171
+ element.scrollIntoView({
13172
+ block: 'center',
13173
+ inline: 'center'
13174
+ });
13175
+ }
13176
+ }
13177
+
13178
+ const properties = [['x', ['left', 'right'], getScrollXOffset], ['y', ['top', 'bottom'], getScrollYOffset]];
13179
+ class Rect {
13180
+ constructor(rect, element) {
13181
+ this.rect = void 0;
13182
+ this.width = void 0;
13183
+ this.height = void 0;
13184
+ this.top = void 0;
13185
+ this.bottom = void 0;
13186
+ this.right = void 0;
13187
+ this.left = void 0;
13188
+ const scrollableAncestors = getScrollableAncestors(element);
13189
+ const scrollOffsets = getScrollOffsets(scrollableAncestors);
13190
+ this.rect = { ...rect
13191
+ };
13192
+ this.width = rect.width;
13193
+ this.height = rect.height;
13194
+
13195
+ for (const [axis, keys, getScrollOffset] of properties) {
13196
+ for (const key of keys) {
13197
+ Object.defineProperty(this, key, {
13198
+ get: () => {
13199
+ const currentOffsets = getScrollOffset(scrollableAncestors);
13200
+ const scrollOffsetsDeltla = scrollOffsets[axis] - currentOffsets;
13201
+ return this.rect[key] + scrollOffsetsDeltla;
13202
+ },
13203
+ enumerable: true
13204
+ });
13205
+ }
13206
+ }
13207
+
13208
+ Object.defineProperty(this, 'rect', {
13209
+ enumerable: false
13210
+ });
13211
+ }
13212
+
13213
+ }
13214
+
13215
+ class Listeners {
13216
+ constructor(target) {
13217
+ this.target = void 0;
13218
+ this.listeners = [];
13219
+
13220
+ this.removeAll = () => {
13221
+ this.listeners.forEach(listener => {
13222
+ var _this$target;
13223
+
13224
+ return (_this$target = this.target) == null ? void 0 : _this$target.removeEventListener(...listener);
13225
+ });
13226
+ };
13227
+
13228
+ this.target = target;
13229
+ }
13230
+
13231
+ add(eventName, handler, options) {
13232
+ var _this$target2;
13233
+
13234
+ (_this$target2 = this.target) == null ? void 0 : _this$target2.addEventListener(eventName, handler, options);
13235
+ this.listeners.push([eventName, handler, options]);
13236
+ }
13237
+
13238
+ }
13239
+
13240
+ function getEventListenerTarget(target) {
13241
+ // If the `event.target` element is removed from the document events will still be targeted
13242
+ // at it, and hence won't always bubble up to the window or document anymore.
13243
+ // If there is any risk of an element being removed while it is being dragged,
13244
+ // the best practice is to attach the event listeners directly to the target.
13245
+ // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
13246
+ const {
13247
+ EventTarget
13248
+ } = getWindow(target);
13249
+ return target instanceof EventTarget ? target : getOwnerDocument(target);
13250
+ }
13251
+
13252
+ function hasExceededDistance(delta, measurement) {
13253
+ const dx = Math.abs(delta.x);
13254
+ const dy = Math.abs(delta.y);
13255
+
13256
+ if (typeof measurement === 'number') {
13257
+ return Math.sqrt(dx ** 2 + dy ** 2) > measurement;
13258
+ }
13259
+
13260
+ if ('x' in measurement && 'y' in measurement) {
13261
+ return dx > measurement.x && dy > measurement.y;
13262
+ }
13263
+
13264
+ if ('x' in measurement) {
13265
+ return dx > measurement.x;
13266
+ }
13267
+
13268
+ if ('y' in measurement) {
13269
+ return dy > measurement.y;
13270
+ }
13271
+
13272
+ return false;
13273
+ }
13274
+
13275
+ var EventName;
13276
+
13277
+ (function (EventName) {
13278
+ EventName["Click"] = "click";
13279
+ EventName["DragStart"] = "dragstart";
13280
+ EventName["Keydown"] = "keydown";
13281
+ EventName["ContextMenu"] = "contextmenu";
13282
+ EventName["Resize"] = "resize";
13283
+ EventName["SelectionChange"] = "selectionchange";
13284
+ EventName["VisibilityChange"] = "visibilitychange";
13285
+ })(EventName || (EventName = {}));
13286
+
13287
+ function preventDefault(event) {
13288
+ event.preventDefault();
13289
+ }
13290
+ function stopPropagation(event) {
13291
+ event.stopPropagation();
13292
+ }
13293
+
13294
+ var KeyboardCode;
13295
+
13296
+ (function (KeyboardCode) {
13297
+ KeyboardCode["Space"] = "Space";
13298
+ KeyboardCode["Down"] = "ArrowDown";
13299
+ KeyboardCode["Right"] = "ArrowRight";
13300
+ KeyboardCode["Left"] = "ArrowLeft";
13301
+ KeyboardCode["Up"] = "ArrowUp";
13302
+ KeyboardCode["Esc"] = "Escape";
13303
+ KeyboardCode["Enter"] = "Enter";
13304
+ KeyboardCode["Tab"] = "Tab";
13305
+ })(KeyboardCode || (KeyboardCode = {}));
13306
+
13307
+ const defaultKeyboardCodes = {
13308
+ start: [KeyboardCode.Space, KeyboardCode.Enter],
13309
+ cancel: [KeyboardCode.Esc],
13310
+ end: [KeyboardCode.Space, KeyboardCode.Enter, KeyboardCode.Tab]
13311
+ };
13312
+ const defaultKeyboardCoordinateGetter = (event, _ref) => {
13313
+ let {
13314
+ currentCoordinates
13315
+ } = _ref;
13316
+
13317
+ switch (event.code) {
13318
+ case KeyboardCode.Right:
13319
+ return { ...currentCoordinates,
13320
+ x: currentCoordinates.x + 25
13321
+ };
13322
+
13323
+ case KeyboardCode.Left:
13324
+ return { ...currentCoordinates,
13325
+ x: currentCoordinates.x - 25
13326
+ };
13327
+
13328
+ case KeyboardCode.Down:
13329
+ return { ...currentCoordinates,
13330
+ y: currentCoordinates.y + 25
13331
+ };
13332
+
13333
+ case KeyboardCode.Up:
13334
+ return { ...currentCoordinates,
13335
+ y: currentCoordinates.y - 25
13336
+ };
13337
+ }
13338
+
13339
+ return undefined;
13340
+ };
13341
+
13342
+ class KeyboardSensor {
13343
+ constructor(props) {
13344
+ this.props = void 0;
13345
+ this.autoScrollEnabled = false;
13346
+ this.referenceCoordinates = void 0;
13347
+ this.listeners = void 0;
13348
+ this.windowListeners = void 0;
13349
+ this.props = props;
13350
+ const {
13351
+ event: {
13352
+ target
13353
+ }
13354
+ } = props;
13355
+ this.props = props;
13356
+ this.listeners = new Listeners(getOwnerDocument(target));
13357
+ this.windowListeners = new Listeners(getWindow(target));
13358
+ this.handleKeyDown = this.handleKeyDown.bind(this);
13359
+ this.handleCancel = this.handleCancel.bind(this);
13360
+ this.attach();
13361
+ }
13362
+
13363
+ attach() {
13364
+ this.handleStart();
13365
+ this.windowListeners.add(EventName.Resize, this.handleCancel);
13366
+ this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
13367
+ setTimeout(() => this.listeners.add(EventName.Keydown, this.handleKeyDown));
13368
+ }
13369
+
13370
+ handleStart() {
13371
+ const {
13372
+ activeNode,
13373
+ onStart
13374
+ } = this.props;
13375
+ const node = activeNode.node.current;
13376
+
13377
+ if (node) {
13378
+ scrollIntoViewIfNeeded(node);
13379
+ }
13380
+
13381
+ onStart(defaultCoordinates);
13382
+ }
13383
+
13384
+ handleKeyDown(event) {
13385
+ if (isKeyboardEvent(event)) {
13386
+ const {
13387
+ active,
13388
+ context,
13389
+ options
13390
+ } = this.props;
13391
+ const {
13392
+ keyboardCodes = defaultKeyboardCodes,
13393
+ coordinateGetter = defaultKeyboardCoordinateGetter,
13394
+ scrollBehavior = 'smooth'
13395
+ } = options;
13396
+ const {
13397
+ code
13398
+ } = event;
13399
+
13400
+ if (keyboardCodes.end.includes(code)) {
13401
+ this.handleEnd(event);
13402
+ return;
13403
+ }
13404
+
13405
+ if (keyboardCodes.cancel.includes(code)) {
13406
+ this.handleCancel(event);
13407
+ return;
13408
+ }
13409
+
13410
+ const {
13411
+ collisionRect
13412
+ } = context.current;
13413
+ const currentCoordinates = collisionRect ? {
13414
+ x: collisionRect.left,
13415
+ y: collisionRect.top
13416
+ } : defaultCoordinates;
13417
+
13418
+ if (!this.referenceCoordinates) {
13419
+ this.referenceCoordinates = currentCoordinates;
13420
+ }
13421
+
13422
+ const newCoordinates = coordinateGetter(event, {
13423
+ active,
13424
+ context: context.current,
13425
+ currentCoordinates
13426
+ });
13427
+
13428
+ if (newCoordinates) {
13429
+ const coordinatesDelta = subtract(newCoordinates, currentCoordinates);
13430
+ const scrollDelta = {
13431
+ x: 0,
13432
+ y: 0
13433
+ };
13434
+ const {
13435
+ scrollableAncestors
13436
+ } = context.current;
13437
+
13438
+ for (const scrollContainer of scrollableAncestors) {
13439
+ const direction = event.code;
13440
+ const {
13441
+ isTop,
13442
+ isRight,
13443
+ isLeft,
13444
+ isBottom,
13445
+ maxScroll,
13446
+ minScroll
13447
+ } = getScrollPosition(scrollContainer);
13448
+ const scrollElementRect = getScrollElementRect(scrollContainer);
13449
+ const clampedCoordinates = {
13450
+ 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)),
13451
+ 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))
13452
+ };
13453
+ const canScrollX = direction === KeyboardCode.Right && !isRight || direction === KeyboardCode.Left && !isLeft;
13454
+ const canScrollY = direction === KeyboardCode.Down && !isBottom || direction === KeyboardCode.Up && !isTop;
13455
+
13456
+ if (canScrollX && clampedCoordinates.x !== newCoordinates.x) {
13457
+ const newScrollCoordinates = scrollContainer.scrollLeft + coordinatesDelta.x;
13458
+ const canScrollToNewCoordinates = direction === KeyboardCode.Right && newScrollCoordinates <= maxScroll.x || direction === KeyboardCode.Left && newScrollCoordinates >= minScroll.x;
13459
+
13460
+ if (canScrollToNewCoordinates && !coordinatesDelta.y) {
13461
+ // We don't need to update coordinates, the scroll adjustment alone will trigger
13462
+ // logic to auto-detect the new container we are over
13463
+ scrollContainer.scrollTo({
13464
+ left: newScrollCoordinates,
13465
+ behavior: scrollBehavior
13466
+ });
13467
+ return;
13468
+ }
13469
+
13470
+ if (canScrollToNewCoordinates) {
13471
+ scrollDelta.x = scrollContainer.scrollLeft - newScrollCoordinates;
13472
+ } else {
13473
+ scrollDelta.x = direction === KeyboardCode.Right ? scrollContainer.scrollLeft - maxScroll.x : scrollContainer.scrollLeft - minScroll.x;
13474
+ }
13475
+
13476
+ if (scrollDelta.x) {
13477
+ scrollContainer.scrollBy({
13478
+ left: -scrollDelta.x,
13479
+ behavior: scrollBehavior
13480
+ });
13481
+ }
13482
+
13483
+ break;
13484
+ } else if (canScrollY && clampedCoordinates.y !== newCoordinates.y) {
13485
+ const newScrollCoordinates = scrollContainer.scrollTop + coordinatesDelta.y;
13486
+ const canScrollToNewCoordinates = direction === KeyboardCode.Down && newScrollCoordinates <= maxScroll.y || direction === KeyboardCode.Up && newScrollCoordinates >= minScroll.y;
13487
+
13488
+ if (canScrollToNewCoordinates && !coordinatesDelta.x) {
13489
+ // We don't need to update coordinates, the scroll adjustment alone will trigger
13490
+ // logic to auto-detect the new container we are over
13491
+ scrollContainer.scrollTo({
13492
+ top: newScrollCoordinates,
13493
+ behavior: scrollBehavior
13494
+ });
13495
+ return;
13496
+ }
13497
+
13498
+ if (canScrollToNewCoordinates) {
13499
+ scrollDelta.y = scrollContainer.scrollTop - newScrollCoordinates;
13500
+ } else {
13501
+ scrollDelta.y = direction === KeyboardCode.Down ? scrollContainer.scrollTop - maxScroll.y : scrollContainer.scrollTop - minScroll.y;
13502
+ }
13503
+
13504
+ if (scrollDelta.y) {
13505
+ scrollContainer.scrollBy({
13506
+ top: -scrollDelta.y,
13507
+ behavior: scrollBehavior
13508
+ });
13509
+ }
13510
+
13511
+ break;
13512
+ }
13513
+ }
13514
+
13515
+ this.handleMove(event, add(subtract(newCoordinates, this.referenceCoordinates), scrollDelta));
13516
+ }
13517
+ }
13518
+ }
13519
+
13520
+ handleMove(event, coordinates) {
13521
+ const {
13522
+ onMove
13523
+ } = this.props;
13524
+ event.preventDefault();
13525
+ onMove(coordinates);
13526
+ }
13527
+
13528
+ handleEnd(event) {
13529
+ const {
13530
+ onEnd
13531
+ } = this.props;
13532
+ event.preventDefault();
13533
+ this.detach();
13534
+ onEnd();
13535
+ }
13536
+
13537
+ handleCancel(event) {
13538
+ const {
13539
+ onCancel
13540
+ } = this.props;
13541
+ event.preventDefault();
13542
+ this.detach();
13543
+ onCancel();
13544
+ }
13545
+
13546
+ detach() {
13547
+ this.listeners.removeAll();
13548
+ this.windowListeners.removeAll();
13549
+ }
13550
+
13551
+ }
13552
+ KeyboardSensor.activators = [{
13553
+ eventName: 'onKeyDown',
13554
+ handler: (event, _ref, _ref2) => {
13555
+ let {
13556
+ keyboardCodes = defaultKeyboardCodes,
13557
+ onActivation
13558
+ } = _ref;
13559
+ let {
13560
+ active
13561
+ } = _ref2;
13562
+ const {
13563
+ code
13564
+ } = event.nativeEvent;
13565
+
13566
+ if (keyboardCodes.start.includes(code)) {
13567
+ const activator = active.activatorNode.current;
13568
+
13569
+ if (activator && event.target !== activator) {
13570
+ return false;
13571
+ }
13572
+
13573
+ event.preventDefault();
13574
+ onActivation == null ? void 0 : onActivation({
13575
+ event: event.nativeEvent
13576
+ });
13577
+ return true;
13578
+ }
13579
+
13580
+ return false;
13581
+ }
13582
+ }];
13583
+
13584
+ function isDistanceConstraint(constraint) {
13585
+ return Boolean(constraint && 'distance' in constraint);
13586
+ }
13587
+
13588
+ function isDelayConstraint(constraint) {
13589
+ return Boolean(constraint && 'delay' in constraint);
13590
+ }
13591
+
13592
+ class AbstractPointerSensor {
13593
+ constructor(props, events, listenerTarget) {
13594
+ var _getEventCoordinates;
13595
+
13596
+ if (listenerTarget === void 0) {
13597
+ listenerTarget = getEventListenerTarget(props.event.target);
13598
+ }
13599
+
13600
+ this.props = void 0;
13601
+ this.events = void 0;
13602
+ this.autoScrollEnabled = true;
13603
+ this.document = void 0;
13604
+ this.activated = false;
13605
+ this.initialCoordinates = void 0;
13606
+ this.timeoutId = null;
13607
+ this.listeners = void 0;
13608
+ this.documentListeners = void 0;
13609
+ this.windowListeners = void 0;
13610
+ this.props = props;
13611
+ this.events = events;
13612
+ const {
13613
+ event
13614
+ } = props;
13615
+ const {
13616
+ target
13617
+ } = event;
13618
+ this.props = props;
13619
+ this.events = events;
13620
+ this.document = getOwnerDocument(target);
13621
+ this.documentListeners = new Listeners(this.document);
13622
+ this.listeners = new Listeners(listenerTarget);
13623
+ this.windowListeners = new Listeners(getWindow(target));
13624
+ this.initialCoordinates = (_getEventCoordinates = getEventCoordinates(event)) != null ? _getEventCoordinates : defaultCoordinates;
13625
+ this.handleStart = this.handleStart.bind(this);
13626
+ this.handleMove = this.handleMove.bind(this);
13627
+ this.handleEnd = this.handleEnd.bind(this);
13628
+ this.handleCancel = this.handleCancel.bind(this);
13629
+ this.handleKeydown = this.handleKeydown.bind(this);
13630
+ this.removeTextSelection = this.removeTextSelection.bind(this);
13631
+ this.attach();
13632
+ }
13633
+
13634
+ attach() {
13635
+ const {
13636
+ events,
13637
+ props: {
13638
+ options: {
13639
+ activationConstraint,
13640
+ bypassActivationConstraint
13641
+ }
13642
+ }
13643
+ } = this;
13644
+ this.listeners.add(events.move.name, this.handleMove, {
13645
+ passive: false
13646
+ });
13647
+ this.listeners.add(events.end.name, this.handleEnd);
13648
+
13649
+ if (events.cancel) {
13650
+ this.listeners.add(events.cancel.name, this.handleCancel);
13651
+ }
13652
+
13653
+ this.windowListeners.add(EventName.Resize, this.handleCancel);
13654
+ this.windowListeners.add(EventName.DragStart, preventDefault);
13655
+ this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
13656
+ this.windowListeners.add(EventName.ContextMenu, preventDefault);
13657
+ this.documentListeners.add(EventName.Keydown, this.handleKeydown);
13658
+
13659
+ if (activationConstraint) {
13660
+ if (bypassActivationConstraint != null && bypassActivationConstraint({
13661
+ event: this.props.event,
13662
+ activeNode: this.props.activeNode,
13663
+ options: this.props.options
13664
+ })) {
13665
+ return this.handleStart();
13666
+ }
13667
+
13668
+ if (isDelayConstraint(activationConstraint)) {
13669
+ this.timeoutId = setTimeout(this.handleStart, activationConstraint.delay);
13670
+ this.handlePending(activationConstraint);
13671
+ return;
13672
+ }
13673
+
13674
+ if (isDistanceConstraint(activationConstraint)) {
13675
+ this.handlePending(activationConstraint);
13676
+ return;
13677
+ }
13678
+ }
13679
+
13680
+ this.handleStart();
13681
+ }
13682
+
13683
+ detach() {
13684
+ this.listeners.removeAll();
13685
+ this.windowListeners.removeAll(); // Wait until the next event loop before removing document listeners
13686
+ // This is necessary because we listen for `click` and `selection` events on the document
13687
+
13688
+ setTimeout(this.documentListeners.removeAll, 50);
13689
+
13690
+ if (this.timeoutId !== null) {
13691
+ clearTimeout(this.timeoutId);
13692
+ this.timeoutId = null;
13693
+ }
13694
+ }
13695
+
13696
+ handlePending(constraint, offset) {
13697
+ const {
13698
+ active,
13699
+ onPending
13700
+ } = this.props;
13701
+ onPending(active, constraint, this.initialCoordinates, offset);
13702
+ }
13703
+
13704
+ handleStart() {
13705
+ const {
13706
+ initialCoordinates
13707
+ } = this;
13708
+ const {
13709
+ onStart
13710
+ } = this.props;
13711
+
13712
+ if (initialCoordinates) {
13713
+ this.activated = true; // Stop propagation of click events once activation constraints are met
13714
+
13715
+ this.documentListeners.add(EventName.Click, stopPropagation, {
13716
+ capture: true
13717
+ }); // Remove any text selection from the document
13718
+
13719
+ this.removeTextSelection(); // Prevent further text selection while dragging
13720
+
13721
+ this.documentListeners.add(EventName.SelectionChange, this.removeTextSelection);
13722
+ onStart(initialCoordinates);
13723
+ }
13724
+ }
13725
+
13726
+ handleMove(event) {
13727
+ var _getEventCoordinates2;
13728
+
13729
+ const {
13730
+ activated,
13731
+ initialCoordinates,
13732
+ props
13733
+ } = this;
13734
+ const {
13735
+ onMove,
13736
+ options: {
13737
+ activationConstraint
13738
+ }
13739
+ } = props;
13740
+
13741
+ if (!initialCoordinates) {
13742
+ return;
13743
+ }
13744
+
13745
+ const coordinates = (_getEventCoordinates2 = getEventCoordinates(event)) != null ? _getEventCoordinates2 : defaultCoordinates;
13746
+ const delta = subtract(initialCoordinates, coordinates); // Constraint validation
13747
+
13748
+ if (!activated && activationConstraint) {
13749
+ if (isDistanceConstraint(activationConstraint)) {
13750
+ if (activationConstraint.tolerance != null && hasExceededDistance(delta, activationConstraint.tolerance)) {
13751
+ return this.handleCancel();
13752
+ }
13753
+
13754
+ if (hasExceededDistance(delta, activationConstraint.distance)) {
13755
+ return this.handleStart();
13756
+ }
13757
+ }
13758
+
13759
+ if (isDelayConstraint(activationConstraint)) {
13760
+ if (hasExceededDistance(delta, activationConstraint.tolerance)) {
13761
+ return this.handleCancel();
13762
+ }
13763
+ }
13764
+
13765
+ this.handlePending(activationConstraint, delta);
13766
+ return;
13767
+ }
13768
+
13769
+ if (event.cancelable) {
13770
+ event.preventDefault();
13771
+ }
13772
+
13773
+ onMove(coordinates);
13774
+ }
13775
+
13776
+ handleEnd() {
13777
+ const {
13778
+ onAbort,
13779
+ onEnd
13780
+ } = this.props;
13781
+ this.detach();
13782
+
13783
+ if (!this.activated) {
13784
+ onAbort(this.props.active);
13785
+ }
13786
+
13787
+ onEnd();
13788
+ }
13789
+
13790
+ handleCancel() {
13791
+ const {
13792
+ onAbort,
13793
+ onCancel
13794
+ } = this.props;
13795
+ this.detach();
13796
+
13797
+ if (!this.activated) {
13798
+ onAbort(this.props.active);
13799
+ }
13800
+
13801
+ onCancel();
13802
+ }
13803
+
13804
+ handleKeydown(event) {
13805
+ if (event.code === KeyboardCode.Esc) {
13806
+ this.handleCancel();
13807
+ }
13808
+ }
13809
+
13810
+ removeTextSelection() {
13811
+ var _this$document$getSel;
13812
+
13813
+ (_this$document$getSel = this.document.getSelection()) == null ? void 0 : _this$document$getSel.removeAllRanges();
13814
+ }
13815
+
13816
+ }
13817
+
13818
+ const events = {
13819
+ cancel: {
13820
+ name: 'pointercancel'
13821
+ },
13822
+ move: {
13823
+ name: 'pointermove'
13824
+ },
13825
+ end: {
13826
+ name: 'pointerup'
13827
+ }
13828
+ };
13829
+ class PointerSensor extends AbstractPointerSensor {
13830
+ constructor(props) {
13831
+ const {
13832
+ event
13833
+ } = props; // Pointer events stop firing if the target is unmounted while dragging
13834
+ // Therefore we attach listeners to the owner document instead
13835
+
13836
+ const listenerTarget = getOwnerDocument(event.target);
13837
+ super(props, events, listenerTarget);
13838
+ }
13839
+
13840
+ }
13841
+ PointerSensor.activators = [{
13842
+ eventName: 'onPointerDown',
13843
+ handler: (_ref, _ref2) => {
13844
+ let {
13845
+ nativeEvent: event
13846
+ } = _ref;
13847
+ let {
13848
+ onActivation
13849
+ } = _ref2;
13850
+
13851
+ if (!event.isPrimary || event.button !== 0) {
13852
+ return false;
13853
+ }
13854
+
13855
+ onActivation == null ? void 0 : onActivation({
13856
+ event
13857
+ });
13858
+ return true;
13859
+ }
13860
+ }];
13861
+
13862
+ const events$1 = {
13863
+ move: {
13864
+ name: 'mousemove'
13865
+ },
13866
+ end: {
13867
+ name: 'mouseup'
13868
+ }
13869
+ };
13870
+ var MouseButton;
13871
+
13872
+ (function (MouseButton) {
13873
+ MouseButton[MouseButton["RightClick"] = 2] = "RightClick";
13874
+ })(MouseButton || (MouseButton = {}));
13875
+
13876
+ class MouseSensor extends AbstractPointerSensor {
13877
+ constructor(props) {
13878
+ super(props, events$1, getOwnerDocument(props.event.target));
13879
+ }
13880
+
13881
+ }
13882
+ MouseSensor.activators = [{
13883
+ eventName: 'onMouseDown',
13884
+ handler: (_ref, _ref2) => {
13885
+ let {
13886
+ nativeEvent: event
13887
+ } = _ref;
13888
+ let {
13889
+ onActivation
13890
+ } = _ref2;
13891
+
13892
+ if (event.button === MouseButton.RightClick) {
13893
+ return false;
13894
+ }
13895
+
13896
+ onActivation == null ? void 0 : onActivation({
13897
+ event
13898
+ });
13899
+ return true;
13900
+ }
13901
+ }];
13902
+
13903
+ const events$2 = {
13904
+ cancel: {
13905
+ name: 'touchcancel'
13906
+ },
13907
+ move: {
13908
+ name: 'touchmove'
13909
+ },
13910
+ end: {
13911
+ name: 'touchend'
13912
+ }
13913
+ };
13914
+ class TouchSensor extends AbstractPointerSensor {
13915
+ constructor(props) {
13916
+ super(props, events$2);
13917
+ }
13918
+
13919
+ static setup() {
13920
+ // Adding a non-capture and non-passive `touchmove` listener in order
13921
+ // to force `event.preventDefault()` calls to work in dynamically added
13922
+ // touchmove event handlers. This is required for iOS Safari.
13923
+ window.addEventListener(events$2.move.name, noop, {
13924
+ capture: false,
13925
+ passive: false
13926
+ });
13927
+ return function teardown() {
13928
+ window.removeEventListener(events$2.move.name, noop);
13929
+ }; // We create a new handler because the teardown function of another sensor
13930
+ // could remove our event listener if we use a referentially equal listener.
13931
+
13932
+ function noop() {}
13933
+ }
13934
+
13935
+ }
13936
+ TouchSensor.activators = [{
13937
+ eventName: 'onTouchStart',
13938
+ handler: (_ref, _ref2) => {
13939
+ let {
13940
+ nativeEvent: event
13941
+ } = _ref;
13942
+ let {
13943
+ onActivation
13944
+ } = _ref2;
13945
+ const {
13946
+ touches
13947
+ } = event;
13948
+
13949
+ if (touches.length > 1) {
13950
+ return false;
13951
+ }
13952
+
13953
+ onActivation == null ? void 0 : onActivation({
13954
+ event
13955
+ });
13956
+ return true;
13957
+ }
13958
+ }];
13959
+
13960
+ var AutoScrollActivator;
13961
+
13962
+ (function (AutoScrollActivator) {
13963
+ AutoScrollActivator[AutoScrollActivator["Pointer"] = 0] = "Pointer";
13964
+ AutoScrollActivator[AutoScrollActivator["DraggableRect"] = 1] = "DraggableRect";
13965
+ })(AutoScrollActivator || (AutoScrollActivator = {}));
13966
+
13967
+ var TraversalOrder;
13968
+
13969
+ (function (TraversalOrder) {
13970
+ TraversalOrder[TraversalOrder["TreeOrder"] = 0] = "TreeOrder";
13971
+ TraversalOrder[TraversalOrder["ReversedTreeOrder"] = 1] = "ReversedTreeOrder";
13972
+ })(TraversalOrder || (TraversalOrder = {}));
13973
+
13974
+ function useAutoScroller(_ref) {
13975
+ let {
13976
+ acceleration,
13977
+ activator = AutoScrollActivator.Pointer,
13978
+ canScroll,
13979
+ draggingRect,
13980
+ enabled,
13981
+ interval = 5,
13982
+ order = TraversalOrder.TreeOrder,
13983
+ pointerCoordinates,
13984
+ scrollableAncestors,
13985
+ scrollableAncestorRects,
13986
+ delta,
13987
+ threshold
13988
+ } = _ref;
13989
+ const scrollIntent = useScrollIntent({
13990
+ delta,
13991
+ disabled: !enabled
13992
+ });
13993
+ const [setAutoScrollInterval, clearAutoScrollInterval] = useInterval();
13994
+ const scrollSpeed = React.useRef({
13995
+ x: 0,
13996
+ y: 0
13997
+ });
13998
+ const scrollDirection = React.useRef({
13999
+ x: 0,
14000
+ y: 0
14001
+ });
14002
+ const rect = React.useMemo(() => {
14003
+ switch (activator) {
14004
+ case AutoScrollActivator.Pointer:
14005
+ return pointerCoordinates ? {
14006
+ top: pointerCoordinates.y,
14007
+ bottom: pointerCoordinates.y,
14008
+ left: pointerCoordinates.x,
14009
+ right: pointerCoordinates.x
14010
+ } : null;
14011
+
14012
+ case AutoScrollActivator.DraggableRect:
14013
+ return draggingRect;
14014
+ }
14015
+ }, [activator, draggingRect, pointerCoordinates]);
14016
+ const scrollContainerRef = React.useRef(null);
14017
+ const autoScroll = React.useCallback(() => {
14018
+ const scrollContainer = scrollContainerRef.current;
14019
+
14020
+ if (!scrollContainer) {
14021
+ return;
14022
+ }
14023
+
14024
+ const scrollLeft = scrollSpeed.current.x * scrollDirection.current.x;
14025
+ const scrollTop = scrollSpeed.current.y * scrollDirection.current.y;
14026
+ scrollContainer.scrollBy(scrollLeft, scrollTop);
14027
+ }, []);
14028
+ const sortedScrollableAncestors = React.useMemo(() => order === TraversalOrder.TreeOrder ? [...scrollableAncestors].reverse() : scrollableAncestors, [order, scrollableAncestors]);
14029
+ React.useEffect(() => {
14030
+ if (!enabled || !scrollableAncestors.length || !rect) {
14031
+ clearAutoScrollInterval();
14032
+ return;
14033
+ }
14034
+
14035
+ for (const scrollContainer of sortedScrollableAncestors) {
14036
+ if ((canScroll == null ? void 0 : canScroll(scrollContainer)) === false) {
14037
+ continue;
14038
+ }
14039
+
14040
+ const index = scrollableAncestors.indexOf(scrollContainer);
14041
+ const scrollContainerRect = scrollableAncestorRects[index];
14042
+
14043
+ if (!scrollContainerRect) {
14044
+ continue;
14045
+ }
14046
+
14047
+ const {
14048
+ direction,
14049
+ speed
14050
+ } = getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, rect, acceleration, threshold);
14051
+
14052
+ for (const axis of ['x', 'y']) {
14053
+ if (!scrollIntent[axis][direction[axis]]) {
14054
+ speed[axis] = 0;
14055
+ direction[axis] = 0;
14056
+ }
14057
+ }
14058
+
14059
+ if (speed.x > 0 || speed.y > 0) {
14060
+ clearAutoScrollInterval();
14061
+ scrollContainerRef.current = scrollContainer;
14062
+ setAutoScrollInterval(autoScroll, interval);
14063
+ scrollSpeed.current = speed;
14064
+ scrollDirection.current = direction;
14065
+ return;
14066
+ }
14067
+ }
14068
+
14069
+ scrollSpeed.current = {
14070
+ x: 0,
14071
+ y: 0
14072
+ };
14073
+ scrollDirection.current = {
14074
+ x: 0,
14075
+ y: 0
14076
+ };
14077
+ clearAutoScrollInterval();
14078
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
14079
+ [acceleration, autoScroll, canScroll, clearAutoScrollInterval, enabled, interval, // eslint-disable-next-line react-hooks/exhaustive-deps
14080
+ JSON.stringify(rect), // eslint-disable-next-line react-hooks/exhaustive-deps
14081
+ JSON.stringify(scrollIntent), setAutoScrollInterval, scrollableAncestors, sortedScrollableAncestors, scrollableAncestorRects, // eslint-disable-next-line react-hooks/exhaustive-deps
14082
+ JSON.stringify(threshold)]);
14083
+ }
14084
+ const defaultScrollIntent = {
14085
+ x: {
14086
+ [Direction.Backward]: false,
14087
+ [Direction.Forward]: false
14088
+ },
14089
+ y: {
14090
+ [Direction.Backward]: false,
14091
+ [Direction.Forward]: false
14092
+ }
14093
+ };
14094
+
14095
+ function useScrollIntent(_ref2) {
14096
+ let {
14097
+ delta,
14098
+ disabled
14099
+ } = _ref2;
14100
+ const previousDelta = usePrevious(delta);
14101
+ return useLazyMemo(previousIntent => {
14102
+ if (disabled || !previousDelta || !previousIntent) {
14103
+ // Reset scroll intent tracking when auto-scrolling is disabled
14104
+ return defaultScrollIntent;
14105
+ }
14106
+
14107
+ const direction = {
14108
+ x: Math.sign(delta.x - previousDelta.x),
14109
+ y: Math.sign(delta.y - previousDelta.y)
14110
+ }; // Keep track of the user intent to scroll in each direction for both axis
14111
+
14112
+ return {
14113
+ x: {
14114
+ [Direction.Backward]: previousIntent.x[Direction.Backward] || direction.x === -1,
14115
+ [Direction.Forward]: previousIntent.x[Direction.Forward] || direction.x === 1
14116
+ },
14117
+ y: {
14118
+ [Direction.Backward]: previousIntent.y[Direction.Backward] || direction.y === -1,
14119
+ [Direction.Forward]: previousIntent.y[Direction.Forward] || direction.y === 1
14120
+ }
14121
+ };
14122
+ }, [disabled, delta, previousDelta]);
14123
+ }
14124
+
14125
+ function useCachedNode(draggableNodes, id) {
14126
+ const draggableNode = id != null ? draggableNodes.get(id) : undefined;
14127
+ const node = draggableNode ? draggableNode.node.current : null;
14128
+ return useLazyMemo(cachedNode => {
14129
+ var _ref;
14130
+
14131
+ if (id == null) {
14132
+ return null;
14133
+ } // In some cases, the draggable node can unmount while dragging
14134
+ // This is the case for virtualized lists. In those situations,
14135
+ // we fall back to the last known value for that node.
14136
+
14137
+
14138
+ return (_ref = node != null ? node : cachedNode) != null ? _ref : null;
14139
+ }, [node, id]);
14140
+ }
14141
+
14142
+ function useCombineActivators(sensors, getSyntheticHandler) {
14143
+ return React.useMemo(() => sensors.reduce((accumulator, sensor) => {
14144
+ const {
14145
+ sensor: Sensor
14146
+ } = sensor;
14147
+ const sensorActivators = Sensor.activators.map(activator => ({
14148
+ eventName: activator.eventName,
14149
+ handler: getSyntheticHandler(activator.handler, sensor)
14150
+ }));
14151
+ return [...accumulator, ...sensorActivators];
14152
+ }, []), [sensors, getSyntheticHandler]);
14153
+ }
14154
+
14155
+ var MeasuringStrategy;
14156
+
14157
+ (function (MeasuringStrategy) {
14158
+ MeasuringStrategy[MeasuringStrategy["Always"] = 0] = "Always";
14159
+ MeasuringStrategy[MeasuringStrategy["BeforeDragging"] = 1] = "BeforeDragging";
14160
+ MeasuringStrategy[MeasuringStrategy["WhileDragging"] = 2] = "WhileDragging";
14161
+ })(MeasuringStrategy || (MeasuringStrategy = {}));
14162
+
14163
+ var MeasuringFrequency;
14164
+
14165
+ (function (MeasuringFrequency) {
14166
+ MeasuringFrequency["Optimized"] = "optimized";
14167
+ })(MeasuringFrequency || (MeasuringFrequency = {}));
14168
+
14169
+ const defaultValue = /*#__PURE__*/new Map();
14170
+ function useDroppableMeasuring(containers, _ref) {
14171
+ let {
14172
+ dragging,
14173
+ dependencies,
14174
+ config
14175
+ } = _ref;
14176
+ const [queue, setQueue] = React.useState(null);
14177
+ const {
14178
+ frequency,
14179
+ measure,
14180
+ strategy
14181
+ } = config;
14182
+ const containersRef = React.useRef(containers);
14183
+ const disabled = isDisabled();
14184
+ const disabledRef = useLatestValue(disabled);
14185
+ const measureDroppableContainers = React.useCallback(function (ids) {
14186
+ if (ids === void 0) {
14187
+ ids = [];
14188
+ }
14189
+
14190
+ if (disabledRef.current) {
14191
+ return;
14192
+ }
14193
+
14194
+ setQueue(value => {
14195
+ if (value === null) {
14196
+ return ids;
14197
+ }
14198
+
14199
+ return value.concat(ids.filter(id => !value.includes(id)));
14200
+ });
14201
+ }, [disabledRef]);
14202
+ const timeoutId = React.useRef(null);
14203
+ const droppableRects = useLazyMemo(previousValue => {
14204
+ if (disabled && !dragging) {
14205
+ return defaultValue;
14206
+ }
14207
+
14208
+ if (!previousValue || previousValue === defaultValue || containersRef.current !== containers || queue != null) {
14209
+ const map = new Map();
14210
+
14211
+ for (let container of containers) {
14212
+ if (!container) {
14213
+ continue;
14214
+ }
14215
+
14216
+ if (queue && queue.length > 0 && !queue.includes(container.id) && container.rect.current) {
14217
+ // This container does not need to be re-measured
14218
+ map.set(container.id, container.rect.current);
14219
+ continue;
14220
+ }
14221
+
14222
+ const node = container.node.current;
14223
+ const rect = node ? new Rect(measure(node), node) : null;
14224
+ container.rect.current = rect;
14225
+
14226
+ if (rect) {
14227
+ map.set(container.id, rect);
14228
+ }
14229
+ }
14230
+
14231
+ return map;
14232
+ }
14233
+
14234
+ return previousValue;
14235
+ }, [containers, queue, dragging, disabled, measure]);
14236
+ React.useEffect(() => {
14237
+ containersRef.current = containers;
14238
+ }, [containers]);
14239
+ React.useEffect(() => {
14240
+ if (disabled) {
14241
+ return;
14242
+ }
14243
+
14244
+ measureDroppableContainers();
14245
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
14246
+ [dragging, disabled]);
14247
+ React.useEffect(() => {
14248
+ if (queue && queue.length > 0) {
14249
+ setQueue(null);
14250
+ }
14251
+ }, //eslint-disable-next-line react-hooks/exhaustive-deps
14252
+ [JSON.stringify(queue)]);
14253
+ React.useEffect(() => {
14254
+ if (disabled || typeof frequency !== 'number' || timeoutId.current !== null) {
14255
+ return;
14256
+ }
14257
+
14258
+ timeoutId.current = setTimeout(() => {
14259
+ measureDroppableContainers();
14260
+ timeoutId.current = null;
14261
+ }, frequency);
14262
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
14263
+ [frequency, disabled, measureDroppableContainers, ...dependencies]);
14264
+ return {
14265
+ droppableRects,
14266
+ measureDroppableContainers,
14267
+ measuringScheduled: queue != null
14268
+ };
14269
+
14270
+ function isDisabled() {
14271
+ switch (strategy) {
14272
+ case MeasuringStrategy.Always:
14273
+ return false;
14274
+
14275
+ case MeasuringStrategy.BeforeDragging:
14276
+ return dragging;
14277
+
14278
+ default:
14279
+ return !dragging;
14280
+ }
14281
+ }
14282
+ }
14283
+
14284
+ function useInitialValue(value, computeFn) {
14285
+ return useLazyMemo(previousValue => {
14286
+ if (!value) {
14287
+ return null;
14288
+ }
14289
+
14290
+ if (previousValue) {
14291
+ return previousValue;
14292
+ }
14293
+
14294
+ return typeof computeFn === 'function' ? computeFn(value) : value;
14295
+ }, [computeFn, value]);
14296
+ }
14297
+
14298
+ function useInitialRect(node, measure) {
14299
+ return useInitialValue(node, measure);
14300
+ }
14301
+
14302
+ /**
14303
+ * Returns a new MutationObserver instance.
14304
+ * If `MutationObserver` is undefined in the execution environment, returns `undefined`.
14305
+ */
14306
+
14307
+ function useMutationObserver(_ref) {
14308
+ let {
14309
+ callback,
14310
+ disabled
14311
+ } = _ref;
14312
+ const handleMutations = useEvent(callback);
14313
+ const mutationObserver = React.useMemo(() => {
14314
+ if (disabled || typeof window === 'undefined' || typeof window.MutationObserver === 'undefined') {
14315
+ return undefined;
14316
+ }
14317
+
14318
+ const {
14319
+ MutationObserver
14320
+ } = window;
14321
+ return new MutationObserver(handleMutations);
14322
+ }, [handleMutations, disabled]);
14323
+ React.useEffect(() => {
14324
+ return () => mutationObserver == null ? void 0 : mutationObserver.disconnect();
14325
+ }, [mutationObserver]);
14326
+ return mutationObserver;
14327
+ }
14328
+
14329
+ /**
14330
+ * Returns a new ResizeObserver instance bound to the `onResize` callback.
14331
+ * If `ResizeObserver` is undefined in the execution environment, returns `undefined`.
14332
+ */
14333
+
14334
+ function useResizeObserver(_ref) {
14335
+ let {
14336
+ callback,
14337
+ disabled
14338
+ } = _ref;
14339
+ const handleResize = useEvent(callback);
14340
+ const resizeObserver = React.useMemo(() => {
14341
+ if (disabled || typeof window === 'undefined' || typeof window.ResizeObserver === 'undefined') {
14342
+ return undefined;
14343
+ }
14344
+
14345
+ const {
14346
+ ResizeObserver
14347
+ } = window;
14348
+ return new ResizeObserver(handleResize);
14349
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
14350
+ [disabled]);
14351
+ React.useEffect(() => {
14352
+ return () => resizeObserver == null ? void 0 : resizeObserver.disconnect();
14353
+ }, [resizeObserver]);
14354
+ return resizeObserver;
14355
+ }
14356
+
14357
+ function defaultMeasure(element) {
14358
+ return new Rect(getClientRect(element), element);
14359
+ }
14360
+
14361
+ function useRect(element, measure, fallbackRect) {
14362
+ if (measure === void 0) {
14363
+ measure = defaultMeasure;
14364
+ }
14365
+
14366
+ const [rect, setRect] = React.useState(null);
14367
+
14368
+ function measureRect() {
14369
+ setRect(currentRect => {
14370
+ if (!element) {
14371
+ return null;
14372
+ }
14373
+
14374
+ if (element.isConnected === false) {
14375
+ var _ref;
14376
+
14377
+ // Fall back to last rect we measured if the element is
14378
+ // no longer connected to the DOM.
14379
+ return (_ref = currentRect != null ? currentRect : fallbackRect) != null ? _ref : null;
14380
+ }
14381
+
14382
+ const newRect = measure(element);
14383
+
14384
+ if (JSON.stringify(currentRect) === JSON.stringify(newRect)) {
14385
+ return currentRect;
14386
+ }
14387
+
14388
+ return newRect;
14389
+ });
14390
+ }
14391
+
14392
+ const mutationObserver = useMutationObserver({
14393
+ callback(records) {
14394
+ if (!element) {
14395
+ return;
14396
+ }
14397
+
14398
+ for (const record of records) {
14399
+ const {
14400
+ type,
14401
+ target
14402
+ } = record;
14403
+
14404
+ if (type === 'childList' && target instanceof HTMLElement && target.contains(element)) {
14405
+ measureRect();
14406
+ break;
14407
+ }
14408
+ }
14409
+ }
14410
+
14411
+ });
14412
+ const resizeObserver = useResizeObserver({
14413
+ callback: measureRect
14414
+ });
14415
+ useIsomorphicLayoutEffect(() => {
14416
+ measureRect();
14417
+
14418
+ if (element) {
14419
+ resizeObserver == null ? void 0 : resizeObserver.observe(element);
14420
+ mutationObserver == null ? void 0 : mutationObserver.observe(document.body, {
14421
+ childList: true,
14422
+ subtree: true
14423
+ });
14424
+ } else {
14425
+ resizeObserver == null ? void 0 : resizeObserver.disconnect();
14426
+ mutationObserver == null ? void 0 : mutationObserver.disconnect();
14427
+ }
14428
+ }, [element]);
14429
+ return rect;
14430
+ }
14431
+
14432
+ function useRectDelta(rect) {
14433
+ const initialRect = useInitialValue(rect);
14434
+ return getRectDelta(rect, initialRect);
14435
+ }
14436
+
14437
+ const defaultValue$1 = [];
14438
+ function useScrollableAncestors(node) {
14439
+ const previousNode = React.useRef(node);
14440
+ const ancestors = useLazyMemo(previousValue => {
14441
+ if (!node) {
14442
+ return defaultValue$1;
14443
+ }
14444
+
14445
+ if (previousValue && previousValue !== defaultValue$1 && node && previousNode.current && node.parentNode === previousNode.current.parentNode) {
14446
+ return previousValue;
14447
+ }
14448
+
14449
+ return getScrollableAncestors(node);
14450
+ }, [node]);
14451
+ React.useEffect(() => {
14452
+ previousNode.current = node;
14453
+ }, [node]);
14454
+ return ancestors;
14455
+ }
14456
+
14457
+ function useScrollOffsets(elements) {
14458
+ const [scrollCoordinates, setScrollCoordinates] = React.useState(null);
14459
+ const prevElements = React.useRef(elements); // To-do: Throttle the handleScroll callback
14460
+
14461
+ const handleScroll = React.useCallback(event => {
14462
+ const scrollingElement = getScrollableElement(event.target);
14463
+
14464
+ if (!scrollingElement) {
14465
+ return;
14466
+ }
14467
+
14468
+ setScrollCoordinates(scrollCoordinates => {
14469
+ if (!scrollCoordinates) {
14470
+ return null;
14471
+ }
14472
+
14473
+ scrollCoordinates.set(scrollingElement, getScrollCoordinates(scrollingElement));
14474
+ return new Map(scrollCoordinates);
14475
+ });
14476
+ }, []);
14477
+ React.useEffect(() => {
14478
+ const previousElements = prevElements.current;
14479
+
14480
+ if (elements !== previousElements) {
14481
+ cleanup(previousElements);
14482
+ const entries = elements.map(element => {
14483
+ const scrollableElement = getScrollableElement(element);
14484
+
14485
+ if (scrollableElement) {
14486
+ scrollableElement.addEventListener('scroll', handleScroll, {
14487
+ passive: true
14488
+ });
14489
+ return [scrollableElement, getScrollCoordinates(scrollableElement)];
14490
+ }
14491
+
14492
+ return null;
14493
+ }).filter(entry => entry != null);
14494
+ setScrollCoordinates(entries.length ? new Map(entries) : null);
14495
+ prevElements.current = elements;
14496
+ }
14497
+
14498
+ return () => {
14499
+ cleanup(elements);
14500
+ cleanup(previousElements);
14501
+ };
14502
+
14503
+ function cleanup(elements) {
14504
+ elements.forEach(element => {
14505
+ const scrollableElement = getScrollableElement(element);
14506
+ scrollableElement == null ? void 0 : scrollableElement.removeEventListener('scroll', handleScroll);
14507
+ });
14508
+ }
14509
+ }, [handleScroll, elements]);
14510
+ return React.useMemo(() => {
14511
+ if (elements.length) {
14512
+ return scrollCoordinates ? Array.from(scrollCoordinates.values()).reduce((acc, coordinates) => add(acc, coordinates), defaultCoordinates) : getScrollOffsets(elements);
14513
+ }
14514
+
14515
+ return defaultCoordinates;
14516
+ }, [elements, scrollCoordinates]);
14517
+ }
14518
+
14519
+ function useScrollOffsetsDelta(scrollOffsets, dependencies) {
14520
+ if (dependencies === void 0) {
14521
+ dependencies = [];
14522
+ }
14523
+
14524
+ const initialScrollOffsets = React.useRef(null);
14525
+ React.useEffect(() => {
14526
+ initialScrollOffsets.current = null;
14527
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
14528
+ dependencies);
14529
+ React.useEffect(() => {
14530
+ const hasScrollOffsets = scrollOffsets !== defaultCoordinates;
14531
+
14532
+ if (hasScrollOffsets && !initialScrollOffsets.current) {
14533
+ initialScrollOffsets.current = scrollOffsets;
14534
+ }
14535
+
14536
+ if (!hasScrollOffsets && initialScrollOffsets.current) {
14537
+ initialScrollOffsets.current = null;
14538
+ }
14539
+ }, [scrollOffsets]);
14540
+ return initialScrollOffsets.current ? subtract(scrollOffsets, initialScrollOffsets.current) : defaultCoordinates;
14541
+ }
14542
+
14543
+ function useSensorSetup(sensors) {
14544
+ React.useEffect(() => {
14545
+ if (!canUseDOM) {
14546
+ return;
14547
+ }
14548
+
14549
+ const teardownFns = sensors.map(_ref => {
14550
+ let {
14551
+ sensor
14552
+ } = _ref;
14553
+ return sensor.setup == null ? void 0 : sensor.setup();
14554
+ });
14555
+ return () => {
14556
+ for (const teardown of teardownFns) {
14557
+ teardown == null ? void 0 : teardown();
14558
+ }
14559
+ };
14560
+ }, // TO-DO: Sensors length could theoretically change which would not be a valid dependency
14561
+ // eslint-disable-next-line react-hooks/exhaustive-deps
14562
+ sensors.map(_ref2 => {
14563
+ let {
14564
+ sensor
14565
+ } = _ref2;
14566
+ return sensor;
14567
+ }));
14568
+ }
14569
+
14570
+ function useSyntheticListeners(listeners, id) {
14571
+ return React.useMemo(() => {
14572
+ return listeners.reduce((acc, _ref) => {
14573
+ let {
14574
+ eventName,
14575
+ handler
14576
+ } = _ref;
14577
+
14578
+ acc[eventName] = event => {
14579
+ handler(event, id);
14580
+ };
14581
+
14582
+ return acc;
14583
+ }, {});
14584
+ }, [listeners, id]);
14585
+ }
14586
+
14587
+ function useWindowRect(element) {
14588
+ return React.useMemo(() => element ? getWindowClientRect(element) : null, [element]);
14589
+ }
14590
+
14591
+ const defaultValue$2 = [];
14592
+ function useRects(elements, measure) {
14593
+ if (measure === void 0) {
14594
+ measure = getClientRect;
14595
+ }
14596
+
14597
+ const [firstElement] = elements;
14598
+ const windowRect = useWindowRect(firstElement ? getWindow(firstElement) : null);
14599
+ const [rects, setRects] = React.useState(defaultValue$2);
14600
+
14601
+ function measureRects() {
14602
+ setRects(() => {
14603
+ if (!elements.length) {
14604
+ return defaultValue$2;
14605
+ }
14606
+
14607
+ return elements.map(element => isDocumentScrollingElement(element) ? windowRect : new Rect(measure(element), element));
14608
+ });
14609
+ }
14610
+
14611
+ const resizeObserver = useResizeObserver({
14612
+ callback: measureRects
14613
+ });
14614
+ useIsomorphicLayoutEffect(() => {
14615
+ resizeObserver == null ? void 0 : resizeObserver.disconnect();
14616
+ measureRects();
14617
+ elements.forEach(element => resizeObserver == null ? void 0 : resizeObserver.observe(element));
14618
+ }, [elements]);
14619
+ return rects;
14620
+ }
14621
+
14622
+ function getMeasurableNode(node) {
14623
+ if (!node) {
14624
+ return null;
14625
+ }
14626
+
14627
+ if (node.children.length > 1) {
14628
+ return node;
14629
+ }
14630
+
14631
+ const firstChild = node.children[0];
14632
+ return isHTMLElement(firstChild) ? firstChild : node;
14633
+ }
14634
+
14635
+ function useDragOverlayMeasuring(_ref) {
14636
+ let {
14637
+ measure
14638
+ } = _ref;
14639
+ const [rect, setRect] = React.useState(null);
14640
+ const handleResize = React.useCallback(entries => {
14641
+ for (const {
14642
+ target
14643
+ } of entries) {
14644
+ if (isHTMLElement(target)) {
14645
+ setRect(rect => {
14646
+ const newRect = measure(target);
14647
+ return rect ? { ...rect,
14648
+ width: newRect.width,
14649
+ height: newRect.height
14650
+ } : newRect;
14651
+ });
14652
+ break;
14653
+ }
14654
+ }
14655
+ }, [measure]);
14656
+ const resizeObserver = useResizeObserver({
14657
+ callback: handleResize
14658
+ });
14659
+ const handleNodeChange = React.useCallback(element => {
14660
+ const node = getMeasurableNode(element);
14661
+ resizeObserver == null ? void 0 : resizeObserver.disconnect();
14662
+
14663
+ if (node) {
14664
+ resizeObserver == null ? void 0 : resizeObserver.observe(node);
14665
+ }
14666
+
14667
+ setRect(node ? measure(node) : null);
14668
+ }, [measure, resizeObserver]);
14669
+ const [nodeRef, setRef] = useNodeRef(handleNodeChange);
14670
+ return React.useMemo(() => ({
14671
+ nodeRef,
14672
+ rect,
14673
+ setRef
14674
+ }), [rect, nodeRef, setRef]);
14675
+ }
14676
+
14677
+ const defaultSensors = [{
14678
+ sensor: PointerSensor,
14679
+ options: {}
14680
+ }, {
14681
+ sensor: KeyboardSensor,
14682
+ options: {}
14683
+ }];
14684
+ const defaultData = {
14685
+ current: {}
14686
+ };
14687
+ const defaultMeasuringConfiguration = {
14688
+ draggable: {
14689
+ measure: getTransformAgnosticClientRect
14690
+ },
14691
+ droppable: {
14692
+ measure: getTransformAgnosticClientRect,
14693
+ strategy: MeasuringStrategy.WhileDragging,
14694
+ frequency: MeasuringFrequency.Optimized
14695
+ },
14696
+ dragOverlay: {
14697
+ measure: getClientRect
14698
+ }
14699
+ };
14700
+
14701
+ class DroppableContainersMap extends Map {
14702
+ get(id) {
14703
+ var _super$get;
14704
+
14705
+ return id != null ? (_super$get = super.get(id)) != null ? _super$get : undefined : undefined;
14706
+ }
14707
+
14708
+ toArray() {
14709
+ return Array.from(this.values());
14710
+ }
14711
+
14712
+ getEnabled() {
14713
+ return this.toArray().filter(_ref => {
14714
+ let {
14715
+ disabled
14716
+ } = _ref;
14717
+ return !disabled;
14718
+ });
14719
+ }
14720
+
14721
+ getNodeFor(id) {
14722
+ var _this$get$node$curren, _this$get;
14723
+
14724
+ return (_this$get$node$curren = (_this$get = this.get(id)) == null ? void 0 : _this$get.node.current) != null ? _this$get$node$curren : undefined;
14725
+ }
14726
+
14727
+ }
14728
+
14729
+ const defaultPublicContext = {
14730
+ activatorEvent: null,
14731
+ active: null,
14732
+ activeNode: null,
14733
+ activeNodeRect: null,
14734
+ collisions: null,
14735
+ containerNodeRect: null,
14736
+ draggableNodes: /*#__PURE__*/new Map(),
14737
+ droppableRects: /*#__PURE__*/new Map(),
14738
+ droppableContainers: /*#__PURE__*/new DroppableContainersMap(),
14739
+ over: null,
14740
+ dragOverlay: {
14741
+ nodeRef: {
14742
+ current: null
14743
+ },
14744
+ rect: null,
14745
+ setRef: noop
14746
+ },
14747
+ scrollableAncestors: [],
14748
+ scrollableAncestorRects: [],
14749
+ measuringConfiguration: defaultMeasuringConfiguration,
14750
+ measureDroppableContainers: noop,
14751
+ windowRect: null,
14752
+ measuringScheduled: false
14753
+ };
14754
+ const defaultInternalContext = {
14755
+ activatorEvent: null,
14756
+ activators: [],
14757
+ active: null,
14758
+ activeNodeRect: null,
14759
+ ariaDescribedById: {
14760
+ draggable: ''
14761
+ },
14762
+ dispatch: noop,
14763
+ draggableNodes: /*#__PURE__*/new Map(),
14764
+ over: null,
14765
+ measureDroppableContainers: noop
14766
+ };
14767
+ const InternalContext = /*#__PURE__*/React.createContext(defaultInternalContext);
14768
+ const PublicContext = /*#__PURE__*/React.createContext(defaultPublicContext);
14769
+
14770
+ function getInitialState() {
14771
+ return {
14772
+ draggable: {
14773
+ active: null,
14774
+ initialCoordinates: {
14775
+ x: 0,
14776
+ y: 0
14777
+ },
14778
+ nodes: new Map(),
14779
+ translate: {
14780
+ x: 0,
14781
+ y: 0
14782
+ }
14783
+ },
14784
+ droppable: {
14785
+ containers: new DroppableContainersMap()
14786
+ }
14787
+ };
14788
+ }
14789
+ function reducer(state, action) {
14790
+ switch (action.type) {
14791
+ case Action.DragStart:
14792
+ return { ...state,
14793
+ draggable: { ...state.draggable,
14794
+ initialCoordinates: action.initialCoordinates,
14795
+ active: action.active
14796
+ }
14797
+ };
14798
+
14799
+ case Action.DragMove:
14800
+ if (state.draggable.active == null) {
14801
+ return state;
14802
+ }
14803
+
14804
+ return { ...state,
14805
+ draggable: { ...state.draggable,
14806
+ translate: {
14807
+ x: action.coordinates.x - state.draggable.initialCoordinates.x,
14808
+ y: action.coordinates.y - state.draggable.initialCoordinates.y
14809
+ }
14810
+ }
14811
+ };
14812
+
14813
+ case Action.DragEnd:
14814
+ case Action.DragCancel:
14815
+ return { ...state,
14816
+ draggable: { ...state.draggable,
14817
+ active: null,
14818
+ initialCoordinates: {
14819
+ x: 0,
14820
+ y: 0
14821
+ },
14822
+ translate: {
14823
+ x: 0,
14824
+ y: 0
14825
+ }
14826
+ }
14827
+ };
14828
+
14829
+ case Action.RegisterDroppable:
14830
+ {
14831
+ const {
14832
+ element
14833
+ } = action;
14834
+ const {
14835
+ id
14836
+ } = element;
14837
+ const containers = new DroppableContainersMap(state.droppable.containers);
14838
+ containers.set(id, element);
14839
+ return { ...state,
14840
+ droppable: { ...state.droppable,
14841
+ containers
14842
+ }
14843
+ };
14844
+ }
14845
+
14846
+ case Action.SetDroppableDisabled:
14847
+ {
14848
+ const {
14849
+ id,
14850
+ key,
14851
+ disabled
14852
+ } = action;
14853
+ const element = state.droppable.containers.get(id);
14854
+
14855
+ if (!element || key !== element.key) {
14856
+ return state;
14857
+ }
14858
+
14859
+ const containers = new DroppableContainersMap(state.droppable.containers);
14860
+ containers.set(id, { ...element,
14861
+ disabled
14862
+ });
14863
+ return { ...state,
14864
+ droppable: { ...state.droppable,
14865
+ containers
14866
+ }
14867
+ };
14868
+ }
14869
+
14870
+ case Action.UnregisterDroppable:
14871
+ {
14872
+ const {
14873
+ id,
14874
+ key
14875
+ } = action;
14876
+ const element = state.droppable.containers.get(id);
14877
+
14878
+ if (!element || key !== element.key) {
14879
+ return state;
14880
+ }
14881
+
14882
+ const containers = new DroppableContainersMap(state.droppable.containers);
14883
+ containers.delete(id);
14884
+ return { ...state,
14885
+ droppable: { ...state.droppable,
14886
+ containers
14887
+ }
14888
+ };
14889
+ }
14890
+
14891
+ default:
14892
+ {
14893
+ return state;
14894
+ }
14895
+ }
14896
+ }
14897
+
14898
+ function RestoreFocus(_ref) {
14899
+ let {
14900
+ disabled
14901
+ } = _ref;
14902
+ const {
14903
+ active,
14904
+ activatorEvent,
14905
+ draggableNodes
14906
+ } = React.useContext(InternalContext);
14907
+ const previousActivatorEvent = usePrevious(activatorEvent);
14908
+ const previousActiveId = usePrevious(active == null ? void 0 : active.id); // Restore keyboard focus on the activator node
14909
+
14910
+ React.useEffect(() => {
14911
+ if (disabled) {
14912
+ return;
14913
+ }
14914
+
14915
+ if (!activatorEvent && previousActivatorEvent && previousActiveId != null) {
14916
+ if (!isKeyboardEvent(previousActivatorEvent)) {
14917
+ return;
14918
+ }
14919
+
14920
+ if (document.activeElement === previousActivatorEvent.target) {
14921
+ // No need to restore focus
14922
+ return;
14923
+ }
14924
+
14925
+ const draggableNode = draggableNodes.get(previousActiveId);
14926
+
14927
+ if (!draggableNode) {
14928
+ return;
14929
+ }
14930
+
14931
+ const {
14932
+ activatorNode,
14933
+ node
14934
+ } = draggableNode;
14935
+
14936
+ if (!activatorNode.current && !node.current) {
14937
+ return;
14938
+ }
14939
+
14940
+ requestAnimationFrame(() => {
14941
+ for (const element of [activatorNode.current, node.current]) {
14942
+ if (!element) {
14943
+ continue;
14944
+ }
14945
+
14946
+ const focusableNode = findFirstFocusableNode(element);
14947
+
14948
+ if (focusableNode) {
14949
+ focusableNode.focus();
14950
+ break;
14951
+ }
14952
+ }
14953
+ });
14954
+ }
14955
+ }, [activatorEvent, disabled, draggableNodes, previousActiveId, previousActivatorEvent]);
14956
+ return null;
14957
+ }
14958
+
14959
+ function applyModifiers(modifiers, _ref) {
14960
+ let {
14961
+ transform,
14962
+ ...args
14963
+ } = _ref;
14964
+ return modifiers != null && modifiers.length ? modifiers.reduce((accumulator, modifier) => {
14965
+ return modifier({
14966
+ transform: accumulator,
14967
+ ...args
14968
+ });
14969
+ }, transform) : transform;
14970
+ }
14971
+
14972
+ function useMeasuringConfiguration(config) {
14973
+ return React.useMemo(() => ({
14974
+ draggable: { ...defaultMeasuringConfiguration.draggable,
14975
+ ...(config == null ? void 0 : config.draggable)
14976
+ },
14977
+ droppable: { ...defaultMeasuringConfiguration.droppable,
14978
+ ...(config == null ? void 0 : config.droppable)
14979
+ },
14980
+ dragOverlay: { ...defaultMeasuringConfiguration.dragOverlay,
14981
+ ...(config == null ? void 0 : config.dragOverlay)
14982
+ }
14983
+ }), // eslint-disable-next-line react-hooks/exhaustive-deps
14984
+ [config == null ? void 0 : config.draggable, config == null ? void 0 : config.droppable, config == null ? void 0 : config.dragOverlay]);
14985
+ }
14986
+
14987
+ function useLayoutShiftScrollCompensation(_ref) {
14988
+ let {
14989
+ activeNode,
14990
+ measure,
14991
+ initialRect,
14992
+ config = true
14993
+ } = _ref;
14994
+ const initialized = React.useRef(false);
14995
+ const {
14996
+ x,
14997
+ y
14998
+ } = typeof config === 'boolean' ? {
14999
+ x: config,
15000
+ y: config
15001
+ } : config;
15002
+ useIsomorphicLayoutEffect(() => {
15003
+ const disabled = !x && !y;
15004
+
15005
+ if (disabled || !activeNode) {
15006
+ initialized.current = false;
15007
+ return;
15008
+ }
15009
+
15010
+ if (initialized.current || !initialRect) {
15011
+ // Return early if layout shift scroll compensation was already attempted
15012
+ // or if there is no initialRect to compare to.
15013
+ return;
15014
+ } // Get the most up to date node ref for the active draggable
15015
+
15016
+
15017
+ const node = activeNode == null ? void 0 : activeNode.node.current;
15018
+
15019
+ if (!node || node.isConnected === false) {
15020
+ // Return early if there is no attached node ref or if the node is
15021
+ // disconnected from the document.
15022
+ return;
15023
+ }
15024
+
15025
+ const rect = measure(node);
15026
+ const rectDelta = getRectDelta(rect, initialRect);
15027
+
15028
+ if (!x) {
15029
+ rectDelta.x = 0;
15030
+ }
15031
+
15032
+ if (!y) {
15033
+ rectDelta.y = 0;
15034
+ } // Only perform layout shift scroll compensation once
15035
+
15036
+
15037
+ initialized.current = true;
15038
+
15039
+ if (Math.abs(rectDelta.x) > 0 || Math.abs(rectDelta.y) > 0) {
15040
+ const firstScrollableAncestor = getFirstScrollableAncestor(node);
15041
+
15042
+ if (firstScrollableAncestor) {
15043
+ firstScrollableAncestor.scrollBy({
15044
+ top: rectDelta.y,
15045
+ left: rectDelta.x
15046
+ });
15047
+ }
15048
+ }
15049
+ }, [activeNode, x, y, initialRect, measure]);
15050
+ }
15051
+
15052
+ const ActiveDraggableContext = /*#__PURE__*/React.createContext({ ...defaultCoordinates,
15053
+ scaleX: 1,
15054
+ scaleY: 1
15055
+ });
15056
+ var Status;
15057
+
15058
+ (function (Status) {
15059
+ Status[Status["Uninitialized"] = 0] = "Uninitialized";
15060
+ Status[Status["Initializing"] = 1] = "Initializing";
15061
+ Status[Status["Initialized"] = 2] = "Initialized";
15062
+ })(Status || (Status = {}));
15063
+
15064
+ const DndContext = /*#__PURE__*/React.memo(function DndContext(_ref) {
15065
+ var _sensorContext$curren, _dragOverlay$nodeRef$, _dragOverlay$rect, _over$rect;
15066
+
15067
+ let {
15068
+ id,
15069
+ accessibility,
15070
+ autoScroll = true,
15071
+ children,
15072
+ sensors = defaultSensors,
15073
+ collisionDetection = rectIntersection,
15074
+ measuring,
15075
+ modifiers,
15076
+ ...props
15077
+ } = _ref;
15078
+ const store = React.useReducer(reducer, undefined, getInitialState);
15079
+ const [state, dispatch] = store;
15080
+ const [dispatchMonitorEvent, registerMonitorListener] = useDndMonitorProvider();
15081
+ const [status, setStatus] = React.useState(Status.Uninitialized);
15082
+ const isInitialized = status === Status.Initialized;
15083
+ const {
15084
+ draggable: {
15085
+ active: activeId,
15086
+ nodes: draggableNodes,
15087
+ translate
15088
+ },
15089
+ droppable: {
15090
+ containers: droppableContainers
15091
+ }
15092
+ } = state;
15093
+ const node = activeId != null ? draggableNodes.get(activeId) : null;
15094
+ const activeRects = React.useRef({
15095
+ initial: null,
15096
+ translated: null
15097
+ });
15098
+ const active = React.useMemo(() => {
15099
+ var _node$data;
15100
+
15101
+ return activeId != null ? {
15102
+ id: activeId,
15103
+ // It's possible for the active node to unmount while dragging
15104
+ data: (_node$data = node == null ? void 0 : node.data) != null ? _node$data : defaultData,
15105
+ rect: activeRects
15106
+ } : null;
15107
+ }, [activeId, node]);
15108
+ const activeRef = React.useRef(null);
15109
+ const [activeSensor, setActiveSensor] = React.useState(null);
15110
+ const [activatorEvent, setActivatorEvent] = React.useState(null);
15111
+ const latestProps = useLatestValue(props, Object.values(props));
15112
+ const draggableDescribedById = useUniqueId("DndDescribedBy", id);
15113
+ const enabledDroppableContainers = React.useMemo(() => droppableContainers.getEnabled(), [droppableContainers]);
15114
+ const measuringConfiguration = useMeasuringConfiguration(measuring);
15115
+ const {
15116
+ droppableRects,
15117
+ measureDroppableContainers,
15118
+ measuringScheduled
15119
+ } = useDroppableMeasuring(enabledDroppableContainers, {
15120
+ dragging: isInitialized,
15121
+ dependencies: [translate.x, translate.y],
15122
+ config: measuringConfiguration.droppable
15123
+ });
15124
+ const activeNode = useCachedNode(draggableNodes, activeId);
15125
+ const activationCoordinates = React.useMemo(() => activatorEvent ? getEventCoordinates(activatorEvent) : null, [activatorEvent]);
15126
+ const autoScrollOptions = getAutoScrollerOptions();
15127
+ const initialActiveNodeRect = useInitialRect(activeNode, measuringConfiguration.draggable.measure);
15128
+ useLayoutShiftScrollCompensation({
15129
+ activeNode: activeId != null ? draggableNodes.get(activeId) : null,
15130
+ config: autoScrollOptions.layoutShiftCompensation,
15131
+ initialRect: initialActiveNodeRect,
15132
+ measure: measuringConfiguration.draggable.measure
15133
+ });
15134
+ const activeNodeRect = useRect(activeNode, measuringConfiguration.draggable.measure, initialActiveNodeRect);
15135
+ const containerNodeRect = useRect(activeNode ? activeNode.parentElement : null);
15136
+ const sensorContext = React.useRef({
15137
+ activatorEvent: null,
15138
+ active: null,
15139
+ activeNode,
15140
+ collisionRect: null,
15141
+ collisions: null,
15142
+ droppableRects,
15143
+ draggableNodes,
15144
+ draggingNode: null,
15145
+ draggingNodeRect: null,
15146
+ droppableContainers,
15147
+ over: null,
15148
+ scrollableAncestors: [],
15149
+ scrollAdjustedTranslate: null
15150
+ });
15151
+ const overNode = droppableContainers.getNodeFor((_sensorContext$curren = sensorContext.current.over) == null ? void 0 : _sensorContext$curren.id);
15152
+ const dragOverlay = useDragOverlayMeasuring({
15153
+ measure: measuringConfiguration.dragOverlay.measure
15154
+ }); // Use the rect of the drag overlay if it is mounted
15155
+
15156
+ const draggingNode = (_dragOverlay$nodeRef$ = dragOverlay.nodeRef.current) != null ? _dragOverlay$nodeRef$ : activeNode;
15157
+ const draggingNodeRect = isInitialized ? (_dragOverlay$rect = dragOverlay.rect) != null ? _dragOverlay$rect : activeNodeRect : null;
15158
+ const usesDragOverlay = Boolean(dragOverlay.nodeRef.current && dragOverlay.rect); // The delta between the previous and new position of the draggable node
15159
+ // is only relevant when there is no drag overlay
15160
+
15161
+ const nodeRectDelta = useRectDelta(usesDragOverlay ? null : activeNodeRect); // Get the window rect of the dragging node
15162
+
15163
+ const windowRect = useWindowRect(draggingNode ? getWindow(draggingNode) : null); // Get scrollable ancestors of the dragging node
15164
+
15165
+ const scrollableAncestors = useScrollableAncestors(isInitialized ? overNode != null ? overNode : activeNode : null);
15166
+ const scrollableAncestorRects = useRects(scrollableAncestors); // Apply modifiers
15167
+
15168
+ const modifiedTranslate = applyModifiers(modifiers, {
15169
+ transform: {
15170
+ x: translate.x - nodeRectDelta.x,
15171
+ y: translate.y - nodeRectDelta.y,
15172
+ scaleX: 1,
15173
+ scaleY: 1
15174
+ },
15175
+ activatorEvent,
15176
+ active,
15177
+ activeNodeRect,
15178
+ containerNodeRect,
15179
+ draggingNodeRect,
15180
+ over: sensorContext.current.over,
15181
+ overlayNodeRect: dragOverlay.rect,
15182
+ scrollableAncestors,
15183
+ scrollableAncestorRects,
15184
+ windowRect
15185
+ });
15186
+ const pointerCoordinates = activationCoordinates ? add(activationCoordinates, translate) : null;
15187
+ const scrollOffsets = useScrollOffsets(scrollableAncestors); // Represents the scroll delta since dragging was initiated
15188
+
15189
+ const scrollAdjustment = useScrollOffsetsDelta(scrollOffsets); // Represents the scroll delta since the last time the active node rect was measured
15190
+
15191
+ const activeNodeScrollDelta = useScrollOffsetsDelta(scrollOffsets, [activeNodeRect]);
15192
+ const scrollAdjustedTranslate = add(modifiedTranslate, scrollAdjustment);
15193
+ const collisionRect = draggingNodeRect ? getAdjustedRect(draggingNodeRect, modifiedTranslate) : null;
15194
+ const collisions = active && collisionRect ? collisionDetection({
15195
+ active,
15196
+ collisionRect,
15197
+ droppableRects,
15198
+ droppableContainers: enabledDroppableContainers,
15199
+ pointerCoordinates
15200
+ }) : null;
15201
+ const overId = getFirstCollision(collisions, 'id');
15202
+ const [over, setOver] = React.useState(null); // When there is no drag overlay used, we need to account for the
15203
+ // window scroll delta
15204
+
15205
+ const appliedTranslate = usesDragOverlay ? modifiedTranslate : add(modifiedTranslate, activeNodeScrollDelta);
15206
+ const transform = adjustScale(appliedTranslate, (_over$rect = over == null ? void 0 : over.rect) != null ? _over$rect : null, activeNodeRect);
15207
+ const activeSensorRef = React.useRef(null);
15208
+ const instantiateSensor = React.useCallback((event, _ref2) => {
15209
+ let {
15210
+ sensor: Sensor,
15211
+ options
15212
+ } = _ref2;
15213
+
15214
+ if (activeRef.current == null) {
15215
+ return;
15216
+ }
15217
+
15218
+ const activeNode = draggableNodes.get(activeRef.current);
15219
+
15220
+ if (!activeNode) {
15221
+ return;
15222
+ }
15223
+
15224
+ const activatorEvent = event.nativeEvent;
15225
+ const sensorInstance = new Sensor({
15226
+ active: activeRef.current,
15227
+ activeNode,
15228
+ event: activatorEvent,
15229
+ options,
15230
+ // Sensors need to be instantiated with refs for arguments that change over time
15231
+ // otherwise they are frozen in time with the stale arguments
15232
+ context: sensorContext,
15233
+
15234
+ onAbort(id) {
15235
+ const draggableNode = draggableNodes.get(id);
15236
+
15237
+ if (!draggableNode) {
15238
+ return;
15239
+ }
15240
+
15241
+ const {
15242
+ onDragAbort
15243
+ } = latestProps.current;
15244
+ const event = {
15245
+ id
15246
+ };
15247
+ onDragAbort == null ? void 0 : onDragAbort(event);
15248
+ dispatchMonitorEvent({
15249
+ type: 'onDragAbort',
15250
+ event
15251
+ });
15252
+ },
15253
+
15254
+ onPending(id, constraint, initialCoordinates, offset) {
15255
+ const draggableNode = draggableNodes.get(id);
15256
+
15257
+ if (!draggableNode) {
15258
+ return;
15259
+ }
15260
+
15261
+ const {
15262
+ onDragPending
15263
+ } = latestProps.current;
15264
+ const event = {
15265
+ id,
15266
+ constraint,
15267
+ initialCoordinates,
15268
+ offset
15269
+ };
15270
+ onDragPending == null ? void 0 : onDragPending(event);
15271
+ dispatchMonitorEvent({
15272
+ type: 'onDragPending',
15273
+ event
15274
+ });
15275
+ },
15276
+
15277
+ onStart(initialCoordinates) {
15278
+ const id = activeRef.current;
15279
+
15280
+ if (id == null) {
15281
+ return;
15282
+ }
15283
+
15284
+ const draggableNode = draggableNodes.get(id);
15285
+
15286
+ if (!draggableNode) {
15287
+ return;
15288
+ }
15289
+
15290
+ const {
15291
+ onDragStart
15292
+ } = latestProps.current;
15293
+ const event = {
15294
+ activatorEvent,
15295
+ active: {
15296
+ id,
15297
+ data: draggableNode.data,
15298
+ rect: activeRects
15299
+ }
15300
+ };
15301
+ reactDom.unstable_batchedUpdates(() => {
15302
+ onDragStart == null ? void 0 : onDragStart(event);
15303
+ setStatus(Status.Initializing);
15304
+ dispatch({
15305
+ type: Action.DragStart,
15306
+ initialCoordinates,
15307
+ active: id
15308
+ });
15309
+ dispatchMonitorEvent({
15310
+ type: 'onDragStart',
15311
+ event
15312
+ });
15313
+ setActiveSensor(activeSensorRef.current);
15314
+ setActivatorEvent(activatorEvent);
15315
+ });
15316
+ },
15317
+
15318
+ onMove(coordinates) {
15319
+ dispatch({
15320
+ type: Action.DragMove,
15321
+ coordinates
15322
+ });
15323
+ },
15324
+
15325
+ onEnd: createHandler(Action.DragEnd),
15326
+ onCancel: createHandler(Action.DragCancel)
15327
+ });
15328
+ activeSensorRef.current = sensorInstance;
15329
+
15330
+ function createHandler(type) {
15331
+ return async function handler() {
15332
+ const {
15333
+ active,
15334
+ collisions,
15335
+ over,
15336
+ scrollAdjustedTranslate
15337
+ } = sensorContext.current;
15338
+ let event = null;
15339
+
15340
+ if (active && scrollAdjustedTranslate) {
15341
+ const {
15342
+ cancelDrop
15343
+ } = latestProps.current;
15344
+ event = {
15345
+ activatorEvent,
15346
+ active: active,
15347
+ collisions,
15348
+ delta: scrollAdjustedTranslate,
15349
+ over
15350
+ };
15351
+
15352
+ if (type === Action.DragEnd && typeof cancelDrop === 'function') {
15353
+ const shouldCancel = await Promise.resolve(cancelDrop(event));
15354
+
15355
+ if (shouldCancel) {
15356
+ type = Action.DragCancel;
15357
+ }
15358
+ }
15359
+ }
15360
+
15361
+ activeRef.current = null;
15362
+ reactDom.unstable_batchedUpdates(() => {
15363
+ dispatch({
15364
+ type
15365
+ });
15366
+ setStatus(Status.Uninitialized);
15367
+ setOver(null);
15368
+ setActiveSensor(null);
15369
+ setActivatorEvent(null);
15370
+ activeSensorRef.current = null;
15371
+ const eventName = type === Action.DragEnd ? 'onDragEnd' : 'onDragCancel';
15372
+
15373
+ if (event) {
15374
+ const handler = latestProps.current[eventName];
15375
+ handler == null ? void 0 : handler(event);
15376
+ dispatchMonitorEvent({
15377
+ type: eventName,
15378
+ event
15379
+ });
15380
+ }
15381
+ });
15382
+ };
15383
+ }
15384
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
15385
+ [draggableNodes]);
15386
+ const bindActivatorToSensorInstantiator = React.useCallback((handler, sensor) => {
15387
+ return (event, active) => {
15388
+ const nativeEvent = event.nativeEvent;
15389
+ const activeDraggableNode = draggableNodes.get(active);
15390
+
15391
+ if ( // Another sensor is already instantiating
15392
+ activeRef.current !== null || // No active draggable
15393
+ !activeDraggableNode || // Event has already been captured
15394
+ nativeEvent.dndKit || nativeEvent.defaultPrevented) {
15395
+ return;
15396
+ }
15397
+
15398
+ const activationContext = {
15399
+ active: activeDraggableNode
15400
+ };
15401
+ const shouldActivate = handler(event, sensor.options, activationContext);
15402
+
15403
+ if (shouldActivate === true) {
15404
+ nativeEvent.dndKit = {
15405
+ capturedBy: sensor.sensor
15406
+ };
15407
+ activeRef.current = active;
15408
+ instantiateSensor(event, sensor);
15409
+ }
15410
+ };
15411
+ }, [draggableNodes, instantiateSensor]);
15412
+ const activators = useCombineActivators(sensors, bindActivatorToSensorInstantiator);
15413
+ useSensorSetup(sensors);
15414
+ useIsomorphicLayoutEffect(() => {
15415
+ if (activeNodeRect && status === Status.Initializing) {
15416
+ setStatus(Status.Initialized);
15417
+ }
15418
+ }, [activeNodeRect, status]);
15419
+ React.useEffect(() => {
15420
+ const {
15421
+ onDragMove
15422
+ } = latestProps.current;
15423
+ const {
15424
+ active,
15425
+ activatorEvent,
15426
+ collisions,
15427
+ over
15428
+ } = sensorContext.current;
15429
+
15430
+ if (!active || !activatorEvent) {
15431
+ return;
15432
+ }
15433
+
15434
+ const event = {
15435
+ active,
15436
+ activatorEvent,
15437
+ collisions,
15438
+ delta: {
15439
+ x: scrollAdjustedTranslate.x,
15440
+ y: scrollAdjustedTranslate.y
15441
+ },
15442
+ over
15443
+ };
15444
+ reactDom.unstable_batchedUpdates(() => {
15445
+ onDragMove == null ? void 0 : onDragMove(event);
15446
+ dispatchMonitorEvent({
15447
+ type: 'onDragMove',
15448
+ event
15449
+ });
15450
+ });
15451
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
15452
+ [scrollAdjustedTranslate.x, scrollAdjustedTranslate.y]);
15453
+ React.useEffect(() => {
15454
+ const {
15455
+ active,
15456
+ activatorEvent,
15457
+ collisions,
15458
+ droppableContainers,
15459
+ scrollAdjustedTranslate
15460
+ } = sensorContext.current;
15461
+
15462
+ if (!active || activeRef.current == null || !activatorEvent || !scrollAdjustedTranslate) {
15463
+ return;
15464
+ }
15465
+
15466
+ const {
15467
+ onDragOver
15468
+ } = latestProps.current;
15469
+ const overContainer = droppableContainers.get(overId);
15470
+ const over = overContainer && overContainer.rect.current ? {
15471
+ id: overContainer.id,
15472
+ rect: overContainer.rect.current,
15473
+ data: overContainer.data,
15474
+ disabled: overContainer.disabled
15475
+ } : null;
15476
+ const event = {
15477
+ active,
15478
+ activatorEvent,
15479
+ collisions,
15480
+ delta: {
15481
+ x: scrollAdjustedTranslate.x,
15482
+ y: scrollAdjustedTranslate.y
15483
+ },
15484
+ over
15485
+ };
15486
+ reactDom.unstable_batchedUpdates(() => {
15487
+ setOver(over);
15488
+ onDragOver == null ? void 0 : onDragOver(event);
15489
+ dispatchMonitorEvent({
15490
+ type: 'onDragOver',
15491
+ event
15492
+ });
15493
+ });
15494
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
15495
+ [overId]);
15496
+ useIsomorphicLayoutEffect(() => {
15497
+ sensorContext.current = {
15498
+ activatorEvent,
15499
+ active,
15500
+ activeNode,
15501
+ collisionRect,
15502
+ collisions,
15503
+ droppableRects,
15504
+ draggableNodes,
15505
+ draggingNode,
15506
+ draggingNodeRect,
15507
+ droppableContainers,
15508
+ over,
15509
+ scrollableAncestors,
15510
+ scrollAdjustedTranslate
15511
+ };
15512
+ activeRects.current = {
15513
+ initial: draggingNodeRect,
15514
+ translated: collisionRect
15515
+ };
15516
+ }, [active, activeNode, collisions, collisionRect, draggableNodes, draggingNode, draggingNodeRect, droppableRects, droppableContainers, over, scrollableAncestors, scrollAdjustedTranslate]);
15517
+ useAutoScroller({ ...autoScrollOptions,
15518
+ delta: translate,
15519
+ draggingRect: collisionRect,
15520
+ pointerCoordinates,
15521
+ scrollableAncestors,
15522
+ scrollableAncestorRects
15523
+ });
15524
+ const publicContext = React.useMemo(() => {
15525
+ const context = {
15526
+ active,
15527
+ activeNode,
15528
+ activeNodeRect,
15529
+ activatorEvent,
15530
+ collisions,
15531
+ containerNodeRect,
15532
+ dragOverlay,
15533
+ draggableNodes,
15534
+ droppableContainers,
15535
+ droppableRects,
15536
+ over,
15537
+ measureDroppableContainers,
15538
+ scrollableAncestors,
15539
+ scrollableAncestorRects,
15540
+ measuringConfiguration,
15541
+ measuringScheduled,
15542
+ windowRect
15543
+ };
15544
+ return context;
15545
+ }, [active, activeNode, activeNodeRect, activatorEvent, collisions, containerNodeRect, dragOverlay, draggableNodes, droppableContainers, droppableRects, over, measureDroppableContainers, scrollableAncestors, scrollableAncestorRects, measuringConfiguration, measuringScheduled, windowRect]);
15546
+ const internalContext = React.useMemo(() => {
15547
+ const context = {
15548
+ activatorEvent,
15549
+ activators,
15550
+ active,
15551
+ activeNodeRect,
15552
+ ariaDescribedById: {
15553
+ draggable: draggableDescribedById
15554
+ },
15555
+ dispatch,
15556
+ draggableNodes,
15557
+ over,
15558
+ measureDroppableContainers
15559
+ };
15560
+ return context;
15561
+ }, [activatorEvent, activators, active, activeNodeRect, dispatch, draggableDescribedById, draggableNodes, over, measureDroppableContainers]);
15562
+ return React.createElement(DndMonitorContext.Provider, {
15563
+ value: registerMonitorListener
15564
+ }, React.createElement(InternalContext.Provider, {
15565
+ value: internalContext
15566
+ }, React.createElement(PublicContext.Provider, {
15567
+ value: publicContext
15568
+ }, React.createElement(ActiveDraggableContext.Provider, {
15569
+ value: transform
15570
+ }, children)), React.createElement(RestoreFocus, {
15571
+ disabled: (accessibility == null ? void 0 : accessibility.restoreFocus) === false
15572
+ })), React.createElement(Accessibility, { ...accessibility,
15573
+ hiddenTextDescribedById: draggableDescribedById
15574
+ }));
15575
+
15576
+ function getAutoScrollerOptions() {
15577
+ const activeSensorDisablesAutoscroll = (activeSensor == null ? void 0 : activeSensor.autoScrollEnabled) === false;
15578
+ const autoScrollGloballyDisabled = typeof autoScroll === 'object' ? autoScroll.enabled === false : autoScroll === false;
15579
+ const enabled = isInitialized && !activeSensorDisablesAutoscroll && !autoScrollGloballyDisabled;
15580
+
15581
+ if (typeof autoScroll === 'object') {
15582
+ return { ...autoScroll,
15583
+ enabled
15584
+ };
15585
+ }
15586
+
15587
+ return {
15588
+ enabled
15589
+ };
15590
+ }
15591
+ });
15592
+
15593
+ const NullContext = /*#__PURE__*/React.createContext(null);
15594
+ const defaultRole = 'button';
15595
+ const ID_PREFIX$1 = 'Draggable';
15596
+ function useDraggable(_ref) {
15597
+ let {
15598
+ id,
15599
+ data,
15600
+ disabled = false,
15601
+ attributes
15602
+ } = _ref;
15603
+ const key = useUniqueId(ID_PREFIX$1);
15604
+ const {
15605
+ activators,
15606
+ activatorEvent,
15607
+ active,
15608
+ activeNodeRect,
15609
+ ariaDescribedById,
15610
+ draggableNodes,
15611
+ over
15612
+ } = React.useContext(InternalContext);
15613
+ const {
15614
+ role = defaultRole,
15615
+ roleDescription = 'draggable',
15616
+ tabIndex = 0
15617
+ } = attributes != null ? attributes : {};
15618
+ const isDragging = (active == null ? void 0 : active.id) === id;
15619
+ const transform = React.useContext(isDragging ? ActiveDraggableContext : NullContext);
15620
+ const [node, setNodeRef] = useNodeRef();
15621
+ const [activatorNode, setActivatorNodeRef] = useNodeRef();
15622
+ const listeners = useSyntheticListeners(activators, id);
15623
+ const dataRef = useLatestValue(data);
15624
+ useIsomorphicLayoutEffect(() => {
15625
+ draggableNodes.set(id, {
15626
+ id,
15627
+ key,
15628
+ node,
15629
+ activatorNode,
15630
+ data: dataRef
15631
+ });
15632
+ return () => {
15633
+ const node = draggableNodes.get(id);
15634
+
15635
+ if (node && node.key === key) {
15636
+ draggableNodes.delete(id);
15637
+ }
15638
+ };
15639
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
15640
+ [draggableNodes, id]);
15641
+ const memoizedAttributes = React.useMemo(() => ({
15642
+ role,
15643
+ tabIndex,
15644
+ 'aria-disabled': disabled,
15645
+ 'aria-pressed': isDragging && role === defaultRole ? true : undefined,
15646
+ 'aria-roledescription': roleDescription,
15647
+ 'aria-describedby': ariaDescribedById.draggable
15648
+ }), [disabled, role, tabIndex, isDragging, roleDescription, ariaDescribedById.draggable]);
15649
+ return {
15650
+ active,
15651
+ activatorEvent,
15652
+ activeNodeRect,
15653
+ attributes: memoizedAttributes,
15654
+ isDragging,
15655
+ listeners: disabled ? undefined : listeners,
15656
+ node,
15657
+ over,
15658
+ setNodeRef,
15659
+ setActivatorNodeRef,
15660
+ transform
15661
+ };
15662
+ }
15663
+
15664
+ function useDndContext() {
15665
+ return React.useContext(PublicContext);
15666
+ }
15667
+
15668
+ const ID_PREFIX$1$1 = 'Droppable';
15669
+ const defaultResizeObserverConfig = {
15670
+ timeout: 25
15671
+ };
15672
+ function useDroppable(_ref) {
15673
+ let {
15674
+ data,
15675
+ disabled = false,
15676
+ id,
15677
+ resizeObserverConfig
15678
+ } = _ref;
15679
+ const key = useUniqueId(ID_PREFIX$1$1);
15680
+ const {
15681
+ active,
15682
+ dispatch,
15683
+ over,
15684
+ measureDroppableContainers
15685
+ } = React.useContext(InternalContext);
15686
+ const previous = React.useRef({
15687
+ disabled
15688
+ });
15689
+ const resizeObserverConnected = React.useRef(false);
15690
+ const rect = React.useRef(null);
15691
+ const callbackId = React.useRef(null);
15692
+ const {
15693
+ disabled: resizeObserverDisabled,
15694
+ updateMeasurementsFor,
15695
+ timeout: resizeObserverTimeout
15696
+ } = { ...defaultResizeObserverConfig,
15697
+ ...resizeObserverConfig
15698
+ };
15699
+ const ids = useLatestValue(updateMeasurementsFor != null ? updateMeasurementsFor : id);
15700
+ const handleResize = React.useCallback(() => {
15701
+ if (!resizeObserverConnected.current) {
15702
+ // ResizeObserver invokes the `handleResize` callback as soon as `observe` is called,
15703
+ // assuming the element is rendered and displayed.
15704
+ resizeObserverConnected.current = true;
15705
+ return;
15706
+ }
15707
+
15708
+ if (callbackId.current != null) {
15709
+ clearTimeout(callbackId.current);
15710
+ }
15711
+
15712
+ callbackId.current = setTimeout(() => {
15713
+ measureDroppableContainers(Array.isArray(ids.current) ? ids.current : [ids.current]);
15714
+ callbackId.current = null;
15715
+ }, resizeObserverTimeout);
15716
+ }, //eslint-disable-next-line react-hooks/exhaustive-deps
15717
+ [resizeObserverTimeout]);
15718
+ const resizeObserver = useResizeObserver({
15719
+ callback: handleResize,
15720
+ disabled: resizeObserverDisabled || !active
15721
+ });
15722
+ const handleNodeChange = React.useCallback((newElement, previousElement) => {
15723
+ if (!resizeObserver) {
15724
+ return;
15725
+ }
15726
+
15727
+ if (previousElement) {
15728
+ resizeObserver.unobserve(previousElement);
15729
+ resizeObserverConnected.current = false;
15730
+ }
15731
+
15732
+ if (newElement) {
15733
+ resizeObserver.observe(newElement);
15734
+ }
15735
+ }, [resizeObserver]);
15736
+ const [nodeRef, setNodeRef] = useNodeRef(handleNodeChange);
15737
+ const dataRef = useLatestValue(data);
15738
+ React.useEffect(() => {
15739
+ if (!resizeObserver || !nodeRef.current) {
15740
+ return;
15741
+ }
15742
+
15743
+ resizeObserver.disconnect();
15744
+ resizeObserverConnected.current = false;
15745
+ resizeObserver.observe(nodeRef.current);
15746
+ }, [nodeRef, resizeObserver]);
15747
+ React.useEffect(() => {
15748
+ dispatch({
15749
+ type: Action.RegisterDroppable,
15750
+ element: {
15751
+ id,
15752
+ key,
15753
+ disabled,
15754
+ node: nodeRef,
15755
+ rect,
15756
+ data: dataRef
15757
+ }
15758
+ });
15759
+ return () => dispatch({
15760
+ type: Action.UnregisterDroppable,
15761
+ key,
15762
+ id
15763
+ });
15764
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
15765
+ [id]);
15766
+ React.useEffect(() => {
15767
+ if (disabled !== previous.current.disabled) {
15768
+ dispatch({
15769
+ type: Action.SetDroppableDisabled,
15770
+ id,
15771
+ key,
15772
+ disabled
15773
+ });
15774
+ previous.current.disabled = disabled;
15775
+ }
15776
+ }, [id, key, disabled, dispatch]);
15777
+ return {
15778
+ active,
15779
+ rect,
15780
+ isOver: (over == null ? void 0 : over.id) === id,
15781
+ node: nodeRef,
15782
+ over,
15783
+ setNodeRef
15784
+ };
15785
+ }
15786
+
15787
+ /**
15788
+ * Move an array item to a different position. Returns a new array with the item moved to the new position.
15789
+ */
15790
+ function arrayMove(array, from, to) {
15791
+ const newArray = array.slice();
15792
+ newArray.splice(to < 0 ? newArray.length + to : to, 0, newArray.splice(from, 1)[0]);
15793
+ return newArray;
15794
+ }
15795
+
15796
+ function getSortedRects(items, rects) {
15797
+ return items.reduce((accumulator, id, index) => {
15798
+ const rect = rects.get(id);
15799
+
15800
+ if (rect) {
15801
+ accumulator[index] = rect;
15802
+ }
15803
+
15804
+ return accumulator;
15805
+ }, Array(items.length));
15806
+ }
15807
+
15808
+ function isValidIndex(index) {
15809
+ return index !== null && index >= 0;
15810
+ }
15811
+
15812
+ function itemsEqual(a, b) {
15813
+ if (a === b) {
15814
+ return true;
15815
+ }
15816
+
15817
+ if (a.length !== b.length) {
15818
+ return false;
15819
+ }
15820
+
15821
+ for (let i = 0; i < a.length; i++) {
15822
+ if (a[i] !== b[i]) {
15823
+ return false;
15824
+ }
15825
+ }
15826
+
15827
+ return true;
15828
+ }
15829
+
15830
+ function normalizeDisabled(disabled) {
15831
+ if (typeof disabled === 'boolean') {
15832
+ return {
15833
+ draggable: disabled,
15834
+ droppable: disabled
15835
+ };
15836
+ }
15837
+
15838
+ return disabled;
15839
+ }
15840
+
15841
+ const rectSortingStrategy = _ref => {
15842
+ let {
15843
+ rects,
15844
+ activeIndex,
15845
+ overIndex,
15846
+ index
15847
+ } = _ref;
15848
+ const newRects = arrayMove(rects, overIndex, activeIndex);
15849
+ const oldRect = rects[index];
15850
+ const newRect = newRects[index];
15851
+
15852
+ if (!newRect || !oldRect) {
15853
+ return null;
15854
+ }
15855
+
15856
+ return {
15857
+ x: newRect.left - oldRect.left,
15858
+ y: newRect.top - oldRect.top,
15859
+ scaleX: newRect.width / oldRect.width,
15860
+ scaleY: newRect.height / oldRect.height
15861
+ };
15862
+ };
15863
+
15864
+ // To-do: We should be calculating scale transformation
15865
+ const defaultScale$1 = {
15866
+ scaleX: 1,
15867
+ scaleY: 1
15868
+ };
15869
+ const verticalListSortingStrategy = _ref => {
15870
+ var _rects$activeIndex;
15871
+
15872
+ let {
15873
+ activeIndex,
15874
+ activeNodeRect: fallbackActiveRect,
15875
+ index,
15876
+ rects,
15877
+ overIndex
15878
+ } = _ref;
15879
+ const activeNodeRect = (_rects$activeIndex = rects[activeIndex]) != null ? _rects$activeIndex : fallbackActiveRect;
15880
+
15881
+ if (!activeNodeRect) {
15882
+ return null;
15883
+ }
15884
+
15885
+ if (index === activeIndex) {
15886
+ const overIndexRect = rects[overIndex];
15887
+
15888
+ if (!overIndexRect) {
15889
+ return null;
15890
+ }
15891
+
15892
+ return {
15893
+ x: 0,
15894
+ y: activeIndex < overIndex ? overIndexRect.top + overIndexRect.height - (activeNodeRect.top + activeNodeRect.height) : overIndexRect.top - activeNodeRect.top,
15895
+ ...defaultScale$1
15896
+ };
15897
+ }
15898
+
15899
+ const itemGap = getItemGap$1(rects, index, activeIndex);
15900
+
15901
+ if (index > activeIndex && index <= overIndex) {
15902
+ return {
15903
+ x: 0,
15904
+ y: -activeNodeRect.height - itemGap,
15905
+ ...defaultScale$1
15906
+ };
15907
+ }
15908
+
15909
+ if (index < activeIndex && index >= overIndex) {
15910
+ return {
15911
+ x: 0,
15912
+ y: activeNodeRect.height + itemGap,
15913
+ ...defaultScale$1
15914
+ };
15915
+ }
15916
+
15917
+ return {
15918
+ x: 0,
15919
+ y: 0,
15920
+ ...defaultScale$1
15921
+ };
15922
+ };
15923
+
15924
+ function getItemGap$1(clientRects, index, activeIndex) {
15925
+ const currentRect = clientRects[index];
15926
+ const previousRect = clientRects[index - 1];
15927
+ const nextRect = clientRects[index + 1];
15928
+
15929
+ if (!currentRect) {
15930
+ return 0;
15931
+ }
15932
+
15933
+ if (activeIndex < index) {
15934
+ return previousRect ? currentRect.top - (previousRect.top + previousRect.height) : nextRect ? nextRect.top - (currentRect.top + currentRect.height) : 0;
15935
+ }
15936
+
15937
+ return nextRect ? nextRect.top - (currentRect.top + currentRect.height) : previousRect ? currentRect.top - (previousRect.top + previousRect.height) : 0;
15938
+ }
15939
+
15940
+ const ID_PREFIX = 'Sortable';
15941
+ const Context = /*#__PURE__*/React.createContext({
15942
+ activeIndex: -1,
15943
+ containerId: ID_PREFIX,
15944
+ disableTransforms: false,
15945
+ items: [],
15946
+ overIndex: -1,
15947
+ useDragOverlay: false,
15948
+ sortedRects: [],
15949
+ strategy: rectSortingStrategy,
15950
+ disabled: {
15951
+ draggable: false,
15952
+ droppable: false
15953
+ }
15954
+ });
15955
+ function SortableContext(_ref) {
15956
+ let {
15957
+ children,
15958
+ id,
15959
+ items: userDefinedItems,
15960
+ strategy = rectSortingStrategy,
15961
+ disabled: disabledProp = false
15962
+ } = _ref;
15963
+ const {
15964
+ active,
15965
+ dragOverlay,
15966
+ droppableRects,
15967
+ over,
15968
+ measureDroppableContainers
15969
+ } = useDndContext();
15970
+ const containerId = useUniqueId(ID_PREFIX, id);
15971
+ const useDragOverlay = Boolean(dragOverlay.rect !== null);
15972
+ const items = React.useMemo(() => userDefinedItems.map(item => typeof item === 'object' && 'id' in item ? item.id : item), [userDefinedItems]);
15973
+ const isDragging = active != null;
15974
+ const activeIndex = active ? items.indexOf(active.id) : -1;
15975
+ const overIndex = over ? items.indexOf(over.id) : -1;
15976
+ const previousItemsRef = React.useRef(items);
15977
+ const itemsHaveChanged = !itemsEqual(items, previousItemsRef.current);
15978
+ const disableTransforms = overIndex !== -1 && activeIndex === -1 || itemsHaveChanged;
15979
+ const disabled = normalizeDisabled(disabledProp);
15980
+ useIsomorphicLayoutEffect(() => {
15981
+ if (itemsHaveChanged && isDragging) {
15982
+ measureDroppableContainers(items);
15983
+ }
15984
+ }, [itemsHaveChanged, items, isDragging, measureDroppableContainers]);
15985
+ React.useEffect(() => {
15986
+ previousItemsRef.current = items;
15987
+ }, [items]);
15988
+ const contextValue = React.useMemo(() => ({
15989
+ activeIndex,
15990
+ containerId,
15991
+ disabled,
15992
+ disableTransforms,
15993
+ items,
15994
+ overIndex,
15995
+ useDragOverlay,
15996
+ sortedRects: getSortedRects(items, droppableRects),
15997
+ strategy
15998
+ }), // eslint-disable-next-line react-hooks/exhaustive-deps
15999
+ [activeIndex, containerId, disabled.draggable, disabled.droppable, disableTransforms, items, overIndex, droppableRects, useDragOverlay, strategy]);
16000
+ return React.createElement(Context.Provider, {
16001
+ value: contextValue
16002
+ }, children);
16003
+ }
16004
+
16005
+ const defaultNewIndexGetter = _ref => {
16006
+ let {
16007
+ id,
16008
+ items,
16009
+ activeIndex,
16010
+ overIndex
16011
+ } = _ref;
16012
+ return arrayMove(items, activeIndex, overIndex).indexOf(id);
16013
+ };
16014
+ const defaultAnimateLayoutChanges = _ref2 => {
16015
+ let {
16016
+ containerId,
16017
+ isSorting,
16018
+ wasDragging,
16019
+ index,
16020
+ items,
16021
+ newIndex,
16022
+ previousItems,
16023
+ previousContainerId,
16024
+ transition
16025
+ } = _ref2;
16026
+
16027
+ if (!transition || !wasDragging) {
16028
+ return false;
16029
+ }
16030
+
16031
+ if (previousItems !== items && index === newIndex) {
16032
+ return false;
16033
+ }
16034
+
16035
+ if (isSorting) {
16036
+ return true;
16037
+ }
16038
+
16039
+ return newIndex !== index && containerId === previousContainerId;
16040
+ };
16041
+ const defaultTransition = {
16042
+ duration: 200,
16043
+ easing: 'ease'
16044
+ };
16045
+ const transitionProperty = 'transform';
16046
+ const disabledTransition = /*#__PURE__*/CSS$1.Transition.toString({
16047
+ property: transitionProperty,
16048
+ duration: 0,
16049
+ easing: 'linear'
16050
+ });
16051
+ const defaultAttributes = {
16052
+ roleDescription: 'sortable'
16053
+ };
16054
+
16055
+ /*
16056
+ * When the index of an item changes while sorting,
16057
+ * we need to temporarily disable the transforms
16058
+ */
16059
+
16060
+ function useDerivedTransform(_ref) {
16061
+ let {
16062
+ disabled,
16063
+ index,
16064
+ node,
16065
+ rect
16066
+ } = _ref;
16067
+ const [derivedTransform, setDerivedtransform] = React.useState(null);
16068
+ const previousIndex = React.useRef(index);
16069
+ useIsomorphicLayoutEffect(() => {
16070
+ if (!disabled && index !== previousIndex.current && node.current) {
16071
+ const initial = rect.current;
16072
+
16073
+ if (initial) {
16074
+ const current = getClientRect(node.current, {
16075
+ ignoreTransform: true
16076
+ });
16077
+ const delta = {
16078
+ x: initial.left - current.left,
16079
+ y: initial.top - current.top,
16080
+ scaleX: initial.width / current.width,
16081
+ scaleY: initial.height / current.height
16082
+ };
16083
+
16084
+ if (delta.x || delta.y) {
16085
+ setDerivedtransform(delta);
16086
+ }
16087
+ }
16088
+ }
16089
+
16090
+ if (index !== previousIndex.current) {
16091
+ previousIndex.current = index;
16092
+ }
16093
+ }, [disabled, index, node, rect]);
16094
+ React.useEffect(() => {
16095
+ if (derivedTransform) {
16096
+ setDerivedtransform(null);
16097
+ }
16098
+ }, [derivedTransform]);
16099
+ return derivedTransform;
16100
+ }
16101
+
16102
+ function useSortable(_ref) {
16103
+ let {
16104
+ animateLayoutChanges = defaultAnimateLayoutChanges,
16105
+ attributes: userDefinedAttributes,
16106
+ disabled: localDisabled,
16107
+ data: customData,
16108
+ getNewIndex = defaultNewIndexGetter,
16109
+ id,
16110
+ strategy: localStrategy,
16111
+ resizeObserverConfig,
16112
+ transition = defaultTransition
16113
+ } = _ref;
16114
+ const {
16115
+ items,
16116
+ containerId,
16117
+ activeIndex,
16118
+ disabled: globalDisabled,
16119
+ disableTransforms,
16120
+ sortedRects,
16121
+ overIndex,
16122
+ useDragOverlay,
16123
+ strategy: globalStrategy
16124
+ } = React.useContext(Context);
16125
+ const disabled = normalizeLocalDisabled(localDisabled, globalDisabled);
16126
+ const index = items.indexOf(id);
16127
+ const data = React.useMemo(() => ({
16128
+ sortable: {
16129
+ containerId,
16130
+ index,
16131
+ items
16132
+ },
16133
+ ...customData
16134
+ }), [containerId, customData, index, items]);
16135
+ const itemsAfterCurrentSortable = React.useMemo(() => items.slice(items.indexOf(id)), [items, id]);
16136
+ const {
16137
+ rect,
16138
+ node,
16139
+ isOver,
16140
+ setNodeRef: setDroppableNodeRef
16141
+ } = useDroppable({
16142
+ id,
16143
+ data,
16144
+ disabled: disabled.droppable,
16145
+ resizeObserverConfig: {
16146
+ updateMeasurementsFor: itemsAfterCurrentSortable,
16147
+ ...resizeObserverConfig
16148
+ }
16149
+ });
16150
+ const {
16151
+ active,
16152
+ activatorEvent,
16153
+ activeNodeRect,
16154
+ attributes,
16155
+ setNodeRef: setDraggableNodeRef,
16156
+ listeners,
16157
+ isDragging,
16158
+ over,
16159
+ setActivatorNodeRef,
16160
+ transform
16161
+ } = useDraggable({
16162
+ id,
16163
+ data,
16164
+ attributes: { ...defaultAttributes,
16165
+ ...userDefinedAttributes
16166
+ },
16167
+ disabled: disabled.draggable
16168
+ });
16169
+ const setNodeRef = useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
16170
+ const isSorting = Boolean(active);
16171
+ const displaceItem = isSorting && !disableTransforms && isValidIndex(activeIndex) && isValidIndex(overIndex);
16172
+ const shouldDisplaceDragSource = !useDragOverlay && isDragging;
16173
+ const dragSourceDisplacement = shouldDisplaceDragSource && displaceItem ? transform : null;
16174
+ const strategy = localStrategy != null ? localStrategy : globalStrategy;
16175
+ const finalTransform = displaceItem ? dragSourceDisplacement != null ? dragSourceDisplacement : strategy({
16176
+ rects: sortedRects,
16177
+ activeNodeRect,
16178
+ activeIndex,
16179
+ overIndex,
16180
+ index
16181
+ }) : null;
16182
+ const newIndex = isValidIndex(activeIndex) && isValidIndex(overIndex) ? getNewIndex({
16183
+ id,
16184
+ items,
16185
+ activeIndex,
16186
+ overIndex
16187
+ }) : index;
16188
+ const activeId = active == null ? void 0 : active.id;
16189
+ const previous = React.useRef({
16190
+ activeId,
16191
+ items,
16192
+ newIndex,
16193
+ containerId
16194
+ });
16195
+ const itemsHaveChanged = items !== previous.current.items;
16196
+ const shouldAnimateLayoutChanges = animateLayoutChanges({
16197
+ active,
16198
+ containerId,
16199
+ isDragging,
16200
+ isSorting,
16201
+ id,
16202
+ index,
16203
+ items,
16204
+ newIndex: previous.current.newIndex,
16205
+ previousItems: previous.current.items,
16206
+ previousContainerId: previous.current.containerId,
16207
+ transition,
16208
+ wasDragging: previous.current.activeId != null
16209
+ });
16210
+ const derivedTransform = useDerivedTransform({
16211
+ disabled: !shouldAnimateLayoutChanges,
16212
+ index,
16213
+ node,
16214
+ rect
16215
+ });
16216
+ React.useEffect(() => {
16217
+ if (isSorting && previous.current.newIndex !== newIndex) {
16218
+ previous.current.newIndex = newIndex;
16219
+ }
16220
+
16221
+ if (containerId !== previous.current.containerId) {
16222
+ previous.current.containerId = containerId;
16223
+ }
16224
+
16225
+ if (items !== previous.current.items) {
16226
+ previous.current.items = items;
16227
+ }
16228
+ }, [isSorting, newIndex, containerId, items]);
16229
+ React.useEffect(() => {
16230
+ if (activeId === previous.current.activeId) {
16231
+ return;
16232
+ }
16233
+
16234
+ if (activeId != null && previous.current.activeId == null) {
16235
+ previous.current.activeId = activeId;
16236
+ return;
16237
+ }
16238
+
16239
+ const timeoutId = setTimeout(() => {
16240
+ previous.current.activeId = activeId;
16241
+ }, 50);
16242
+ return () => clearTimeout(timeoutId);
16243
+ }, [activeId]);
16244
+ return {
16245
+ active,
16246
+ activeIndex,
16247
+ attributes,
16248
+ data,
16249
+ rect,
16250
+ index,
16251
+ newIndex,
16252
+ items,
16253
+ isOver,
16254
+ isSorting,
16255
+ isDragging,
16256
+ listeners,
16257
+ node,
16258
+ overIndex,
16259
+ over,
16260
+ setNodeRef,
16261
+ setActivatorNodeRef,
16262
+ setDroppableNodeRef,
16263
+ setDraggableNodeRef,
16264
+ transform: derivedTransform != null ? derivedTransform : finalTransform,
16265
+ transition: getTransition()
16266
+ };
16267
+
16268
+ function getTransition() {
16269
+ if ( // Temporarily disable transitions for a single frame to set up derived transforms
16270
+ derivedTransform || // Or to prevent items jumping to back to their "new" position when items change
16271
+ itemsHaveChanged && previous.current.newIndex === index) {
16272
+ return disabledTransition;
16273
+ }
16274
+
16275
+ if (shouldDisplaceDragSource && !isKeyboardEvent(activatorEvent) || !transition) {
16276
+ return undefined;
16277
+ }
16278
+
16279
+ if (isSorting || shouldAnimateLayoutChanges) {
16280
+ return CSS$1.Transition.toString({ ...transition,
16281
+ property: transitionProperty
16282
+ });
16283
+ }
16284
+
16285
+ return undefined;
16286
+ }
16287
+ }
16288
+
16289
+ function normalizeLocalDisabled(localDisabled, globalDisabled) {
16290
+ var _localDisabled$dragga, _localDisabled$droppa;
16291
+
16292
+ if (typeof localDisabled === 'boolean') {
16293
+ return {
16294
+ draggable: localDisabled,
16295
+ // Backwards compatibility
16296
+ droppable: false
16297
+ };
16298
+ }
16299
+
16300
+ return {
16301
+ draggable: (_localDisabled$dragga = localDisabled == null ? void 0 : localDisabled.draggable) != null ? _localDisabled$dragga : globalDisabled.draggable,
16302
+ droppable: (_localDisabled$droppa = localDisabled == null ? void 0 : localDisabled.droppable) != null ? _localDisabled$droppa : globalDisabled.droppable
16303
+ };
16304
+ }
16305
+
16306
+ [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];
16307
+
16308
+ const createDefaultRow = () => ({
16309
+ id: typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`,
16310
+ product: "",
16311
+ material: "",
16312
+ lot: "",
16313
+ quantity: 0,
16314
+ multiplier: 1
16315
+ });
16316
+ function SortableRow({
16317
+ row,
16318
+ index,
16319
+ handleChange,
16320
+ removeRow,
16321
+ addRow,
16322
+ options1 = [],
16323
+ options2 = [],
16324
+ isDisabled
16325
+ }) {
16326
+ const {
16327
+ attributes,
16328
+ listeners,
16329
+ setNodeRef,
16330
+ transform,
16331
+ transition,
16332
+ isDragging
16333
+ } = useSortable({
16334
+ id: row.id,
16335
+ animateLayoutChanges: args => defaultAnimateLayoutChanges({
16336
+ ...args,
16337
+ wasDragging: true
16338
+ })
16339
+ });
16340
+ const style = {
16341
+ transform: transform ? CSS$1.Transform.toString(transform) : undefined,
16342
+ transition,
16343
+ boxShadow: isDragging ? "0 4px 8px rgba(0,0,0,0.12)" : "none",
16344
+ marginBottom: 10,
16345
+ display: "flex",
16346
+ alignItems: "center",
16347
+ gap: 8
16348
+ };
16349
+ return /*#__PURE__*/React.createElement("div", _extends$1({
16350
+ ref: setNodeRef,
16351
+ style: style,
16352
+ className: "row"
16353
+ }, attributes), /*#__PURE__*/React.createElement("span", _extends$1({}, listeners, {
16354
+ className: "drag-handle",
16355
+ style: {
16356
+ cursor: "grab",
16357
+ paddingRight: "8px",
16358
+ userSelect: "none",
16359
+ fontSize: "1.2em"
16360
+ },
16361
+ title: "Drag to reorder"
16362
+ }), "\u2630"), Array.isArray(options1) && options1.length > 0 ? /*#__PURE__*/React.createElement("select", {
16363
+ className: "basic-input",
16364
+ value: row.product ?? "",
16365
+ onChange: e => handleChange(index, "product", e.target.value)
16366
+ }, /*#__PURE__*/React.createElement("option", {
16367
+ value: ""
16368
+ }, "Select"), options1.map(opt => /*#__PURE__*/React.createElement("option", {
16369
+ key: opt,
16370
+ value: opt
16371
+ }, opt))) : /*#__PURE__*/React.createElement(DebounceSelect, {
16372
+ objValue: row.product,
16373
+ fetchOptions: async () => [],
16374
+ onSelect: value => handleChange(index, "product", value),
16375
+ disabled: false,
16376
+ style: {
16377
+ width: 200
16378
+ }
16379
+ }), Array.isArray(options2) && options2.length > 0 ? /*#__PURE__*/React.createElement("select", {
16380
+ className: "basic-input",
16381
+ value: row.material ?? "",
16382
+ onChange: e => handleChange(index, "material", e.target.value)
16383
+ }, /*#__PURE__*/React.createElement("option", {
16384
+ value: ""
16385
+ }, "Select"), options2.map(opt => /*#__PURE__*/React.createElement("option", {
16386
+ key: opt,
16387
+ value: opt
16388
+ }, opt))) : /*#__PURE__*/React.createElement(DebounceSelect, {
16389
+ fetchOptions: async () => [],
16390
+ onSelect: value => handleChange(index, "material", value),
16391
+ disabled: false,
16392
+ style: {
16393
+ width: 200
16394
+ }
16395
+ }), /*#__PURE__*/React.createElement("input", {
16396
+ className: "basic-input",
16397
+ type: "text",
16398
+ value: row.lot,
16399
+ placeholder: "lot",
16400
+ onChange: e => handleChange(index, "lot", e.target.value)
16401
+ }), /*#__PURE__*/React.createElement("input", {
16402
+ className: "basic-input",
16403
+ type: "number",
16404
+ value: row.quantity,
16405
+ onChange: e => handleChange(index, "quantity", Number(e.target.value))
16406
+ }), /*#__PURE__*/React.createElement("input", {
16407
+ className: "basic-input",
16408
+ type: "number",
16409
+ value: row.multiplier,
16410
+ onChange: e => handleChange(index, "multiplier", Number(e.target.value))
16411
+ }), /*#__PURE__*/React.createElement("button", {
16412
+ type: "button",
16413
+ className: "basic-button remove",
16414
+ style: {
16415
+ background: isDisabled ? "#f18989" : "red",
16416
+ color: "white"
16417
+ },
16418
+ onClick: e => {
16419
+ e.stopPropagation();
16420
+ removeRow(index);
16421
+ },
16422
+ disabled: isDisabled
16423
+ }, "-"), /*#__PURE__*/React.createElement("button", {
16424
+ type: "button",
16425
+ className: "basic-button",
16426
+ onClick: e => {
16427
+ e.stopPropagation();
16428
+ addRow();
16429
+ }
16430
+ }, "+"));
16431
+ }
16432
+ function EditableRows({
16433
+ rows: propsRows = [],
16434
+ onChange = () => {},
16435
+ options1 = [],
16436
+ options2 = [],
16437
+ user
16438
+ }) {
16439
+ // 1) Create rowsWithIds synchronously so first render has keys
16440
+ const rowsWithIds = React.useMemo(() => {
16441
+ return propsRows.length > 0 ? propsRows.map(r => r && r.id ? r : {
16442
+ ...(r || {}),
16443
+ id: typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`
16444
+ }) : [createDefaultRow()];
16445
+ }, [propsRows]);
16446
+
16447
+ // 2) If we injected ids or injected a default row, sync them back to parent once
16448
+ React.useEffect(() => {
16449
+ const hasMissing = propsRows.length === 0 || propsRows.some(r => !r || !r.id);
16450
+ if (hasMissing) {
16451
+ onChange(rowsWithIds);
16452
+ }
16453
+ // run once on mount
16454
+ // eslint-disable-next-line react-hooks/exhaustive-deps
16455
+ }, []);
16456
+ const rows = rowsWithIds;
16457
+ const sensors = useSensors(useSensor(PointerSensor));
16458
+ const handleDragEnd = event => {
16459
+ const {
16460
+ active,
16461
+ over
16462
+ } = event;
16463
+ if (!over || active.id === over.id) return;
16464
+ const oldIndex = rows.findIndex(r => r.id === active.id);
16465
+ const newIndex = rows.findIndex(r => r.id === over.id);
16466
+ if (oldIndex === -1 || newIndex === -1) return;
16467
+ onChange(arrayMove(rows, oldIndex, newIndex));
16468
+ };
16469
+ const handleChange = (index, field, value) => {
16470
+ const updated = [...rows];
16471
+ updated[index] = {
16472
+ ...updated[index],
16473
+ [field]: value
16474
+ };
16475
+ onChange(updated);
16476
+ };
16477
+ const addRow = () => onChange([...rows, createDefaultRow()]);
16478
+ const removeRow = index => {
16479
+ const updated = rows.filter((_, i) => i !== index);
16480
+ onChange(updated.length ? updated : [createDefaultRow()]);
16481
+ };
16482
+ return /*#__PURE__*/React.createElement("div", {
16483
+ className: "editable-rows"
16484
+ }, /*#__PURE__*/React.createElement(DndContext, {
16485
+ sensors: sensors,
16486
+ collisionDetection: closestCenter,
16487
+ onDragEnd: handleDragEnd
16488
+ }, /*#__PURE__*/React.createElement(SortableContext, {
16489
+ items: rows.map(r => r.id),
16490
+ strategy: verticalListSortingStrategy
16491
+ }, rows.map((row, index) => /*#__PURE__*/React.createElement(SortableRow, {
16492
+ key: row.id,
16493
+ row: row,
16494
+ index: index,
16495
+ handleChange: handleChange,
16496
+ removeRow: removeRow,
16497
+ addRow: addRow,
16498
+ options1: options1,
16499
+ options2: options2,
16500
+ isDisabled: rows.length === 1,
16501
+ user: user
16502
+ })))));
16503
+ }
16504
+
11938
16505
  exports.Button = Button;
11939
16506
  exports.CalendarRangePicker = CalendarRangePicker;
11940
16507
  exports.CardSelect = CardSelect;
11941
16508
  exports.ColorPicker = ColorPicker;
11942
16509
  exports.DateTimeInput = DateTimeInput;
11943
16510
  exports.DebounceSelect = DebounceSelect;
16511
+ exports.EditableRows = EditableRows;
11944
16512
  exports.IconInput = IconInput;
11945
16513
  exports.LineDivider = LineDivider;
11946
16514
  exports.MultiSelect = MultiSelect;