@react-aria/focus 3.16.2 → 3.17.1

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 (46) hide show
  1. package/dist/FocusRing.main.js +44 -0
  2. package/dist/FocusRing.main.js.map +1 -0
  3. package/dist/FocusRing.mjs +35 -0
  4. package/dist/FocusRing.module.js +35 -0
  5. package/dist/FocusRing.module.js.map +1 -0
  6. package/dist/FocusScope.main.js +728 -0
  7. package/dist/FocusScope.main.js.map +1 -0
  8. package/dist/FocusScope.mjs +714 -0
  9. package/dist/FocusScope.module.js +714 -0
  10. package/dist/FocusScope.module.js.map +1 -0
  11. package/dist/focusSafely.main.js +39 -0
  12. package/dist/focusSafely.main.js.map +1 -0
  13. package/dist/focusSafely.mjs +34 -0
  14. package/dist/focusSafely.module.js +34 -0
  15. package/dist/focusSafely.module.js.map +1 -0
  16. package/dist/import.mjs +7 -939
  17. package/dist/isElementVisible.main.js +41 -0
  18. package/dist/isElementVisible.main.js.map +1 -0
  19. package/dist/isElementVisible.mjs +36 -0
  20. package/dist/isElementVisible.module.js +36 -0
  21. package/dist/isElementVisible.module.js.map +1 -0
  22. package/dist/main.js +18 -953
  23. package/dist/main.js.map +1 -1
  24. package/dist/module.js +7 -939
  25. package/dist/module.js.map +1 -1
  26. package/dist/types.d.ts +1 -0
  27. package/dist/types.d.ts.map +1 -1
  28. package/dist/useFocusRing.main.js +50 -0
  29. package/dist/useFocusRing.main.js.map +1 -0
  30. package/dist/useFocusRing.mjs +45 -0
  31. package/dist/useFocusRing.module.js +45 -0
  32. package/dist/useFocusRing.module.js.map +1 -0
  33. package/dist/useFocusable.main.js +75 -0
  34. package/dist/useFocusable.main.js.map +1 -0
  35. package/dist/useFocusable.mjs +65 -0
  36. package/dist/useFocusable.module.js +65 -0
  37. package/dist/useFocusable.module.js.map +1 -0
  38. package/dist/useHasTabbableChild.main.js +62 -0
  39. package/dist/useHasTabbableChild.main.js.map +1 -0
  40. package/dist/useHasTabbableChild.mjs +57 -0
  41. package/dist/useHasTabbableChild.module.js +57 -0
  42. package/dist/useHasTabbableChild.module.js.map +1 -0
  43. package/package.json +5 -5
  44. package/src/FocusScope.tsx +6 -2
  45. package/src/index.ts +1 -1
  46. package/src/isElementVisible.ts +2 -0
package/dist/main.js CHANGED
@@ -1,28 +1,27 @@
1
- var $aB6Cp$reactariautils = require("@react-aria/utils");
2
- var $aB6Cp$react = require("react");
3
- var $aB6Cp$reactariainteractions = require("@react-aria/interactions");
4
- var $aB6Cp$clsx = require("clsx");
1
+ var $a7a032acae3ddda9$exports = require("./FocusScope.main.js");
2
+ var $dfd8c70b928eb1b3$exports = require("./FocusRing.main.js");
3
+ var $fb504d83237fd6ac$exports = require("./useFocusable.main.js");
4
+ var $581a96d6eb128c1b$exports = require("./useFocusRing.main.js");
5
+ var $1c7f9157d722357d$exports = require("./focusSafely.main.js");
6
+ var $259c6413a286f2e6$exports = require("./useHasTabbableChild.main.js");
5
7
 
6
8
 
7
9
  function $parcel$export(e, n, v, s) {
8
10
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
11
  }
10
12
 
11
- function $parcel$interopDefault(a) {
12
- return a && a.__esModule ? a.default : a;
13
- }
14
-
15
- $parcel$export(module.exports, "FocusScope", () => $a7a032acae3ddda9$export$20e40289641fbbb6);
16
- $parcel$export(module.exports, "useFocusManager", () => $a7a032acae3ddda9$export$10c5169755ce7bd7);
17
- $parcel$export(module.exports, "getFocusableTreeWalker", () => $a7a032acae3ddda9$export$2d6ec8fc375ceafa);
18
- $parcel$export(module.exports, "createFocusManager", () => $a7a032acae3ddda9$export$c5251b9e124bf29);
19
- $parcel$export(module.exports, "isElementInChildOfActiveScope", () => $a7a032acae3ddda9$export$1258395f99bf9cbf);
20
- $parcel$export(module.exports, "FocusRing", () => $dfd8c70b928eb1b3$export$1a38b4ad7f578e1d);
21
- $parcel$export(module.exports, "FocusableProvider", () => $fb504d83237fd6ac$export$13f3202a3e5ddd5);
22
- $parcel$export(module.exports, "useFocusable", () => $fb504d83237fd6ac$export$4c014de7c8940b4c);
23
- $parcel$export(module.exports, "useFocusRing", () => $581a96d6eb128c1b$export$4e328f61c538687f);
24
- $parcel$export(module.exports, "focusSafely", () => $1c7f9157d722357d$export$80f3e147d781571c);
25
- $parcel$export(module.exports, "useHasTabbableChild", () => $259c6413a286f2e6$export$eac1895992b9f3d6);
13
+ $parcel$export(module.exports, "FocusScope", () => $a7a032acae3ddda9$exports.FocusScope);
14
+ $parcel$export(module.exports, "useFocusManager", () => $a7a032acae3ddda9$exports.useFocusManager);
15
+ $parcel$export(module.exports, "getFocusableTreeWalker", () => $a7a032acae3ddda9$exports.getFocusableTreeWalker);
16
+ $parcel$export(module.exports, "createFocusManager", () => $a7a032acae3ddda9$exports.createFocusManager);
17
+ $parcel$export(module.exports, "isElementInChildOfActiveScope", () => $a7a032acae3ddda9$exports.isElementInChildOfActiveScope);
18
+ $parcel$export(module.exports, "isFocusable", () => $a7a032acae3ddda9$exports.isFocusable);
19
+ $parcel$export(module.exports, "FocusRing", () => $dfd8c70b928eb1b3$exports.FocusRing);
20
+ $parcel$export(module.exports, "FocusableProvider", () => $fb504d83237fd6ac$exports.FocusableProvider);
21
+ $parcel$export(module.exports, "useFocusable", () => $fb504d83237fd6ac$exports.useFocusable);
22
+ $parcel$export(module.exports, "useFocusRing", () => $581a96d6eb128c1b$exports.useFocusRing);
23
+ $parcel$export(module.exports, "focusSafely", () => $1c7f9157d722357d$exports.focusSafely);
24
+ $parcel$export(module.exports, "useHasTabbableChild", () => $259c6413a286f2e6$exports.useHasTabbableChild);
26
25
  /*
27
26
  * Copyright 2020 Adobe. All rights reserved.
28
27
  * This file is licensed to you under the Apache License, Version 2.0 (the "License");
@@ -33,944 +32,10 @@ $parcel$export(module.exports, "useHasTabbableChild", () => $259c6413a286f2e6$ex
33
32
  * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
34
33
  * OF ANY KIND, either express or implied. See the License for the specific language
35
34
  * governing permissions and limitations under the License.
36
- */ /*
37
- * Copyright 2020 Adobe. All rights reserved.
38
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
39
- * you may not use this file except in compliance with the License. You may obtain a copy
40
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
41
- *
42
- * Unless required by applicable law or agreed to in writing, software distributed under
43
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
44
- * OF ANY KIND, either express or implied. See the License for the specific language
45
- * governing permissions and limitations under the License.
46
- */ /*
47
- * Copyright 2020 Adobe. All rights reserved.
48
- * This file is licensed to you under the Apache License, Version 2.0 (the 'License');
49
- * you may not use this file except in compliance with the License. You may obtain a copy
50
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
51
- *
52
- * Unless required by applicable law or agreed to in writing, software distributed under
53
- * the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
54
- * OF ANY KIND, either express or implied. See the License for the specific language
55
- * governing permissions and limitations under the License.
56
- */
57
-
58
- function $1c7f9157d722357d$export$80f3e147d781571c(element) {
59
- // If the user is interacting with a virtual cursor, e.g. screen reader, then
60
- // wait until after any animated transitions that are currently occurring on
61
- // the page before shifting focus. This avoids issues with VoiceOver on iOS
62
- // causing the page to scroll when moving focus if the element is transitioning
63
- // from off the screen.
64
- const ownerDocument = (0, $aB6Cp$reactariautils.getOwnerDocument)(element);
65
- if ((0, $aB6Cp$reactariainteractions.getInteractionModality)() === "virtual") {
66
- let lastFocusedElement = ownerDocument.activeElement;
67
- (0, $aB6Cp$reactariautils.runAfterTransition)(()=>{
68
- // If focus did not move and the element is still in the document, focus it.
69
- if (ownerDocument.activeElement === lastFocusedElement && element.isConnected) (0, $aB6Cp$reactariautils.focusWithoutScrolling)(element);
70
- });
71
- } else (0, $aB6Cp$reactariautils.focusWithoutScrolling)(element);
72
- }
73
-
74
-
75
-
76
- /*
77
- * Copyright 2021 Adobe. All rights reserved.
78
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
79
- * you may not use this file except in compliance with the License. You may obtain a copy
80
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
81
- *
82
- * Unless required by applicable law or agreed to in writing, software distributed under
83
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
84
- * OF ANY KIND, either express or implied. See the License for the specific language
85
- * governing permissions and limitations under the License.
86
35
  */
87
- function $d5156037ad898a4d$var$isStyleVisible(element) {
88
- const windowObject = (0, $aB6Cp$reactariautils.getOwnerWindow)(element);
89
- if (!(element instanceof windowObject.HTMLElement) && !(element instanceof windowObject.SVGElement)) return false;
90
- let { display: display, visibility: visibility } = element.style;
91
- let isVisible = display !== "none" && visibility !== "hidden" && visibility !== "collapse";
92
- if (isVisible) {
93
- const { getComputedStyle: getComputedStyle } = element.ownerDocument.defaultView;
94
- let { display: computedDisplay, visibility: computedVisibility } = getComputedStyle(element);
95
- isVisible = computedDisplay !== "none" && computedVisibility !== "hidden" && computedVisibility !== "collapse";
96
- }
97
- return isVisible;
98
- }
99
- function $d5156037ad898a4d$var$isAttributeVisible(element, childElement) {
100
- return !element.hasAttribute("hidden") && (element.nodeName === "DETAILS" && childElement && childElement.nodeName !== "SUMMARY" ? element.hasAttribute("open") : true);
101
- }
102
- function $d5156037ad898a4d$export$e989c0fffaa6b27a(element, childElement) {
103
- return element.nodeName !== "#comment" && $d5156037ad898a4d$var$isStyleVisible(element) && $d5156037ad898a4d$var$isAttributeVisible(element, childElement) && (!element.parentElement || $d5156037ad898a4d$export$e989c0fffaa6b27a(element.parentElement, element));
104
- }
105
36
 
106
37
 
107
38
 
108
- const $a7a032acae3ddda9$var$FocusContext = /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).createContext(null);
109
- let $a7a032acae3ddda9$var$activeScope = null;
110
- function $a7a032acae3ddda9$export$20e40289641fbbb6(props) {
111
- let { children: children, contain: contain, restoreFocus: restoreFocus, autoFocus: autoFocus } = props;
112
- let startRef = (0, $aB6Cp$react.useRef)(null);
113
- let endRef = (0, $aB6Cp$react.useRef)(null);
114
- let scopeRef = (0, $aB6Cp$react.useRef)([]);
115
- let { parentNode: parentNode } = (0, $aB6Cp$react.useContext)($a7a032acae3ddda9$var$FocusContext) || {};
116
- // Create a tree node here so we can add children to it even before it is added to the tree.
117
- let node = (0, $aB6Cp$react.useMemo)(()=>new $a7a032acae3ddda9$var$TreeNode({
118
- scopeRef: scopeRef
119
- }), [
120
- scopeRef
121
- ]);
122
- (0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
123
- // If a new scope mounts outside the active scope, (e.g. DialogContainer launched from a menu),
124
- // use the active scope as the parent instead of the parent from context. Layout effects run bottom
125
- // up, so if the parent is not yet added to the tree, don't do this. Only the outer-most FocusScope
126
- // that is being added should get the activeScope as its parent.
127
- let parent = parentNode || $a7a032acae3ddda9$export$d06fae2ee68b101e.root;
128
- if ($a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(parent.scopeRef) && $a7a032acae3ddda9$var$activeScope && !$a7a032acae3ddda9$var$isAncestorScope($a7a032acae3ddda9$var$activeScope, parent.scopeRef)) {
129
- let activeNode = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode($a7a032acae3ddda9$var$activeScope);
130
- if (activeNode) parent = activeNode;
131
- }
132
- // Add the node to the parent, and to the tree.
133
- parent.addChild(node);
134
- $a7a032acae3ddda9$export$d06fae2ee68b101e.addNode(node);
135
- }, [
136
- node,
137
- parentNode
138
- ]);
139
- (0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
140
- let node = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef);
141
- if (node) node.contain = !!contain;
142
- }, [
143
- contain
144
- ]);
145
- (0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
146
- var _startRef_current;
147
- // Find all rendered nodes between the sentinels and add them to the scope.
148
- let node = (_startRef_current = startRef.current) === null || _startRef_current === void 0 ? void 0 : _startRef_current.nextSibling;
149
- let nodes = [];
150
- while(node && node !== endRef.current){
151
- nodes.push(node);
152
- node = node.nextSibling;
153
- }
154
- scopeRef.current = nodes;
155
- }, [
156
- children
157
- ]);
158
- $a7a032acae3ddda9$var$useActiveScopeTracker(scopeRef, restoreFocus, contain);
159
- $a7a032acae3ddda9$var$useFocusContainment(scopeRef, contain);
160
- $a7a032acae3ddda9$var$useRestoreFocus(scopeRef, restoreFocus, contain);
161
- $a7a032acae3ddda9$var$useAutoFocus(scopeRef, autoFocus);
162
- // This needs to be an effect so that activeScope is updated after the FocusScope tree is complete.
163
- // It cannot be a useLayoutEffect because the parent of this node hasn't been attached in the tree yet.
164
- (0, $aB6Cp$react.useEffect)(()=>{
165
- const activeElement = (0, $aB6Cp$reactariautils.getOwnerDocument)(scopeRef.current ? scopeRef.current[0] : undefined).activeElement;
166
- let scope = null;
167
- if ($a7a032acae3ddda9$var$isElementInScope(activeElement, scopeRef.current)) {
168
- // We need to traverse the focusScope tree and find the bottom most scope that
169
- // contains the active element and set that as the activeScope.
170
- for (let node of $a7a032acae3ddda9$export$d06fae2ee68b101e.traverse())if (node.scopeRef && $a7a032acae3ddda9$var$isElementInScope(activeElement, node.scopeRef.current)) scope = node;
171
- if (scope === $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef)) $a7a032acae3ddda9$var$activeScope = scope.scopeRef;
172
- }
173
- }, [
174
- scopeRef
175
- ]);
176
- // This layout effect cleanup is so that the tree node is removed synchronously with react before the RAF
177
- // in useRestoreFocus cleanup runs.
178
- (0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
179
- return ()=>{
180
- var _focusScopeTree_getTreeNode_parent, _focusScopeTree_getTreeNode;
181
- var _focusScopeTree_getTreeNode_parent_scopeRef;
182
- // Scope may have been re-parented.
183
- let parentScope = (_focusScopeTree_getTreeNode_parent_scopeRef = (_focusScopeTree_getTreeNode = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef)) === null || _focusScopeTree_getTreeNode === void 0 ? void 0 : (_focusScopeTree_getTreeNode_parent = _focusScopeTree_getTreeNode.parent) === null || _focusScopeTree_getTreeNode_parent === void 0 ? void 0 : _focusScopeTree_getTreeNode_parent.scopeRef) !== null && _focusScopeTree_getTreeNode_parent_scopeRef !== void 0 ? _focusScopeTree_getTreeNode_parent_scopeRef : null;
184
- if ((scopeRef === $a7a032acae3ddda9$var$activeScope || $a7a032acae3ddda9$var$isAncestorScope(scopeRef, $a7a032acae3ddda9$var$activeScope)) && (!parentScope || $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(parentScope))) $a7a032acae3ddda9$var$activeScope = parentScope;
185
- $a7a032acae3ddda9$export$d06fae2ee68b101e.removeTreeNode(scopeRef);
186
- };
187
- }, [
188
- scopeRef
189
- ]);
190
- let focusManager = (0, $aB6Cp$react.useMemo)(()=>$a7a032acae3ddda9$var$createFocusManagerForScope(scopeRef), []);
191
- let value = (0, $aB6Cp$react.useMemo)(()=>({
192
- focusManager: focusManager,
193
- parentNode: node
194
- }), [
195
- node,
196
- focusManager
197
- ]);
198
- return /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).createElement($a7a032acae3ddda9$var$FocusContext.Provider, {
199
- value: value
200
- }, /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).createElement("span", {
201
- "data-focus-scope-start": true,
202
- hidden: true,
203
- ref: startRef
204
- }), children, /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).createElement("span", {
205
- "data-focus-scope-end": true,
206
- hidden: true,
207
- ref: endRef
208
- }));
209
- }
210
- function $a7a032acae3ddda9$export$10c5169755ce7bd7() {
211
- var _useContext;
212
- return (_useContext = (0, $aB6Cp$react.useContext)($a7a032acae3ddda9$var$FocusContext)) === null || _useContext === void 0 ? void 0 : _useContext.focusManager;
213
- }
214
- function $a7a032acae3ddda9$var$createFocusManagerForScope(scopeRef) {
215
- return {
216
- focusNext (opts = {}) {
217
- let scope = scopeRef.current;
218
- let { from: from, tabbable: tabbable, wrap: wrap, accept: accept } = opts;
219
- let node = from || (0, $aB6Cp$reactariautils.getOwnerDocument)(scope[0]).activeElement;
220
- let sentinel = scope[0].previousElementSibling;
221
- let scopeRoot = $a7a032acae3ddda9$var$getScopeRoot(scope);
222
- let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa(scopeRoot, {
223
- tabbable: tabbable,
224
- accept: accept
225
- }, scope);
226
- walker.currentNode = $a7a032acae3ddda9$var$isElementInScope(node, scope) ? node : sentinel;
227
- let nextNode = walker.nextNode();
228
- if (!nextNode && wrap) {
229
- walker.currentNode = sentinel;
230
- nextNode = walker.nextNode();
231
- }
232
- if (nextNode) $a7a032acae3ddda9$var$focusElement(nextNode, true);
233
- return nextNode;
234
- },
235
- focusPrevious (opts = {}) {
236
- let scope = scopeRef.current;
237
- let { from: from, tabbable: tabbable, wrap: wrap, accept: accept } = opts;
238
- let node = from || (0, $aB6Cp$reactariautils.getOwnerDocument)(scope[0]).activeElement;
239
- let sentinel = scope[scope.length - 1].nextElementSibling;
240
- let scopeRoot = $a7a032acae3ddda9$var$getScopeRoot(scope);
241
- let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa(scopeRoot, {
242
- tabbable: tabbable,
243
- accept: accept
244
- }, scope);
245
- walker.currentNode = $a7a032acae3ddda9$var$isElementInScope(node, scope) ? node : sentinel;
246
- let previousNode = walker.previousNode();
247
- if (!previousNode && wrap) {
248
- walker.currentNode = sentinel;
249
- previousNode = walker.previousNode();
250
- }
251
- if (previousNode) $a7a032acae3ddda9$var$focusElement(previousNode, true);
252
- return previousNode;
253
- },
254
- focusFirst (opts = {}) {
255
- let scope = scopeRef.current;
256
- let { tabbable: tabbable, accept: accept } = opts;
257
- let scopeRoot = $a7a032acae3ddda9$var$getScopeRoot(scope);
258
- let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa(scopeRoot, {
259
- tabbable: tabbable,
260
- accept: accept
261
- }, scope);
262
- walker.currentNode = scope[0].previousElementSibling;
263
- let nextNode = walker.nextNode();
264
- if (nextNode) $a7a032acae3ddda9$var$focusElement(nextNode, true);
265
- return nextNode;
266
- },
267
- focusLast (opts = {}) {
268
- let scope = scopeRef.current;
269
- let { tabbable: tabbable, accept: accept } = opts;
270
- let scopeRoot = $a7a032acae3ddda9$var$getScopeRoot(scope);
271
- let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa(scopeRoot, {
272
- tabbable: tabbable,
273
- accept: accept
274
- }, scope);
275
- walker.currentNode = scope[scope.length - 1].nextElementSibling;
276
- let previousNode = walker.previousNode();
277
- if (previousNode) $a7a032acae3ddda9$var$focusElement(previousNode, true);
278
- return previousNode;
279
- }
280
- };
281
- }
282
- const $a7a032acae3ddda9$var$focusableElements = [
283
- "input:not([disabled]):not([type=hidden])",
284
- "select:not([disabled])",
285
- "textarea:not([disabled])",
286
- "button:not([disabled])",
287
- "a[href]",
288
- "area[href]",
289
- "summary",
290
- "iframe",
291
- "object",
292
- "embed",
293
- "audio[controls]",
294
- "video[controls]",
295
- "[contenteditable]"
296
- ];
297
- const $a7a032acae3ddda9$var$FOCUSABLE_ELEMENT_SELECTOR = $a7a032acae3ddda9$var$focusableElements.join(":not([hidden]),") + ",[tabindex]:not([disabled]):not([hidden])";
298
- $a7a032acae3ddda9$var$focusableElements.push('[tabindex]:not([tabindex="-1"]):not([disabled])');
299
- const $a7a032acae3ddda9$var$TABBABLE_ELEMENT_SELECTOR = $a7a032acae3ddda9$var$focusableElements.join(':not([hidden]):not([tabindex="-1"]),');
300
- function $a7a032acae3ddda9$var$getScopeRoot(scope) {
301
- return scope[0].parentElement;
302
- }
303
- function $a7a032acae3ddda9$var$shouldContainFocus(scopeRef) {
304
- let scope = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode($a7a032acae3ddda9$var$activeScope);
305
- while(scope && scope.scopeRef !== scopeRef){
306
- if (scope.contain) return false;
307
- scope = scope.parent;
308
- }
309
- return true;
310
- }
311
- function $a7a032acae3ddda9$var$useFocusContainment(scopeRef, contain) {
312
- let focusedNode = (0, $aB6Cp$react.useRef)();
313
- let raf = (0, $aB6Cp$react.useRef)();
314
- (0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
315
- let scope = scopeRef.current;
316
- if (!contain) {
317
- // if contain was changed, then we should cancel any ongoing waits to pull focus back into containment
318
- if (raf.current) {
319
- cancelAnimationFrame(raf.current);
320
- raf.current = undefined;
321
- }
322
- return;
323
- }
324
- const ownerDocument = (0, $aB6Cp$reactariautils.getOwnerDocument)(scope ? scope[0] : undefined);
325
- // Handle the Tab key to contain focus within the scope
326
- let onKeyDown = (e)=>{
327
- if (e.key !== "Tab" || e.altKey || e.ctrlKey || e.metaKey || !$a7a032acae3ddda9$var$shouldContainFocus(scopeRef)) return;
328
- let focusedElement = ownerDocument.activeElement;
329
- let scope = scopeRef.current;
330
- if (!scope || !$a7a032acae3ddda9$var$isElementInScope(focusedElement, scope)) return;
331
- let scopeRoot = $a7a032acae3ddda9$var$getScopeRoot(scope);
332
- let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa(scopeRoot, {
333
- tabbable: true
334
- }, scope);
335
- if (!focusedElement) return;
336
- walker.currentNode = focusedElement;
337
- let nextElement = e.shiftKey ? walker.previousNode() : walker.nextNode();
338
- if (!nextElement) {
339
- walker.currentNode = e.shiftKey ? scope[scope.length - 1].nextElementSibling : scope[0].previousElementSibling;
340
- nextElement = e.shiftKey ? walker.previousNode() : walker.nextNode();
341
- }
342
- e.preventDefault();
343
- if (nextElement) $a7a032acae3ddda9$var$focusElement(nextElement, true);
344
- };
345
- let onFocus = (e)=>{
346
- // If focusing an element in a child scope of the currently active scope, the child becomes active.
347
- // Moving out of the active scope to an ancestor is not allowed.
348
- if ((!$a7a032acae3ddda9$var$activeScope || $a7a032acae3ddda9$var$isAncestorScope($a7a032acae3ddda9$var$activeScope, scopeRef)) && $a7a032acae3ddda9$var$isElementInScope(e.target, scopeRef.current)) {
349
- $a7a032acae3ddda9$var$activeScope = scopeRef;
350
- focusedNode.current = e.target;
351
- } else if ($a7a032acae3ddda9$var$shouldContainFocus(scopeRef) && !$a7a032acae3ddda9$var$isElementInChildScope(e.target, scopeRef)) {
352
- // If a focus event occurs outside the active scope (e.g. user tabs from browser location bar),
353
- // restore focus to the previously focused node or the first tabbable element in the active scope.
354
- if (focusedNode.current) focusedNode.current.focus();
355
- else if ($a7a032acae3ddda9$var$activeScope && $a7a032acae3ddda9$var$activeScope.current) $a7a032acae3ddda9$var$focusFirstInScope($a7a032acae3ddda9$var$activeScope.current);
356
- } else if ($a7a032acae3ddda9$var$shouldContainFocus(scopeRef)) focusedNode.current = e.target;
357
- };
358
- let onBlur = (e)=>{
359
- // Firefox doesn't shift focus back to the Dialog properly without this
360
- if (raf.current) cancelAnimationFrame(raf.current);
361
- raf.current = requestAnimationFrame(()=>{
362
- // Use document.activeElement instead of e.relatedTarget so we can tell if user clicked into iframe
363
- if (ownerDocument.activeElement && $a7a032acae3ddda9$var$shouldContainFocus(scopeRef) && !$a7a032acae3ddda9$var$isElementInChildScope(ownerDocument.activeElement, scopeRef)) {
364
- $a7a032acae3ddda9$var$activeScope = scopeRef;
365
- if (ownerDocument.body.contains(e.target)) {
366
- var _focusedNode_current;
367
- focusedNode.current = e.target;
368
- (_focusedNode_current = focusedNode.current) === null || _focusedNode_current === void 0 ? void 0 : _focusedNode_current.focus();
369
- } else if ($a7a032acae3ddda9$var$activeScope.current) $a7a032acae3ddda9$var$focusFirstInScope($a7a032acae3ddda9$var$activeScope.current);
370
- }
371
- });
372
- };
373
- ownerDocument.addEventListener("keydown", onKeyDown, false);
374
- ownerDocument.addEventListener("focusin", onFocus, false);
375
- scope === null || scope === void 0 ? void 0 : scope.forEach((element)=>element.addEventListener("focusin", onFocus, false));
376
- scope === null || scope === void 0 ? void 0 : scope.forEach((element)=>element.addEventListener("focusout", onBlur, false));
377
- return ()=>{
378
- ownerDocument.removeEventListener("keydown", onKeyDown, false);
379
- ownerDocument.removeEventListener("focusin", onFocus, false);
380
- scope === null || scope === void 0 ? void 0 : scope.forEach((element)=>element.removeEventListener("focusin", onFocus, false));
381
- scope === null || scope === void 0 ? void 0 : scope.forEach((element)=>element.removeEventListener("focusout", onBlur, false));
382
- };
383
- }, [
384
- scopeRef,
385
- contain
386
- ]);
387
- // This is a useLayoutEffect so it is guaranteed to run before our async synthetic blur
388
- // eslint-disable-next-line arrow-body-style
389
- (0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
390
- return ()=>{
391
- if (raf.current) cancelAnimationFrame(raf.current);
392
- };
393
- }, [
394
- raf
395
- ]);
396
- }
397
- function $a7a032acae3ddda9$var$isElementInAnyScope(element) {
398
- return $a7a032acae3ddda9$var$isElementInChildScope(element);
399
- }
400
- function $a7a032acae3ddda9$var$isElementInScope(element, scope) {
401
- if (!element) return false;
402
- if (!scope) return false;
403
- return scope.some((node)=>node.contains(element));
404
- }
405
- function $a7a032acae3ddda9$var$isElementInChildScope(element, scope = null) {
406
- // If the element is within a top layer element (e.g. toasts), always allow moving focus there.
407
- if (element instanceof Element && element.closest("[data-react-aria-top-layer]")) return true;
408
- // node.contains in isElementInScope covers child scopes that are also DOM children,
409
- // but does not cover child scopes in portals.
410
- for (let { scopeRef: s } of $a7a032acae3ddda9$export$d06fae2ee68b101e.traverse($a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scope))){
411
- if (s && $a7a032acae3ddda9$var$isElementInScope(element, s.current)) return true;
412
- }
413
- return false;
414
- }
415
- function $a7a032acae3ddda9$export$1258395f99bf9cbf(element) {
416
- return $a7a032acae3ddda9$var$isElementInChildScope(element, $a7a032acae3ddda9$var$activeScope);
417
- }
418
- function $a7a032acae3ddda9$var$isAncestorScope(ancestor, scope) {
419
- var _focusScopeTree_getTreeNode;
420
- let parent = (_focusScopeTree_getTreeNode = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scope)) === null || _focusScopeTree_getTreeNode === void 0 ? void 0 : _focusScopeTree_getTreeNode.parent;
421
- while(parent){
422
- if (parent.scopeRef === ancestor) return true;
423
- parent = parent.parent;
424
- }
425
- return false;
426
- }
427
- function $a7a032acae3ddda9$var$focusElement(element, scroll = false) {
428
- if (element != null && !scroll) try {
429
- (0, $1c7f9157d722357d$export$80f3e147d781571c)(element);
430
- } catch (err) {
431
- // ignore
432
- }
433
- else if (element != null) try {
434
- element.focus();
435
- } catch (err) {
436
- // ignore
437
- }
438
- }
439
- function $a7a032acae3ddda9$var$focusFirstInScope(scope, tabbable = true) {
440
- let sentinel = scope[0].previousElementSibling;
441
- let scopeRoot = $a7a032acae3ddda9$var$getScopeRoot(scope);
442
- let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa(scopeRoot, {
443
- tabbable: tabbable
444
- }, scope);
445
- walker.currentNode = sentinel;
446
- let nextNode = walker.nextNode();
447
- // If the scope does not contain a tabbable element, use the first focusable element.
448
- if (tabbable && !nextNode) {
449
- scopeRoot = $a7a032acae3ddda9$var$getScopeRoot(scope);
450
- walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa(scopeRoot, {
451
- tabbable: false
452
- }, scope);
453
- walker.currentNode = sentinel;
454
- nextNode = walker.nextNode();
455
- }
456
- $a7a032acae3ddda9$var$focusElement(nextNode);
457
- }
458
- function $a7a032acae3ddda9$var$useAutoFocus(scopeRef, autoFocus) {
459
- const autoFocusRef = (0, ($parcel$interopDefault($aB6Cp$react))).useRef(autoFocus);
460
- (0, $aB6Cp$react.useEffect)(()=>{
461
- if (autoFocusRef.current) {
462
- $a7a032acae3ddda9$var$activeScope = scopeRef;
463
- const ownerDocument = (0, $aB6Cp$reactariautils.getOwnerDocument)(scopeRef.current ? scopeRef.current[0] : undefined);
464
- if (!$a7a032acae3ddda9$var$isElementInScope(ownerDocument.activeElement, $a7a032acae3ddda9$var$activeScope.current) && scopeRef.current) $a7a032acae3ddda9$var$focusFirstInScope(scopeRef.current);
465
- }
466
- autoFocusRef.current = false;
467
- }, [
468
- scopeRef
469
- ]);
470
- }
471
- function $a7a032acae3ddda9$var$useActiveScopeTracker(scopeRef, restore, contain) {
472
- // tracks the active scope, in case restore and contain are both false.
473
- // if either are true, this is tracked in useRestoreFocus or useFocusContainment.
474
- (0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
475
- if (restore || contain) return;
476
- let scope = scopeRef.current;
477
- const ownerDocument = (0, $aB6Cp$reactariautils.getOwnerDocument)(scope ? scope[0] : undefined);
478
- let onFocus = (e)=>{
479
- let target = e.target;
480
- if ($a7a032acae3ddda9$var$isElementInScope(target, scopeRef.current)) $a7a032acae3ddda9$var$activeScope = scopeRef;
481
- else if (!$a7a032acae3ddda9$var$isElementInAnyScope(target)) $a7a032acae3ddda9$var$activeScope = null;
482
- };
483
- ownerDocument.addEventListener("focusin", onFocus, false);
484
- scope === null || scope === void 0 ? void 0 : scope.forEach((element)=>element.addEventListener("focusin", onFocus, false));
485
- return ()=>{
486
- ownerDocument.removeEventListener("focusin", onFocus, false);
487
- scope === null || scope === void 0 ? void 0 : scope.forEach((element)=>element.removeEventListener("focusin", onFocus, false));
488
- };
489
- }, [
490
- scopeRef,
491
- restore,
492
- contain
493
- ]);
494
- }
495
- function $a7a032acae3ddda9$var$shouldRestoreFocus(scopeRef) {
496
- let scope = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode($a7a032acae3ddda9$var$activeScope);
497
- while(scope && scope.scopeRef !== scopeRef){
498
- if (scope.nodeToRestore) return false;
499
- scope = scope.parent;
500
- }
501
- return (scope === null || scope === void 0 ? void 0 : scope.scopeRef) === scopeRef;
502
- }
503
- function $a7a032acae3ddda9$var$useRestoreFocus(scopeRef, restoreFocus, contain) {
504
- // create a ref during render instead of useLayoutEffect so the active element is saved before a child with autoFocus=true mounts.
505
- // eslint-disable-next-line no-restricted-globals
506
- const nodeToRestoreRef = (0, $aB6Cp$react.useRef)(typeof document !== "undefined" ? (0, $aB6Cp$reactariautils.getOwnerDocument)(scopeRef.current ? scopeRef.current[0] : undefined).activeElement : null);
507
- // restoring scopes should all track if they are active regardless of contain, but contain already tracks it plus logic to contain the focus
508
- // restoring-non-containing scopes should only care if they become active so they can perform the restore
509
- (0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
510
- let scope = scopeRef.current;
511
- const ownerDocument = (0, $aB6Cp$reactariautils.getOwnerDocument)(scope ? scope[0] : undefined);
512
- if (!restoreFocus || contain) return;
513
- let onFocus = ()=>{
514
- // If focusing an element in a child scope of the currently active scope, the child becomes active.
515
- // Moving out of the active scope to an ancestor is not allowed.
516
- if ((!$a7a032acae3ddda9$var$activeScope || $a7a032acae3ddda9$var$isAncestorScope($a7a032acae3ddda9$var$activeScope, scopeRef)) && $a7a032acae3ddda9$var$isElementInScope(ownerDocument.activeElement, scopeRef.current)) $a7a032acae3ddda9$var$activeScope = scopeRef;
517
- };
518
- ownerDocument.addEventListener("focusin", onFocus, false);
519
- scope === null || scope === void 0 ? void 0 : scope.forEach((element)=>element.addEventListener("focusin", onFocus, false));
520
- return ()=>{
521
- ownerDocument.removeEventListener("focusin", onFocus, false);
522
- scope === null || scope === void 0 ? void 0 : scope.forEach((element)=>element.removeEventListener("focusin", onFocus, false));
523
- };
524
- // eslint-disable-next-line react-hooks/exhaustive-deps
525
- }, [
526
- scopeRef,
527
- contain
528
- ]);
529
- (0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
530
- const ownerDocument = (0, $aB6Cp$reactariautils.getOwnerDocument)(scopeRef.current ? scopeRef.current[0] : undefined);
531
- if (!restoreFocus) return;
532
- // Handle the Tab key so that tabbing out of the scope goes to the next element
533
- // after the node that had focus when the scope mounted. This is important when
534
- // using portals for overlays, so that focus goes to the expected element when
535
- // tabbing out of the overlay.
536
- let onKeyDown = (e)=>{
537
- if (e.key !== "Tab" || e.altKey || e.ctrlKey || e.metaKey || !$a7a032acae3ddda9$var$shouldContainFocus(scopeRef)) return;
538
- let focusedElement = ownerDocument.activeElement;
539
- if (!$a7a032acae3ddda9$var$isElementInScope(focusedElement, scopeRef.current)) return;
540
- let treeNode = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef);
541
- if (!treeNode) return;
542
- let nodeToRestore = treeNode.nodeToRestore;
543
- // Create a DOM tree walker that matches all tabbable elements
544
- let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa(ownerDocument.body, {
545
- tabbable: true
546
- });
547
- // Find the next tabbable element after the currently focused element
548
- walker.currentNode = focusedElement;
549
- let nextElement = e.shiftKey ? walker.previousNode() : walker.nextNode();
550
- if (!nodeToRestore || !ownerDocument.body.contains(nodeToRestore) || nodeToRestore === ownerDocument.body) {
551
- nodeToRestore = undefined;
552
- treeNode.nodeToRestore = undefined;
553
- }
554
- // If there is no next element, or it is outside the current scope, move focus to the
555
- // next element after the node to restore to instead.
556
- if ((!nextElement || !$a7a032acae3ddda9$var$isElementInScope(nextElement, scopeRef.current)) && nodeToRestore) {
557
- walker.currentNode = nodeToRestore;
558
- // Skip over elements within the scope, in case the scope immediately follows the node to restore.
559
- do nextElement = e.shiftKey ? walker.previousNode() : walker.nextNode();
560
- while ($a7a032acae3ddda9$var$isElementInScope(nextElement, scopeRef.current));
561
- e.preventDefault();
562
- e.stopPropagation();
563
- if (nextElement) $a7a032acae3ddda9$var$focusElement(nextElement, true);
564
- else // If there is no next element and the nodeToRestore isn't within a FocusScope (i.e. we are leaving the top level focus scope)
565
- // then move focus to the body.
566
- // Otherwise restore focus to the nodeToRestore (e.g menu within a popover -> tabbing to close the menu should move focus to menu trigger)
567
- if (!$a7a032acae3ddda9$var$isElementInAnyScope(nodeToRestore)) focusedElement.blur();
568
- else $a7a032acae3ddda9$var$focusElement(nodeToRestore, true);
569
- }
570
- };
571
- if (!contain) ownerDocument.addEventListener("keydown", onKeyDown, true);
572
- return ()=>{
573
- if (!contain) ownerDocument.removeEventListener("keydown", onKeyDown, true);
574
- };
575
- }, [
576
- scopeRef,
577
- restoreFocus,
578
- contain
579
- ]);
580
- // useLayoutEffect instead of useEffect so the active element is saved synchronously instead of asynchronously.
581
- (0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
582
- const ownerDocument = (0, $aB6Cp$reactariautils.getOwnerDocument)(scopeRef.current ? scopeRef.current[0] : undefined);
583
- if (!restoreFocus) return;
584
- let treeNode = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef);
585
- if (!treeNode) return;
586
- var _nodeToRestoreRef_current;
587
- treeNode.nodeToRestore = (_nodeToRestoreRef_current = nodeToRestoreRef.current) !== null && _nodeToRestoreRef_current !== void 0 ? _nodeToRestoreRef_current : undefined;
588
- return ()=>{
589
- let treeNode = $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(scopeRef);
590
- if (!treeNode) return;
591
- let nodeToRestore = treeNode.nodeToRestore;
592
- // if we already lost focus to the body and this was the active scope, then we should attempt to restore
593
- if (restoreFocus && nodeToRestore && // eslint-disable-next-line react-hooks/exhaustive-deps
594
- ($a7a032acae3ddda9$var$isElementInScope(ownerDocument.activeElement, scopeRef.current) || ownerDocument.activeElement === ownerDocument.body && $a7a032acae3ddda9$var$shouldRestoreFocus(scopeRef))) {
595
- // freeze the focusScopeTree so it persists after the raf, otherwise during unmount nodes are removed from it
596
- let clonedTree = $a7a032acae3ddda9$export$d06fae2ee68b101e.clone();
597
- requestAnimationFrame(()=>{
598
- // Only restore focus if we've lost focus to the body, the alternative is that focus has been purposefully moved elsewhere
599
- if (ownerDocument.activeElement === ownerDocument.body) {
600
- // look up the tree starting with our scope to find a nodeToRestore still in the DOM
601
- let treeNode = clonedTree.getTreeNode(scopeRef);
602
- while(treeNode){
603
- if (treeNode.nodeToRestore && treeNode.nodeToRestore.isConnected) {
604
- $a7a032acae3ddda9$var$focusElement(treeNode.nodeToRestore);
605
- return;
606
- }
607
- treeNode = treeNode.parent;
608
- }
609
- // If no nodeToRestore was found, focus the first element in the nearest
610
- // ancestor scope that is still in the tree.
611
- treeNode = clonedTree.getTreeNode(scopeRef);
612
- while(treeNode){
613
- if (treeNode.scopeRef && treeNode.scopeRef.current && $a7a032acae3ddda9$export$d06fae2ee68b101e.getTreeNode(treeNode.scopeRef)) {
614
- $a7a032acae3ddda9$var$focusFirstInScope(treeNode.scopeRef.current, true);
615
- return;
616
- }
617
- treeNode = treeNode.parent;
618
- }
619
- }
620
- });
621
- }
622
- };
623
- }, [
624
- scopeRef,
625
- restoreFocus
626
- ]);
627
- }
628
- function $a7a032acae3ddda9$export$2d6ec8fc375ceafa(root, opts, scope) {
629
- let selector = (opts === null || opts === void 0 ? void 0 : opts.tabbable) ? $a7a032acae3ddda9$var$TABBABLE_ELEMENT_SELECTOR : $a7a032acae3ddda9$var$FOCUSABLE_ELEMENT_SELECTOR;
630
- let walker = (0, $aB6Cp$reactariautils.getOwnerDocument)(root).createTreeWalker(root, NodeFilter.SHOW_ELEMENT, {
631
- acceptNode (node) {
632
- var _opts_from;
633
- // Skip nodes inside the starting node.
634
- if (opts === null || opts === void 0 ? void 0 : (_opts_from = opts.from) === null || _opts_from === void 0 ? void 0 : _opts_from.contains(node)) return NodeFilter.FILTER_REJECT;
635
- if (node.matches(selector) && (0, $d5156037ad898a4d$export$e989c0fffaa6b27a)(node) && (!scope || $a7a032acae3ddda9$var$isElementInScope(node, scope)) && (!(opts === null || opts === void 0 ? void 0 : opts.accept) || opts.accept(node))) return NodeFilter.FILTER_ACCEPT;
636
- return NodeFilter.FILTER_SKIP;
637
- }
638
- });
639
- if (opts === null || opts === void 0 ? void 0 : opts.from) walker.currentNode = opts.from;
640
- return walker;
641
- }
642
- function $a7a032acae3ddda9$export$c5251b9e124bf29(ref, defaultOptions = {}) {
643
- return {
644
- focusNext (opts = {}) {
645
- let root = ref.current;
646
- if (!root) return null;
647
- let { from: from, tabbable: tabbable = defaultOptions.tabbable, wrap: wrap = defaultOptions.wrap, accept: accept = defaultOptions.accept } = opts;
648
- let node = from || (0, $aB6Cp$reactariautils.getOwnerDocument)(root).activeElement;
649
- let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa(root, {
650
- tabbable: tabbable,
651
- accept: accept
652
- });
653
- if (root.contains(node)) walker.currentNode = node;
654
- let nextNode = walker.nextNode();
655
- if (!nextNode && wrap) {
656
- walker.currentNode = root;
657
- nextNode = walker.nextNode();
658
- }
659
- if (nextNode) $a7a032acae3ddda9$var$focusElement(nextNode, true);
660
- return nextNode;
661
- },
662
- focusPrevious (opts = defaultOptions) {
663
- let root = ref.current;
664
- if (!root) return null;
665
- let { from: from, tabbable: tabbable = defaultOptions.tabbable, wrap: wrap = defaultOptions.wrap, accept: accept = defaultOptions.accept } = opts;
666
- let node = from || (0, $aB6Cp$reactariautils.getOwnerDocument)(root).activeElement;
667
- let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa(root, {
668
- tabbable: tabbable,
669
- accept: accept
670
- });
671
- if (root.contains(node)) walker.currentNode = node;
672
- else {
673
- let next = $a7a032acae3ddda9$var$last(walker);
674
- if (next) $a7a032acae3ddda9$var$focusElement(next, true);
675
- return next !== null && next !== void 0 ? next : null;
676
- }
677
- let previousNode = walker.previousNode();
678
- if (!previousNode && wrap) {
679
- walker.currentNode = root;
680
- let lastNode = $a7a032acae3ddda9$var$last(walker);
681
- if (!lastNode) // couldn't wrap
682
- return null;
683
- previousNode = lastNode;
684
- }
685
- if (previousNode) $a7a032acae3ddda9$var$focusElement(previousNode, true);
686
- return previousNode !== null && previousNode !== void 0 ? previousNode : null;
687
- },
688
- focusFirst (opts = defaultOptions) {
689
- let root = ref.current;
690
- if (!root) return null;
691
- let { tabbable: tabbable = defaultOptions.tabbable, accept: accept = defaultOptions.accept } = opts;
692
- let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa(root, {
693
- tabbable: tabbable,
694
- accept: accept
695
- });
696
- let nextNode = walker.nextNode();
697
- if (nextNode) $a7a032acae3ddda9$var$focusElement(nextNode, true);
698
- return nextNode;
699
- },
700
- focusLast (opts = defaultOptions) {
701
- let root = ref.current;
702
- if (!root) return null;
703
- let { tabbable: tabbable = defaultOptions.tabbable, accept: accept = defaultOptions.accept } = opts;
704
- let walker = $a7a032acae3ddda9$export$2d6ec8fc375ceafa(root, {
705
- tabbable: tabbable,
706
- accept: accept
707
- });
708
- let next = $a7a032acae3ddda9$var$last(walker);
709
- if (next) $a7a032acae3ddda9$var$focusElement(next, true);
710
- return next !== null && next !== void 0 ? next : null;
711
- }
712
- };
713
- }
714
- function $a7a032acae3ddda9$var$last(walker) {
715
- let next = undefined;
716
- let last;
717
- do {
718
- last = walker.lastChild();
719
- if (last) next = last;
720
- }while (last);
721
- return next;
722
- }
723
- class $a7a032acae3ddda9$var$Tree {
724
- get size() {
725
- return this.fastMap.size;
726
- }
727
- getTreeNode(data) {
728
- return this.fastMap.get(data);
729
- }
730
- addTreeNode(scopeRef, parent, nodeToRestore) {
731
- let parentNode = this.fastMap.get(parent !== null && parent !== void 0 ? parent : null);
732
- if (!parentNode) return;
733
- let node = new $a7a032acae3ddda9$var$TreeNode({
734
- scopeRef: scopeRef
735
- });
736
- parentNode.addChild(node);
737
- node.parent = parentNode;
738
- this.fastMap.set(scopeRef, node);
739
- if (nodeToRestore) node.nodeToRestore = nodeToRestore;
740
- }
741
- addNode(node) {
742
- this.fastMap.set(node.scopeRef, node);
743
- }
744
- removeTreeNode(scopeRef) {
745
- // never remove the root
746
- if (scopeRef === null) return;
747
- let node = this.fastMap.get(scopeRef);
748
- if (!node) return;
749
- let parentNode = node.parent;
750
- // when we remove a scope, check if any sibling scopes are trying to restore focus to something inside the scope we're removing
751
- // if we are, then replace the siblings restore with the restore from the scope we're removing
752
- for (let current of this.traverse())if (current !== node && node.nodeToRestore && current.nodeToRestore && node.scopeRef && node.scopeRef.current && $a7a032acae3ddda9$var$isElementInScope(current.nodeToRestore, node.scopeRef.current)) current.nodeToRestore = node.nodeToRestore;
753
- let children = node.children;
754
- if (parentNode) {
755
- parentNode.removeChild(node);
756
- if (children.size > 0) children.forEach((child)=>parentNode && parentNode.addChild(child));
757
- }
758
- this.fastMap.delete(node.scopeRef);
759
- }
760
- // Pre Order Depth First
761
- *traverse(node = this.root) {
762
- if (node.scopeRef != null) yield node;
763
- if (node.children.size > 0) for (let child of node.children)yield* this.traverse(child);
764
- }
765
- clone() {
766
- var _node_parent;
767
- let newTree = new $a7a032acae3ddda9$var$Tree();
768
- var _node_parent_scopeRef;
769
- for (let node of this.traverse())newTree.addTreeNode(node.scopeRef, (_node_parent_scopeRef = (_node_parent = node.parent) === null || _node_parent === void 0 ? void 0 : _node_parent.scopeRef) !== null && _node_parent_scopeRef !== void 0 ? _node_parent_scopeRef : null, node.nodeToRestore);
770
- return newTree;
771
- }
772
- constructor(){
773
- this.fastMap = new Map();
774
- this.root = new $a7a032acae3ddda9$var$TreeNode({
775
- scopeRef: null
776
- });
777
- this.fastMap.set(null, this.root);
778
- }
779
- }
780
- class $a7a032acae3ddda9$var$TreeNode {
781
- addChild(node) {
782
- this.children.add(node);
783
- node.parent = this;
784
- }
785
- removeChild(node) {
786
- this.children.delete(node);
787
- node.parent = undefined;
788
- }
789
- constructor(props){
790
- this.children = new Set();
791
- this.contain = false;
792
- this.scopeRef = props.scopeRef;
793
- }
794
- }
795
- let $a7a032acae3ddda9$export$d06fae2ee68b101e = new $a7a032acae3ddda9$var$Tree();
796
-
797
-
798
- /*
799
- * Copyright 2020 Adobe. All rights reserved.
800
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
801
- * you may not use this file except in compliance with the License. You may obtain a copy
802
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
803
- *
804
- * Unless required by applicable law or agreed to in writing, software distributed under
805
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
806
- * OF ANY KIND, either express or implied. See the License for the specific language
807
- * governing permissions and limitations under the License.
808
- */
809
-
810
-
811
-
812
-
813
- function $581a96d6eb128c1b$export$4e328f61c538687f(props = {}) {
814
- let { autoFocus: autoFocus = false, isTextInput: isTextInput, within: within } = props;
815
- let state = (0, $aB6Cp$react.useRef)({
816
- isFocused: false,
817
- isFocusVisible: autoFocus || (0, $aB6Cp$reactariainteractions.isFocusVisible)()
818
- });
819
- let [isFocused, setFocused] = (0, $aB6Cp$react.useState)(false);
820
- let [isFocusVisibleState, setFocusVisible] = (0, $aB6Cp$react.useState)(()=>state.current.isFocused && state.current.isFocusVisible);
821
- let updateState = (0, $aB6Cp$react.useCallback)(()=>setFocusVisible(state.current.isFocused && state.current.isFocusVisible), []);
822
- let onFocusChange = (0, $aB6Cp$react.useCallback)((isFocused)=>{
823
- state.current.isFocused = isFocused;
824
- setFocused(isFocused);
825
- updateState();
826
- }, [
827
- updateState
828
- ]);
829
- (0, $aB6Cp$reactariainteractions.useFocusVisibleListener)((isFocusVisible)=>{
830
- state.current.isFocusVisible = isFocusVisible;
831
- updateState();
832
- }, [], {
833
- isTextInput: isTextInput
834
- });
835
- let { focusProps: focusProps } = (0, $aB6Cp$reactariainteractions.useFocus)({
836
- isDisabled: within,
837
- onFocusChange: onFocusChange
838
- });
839
- let { focusWithinProps: focusWithinProps } = (0, $aB6Cp$reactariainteractions.useFocusWithin)({
840
- isDisabled: !within,
841
- onFocusWithinChange: onFocusChange
842
- });
843
- return {
844
- isFocused: isFocused,
845
- isFocusVisible: isFocusVisibleState,
846
- focusProps: within ? focusWithinProps : focusProps
847
- };
848
- }
849
-
850
-
851
- function $dfd8c70b928eb1b3$export$1a38b4ad7f578e1d(props) {
852
- let { children: children, focusClass: focusClass, focusRingClass: focusRingClass } = props;
853
- let { isFocused: isFocused, isFocusVisible: isFocusVisible, focusProps: focusProps } = (0, $581a96d6eb128c1b$export$4e328f61c538687f)(props);
854
- let child = (0, ($parcel$interopDefault($aB6Cp$react))).Children.only(children);
855
- return /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).cloneElement(child, (0, $aB6Cp$reactariautils.mergeProps)(child.props, {
856
- ...focusProps,
857
- className: (0, ($parcel$interopDefault($aB6Cp$clsx)))({
858
- [focusClass || ""]: isFocused,
859
- [focusRingClass || ""]: isFocusVisible
860
- })
861
- }));
862
- }
863
-
864
-
865
- /*
866
- * Copyright 2020 Adobe. All rights reserved.
867
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
868
- * you may not use this file except in compliance with the License. You may obtain a copy
869
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
870
- *
871
- * Unless required by applicable law or agreed to in writing, software distributed under
872
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
873
- * OF ANY KIND, either express or implied. See the License for the specific language
874
- * governing permissions and limitations under the License.
875
- */
876
-
877
-
878
-
879
- let $fb504d83237fd6ac$var$FocusableContext = /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).createContext(null);
880
- function $fb504d83237fd6ac$var$useFocusableContext(ref) {
881
- let context = (0, $aB6Cp$react.useContext)($fb504d83237fd6ac$var$FocusableContext) || {};
882
- (0, $aB6Cp$reactariautils.useSyncRef)(context, ref);
883
- // eslint-disable-next-line
884
- let { ref: _, ...otherProps } = context;
885
- return otherProps;
886
- }
887
- /**
888
- * Provides DOM props to the nearest focusable child.
889
- */ function $fb504d83237fd6ac$var$FocusableProvider(props, ref) {
890
- let { children: children, ...otherProps } = props;
891
- let objRef = (0, $aB6Cp$reactariautils.useObjectRef)(ref);
892
- let context = {
893
- ...otherProps,
894
- ref: objRef
895
- };
896
- return /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).createElement($fb504d83237fd6ac$var$FocusableContext.Provider, {
897
- value: context
898
- }, children);
899
- }
900
- let $fb504d83237fd6ac$export$13f3202a3e5ddd5 = /*#__PURE__*/ (0, ($parcel$interopDefault($aB6Cp$react))).forwardRef($fb504d83237fd6ac$var$FocusableProvider);
901
- function $fb504d83237fd6ac$export$4c014de7c8940b4c(props, domRef) {
902
- let { focusProps: focusProps } = (0, $aB6Cp$reactariainteractions.useFocus)(props);
903
- let { keyboardProps: keyboardProps } = (0, $aB6Cp$reactariainteractions.useKeyboard)(props);
904
- let interactions = (0, $aB6Cp$reactariautils.mergeProps)(focusProps, keyboardProps);
905
- let domProps = $fb504d83237fd6ac$var$useFocusableContext(domRef);
906
- let interactionProps = props.isDisabled ? {} : domProps;
907
- let autoFocusRef = (0, $aB6Cp$react.useRef)(props.autoFocus);
908
- (0, $aB6Cp$react.useEffect)(()=>{
909
- if (autoFocusRef.current && domRef.current) (0, $1c7f9157d722357d$export$80f3e147d781571c)(domRef.current);
910
- autoFocusRef.current = false;
911
- }, [
912
- domRef
913
- ]);
914
- return {
915
- focusableProps: (0, $aB6Cp$reactariautils.mergeProps)({
916
- ...interactions,
917
- tabIndex: props.excludeFromTabOrder && !props.isDisabled ? -1 : undefined
918
- }, interactionProps)
919
- };
920
- }
921
-
922
-
923
-
924
-
925
- /*
926
- * Copyright 2022 Adobe. All rights reserved.
927
- * This file is licensed to you under the Apache License, Version 2.0 (the "License");
928
- * you may not use this file except in compliance with the License. You may obtain a copy
929
- * of the License at http://www.apache.org/licenses/LICENSE-2.0
930
- *
931
- * Unless required by applicable law or agreed to in writing, software distributed under
932
- * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
933
- * OF ANY KIND, either express or implied. See the License for the specific language
934
- * governing permissions and limitations under the License.
935
- */
936
-
937
-
938
- function $259c6413a286f2e6$export$eac1895992b9f3d6(ref, options) {
939
- let isDisabled = options === null || options === void 0 ? void 0 : options.isDisabled;
940
- let [hasTabbableChild, setHasTabbableChild] = (0, $aB6Cp$react.useState)(false);
941
- (0, $aB6Cp$reactariautils.useLayoutEffect)(()=>{
942
- if ((ref === null || ref === void 0 ? void 0 : ref.current) && !isDisabled) {
943
- let update = ()=>{
944
- if (ref.current) {
945
- let walker = (0, $a7a032acae3ddda9$export$2d6ec8fc375ceafa)(ref.current, {
946
- tabbable: true
947
- });
948
- setHasTabbableChild(!!walker.nextNode());
949
- }
950
- };
951
- update();
952
- // Update when new elements are inserted, or the tabIndex/disabled attribute updates.
953
- let observer = new MutationObserver(update);
954
- observer.observe(ref.current, {
955
- subtree: true,
956
- childList: true,
957
- attributes: true,
958
- attributeFilter: [
959
- "tabIndex",
960
- "disabled"
961
- ]
962
- });
963
- return ()=>{
964
- // Disconnect mutation observer when a React update occurs on the top-level component
965
- // so we update synchronously after re-rendering. Otherwise React will emit act warnings
966
- // in tests since mutation observers fire asynchronously. The mutation observer is necessary
967
- // so we also update if a child component re-renders and adds/removes something tabbable.
968
- observer.disconnect();
969
- };
970
- }
971
- });
972
- return isDisabled ? false : hasTabbableChild;
973
- }
974
39
 
975
40
 
976
41