@react-aria/interactions 3.22.5 → 3.24.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/Pressable.main.js +28 -4
- package/dist/Pressable.main.js.map +1 -1
- package/dist/Pressable.mjs +30 -6
- package/dist/Pressable.module.js +30 -6
- package/dist/Pressable.module.js.map +1 -1
- package/dist/createEventHandler.main.js +5 -1
- package/dist/createEventHandler.main.js.map +1 -1
- package/dist/createEventHandler.mjs +5 -1
- package/dist/createEventHandler.module.js +5 -1
- package/dist/createEventHandler.module.js.map +1 -1
- package/dist/focusSafely.main.js +40 -0
- package/dist/focusSafely.main.js.map +1 -0
- package/dist/focusSafely.mjs +35 -0
- package/dist/focusSafely.module.js +35 -0
- package/dist/focusSafely.module.js.map +1 -0
- package/dist/import.mjs +5 -1
- package/dist/main.js +9 -0
- package/dist/main.js.map +1 -1
- package/dist/module.js +5 -1
- package/dist/module.js.map +1 -1
- package/dist/textSelection.main.js +5 -3
- package/dist/textSelection.main.js.map +1 -1
- package/dist/textSelection.mjs +5 -3
- package/dist/textSelection.module.js +5 -3
- package/dist/textSelection.module.js.map +1 -1
- package/dist/types.d.ts +59 -25
- package/dist/types.d.ts.map +1 -1
- package/dist/useFocus.main.js +2 -1
- package/dist/useFocus.main.js.map +1 -1
- package/dist/useFocus.mjs +3 -2
- package/dist/useFocus.module.js +3 -2
- package/dist/useFocus.module.js.map +1 -1
- package/dist/useFocusVisible.main.js +9 -3
- package/dist/useFocusVisible.main.js.map +1 -1
- package/dist/useFocusVisible.mjs +9 -3
- package/dist/useFocusVisible.module.js +9 -3
- package/dist/useFocusVisible.module.js.map +1 -1
- package/dist/useFocusWithin.main.js +33 -4
- package/dist/useFocusWithin.main.js.map +1 -1
- package/dist/useFocusWithin.mjs +34 -5
- package/dist/useFocusWithin.module.js +34 -5
- package/dist/useFocusWithin.module.js.map +1 -1
- package/dist/useFocusable.main.js +112 -0
- package/dist/useFocusable.main.js.map +1 -0
- package/dist/useFocusable.mjs +100 -0
- package/dist/useFocusable.module.js +100 -0
- package/dist/useFocusable.module.js.map +1 -0
- package/dist/useHover.main.js +18 -3
- package/dist/useHover.main.js.map +1 -1
- package/dist/useHover.mjs +18 -3
- package/dist/useHover.module.js +18 -3
- package/dist/useHover.module.js.map +1 -1
- package/dist/useInteractOutside.main.js +6 -1
- package/dist/useInteractOutside.main.js.map +1 -1
- package/dist/useInteractOutside.mjs +6 -1
- package/dist/useInteractOutside.module.js +6 -1
- package/dist/useInteractOutside.module.js.map +1 -1
- package/dist/useLongPress.main.js +2 -0
- package/dist/useLongPress.main.js.map +1 -1
- package/dist/useLongPress.mjs +3 -1
- package/dist/useLongPress.module.js +3 -1
- package/dist/useLongPress.module.js.map +1 -1
- package/dist/usePress.main.js +97 -94
- package/dist/usePress.main.js.map +1 -1
- package/dist/usePress.mjs +98 -95
- package/dist/usePress.module.js +98 -95
- package/dist/usePress.module.js.map +1 -1
- package/dist/utils.main.js +57 -1
- package/dist/utils.main.js.map +1 -1
- package/dist/utils.mjs +55 -2
- package/dist/utils.module.js +55 -2
- package/dist/utils.module.js.map +1 -1
- package/package.json +7 -5
- package/src/Pressable.tsx +66 -6
- package/src/createEventHandler.ts +8 -1
- package/src/focusSafely.ts +45 -0
- package/src/index.ts +3 -0
- package/src/textSelection.ts +6 -4
- package/src/useFocus.ts +3 -3
- package/src/useFocusVisible.ts +14 -4
- package/src/useFocusWithin.ts +34 -5
- package/src/useFocusable.tsx +183 -0
- package/src/useHover.ts +17 -3
- package/src/useInteractOutside.ts +9 -3
- package/src/useLongPress.ts +8 -2
- package/src/usePress.ts +132 -131
- package/src/utils.ts +80 -1
- package/src/DOMPropsContext.ts +0 -39
- package/src/DOMPropsResponder.tsx +0 -47
- package/src/useDOMPropsResponder.ts +0 -27
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {focusSafely as $3ad3f6e1647bc98d$export$80f3e147d781571c} from "./focusSafely.mjs";
|
|
2
|
+
import {useFocus as $a1ea59d68270f0dd$export$f8168d8dd8fd66e6} from "./useFocus.mjs";
|
|
3
|
+
import {useKeyboard as $46d819fcbaf35654$export$8f71654801c2f7cd} from "./useKeyboard.mjs";
|
|
4
|
+
import {useSyncRef as $fcPuG$useSyncRef, useObjectRef as $fcPuG$useObjectRef, mergeProps as $fcPuG$mergeProps, getOwnerWindow as $fcPuG$getOwnerWindow, isFocusable as $fcPuG$isFocusable, mergeRefs as $fcPuG$mergeRefs} from "@react-aria/utils";
|
|
5
|
+
import $fcPuG$react, {useContext as $fcPuG$useContext, useRef as $fcPuG$useRef, useEffect as $fcPuG$useEffect, forwardRef as $fcPuG$forwardRef} from "react";
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
9
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
11
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
14
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
15
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
16
|
+
* governing permissions and limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
let $f645667febf57a63$export$f9762fab77588ecb = /*#__PURE__*/ (0, $fcPuG$react).createContext(null);
|
|
23
|
+
function $f645667febf57a63$var$useFocusableContext(ref) {
|
|
24
|
+
let context = (0, $fcPuG$useContext)($f645667febf57a63$export$f9762fab77588ecb) || {};
|
|
25
|
+
(0, $fcPuG$useSyncRef)(context, ref);
|
|
26
|
+
// eslint-disable-next-line
|
|
27
|
+
let { ref: _, ...otherProps } = context;
|
|
28
|
+
return otherProps;
|
|
29
|
+
}
|
|
30
|
+
const $f645667febf57a63$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, $fcPuG$react).forwardRef(function FocusableProvider(props, ref) {
|
|
31
|
+
let { children: children, ...otherProps } = props;
|
|
32
|
+
let objRef = (0, $fcPuG$useObjectRef)(ref);
|
|
33
|
+
let context = {
|
|
34
|
+
...otherProps,
|
|
35
|
+
ref: objRef
|
|
36
|
+
};
|
|
37
|
+
return /*#__PURE__*/ (0, $fcPuG$react).createElement($f645667febf57a63$export$f9762fab77588ecb.Provider, {
|
|
38
|
+
value: context
|
|
39
|
+
}, children);
|
|
40
|
+
});
|
|
41
|
+
function $f645667febf57a63$export$4c014de7c8940b4c(props, domRef) {
|
|
42
|
+
let { focusProps: focusProps } = (0, $a1ea59d68270f0dd$export$f8168d8dd8fd66e6)(props);
|
|
43
|
+
let { keyboardProps: keyboardProps } = (0, $46d819fcbaf35654$export$8f71654801c2f7cd)(props);
|
|
44
|
+
let interactions = (0, $fcPuG$mergeProps)(focusProps, keyboardProps);
|
|
45
|
+
let domProps = $f645667febf57a63$var$useFocusableContext(domRef);
|
|
46
|
+
let interactionProps = props.isDisabled ? {} : domProps;
|
|
47
|
+
let autoFocusRef = (0, $fcPuG$useRef)(props.autoFocus);
|
|
48
|
+
(0, $fcPuG$useEffect)(()=>{
|
|
49
|
+
if (autoFocusRef.current && domRef.current) (0, $3ad3f6e1647bc98d$export$80f3e147d781571c)(domRef.current);
|
|
50
|
+
autoFocusRef.current = false;
|
|
51
|
+
}, [
|
|
52
|
+
domRef
|
|
53
|
+
]);
|
|
54
|
+
// Always set a tabIndex so that Safari allows focusing native buttons and inputs.
|
|
55
|
+
let tabIndex = props.excludeFromTabOrder ? -1 : 0;
|
|
56
|
+
if (props.isDisabled) tabIndex = undefined;
|
|
57
|
+
return {
|
|
58
|
+
focusableProps: (0, $fcPuG$mergeProps)({
|
|
59
|
+
...interactions,
|
|
60
|
+
tabIndex: tabIndex
|
|
61
|
+
}, interactionProps)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const $f645667febf57a63$export$35a3bebf7ef2d934 = /*#__PURE__*/ (0, $fcPuG$forwardRef)(({ children: children, ...props }, ref)=>{
|
|
65
|
+
ref = (0, $fcPuG$useObjectRef)(ref);
|
|
66
|
+
let { focusableProps: focusableProps } = $f645667febf57a63$export$4c014de7c8940b4c(props, ref);
|
|
67
|
+
let child = (0, $fcPuG$react).Children.only(children);
|
|
68
|
+
(0, $fcPuG$useEffect)(()=>{
|
|
69
|
+
let el = ref.current;
|
|
70
|
+
if (!el || !(el instanceof (0, $fcPuG$getOwnerWindow)(el).Element)) {
|
|
71
|
+
console.error('<Focusable> child must forward its ref to a DOM element.');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (!props.isDisabled && !(0, $fcPuG$isFocusable)(el)) {
|
|
75
|
+
console.warn('<Focusable> child must be focusable. Please ensure the tabIndex prop is passed through.');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (el.localName !== 'button' && el.localName !== 'input' && el.localName !== 'select' && el.localName !== 'textarea' && el.localName !== 'a' && el.localName !== 'area' && el.localName !== 'summary' && el.localName !== 'img' && el.localName !== 'svg') {
|
|
79
|
+
let role = el.getAttribute('role');
|
|
80
|
+
if (!role) console.warn('<Focusable> child must have an interactive ARIA role.');
|
|
81
|
+
else if (// https://w3c.github.io/aria/#widget_roles
|
|
82
|
+
role !== 'application' && role !== 'button' && role !== 'checkbox' && role !== 'combobox' && role !== 'gridcell' && role !== 'link' && role !== 'menuitem' && role !== 'menuitemcheckbox' && role !== 'menuitemradio' && role !== 'option' && role !== 'radio' && role !== 'searchbox' && role !== 'separator' && role !== 'slider' && role !== 'spinbutton' && role !== 'switch' && role !== 'tab' && role !== 'tabpanel' && role !== 'textbox' && role !== 'treeitem' && // aria-describedby is also announced on these roles
|
|
83
|
+
role !== 'img' && role !== 'meter' && role !== 'progressbar') console.warn(`<Focusable> child must have an interactive ARIA role. Got "${role}".`);
|
|
84
|
+
}
|
|
85
|
+
}, [
|
|
86
|
+
ref,
|
|
87
|
+
props.isDisabled
|
|
88
|
+
]);
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
let childRef = parseInt((0, $fcPuG$react).version, 10) < 19 ? child.ref : child.props.ref;
|
|
91
|
+
return /*#__PURE__*/ (0, $fcPuG$react).cloneElement(child, {
|
|
92
|
+
...(0, $fcPuG$mergeProps)(focusableProps, child.props),
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
ref: (0, $fcPuG$mergeRefs)(childRef, ref)
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
export {$f645667febf57a63$export$f9762fab77588ecb as FocusableContext, $f645667febf57a63$export$13f3202a3e5ddd5 as FocusableProvider, $f645667febf57a63$export$4c014de7c8940b4c as useFocusable, $f645667febf57a63$export$35a3bebf7ef2d934 as Focusable};
|
|
100
|
+
//# sourceMappingURL=useFocusable.module.js.map
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import {focusSafely as $3ad3f6e1647bc98d$export$80f3e147d781571c} from "./focusSafely.module.js";
|
|
2
|
+
import {useFocus as $a1ea59d68270f0dd$export$f8168d8dd8fd66e6} from "./useFocus.module.js";
|
|
3
|
+
import {useKeyboard as $46d819fcbaf35654$export$8f71654801c2f7cd} from "./useKeyboard.module.js";
|
|
4
|
+
import {useSyncRef as $fcPuG$useSyncRef, useObjectRef as $fcPuG$useObjectRef, mergeProps as $fcPuG$mergeProps, getOwnerWindow as $fcPuG$getOwnerWindow, isFocusable as $fcPuG$isFocusable, mergeRefs as $fcPuG$mergeRefs} from "@react-aria/utils";
|
|
5
|
+
import $fcPuG$react, {useContext as $fcPuG$useContext, useRef as $fcPuG$useRef, useEffect as $fcPuG$useEffect, forwardRef as $fcPuG$forwardRef} from "react";
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
9
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
11
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
14
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
15
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
16
|
+
* governing permissions and limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
let $f645667febf57a63$export$f9762fab77588ecb = /*#__PURE__*/ (0, $fcPuG$react).createContext(null);
|
|
23
|
+
function $f645667febf57a63$var$useFocusableContext(ref) {
|
|
24
|
+
let context = (0, $fcPuG$useContext)($f645667febf57a63$export$f9762fab77588ecb) || {};
|
|
25
|
+
(0, $fcPuG$useSyncRef)(context, ref);
|
|
26
|
+
// eslint-disable-next-line
|
|
27
|
+
let { ref: _, ...otherProps } = context;
|
|
28
|
+
return otherProps;
|
|
29
|
+
}
|
|
30
|
+
const $f645667febf57a63$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, $fcPuG$react).forwardRef(function FocusableProvider(props, ref) {
|
|
31
|
+
let { children: children, ...otherProps } = props;
|
|
32
|
+
let objRef = (0, $fcPuG$useObjectRef)(ref);
|
|
33
|
+
let context = {
|
|
34
|
+
...otherProps,
|
|
35
|
+
ref: objRef
|
|
36
|
+
};
|
|
37
|
+
return /*#__PURE__*/ (0, $fcPuG$react).createElement($f645667febf57a63$export$f9762fab77588ecb.Provider, {
|
|
38
|
+
value: context
|
|
39
|
+
}, children);
|
|
40
|
+
});
|
|
41
|
+
function $f645667febf57a63$export$4c014de7c8940b4c(props, domRef) {
|
|
42
|
+
let { focusProps: focusProps } = (0, $a1ea59d68270f0dd$export$f8168d8dd8fd66e6)(props);
|
|
43
|
+
let { keyboardProps: keyboardProps } = (0, $46d819fcbaf35654$export$8f71654801c2f7cd)(props);
|
|
44
|
+
let interactions = (0, $fcPuG$mergeProps)(focusProps, keyboardProps);
|
|
45
|
+
let domProps = $f645667febf57a63$var$useFocusableContext(domRef);
|
|
46
|
+
let interactionProps = props.isDisabled ? {} : domProps;
|
|
47
|
+
let autoFocusRef = (0, $fcPuG$useRef)(props.autoFocus);
|
|
48
|
+
(0, $fcPuG$useEffect)(()=>{
|
|
49
|
+
if (autoFocusRef.current && domRef.current) (0, $3ad3f6e1647bc98d$export$80f3e147d781571c)(domRef.current);
|
|
50
|
+
autoFocusRef.current = false;
|
|
51
|
+
}, [
|
|
52
|
+
domRef
|
|
53
|
+
]);
|
|
54
|
+
// Always set a tabIndex so that Safari allows focusing native buttons and inputs.
|
|
55
|
+
let tabIndex = props.excludeFromTabOrder ? -1 : 0;
|
|
56
|
+
if (props.isDisabled) tabIndex = undefined;
|
|
57
|
+
return {
|
|
58
|
+
focusableProps: (0, $fcPuG$mergeProps)({
|
|
59
|
+
...interactions,
|
|
60
|
+
tabIndex: tabIndex
|
|
61
|
+
}, interactionProps)
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const $f645667febf57a63$export$35a3bebf7ef2d934 = /*#__PURE__*/ (0, $fcPuG$forwardRef)(({ children: children, ...props }, ref)=>{
|
|
65
|
+
ref = (0, $fcPuG$useObjectRef)(ref);
|
|
66
|
+
let { focusableProps: focusableProps } = $f645667febf57a63$export$4c014de7c8940b4c(props, ref);
|
|
67
|
+
let child = (0, $fcPuG$react).Children.only(children);
|
|
68
|
+
(0, $fcPuG$useEffect)(()=>{
|
|
69
|
+
let el = ref.current;
|
|
70
|
+
if (!el || !(el instanceof (0, $fcPuG$getOwnerWindow)(el).Element)) {
|
|
71
|
+
console.error('<Focusable> child must forward its ref to a DOM element.');
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (!props.isDisabled && !(0, $fcPuG$isFocusable)(el)) {
|
|
75
|
+
console.warn('<Focusable> child must be focusable. Please ensure the tabIndex prop is passed through.');
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (el.localName !== 'button' && el.localName !== 'input' && el.localName !== 'select' && el.localName !== 'textarea' && el.localName !== 'a' && el.localName !== 'area' && el.localName !== 'summary' && el.localName !== 'img' && el.localName !== 'svg') {
|
|
79
|
+
let role = el.getAttribute('role');
|
|
80
|
+
if (!role) console.warn('<Focusable> child must have an interactive ARIA role.');
|
|
81
|
+
else if (// https://w3c.github.io/aria/#widget_roles
|
|
82
|
+
role !== 'application' && role !== 'button' && role !== 'checkbox' && role !== 'combobox' && role !== 'gridcell' && role !== 'link' && role !== 'menuitem' && role !== 'menuitemcheckbox' && role !== 'menuitemradio' && role !== 'option' && role !== 'radio' && role !== 'searchbox' && role !== 'separator' && role !== 'slider' && role !== 'spinbutton' && role !== 'switch' && role !== 'tab' && role !== 'tabpanel' && role !== 'textbox' && role !== 'treeitem' && // aria-describedby is also announced on these roles
|
|
83
|
+
role !== 'img' && role !== 'meter' && role !== 'progressbar') console.warn(`<Focusable> child must have an interactive ARIA role. Got "${role}".`);
|
|
84
|
+
}
|
|
85
|
+
}, [
|
|
86
|
+
ref,
|
|
87
|
+
props.isDisabled
|
|
88
|
+
]);
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
let childRef = parseInt((0, $fcPuG$react).version, 10) < 19 ? child.ref : child.props.ref;
|
|
91
|
+
return /*#__PURE__*/ (0, $fcPuG$react).cloneElement(child, {
|
|
92
|
+
...(0, $fcPuG$mergeProps)(focusableProps, child.props),
|
|
93
|
+
// @ts-ignore
|
|
94
|
+
ref: (0, $fcPuG$mergeRefs)(childRef, ref)
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
export {$f645667febf57a63$export$f9762fab77588ecb as FocusableContext, $f645667febf57a63$export$13f3202a3e5ddd5 as FocusableProvider, $f645667febf57a63$export$4c014de7c8940b4c as useFocusable, $f645667febf57a63$export$35a3bebf7ef2d934 as Focusable};
|
|
100
|
+
//# sourceMappingURL=useFocusable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oDAAoD;YACpD,SAAS,SACT,SAAS,WACT,SAAS,eAET,QAAQ,IAAI,CAAC,CAAC,2DAA2D,EAAE,KAAK,EAAE,CAAC;QAEvF;IACF,GAAG;QAAC;QAAK,MAAM,UAAU;KAAC;IAE1B,aAAa;IACb,IAAI,WAAW,SAAS,CAAA,GAAA,YAAI,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG;IAE7E,qBAAO,CAAA,GAAA,YAAI,EAAE,YAAY,CACvB,OACA;QACE,GAAG,CAAA,GAAA,iBAAS,EAAE,gBAAgB,MAAM,KAAK,CAAC;QAC1C,aAAa;QACb,KAAK,CAAA,GAAA,gBAAQ,EAAE,UAAU;IAC3B;AAEJ","sources":["packages/@react-aria/interactions/src/useFocusable.tsx"],"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 {DOMAttributes, FocusableDOMProps, FocusableElement, FocusableProps, RefObject} from '@react-types/shared';\nimport {focusSafely} from './';\nimport {getOwnerWindow, isFocusable, mergeProps, mergeRefs, useObjectRef, useSyncRef} from '@react-aria/utils';\nimport React, {ForwardedRef, forwardRef, MutableRefObject, ReactElement, ReactNode, useContext, useEffect, useRef} from 'react';\nimport {useFocus} from './useFocus';\nimport {useKeyboard} from './useKeyboard';\n\nexport interface FocusableOptions<T = FocusableElement> extends FocusableProps<T>, FocusableDOMProps {\n /** Whether focus should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusableProviderProps extends DOMAttributes {\n /** The child element to provide DOM props to. */\n children?: ReactNode\n}\n\ninterface FocusableContextValue extends FocusableProviderProps {\n ref?: MutableRefObject<FocusableElement | null>\n}\n\n// Exported for @react-aria/collections, which forwards this context.\n/** @private */\nexport let FocusableContext = React.createContext<FocusableContextValue | null>(null);\n\nfunction useFocusableContext(ref: RefObject<FocusableElement | null>): FocusableContextValue {\n let context = useContext(FocusableContext) || {};\n useSyncRef(context, ref);\n\n // eslint-disable-next-line\n let {ref: _, ...otherProps} = context;\n return otherProps;\n}\n\n/**\n * Provides DOM props to the nearest focusable child.\n */\nexport const FocusableProvider = React.forwardRef(function FocusableProvider(props: FocusableProviderProps, ref: ForwardedRef<FocusableElement>) {\n let {children, ...otherProps} = props;\n let objRef = useObjectRef(ref);\n let context = {\n ...otherProps,\n ref: objRef\n };\n\n return (\n <FocusableContext.Provider value={context}>\n {children}\n </FocusableContext.Provider>\n );\n});\n\nexport interface FocusableAria {\n /** Props for the focusable element. */\n focusableProps: DOMAttributes\n}\n\n/**\n * Used to make an element focusable and capable of auto focus.\n */\nexport function useFocusable<T extends FocusableElement = FocusableElement>(props: FocusableOptions<T>, domRef: RefObject<FocusableElement | null>): FocusableAria {\n let {focusProps} = useFocus(props);\n let {keyboardProps} = useKeyboard(props);\n let interactions = mergeProps(focusProps, keyboardProps);\n let domProps = useFocusableContext(domRef);\n let interactionProps = props.isDisabled ? {} : domProps;\n let autoFocusRef = useRef(props.autoFocus);\n\n useEffect(() => {\n if (autoFocusRef.current && domRef.current) {\n focusSafely(domRef.current);\n }\n autoFocusRef.current = false;\n }, [domRef]);\n\n // Always set a tabIndex so that Safari allows focusing native buttons and inputs.\n let tabIndex: number | undefined = props.excludeFromTabOrder ? -1 : 0;\n if (props.isDisabled) {\n tabIndex = undefined;\n }\n\n return {\n focusableProps: mergeProps(\n {\n ...interactions,\n tabIndex\n },\n interactionProps\n )\n };\n}\n\nexport interface FocusableComponentProps extends FocusableOptions {\n children: ReactElement<DOMAttributes, string>\n}\n\nexport const Focusable = forwardRef(({children, ...props}: FocusableComponentProps, ref: ForwardedRef<FocusableElement>) => {\n ref = useObjectRef(ref);\n let {focusableProps} = useFocusable(props, ref);\n let child = React.Children.only(children);\n\n useEffect(() => {\n let el = ref.current;\n if (!el || !(el instanceof getOwnerWindow(el).Element)) {\n console.error('<Focusable> child must forward its ref to a DOM element.');\n return;\n }\n\n if (!props.isDisabled && !isFocusable(el)) {\n console.warn('<Focusable> child must be focusable. Please ensure the tabIndex prop is passed through.');\n return;\n }\n\n if (\n el.localName !== 'button' &&\n el.localName !== 'input' &&\n el.localName !== 'select' &&\n el.localName !== 'textarea' &&\n el.localName !== 'a' &&\n el.localName !== 'area' &&\n el.localName !== 'summary' &&\n el.localName !== 'img' &&\n el.localName !== 'svg'\n ) {\n let role = el.getAttribute('role');\n if (!role) {\n console.warn('<Focusable> child must have an interactive ARIA role.');\n } else if (\n // https://w3c.github.io/aria/#widget_roles\n role !== 'application' &&\n role !== 'button' &&\n role !== 'checkbox' &&\n role !== 'combobox' &&\n role !== 'gridcell' &&\n role !== 'link' &&\n role !== 'menuitem' &&\n role !== 'menuitemcheckbox' &&\n role !== 'menuitemradio' &&\n role !== 'option' &&\n role !== 'radio' &&\n role !== 'searchbox' &&\n role !== 'separator' &&\n role !== 'slider' &&\n role !== 'spinbutton' &&\n role !== 'switch' &&\n role !== 'tab' &&\n role !== 'tabpanel' &&\n role !== 'textbox' &&\n role !== 'treeitem' &&\n // aria-describedby is also announced on these roles\n role !== 'img' &&\n role !== 'meter' &&\n role !== 'progressbar'\n ) {\n console.warn(`<Focusable> child must have an interactive ARIA role. Got \"${role}\".`);\n }\n }\n }, [ref, props.isDisabled]);\n\n // @ts-ignore\n let childRef = parseInt(React.version, 10) < 19 ? child.ref : child.props.ref;\n\n return React.cloneElement(\n child,\n {\n ...mergeProps(focusableProps, child.props),\n // @ts-ignore\n ref: mergeRefs(childRef, ref)\n }\n );\n});\n"],"names":[],"version":3,"file":"useFocusable.module.js.map"}
|
package/dist/useHover.main.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
var $82z6W$reactariautils = require("@react-aria/utils");
|
|
1
2
|
var $82z6W$react = require("react");
|
|
2
3
|
|
|
3
4
|
|
|
@@ -21,6 +22,7 @@ $parcel$export(module.exports, "useHover", () => $ffbc150311c75f01$export$ae780d
|
|
|
21
22
|
// NOTICE file in the root directory of this source tree.
|
|
22
23
|
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
23
24
|
|
|
25
|
+
|
|
24
26
|
// iOS fires onPointerEnter twice: once with pointerType="touch" and again with pointerType="mouse".
|
|
25
27
|
// We want to ignore these emulated events so they do not trigger hover behavior.
|
|
26
28
|
// See https://bugs.webkit.org/show_bug.cgi?id=214609.
|
|
@@ -61,6 +63,7 @@ function $ffbc150311c75f01$export$ae780daf29e6d456(props) {
|
|
|
61
63
|
target: null
|
|
62
64
|
}).current;
|
|
63
65
|
(0, $82z6W$react.useEffect)($ffbc150311c75f01$var$setupGlobalTouchEvents, []);
|
|
66
|
+
let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $82z6W$reactariautils.useGlobalListeners)();
|
|
64
67
|
let { hoverProps: hoverProps, triggerHoverEnd: triggerHoverEnd } = (0, $82z6W$react.useMemo)(()=>{
|
|
65
68
|
let triggerHoverStart = (event, pointerType)=>{
|
|
66
69
|
state.pointerType = pointerType;
|
|
@@ -68,6 +71,15 @@ function $ffbc150311c75f01$export$ae780daf29e6d456(props) {
|
|
|
68
71
|
state.isHovered = true;
|
|
69
72
|
let target = event.currentTarget;
|
|
70
73
|
state.target = target;
|
|
74
|
+
// When an element that is hovered over is removed, no pointerleave event is fired by the browser,
|
|
75
|
+
// even though the originally hovered target may have shrunk in size so it is no longer hovered.
|
|
76
|
+
// However, a pointerover event will be fired on the new target the mouse is over.
|
|
77
|
+
// In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.
|
|
78
|
+
addGlobalListener((0, $82z6W$reactariautils.getOwnerDocument)(event.target), 'pointerover', (e)=>{
|
|
79
|
+
if (state.isHovered && state.target && !(0, $82z6W$reactariautils.nodeContains)(state.target, e.target)) triggerHoverEnd(e, e.pointerType);
|
|
80
|
+
}, {
|
|
81
|
+
capture: true
|
|
82
|
+
});
|
|
71
83
|
if (onHoverStart) onHoverStart({
|
|
72
84
|
type: 'hoverstart',
|
|
73
85
|
target: target,
|
|
@@ -77,11 +89,12 @@ function $ffbc150311c75f01$export$ae780daf29e6d456(props) {
|
|
|
77
89
|
setHovered(true);
|
|
78
90
|
};
|
|
79
91
|
let triggerHoverEnd = (event, pointerType)=>{
|
|
92
|
+
let target = state.target;
|
|
80
93
|
state.pointerType = '';
|
|
81
94
|
state.target = null;
|
|
82
|
-
if (pointerType === 'touch' || !state.isHovered) return;
|
|
95
|
+
if (pointerType === 'touch' || !state.isHovered || !target) return;
|
|
83
96
|
state.isHovered = false;
|
|
84
|
-
|
|
97
|
+
removeAllGlobalListeners();
|
|
85
98
|
if (onHoverEnd) onHoverEnd({
|
|
86
99
|
type: 'hoverend',
|
|
87
100
|
target: target,
|
|
@@ -120,7 +133,9 @@ function $ffbc150311c75f01$export$ae780daf29e6d456(props) {
|
|
|
120
133
|
onHoverChange,
|
|
121
134
|
onHoverEnd,
|
|
122
135
|
isDisabled,
|
|
123
|
-
state
|
|
136
|
+
state,
|
|
137
|
+
addGlobalListener,
|
|
138
|
+
removeAllGlobalListeners
|
|
124
139
|
]);
|
|
125
140
|
(0, $82z6W$react.useEffect)(()=>{
|
|
126
141
|
// Call the triggerHoverEnd as soon as isDisabled changes to true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;AAiBlH,oGAAoG;AACpG,iFAAiF;AACjF,sDAAsD;AACtD,IAAI,wDAAkC;AACtC,IAAI,mCAAa;A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aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAClD,gBAAgB,GAAG;YAEvB;QACF;QACA,OAAO;wBAAC;6BAAY;QAAe;IACrC,GAAG;QAAC;QAAc;QAAe;QAAY;QAAY;QAAO;QAAmB;KAAyB;IAE5G,CAAA,GAAA,sBAAQ,EAAE;QACR,iEAAiE;QACjE,qFAAqF;QACrF,IAAI,YACF,gBAAgB;YAAC,eAAe,MAAM,MAAM;QAAA,GAAG,MAAM,WAAW;IAEpE,uDAAuD;IACvD,GAAG;QAAC;KAAW;IAEf,OAAO;oBACL;mBACA;IACF;AACF","sources":["packages/@react-aria/interactions/src/useHover.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {DOMAttributes, HoverEvents} from '@react-types/shared';\nimport {getOwnerDocument, nodeContains, useGlobalListeners} from '@react-aria/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\n\nexport interface HoverProps extends HoverEvents {\n /** Whether the hover events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface HoverResult {\n /** Props to spread on the target element. */\n hoverProps: DOMAttributes,\n isHovered: boolean\n}\n\n// iOS fires onPointerEnter twice: once with pointerType=\"touch\" and again with pointerType=\"mouse\".\n// We want to ignore these emulated events so they do not trigger hover behavior.\n// See https://bugs.webkit.org/show_bug.cgi?id=214609.\nlet globalIgnoreEmulatedMouseEvents = false;\nlet hoverCount = 0;\n\nfunction setGlobalIgnoreEmulatedMouseEvents() {\n globalIgnoreEmulatedMouseEvents = true;\n\n // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter\n // with pointerType=\"mouse\" immediately after onPointerUp and before onFocus. On other\n // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in\n // the distant future because a user previously touched the element.\n setTimeout(() => {\n globalIgnoreEmulatedMouseEvents = false;\n }, 50);\n}\n\nfunction handleGlobalPointerEvent(e) {\n if (e.pointerType === 'touch') {\n setGlobalIgnoreEmulatedMouseEvents();\n }\n}\n\nfunction setupGlobalTouchEvents() {\n if (typeof document === 'undefined') {\n return;\n }\n\n if (typeof PointerEvent !== 'undefined') {\n document.addEventListener('pointerup', handleGlobalPointerEvent);\n } else {\n document.addEventListener('touchend', setGlobalIgnoreEmulatedMouseEvents);\n }\n\n hoverCount++;\n return () => {\n hoverCount--;\n if (hoverCount > 0) {\n return;\n }\n\n if (typeof PointerEvent !== 'undefined') {\n document.removeEventListener('pointerup', handleGlobalPointerEvent);\n } else {\n document.removeEventListener('touchend', setGlobalIgnoreEmulatedMouseEvents);\n }\n };\n}\n\n/**\n * Handles pointer hover interactions for an element. Normalizes behavior\n * across browsers and platforms, and ignores emulated mouse events on touch devices.\n */\nexport function useHover(props: HoverProps): HoverResult {\n let {\n onHoverStart,\n onHoverChange,\n onHoverEnd,\n isDisabled\n } = props;\n\n let [isHovered, setHovered] = useState(false);\n let state = useRef({\n isHovered: false,\n ignoreEmulatedMouseEvents: false,\n pointerType: '',\n target: null\n }).current;\n\n useEffect(setupGlobalTouchEvents, []);\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n\n let {hoverProps, triggerHoverEnd} = useMemo(() => {\n let triggerHoverStart = (event, pointerType) => {\n state.pointerType = pointerType;\n if (isDisabled || pointerType === 'touch' || state.isHovered || !event.currentTarget.contains(event.target)) {\n return;\n }\n\n state.isHovered = true;\n let target = event.currentTarget;\n state.target = target;\n\n // When an element that is hovered over is removed, no pointerleave event is fired by the browser,\n // even though the originally hovered target may have shrunk in size so it is no longer hovered.\n // However, a pointerover event will be fired on the new target the mouse is over.\n // In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.\n addGlobalListener(getOwnerDocument(event.target), 'pointerover', e => {\n if (state.isHovered && state.target && !nodeContains(state.target, e.target as Element)) {\n triggerHoverEnd(e, e.pointerType);\n }\n }, {capture: true});\n\n if (onHoverStart) {\n onHoverStart({\n type: 'hoverstart',\n target,\n pointerType\n });\n }\n\n if (onHoverChange) {\n onHoverChange(true);\n }\n\n setHovered(true);\n };\n\n let triggerHoverEnd = (event, pointerType) => {\n let target = state.target;\n state.pointerType = '';\n state.target = null;\n\n if (pointerType === 'touch' || !state.isHovered || !target) {\n return;\n }\n\n state.isHovered = false;\n removeAllGlobalListeners();\n\n if (onHoverEnd) {\n onHoverEnd({\n type: 'hoverend',\n target,\n pointerType\n });\n }\n\n if (onHoverChange) {\n onHoverChange(false);\n }\n\n setHovered(false);\n };\n\n let hoverProps: DOMAttributes = {};\n\n if (typeof PointerEvent !== 'undefined') {\n hoverProps.onPointerEnter = (e) => {\n if (globalIgnoreEmulatedMouseEvents && e.pointerType === 'mouse') {\n return;\n }\n\n triggerHoverStart(e, e.pointerType);\n };\n\n hoverProps.onPointerLeave = (e) => {\n if (!isDisabled && e.currentTarget.contains(e.target as Element)) {\n triggerHoverEnd(e, e.pointerType);\n }\n };\n } else {\n hoverProps.onTouchStart = () => {\n state.ignoreEmulatedMouseEvents = true;\n };\n\n hoverProps.onMouseEnter = (e) => {\n if (!state.ignoreEmulatedMouseEvents && !globalIgnoreEmulatedMouseEvents) {\n triggerHoverStart(e, 'mouse');\n }\n\n state.ignoreEmulatedMouseEvents = false;\n };\n\n hoverProps.onMouseLeave = (e) => {\n if (!isDisabled && e.currentTarget.contains(e.target as Element)) {\n triggerHoverEnd(e, 'mouse');\n }\n };\n }\n return {hoverProps, triggerHoverEnd};\n }, [onHoverStart, onHoverChange, onHoverEnd, isDisabled, state, addGlobalListener, removeAllGlobalListeners]);\n\n useEffect(() => {\n // Call the triggerHoverEnd as soon as isDisabled changes to true\n // Safe to call triggerHoverEnd, it will early return if we aren't currently hovering\n if (isDisabled) {\n triggerHoverEnd({currentTarget: state.target}, state.pointerType);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isDisabled]);\n\n return {\n hoverProps,\n isHovered\n };\n}\n"],"names":[],"version":3,"file":"useHover.main.js.map"}
|
package/dist/useHover.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {useGlobalListeners as $AWxnT$useGlobalListeners, getOwnerDocument as $AWxnT$getOwnerDocument, nodeContains as $AWxnT$nodeContains} from "@react-aria/utils";
|
|
1
2
|
import {useState as $AWxnT$useState, useRef as $AWxnT$useRef, useEffect as $AWxnT$useEffect, useMemo as $AWxnT$useMemo} from "react";
|
|
2
3
|
|
|
3
4
|
/*
|
|
@@ -15,6 +16,7 @@ import {useState as $AWxnT$useState, useRef as $AWxnT$useRef, useEffect as $AWxn
|
|
|
15
16
|
// NOTICE file in the root directory of this source tree.
|
|
16
17
|
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
17
18
|
|
|
19
|
+
|
|
18
20
|
// iOS fires onPointerEnter twice: once with pointerType="touch" and again with pointerType="mouse".
|
|
19
21
|
// We want to ignore these emulated events so they do not trigger hover behavior.
|
|
20
22
|
// See https://bugs.webkit.org/show_bug.cgi?id=214609.
|
|
@@ -55,6 +57,7 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
55
57
|
target: null
|
|
56
58
|
}).current;
|
|
57
59
|
(0, $AWxnT$useEffect)($6179b936705e76d3$var$setupGlobalTouchEvents, []);
|
|
60
|
+
let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $AWxnT$useGlobalListeners)();
|
|
58
61
|
let { hoverProps: hoverProps, triggerHoverEnd: triggerHoverEnd } = (0, $AWxnT$useMemo)(()=>{
|
|
59
62
|
let triggerHoverStart = (event, pointerType)=>{
|
|
60
63
|
state.pointerType = pointerType;
|
|
@@ -62,6 +65,15 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
62
65
|
state.isHovered = true;
|
|
63
66
|
let target = event.currentTarget;
|
|
64
67
|
state.target = target;
|
|
68
|
+
// When an element that is hovered over is removed, no pointerleave event is fired by the browser,
|
|
69
|
+
// even though the originally hovered target may have shrunk in size so it is no longer hovered.
|
|
70
|
+
// However, a pointerover event will be fired on the new target the mouse is over.
|
|
71
|
+
// In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.
|
|
72
|
+
addGlobalListener((0, $AWxnT$getOwnerDocument)(event.target), 'pointerover', (e)=>{
|
|
73
|
+
if (state.isHovered && state.target && !(0, $AWxnT$nodeContains)(state.target, e.target)) triggerHoverEnd(e, e.pointerType);
|
|
74
|
+
}, {
|
|
75
|
+
capture: true
|
|
76
|
+
});
|
|
65
77
|
if (onHoverStart) onHoverStart({
|
|
66
78
|
type: 'hoverstart',
|
|
67
79
|
target: target,
|
|
@@ -71,11 +83,12 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
71
83
|
setHovered(true);
|
|
72
84
|
};
|
|
73
85
|
let triggerHoverEnd = (event, pointerType)=>{
|
|
86
|
+
let target = state.target;
|
|
74
87
|
state.pointerType = '';
|
|
75
88
|
state.target = null;
|
|
76
|
-
if (pointerType === 'touch' || !state.isHovered) return;
|
|
89
|
+
if (pointerType === 'touch' || !state.isHovered || !target) return;
|
|
77
90
|
state.isHovered = false;
|
|
78
|
-
|
|
91
|
+
removeAllGlobalListeners();
|
|
79
92
|
if (onHoverEnd) onHoverEnd({
|
|
80
93
|
type: 'hoverend',
|
|
81
94
|
target: target,
|
|
@@ -114,7 +127,9 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
114
127
|
onHoverChange,
|
|
115
128
|
onHoverEnd,
|
|
116
129
|
isDisabled,
|
|
117
|
-
state
|
|
130
|
+
state,
|
|
131
|
+
addGlobalListener,
|
|
132
|
+
removeAllGlobalListeners
|
|
118
133
|
]);
|
|
119
134
|
(0, $AWxnT$useEffect)(()=>{
|
|
120
135
|
// Call the triggerHoverEnd as soon as isDisabled changes to true
|
package/dist/useHover.module.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {useGlobalListeners as $AWxnT$useGlobalListeners, getOwnerDocument as $AWxnT$getOwnerDocument, nodeContains as $AWxnT$nodeContains} from "@react-aria/utils";
|
|
1
2
|
import {useState as $AWxnT$useState, useRef as $AWxnT$useRef, useEffect as $AWxnT$useEffect, useMemo as $AWxnT$useMemo} from "react";
|
|
2
3
|
|
|
3
4
|
/*
|
|
@@ -15,6 +16,7 @@ import {useState as $AWxnT$useState, useRef as $AWxnT$useRef, useEffect as $AWxn
|
|
|
15
16
|
// NOTICE file in the root directory of this source tree.
|
|
16
17
|
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
17
18
|
|
|
19
|
+
|
|
18
20
|
// iOS fires onPointerEnter twice: once with pointerType="touch" and again with pointerType="mouse".
|
|
19
21
|
// We want to ignore these emulated events so they do not trigger hover behavior.
|
|
20
22
|
// See https://bugs.webkit.org/show_bug.cgi?id=214609.
|
|
@@ -55,6 +57,7 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
55
57
|
target: null
|
|
56
58
|
}).current;
|
|
57
59
|
(0, $AWxnT$useEffect)($6179b936705e76d3$var$setupGlobalTouchEvents, []);
|
|
60
|
+
let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $AWxnT$useGlobalListeners)();
|
|
58
61
|
let { hoverProps: hoverProps, triggerHoverEnd: triggerHoverEnd } = (0, $AWxnT$useMemo)(()=>{
|
|
59
62
|
let triggerHoverStart = (event, pointerType)=>{
|
|
60
63
|
state.pointerType = pointerType;
|
|
@@ -62,6 +65,15 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
62
65
|
state.isHovered = true;
|
|
63
66
|
let target = event.currentTarget;
|
|
64
67
|
state.target = target;
|
|
68
|
+
// When an element that is hovered over is removed, no pointerleave event is fired by the browser,
|
|
69
|
+
// even though the originally hovered target may have shrunk in size so it is no longer hovered.
|
|
70
|
+
// However, a pointerover event will be fired on the new target the mouse is over.
|
|
71
|
+
// In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.
|
|
72
|
+
addGlobalListener((0, $AWxnT$getOwnerDocument)(event.target), 'pointerover', (e)=>{
|
|
73
|
+
if (state.isHovered && state.target && !(0, $AWxnT$nodeContains)(state.target, e.target)) triggerHoverEnd(e, e.pointerType);
|
|
74
|
+
}, {
|
|
75
|
+
capture: true
|
|
76
|
+
});
|
|
65
77
|
if (onHoverStart) onHoverStart({
|
|
66
78
|
type: 'hoverstart',
|
|
67
79
|
target: target,
|
|
@@ -71,11 +83,12 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
71
83
|
setHovered(true);
|
|
72
84
|
};
|
|
73
85
|
let triggerHoverEnd = (event, pointerType)=>{
|
|
86
|
+
let target = state.target;
|
|
74
87
|
state.pointerType = '';
|
|
75
88
|
state.target = null;
|
|
76
|
-
if (pointerType === 'touch' || !state.isHovered) return;
|
|
89
|
+
if (pointerType === 'touch' || !state.isHovered || !target) return;
|
|
77
90
|
state.isHovered = false;
|
|
78
|
-
|
|
91
|
+
removeAllGlobalListeners();
|
|
79
92
|
if (onHoverEnd) onHoverEnd({
|
|
80
93
|
type: 'hoverend',
|
|
81
94
|
target: target,
|
|
@@ -114,7 +127,9 @@ function $6179b936705e76d3$export$ae780daf29e6d456(props) {
|
|
|
114
127
|
onHoverChange,
|
|
115
128
|
onHoverEnd,
|
|
116
129
|
isDisabled,
|
|
117
|
-
state
|
|
130
|
+
state,
|
|
131
|
+
addGlobalListener,
|
|
132
|
+
removeAllGlobalListeners
|
|
118
133
|
]);
|
|
119
134
|
(0, $AWxnT$useEffect)(()=>{
|
|
120
135
|
// Call the triggerHoverEnd as soon as isDisabled changes to true
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;AAiBlH,oGAAoG;AACpG,iFAAiF;AACjF,sDAAsD;AACtD,IAAI,wDAAkC;AACtC,IAAI,mCAAa;AAEjB,SAAS;IACP,wDAAkC;IAElC,wFAAwF;IACxF,sFAAsF;IACtF,wFAAwF;IACxF,oEAAoE;IACpE,WAAW;QACT,wDAAkC;IACpC,GAAG;AACL;AAEA,SAAS,+CAAyB,CAAC;IACjC,IAAI,EAAE,WAAW,KAAK,SACpB;AAEJ;AAEA,SAAS;IACP,IAAI,OAAO,aAAa,aACtB;IAGF,IAAI,OAAO,iBAAiB,aAC1B,SAAS,gBAAgB,CAAC,aAAa;SAEvC,SAAS,gBAAgB,CAAC,YAAY;IAGxC;IACA,OAAO;QACL;QACA,IAAI,mCAAa,GACf;QAGF,IAAI,OAAO,iBAAiB,aAC1B,SAAS,mBAAmB,CAAC,aAAa;aAE1C,SAAS,mBAAmB,CAAC,YAAY;IAE7C;AACF;AAMO,SAAS,0CAAS,KAAiB;IACxC,IAAI,gBACF,YAAY,iBACZ,aAAa,cACb,UAAU,cACV,UAAU,EACX,GAAG;IAEJ,IAAI,CAAC,WAAW,WAAW,GAAG,CAAA,GAAA,eAAO,EAAE;IACvC,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAE;QACjB,WAAW;QACX,2BAA2B;QAC3B,aAAa;QACb,QAAQ;IACV,GAAG,OAAO;IAEV,CAAA,GAAA,gBAAQ,EAAE,8CAAwB,EAAE;IACpC,IAAI,qBAAC,iBAAiB,4BAAE,wB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WAAW,cAAc,GAAG,CAAC;gBAC3B,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAClD,gBAAgB,GAAG,EAAE,WAAW;YAEpC;QACF,OAAO;YACL,WAAW,YAAY,GAAG;gBACxB,MAAM,yBAAyB,GAAG;YACpC;YAEA,WAAW,YAAY,GAAG,CAAC;gBACzB,IAAI,CAAC,MAAM,yBAAyB,IAAI,CAAC,uDACvC,kBAAkB,GAAG;gBAGvB,MAAM,yBAAyB,GAAG;YACpC;YAEA,WAAW,YAAY,GAAG,CAAC;gBACzB,IAAI,CAAC,cAAc,EAAE,aAAa,CAAC,QAAQ,CAAC,EAAE,MAAM,GAClD,gBAAgB,GAAG;YAEvB;QACF;QACA,OAAO;wBAAC;6BAAY;QAAe;IACrC,GAAG;QAAC;QAAc;QAAe;QAAY;QAAY;QAAO;QAAmB;KAAyB;IAE5G,CAAA,GAAA,gBAAQ,EAAE;QACR,iEAAiE;QACjE,qFAAqF;QACrF,IAAI,YACF,gBAAgB;YAAC,eAAe,MAAM,MAAM;QAAA,GAAG,MAAM,WAAW;IAEpE,uDAAuD;IACvD,GAAG;QAAC;KAAW;IAEf,OAAO;oBACL;mBACA;IACF;AACF","sources":["packages/@react-aria/interactions/src/useHover.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {DOMAttributes, HoverEvents} from '@react-types/shared';\nimport {getOwnerDocument, nodeContains, useGlobalListeners} from '@react-aria/utils';\nimport {useEffect, useMemo, useRef, useState} from 'react';\n\nexport interface HoverProps extends HoverEvents {\n /** Whether the hover events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface HoverResult {\n /** Props to spread on the target element. */\n hoverProps: DOMAttributes,\n isHovered: boolean\n}\n\n// iOS fires onPointerEnter twice: once with pointerType=\"touch\" and again with pointerType=\"mouse\".\n// We want to ignore these emulated events so they do not trigger hover behavior.\n// See https://bugs.webkit.org/show_bug.cgi?id=214609.\nlet globalIgnoreEmulatedMouseEvents = false;\nlet hoverCount = 0;\n\nfunction setGlobalIgnoreEmulatedMouseEvents() {\n globalIgnoreEmulatedMouseEvents = true;\n\n // Clear globalIgnoreEmulatedMouseEvents after a short timeout. iOS fires onPointerEnter\n // with pointerType=\"mouse\" immediately after onPointerUp and before onFocus. On other\n // devices that don't have this quirk, we don't want to ignore a mouse hover sometime in\n // the distant future because a user previously touched the element.\n setTimeout(() => {\n globalIgnoreEmulatedMouseEvents = false;\n }, 50);\n}\n\nfunction handleGlobalPointerEvent(e) {\n if (e.pointerType === 'touch') {\n setGlobalIgnoreEmulatedMouseEvents();\n }\n}\n\nfunction setupGlobalTouchEvents() {\n if (typeof document === 'undefined') {\n return;\n }\n\n if (typeof PointerEvent !== 'undefined') {\n document.addEventListener('pointerup', handleGlobalPointerEvent);\n } else {\n document.addEventListener('touchend', setGlobalIgnoreEmulatedMouseEvents);\n }\n\n hoverCount++;\n return () => {\n hoverCount--;\n if (hoverCount > 0) {\n return;\n }\n\n if (typeof PointerEvent !== 'undefined') {\n document.removeEventListener('pointerup', handleGlobalPointerEvent);\n } else {\n document.removeEventListener('touchend', setGlobalIgnoreEmulatedMouseEvents);\n }\n };\n}\n\n/**\n * Handles pointer hover interactions for an element. Normalizes behavior\n * across browsers and platforms, and ignores emulated mouse events on touch devices.\n */\nexport function useHover(props: HoverProps): HoverResult {\n let {\n onHoverStart,\n onHoverChange,\n onHoverEnd,\n isDisabled\n } = props;\n\n let [isHovered, setHovered] = useState(false);\n let state = useRef({\n isHovered: false,\n ignoreEmulatedMouseEvents: false,\n pointerType: '',\n target: null\n }).current;\n\n useEffect(setupGlobalTouchEvents, []);\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n\n let {hoverProps, triggerHoverEnd} = useMemo(() => {\n let triggerHoverStart = (event, pointerType) => {\n state.pointerType = pointerType;\n if (isDisabled || pointerType === 'touch' || state.isHovered || !event.currentTarget.contains(event.target)) {\n return;\n }\n\n state.isHovered = true;\n let target = event.currentTarget;\n state.target = target;\n\n // When an element that is hovered over is removed, no pointerleave event is fired by the browser,\n // even though the originally hovered target may have shrunk in size so it is no longer hovered.\n // However, a pointerover event will be fired on the new target the mouse is over.\n // In Chrome this happens immediately. In Safari and Firefox, it happens upon moving the mouse one pixel.\n addGlobalListener(getOwnerDocument(event.target), 'pointerover', e => {\n if (state.isHovered && state.target && !nodeContains(state.target, e.target as Element)) {\n triggerHoverEnd(e, e.pointerType);\n }\n }, {capture: true});\n\n if (onHoverStart) {\n onHoverStart({\n type: 'hoverstart',\n target,\n pointerType\n });\n }\n\n if (onHoverChange) {\n onHoverChange(true);\n }\n\n setHovered(true);\n };\n\n let triggerHoverEnd = (event, pointerType) => {\n let target = state.target;\n state.pointerType = '';\n state.target = null;\n\n if (pointerType === 'touch' || !state.isHovered || !target) {\n return;\n }\n\n state.isHovered = false;\n removeAllGlobalListeners();\n\n if (onHoverEnd) {\n onHoverEnd({\n type: 'hoverend',\n target,\n pointerType\n });\n }\n\n if (onHoverChange) {\n onHoverChange(false);\n }\n\n setHovered(false);\n };\n\n let hoverProps: DOMAttributes = {};\n\n if (typeof PointerEvent !== 'undefined') {\n hoverProps.onPointerEnter = (e) => {\n if (globalIgnoreEmulatedMouseEvents && e.pointerType === 'mouse') {\n return;\n }\n\n triggerHoverStart(e, e.pointerType);\n };\n\n hoverProps.onPointerLeave = (e) => {\n if (!isDisabled && e.currentTarget.contains(e.target as Element)) {\n triggerHoverEnd(e, e.pointerType);\n }\n };\n } else {\n hoverProps.onTouchStart = () => {\n state.ignoreEmulatedMouseEvents = true;\n };\n\n hoverProps.onMouseEnter = (e) => {\n if (!state.ignoreEmulatedMouseEvents && !globalIgnoreEmulatedMouseEvents) {\n triggerHoverStart(e, 'mouse');\n }\n\n state.ignoreEmulatedMouseEvents = false;\n };\n\n hoverProps.onMouseLeave = (e) => {\n if (!isDisabled && e.currentTarget.contains(e.target as Element)) {\n triggerHoverEnd(e, 'mouse');\n }\n };\n }\n return {hoverProps, triggerHoverEnd};\n }, [onHoverStart, onHoverChange, onHoverEnd, isDisabled, state, addGlobalListener, removeAllGlobalListeners]);\n\n useEffect(() => {\n // Call the triggerHoverEnd as soon as isDisabled changes to true\n // Safe to call triggerHoverEnd, it will early return if we aren't currently hovering\n if (isDisabled) {\n triggerHoverEnd({currentTarget: state.target}, state.pointerType);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isDisabled]);\n\n return {\n hoverProps,\n isHovered\n };\n}\n"],"names":[],"version":3,"file":"useHover.module.js.map"}
|
|
@@ -94,7 +94,12 @@ function $edcfa848c42f94f4$var$isValidEvent(event, ref) {
|
|
|
94
94
|
// If the target is within a top layer element (e.g. toasts), ignore.
|
|
95
95
|
if (event.target.closest('[data-react-aria-top-layer]')) return false;
|
|
96
96
|
}
|
|
97
|
-
|
|
97
|
+
if (!ref.current) return false;
|
|
98
|
+
// When the event source is inside a Shadow DOM, event.target is just the shadow root.
|
|
99
|
+
// Using event.composedPath instead means we can get the actual element inside the shadow root.
|
|
100
|
+
// This only works if the shadow root is open, there is no way to detect if it is closed.
|
|
101
|
+
// If the event composed path contains the ref, interaction is inside.
|
|
102
|
+
return !event.composedPath().includes(ref.current);
|
|
98
103
|
}
|
|
99
104
|
|
|
100
105
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;AAAA;;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AM,EAAE;QAChB,2DAA2D;QAC3D,MAAM,gBAAgB,MAAM,MAAM,CAAC,aAAa;QAChD,IAAI,CAAC,iBAAiB,CAAC,cAAc,eAAe,CAAC,QAAQ,CAAC,MAAM,MAAM,GACxE,OAAO;QAET,qEAAqE;QACrE,IAAI,MAAM,MAAM,CAAC,OAAO,CAAC,gCACvB,OAAO;IAEX;IAEA,IAAI,CAAC,IAAI,OAAO,EACd,OAAO;IAGT,sFAAsF;IACtF,+FAA+F;IAC/F,yFAAyF;IACzF,sEAAsE;IACtE,OAAO,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC,IAAI,OAAO;AACnD","sources":["packages/@react-aria/interactions/src/useInteractOutside.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\n// Portions of the code in this file are based on code from react.\n// Original licensing for the following can be found in the\n// NOTICE file in the root directory of this source tree.\n// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions\n\nimport {getOwnerDocument, useEffectEvent} from '@react-aria/utils';\nimport {RefObject} from '@react-types/shared';\nimport {useEffect, useRef} from 'react';\n\nexport interface InteractOutsideProps {\n ref: RefObject<Element | null>,\n onInteractOutside?: (e: PointerEvent) => void,\n onInteractOutsideStart?: (e: PointerEvent) => void,\n /** Whether the interact outside events should be disabled. */\n isDisabled?: boolean\n}\n\n/**\n * Example, used in components like Dialogs and Popovers so they can close\n * when a user clicks outside them.\n */\nexport function useInteractOutside(props: InteractOutsideProps) {\n let {ref, onInteractOutside, isDisabled, onInteractOutsideStart} = props;\n let stateRef = useRef({\n isPointerDown: false,\n ignoreEmulatedMouseEvents: false\n });\n\n let onPointerDown = useEffectEvent((e) => {\n if (onInteractOutside && isValidEvent(e, ref)) {\n if (onInteractOutsideStart) {\n onInteractOutsideStart(e);\n }\n stateRef.current.isPointerDown = true;\n }\n });\n\n let triggerInteractOutside = useEffectEvent((e: PointerEvent) => {\n if (onInteractOutside) {\n onInteractOutside(e);\n }\n });\n\n useEffect(() => {\n let state = stateRef.current;\n if (isDisabled) {\n return;\n }\n\n const element = ref.current;\n const documentObject = getOwnerDocument(element);\n\n // Use pointer events if available. Otherwise, fall back to mouse and touch events.\n if (typeof PointerEvent !== 'undefined') {\n let onPointerUp = (e) => {\n if (state.isPointerDown && isValidEvent(e, ref)) {\n triggerInteractOutside(e);\n }\n state.isPointerDown = false;\n };\n\n // changing these to capture phase fixed combobox\n documentObject.addEventListener('pointerdown', onPointerDown, true);\n documentObject.addEventListener('pointerup', onPointerUp, true);\n\n return () => {\n documentObject.removeEventListener('pointerdown', onPointerDown, true);\n documentObject.removeEventListener('pointerup', onPointerUp, true);\n };\n } else {\n let onMouseUp = (e) => {\n if (state.ignoreEmulatedMouseEvents) {\n state.ignoreEmulatedMouseEvents = false;\n } else if (state.isPointerDown && isValidEvent(e, ref)) {\n triggerInteractOutside(e);\n }\n state.isPointerDown = false;\n };\n\n let onTouchEnd = (e) => {\n state.ignoreEmulatedMouseEvents = true;\n if (state.isPointerDown && isValidEvent(e, ref)) {\n triggerInteractOutside(e);\n }\n state.isPointerDown = false;\n };\n\n documentObject.addEventListener('mousedown', onPointerDown, true);\n documentObject.addEventListener('mouseup', onMouseUp, true);\n documentObject.addEventListener('touchstart', onPointerDown, true);\n documentObject.addEventListener('touchend', onTouchEnd, true);\n\n return () => {\n documentObject.removeEventListener('mousedown', onPointerDown, true);\n documentObject.removeEventListener('mouseup', onMouseUp, true);\n documentObject.removeEventListener('touchstart', onPointerDown, true);\n documentObject.removeEventListener('touchend', onTouchEnd, true);\n };\n }\n }, [ref, isDisabled, onPointerDown, triggerInteractOutside]);\n}\n\nfunction isValidEvent(event, ref) {\n if (event.button > 0) {\n return false;\n }\n if (event.target) {\n // if the event target is no longer in the document, ignore\n const ownerDocument = event.target.ownerDocument;\n if (!ownerDocument || !ownerDocument.documentElement.contains(event.target)) {\n return false;\n }\n // If the target is within a top layer element (e.g. toasts), ignore.\n if (event.target.closest('[data-react-aria-top-layer]')) {\n return false;\n }\n }\n\n if (!ref.current) {\n return false;\n }\n\n // When the event source is inside a Shadow DOM, event.target is just the shadow root.\n // Using event.composedPath instead means we can get the actual element inside the shadow root.\n // This only works if the shadow root is open, there is no way to detect if it is closed.\n // If the event composed path contains the ref, interaction is inside.\n return !event.composedPath().includes(ref.current);\n}\n"],"names":[],"version":3,"file":"useInteractOutside.main.js.map"}
|
|
@@ -88,7 +88,12 @@ function $e0b6e0b68ec7f50f$var$isValidEvent(event, ref) {
|
|
|
88
88
|
// If the target is within a top layer element (e.g. toasts), ignore.
|
|
89
89
|
if (event.target.closest('[data-react-aria-top-layer]')) return false;
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
if (!ref.current) return false;
|
|
92
|
+
// When the event source is inside a Shadow DOM, event.target is just the shadow root.
|
|
93
|
+
// Using event.composedPath instead means we can get the actual element inside the shadow root.
|
|
94
|
+
// This only works if the shadow root is open, there is no way to detect if it is closed.
|
|
95
|
+
// If the event composed path contains the ref, interaction is inside.
|
|
96
|
+
return !event.composedPath().includes(ref.current);
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
|
|
@@ -88,7 +88,12 @@ function $e0b6e0b68ec7f50f$var$isValidEvent(event, ref) {
|
|
|
88
88
|
// If the target is within a top layer element (e.g. toasts), ignore.
|
|
89
89
|
if (event.target.closest('[data-react-aria-top-layer]')) return false;
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
if (!ref.current) return false;
|
|
92
|
+
// When the event source is inside a Shadow DOM, event.target is just the shadow root.
|
|
93
|
+
// Using event.composedPath instead means we can get the actual element inside the shadow root.
|
|
94
|
+
// This only works if the shadow root is open, there is no way to detect if it is closed.
|
|
95
|
+
// If the event composed path contains the ref, interaction is inside.
|
|
96
|
+
return !event.composedPath().includes(ref.current);
|
|
92
97
|
}
|
|
93
98
|
|
|
94
99
|
|