@tamagui/roving-focus 1.114.4 → 1.115.1
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/dist/cjs/RovingFocusGroup.cjs +219 -0
- package/dist/cjs/RovingFocusGroup.native.cjs +62 -0
- package/dist/cjs/RovingFocusGroup.native.cjs.map +6 -0
- package/dist/cjs/index.cjs +18 -0
- package/package.json +13 -12
- package/dist/cjs/RovingFocusGroup.js +0 -210
- package/dist/cjs/index.js +0 -15
- /package/dist/cjs/{RovingFocusGroup.js.map → RovingFocusGroup.cjs.map} +0 -0
- /package/dist/cjs/{index.js.map → index.cjs.map} +0 -0
|
@@ -0,0 +1,219 @@
|
|
|
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_exports = {};
|
|
33
|
+
__export(RovingFocusGroup_exports, {
|
|
34
|
+
RovingFocusGroup: () => RovingFocusGroup
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(RovingFocusGroup_exports);
|
|
37
|
+
var import_collection = require("@tamagui/collection"),
|
|
38
|
+
import_compose_refs = require("@tamagui/compose-refs"),
|
|
39
|
+
import_constants = require("@tamagui/constants"),
|
|
40
|
+
import_core = require("@tamagui/core"),
|
|
41
|
+
import_helpers = require("@tamagui/helpers"),
|
|
42
|
+
import_use_controllable_state = require("@tamagui/use-controllable-state"),
|
|
43
|
+
import_use_direction = require("@tamagui/use-direction"),
|
|
44
|
+
React = __toESM(require("react")),
|
|
45
|
+
import_jsx_runtime = require("react/jsx-runtime");
|
|
46
|
+
const ENTRY_FOCUS = "rovingFocusGroup.onEntryFocus",
|
|
47
|
+
EVENT_OPTIONS = {
|
|
48
|
+
bubbles: !1,
|
|
49
|
+
cancelable: !0
|
|
50
|
+
},
|
|
51
|
+
RovingFocusGroupImpl = React.forwardRef((props, forwardedRef) => {
|
|
52
|
+
const {
|
|
53
|
+
__scopeRovingFocusGroup,
|
|
54
|
+
orientation,
|
|
55
|
+
loop = !1,
|
|
56
|
+
dir,
|
|
57
|
+
currentTabStopId: currentTabStopIdProp,
|
|
58
|
+
defaultCurrentTabStopId,
|
|
59
|
+
onCurrentTabStopIdChange,
|
|
60
|
+
onEntryFocus,
|
|
61
|
+
...groupProps
|
|
62
|
+
} = props,
|
|
63
|
+
ref = React.useRef(null),
|
|
64
|
+
composedRefs = (0, import_compose_refs.useComposedRefs)(forwardedRef, ref),
|
|
65
|
+
direction = (0, import_use_direction.useDirection)(dir),
|
|
66
|
+
[currentTabStopId = null, setCurrentTabStopId] = (0, import_use_controllable_state.useControllableState)({
|
|
67
|
+
prop: currentTabStopIdProp,
|
|
68
|
+
defaultProp: defaultCurrentTabStopId ?? null,
|
|
69
|
+
onChange: onCurrentTabStopIdChange
|
|
70
|
+
}),
|
|
71
|
+
[isTabbingBackOut, setIsTabbingBackOut] = React.useState(!1),
|
|
72
|
+
handleEntryFocus = (0, import_core.useEvent)(onEntryFocus),
|
|
73
|
+
getItems = useCollection(__scopeRovingFocusGroup || ROVING_FOCUS_GROUP_CONTEXT),
|
|
74
|
+
isClickFocusRef = React.useRef(!1),
|
|
75
|
+
[focusableItemsCount, setFocusableItemsCount] = React.useState(0);
|
|
76
|
+
return React.useEffect(() => {
|
|
77
|
+
const node = ref.current;
|
|
78
|
+
if (node) return node.addEventListener(ENTRY_FOCUS, handleEntryFocus), () => node.removeEventListener(ENTRY_FOCUS, handleEntryFocus);
|
|
79
|
+
}, [handleEntryFocus]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(RovingFocusProvider, {
|
|
80
|
+
scope: __scopeRovingFocusGroup,
|
|
81
|
+
orientation,
|
|
82
|
+
dir: direction,
|
|
83
|
+
loop,
|
|
84
|
+
currentTabStopId,
|
|
85
|
+
onItemFocus: React.useCallback(tabStopId => setCurrentTabStopId(tabStopId), [setCurrentTabStopId]),
|
|
86
|
+
onItemShiftTab: React.useCallback(() => setIsTabbingBackOut(!0), []),
|
|
87
|
+
onFocusableItemAdd: React.useCallback(() => setFocusableItemsCount(prevCount => prevCount + 1), []),
|
|
88
|
+
onFocusableItemRemove: React.useCallback(() => setFocusableItemsCount(prevCount => prevCount - 1), []),
|
|
89
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Stack, {
|
|
90
|
+
tabIndex: isTabbingBackOut || focusableItemsCount === 0 ? -1 : 0,
|
|
91
|
+
"data-orientation": orientation,
|
|
92
|
+
...groupProps,
|
|
93
|
+
ref: composedRefs,
|
|
94
|
+
style: [{
|
|
95
|
+
outline: "none"
|
|
96
|
+
}, props.style],
|
|
97
|
+
onMouseDown: (0, import_helpers.composeEventHandlers)(props.onMouseDown, () => {
|
|
98
|
+
isClickFocusRef.current = !0;
|
|
99
|
+
}),
|
|
100
|
+
onFocus: (0, import_helpers.composeEventHandlers)(props.onFocus, event => {
|
|
101
|
+
const isKeyboardFocus = !isClickFocusRef.current;
|
|
102
|
+
if (event.target === event.currentTarget && isKeyboardFocus && !isTabbingBackOut) {
|
|
103
|
+
const entryFocusEvent = new CustomEvent(ENTRY_FOCUS, EVENT_OPTIONS);
|
|
104
|
+
if (event.currentTarget.dispatchEvent(entryFocusEvent), !entryFocusEvent.defaultPrevented) {
|
|
105
|
+
const items = getItems().filter(item => item.focusable),
|
|
106
|
+
activeItem = items.find(item => item.active),
|
|
107
|
+
currentItem = items.find(item => item.id === currentTabStopId),
|
|
108
|
+
candidateNodes = [activeItem, currentItem, ...items].filter(Boolean).map(item => item.ref.current);
|
|
109
|
+
focusFirst(candidateNodes);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
isClickFocusRef.current = !1;
|
|
113
|
+
}),
|
|
114
|
+
onBlur: (0, import_helpers.composeEventHandlers)(props.onBlur, () => setIsTabbingBackOut(!1))
|
|
115
|
+
})
|
|
116
|
+
});
|
|
117
|
+
}),
|
|
118
|
+
ITEM_NAME = "RovingFocusGroupItem",
|
|
119
|
+
RovingFocusGroupItem = React.forwardRef((props, forwardedRef) => {
|
|
120
|
+
const {
|
|
121
|
+
__scopeRovingFocusGroup,
|
|
122
|
+
focusable = !0,
|
|
123
|
+
active = !1,
|
|
124
|
+
tabStopId,
|
|
125
|
+
...itemProps
|
|
126
|
+
} = props,
|
|
127
|
+
autoId = React.useId(),
|
|
128
|
+
id = tabStopId || autoId,
|
|
129
|
+
context = useRovingFocusContext(__scopeRovingFocusGroup),
|
|
130
|
+
isCurrentTabStop = context.currentTabStopId === id,
|
|
131
|
+
getItems = useCollection(__scopeRovingFocusGroup || ROVING_FOCUS_GROUP_CONTEXT),
|
|
132
|
+
{
|
|
133
|
+
onFocusableItemAdd,
|
|
134
|
+
onFocusableItemRemove
|
|
135
|
+
} = context;
|
|
136
|
+
return React.useEffect(() => {
|
|
137
|
+
if (focusable) return onFocusableItemAdd(), () => onFocusableItemRemove();
|
|
138
|
+
}, [focusable, onFocusableItemAdd, onFocusableItemRemove]), /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.ItemSlot, {
|
|
139
|
+
__scopeCollection: __scopeRovingFocusGroup || ROVING_FOCUS_GROUP_CONTEXT,
|
|
140
|
+
id,
|
|
141
|
+
focusable,
|
|
142
|
+
active,
|
|
143
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_core.Stack, {
|
|
144
|
+
tabIndex: isCurrentTabStop ? 0 : -1,
|
|
145
|
+
"data-orientation": context.orientation,
|
|
146
|
+
...itemProps,
|
|
147
|
+
ref: forwardedRef,
|
|
148
|
+
onMouseDown: (0, import_helpers.composeEventHandlers)(props.onMouseDown, event => {
|
|
149
|
+
focusable ? context.onItemFocus(id) : event.preventDefault();
|
|
150
|
+
}),
|
|
151
|
+
onFocus: (0, import_helpers.composeEventHandlers)(props.onFocus, () => context.onItemFocus(id)),
|
|
152
|
+
...(import_constants.isWeb && {
|
|
153
|
+
onKeyDown: (0, import_helpers.composeEventHandlers)(props.onKeyDown, event => {
|
|
154
|
+
if (event.key === "Tab" && event.shiftKey) {
|
|
155
|
+
context.onItemShiftTab();
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (event.target !== event.currentTarget) return;
|
|
159
|
+
const focusIntent = getFocusIntent(event, context.orientation, context.dir);
|
|
160
|
+
if (focusIntent !== void 0) {
|
|
161
|
+
event.preventDefault();
|
|
162
|
+
let candidateNodes = getItems().filter(item => item.focusable).map(item => item.ref.current);
|
|
163
|
+
if (focusIntent === "last") candidateNodes.reverse();else if (focusIntent === "prev" || focusIntent === "next") {
|
|
164
|
+
focusIntent === "prev" && candidateNodes.reverse();
|
|
165
|
+
const currentIndex = candidateNodes.indexOf(event.currentTarget);
|
|
166
|
+
candidateNodes = context.loop ? wrapArray(candidateNodes, currentIndex + 1) : candidateNodes.slice(currentIndex + 1);
|
|
167
|
+
}
|
|
168
|
+
setTimeout(() => focusFirst(candidateNodes));
|
|
169
|
+
}
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
})
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
RovingFocusGroupItem.displayName = ITEM_NAME;
|
|
176
|
+
const GROUP_NAME = "RovingFocusGroup",
|
|
177
|
+
[Collection, useCollection] = (0, import_collection.createCollection)(GROUP_NAME),
|
|
178
|
+
{
|
|
179
|
+
Provider: RovingFocusProvider,
|
|
180
|
+
useStyledContext: useRovingFocusContext
|
|
181
|
+
} = (0, import_core.createStyledContext)(),
|
|
182
|
+
ROVING_FOCUS_GROUP_CONTEXT = "RovingFocusGroupContext",
|
|
183
|
+
RovingFocusGroup = (0, import_helpers.withStaticProperties)(React.forwardRef((props, forwardedRef) => /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.Provider, {
|
|
184
|
+
__scopeCollection: props.__scopeRovingFocusGroup || ROVING_FOCUS_GROUP_CONTEXT,
|
|
185
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Collection.Slot, {
|
|
186
|
+
__scopeCollection: props.__scopeRovingFocusGroup || ROVING_FOCUS_GROUP_CONTEXT,
|
|
187
|
+
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(RovingFocusGroupImpl, {
|
|
188
|
+
...props,
|
|
189
|
+
ref: forwardedRef
|
|
190
|
+
})
|
|
191
|
+
})
|
|
192
|
+
})), {
|
|
193
|
+
Item: RovingFocusGroupItem
|
|
194
|
+
});
|
|
195
|
+
RovingFocusGroup.displayName = GROUP_NAME;
|
|
196
|
+
const MAP_KEY_TO_FOCUS_INTENT = {
|
|
197
|
+
ArrowLeft: "prev",
|
|
198
|
+
ArrowUp: "prev",
|
|
199
|
+
ArrowRight: "next",
|
|
200
|
+
ArrowDown: "next",
|
|
201
|
+
PageUp: "first",
|
|
202
|
+
Home: "first",
|
|
203
|
+
PageDown: "last",
|
|
204
|
+
End: "last"
|
|
205
|
+
};
|
|
206
|
+
function getDirectionAwareKey(key, dir) {
|
|
207
|
+
return dir !== "rtl" ? key : key === "ArrowLeft" ? "ArrowRight" : key === "ArrowRight" ? "ArrowLeft" : key;
|
|
208
|
+
}
|
|
209
|
+
function getFocusIntent(event, orientation, dir) {
|
|
210
|
+
const key = getDirectionAwareKey(event.key, dir);
|
|
211
|
+
if (!(orientation === "vertical" && ["ArrowLeft", "ArrowRight"].includes(key)) && !(orientation === "horizontal" && ["ArrowUp", "ArrowDown"].includes(key))) return MAP_KEY_TO_FOCUS_INTENT[key];
|
|
212
|
+
}
|
|
213
|
+
function focusFirst(candidates) {
|
|
214
|
+
const PREVIOUSLY_FOCUSED_ELEMENT = document.activeElement;
|
|
215
|
+
for (const candidate of candidates) if (candidate === PREVIOUSLY_FOCUSED_ELEMENT || (candidate.focus(), document.activeElement !== PREVIOUSLY_FOCUSED_ELEMENT)) return;
|
|
216
|
+
}
|
|
217
|
+
function wrapArray(array, startIndex) {
|
|
218
|
+
return array.map((_, index) => array[(startIndex + index) % array.length]);
|
|
219
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
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 = () => () => ({});
|
|
@@ -0,0 +1,6 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
7
|
+
get: () => from[key],
|
|
8
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
9
|
+
});
|
|
10
|
+
return to;
|
|
11
|
+
},
|
|
12
|
+
__reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
13
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
14
|
+
value: !0
|
|
15
|
+
}), mod);
|
|
16
|
+
var src_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(src_exports);
|
|
18
|
+
__reExport(src_exports, require("./RovingFocusGroup.cjs"), module.exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamagui/roving-focus",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.115.1",
|
|
4
4
|
"sideEffects": [
|
|
5
5
|
"*.css"
|
|
6
6
|
],
|
|
@@ -29,22 +29,23 @@
|
|
|
29
29
|
"react-native": "./dist/cjs/index.native.js",
|
|
30
30
|
"types": "./types/index.d.ts",
|
|
31
31
|
"import": "./dist/esm/index.mjs",
|
|
32
|
-
"require": "./dist/cjs/index.
|
|
32
|
+
"require": "./dist/cjs/index.cjs",
|
|
33
|
+
"default": "./dist/cjs/index.native.js"
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
|
-
"@tamagui/collection": "1.
|
|
37
|
-
"@tamagui/compose-refs": "1.
|
|
38
|
-
"@tamagui/constants": "1.
|
|
39
|
-
"@tamagui/core": "1.
|
|
40
|
-
"@tamagui/create-context": "1.
|
|
41
|
-
"@tamagui/helpers": "1.
|
|
42
|
-
"@tamagui/use-controllable-state": "1.
|
|
43
|
-
"@tamagui/use-direction": "1.
|
|
44
|
-
"@tamagui/use-event": "1.
|
|
37
|
+
"@tamagui/collection": "1.115.1",
|
|
38
|
+
"@tamagui/compose-refs": "1.115.1",
|
|
39
|
+
"@tamagui/constants": "1.115.1",
|
|
40
|
+
"@tamagui/core": "1.115.1",
|
|
41
|
+
"@tamagui/create-context": "1.115.1",
|
|
42
|
+
"@tamagui/helpers": "1.115.1",
|
|
43
|
+
"@tamagui/use-controllable-state": "1.115.1",
|
|
44
|
+
"@tamagui/use-direction": "1.115.1",
|
|
45
|
+
"@tamagui/use-event": "1.115.1"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
|
-
"@tamagui/build": "1.
|
|
48
|
+
"@tamagui/build": "1.115.1",
|
|
48
49
|
"react": "^18.2.0 || ^19.0.0"
|
|
49
50
|
},
|
|
50
51
|
"publishConfig": {
|
|
@@ -1,210 +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 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
|
package/dist/cjs/index.js
DELETED
|
@@ -1,15 +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 src_exports = {};
|
|
13
|
-
module.exports = __toCommonJS(src_exports);
|
|
14
|
-
__reExport(src_exports, require("./RovingFocusGroup"), module.exports);
|
|
15
|
-
//# sourceMappingURL=index.js.map
|
|
File without changes
|
|
File without changes
|