@react-aria/utils 3.33.0 → 3.34.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/import.mjs +47 -43
- package/dist/main.js +120 -114
- package/dist/main.js.map +1 -1
- package/dist/module.js +47 -43
- package/dist/module.js.map +1 -1
- package/dist/types/src/index.d.ts +45 -0
- package/package.json +15 -15
- package/src/index.ts +45 -43
- package/dist/DOMFunctions.main.js +0 -44
- package/dist/DOMFunctions.main.js.map +0 -1
- package/dist/DOMFunctions.mjs +0 -37
- package/dist/DOMFunctions.module.js +0 -37
- package/dist/DOMFunctions.module.js.map +0 -1
- package/dist/ShadowTreeWalker.main.js +0 -200
- package/dist/ShadowTreeWalker.main.js.map +0 -1
- package/dist/ShadowTreeWalker.mjs +0 -194
- package/dist/ShadowTreeWalker.module.js +0 -194
- package/dist/ShadowTreeWalker.module.js.map +0 -1
- package/dist/animation.main.js +0 -97
- package/dist/animation.main.js.map +0 -1
- package/dist/animation.mjs +0 -91
- package/dist/animation.module.js +0 -91
- package/dist/animation.module.js.map +0 -1
- package/dist/chain.main.js +0 -26
- package/dist/chain.main.js.map +0 -1
- package/dist/chain.mjs +0 -21
- package/dist/chain.module.js +0 -21
- package/dist/chain.module.js.map +0 -1
- package/dist/constants.main.js +0 -23
- package/dist/constants.main.js.map +0 -1
- package/dist/constants.mjs +0 -17
- package/dist/constants.module.js +0 -17
- package/dist/constants.module.js.map +0 -1
- package/dist/domHelpers.main.js +0 -28
- package/dist/domHelpers.main.js.map +0 -1
- package/dist/domHelpers.mjs +0 -21
- package/dist/domHelpers.module.js +0 -21
- package/dist/domHelpers.module.js.map +0 -1
- package/dist/filterDOMProps.main.js +0 -88
- package/dist/filterDOMProps.main.js.map +0 -1
- package/dist/filterDOMProps.mjs +0 -83
- package/dist/filterDOMProps.module.js +0 -83
- package/dist/filterDOMProps.module.js.map +0 -1
- package/dist/focusWithoutScrolling.main.js +0 -72
- package/dist/focusWithoutScrolling.main.js.map +0 -1
- package/dist/focusWithoutScrolling.mjs +0 -67
- package/dist/focusWithoutScrolling.module.js +0 -67
- package/dist/focusWithoutScrolling.module.js.map +0 -1
- package/dist/getOffset.main.js +0 -24
- package/dist/getOffset.main.js.map +0 -1
- package/dist/getOffset.mjs +0 -19
- package/dist/getOffset.module.js +0 -19
- package/dist/getOffset.module.js.map +0 -1
- package/dist/getScrollParent.main.js +0 -28
- package/dist/getScrollParent.main.js.map +0 -1
- package/dist/getScrollParent.mjs +0 -23
- package/dist/getScrollParent.module.js +0 -23
- package/dist/getScrollParent.module.js.map +0 -1
- package/dist/getScrollParents.main.js +0 -30
- package/dist/getScrollParents.main.js.map +0 -1
- package/dist/getScrollParents.mjs +0 -25
- package/dist/getScrollParents.module.js +0 -25
- package/dist/getScrollParents.module.js.map +0 -1
- package/dist/inertValue.main.js +0 -19
- package/dist/inertValue.main.js.map +0 -1
- package/dist/inertValue.mjs +0 -14
- package/dist/inertValue.module.js +0 -14
- package/dist/inertValue.module.js.map +0 -1
- package/dist/isElementVisible.main.js +0 -45
- package/dist/isElementVisible.main.js.map +0 -1
- package/dist/isElementVisible.mjs +0 -40
- package/dist/isElementVisible.module.js +0 -40
- package/dist/isElementVisible.module.js.map +0 -1
- package/dist/isFocusable.main.js +0 -56
- package/dist/isFocusable.main.js.map +0 -1
- package/dist/isFocusable.mjs +0 -50
- package/dist/isFocusable.module.js +0 -50
- package/dist/isFocusable.module.js.map +0 -1
- package/dist/isScrollable.main.js +0 -26
- package/dist/isScrollable.main.js.map +0 -1
- package/dist/isScrollable.mjs +0 -21
- package/dist/isScrollable.module.js +0 -21
- package/dist/isScrollable.module.js.map +0 -1
- package/dist/isVirtualEvent.main.js +0 -41
- package/dist/isVirtualEvent.main.js.map +0 -1
- package/dist/isVirtualEvent.mjs +0 -35
- package/dist/isVirtualEvent.module.js +0 -35
- package/dist/isVirtualEvent.module.js.map +0 -1
- package/dist/keyboard.main.js +0 -42
- package/dist/keyboard.main.js.map +0 -1
- package/dist/keyboard.mjs +0 -36
- package/dist/keyboard.module.js +0 -36
- package/dist/keyboard.module.js.map +0 -1
- package/dist/mergeProps.main.js +0 -54
- package/dist/mergeProps.main.js.map +0 -1
- package/dist/mergeProps.mjs +0 -45
- package/dist/mergeProps.module.js +0 -45
- package/dist/mergeProps.module.js.map +0 -1
- package/dist/mergeRefs.main.js +0 -40
- package/dist/mergeRefs.main.js.map +0 -1
- package/dist/mergeRefs.mjs +0 -35
- package/dist/mergeRefs.module.js +0 -35
- package/dist/mergeRefs.module.js.map +0 -1
- package/dist/openLink.main.js +0 -169
- package/dist/openLink.main.js.map +0 -1
- package/dist/openLink.mjs +0 -153
- package/dist/openLink.module.js +0 -153
- package/dist/openLink.module.js.map +0 -1
- package/dist/platform.main.js +0 -73
- package/dist/platform.main.js.map +0 -1
- package/dist/platform.mjs +0 -60
- package/dist/platform.module.js +0 -60
- package/dist/platform.module.js.map +0 -1
- package/dist/runAfterTransition.main.js +0 -92
- package/dist/runAfterTransition.main.js.map +0 -1
- package/dist/runAfterTransition.mjs +0 -87
- package/dist/runAfterTransition.module.js +0 -87
- package/dist/runAfterTransition.module.js.map +0 -1
- package/dist/scrollIntoView.main.js +0 -105
- package/dist/scrollIntoView.main.js.map +0 -1
- package/dist/scrollIntoView.mjs +0 -99
- package/dist/scrollIntoView.module.js +0 -99
- package/dist/scrollIntoView.module.js.map +0 -1
- package/dist/types.d.ts +0 -286
- package/dist/types.d.ts.map +0 -1
- package/dist/useDeepMemo.main.js +0 -30
- package/dist/useDeepMemo.main.js.map +0 -1
- package/dist/useDeepMemo.mjs +0 -25
- package/dist/useDeepMemo.module.js +0 -25
- package/dist/useDeepMemo.module.js.map +0 -1
- package/dist/useDescription.main.js +0 -59
- package/dist/useDescription.main.js.map +0 -1
- package/dist/useDescription.mjs +0 -54
- package/dist/useDescription.module.js +0 -54
- package/dist/useDescription.module.js.map +0 -1
- package/dist/useDrag1D.main.js +0 -141
- package/dist/useDrag1D.main.js.map +0 -1
- package/dist/useDrag1D.mjs +0 -136
- package/dist/useDrag1D.module.js +0 -136
- package/dist/useDrag1D.module.js.map +0 -1
- package/dist/useEffectEvent.main.js +0 -45
- package/dist/useEffectEvent.main.js.map +0 -1
- package/dist/useEffectEvent.mjs +0 -36
- package/dist/useEffectEvent.module.js +0 -36
- package/dist/useEffectEvent.module.js.map +0 -1
- package/dist/useEvent.main.js +0 -41
- package/dist/useEvent.main.js.map +0 -1
- package/dist/useEvent.mjs +0 -36
- package/dist/useEvent.module.js +0 -36
- package/dist/useEvent.module.js.map +0 -1
- package/dist/useFormReset.main.js +0 -39
- package/dist/useFormReset.main.js.map +0 -1
- package/dist/useFormReset.mjs +0 -34
- package/dist/useFormReset.module.js +0 -34
- package/dist/useFormReset.module.js.map +0 -1
- package/dist/useGlobalListeners.main.js +0 -62
- package/dist/useGlobalListeners.main.js.map +0 -1
- package/dist/useGlobalListeners.mjs +0 -57
- package/dist/useGlobalListeners.module.js +0 -57
- package/dist/useGlobalListeners.module.js.map +0 -1
- package/dist/useId.main.js +0 -108
- package/dist/useId.main.js.map +0 -1
- package/dist/useId.mjs +0 -101
- package/dist/useId.module.js +0 -101
- package/dist/useId.module.js.map +0 -1
- package/dist/useLabels.main.js +0 -44
- package/dist/useLabels.main.js.map +0 -1
- package/dist/useLabels.mjs +0 -39
- package/dist/useLabels.module.js +0 -39
- package/dist/useLabels.module.js.map +0 -1
- package/dist/useLayoutEffect.main.js +0 -27
- package/dist/useLayoutEffect.main.js.map +0 -1
- package/dist/useLayoutEffect.mjs +0 -18
- package/dist/useLayoutEffect.module.js +0 -18
- package/dist/useLayoutEffect.module.js.map +0 -1
- package/dist/useLoadMore.main.js +0 -73
- package/dist/useLoadMore.main.js.map +0 -1
- package/dist/useLoadMore.mjs +0 -68
- package/dist/useLoadMore.module.js +0 -68
- package/dist/useLoadMore.module.js.map +0 -1
- package/dist/useLoadMoreSentinel.main.js +0 -58
- package/dist/useLoadMoreSentinel.main.js.map +0 -1
- package/dist/useLoadMoreSentinel.mjs +0 -53
- package/dist/useLoadMoreSentinel.module.js +0 -53
- package/dist/useLoadMoreSentinel.module.js.map +0 -1
- package/dist/useObjectRef.main.js +0 -58
- package/dist/useObjectRef.main.js.map +0 -1
- package/dist/useObjectRef.mjs +0 -53
- package/dist/useObjectRef.module.js +0 -53
- package/dist/useObjectRef.module.js.map +0 -1
- package/dist/useResizeObserver.main.js +0 -47
- package/dist/useResizeObserver.main.js.map +0 -1
- package/dist/useResizeObserver.mjs +0 -42
- package/dist/useResizeObserver.module.js +0 -42
- package/dist/useResizeObserver.module.js.map +0 -1
- package/dist/useSyncRef.main.js +0 -32
- package/dist/useSyncRef.main.js.map +0 -1
- package/dist/useSyncRef.mjs +0 -27
- package/dist/useSyncRef.module.js +0 -27
- package/dist/useSyncRef.module.js.map +0 -1
- package/dist/useUpdateEffect.main.js +0 -42
- package/dist/useUpdateEffect.main.js.map +0 -1
- package/dist/useUpdateEffect.mjs +0 -37
- package/dist/useUpdateEffect.module.js +0 -37
- package/dist/useUpdateEffect.module.js.map +0 -1
- package/dist/useUpdateLayoutEffect.main.js +0 -40
- package/dist/useUpdateLayoutEffect.main.js.map +0 -1
- package/dist/useUpdateLayoutEffect.mjs +0 -35
- package/dist/useUpdateLayoutEffect.module.js +0 -35
- package/dist/useUpdateLayoutEffect.module.js.map +0 -1
- package/dist/useValueEffect.main.js +0 -63
- package/dist/useValueEffect.main.js.map +0 -1
- package/dist/useValueEffect.mjs +0 -58
- package/dist/useValueEffect.module.js +0 -58
- package/dist/useValueEffect.module.js.map +0 -1
- package/dist/useViewportSize.main.js +0 -79
- package/dist/useViewportSize.main.js.map +0 -1
- package/dist/useViewportSize.mjs +0 -74
- package/dist/useViewportSize.module.js +0 -74
- package/dist/useViewportSize.module.js.map +0 -1
- package/src/animation.ts +0 -103
- package/src/chain.ts +0 -24
- package/src/constants.ts +0 -15
- package/src/domHelpers.ts +0 -33
- package/src/filterDOMProps.ts +0 -127
- package/src/focusWithoutScrolling.ts +0 -96
- package/src/getOffset.ts +0 -21
- package/src/getScrollParent.ts +0 -27
- package/src/getScrollParents.ts +0 -26
- package/src/inertValue.ts +0 -11
- package/src/isElementVisible.ts +0 -75
- package/src/isFocusable.ts +0 -56
- package/src/isScrollable.ts +0 -25
- package/src/isVirtualEvent.ts +0 -58
- package/src/keyboard.tsx +0 -48
- package/src/mergeProps.ts +0 -77
- package/src/mergeRefs.ts +0 -52
- package/src/openLink.tsx +0 -201
- package/src/platform.ts +0 -78
- package/src/runAfterTransition.ts +0 -121
- package/src/scrollIntoView.ts +0 -129
- package/src/shadowdom/DOMFunctions.ts +0 -71
- package/src/shadowdom/ShadowTreeWalker.ts +0 -319
- package/src/useDeepMemo.ts +0 -27
- package/src/useDescription.ts +0 -56
- package/src/useDrag1D.ts +0 -191
- package/src/useEffectEvent.ts +0 -30
- package/src/useEvent.ts +0 -37
- package/src/useFormReset.ts +0 -36
- package/src/useGlobalListeners.ts +0 -52
- package/src/useId.ts +0 -129
- package/src/useLabels.ts +0 -48
- package/src/useLayoutEffect.ts +0 -20
- package/src/useLoadMore.ts +0 -82
- package/src/useLoadMoreSentinel.ts +0 -63
- package/src/useObjectRef.ts +0 -69
- package/src/useResizeObserver.ts +0 -52
- package/src/useSyncRef.ts +0 -33
- package/src/useUpdateEffect.ts +0 -39
- package/src/useUpdateLayoutEffect.ts +0 -37
- package/src/useValueEffect.ts +0 -68
- package/src/useViewportSize.ts +0 -96
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
var $2308dc377e184bb0$exports = require("./keyboard.main.js");
|
|
2
|
-
var $4gIVO$react = require("react");
|
|
3
|
-
var $4gIVO$reactariassr = require("@react-aria/ssr");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
function $parcel$export(e, n, v, s) {
|
|
7
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
$parcel$export(module.exports, "useViewportSize", () => $8b24bab62f5c65ad$export$d699905dd57c73ca);
|
|
11
|
-
/*
|
|
12
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
13
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
14
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
15
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
-
*
|
|
17
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
18
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
19
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
20
|
-
* governing permissions and limitations under the License.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
let $8b24bab62f5c65ad$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
25
|
-
function $8b24bab62f5c65ad$export$d699905dd57c73ca() {
|
|
26
|
-
let isSSR = (0, $4gIVO$reactariassr.useIsSSR)();
|
|
27
|
-
let [size, setSize] = (0, $4gIVO$react.useState)(()=>isSSR ? {
|
|
28
|
-
width: 0,
|
|
29
|
-
height: 0
|
|
30
|
-
} : $8b24bab62f5c65ad$var$getViewportSize());
|
|
31
|
-
(0, $4gIVO$react.useEffect)(()=>{
|
|
32
|
-
let updateSize = (newSize)=>{
|
|
33
|
-
setSize((size)=>{
|
|
34
|
-
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
35
|
-
return newSize;
|
|
36
|
-
});
|
|
37
|
-
};
|
|
38
|
-
// Use visualViewport api to track available height even on iOS virtual keyboard opening
|
|
39
|
-
let onResize = ()=>{
|
|
40
|
-
// Ignore updates when zoomed.
|
|
41
|
-
if ($8b24bab62f5c65ad$var$visualViewport && $8b24bab62f5c65ad$var$visualViewport.scale > 1) return;
|
|
42
|
-
updateSize($8b24bab62f5c65ad$var$getViewportSize());
|
|
43
|
-
};
|
|
44
|
-
// When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
|
|
45
|
-
// We can anticipate this and resize early by handling the blur event and using the layout size.
|
|
46
|
-
let frame;
|
|
47
|
-
let onBlur = (e)=>{
|
|
48
|
-
if ($8b24bab62f5c65ad$var$visualViewport && $8b24bab62f5c65ad$var$visualViewport.scale > 1) return;
|
|
49
|
-
if ((0, $2308dc377e184bb0$exports.willOpenKeyboard)(e.target)) // Wait one frame to see if a new element gets focused.
|
|
50
|
-
frame = requestAnimationFrame(()=>{
|
|
51
|
-
if (!document.activeElement || !(0, $2308dc377e184bb0$exports.willOpenKeyboard)(document.activeElement)) updateSize({
|
|
52
|
-
width: document.documentElement.clientWidth,
|
|
53
|
-
height: document.documentElement.clientHeight
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
updateSize($8b24bab62f5c65ad$var$getViewportSize());
|
|
58
|
-
window.addEventListener('blur', onBlur, true);
|
|
59
|
-
if (!$8b24bab62f5c65ad$var$visualViewport) window.addEventListener('resize', onResize);
|
|
60
|
-
else $8b24bab62f5c65ad$var$visualViewport.addEventListener('resize', onResize);
|
|
61
|
-
return ()=>{
|
|
62
|
-
cancelAnimationFrame(frame);
|
|
63
|
-
window.removeEventListener('blur', onBlur, true);
|
|
64
|
-
if (!$8b24bab62f5c65ad$var$visualViewport) window.removeEventListener('resize', onResize);
|
|
65
|
-
else $8b24bab62f5c65ad$var$visualViewport.removeEventListener('resize', onResize);
|
|
66
|
-
};
|
|
67
|
-
}, []);
|
|
68
|
-
return size;
|
|
69
|
-
}
|
|
70
|
-
function $8b24bab62f5c65ad$var$getViewportSize() {
|
|
71
|
-
return {
|
|
72
|
-
// Multiply by the visualViewport scale to get the "natural" size, unaffected by pinch zooming.
|
|
73
|
-
width: $8b24bab62f5c65ad$var$visualViewport ? $8b24bab62f5c65ad$var$visualViewport.width * $8b24bab62f5c65ad$var$visualViewport.scale : document.documentElement.clientWidth,
|
|
74
|
-
height: $8b24bab62f5c65ad$var$visualViewport ? $8b24bab62f5c65ad$var$visualViewport.height * $8b24bab62f5c65ad$var$visualViewport.scale : document.documentElement.clientHeight
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
//# sourceMappingURL=useViewportSize.main.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,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,EAAE,MAAM,GAC3B,uDAAuD;YACvD,QAAQ,sBAAsB;gBAC5B,IAAI,CAAC,SAAS,aAAa,IAAI,CAAC,CAAA,GAAA,0CAAe,EAAE,SAAS,aAAa,GACrE,WAAW;oBAAC,OAAO,SAAS,eAAe,CAAC,WAAW;oBAAE,QAAQ,SAAS,eAAe,CAAC,YAAY;gBAAA;YAE1G;QAEJ;QAEA,WAAW;QAEX,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,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 {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(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 updateSize({width: document.documentElement.clientWidth, height: document.documentElement.clientHeight});\n }\n });\n }\n };\n\n updateSize(getViewportSize());\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 : 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
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import {willOpenKeyboard as $21f1aa98acb08317$export$c57958e35f31ed73} from "./keyboard.mjs";
|
|
2
|
-
import {useState as $fuDHA$useState, useEffect as $fuDHA$useEffect} from "react";
|
|
3
|
-
import {useIsSSR as $fuDHA$useIsSSR} from "@react-aria/ssr";
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
7
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
-
* governing permissions and limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let $5df64b3807dc15ee$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
19
|
-
function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
20
|
-
let isSSR = (0, $fuDHA$useIsSSR)();
|
|
21
|
-
let [size, setSize] = (0, $fuDHA$useState)(()=>isSSR ? {
|
|
22
|
-
width: 0,
|
|
23
|
-
height: 0
|
|
24
|
-
} : $5df64b3807dc15ee$var$getViewportSize());
|
|
25
|
-
(0, $fuDHA$useEffect)(()=>{
|
|
26
|
-
let updateSize = (newSize)=>{
|
|
27
|
-
setSize((size)=>{
|
|
28
|
-
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
29
|
-
return newSize;
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
// Use visualViewport api to track available height even on iOS virtual keyboard opening
|
|
33
|
-
let onResize = ()=>{
|
|
34
|
-
// Ignore updates when zoomed.
|
|
35
|
-
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
36
|
-
updateSize($5df64b3807dc15ee$var$getViewportSize());
|
|
37
|
-
};
|
|
38
|
-
// When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
|
|
39
|
-
// We can anticipate this and resize early by handling the blur event and using the layout size.
|
|
40
|
-
let frame;
|
|
41
|
-
let onBlur = (e)=>{
|
|
42
|
-
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
43
|
-
if ((0, $21f1aa98acb08317$export$c57958e35f31ed73)(e.target)) // Wait one frame to see if a new element gets focused.
|
|
44
|
-
frame = requestAnimationFrame(()=>{
|
|
45
|
-
if (!document.activeElement || !(0, $21f1aa98acb08317$export$c57958e35f31ed73)(document.activeElement)) updateSize({
|
|
46
|
-
width: document.documentElement.clientWidth,
|
|
47
|
-
height: document.documentElement.clientHeight
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
updateSize($5df64b3807dc15ee$var$getViewportSize());
|
|
52
|
-
window.addEventListener('blur', onBlur, true);
|
|
53
|
-
if (!$5df64b3807dc15ee$var$visualViewport) window.addEventListener('resize', onResize);
|
|
54
|
-
else $5df64b3807dc15ee$var$visualViewport.addEventListener('resize', onResize);
|
|
55
|
-
return ()=>{
|
|
56
|
-
cancelAnimationFrame(frame);
|
|
57
|
-
window.removeEventListener('blur', onBlur, true);
|
|
58
|
-
if (!$5df64b3807dc15ee$var$visualViewport) window.removeEventListener('resize', onResize);
|
|
59
|
-
else $5df64b3807dc15ee$var$visualViewport.removeEventListener('resize', onResize);
|
|
60
|
-
};
|
|
61
|
-
}, []);
|
|
62
|
-
return size;
|
|
63
|
-
}
|
|
64
|
-
function $5df64b3807dc15ee$var$getViewportSize() {
|
|
65
|
-
return {
|
|
66
|
-
// Multiply by the visualViewport scale to get the "natural" size, unaffected by pinch zooming.
|
|
67
|
-
width: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.width * $5df64b3807dc15ee$var$visualViewport.scale : document.documentElement.clientWidth,
|
|
68
|
-
height: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.height * $5df64b3807dc15ee$var$visualViewport.scale : document.documentElement.clientHeight
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
export {$5df64b3807dc15ee$export$d699905dd57c73ca as useViewportSize};
|
|
74
|
-
//# sourceMappingURL=useViewportSize.module.js.map
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import {willOpenKeyboard as $21f1aa98acb08317$export$c57958e35f31ed73} from "./keyboard.module.js";
|
|
2
|
-
import {useState as $fuDHA$useState, useEffect as $fuDHA$useEffect} from "react";
|
|
3
|
-
import {useIsSSR as $fuDHA$useIsSSR} from "@react-aria/ssr";
|
|
4
|
-
|
|
5
|
-
/*
|
|
6
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
7
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
8
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
-
* governing permissions and limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let $5df64b3807dc15ee$var$visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
19
|
-
function $5df64b3807dc15ee$export$d699905dd57c73ca() {
|
|
20
|
-
let isSSR = (0, $fuDHA$useIsSSR)();
|
|
21
|
-
let [size, setSize] = (0, $fuDHA$useState)(()=>isSSR ? {
|
|
22
|
-
width: 0,
|
|
23
|
-
height: 0
|
|
24
|
-
} : $5df64b3807dc15ee$var$getViewportSize());
|
|
25
|
-
(0, $fuDHA$useEffect)(()=>{
|
|
26
|
-
let updateSize = (newSize)=>{
|
|
27
|
-
setSize((size)=>{
|
|
28
|
-
if (newSize.width === size.width && newSize.height === size.height) return size;
|
|
29
|
-
return newSize;
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
// Use visualViewport api to track available height even on iOS virtual keyboard opening
|
|
33
|
-
let onResize = ()=>{
|
|
34
|
-
// Ignore updates when zoomed.
|
|
35
|
-
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
36
|
-
updateSize($5df64b3807dc15ee$var$getViewportSize());
|
|
37
|
-
};
|
|
38
|
-
// When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
|
|
39
|
-
// We can anticipate this and resize early by handling the blur event and using the layout size.
|
|
40
|
-
let frame;
|
|
41
|
-
let onBlur = (e)=>{
|
|
42
|
-
if ($5df64b3807dc15ee$var$visualViewport && $5df64b3807dc15ee$var$visualViewport.scale > 1) return;
|
|
43
|
-
if ((0, $21f1aa98acb08317$export$c57958e35f31ed73)(e.target)) // Wait one frame to see if a new element gets focused.
|
|
44
|
-
frame = requestAnimationFrame(()=>{
|
|
45
|
-
if (!document.activeElement || !(0, $21f1aa98acb08317$export$c57958e35f31ed73)(document.activeElement)) updateSize({
|
|
46
|
-
width: document.documentElement.clientWidth,
|
|
47
|
-
height: document.documentElement.clientHeight
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
updateSize($5df64b3807dc15ee$var$getViewportSize());
|
|
52
|
-
window.addEventListener('blur', onBlur, true);
|
|
53
|
-
if (!$5df64b3807dc15ee$var$visualViewport) window.addEventListener('resize', onResize);
|
|
54
|
-
else $5df64b3807dc15ee$var$visualViewport.addEventListener('resize', onResize);
|
|
55
|
-
return ()=>{
|
|
56
|
-
cancelAnimationFrame(frame);
|
|
57
|
-
window.removeEventListener('blur', onBlur, true);
|
|
58
|
-
if (!$5df64b3807dc15ee$var$visualViewport) window.removeEventListener('resize', onResize);
|
|
59
|
-
else $5df64b3807dc15ee$var$visualViewport.removeEventListener('resize', onResize);
|
|
60
|
-
};
|
|
61
|
-
}, []);
|
|
62
|
-
return size;
|
|
63
|
-
}
|
|
64
|
-
function $5df64b3807dc15ee$var$getViewportSize() {
|
|
65
|
-
return {
|
|
66
|
-
// Multiply by the visualViewport scale to get the "natural" size, unaffected by pinch zooming.
|
|
67
|
-
width: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.width * $5df64b3807dc15ee$var$visualViewport.scale : document.documentElement.clientWidth,
|
|
68
|
-
height: $5df64b3807dc15ee$var$visualViewport ? $5df64b3807dc15ee$var$visualViewport.height * $5df64b3807dc15ee$var$visualViewport.scale : document.documentElement.clientHeight
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
export {$5df64b3807dc15ee$export$d699905dd57c73ca as useViewportSize};
|
|
74
|
-
//# sourceMappingURL=useViewportSize.module.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAWD,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,EAAE,MAAM,GAC3B,uDAAuD;YACvD,QAAQ,sBAAsB;gBAC5B,IAAI,CAAC,SAAS,aAAa,IAAI,CAAC,CAAA,GAAA,yCAAe,EAAE,SAAS,aAAa,GACrE,WAAW;oBAAC,OAAO,SAAS,eAAe,CAAC,WAAW;oBAAE,QAAQ,SAAS,eAAe,CAAC,YAAY;gBAAA;YAE1G;QAEJ;QAEA,WAAW;QAEX,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,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 {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(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 updateSize({width: document.documentElement.clientWidth, height: document.documentElement.clientHeight});\n }\n });\n }\n };\n\n updateSize(getViewportSize());\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 : 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/src/animation.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {flushSync} from 'react-dom';
|
|
14
|
-
import {RefObject, useCallback, useState} from 'react';
|
|
15
|
-
import {useLayoutEffect} from './useLayoutEffect';
|
|
16
|
-
|
|
17
|
-
export function useEnterAnimation(ref: RefObject<HTMLElement | null>, isReady: boolean = true): boolean {
|
|
18
|
-
let [isEntering, setEntering] = useState(true);
|
|
19
|
-
let isAnimationReady = isEntering && isReady;
|
|
20
|
-
|
|
21
|
-
// There are two cases for entry animations:
|
|
22
|
-
// 1. CSS @keyframes. The `animation` property is set during the isEntering state, and it is removed after the animation finishes.
|
|
23
|
-
// 2. CSS transitions. The initial styles are applied during the isEntering state, and removed immediately, causing the transition to occur.
|
|
24
|
-
//
|
|
25
|
-
// In the second case, cancel any transitions that were triggered prior to the isEntering = false state (when the transition is supposed to start).
|
|
26
|
-
// This can happen when isReady starts as false (e.g. popovers prior to placement calculation).
|
|
27
|
-
useLayoutEffect(() => {
|
|
28
|
-
if (isAnimationReady && ref.current && 'getAnimations' in ref.current) {
|
|
29
|
-
for (let animation of ref.current.getAnimations()) {
|
|
30
|
-
if (animation instanceof CSSTransition) {
|
|
31
|
-
animation.cancel();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}, [ref, isAnimationReady]);
|
|
36
|
-
|
|
37
|
-
useAnimation(ref, isAnimationReady, useCallback(() => setEntering(false), []));
|
|
38
|
-
return isAnimationReady;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function useExitAnimation(ref: RefObject<HTMLElement | null>, isOpen: boolean): boolean {
|
|
42
|
-
let [exitState, setExitState] = useState<'closed' | 'open' | 'exiting'>(isOpen ? 'open' : 'closed');
|
|
43
|
-
|
|
44
|
-
switch (exitState) {
|
|
45
|
-
case 'open':
|
|
46
|
-
// If isOpen becomes false, set the state to exiting.
|
|
47
|
-
if (!isOpen) {
|
|
48
|
-
setExitState('exiting');
|
|
49
|
-
}
|
|
50
|
-
break;
|
|
51
|
-
case 'closed':
|
|
52
|
-
case 'exiting':
|
|
53
|
-
// If we are exiting and isOpen becomes true, the animation was interrupted.
|
|
54
|
-
// Reset the state to open.
|
|
55
|
-
if (isOpen) {
|
|
56
|
-
setExitState('open');
|
|
57
|
-
}
|
|
58
|
-
break;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
let isExiting = exitState === 'exiting';
|
|
62
|
-
useAnimation(
|
|
63
|
-
ref,
|
|
64
|
-
isExiting,
|
|
65
|
-
useCallback(() => {
|
|
66
|
-
// Set the state to closed, which will cause the element to be unmounted.
|
|
67
|
-
setExitState(state => state === 'exiting' ? 'closed' : state);
|
|
68
|
-
}, [])
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
return isExiting;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function useAnimation(ref: RefObject<HTMLElement | null>, isActive: boolean, onEnd: () => void): void {
|
|
75
|
-
useLayoutEffect(() => {
|
|
76
|
-
if (isActive && ref.current) {
|
|
77
|
-
if (!('getAnimations' in ref.current)) {
|
|
78
|
-
// JSDOM
|
|
79
|
-
onEnd();
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
let animations = ref.current.getAnimations();
|
|
84
|
-
if (animations.length === 0) {
|
|
85
|
-
onEnd();
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
let canceled = false;
|
|
90
|
-
Promise.all(animations.map(a => a.finished)).then(() => {
|
|
91
|
-
if (!canceled) {
|
|
92
|
-
flushSync(() => {
|
|
93
|
-
onEnd();
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}).catch(() => {});
|
|
97
|
-
|
|
98
|
-
return () => {
|
|
99
|
-
canceled = true;
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
}, [ref, isActive, onEnd]);
|
|
103
|
-
}
|
package/src/chain.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Calls all functions in the order they were chained with the same arguments.
|
|
15
|
-
*/
|
|
16
|
-
export function chain(...callbacks: any[]): (...args: any[]) => void {
|
|
17
|
-
return (...args: any[]) => {
|
|
18
|
-
for (let callback of callbacks) {
|
|
19
|
-
if (typeof callback === 'function') {
|
|
20
|
-
callback(...args);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
}
|
package/src/constants.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2024 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
// Custom event names for updating the autocomplete's aria-activedecendant.
|
|
14
|
-
export const CLEAR_FOCUS_EVENT = 'react-aria-clear-focus';
|
|
15
|
-
export const FOCUS_EVENT = 'react-aria-focus';
|
package/src/domHelpers.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export const getOwnerDocument = (el: Element | null | undefined): Document => {
|
|
2
|
-
return el?.ownerDocument ?? document;
|
|
3
|
-
};
|
|
4
|
-
|
|
5
|
-
export const getOwnerWindow = (
|
|
6
|
-
el: (Window & typeof globalThis) | Element | null | undefined
|
|
7
|
-
): Window & typeof globalThis => {
|
|
8
|
-
if (el && 'window' in el && el.window === el) {
|
|
9
|
-
return el;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const doc = getOwnerDocument(el as Element | null | undefined);
|
|
13
|
-
return doc.defaultView || window;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Type guard that checks if a value is a Node. Verifies the presence and type of the nodeType property.
|
|
18
|
-
*/
|
|
19
|
-
function isNode(value: unknown): value is Node {
|
|
20
|
-
return value !== null &&
|
|
21
|
-
typeof value === 'object' &&
|
|
22
|
-
'nodeType' in value &&
|
|
23
|
-
typeof (value as Node).nodeType === 'number';
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Type guard that checks if a node is a ShadowRoot. Uses nodeType and host property checks to
|
|
27
|
-
* distinguish ShadowRoot from other DocumentFragments.
|
|
28
|
-
*/
|
|
29
|
-
export function isShadowRoot(node: Node | null): node is ShadowRoot {
|
|
30
|
-
return isNode(node) &&
|
|
31
|
-
node.nodeType === Node.DOCUMENT_FRAGMENT_NODE &&
|
|
32
|
-
'host' in node;
|
|
33
|
-
}
|
package/src/filterDOMProps.ts
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {AriaLabelingProps, DOMProps, GlobalDOMAttributes, LinkDOMProps} from '@react-types/shared';
|
|
14
|
-
|
|
15
|
-
const DOMPropNames = new Set([
|
|
16
|
-
'id'
|
|
17
|
-
]);
|
|
18
|
-
|
|
19
|
-
const labelablePropNames = new Set([
|
|
20
|
-
'aria-label',
|
|
21
|
-
'aria-labelledby',
|
|
22
|
-
'aria-describedby',
|
|
23
|
-
'aria-details'
|
|
24
|
-
]);
|
|
25
|
-
|
|
26
|
-
// See LinkDOMProps in dom.d.ts.
|
|
27
|
-
const linkPropNames = new Set([
|
|
28
|
-
'href',
|
|
29
|
-
'hrefLang',
|
|
30
|
-
'target',
|
|
31
|
-
'rel',
|
|
32
|
-
'download',
|
|
33
|
-
'ping',
|
|
34
|
-
'referrerPolicy'
|
|
35
|
-
]);
|
|
36
|
-
|
|
37
|
-
const globalAttrs = new Set([
|
|
38
|
-
'dir',
|
|
39
|
-
'lang',
|
|
40
|
-
'hidden',
|
|
41
|
-
'inert',
|
|
42
|
-
'translate'
|
|
43
|
-
]);
|
|
44
|
-
|
|
45
|
-
const globalEvents = new Set([
|
|
46
|
-
'onClick',
|
|
47
|
-
'onAuxClick',
|
|
48
|
-
'onContextMenu',
|
|
49
|
-
'onDoubleClick',
|
|
50
|
-
'onMouseDown',
|
|
51
|
-
'onMouseEnter',
|
|
52
|
-
'onMouseLeave',
|
|
53
|
-
'onMouseMove',
|
|
54
|
-
'onMouseOut',
|
|
55
|
-
'onMouseOver',
|
|
56
|
-
'onMouseUp',
|
|
57
|
-
'onTouchCancel',
|
|
58
|
-
'onTouchEnd',
|
|
59
|
-
'onTouchMove',
|
|
60
|
-
'onTouchStart',
|
|
61
|
-
'onPointerDown',
|
|
62
|
-
'onPointerMove',
|
|
63
|
-
'onPointerUp',
|
|
64
|
-
'onPointerCancel',
|
|
65
|
-
'onPointerEnter',
|
|
66
|
-
'onPointerLeave',
|
|
67
|
-
'onPointerOver',
|
|
68
|
-
'onPointerOut',
|
|
69
|
-
'onGotPointerCapture',
|
|
70
|
-
'onLostPointerCapture',
|
|
71
|
-
'onScroll',
|
|
72
|
-
'onWheel',
|
|
73
|
-
'onAnimationStart',
|
|
74
|
-
'onAnimationEnd',
|
|
75
|
-
'onAnimationIteration',
|
|
76
|
-
'onTransitionCancel',
|
|
77
|
-
'onTransitionEnd',
|
|
78
|
-
'onTransitionRun',
|
|
79
|
-
'onTransitionStart'
|
|
80
|
-
]);
|
|
81
|
-
|
|
82
|
-
interface Options {
|
|
83
|
-
/**
|
|
84
|
-
* If labelling associated aria properties should be included in the filter.
|
|
85
|
-
*/
|
|
86
|
-
labelable?: boolean,
|
|
87
|
-
/** Whether the element is a link and should include DOM props for <a> elements. */
|
|
88
|
-
isLink?: boolean,
|
|
89
|
-
/** Whether to include global DOM attributes. */
|
|
90
|
-
global?: boolean,
|
|
91
|
-
/** Whether to include DOM events. */
|
|
92
|
-
events?: boolean,
|
|
93
|
-
/**
|
|
94
|
-
* A Set of other property names that should be included in the filter.
|
|
95
|
-
*/
|
|
96
|
-
propNames?: Set<string>
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const propRe = /^(data-.*)$/;
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Filters out all props that aren't valid DOM props or defined via override prop obj.
|
|
103
|
-
* @param props - The component props to be filtered.
|
|
104
|
-
* @param opts - Props to override.
|
|
105
|
-
*/
|
|
106
|
-
export function filterDOMProps(props: DOMProps & AriaLabelingProps & LinkDOMProps & GlobalDOMAttributes, opts: Options = {}): DOMProps & AriaLabelingProps & GlobalDOMAttributes {
|
|
107
|
-
let {labelable, isLink, global, events = global, propNames} = opts;
|
|
108
|
-
let filteredProps = {};
|
|
109
|
-
|
|
110
|
-
for (const prop in props) {
|
|
111
|
-
if (
|
|
112
|
-
Object.prototype.hasOwnProperty.call(props, prop) && (
|
|
113
|
-
DOMPropNames.has(prop) ||
|
|
114
|
-
(labelable && labelablePropNames.has(prop)) ||
|
|
115
|
-
(isLink && linkPropNames.has(prop)) ||
|
|
116
|
-
(global && globalAttrs.has(prop)) ||
|
|
117
|
-
(events && (globalEvents.has(prop) || (prop.endsWith('Capture') && globalEvents.has(prop.slice(0, -7))))) ||
|
|
118
|
-
propNames?.has(prop) ||
|
|
119
|
-
propRe.test(prop)
|
|
120
|
-
)
|
|
121
|
-
) {
|
|
122
|
-
filteredProps[prop] = props[prop];
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return filteredProps;
|
|
127
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import {FocusableElement} from '@react-types/shared';
|
|
14
|
-
|
|
15
|
-
// This is a polyfill for element.focus({preventScroll: true});
|
|
16
|
-
// Currently necessary for Safari and old Edge:
|
|
17
|
-
// https://caniuse.com/#feat=mdn-api_htmlelement_focus_preventscroll_option
|
|
18
|
-
// See https://bugs.webkit.org/show_bug.cgi?id=178583
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
// Original licensing for the following methods can be found in the
|
|
22
|
-
// NOTICE file in the root directory of this source tree.
|
|
23
|
-
// See https://github.com/calvellido/focus-options-polyfill
|
|
24
|
-
|
|
25
|
-
interface ScrollableElement {
|
|
26
|
-
element: HTMLElement,
|
|
27
|
-
scrollTop: number,
|
|
28
|
-
scrollLeft: number
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function focusWithoutScrolling(element: FocusableElement): void {
|
|
32
|
-
if (supportsPreventScroll()) {
|
|
33
|
-
element.focus({preventScroll: true});
|
|
34
|
-
} else {
|
|
35
|
-
let scrollableElements = getScrollableElements(element);
|
|
36
|
-
element.focus();
|
|
37
|
-
restoreScrollPosition(scrollableElements);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
let supportsPreventScrollCached: boolean | null = null;
|
|
42
|
-
function supportsPreventScroll() {
|
|
43
|
-
if (supportsPreventScrollCached == null) {
|
|
44
|
-
supportsPreventScrollCached = false;
|
|
45
|
-
try {
|
|
46
|
-
let focusElem = document.createElement('div');
|
|
47
|
-
focusElem.focus({
|
|
48
|
-
get preventScroll() {
|
|
49
|
-
supportsPreventScrollCached = true;
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
} catch {
|
|
54
|
-
// Ignore
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return supportsPreventScrollCached;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function getScrollableElements(element: FocusableElement): ScrollableElement[] {
|
|
62
|
-
let parent = element.parentNode;
|
|
63
|
-
let scrollableElements: ScrollableElement[] = [];
|
|
64
|
-
let rootScrollingElement = document.scrollingElement || document.documentElement;
|
|
65
|
-
|
|
66
|
-
while (parent instanceof HTMLElement && parent !== rootScrollingElement) {
|
|
67
|
-
if (
|
|
68
|
-
parent.offsetHeight < parent.scrollHeight ||
|
|
69
|
-
parent.offsetWidth < parent.scrollWidth
|
|
70
|
-
) {
|
|
71
|
-
scrollableElements.push({
|
|
72
|
-
element: parent,
|
|
73
|
-
scrollTop: parent.scrollTop,
|
|
74
|
-
scrollLeft: parent.scrollLeft
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
parent = parent.parentNode;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (rootScrollingElement instanceof HTMLElement) {
|
|
81
|
-
scrollableElements.push({
|
|
82
|
-
element: rootScrollingElement,
|
|
83
|
-
scrollTop: rootScrollingElement.scrollTop,
|
|
84
|
-
scrollLeft: rootScrollingElement.scrollLeft
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return scrollableElements;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function restoreScrollPosition(scrollableElements: ScrollableElement[]) {
|
|
92
|
-
for (let {element, scrollTop, scrollLeft} of scrollableElements) {
|
|
93
|
-
element.scrollTop = scrollTop;
|
|
94
|
-
element.scrollLeft = scrollLeft;
|
|
95
|
-
}
|
|
96
|
-
}
|