@react-aria/utils 3.33.1 → 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 -115
- 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 -57
- package/dist/DOMFunctions.main.js.map +0 -1
- package/dist/DOMFunctions.mjs +0 -49
- package/dist/DOMFunctions.module.js +0 -49
- 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 -31
- package/dist/getScrollParents.main.js.map +0 -1
- package/dist/getScrollParents.mjs +0 -26
- package/dist/getScrollParents.module.js +0 -26
- 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 -29
- package/dist/isScrollable.main.js.map +0 -1
- package/dist/isScrollable.mjs +0 -24
- package/dist/isScrollable.module.js +0 -24
- 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 -97
- package/dist/runAfterTransition.main.js.map +0 -1
- package/dist/runAfterTransition.mjs +0 -92
- package/dist/runAfterTransition.module.js +0 -92
- package/dist/runAfterTransition.module.js.map +0 -1
- package/dist/scrollIntoView.main.js +0 -138
- package/dist/scrollIntoView.main.js.map +0 -1
- package/dist/scrollIntoView.mjs +0 -132
- package/dist/scrollIntoView.module.js +0 -132
- package/dist/scrollIntoView.module.js.map +0 -1
- package/dist/types.d.ts +0 -299
- 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 -84
- package/dist/useViewportSize.main.js.map +0 -1
- package/dist/useViewportSize.mjs +0 -79
- package/dist/useViewportSize.module.js +0 -79
- 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 -27
- package/src/inertValue.ts +0 -11
- package/src/isElementVisible.ts +0 -75
- package/src/isFocusable.ts +0 -56
- package/src/isScrollable.ts +0 -31
- 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 -124
- package/src/scrollIntoView.ts +0 -168
- package/src/shadowdom/DOMFunctions.ts +0 -100
- 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 -103
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
|
-
}
|
package/src/getOffset.ts
DELETED
|
@@ -1,21 +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 {Orientation} from '@react-types/shared';
|
|
14
|
-
|
|
15
|
-
export function getOffset(element: HTMLElement, reverse?: boolean, orientation: Orientation = 'horizontal'): number {
|
|
16
|
-
let rect = element.getBoundingClientRect();
|
|
17
|
-
if (reverse) {
|
|
18
|
-
return orientation === 'horizontal' ? rect.right : rect.bottom;
|
|
19
|
-
}
|
|
20
|
-
return orientation === 'horizontal' ? rect.left : rect.top;
|
|
21
|
-
}
|
package/src/getScrollParent.ts
DELETED
|
@@ -1,27 +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 {isScrollable} from './isScrollable';
|
|
14
|
-
|
|
15
|
-
export function getScrollParent(node: Element, checkForOverflow?: boolean): Element {
|
|
16
|
-
let scrollableNode: Element | null = node;
|
|
17
|
-
if (isScrollable(scrollableNode, checkForOverflow)) {
|
|
18
|
-
scrollableNode = scrollableNode.parentElement;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
while (scrollableNode && !isScrollable(scrollableNode, checkForOverflow)) {
|
|
22
|
-
scrollableNode = scrollableNode.parentElement;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return scrollableNode || document.scrollingElement || document.documentElement;
|
|
26
|
-
}
|
|
27
|
-
|
package/src/getScrollParents.ts
DELETED
|
@@ -1,27 +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
|
-
import {isScrollable} from './isScrollable';
|
|
14
|
-
|
|
15
|
-
export function getScrollParents(node: Element, checkForOverflow?: boolean): Element[] {
|
|
16
|
-
let parentElements: Element[] = [];
|
|
17
|
-
let root = document.scrollingElement || document.documentElement;
|
|
18
|
-
|
|
19
|
-
do {
|
|
20
|
-
if (isScrollable(node, checkForOverflow)) {
|
|
21
|
-
parentElements.push(node);
|
|
22
|
-
}
|
|
23
|
-
node = node.parentElement as Element;
|
|
24
|
-
} while (node && node !== root);
|
|
25
|
-
|
|
26
|
-
return parentElements;
|
|
27
|
-
}
|
package/src/inertValue.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {version} from 'react';
|
|
2
|
-
|
|
3
|
-
export function inertValue(value?: boolean): string | boolean | undefined {
|
|
4
|
-
const pieces = version.split('.');
|
|
5
|
-
const major = parseInt(pieces[0], 10);
|
|
6
|
-
if (major >= 19) {
|
|
7
|
-
return value;
|
|
8
|
-
}
|
|
9
|
-
// compatibility with React < 19
|
|
10
|
-
return value ? 'true' : undefined;
|
|
11
|
-
}
|
package/src/isElementVisible.ts
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2021 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 {getOwnerWindow} from './domHelpers';
|
|
14
|
-
|
|
15
|
-
const supportsCheckVisibility = typeof Element !== 'undefined' && 'checkVisibility' in Element.prototype;
|
|
16
|
-
|
|
17
|
-
function isStyleVisible(element: Element) {
|
|
18
|
-
const windowObject = getOwnerWindow(element);
|
|
19
|
-
if (!(element instanceof windowObject.HTMLElement) && !(element instanceof windowObject.SVGElement)) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
let {display, visibility} = element.style;
|
|
24
|
-
|
|
25
|
-
let isVisible = (
|
|
26
|
-
display !== 'none' &&
|
|
27
|
-
visibility !== 'hidden' &&
|
|
28
|
-
visibility !== 'collapse'
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
if (isVisible) {
|
|
32
|
-
const {getComputedStyle} = element.ownerDocument.defaultView as unknown as Window;
|
|
33
|
-
let {display: computedDisplay, visibility: computedVisibility} = getComputedStyle(element);
|
|
34
|
-
|
|
35
|
-
isVisible = (
|
|
36
|
-
computedDisplay !== 'none' &&
|
|
37
|
-
computedVisibility !== 'hidden' &&
|
|
38
|
-
computedVisibility !== 'collapse'
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return isVisible;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function isAttributeVisible(element: Element, childElement?: Element) {
|
|
46
|
-
return (
|
|
47
|
-
!element.hasAttribute('hidden') &&
|
|
48
|
-
// Ignore HiddenSelect when tree walking.
|
|
49
|
-
!element.hasAttribute('data-react-aria-prevent-focus') &&
|
|
50
|
-
(element.nodeName === 'DETAILS' &&
|
|
51
|
-
childElement &&
|
|
52
|
-
childElement.nodeName !== 'SUMMARY'
|
|
53
|
-
? element.hasAttribute('open')
|
|
54
|
-
: true)
|
|
55
|
-
);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Adapted from https://github.com/testing-library/jest-dom and
|
|
60
|
-
* https://github.com/vuejs/vue-test-utils-next/.
|
|
61
|
-
* Licensed under the MIT License.
|
|
62
|
-
* @param element - Element to evaluate for display or visibility.
|
|
63
|
-
*/
|
|
64
|
-
export function isElementVisible(element: Element, childElement?: Element): boolean {
|
|
65
|
-
if (supportsCheckVisibility) {
|
|
66
|
-
return element.checkVisibility({visibilityProperty: true}) && !element.closest('[data-react-aria-prevent-focus]');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return (
|
|
70
|
-
element.nodeName !== '#comment' &&
|
|
71
|
-
isStyleVisible(element) &&
|
|
72
|
-
isAttributeVisible(element, childElement) &&
|
|
73
|
-
(!element.parentElement || isElementVisible(element.parentElement, element))
|
|
74
|
-
);
|
|
75
|
-
}
|
package/src/isFocusable.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2025 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 {isElementVisible} from './isElementVisible';
|
|
14
|
-
|
|
15
|
-
const focusableElements = [
|
|
16
|
-
'input:not([disabled]):not([type=hidden])',
|
|
17
|
-
'select:not([disabled])',
|
|
18
|
-
'textarea:not([disabled])',
|
|
19
|
-
'button:not([disabled])',
|
|
20
|
-
'a[href]',
|
|
21
|
-
'area[href]',
|
|
22
|
-
'summary',
|
|
23
|
-
'iframe',
|
|
24
|
-
'object',
|
|
25
|
-
'embed',
|
|
26
|
-
'audio[controls]',
|
|
27
|
-
'video[controls]',
|
|
28
|
-
'[contenteditable]:not([contenteditable^="false"])',
|
|
29
|
-
'permission'
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
const FOCUSABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]),') + ',[tabindex]:not([disabled]):not([hidden])';
|
|
33
|
-
|
|
34
|
-
focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
|
|
35
|
-
const TABBABLE_ELEMENT_SELECTOR = focusableElements.join(':not([hidden]):not([tabindex="-1"]),');
|
|
36
|
-
|
|
37
|
-
export function isFocusable(element: Element): boolean {
|
|
38
|
-
return element.matches(FOCUSABLE_ELEMENT_SELECTOR) && isElementVisible(element) && !isInert(element);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function isTabbable(element: Element): boolean {
|
|
42
|
-
return element.matches(TABBABLE_ELEMENT_SELECTOR) && isElementVisible(element) && !isInert(element);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function isInert(element: Element): boolean {
|
|
46
|
-
let node: Element | null = element;
|
|
47
|
-
while (node != null) {
|
|
48
|
-
if (node instanceof node.ownerDocument.defaultView!.HTMLElement && node.inert) {
|
|
49
|
-
return true;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
node = node.parentElement;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return false;
|
|
56
|
-
}
|
package/src/isScrollable.ts
DELETED
|
@@ -1,31 +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
|
-
export function isScrollable(node: Element | null, checkForOverflow?: boolean): boolean {
|
|
14
|
-
if (!node) {
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
let style = window.getComputedStyle(node);
|
|
18
|
-
let root = document.scrollingElement || document.documentElement;
|
|
19
|
-
let isScrollable = /(auto|scroll)/.test(style.overflow + style.overflowX + style.overflowY);
|
|
20
|
-
|
|
21
|
-
// Root element has `visible` overflow by default, but is scrollable nonetheless.
|
|
22
|
-
if (node === root && style.overflow !== 'hidden') {
|
|
23
|
-
isScrollable = true;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (isScrollable && checkForOverflow) {
|
|
27
|
-
isScrollable = node.scrollHeight !== node.clientHeight || node.scrollWidth !== node.clientWidth;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return isScrollable;
|
|
31
|
-
}
|
package/src/isVirtualEvent.ts
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2022 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 {isAndroid} from './platform';
|
|
14
|
-
|
|
15
|
-
// Original licensing for the following method can be found in the
|
|
16
|
-
// NOTICE file in the root directory of this source tree.
|
|
17
|
-
// See https://github.com/facebook/react/blob/3c713d513195a53788b3f8bb4b70279d68b15bcc/packages/react-interactions/events/src/dom/shared/index.js#L74-L87
|
|
18
|
-
|
|
19
|
-
// Keyboards, Assistive Technologies, and element.click() all produce a "virtual"
|
|
20
|
-
// click event. This is a method of inferring such clicks. Every browser except
|
|
21
|
-
// IE 11 only sets a zero value of "detail" for click events that are "virtual".
|
|
22
|
-
// However, IE 11 uses a zero value for all click events. For IE 11 we rely on
|
|
23
|
-
// the quirk that it produces click events that are of type PointerEvent, and
|
|
24
|
-
// where only the "virtual" click lacks a pointerType field.
|
|
25
|
-
|
|
26
|
-
export function isVirtualClick(event: MouseEvent | PointerEvent): boolean {
|
|
27
|
-
// JAWS/NVDA with Firefox.
|
|
28
|
-
if ((event as PointerEvent).pointerType === '' && event.isTrusted) {
|
|
29
|
-
return true;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// Android TalkBack's detail value varies depending on the event listener providing the event so we have specific logic here instead
|
|
33
|
-
// If pointerType is defined, event is from a click listener. For events from mousedown listener, detail === 0 is a sufficient check
|
|
34
|
-
// to detect TalkBack virtual clicks.
|
|
35
|
-
if (isAndroid() && (event as PointerEvent).pointerType) {
|
|
36
|
-
return event.type === 'click' && event.buttons === 1;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return event.detail === 0 && !(event as PointerEvent).pointerType;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export function isVirtualPointerEvent(event: PointerEvent): boolean {
|
|
43
|
-
// If the pointer size is zero, then we assume it's from a screen reader.
|
|
44
|
-
// Android TalkBack double tap will sometimes return a event with width and height of 1
|
|
45
|
-
// and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
|
|
46
|
-
// Cannot use "event.pressure === 0" as the sole check due to Safari pointer events always returning pressure === 0
|
|
47
|
-
// instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216. event.pointerType === 'mouse' is to distingush
|
|
48
|
-
// Talkback double tap from Windows Firefox touch screen press
|
|
49
|
-
return (
|
|
50
|
-
(!isAndroid() && event.width === 0 && event.height === 0) ||
|
|
51
|
-
(event.width === 1 &&
|
|
52
|
-
event.height === 1 &&
|
|
53
|
-
event.pressure === 0 &&
|
|
54
|
-
event.detail === 0 &&
|
|
55
|
-
event.pointerType === 'mouse'
|
|
56
|
-
)
|
|
57
|
-
);
|
|
58
|
-
}
|
package/src/keyboard.tsx
DELETED
|
@@ -1,48 +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
|
-
import {isMac} from './platform';
|
|
14
|
-
|
|
15
|
-
interface Event {
|
|
16
|
-
altKey: boolean,
|
|
17
|
-
ctrlKey: boolean,
|
|
18
|
-
metaKey: boolean
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function isCtrlKeyPressed(e: Event): boolean {
|
|
22
|
-
if (isMac()) {
|
|
23
|
-
return e.metaKey;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return e.ctrlKey;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// HTML input types that do not cause the software keyboard to appear.
|
|
30
|
-
const nonTextInputTypes = new Set([
|
|
31
|
-
'checkbox',
|
|
32
|
-
'radio',
|
|
33
|
-
'range',
|
|
34
|
-
'color',
|
|
35
|
-
'file',
|
|
36
|
-
'image',
|
|
37
|
-
'button',
|
|
38
|
-
'submit',
|
|
39
|
-
'reset'
|
|
40
|
-
]);
|
|
41
|
-
|
|
42
|
-
export function willOpenKeyboard(target: Element) {
|
|
43
|
-
return (
|
|
44
|
-
(target instanceof HTMLInputElement && !nonTextInputTypes.has(target.type)) ||
|
|
45
|
-
target instanceof HTMLTextAreaElement ||
|
|
46
|
-
(target instanceof HTMLElement && target.isContentEditable)
|
|
47
|
-
);
|
|
48
|
-
}
|
package/src/mergeProps.ts
DELETED
|
@@ -1,77 +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 {chain} from './chain';
|
|
14
|
-
import clsx from 'clsx';
|
|
15
|
-
import {mergeIds} from './useId';
|
|
16
|
-
import {mergeRefs} from './mergeRefs';
|
|
17
|
-
|
|
18
|
-
interface Props {
|
|
19
|
-
[key: string]: any
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
type PropsArg = Props | null | undefined;
|
|
23
|
-
|
|
24
|
-
// taken from: https://stackoverflow.com/questions/51603250/typescript-3-parameter-list-intersection-type/51604379#51604379
|
|
25
|
-
type TupleTypes<T> = { [P in keyof T]: T[P] } extends { [key: number]: infer V } ? NullToObject<V> : never;
|
|
26
|
-
type NullToObject<T> = T extends (null | undefined) ? {} : T;
|
|
27
|
-
|
|
28
|
-
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Merges multiple props objects together. Event handlers are chained,
|
|
32
|
-
* classNames are combined, ids are deduplicated, and refs are merged.
|
|
33
|
-
* For all other props, the last prop object overrides all previous ones.
|
|
34
|
-
* @param args - Multiple sets of props to merge together.
|
|
35
|
-
*/
|
|
36
|
-
export function mergeProps<T extends PropsArg[]>(...args: T): UnionToIntersection<TupleTypes<T>> {
|
|
37
|
-
// Start with a base clone of the first argument. This is a lot faster than starting
|
|
38
|
-
// with an empty object and adding properties as we go.
|
|
39
|
-
let result: Props = {...args[0]};
|
|
40
|
-
for (let i = 1; i < args.length; i++) {
|
|
41
|
-
let props = args[i];
|
|
42
|
-
for (let key in props) {
|
|
43
|
-
let a = result[key];
|
|
44
|
-
let b = props[key];
|
|
45
|
-
|
|
46
|
-
// Chain events
|
|
47
|
-
if (
|
|
48
|
-
typeof a === 'function' &&
|
|
49
|
-
typeof b === 'function' &&
|
|
50
|
-
// This is a lot faster than a regex.
|
|
51
|
-
key[0] === 'o' &&
|
|
52
|
-
key[1] === 'n' &&
|
|
53
|
-
key.charCodeAt(2) >= /* 'A' */ 65 &&
|
|
54
|
-
key.charCodeAt(2) <= /* 'Z' */ 90
|
|
55
|
-
) {
|
|
56
|
-
result[key] = chain(a, b);
|
|
57
|
-
|
|
58
|
-
// Merge classnames, sometimes classNames are empty string which eval to false, so we just need to do a type check
|
|
59
|
-
} else if (
|
|
60
|
-
(key === 'className' || key === 'UNSAFE_className') &&
|
|
61
|
-
typeof a === 'string' &&
|
|
62
|
-
typeof b === 'string'
|
|
63
|
-
) {
|
|
64
|
-
result[key] = clsx(a, b);
|
|
65
|
-
} else if (key === 'id' && a && b) {
|
|
66
|
-
result.id = mergeIds(a, b);
|
|
67
|
-
} else if (key === 'ref' && a && b) {
|
|
68
|
-
result.ref = mergeRefs(a, b);
|
|
69
|
-
// Override others
|
|
70
|
-
} else {
|
|
71
|
-
result[key] = b !== undefined ? b : a;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return result as UnionToIntersection<TupleTypes<T>>;
|
|
77
|
-
}
|