@tanstack/octane-hotkeys 0.11.2 → 0.11.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.
@@ -1,7 +1,12 @@
1
1
  import { AppHotkey, HotkeyCallback, HotkeyCallbackContextFor, RegisterableHotkey, Target } from "@tanstack/hotkeys";
2
2
  import { AdapterAppHotkeyOptions, AdapterChordOptions, AdapterCommonOptions, AdapterHotkeyOptions, AdapterOptionsFor, AdapterSequenceOptions } from "@tanstack/hotkeys/adapter";
3
- /** The element to listen on. A `null` target skips registration until it is set. */
4
- export type UseHotkeyTarget = Target | null;
3
+ /**
4
+ * A ref object, element, document, or window to listen on. A `null` or
5
+ * `undefined` target, or a ref that is still unset, waits for the element.
6
+ */
7
+ export type UseHotkeyTarget = {
8
+ current: HTMLElement | null | undefined;
9
+ } | Target | null;
5
10
  /** Options shared by chords and sequences. */
6
11
  export type UseHotkeyOptions = AdapterHotkeyOptions<UseHotkeyTarget>;
7
12
  /** Options for a chord such as `'Mod+S'`. */
@@ -17,7 +17,7 @@ function useHotkeys(definitions, ...rest) {
17
17
  appHotkeysStore,
18
18
  defaults: context?.defaultOptions.hotkey,
19
19
  commonOptions,
20
- resolveTarget: (target) => target
20
+ resolveTarget: (target) => target && "current" in target ? target.current : target
21
21
  }));
22
22
  }, null, subSlot(slot, "update"));
23
23
  useLayoutEffect(() => () => bindings.destroy(), [], subSlot(slot, "cleanup"));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/octane-hotkeys",
3
- "version": "0.11.2",
3
+ "version": "0.11.3",
4
4
  "description": "Octane adapter for TanStack Hotkeys",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -35,7 +35,7 @@
35
35
  "skills"
36
36
  ],
37
37
  "dependencies": {
38
- "@tanstack/hotkeys": "0.25.1"
38
+ "@tanstack/hotkeys": "0.26.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@tsrx/oxc": "0.23.0",
@@ -73,7 +73,7 @@ No provider is required. Use Octane 0.12 or newer, with hooks in compiler-enable
73
73
 
74
74
  ## Pitfalls
75
75
 
76
- - **Targets are elements, not ref objects.** Keep the element in state with a callback ref, as above; a `null` target waits for the element.
76
+ - **Keep elements that mount later in state.** A ref object such as `useRef<HTMLDivElement | null>(null)` works as `target`, but the hook reads `ref.current` only after its component renders, so it misses an element that mounts later, such as one a child shows from its own state. Keep such an element in state with a callback ref, as above. A `null` or `undefined` target, or an unset ref, waits for the element.
77
77
  - **Register a dialog's hotkeys in a child of its provider.** A hook uses the nearest `HotkeysProvider` above its component, so a dialog that renders `<HotkeysProvider scope={...} exclusive>` and registers `Escape` itself puts it in the suspended outer scope. Give each open dialog its own scope name, such as `` `dialog-${useId()}` ``.
78
78
  - **Hooks are tracked by call site.** Use `useHotkeys(items.map(...))` for lists, not `useHotkey` in a loop.
79
79
  - **Custom hooks in plain `.ts` and `.js` files need the compiler.** Calls from a `.ts` or `.js` file that the compiler skips share one slot per hook in each component, even across different custom hooks, so only the last `useHotkey` call works. The compiler handles a file that imports a value from `octane` or starts with `/** @jsxImportSource octane */`. A type-only import doesn't count. `.tsrx` and `.tsx` files are fine.