@tanstack/solid-hotkeys 0.21.2 → 0.22.0

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,9 +1,9 @@
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
3
  /**
4
- * The element to listen on. A `null` target skips registration, so pass an
5
- * accessor such as `() => ({ target: element() })` for elements that attach
6
- * after mount.
4
+ * The element to listen on. A `null` or `undefined` target skips
5
+ * registration, so pass an accessor such as `() => ({ target: element() })`
6
+ * for elements that attach after mount. Omit `target` for the document.
7
7
  */
8
8
  export type CreateHotkeyTarget = Target | null;
9
9
  /** Options shared by chords and sequences. */
@@ -13,7 +13,7 @@ export type CreateHotkeyDefinition = AdapterHotkeyDefinition<CreateHotkeyTarget>
13
13
  * commonOptions, per-hotkey options. Each option applies only to the kinds
14
14
  * that support it. Unbound app hotkeys, empty sequences, and `undefined`,
15
15
  * `null`, or `''` hotkeys register nothing.
16
- * A `null` target skips registration until it is set.
16
+ * A `null` or `undefined` target skips registration until it is set.
17
17
  *
18
18
  * @example
19
19
  * ```tsx
@@ -12,7 +12,7 @@ import { createEffect, onCleanup, untrack } from "solid-js";
12
12
  * commonOptions, per-hotkey options. Each option applies only to the kinds
13
13
  * that support it. Unbound app hotkeys, empty sequences, and `undefined`,
14
14
  * `null`, or `''` hotkeys register nothing.
15
- * A `null` target skips registration until it is set.
15
+ * A `null` or `undefined` target skips registration until it is set.
16
16
  *
17
17
  * @example
18
18
  * ```tsx
@@ -46,8 +46,8 @@ function createKeyHold(key) {
46
46
  const tracker = getKeyStateTracker();
47
47
  const heldKeysSelector = useSelector(tracker.store, (state) => state.heldKeys);
48
48
  return createMemo(() => {
49
- const normalizedKey = (typeof key === "function" ? key() : key).toLowerCase();
50
- return heldKeysSelector().some((heldKey) => heldKey.toLowerCase() === normalizedKey);
49
+ heldKeysSelector();
50
+ return tracker.isKeyHeld(typeof key === "function" ? key() : key);
51
51
  });
52
52
  }
53
53
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-hotkeys",
3
- "version": "0.21.2",
3
+ "version": "0.22.0",
4
4
  "description": "SolidJS adapter for TanStack Hotkeys",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -38,10 +38,11 @@
38
38
  "skills"
39
39
  ],
40
40
  "dependencies": {
41
- "@tanstack/hotkeys": "0.25.1"
41
+ "@tanstack/hotkeys": "0.27.0"
42
42
  },
43
43
  "devDependencies": {
44
44
  "@solidjs/testing-library": "^0.8.10",
45
+ "@tanstack/hotkeys-test-utils": "0.0.0",
45
46
  "@testing-library/jest-dom": "^7.0.1",
46
47
  "solid-js": "^1.9.18",
47
48
  "vite-plugin-solid": "^2.11.15"
@@ -54,8 +55,9 @@
54
55
  "lint": "oxlint ./src",
55
56
  "lint:fix": "oxlint ./src --fix",
56
57
  "test:oxlint": "oxlint ./src",
57
- "test:lib": "vitest --passWithNoTests",
58
+ "test:lib": "vitest",
58
59
  "test:lib:dev": "pnpm test:lib --watch",
60
+ "test:coverage": "vitest --coverage",
59
61
  "test:types": "tsc",
60
62
  "build": "tsdown",
61
63
  "test:build": "publint --strict && node ../../scripts/verify-package.ts"
@@ -69,7 +69,7 @@ export function Editor() {
69
69
  | `createHotkeyRegistrations()` | Get an accessor listing every registered hotkey with its options, `meta`, and `status` (whether it's enabled and in an active scope). |
70
70
  | `createHotkeyScopesState()` | Get an accessor of the active scopes and the exclusive scope that owns the keyboard. |
71
71
  | `createHotkeyHint(hotkey, options?)` | Get an accessor of whether held modifiers should reveal a shortcut's hint. False unless a registration of the hotkey can fire: enabled, in an active scope, and with focus inside its element target. |
72
- | `createKeyHold(key)` | Get an accessor of whether one key is held. |
72
+ | `createKeyHold(key)` | Get an accessor of whether one key is held. Letters match in any case; other names, such as `Shift`, are case-sensitive. |
73
73
  | `createHeldKeys()` | Get an accessor of every key that's held right now. |
74
74
  | `createHeldKeyCodes()` | Get an accessor mapping each held key to its physical `event.code`. |
75
75
 
@@ -80,7 +80,7 @@ The state these return is accessors, including the recorder's fields. No provide
80
80
  ## Pitfalls
81
81
 
82
82
  - **Pass options as an accessor.** `{ enabled: isDirty() }` is read once, during setup, so the hotkey never follows the signal. Use `() => ({ enabled: isDirty() })`. The hotkey and `createHotkeys`' definitions also accept accessors.
83
- - **Keep element targets in a signal.** A `let el` variable is still `undefined` when the options are read, and an undefined target means `document`. Use `ref={setEl}` and `() => ({ target: el() })`; a `null` target waits for the element.
83
+ - **Keep element targets in a signal.** A `let el` variable is still `undefined` when the options are read, and nothing tracks it, so the hotkey waits and never registers. Use `ref={setEl}` and `() => ({ target: el() })`; a `null` or `undefined` target waits for the element.
84
84
  - **Register hotkeys for removable elements in their `ref`.** Solid never calls a `ref` with `null`, so a signal keeps an element that `<Show>` or `<For>` removed, and the hotkey stays registered on it. Use `ref={(el) => createHotkey('K', cb, { target: el })}`; the hotkey unregisters when the element is removed.
85
85
  - **The callback isn't tracked.** Read props inside it, as `() => props.onClose()`, rather than passing `props.onClose` itself.
86
86
  - **Register a dialog's hotkeys in a child of its provider.** A primitive uses the nearest `HotkeysProvider` above its component, so a dialog that renders `<HotkeysProvider scope={...} exclusive>` and creates `Escape` itself puts it in the suspended outer scope. Give each open dialog its own scope name, such as `` `dialog-${createUniqueId()}` ``.