@react-aria/interactions 3.27.1 → 3.28.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.
Files changed (118) hide show
  1. package/dist/import.mjs +21 -15
  2. package/dist/main.js +45 -39
  3. package/dist/main.js.map +1 -1
  4. package/dist/module.js +21 -15
  5. package/dist/module.js.map +1 -1
  6. package/dist/types/src/index.d.ts +31 -0
  7. package/package.json +16 -15
  8. package/src/index.ts +30 -34
  9. package/dist/PressResponder.main.js +0 -61
  10. package/dist/PressResponder.main.js.map +0 -1
  11. package/dist/PressResponder.mjs +0 -51
  12. package/dist/PressResponder.module.js +0 -51
  13. package/dist/PressResponder.module.js.map +0 -1
  14. package/dist/Pressable.main.js +0 -69
  15. package/dist/Pressable.main.js.map +0 -1
  16. package/dist/Pressable.mjs +0 -60
  17. package/dist/Pressable.module.js +0 -60
  18. package/dist/Pressable.module.js.map +0 -1
  19. package/dist/context.main.js +0 -30
  20. package/dist/context.main.js.map +0 -1
  21. package/dist/context.mjs +0 -21
  22. package/dist/context.module.js +0 -21
  23. package/dist/context.module.js.map +0 -1
  24. package/dist/createEventHandler.main.js +0 -46
  25. package/dist/createEventHandler.main.js.map +0 -1
  26. package/dist/createEventHandler.mjs +0 -41
  27. package/dist/createEventHandler.module.js +0 -41
  28. package/dist/createEventHandler.module.js.map +0 -1
  29. package/dist/focusSafely.main.js +0 -41
  30. package/dist/focusSafely.main.js.map +0 -1
  31. package/dist/focusSafely.mjs +0 -36
  32. package/dist/focusSafely.module.js +0 -36
  33. package/dist/focusSafely.module.js.map +0 -1
  34. package/dist/textSelection.main.js +0 -77
  35. package/dist/textSelection.main.js.map +0 -1
  36. package/dist/textSelection.mjs +0 -71
  37. package/dist/textSelection.module.js +0 -71
  38. package/dist/textSelection.module.js.map +0 -1
  39. package/dist/types.d.ts +0 -255
  40. package/dist/types.d.ts.map +0 -1
  41. package/dist/useFocus.main.js +0 -66
  42. package/dist/useFocus.main.js.map +0 -1
  43. package/dist/useFocus.mjs +0 -61
  44. package/dist/useFocus.module.js +0 -61
  45. package/dist/useFocus.module.js.map +0 -1
  46. package/dist/useFocusVisible.main.js +0 -267
  47. package/dist/useFocusVisible.main.js.map +0 -1
  48. package/dist/useFocusVisible.mjs +0 -255
  49. package/dist/useFocusVisible.module.js +0 -255
  50. package/dist/useFocusVisible.module.js.map +0 -1
  51. package/dist/useFocusWithin.main.js +0 -107
  52. package/dist/useFocusWithin.main.js.map +0 -1
  53. package/dist/useFocusWithin.mjs +0 -102
  54. package/dist/useFocusWithin.module.js +0 -102
  55. package/dist/useFocusWithin.module.js.map +0 -1
  56. package/dist/useFocusable.main.js +0 -113
  57. package/dist/useFocusable.main.js.map +0 -1
  58. package/dist/useFocusable.mjs +0 -101
  59. package/dist/useFocusable.module.js +0 -101
  60. package/dist/useFocusable.module.js.map +0 -1
  61. package/dist/useHover.main.js +0 -159
  62. package/dist/useHover.main.js.map +0 -1
  63. package/dist/useHover.mjs +0 -154
  64. package/dist/useHover.module.js +0 -154
  65. package/dist/useHover.module.js.map +0 -1
  66. package/dist/useInteractOutside.main.js +0 -107
  67. package/dist/useInteractOutside.main.js.map +0 -1
  68. package/dist/useInteractOutside.mjs +0 -102
  69. package/dist/useInteractOutside.module.js +0 -102
  70. package/dist/useInteractOutside.module.js.map +0 -1
  71. package/dist/useKeyboard.main.js +0 -30
  72. package/dist/useKeyboard.main.js.map +0 -1
  73. package/dist/useKeyboard.mjs +0 -25
  74. package/dist/useKeyboard.module.js +0 -25
  75. package/dist/useKeyboard.module.js.map +0 -1
  76. package/dist/useLongPress.main.js +0 -86
  77. package/dist/useLongPress.main.js.map +0 -1
  78. package/dist/useLongPress.mjs +0 -81
  79. package/dist/useLongPress.module.js +0 -81
  80. package/dist/useLongPress.module.js.map +0 -1
  81. package/dist/useMove.main.js +0 -272
  82. package/dist/useMove.main.js.map +0 -1
  83. package/dist/useMove.mjs +0 -267
  84. package/dist/useMove.module.js +0 -267
  85. package/dist/useMove.module.js.map +0 -1
  86. package/dist/usePress.main.js +0 -763
  87. package/dist/usePress.main.js.map +0 -1
  88. package/dist/usePress.mjs +0 -758
  89. package/dist/usePress.module.js +0 -758
  90. package/dist/usePress.module.js.map +0 -1
  91. package/dist/useScrollWheel.main.js +0 -41
  92. package/dist/useScrollWheel.main.js.map +0 -1
  93. package/dist/useScrollWheel.mjs +0 -36
  94. package/dist/useScrollWheel.module.js +0 -36
  95. package/dist/useScrollWheel.module.js.map +0 -1
  96. package/dist/utils.main.js +0 -164
  97. package/dist/utils.main.js.map +0 -1
  98. package/dist/utils.mjs +0 -155
  99. package/dist/utils.module.js +0 -155
  100. package/dist/utils.module.js.map +0 -1
  101. package/src/PressResponder.tsx +0 -67
  102. package/src/Pressable.tsx +0 -97
  103. package/src/context.ts +0 -23
  104. package/src/createEventHandler.ts +0 -55
  105. package/src/focusSafely.ts +0 -49
  106. package/src/textSelection.ts +0 -101
  107. package/src/useFocus.ts +0 -88
  108. package/src/useFocusVisible.ts +0 -359
  109. package/src/useFocusWithin.ts +0 -134
  110. package/src/useFocusable.tsx +0 -191
  111. package/src/useHover.ts +0 -222
  112. package/src/useInteractOutside.ts +0 -143
  113. package/src/useKeyboard.ts +0 -36
  114. package/src/useLongPress.ts +0 -135
  115. package/src/useMove.ts +0 -259
  116. package/src/usePress.ts +0 -1095
  117. package/src/useScrollWheel.ts +0 -41
  118. package/src/utils.ts +0 -175
@@ -1,107 +0,0 @@
1
- var $625cf83917e112ad$exports = require("./utils.main.js");
2
- var $kDAhS$react = require("react");
3
- var $kDAhS$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, "useFocusWithin", () => $d16842bbd0359d1b$export$420e68273165f4ec);
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 $d16842bbd0359d1b$export$420e68273165f4ec(props) {
29
- let { isDisabled: isDisabled, onBlurWithin: onBlurWithin, onFocusWithin: onFocusWithin, onFocusWithinChange: onFocusWithinChange } = props;
30
- let state = (0, $kDAhS$react.useRef)({
31
- isFocusWithin: false
32
- });
33
- let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $kDAhS$reactariautils.useGlobalListeners)();
34
- let onBlur = (0, $kDAhS$react.useCallback)((e)=>{
35
- // Ignore events bubbling through portals.
36
- if (!(0, $kDAhS$reactariautils.nodeContains)(e.currentTarget, (0, $kDAhS$reactariautils.getEventTarget)(e))) return;
37
- // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
38
- // when moving focus inside the element. Only trigger if the currentTarget doesn't
39
- // include the relatedTarget (where focus is moving).
40
- if (state.current.isFocusWithin && !(0, $kDAhS$reactariautils.nodeContains)(e.currentTarget, e.relatedTarget)) {
41
- state.current.isFocusWithin = false;
42
- removeAllGlobalListeners();
43
- if (onBlurWithin) onBlurWithin(e);
44
- if (onFocusWithinChange) onFocusWithinChange(false);
45
- }
46
- }, [
47
- onBlurWithin,
48
- onFocusWithinChange,
49
- state,
50
- removeAllGlobalListeners
51
- ]);
52
- let onSyntheticFocus = (0, $625cf83917e112ad$exports.useSyntheticBlurEvent)(onBlur);
53
- let onFocus = (0, $kDAhS$react.useCallback)((e)=>{
54
- // Ignore events bubbling through portals.
55
- if (!(0, $kDAhS$reactariautils.nodeContains)(e.currentTarget, (0, $kDAhS$reactariautils.getEventTarget)(e))) return;
56
- // Double check that document.activeElement actually matches e.target in case a previously chained
57
- // focus handler already moved focus somewhere else.
58
- let eventTarget = (0, $kDAhS$reactariautils.getEventTarget)(e);
59
- const ownerDocument = (0, $kDAhS$reactariautils.getOwnerDocument)(eventTarget);
60
- const activeElement = (0, $kDAhS$reactariautils.getActiveElement)(ownerDocument);
61
- if (!state.current.isFocusWithin && activeElement === eventTarget) {
62
- if (onFocusWithin) onFocusWithin(e);
63
- if (onFocusWithinChange) onFocusWithinChange(true);
64
- state.current.isFocusWithin = true;
65
- onSyntheticFocus(e);
66
- // Browsers don't fire blur events when elements are removed from the DOM.
67
- // However, if a focus event occurs outside the element we're tracking, we
68
- // can manually fire onBlur.
69
- let currentTarget = e.currentTarget;
70
- addGlobalListener(ownerDocument, 'focus', (e)=>{
71
- let eventTarget = (0, $kDAhS$reactariautils.getEventTarget)(e);
72
- if (state.current.isFocusWithin && !(0, $kDAhS$reactariautils.nodeContains)(currentTarget, eventTarget)) {
73
- let nativeEvent = new ownerDocument.defaultView.FocusEvent('blur', {
74
- relatedTarget: eventTarget
75
- });
76
- (0, $625cf83917e112ad$exports.setEventTarget)(nativeEvent, currentTarget);
77
- let event = (0, $625cf83917e112ad$exports.createSyntheticEvent)(nativeEvent);
78
- onBlur(event);
79
- }
80
- }, {
81
- capture: true
82
- });
83
- }
84
- }, [
85
- onFocusWithin,
86
- onFocusWithinChange,
87
- onSyntheticFocus,
88
- addGlobalListener,
89
- onBlur
90
- ]);
91
- if (isDisabled) return {
92
- focusWithinProps: {
93
- // These cannot be null, that would conflict in mergeProps
94
- onFocus: undefined,
95
- onBlur: undefined
96
- }
97
- };
98
- return {
99
- focusWithinProps: {
100
- onFocus: onFocus,
101
- onBlur: onBlur
102
- }
103
- };
104
- }
105
-
106
-
107
- //# sourceMappingURL=useFocusWith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C,aAAa,IAAI,kBAAkB,aAAa;YACjE,IAAI,eACF,cAAc;YAGhB,IAAI,qBACF,oBAAoB;YAGtB,MAAM,OAAO,CAAC,aAAa,GAAG;YAC9B,iBAAiB;YAEjB,0EAA0E;YAC1E,0EAA0E;YAC1E,4BAA4B;YAC5B,IAAI,gBAAgB,EAAE,aAAa;YACnC,kBAAkB,eAAe,SAAS,CAAA;gBACxC,IAAI,cAAc,CAAA,GAAA,oCAAa,EAAE;gBACjC,IAAI,MAAM,OAAO,CAAC,aAAa,IAAI,CAAC,CAAA,GAAA,kCAAW,EAAE,eAAe,cAAyB;oBACvF,IAAI,cAAc,IAAI,cAAc,WAAW,CAAE,UAAU,CAAC,QAAQ;wBAAC,eAAe;oBAAW;oBAC/F,CAAA,GAAA,wCAAa,EAAE,aAAa;oBAC5B,IAAI,QAAQ,CAAA,GAAA,8CAAmB,EAAc;oBAC7C,OAAO;gBACT;YACF,GAAG;gBAAC,SAAS;YAAI;QACnB;IACF,GAAG;QAAC;QAAe;QAAqB;QAAkB;QAAmB;KAAO;IAEpF,IAAI,YACF,OAAO;QACL,kBAAkB;YAChB,0DAA0D;YAC1D,SAAS;YACT,QAAQ;QACV;IACF;IAGF,OAAO;QACL,kBAAkB;qBAChB;oBACA;QACF;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocusWithin.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 {createSyntheticEvent, setEventTarget, useSyntheticBlurEvent} from './utils';\nimport {DOMAttributes} from '@react-types/shared';\nimport {FocusEvent, useCallback, useRef} from 'react';\nimport {getActiveElement, getEventTarget, getOwnerDocument, nodeContains, useGlobalListeners} from '@react-aria/utils';\n\nexport interface FocusWithinProps {\n /** Whether the focus within events should be disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the target element or a descendant receives focus. */\n onFocusWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the target element and all descendants lose focus. */\n onBlurWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the the focus within state changes. */\n onFocusWithinChange?: (isFocusWithin: boolean) => void\n}\n\nexport interface FocusWithinResult {\n /** Props to spread onto the target element. */\n focusWithinProps: DOMAttributes\n}\n\n/**\n * Handles focus events for the target and its descendants.\n */\nexport function useFocusWithin(props: FocusWithinProps): FocusWithinResult {\n let {\n isDisabled,\n onBlurWithin,\n onFocusWithin,\n onFocusWithinChange\n } = props;\n let state = useRef({\n isFocusWithin: false\n });\n\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n\n let onBlur = useCallback((e: FocusEvent) => {\n // Ignore events bubbling through portals.\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n // We don't want to trigger onBlurWithin and then immediately onFocusWithin again\n // when moving focus inside the element. Only trigger if the currentTarget doesn't\n // include the relatedTarget (where focus is moving).\n if (state.current.isFocusWithin && !nodeContains(e.currentTarget as Element, e.relatedTarget as Element)) {\n state.current.isFocusWithin = false;\n removeAllGlobalListeners();\n\n if (onBlurWithin) {\n onBlurWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(false);\n }\n }\n }, [onBlurWithin, onFocusWithinChange, state, removeAllGlobalListeners]);\n\n let onSyntheticFocus = useSyntheticBlurEvent(onBlur);\n let onFocus = useCallback((e: FocusEvent) => {\n // Ignore events bubbling through portals.\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n let eventTarget = getEventTarget(e);\n const ownerDocument = getOwnerDocument(eventTarget);\n const activeElement = getActiveElement(ownerDocument);\n if (!state.current.isFocusWithin && activeElement === eventTarget) {\n if (onFocusWithin) {\n onFocusWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(true);\n }\n\n state.current.isFocusWithin = true;\n onSyntheticFocus(e);\n\n // Browsers don't fire blur events when elements are removed from the DOM.\n // However, if a focus event occurs outside the element we're tracking, we\n // can manually fire onBlur.\n let currentTarget = e.currentTarget;\n addGlobalListener(ownerDocument, 'focus', e => {\n let eventTarget = getEventTarget(e);\n if (state.current.isFocusWithin && !nodeContains(currentTarget, eventTarget as Element)) {\n let nativeEvent = new ownerDocument.defaultView!.FocusEvent('blur', {relatedTarget: eventTarget});\n setEventTarget(nativeEvent, currentTarget);\n let event = createSyntheticEvent<FocusEvent>(nativeEvent);\n onBlur(event);\n }\n }, {capture: true});\n }\n }, [onFocusWithin, onFocusWithinChange, onSyntheticFocus, addGlobalListener, onBlur]);\n\n if (isDisabled) {\n return {\n focusWithinProps: {\n // These cannot be null, that would conflict in mergeProps\n onFocus: undefined,\n onBlur: undefined\n }\n };\n }\n\n return {\n focusWithinProps: {\n onFocus,\n onBlur\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocusWithin.main.js.map"}
@@ -1,102 +0,0 @@
1
- import {createSyntheticEvent as $8a9cb279dc87e130$export$525bc4921d56d4a, setEventTarget as $8a9cb279dc87e130$export$c2b7abe5d61ec696, useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.mjs";
2
- import {useRef as $3b9Q0$useRef, useCallback as $3b9Q0$useCallback} from "react";
3
- import {useGlobalListeners as $3b9Q0$useGlobalListeners, nodeContains as $3b9Q0$nodeContains, getEventTarget as $3b9Q0$getEventTarget, getOwnerDocument as $3b9Q0$getOwnerDocument, getActiveElement as $3b9Q0$getActiveElement} 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 $9ab94262bd0047c7$export$420e68273165f4ec(props) {
23
- let { isDisabled: isDisabled, onBlurWithin: onBlurWithin, onFocusWithin: onFocusWithin, onFocusWithinChange: onFocusWithinChange } = props;
24
- let state = (0, $3b9Q0$useRef)({
25
- isFocusWithin: false
26
- });
27
- let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $3b9Q0$useGlobalListeners)();
28
- let onBlur = (0, $3b9Q0$useCallback)((e)=>{
29
- // Ignore events bubbling through portals.
30
- if (!(0, $3b9Q0$nodeContains)(e.currentTarget, (0, $3b9Q0$getEventTarget)(e))) return;
31
- // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
32
- // when moving focus inside the element. Only trigger if the currentTarget doesn't
33
- // include the relatedTarget (where focus is moving).
34
- if (state.current.isFocusWithin && !(0, $3b9Q0$nodeContains)(e.currentTarget, e.relatedTarget)) {
35
- state.current.isFocusWithin = false;
36
- removeAllGlobalListeners();
37
- if (onBlurWithin) onBlurWithin(e);
38
- if (onFocusWithinChange) onFocusWithinChange(false);
39
- }
40
- }, [
41
- onBlurWithin,
42
- onFocusWithinChange,
43
- state,
44
- removeAllGlobalListeners
45
- ]);
46
- let onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
47
- let onFocus = (0, $3b9Q0$useCallback)((e)=>{
48
- // Ignore events bubbling through portals.
49
- if (!(0, $3b9Q0$nodeContains)(e.currentTarget, (0, $3b9Q0$getEventTarget)(e))) return;
50
- // Double check that document.activeElement actually matches e.target in case a previously chained
51
- // focus handler already moved focus somewhere else.
52
- let eventTarget = (0, $3b9Q0$getEventTarget)(e);
53
- const ownerDocument = (0, $3b9Q0$getOwnerDocument)(eventTarget);
54
- const activeElement = (0, $3b9Q0$getActiveElement)(ownerDocument);
55
- if (!state.current.isFocusWithin && activeElement === eventTarget) {
56
- if (onFocusWithin) onFocusWithin(e);
57
- if (onFocusWithinChange) onFocusWithinChange(true);
58
- state.current.isFocusWithin = true;
59
- onSyntheticFocus(e);
60
- // Browsers don't fire blur events when elements are removed from the DOM.
61
- // However, if a focus event occurs outside the element we're tracking, we
62
- // can manually fire onBlur.
63
- let currentTarget = e.currentTarget;
64
- addGlobalListener(ownerDocument, 'focus', (e)=>{
65
- let eventTarget = (0, $3b9Q0$getEventTarget)(e);
66
- if (state.current.isFocusWithin && !(0, $3b9Q0$nodeContains)(currentTarget, eventTarget)) {
67
- let nativeEvent = new ownerDocument.defaultView.FocusEvent('blur', {
68
- relatedTarget: eventTarget
69
- });
70
- (0, $8a9cb279dc87e130$export$c2b7abe5d61ec696)(nativeEvent, currentTarget);
71
- let event = (0, $8a9cb279dc87e130$export$525bc4921d56d4a)(nativeEvent);
72
- onBlur(event);
73
- }
74
- }, {
75
- capture: true
76
- });
77
- }
78
- }, [
79
- onFocusWithin,
80
- onFocusWithinChange,
81
- onSyntheticFocus,
82
- addGlobalListener,
83
- onBlur
84
- ]);
85
- if (isDisabled) return {
86
- focusWithinProps: {
87
- // These cannot be null, that would conflict in mergeProps
88
- onFocus: undefined,
89
- onBlur: undefined
90
- }
91
- };
92
- return {
93
- focusWithinProps: {
94
- onFocus: onFocus,
95
- onBlur: onBlur
96
- }
97
- };
98
- }
99
-
100
-
101
- export {$9ab94262bd0047c7$export$420e68273165f4ec as useFocusWithin};
102
- //# sourceMappingURL=useFocusWithin.module.js.map
@@ -1,102 +0,0 @@
1
- import {createSyntheticEvent as $8a9cb279dc87e130$export$525bc4921d56d4a, setEventTarget as $8a9cb279dc87e130$export$c2b7abe5d61ec696, useSyntheticBlurEvent as $8a9cb279dc87e130$export$715c682d09d639cc} from "./utils.module.js";
2
- import {useRef as $3b9Q0$useRef, useCallback as $3b9Q0$useCallback} from "react";
3
- import {useGlobalListeners as $3b9Q0$useGlobalListeners, nodeContains as $3b9Q0$nodeContains, getEventTarget as $3b9Q0$getEventTarget, getOwnerDocument as $3b9Q0$getOwnerDocument, getActiveElement as $3b9Q0$getActiveElement} 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 $9ab94262bd0047c7$export$420e68273165f4ec(props) {
23
- let { isDisabled: isDisabled, onBlurWithin: onBlurWithin, onFocusWithin: onFocusWithin, onFocusWithinChange: onFocusWithinChange } = props;
24
- let state = (0, $3b9Q0$useRef)({
25
- isFocusWithin: false
26
- });
27
- let { addGlobalListener: addGlobalListener, removeAllGlobalListeners: removeAllGlobalListeners } = (0, $3b9Q0$useGlobalListeners)();
28
- let onBlur = (0, $3b9Q0$useCallback)((e)=>{
29
- // Ignore events bubbling through portals.
30
- if (!(0, $3b9Q0$nodeContains)(e.currentTarget, (0, $3b9Q0$getEventTarget)(e))) return;
31
- // We don't want to trigger onBlurWithin and then immediately onFocusWithin again
32
- // when moving focus inside the element. Only trigger if the currentTarget doesn't
33
- // include the relatedTarget (where focus is moving).
34
- if (state.current.isFocusWithin && !(0, $3b9Q0$nodeContains)(e.currentTarget, e.relatedTarget)) {
35
- state.current.isFocusWithin = false;
36
- removeAllGlobalListeners();
37
- if (onBlurWithin) onBlurWithin(e);
38
- if (onFocusWithinChange) onFocusWithinChange(false);
39
- }
40
- }, [
41
- onBlurWithin,
42
- onFocusWithinChange,
43
- state,
44
- removeAllGlobalListeners
45
- ]);
46
- let onSyntheticFocus = (0, $8a9cb279dc87e130$export$715c682d09d639cc)(onBlur);
47
- let onFocus = (0, $3b9Q0$useCallback)((e)=>{
48
- // Ignore events bubbling through portals.
49
- if (!(0, $3b9Q0$nodeContains)(e.currentTarget, (0, $3b9Q0$getEventTarget)(e))) return;
50
- // Double check that document.activeElement actually matches e.target in case a previously chained
51
- // focus handler already moved focus somewhere else.
52
- let eventTarget = (0, $3b9Q0$getEventTarget)(e);
53
- const ownerDocument = (0, $3b9Q0$getOwnerDocument)(eventTarget);
54
- const activeElement = (0, $3b9Q0$getActiveElement)(ownerDocument);
55
- if (!state.current.isFocusWithin && activeElement === eventTarget) {
56
- if (onFocusWithin) onFocusWithin(e);
57
- if (onFocusWithinChange) onFocusWithinChange(true);
58
- state.current.isFocusWithin = true;
59
- onSyntheticFocus(e);
60
- // Browsers don't fire blur events when elements are removed from the DOM.
61
- // However, if a focus event occurs outside the element we're tracking, we
62
- // can manually fire onBlur.
63
- let currentTarget = e.currentTarget;
64
- addGlobalListener(ownerDocument, 'focus', (e)=>{
65
- let eventTarget = (0, $3b9Q0$getEventTarget)(e);
66
- if (state.current.isFocusWithin && !(0, $3b9Q0$nodeContains)(currentTarget, eventTarget)) {
67
- let nativeEvent = new ownerDocument.defaultView.FocusEvent('blur', {
68
- relatedTarget: eventTarget
69
- });
70
- (0, $8a9cb279dc87e130$export$c2b7abe5d61ec696)(nativeEvent, currentTarget);
71
- let event = (0, $8a9cb279dc87e130$export$525bc4921d56d4a)(nativeEvent);
72
- onBlur(event);
73
- }
74
- }, {
75
- capture: true
76
- });
77
- }
78
- }, [
79
- onFocusWithin,
80
- onFocusWithinChange,
81
- onSyntheticFocus,
82
- addGlobalListener,
83
- onBlur
84
- ]);
85
- if (isDisabled) return {
86
- focusWithinProps: {
87
- // These cannot be null, that would conflict in mergeProps
88
- onFocus: undefined,
89
- onBlur: undefined
90
- }
91
- };
92
- return {
93
- focusWithinProps: {
94
- onFocus: onFocus,
95
- onBlur: onBlur
96
- }
97
- };
98
- }
99
-
100
-
101
- export {$9ab94262bd0047c7$export$420e68273165f4ec as useFocusWithin};
102
- //# sourceMappingURL=useFocusWithin.module.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;AAAA;;;;;;;;;;CAUC,GAED,kEAAkE;AAClE,2DAA2D;AAC3D,yDAAyD;AACzD,kHAAkH;;;;AA0B3G,SAAS,0CAAe,KAAuB;IACpD,IAAI,cACF,UAAU,gBACV,YAAY,iBACZ,aAAa,uBACb,mBAAmB,EACpB,GAAG;IACJ,IAAI,QAAQ,CAAA,GAAA,aAAK,EAAE;QACjB,eAAe;IACjB;IAEA,IAAI,qBAAC,iBAAiB,4BAAE,wBAAwB,EAAC,GAAG,CAAA,GAAA,yBAAiB;IAErE,IAAI,SAAS,CAAA,GAAA,kBAAU,EAAE,CAAC;QACxB,0CAA0C;QAC1C,IAAI,CAAC,CAAA,GAAA,mBAAW,EAAE,EAAE,aAAa,EAAE,CAAA,GAAA,qBAAa,EAAE,KAChD;QAGF,iFAAiF;QACjF,kFAAkF;QAClF,qDAAqD;QACrD,IAAI,MAAM,OAAO,CAAC,aAAa,IAAI,CAAC,CAAA,GAAA,mBAAW,EAAE,E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AAO;IAEpF,IAAI,YACF,OAAO;QACL,kBAAkB;YAChB,0DAA0D;YAC1D,SAAS;YACT,QAAQ;QACV;IACF;IAGF,OAAO;QACL,kBAAkB;qBAChB;oBACA;QACF;IACF;AACF","sources":["packages/@react-aria/interactions/src/useFocusWithin.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 {createSyntheticEvent, setEventTarget, useSyntheticBlurEvent} from './utils';\nimport {DOMAttributes} from '@react-types/shared';\nimport {FocusEvent, useCallback, useRef} from 'react';\nimport {getActiveElement, getEventTarget, getOwnerDocument, nodeContains, useGlobalListeners} from '@react-aria/utils';\n\nexport interface FocusWithinProps {\n /** Whether the focus within events should be disabled. */\n isDisabled?: boolean,\n /** Handler that is called when the target element or a descendant receives focus. */\n onFocusWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the target element and all descendants lose focus. */\n onBlurWithin?: (e: FocusEvent) => void,\n /** Handler that is called when the the focus within state changes. */\n onFocusWithinChange?: (isFocusWithin: boolean) => void\n}\n\nexport interface FocusWithinResult {\n /** Props to spread onto the target element. */\n focusWithinProps: DOMAttributes\n}\n\n/**\n * Handles focus events for the target and its descendants.\n */\nexport function useFocusWithin(props: FocusWithinProps): FocusWithinResult {\n let {\n isDisabled,\n onBlurWithin,\n onFocusWithin,\n onFocusWithinChange\n } = props;\n let state = useRef({\n isFocusWithin: false\n });\n\n let {addGlobalListener, removeAllGlobalListeners} = useGlobalListeners();\n\n let onBlur = useCallback((e: FocusEvent) => {\n // Ignore events bubbling through portals.\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n // We don't want to trigger onBlurWithin and then immediately onFocusWithin again\n // when moving focus inside the element. Only trigger if the currentTarget doesn't\n // include the relatedTarget (where focus is moving).\n if (state.current.isFocusWithin && !nodeContains(e.currentTarget as Element, e.relatedTarget as Element)) {\n state.current.isFocusWithin = false;\n removeAllGlobalListeners();\n\n if (onBlurWithin) {\n onBlurWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(false);\n }\n }\n }, [onBlurWithin, onFocusWithinChange, state, removeAllGlobalListeners]);\n\n let onSyntheticFocus = useSyntheticBlurEvent(onBlur);\n let onFocus = useCallback((e: FocusEvent) => {\n // Ignore events bubbling through portals.\n if (!nodeContains(e.currentTarget, getEventTarget(e))) {\n return;\n }\n\n // Double check that document.activeElement actually matches e.target in case a previously chained\n // focus handler already moved focus somewhere else.\n let eventTarget = getEventTarget(e);\n const ownerDocument = getOwnerDocument(eventTarget);\n const activeElement = getActiveElement(ownerDocument);\n if (!state.current.isFocusWithin && activeElement === eventTarget) {\n if (onFocusWithin) {\n onFocusWithin(e);\n }\n\n if (onFocusWithinChange) {\n onFocusWithinChange(true);\n }\n\n state.current.isFocusWithin = true;\n onSyntheticFocus(e);\n\n // Browsers don't fire blur events when elements are removed from the DOM.\n // However, if a focus event occurs outside the element we're tracking, we\n // can manually fire onBlur.\n let currentTarget = e.currentTarget;\n addGlobalListener(ownerDocument, 'focus', e => {\n let eventTarget = getEventTarget(e);\n if (state.current.isFocusWithin && !nodeContains(currentTarget, eventTarget as Element)) {\n let nativeEvent = new ownerDocument.defaultView!.FocusEvent('blur', {relatedTarget: eventTarget});\n setEventTarget(nativeEvent, currentTarget);\n let event = createSyntheticEvent<FocusEvent>(nativeEvent);\n onBlur(event);\n }\n }, {capture: true});\n }\n }, [onFocusWithin, onFocusWithinChange, onSyntheticFocus, addGlobalListener, onBlur]);\n\n if (isDisabled) {\n return {\n focusWithinProps: {\n // These cannot be null, that would conflict in mergeProps\n onFocus: undefined,\n onBlur: undefined\n }\n };\n }\n\n return {\n focusWithinProps: {\n onFocus,\n onBlur\n }\n };\n}\n"],"names":[],"version":3,"file":"useFocusWithin.module.js.map"}
@@ -1,113 +0,0 @@
1
- var $2833058fcd3993f5$exports = require("./focusSafely.main.js");
2
- var $5cb73d0ce355b0dc$exports = require("./useFocus.main.js");
3
- var $892d64db2a3c53b0$exports = require("./useKeyboard.main.js");
4
- var $cvQje$reactariautils = require("@react-aria/utils");
5
- var $cvQje$react = require("react");
6
-
7
-
8
- function $parcel$interopDefault(a) {
9
- return a && a.__esModule ? a.default : a;
10
- }
11
-
12
- function $parcel$export(e, n, v, s) {
13
- Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
14
- }
15
-
16
- $parcel$export(module.exports, "FocusableContext", () => $15f8fd80892557ff$export$f9762fab77588ecb);
17
- $parcel$export(module.exports, "FocusableProvider", () => $15f8fd80892557ff$export$13f3202a3e5ddd5);
18
- $parcel$export(module.exports, "useFocusable", () => $15f8fd80892557ff$export$4c014de7c8940b4c);
19
- $parcel$export(module.exports, "Focusable", () => $15f8fd80892557ff$export$35a3bebf7ef2d934);
20
- /*
21
- * Copyright 2020 Adobe. All rights reserved.
22
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
23
- * you may not use this file except in compliance with the License. You may obtain a copy
24
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
25
- *
26
- * Unless required by applicable law or agreed to in writing, software distributed under
27
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
28
- * OF ANY KIND, either express or implied. See the License for the specific language
29
- * governing permissions and limitations under the License.
30
- */
31
-
32
-
33
-
34
-
35
- let $15f8fd80892557ff$export$f9762fab77588ecb = /*#__PURE__*/ (0, ($parcel$interopDefault($cvQje$react))).createContext(null);
36
- function $15f8fd80892557ff$var$useFocusableContext(ref) {
37
- let context = (0, $cvQje$react.useContext)($15f8fd80892557ff$export$f9762fab77588ecb) || {};
38
- (0, $cvQje$reactariautils.useSyncRef)(context, ref);
39
- // eslint-disable-next-line
40
- let { ref: _, ...otherProps } = context;
41
- return otherProps;
42
- }
43
- const $15f8fd80892557ff$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, ($parcel$interopDefault($cvQje$react))).forwardRef(function FocusableProvider(props, ref) {
44
- let { children: children, ...otherProps } = props;
45
- let objRef = (0, $cvQje$reactariautils.useObjectRef)(ref);
46
- let context = {
47
- ...otherProps,
48
- ref: objRef
49
- };
50
- return /*#__PURE__*/ (0, ($parcel$interopDefault($cvQje$react))).createElement($15f8fd80892557ff$export$f9762fab77588ecb.Provider, {
51
- value: context
52
- }, children);
53
- });
54
- function $15f8fd80892557ff$export$4c014de7c8940b4c(props, domRef) {
55
- let { focusProps: focusProps } = (0, $5cb73d0ce355b0dc$exports.useFocus)(props);
56
- let { keyboardProps: keyboardProps } = (0, $892d64db2a3c53b0$exports.useKeyboard)(props);
57
- let interactions = (0, $cvQje$reactariautils.mergeProps)(focusProps, keyboardProps);
58
- let domProps = $15f8fd80892557ff$var$useFocusableContext(domRef);
59
- let interactionProps = props.isDisabled ? {} : domProps;
60
- let autoFocusRef = (0, $cvQje$react.useRef)(props.autoFocus);
61
- (0, $cvQje$react.useEffect)(()=>{
62
- if (autoFocusRef.current && domRef.current) (0, $2833058fcd3993f5$exports.focusSafely)(domRef.current);
63
- autoFocusRef.current = false;
64
- }, [
65
- domRef
66
- ]);
67
- // Always set a tabIndex so that Safari allows focusing native buttons and inputs.
68
- let tabIndex = props.excludeFromTabOrder ? -1 : 0;
69
- if (props.isDisabled) tabIndex = undefined;
70
- return {
71
- focusableProps: (0, $cvQje$reactariautils.mergeProps)({
72
- ...interactions,
73
- tabIndex: tabIndex
74
- }, interactionProps)
75
- };
76
- }
77
- const $15f8fd80892557ff$export$35a3bebf7ef2d934 = /*#__PURE__*/ (0, $cvQje$react.forwardRef)(({ children: children, ...props }, ref)=>{
78
- ref = (0, $cvQje$reactariautils.useObjectRef)(ref);
79
- let { focusableProps: focusableProps } = $15f8fd80892557ff$export$4c014de7c8940b4c(props, ref);
80
- let child = (0, ($parcel$interopDefault($cvQje$react))).Children.only(children);
81
- (0, $cvQje$react.useEffect)(()=>{
82
- if (process.env.NODE_ENV === 'production') return;
83
- let el = ref.current;
84
- if (!el || !(el instanceof (0, $cvQje$reactariautils.getOwnerWindow)(el).Element)) {
85
- console.error('<Focusable> child must forward its ref to a DOM element.');
86
- return;
87
- }
88
- if (!props.isDisabled && !(0, $cvQje$reactariautils.isFocusable)(el)) {
89
- console.warn('<Focusable> child must be focusable. Please ensure the tabIndex prop is passed through.');
90
- return;
91
- }
92
- 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') {
93
- let role = el.getAttribute('role');
94
- if (!role) console.warn('<Focusable> child must have an interactive ARIA role.');
95
- else if (// https://w3c.github.io/aria/#widget_roles
96
- 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
97
- role !== 'img' && role !== 'meter' && role !== 'progressbar') console.warn(`<Focusable> child must have an interactive ARIA role. Got "${role}".`);
98
- }
99
- }, [
100
- ref,
101
- props.isDisabled
102
- ]);
103
- // @ts-ignore
104
- let childRef = parseInt((0, ($parcel$interopDefault($cvQje$react))).version, 10) < 19 ? child.ref : child.props.ref;
105
- return /*#__PURE__*/ (0, ($parcel$interopDefault($cvQje$react))).cloneElement(child, {
106
- ...(0, $cvQje$reactariautils.mergeProps)(focusableProps, child.props),
107
- // @ts-ignore
108
- ref: (0, $cvQje$reactariautils.mergeRefs)(childRef, ref)
109
- });
110
- });
111
-
112
-
113
- //# sourceMappingURL=useFocusable.main.js.map
@@ -1 +0,0 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;AAyBM,IAAI,0DAAgE,CAAA,GAAA,sCAAI,EAAE,aAAa,CAA+B;AAE7H,SAAS,0CAAoB,GAAuC;IAClE,IAAI,UAAU,CAAA,GAAA,uBAAS,EAAE,8CAAqB,CAAC;IAC/C,CAAA,GAAA,gCAAS,EAAE,SAAS;IAEpB,2BAA2B;IAC3B,IAAI,EAAC,KAAK,CAAC,EAAE,GAAG,YAAW,GAAG;IAC9B,OAAO;AACT;AAKO,MAAM,yDAEb,CAAA,GAAA,sCAAI,EAAE,UAAU,CAAC,SAAS,kBAAkB,KAA6B,EAAE,GAAmC;IAC5G,IAAI,YAAC,QAAQ,EAAE,GAAG,YAAW,GAAG;IAChC,IAAI,SAAS,CAAA,GAAA,kCAAW,EAAE;IAC1B,IAAI,UAAU;QACZ,GAAG,UAAU;QACb,KAAK;IACP;IAEA,qBACE,0DAAC,0CAAiB,QAAQ;QAAC,OAAO;OAC/B;AAGP;AAUO,SAAS,0CAA4D,KAA0B,EAAE,MAA0C;IAChJ,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,kCAAO,EAAE;IAC5B,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,qCAAU,EAAE;IAClC,IAAI,eAAe,CAAA,GAAA,gCAAS,EAAE,YAAY;IAC1C,IAAI,WAAW,0CAAoB;IACnC,IAAI,mBAAmB,MAAM,UAAU,GAAG,CAAC,IAAI;IAC/C,IAAI,eAAe,CAAA,GAAA,mBAAK,EAAE,MAAM,SAAS;IAEzC,CAAA,GAAA,sBA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CAAC;iBACR,IACL,2CAA2C;YAC3C,SAAS,iBACT,SAAS,YACT,SAAS,cACT,SAAS,cACT,SAAS,cACT,SAAS,UACT,SAAS,cACT,SAAS,sBACT,SAAS,mBACT,SAAS,YACT,SAAS,WACT,SAAS,eACT,SAAS,eACT,SAAS,YACT,SAAS,gBACT,SAAS,YACT,SAAS,SACT,SAAS,cACT,SAAS,aACT,SAAS,cACT,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,sCAAI,EAAE,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,GAAG;IAE7E,qBAAO,CAAA,GAAA,sCAAI,EAAE,YAAY,CACvB,OACA;QACE,GAAG,CAAA,GAAA,gCAAS,EAAE,gBAAgB,MAAM,KAAK,CAAC;QAC1C,aAAa;QACb,KAAK,CAAA,GAAA,+BAAQ,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.Context<FocusableContextValue | null> = 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:\n React.ForwardRefExoticComponent<FocusableProviderProps & React.RefAttributes<FocusableElement>> =\nReact.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:\n React.ForwardRefExoticComponent<FocusableComponentProps & React.RefAttributes<FocusableElement>> =\nforwardRef(({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 if (process.env.NODE_ENV === 'production') {\n return;\n }\n\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.main.js.map"}
@@ -1,101 +0,0 @@
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
- if (process.env.NODE_ENV === 'production') return;
70
- let el = ref.current;
71
- if (!el || !(el instanceof (0, $fcPuG$getOwnerWindow)(el).Element)) {
72
- console.error('<Focusable> child must forward its ref to a DOM element.');
73
- return;
74
- }
75
- if (!props.isDisabled && !(0, $fcPuG$isFocusable)(el)) {
76
- console.warn('<Focusable> child must be focusable. Please ensure the tabIndex prop is passed through.');
77
- return;
78
- }
79
- 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') {
80
- let role = el.getAttribute('role');
81
- if (!role) console.warn('<Focusable> child must have an interactive ARIA role.');
82
- else if (// https://w3c.github.io/aria/#widget_roles
83
- 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
84
- role !== 'img' && role !== 'meter' && role !== 'progressbar') console.warn(`<Focusable> child must have an interactive ARIA role. Got "${role}".`);
85
- }
86
- }, [
87
- ref,
88
- props.isDisabled
89
- ]);
90
- // @ts-ignore
91
- let childRef = parseInt((0, $fcPuG$react).version, 10) < 19 ? child.ref : child.props.ref;
92
- return /*#__PURE__*/ (0, $fcPuG$react).cloneElement(child, {
93
- ...(0, $fcPuG$mergeProps)(focusableProps, child.props),
94
- // @ts-ignore
95
- ref: (0, $fcPuG$mergeRefs)(childRef, ref)
96
- });
97
- });
98
-
99
-
100
- export {$f645667febf57a63$export$f9762fab77588ecb as FocusableContext, $f645667febf57a63$export$13f3202a3e5ddd5 as FocusableProvider, $f645667febf57a63$export$4c014de7c8940b4c as useFocusable, $f645667febf57a63$export$35a3bebf7ef2d934 as Focusable};
101
- //# sourceMappingURL=useFocusable.module.js.map