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