giggles 0.3.8 → 0.3.9

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.
@@ -119,7 +119,13 @@ var FocusProvider = ({ children }) => {
119
119
  const nodes = nodesRef.current;
120
120
  const parent = nodes.get(parentId);
121
121
  if (parent && parent.childrenIds.length > 0) {
122
- focusNode(parent.childrenIds[0]);
122
+ let target = parent.childrenIds[0];
123
+ let targetNode = nodes.get(target);
124
+ while (targetNode && targetNode.childrenIds.length > 0) {
125
+ target = targetNode.childrenIds[0];
126
+ targetNode = nodes.get(target);
127
+ }
128
+ focusNode(target);
123
129
  } else {
124
130
  pendingFocusFirstChildRef.current.add(parentId);
125
131
  }
@@ -196,16 +202,34 @@ var FocusProvider = ({ children }) => {
196
202
  return pathArray;
197
203
  }, [focusedId]);
198
204
  const navigateSibling = useCallback2(
199
- (direction, wrap = true) => {
200
- const currentId = focusedId;
201
- if (!currentId) return;
205
+ (direction, wrap = true, groupId) => {
206
+ if (!focusedId) return;
202
207
  const nodes = nodesRef.current;
203
- const currentNode = nodes.get(currentId);
204
- if (!(currentNode == null ? void 0 : currentNode.parentId)) return;
205
- const parent = nodes.get(currentNode.parentId);
206
- if (!parent || parent.childrenIds.length === 0) return;
207
- const siblings = parent.childrenIds;
208
- const currentIndex = siblings.indexOf(currentId);
208
+ let currentChildId;
209
+ let siblings;
210
+ if (groupId) {
211
+ const group = nodes.get(groupId);
212
+ if (!group || group.childrenIds.length === 0) return;
213
+ siblings = group.childrenIds;
214
+ let cursor = focusedId;
215
+ while (cursor) {
216
+ const node = nodes.get(cursor);
217
+ if ((node == null ? void 0 : node.parentId) === groupId) {
218
+ currentChildId = cursor;
219
+ break;
220
+ }
221
+ cursor = (node == null ? void 0 : node.parentId) ?? null;
222
+ }
223
+ if (!currentChildId) return;
224
+ } else {
225
+ const currentNode = nodes.get(focusedId);
226
+ if (!(currentNode == null ? void 0 : currentNode.parentId)) return;
227
+ const parent = nodes.get(currentNode.parentId);
228
+ if (!parent || parent.childrenIds.length === 0) return;
229
+ siblings = parent.childrenIds;
230
+ currentChildId = focusedId;
231
+ }
232
+ const currentIndex = siblings.indexOf(currentChildId);
209
233
  if (currentIndex === -1) return;
210
234
  let nextIndex;
211
235
  if (wrap) {
@@ -213,9 +237,15 @@ var FocusProvider = ({ children }) => {
213
237
  } else {
214
238
  nextIndex = direction === "next" ? Math.min(currentIndex + 1, siblings.length - 1) : Math.max(currentIndex - 1, 0);
215
239
  }
216
- focusNode(siblings[nextIndex]);
240
+ const targetId = siblings[nextIndex];
241
+ const target = nodes.get(targetId);
242
+ if (target && target.childrenIds.length > 0) {
243
+ focusFirstChild(targetId);
244
+ } else {
245
+ focusNode(targetId);
246
+ }
217
247
  },
218
- [focusedId, focusNode]
248
+ [focusedId, focusNode, focusFirstChild]
219
249
  );
220
250
  return /* @__PURE__ */ jsx2(
221
251
  FocusContext.Provider,
@@ -311,18 +341,18 @@ function InputRouter({ children }) {
311
341
  if (!keyName) return;
312
342
  for (const nodeId of path) {
313
343
  const nodeBindings = getNodeBindings(nodeId);
314
- if (!nodeBindings) continue;
315
- const entry = nodeBindings.bindings.get(keyName);
316
- if (entry && entry.when !== "mounted") {
317
- entry.handler(input, key);
318
- return;
319
- }
320
- if (nodeBindings.capture && nodeBindings.onKeypress) {
321
- if ((_a = nodeBindings.passthrough) == null ? void 0 : _a.has(keyName)) {
322
- continue;
344
+ if (nodeBindings) {
345
+ const entry = nodeBindings.bindings.get(keyName);
346
+ if (entry && entry.when !== "mounted") {
347
+ entry.handler(input, key);
348
+ return;
349
+ }
350
+ if (nodeBindings.capture && nodeBindings.onKeypress) {
351
+ if (!((_a = nodeBindings.passthrough) == null ? void 0 : _a.has(keyName))) {
352
+ nodeBindings.onKeypress(input, key);
353
+ return;
354
+ }
323
355
  }
324
- nodeBindings.onKeypress(input, key);
325
- return;
326
356
  }
327
357
  if (nodeId === trapNodeId) {
328
358
  return;
@@ -401,8 +431,8 @@ function FocusGroup({
401
431
  const bindContextValue = useMemo(() => value ? { register, unregister } : null, [value, register, unregister]);
402
432
  const navigationKeys = useMemo(() => {
403
433
  if (!navigable) return {};
404
- const next = () => navigateSibling("next", wrap);
405
- const prev = () => navigateSibling("prev", wrap);
434
+ const next = () => navigateSibling("next", wrap, focus.id);
435
+ const prev = () => navigateSibling("prev", wrap, focus.id);
406
436
  const base = direction === "vertical" ? {
407
437
  j: next,
408
438
  k: prev,
@@ -415,7 +445,7 @@ function FocusGroup({
415
445
  left: prev
416
446
  };
417
447
  return { ...base, tab: next, "shift+tab": prev };
418
- }, [navigable, direction, wrap, navigateSibling]);
448
+ }, [navigable, direction, wrap, navigateSibling, focus.id]);
419
449
  const mergedBindings = useMemo(
420
450
  () => ({ ...navigationKeys, ...customBindings }),
421
451
  [navigationKeys, customBindings]
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  useFocusState,
15
15
  useKeybindingRegistry,
16
16
  useKeybindings
17
- } from "./chunk-OYQZHF73.js";
17
+ } from "./chunk-CKA5JJ4B.js";
18
18
  import {
19
19
  ThemeProvider,
20
20
  useTheme
package/dist/ui/index.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  useFocus,
5
5
  useKeybindingRegistry,
6
6
  useKeybindings
7
- } from "../chunk-OYQZHF73.js";
7
+ } from "../chunk-CKA5JJ4B.js";
8
8
  import {
9
9
  CodeBlock
10
10
  } from "../chunk-TFYBLNEZ.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "giggles",
3
- "version": "0.3.8",
3
+ "version": "0.3.9",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",