@tanstack/octane-hotkeys 0.9.0 → 0.9.2

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.
@@ -9,18 +9,23 @@ function useHotkeyRecorder(options, slot) {
9
9
  const defaults = useDefaultHotkeysOptions();
10
10
  const merged = withDefaults(defaults.hotkeyRecorder, options);
11
11
  const ref = useRef(null, subSlot(slot, "recorder"));
12
- ref.current ??= new HotkeyRecorder(merged);
13
- const recorder = ref.current;
12
+ if (!ref.current) {
13
+ const recorder = new HotkeyRecorder(merged);
14
+ ref.current = [recorder, {
15
+ startRecording: () => recorder.start(),
16
+ stopRecording: () => recorder.stop(),
17
+ cancelRecording: () => recorder.cancel(),
18
+ commitRecording: () => recorder.commit()
19
+ }];
20
+ }
21
+ const [recorder, actions] = ref.current;
14
22
  useLayoutEffect(() => {
15
23
  recorder.setOptions(merged);
16
24
  }, null, subSlot(slot, "options"));
17
25
  useLayoutEffect(() => () => recorder.destroy(), [], subSlot(slot, "cleanup"));
18
26
  return {
19
27
  ...select(recorder.store, (value) => value, subSlot(slot, "state")),
20
- startRecording: () => recorder.start(),
21
- stopRecording: () => recorder.stop(),
22
- cancelRecording: () => recorder.cancel(),
23
- commitRecording: () => recorder.commit()
28
+ ...actions
24
29
  };
25
30
  }
26
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/octane-hotkeys",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
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.21.0"
38
+ "@tanstack/hotkeys": "0.22.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@tsrx/oxc": "0.20.0",
@@ -75,6 +75,7 @@ No provider is required. Use Octane 0.12 or newer, with hooks in compiler-enable
75
75
  - **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
76
  - **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()}` ``.
77
77
  - **Hooks are tracked by call site.** Use `useHotkeys(items.map(...))` for lists, not `useHotkey` in a loop.
78
+ - **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.
78
79
  - **Call the hooks directly.** A `useShortcut(keys: string)` wrapper has to cast strings to hotkeys, which turns off type checking and drops sequences, options, and app hotkeys.
79
80
 
80
81
  When declaring app hotkeys, building a cheat sheet, or letting users rebind shortcuts, load `@tanstack/hotkeys#app-hotkeys` and read [app hotkeys in Octane](references/app-hotkeys.md).