@react-aria/utils 3.23.2 → 3.24.1
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/chain.main.js +26 -0
- package/dist/chain.main.js.map +1 -0
- package/dist/chain.mjs +21 -0
- package/dist/chain.module.js +21 -0
- package/dist/chain.module.js.map +1 -0
- package/dist/domHelpers.main.js +19 -0
- package/dist/domHelpers.main.js.map +1 -0
- package/dist/domHelpers.mjs +13 -0
- package/dist/domHelpers.module.js +13 -0
- package/dist/domHelpers.module.js.map +1 -0
- package/dist/filterDOMProps.main.js +45 -0
- package/dist/filterDOMProps.main.js.map +1 -0
- package/dist/filterDOMProps.mjs +40 -0
- package/dist/filterDOMProps.module.js +40 -0
- package/dist/filterDOMProps.module.js.map +1 -0
- package/dist/focusWithoutScrolling.main.js +72 -0
- package/dist/focusWithoutScrolling.main.js.map +1 -0
- package/dist/focusWithoutScrolling.mjs +67 -0
- package/dist/focusWithoutScrolling.module.js +67 -0
- package/dist/focusWithoutScrolling.module.js.map +1 -0
- package/dist/getOffset.main.js +24 -0
- package/dist/getOffset.main.js.map +1 -0
- package/dist/getOffset.mjs +19 -0
- package/dist/getOffset.module.js +19 -0
- package/dist/getOffset.module.js.map +1 -0
- package/dist/getScrollParent.main.js +28 -0
- package/dist/getScrollParent.main.js.map +1 -0
- package/dist/getScrollParent.mjs +23 -0
- package/dist/getScrollParent.module.js +23 -0
- package/dist/getScrollParent.module.js.map +1 -0
- package/dist/getScrollParents.main.js +30 -0
- package/dist/getScrollParents.main.js.map +1 -0
- package/dist/getScrollParents.mjs +25 -0
- package/dist/getScrollParents.module.js +25 -0
- package/dist/getScrollParents.module.js.map +1 -0
- package/dist/import.mjs +32 -1232
- package/dist/isScrollable.main.js +25 -0
- package/dist/isScrollable.main.js.map +1 -0
- package/dist/isScrollable.mjs +20 -0
- package/dist/isScrollable.module.js +20 -0
- package/dist/isScrollable.module.js.map +1 -0
- package/dist/isVirtualEvent.main.js +41 -0
- package/dist/isVirtualEvent.main.js.map +1 -0
- package/dist/isVirtualEvent.mjs +35 -0
- package/dist/isVirtualEvent.module.js +35 -0
- package/dist/isVirtualEvent.module.js.map +1 -0
- package/dist/main.js +80 -1282
- package/dist/main.js.map +1 -1
- package/dist/mergeProps.main.js +51 -0
- package/dist/mergeProps.main.js.map +1 -0
- package/dist/mergeProps.mjs +42 -0
- package/dist/mergeProps.module.js +42 -0
- package/dist/mergeProps.module.js.map +1 -0
- package/dist/mergeRefs.main.js +28 -0
- package/dist/mergeRefs.main.js.map +1 -0
- package/dist/mergeRefs.mjs +23 -0
- package/dist/mergeRefs.module.js +23 -0
- package/dist/mergeRefs.module.js.map +1 -0
- package/dist/module.js +32 -1232
- package/dist/module.js.map +1 -1
- package/dist/openLink.main.js +143 -0
- package/dist/openLink.main.js.map +1 -0
- package/dist/openLink.mjs +129 -0
- package/dist/openLink.module.js +129 -0
- package/dist/openLink.module.js.map +1 -0
- package/dist/platform.main.js +64 -0
- package/dist/platform.main.js.map +1 -0
- package/dist/platform.mjs +51 -0
- package/dist/platform.module.js +51 -0
- package/dist/platform.module.js.map +1 -0
- package/dist/runAfterTransition.main.js +82 -0
- package/dist/runAfterTransition.main.js.map +1 -0
- package/dist/runAfterTransition.mjs +77 -0
- package/dist/runAfterTransition.module.js +77 -0
- package/dist/runAfterTransition.module.js.map +1 -0
- package/dist/scrollIntoView.main.js +96 -0
- package/dist/scrollIntoView.main.js.map +1 -0
- package/dist/scrollIntoView.mjs +90 -0
- package/dist/scrollIntoView.module.js +90 -0
- package/dist/scrollIntoView.module.js.map +1 -0
- package/dist/types.d.ts +17 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/useDeepMemo.main.js +30 -0
- package/dist/useDeepMemo.main.js.map +1 -0
- package/dist/useDeepMemo.mjs +25 -0
- package/dist/useDeepMemo.module.js +25 -0
- package/dist/useDeepMemo.module.js.map +1 -0
- package/dist/useDescription.main.js +59 -0
- package/dist/useDescription.main.js.map +1 -0
- package/dist/useDescription.mjs +54 -0
- package/dist/useDescription.module.js +54 -0
- package/dist/useDescription.module.js.map +1 -0
- package/dist/useDrag1D.main.js +139 -0
- package/dist/useDrag1D.main.js.map +1 -0
- package/dist/useDrag1D.mjs +134 -0
- package/dist/useDrag1D.module.js +134 -0
- package/dist/useDrag1D.module.js.map +1 -0
- package/dist/useEffectEvent.main.js +37 -0
- package/dist/useEffectEvent.main.js.map +1 -0
- package/dist/useEffectEvent.mjs +32 -0
- package/dist/useEffectEvent.module.js +32 -0
- package/dist/useEffectEvent.module.js.map +1 -0
- package/dist/useEvent.main.js +42 -0
- package/dist/useEvent.main.js.map +1 -0
- package/dist/useEvent.mjs +37 -0
- package/dist/useEvent.module.js +37 -0
- package/dist/useEvent.module.js.map +1 -0
- package/dist/useFormReset.main.js +41 -0
- package/dist/useFormReset.main.js.map +1 -0
- package/dist/useFormReset.mjs +36 -0
- package/dist/useFormReset.module.js +36 -0
- package/dist/useFormReset.module.js.map +1 -0
- package/dist/useGlobalListeners.main.js +63 -0
- package/dist/useGlobalListeners.main.js.map +1 -0
- package/dist/useGlobalListeners.mjs +58 -0
- package/dist/useGlobalListeners.module.js +58 -0
- package/dist/useGlobalListeners.module.js.map +1 -0
- package/dist/useId.main.js +93 -0
- package/dist/useId.main.js.map +1 -0
- package/dist/useId.mjs +86 -0
- package/dist/useId.module.js +86 -0
- package/dist/useId.module.js.map +1 -0
- package/dist/useLabels.main.js +44 -0
- package/dist/useLabels.main.js.map +1 -0
- package/dist/useLabels.mjs +39 -0
- package/dist/useLabels.module.js +39 -0
- package/dist/useLabels.module.js.map +1 -0
- package/dist/useLayoutEffect.main.js +27 -0
- package/dist/useLayoutEffect.main.js.map +1 -0
- package/dist/useLayoutEffect.mjs +18 -0
- package/dist/useLayoutEffect.module.js +18 -0
- package/dist/useLayoutEffect.module.js.map +1 -0
- package/dist/useObjectRef.main.js +37 -0
- package/dist/useObjectRef.main.js.map +1 -0
- package/dist/useObjectRef.mjs +32 -0
- package/dist/useObjectRef.module.js +32 -0
- package/dist/useObjectRef.module.js.map +1 -0
- package/dist/useResizeObserver.main.js +40 -0
- package/dist/useResizeObserver.main.js.map +1 -0
- package/dist/useResizeObserver.mjs +35 -0
- package/dist/useResizeObserver.module.js +35 -0
- package/dist/useResizeObserver.module.js.map +1 -0
- package/dist/useSyncRef.main.js +32 -0
- package/dist/useSyncRef.main.js.map +1 -0
- package/dist/useSyncRef.mjs +27 -0
- package/dist/useSyncRef.module.js +27 -0
- package/dist/useSyncRef.module.js.map +1 -0
- package/dist/useUpdateEffect.main.js +38 -0
- package/dist/useUpdateEffect.main.js.map +1 -0
- package/dist/useUpdateEffect.mjs +33 -0
- package/dist/useUpdateEffect.module.js +33 -0
- package/dist/useUpdateEffect.module.js.map +1 -0
- package/dist/useValueEffect.main.js +58 -0
- package/dist/useValueEffect.main.js.map +1 -0
- package/dist/useValueEffect.mjs +53 -0
- package/dist/useValueEffect.module.js +53 -0
- package/dist/useValueEffect.module.js.map +1 -0
- package/dist/useViewportSize.main.js +56 -0
- package/dist/useViewportSize.main.js.map +1 -0
- package/dist/useViewportSize.mjs +51 -0
- package/dist/useViewportSize.module.js +51 -0
- package/dist/useViewportSize.module.js.map +1 -0
- package/package.json +5 -5
- package/src/filterDOMProps.ts +1 -0
- package/src/getScrollParent.ts +2 -10
- package/src/getScrollParents.ts +26 -0
- package/src/index.ts +4 -2
- package/src/isScrollable.ts +22 -0
- package/src/mergeRefs.ts +2 -2
- package/src/openLink.tsx +25 -9
- package/src/scrollIntoView.ts +3 -5
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {useLayoutEffect as $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c} from "./useLayoutEffect.mjs";
|
|
2
|
+
import {useState as $hQ5Hp$useState} from "react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
let $ef06256079686ba0$var$descriptionId = 0;
|
|
17
|
+
const $ef06256079686ba0$var$descriptionNodes = new Map();
|
|
18
|
+
function $ef06256079686ba0$export$f8aeda7b10753fa1(description) {
|
|
19
|
+
let [id, setId] = (0, $hQ5Hp$useState)();
|
|
20
|
+
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
21
|
+
if (!description) return;
|
|
22
|
+
let desc = $ef06256079686ba0$var$descriptionNodes.get(description);
|
|
23
|
+
if (!desc) {
|
|
24
|
+
let id = `react-aria-description-${$ef06256079686ba0$var$descriptionId++}`;
|
|
25
|
+
setId(id);
|
|
26
|
+
let node = document.createElement('div');
|
|
27
|
+
node.id = id;
|
|
28
|
+
node.style.display = 'none';
|
|
29
|
+
node.textContent = description;
|
|
30
|
+
document.body.appendChild(node);
|
|
31
|
+
desc = {
|
|
32
|
+
refCount: 0,
|
|
33
|
+
element: node
|
|
34
|
+
};
|
|
35
|
+
$ef06256079686ba0$var$descriptionNodes.set(description, desc);
|
|
36
|
+
} else setId(desc.element.id);
|
|
37
|
+
desc.refCount++;
|
|
38
|
+
return ()=>{
|
|
39
|
+
if (desc && --desc.refCount === 0) {
|
|
40
|
+
desc.element.remove();
|
|
41
|
+
$ef06256079686ba0$var$descriptionNodes.delete(description);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}, [
|
|
45
|
+
description
|
|
46
|
+
]);
|
|
47
|
+
return {
|
|
48
|
+
'aria-describedby': description ? id : undefined
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
export {$ef06256079686ba0$export$f8aeda7b10753fa1 as useDescription};
|
|
54
|
+
//# sourceMappingURL=useDescription.module.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import {useLayoutEffect as $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c} from "./useLayoutEffect.module.js";
|
|
2
|
+
import {useState as $hQ5Hp$useState} from "react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
let $ef06256079686ba0$var$descriptionId = 0;
|
|
17
|
+
const $ef06256079686ba0$var$descriptionNodes = new Map();
|
|
18
|
+
function $ef06256079686ba0$export$f8aeda7b10753fa1(description) {
|
|
19
|
+
let [id, setId] = (0, $hQ5Hp$useState)();
|
|
20
|
+
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
21
|
+
if (!description) return;
|
|
22
|
+
let desc = $ef06256079686ba0$var$descriptionNodes.get(description);
|
|
23
|
+
if (!desc) {
|
|
24
|
+
let id = `react-aria-description-${$ef06256079686ba0$var$descriptionId++}`;
|
|
25
|
+
setId(id);
|
|
26
|
+
let node = document.createElement('div');
|
|
27
|
+
node.id = id;
|
|
28
|
+
node.style.display = 'none';
|
|
29
|
+
node.textContent = description;
|
|
30
|
+
document.body.appendChild(node);
|
|
31
|
+
desc = {
|
|
32
|
+
refCount: 0,
|
|
33
|
+
element: node
|
|
34
|
+
};
|
|
35
|
+
$ef06256079686ba0$var$descriptionNodes.set(description, desc);
|
|
36
|
+
} else setId(desc.element.id);
|
|
37
|
+
desc.refCount++;
|
|
38
|
+
return ()=>{
|
|
39
|
+
if (desc && --desc.refCount === 0) {
|
|
40
|
+
desc.element.remove();
|
|
41
|
+
$ef06256079686ba0$var$descriptionNodes.delete(description);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}, [
|
|
45
|
+
description
|
|
46
|
+
]);
|
|
47
|
+
return {
|
|
48
|
+
'aria-describedby': description ? id : undefined
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
export {$ef06256079686ba0$export$f8aeda7b10753fa1 as useDescription};
|
|
54
|
+
//# sourceMappingURL=useDescription.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAMD,IAAI,sCAAgB;AACpB,MAAM,yCAAmB,IAAI;AAEtB,SAAS,0CAAe,WAAoB;IACjD,IAAI,CAAC,IAAI,MAAM,GAAG,CAAA,GAAA,eAAO;IAEzB,CAAA,GAAA,yCAAc,EAAE;QACd,IAAI,CAAC,aACH;QAGF,IAAI,OAAO,uCAAiB,GAAG,CAAC;QAChC,IAAI,CAAC,MAAM;YACT,IAAI,KAAK,CAAC,uBAAuB,EAAE,sCAAgB,CAAC;YACpD,MAAM;YAEN,IAAI,OAAO,SAAS,aAAa,CAAC;YAClC,KAAK,EAAE,GAAG;YACV,KAAK,KAAK,CAAC,OAAO,GAAG;YACrB,KAAK,WAAW,GAAG;YACnB,SAAS,IAAI,CAAC,WAAW,CAAC;YAC1B,OAAO;gBAAC,UAAU;gBAAG,SAAS;YAAI;YAClC,uCAAiB,GAAG,CAAC,aAAa;QACpC,OACE,MAAM,KAAK,OAAO,CAAC,EAAE;QAGvB,KAAK,QAAQ;QACb,OAAO;YACL,IAAI,QAAQ,EAAE,KAAK,QAAQ,KAAK,GAAG;gBACjC,KAAK,OAAO,CAAC,MAAM;gBACnB,uCAAiB,MAAM,CAAC;YAC1B;QACF;IACF,GAAG;QAAC;KAAY;IAEhB,OAAO;QACL,oBAAoB,cAAc,KAAK;IACzC;AACF","sources":["packages/@react-aria/utils/src/useDescription.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaLabelingProps} from '@react-types/shared';\nimport {useLayoutEffect} from './useLayoutEffect';\nimport {useState} from 'react';\n\nlet descriptionId = 0;\nconst descriptionNodes = new Map<string, {refCount: number, element: Element}>();\n\nexport function useDescription(description?: string): AriaLabelingProps {\n let [id, setId] = useState<string | undefined>();\n\n useLayoutEffect(() => {\n if (!description) {\n return;\n }\n\n let desc = descriptionNodes.get(description);\n if (!desc) {\n let id = `react-aria-description-${descriptionId++}`;\n setId(id);\n\n let node = document.createElement('div');\n node.id = id;\n node.style.display = 'none';\n node.textContent = description;\n document.body.appendChild(node);\n desc = {refCount: 0, element: node};\n descriptionNodes.set(description, desc);\n } else {\n setId(desc.element.id);\n }\n\n desc.refCount++;\n return () => {\n if (desc && --desc.refCount === 0) {\n desc.element.remove();\n descriptionNodes.delete(description);\n }\n };\n }, [description]);\n\n return {\n 'aria-describedby': description ? id : undefined\n };\n}\n"],"names":[],"version":3,"file":"useDescription.module.js.map"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
var $16ec41ef3e36c19c$exports = require("./getOffset.main.js");
|
|
2
|
+
var $hK8r3$react = require("react");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "useDrag1D", () => $28ed3fb20343b78b$export$7bbed75feba39706);
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
12
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
* governing permissions and limitations under the License.
|
|
20
|
+
*/ /* eslint-disable rulesdir/pure-render */
|
|
21
|
+
|
|
22
|
+
// Keep track of elements that we are currently handling dragging for via useDrag1D.
|
|
23
|
+
// If there's an ancestor and a descendant both using useDrag1D(), and the user starts
|
|
24
|
+
// dragging the descendant, we don't want useDrag1D events to fire for the ancestor.
|
|
25
|
+
const $28ed3fb20343b78b$var$draggingElements = [];
|
|
26
|
+
function $28ed3fb20343b78b$export$7bbed75feba39706(props) {
|
|
27
|
+
console.warn('useDrag1D is deprecated, please use `useMove` instead https://react-spectrum.adobe.com/react-aria/useMove.html');
|
|
28
|
+
let { containerRef: containerRef, reverse: reverse, orientation: orientation, onHover: onHover, onDrag: onDrag, onPositionChange: onPositionChange, onIncrement: onIncrement, onDecrement: onDecrement, onIncrementToMax: onIncrementToMax, onDecrementToMin: onDecrementToMin, onCollapseToggle: onCollapseToggle } = props;
|
|
29
|
+
let getPosition = (e)=>orientation === 'horizontal' ? e.clientX : e.clientY;
|
|
30
|
+
let getNextOffset = (e)=>{
|
|
31
|
+
let containerOffset = (0, $16ec41ef3e36c19c$exports.getOffset)(containerRef.current, reverse, orientation);
|
|
32
|
+
let mouseOffset = getPosition(e);
|
|
33
|
+
let nextOffset = reverse ? containerOffset - mouseOffset : mouseOffset - containerOffset;
|
|
34
|
+
return nextOffset;
|
|
35
|
+
};
|
|
36
|
+
let dragging = (0, $hK8r3$react.useRef)(false);
|
|
37
|
+
let prevPosition = (0, $hK8r3$react.useRef)(0);
|
|
38
|
+
// Keep track of the current handlers in a ref so that the events can access them.
|
|
39
|
+
let handlers = (0, $hK8r3$react.useRef)({
|
|
40
|
+
onPositionChange: onPositionChange,
|
|
41
|
+
onDrag: onDrag
|
|
42
|
+
});
|
|
43
|
+
handlers.current.onDrag = onDrag;
|
|
44
|
+
handlers.current.onPositionChange = onPositionChange;
|
|
45
|
+
let onMouseDragged = (e)=>{
|
|
46
|
+
e.preventDefault();
|
|
47
|
+
let nextOffset = getNextOffset(e);
|
|
48
|
+
if (!dragging.current) {
|
|
49
|
+
dragging.current = true;
|
|
50
|
+
if (handlers.current.onDrag) handlers.current.onDrag(true);
|
|
51
|
+
if (handlers.current.onPositionChange) handlers.current.onPositionChange(nextOffset);
|
|
52
|
+
}
|
|
53
|
+
if (prevPosition.current === nextOffset) return;
|
|
54
|
+
prevPosition.current = nextOffset;
|
|
55
|
+
if (onPositionChange) onPositionChange(nextOffset);
|
|
56
|
+
};
|
|
57
|
+
let onMouseUp = (e)=>{
|
|
58
|
+
const target = e.target;
|
|
59
|
+
dragging.current = false;
|
|
60
|
+
let nextOffset = getNextOffset(e);
|
|
61
|
+
if (handlers.current.onDrag) handlers.current.onDrag(false);
|
|
62
|
+
if (handlers.current.onPositionChange) handlers.current.onPositionChange(nextOffset);
|
|
63
|
+
$28ed3fb20343b78b$var$draggingElements.splice($28ed3fb20343b78b$var$draggingElements.indexOf(target), 1);
|
|
64
|
+
window.removeEventListener('mouseup', onMouseUp, false);
|
|
65
|
+
window.removeEventListener('mousemove', onMouseDragged, false);
|
|
66
|
+
};
|
|
67
|
+
let onMouseDown = (e)=>{
|
|
68
|
+
const target = e.currentTarget;
|
|
69
|
+
// If we're already handling dragging on a descendant with useDrag1D, then
|
|
70
|
+
// we don't want to handle the drag motion on this target as well.
|
|
71
|
+
if ($28ed3fb20343b78b$var$draggingElements.some((elt)=>target.contains(elt))) return;
|
|
72
|
+
$28ed3fb20343b78b$var$draggingElements.push(target);
|
|
73
|
+
window.addEventListener('mousemove', onMouseDragged, false);
|
|
74
|
+
window.addEventListener('mouseup', onMouseUp, false);
|
|
75
|
+
};
|
|
76
|
+
let onMouseEnter = ()=>{
|
|
77
|
+
if (onHover) onHover(true);
|
|
78
|
+
};
|
|
79
|
+
let onMouseOut = ()=>{
|
|
80
|
+
if (onHover) onHover(false);
|
|
81
|
+
};
|
|
82
|
+
let onKeyDown = (e)=>{
|
|
83
|
+
switch(e.key){
|
|
84
|
+
case 'Left':
|
|
85
|
+
case 'ArrowLeft':
|
|
86
|
+
if (orientation === 'horizontal') {
|
|
87
|
+
e.preventDefault();
|
|
88
|
+
if (onDecrement && !reverse) onDecrement();
|
|
89
|
+
else if (onIncrement && reverse) onIncrement();
|
|
90
|
+
}
|
|
91
|
+
break;
|
|
92
|
+
case 'Up':
|
|
93
|
+
case 'ArrowUp':
|
|
94
|
+
if (orientation === 'vertical') {
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
if (onDecrement && !reverse) onDecrement();
|
|
97
|
+
else if (onIncrement && reverse) onIncrement();
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
case 'Right':
|
|
101
|
+
case 'ArrowRight':
|
|
102
|
+
if (orientation === 'horizontal') {
|
|
103
|
+
e.preventDefault();
|
|
104
|
+
if (onIncrement && !reverse) onIncrement();
|
|
105
|
+
else if (onDecrement && reverse) onDecrement();
|
|
106
|
+
}
|
|
107
|
+
break;
|
|
108
|
+
case 'Down':
|
|
109
|
+
case 'ArrowDown':
|
|
110
|
+
if (orientation === 'vertical') {
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
if (onIncrement && !reverse) onIncrement();
|
|
113
|
+
else if (onDecrement && reverse) onDecrement();
|
|
114
|
+
}
|
|
115
|
+
break;
|
|
116
|
+
case 'Home':
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
if (onDecrementToMin) onDecrementToMin();
|
|
119
|
+
break;
|
|
120
|
+
case 'End':
|
|
121
|
+
e.preventDefault();
|
|
122
|
+
if (onIncrementToMax) onIncrementToMax();
|
|
123
|
+
break;
|
|
124
|
+
case 'Enter':
|
|
125
|
+
e.preventDefault();
|
|
126
|
+
if (onCollapseToggle) onCollapseToggle();
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
return {
|
|
131
|
+
onMouseDown: onMouseDown,
|
|
132
|
+
onMouseEnter: onMouseEnter,
|
|
133
|
+
onMouseOut: onMouseOut,
|
|
134
|
+
onKeyDown: onKeyDown
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
//# sourceMappingURL=useDrag1D.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"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","sources":["packages/@react-aria/utils/src/useDrag1D.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n /* eslint-disable rulesdir/pure-render */\n\nimport {getOffset} from './getOffset';\nimport {Orientation} from '@react-types/shared';\nimport React, {HTMLAttributes, MutableRefObject, useRef} from 'react';\n\ninterface UseDrag1DProps {\n containerRef: MutableRefObject<HTMLElement>,\n reverse?: boolean,\n orientation?: Orientation,\n onHover?: (hovered: boolean) => void,\n onDrag?: (dragging: boolean) => void,\n onPositionChange?: (position: number) => void,\n onIncrement?: () => void,\n onDecrement?: () => void,\n onIncrementToMax?: () => void,\n onDecrementToMin?: () => void,\n onCollapseToggle?: () => void\n}\n\n// Keep track of elements that we are currently handling dragging for via useDrag1D.\n// If there's an ancestor and a descendant both using useDrag1D(), and the user starts\n// dragging the descendant, we don't want useDrag1D events to fire for the ancestor.\nconst draggingElements: HTMLElement[] = [];\n\n// created for splitview, this should be reusable for things like sliders/dials\n// It also handles keyboard events on the target allowing for increment/decrement by a given stepsize as well as minifying/maximizing and toggling between minified and previous size\n// It can also take a 'reverse' param to say if we should measure from the right/bottom instead of the top/left\n// It can also handle either a vertical or horizontal movement, but not both at the same time\n\nexport function useDrag1D(props: UseDrag1DProps): HTMLAttributes<HTMLElement> {\n console.warn('useDrag1D is deprecated, please use `useMove` instead https://react-spectrum.adobe.com/react-aria/useMove.html');\n let {containerRef, reverse, orientation, onHover, onDrag, onPositionChange, onIncrement, onDecrement, onIncrementToMax, onDecrementToMin, onCollapseToggle} = props;\n let getPosition = (e) => orientation === 'horizontal' ? e.clientX : e.clientY;\n let getNextOffset = (e: MouseEvent) => {\n let containerOffset = getOffset(containerRef.current, reverse, orientation);\n let mouseOffset = getPosition(e);\n let nextOffset = reverse ? containerOffset - mouseOffset : mouseOffset - containerOffset;\n return nextOffset;\n };\n let dragging = useRef(false);\n let prevPosition = useRef(0);\n\n // Keep track of the current handlers in a ref so that the events can access them.\n let handlers = useRef({onPositionChange, onDrag});\n handlers.current.onDrag = onDrag;\n handlers.current.onPositionChange = onPositionChange;\n\n let onMouseDragged = (e: MouseEvent) => {\n e.preventDefault();\n let nextOffset = getNextOffset(e);\n if (!dragging.current) {\n dragging.current = true;\n if (handlers.current.onDrag) {\n handlers.current.onDrag(true);\n }\n if (handlers.current.onPositionChange) {\n handlers.current.onPositionChange(nextOffset);\n }\n }\n if (prevPosition.current === nextOffset) {\n return;\n }\n prevPosition.current = nextOffset;\n if (onPositionChange) {\n onPositionChange(nextOffset);\n }\n };\n\n let onMouseUp = (e: MouseEvent) => {\n const target = e.target as HTMLElement;\n dragging.current = false;\n let nextOffset = getNextOffset(e);\n if (handlers.current.onDrag) {\n handlers.current.onDrag(false);\n }\n if (handlers.current.onPositionChange) {\n handlers.current.onPositionChange(nextOffset);\n }\n\n draggingElements.splice(draggingElements.indexOf(target), 1);\n window.removeEventListener('mouseup', onMouseUp, false);\n window.removeEventListener('mousemove', onMouseDragged, false);\n };\n\n let onMouseDown = (e: React.MouseEvent<HTMLElement>) => {\n const target = e.currentTarget;\n // If we're already handling dragging on a descendant with useDrag1D, then\n // we don't want to handle the drag motion on this target as well.\n if (draggingElements.some(elt => target.contains(elt))) {\n return;\n }\n draggingElements.push(target);\n window.addEventListener('mousemove', onMouseDragged, false);\n window.addEventListener('mouseup', onMouseUp, false);\n };\n\n let onMouseEnter = () => {\n if (onHover) {\n onHover(true);\n }\n };\n\n let onMouseOut = () => {\n if (onHover) {\n onHover(false);\n }\n };\n\n let onKeyDown = (e) => {\n switch (e.key) {\n case 'Left':\n case 'ArrowLeft':\n if (orientation === 'horizontal') {\n e.preventDefault();\n if (onDecrement && !reverse) {\n onDecrement();\n } else if (onIncrement && reverse) {\n onIncrement();\n }\n }\n break;\n case 'Up':\n case 'ArrowUp':\n if (orientation === 'vertical') {\n e.preventDefault();\n if (onDecrement && !reverse) {\n onDecrement();\n } else if (onIncrement && reverse) {\n onIncrement();\n }\n }\n break;\n case 'Right':\n case 'ArrowRight':\n if (orientation === 'horizontal') {\n e.preventDefault();\n if (onIncrement && !reverse) {\n onIncrement();\n } else if (onDecrement && reverse) {\n onDecrement();\n }\n }\n break;\n case 'Down':\n case 'ArrowDown':\n if (orientation === 'vertical') {\n e.preventDefault();\n if (onIncrement && !reverse) {\n onIncrement();\n } else if (onDecrement && reverse) {\n onDecrement();\n }\n }\n break;\n case 'Home':\n e.preventDefault();\n if (onDecrementToMin) {\n onDecrementToMin();\n }\n break;\n case 'End':\n e.preventDefault();\n if (onIncrementToMax) {\n onIncrementToMax();\n }\n break;\n case 'Enter':\n e.preventDefault();\n if (onCollapseToggle) {\n onCollapseToggle();\n }\n break;\n }\n };\n\n return {onMouseDown, onMouseEnter, onMouseOut, onKeyDown};\n}\n"],"names":[],"version":3,"file":"useDrag1D.main.js.map"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {getOffset as $ab71dadb03a6fb2e$export$622cea445a1c5b7d} from "./getOffset.mjs";
|
|
2
|
+
import {useRef as $1rnCS$useRef} from "react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/ /* eslint-disable rulesdir/pure-render */
|
|
15
|
+
|
|
16
|
+
// Keep track of elements that we are currently handling dragging for via useDrag1D.
|
|
17
|
+
// If there's an ancestor and a descendant both using useDrag1D(), and the user starts
|
|
18
|
+
// dragging the descendant, we don't want useDrag1D events to fire for the ancestor.
|
|
19
|
+
const $9cc09df9fd7676be$var$draggingElements = [];
|
|
20
|
+
function $9cc09df9fd7676be$export$7bbed75feba39706(props) {
|
|
21
|
+
console.warn('useDrag1D is deprecated, please use `useMove` instead https://react-spectrum.adobe.com/react-aria/useMove.html');
|
|
22
|
+
let { containerRef: containerRef, reverse: reverse, orientation: orientation, onHover: onHover, onDrag: onDrag, onPositionChange: onPositionChange, onIncrement: onIncrement, onDecrement: onDecrement, onIncrementToMax: onIncrementToMax, onDecrementToMin: onDecrementToMin, onCollapseToggle: onCollapseToggle } = props;
|
|
23
|
+
let getPosition = (e)=>orientation === 'horizontal' ? e.clientX : e.clientY;
|
|
24
|
+
let getNextOffset = (e)=>{
|
|
25
|
+
let containerOffset = (0, $ab71dadb03a6fb2e$export$622cea445a1c5b7d)(containerRef.current, reverse, orientation);
|
|
26
|
+
let mouseOffset = getPosition(e);
|
|
27
|
+
let nextOffset = reverse ? containerOffset - mouseOffset : mouseOffset - containerOffset;
|
|
28
|
+
return nextOffset;
|
|
29
|
+
};
|
|
30
|
+
let dragging = (0, $1rnCS$useRef)(false);
|
|
31
|
+
let prevPosition = (0, $1rnCS$useRef)(0);
|
|
32
|
+
// Keep track of the current handlers in a ref so that the events can access them.
|
|
33
|
+
let handlers = (0, $1rnCS$useRef)({
|
|
34
|
+
onPositionChange: onPositionChange,
|
|
35
|
+
onDrag: onDrag
|
|
36
|
+
});
|
|
37
|
+
handlers.current.onDrag = onDrag;
|
|
38
|
+
handlers.current.onPositionChange = onPositionChange;
|
|
39
|
+
let onMouseDragged = (e)=>{
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
let nextOffset = getNextOffset(e);
|
|
42
|
+
if (!dragging.current) {
|
|
43
|
+
dragging.current = true;
|
|
44
|
+
if (handlers.current.onDrag) handlers.current.onDrag(true);
|
|
45
|
+
if (handlers.current.onPositionChange) handlers.current.onPositionChange(nextOffset);
|
|
46
|
+
}
|
|
47
|
+
if (prevPosition.current === nextOffset) return;
|
|
48
|
+
prevPosition.current = nextOffset;
|
|
49
|
+
if (onPositionChange) onPositionChange(nextOffset);
|
|
50
|
+
};
|
|
51
|
+
let onMouseUp = (e)=>{
|
|
52
|
+
const target = e.target;
|
|
53
|
+
dragging.current = false;
|
|
54
|
+
let nextOffset = getNextOffset(e);
|
|
55
|
+
if (handlers.current.onDrag) handlers.current.onDrag(false);
|
|
56
|
+
if (handlers.current.onPositionChange) handlers.current.onPositionChange(nextOffset);
|
|
57
|
+
$9cc09df9fd7676be$var$draggingElements.splice($9cc09df9fd7676be$var$draggingElements.indexOf(target), 1);
|
|
58
|
+
window.removeEventListener('mouseup', onMouseUp, false);
|
|
59
|
+
window.removeEventListener('mousemove', onMouseDragged, false);
|
|
60
|
+
};
|
|
61
|
+
let onMouseDown = (e)=>{
|
|
62
|
+
const target = e.currentTarget;
|
|
63
|
+
// If we're already handling dragging on a descendant with useDrag1D, then
|
|
64
|
+
// we don't want to handle the drag motion on this target as well.
|
|
65
|
+
if ($9cc09df9fd7676be$var$draggingElements.some((elt)=>target.contains(elt))) return;
|
|
66
|
+
$9cc09df9fd7676be$var$draggingElements.push(target);
|
|
67
|
+
window.addEventListener('mousemove', onMouseDragged, false);
|
|
68
|
+
window.addEventListener('mouseup', onMouseUp, false);
|
|
69
|
+
};
|
|
70
|
+
let onMouseEnter = ()=>{
|
|
71
|
+
if (onHover) onHover(true);
|
|
72
|
+
};
|
|
73
|
+
let onMouseOut = ()=>{
|
|
74
|
+
if (onHover) onHover(false);
|
|
75
|
+
};
|
|
76
|
+
let onKeyDown = (e)=>{
|
|
77
|
+
switch(e.key){
|
|
78
|
+
case 'Left':
|
|
79
|
+
case 'ArrowLeft':
|
|
80
|
+
if (orientation === 'horizontal') {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
if (onDecrement && !reverse) onDecrement();
|
|
83
|
+
else if (onIncrement && reverse) onIncrement();
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case 'Up':
|
|
87
|
+
case 'ArrowUp':
|
|
88
|
+
if (orientation === 'vertical') {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
if (onDecrement && !reverse) onDecrement();
|
|
91
|
+
else if (onIncrement && reverse) onIncrement();
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
case 'Right':
|
|
95
|
+
case 'ArrowRight':
|
|
96
|
+
if (orientation === 'horizontal') {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
if (onIncrement && !reverse) onIncrement();
|
|
99
|
+
else if (onDecrement && reverse) onDecrement();
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case 'Down':
|
|
103
|
+
case 'ArrowDown':
|
|
104
|
+
if (orientation === 'vertical') {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
if (onIncrement && !reverse) onIncrement();
|
|
107
|
+
else if (onDecrement && reverse) onDecrement();
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
case 'Home':
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
if (onDecrementToMin) onDecrementToMin();
|
|
113
|
+
break;
|
|
114
|
+
case 'End':
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
if (onIncrementToMax) onIncrementToMax();
|
|
117
|
+
break;
|
|
118
|
+
case 'Enter':
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
if (onCollapseToggle) onCollapseToggle();
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
onMouseDown: onMouseDown,
|
|
126
|
+
onMouseEnter: onMouseEnter,
|
|
127
|
+
onMouseOut: onMouseOut,
|
|
128
|
+
onKeyDown: onKeyDown
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
export {$9cc09df9fd7676be$export$7bbed75feba39706 as useDrag1D};
|
|
134
|
+
//# sourceMappingURL=useDrag1D.module.js.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import {getOffset as $ab71dadb03a6fb2e$export$622cea445a1c5b7d} from "./getOffset.module.js";
|
|
2
|
+
import {useRef as $1rnCS$useRef} from "react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/ /* eslint-disable rulesdir/pure-render */
|
|
15
|
+
|
|
16
|
+
// Keep track of elements that we are currently handling dragging for via useDrag1D.
|
|
17
|
+
// If there's an ancestor and a descendant both using useDrag1D(), and the user starts
|
|
18
|
+
// dragging the descendant, we don't want useDrag1D events to fire for the ancestor.
|
|
19
|
+
const $9cc09df9fd7676be$var$draggingElements = [];
|
|
20
|
+
function $9cc09df9fd7676be$export$7bbed75feba39706(props) {
|
|
21
|
+
console.warn('useDrag1D is deprecated, please use `useMove` instead https://react-spectrum.adobe.com/react-aria/useMove.html');
|
|
22
|
+
let { containerRef: containerRef, reverse: reverse, orientation: orientation, onHover: onHover, onDrag: onDrag, onPositionChange: onPositionChange, onIncrement: onIncrement, onDecrement: onDecrement, onIncrementToMax: onIncrementToMax, onDecrementToMin: onDecrementToMin, onCollapseToggle: onCollapseToggle } = props;
|
|
23
|
+
let getPosition = (e)=>orientation === 'horizontal' ? e.clientX : e.clientY;
|
|
24
|
+
let getNextOffset = (e)=>{
|
|
25
|
+
let containerOffset = (0, $ab71dadb03a6fb2e$export$622cea445a1c5b7d)(containerRef.current, reverse, orientation);
|
|
26
|
+
let mouseOffset = getPosition(e);
|
|
27
|
+
let nextOffset = reverse ? containerOffset - mouseOffset : mouseOffset - containerOffset;
|
|
28
|
+
return nextOffset;
|
|
29
|
+
};
|
|
30
|
+
let dragging = (0, $1rnCS$useRef)(false);
|
|
31
|
+
let prevPosition = (0, $1rnCS$useRef)(0);
|
|
32
|
+
// Keep track of the current handlers in a ref so that the events can access them.
|
|
33
|
+
let handlers = (0, $1rnCS$useRef)({
|
|
34
|
+
onPositionChange: onPositionChange,
|
|
35
|
+
onDrag: onDrag
|
|
36
|
+
});
|
|
37
|
+
handlers.current.onDrag = onDrag;
|
|
38
|
+
handlers.current.onPositionChange = onPositionChange;
|
|
39
|
+
let onMouseDragged = (e)=>{
|
|
40
|
+
e.preventDefault();
|
|
41
|
+
let nextOffset = getNextOffset(e);
|
|
42
|
+
if (!dragging.current) {
|
|
43
|
+
dragging.current = true;
|
|
44
|
+
if (handlers.current.onDrag) handlers.current.onDrag(true);
|
|
45
|
+
if (handlers.current.onPositionChange) handlers.current.onPositionChange(nextOffset);
|
|
46
|
+
}
|
|
47
|
+
if (prevPosition.current === nextOffset) return;
|
|
48
|
+
prevPosition.current = nextOffset;
|
|
49
|
+
if (onPositionChange) onPositionChange(nextOffset);
|
|
50
|
+
};
|
|
51
|
+
let onMouseUp = (e)=>{
|
|
52
|
+
const target = e.target;
|
|
53
|
+
dragging.current = false;
|
|
54
|
+
let nextOffset = getNextOffset(e);
|
|
55
|
+
if (handlers.current.onDrag) handlers.current.onDrag(false);
|
|
56
|
+
if (handlers.current.onPositionChange) handlers.current.onPositionChange(nextOffset);
|
|
57
|
+
$9cc09df9fd7676be$var$draggingElements.splice($9cc09df9fd7676be$var$draggingElements.indexOf(target), 1);
|
|
58
|
+
window.removeEventListener('mouseup', onMouseUp, false);
|
|
59
|
+
window.removeEventListener('mousemove', onMouseDragged, false);
|
|
60
|
+
};
|
|
61
|
+
let onMouseDown = (e)=>{
|
|
62
|
+
const target = e.currentTarget;
|
|
63
|
+
// If we're already handling dragging on a descendant with useDrag1D, then
|
|
64
|
+
// we don't want to handle the drag motion on this target as well.
|
|
65
|
+
if ($9cc09df9fd7676be$var$draggingElements.some((elt)=>target.contains(elt))) return;
|
|
66
|
+
$9cc09df9fd7676be$var$draggingElements.push(target);
|
|
67
|
+
window.addEventListener('mousemove', onMouseDragged, false);
|
|
68
|
+
window.addEventListener('mouseup', onMouseUp, false);
|
|
69
|
+
};
|
|
70
|
+
let onMouseEnter = ()=>{
|
|
71
|
+
if (onHover) onHover(true);
|
|
72
|
+
};
|
|
73
|
+
let onMouseOut = ()=>{
|
|
74
|
+
if (onHover) onHover(false);
|
|
75
|
+
};
|
|
76
|
+
let onKeyDown = (e)=>{
|
|
77
|
+
switch(e.key){
|
|
78
|
+
case 'Left':
|
|
79
|
+
case 'ArrowLeft':
|
|
80
|
+
if (orientation === 'horizontal') {
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
if (onDecrement && !reverse) onDecrement();
|
|
83
|
+
else if (onIncrement && reverse) onIncrement();
|
|
84
|
+
}
|
|
85
|
+
break;
|
|
86
|
+
case 'Up':
|
|
87
|
+
case 'ArrowUp':
|
|
88
|
+
if (orientation === 'vertical') {
|
|
89
|
+
e.preventDefault();
|
|
90
|
+
if (onDecrement && !reverse) onDecrement();
|
|
91
|
+
else if (onIncrement && reverse) onIncrement();
|
|
92
|
+
}
|
|
93
|
+
break;
|
|
94
|
+
case 'Right':
|
|
95
|
+
case 'ArrowRight':
|
|
96
|
+
if (orientation === 'horizontal') {
|
|
97
|
+
e.preventDefault();
|
|
98
|
+
if (onIncrement && !reverse) onIncrement();
|
|
99
|
+
else if (onDecrement && reverse) onDecrement();
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case 'Down':
|
|
103
|
+
case 'ArrowDown':
|
|
104
|
+
if (orientation === 'vertical') {
|
|
105
|
+
e.preventDefault();
|
|
106
|
+
if (onIncrement && !reverse) onIncrement();
|
|
107
|
+
else if (onDecrement && reverse) onDecrement();
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
case 'Home':
|
|
111
|
+
e.preventDefault();
|
|
112
|
+
if (onDecrementToMin) onDecrementToMin();
|
|
113
|
+
break;
|
|
114
|
+
case 'End':
|
|
115
|
+
e.preventDefault();
|
|
116
|
+
if (onIncrementToMax) onIncrementToMax();
|
|
117
|
+
break;
|
|
118
|
+
case 'Enter':
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
if (onCollapseToggle) onCollapseToggle();
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
onMouseDown: onMouseDown,
|
|
126
|
+
onMouseEnter: onMouseEnter,
|
|
127
|
+
onMouseOut: onMouseOut,
|
|
128
|
+
onKeyDown: onKeyDown
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
export {$9cc09df9fd7676be$export$7bbed75feba39706 as useDrag1D};
|
|
134
|
+
//# sourceMappingURL=useDrag1D.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"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","sources":["packages/@react-aria/utils/src/useDrag1D.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n /* eslint-disable rulesdir/pure-render */\n\nimport {getOffset} from './getOffset';\nimport {Orientation} from '@react-types/shared';\nimport React, {HTMLAttributes, MutableRefObject, useRef} from 'react';\n\ninterface UseDrag1DProps {\n containerRef: MutableRefObject<HTMLElement>,\n reverse?: boolean,\n orientation?: Orientation,\n onHover?: (hovered: boolean) => void,\n onDrag?: (dragging: boolean) => void,\n onPositionChange?: (position: number) => void,\n onIncrement?: () => void,\n onDecrement?: () => void,\n onIncrementToMax?: () => void,\n onDecrementToMin?: () => void,\n onCollapseToggle?: () => void\n}\n\n// Keep track of elements that we are currently handling dragging for via useDrag1D.\n// If there's an ancestor and a descendant both using useDrag1D(), and the user starts\n// dragging the descendant, we don't want useDrag1D events to fire for the ancestor.\nconst draggingElements: HTMLElement[] = [];\n\n// created for splitview, this should be reusable for things like sliders/dials\n// It also handles keyboard events on the target allowing for increment/decrement by a given stepsize as well as minifying/maximizing and toggling between minified and previous size\n// It can also take a 'reverse' param to say if we should measure from the right/bottom instead of the top/left\n// It can also handle either a vertical or horizontal movement, but not both at the same time\n\nexport function useDrag1D(props: UseDrag1DProps): HTMLAttributes<HTMLElement> {\n console.warn('useDrag1D is deprecated, please use `useMove` instead https://react-spectrum.adobe.com/react-aria/useMove.html');\n let {containerRef, reverse, orientation, onHover, onDrag, onPositionChange, onIncrement, onDecrement, onIncrementToMax, onDecrementToMin, onCollapseToggle} = props;\n let getPosition = (e) => orientation === 'horizontal' ? e.clientX : e.clientY;\n let getNextOffset = (e: MouseEvent) => {\n let containerOffset = getOffset(containerRef.current, reverse, orientation);\n let mouseOffset = getPosition(e);\n let nextOffset = reverse ? containerOffset - mouseOffset : mouseOffset - containerOffset;\n return nextOffset;\n };\n let dragging = useRef(false);\n let prevPosition = useRef(0);\n\n // Keep track of the current handlers in a ref so that the events can access them.\n let handlers = useRef({onPositionChange, onDrag});\n handlers.current.onDrag = onDrag;\n handlers.current.onPositionChange = onPositionChange;\n\n let onMouseDragged = (e: MouseEvent) => {\n e.preventDefault();\n let nextOffset = getNextOffset(e);\n if (!dragging.current) {\n dragging.current = true;\n if (handlers.current.onDrag) {\n handlers.current.onDrag(true);\n }\n if (handlers.current.onPositionChange) {\n handlers.current.onPositionChange(nextOffset);\n }\n }\n if (prevPosition.current === nextOffset) {\n return;\n }\n prevPosition.current = nextOffset;\n if (onPositionChange) {\n onPositionChange(nextOffset);\n }\n };\n\n let onMouseUp = (e: MouseEvent) => {\n const target = e.target as HTMLElement;\n dragging.current = false;\n let nextOffset = getNextOffset(e);\n if (handlers.current.onDrag) {\n handlers.current.onDrag(false);\n }\n if (handlers.current.onPositionChange) {\n handlers.current.onPositionChange(nextOffset);\n }\n\n draggingElements.splice(draggingElements.indexOf(target), 1);\n window.removeEventListener('mouseup', onMouseUp, false);\n window.removeEventListener('mousemove', onMouseDragged, false);\n };\n\n let onMouseDown = (e: React.MouseEvent<HTMLElement>) => {\n const target = e.currentTarget;\n // If we're already handling dragging on a descendant with useDrag1D, then\n // we don't want to handle the drag motion on this target as well.\n if (draggingElements.some(elt => target.contains(elt))) {\n return;\n }\n draggingElements.push(target);\n window.addEventListener('mousemove', onMouseDragged, false);\n window.addEventListener('mouseup', onMouseUp, false);\n };\n\n let onMouseEnter = () => {\n if (onHover) {\n onHover(true);\n }\n };\n\n let onMouseOut = () => {\n if (onHover) {\n onHover(false);\n }\n };\n\n let onKeyDown = (e) => {\n switch (e.key) {\n case 'Left':\n case 'ArrowLeft':\n if (orientation === 'horizontal') {\n e.preventDefault();\n if (onDecrement && !reverse) {\n onDecrement();\n } else if (onIncrement && reverse) {\n onIncrement();\n }\n }\n break;\n case 'Up':\n case 'ArrowUp':\n if (orientation === 'vertical') {\n e.preventDefault();\n if (onDecrement && !reverse) {\n onDecrement();\n } else if (onIncrement && reverse) {\n onIncrement();\n }\n }\n break;\n case 'Right':\n case 'ArrowRight':\n if (orientation === 'horizontal') {\n e.preventDefault();\n if (onIncrement && !reverse) {\n onIncrement();\n } else if (onDecrement && reverse) {\n onDecrement();\n }\n }\n break;\n case 'Down':\n case 'ArrowDown':\n if (orientation === 'vertical') {\n e.preventDefault();\n if (onIncrement && !reverse) {\n onIncrement();\n } else if (onDecrement && reverse) {\n onDecrement();\n }\n }\n break;\n case 'Home':\n e.preventDefault();\n if (onDecrementToMin) {\n onDecrementToMin();\n }\n break;\n case 'End':\n e.preventDefault();\n if (onIncrementToMax) {\n onIncrementToMax();\n }\n break;\n case 'Enter':\n e.preventDefault();\n if (onCollapseToggle) {\n onCollapseToggle();\n }\n break;\n }\n };\n\n return {onMouseDown, onMouseEnter, onMouseOut, onKeyDown};\n}\n"],"names":[],"version":3,"file":"useDrag1D.module.js.map"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var $78605a5d7424e31b$exports = require("./useLayoutEffect.main.js");
|
|
2
|
+
var $gErir$react = require("react");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "useEffectEvent", () => $1254e5bb94ac8761$export$7f54fc3180508a52);
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2023 Adobe. All rights reserved.
|
|
12
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
* governing permissions and limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
function $1254e5bb94ac8761$export$7f54fc3180508a52(fn) {
|
|
23
|
+
const ref = (0, $gErir$react.useRef)(null);
|
|
24
|
+
(0, $78605a5d7424e31b$exports.useLayoutEffect)(()=>{
|
|
25
|
+
ref.current = fn;
|
|
26
|
+
}, [
|
|
27
|
+
fn
|
|
28
|
+
]);
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
return (0, $gErir$react.useCallback)((...args)=>{
|
|
31
|
+
const f = ref.current;
|
|
32
|
+
return f === null || f === void 0 ? void 0 : f(...args);
|
|
33
|
+
}, []);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=useEffectEvent.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAKM,SAAS,0CAAmC,EAAM;IACvD,MAAM,MAAM,CAAA,GAAA,mBAAK,EAAwB;IACzC,CAAA,GAAA,yCAAc,EAAE;QACd,IAAI,OAAO,GAAG;IAChB,GAAG;QAAC;KAAG;IACP,aAAa;IACb,OAAO,CAAA,GAAA,wBAAU,EAAK,CAAC,GAAG;QACxB,MAAM,IAAI,IAAI,OAAO;QACrB,OAAO,cAAA,wBAAA,KAAO;IAChB,GAAG,EAAE;AACP","sources":["packages/@react-aria/utils/src/useEffectEvent.ts"],"sourcesContent":["/*\n * Copyright 2023 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {useCallback, useRef} from 'react';\nimport {useLayoutEffect} from './useLayoutEffect';\n\nexport function useEffectEvent<T extends Function>(fn?: T): T {\n const ref = useRef<T | null | undefined>(null);\n useLayoutEffect(() => {\n ref.current = fn;\n }, [fn]);\n // @ts-ignore\n return useCallback<T>((...args) => {\n const f = ref.current!;\n return f?.(...args);\n }, []);\n}\n"],"names":[],"version":3,"file":"useEffectEvent.main.js.map"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {useLayoutEffect as $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c} from "./useLayoutEffect.mjs";
|
|
2
|
+
import {useRef as $lmaYr$useRef, useCallback as $lmaYr$useCallback} from "react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2023 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
function $8ae05eaa5c114e9c$export$7f54fc3180508a52(fn) {
|
|
17
|
+
const ref = (0, $lmaYr$useRef)(null);
|
|
18
|
+
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
19
|
+
ref.current = fn;
|
|
20
|
+
}, [
|
|
21
|
+
fn
|
|
22
|
+
]);
|
|
23
|
+
// @ts-ignore
|
|
24
|
+
return (0, $lmaYr$useCallback)((...args)=>{
|
|
25
|
+
const f = ref.current;
|
|
26
|
+
return f === null || f === void 0 ? void 0 : f(...args);
|
|
27
|
+
}, []);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
export {$8ae05eaa5c114e9c$export$7f54fc3180508a52 as useEffectEvent};
|
|
32
|
+
//# sourceMappingURL=useEffectEvent.module.js.map
|