@react-aria/utils 3.32.0 → 3.33.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/DOMFunctions.main.js +16 -3
- package/dist/DOMFunctions.main.js.map +1 -1
- package/dist/DOMFunctions.mjs +17 -5
- package/dist/DOMFunctions.module.js +17 -5
- package/dist/DOMFunctions.module.js.map +1 -1
- package/dist/domHelpers.main.js.map +1 -1
- package/dist/domHelpers.module.js.map +1 -1
- package/dist/getScrollParents.main.js +6 -5
- package/dist/getScrollParents.main.js.map +1 -1
- package/dist/getScrollParents.mjs +6 -5
- package/dist/getScrollParents.module.js +6 -5
- package/dist/getScrollParents.module.js.map +1 -1
- package/dist/import.mjs +2 -2
- package/dist/isScrollable.main.js +3 -0
- package/dist/isScrollable.main.js.map +1 -1
- package/dist/isScrollable.mjs +3 -0
- package/dist/isScrollable.module.js +3 -0
- package/dist/isScrollable.module.js.map +1 -1
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -1
- package/dist/mergeProps.main.js +3 -0
- package/dist/mergeProps.main.js.map +1 -1
- package/dist/mergeProps.mjs +3 -0
- package/dist/mergeProps.module.js +3 -0
- package/dist/mergeProps.module.js.map +1 -1
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/dist/runAfterTransition.main.js +13 -8
- package/dist/runAfterTransition.main.js.map +1 -1
- package/dist/runAfterTransition.mjs +13 -8
- package/dist/runAfterTransition.module.js +13 -8
- package/dist/runAfterTransition.module.js.map +1 -1
- package/dist/scrollIntoView.main.js +87 -52
- package/dist/scrollIntoView.main.js.map +1 -1
- package/dist/scrollIntoView.mjs +87 -52
- package/dist/scrollIntoView.module.js +87 -52
- package/dist/scrollIntoView.module.js.map +1 -1
- package/dist/types.d.ts +23 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/useDrag1D.main.js +4 -2
- package/dist/useDrag1D.main.js.map +1 -1
- package/dist/useDrag1D.mjs +4 -2
- package/dist/useDrag1D.module.js +4 -2
- package/dist/useDrag1D.module.js.map +1 -1
- package/dist/useViewportSize.main.js +21 -17
- package/dist/useViewportSize.main.js.map +1 -1
- package/dist/useViewportSize.mjs +21 -17
- package/dist/useViewportSize.module.js +21 -17
- package/dist/useViewportSize.module.js.map +1 -1
- package/package.json +3 -3
- package/src/domHelpers.ts +2 -2
- package/src/getScrollParents.ts +6 -5
- package/src/index.ts +1 -1
- package/src/isScrollable.ts +6 -0
- package/src/mergeProps.ts +4 -1
- package/src/runAfterTransition.ts +11 -8
- package/src/scrollIntoView.ts +110 -70
- package/src/shadowdom/DOMFunctions.ts +38 -8
- package/src/useDrag1D.ts +3 -2
- package/src/useViewportSize.ts +26 -20
package/dist/useDrag1D.main.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var $d723bea02f3e2567$exports = require("./DOMFunctions.main.js");
|
|
1
2
|
var $16ec41ef3e36c19c$exports = require("./getOffset.main.js");
|
|
2
3
|
var $hK8r3$react = require("react");
|
|
3
4
|
|
|
@@ -19,6 +20,7 @@ $parcel$export(module.exports, "useDrag1D", () => $28ed3fb20343b78b$export$7bbed
|
|
|
19
20
|
* governing permissions and limitations under the License.
|
|
20
21
|
*/ /* eslint-disable rulesdir/pure-render */
|
|
21
22
|
|
|
23
|
+
|
|
22
24
|
// Keep track of elements that we are currently handling dragging for via useDrag1D.
|
|
23
25
|
// If there's an ancestor and a descendant both using useDrag1D(), and the user starts
|
|
24
26
|
// dragging the descendant, we don't want useDrag1D events to fire for the ancestor.
|
|
@@ -55,7 +57,7 @@ function $28ed3fb20343b78b$export$7bbed75feba39706(props) {
|
|
|
55
57
|
if (onPositionChange) onPositionChange(nextOffset);
|
|
56
58
|
};
|
|
57
59
|
let onMouseUp = (e)=>{
|
|
58
|
-
|
|
60
|
+
let target = (0, $d723bea02f3e2567$exports.getEventTarget)(e);
|
|
59
61
|
dragging.current = false;
|
|
60
62
|
let nextOffset = getNextOffset(e);
|
|
61
63
|
if (handlers.current.onDrag) handlers.current.onDrag(false);
|
|
@@ -68,7 +70,7 @@ function $28ed3fb20343b78b$export$7bbed75feba39706(props) {
|
|
|
68
70
|
const target = e.currentTarget;
|
|
69
71
|
// If we're already handling dragging on a descendant with useDrag1D, then
|
|
70
72
|
// we don't want to handle the drag motion on this target as well.
|
|
71
|
-
if ($28ed3fb20343b78b$var$draggingElements.some((elt)=>
|
|
73
|
+
if ($28ed3fb20343b78b$var$draggingElements.some((elt)=>(0, $d723bea02f3e2567$exports.nodeContains)(target, elt))) return;
|
|
72
74
|
$28ed3fb20343b78b$var$draggingElements.push(target);
|
|
73
75
|
window.addEventListener('mousemove', onMouseDragged, false);
|
|
74
76
|
window.addEventListener('mouseup', onMouseUp, false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
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 {getEventTarget, nodeContains} from './shadowdom/DOMFunctions';\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 let target = getEventTarget(e) 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 => nodeContains(target, 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"}
|
package/dist/useDrag1D.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {getEventTarget as $d4ee10de306f2510$export$e58f029f0fbfdb29, nodeContains as $d4ee10de306f2510$export$4282f70798064fe0} from "./DOMFunctions.mjs";
|
|
1
2
|
import {getOffset as $ab71dadb03a6fb2e$export$622cea445a1c5b7d} from "./getOffset.mjs";
|
|
2
3
|
import {useRef as $1rnCS$useRef} from "react";
|
|
3
4
|
|
|
@@ -13,6 +14,7 @@ import {useRef as $1rnCS$useRef} from "react";
|
|
|
13
14
|
* governing permissions and limitations under the License.
|
|
14
15
|
*/ /* eslint-disable rulesdir/pure-render */
|
|
15
16
|
|
|
17
|
+
|
|
16
18
|
// Keep track of elements that we are currently handling dragging for via useDrag1D.
|
|
17
19
|
// If there's an ancestor and a descendant both using useDrag1D(), and the user starts
|
|
18
20
|
// dragging the descendant, we don't want useDrag1D events to fire for the ancestor.
|
|
@@ -49,7 +51,7 @@ function $9cc09df9fd7676be$export$7bbed75feba39706(props) {
|
|
|
49
51
|
if (onPositionChange) onPositionChange(nextOffset);
|
|
50
52
|
};
|
|
51
53
|
let onMouseUp = (e)=>{
|
|
52
|
-
|
|
54
|
+
let target = (0, $d4ee10de306f2510$export$e58f029f0fbfdb29)(e);
|
|
53
55
|
dragging.current = false;
|
|
54
56
|
let nextOffset = getNextOffset(e);
|
|
55
57
|
if (handlers.current.onDrag) handlers.current.onDrag(false);
|
|
@@ -62,7 +64,7 @@ function $9cc09df9fd7676be$export$7bbed75feba39706(props) {
|
|
|
62
64
|
const target = e.currentTarget;
|
|
63
65
|
// If we're already handling dragging on a descendant with useDrag1D, then
|
|
64
66
|
// we don't want to handle the drag motion on this target as well.
|
|
65
|
-
if ($9cc09df9fd7676be$var$draggingElements.some((elt)=>target
|
|
67
|
+
if ($9cc09df9fd7676be$var$draggingElements.some((elt)=>(0, $d4ee10de306f2510$export$4282f70798064fe0)(target, elt))) return;
|
|
66
68
|
$9cc09df9fd7676be$var$draggingElements.push(target);
|
|
67
69
|
window.addEventListener('mousemove', onMouseDragged, false);
|
|
68
70
|
window.addEventListener('mouseup', onMouseUp, false);
|
package/dist/useDrag1D.module.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {getEventTarget as $d4ee10de306f2510$export$e58f029f0fbfdb29, nodeContains as $d4ee10de306f2510$export$4282f70798064fe0} from "./DOMFunctions.module.js";
|
|
1
2
|
import {getOffset as $ab71dadb03a6fb2e$export$622cea445a1c5b7d} from "./getOffset.module.js";
|
|
2
3
|
import {useRef as $1rnCS$useRef} from "react";
|
|
3
4
|
|
|
@@ -13,6 +14,7 @@ import {useRef as $1rnCS$useRef} from "react";
|
|
|
13
14
|
* governing permissions and limitations under the License.
|
|
14
15
|
*/ /* eslint-disable rulesdir/pure-render */
|
|
15
16
|
|
|
17
|
+
|
|
16
18
|
// Keep track of elements that we are currently handling dragging for via useDrag1D.
|
|
17
19
|
// If there's an ancestor and a descendant both using useDrag1D(), and the user starts
|
|
18
20
|
// dragging the descendant, we don't want useDrag1D events to fire for the ancestor.
|
|
@@ -49,7 +51,7 @@ function $9cc09df9fd7676be$export$7bbed75feba39706(props) {
|
|
|
49
51
|
if (onPositionChange) onPositionChange(nextOffset);
|
|
50
52
|
};
|
|
51
53
|
let onMouseUp = (e)=>{
|
|
52
|
-
|
|
54
|
+
let target = (0, $d4ee10de306f2510$export$e58f029f0fbfdb29)(e);
|
|
53
55
|
dragging.current = false;
|
|
54
56
|
let nextOffset = getNextOffset(e);
|
|
55
57
|
if (handlers.current.onDrag) handlers.current.onDrag(false);
|
|
@@ -62,7 +64,7 @@ function $9cc09df9fd7676be$export$7bbed75feba39706(props) {
|
|
|
62
64
|
const target = e.currentTarget;
|
|
63
65
|
// If we're already handling dragging on a descendant with useDrag1D, then
|
|
64
66
|
// we don't want to handle the drag motion on this target as well.
|
|
65
|
-
if ($9cc09df9fd7676be$var$draggingElements.some((elt)=>target
|
|
67
|
+
if ($9cc09df9fd7676be$var$draggingElements.some((elt)=>(0, $d4ee10de306f2510$export$4282f70798064fe0)(target, elt))) return;
|
|
66
68
|
$9cc09df9fd7676be$var$draggingElements.push(target);
|
|
67
69
|
window.addEventListener('mousemove', onMouseDragged, false);
|
|
68
70
|
window.addEventListener('mouseup', onMouseUp, false);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
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 {getEventTarget, nodeContains} from './shadowdom/DOMFunctions';\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 let target = getEventTarget(e) 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 => nodeContains(target, 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"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
var $d723bea02f3e2567$exports = require("./DOMFunctions.main.js");
|
|
2
|
+
var $9e20cff0af27e8cc$exports = require("./platform.main.js");
|
|
1
3
|
var $2308dc377e184bb0$exports = require("./keyboard.main.js");
|
|
2
4
|
var $4gIVO$react = require("react");
|
|
3
5
|
var $4gIVO$reactariassr = require("@react-aria/ssr");
|
|
@@ -21,6 +23,8 @@ $parcel$export(module.exports, "useViewportSize", () => $8b24bab62f5c65ad$export
|
|
|
21
23
|
*/
|
|
22
24
|
|
|
23
25
|
|
|
26
|
+
|
|
27
|
+
|
|
24
28
|
let $8b24bab62f5c65ad$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
25
29
|
function $8b24bab62f5c65ad$export$d699905dd57c73ca() {
|
|
26
30
|
let isSSR = (0, $4gIVO$reactariassr.useIsSSR)();
|
|
@@ -29,39 +33,39 @@ function $8b24bab62f5c65ad$export$d699905dd57c73ca() {
|
|
|
29
33
|
height: 0
|
|
30
34
|
} : $8b24bab62f5c65ad$var$getViewportSize());
|
|
31
35
|
(0, $4gIVO$react.useEffect)(()=>{
|
|
32
|
-
|
|
33
|
-
let onResize = ()=>{
|
|
34
|
-
// Ignore updates when zoomed.
|
|
35
|
-
if ($8b24bab62f5c65ad$var$visualViewport && $8b24bab62f5c65ad$var$visualViewport.scale > 1) return;
|
|
36
|
+
let updateSize = (newSize)=>{
|
|
36
37
|
setSize((size)=>{
|
|
37
|
-
let newSize = $8b24bab62f5c65ad$var$getViewportSize();
|
|
38
38
|
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
39
39
|
return newSize;
|
|
40
40
|
});
|
|
41
41
|
};
|
|
42
|
+
// Use visualViewport api to track available height even on iOS virtual keyboard opening
|
|
43
|
+
let onResize = ()=>{
|
|
44
|
+
// Ignore updates when zoomed.
|
|
45
|
+
if ($8b24bab62f5c65ad$var$visualViewport && $8b24bab62f5c65ad$var$visualViewport.scale > 1) return;
|
|
46
|
+
updateSize($8b24bab62f5c65ad$var$getViewportSize());
|
|
47
|
+
};
|
|
42
48
|
// When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
|
|
43
49
|
// We can anticipate this and resize early by handling the blur event and using the layout size.
|
|
44
50
|
let frame;
|
|
45
51
|
let onBlur = (e)=>{
|
|
46
52
|
if ($8b24bab62f5c65ad$var$visualViewport && $8b24bab62f5c65ad$var$visualViewport.scale > 1) return;
|
|
47
|
-
if ((0, $2308dc377e184bb0$exports.willOpenKeyboard)(
|
|
53
|
+
if ((0, $2308dc377e184bb0$exports.willOpenKeyboard)((0, $d723bea02f3e2567$exports.getEventTarget)(e))) // Wait one frame to see if a new element gets focused.
|
|
48
54
|
frame = requestAnimationFrame(()=>{
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
};
|
|
54
|
-
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
55
|
-
return newSize;
|
|
55
|
+
let activeElement = (0, $d723bea02f3e2567$exports.getActiveElement)();
|
|
56
|
+
if (!activeElement || !(0, $2308dc377e184bb0$exports.willOpenKeyboard)(activeElement)) updateSize({
|
|
57
|
+
width: document.documentElement.clientWidth,
|
|
58
|
+
height: document.documentElement.clientHeight
|
|
56
59
|
});
|
|
57
60
|
});
|
|
58
61
|
};
|
|
59
|
-
|
|
62
|
+
updateSize($8b24bab62f5c65ad$var$getViewportSize());
|
|
63
|
+
if ((0, $9e20cff0af27e8cc$exports.isIOS)()) window.addEventListener('blur', onBlur, true);
|
|
60
64
|
if (!$8b24bab62f5c65ad$var$visualViewport) window.addEventListener('resize', onResize);
|
|
61
65
|
else $8b24bab62f5c65ad$var$visualViewport.addEventListener('resize', onResize);
|
|
62
66
|
return ()=>{
|
|
63
67
|
cancelAnimationFrame(frame);
|
|
64
|
-
window.removeEventListener('blur', onBlur, true);
|
|
68
|
+
if ((0, $9e20cff0af27e8cc$exports.isIOS)()) window.removeEventListener('blur', onBlur, true);
|
|
65
69
|
if (!$8b24bab62f5c65ad$var$visualViewport) window.removeEventListener('resize', onResize);
|
|
66
70
|
else $8b24bab62f5c65ad$var$visualViewport.removeEventListener('resize', onResize);
|
|
67
71
|
};
|
|
@@ -71,8 +75,8 @@ function $8b24bab62f5c65ad$export$d699905dd57c73ca() {
|
|
|
71
75
|
function $8b24bab62f5c65ad$var$getViewportSize() {
|
|
72
76
|
return {
|
|
73
77
|
// Multiply by the visualViewport scale to get the "natural" size, unaffected by pinch zooming.
|
|
74
|
-
width: $8b24bab62f5c65ad$var$visualViewport ? $8b24bab62f5c65ad$var$visualViewport.width * $8b24bab62f5c65ad$var$visualViewport.scale :
|
|
75
|
-
height: $8b24bab62f5c65ad$var$visualViewport ? $8b24bab62f5c65ad$var$visualViewport.height * $8b24bab62f5c65ad$var$visualViewport.scale :
|
|
78
|
+
width: $8b24bab62f5c65ad$var$visualViewport ? $8b24bab62f5c65ad$var$visualViewport.width * $8b24bab62f5c65ad$var$visualViewport.scale : document.documentElement.clientWidth,
|
|
79
|
+
height: $8b24bab62f5c65ad$var$visualViewport ? $8b24bab62f5c65ad$var$visualViewport.height * $8b24bab62f5c65ad$var$visualViewport.scale : document.documentElement.clientHeight
|
|
76
80
|
};
|
|
77
81
|
}
|
|
78
82
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAaD,IAAI,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAEtE,SAAS;IACd,IAAI,QAAQ,CAAA,GAAA,4BAAO;IACnB,IAAI,CAAC,MAAM,QAAQ,GAAG,CAAA,GAAA,qBAAO,EAAE,IAAM,QAAQ;YAAC,OAAO;YAAG,QAAQ;QAAC,IAAI;IAErE,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,aAAa,CAAC;YAChB,QAAQ,CAAA;gBACN,IAAI,QAAQ,KAAK,KAAK,KAAK,KAAK,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,EAChE,OAAO;gBAET,OAAO;YACT;QACF;QAEA,wFAAwF;QACxF,IAAI,WAAW;YACb,8BAA8B;YAC9B,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,WAAW;QACb;QAEA,iHAAiH;QACjH,gGAAgG;QAChG,IAAI;QACJ,IAAI,SAAS,CAAC;YACZ,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,IAAI,CAAA,GAAA,0CAAe,EAAE,CAAA,GAAA,wCAAa,EAAE,KAClC,uDAAuD;YACvD,QAAQ,sBAAsB;gBAC5B,IAAI,gBAAgB,CAAA,GAAA,0CAAe;gBACnC,IAAI,CAAC,iBAAiB,CAAC,CAAA,GAAA,0CAAe,EAAE,gBACtC,WAAW;oBAAC,OAAO,SAAS,eAAe,CAAC,WAAW;oBAAE,QAAQ,SAAS,eAAe,CAAC,YAAY;gBAAA;YAE1G;QAEJ;QAEA,WAAW;QAEX,IAAI,CAAA,GAAA,+BAAI,KACN,OAAO,gBAAgB,CAAC,QAAQ,QAAQ;QAG1C,IAAI,CAAC,sCACH,OAAO,gBAAgB,CAAC,UAAU;aAElC,qCAAe,gBAAgB,CAAC,UAAU;QAG5C,OAAO;YACL,qBAAqB;YACrB,IAAI,CAAA,GAAA,+BAAI,KACN,OAAO,mBAAmB,CAAC,QAAQ,QAAQ;YAE7C,IAAI,CAAC,sCACH,OAAO,mBAAmB,CAAC,UAAU;iBAErC,qCAAe,mBAAmB,CAAC,UAAU;QAEjD;IACF,GAAG,EAAE;IAEL,OAAO;AACT;AAEA,SAAS;IACP,OAAO;QACL,+FAA+F;QAC/F,OAAO,uCAAiB,qCAAe,KAAK,GAAG,qCAAe,KAAK,GAAG,SAAS,eAAe,CAAC,WAAW;QAC1G,QAAQ,uCAAiB,qCAAe,MAAM,GAAG,qCAAe,KAAK,GAAG,SAAS,eAAe,CAAC,YAAY;IAC/G;AACF","sources":["packages/@react-aria/utils/src/useViewportSize.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 {getActiveElement, getEventTarget} from './shadowdom/DOMFunctions';\nimport {isIOS} from './platform';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\nimport {willOpenKeyboard} from './keyboard';\n\ninterface ViewportSize {\n width: number,\n height: number\n}\n\nlet visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\nexport function useViewportSize(): ViewportSize {\n let isSSR = useIsSSR();\n let [size, setSize] = useState(() => isSSR ? {width: 0, height: 0} : getViewportSize());\n\n useEffect(() => {\n let updateSize = (newSize: ViewportSize) => {\n setSize(size => {\n if (newSize.width === size.width && newSize.height === size.height) {\n return size;\n }\n return newSize;\n });\n };\n\n // Use visualViewport api to track available height even on iOS virtual keyboard opening\n let onResize = () => {\n // Ignore updates when zoomed.\n if (visualViewport && visualViewport.scale > 1) {\n return;\n }\n\n updateSize(getViewportSize());\n };\n\n // When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.\n // We can anticipate this and resize early by handling the blur event and using the layout size.\n let frame: number;\n let onBlur = (e: FocusEvent) => {\n if (visualViewport && visualViewport.scale > 1) {\n return;\n }\n\n if (willOpenKeyboard(getEventTarget(e) as Element)) {\n // Wait one frame to see if a new element gets focused.\n frame = requestAnimationFrame(() => {\n let activeElement = getActiveElement();\n if (!activeElement || !willOpenKeyboard(activeElement)) {\n updateSize({width: document.documentElement.clientWidth, height: document.documentElement.clientHeight});\n }\n });\n }\n };\n\n updateSize(getViewportSize());\n\n if (isIOS()) {\n window.addEventListener('blur', onBlur, true);\n }\n\n if (!visualViewport) {\n window.addEventListener('resize', onResize);\n } else {\n visualViewport.addEventListener('resize', onResize);\n }\n\n return () => {\n cancelAnimationFrame(frame);\n if (isIOS()) {\n window.removeEventListener('blur', onBlur, true);\n }\n if (!visualViewport) {\n window.removeEventListener('resize', onResize);\n } else {\n visualViewport.removeEventListener('resize', onResize);\n }\n };\n }, []);\n\n return size;\n}\n\nfunction getViewportSize(): ViewportSize {\n return {\n // Multiply by the visualViewport scale to get the \"natural\" size, unaffected by pinch zooming.\n width: visualViewport ? visualViewport.width * visualViewport.scale : document.documentElement.clientWidth,\n height: visualViewport ? visualViewport.height * visualViewport.scale : document.documentElement.clientHeight\n };\n}\n"],"names":[],"version":3,"file":"useViewportSize.main.js.map"}
|
package/dist/useViewportSize.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {getActiveElement as $d4ee10de306f2510$export$cd4e5573fbe2b576, getEventTarget as $d4ee10de306f2510$export$e58f029f0fbfdb29} from "./DOMFunctions.mjs";
|
|
2
|
+
import {isIOS as $c87311424ea30a05$export$fedb369cb70207f1} from "./platform.mjs";
|
|
1
3
|
import {willOpenKeyboard as $21f1aa98acb08317$export$c57958e35f31ed73} from "./keyboard.mjs";
|
|
2
4
|
import {useState as $fuDHA$useState, useEffect as $fuDHA$useEffect} from "react";
|
|
3
5
|
import {useIsSSR as $fuDHA$useIsSSR} from "@react-aria/ssr";
|
|
@@ -15,6 +17,8 @@ import {useIsSSR as $fuDHA$useIsSSR} from "@react-aria/ssr";
|
|
|
15
17
|
*/
|
|
16
18
|
|
|
17
19
|
|
|
20
|
+
|
|
21
|
+
|
|
18
22
|
let $5df64b3807dc15ee$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
19
23
|
function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
20
24
|
let isSSR = (0, $fuDHA$useIsSSR)();
|
|
@@ -23,39 +27,39 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
|
23
27
|
height: 0
|
|
24
28
|
} : $5df64b3807dc15ee$var$getViewportSize());
|
|
25
29
|
(0, $fuDHA$useEffect)(()=>{
|
|
26
|
-
|
|
27
|
-
let onResize = ()=>{
|
|
28
|
-
// Ignore updates when zoomed.
|
|
29
|
-
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
30
|
+
let updateSize = (newSize)=>{
|
|
30
31
|
setSize((size)=>{
|
|
31
|
-
let newSize = $5df64b3807dc15ee$var$getViewportSize();
|
|
32
32
|
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
33
33
|
return newSize;
|
|
34
34
|
});
|
|
35
35
|
};
|
|
36
|
+
// Use visualViewport api to track available height even on iOS virtual keyboard opening
|
|
37
|
+
let onResize = ()=>{
|
|
38
|
+
// Ignore updates when zoomed.
|
|
39
|
+
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
40
|
+
updateSize($5df64b3807dc15ee$var$getViewportSize());
|
|
41
|
+
};
|
|
36
42
|
// When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
|
|
37
43
|
// We can anticipate this and resize early by handling the blur event and using the layout size.
|
|
38
44
|
let frame;
|
|
39
45
|
let onBlur = (e)=>{
|
|
40
46
|
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
41
|
-
if ((0, $21f1aa98acb08317$export$c57958e35f31ed73)(e
|
|
47
|
+
if ((0, $21f1aa98acb08317$export$c57958e35f31ed73)((0, $d4ee10de306f2510$export$e58f029f0fbfdb29)(e))) // Wait one frame to see if a new element gets focused.
|
|
42
48
|
frame = requestAnimationFrame(()=>{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
49
|
-
return newSize;
|
|
49
|
+
let activeElement = (0, $d4ee10de306f2510$export$cd4e5573fbe2b576)();
|
|
50
|
+
if (!activeElement || !(0, $21f1aa98acb08317$export$c57958e35f31ed73)(activeElement)) updateSize({
|
|
51
|
+
width: document.documentElement.clientWidth,
|
|
52
|
+
height: document.documentElement.clientHeight
|
|
50
53
|
});
|
|
51
54
|
});
|
|
52
55
|
};
|
|
53
|
-
|
|
56
|
+
updateSize($5df64b3807dc15ee$var$getViewportSize());
|
|
57
|
+
if ((0, $c87311424ea30a05$export$fedb369cb70207f1)()) window.addEventListener('blur', onBlur, true);
|
|
54
58
|
if (!$5df64b3807dc15ee$var$visualViewport) window.addEventListener('resize', onResize);
|
|
55
59
|
else $5df64b3807dc15ee$var$visualViewport.addEventListener('resize', onResize);
|
|
56
60
|
return ()=>{
|
|
57
61
|
cancelAnimationFrame(frame);
|
|
58
|
-
window.removeEventListener('blur', onBlur, true);
|
|
62
|
+
if ((0, $c87311424ea30a05$export$fedb369cb70207f1)()) window.removeEventListener('blur', onBlur, true);
|
|
59
63
|
if (!$5df64b3807dc15ee$var$visualViewport) window.removeEventListener('resize', onResize);
|
|
60
64
|
else $5df64b3807dc15ee$var$visualViewport.removeEventListener('resize', onResize);
|
|
61
65
|
};
|
|
@@ -65,8 +69,8 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
|
65
69
|
function $5df64b3807dc15ee$var$getViewportSize() {
|
|
66
70
|
return {
|
|
67
71
|
// Multiply by the visualViewport scale to get the "natural" size, unaffected by pinch zooming.
|
|
68
|
-
width: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.width * $5df64b3807dc15ee$var$visualViewport.scale :
|
|
69
|
-
height: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.height * $5df64b3807dc15ee$var$visualViewport.scale :
|
|
72
|
+
width: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.width * $5df64b3807dc15ee$var$visualViewport.scale : document.documentElement.clientWidth,
|
|
73
|
+
height: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.height * $5df64b3807dc15ee$var$visualViewport.scale : document.documentElement.clientHeight
|
|
70
74
|
};
|
|
71
75
|
}
|
|
72
76
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {getActiveElement as $d4ee10de306f2510$export$cd4e5573fbe2b576, getEventTarget as $d4ee10de306f2510$export$e58f029f0fbfdb29} from "./DOMFunctions.module.js";
|
|
2
|
+
import {isIOS as $c87311424ea30a05$export$fedb369cb70207f1} from "./platform.module.js";
|
|
1
3
|
import {willOpenKeyboard as $21f1aa98acb08317$export$c57958e35f31ed73} from "./keyboard.module.js";
|
|
2
4
|
import {useState as $fuDHA$useState, useEffect as $fuDHA$useEffect} from "react";
|
|
3
5
|
import {useIsSSR as $fuDHA$useIsSSR} from "@react-aria/ssr";
|
|
@@ -15,6 +17,8 @@ import {useIsSSR as $fuDHA$useIsSSR} from "@react-aria/ssr";
|
|
|
15
17
|
*/
|
|
16
18
|
|
|
17
19
|
|
|
20
|
+
|
|
21
|
+
|
|
18
22
|
let $5df64b3807dc15ee$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
19
23
|
function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
20
24
|
let isSSR = (0, $fuDHA$useIsSSR)();
|
|
@@ -23,39 +27,39 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
|
23
27
|
height: 0
|
|
24
28
|
} : $5df64b3807dc15ee$var$getViewportSize());
|
|
25
29
|
(0, $fuDHA$useEffect)(()=>{
|
|
26
|
-
|
|
27
|
-
let onResize = ()=>{
|
|
28
|
-
// Ignore updates when zoomed.
|
|
29
|
-
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
30
|
+
let updateSize = (newSize)=>{
|
|
30
31
|
setSize((size)=>{
|
|
31
|
-
let newSize = $5df64b3807dc15ee$var$getViewportSize();
|
|
32
32
|
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
33
33
|
return newSize;
|
|
34
34
|
});
|
|
35
35
|
};
|
|
36
|
+
// Use visualViewport api to track available height even on iOS virtual keyboard opening
|
|
37
|
+
let onResize = ()=>{
|
|
38
|
+
// Ignore updates when zoomed.
|
|
39
|
+
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
40
|
+
updateSize($5df64b3807dc15ee$var$getViewportSize());
|
|
41
|
+
};
|
|
36
42
|
// When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
|
|
37
43
|
// We can anticipate this and resize early by handling the blur event and using the layout size.
|
|
38
44
|
let frame;
|
|
39
45
|
let onBlur = (e)=>{
|
|
40
46
|
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
41
|
-
if ((0, $21f1aa98acb08317$export$c57958e35f31ed73)(e
|
|
47
|
+
if ((0, $21f1aa98acb08317$export$c57958e35f31ed73)((0, $d4ee10de306f2510$export$e58f029f0fbfdb29)(e))) // Wait one frame to see if a new element gets focused.
|
|
42
48
|
frame = requestAnimationFrame(()=>{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
};
|
|
48
|
-
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
49
|
-
return newSize;
|
|
49
|
+
let activeElement = (0, $d4ee10de306f2510$export$cd4e5573fbe2b576)();
|
|
50
|
+
if (!activeElement || !(0, $21f1aa98acb08317$export$c57958e35f31ed73)(activeElement)) updateSize({
|
|
51
|
+
width: document.documentElement.clientWidth,
|
|
52
|
+
height: document.documentElement.clientHeight
|
|
50
53
|
});
|
|
51
54
|
});
|
|
52
55
|
};
|
|
53
|
-
|
|
56
|
+
updateSize($5df64b3807dc15ee$var$getViewportSize());
|
|
57
|
+
if ((0, $c87311424ea30a05$export$fedb369cb70207f1)()) window.addEventListener('blur', onBlur, true);
|
|
54
58
|
if (!$5df64b3807dc15ee$var$visualViewport) window.addEventListener('resize', onResize);
|
|
55
59
|
else $5df64b3807dc15ee$var$visualViewport.addEventListener('resize', onResize);
|
|
56
60
|
return ()=>{
|
|
57
61
|
cancelAnimationFrame(frame);
|
|
58
|
-
window.removeEventListener('blur', onBlur, true);
|
|
62
|
+
if ((0, $c87311424ea30a05$export$fedb369cb70207f1)()) window.removeEventListener('blur', onBlur, true);
|
|
59
63
|
if (!$5df64b3807dc15ee$var$visualViewport) window.removeEventListener('resize', onResize);
|
|
60
64
|
else $5df64b3807dc15ee$var$visualViewport.removeEventListener('resize', onResize);
|
|
61
65
|
};
|
|
@@ -65,8 +69,8 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
|
65
69
|
function $5df64b3807dc15ee$var$getViewportSize() {
|
|
66
70
|
return {
|
|
67
71
|
// Multiply by the visualViewport scale to get the "natural" size, unaffected by pinch zooming.
|
|
68
|
-
width: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.width * $5df64b3807dc15ee$var$visualViewport.scale :
|
|
69
|
-
height: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.height * $5df64b3807dc15ee$var$visualViewport.scale :
|
|
72
|
+
width: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.width * $5df64b3807dc15ee$var$visualViewport.scale : document.documentElement.clientWidth,
|
|
73
|
+
height: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.height * $5df64b3807dc15ee$var$visualViewport.scale : document.documentElement.clientHeight
|
|
70
74
|
};
|
|
71
75
|
}
|
|
72
76
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAaD,IAAI,uCAAiB,OAAO,aAAa,eAAe,OAAO,cAAc;AAEtE,SAAS;IACd,IAAI,QAAQ,CAAA,GAAA,eAAO;IACnB,IAAI,CAAC,MAAM,QAAQ,GAAG,CAAA,GAAA,eAAO,EAAE,IAAM,QAAQ;YAAC,OAAO;YAAG,QAAQ;QAAC,IAAI;IAErE,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,aAAa,CAAC;YAChB,QAAQ,CAAA;gBACN,IAAI,QAAQ,KAAK,KAAK,KAAK,KAAK,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,EAChE,OAAO;gBAET,OAAO;YACT;QACF;QAEA,wFAAwF;QACxF,IAAI,WAAW;YACb,8BAA8B;YAC9B,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,WAAW;QACb;QAEA,iHAAiH;QACjH,gGAAgG;QAChG,IAAI;QACJ,IAAI,SAAS,CAAC;YACZ,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,IAAI,CAAA,GAAA,yCAAe,EAAE,CAAA,GAAA,yCAAa,EAAE,KAClC,uDAAuD;YACvD,QAAQ,sBAAsB;gBAC5B,IAAI,gBAAgB,CAAA,GAAA,yCAAe;gBACnC,IAAI,CAAC,iBAAiB,CAAC,CAAA,GAAA,yCAAe,EAAE,gBACtC,WAAW;oBAAC,OAAO,SAAS,eAAe,CAAC,WAAW;oBAAE,QAAQ,SAAS,eAAe,CAAC,YAAY;gBAAA;YAE1G;QAEJ;QAEA,WAAW;QAEX,IAAI,CAAA,GAAA,yCAAI,KACN,OAAO,gBAAgB,CAAC,QAAQ,QAAQ;QAG1C,IAAI,CAAC,sCACH,OAAO,gBAAgB,CAAC,UAAU;aAElC,qCAAe,gBAAgB,CAAC,UAAU;QAG5C,OAAO;YACL,qBAAqB;YACrB,IAAI,CAAA,GAAA,yCAAI,KACN,OAAO,mBAAmB,CAAC,QAAQ,QAAQ;YAE7C,IAAI,CAAC,sCACH,OAAO,mBAAmB,CAAC,UAAU;iBAErC,qCAAe,mBAAmB,CAAC,UAAU;QAEjD;IACF,GAAG,EAAE;IAEL,OAAO;AACT;AAEA,SAAS;IACP,OAAO;QACL,+FAA+F;QAC/F,OAAO,uCAAiB,qCAAe,KAAK,GAAG,qCAAe,KAAK,GAAG,SAAS,eAAe,CAAC,WAAW;QAC1G,QAAQ,uCAAiB,qCAAe,MAAM,GAAG,qCAAe,KAAK,GAAG,SAAS,eAAe,CAAC,YAAY;IAC/G;AACF","sources":["packages/@react-aria/utils/src/useViewportSize.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 {getActiveElement, getEventTarget} from './shadowdom/DOMFunctions';\nimport {isIOS} from './platform';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\nimport {willOpenKeyboard} from './keyboard';\n\ninterface ViewportSize {\n width: number,\n height: number\n}\n\nlet visualViewport = typeof document !== 'undefined' && window.visualViewport;\n\nexport function useViewportSize(): ViewportSize {\n let isSSR = useIsSSR();\n let [size, setSize] = useState(() => isSSR ? {width: 0, height: 0} : getViewportSize());\n\n useEffect(() => {\n let updateSize = (newSize: ViewportSize) => {\n setSize(size => {\n if (newSize.width === size.width && newSize.height === size.height) {\n return size;\n }\n return newSize;\n });\n };\n\n // Use visualViewport api to track available height even on iOS virtual keyboard opening\n let onResize = () => {\n // Ignore updates when zoomed.\n if (visualViewport && visualViewport.scale > 1) {\n return;\n }\n\n updateSize(getViewportSize());\n };\n\n // When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.\n // We can anticipate this and resize early by handling the blur event and using the layout size.\n let frame: number;\n let onBlur = (e: FocusEvent) => {\n if (visualViewport && visualViewport.scale > 1) {\n return;\n }\n\n if (willOpenKeyboard(getEventTarget(e) as Element)) {\n // Wait one frame to see if a new element gets focused.\n frame = requestAnimationFrame(() => {\n let activeElement = getActiveElement();\n if (!activeElement || !willOpenKeyboard(activeElement)) {\n updateSize({width: document.documentElement.clientWidth, height: document.documentElement.clientHeight});\n }\n });\n }\n };\n\n updateSize(getViewportSize());\n\n if (isIOS()) {\n window.addEventListener('blur', onBlur, true);\n }\n\n if (!visualViewport) {\n window.addEventListener('resize', onResize);\n } else {\n visualViewport.addEventListener('resize', onResize);\n }\n\n return () => {\n cancelAnimationFrame(frame);\n if (isIOS()) {\n window.removeEventListener('blur', onBlur, true);\n }\n if (!visualViewport) {\n window.removeEventListener('resize', onResize);\n } else {\n visualViewport.removeEventListener('resize', onResize);\n }\n };\n }, []);\n\n return size;\n}\n\nfunction getViewportSize(): ViewportSize {\n return {\n // Multiply by the visualViewport scale to get the \"natural\" size, unaffected by pinch zooming.\n width: visualViewport ? visualViewport.width * visualViewport.scale : document.documentElement.clientWidth,\n height: visualViewport ? visualViewport.height * visualViewport.scale : document.documentElement.clientHeight\n };\n}\n"],"names":[],"version":3,"file":"useViewportSize.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/utils",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.33.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@react-aria/ssr": "^3.9.10",
|
|
30
30
|
"@react-stately/flags": "^3.1.2",
|
|
31
31
|
"@react-stately/utils": "^3.11.0",
|
|
32
|
-
"@react-types/shared": "^3.
|
|
32
|
+
"@react-types/shared": "^3.33.1",
|
|
33
33
|
"@swc/helpers": "^0.5.0",
|
|
34
34
|
"clsx": "^2.0.0"
|
|
35
35
|
},
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "8df187370053aa35f553cb388ad670f65e1ab371"
|
|
44
44
|
}
|
package/src/domHelpers.ts
CHANGED
|
@@ -3,8 +3,8 @@ export const getOwnerDocument = (el: Element | null | undefined): Document => {
|
|
|
3
3
|
};
|
|
4
4
|
|
|
5
5
|
export const getOwnerWindow = (
|
|
6
|
-
el: (Window & typeof
|
|
7
|
-
): Window & typeof
|
|
6
|
+
el: (Window & typeof globalThis) | Element | null | undefined
|
|
7
|
+
): Window & typeof globalThis => {
|
|
8
8
|
if (el && 'window' in el && el.window === el) {
|
|
9
9
|
return el;
|
|
10
10
|
}
|
package/src/getScrollParents.ts
CHANGED
|
@@ -13,14 +13,15 @@
|
|
|
13
13
|
import {isScrollable} from './isScrollable';
|
|
14
14
|
|
|
15
15
|
export function getScrollParents(node: Element, checkForOverflow?: boolean): Element[] {
|
|
16
|
-
|
|
16
|
+
let parentElements: Element[] = [];
|
|
17
|
+
let root = document.scrollingElement || document.documentElement;
|
|
17
18
|
|
|
18
|
-
|
|
19
|
+
do {
|
|
19
20
|
if (isScrollable(node, checkForOverflow)) {
|
|
20
|
-
|
|
21
|
+
parentElements.push(node);
|
|
21
22
|
}
|
|
22
23
|
node = node.parentElement as Element;
|
|
23
|
-
}
|
|
24
|
+
} while (node && node !== root);
|
|
24
25
|
|
|
25
|
-
return
|
|
26
|
+
return parentElements;
|
|
26
27
|
}
|
package/src/index.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
export {useId, mergeIds, useSlotId} from './useId';
|
|
13
13
|
export {chain} from './chain';
|
|
14
14
|
export {createShadowTreeWalker, ShadowTreeWalker} from './shadowdom/ShadowTreeWalker';
|
|
15
|
-
export {getActiveElement, getEventTarget, nodeContains} from './shadowdom/DOMFunctions';
|
|
15
|
+
export {getActiveElement, getEventTarget, nodeContains, isFocusWithin} from './shadowdom/DOMFunctions';
|
|
16
16
|
export {getOwnerDocument, getOwnerWindow, isShadowRoot} from './domHelpers';
|
|
17
17
|
export {mergeProps} from './mergeProps';
|
|
18
18
|
export {mergeRefs} from './mergeRefs';
|
package/src/isScrollable.ts
CHANGED
|
@@ -15,8 +15,14 @@ export function isScrollable(node: Element | null, checkForOverflow?: boolean):
|
|
|
15
15
|
return false;
|
|
16
16
|
}
|
|
17
17
|
let style = window.getComputedStyle(node);
|
|
18
|
+
let root = document.scrollingElement || document.documentElement;
|
|
18
19
|
let isScrollable = /(auto|scroll)/.test(style.overflow + style.overflowX + style.overflowY);
|
|
19
20
|
|
|
21
|
+
// Root element has `visible` overflow by default, but is scrollable nonetheless.
|
|
22
|
+
if (node === root && style.overflow !== 'hidden') {
|
|
23
|
+
isScrollable = true;
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
if (isScrollable && checkForOverflow) {
|
|
21
27
|
isScrollable = node.scrollHeight !== node.clientHeight || node.scrollWidth !== node.clientWidth;
|
|
22
28
|
}
|
package/src/mergeProps.ts
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
import {chain} from './chain';
|
|
14
14
|
import clsx from 'clsx';
|
|
15
15
|
import {mergeIds} from './useId';
|
|
16
|
+
import {mergeRefs} from './mergeRefs';
|
|
16
17
|
|
|
17
18
|
interface Props {
|
|
18
19
|
[key: string]: any
|
|
@@ -28,7 +29,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Merges multiple props objects together. Event handlers are chained,
|
|
31
|
-
* classNames are combined, and
|
|
32
|
+
* classNames are combined, ids are deduplicated, and refs are merged.
|
|
32
33
|
* For all other props, the last prop object overrides all previous ones.
|
|
33
34
|
* @param args - Multiple sets of props to merge together.
|
|
34
35
|
*/
|
|
@@ -63,6 +64,8 @@ export function mergeProps<T extends PropsArg[]>(...args: T): UnionToIntersectio
|
|
|
63
64
|
result[key] = clsx(a, b);
|
|
64
65
|
} else if (key === 'id' && a && b) {
|
|
65
66
|
result.id = mergeIds(a, b);
|
|
67
|
+
} else if (key === 'ref' && a && b) {
|
|
68
|
+
result.ref = mergeRefs(a, b);
|
|
66
69
|
// Override others
|
|
67
70
|
} else {
|
|
68
71
|
result[key] = b !== undefined ? b : a;
|