@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
package/src/useValueEffect.ts
DELETED
|
@@ -1,68 +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 {Dispatch, RefObject, useCallback, useRef, useState} from 'react';
|
|
14
|
-
import {useLayoutEffect} from './';
|
|
15
|
-
|
|
16
|
-
type SetValueAction<S> = (prev: S) => Generator<any, void, unknown>;
|
|
17
|
-
|
|
18
|
-
// This hook works like `useState`, but when setting the value, you pass a generator function
|
|
19
|
-
// that can yield multiple values. Each yielded value updates the state and waits for the next
|
|
20
|
-
// layout effect, then continues the generator. This allows sequential updates to state to be
|
|
21
|
-
// written linearly.
|
|
22
|
-
export function useValueEffect<S>(defaultValue: S | (() => S)): [S, Dispatch<SetValueAction<S>>] {
|
|
23
|
-
let [value, setValue] = 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 = useRef(value);
|
|
27
|
-
let effect: RefObject<Generator<S> | null> = useRef<Generator<S> | null>(null);
|
|
28
|
-
|
|
29
|
-
// Store the function in a ref so we can always access the current version
|
|
30
|
-
// which has the proper `value` in scope.
|
|
31
|
-
let nextRef = useRef(() => {
|
|
32
|
-
if (!effect.current) {
|
|
33
|
-
return;
|
|
34
|
-
}
|
|
35
|
-
// Run the generator to the next yield.
|
|
36
|
-
let newValue = effect.current.next();
|
|
37
|
-
|
|
38
|
-
// If the generator is done, reset the effect.
|
|
39
|
-
if (newValue.done) {
|
|
40
|
-
effect.current = null;
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// If the value is the same as the current value,
|
|
45
|
-
// then continue to the next yield. Otherwise,
|
|
46
|
-
// set the value in state and wait for the next layout effect.
|
|
47
|
-
if (currValue.current === newValue.value) {
|
|
48
|
-
nextRef.current();
|
|
49
|
-
} else {
|
|
50
|
-
setValue(newValue.value);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
useLayoutEffect(() => {
|
|
55
|
-
currValue.current = value;
|
|
56
|
-
// If there is an effect currently running, continue to the next yield.
|
|
57
|
-
if (effect.current) {
|
|
58
|
-
nextRef.current();
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
let queue = useCallback(fn => {
|
|
63
|
-
effect.current = fn(currValue.current);
|
|
64
|
-
nextRef.current();
|
|
65
|
-
}, [nextRef]);
|
|
66
|
-
|
|
67
|
-
return [value, queue];
|
|
68
|
-
}
|
package/src/useViewportSize.ts
DELETED
|
@@ -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 {useEffect, useState} from 'react';
|
|
14
|
-
import {useIsSSR} from '@react-aria/ssr';
|
|
15
|
-
import {willOpenKeyboard} from './keyboard';
|
|
16
|
-
|
|
17
|
-
interface ViewportSize {
|
|
18
|
-
width: number,
|
|
19
|
-
height: number
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let visualViewport = typeof document !== 'undefined' && window.visualViewport;
|
|
23
|
-
|
|
24
|
-
export function useViewportSize(): ViewportSize {
|
|
25
|
-
let isSSR = useIsSSR();
|
|
26
|
-
let [size, setSize] = useState(() => isSSR ? {width: 0, height: 0} : getViewportSize());
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
let updateSize = (newSize: ViewportSize) => {
|
|
30
|
-
setSize(size => {
|
|
31
|
-
if (newSize.width === size.width && newSize.height === size.height) {
|
|
32
|
-
return size;
|
|
33
|
-
}
|
|
34
|
-
return newSize;
|
|
35
|
-
});
|
|
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 (visualViewport && visualViewport.scale > 1) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
updateSize(getViewportSize());
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// When closing the keyboard, iOS does not fire the visual viewport resize event until the animation is complete.
|
|
49
|
-
// We can anticipate this and resize early by handling the blur event and using the layout size.
|
|
50
|
-
let frame: number;
|
|
51
|
-
let onBlur = (e: FocusEvent) => {
|
|
52
|
-
if (visualViewport && visualViewport.scale > 1) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (willOpenKeyboard(e.target as Element)) {
|
|
57
|
-
// Wait one frame to see if a new element gets focused.
|
|
58
|
-
frame = requestAnimationFrame(() => {
|
|
59
|
-
if (!document.activeElement || !willOpenKeyboard(document.activeElement)) {
|
|
60
|
-
updateSize({width: document.documentElement.clientWidth, height: document.documentElement.clientHeight});
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
updateSize(getViewportSize());
|
|
67
|
-
|
|
68
|
-
window.addEventListener('blur', onBlur, true);
|
|
69
|
-
|
|
70
|
-
if (!visualViewport) {
|
|
71
|
-
window.addEventListener('resize', onResize);
|
|
72
|
-
} else {
|
|
73
|
-
visualViewport.addEventListener('resize', onResize);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return () => {
|
|
77
|
-
cancelAnimationFrame(frame);
|
|
78
|
-
window.removeEventListener('blur', onBlur, true);
|
|
79
|
-
if (!visualViewport) {
|
|
80
|
-
window.removeEventListener('resize', onResize);
|
|
81
|
-
} else {
|
|
82
|
-
visualViewport.removeEventListener('resize', onResize);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
}, []);
|
|
86
|
-
|
|
87
|
-
return size;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function getViewportSize(): ViewportSize {
|
|
91
|
-
return {
|
|
92
|
-
// Multiply by the visualViewport scale to get the "natural" size, unaffected by pinch zooming.
|
|
93
|
-
width: visualViewport ? visualViewport.width * visualViewport.scale : document.documentElement.clientWidth,
|
|
94
|
-
height: visualViewport ? visualViewport.height * visualViewport.scale : document.documentElement.clientHeight
|
|
95
|
-
};
|
|
96
|
-
}
|