@tamagui/focus-scope 2.0.0-rc.4 → 2.0.0-rc.40

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 (55) hide show
  1. package/dist/cjs/FocusScope.cjs +284 -167
  2. package/dist/cjs/FocusScope.native.js +28 -26
  3. package/dist/cjs/FocusScope.native.js.map +1 -1
  4. package/dist/cjs/FocusScopeController.cjs +52 -50
  5. package/dist/cjs/FocusScopeController.native.js +49 -47
  6. package/dist/cjs/FocusScopeController.native.js.map +1 -1
  7. package/dist/cjs/index.cjs +7 -5
  8. package/dist/cjs/index.native.js +7 -5
  9. package/dist/cjs/index.native.js.map +1 -1
  10. package/dist/cjs/types.cjs +7 -5
  11. package/dist/cjs/types.native.js +7 -5
  12. package/dist/cjs/types.native.js.map +1 -1
  13. package/dist/esm/FocusScope.mjs +253 -138
  14. package/dist/esm/FocusScope.mjs.map +1 -1
  15. package/dist/esm/FocusScopeController.mjs +24 -24
  16. package/dist/esm/FocusScopeController.mjs.map +1 -1
  17. package/dist/esm/FocusScopeController.native.js +21 -21
  18. package/dist/esm/FocusScopeController.native.js.map +1 -1
  19. package/dist/esm/index.js +2 -2
  20. package/dist/esm/index.js.map +1 -6
  21. package/dist/jsx/FocusScope.mjs +253 -138
  22. package/dist/jsx/FocusScope.mjs.map +1 -1
  23. package/dist/jsx/FocusScope.native.js +28 -26
  24. package/dist/jsx/FocusScope.native.js.map +1 -1
  25. package/dist/jsx/FocusScopeController.mjs +24 -24
  26. package/dist/jsx/FocusScopeController.mjs.map +1 -1
  27. package/dist/jsx/FocusScopeController.native.js +49 -47
  28. package/dist/jsx/FocusScopeController.native.js.map +1 -1
  29. package/dist/jsx/index.js +2 -2
  30. package/dist/jsx/index.js.map +1 -6
  31. package/dist/jsx/index.native.js +7 -5
  32. package/dist/jsx/types.native.js +7 -5
  33. package/package.json +11 -14
  34. package/src/FocusScope.tsx +33 -6
  35. package/types/FocusScope.d.ts.map +1 -1
  36. package/dist/cjs/FocusScope.js +0 -245
  37. package/dist/cjs/FocusScope.js.map +0 -6
  38. package/dist/cjs/FocusScopeController.js +0 -69
  39. package/dist/cjs/FocusScopeController.js.map +0 -6
  40. package/dist/cjs/index.js +0 -16
  41. package/dist/cjs/index.js.map +0 -6
  42. package/dist/cjs/types.js +0 -14
  43. package/dist/cjs/types.js.map +0 -6
  44. package/dist/esm/FocusScope.js +0 -227
  45. package/dist/esm/FocusScope.js.map +0 -6
  46. package/dist/esm/FocusScopeController.js +0 -48
  47. package/dist/esm/FocusScopeController.js.map +0 -6
  48. package/dist/esm/types.js +0 -1
  49. package/dist/esm/types.js.map +0 -6
  50. package/dist/jsx/FocusScope.js +0 -227
  51. package/dist/jsx/FocusScope.js.map +0 -6
  52. package/dist/jsx/FocusScopeController.js +0 -48
  53. package/dist/jsx/FocusScopeController.js.map +0 -6
  54. package/dist/jsx/types.js +0 -1
  55. package/dist/jsx/types.js.map +0 -6
@@ -1,245 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
- var FocusScope_exports = {};
24
- __export(FocusScope_exports, {
25
- FocusScope: () => FocusScope,
26
- useFocusScope: () => useFocusScope
27
- });
28
- module.exports = __toCommonJS(FocusScope_exports);
29
- var import_compose_refs = require("@tamagui/compose-refs"), import_constants = require("@tamagui/constants"), import_use_async = require("@tamagui/use-async"), import_use_event = require("@tamagui/use-event"), React = __toESM(require("react"), 1), import_FocusScopeController = require("./FocusScopeController"), import_jsx_runtime = require("react/jsx-runtime");
30
- const AUTOFOCUS_ON_MOUNT = "focusScope.autoFocusOnMount", AUTOFOCUS_ON_UNMOUNT = "focusScope.autoFocusOnUnmount", EVENT_OPTIONS = { bubbles: !1, cancelable: !0 }, FocusScope = React.forwardRef(
31
- function({ __scopeFocusScope, ...props }, forwardedRef) {
32
- const context = (0, import_FocusScopeController.useFocusScopeControllerContext)("FocusScope", __scopeFocusScope, {
33
- warn: !1,
34
- fallback: {}
35
- }), mergedProps = {
36
- ...props,
37
- enabled: context.enabled ?? props.enabled,
38
- loop: context.loop ?? props.loop,
39
- trapped: context.trapped ?? props.trapped,
40
- onMountAutoFocus: context.onMountAutoFocus ?? props.onMountAutoFocus,
41
- onUnmountAutoFocus: context.onUnmountAutoFocus ?? props.onUnmountAutoFocus,
42
- forceUnmount: context.forceUnmount ?? props.forceUnmount,
43
- focusOnIdle: context.focusOnIdle ?? props.focusOnIdle
44
- }, childProps = useFocusScope(mergedProps, forwardedRef);
45
- return typeof mergedProps.children == "function" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: mergedProps.children(childProps) }) : React.cloneElement(
46
- React.Children.only(mergedProps.children),
47
- childProps
48
- );
49
- }
50
- );
51
- function setupFocusTrap(container, lastFocusedElementRef, focusScope) {
52
- const controller = new AbortController();
53
- let rafId = null;
54
- function scheduleRefocus() {
55
- if (rafId) return;
56
- const elementToFocus = lastFocusedElementRef.current;
57
- rafId = requestAnimationFrame(() => {
58
- rafId = null, !focusScope.paused && (focusScope.stopped || container.isConnected && (container.contains(document.activeElement) || focus(elementToFocus)));
59
- });
60
- }
61
- function handleFocusIn(event) {
62
- if (focusScope.paused) return;
63
- const target = event.target;
64
- container.contains(target) ? (target?.addEventListener("blur", handleBlur, { signal: controller.signal }), lastFocusedElementRef.current = target) : scheduleRefocus();
65
- }
66
- function handleFocusOut(event) {
67
- controller.abort(), !focusScope.paused && (container.contains(event.relatedTarget) || scheduleRefocus());
68
- }
69
- function handleBlur() {
70
- }
71
- return document.addEventListener("focusin", handleFocusIn), document.addEventListener("focusout", handleFocusOut), () => {
72
- rafId && (cancelAnimationFrame(rafId), rafId = null), controller.abort(), document.removeEventListener("focusin", handleFocusIn), document.removeEventListener("focusout", handleFocusOut);
73
- };
74
- }
75
- function useFocusScope(props, forwardedRef) {
76
- const {
77
- loop = !1,
78
- enabled = !0,
79
- trapped = !1,
80
- onMountAutoFocus: onMountAutoFocusProp,
81
- onUnmountAutoFocus: onUnmountAutoFocusProp,
82
- forceUnmount,
83
- focusOnIdle = !0,
84
- children,
85
- ...scopeProps
86
- } = props, [container, setContainer] = React.useState(null), containerRef = React.useRef(null), onMountAutoFocus = (0, import_use_event.useEvent)(onMountAutoFocusProp), onUnmountAutoFocus = (0, import_use_event.useEvent)(onUnmountAutoFocusProp), lastFocusedElementRef = React.useRef(null), focusScopeRef = React.useRef({
87
- paused: !1,
88
- stopped: !1,
89
- // set to true when cleanup starts, signals trap to stop
90
- pause() {
91
- this.paused = !0;
92
- },
93
- resume() {
94
- this.paused = !1;
95
- },
96
- stop() {
97
- this.stopped = !0;
98
- }
99
- }), focusScope = focusScopeRef.current, trapCleanupRef = React.useRef(null), setContainerRef = React.useCallback(
100
- (node) => {
101
- trapCleanupRef.current && (trapCleanupRef.current(), trapCleanupRef.current = null), containerRef.current = node, import_constants.isWeb && node && enabled && trapped && (trapCleanupRef.current = setupFocusTrap(
102
- node,
103
- lastFocusedElementRef,
104
- focusScopeRef.current
105
- )), setContainer(node);
106
- },
107
- [enabled, trapped]
108
- ), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, setContainerRef);
109
- (0, import_constants.useIsomorphicLayoutEffect)(() => () => {
110
- trapCleanupRef.current && (trapCleanupRef.current(), trapCleanupRef.current = null);
111
- }, []), (0, import_use_async.useAsyncEffect)(
112
- async (signal) => {
113
- if (!enabled || !container || forceUnmount) return;
114
- focusScope.stopped = !1, focusScopesStack.add(focusScope);
115
- const previouslyFocusedElement = document.activeElement;
116
- if (!container.contains(previouslyFocusedElement)) {
117
- const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
118
- if (container.addEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus), container.dispatchEvent(mountEvent), !mountEvent.defaultPrevented) {
119
- focusOnIdle && await (0, import_use_async.idle)(
120
- signal,
121
- typeof focusOnIdle == "object" ? focusOnIdle : {
122
- // we can't wait too long or else user can take an action and then we focus
123
- max: 200,
124
- min: typeof focusOnIdle == "number" ? focusOnIdle : 16
125
- }
126
- );
127
- const allCandidates = getTabbableCandidates(container), visibleCandidates = removeLinks(allCandidates).filter(
128
- (candidate) => !isHidden(candidate, { upTo: container })
129
- );
130
- focusFirst(visibleCandidates, { select: !0 }), visibleCandidates.length > 0 ? lastFocusedElementRef.current = visibleCandidates[0] : lastFocusedElementRef.current = container, document.activeElement === previouslyFocusedElement && visibleCandidates.length === 0 && focus(container);
131
- }
132
- }
133
- return () => {
134
- focusScope.stop(), container.removeEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
135
- const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
136
- container.addEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus), container.dispatchEvent(unmountEvent), unmountEvent.defaultPrevented || focus(previouslyFocusedElement ?? document.body, { select: !0 }), container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus), focusScopesStack.remove(focusScope);
137
- };
138
- },
139
- [
140
- enabled,
141
- container,
142
- forceUnmount,
143
- onMountAutoFocus,
144
- onUnmountAutoFocus,
145
- focusScope,
146
- focusOnIdle
147
- ]
148
- );
149
- const handleKeyDown = React.useCallback(
150
- (event) => {
151
- if (!trapped || !loop || focusScope.paused || !enabled || !container) return;
152
- const isTabKey = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey, focusedElement = document.activeElement;
153
- if (isTabKey && focusedElement) {
154
- const [first, last] = getTabbableEdges(container);
155
- first && last ? !event.shiftKey && focusedElement === last ? (event.preventDefault(), loop && focus(first, { select: !0 })) : event.shiftKey && focusedElement === first && (event.preventDefault(), loop && focus(last, { select: !0 })) : focusedElement === container && event.preventDefault();
156
- }
157
- },
158
- [loop, trapped, focusScope.paused, enabled, container]
159
- );
160
- React.useEffect(() => {
161
- if (!container || !trapped || !loop || !enabled) return;
162
- const handleKeyDownCapture = (event) => {
163
- event.key === "Tab" && handleKeyDown(event);
164
- };
165
- return container.addEventListener("keydown", handleKeyDownCapture, !0), () => {
166
- container.removeEventListener("keydown", handleKeyDownCapture, !0);
167
- };
168
- }, [container, trapped, loop, enabled, handleKeyDown]);
169
- const existingOnKeyDown = scopeProps.onKeyDown, composedOnKeyDown = React.useCallback(
170
- (event) => {
171
- existingOnKeyDown?.(event);
172
- },
173
- [existingOnKeyDown]
174
- );
175
- return {
176
- ...scopeProps,
177
- ref: composedRefs,
178
- onKeyDown: composedOnKeyDown
179
- };
180
- }
181
- function focusFirst(candidates, { select = !1 } = {}) {
182
- const previouslyFocusedElement = document.activeElement;
183
- for (const candidate of candidates)
184
- if (focus(candidate, { select }), document.activeElement !== previouslyFocusedElement) return;
185
- }
186
- function getTabbableEdges(container) {
187
- const candidates = getTabbableCandidates(container), first = findVisible(candidates, container), last = findVisible(candidates.reverse(), container);
188
- return [first, last];
189
- }
190
- function getTabbableCandidates(container) {
191
- const nodes = [], walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
192
- acceptNode: (node) => {
193
- const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
194
- return node.disabled || node.hidden || isHiddenInput ? NodeFilter.FILTER_SKIP : node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
195
- }
196
- });
197
- for (; walker.nextNode(); ) nodes.push(walker.currentNode);
198
- return nodes;
199
- }
200
- function findVisible(elements, container) {
201
- for (const element of elements)
202
- if (!isHidden(element, { upTo: container })) return element;
203
- }
204
- function isHidden(node, { upTo }) {
205
- if (getComputedStyle(node).visibility === "hidden") return !0;
206
- for (; node; ) {
207
- if (upTo !== void 0 && node === upTo) return !1;
208
- if (getComputedStyle(node).display === "none") return !0;
209
- node = node.parentElement;
210
- }
211
- return !1;
212
- }
213
- function isSelectableInput(element) {
214
- return element instanceof HTMLInputElement && "select" in element;
215
- }
216
- function focus(element, { select = !1 } = {}) {
217
- if (element?.focus) {
218
- const previouslyFocusedElement = document.activeElement;
219
- try {
220
- element.focus({ preventScroll: !0 }), element !== previouslyFocusedElement && isSelectableInput(element) && select && element.select();
221
- } catch {
222
- }
223
- }
224
- }
225
- const focusScopesStack = createFocusScopesStack();
226
- function createFocusScopesStack() {
227
- let stack = [];
228
- return {
229
- add(focusScope) {
230
- const activeFocusScope = stack[0];
231
- focusScope !== activeFocusScope && activeFocusScope?.pause(), stack = arrayRemove(stack, focusScope), stack.unshift(focusScope);
232
- },
233
- remove(focusScope) {
234
- stack = arrayRemove(stack, focusScope), stack[0]?.resume();
235
- }
236
- };
237
- }
238
- function arrayRemove(array, item) {
239
- const updatedArray = [...array], index = updatedArray.indexOf(item);
240
- return index !== -1 && updatedArray.splice(index, 1), updatedArray;
241
- }
242
- function removeLinks(items) {
243
- return items.filter((item) => item.tagName !== "A");
244
- }
245
- //# sourceMapping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AAY,MAAS;AAC3C,QAAM,eAAe,CAAC,GAAG,KAAK,GACxB,QAAQ,aAAa,QAAQ,IAAI;AACvC,SAAI,UAAU,MACZ,aAAa,OAAO,OAAO,CAAC,GAEvB;AACT;AAEA,SAAS,YAAY,OAAsB;AACzC,SAAO,MAAM,OAAO,CAAC,SAAS,KAAK,YAAY,GAAG;AACpD;",
5
- "names": []
6
- }
@@ -1,69 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: !0 });
9
- }, __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from == "object" || typeof from == "function")
11
- for (let key of __getOwnPropNames(from))
12
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
13
- return to;
14
- };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
21
- mod
22
- )), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
23
- var FocusScopeController_exports = {};
24
- __export(FocusScopeController_exports, {
25
- FocusScopeController: () => FocusScopeControllerComponent,
26
- FocusScopeControllerProvider: () => FocusScopeControllerProvider,
27
- createFocusScopeControllerScope: () => createFocusScopeControllerScope,
28
- useFocusScopeControllerContext: () => useFocusScopeControllerContext
29
- });
30
- module.exports = __toCommonJS(FocusScopeController_exports);
31
- var import_create_context = require("@tamagui/create-context"), import_use_event = require("@tamagui/use-event"), React = __toESM(require("react"), 1), import_jsx_runtime = require("react/jsx-runtime");
32
- const FOCUS_SCOPE_CONTROLLER_NAME = "FocusScopeController", [createFocusScopeControllerContext, createFocusScopeControllerScope] = (0, import_create_context.createContextScope)(FOCUS_SCOPE_CONTROLLER_NAME), [FocusScopeControllerProvider, useFocusScopeControllerContext] = createFocusScopeControllerContext(
33
- FOCUS_SCOPE_CONTROLLER_NAME
34
- );
35
- function FocusScopeController(props) {
36
- const {
37
- __scopeFocusScope,
38
- children,
39
- enabled,
40
- loop,
41
- trapped,
42
- onMountAutoFocus,
43
- onUnmountAutoFocus,
44
- forceUnmount,
45
- focusOnIdle
46
- } = props, stableOnMountAutoFocus = (0, import_use_event.useEvent)(onMountAutoFocus), stableOnUnmountAutoFocus = (0, import_use_event.useEvent)(onUnmountAutoFocus), contextValue = React.useMemo(
47
- () => ({
48
- enabled,
49
- loop,
50
- trapped,
51
- onMountAutoFocus: stableOnMountAutoFocus,
52
- onUnmountAutoFocus: stableOnUnmountAutoFocus,
53
- forceUnmount,
54
- focusOnIdle
55
- }),
56
- [
57
- enabled,
58
- loop,
59
- trapped,
60
- stableOnMountAutoFocus,
61
- stableOnUnmountAutoFocus,
62
- forceUnmount,
63
- focusOnIdle
64
- ]
65
- );
66
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FocusScopeControllerProvider, { scope: __scopeFocusScope, ...contextValue, children });
67
- }
68
- const FocusScopeControllerComponent = FocusScopeController;
69
- //# sourceMappingURL=FocusScopeController.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/FocusScopeController.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAmC,oCACnC,mBAAyB,+BACzB,QAAuB,8BA8DnB;AA1DJ,MAAM,8BAA8B,wBAE9B,CAAC,mCAAmC,+BAA+B,QACvE,0CAAmB,2BAA2B,GAI1C,CAAC,8BAA8B,8BAA8B,IACjE;AAAA,EACE;AACF;AAUF,SAAS,qBAAqB,OAA+C;AAC3E,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,OAEE,6BAAyB,2BAAS,gBAAgB,GAClD,+BAA2B,2BAAS,kBAAkB,GAEtD,eAAe,MAAM;AAAA,IACzB,OAAO;AAAA,MACL;AAAA,MACA;AAAA,MACA;AAAA,MACA,kBAAkB;AAAA,MAClB,oBAAoB;AAAA,MACpB;AAAA,MACA;AAAA,IACF;AAAA,IACA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AAEA,SACE,4CAAC,gCAA6B,OAAO,mBAAoB,GAAG,cACzD,UACH;AAEJ;AAEA,MAAM,gCAAgC;",
5
- "names": []
6
- }
package/dist/cjs/index.js DELETED
@@ -1,16 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from == "object" || typeof from == "function")
7
- for (let key of __getOwnPropNames(from))
8
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
- return to;
10
- }, __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
11
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
12
- var index_exports = {};
13
- module.exports = __toCommonJS(index_exports);
14
- __reExport(index_exports, require("./FocusScope"), module.exports);
15
- __reExport(index_exports, require("./FocusScopeController"), module.exports);
16
- //# sourceMappingURL=index.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/index.ts"],
4
- "mappings": ";;;;;;;;;;;AAAA;AAAA;AAAA,0BAAc,yBAAd;AACA,0BAAc,mCADd;",
5
- "names": []
6
- }
package/dist/cjs/types.js DELETED
@@ -1,14 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from == "object" || typeof from == "function")
7
- for (let key of __getOwnPropNames(from))
8
- !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
9
- return to;
10
- };
11
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
12
- var types_exports = {};
13
- module.exports = __toCommonJS(types_exports);
14
- //# sourceMappingURL=types.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/types.tsx"],
4
- "mappings": ";;;;;;;;;;;AAAA;AAAA;",
5
- "names": []
6
- }
@@ -1,227 +0,0 @@
1
- import { useComposedRefs } from "@tamagui/compose-refs";
2
- import { isWeb, useIsomorphicLayoutEffect } from "@tamagui/constants";
3
- import { idle, useAsyncEffect } from "@tamagui/use-async";
4
- import { useEvent } from "@tamagui/use-event";
5
- import * as React from "react";
6
- import { useFocusScopeControllerContext } from "./FocusScopeController";
7
- import { Fragment, jsx } from "react/jsx-runtime";
8
- const AUTOFOCUS_ON_MOUNT = "focusScope.autoFocusOnMount", AUTOFOCUS_ON_UNMOUNT = "focusScope.autoFocusOnUnmount", EVENT_OPTIONS = { bubbles: !1, cancelable: !0 }, FocusScope = React.forwardRef(
9
- function({ __scopeFocusScope, ...props }, forwardedRef) {
10
- const context = useFocusScopeControllerContext("FocusScope", __scopeFocusScope, {
11
- warn: !1,
12
- fallback: {}
13
- }), mergedProps = {
14
- ...props,
15
- enabled: context.enabled ?? props.enabled,
16
- loop: context.loop ?? props.loop,
17
- trapped: context.trapped ?? props.trapped,
18
- onMountAutoFocus: context.onMountAutoFocus ?? props.onMountAutoFocus,
19
- onUnmountAutoFocus: context.onUnmountAutoFocus ?? props.onUnmountAutoFocus,
20
- forceUnmount: context.forceUnmount ?? props.forceUnmount,
21
- focusOnIdle: context.focusOnIdle ?? props.focusOnIdle
22
- }, childProps = useFocusScope(mergedProps, forwardedRef);
23
- return typeof mergedProps.children == "function" ? /* @__PURE__ */ jsx(Fragment, { children: mergedProps.children(childProps) }) : React.cloneElement(
24
- React.Children.only(mergedProps.children),
25
- childProps
26
- );
27
- }
28
- );
29
- function setupFocusTrap(container, lastFocusedElementRef, focusScope) {
30
- const controller = new AbortController();
31
- let rafId = null;
32
- function scheduleRefocus() {
33
- if (rafId) return;
34
- const elementToFocus = lastFocusedElementRef.current;
35
- rafId = requestAnimationFrame(() => {
36
- rafId = null, !focusScope.paused && (focusScope.stopped || container.isConnected && (container.contains(document.activeElement) || focus(elementToFocus)));
37
- });
38
- }
39
- function handleFocusIn(event) {
40
- if (focusScope.paused) return;
41
- const target = event.target;
42
- container.contains(target) ? (target?.addEventListener("blur", handleBlur, { signal: controller.signal }), lastFocusedElementRef.current = target) : scheduleRefocus();
43
- }
44
- function handleFocusOut(event) {
45
- controller.abort(), !focusScope.paused && (container.contains(event.relatedTarget) || scheduleRefocus());
46
- }
47
- function handleBlur() {
48
- }
49
- return document.addEventListener("focusin", handleFocusIn), document.addEventListener("focusout", handleFocusOut), () => {
50
- rafId && (cancelAnimationFrame(rafId), rafId = null), controller.abort(), document.removeEventListener("focusin", handleFocusIn), document.removeEventListener("focusout", handleFocusOut);
51
- };
52
- }
53
- function useFocusScope(props, forwardedRef) {
54
- const {
55
- loop = !1,
56
- enabled = !0,
57
- trapped = !1,
58
- onMountAutoFocus: onMountAutoFocusProp,
59
- onUnmountAutoFocus: onUnmountAutoFocusProp,
60
- forceUnmount,
61
- focusOnIdle = !0,
62
- children,
63
- ...scopeProps
64
- } = props, [container, setContainer] = React.useState(null), containerRef = React.useRef(null), onMountAutoFocus = useEvent(onMountAutoFocusProp), onUnmountAutoFocus = useEvent(onUnmountAutoFocusProp), lastFocusedElementRef = React.useRef(null), focusScopeRef = React.useRef({
65
- paused: !1,
66
- stopped: !1,
67
- // set to true when cleanup starts, signals trap to stop
68
- pause() {
69
- this.paused = !0;
70
- },
71
- resume() {
72
- this.paused = !1;
73
- },
74
- stop() {
75
- this.stopped = !0;
76
- }
77
- }), focusScope = focusScopeRef.current, trapCleanupRef = React.useRef(null), setContainerRef = React.useCallback(
78
- (node) => {
79
- trapCleanupRef.current && (trapCleanupRef.current(), trapCleanupRef.current = null), containerRef.current = node, isWeb && node && enabled && trapped && (trapCleanupRef.current = setupFocusTrap(
80
- node,
81
- lastFocusedElementRef,
82
- focusScopeRef.current
83
- )), setContainer(node);
84
- },
85
- [enabled, trapped]
86
- ), composedRefs = useComposedRefs(forwardedRef, setContainerRef);
87
- useIsomorphicLayoutEffect(() => () => {
88
- trapCleanupRef.current && (trapCleanupRef.current(), trapCleanupRef.current = null);
89
- }, []), useAsyncEffect(
90
- async (signal) => {
91
- if (!enabled || !container || forceUnmount) return;
92
- focusScope.stopped = !1, focusScopesStack.add(focusScope);
93
- const previouslyFocusedElement = document.activeElement;
94
- if (!container.contains(previouslyFocusedElement)) {
95
- const mountEvent = new CustomEvent(AUTOFOCUS_ON_MOUNT, EVENT_OPTIONS);
96
- if (container.addEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus), container.dispatchEvent(mountEvent), !mountEvent.defaultPrevented) {
97
- focusOnIdle && await idle(
98
- signal,
99
- typeof focusOnIdle == "object" ? focusOnIdle : {
100
- // we can't wait too long or else user can take an action and then we focus
101
- max: 200,
102
- min: typeof focusOnIdle == "number" ? focusOnIdle : 16
103
- }
104
- );
105
- const allCandidates = getTabbableCandidates(container), visibleCandidates = removeLinks(allCandidates).filter(
106
- (candidate) => !isHidden(candidate, { upTo: container })
107
- );
108
- focusFirst(visibleCandidates, { select: !0 }), visibleCandidates.length > 0 ? lastFocusedElementRef.current = visibleCandidates[0] : lastFocusedElementRef.current = container, document.activeElement === previouslyFocusedElement && visibleCandidates.length === 0 && focus(container);
109
- }
110
- }
111
- return () => {
112
- focusScope.stop(), container.removeEventListener(AUTOFOCUS_ON_MOUNT, onMountAutoFocus);
113
- const unmountEvent = new CustomEvent(AUTOFOCUS_ON_UNMOUNT, EVENT_OPTIONS);
114
- container.addEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus), container.dispatchEvent(unmountEvent), unmountEvent.defaultPrevented || focus(previouslyFocusedElement ?? document.body, { select: !0 }), container.removeEventListener(AUTOFOCUS_ON_UNMOUNT, onUnmountAutoFocus), focusScopesStack.remove(focusScope);
115
- };
116
- },
117
- [
118
- enabled,
119
- container,
120
- forceUnmount,
121
- onMountAutoFocus,
122
- onUnmountAutoFocus,
123
- focusScope,
124
- focusOnIdle
125
- ]
126
- );
127
- const handleKeyDown = React.useCallback(
128
- (event) => {
129
- if (!trapped || !loop || focusScope.paused || !enabled || !container) return;
130
- const isTabKey = event.key === "Tab" && !event.altKey && !event.ctrlKey && !event.metaKey, focusedElement = document.activeElement;
131
- if (isTabKey && focusedElement) {
132
- const [first, last] = getTabbableEdges(container);
133
- first && last ? !event.shiftKey && focusedElement === last ? (event.preventDefault(), loop && focus(first, { select: !0 })) : event.shiftKey && focusedElement === first && (event.preventDefault(), loop && focus(last, { select: !0 })) : focusedElement === container && event.preventDefault();
134
- }
135
- },
136
- [loop, trapped, focusScope.paused, enabled, container]
137
- );
138
- React.useEffect(() => {
139
- if (!container || !trapped || !loop || !enabled) return;
140
- const handleKeyDownCapture = (event) => {
141
- event.key === "Tab" && handleKeyDown(event);
142
- };
143
- return container.addEventListener("keydown", handleKeyDownCapture, !0), () => {
144
- container.removeEventListener("keydown", handleKeyDownCapture, !0);
145
- };
146
- }, [container, trapped, loop, enabled, handleKeyDown]);
147
- const existingOnKeyDown = scopeProps.onKeyDown, composedOnKeyDown = React.useCallback(
148
- (event) => {
149
- existingOnKeyDown?.(event);
150
- },
151
- [existingOnKeyDown]
152
- );
153
- return {
154
- ...scopeProps,
155
- ref: composedRefs,
156
- onKeyDown: composedOnKeyDown
157
- };
158
- }
159
- function focusFirst(candidates, { select = !1 } = {}) {
160
- const previouslyFocusedElement = document.activeElement;
161
- for (const candidate of candidates)
162
- if (focus(candidate, { select }), document.activeElement !== previouslyFocusedElement) return;
163
- }
164
- function getTabbableEdges(container) {
165
- const candidates = getTabbableCandidates(container), first = findVisible(candidates, container), last = findVisible(candidates.reverse(), container);
166
- return [first, last];
167
- }
168
- function getTabbableCandidates(container) {
169
- const nodes = [], walker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
170
- acceptNode: (node) => {
171
- const isHiddenInput = node.tagName === "INPUT" && node.type === "hidden";
172
- return node.disabled || node.hidden || isHiddenInput ? NodeFilter.FILTER_SKIP : node.tabIndex >= 0 ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
173
- }
174
- });
175
- for (; walker.nextNode(); ) nodes.push(walker.currentNode);
176
- return nodes;
177
- }
178
- function findVisible(elements, container) {
179
- for (const element of elements)
180
- if (!isHidden(element, { upTo: container })) return element;
181
- }
182
- function isHidden(node, { upTo }) {
183
- if (getComputedStyle(node).visibility === "hidden") return !0;
184
- for (; node; ) {
185
- if (upTo !== void 0 && node === upTo) return !1;
186
- if (getComputedStyle(node).display === "none") return !0;
187
- node = node.parentElement;
188
- }
189
- return !1;
190
- }
191
- function isSelectableInput(element) {
192
- return element instanceof HTMLInputElement && "select" in element;
193
- }
194
- function focus(element, { select = !1 } = {}) {
195
- if (element?.focus) {
196
- const previouslyFocusedElement = document.activeElement;
197
- try {
198
- element.focus({ preventScroll: !0 }), element !== previouslyFocusedElement && isSelectableInput(element) && select && element.select();
199
- } catch {
200
- }
201
- }
202
- }
203
- const focusScopesStack = createFocusScopesStack();
204
- function createFocusScopesStack() {
205
- let stack = [];
206
- return {
207
- add(focusScope) {
208
- const activeFocusScope = stack[0];
209
- focusScope !== activeFocusScope && activeFocusScope?.pause(), stack = arrayRemove(stack, focusScope), stack.unshift(focusScope);
210
- },
211
- remove(focusScope) {
212
- stack = arrayRemove(stack, focusScope), stack[0]?.resume();
213
- }
214
- };
215
- }
216
- function arrayRemove(array, item) {
217
- const updatedArray = [...array], index = updatedArray.indexOf(item);
218
- return index !== -1 && updatedArray.splice(index, 1), updatedArray;
219
- }
220
- function removeLinks(items) {
221
- return items.filter((item) => item.tagName !== "A");
222
- }
223
- export {
224
- FocusScope,
225
- useFocusScope
226
- };
227
- //# sourceMappingURL=FocusScope.js.map
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/FocusScope.tsx"],
4
- "mappings": "AAAA,SAAS,uBAAuB;AAChC,SAAS,OAAO,iCAAiC;AACjD,SAAS,MAAM,sBAAsB;AACrC,SAAS,gBAAgB;AACzB,YAAY,WAAW;AACvB,SAAS,sCAAsC;AAwClC;AArCb,MAAM,qBAAqB,+BACrB,uBAAuB,iCACvB,gBAAgB,EAAE,SAAS,IAAO,YAAY,GAAK,GAUnD,aAAa,MAAM;AAAA,EACvB,SACE,EAAE,mBAAmB,GAAG,MAAM,GAC9B,cACA;AAEA,UAAM,UAAU,+BAA+B,cAAc,mBAAmB;AAAA,MAC9E,MAAM;AAAA,MACN,UAAU,CAAC;AAAA,IACb,CAAC,GAEK,cAA+B;AAAA,MACnC,GAAG;AAAA,MACH,SAAS,QAAQ,WAAW,MAAM;AAAA,MAClC,MAAM,QAAQ,QAAQ,MAAM;AAAA,MAC5B,SAAS,QAAQ,WAAW,MAAM;AAAA,MAClC,kBAAkB,QAAQ,oBAAo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