@tanstack/lit-hotkeys 0.0.1 → 0.10.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Tanner Linsley
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,70 @@
1
+ let _tanstack_hotkeys = require("@tanstack/hotkeys");
2
+
3
+ //#region src/controllers/hotkey-registrations.ts
4
+ /**
5
+ * A Lit ReactiveController that tracks all hotkey and sequence registrations.
6
+ *
7
+ * Subscribes to the singleton HotkeyManager and SequenceManager stores and
8
+ * triggers host updates whenever registrations change.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * class ShortcutPalette extends LitElement {
13
+ * private registrations = new HotkeyRegistrationsController(this)
14
+ *
15
+ * render() {
16
+ * return html`
17
+ * <ul>
18
+ * ${this.registrations.hotkeys.map(
19
+ * (reg) => html`<li>${reg.options.meta?.name ?? reg.hotkey}</li>`,
20
+ * )}
21
+ * </ul>
22
+ * `
23
+ * }
24
+ * }
25
+ * ```
26
+ */
27
+ var HotkeyRegistrationsController = class {
28
+ /** All registered hotkeys (public view, no callbacks). */
29
+ get hotkeys() {
30
+ return this._hotkeys;
31
+ }
32
+ /** All registered sequences. */
33
+ get sequences() {
34
+ return this._sequences;
35
+ }
36
+ constructor(_host) {
37
+ this._host = _host;
38
+ this._hotkeys = [];
39
+ this._sequences = [];
40
+ this._host.addController(this);
41
+ }
42
+ hostConnected() {
43
+ const hotkeyManager = (0, _tanstack_hotkeys.getHotkeyManager)();
44
+ const sequenceManager = (0, _tanstack_hotkeys.getSequenceManager)();
45
+ const hotkeysSub = hotkeyManager.registrations.subscribe(() => {
46
+ this._hotkeys = Array.from(hotkeyManager.registrations.state.values()).map(_tanstack_hotkeys.toHotkeyRegistrationView);
47
+ this._host.requestUpdate();
48
+ });
49
+ const sequencesSub = sequenceManager.registrations.subscribe(() => {
50
+ this._sequences = Array.from(sequenceManager.registrations.state.values());
51
+ this._host.requestUpdate();
52
+ });
53
+ this._unsubscribeHotkeys = () => hotkeysSub.unsubscribe();
54
+ this._unsubscribeSequences = () => sequencesSub.unsubscribe();
55
+ this._hotkeys = Array.from(hotkeyManager.registrations.state.values()).map(_tanstack_hotkeys.toHotkeyRegistrationView);
56
+ this._sequences = Array.from(sequenceManager.registrations.state.values());
57
+ }
58
+ hostDisconnected() {
59
+ this._unsubscribeHotkeys?.();
60
+ this._unsubscribeSequences?.();
61
+ this._unsubscribeHotkeys = void 0;
62
+ this._unsubscribeSequences = void 0;
63
+ this._hotkeys = [];
64
+ this._sequences = [];
65
+ }
66
+ };
67
+
68
+ //#endregion
69
+ exports.HotkeyRegistrationsController = HotkeyRegistrationsController;
70
+ //# sourceMappingURL=hotkey-registrations.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hotkey-registrations.cjs","names":["toHotkeyRegistrationView"],"sources":["../../src/controllers/hotkey-registrations.ts"],"sourcesContent":["import {\n getHotkeyManager,\n getSequenceManager,\n toHotkeyRegistrationView,\n} from '@tanstack/hotkeys'\nimport type {\n HotkeyRegistrationView,\n SequenceRegistrationView,\n} from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\n\n/**\n * A Lit ReactiveController that tracks all hotkey and sequence registrations.\n *\n * Subscribes to the singleton HotkeyManager and SequenceManager stores and\n * triggers host updates whenever registrations change.\n *\n * @example\n * ```ts\n * class ShortcutPalette extends LitElement {\n * private registrations = new HotkeyRegistrationsController(this)\n *\n * render() {\n * return html`\n * <ul>\n * ${this.registrations.hotkeys.map(\n * (reg) => html`<li>${reg.options.meta?.name ?? reg.hotkey}</li>`,\n * )}\n * </ul>\n * `\n * }\n * }\n * ```\n */\nexport class HotkeyRegistrationsController implements ReactiveController {\n private _unsubscribeHotkeys: (() => void) | undefined\n private _unsubscribeSequences: (() => void) | undefined\n private _hotkeys: Array<HotkeyRegistrationView> = []\n private _sequences: Array<SequenceRegistrationView> = []\n\n /** All registered hotkeys (public view, no callbacks). */\n public get hotkeys(): Array<HotkeyRegistrationView> {\n return this._hotkeys\n }\n\n /** All registered sequences. */\n public get sequences(): Array<SequenceRegistrationView> {\n return this._sequences\n }\n\n constructor(private _host: ReactiveControllerHost) {\n this._host.addController(this)\n }\n\n public hostConnected(): void {\n const hotkeyManager = getHotkeyManager()\n const sequenceManager = getSequenceManager()\n\n const hotkeysSub = hotkeyManager.registrations.subscribe(() => {\n this._hotkeys = Array.from(\n hotkeyManager.registrations.state.values(),\n ).map(toHotkeyRegistrationView)\n this._host.requestUpdate()\n })\n\n const sequencesSub = sequenceManager.registrations.subscribe(() => {\n this._sequences = Array.from(sequenceManager.registrations.state.values())\n this._host.requestUpdate()\n })\n\n this._unsubscribeHotkeys = () => hotkeysSub.unsubscribe()\n this._unsubscribeSequences = () => sequencesSub.unsubscribe()\n\n // Sync initial state\n this._hotkeys = Array.from(hotkeyManager.registrations.state.values()).map(\n toHotkeyRegistrationView,\n )\n this._sequences = Array.from(sequenceManager.registrations.state.values())\n }\n\n public hostDisconnected(): void {\n this._unsubscribeHotkeys?.()\n this._unsubscribeSequences?.()\n this._unsubscribeHotkeys = undefined\n this._unsubscribeSequences = undefined\n this._hotkeys = []\n this._sequences = []\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,gCAAb,MAAyE;;CAOvE,IAAW,UAAyC;AAClD,SAAO,KAAK;;;CAId,IAAW,YAA6C;AACtD,SAAO,KAAK;;CAGd,YAAY,AAAQ,OAA+B;EAA/B;kBAb8B,EAAE;oBACE,EAAE;AAatD,OAAK,MAAM,cAAc,KAAK;;CAGhC,AAAO,gBAAsB;EAC3B,MAAM,yDAAkC;EACxC,MAAM,6DAAsC;EAE5C,MAAM,aAAa,cAAc,cAAc,gBAAgB;AAC7D,QAAK,WAAW,MAAM,KACpB,cAAc,cAAc,MAAM,QAAQ,CAC3C,CAAC,IAAIA,2CAAyB;AAC/B,QAAK,MAAM,eAAe;IAC1B;EAEF,MAAM,eAAe,gBAAgB,cAAc,gBAAgB;AACjE,QAAK,aAAa,MAAM,KAAK,gBAAgB,cAAc,MAAM,QAAQ,CAAC;AAC1E,QAAK,MAAM,eAAe;IAC1B;AAEF,OAAK,4BAA4B,WAAW,aAAa;AACzD,OAAK,8BAA8B,aAAa,aAAa;AAG7D,OAAK,WAAW,MAAM,KAAK,cAAc,cAAc,MAAM,QAAQ,CAAC,CAAC,IACrEA,2CACD;AACD,OAAK,aAAa,MAAM,KAAK,gBAAgB,cAAc,MAAM,QAAQ,CAAC;;CAG5E,AAAO,mBAAyB;AAC9B,OAAK,uBAAuB;AAC5B,OAAK,yBAAyB;AAC9B,OAAK,sBAAsB;AAC3B,OAAK,wBAAwB;AAC7B,OAAK,WAAW,EAAE;AAClB,OAAK,aAAa,EAAE"}
@@ -0,0 +1,44 @@
1
+ import { HotkeyRegistrationView, SequenceRegistrationView } from "@tanstack/hotkeys";
2
+ import { ReactiveController, ReactiveControllerHost } from "lit";
3
+
4
+ //#region src/controllers/hotkey-registrations.d.ts
5
+ /**
6
+ * A Lit ReactiveController that tracks all hotkey and sequence registrations.
7
+ *
8
+ * Subscribes to the singleton HotkeyManager and SequenceManager stores and
9
+ * triggers host updates whenever registrations change.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * class ShortcutPalette extends LitElement {
14
+ * private registrations = new HotkeyRegistrationsController(this)
15
+ *
16
+ * render() {
17
+ * return html`
18
+ * <ul>
19
+ * ${this.registrations.hotkeys.map(
20
+ * (reg) => html`<li>${reg.options.meta?.name ?? reg.hotkey}</li>`,
21
+ * )}
22
+ * </ul>
23
+ * `
24
+ * }
25
+ * }
26
+ * ```
27
+ */
28
+ declare class HotkeyRegistrationsController implements ReactiveController {
29
+ private _host;
30
+ private _unsubscribeHotkeys;
31
+ private _unsubscribeSequences;
32
+ private _hotkeys;
33
+ private _sequences;
34
+ /** All registered hotkeys (public view, no callbacks). */
35
+ get hotkeys(): Array<HotkeyRegistrationView>;
36
+ /** All registered sequences. */
37
+ get sequences(): Array<SequenceRegistrationView>;
38
+ constructor(_host: ReactiveControllerHost);
39
+ hostConnected(): void;
40
+ hostDisconnected(): void;
41
+ }
42
+ //#endregion
43
+ export { HotkeyRegistrationsController };
44
+ //# sourceMappingURL=hotkey-registrations.d.cts.map
@@ -0,0 +1,44 @@
1
+ import { HotkeyRegistrationView, SequenceRegistrationView } from "@tanstack/hotkeys";
2
+ import { ReactiveController, ReactiveControllerHost } from "lit";
3
+
4
+ //#region src/controllers/hotkey-registrations.d.ts
5
+ /**
6
+ * A Lit ReactiveController that tracks all hotkey and sequence registrations.
7
+ *
8
+ * Subscribes to the singleton HotkeyManager and SequenceManager stores and
9
+ * triggers host updates whenever registrations change.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * class ShortcutPalette extends LitElement {
14
+ * private registrations = new HotkeyRegistrationsController(this)
15
+ *
16
+ * render() {
17
+ * return html`
18
+ * <ul>
19
+ * ${this.registrations.hotkeys.map(
20
+ * (reg) => html`<li>${reg.options.meta?.name ?? reg.hotkey}</li>`,
21
+ * )}
22
+ * </ul>
23
+ * `
24
+ * }
25
+ * }
26
+ * ```
27
+ */
28
+ declare class HotkeyRegistrationsController implements ReactiveController {
29
+ private _host;
30
+ private _unsubscribeHotkeys;
31
+ private _unsubscribeSequences;
32
+ private _hotkeys;
33
+ private _sequences;
34
+ /** All registered hotkeys (public view, no callbacks). */
35
+ get hotkeys(): Array<HotkeyRegistrationView>;
36
+ /** All registered sequences. */
37
+ get sequences(): Array<SequenceRegistrationView>;
38
+ constructor(_host: ReactiveControllerHost);
39
+ hostConnected(): void;
40
+ hostDisconnected(): void;
41
+ }
42
+ //#endregion
43
+ export { HotkeyRegistrationsController };
44
+ //# sourceMappingURL=hotkey-registrations.d.ts.map
@@ -0,0 +1,70 @@
1
+ import { getHotkeyManager, getSequenceManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
2
+
3
+ //#region src/controllers/hotkey-registrations.ts
4
+ /**
5
+ * A Lit ReactiveController that tracks all hotkey and sequence registrations.
6
+ *
7
+ * Subscribes to the singleton HotkeyManager and SequenceManager stores and
8
+ * triggers host updates whenever registrations change.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * class ShortcutPalette extends LitElement {
13
+ * private registrations = new HotkeyRegistrationsController(this)
14
+ *
15
+ * render() {
16
+ * return html`
17
+ * <ul>
18
+ * ${this.registrations.hotkeys.map(
19
+ * (reg) => html`<li>${reg.options.meta?.name ?? reg.hotkey}</li>`,
20
+ * )}
21
+ * </ul>
22
+ * `
23
+ * }
24
+ * }
25
+ * ```
26
+ */
27
+ var HotkeyRegistrationsController = class {
28
+ /** All registered hotkeys (public view, no callbacks). */
29
+ get hotkeys() {
30
+ return this._hotkeys;
31
+ }
32
+ /** All registered sequences. */
33
+ get sequences() {
34
+ return this._sequences;
35
+ }
36
+ constructor(_host) {
37
+ this._host = _host;
38
+ this._hotkeys = [];
39
+ this._sequences = [];
40
+ this._host.addController(this);
41
+ }
42
+ hostConnected() {
43
+ const hotkeyManager = getHotkeyManager();
44
+ const sequenceManager = getSequenceManager();
45
+ const hotkeysSub = hotkeyManager.registrations.subscribe(() => {
46
+ this._hotkeys = Array.from(hotkeyManager.registrations.state.values()).map(toHotkeyRegistrationView);
47
+ this._host.requestUpdate();
48
+ });
49
+ const sequencesSub = sequenceManager.registrations.subscribe(() => {
50
+ this._sequences = Array.from(sequenceManager.registrations.state.values());
51
+ this._host.requestUpdate();
52
+ });
53
+ this._unsubscribeHotkeys = () => hotkeysSub.unsubscribe();
54
+ this._unsubscribeSequences = () => sequencesSub.unsubscribe();
55
+ this._hotkeys = Array.from(hotkeyManager.registrations.state.values()).map(toHotkeyRegistrationView);
56
+ this._sequences = Array.from(sequenceManager.registrations.state.values());
57
+ }
58
+ hostDisconnected() {
59
+ this._unsubscribeHotkeys?.();
60
+ this._unsubscribeSequences?.();
61
+ this._unsubscribeHotkeys = void 0;
62
+ this._unsubscribeSequences = void 0;
63
+ this._hotkeys = [];
64
+ this._sequences = [];
65
+ }
66
+ };
67
+
68
+ //#endregion
69
+ export { HotkeyRegistrationsController };
70
+ //# sourceMappingURL=hotkey-registrations.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hotkey-registrations.js","names":[],"sources":["../../src/controllers/hotkey-registrations.ts"],"sourcesContent":["import {\n getHotkeyManager,\n getSequenceManager,\n toHotkeyRegistrationView,\n} from '@tanstack/hotkeys'\nimport type {\n HotkeyRegistrationView,\n SequenceRegistrationView,\n} from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\n\n/**\n * A Lit ReactiveController that tracks all hotkey and sequence registrations.\n *\n * Subscribes to the singleton HotkeyManager and SequenceManager stores and\n * triggers host updates whenever registrations change.\n *\n * @example\n * ```ts\n * class ShortcutPalette extends LitElement {\n * private registrations = new HotkeyRegistrationsController(this)\n *\n * render() {\n * return html`\n * <ul>\n * ${this.registrations.hotkeys.map(\n * (reg) => html`<li>${reg.options.meta?.name ?? reg.hotkey}</li>`,\n * )}\n * </ul>\n * `\n * }\n * }\n * ```\n */\nexport class HotkeyRegistrationsController implements ReactiveController {\n private _unsubscribeHotkeys: (() => void) | undefined\n private _unsubscribeSequences: (() => void) | undefined\n private _hotkeys: Array<HotkeyRegistrationView> = []\n private _sequences: Array<SequenceRegistrationView> = []\n\n /** All registered hotkeys (public view, no callbacks). */\n public get hotkeys(): Array<HotkeyRegistrationView> {\n return this._hotkeys\n }\n\n /** All registered sequences. */\n public get sequences(): Array<SequenceRegistrationView> {\n return this._sequences\n }\n\n constructor(private _host: ReactiveControllerHost) {\n this._host.addController(this)\n }\n\n public hostConnected(): void {\n const hotkeyManager = getHotkeyManager()\n const sequenceManager = getSequenceManager()\n\n const hotkeysSub = hotkeyManager.registrations.subscribe(() => {\n this._hotkeys = Array.from(\n hotkeyManager.registrations.state.values(),\n ).map(toHotkeyRegistrationView)\n this._host.requestUpdate()\n })\n\n const sequencesSub = sequenceManager.registrations.subscribe(() => {\n this._sequences = Array.from(sequenceManager.registrations.state.values())\n this._host.requestUpdate()\n })\n\n this._unsubscribeHotkeys = () => hotkeysSub.unsubscribe()\n this._unsubscribeSequences = () => sequencesSub.unsubscribe()\n\n // Sync initial state\n this._hotkeys = Array.from(hotkeyManager.registrations.state.values()).map(\n toHotkeyRegistrationView,\n )\n this._sequences = Array.from(sequenceManager.registrations.state.values())\n }\n\n public hostDisconnected(): void {\n this._unsubscribeHotkeys?.()\n this._unsubscribeSequences?.()\n this._unsubscribeHotkeys = undefined\n this._unsubscribeSequences = undefined\n this._hotkeys = []\n this._sequences = []\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAa,gCAAb,MAAyE;;CAOvE,IAAW,UAAyC;AAClD,SAAO,KAAK;;;CAId,IAAW,YAA6C;AACtD,SAAO,KAAK;;CAGd,YAAY,AAAQ,OAA+B;EAA/B;kBAb8B,EAAE;oBACE,EAAE;AAatD,OAAK,MAAM,cAAc,KAAK;;CAGhC,AAAO,gBAAsB;EAC3B,MAAM,gBAAgB,kBAAkB;EACxC,MAAM,kBAAkB,oBAAoB;EAE5C,MAAM,aAAa,cAAc,cAAc,gBAAgB;AAC7D,QAAK,WAAW,MAAM,KACpB,cAAc,cAAc,MAAM,QAAQ,CAC3C,CAAC,IAAI,yBAAyB;AAC/B,QAAK,MAAM,eAAe;IAC1B;EAEF,MAAM,eAAe,gBAAgB,cAAc,gBAAgB;AACjE,QAAK,aAAa,MAAM,KAAK,gBAAgB,cAAc,MAAM,QAAQ,CAAC;AAC1E,QAAK,MAAM,eAAe;IAC1B;AAEF,OAAK,4BAA4B,WAAW,aAAa;AACzD,OAAK,8BAA8B,aAAa,aAAa;AAG7D,OAAK,WAAW,MAAM,KAAK,cAAc,cAAc,MAAM,QAAQ,CAAC,CAAC,IACrE,yBACD;AACD,OAAK,aAAa,MAAM,KAAK,gBAAgB,cAAc,MAAM,QAAQ,CAAC;;CAG5E,AAAO,mBAAyB;AAC9B,OAAK,uBAAuB;AAC5B,OAAK,yBAAyB;AAC9B,OAAK,sBAAsB;AAC3B,OAAK,wBAAwB;AAC7B,OAAK,WAAW,EAAE;AAClB,OAAK,aAAa,EAAE"}
@@ -2,6 +2,7 @@ import { HeldKeyCodesController } from "./held-key-codes.cjs";
2
2
  import { HeldKeysController } from "./held-keys.cjs";
3
3
  import { HotkeyController } from "./hotkey.cjs";
4
4
  import { HotkeyRecorderController } from "./hotkey-recorder.cjs";
5
+ import { HotkeyRegistrationsController } from "./hotkey-registrations.cjs";
5
6
  import { HotkeySequenceController } from "./hotkey-sequence.cjs";
6
7
  import { HotkeySequenceRecorderController } from "./hotkey-sequence-recorder.cjs";
7
8
  import { KeyHoldController } from "./key-hold.cjs";
@@ -2,6 +2,7 @@ import { HeldKeyCodesController } from "./held-key-codes.js";
2
2
  import { HeldKeysController } from "./held-keys.js";
3
3
  import { HotkeyController } from "./hotkey.js";
4
4
  import { HotkeyRecorderController } from "./hotkey-recorder.js";
5
+ import { HotkeyRegistrationsController } from "./hotkey-registrations.js";
5
6
  import { HotkeySequenceController } from "./hotkey-sequence.js";
6
7
  import { HotkeySequenceRecorderController } from "./hotkey-sequence-recorder.js";
7
8
  import { KeyHoldController } from "./key-hold.js";
@@ -1 +1 @@
1
- {"version":3,"file":"key-hold.cjs","names":[],"sources":["../../src/controllers/key-hold.ts"],"sourcesContent":["import { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type { HeldKey, KeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * A Lit ReactiveController that tracks whether a specific key is currently held.\n *\n * Subscribes to the global KeyStateTracker and triggers host updates\n * when the held state of the specified key changes.\n *\n * @example\n * ```ts\n * class MyElement extends LitElement {\n * private shiftHold = new KeyHoldController(this, 'Shift')\n *\n * render() {\n * return html`\n * <div style=\"opacity: ${this.shiftHold.value ? 1 : 0.5}\">\n * ${this.shiftHold.value ? 'Shift is pressed!' : 'Press Shift'}\n * </div>\n * `\n * }\n * }\n * ```\n *\n * @example\n * ```ts\n * class ModifierIndicators extends LitElement {\n * private ctrl = new KeyHoldController(this, 'Control')\n * private shift = new KeyHoldController(this, 'Shift')\n * private alt = new KeyHoldController(this, 'Alt')\n *\n * render() {\n * return html`\n * <span style=\"opacity: ${this.ctrl.value ? 1 : 0.3}\">Ctrl</span>\n * <span style=\"opacity: ${this.shift.value ? 1 : 0.3}\">Shift</span>\n * <span style=\"opacity: ${this.alt.value ? 1 : 0.3}\">Alt</span>\n * `\n * }\n * }\n * ```\n */\nexport class KeyHoldController implements ReactiveController {\n /** The unsubscribe function to unsubscribe from the tracker store. */\n private _unsubscribe: (() => void) | undefined\n /** Whether the tracked key is currently held down. */\n private _value = false\n\n /** Whether the tracked key is currently held down. */\n public get value(): boolean {\n return this._value\n }\n\n /**\n * @param host - The Lit component that owns this controller.\n * @param key - The key to track (e.g. 'Shift', 'Control', 'A').\n */\n constructor(\n private _host: ReactiveControllerHost,\n private _key: HeldKey,\n ) {\n this._host.addController(this)\n }\n\n public hostConnected(): void {\n const tracker: KeyStateTracker = getKeyStateTracker()\n const normalizedKey: string = this._key.toLowerCase()\n\n const subscription = tracker.store.subscribe(() => {\n const isHeld: boolean = tracker.store.state.heldKeys.some(\n (heldKey: string) => heldKey.toLowerCase() === normalizedKey,\n )\n\n if (isHeld !== this._value) {\n this._value = isHeld\n this._host.requestUpdate()\n }\n })\n\n this._unsubscribe = () => subscription.unsubscribe()\n }\n\n public hostDisconnected(): void {\n this._unsubscribe?.()\n this._unsubscribe = undefined\n this._value = false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,oBAAb,MAA6D;;CAO3D,IAAW,QAAiB;AAC1B,SAAO,KAAK;;;;;;CAOd,YACE,AAAQ,OACR,AAAQ,MACR;EAFQ;EACA;gBAbO;AAef,OAAK,MAAM,cAAc,KAAK;;CAGhC,AAAO,gBAAsB;EAC3B,MAAM,qDAA+C;EACrD,MAAM,gBAAwB,KAAK,KAAK,aAAa;EAErD,MAAM,eAAe,QAAQ,MAAM,gBAAgB;GACjD,MAAM,SAAkB,QAAQ,MAAM,MAAM,SAAS,MAClD,YAAoB,QAAQ,aAAa,KAAK,cAChD;AAED,OAAI,WAAW,KAAK,QAAQ;AAC1B,SAAK,SAAS;AACd,SAAK,MAAM,eAAe;;IAE5B;AAEF,OAAK,qBAAqB,aAAa,aAAa;;CAGtD,AAAO,mBAAyB;AAC9B,OAAK,gBAAgB;AACrB,OAAK,eAAe;AACpB,OAAK,SAAS"}
1
+ {"version":3,"file":"key-hold.cjs","names":[],"sources":["../../src/controllers/key-hold.ts"],"sourcesContent":["import { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type { IndividualKey, KeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * A Lit ReactiveController that tracks whether a specific key is currently held.\n *\n * Subscribes to the global KeyStateTracker and triggers host updates\n * when the held state of the specified key changes.\n *\n * @example\n * ```ts\n * class MyElement extends LitElement {\n * private shiftHold = new KeyHoldController(this, 'Shift')\n *\n * render() {\n * return html`\n * <div style=\"opacity: ${this.shiftHold.value ? 1 : 0.5}\">\n * ${this.shiftHold.value ? 'Shift is pressed!' : 'Press Shift'}\n * </div>\n * `\n * }\n * }\n * ```\n *\n * @example\n * ```ts\n * class ModifierIndicators extends LitElement {\n * private ctrl = new KeyHoldController(this, 'Control')\n * private shift = new KeyHoldController(this, 'Shift')\n * private alt = new KeyHoldController(this, 'Alt')\n *\n * render() {\n * return html`\n * <span style=\"opacity: ${this.ctrl.value ? 1 : 0.3}\">Ctrl</span>\n * <span style=\"opacity: ${this.shift.value ? 1 : 0.3}\">Shift</span>\n * <span style=\"opacity: ${this.alt.value ? 1 : 0.3}\">Alt</span>\n * `\n * }\n * }\n * ```\n */\nexport class KeyHoldController implements ReactiveController {\n /** The unsubscribe function to unsubscribe from the tracker store. */\n private _unsubscribe: (() => void) | undefined\n /** Whether the tracked key is currently held down. */\n private _value = false\n\n /** Whether the tracked key is currently held down. */\n public get value(): boolean {\n return this._value\n }\n\n /**\n * @param host - The Lit component that owns this controller.\n * @param key - The key to track (e.g. 'Shift', 'Control', 'A').\n */\n constructor(\n private _host: ReactiveControllerHost,\n private _key: IndividualKey,\n ) {\n this._host.addController(this)\n }\n\n public hostConnected(): void {\n const tracker: KeyStateTracker = getKeyStateTracker()\n const normalizedKey: string = this._key.toLowerCase()\n\n const subscription = tracker.store.subscribe(() => {\n const isHeld: boolean = tracker.store.state.heldKeys.some(\n (heldKey: string) => heldKey.toLowerCase() === normalizedKey,\n )\n\n if (isHeld !== this._value) {\n this._value = isHeld\n this._host.requestUpdate()\n }\n })\n\n this._unsubscribe = () => subscription.unsubscribe()\n }\n\n public hostDisconnected(): void {\n this._unsubscribe?.()\n this._unsubscribe = undefined\n this._value = false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,oBAAb,MAA6D;;CAO3D,IAAW,QAAiB;AAC1B,SAAO,KAAK;;;;;;CAOd,YACE,AAAQ,OACR,AAAQ,MACR;EAFQ;EACA;gBAbO;AAef,OAAK,MAAM,cAAc,KAAK;;CAGhC,AAAO,gBAAsB;EAC3B,MAAM,qDAA+C;EACrD,MAAM,gBAAwB,KAAK,KAAK,aAAa;EAErD,MAAM,eAAe,QAAQ,MAAM,gBAAgB;GACjD,MAAM,SAAkB,QAAQ,MAAM,MAAM,SAAS,MAClD,YAAoB,QAAQ,aAAa,KAAK,cAChD;AAED,OAAI,WAAW,KAAK,QAAQ;AAC1B,SAAK,SAAS;AACd,SAAK,MAAM,eAAe;;IAE5B;AAEF,OAAK,qBAAqB,aAAa,aAAa;;CAGtD,AAAO,mBAAyB;AAC9B,OAAK,gBAAgB;AACrB,OAAK,eAAe;AACpB,OAAK,SAAS"}
@@ -1,4 +1,4 @@
1
- import { HeldKey } from "@tanstack/hotkeys";
1
+ import { IndividualKey } from "@tanstack/hotkeys";
2
2
  import { ReactiveController, ReactiveControllerHost } from "lit";
3
3
 
4
4
  //#region src/controllers/key-hold.d.ts
@@ -53,7 +53,7 @@ declare class KeyHoldController implements ReactiveController {
53
53
  * @param host - The Lit component that owns this controller.
54
54
  * @param key - The key to track (e.g. 'Shift', 'Control', 'A').
55
55
  */
56
- constructor(_host: ReactiveControllerHost, _key: HeldKey);
56
+ constructor(_host: ReactiveControllerHost, _key: IndividualKey);
57
57
  hostConnected(): void;
58
58
  hostDisconnected(): void;
59
59
  }
@@ -1,4 +1,4 @@
1
- import { HeldKey } from "@tanstack/hotkeys";
1
+ import { IndividualKey } from "@tanstack/hotkeys";
2
2
  import { ReactiveController, ReactiveControllerHost } from "lit";
3
3
 
4
4
  //#region src/controllers/key-hold.d.ts
@@ -53,7 +53,7 @@ declare class KeyHoldController implements ReactiveController {
53
53
  * @param host - The Lit component that owns this controller.
54
54
  * @param key - The key to track (e.g. 'Shift', 'Control', 'A').
55
55
  */
56
- constructor(_host: ReactiveControllerHost, _key: HeldKey);
56
+ constructor(_host: ReactiveControllerHost, _key: IndividualKey);
57
57
  hostConnected(): void;
58
58
  hostDisconnected(): void;
59
59
  }
@@ -1 +1 @@
1
- {"version":3,"file":"key-hold.js","names":[],"sources":["../../src/controllers/key-hold.ts"],"sourcesContent":["import { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type { HeldKey, KeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * A Lit ReactiveController that tracks whether a specific key is currently held.\n *\n * Subscribes to the global KeyStateTracker and triggers host updates\n * when the held state of the specified key changes.\n *\n * @example\n * ```ts\n * class MyElement extends LitElement {\n * private shiftHold = new KeyHoldController(this, 'Shift')\n *\n * render() {\n * return html`\n * <div style=\"opacity: ${this.shiftHold.value ? 1 : 0.5}\">\n * ${this.shiftHold.value ? 'Shift is pressed!' : 'Press Shift'}\n * </div>\n * `\n * }\n * }\n * ```\n *\n * @example\n * ```ts\n * class ModifierIndicators extends LitElement {\n * private ctrl = new KeyHoldController(this, 'Control')\n * private shift = new KeyHoldController(this, 'Shift')\n * private alt = new KeyHoldController(this, 'Alt')\n *\n * render() {\n * return html`\n * <span style=\"opacity: ${this.ctrl.value ? 1 : 0.3}\">Ctrl</span>\n * <span style=\"opacity: ${this.shift.value ? 1 : 0.3}\">Shift</span>\n * <span style=\"opacity: ${this.alt.value ? 1 : 0.3}\">Alt</span>\n * `\n * }\n * }\n * ```\n */\nexport class KeyHoldController implements ReactiveController {\n /** The unsubscribe function to unsubscribe from the tracker store. */\n private _unsubscribe: (() => void) | undefined\n /** Whether the tracked key is currently held down. */\n private _value = false\n\n /** Whether the tracked key is currently held down. */\n public get value(): boolean {\n return this._value\n }\n\n /**\n * @param host - The Lit component that owns this controller.\n * @param key - The key to track (e.g. 'Shift', 'Control', 'A').\n */\n constructor(\n private _host: ReactiveControllerHost,\n private _key: HeldKey,\n ) {\n this._host.addController(this)\n }\n\n public hostConnected(): void {\n const tracker: KeyStateTracker = getKeyStateTracker()\n const normalizedKey: string = this._key.toLowerCase()\n\n const subscription = tracker.store.subscribe(() => {\n const isHeld: boolean = tracker.store.state.heldKeys.some(\n (heldKey: string) => heldKey.toLowerCase() === normalizedKey,\n )\n\n if (isHeld !== this._value) {\n this._value = isHeld\n this._host.requestUpdate()\n }\n })\n\n this._unsubscribe = () => subscription.unsubscribe()\n }\n\n public hostDisconnected(): void {\n this._unsubscribe?.()\n this._unsubscribe = undefined\n this._value = false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,oBAAb,MAA6D;;CAO3D,IAAW,QAAiB;AAC1B,SAAO,KAAK;;;;;;CAOd,YACE,AAAQ,OACR,AAAQ,MACR;EAFQ;EACA;gBAbO;AAef,OAAK,MAAM,cAAc,KAAK;;CAGhC,AAAO,gBAAsB;EAC3B,MAAM,UAA2B,oBAAoB;EACrD,MAAM,gBAAwB,KAAK,KAAK,aAAa;EAErD,MAAM,eAAe,QAAQ,MAAM,gBAAgB;GACjD,MAAM,SAAkB,QAAQ,MAAM,MAAM,SAAS,MAClD,YAAoB,QAAQ,aAAa,KAAK,cAChD;AAED,OAAI,WAAW,KAAK,QAAQ;AAC1B,SAAK,SAAS;AACd,SAAK,MAAM,eAAe;;IAE5B;AAEF,OAAK,qBAAqB,aAAa,aAAa;;CAGtD,AAAO,mBAAyB;AAC9B,OAAK,gBAAgB;AACrB,OAAK,eAAe;AACpB,OAAK,SAAS"}
1
+ {"version":3,"file":"key-hold.js","names":[],"sources":["../../src/controllers/key-hold.ts"],"sourcesContent":["import { getKeyStateTracker } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type { IndividualKey, KeyStateTracker } from '@tanstack/hotkeys'\n\n/**\n * A Lit ReactiveController that tracks whether a specific key is currently held.\n *\n * Subscribes to the global KeyStateTracker and triggers host updates\n * when the held state of the specified key changes.\n *\n * @example\n * ```ts\n * class MyElement extends LitElement {\n * private shiftHold = new KeyHoldController(this, 'Shift')\n *\n * render() {\n * return html`\n * <div style=\"opacity: ${this.shiftHold.value ? 1 : 0.5}\">\n * ${this.shiftHold.value ? 'Shift is pressed!' : 'Press Shift'}\n * </div>\n * `\n * }\n * }\n * ```\n *\n * @example\n * ```ts\n * class ModifierIndicators extends LitElement {\n * private ctrl = new KeyHoldController(this, 'Control')\n * private shift = new KeyHoldController(this, 'Shift')\n * private alt = new KeyHoldController(this, 'Alt')\n *\n * render() {\n * return html`\n * <span style=\"opacity: ${this.ctrl.value ? 1 : 0.3}\">Ctrl</span>\n * <span style=\"opacity: ${this.shift.value ? 1 : 0.3}\">Shift</span>\n * <span style=\"opacity: ${this.alt.value ? 1 : 0.3}\">Alt</span>\n * `\n * }\n * }\n * ```\n */\nexport class KeyHoldController implements ReactiveController {\n /** The unsubscribe function to unsubscribe from the tracker store. */\n private _unsubscribe: (() => void) | undefined\n /** Whether the tracked key is currently held down. */\n private _value = false\n\n /** Whether the tracked key is currently held down. */\n public get value(): boolean {\n return this._value\n }\n\n /**\n * @param host - The Lit component that owns this controller.\n * @param key - The key to track (e.g. 'Shift', 'Control', 'A').\n */\n constructor(\n private _host: ReactiveControllerHost,\n private _key: IndividualKey,\n ) {\n this._host.addController(this)\n }\n\n public hostConnected(): void {\n const tracker: KeyStateTracker = getKeyStateTracker()\n const normalizedKey: string = this._key.toLowerCase()\n\n const subscription = tracker.store.subscribe(() => {\n const isHeld: boolean = tracker.store.state.heldKeys.some(\n (heldKey: string) => heldKey.toLowerCase() === normalizedKey,\n )\n\n if (isHeld !== this._value) {\n this._value = isHeld\n this._host.requestUpdate()\n }\n })\n\n this._unsubscribe = () => subscription.unsubscribe()\n }\n\n public hostDisconnected(): void {\n this._unsubscribe?.()\n this._unsubscribe = undefined\n this._value = false\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0CA,IAAa,oBAAb,MAA6D;;CAO3D,IAAW,QAAiB;AAC1B,SAAO,KAAK;;;;;;CAOd,YACE,AAAQ,OACR,AAAQ,MACR;EAFQ;EACA;gBAbO;AAef,OAAK,MAAM,cAAc,KAAK;;CAGhC,AAAO,gBAAsB;EAC3B,MAAM,UAA2B,oBAAoB;EACrD,MAAM,gBAAwB,KAAK,KAAK,aAAa;EAErD,MAAM,eAAe,QAAQ,MAAM,gBAAgB;GACjD,MAAM,SAAkB,QAAQ,MAAM,MAAM,SAAS,MAClD,YAAoB,QAAQ,aAAa,KAAK,cAChD;AAED,OAAI,WAAW,KAAK,QAAQ;AAC1B,SAAK,SAAS;AACd,SAAK,MAAM,eAAe;;IAE5B;AAEF,OAAK,qBAAqB,aAAa,aAAa;;CAGtD,AAAO,mBAAyB;AAC9B,OAAK,gBAAgB;AACrB,OAAK,eAAe;AACpB,OAAK,SAAS"}
package/dist/index.cjs CHANGED
@@ -6,6 +6,7 @@ const require_hotkey$1 = require('./decorators/hotkey.cjs');
6
6
  const require_held_key_codes = require('./controllers/held-key-codes.cjs');
7
7
  const require_held_keys = require('./controllers/held-keys.cjs');
8
8
  const require_hotkey_recorder = require('./controllers/hotkey-recorder.cjs');
9
+ const require_hotkey_registrations = require('./controllers/hotkey-registrations.cjs');
9
10
  const require_hotkey_sequence_recorder = require('./controllers/hotkey-sequence-recorder.cjs');
10
11
  const require_key_hold = require('./controllers/key-hold.cjs');
11
12
 
@@ -13,6 +14,7 @@ exports.HeldKeyCodesController = require_held_key_codes.HeldKeyCodesController;
13
14
  exports.HeldKeysController = require_held_keys.HeldKeysController;
14
15
  exports.HotkeyController = require_hotkey.HotkeyController;
15
16
  exports.HotkeyRecorderController = require_hotkey_recorder.HotkeyRecorderController;
17
+ exports.HotkeyRegistrationsController = require_hotkey_registrations.HotkeyRegistrationsController;
16
18
  exports.HotkeySequenceController = require_hotkey_sequence.HotkeySequenceController;
17
19
  exports.HotkeySequenceRecorderController = require_hotkey_sequence_recorder.HotkeySequenceRecorderController;
18
20
  exports.KeyHoldController = require_key_hold.KeyHoldController;
package/dist/index.d.cts CHANGED
@@ -4,8 +4,9 @@ import { HeldKeyCodesController } from "./controllers/held-key-codes.cjs";
4
4
  import { HeldKeysController } from "./controllers/held-keys.cjs";
5
5
  import { HotkeyController } from "./controllers/hotkey.cjs";
6
6
  import { HotkeyRecorderController } from "./controllers/hotkey-recorder.cjs";
7
+ import { HotkeyRegistrationsController } from "./controllers/hotkey-registrations.cjs";
7
8
  import { HotkeySequenceController } from "./controllers/hotkey-sequence.cjs";
8
9
  import { HotkeySequenceRecorderController } from "./controllers/hotkey-sequence-recorder.cjs";
9
10
  import { KeyHoldController } from "./controllers/key-hold.cjs";
10
11
  export * from "@tanstack/hotkeys";
11
- export { HeldKeyCodesController, HeldKeysController, HotkeyController, HotkeyRecorderController, HotkeySequenceController, HotkeySequenceRecorderController, KeyHoldController, hotkey, hotkeySequence };
12
+ export { HeldKeyCodesController, HeldKeysController, HotkeyController, HotkeyRecorderController, HotkeyRegistrationsController, HotkeySequenceController, HotkeySequenceRecorderController, KeyHoldController, hotkey, hotkeySequence };
package/dist/index.d.ts CHANGED
@@ -4,8 +4,9 @@ import { HeldKeyCodesController } from "./controllers/held-key-codes.js";
4
4
  import { HeldKeysController } from "./controllers/held-keys.js";
5
5
  import { HotkeyController } from "./controllers/hotkey.js";
6
6
  import { HotkeyRecorderController } from "./controllers/hotkey-recorder.js";
7
+ import { HotkeyRegistrationsController } from "./controllers/hotkey-registrations.js";
7
8
  import { HotkeySequenceController } from "./controllers/hotkey-sequence.js";
8
9
  import { HotkeySequenceRecorderController } from "./controllers/hotkey-sequence-recorder.js";
9
10
  import { KeyHoldController } from "./controllers/key-hold.js";
10
11
  export * from "@tanstack/hotkeys";
11
- export { HeldKeyCodesController, HeldKeysController, HotkeyController, HotkeyRecorderController, HotkeySequenceController, HotkeySequenceRecorderController, KeyHoldController, hotkey, hotkeySequence };
12
+ export { HeldKeyCodesController, HeldKeysController, HotkeyController, HotkeyRecorderController, HotkeyRegistrationsController, HotkeySequenceController, HotkeySequenceRecorderController, KeyHoldController, hotkey, hotkeySequence };
package/dist/index.js CHANGED
@@ -5,9 +5,10 @@ import { hotkey } from "./decorators/hotkey.js";
5
5
  import { HeldKeyCodesController } from "./controllers/held-key-codes.js";
6
6
  import { HeldKeysController } from "./controllers/held-keys.js";
7
7
  import { HotkeyRecorderController } from "./controllers/hotkey-recorder.js";
8
+ import { HotkeyRegistrationsController } from "./controllers/hotkey-registrations.js";
8
9
  import { HotkeySequenceRecorderController } from "./controllers/hotkey-sequence-recorder.js";
9
10
  import { KeyHoldController } from "./controllers/key-hold.js";
10
11
 
11
12
  export * from "@tanstack/hotkeys"
12
13
 
13
- export { HeldKeyCodesController, HeldKeysController, HotkeyController, HotkeyRecorderController, HotkeySequenceController, HotkeySequenceRecorderController, KeyHoldController, hotkey, hotkeySequence };
14
+ export { HeldKeyCodesController, HeldKeysController, HotkeyController, HotkeyRecorderController, HotkeyRegistrationsController, HotkeySequenceController, HotkeySequenceRecorderController, KeyHoldController, hotkey, hotkeySequence };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/lit-hotkeys",
3
- "version": "0.0.1",
3
+ "version": "0.10.0",
4
4
  "description": "Lit adapter for TanStack Hotkeys",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -19,16 +19,6 @@
19
19
  "tanstack",
20
20
  "keys"
21
21
  ],
22
- "scripts": {
23
- "clean": "premove ./build ./dist",
24
- "lint": "eslint ./src",
25
- "lint:fix": "eslint ./src --fix",
26
- "test:eslint": "eslint ./src",
27
- "test:lib": "vitest --passWithNoTests",
28
- "test:lib:dev": "pnpm test:lib --watch",
29
- "test:types": "tsc",
30
- "build": "tsdown"
31
- },
32
22
  "type": "module",
33
23
  "main": "./dist/index.cjs",
34
24
  "module": "./dist/index.js",
@@ -49,12 +39,22 @@
49
39
  "src"
50
40
  ],
51
41
  "dependencies": {
52
- "@tanstack/hotkeys": "workspace:*"
42
+ "@tanstack/hotkeys": "0.7.0"
53
43
  },
54
44
  "devDependencies": {
55
45
  "lit": "^3.3.2"
56
46
  },
57
47
  "peerDependencies": {
58
48
  "lit": ">=3.0.0"
49
+ },
50
+ "scripts": {
51
+ "clean": "premove ./build ./dist",
52
+ "lint": "eslint ./src",
53
+ "lint:fix": "eslint ./src --fix",
54
+ "test:eslint": "eslint ./src",
55
+ "test:lib": "vitest --passWithNoTests",
56
+ "test:lib:dev": "pnpm test:lib --watch",
57
+ "test:types": "tsc",
58
+ "build": "tsdown"
59
59
  }
60
- }
60
+ }
@@ -0,0 +1,89 @@
1
+ import {
2
+ getHotkeyManager,
3
+ getSequenceManager,
4
+ toHotkeyRegistrationView,
5
+ } from '@tanstack/hotkeys'
6
+ import type {
7
+ HotkeyRegistrationView,
8
+ SequenceRegistrationView,
9
+ } from '@tanstack/hotkeys'
10
+ import type { ReactiveController, ReactiveControllerHost } from 'lit'
11
+
12
+ /**
13
+ * A Lit ReactiveController that tracks all hotkey and sequence registrations.
14
+ *
15
+ * Subscribes to the singleton HotkeyManager and SequenceManager stores and
16
+ * triggers host updates whenever registrations change.
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * class ShortcutPalette extends LitElement {
21
+ * private registrations = new HotkeyRegistrationsController(this)
22
+ *
23
+ * render() {
24
+ * return html`
25
+ * <ul>
26
+ * ${this.registrations.hotkeys.map(
27
+ * (reg) => html`<li>${reg.options.meta?.name ?? reg.hotkey}</li>`,
28
+ * )}
29
+ * </ul>
30
+ * `
31
+ * }
32
+ * }
33
+ * ```
34
+ */
35
+ export class HotkeyRegistrationsController implements ReactiveController {
36
+ private _unsubscribeHotkeys: (() => void) | undefined
37
+ private _unsubscribeSequences: (() => void) | undefined
38
+ private _hotkeys: Array<HotkeyRegistrationView> = []
39
+ private _sequences: Array<SequenceRegistrationView> = []
40
+
41
+ /** All registered hotkeys (public view, no callbacks). */
42
+ public get hotkeys(): Array<HotkeyRegistrationView> {
43
+ return this._hotkeys
44
+ }
45
+
46
+ /** All registered sequences. */
47
+ public get sequences(): Array<SequenceRegistrationView> {
48
+ return this._sequences
49
+ }
50
+
51
+ constructor(private _host: ReactiveControllerHost) {
52
+ this._host.addController(this)
53
+ }
54
+
55
+ public hostConnected(): void {
56
+ const hotkeyManager = getHotkeyManager()
57
+ const sequenceManager = getSequenceManager()
58
+
59
+ const hotkeysSub = hotkeyManager.registrations.subscribe(() => {
60
+ this._hotkeys = Array.from(
61
+ hotkeyManager.registrations.state.values(),
62
+ ).map(toHotkeyRegistrationView)
63
+ this._host.requestUpdate()
64
+ })
65
+
66
+ const sequencesSub = sequenceManager.registrations.subscribe(() => {
67
+ this._sequences = Array.from(sequenceManager.registrations.state.values())
68
+ this._host.requestUpdate()
69
+ })
70
+
71
+ this._unsubscribeHotkeys = () => hotkeysSub.unsubscribe()
72
+ this._unsubscribeSequences = () => sequencesSub.unsubscribe()
73
+
74
+ // Sync initial state
75
+ this._hotkeys = Array.from(hotkeyManager.registrations.state.values()).map(
76
+ toHotkeyRegistrationView,
77
+ )
78
+ this._sequences = Array.from(sequenceManager.registrations.state.values())
79
+ }
80
+
81
+ public hostDisconnected(): void {
82
+ this._unsubscribeHotkeys?.()
83
+ this._unsubscribeSequences?.()
84
+ this._unsubscribeHotkeys = undefined
85
+ this._unsubscribeSequences = undefined
86
+ this._hotkeys = []
87
+ this._sequences = []
88
+ }
89
+ }
@@ -2,6 +2,7 @@ export * from './held-key-codes'
2
2
  export * from './held-keys'
3
3
  export * from './hotkey'
4
4
  export * from './hotkey-recorder'
5
+ export * from './hotkey-registrations'
5
6
  export * from './hotkey-sequence'
6
7
  export * from './hotkey-sequence-recorder'
7
8
  export * from './key-hold'
@@ -1,6 +1,6 @@
1
1
  import { getKeyStateTracker } from '@tanstack/hotkeys'
2
2
  import type { ReactiveController, ReactiveControllerHost } from 'lit'
3
- import type { HeldKey, KeyStateTracker } from '@tanstack/hotkeys'
3
+ import type { IndividualKey, KeyStateTracker } from '@tanstack/hotkeys'
4
4
 
5
5
  /**
6
6
  * A Lit ReactiveController that tracks whether a specific key is currently held.
@@ -57,7 +57,7 @@ export class KeyHoldController implements ReactiveController {
57
57
  */
58
58
  constructor(
59
59
  private _host: ReactiveControllerHost,
60
- private _key: HeldKey,
60
+ private _key: IndividualKey,
61
61
  ) {
62
62
  this._host.addController(this)
63
63
  }