@react-aria/interactions 3.21.1 → 3.21.3
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/PressResponder.main.js +62 -0
- package/dist/PressResponder.main.js.map +1 -0
- package/dist/PressResponder.mjs +52 -0
- package/dist/PressResponder.module.js +52 -0
- package/dist/PressResponder.module.js.map +1 -0
- package/dist/Pressable.main.js +43 -0
- package/dist/Pressable.main.js.map +1 -0
- package/dist/Pressable.mjs +34 -0
- package/dist/Pressable.module.js +34 -0
- package/dist/Pressable.module.js.map +1 -0
- package/dist/context.main.js +30 -0
- package/dist/context.main.js.map +1 -0
- package/dist/context.mjs +21 -0
- package/dist/context.module.js +21 -0
- package/dist/context.module.js.map +1 -0
- package/dist/createEventHandler.main.js +42 -0
- package/dist/createEventHandler.main.js.map +1 -0
- package/dist/createEventHandler.mjs +37 -0
- package/dist/createEventHandler.module.js +37 -0
- package/dist/createEventHandler.module.js.map +1 -0
- package/dist/import.mjs +12 -1771
- package/dist/main.js +31 -1794
- package/dist/main.js.map +1 -1
- package/dist/module.js +12 -1771
- package/dist/module.js.map +1 -1
- package/dist/textSelection.main.js +77 -0
- package/dist/textSelection.main.js.map +1 -0
- package/dist/textSelection.mjs +71 -0
- package/dist/textSelection.module.js +71 -0
- package/dist/textSelection.module.js.map +1 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/useFocus.main.js +64 -0
- package/dist/useFocus.main.js.map +1 -0
- package/dist/useFocus.mjs +59 -0
- package/dist/useFocus.module.js +59 -0
- package/dist/useFocus.module.js.map +1 -0
- package/dist/useFocusVisible.main.js +248 -0
- package/dist/useFocusVisible.main.js.map +1 -0
- package/dist/useFocusVisible.mjs +237 -0
- package/dist/useFocusVisible.module.js +237 -0
- package/dist/useFocusVisible.module.js.map +1 -0
- package/dist/useFocusWithin.main.js +76 -0
- package/dist/useFocusWithin.main.js.map +1 -0
- package/dist/useFocusWithin.mjs +71 -0
- package/dist/useFocusWithin.module.js +71 -0
- package/dist/useFocusWithin.module.js.map +1 -0
- package/dist/useHover.main.js +142 -0
- package/dist/useHover.main.js.map +1 -0
- package/dist/useHover.mjs +137 -0
- package/dist/useHover.module.js +137 -0
- package/dist/useHover.module.js.map +1 -0
- package/dist/useInteractOutside.main.js +101 -0
- package/dist/useInteractOutside.main.js.map +1 -0
- package/dist/useInteractOutside.mjs +96 -0
- package/dist/useInteractOutside.module.js +96 -0
- package/dist/useInteractOutside.module.js.map +1 -0
- package/dist/useKeyboard.main.js +30 -0
- package/dist/useKeyboard.main.js.map +1 -0
- package/dist/useKeyboard.mjs +25 -0
- package/dist/useKeyboard.module.js +25 -0
- package/dist/useKeyboard.module.js.map +1 -0
- package/dist/useLongPress.main.js +84 -0
- package/dist/useLongPress.main.js.map +1 -0
- package/dist/useLongPress.mjs +79 -0
- package/dist/useLongPress.module.js +79 -0
- package/dist/useLongPress.module.js.map +1 -0
- package/dist/useMove.main.js +236 -0
- package/dist/useMove.main.js.map +1 -0
- package/dist/useMove.mjs +231 -0
- package/dist/useMove.module.js +231 -0
- package/dist/useMove.module.js.map +1 -0
- package/dist/usePress.main.js +571 -0
- package/dist/usePress.main.js.map +1 -0
- package/dist/usePress.mjs +566 -0
- package/dist/usePress.module.js +566 -0
- package/dist/usePress.module.js.map +1 -0
- package/dist/useScrollWheel.main.js +41 -0
- package/dist/useScrollWheel.main.js.map +1 -0
- package/dist/useScrollWheel.mjs +36 -0
- package/dist/useScrollWheel.module.js +36 -0
- package/dist/useScrollWheel.module.js.map +1 -0
- package/dist/utils.main.js +120 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +115 -0
- package/dist/utils.module.js +115 -0
- package/dist/utils.module.js.map +1 -0
- package/package.json +5 -5
- package/src/useFocus.ts +5 -1
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AEuBA,2BAA4B,SAAQ,WAAW;IAC7C,+FAA+F;IAC/F,SAAS,CAAC,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Y,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,cAAc,EAAC,MAAM,qBAAqB,CAAC","sources":["packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/textSelection.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/context.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/usePress.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/Pressable.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/PressResponder.tsx","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/utils.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocus.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusVisible.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useFocusWithin.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useHover.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useInteractOutside.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/createEventHandler.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useKeyboard.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useMove.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useScrollWheel.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/useLongPress.ts","packages/@react-aria/interactions/src/packages/@react-aria/interactions/src/index.ts","packages/@react-aria/interactions/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,"/*\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\nexport {Pressable} from './Pressable';\nexport {PressResponder, ClearPressResponder} from './PressResponder';\nexport {useFocus} from './useFocus';\nexport {\n isFocusVisible,\n getInteractionModality,\n setInteractionModality,\n addWindowFocusTracking,\n useInteractionModality,\n useFocusVisible,\n useFocusVisibleListener\n} from './useFocusVisible';\nexport {useFocusWithin} from './useFocusWithin';\nexport {useHover} from './useHover';\nexport {useInteractOutside} from './useInteractOutside';\nexport {useKeyboard} from './useKeyboard';\nexport {useMove} from './useMove';\nexport {usePress} from './usePress';\nexport {useScrollWheel} from './useScrollWheel';\nexport {useLongPress} from './useLongPress';\n\nexport type {FocusProps, FocusResult} from './useFocus';\nexport type {FocusVisibleHandler, FocusVisibleProps, FocusVisibleResult, Modality} from './useFocusVisible';\nexport type {FocusWithinProps, FocusWithinResult} from './useFocusWithin';\nexport type {HoverProps, HoverResult} from './useHover';\nexport type {InteractOutsideProps} from './useInteractOutside';\nexport type {KeyboardProps, KeyboardResult} from './useKeyboard';\nexport type {PressProps, PressHookProps, PressResult} from './usePress';\nexport type {PressEvent, PressEvents, MoveStartEvent, MoveMoveEvent, MoveEndEvent, MoveEvents, HoverEvent, HoverEvents, FocusEvents, KeyboardEvents} from '@react-types/shared';\nexport type {MoveResult} from './useMove';\nexport type {LongPressProps, LongPressResult} from './useLongPress';\nexport type {ScrollWheelProps} from './useScrollWheel';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
var $625cf83917e112ad$exports = require("./utils.main.js");
|
|
2
|
+
var $hrHul$react = require("react");
|
|
3
|
+
var $hrHul$reactariautils = require("@react-aria/utils");
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
function $parcel$export(e, n, v, s) {
|
|
7
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
$parcel$export(module.exports, "useFocus", () => $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6);
|
|
11
|
+
/*
|
|
12
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
13
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
14
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
15
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
16
|
+
*
|
|
17
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
18
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
19
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
20
|
+
* governing permissions and limitations under the License.
|
|
21
|
+
*/ // Portions of the code in this file are based on code from react.
|
|
22
|
+
// Original licensing for the following can be found in the
|
|
23
|
+
// NOTICE file in the root directory of this source tree.
|
|
24
|
+
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function $5cb73d0ce355b0dc$export$f8168d8dd8fd66e6(props) {
|
|
29
|
+
let { isDisabled: isDisabled, onFocus: onFocusProp, onBlur: onBlurProp, onFocusChange: onFocusChange } = props;
|
|
30
|
+
const onBlur = (0, $hrHul$react.useCallback)((e)=>{
|
|
31
|
+
if (e.target === e.currentTarget) {
|
|
32
|
+
if (onBlurProp) onBlurProp(e);
|
|
33
|
+
if (onFocusChange) onFocusChange(false);
|
|
34
|
+
return true;
|
|
35
|
+
}
|
|
36
|
+
}, [
|
|
37
|
+
onBlurProp,
|
|
38
|
+
onFocusChange
|
|
39
|
+
]);
|
|
40
|
+
const onSyntheticFocus = (0, $625cf83917e112ad$exports.useSyntheticBlurEvent)(onBlur);
|
|
41
|
+
const onFocus = (0, $hrHul$react.useCallback)((e)=>{
|
|
42
|
+
// Double check that document.activeElement actually matches e.target in case a previously chained
|
|
43
|
+
// focus handler already moved focus somewhere else.
|
|
44
|
+
const ownerDocument = (0, $hrHul$reactariautils.getOwnerDocument)(e.target);
|
|
45
|
+
if (e.target === e.currentTarget && ownerDocument.activeElement === e.target) {
|
|
46
|
+
if (onFocusProp) onFocusProp(e);
|
|
47
|
+
if (onFocusChange) onFocusChange(true);
|
|
48
|
+
onSyntheticFocus(e);
|
|
49
|
+
}
|
|
50
|
+
}, [
|
|
51
|
+
onFocusChange,
|
|
52
|
+
onFocusProp,
|
|
53
|
+
onSyntheticFocus
|
|
54
|
+
]);
|
|
55
|
+
return {
|
|
56
|
+
focusProps: {
|
|
57
|
+
onFocus: !isDisabled && (onFocusProp || onFocusChange || onBlurProp) ? onFocus : undefined,
|
|
58
|
+
onBlur: !isDisabled && (onBlurProp || onFocusChange) ? onBlur : undefined
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=useFocus.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;AAqB3G,SAAS,0CAA6D,KAAyB;IACpG,IAAI,cACF,UAAU,EACV,SAAS,WAAW,EACpB,QAAQ,UAAU,iBAClB,aAAa,EACd,GAAG;IAEJ,MAAM,SAAuC,CAAA,GAAA,wBAAU,EAAE,CAAC;QACxD,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,EAAE;YAChC,IAAI,YACF,WAAW;YAGb,IAAI,eACF,cAAc;YAGhB,OAAO;QACT;IACF,GAAG;QAAC;QAAY;KAAc;IAG9B,MAAM,mBAAmB,CAAA,GAAA,+CAAoB,EAAU;IAEvD,MAAM,UAAyC,CAAA,GAAA,wBAAU,EAAE,CAAC;QAC1D,kGAAkG;QAClG,oDAAoD;QAEpD,MAAM,gBAAgB,CAAA,GAAA,sCAAe,EAAE,EAAE,MAAM;QAE/C,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,IAAI,cAAc,aAAa,KAAK,EAAE,MAAM,EAAE;YAC5E,IAAI,aACF,YAAY;YAGd,IAAI,eACF,cAAc;YAGhB,iBAAiB;QACnB;IACF,GAAG;QAAC;QAAe;QAAa;KAAiB;IAEjD,OAAO;QACL,YAAY;YACV,SAAS,AAAC,CAAC,cAAe,CAAA,eAAe,iBAAiB,UAAS,IAAM,UAAU;YACnF,QAAQ,AAAC,CAAC,cAAe,CAAA,cAAc,aAAY,IAAM,SAAS;QACpE;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocus.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, FocusableElement, FocusEvents} from '@react-types/shared';\nimport {FocusEvent, useCallback} from 'react';\nimport {getOwnerDocument} from '@react-aria/utils';\nimport {useSyntheticBlurEvent} from './utils';\n\nexport interface FocusProps<Target = FocusableElement> extends FocusEvents<Target> {\n /** Whether the focus events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusResult<Target = FocusableElement> {\n /** Props to spread onto the target element. */\n focusProps: DOMAttributes<Target>\n}\n\n/**\n * Handles focus events for the immediate target.\n * Focus events on child elements will be ignored.\n */\nexport function useFocus<Target extends FocusableElement = FocusableElement>(props: FocusProps<Target>): FocusResult<Target> {\n let {\n isDisabled,\n onFocus: onFocusProp,\n onBlur: onBlurProp,\n onFocusChange\n } = props;\n\n const onBlur: FocusProps<Target>['onBlur'] = useCallback((e: FocusEvent<Target>) => {\n if (e.target === e.currentTarget) {\n if (onBlurProp) {\n onBlurProp(e);\n }\n\n if (onFocusChange) {\n onFocusChange(false);\n }\n\n return true;\n }\n }, [onBlurProp, onFocusChange]);\n\n\n const onSyntheticFocus = useSyntheticBlurEvent<Target>(onBlur);\n\n const onFocus: FocusProps<Target>['onFocus'] = useCallback((e: FocusEvent<Target>) => {\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n\n const ownerDocument = getOwnerDocument(e.target);\n\n if (e.target === e.currentTarget && ownerDocument.activeElement === e.target) {\n if (onFocusProp) {\n onFocusProp(e);\n }\n\n if (onFocusChange) {\n onFocusChange(true);\n }\n\n onSyntheticFocus(e);\n }\n }, [onFocusChange, onFocusProp, onSyntheticFocus]);\n\n return {\n focusProps: {\n onFocus: (!isDisabled && (onFocusProp || onFocusChange || onBlurProp)) ? onFocus : undefined,\n onBlur: (!isDisabled && (onBlurProp || onFocusChange)) ? onBlur : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocus.main.js.map"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.mjs";
|
|
2
|
+
import {useCallback as $hf0lj$useCallback} from "react";
|
|
3
|
+
import {getOwnerDocument as $hf0lj$getOwnerDocument} from "@react-aria/utils";
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
7
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
+
* governing permissions and limitations under the License.
|
|
15
|
+
*/ // Portions of the code in this file are based on code from react.
|
|
16
|
+
// Original licensing for the following can be found in the
|
|
17
|
+
// NOTICE file in the root directory of this source tree.
|
|
18
|
+
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
|
|
23
|
+
let { isDisabled: isDisabled, onFocus: onFocusProp, onBlur: onBlurProp, onFocusChange: onFocusChange } = props;
|
|
24
|
+
const onBlur = (0, $hf0lj$useCallback)((e)=>{
|
|
25
|
+
if (e.target === e.currentTarget) {
|
|
26
|
+
if (onBlurProp) onBlurProp(e);
|
|
27
|
+
if (onFocusChange) onFocusChange(false);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}, [
|
|
31
|
+
onBlurProp,
|
|
32
|
+
onFocusChange
|
|
33
|
+
]);
|
|
34
|
+
const onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
|
|
35
|
+
const onFocus = (0, $hf0lj$useCallback)((e)=>{
|
|
36
|
+
// Double check that document.activeElement actually matches e.target in case a previously chained
|
|
37
|
+
// focus handler already moved focus somewhere else.
|
|
38
|
+
const ownerDocument = (0, $hf0lj$getOwnerDocument)(e.target);
|
|
39
|
+
if (e.target === e.currentTarget && ownerDocument.activeElement === e.target) {
|
|
40
|
+
if (onFocusProp) onFocusProp(e);
|
|
41
|
+
if (onFocusChange) onFocusChange(true);
|
|
42
|
+
onSyntheticFocus(e);
|
|
43
|
+
}
|
|
44
|
+
}, [
|
|
45
|
+
onFocusChange,
|
|
46
|
+
onFocusProp,
|
|
47
|
+
onSyntheticFocus
|
|
48
|
+
]);
|
|
49
|
+
return {
|
|
50
|
+
focusProps: {
|
|
51
|
+
onFocus: !isDisabled && (onFocusProp || onFocusChange || onBlurProp) ? onFocus : undefined,
|
|
52
|
+
onBlur: !isDisabled && (onBlurProp || onFocusChange) ? onBlur : undefined
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
export {$a1ea59d68270f0dd$export$f8168d8dd8fd66e6 as useFocus};
|
|
59
|
+
//# sourceMappingURL=useFocus.module.js.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.module.js";
|
|
2
|
+
import {useCallback as $hf0lj$useCallback} from "react";
|
|
3
|
+
import {getOwnerDocument as $hf0lj$getOwnerDocument} from "@react-aria/utils";
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
7
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
9
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
12
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
13
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
14
|
+
* governing permissions and limitations under the License.
|
|
15
|
+
*/ // Portions of the code in this file are based on code from react.
|
|
16
|
+
// Original licensing for the following can be found in the
|
|
17
|
+
// NOTICE file in the root directory of this source tree.
|
|
18
|
+
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
function $a1ea59d68270f0dd$export$f8168d8dd8fd66e6(props) {
|
|
23
|
+
let { isDisabled: isDisabled, onFocus: onFocusProp, onBlur: onBlurProp, onFocusChange: onFocusChange } = props;
|
|
24
|
+
const onBlur = (0, $hf0lj$useCallback)((e)=>{
|
|
25
|
+
if (e.target === e.currentTarget) {
|
|
26
|
+
if (onBlurProp) onBlurProp(e);
|
|
27
|
+
if (onFocusChange) onFocusChange(false);
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
}, [
|
|
31
|
+
onBlurProp,
|
|
32
|
+
onFocusChange
|
|
33
|
+
]);
|
|
34
|
+
const onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
|
|
35
|
+
const onFocus = (0, $hf0lj$useCallback)((e)=>{
|
|
36
|
+
// Double check that document.activeElement actually matches e.target in case a previously chained
|
|
37
|
+
// focus handler already moved focus somewhere else.
|
|
38
|
+
const ownerDocument = (0, $hf0lj$getOwnerDocument)(e.target);
|
|
39
|
+
if (e.target === e.currentTarget && ownerDocument.activeElement === e.target) {
|
|
40
|
+
if (onFocusProp) onFocusProp(e);
|
|
41
|
+
if (onFocusChange) onFocusChange(true);
|
|
42
|
+
onSyntheticFocus(e);
|
|
43
|
+
}
|
|
44
|
+
}, [
|
|
45
|
+
onFocusChange,
|
|
46
|
+
onFocusProp,
|
|
47
|
+
onSyntheticFocus
|
|
48
|
+
]);
|
|
49
|
+
return {
|
|
50
|
+
focusProps: {
|
|
51
|
+
onFocus: !isDisabled && (onFocusProp || onFocusChange || onBlurProp) ? onFocus : undefined,
|
|
52
|
+
onBlur: !isDisabled && (onBlurProp || onFocusChange) ? onBlur : undefined
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
export {$a1ea59d68270f0dd$export$f8168d8dd8fd66e6 as useFocus};
|
|
59
|
+
//# sourceMappingURL=useFocus.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;AAqB3G,SAAS,0CAA6D,KAAyB;IACpG,IAAI,cACF,UAAU,EACV,SAAS,WAAW,EACpB,QAAQ,UAAU,iBAClB,aAAa,EACd,GAAG;IAEJ,MAAM,SAAuC,CAAA,GAAA,kBAAU,EAAE,CAAC;QACxD,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,EAAE;YAChC,IAAI,YACF,WAAW;YAGb,IAAI,eACF,cAAc;YAGhB,OAAO;QACT;IACF,GAAG;QAAC;QAAY;KAAc;IAG9B,MAAM,mBAAmB,CAAA,GAAA,yCAAoB,EAAU;IAEvD,MAAM,UAAyC,CAAA,GAAA,kBAAU,EAAE,CAAC;QAC1D,kGAAkG;QAClG,oDAAoD;QAEpD,MAAM,gBAAgB,CAAA,GAAA,uBAAe,EAAE,EAAE,MAAM;QAE/C,IAAI,EAAE,MAAM,KAAK,EAAE,aAAa,IAAI,cAAc,aAAa,KAAK,EAAE,MAAM,EAAE;YAC5E,IAAI,aACF,YAAY;YAGd,IAAI,eACF,cAAc;YAGhB,iBAAiB;QACnB;IACF,GAAG;QAAC;QAAe;QAAa;KAAiB;IAEjD,OAAO;QACL,YAAY;YACV,SAAS,AAAC,CAAC,cAAe,CAAA,eAAe,iBAAiB,UAAS,IAAM,UAAU;YACnF,QAAQ,AAAC,CAAC,cAAe,CAAA,cAAc,aAAY,IAAM,SAAS;QACpE;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocus.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, FocusableElement, FocusEvents} from '@react-types/shared';\nimport {FocusEvent, useCallback} from 'react';\nimport {getOwnerDocument} from '@react-aria/utils';\nimport {useSyntheticBlurEvent} from './utils';\n\nexport interface FocusProps<Target = FocusableElement> extends FocusEvents<Target> {\n /** Whether the focus events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface FocusResult<Target = FocusableElement> {\n /** Props to spread onto the target element. */\n focusProps: DOMAttributes<Target>\n}\n\n/**\n * Handles focus events for the immediate target.\n * Focus events on child elements will be ignored.\n */\nexport function useFocus<Target extends FocusableElement = FocusableElement>(props: FocusProps<Target>): FocusResult<Target> {\n let {\n isDisabled,\n onFocus: onFocusProp,\n onBlur: onBlurProp,\n onFocusChange\n } = props;\n\n const onBlur: FocusProps<Target>['onBlur'] = useCallback((e: FocusEvent<Target>) => {\n if (e.target === e.currentTarget) {\n if (onBlurProp) {\n onBlurProp(e);\n }\n\n if (onFocusChange) {\n onFocusChange(false);\n }\n\n return true;\n }\n }, [onBlurProp, onFocusChange]);\n\n\n const onSyntheticFocus = useSyntheticBlurEvent<Target>(onBlur);\n\n const onFocus: FocusProps<Target>['onFocus'] = useCallback((e: FocusEvent<Target>) => {\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n\n const ownerDocument = getOwnerDocument(e.target);\n\n if (e.target === e.currentTarget && ownerDocument.activeElement === e.target) {\n if (onFocusProp) {\n onFocusProp(e);\n }\n\n if (onFocusChange) {\n onFocusChange(true);\n }\n\n onSyntheticFocus(e);\n }\n }, [onFocusChange, onFocusProp, onSyntheticFocus]);\n\n return {\n focusProps: {\n onFocus: (!isDisabled && (onFocusProp || onFocusChange || onBlurProp)) ? onFocus : undefined,\n onBlur: (!isDisabled && (onBlurProp || onFocusChange)) ? onBlur : undefined\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocus.module.js.map"}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
var $cR3F8$reactariautils = require("@react-aria/utils");
|
|
2
|
+
var $cR3F8$react = require("react");
|
|
3
|
+
var $cR3F8$reactariassr = require("@react-aria/ssr");
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
function $parcel$export(e, n, v, s) {
|
|
7
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
$parcel$export(module.exports, "addWindowFocusTracking", () => $e77252a287ef94ab$export$2f1888112f558a7d);
|
|
11
|
+
$parcel$export(module.exports, "isFocusVisible", () => $e77252a287ef94ab$export$b9b3dfddab17db27);
|
|
12
|
+
$parcel$export(module.exports, "getInteractionModality", () => $e77252a287ef94ab$export$630ff653c5ada6a9);
|
|
13
|
+
$parcel$export(module.exports, "setInteractionModality", () => $e77252a287ef94ab$export$8397ddfc504fdb9a);
|
|
14
|
+
$parcel$export(module.exports, "useInteractionModality", () => $e77252a287ef94ab$export$98e20ec92f614cfe);
|
|
15
|
+
$parcel$export(module.exports, "useFocusVisible", () => $e77252a287ef94ab$export$ffd9e5021c1fb2d6);
|
|
16
|
+
$parcel$export(module.exports, "useFocusVisibleListener", () => $e77252a287ef94ab$export$ec71b4b83ac08ec3);
|
|
17
|
+
/*
|
|
18
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
19
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
20
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
21
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
22
|
+
*
|
|
23
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
24
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
25
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
26
|
+
* governing permissions and limitations under the License.
|
|
27
|
+
*/ // Portions of the code in this file are based on code from react.
|
|
28
|
+
// Original licensing for the following can be found in the
|
|
29
|
+
// NOTICE file in the root directory of this source tree.
|
|
30
|
+
// See https://github.com/facebook/react/tree/cc7c1aece46a6b69b41958d731e0fd27c94bfc6c/packages/react-interactions
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
let $e77252a287ef94ab$var$currentModality = null;
|
|
35
|
+
let $e77252a287ef94ab$var$changeHandlers = new Set();
|
|
36
|
+
let $e77252a287ef94ab$export$d90243b58daecda7 = new Map(); // We use a map here to support setting event listeners across multiple document objects.
|
|
37
|
+
let $e77252a287ef94ab$var$hasEventBeforeFocus = false;
|
|
38
|
+
let $e77252a287ef94ab$var$hasBlurredWindowRecently = false;
|
|
39
|
+
// Only Tab or Esc keys will make focus visible on text input elements
|
|
40
|
+
const $e77252a287ef94ab$var$FOCUS_VISIBLE_INPUT_KEYS = {
|
|
41
|
+
Tab: true,
|
|
42
|
+
Escape: true
|
|
43
|
+
};
|
|
44
|
+
function $e77252a287ef94ab$var$triggerChangeHandlers(modality, e) {
|
|
45
|
+
for (let handler of $e77252a287ef94ab$var$changeHandlers)handler(modality, e);
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus styles visible.
|
|
49
|
+
*/ function $e77252a287ef94ab$var$isValidKey(e) {
|
|
50
|
+
// Control and Shift keys trigger when navigating back to the tab with keyboard.
|
|
51
|
+
return !(e.metaKey || !(0, $cR3F8$reactariautils.isMac)() && e.altKey || e.ctrlKey || e.key === 'Control' || e.key === 'Shift' || e.key === 'Meta');
|
|
52
|
+
}
|
|
53
|
+
function $e77252a287ef94ab$var$handleKeyboardEvent(e) {
|
|
54
|
+
$e77252a287ef94ab$var$hasEventBeforeFocus = true;
|
|
55
|
+
if ($e77252a287ef94ab$var$isValidKey(e)) {
|
|
56
|
+
$e77252a287ef94ab$var$currentModality = 'keyboard';
|
|
57
|
+
$e77252a287ef94ab$var$triggerChangeHandlers('keyboard', e);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
function $e77252a287ef94ab$var$handlePointerEvent(e) {
|
|
61
|
+
$e77252a287ef94ab$var$currentModality = 'pointer';
|
|
62
|
+
if (e.type === 'mousedown' || e.type === 'pointerdown') {
|
|
63
|
+
$e77252a287ef94ab$var$hasEventBeforeFocus = true;
|
|
64
|
+
$e77252a287ef94ab$var$triggerChangeHandlers('pointer', e);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function $e77252a287ef94ab$var$handleClickEvent(e) {
|
|
68
|
+
if ((0, $cR3F8$reactariautils.isVirtualClick)(e)) {
|
|
69
|
+
$e77252a287ef94ab$var$hasEventBeforeFocus = true;
|
|
70
|
+
$e77252a287ef94ab$var$currentModality = 'virtual';
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function $e77252a287ef94ab$var$handleFocusEvent(e) {
|
|
74
|
+
// Firefox fires two extra focus events when the user first clicks into an iframe:
|
|
75
|
+
// first on the window, then on the document. We ignore these events so they don't
|
|
76
|
+
// cause keyboard focus rings to appear.
|
|
77
|
+
if (e.target === window || e.target === document) return;
|
|
78
|
+
// If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.
|
|
79
|
+
// This occurs, for example, when navigating a form with the next/previous buttons on iOS.
|
|
80
|
+
if (!$e77252a287ef94ab$var$hasEventBeforeFocus && !$e77252a287ef94ab$var$hasBlurredWindowRecently) {
|
|
81
|
+
$e77252a287ef94ab$var$currentModality = 'virtual';
|
|
82
|
+
$e77252a287ef94ab$var$triggerChangeHandlers('virtual', e);
|
|
83
|
+
}
|
|
84
|
+
$e77252a287ef94ab$var$hasEventBeforeFocus = false;
|
|
85
|
+
$e77252a287ef94ab$var$hasBlurredWindowRecently = false;
|
|
86
|
+
}
|
|
87
|
+
function $e77252a287ef94ab$var$handleWindowBlur() {
|
|
88
|
+
// When the window is blurred, reset state. This is necessary when tabbing out of the window,
|
|
89
|
+
// for example, since a subsequent focus event won't be fired.
|
|
90
|
+
$e77252a287ef94ab$var$hasEventBeforeFocus = false;
|
|
91
|
+
$e77252a287ef94ab$var$hasBlurredWindowRecently = true;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Setup global event listeners to control when keyboard focus style should be visible.
|
|
95
|
+
*/ function $e77252a287ef94ab$var$setupGlobalFocusEvents(element) {
|
|
96
|
+
if (typeof window === 'undefined' || $e77252a287ef94ab$export$d90243b58daecda7.get((0, $cR3F8$reactariautils.getOwnerWindow)(element))) return;
|
|
97
|
+
const windowObject = (0, $cR3F8$reactariautils.getOwnerWindow)(element);
|
|
98
|
+
const documentObject = (0, $cR3F8$reactariautils.getOwnerDocument)(element);
|
|
99
|
+
// Programmatic focus() calls shouldn't affect the current input modality.
|
|
100
|
+
// However, we need to detect other cases when a focus event occurs without
|
|
101
|
+
// a preceding user event (e.g. screen reader focus). Overriding the focus
|
|
102
|
+
// method on HTMLElement.prototype is a bit hacky, but works.
|
|
103
|
+
let focus = windowObject.HTMLElement.prototype.focus;
|
|
104
|
+
windowObject.HTMLElement.prototype.focus = function() {
|
|
105
|
+
$e77252a287ef94ab$var$hasEventBeforeFocus = true;
|
|
106
|
+
focus.apply(this, arguments);
|
|
107
|
+
};
|
|
108
|
+
documentObject.addEventListener('keydown', $e77252a287ef94ab$var$handleKeyboardEvent, true);
|
|
109
|
+
documentObject.addEventListener('keyup', $e77252a287ef94ab$var$handleKeyboardEvent, true);
|
|
110
|
+
documentObject.addEventListener('click', $e77252a287ef94ab$var$handleClickEvent, true);
|
|
111
|
+
// Register focus events on the window so they are sure to happen
|
|
112
|
+
// before React's event listeners (registered on the document).
|
|
113
|
+
windowObject.addEventListener('focus', $e77252a287ef94ab$var$handleFocusEvent, true);
|
|
114
|
+
windowObject.addEventListener('blur', $e77252a287ef94ab$var$handleWindowBlur, false);
|
|
115
|
+
if (typeof PointerEvent !== 'undefined') {
|
|
116
|
+
documentObject.addEventListener('pointerdown', $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
117
|
+
documentObject.addEventListener('pointermove', $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
118
|
+
documentObject.addEventListener('pointerup', $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
119
|
+
} else {
|
|
120
|
+
documentObject.addEventListener('mousedown', $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
121
|
+
documentObject.addEventListener('mousemove', $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
122
|
+
documentObject.addEventListener('mouseup', $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
123
|
+
}
|
|
124
|
+
// Add unmount handler
|
|
125
|
+
windowObject.addEventListener('beforeunload', ()=>{
|
|
126
|
+
$e77252a287ef94ab$var$tearDownWindowFocusTracking(element);
|
|
127
|
+
}, {
|
|
128
|
+
once: true
|
|
129
|
+
});
|
|
130
|
+
$e77252a287ef94ab$export$d90243b58daecda7.set(windowObject, {
|
|
131
|
+
focus: focus
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const $e77252a287ef94ab$var$tearDownWindowFocusTracking = (element, loadListener)=>{
|
|
135
|
+
const windowObject = (0, $cR3F8$reactariautils.getOwnerWindow)(element);
|
|
136
|
+
const documentObject = (0, $cR3F8$reactariautils.getOwnerDocument)(element);
|
|
137
|
+
if (loadListener) documentObject.removeEventListener('DOMContentLoaded', loadListener);
|
|
138
|
+
if (!$e77252a287ef94ab$export$d90243b58daecda7.has(windowObject)) return;
|
|
139
|
+
windowObject.HTMLElement.prototype.focus = $e77252a287ef94ab$export$d90243b58daecda7.get(windowObject).focus;
|
|
140
|
+
documentObject.removeEventListener('keydown', $e77252a287ef94ab$var$handleKeyboardEvent, true);
|
|
141
|
+
documentObject.removeEventListener('keyup', $e77252a287ef94ab$var$handleKeyboardEvent, true);
|
|
142
|
+
documentObject.removeEventListener('click', $e77252a287ef94ab$var$handleClickEvent, true);
|
|
143
|
+
windowObject.removeEventListener('focus', $e77252a287ef94ab$var$handleFocusEvent, true);
|
|
144
|
+
windowObject.removeEventListener('blur', $e77252a287ef94ab$var$handleWindowBlur, false);
|
|
145
|
+
if (typeof PointerEvent !== 'undefined') {
|
|
146
|
+
documentObject.removeEventListener('pointerdown', $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
147
|
+
documentObject.removeEventListener('pointermove', $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
148
|
+
documentObject.removeEventListener('pointerup', $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
149
|
+
} else {
|
|
150
|
+
documentObject.removeEventListener('mousedown', $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
151
|
+
documentObject.removeEventListener('mousemove', $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
152
|
+
documentObject.removeEventListener('mouseup', $e77252a287ef94ab$var$handlePointerEvent, true);
|
|
153
|
+
}
|
|
154
|
+
$e77252a287ef94ab$export$d90243b58daecda7.delete(windowObject);
|
|
155
|
+
};
|
|
156
|
+
function $e77252a287ef94ab$export$2f1888112f558a7d(element) {
|
|
157
|
+
const documentObject = (0, $cR3F8$reactariautils.getOwnerDocument)(element);
|
|
158
|
+
let loadListener;
|
|
159
|
+
if (documentObject.readyState !== 'loading') $e77252a287ef94ab$var$setupGlobalFocusEvents(element);
|
|
160
|
+
else {
|
|
161
|
+
loadListener = ()=>{
|
|
162
|
+
$e77252a287ef94ab$var$setupGlobalFocusEvents(element);
|
|
163
|
+
};
|
|
164
|
+
documentObject.addEventListener('DOMContentLoaded', loadListener);
|
|
165
|
+
}
|
|
166
|
+
return ()=>$e77252a287ef94ab$var$tearDownWindowFocusTracking(element, loadListener);
|
|
167
|
+
}
|
|
168
|
+
// Server-side rendering does not have the document object defined
|
|
169
|
+
// eslint-disable-next-line no-restricted-globals
|
|
170
|
+
if (typeof document !== 'undefined') $e77252a287ef94ab$export$2f1888112f558a7d();
|
|
171
|
+
function $e77252a287ef94ab$export$b9b3dfddab17db27() {
|
|
172
|
+
return $e77252a287ef94ab$var$currentModality !== 'pointer';
|
|
173
|
+
}
|
|
174
|
+
function $e77252a287ef94ab$export$630ff653c5ada6a9() {
|
|
175
|
+
return $e77252a287ef94ab$var$currentModality;
|
|
176
|
+
}
|
|
177
|
+
function $e77252a287ef94ab$export$8397ddfc504fdb9a(modality) {
|
|
178
|
+
$e77252a287ef94ab$var$currentModality = modality;
|
|
179
|
+
$e77252a287ef94ab$var$triggerChangeHandlers(modality, null);
|
|
180
|
+
}
|
|
181
|
+
function $e77252a287ef94ab$export$98e20ec92f614cfe() {
|
|
182
|
+
$e77252a287ef94ab$var$setupGlobalFocusEvents();
|
|
183
|
+
let [modality, setModality] = (0, $cR3F8$react.useState)($e77252a287ef94ab$var$currentModality);
|
|
184
|
+
(0, $cR3F8$react.useEffect)(()=>{
|
|
185
|
+
let handler = ()=>{
|
|
186
|
+
setModality($e77252a287ef94ab$var$currentModality);
|
|
187
|
+
};
|
|
188
|
+
$e77252a287ef94ab$var$changeHandlers.add(handler);
|
|
189
|
+
return ()=>{
|
|
190
|
+
$e77252a287ef94ab$var$changeHandlers.delete(handler);
|
|
191
|
+
};
|
|
192
|
+
}, []);
|
|
193
|
+
return (0, $cR3F8$reactariassr.useIsSSR)() ? null : modality;
|
|
194
|
+
}
|
|
195
|
+
const $e77252a287ef94ab$var$nonTextInputTypes = new Set([
|
|
196
|
+
'checkbox',
|
|
197
|
+
'radio',
|
|
198
|
+
'range',
|
|
199
|
+
'color',
|
|
200
|
+
'file',
|
|
201
|
+
'image',
|
|
202
|
+
'button',
|
|
203
|
+
'submit',
|
|
204
|
+
'reset'
|
|
205
|
+
]);
|
|
206
|
+
/**
|
|
207
|
+
* If this is attached to text input component, return if the event is a focus event (Tab/Escape keys pressed) so that
|
|
208
|
+
* focus visible style can be properly set.
|
|
209
|
+
*/ function $e77252a287ef94ab$var$isKeyboardFocusEvent(isTextInput, modality, e) {
|
|
210
|
+
var _e_target;
|
|
211
|
+
const IHTMLInputElement = typeof window !== 'undefined' ? (0, $cR3F8$reactariautils.getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLInputElement : HTMLInputElement;
|
|
212
|
+
const IHTMLTextAreaElement = typeof window !== 'undefined' ? (0, $cR3F8$reactariautils.getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLTextAreaElement : HTMLTextAreaElement;
|
|
213
|
+
const IHTMLElement = typeof window !== 'undefined' ? (0, $cR3F8$reactariautils.getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).HTMLElement : HTMLElement;
|
|
214
|
+
const IKeyboardEvent = typeof window !== 'undefined' ? (0, $cR3F8$reactariautils.getOwnerWindow)(e === null || e === void 0 ? void 0 : e.target).KeyboardEvent : KeyboardEvent;
|
|
215
|
+
isTextInput = isTextInput || (e === null || e === void 0 ? void 0 : e.target) instanceof IHTMLInputElement && !$e77252a287ef94ab$var$nonTextInputTypes.has(e === null || e === void 0 ? void 0 : (_e_target = e.target) === null || _e_target === void 0 ? void 0 : _e_target.type) || (e === null || e === void 0 ? void 0 : e.target) instanceof IHTMLTextAreaElement || (e === null || e === void 0 ? void 0 : e.target) instanceof IHTMLElement && (e === null || e === void 0 ? void 0 : e.target.isContentEditable);
|
|
216
|
+
return !(isTextInput && modality === 'keyboard' && e instanceof IKeyboardEvent && !$e77252a287ef94ab$var$FOCUS_VISIBLE_INPUT_KEYS[e.key]);
|
|
217
|
+
}
|
|
218
|
+
function $e77252a287ef94ab$export$ffd9e5021c1fb2d6(props = {}) {
|
|
219
|
+
let { isTextInput: isTextInput, autoFocus: autoFocus } = props;
|
|
220
|
+
let [isFocusVisibleState, setFocusVisible] = (0, $cR3F8$react.useState)(autoFocus || $e77252a287ef94ab$export$b9b3dfddab17db27());
|
|
221
|
+
$e77252a287ef94ab$export$ec71b4b83ac08ec3((isFocusVisible)=>{
|
|
222
|
+
setFocusVisible(isFocusVisible);
|
|
223
|
+
}, [
|
|
224
|
+
isTextInput
|
|
225
|
+
], {
|
|
226
|
+
isTextInput: isTextInput
|
|
227
|
+
});
|
|
228
|
+
return {
|
|
229
|
+
isFocusVisible: isFocusVisibleState
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function $e77252a287ef94ab$export$ec71b4b83ac08ec3(fn, deps, opts) {
|
|
233
|
+
$e77252a287ef94ab$var$setupGlobalFocusEvents();
|
|
234
|
+
(0, $cR3F8$react.useEffect)(()=>{
|
|
235
|
+
let handler = (modality, e)=>{
|
|
236
|
+
if (!$e77252a287ef94ab$var$isKeyboardFocusEvent(!!(opts === null || opts === void 0 ? void 0 : opts.isTextInput), modality, e)) return;
|
|
237
|
+
fn($e77252a287ef94ab$export$b9b3dfddab17db27());
|
|
238
|
+
};
|
|
239
|
+
$e77252a287ef94ab$var$changeHandlers.add(handler);
|
|
240
|
+
return ()=>{
|
|
241
|
+
$e77252a287ef94ab$var$changeHandlers.delete(handler);
|
|
242
|
+
};
|
|
243
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
244
|
+
}, deps);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
//# sourceMappingURL=useFocusVisible.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;AAsBlH,IAAI,wCAAmC;AACvC,IAAI,uCAAiB,IAAI;AAIlB,IAAI,4CAA0B,IAAI,OAAmC,yFAAyF;AACrK,IAAI,4CAAsB;AAC1B,IAAI,iDAA2B;AAE/B,sEAAsE;AACtE,MAAM,iDAA2B;IAC/B,KAAK;IACL,QAAQ;AACV;AAEA,SAAS,4CAAsB,QAAkB,EAAE,CAAe;IAChE,KAAK,IAAI,WAAW,qCAClB,QAAQ,UAAU;AAEtB;AAEA;;CAEC,GACD,SAAS,iCAAW,CAAgB;IAClC,gFAAgF;IAChF,OAAO,CAAE,CAAA,EAAE,OAAO,IAAK,CAAC,CAAA,GAAA,2BAAI,OAAO,EAAE,MAAM,IAAK,EAAE,O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W,GAAG,UAAU,IACzD;YAEF,GAAG;QACL;QACA,qCAAe,GAAG,CAAC;QACnB,OAAO;YACL,qCAAe,MAAM,CAAC;QACxB;IACF,uDAAuD;IACvD,GAAG;AACL","sources":["packages/@react-aria/interactions/src/useFocusVisible.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, getOwnerWindow, isMac, isVirtualClick} from '@react-aria/utils';\nimport {useEffect, useState} from 'react';\nimport {useIsSSR} from '@react-aria/ssr';\n\nexport type Modality = 'keyboard' | 'pointer' | 'virtual';\ntype HandlerEvent = PointerEvent | MouseEvent | KeyboardEvent | FocusEvent | null;\ntype Handler = (modality: Modality, e: HandlerEvent) => void;\nexport type FocusVisibleHandler = (isFocusVisible: boolean) => void;\nexport interface FocusVisibleProps {\n /** Whether the element is a text input. */\n isTextInput?: boolean,\n /** Whether the element will be auto focused. */\n autoFocus?: boolean\n}\n\nexport interface FocusVisibleResult {\n /** Whether keyboard focus is visible globally. */\n isFocusVisible: boolean\n}\n\nlet currentModality: null | Modality = null;\nlet changeHandlers = new Set<Handler>();\ninterface GlobalListenerData {\n focus: () => void\n}\nexport let hasSetupGlobalListeners = new Map<Window, GlobalListenerData>(); // We use a map here to support setting event listeners across multiple document objects.\nlet hasEventBeforeFocus = false;\nlet hasBlurredWindowRecently = false;\n\n// Only Tab or Esc keys will make focus visible on text input elements\nconst FOCUS_VISIBLE_INPUT_KEYS = {\n Tab: true,\n Escape: true\n};\n\nfunction triggerChangeHandlers(modality: Modality, e: HandlerEvent) {\n for (let handler of changeHandlers) {\n handler(modality, e);\n }\n}\n\n/**\n * Helper function to determine if a KeyboardEvent is unmodified and could make keyboard focus styles visible.\n */\nfunction isValidKey(e: KeyboardEvent) {\n // Control and Shift keys trigger when navigating back to the tab with keyboard.\n return !(e.metaKey || (!isMac() && e.altKey) || e.ctrlKey || e.key === 'Control' || e.key === 'Shift' || e.key === 'Meta');\n}\n\n\nfunction handleKeyboardEvent(e: KeyboardEvent) {\n hasEventBeforeFocus = true;\n if (isValidKey(e)) {\n currentModality = 'keyboard';\n triggerChangeHandlers('keyboard', e);\n }\n}\n\nfunction handlePointerEvent(e: PointerEvent | MouseEvent) {\n currentModality = 'pointer';\n if (e.type === 'mousedown' || e.type === 'pointerdown') {\n hasEventBeforeFocus = true;\n triggerChangeHandlers('pointer', e);\n }\n}\n\nfunction handleClickEvent(e: MouseEvent) {\n if (isVirtualClick(e)) {\n hasEventBeforeFocus = true;\n currentModality = 'virtual';\n }\n}\n\nfunction handleFocusEvent(e: FocusEvent) {\n // Firefox fires two extra focus events when the user first clicks into an iframe:\n // first on the window, then on the document. We ignore these events so they don't\n // cause keyboard focus rings to appear.\n if (e.target === window || e.target === document) {\n return;\n }\n\n // If a focus event occurs without a preceding keyboard or pointer event, switch to virtual modality.\n // This occurs, for example, when navigating a form with the next/previous buttons on iOS.\n if (!hasEventBeforeFocus && !hasBlurredWindowRecently) {\n currentModality = 'virtual';\n triggerChangeHandlers('virtual', e);\n }\n\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = false;\n}\n\nfunction handleWindowBlur() {\n // When the window is blurred, reset state. This is necessary when tabbing out of the window,\n // for example, since a subsequent focus event won't be fired.\n hasEventBeforeFocus = false;\n hasBlurredWindowRecently = true;\n}\n\n/**\n * Setup global event listeners to control when keyboard focus style should be visible.\n */\nfunction setupGlobalFocusEvents(element?: HTMLElement | null) {\n if (typeof window === 'undefined' || hasSetupGlobalListeners.get(getOwnerWindow(element))) {\n return;\n }\n\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n\n // Programmatic focus() calls shouldn't affect the current input modality.\n // However, we need to detect other cases when a focus event occurs without\n // a preceding user event (e.g. screen reader focus). Overriding the focus\n // method on HTMLElement.prototype is a bit hacky, but works.\n let focus = windowObject.HTMLElement.prototype.focus;\n windowObject.HTMLElement.prototype.focus = function () {\n hasEventBeforeFocus = true;\n focus.apply(this, arguments as unknown as [options?: FocusOptions | undefined]);\n };\n\n documentObject.addEventListener('keydown', handleKeyboardEvent, true);\n documentObject.addEventListener('keyup', handleKeyboardEvent, true);\n documentObject.addEventListener('click', handleClickEvent, true);\n\n // Register focus events on the window so they are sure to happen\n // before React's event listeners (registered on the document).\n windowObject.addEventListener('focus', handleFocusEvent, true);\n windowObject.addEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.addEventListener('pointerdown', handlePointerEvent, true);\n documentObject.addEventListener('pointermove', handlePointerEvent, true);\n documentObject.addEventListener('pointerup', handlePointerEvent, true);\n } else {\n documentObject.addEventListener('mousedown', handlePointerEvent, true);\n documentObject.addEventListener('mousemove', handlePointerEvent, true);\n documentObject.addEventListener('mouseup', handlePointerEvent, true);\n }\n\n // Add unmount handler\n windowObject.addEventListener('beforeunload', () => {\n tearDownWindowFocusTracking(element);\n }, {once: true});\n\n hasSetupGlobalListeners.set(windowObject, {focus});\n}\n\nconst tearDownWindowFocusTracking = (element, loadListener?: () => void) => {\n const windowObject = getOwnerWindow(element);\n const documentObject = getOwnerDocument(element);\n if (loadListener) {\n documentObject.removeEventListener('DOMContentLoaded', loadListener);\n }\n if (!hasSetupGlobalListeners.has(windowObject)) {\n return;\n }\n windowObject.HTMLElement.prototype.focus = hasSetupGlobalListeners.get(windowObject)!.focus;\n\n documentObject.removeEventListener('keydown', handleKeyboardEvent, true);\n documentObject.removeEventListener('keyup', handleKeyboardEvent, true);\n documentObject.removeEventListener('click', handleClickEvent, true);\n windowObject.removeEventListener('focus', handleFocusEvent, true);\n windowObject.removeEventListener('blur', handleWindowBlur, false);\n\n if (typeof PointerEvent !== 'undefined') {\n documentObject.removeEventListener('pointerdown', handlePointerEvent, true);\n documentObject.removeEventListener('pointermove', handlePointerEvent, true);\n documentObject.removeEventListener('pointerup', handlePointerEvent, true);\n } else {\n documentObject.removeEventListener('mousedown', handlePointerEvent, true);\n documentObject.removeEventListener('mousemove', handlePointerEvent, true);\n documentObject.removeEventListener('mouseup', handlePointerEvent, true);\n }\n\n hasSetupGlobalListeners.delete(windowObject);\n};\n\n/**\n * EXPERIMENTAL\n * Adds a window (i.e. iframe) to the list of windows that are being tracked for focus visible.\n *\n * Sometimes apps render portions of their tree into an iframe. In this case, we cannot accurately track if the focus\n * is visible because we cannot see interactions inside the iframe. If you have this in your application's architecture,\n * then this function will attach event listeners inside the iframe. You should call `addWindowFocusTracking` with an\n * element from inside the window you wish to add. We'll retrieve the relevant elements based on that.\n * Note, you do not need to call this for the default window, as we call it for you.\n *\n * When you are ready to stop listening, but you do not wish to unmount the iframe, you may call the cleanup function\n * returned by `addWindowFocusTracking`. Otherwise, when you unmount the iframe, all listeners and state will be cleaned\n * up automatically for you.\n *\n * @param element @default document.body - The element provided will be used to get the window to add.\n * @returns A function to remove the event listeners and cleanup the state.\n */\nexport function addWindowFocusTracking(element?: HTMLElement | null): () => void {\n const documentObject = getOwnerDocument(element);\n let loadListener;\n if (documentObject.readyState !== 'loading') {\n setupGlobalFocusEvents(element);\n } else {\n loadListener = () => {\n setupGlobalFocusEvents(element);\n };\n documentObject.addEventListener('DOMContentLoaded', loadListener);\n }\n\n return () => tearDownWindowFocusTracking(element, loadListener);\n}\n\n// Server-side rendering does not have the document object defined\n// eslint-disable-next-line no-restricted-globals\nif (typeof document !== 'undefined') {\n addWindowFocusTracking();\n}\n\n/**\n * If true, keyboard focus is visible.\n */\nexport function isFocusVisible(): boolean {\n return currentModality !== 'pointer';\n}\n\nexport function getInteractionModality(): Modality | null {\n return currentModality;\n}\n\nexport function setInteractionModality(modality: Modality) {\n currentModality = modality;\n triggerChangeHandlers(modality, null);\n}\n\n/**\n * Keeps state of the current modality.\n */\nexport function useInteractionModality(): Modality | null {\n setupGlobalFocusEvents();\n\n let [modality, setModality] = useState(currentModality);\n useEffect(() => {\n let handler = () => {\n setModality(currentModality);\n };\n\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n }, []);\n\n return useIsSSR() ? null : modality;\n}\n\nconst nonTextInputTypes = new Set([\n 'checkbox',\n 'radio',\n 'range',\n 'color',\n 'file',\n 'image',\n 'button',\n 'submit',\n 'reset'\n]);\n\n/**\n * If this is attached to text input component, return if the event is a focus event (Tab/Escape keys pressed) so that\n * focus visible style can be properly set.\n */\nfunction isKeyboardFocusEvent(isTextInput: boolean, modality: Modality, e: HandlerEvent) {\n const IHTMLInputElement = typeof window !== 'undefined' ? getOwnerWindow(e?.target as Element).HTMLInputElement : HTMLInputElement;\n const IHTMLTextAreaElement = typeof window !== 'undefined' ? getOwnerWindow(e?.target as Element).HTMLTextAreaElement : HTMLTextAreaElement;\n const IHTMLElement = typeof window !== 'undefined' ? getOwnerWindow(e?.target as Element).HTMLElement : HTMLElement;\n const IKeyboardEvent = typeof window !== 'undefined' ? getOwnerWindow(e?.target as Element).KeyboardEvent : KeyboardEvent;\n\n isTextInput = isTextInput ||\n (e?.target instanceof IHTMLInputElement && !nonTextInputTypes.has(e?.target?.type)) ||\n e?.target instanceof IHTMLTextAreaElement ||\n (e?.target instanceof IHTMLElement && e?.target.isContentEditable);\n return !(isTextInput && modality === 'keyboard' && e instanceof IKeyboardEvent && !FOCUS_VISIBLE_INPUT_KEYS[e.key]);\n}\n\n/**\n * Manages focus visible state for the page, and subscribes individual components for updates.\n */\nexport function useFocusVisible(props: FocusVisibleProps = {}): FocusVisibleResult {\n let {isTextInput, autoFocus} = props;\n let [isFocusVisibleState, setFocusVisible] = useState(autoFocus || isFocusVisible());\n useFocusVisibleListener((isFocusVisible) => {\n setFocusVisible(isFocusVisible);\n }, [isTextInput], {isTextInput});\n\n return {isFocusVisible: isFocusVisibleState};\n}\n\n/**\n * Listens for trigger change and reports if focus is visible (i.e., modality is not pointer).\n */\nexport function useFocusVisibleListener(fn: FocusVisibleHandler, deps: ReadonlyArray<any>, opts?: {isTextInput?: boolean}): void {\n setupGlobalFocusEvents();\n\n useEffect(() => {\n let handler = (modality: Modality, e: HandlerEvent) => {\n if (!isKeyboardFocusEvent(!!(opts?.isTextInput), modality, e)) {\n return;\n }\n fn(isFocusVisible());\n };\n changeHandlers.add(handler);\n return () => {\n changeHandlers.delete(handler);\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n"],"names":[],"version":3,"file":"useFocusVisible.main.js.map"}
|