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