@tamagui/roving-focus 1.116.1 → 1.116.3

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.
@@ -0,0 +1,210 @@
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 RovingFocusGroup_exports = {};
24
+ __export(RovingFocusGroup_exports, {
25
+ RovingFocusGroup: () => RovingFocusGroup
26
+ });
27
+ module.exports = __toCommonJS(RovingFocusGroup_exports);
28
+ var import_collection = require("@tamagui/collection"), import_compose_refs = require("@tamagui/compose-refs"), import_constants = require("@tamagui/constants"), import_core = require("@tamagui/core"), import_helpers = require("@tamagui/helpers"), import_use_controllable_state = require("@tamagui/use-controllable-state"), import_use_direction = require("@tamagui/use-direction"), React = __toESM(require("react")), import_jsx_runtime = require("react/jsx-runtime");
29
+ const ENTRY_FOCUS = "rovingFocusGroup.onEntryFocus", EVENT_OPTIONS = { bubbles: !1, cancelable: !0 }, RovingFocusGroupImpl = React.forwardRef((props, forwardedRef) => {
30
+ const {
31
+ __scopeRovingFocusGroup,
32
+ orientation,
33
+ loop = !1,
34
+ dir,
35
+ currentTabStopId: currentTabStopIdProp,
36
+ defaultCurrentTabStopId,
37
+ onCurrentTabStopIdChange,
38
+ onEntryFocus,
39
+ ...groupProps
40
+ } = props, ref = React.useRef(null), composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref), direction = (0, import_use_direction.useDirection)(dir), [currentTabStopId = null, setCurrentTabStopId] = (0, import_use_controllable_state.useControllableState)({
41
+ prop: currentTabStopIdProp,
42
+ defaultProp: defaultCurrentTabStopId ?? null,
43
+ onChange: onCurrentTabStopIdChange
44
+ }), [isTabbingBackOut, setIsTabbingBackOut] = React.useState(!1), handleEntryFocus = (0, import_core.useEvent)(onEntryFocus), getItems = useCollection(__scopeRovingFocusGroup || ROVING_FOCUS_GROUP_CONTEXT), isClickFocusRef = React.useRef(!1), [focusableItemsCount, setFocusableItemsCount] = React.useState(0);
45
+ return React.useEffect(() => {
46
+ const node = ref.current;
47
+ if (node)
48
+ return node.addEventListener(ENTRY_FOCUS, handleEntryFocus), () => node.removeEventListener(ENTRY_FOCUS, handleEntryFocus);
49
+ }, [handleEntryFocus]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
50
+ RovingFocusProvider,
51
+ {
52
+ scope: __scopeRovingFocusGroup,
53
+ orientation,
54
+ dir: direction,
55
+ loop,
56
+ currentTabStopId,
57
+ onItemFocus: React.useCallback(
58
+ (tabStopId) => setCurrentTabStopId(tabStopId),
59
+ [setCurrentTabStopId]
60
+ ),
61
+ onItemShiftTab: React.useCallback(() => setIsTabbingBackOut(!0), []),
62
+ onFocusableItemAdd: React.useCallback(
63
+ () => setFocusableItemsCount((prevCount) => prevCount + 1),
64
+ []
65
+ ),
66
+ onFocusableItemRemove: React.useCallback(
67
+ () => setFocusableItemsCount((prevCount) => prevCount - 1),
68
+ []
69
+ ),
70
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
71
+ import_core.Stack,
72
+ {
73
+ tabIndex: isTabbingBackOut || focusableItemsCount === 0 ? -1 : 0,
74
+ "data-orientation": orientation,
75
+ ...groupProps,
76
+ ref: composedRefs,
77
+ style: [{ outline: "none" }, props.style],
78
+ onMouseDown: (0, import_helpers.composeEventHandlers)(props.onMouseDown, () => {
79
+ isClickFocusRef.current = !0;
80
+ }),
81
+ onFocus: (0, import_helpers.composeEventHandlers)(props.onFocus, (event) => {
82
+ const isKeyboardFocus = !isClickFocusRef.current;
83
+ if (event.target === event.currentTarget && isKeyboardFocus && !isTabbingBackOut) {
84
+ const entryFocusEvent = new CustomEvent(ENTRY_FOCUS, EVENT_OPTIONS);
85
+ if (event.currentTarget.dispatchEvent(entryFocusEvent), !entryFocusEvent.defaultPrevented) {
86
+ const items = getItems().filter((item) => item.focusable), activeItem = items.find((item) => item.active), currentItem = items.find((item) => item.id === currentTabStopId), candidateNodes = [activeItem, currentItem, ...items].filter(
87
+ Boolean
88
+ ).map((item) => item.ref.current);
89
+ focusFirst(candidateNodes);
90
+ }
91
+ }
92
+ isClickFocusRef.current = !1;
93
+ }),
94
+ onBlur: (0, import_helpers.composeEventHandlers)(
95
+ props.onBlur,
96
+ () => setIsTabbingBackOut(!1)
97
+ )
98
+ }
99
+ )
100
+ }
101
+ );
102
+ }), ITEM_NAME = "RovingFocusGroupItem", RovingFocusGroupItem = React.forwardRef((props, forwardedRef) => {
103
+ const {
104
+ __scopeRovingFocusGroup,
105
+ focusable = !0,
106
+ active = !1,
107
+ tabStopId,
108
+ ...itemProps
109
+ } = props, autoId = React.useId(), id = tabStopId || autoId, context = useRovingFocusContext(__scopeRovingFocusGroup), isCurrentTabStop = context.currentTabStopId === id, getItems = useCollection(__scopeRovingFocusGroup || ROVING_FOCUS_GROUP_CONTEXT), { onFocusableItemAdd, onFocusableItemRemove } = context;
110
+ return React.useEffect(() => {
111
+ if (focusable)
112
+ return onFocusableItemAdd(), () => onFocusableItemRemove();
113
+ }, [focusable, onFocusableItemAdd, onFocusableItemRemove]), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
114
+ Collection.ItemSlot,
115
+ {
116
+ __scopeCollection: __scopeRovingFocusGroup || ROVING_FOCUS_GROUP_CONTEXT,
117
+ id,
118
+ focusable,
119
+ active,
120
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
121
+ import_core.Stack,
122
+ {
123
+ tabIndex: isCurrentTabStop ? 0 : -1,
124
+ "data-orientation": context.orientation,
125
+ ...itemProps,
126
+ ref: forwardedRef,
127
+ onMouseDown: (0, import_helpers.composeEventHandlers)(props.onMouseDown, (event) => {
128
+ focusable ? context.onItemFocus(id) : event.preventDefault();
129
+ }),
130
+ onFocus: (0, import_helpers.composeEventHandlers)(props.onFocus, () => context.onItemFocus(id)),
131
+ ...import_constants.isWeb && {
132
+ onKeyDown: (0, import_helpers.composeEventHandlers)(
133
+ props.onKeyDown,
134
+ (event) => {
135
+ if (event.key === "Tab" && event.shiftKey) {
136
+ context.onItemShiftTab();
137
+ return;
138
+ }
139
+ if (event.target !== event.currentTarget) return;
140
+ const focusIntent = getFocusIntent(event, context.orientation, context.dir);
141
+ if (focusIntent !== void 0) {
142
+ event.preventDefault();
143
+ let candidateNodes = getItems().filter((item) => item.focusable).map((item) => item.ref.current);
144
+ if (focusIntent === "last") candidateNodes.reverse();
145
+ else if (focusIntent === "prev" || focusIntent === "next") {
146
+ focusIntent === "prev" && candidateNodes.reverse();
147
+ const currentIndex = candidateNodes.indexOf(event.currentTarget);
148
+ candidateNodes = context.loop ? wrapArray(candidateNodes, currentIndex + 1) : candidateNodes.slice(currentIndex + 1);
149
+ }
150
+ setTimeout(() => focusFirst(candidateNodes));
151
+ }
152
+ }
153
+ )
154
+ }
155
+ }
156
+ )
157
+ }
158
+ );
159
+ });
160
+ RovingFocusGroupItem.displayName = ITEM_NAME;
161
+ const GROUP_NAME = "RovingFocusGroup", [Collection, useCollection] = (0, import_collection.createCollection)(
162
+ GROUP_NAME
163
+ ), { Provider: RovingFocusProvider, useStyledContext: useRovingFocusContext } = (0, import_core.createStyledContext)(), ROVING_FOCUS_GROUP_CONTEXT = "RovingFocusGroupContext", RovingFocusGroup = (0, import_helpers.withStaticProperties)(
164
+ React.forwardRef(
165
+ (props, forwardedRef) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
166
+ Collection.Provider,
167
+ {
168
+ __scopeCollection: props.__scopeRovingFocusGroup || ROVING_FOCUS_GROUP_CONTEXT,
169
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
170
+ Collection.Slot,
171
+ {
172
+ __scopeCollection: props.__scopeRovingFocusGroup || ROVING_FOCUS_GROUP_CONTEXT,
173
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RovingFocusGroupImpl, { ...props, ref: forwardedRef })
174
+ }
175
+ )
176
+ }
177
+ )
178
+ ),
179
+ {
180
+ Item: RovingFocusGroupItem
181
+ }
182
+ );
183
+ RovingFocusGroup.displayName = GROUP_NAME;
184
+ const MAP_KEY_TO_FOCUS_INTENT = {
185
+ ArrowLeft: "prev",
186
+ ArrowUp: "prev",
187
+ ArrowRight: "next",
188
+ ArrowDown: "next",
189
+ PageUp: "first",
190
+ Home: "first",
191
+ PageDown: "last",
192
+ End: "last"
193
+ };
194
+ function getDirectionAwareKey(key, dir) {
195
+ return dir !== "rtl" ? key : key === "ArrowLeft" ? "ArrowRight" : key === "ArrowRight" ? "ArrowLeft" : key;
196
+ }
197
+ function getFocusIntent(event, orientation, dir) {
198
+ const key = getDirectionAwareKey(event.key, dir);
199
+ if (!(orientation === "vertical" && ["ArrowLeft", "ArrowRight"].includes(key)) && !(orientation === "horizontal" && ["ArrowUp", "ArrowDown"].includes(key)))
200
+ return MAP_KEY_TO_FOCUS_INTENT[key];
201
+ }
202
+ function focusFirst(candidates) {
203
+ const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
204
+ for (const candidate of candidates)
205
+ if (candidate === PREVIOUSLY_FOCUSED_ELEMENT || (candidate.focus(), document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT)) return;
206
+ }
207
+ function wrapArray(array, startIndex) {
208
+ return array.map((_, index) => array[(startIndex + index) % array.length]);
209
+ }
210
+ //# sourceMappingURL=RovingFocusGroup.js.map
@@ -0,0 +1,15 @@
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 src_exports = {};
13
+ module.exports = __toCommonJS(src_exports);
14
+ __reExport(src_exports, require("./RovingFocusGroup"), module.exports);
15
+ //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/roving-focus",
3
- "version": "1.116.1",
3
+ "version": "1.116.3",
4
4
  "sideEffects": [
5
5
  "*.css"
6
6
  ],
@@ -34,18 +34,18 @@
34
34
  }
35
35
  },
36
36
  "dependencies": {
37
- "@tamagui/collection": "1.116.1",
38
- "@tamagui/compose-refs": "1.116.1",
39
- "@tamagui/constants": "1.116.1",
40
- "@tamagui/core": "1.116.1",
41
- "@tamagui/create-context": "1.116.1",
42
- "@tamagui/helpers": "1.116.1",
43
- "@tamagui/use-controllable-state": "1.116.1",
44
- "@tamagui/use-direction": "1.116.1",
45
- "@tamagui/use-event": "1.116.1"
37
+ "@tamagui/collection": "1.116.3",
38
+ "@tamagui/compose-refs": "1.116.3",
39
+ "@tamagui/constants": "1.116.3",
40
+ "@tamagui/core": "1.116.3",
41
+ "@tamagui/create-context": "1.116.3",
42
+ "@tamagui/helpers": "1.116.3",
43
+ "@tamagui/use-controllable-state": "1.116.3",
44
+ "@tamagui/use-direction": "1.116.3",
45
+ "@tamagui/use-event": "1.116.3"
46
46
  },
47
47
  "devDependencies": {
48
- "@tamagui/build": "1.116.1",
48
+ "@tamagui/build": "1.116.3",
49
49
  "react": "^18.2.0 || ^19.0.0"
50
50
  },
51
51
  "publishConfig": {
@@ -1,62 +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,
6
- __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
15
- get: () => from[key],
16
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
- });
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
- value: mod,
27
- enumerable: !0
28
- }) : target, mod)),
29
- __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
30
- value: !0
31
- }), mod);
32
- var RovingFocusGroup_native_exports = {};
33
- __export(RovingFocusGroup_native_exports, {
34
- RovingFocusGroup: () => RovingFocusGroup,
35
- createRovingFocusGroupScope: () => createRovingFocusGroupScope
36
- });
37
- module.exports = __toCommonJS(RovingFocusGroup_native_exports);
38
- var import_core = require("@tamagui/core"),
39
- import_helpers = require("@tamagui/helpers"),
40
- import_react = __toESM(require("react")),
41
- import_jsx_runtime = require("react/jsx-runtime");
42
- const ITEM_NAME = "RovingFocusGroupItem",
43
- RovingFocusGroupItem = import_react.default.forwardRef(({
44
- children,
45
- ...props
46
- }, _ref) => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Stack, {
47
- ...props,
48
- children
49
- }));
50
- RovingFocusGroupItem.displayName = ITEM_NAME;
51
- const GROUP_NAME = "RovingFocusGroup",
52
- RovingFocusGroup = (0, import_helpers.withStaticProperties)(import_react.default.forwardRef(({
53
- children,
54
- ...props
55
- }, _ref) => /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Stack, {
56
- ...props,
57
- children
58
- })), {
59
- Item: RovingFocusGroupItem
60
- });
61
- RovingFocusGroup.displayName = GROUP_NAME;
62
- const createRovingFocusGroupScope = () => () => ({});
@@ -1,6 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/RovingFocusGroup.native.tsx"],
4
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAsB,0BACtB,iBAAqC,6BACrC,eAAkB,2BASd;AAHJ,MAAM,YAAY,wBACZ,uBAAuB,aAAAA,QAAM;AAAA,EACjC,CAAC,EAAE,UAAU,GAAG,MAAM,GAAyB,SAC7C,4CAAC,qBAAO,GAAG,OAAQ,UAAS;AAEhC;AACA,qBAAqB,cAAc;AACnC,MAAM,aAAa,oBAEb,uBAAmB;AAAA,EACvB,aAAAA,QAAM,WAAW,CAAC,EAAE,UAAU,GAAG,MAAM,GAA0B,SAC/D,4CAAC,qBAAO,GAAG,OAAQ,UAAS,CAC7B;AAAA,EACD;AAAA,IACE,MAAM;AAAA,EACR;AACF;AAEA,iBAAiB,cAAc;AAE/B,MAAM,8BAA8B,MAAM,OAAO,CAAC;",
5
- "names": ["React"]
6
- }
File without changes