@tanstack/solid-hotkeys 0.25.3 → 0.26.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/README.md CHANGED
@@ -91,15 +91,6 @@ Type-safe keyboard shortcuts for the web. Template-string bindings, parsed objec
91
91
 
92
92
  <table align="center">
93
93
  <tr>
94
- <td>
95
- <a href="https://www.coderabbit.ai/?via=tanstack&dub_id=aCcEEdAOqqutX6OS" >
96
- <picture>
97
- <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/TanStack/tanstack.com/main/src/images/coderabbit-dark.svg" height="40" />
98
- <source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/TanStack/tanstack.com/main/src/images/coderabbit-light.svg" height="40" />
99
- <img src="https://raw.githubusercontent.com/TanStack/tanstack.com/main/src/images/coderabbit-light.svg" height="40" alt="CodeRabbit" />
100
- </picture>
101
- </a>
102
- </td>
103
94
  <td>
104
95
  <a href="https://www.cloudflare.com?utm_source=tanstack">
105
96
  <picture>
@@ -1,7 +1,7 @@
1
1
  import { CreateHotkeyCommonOptions } from "./createHotkey.js";
2
2
  import { AppHotkeys, CustomHotkeys, HotkeyPlatform } from "@tanstack/hotkeys";
3
3
  import { HotkeyRecorderDefaults, HotkeysContextValue, HotkeysProviderScopeProps } from "@tanstack/hotkeys/adapter";
4
- import { JSX, ParentComponent } from "solid-js";
4
+ import { Element, ParentComponent } from "solid-js";
5
5
  export interface HotkeysProviderOptions {
6
6
  /**
7
7
  * The user's platform, for labels from `createFormatForDisplay`, hotkeys,
@@ -26,7 +26,7 @@ export interface HotkeysProviderOptions {
26
26
  hotkeyRecorder?: HotkeyRecorderDefaults;
27
27
  }
28
28
  export interface HotkeysProviderProps extends HotkeysProviderScopeProps {
29
- children: JSX.Element;
29
+ children: Element;
30
30
  /**
31
31
  * Every app hotkey, from `defineAppHotkeys`. Listed by `createAppHotkeyList`
32
32
  * whether or not they are registered. It can start as `undefined` and arrive
@@ -1,7 +1,6 @@
1
1
  import { publishAppHotkeysStore } from "@tanstack/hotkeys";
2
- import { createComponent } from "solid-js/web";
3
2
  import { activateHotkeysProviderScope, createAppHotkeysStore, getHotkeysProviderScopeKey, mergeHotkeysProviderDefaults } from "@tanstack/hotkeys/adapter";
4
- import { createContext, createEffect, createMemo, onCleanup, untrack, useContext } from "solid-js";
3
+ import { createComponent, createContext, createEffect, createMemo, untrack, useContext } from "solid-js";
5
4
 
6
5
  // src/HotkeysProvider.tsx
7
6
  const HotkeysContext = createContext(null);
@@ -39,35 +38,29 @@ const HotkeysProvider = (props) => {
39
38
  customHotkeys: props.customHotkeys,
40
39
  onCustomHotkeysChange: (custom) => props.onCustomHotkeysChange?.(custom),
41
40
  platform: props.defaultOptions?.platform ?? parent?.defaultOptions.platform
42
- })) : null), null);
43
- createEffect(() => {
44
- if (props.appHotkeys) store()?.setAppHotkeys(props.appHotkeys);
45
- });
46
- createEffect(() => {
47
- const created = store();
48
- if (created) onCleanup(publishAppHotkeysStore(created));
41
+ })) : null));
42
+ createEffect(() => ({
43
+ store: store(),
44
+ appHotkeys: props.appHotkeys
45
+ }), ({ store, appHotkeys }) => {
46
+ if (appHotkeys) store?.setAppHotkeys(appHotkeys);
49
47
  });
48
+ createEffect(store, (created) => created ? publishAppHotkeysStore(created) : void 0);
50
49
  const active = () => (parent?.enabled ?? true) && props.enabled !== false;
51
50
  const defaultOptions = createMemo(() => mergeHotkeysProviderDefaults(parent?.defaultOptions, props.defaultOptions, props.scope));
52
- createEffect(() => {
53
- const customHotkeys = props.customHotkeys;
54
- const platform = defaultOptions().platform;
55
- store()?.setOptions({
56
- customHotkeys,
57
- platform
58
- });
59
- });
51
+ createEffect(() => ({
52
+ store: store(),
53
+ customHotkeys: props.customHotkeys,
54
+ platform: defaultOptions().platform
55
+ }), ({ store, ...options }) => store?.setOptions(options));
60
56
  const scopeKey = createMemo(() => getHotkeysProviderScopeKey({
61
57
  scope: props.scope,
62
58
  exclusive: props.exclusive,
63
59
  active: active(),
64
60
  parent: parent?.defaultOptions.hotkey?.scope
65
61
  }));
66
- createEffect(() => {
67
- const key = scopeKey();
68
- if (key) onCleanup(activateHotkeysProviderScope(key));
69
- });
70
- return createComponent(HotkeysContext.Provider, {
62
+ createEffect(scopeKey, (key) => key ? activateHotkeysProviderScope(key) : void 0);
63
+ return createComponent(HotkeysContext, {
71
64
  value: {
72
65
  get appHotkeysStore() {
73
66
  return store() ?? parent?.appHotkeysStore ?? null;
@@ -1,17 +1,25 @@
1
- import { createSignal, onCleanup } from "solid-js";
1
+ import { createMemo, createSignal, onCleanup } from "solid-js";
2
2
 
3
3
  // src/_useSelector.ts
4
4
  /**
5
5
  * Subscribes to a store until the owner is cleaned up and returns an accessor
6
6
  * for the selected value, which updates when it changes (by `===`).
7
+ *
8
+ * Works like `useSelector` from `@tanstack/solid-store`: the store state is
9
+ * held in a signal and the selection is derived from it, so each run tracks
10
+ * the signals the selector reads for the current state.
7
11
  */
8
12
  function useSelector(store, selector) {
9
- const [selected, setSelected] = createSignal(selector(store.get()));
10
- const { unsubscribe } = store.subscribe((state) => {
11
- setSelected(() => selector(state));
13
+ const [snapshot, setSnapshot] = createSignal({ value: store.get() }, { ownedWrite: true });
14
+ const selection = createMemo(() => ({ value: selector(snapshot().value) }), {
15
+ equals: (a, b) => a.value === b.value,
16
+ sync: true
17
+ });
18
+ const { unsubscribe } = store.subscribe((value) => {
19
+ setSnapshot({ value });
12
20
  });
13
21
  onCleanup(unsubscribe);
14
- return selected;
22
+ return () => selection().value;
15
23
  }
16
24
 
17
25
  export { useSelector };
@@ -2,21 +2,19 @@ import { useSelector } from "./_useSelector.js";
2
2
  import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
3
3
  import { HotkeyRecorder } from "@tanstack/hotkeys";
4
4
  import { resolveMaybeGetter, withDefaults } from "@tanstack/hotkeys/adapter";
5
- import { createEffect, onCleanup } from "solid-js";
5
+ import { createRenderEffect, onCleanup } from "solid-js";
6
6
 
7
7
  // src/createHotkeyRecorder.ts
8
8
  function createHotkeyRecorder(options) {
9
9
  const defaultOptions = useDefaultHotkeysOptionsSource();
10
10
  const resolve = () => withDefaults(defaultOptions().hotkeyRecorder, resolveMaybeGetter(options));
11
- const recorder = new HotkeyRecorder(resolve());
11
+ const recorder = new HotkeyRecorder({});
12
+ onCleanup(() => recorder.destroy());
12
13
  const isRecording = useSelector(recorder.store, (state) => state.isRecording);
13
14
  const steps = useSelector(recorder.store, (state) => state.steps);
14
15
  const recordedHotkey = useSelector(recorder.store, (state) => state.recordedHotkey);
15
- createEffect(() => {
16
- recorder.setOptions(resolve());
17
- });
18
- onCleanup(() => {
19
- recorder.destroy();
16
+ createRenderEffect(resolve, (resolved) => {
17
+ recorder.setOptions(resolved);
20
18
  });
21
19
  return {
22
20
  isRecording,
@@ -1,6 +1,7 @@
1
1
  import { useSelector } from "./_useSelector.js";
2
2
  import { getHotkeyManager } from "@tanstack/hotkeys";
3
3
  import { getHotkeyRegistrationViews } from "@tanstack/hotkeys/adapter";
4
+ import { createProjection } from "solid-js";
4
5
 
5
6
  // src/createHotkeyRegistrations.ts
6
7
  /**
@@ -21,7 +22,9 @@ import { getHotkeyRegistrationViews } from "@tanstack/hotkeys/adapter";
21
22
  * ```
22
23
  */
23
24
  function createHotkeyRegistrations() {
24
- return useSelector(getHotkeyManager().registrations, getHotkeyRegistrationViews);
25
+ const views = useSelector(getHotkeyManager().registrations, getHotkeyRegistrationViews);
26
+ const registrations = createProjection(() => views(), [], { key: "id" });
27
+ return () => registrations;
25
28
  }
26
29
 
27
30
  export { createHotkeyRegistrations };
@@ -1,7 +1,6 @@
1
1
  import { useAppHotkeysStoreSource, useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
2
- import { delegateEvents } from "solid-js/web";
3
2
  import { createHotkeyBindings, prepareHotkeyDefinitions, resolveMaybeGetter } from "@tanstack/hotkeys/adapter";
4
- import { createEffect, onCleanup, untrack } from "solid-js";
3
+ import { createEffect, onCleanup } from "solid-js";
5
4
 
6
5
  // src/createHotkeys.ts
7
6
  /**
@@ -29,15 +28,13 @@ function createHotkeys(hotkeys, commonOptions = {}) {
29
28
  onCleanup(() => bindings.destroy());
30
29
  createEffect(() => {
31
30
  appHotkeys.state();
32
- const definitions = prepareHotkeyDefinitions(resolveMaybeGetter(hotkeys), {
31
+ return prepareHotkeyDefinitions(resolveMaybeGetter(hotkeys), {
33
32
  appHotkeysStore: appHotkeys.store,
34
33
  defaults: defaultOptions().hotkey,
35
34
  commonOptions: resolveMaybeGetter(commonOptions),
36
35
  resolveTarget: (target) => target
37
36
  });
38
- delegateEvents(["keydown", "keyup"]);
39
- untrack(() => bindings.update(definitions));
40
- });
37
+ }, (definitions) => bindings.update(definitions));
41
38
  }
42
39
 
43
40
  export { createHotkeys };
@@ -1,7 +1,7 @@
1
1
  import { useDefaultHotkeysOptionsSource } from "./defaultOptions.js";
2
2
  import { getKeyboardLayoutStore } from "@tanstack/hotkeys";
3
3
  import { followKeyboardLayout } from "@tanstack/hotkeys/adapter";
4
- import { createEffect, createMemo, createSignal, onCleanup } from "solid-js";
4
+ import { createEffect, createMemo, createSignal } from "solid-js";
5
5
 
6
6
  // src/createKeyboardLayout.ts
7
7
  /**
@@ -34,10 +34,10 @@ function createKeyboardLayout() {
34
34
  const defaultOptions = useDefaultHotkeysOptionsSource();
35
35
  const enabled = createMemo(() => defaultOptions().keyboardLayout !== false);
36
36
  const [layoutMap, setLayoutMap] = createSignal(null);
37
- createEffect(() => {
38
- if (!enabled()) return;
39
- onCleanup(followKeyboardLayout((state) => setLayoutMap(() => state)));
37
+ createEffect(enabled, (isEnabled) => {
38
+ if (!isEnabled) return;
40
39
  setLayoutMap(() => getKeyboardLayoutStore().get());
40
+ return followKeyboardLayout((state) => setLayoutMap(() => state));
41
41
  });
42
42
  return () => enabled() ? layoutMap() : null;
43
43
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/solid-hotkeys",
3
- "version": "0.25.3",
3
+ "version": "0.26.1",
4
4
  "description": "SolidJS adapter for TanStack Hotkeys",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -31,24 +31,25 @@
31
31
  },
32
32
  "sideEffects": false,
33
33
  "engines": {
34
- "node": ">=20"
34
+ "node": ">=22.12.0"
35
35
  },
36
36
  "files": [
37
37
  "dist",
38
38
  "skills"
39
39
  ],
40
40
  "dependencies": {
41
- "@tanstack/hotkeys": "0.33.1"
41
+ "@tanstack/hotkeys": "0.34.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@solidjs/testing-library": "^0.8.10",
44
+ "@solidjs/testing-library": "^1.0.0-rc.2",
45
+ "@solidjs/vite-plugin": "^3.0.1",
46
+ "@solidjs/web": "^2.0.3",
45
47
  "@tanstack/hotkeys-test-utils": "0.0.0",
46
48
  "@testing-library/jest-dom": "^7.0.1",
47
- "solid-js": "^1.9.18",
48
- "vite-plugin-solid": "^2.11.15"
49
+ "solid-js": "^2.0.3"
49
50
  },
50
51
  "peerDependencies": {
51
- "solid-js": "^1.7.0"
52
+ "solid-js": "^2.0.0"
52
53
  },
53
54
  "scripts": {
54
55
  "clean": "premove ./build ./dist",
@@ -29,6 +29,8 @@ requires:
29
29
 
30
30
  Before starting, load the `@tanstack/hotkeys#hotkeys-core` skill (`npx @tanstack/intent@latest load @tanstack/hotkeys#hotkeys-core`).
31
31
 
32
+ This adapter needs Solid 2 (`solid-js` 2 with `@solidjs/web`), so write Solid 2 code: two-function `createEffect`, `onSettled` instead of `onMount`, `<Context value>`, and lowercase attributes such as `tabindex`. Solid 1 apps use `@tanstack/solid-hotkeys@0.25`, the last release for Solid 1.
33
+
32
34
  ```tsx
33
35
  import { createHotkey } from '@tanstack/solid-hotkeys'
34
36
  import { createSignal } from 'solid-js'
@@ -48,7 +50,7 @@ export function Editor() {
48
50
  () => ({ target: panel() }),
49
51
  )
50
52
 
51
- return <div ref={setPanel} tabIndex={0} onInput={() => setIsDirty(true)} />
53
+ return <div ref={setPanel} tabindex={0} onInput={() => setIsDirty(true)} />
52
54
  }
53
55
  ```
54
56
 
@@ -81,7 +83,7 @@ The state these return is accessors, including the recorder's fields. No provide
81
83
 
82
84
  - **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
85
  - **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
- - **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.
86
+ - **Give removable elements their own component.** For an element inside `<Show>` or `<For>`, call `createHotkey` with a signal `target` in a component that renders the element, so the hotkey unregisters when Solid removes the component. Don't call `createHotkey` in a `ref` callback: Solid 2 runs it outside the component's owner, and it throws.
85
87
  - **The callback isn't tracked.** Read props inside it, as `() => props.onClose()`, rather than passing `props.onClose` itself.
86
88
  - **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()}` ``.
87
89
  - **Call the primitives directly.** A `createShortcut(keys: string)` wrapper has to cast strings to hotkeys, which turns off type checking and drops sequences, accessor options, and app hotkeys.
@@ -21,8 +21,8 @@ declare module '@tanstack/solid-hotkeys' {
21
21
  ```tsx no-check
22
22
  import { HotkeysProvider } from '@tanstack/solid-hotkeys'
23
23
  import { appHotkeys } from './app-hotkeys'
24
+ import type { JSX } from '@solidjs/web'
24
25
  import type { CustomHotkeys } from '@tanstack/solid-hotkeys'
25
- import type { JSX } from 'solid-js'
26
26
 
27
27
  const saved: CustomHotkeys = JSON.parse(localStorage.getItem('hotkeys') ?? '{}')
28
28