@react-aria/focus 3.0.0-nightly.2843 → 3.0.0-nightly.2846

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