@tamagui/focus-scope 1.88.13 → 1.88.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/FocusScope.mjs +176 -0
- package/dist/esm/FocusScopeProps.mjs +0 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -0
- package/dist/esm/index.native.js.map +1 -1
- package/dist/jsx/FocusScope.mjs +176 -0
- package/dist/jsx/FocusScopeProps.mjs +0 -0
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +1 -0
- package/dist/jsx/index.native.js.map +1 -1
- package/package.json +4 -4
- package/src/FocusScope.native.tsx +1 -1
- package/src/FocusScope.tsx +1 -1
- package/src/FocusScopeProps.tsx +1 -1
- package/types/FocusScope.d.ts +1 -1
- package/types/FocusScope.d.ts.map +1 -1
- package/types/FocusScope.native.d.ts +1 -1
- package/types/FocusScope.native.d.ts.map +1 -1
- package/types/FocusScopeProps.d.ts +1 -1
- package/types/FocusScopeProps.d.ts.map +1 -1
- package/types/index.d.ts.map +1 -1
- /package/src/{index.tsx → index.ts} +0 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 Nate Wienert
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { useEvent } from "@tamagui/use-event";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
5
|
+
const AUTOFOCUS_ON_MOUNT = "focusScope.autoFocusOnMount",
|
|
6
|
+
AUTOFOCUS_ON_UNMOUNT = "focusScope.autoFocusOnUnmount",
|
|
7
|
+
EVENT_OPTIONS = {
|
|
8
|
+
bubbles: !1,
|
|
9
|
+
cancelable: !0
|
|
10
|
+
},
|
|
11
|
+
FocusScope = React.forwardRef(function (props, forwardedRef) {
|
|
12
|
+
const childProps = useFocusScope(props, forwardedRef);
|
|
13
|
+
return typeof props.children == "function" ? /* @__PURE__ */jsx(Fragment, {
|
|
14
|
+
children: props.children(childProps)
|
|
15
|
+
}) : React.cloneElement(React.Children.only(props.children), childProps);
|
|
16
|
+
});
|
|
17
|
+
function useFocusScope(props, forwardedRef) {
|
|
18
|
+
const {
|
|
19
|
+
loop = !1,
|
|
20
|
+
enabled = !0,
|
|
21
|
+
trapped = !1,
|
|
22
|
+
onMountAutoFocus: onMountAutoFocusProp,
|
|
23
|
+
onUnmountAutoFocus: onUnmountAutoFocusProp,
|
|
24
|
+
forceUnmount,
|
|
25
|
+
children,
|
|
26
|
+
...scopeProps
|
|
27
|
+
} = props,
|
|
28
|
+
[container, setContainer] = React.useState(null),
|
|
29
|
+
onMountAutoFocus = useEvent(onMountAutoFocusProp),
|
|
30
|
+
onUnmountAutoFocus = useEvent(onUnmountAutoFocusProp),
|
|
31
|
+
lastFocusedElementRef = React.useRef(null),
|
|
32
|
+
composedRefs = useComposedRefs(forwardedRef, node => setContainer(node)),
|
|
33
|
+
focusScope = React.useRef({
|
|
34
|
+
paused: !1,
|
|
35
|
+
pause() {
|
|
36
|
+
this.paused = !0;
|
|
37
|
+
},
|
|
38
|
+
resume() {
|
|
39
|
+
this.paused = !1;
|
|
40
|
+
}
|
|
41
|
+
}).current;
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (!enabled || !trapped) return;
|
|
44
|
+
function handleFocusIn(event) {
|
|
45
|
+
if (focusScope.paused || !container) return;
|
|
46
|
+
const target = event.target;
|
|
47
|
+
container.contains(target) ? lastFocusedElementRef.current = target : focus(lastFocusedElementRef.current, {
|
|
48
|
+
select: !0
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function handleFocusOut(event) {
|
|
52
|
+
focusScope.paused || !container || container.contains(event.relatedTarget) || focus(lastFocusedElementRef.current, {
|
|
53
|
+
select: !0
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return document.addEventListener("focusin", handleFocusIn), document.addEventListener("focusout", handleFocusOut), () => {
|
|
57
|
+
document.removeEventListener("focusin", handleFocusIn), document.removeEventListener("focusout", handleFocusOut);
|
|
58
|
+
};
|
|
59
|
+
}, [trapped, forceUnmount, container, focusScope.paused]), React.useEffect(() => {
|
|
60
|
+
if (!enabled || !container || forceUnmount) return;
|
|
61
|
+
focusScopesStack.add(focusScope);
|
|
62
|
+
const previouslyFocusedElement = document.activeElement;
|
|
63
|
+
if (!container.contains(previouslyFocusedElement)) {
|
|
64
|
+
const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
|
|
65
|
+
if (container.addEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus), container.dispatchEvent(mountEvent), !mountEvent.defaultPrevented) {
|
|
66
|
+
const candidates = removeLinks(getTabbableCandidates(container));
|
|
67
|
+
focusFirst(candidates, {
|
|
68
|
+
select: !0
|
|
69
|
+
}), document.activeElement === previouslyFocusedElement && focus(container);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return () => {
|
|
73
|
+
container.removeEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
|
74
|
+
const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
|
|
75
|
+
container.addEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus), container.dispatchEvent(unmountEvent), unmountEvent.defaultPrevented || focus(previouslyFocusedElement ?? document.body, {
|
|
76
|
+
select: !0
|
|
77
|
+
}), container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus), focusScopesStack.remove(focusScope);
|
|
78
|
+
};
|
|
79
|
+
}, [enabled, container, forceUnmount, onMountAutoFocus, onUnmountAutoFocus, focusScope]);
|
|
80
|
+
const handleKeyDown = React.useCallback(event => {
|
|
81
|
+
if (!trapped || !loop || focusScope.paused) return;
|
|
82
|
+
const isTabKey = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey,
|
|
83
|
+
focusedElement = document.activeElement;
|
|
84
|
+
if (isTabKey && focusedElement) {
|
|
85
|
+
const container2 = event.currentTarget,
|
|
86
|
+
[first, last] = getTabbableEdges(container2);
|
|
87
|
+
first && last ? !event.shiftKey && focusedElement === last ? (event.preventDefault(), loop && focus(first, {
|
|
88
|
+
select: !0
|
|
89
|
+
})) : event.shiftKey && focusedElement === first && (event.preventDefault(), loop && focus(last, {
|
|
90
|
+
select: !0
|
|
91
|
+
})) : focusedElement === container2 && event.preventDefault();
|
|
92
|
+
}
|
|
93
|
+
}, [loop, trapped, focusScope.paused]);
|
|
94
|
+
return {
|
|
95
|
+
tabIndex: -1,
|
|
96
|
+
...scopeProps,
|
|
97
|
+
ref: composedRefs,
|
|
98
|
+
onKeyDown: handleKeyDown
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function focusFirst(candidates, {
|
|
102
|
+
select = !1
|
|
103
|
+
} = {}) {
|
|
104
|
+
const previouslyFocusedElement = document.activeElement;
|
|
105
|
+
for (const candidate of candidates) if (focus(candidate, {
|
|
106
|
+
select
|
|
107
|
+
}), document.activeElement !== previouslyFocusedElement) return;
|
|
108
|
+
}
|
|
109
|
+
function getTabbableEdges(container) {
|
|
110
|
+
const candidates = getTabbableCandidates(container),
|
|
111
|
+
first = findVisible(candidates, container),
|
|
112
|
+
last = findVisible(candidates.reverse(), container);
|
|
113
|
+
return [first, last];
|
|
114
|
+
}
|
|
115
|
+
function getTabbableCandidates(container) {
|
|
116
|
+
const nodes = [],
|
|
117
|
+
walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
118
|
+
acceptNode: node => {
|
|
119
|
+
const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
|
|
120
|
+
return node.disabled || node.hidden || isHiddenInput ? NodeFilter.FILTER_SKIP : node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
for (; walker.nextNode();) nodes.push(walker.currentNode);
|
|
124
|
+
return nodes;
|
|
125
|
+
}
|
|
126
|
+
function findVisible(elements, container) {
|
|
127
|
+
for (const element of elements) if (!isHidden(element, {
|
|
128
|
+
upTo: container
|
|
129
|
+
})) return element;
|
|
130
|
+
}
|
|
131
|
+
function isHidden(node, {
|
|
132
|
+
upTo
|
|
133
|
+
}) {
|
|
134
|
+
if (getComputedStyle(node).visibility === "hidden") return !0;
|
|
135
|
+
for (; node;) {
|
|
136
|
+
if (upTo !== void 0 && node === upTo) return !1;
|
|
137
|
+
if (getComputedStyle(node).display === "none") return !0;
|
|
138
|
+
node = node.parentElement;
|
|
139
|
+
}
|
|
140
|
+
return !1;
|
|
141
|
+
}
|
|
142
|
+
function isSelectableInput(element) {
|
|
143
|
+
return element instanceof HTMLInputElement && "select" in element;
|
|
144
|
+
}
|
|
145
|
+
function focus(element, {
|
|
146
|
+
select = !1
|
|
147
|
+
} = {}) {
|
|
148
|
+
if (element?.focus) {
|
|
149
|
+
const previouslyFocusedElement = document.activeElement;
|
|
150
|
+
element.focus({
|
|
151
|
+
preventScroll: !0
|
|
152
|
+
}), element !== previouslyFocusedElement && isSelectableInput(element) && select && element.select();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const focusScopesStack = createFocusScopesStack();
|
|
156
|
+
function createFocusScopesStack() {
|
|
157
|
+
let stack = [];
|
|
158
|
+
return {
|
|
159
|
+
add(focusScope) {
|
|
160
|
+
const activeFocusScope = stack[0];
|
|
161
|
+
focusScope !== activeFocusScope && activeFocusScope?.pause(), stack = arrayRemove(stack, focusScope), stack.unshift(focusScope);
|
|
162
|
+
},
|
|
163
|
+
remove(focusScope) {
|
|
164
|
+
stack = arrayRemove(stack, focusScope), stack[0]?.resume();
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function arrayRemove(array, item) {
|
|
169
|
+
const updatedArray = [...array],
|
|
170
|
+
index = updatedArray.indexOf(item);
|
|
171
|
+
return index !== -1 && updatedArray.splice(index, 1), updatedArray;
|
|
172
|
+
}
|
|
173
|
+
function removeLinks(items) {
|
|
174
|
+
return items.filter(item => item.tagName !== "A");
|
|
175
|
+
}
|
|
176
|
+
export { FocusScope, useFocusScope };
|
|
File without changes
|
package/dist/esm/index.js.map
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./FocusScope.mjs";
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { useComposedRefs } from "@tamagui/compose-refs";
|
|
2
|
+
import { useEvent } from "@tamagui/use-event";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
5
|
+
const AUTOFOCUS_ON_MOUNT = "focusScope.autoFocusOnMount",
|
|
6
|
+
AUTOFOCUS_ON_UNMOUNT = "focusScope.autoFocusOnUnmount",
|
|
7
|
+
EVENT_OPTIONS = {
|
|
8
|
+
bubbles: !1,
|
|
9
|
+
cancelable: !0
|
|
10
|
+
},
|
|
11
|
+
FocusScope = React.forwardRef(function (props, forwardedRef) {
|
|
12
|
+
const childProps = useFocusScope(props, forwardedRef);
|
|
13
|
+
return typeof props.children == "function" ? /* @__PURE__ */jsx(Fragment, {
|
|
14
|
+
children: props.children(childProps)
|
|
15
|
+
}) : React.cloneElement(React.Children.only(props.children), childProps);
|
|
16
|
+
});
|
|
17
|
+
function useFocusScope(props, forwardedRef) {
|
|
18
|
+
const {
|
|
19
|
+
loop = !1,
|
|
20
|
+
enabled = !0,
|
|
21
|
+
trapped = !1,
|
|
22
|
+
onMountAutoFocus: onMountAutoFocusProp,
|
|
23
|
+
onUnmountAutoFocus: onUnmountAutoFocusProp,
|
|
24
|
+
forceUnmount,
|
|
25
|
+
children,
|
|
26
|
+
...scopeProps
|
|
27
|
+
} = props,
|
|
28
|
+
[container, setContainer] = React.useState(null),
|
|
29
|
+
onMountAutoFocus = useEvent(onMountAutoFocusProp),
|
|
30
|
+
onUnmountAutoFocus = useEvent(onUnmountAutoFocusProp),
|
|
31
|
+
lastFocusedElementRef = React.useRef(null),
|
|
32
|
+
composedRefs = useComposedRefs(forwardedRef, node => setContainer(node)),
|
|
33
|
+
focusScope = React.useRef({
|
|
34
|
+
paused: !1,
|
|
35
|
+
pause() {
|
|
36
|
+
this.paused = !0;
|
|
37
|
+
},
|
|
38
|
+
resume() {
|
|
39
|
+
this.paused = !1;
|
|
40
|
+
}
|
|
41
|
+
}).current;
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (!enabled || !trapped) return;
|
|
44
|
+
function handleFocusIn(event) {
|
|
45
|
+
if (focusScope.paused || !container) return;
|
|
46
|
+
const target = event.target;
|
|
47
|
+
container.contains(target) ? lastFocusedElementRef.current = target : focus(lastFocusedElementRef.current, {
|
|
48
|
+
select: !0
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
function handleFocusOut(event) {
|
|
52
|
+
focusScope.paused || !container || container.contains(event.relatedTarget) || focus(lastFocusedElementRef.current, {
|
|
53
|
+
select: !0
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
return document.addEventListener("focusin", handleFocusIn), document.addEventListener("focusout", handleFocusOut), () => {
|
|
57
|
+
document.removeEventListener("focusin", handleFocusIn), document.removeEventListener("focusout", handleFocusOut);
|
|
58
|
+
};
|
|
59
|
+
}, [trapped, forceUnmount, container, focusScope.paused]), React.useEffect(() => {
|
|
60
|
+
if (!enabled || !container || forceUnmount) return;
|
|
61
|
+
focusScopesStack.add(focusScope);
|
|
62
|
+
const previouslyFocusedElement = document.activeElement;
|
|
63
|
+
if (!container.contains(previouslyFocusedElement)) {
|
|
64
|
+
const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
|
|
65
|
+
if (container.addEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus), container.dispatchEvent(mountEvent), !mountEvent.defaultPrevented) {
|
|
66
|
+
const candidates = removeLinks(getTabbableCandidates(container));
|
|
67
|
+
focusFirst(candidates, {
|
|
68
|
+
select: !0
|
|
69
|
+
}), document.activeElement === previouslyFocusedElement && focus(container);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return () => {
|
|
73
|
+
container.removeEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
|
|
74
|
+
const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
|
|
75
|
+
container.addEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus), container.dispatchEvent(unmountEvent), unmountEvent.defaultPrevented || focus(previouslyFocusedElement ?? document.body, {
|
|
76
|
+
select: !0
|
|
77
|
+
}), container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus), focusScopesStack.remove(focusScope);
|
|
78
|
+
};
|
|
79
|
+
}, [enabled, container, forceUnmount, onMountAutoFocus, onUnmountAutoFocus, focusScope]);
|
|
80
|
+
const handleKeyDown = React.useCallback(event => {
|
|
81
|
+
if (!trapped || !loop || focusScope.paused) return;
|
|
82
|
+
const isTabKey = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey,
|
|
83
|
+
focusedElement = document.activeElement;
|
|
84
|
+
if (isTabKey && focusedElement) {
|
|
85
|
+
const container2 = event.currentTarget,
|
|
86
|
+
[first, last] = getTabbableEdges(container2);
|
|
87
|
+
first && last ? !event.shiftKey && focusedElement === last ? (event.preventDefault(), loop && focus(first, {
|
|
88
|
+
select: !0
|
|
89
|
+
})) : event.shiftKey && focusedElement === first && (event.preventDefault(), loop && focus(last, {
|
|
90
|
+
select: !0
|
|
91
|
+
})) : focusedElement === container2 && event.preventDefault();
|
|
92
|
+
}
|
|
93
|
+
}, [loop, trapped, focusScope.paused]);
|
|
94
|
+
return {
|
|
95
|
+
tabIndex: -1,
|
|
96
|
+
...scopeProps,
|
|
97
|
+
ref: composedRefs,
|
|
98
|
+
onKeyDown: handleKeyDown
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
function focusFirst(candidates, {
|
|
102
|
+
select = !1
|
|
103
|
+
} = {}) {
|
|
104
|
+
const previouslyFocusedElement = document.activeElement;
|
|
105
|
+
for (const candidate of candidates) if (focus(candidate, {
|
|
106
|
+
select
|
|
107
|
+
}), document.activeElement !== previouslyFocusedElement) return;
|
|
108
|
+
}
|
|
109
|
+
function getTabbableEdges(container) {
|
|
110
|
+
const candidates = getTabbableCandidates(container),
|
|
111
|
+
first = findVisible(candidates, container),
|
|
112
|
+
last = findVisible(candidates.reverse(), container);
|
|
113
|
+
return [first, last];
|
|
114
|
+
}
|
|
115
|
+
function getTabbableCandidates(container) {
|
|
116
|
+
const nodes = [],
|
|
117
|
+
walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
|
|
118
|
+
acceptNode: node => {
|
|
119
|
+
const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
|
|
120
|
+
return node.disabled || node.hidden || isHiddenInput ? NodeFilter.FILTER_SKIP : node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
for (; walker.nextNode();) nodes.push(walker.currentNode);
|
|
124
|
+
return nodes;
|
|
125
|
+
}
|
|
126
|
+
function findVisible(elements, container) {
|
|
127
|
+
for (const element of elements) if (!isHidden(element, {
|
|
128
|
+
upTo: container
|
|
129
|
+
})) return element;
|
|
130
|
+
}
|
|
131
|
+
function isHidden(node, {
|
|
132
|
+
upTo
|
|
133
|
+
}) {
|
|
134
|
+
if (getComputedStyle(node).visibility === "hidden") return !0;
|
|
135
|
+
for (; node;) {
|
|
136
|
+
if (upTo !== void 0 && node === upTo) return !1;
|
|
137
|
+
if (getComputedStyle(node).display === "none") return !0;
|
|
138
|
+
node = node.parentElement;
|
|
139
|
+
}
|
|
140
|
+
return !1;
|
|
141
|
+
}
|
|
142
|
+
function isSelectableInput(element) {
|
|
143
|
+
return element instanceof HTMLInputElement && "select" in element;
|
|
144
|
+
}
|
|
145
|
+
function focus(element, {
|
|
146
|
+
select = !1
|
|
147
|
+
} = {}) {
|
|
148
|
+
if (element?.focus) {
|
|
149
|
+
const previouslyFocusedElement = document.activeElement;
|
|
150
|
+
element.focus({
|
|
151
|
+
preventScroll: !0
|
|
152
|
+
}), element !== previouslyFocusedElement && isSelectableInput(element) && select && element.select();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const focusScopesStack = createFocusScopesStack();
|
|
156
|
+
function createFocusScopesStack() {
|
|
157
|
+
let stack = [];
|
|
158
|
+
return {
|
|
159
|
+
add(focusScope) {
|
|
160
|
+
const activeFocusScope = stack[0];
|
|
161
|
+
focusScope !== activeFocusScope && activeFocusScope?.pause(), stack = arrayRemove(stack, focusScope), stack.unshift(focusScope);
|
|
162
|
+
},
|
|
163
|
+
remove(focusScope) {
|
|
164
|
+
stack = arrayRemove(stack, focusScope), stack[0]?.resume();
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function arrayRemove(array, item) {
|
|
169
|
+
const updatedArray = [...array],
|
|
170
|
+
index = updatedArray.indexOf(item);
|
|
171
|
+
return index !== -1 && updatedArray.splice(index, 1), updatedArray;
|
|
172
|
+
}
|
|
173
|
+
function removeLinks(items) {
|
|
174
|
+
return items.filter(item => item.tagName !== "A");
|
|
175
|
+
}
|
|
176
|
+
export { FocusScope, useFocusScope };
|
|
File without changes
|
package/dist/jsx/index.js.map
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./FocusScope.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/focus-scope",
|
|
3
|
-
"version": "1.88.
|
|
3
|
+
"version": "1.88.15",
|
|
4
4
|
"sideEffects": true,
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
@@ -21,14 +21,14 @@
|
|
|
21
21
|
"clean:build": "tamagui-build clean:build"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@tamagui/compose-refs": "1.88.
|
|
25
|
-
"@tamagui/use-event": "1.88.
|
|
24
|
+
"@tamagui/compose-refs": "1.88.15",
|
|
25
|
+
"@tamagui/use-event": "1.88.15"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"react": "*"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@tamagui/build": "1.88.
|
|
31
|
+
"@tamagui/build": "1.88.15",
|
|
32
32
|
"react": "^18.2.0"
|
|
33
33
|
},
|
|
34
34
|
"publishConfig": {
|
package/src/FocusScope.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { useComposedRefs } from '@tamagui/compose-refs'
|
|
|
2
2
|
import { useEvent } from '@tamagui/use-event'
|
|
3
3
|
import * as React from 'react'
|
|
4
4
|
|
|
5
|
-
import { FocusScopeProps } from './FocusScopeProps'
|
|
5
|
+
import type { FocusScopeProps } from './FocusScopeProps'
|
|
6
6
|
|
|
7
7
|
const AUTOFOCUS_ON_MOUNT = 'focusScope.autoFocusOnMount'
|
|
8
8
|
const AUTOFOCUS_ON_UNMOUNT = 'focusScope.autoFocusOnUnmount'
|
package/src/FocusScopeProps.tsx
CHANGED
package/types/FocusScope.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { FocusScopeProps } from './FocusScopeProps';
|
|
2
|
+
import type { FocusScopeProps } from './FocusScopeProps';
|
|
3
3
|
type FocusScopeElement = HTMLDivElement;
|
|
4
4
|
declare const FocusScope: React.ForwardRefExoticComponent<FocusScopeProps & React.RefAttributes<HTMLDivElement>>;
|
|
5
5
|
export declare function useFocusScope(props: FocusScopeProps, forwardedRef: React.ForwardedRef<FocusScopeElement>): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusScope.d.ts","sourceRoot":"","sources":["../src/FocusScope.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"FocusScope.d.ts","sourceRoot":"","sources":["../src/FocusScope.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAYxD,KAAK,iBAAiB,GAAG,cAAc,CAAA;AAEvC,QAAA,MAAM,UAAU,wFAUf,CAAA;AAMD,wBAAgB,aAAa,CAC3B,KAAK,EAAE,eAAe,EACtB,YAAY,EAAE,KAAK,CAAC,YAAY,CAAC,iBAAiB,CAAC;;uBAmGzC,mBAAmB;;EAqC9B;AA2ID,OAAO,EAAE,UAAU,EAAE,CAAA;AAErB,YAAY,EAAE,eAAe,EAAE,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { FocusScopeProps } from './FocusScopeProps';
|
|
2
|
+
import type { FocusScopeProps } from './FocusScopeProps';
|
|
3
3
|
export declare const FocusScope: import("react").ForwardRefExoticComponent<FocusScopeProps & import("react").RefAttributes<unknown>>;
|
|
4
4
|
//# sourceMappingURL=FocusScope.native.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusScope.native.d.ts","sourceRoot":"","sources":["../src/FocusScope.native.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"FocusScope.native.d.ts","sourceRoot":"","sources":["../src/FocusScope.native.tsx"],"names":[],"mappings":";AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAExD,eAAO,MAAM,UAAU,qGAErB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FocusScopeProps.d.ts","sourceRoot":"","sources":["../src/FocusScopeProps.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"FocusScopeProps.d.ts","sourceRoot":"","sources":["../src/FocusScopeProps.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;;OAIG;IACH,IAAI,CAAC,EAAE,OAAO,CAAA;IAEd;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAEzC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAA;IAE3C;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IAEtB,QAAQ,CAAC,EACL,KAAK,CAAC,SAAS,GACf,CAAC,CAAC,KAAK,EAAE;QACP,SAAS,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,KAAK,IAAI,CAAA;QAC/C,QAAQ,EAAE,MAAM,CAAA;QAChB,GAAG,EAAE,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,CAAA;KAC7B,KAAK,KAAK,CAAC,SAAS,CAAC,CAAA;CAC3B"}
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA"}
|
|
File without changes
|