@react-aria/utils 3.30.1 → 3.32.0
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/filterDOMProps.main.js +1 -1
- package/dist/filterDOMProps.main.js.map +1 -1
- package/dist/filterDOMProps.mjs +1 -1
- package/dist/filterDOMProps.module.js +1 -1
- package/dist/filterDOMProps.module.js.map +1 -1
- package/dist/import.mjs +2 -2
- package/dist/isElementVisible.main.js +3 -1
- package/dist/isElementVisible.main.js.map +1 -1
- package/dist/isElementVisible.mjs +3 -1
- package/dist/isElementVisible.module.js +3 -1
- package/dist/isElementVisible.module.js.map +1 -1
- package/dist/keyboard.main.js +16 -0
- package/dist/keyboard.main.js.map +1 -1
- package/dist/keyboard.mjs +16 -1
- package/dist/keyboard.module.js +16 -1
- package/dist/keyboard.module.js.map +1 -1
- package/dist/main.js +1 -0
- package/dist/main.js.map +1 -1
- package/dist/mergeProps.main.js.map +1 -1
- package/dist/mergeProps.module.js.map +1 -1
- package/dist/module.js +2 -2
- package/dist/module.js.map +1 -1
- package/dist/openLink.main.js +1 -0
- package/dist/openLink.main.js.map +1 -1
- package/dist/openLink.mjs +1 -0
- package/dist/openLink.module.js +1 -0
- package/dist/openLink.module.js.map +1 -1
- package/dist/scrollIntoView.main.js +1 -0
- package/dist/scrollIntoView.main.js.map +1 -1
- package/dist/scrollIntoView.mjs +1 -0
- package/dist/scrollIntoView.module.js +1 -0
- package/dist/scrollIntoView.module.js.map +1 -1
- package/dist/types.d.ts +10 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/useEvent.main.js +1 -2
- package/dist/useEvent.main.js.map +1 -1
- package/dist/useEvent.mjs +1 -2
- package/dist/useEvent.module.js +1 -2
- package/dist/useEvent.module.js.map +1 -1
- package/dist/useFormReset.main.js +1 -2
- package/dist/useFormReset.main.js.map +1 -1
- package/dist/useFormReset.mjs +1 -2
- package/dist/useFormReset.module.js +1 -2
- package/dist/useFormReset.module.js.map +1 -1
- package/dist/useLoadMoreSentinel.main.js +0 -1
- package/dist/useLoadMoreSentinel.main.js.map +1 -1
- package/dist/useLoadMoreSentinel.mjs +0 -1
- package/dist/useLoadMoreSentinel.module.js +0 -1
- package/dist/useLoadMoreSentinel.module.js.map +1 -1
- package/dist/useResizeObserver.main.js +8 -4
- package/dist/useResizeObserver.main.js.map +1 -1
- package/dist/useResizeObserver.mjs +8 -4
- package/dist/useResizeObserver.module.js +8 -4
- package/dist/useResizeObserver.module.js.map +1 -1
- package/dist/useUpdateEffect.main.js +5 -2
- package/dist/useUpdateEffect.main.js.map +1 -1
- package/dist/useUpdateEffect.mjs +5 -2
- package/dist/useUpdateEffect.module.js +5 -2
- package/dist/useUpdateEffect.module.js.map +1 -1
- package/dist/useValueEffect.main.js +13 -8
- package/dist/useValueEffect.main.js.map +1 -1
- package/dist/useValueEffect.mjs +14 -9
- package/dist/useValueEffect.module.js +14 -9
- package/dist/useValueEffect.module.js.map +1 -1
- package/dist/useViewportSize.main.js +27 -2
- package/dist/useViewportSize.main.js.map +1 -1
- package/dist/useViewportSize.mjs +27 -2
- package/dist/useViewportSize.module.js +27 -2
- package/dist/useViewportSize.module.js.map +1 -1
- package/package.json +4 -4
- package/src/filterDOMProps.ts +1 -1
- package/src/index.ts +1 -1
- package/src/isElementVisible.ts +1 -1
- package/src/keyboard.tsx +21 -0
- package/src/mergeProps.ts +1 -2
- package/src/openLink.tsx +1 -1
- package/src/scrollIntoView.ts +3 -0
- package/src/useEvent.ts +1 -1
- package/src/useFormReset.ts +1 -1
- package/src/useLoadMoreSentinel.ts +1 -1
- package/src/useResizeObserver.ts +8 -4
- package/src/useUpdateEffect.ts +5 -3
- package/src/useValueEffect.ts +15 -11
- package/src/useViewportSize.ts +37 -2
|
@@ -1,23 +1,28 @@
|
|
|
1
|
+
import {useEffectEvent as $8ae05eaa5c114e9c$export$7f54fc3180508a52} from "./useEffectEvent.mjs";
|
|
1
2
|
import {useEffect as $Vsl8o$useEffect} from "react";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
|
|
4
6
|
function $9daab02d461809db$var$hasResizeObserver() {
|
|
5
7
|
return typeof window.ResizeObserver !== 'undefined';
|
|
6
8
|
}
|
|
7
9
|
function $9daab02d461809db$export$683480f191c0e3ea(options) {
|
|
10
|
+
// Only call onResize from inside the effect, otherwise we'll void our assumption that
|
|
11
|
+
// useEffectEvents are safe to pass in.
|
|
8
12
|
const { ref: ref, box: box, onResize: onResize } = options;
|
|
13
|
+
let onResizeEvent = (0, $8ae05eaa5c114e9c$export$7f54fc3180508a52)(onResize);
|
|
9
14
|
(0, $Vsl8o$useEffect)(()=>{
|
|
10
15
|
let element = ref === null || ref === void 0 ? void 0 : ref.current;
|
|
11
16
|
if (!element) return;
|
|
12
17
|
if (!$9daab02d461809db$var$hasResizeObserver()) {
|
|
13
|
-
window.addEventListener('resize',
|
|
18
|
+
window.addEventListener('resize', onResizeEvent, false);
|
|
14
19
|
return ()=>{
|
|
15
|
-
window.removeEventListener('resize',
|
|
20
|
+
window.removeEventListener('resize', onResizeEvent, false);
|
|
16
21
|
};
|
|
17
22
|
} else {
|
|
18
23
|
const resizeObserverInstance = new window.ResizeObserver((entries)=>{
|
|
19
24
|
if (!entries.length) return;
|
|
20
|
-
|
|
25
|
+
onResizeEvent();
|
|
21
26
|
});
|
|
22
27
|
resizeObserverInstance.observe(element, {
|
|
23
28
|
box: box
|
|
@@ -27,7 +32,6 @@ function $9daab02d461809db$export$683480f191c0e3ea(options) {
|
|
|
27
32
|
};
|
|
28
33
|
}
|
|
29
34
|
}, [
|
|
30
|
-
onResize,
|
|
31
35
|
ref,
|
|
32
36
|
box
|
|
33
37
|
]);
|
|
@@ -1,23 +1,28 @@
|
|
|
1
|
+
import {useEffectEvent as $8ae05eaa5c114e9c$export$7f54fc3180508a52} from "./useEffectEvent.module.js";
|
|
1
2
|
import {useEffect as $Vsl8o$useEffect} from "react";
|
|
2
3
|
|
|
3
4
|
|
|
5
|
+
|
|
4
6
|
function $9daab02d461809db$var$hasResizeObserver() {
|
|
5
7
|
return typeof window.ResizeObserver !== 'undefined';
|
|
6
8
|
}
|
|
7
9
|
function $9daab02d461809db$export$683480f191c0e3ea(options) {
|
|
10
|
+
// Only call onResize from inside the effect, otherwise we'll void our assumption that
|
|
11
|
+
// useEffectEvents are safe to pass in.
|
|
8
12
|
const { ref: ref, box: box, onResize: onResize } = options;
|
|
13
|
+
let onResizeEvent = (0, $8ae05eaa5c114e9c$export$7f54fc3180508a52)(onResize);
|
|
9
14
|
(0, $Vsl8o$useEffect)(()=>{
|
|
10
15
|
let element = ref === null || ref === void 0 ? void 0 : ref.current;
|
|
11
16
|
if (!element) return;
|
|
12
17
|
if (!$9daab02d461809db$var$hasResizeObserver()) {
|
|
13
|
-
window.addEventListener('resize',
|
|
18
|
+
window.addEventListener('resize', onResizeEvent, false);
|
|
14
19
|
return ()=>{
|
|
15
|
-
window.removeEventListener('resize',
|
|
20
|
+
window.removeEventListener('resize', onResizeEvent, false);
|
|
16
21
|
};
|
|
17
22
|
} else {
|
|
18
23
|
const resizeObserverInstance = new window.ResizeObserver((entries)=>{
|
|
19
24
|
if (!entries.length) return;
|
|
20
|
-
|
|
25
|
+
onResizeEvent();
|
|
21
26
|
});
|
|
22
27
|
resizeObserverInstance.observe(element, {
|
|
23
28
|
box: box
|
|
@@ -27,7 +32,6 @@ function $9daab02d461809db$export$683480f191c0e3ea(options) {
|
|
|
27
32
|
};
|
|
28
33
|
}
|
|
29
34
|
}, [
|
|
30
|
-
onResize,
|
|
31
35
|
ref,
|
|
32
36
|
box
|
|
33
37
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;AAKA,SAAS;IACP,OAAO,OAAO,OAAO,cAAc,KAAK;AAC1C;AAQO,SAAS,0CAAqC,OAAwC;IAC3F,sFAAsF;IACtF,uCAAuC;IACvC,MAAM,OAAC,GAAG,OAAE,GAAG,YAAE,QAAQ,EAAC,GAAG;IAC7B,IAAI,gBAAgB,CAAA,GAAA,yCAAa,EAAE;IAEnC,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,UAAU,gBAAA,0BAAA,IAAK,OAAO;QAC1B,IAAI,CAAC,SACH;QAGF,IAAI,CAAC,2CAAqB;YACxB,OAAO,gBAAgB,CAAC,UAAU,eAAe;YACjD,OAAO;gBACL,OAAO,mBAAmB,CAAC,UAAU,eAAe;YACtD;QACF,OAAO;YAEL,MAAM,yBAAyB,IAAI,OAAO,cAAc,CAAC,CAAC;gBACxD,IAAI,CAAC,QAAQ,MAAM,EACjB;gBAGF;YACF;YACA,uBAAuB,OAAO,CAAC,SAAS;qBAAC;YAAG;YAE5C,OAAO;gBACL,IAAI,SACF,uBAAuB,SAAS,CAAC;YAErC;QACF;IAEF,GAAG;QAAC;QAAK;KAAI;AACf","sources":["packages/@react-aria/utils/src/useResizeObserver.ts"],"sourcesContent":["\nimport {RefObject} from '@react-types/shared';\nimport {useEffect} from 'react';\nimport {useEffectEvent} from './useEffectEvent';\n\nfunction hasResizeObserver() {\n return typeof window.ResizeObserver !== 'undefined';\n}\n\ntype useResizeObserverOptionsType<T> = {\n ref: RefObject<T | undefined | null> | undefined,\n box?: ResizeObserverBoxOptions,\n onResize: () => void\n}\n\nexport function useResizeObserver<T extends Element>(options: useResizeObserverOptionsType<T>): void {\n // Only call onResize from inside the effect, otherwise we'll void our assumption that\n // useEffectEvents are safe to pass in.\n const {ref, box, onResize} = options;\n let onResizeEvent = useEffectEvent(onResize);\n\n useEffect(() => {\n let element = ref?.current;\n if (!element) {\n return;\n }\n\n if (!hasResizeObserver()) {\n window.addEventListener('resize', onResizeEvent, false);\n return () => {\n window.removeEventListener('resize', onResizeEvent, false);\n };\n } else {\n\n const resizeObserverInstance = new window.ResizeObserver((entries) => {\n if (!entries.length) {\n return;\n }\n\n onResizeEvent();\n });\n resizeObserverInstance.observe(element, {box});\n\n return () => {\n if (element) {\n resizeObserverInstance.unobserve(element);\n }\n };\n }\n\n }, [ref, box]);\n}\n"],"names":[],"version":3,"file":"useResizeObserver.module.js.map"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var $1254e5bb94ac8761$exports = require("./useEffectEvent.main.js");
|
|
1
2
|
var $cagC1$react = require("react");
|
|
2
3
|
|
|
3
4
|
|
|
@@ -17,9 +18,11 @@ $parcel$export(module.exports, "useUpdateEffect", () => $29293a6f5c75b37e$export
|
|
|
17
18
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
18
19
|
* governing permissions and limitations under the License.
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
|
|
22
|
+
function $29293a6f5c75b37e$export$496315a1608d9602(cb, dependencies) {
|
|
21
23
|
const isInitialMount = (0, $cagC1$react.useRef)(true);
|
|
22
24
|
const lastDeps = (0, $cagC1$react.useRef)(null);
|
|
25
|
+
let cbEvent = (0, $1254e5bb94ac8761$exports.useEffectEvent)(cb);
|
|
23
26
|
(0, $cagC1$react.useEffect)(()=>{
|
|
24
27
|
isInitialMount.current = true;
|
|
25
28
|
return ()=>{
|
|
@@ -29,7 +32,7 @@ function $29293a6f5c75b37e$export$496315a1608d9602(effect, dependencies) {
|
|
|
29
32
|
(0, $cagC1$react.useEffect)(()=>{
|
|
30
33
|
let prevDeps = lastDeps.current;
|
|
31
34
|
if (isInitialMount.current) isInitialMount.current = false;
|
|
32
|
-
else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i])))
|
|
35
|
+
else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i]))) cbEvent();
|
|
33
36
|
lastDeps.current = dependencies;
|
|
34
37
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
35
38
|
}, dependencies);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAMM,SAAS,0CAAgB,EAAkB,EAAE,YAAmB;IACrE,MAAM,iBAAiB,CAAA,GAAA,mBAAK,EAAE;IAC9B,MAAM,WAAW,CAAA,GAAA,mBAAK,EAAgB;IACtC,IAAI,UAAU,CAAA,GAAA,wCAAa,EAAE;IAE7B,CAAA,GAAA,sBAAQ,EAAE;QACR,eAAe,OAAO,GAAG;QACzB,OAAO;YACL,eAAe,OAAO,GAAG;QAC3B;IACF,GAAG,EAAE;IAEL,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,WAAW,SAAS,OAAO;QAC/B,IAAI,eAAe,OAAO,EACxB,eAAe,OAAO,GAAG;aACpB,IAAI,CAAC,YAAY,aAAa,IAAI,CAAC,CAAC,KAAK,IAAM,CAAC,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,EAAE,IAC/E;QAEF,SAAS,OAAO,GAAG;IACrB,uDAAuD;IACvD,GAAG;AACL","sources":["packages/@react-aria/utils/src/useUpdateEffect.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 {EffectCallback, useEffect, useRef} from 'react';\nimport {useEffectEvent} from './useEffectEvent';\n\n// Like useEffect, but only called for updates after the initial render.\nexport function useUpdateEffect(cb: EffectCallback, dependencies: any[]): void {\n const isInitialMount = useRef(true);\n const lastDeps = useRef<any[] | null>(null);\n let cbEvent = useEffectEvent(cb);\n\n useEffect(() => {\n isInitialMount.current = true;\n return () => {\n isInitialMount.current = false;\n };\n }, []);\n\n useEffect(() => {\n let prevDeps = lastDeps.current;\n if (isInitialMount.current) {\n isInitialMount.current = false;\n } else if (!prevDeps || dependencies.some((dep, i) => !Object.is(dep, prevDeps[i]))) {\n cbEvent();\n }\n lastDeps.current = dependencies;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, dependencies);\n}\n"],"names":[],"version":3,"file":"useUpdateEffect.main.js.map"}
|
package/dist/useUpdateEffect.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {useEffectEvent as $8ae05eaa5c114e9c$export$7f54fc3180508a52} from "./useEffectEvent.mjs";
|
|
1
2
|
import {useRef as $9vW05$useRef, useEffect as $9vW05$useEffect} from "react";
|
|
2
3
|
|
|
3
4
|
/*
|
|
@@ -11,9 +12,11 @@ import {useRef as $9vW05$useRef, useEffect as $9vW05$useEffect} from "react";
|
|
|
11
12
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
13
|
* governing permissions and limitations under the License.
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
function $4f58c5f72bcf79f7$export$496315a1608d9602(cb, dependencies) {
|
|
15
17
|
const isInitialMount = (0, $9vW05$useRef)(true);
|
|
16
18
|
const lastDeps = (0, $9vW05$useRef)(null);
|
|
19
|
+
let cbEvent = (0, $8ae05eaa5c114e9c$export$7f54fc3180508a52)(cb);
|
|
17
20
|
(0, $9vW05$useEffect)(()=>{
|
|
18
21
|
isInitialMount.current = true;
|
|
19
22
|
return ()=>{
|
|
@@ -23,7 +26,7 @@ function $4f58c5f72bcf79f7$export$496315a1608d9602(effect, dependencies) {
|
|
|
23
26
|
(0, $9vW05$useEffect)(()=>{
|
|
24
27
|
let prevDeps = lastDeps.current;
|
|
25
28
|
if (isInitialMount.current) isInitialMount.current = false;
|
|
26
|
-
else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i])))
|
|
29
|
+
else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i]))) cbEvent();
|
|
27
30
|
lastDeps.current = dependencies;
|
|
28
31
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
32
|
}, dependencies);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {useEffectEvent as $8ae05eaa5c114e9c$export$7f54fc3180508a52} from "./useEffectEvent.module.js";
|
|
1
2
|
import {useRef as $9vW05$useRef, useEffect as $9vW05$useEffect} from "react";
|
|
2
3
|
|
|
3
4
|
/*
|
|
@@ -11,9 +12,11 @@ import {useRef as $9vW05$useRef, useEffect as $9vW05$useEffect} from "react";
|
|
|
11
12
|
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
12
13
|
* governing permissions and limitations under the License.
|
|
13
14
|
*/
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
function $4f58c5f72bcf79f7$export$496315a1608d9602(cb, dependencies) {
|
|
15
17
|
const isInitialMount = (0, $9vW05$useRef)(true);
|
|
16
18
|
const lastDeps = (0, $9vW05$useRef)(null);
|
|
19
|
+
let cbEvent = (0, $8ae05eaa5c114e9c$export$7f54fc3180508a52)(cb);
|
|
17
20
|
(0, $9vW05$useEffect)(()=>{
|
|
18
21
|
isInitialMount.current = true;
|
|
19
22
|
return ()=>{
|
|
@@ -23,7 +26,7 @@ function $4f58c5f72bcf79f7$export$496315a1608d9602(effect, dependencies) {
|
|
|
23
26
|
(0, $9vW05$useEffect)(()=>{
|
|
24
27
|
let prevDeps = lastDeps.current;
|
|
25
28
|
if (isInitialMount.current) isInitialMount.current = false;
|
|
26
|
-
else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i])))
|
|
29
|
+
else if (!prevDeps || dependencies.some((dep, i)=>!Object.is(dep, prevDeps[i]))) cbEvent();
|
|
27
30
|
lastDeps.current = dependencies;
|
|
28
31
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
32
|
}, dependencies);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAMM,SAAS,0CAAgB,EAAkB,EAAE,YAAmB;IACrE,MAAM,iBAAiB,CAAA,GAAA,aAAK,EAAE;IAC9B,MAAM,WAAW,CAAA,GAAA,aAAK,EAAgB;IACtC,IAAI,UAAU,CAAA,GAAA,yCAAa,EAAE;IAE7B,CAAA,GAAA,gBAAQ,EAAE;QACR,eAAe,OAAO,GAAG;QACzB,OAAO;YACL,eAAe,OAAO,GAAG;QAC3B;IACF,GAAG,EAAE;IAEL,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,WAAW,SAAS,OAAO;QAC/B,IAAI,eAAe,OAAO,EACxB,eAAe,OAAO,GAAG;aACpB,IAAI,CAAC,YAAY,aAAa,IAAI,CAAC,CAAC,KAAK,IAAM,CAAC,OAAO,EAAE,CAAC,KAAK,QAAQ,CAAC,EAAE,IAC/E;QAEF,SAAS,OAAO,GAAG;IACrB,uDAAuD;IACvD,GAAG;AACL","sources":["packages/@react-aria/utils/src/useUpdateEffect.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 {EffectCallback, useEffect, useRef} from 'react';\nimport {useEffectEvent} from './useEffectEvent';\n\n// Like useEffect, but only called for updates after the initial render.\nexport function useUpdateEffect(cb: EffectCallback, dependencies: any[]): void {\n const isInitialMount = useRef(true);\n const lastDeps = useRef<any[] | null>(null);\n let cbEvent = useEffectEvent(cb);\n\n useEffect(() => {\n isInitialMount.current = true;\n return () => {\n isInitialMount.current = false;\n };\n }, []);\n\n useEffect(() => {\n let prevDeps = lastDeps.current;\n if (isInitialMount.current) {\n isInitialMount.current = false;\n } else if (!prevDeps || dependencies.some((dep, i) => !Object.is(dep, prevDeps[i]))) {\n cbEvent();\n }\n lastDeps.current = dependencies;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, dependencies);\n}\n"],"names":[],"version":3,"file":"useUpdateEffect.module.js.map"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
var $1254e5bb94ac8761$exports = require("./useEffectEvent.main.js");
|
|
2
1
|
var $78605a5d7424e31b$exports = require("./useLayoutEffect.main.js");
|
|
3
2
|
var $fymK9$react = require("react");
|
|
4
3
|
|
|
@@ -22,10 +21,13 @@ $parcel$export(module.exports, "useValueEffect", () => $19a2307bfabafaf1$export$
|
|
|
22
21
|
|
|
23
22
|
function $19a2307bfabafaf1$export$14d238f342723f25(defaultValue) {
|
|
24
23
|
let [value, setValue] = (0, $fymK9$react.useState)(defaultValue);
|
|
24
|
+
// Keep an up to date copy of value in a ref so we can access the current value in the generator.
|
|
25
|
+
// This allows us to maintain a stable queue function.
|
|
26
|
+
let currValue = (0, $fymK9$react.useRef)(value);
|
|
25
27
|
let effect = (0, $fymK9$react.useRef)(null);
|
|
26
28
|
// Store the function in a ref so we can always access the current version
|
|
27
29
|
// which has the proper `value` in scope.
|
|
28
|
-
let nextRef = (0, $
|
|
30
|
+
let nextRef = (0, $fymK9$react.useRef)(()=>{
|
|
29
31
|
if (!effect.current) return;
|
|
30
32
|
// Run the generator to the next yield.
|
|
31
33
|
let newValue = effect.current.next();
|
|
@@ -37,17 +39,20 @@ function $19a2307bfabafaf1$export$14d238f342723f25(defaultValue) {
|
|
|
37
39
|
// If the value is the same as the current value,
|
|
38
40
|
// then continue to the next yield. Otherwise,
|
|
39
41
|
// set the value in state and wait for the next layout effect.
|
|
40
|
-
if (
|
|
42
|
+
if (currValue.current === newValue.value) nextRef.current();
|
|
41
43
|
else setValue(newValue.value);
|
|
42
44
|
});
|
|
43
45
|
(0, $78605a5d7424e31b$exports.useLayoutEffect)(()=>{
|
|
46
|
+
currValue.current = value;
|
|
44
47
|
// If there is an effect currently running, continue to the next yield.
|
|
45
|
-
if (effect.current) nextRef();
|
|
46
|
-
});
|
|
47
|
-
let queue = (0, $1254e5bb94ac8761$exports.useEffectEvent)((fn)=>{
|
|
48
|
-
effect.current = fn(value);
|
|
49
|
-
nextRef();
|
|
48
|
+
if (effect.current) nextRef.current();
|
|
50
49
|
});
|
|
50
|
+
let queue = (0, $fymK9$react.useCallback)((fn)=>{
|
|
51
|
+
effect.current = fn(currValue.current);
|
|
52
|
+
nextRef.current();
|
|
53
|
+
}, [
|
|
54
|
+
nextRef
|
|
55
|
+
]);
|
|
51
56
|
return [
|
|
52
57
|
value,
|
|
53
58
|
queue
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;AAWM,SAAS,0CAAkB,YAA2B;IAC3D,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,qBAAO,EAAE;IACjC,iGAAiG;IACjG,sDAAsD;IACtD,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE;IACvB,IAAI,SAAyC,CAAA,GAAA,mBAAK,EAAuB;IAEzE,0EAA0E;IAC1E,yCAAyC;IACzC,IAAI,UAAU,CAAA,GAAA,mBAAK,EAAE;QACnB,IAAI,CAAC,OAAO,OAAO,EACjB;QAEF,uCAAuC;QACvC,IAAI,WAAW,OAAO,OAAO,CAAC,IAAI;QAElC,8CAA8C;QAC9C,IAAI,SAAS,IAAI,EAAE;YACjB,OAAO,OAAO,GAAG;YACjB;QACF;QAEA,iDAAiD;QACjD,8CAA8C;QAC9C,8DAA8D;QAC9D,IAAI,UAAU,OAAO,KAAK,SAAS,KAAK,EACtC,QAAQ,OAAO;aAEf,SAAS,SAAS,KAAK;IAE3B;IAEA,CAAA,GAAA,yCAAc,EAAE;QACd,UAAU,OAAO,GAAG;QACpB,uEAAuE;QACvE,IAAI,OAAO,OAAO,EAChB,QAAQ,OAAO;IAEnB;IAEA,IAAI,QAAQ,CAAA,GAAA,wBAAU,EAAE,CAAA;QACtB,OAAO,OAAO,GAAG,GAAG,UAAU,OAAO;QACrC,QAAQ,OAAO;IACjB,GAAG;QAAC;KAAQ;IAEZ,OAAO;QAAC;QAAO;KAAM;AACvB","sources":["packages/@react-aria/utils/src/useValueEffect.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 {Dispatch, RefObject, useCallback, useRef, useState} from 'react';\nimport {useLayoutEffect} from './';\n\ntype SetValueAction<S> = (prev: S) => Generator<any, void, unknown>;\n\n// This hook works like `useState`, but when setting the value, you pass a generator function\n// that can yield multiple values. Each yielded value updates the state and waits for the next\n// layout effect, then continues the generator. This allows sequential updates to state to be\n// written linearly.\nexport function useValueEffect<S>(defaultValue: S | (() => S)): [S, Dispatch<SetValueAction<S>>] {\n let [value, setValue] = useState(defaultValue);\n // Keep an up to date copy of value in a ref so we can access the current value in the generator.\n // This allows us to maintain a stable queue function.\n let currValue = useRef(value);\n let effect: RefObject<Generator<S> | null> = useRef<Generator<S> | null>(null);\n\n // Store the function in a ref so we can always access the current version\n // which has the proper `value` in scope.\n let nextRef = useRef(() => {\n if (!effect.current) {\n return;\n }\n // Run the generator to the next yield.\n let newValue = effect.current.next();\n\n // If the generator is done, reset the effect.\n if (newValue.done) {\n effect.current = null;\n return;\n }\n\n // If the value is the same as the current value,\n // then continue to the next yield. Otherwise,\n // set the value in state and wait for the next layout effect.\n if (currValue.current === newValue.value) {\n nextRef.current();\n } else {\n setValue(newValue.value);\n }\n });\n\n useLayoutEffect(() => {\n currValue.current = value;\n // If there is an effect currently running, continue to the next yield.\n if (effect.current) {\n nextRef.current();\n }\n });\n\n let queue = useCallback(fn => {\n effect.current = fn(currValue.current);\n nextRef.current();\n }, [nextRef]);\n\n return [value, queue];\n}\n"],"names":[],"version":3,"file":"useValueEffect.main.js.map"}
|
package/dist/useValueEffect.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {useEffectEvent as $8ae05eaa5c114e9c$export$7f54fc3180508a52} from "./useEffectEvent.mjs";
|
|
2
1
|
import {useLayoutEffect as $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c} from "./useLayoutEffect.mjs";
|
|
3
|
-
import {useState as $fCAlL$useState, useRef as $fCAlL$useRef} from "react";
|
|
2
|
+
import {useState as $fCAlL$useState, useRef as $fCAlL$useRef, useCallback as $fCAlL$useCallback} from "react";
|
|
4
3
|
|
|
5
4
|
/*
|
|
6
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -16,10 +15,13 @@ import {useState as $fCAlL$useState, useRef as $fCAlL$useRef} from "react";
|
|
|
16
15
|
|
|
17
16
|
function $1dbecbe27a04f9af$export$14d238f342723f25(defaultValue) {
|
|
18
17
|
let [value, setValue] = (0, $fCAlL$useState)(defaultValue);
|
|
18
|
+
// Keep an up to date copy of value in a ref so we can access the current value in the generator.
|
|
19
|
+
// This allows us to maintain a stable queue function.
|
|
20
|
+
let currValue = (0, $fCAlL$useRef)(value);
|
|
19
21
|
let effect = (0, $fCAlL$useRef)(null);
|
|
20
22
|
// Store the function in a ref so we can always access the current version
|
|
21
23
|
// which has the proper `value` in scope.
|
|
22
|
-
let nextRef = (0, $
|
|
24
|
+
let nextRef = (0, $fCAlL$useRef)(()=>{
|
|
23
25
|
if (!effect.current) return;
|
|
24
26
|
// Run the generator to the next yield.
|
|
25
27
|
let newValue = effect.current.next();
|
|
@@ -31,17 +33,20 @@ function $1dbecbe27a04f9af$export$14d238f342723f25(defaultValue) {
|
|
|
31
33
|
// If the value is the same as the current value,
|
|
32
34
|
// then continue to the next yield. Otherwise,
|
|
33
35
|
// set the value in state and wait for the next layout effect.
|
|
34
|
-
if (
|
|
36
|
+
if (currValue.current === newValue.value) nextRef.current();
|
|
35
37
|
else setValue(newValue.value);
|
|
36
38
|
});
|
|
37
39
|
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
40
|
+
currValue.current = value;
|
|
38
41
|
// If there is an effect currently running, continue to the next yield.
|
|
39
|
-
if (effect.current) nextRef();
|
|
40
|
-
});
|
|
41
|
-
let queue = (0, $8ae05eaa5c114e9c$export$7f54fc3180508a52)((fn)=>{
|
|
42
|
-
effect.current = fn(value);
|
|
43
|
-
nextRef();
|
|
42
|
+
if (effect.current) nextRef.current();
|
|
44
43
|
});
|
|
44
|
+
let queue = (0, $fCAlL$useCallback)((fn)=>{
|
|
45
|
+
effect.current = fn(currValue.current);
|
|
46
|
+
nextRef.current();
|
|
47
|
+
}, [
|
|
48
|
+
nextRef
|
|
49
|
+
]);
|
|
45
50
|
return [
|
|
46
51
|
value,
|
|
47
52
|
queue
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {useEffectEvent as $8ae05eaa5c114e9c$export$7f54fc3180508a52} from "./useEffectEvent.module.js";
|
|
2
1
|
import {useLayoutEffect as $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c} from "./useLayoutEffect.module.js";
|
|
3
|
-
import {useState as $fCAlL$useState, useRef as $fCAlL$useRef} from "react";
|
|
2
|
+
import {useState as $fCAlL$useState, useRef as $fCAlL$useRef, useCallback as $fCAlL$useCallback} from "react";
|
|
4
3
|
|
|
5
4
|
/*
|
|
6
5
|
* Copyright 2020 Adobe. All rights reserved.
|
|
@@ -16,10 +15,13 @@ import {useState as $fCAlL$useState, useRef as $fCAlL$useRef} from "react";
|
|
|
16
15
|
|
|
17
16
|
function $1dbecbe27a04f9af$export$14d238f342723f25(defaultValue) {
|
|
18
17
|
let [value, setValue] = (0, $fCAlL$useState)(defaultValue);
|
|
18
|
+
// Keep an up to date copy of value in a ref so we can access the current value in the generator.
|
|
19
|
+
// This allows us to maintain a stable queue function.
|
|
20
|
+
let currValue = (0, $fCAlL$useRef)(value);
|
|
19
21
|
let effect = (0, $fCAlL$useRef)(null);
|
|
20
22
|
// Store the function in a ref so we can always access the current version
|
|
21
23
|
// which has the proper `value` in scope.
|
|
22
|
-
let nextRef = (0, $
|
|
24
|
+
let nextRef = (0, $fCAlL$useRef)(()=>{
|
|
23
25
|
if (!effect.current) return;
|
|
24
26
|
// Run the generator to the next yield.
|
|
25
27
|
let newValue = effect.current.next();
|
|
@@ -31,17 +33,20 @@ function $1dbecbe27a04f9af$export$14d238f342723f25(defaultValue) {
|
|
|
31
33
|
// If the value is the same as the current value,
|
|
32
34
|
// then continue to the next yield. Otherwise,
|
|
33
35
|
// set the value in state and wait for the next layout effect.
|
|
34
|
-
if (
|
|
36
|
+
if (currValue.current === newValue.value) nextRef.current();
|
|
35
37
|
else setValue(newValue.value);
|
|
36
38
|
});
|
|
37
39
|
(0, $f0a04ccd8dbdd83b$export$e5c5a5f917a5871c)(()=>{
|
|
40
|
+
currValue.current = value;
|
|
38
41
|
// If there is an effect currently running, continue to the next yield.
|
|
39
|
-
if (effect.current) nextRef();
|
|
40
|
-
});
|
|
41
|
-
let queue = (0, $8ae05eaa5c114e9c$export$7f54fc3180508a52)((fn)=>{
|
|
42
|
-
effect.current = fn(value);
|
|
43
|
-
nextRef();
|
|
42
|
+
if (effect.current) nextRef.current();
|
|
44
43
|
});
|
|
44
|
+
let queue = (0, $fCAlL$useCallback)((fn)=>{
|
|
45
|
+
effect.current = fn(currValue.current);
|
|
46
|
+
nextRef.current();
|
|
47
|
+
}, [
|
|
48
|
+
nextRef
|
|
49
|
+
]);
|
|
45
50
|
return [
|
|
46
51
|
value,
|
|
47
52
|
queue
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAWM,SAAS,0CAAkB,YAA2B;IAC3D,IAAI,CAAC,OAAO,SAAS,GAAG,CAAA,GAAA,eAAO,EAAE;IACjC,iGAAiG;IACjG,sDAAsD;IACtD,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE;IACvB,IAAI,SAAyC,CAAA,GAAA,aAAK,EAAuB;IAEzE,0EAA0E;IAC1E,yCAAyC;IACzC,IAAI,UAAU,CAAA,GAAA,aAAK,EAAE;QACnB,IAAI,CAAC,OAAO,OAAO,EACjB;QAEF,uCAAuC;QACvC,IAAI,WAAW,OAAO,OAAO,CAAC,IAAI;QAElC,8CAA8C;QAC9C,IAAI,SAAS,IAAI,EAAE;YACjB,OAAO,OAAO,GAAG;YACjB;QACF;QAEA,iDAAiD;QACjD,8CAA8C;QAC9C,8DAA8D;QAC9D,IAAI,UAAU,OAAO,KAAK,SAAS,KAAK,EACtC,QAAQ,OAAO;aAEf,SAAS,SAAS,KAAK;IAE3B;IAEA,CAAA,GAAA,yCAAc,EAAE;QACd,UAAU,OAAO,GAAG;QACpB,uEAAuE;QACvE,IAAI,OAAO,OAAO,EAChB,QAAQ,OAAO;IAEnB;IAEA,IAAI,QAAQ,CAAA,GAAA,kBAAU,EAAE,CAAA;QACtB,OAAO,OAAO,GAAG,GAAG,UAAU,OAAO;QACrC,QAAQ,OAAO;IACjB,GAAG;QAAC;KAAQ;IAEZ,OAAO;QAAC;QAAO;KAAM;AACvB","sources":["packages/@react-aria/utils/src/useValueEffect.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 {Dispatch, RefObject, useCallback, useRef, useState} from 'react';\nimport {useLayoutEffect} from './';\n\ntype SetValueAction<S> = (prev: S) => Generator<any, void, unknown>;\n\n// This hook works like `useState`, but when setting the value, you pass a generator function\n// that can yield multiple values. Each yielded value updates the state and waits for the next\n// layout effect, then continues the generator. This allows sequential updates to state to be\n// written linearly.\nexport function useValueEffect<S>(defaultValue: S | (() => S)): [S, Dispatch<SetValueAction<S>>] {\n let [value, setValue] = useState(defaultValue);\n // Keep an up to date copy of value in a ref so we can access the current value in the generator.\n // This allows us to maintain a stable queue function.\n let currValue = useRef(value);\n let effect: RefObject<Generator<S> | null> = useRef<Generator<S> | null>(null);\n\n // Store the function in a ref so we can always access the current version\n // which has the proper `value` in scope.\n let nextRef = useRef(() => {\n if (!effect.current) {\n return;\n }\n // Run the generator to the next yield.\n let newValue = effect.current.next();\n\n // If the generator is done, reset the effect.\n if (newValue.done) {\n effect.current = null;\n return;\n }\n\n // If the value is the same as the current value,\n // then continue to the next yield. Otherwise,\n // set the value in state and wait for the next layout effect.\n if (currValue.current === newValue.value) {\n nextRef.current();\n } else {\n setValue(newValue.value);\n }\n });\n\n useLayoutEffect(() => {\n currValue.current = value;\n // If there is an effect currently running, continue to the next yield.\n if (effect.current) {\n nextRef.current();\n }\n });\n\n let queue = useCallback(fn => {\n effect.current = fn(currValue.current);\n nextRef.current();\n }, [nextRef]);\n\n return [value, queue];\n}\n"],"names":[],"version":3,"file":"useValueEffect.module.js.map"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var $2308dc377e184bb0$exports = require("./keyboard.main.js");
|
|
1
2
|
var $4gIVO$react = require("react");
|
|
2
3
|
var $4gIVO$reactariassr = require("@react-aria/ssr");
|
|
3
4
|
|
|
@@ -19,6 +20,7 @@ $parcel$export(module.exports, "useViewportSize", () => $8b24bab62f5c65ad$export
|
|
|
19
20
|
* governing permissions and limitations under the License.
|
|
20
21
|
*/
|
|
21
22
|
|
|
23
|
+
|
|
22
24
|
let $8b24bab62f5c65ad$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
23
25
|
function $8b24bab62f5c65ad$export$d699905dd57c73ca() {
|
|
24
26
|
let isSSR = (0, $4gIVO$reactariassr.useIsSSR)();
|
|
@@ -29,15 +31,37 @@ function $8b24bab62f5c65ad$export$d699905dd57c73ca() {
|
|
|
29
31
|
(0, $4gIVO$react.useEffect)(()=>{
|
|
30
32
|
// Use visualViewport api to track available height even on iOS virtual keyboard opening
|
|
31
33
|
let onResize = ()=>{
|
|
34
|
+
// Ignore updates when zoomed.
|
|
35
|
+
if ($8b24bab62f5c65ad$var$visualViewport && $8b24bab62f5c65ad$var$visualViewport.scale > 1) return;
|
|
32
36
|
setSize((size)=>{
|
|
33
37
|
let newSize = $8b24bab62f5c65ad$var$getViewportSize();
|
|
34
38
|
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
35
39
|
return newSize;
|
|
36
40
|
});
|
|
37
41
|
};
|
|
42
|
+
// When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
|
|
43
|
+
// We can anticipate this and resize early by handling the blur event and using the layout size.
|
|
44
|
+
let frame;
|
|
45
|
+
let onBlur = (e)=>{
|
|
46
|
+
if ($8b24bab62f5c65ad$var$visualViewport && $8b24bab62f5c65ad$var$visualViewport.scale > 1) return;
|
|
47
|
+
if ((0, $2308dc377e184bb0$exports.willOpenKeyboard)(e.target)) // Wait one frame to see if a new element gets focused.
|
|
48
|
+
frame = requestAnimationFrame(()=>{
|
|
49
|
+
if (!document.activeElement || !(0, $2308dc377e184bb0$exports.willOpenKeyboard)(document.activeElement)) setSize((size)=>{
|
|
50
|
+
let newSize = {
|
|
51
|
+
width: window.innerWidth,
|
|
52
|
+
height: window.innerHeight
|
|
53
|
+
};
|
|
54
|
+
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
55
|
+
return newSize;
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
window.addEventListener('blur', onBlur, true);
|
|
38
60
|
if (!$8b24bab62f5c65ad$var$visualViewport) window.addEventListener('resize', onResize);
|
|
39
61
|
else $8b24bab62f5c65ad$var$visualViewport.addEventListener('resize', onResize);
|
|
40
62
|
return ()=>{
|
|
63
|
+
cancelAnimationFrame(frame);
|
|
64
|
+
window.removeEventListener('blur', onBlur, true);
|
|
41
65
|
if (!$8b24bab62f5c65ad$var$visualViewport) window.removeEventListener('resize', onResize);
|
|
42
66
|
else $8b24bab62f5c65ad$var$visualViewport.removeEventListener('resize', onResize);
|
|
43
67
|
};
|
|
@@ -46,8 +70,9 @@ function $8b24bab62f5c65ad$export$d699905dd57c73ca() {
|
|
|
46
70
|
}
|
|
47
71
|
function $8b24bab62f5c65ad$var$getViewportSize() {
|
|
48
72
|
return {
|
|
49
|
-
|
|
50
|
-
|
|
73
|
+
// 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 : window.innerWidth,
|
|
75
|
+
height: $8b24bab62f5c65ad$var$visualViewport ? $8b24bab62f5c65ad$var$visualViewport.height * $8b24bab62f5c65ad$var$visualViewport.scale : window.innerHeight
|
|
51
76
|
};
|
|
52
77
|
}
|
|
53
78
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAWD,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,wFAAwF;QACxF,IAAI,WAAW;YACb,8BAA8B;YAC9B,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,QAAQ,CAAA;gBACN,IAAI,UAAU;gBACd,IAAI,QAAQ,KAAK,KAAK,KAAK,KAAK,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,EAChE,OAAO;gBAET,OAAO;YACT;QACF;QAEA,iHAAiH;QACjH,gGAAgG;QAChG,IAAI;QACJ,IAAI,SAAS,CAAC;YACZ,IAAI,wCAAkB,qCAAe,KAAK,GAAG,GAC3C;YAGF,IAAI,CAAA,GAAA,0CAAe,EAAE,EAAE,MAAM,GAC3B,uDAAuD;YACvD,QAAQ,sBAAsB;gBAC5B,IAAI,CAAC,SAAS,aAAa,IAAI,CAAC,CAAA,GAAA,0CAAe,EAAE,SAAS,aAAa,GACrE,QAAQ,CAAA;oBACN,IAAI,UAAU;wBAAC,OAAO,OAAO,UAAU;wBAAE,QAAQ,OAAO,WAAW;oBAAA;oBACnE,IAAI,QAAQ,KAAK,KAAK,KAAK,KAAK,IAAI,QAAQ,MAAM,KAAK,KAAK,MAAM,EAChE,OAAO;oBAET,OAAO;gBACT;YAEJ;QAEJ;QAEA,OAAO,gBAAgB,CAAC,QAAQ,QAAQ;QAExC,IAAI,CAAC,sCACH,OAAO,gBAAgB,CAAC,UAAU;aAElC,qCAAe,gBAAgB,CAAC,UAAU;QAG5C,OAAO;YACL,qBAAqB;YACrB,OAAO,mBAAmB,CAAC,QAAQ,QAAQ;YAC3C,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,OAAO,UAAU;QACvF,QAAQ,uCAAiB,qCAAe,MAAM,GAAG,qCAAe,KAAK,GAAG,OAAO,WAAW;IAC5F;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 {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 // 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 setSize(size => {\n let newSize = getViewportSize();\n if (newSize.width === size.width && newSize.height === size.height) {\n return size;\n }\n return newSize;\n });\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(e.target as Element)) {\n // Wait one frame to see if a new element gets focused.\n frame = requestAnimationFrame(() => {\n if (!document.activeElement || !willOpenKeyboard(document.activeElement)) {\n setSize(size => {\n let newSize = {width: window.innerWidth, height: window.innerHeight};\n if (newSize.width === size.width && newSize.height === size.height) {\n return size;\n }\n return newSize;\n });\n }\n });\n }\n };\n\n window.addEventListener('blur', onBlur, true);\n\n if (!visualViewport) {\n window.addEventListener('resize', onResize);\n } else {\n visualViewport.addEventListener('resize', onResize);\n }\n\n return () => {\n cancelAnimationFrame(frame);\n window.removeEventListener('blur', onBlur, true);\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 : window.innerWidth,\n height: visualViewport ? visualViewport.height * visualViewport.scale : window.innerHeight\n };\n}\n"],"names":[],"version":3,"file":"useViewportSize.main.js.map"}
|
package/dist/useViewportSize.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {willOpenKeyboard as $21f1aa98acb08317$export$c57958e35f31ed73} from "./keyboard.mjs";
|
|
1
2
|
import {useState as $fuDHA$useState, useEffect as $fuDHA$useEffect} from "react";
|
|
2
3
|
import {useIsSSR as $fuDHA$useIsSSR} from "@react-aria/ssr";
|
|
3
4
|
|
|
@@ -13,6 +14,7 @@ import {useIsSSR as $fuDHA$useIsSSR} from "@react-aria/ssr";
|
|
|
13
14
|
* governing permissions and limitations under the License.
|
|
14
15
|
*/
|
|
15
16
|
|
|
17
|
+
|
|
16
18
|
let $5df64b3807dc15ee$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
17
19
|
function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
18
20
|
let isSSR = (0, $fuDHA$useIsSSR)();
|
|
@@ -23,15 +25,37 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
|
23
25
|
(0, $fuDHA$useEffect)(()=>{
|
|
24
26
|
// Use visualViewport api to track available height even on iOS virtual keyboard opening
|
|
25
27
|
let onResize = ()=>{
|
|
28
|
+
// Ignore updates when zoomed.
|
|
29
|
+
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
26
30
|
setSize((size)=>{
|
|
27
31
|
let newSize = $5df64b3807dc15ee$var$getViewportSize();
|
|
28
32
|
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
29
33
|
return newSize;
|
|
30
34
|
});
|
|
31
35
|
};
|
|
36
|
+
// When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
|
|
37
|
+
// We can anticipate this and resize early by handling the blur event and using the layout size.
|
|
38
|
+
let frame;
|
|
39
|
+
let onBlur = (e)=>{
|
|
40
|
+
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
41
|
+
if ((0, $21f1aa98acb08317$export$c57958e35f31ed73)(e.target)) // Wait one frame to see if a new element gets focused.
|
|
42
|
+
frame = requestAnimationFrame(()=>{
|
|
43
|
+
if (!document.activeElement || !(0, $21f1aa98acb08317$export$c57958e35f31ed73)(document.activeElement)) setSize((size)=>{
|
|
44
|
+
let newSize = {
|
|
45
|
+
width: window.innerWidth,
|
|
46
|
+
height: window.innerHeight
|
|
47
|
+
};
|
|
48
|
+
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
49
|
+
return newSize;
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
window.addEventListener('blur', onBlur, true);
|
|
32
54
|
if (!$5df64b3807dc15ee$var$visualViewport) window.addEventListener('resize', onResize);
|
|
33
55
|
else $5df64b3807dc15ee$var$visualViewport.addEventListener('resize', onResize);
|
|
34
56
|
return ()=>{
|
|
57
|
+
cancelAnimationFrame(frame);
|
|
58
|
+
window.removeEventListener('blur', onBlur, true);
|
|
35
59
|
if (!$5df64b3807dc15ee$var$visualViewport) window.removeEventListener('resize', onResize);
|
|
36
60
|
else $5df64b3807dc15ee$var$visualViewport.removeEventListener('resize', onResize);
|
|
37
61
|
};
|
|
@@ -40,8 +64,9 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
|
40
64
|
}
|
|
41
65
|
function $5df64b3807dc15ee$var$getViewportSize() {
|
|
42
66
|
return {
|
|
43
|
-
|
|
44
|
-
|
|
67
|
+
// 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 : window.innerWidth,
|
|
69
|
+
height: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.height * $5df64b3807dc15ee$var$visualViewport.scale : window.innerHeight
|
|
45
70
|
};
|
|
46
71
|
}
|
|
47
72
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {willOpenKeyboard as $21f1aa98acb08317$export$c57958e35f31ed73} from "./keyboard.module.js";
|
|
1
2
|
import {useState as $fuDHA$useState, useEffect as $fuDHA$useEffect} from "react";
|
|
2
3
|
import {useIsSSR as $fuDHA$useIsSSR} from "@react-aria/ssr";
|
|
3
4
|
|
|
@@ -13,6 +14,7 @@ import {useIsSSR as $fuDHA$useIsSSR} from "@react-aria/ssr";
|
|
|
13
14
|
* governing permissions and limitations under the License.
|
|
14
15
|
*/
|
|
15
16
|
|
|
17
|
+
|
|
16
18
|
let $5df64b3807dc15ee$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
17
19
|
function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
18
20
|
let isSSR = (0, $fuDHA$useIsSSR)();
|
|
@@ -23,15 +25,37 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
|
23
25
|
(0, $fuDHA$useEffect)(()=>{
|
|
24
26
|
// Use visualViewport api to track available height even on iOS virtual keyboard opening
|
|
25
27
|
let onResize = ()=>{
|
|
28
|
+
// Ignore updates when zoomed.
|
|
29
|
+
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
26
30
|
setSize((size)=>{
|
|
27
31
|
let newSize = $5df64b3807dc15ee$var$getViewportSize();
|
|
28
32
|
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
29
33
|
return newSize;
|
|
30
34
|
});
|
|
31
35
|
};
|
|
36
|
+
// When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
|
|
37
|
+
// We can anticipate this and resize early by handling the blur event and using the layout size.
|
|
38
|
+
let frame;
|
|
39
|
+
let onBlur = (e)=>{
|
|
40
|
+
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
41
|
+
if ((0, $21f1aa98acb08317$export$c57958e35f31ed73)(e.target)) // Wait one frame to see if a new element gets focused.
|
|
42
|
+
frame = requestAnimationFrame(()=>{
|
|
43
|
+
if (!document.activeElement || !(0, $21f1aa98acb08317$export$c57958e35f31ed73)(document.activeElement)) setSize((size)=>{
|
|
44
|
+
let newSize = {
|
|
45
|
+
width: window.innerWidth,
|
|
46
|
+
height: window.innerHeight
|
|
47
|
+
};
|
|
48
|
+
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
49
|
+
return newSize;
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
window.addEventListener('blur', onBlur, true);
|
|
32
54
|
if (!$5df64b3807dc15ee$var$visualViewport) window.addEventListener('resize', onResize);
|
|
33
55
|
else $5df64b3807dc15ee$var$visualViewport.addEventListener('resize', onResize);
|
|
34
56
|
return ()=>{
|
|
57
|
+
cancelAnimationFrame(frame);
|
|
58
|
+
window.removeEventListener('blur', onBlur, true);
|
|
35
59
|
if (!$5df64b3807dc15ee$var$visualViewport) window.removeEventListener('resize', onResize);
|
|
36
60
|
else $5df64b3807dc15ee$var$visualViewport.removeEventListener('resize', onResize);
|
|
37
61
|
};
|
|
@@ -40,8 +64,9 @@ function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
|
40
64
|
}
|
|
41
65
|
function $5df64b3807dc15ee$var$getViewportSize() {
|
|
42
66
|
return {
|
|
43
|
-
|
|
44
|
-
|
|
67
|
+
// 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 : window.innerWidth,
|
|
69
|
+
height: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.height * $5df64b3807dc15ee$var$visualViewport.scale : window.innerHeight
|
|
45
70
|
};
|
|
46
71
|
}
|
|
47
72
|
|