@tanstack/lit-hotkeys 0.12.0 → 0.13.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.
Files changed (93) hide show
  1. package/dist/constants.js +1 -2
  2. package/dist/controllers/held-key-codes.d.ts +2 -5
  3. package/dist/controllers/held-key-codes.js +6 -3
  4. package/dist/controllers/held-keys.d.ts +2 -5
  5. package/dist/controllers/held-keys.js +6 -3
  6. package/dist/controllers/hotkey-hint.d.ts +2 -5
  7. package/dist/controllers/hotkey-hint.js +6 -3
  8. package/dist/controllers/hotkey-recorder.d.ts +2 -5
  9. package/dist/controllers/hotkey-recorder.js +11 -4
  10. package/dist/controllers/hotkey-registrations.d.ts +2 -5
  11. package/dist/controllers/hotkey-registrations.js +6 -4
  12. package/dist/controllers/hotkey-sequence-recorder.d.ts +2 -5
  13. package/dist/controllers/hotkey-sequence-recorder.js +13 -5
  14. package/dist/controllers/hotkey-sequence.d.ts +2 -5
  15. package/dist/controllers/hotkey-sequence.js +7 -2
  16. package/dist/controllers/hotkey.d.ts +2 -5
  17. package/dist/controllers/hotkey.js +7 -2
  18. package/dist/controllers/index.d.ts +2 -1
  19. package/dist/controllers/key-hold.d.ts +2 -5
  20. package/dist/controllers/key-hold.js +7 -3
  21. package/dist/decorators/hotkey-sequence.d.ts +2 -5
  22. package/dist/decorators/hotkey-sequence.js +1 -2
  23. package/dist/decorators/hotkey.d.ts +2 -5
  24. package/dist/decorators/hotkey.js +1 -2
  25. package/dist/decorators/index.d.ts +2 -1
  26. package/dist/index.d.ts +2 -0
  27. package/package.json +9 -14
  28. package/dist/constants.cjs +0 -27
  29. package/dist/constants.cjs.map +0 -1
  30. package/dist/constants.js.map +0 -1
  31. package/dist/controllers/held-key-codes.cjs +0 -61
  32. package/dist/controllers/held-key-codes.cjs.map +0 -1
  33. package/dist/controllers/held-key-codes.d.cts +0 -45
  34. package/dist/controllers/held-key-codes.js.map +0 -1
  35. package/dist/controllers/held-keys.cjs +0 -58
  36. package/dist/controllers/held-keys.cjs.map +0 -1
  37. package/dist/controllers/held-keys.d.cts +0 -44
  38. package/dist/controllers/held-keys.js.map +0 -1
  39. package/dist/controllers/hotkey-hint.cjs +0 -47
  40. package/dist/controllers/hotkey-hint.cjs.map +0 -1
  41. package/dist/controllers/hotkey-hint.d.cts +0 -27
  42. package/dist/controllers/hotkey-hint.js.map +0 -1
  43. package/dist/controllers/hotkey-recorder.cjs +0 -104
  44. package/dist/controllers/hotkey-recorder.cjs.map +0 -1
  45. package/dist/controllers/hotkey-recorder.d.cts +0 -75
  46. package/dist/controllers/hotkey-recorder.js.map +0 -1
  47. package/dist/controllers/hotkey-registrations.cjs +0 -70
  48. package/dist/controllers/hotkey-registrations.cjs.map +0 -1
  49. package/dist/controllers/hotkey-registrations.d.cts +0 -44
  50. package/dist/controllers/hotkey-registrations.js.map +0 -1
  51. package/dist/controllers/hotkey-sequence-recorder.cjs +0 -117
  52. package/dist/controllers/hotkey-sequence-recorder.cjs.map +0 -1
  53. package/dist/controllers/hotkey-sequence-recorder.d.cts +0 -83
  54. package/dist/controllers/hotkey-sequence-recorder.js.map +0 -1
  55. package/dist/controllers/hotkey-sequence.cjs +0 -58
  56. package/dist/controllers/hotkey-sequence.cjs.map +0 -1
  57. package/dist/controllers/hotkey-sequence.d.cts +0 -45
  58. package/dist/controllers/hotkey-sequence.js.map +0 -1
  59. package/dist/controllers/hotkey.cjs +0 -60
  60. package/dist/controllers/hotkey.cjs.map +0 -1
  61. package/dist/controllers/hotkey.d.cts +0 -45
  62. package/dist/controllers/hotkey.js.map +0 -1
  63. package/dist/controllers/index.d.cts +0 -9
  64. package/dist/controllers/key-hold.cjs +0 -78
  65. package/dist/controllers/key-hold.cjs.map +0 -1
  66. package/dist/controllers/key-hold.d.cts +0 -62
  67. package/dist/controllers/key-hold.js.map +0 -1
  68. package/dist/decorators/hotkey-sequence.cjs +0 -45
  69. package/dist/decorators/hotkey-sequence.cjs.map +0 -1
  70. package/dist/decorators/hotkey-sequence.d.cts +0 -28
  71. package/dist/decorators/hotkey-sequence.js.map +0 -1
  72. package/dist/decorators/hotkey.cjs +0 -44
  73. package/dist/decorators/hotkey.cjs.map +0 -1
  74. package/dist/decorators/hotkey.d.cts +0 -27
  75. package/dist/decorators/hotkey.js.map +0 -1
  76. package/dist/decorators/index.d.cts +0 -2
  77. package/dist/index.cjs +0 -31
  78. package/dist/index.d.cts +0 -13
  79. package/src/constants.ts +0 -23
  80. package/src/controllers/held-key-codes.ts +0 -67
  81. package/src/controllers/held-keys.ts +0 -64
  82. package/src/controllers/hotkey-hint.ts +0 -56
  83. package/src/controllers/hotkey-recorder.ts +0 -120
  84. package/src/controllers/hotkey-registrations.ts +0 -89
  85. package/src/controllers/hotkey-sequence-recorder.ts +0 -141
  86. package/src/controllers/hotkey-sequence.ts +0 -82
  87. package/src/controllers/hotkey.ts +0 -96
  88. package/src/controllers/index.ts +0 -9
  89. package/src/controllers/key-hold.ts +0 -88
  90. package/src/decorators/hotkey-sequence.ts +0 -68
  91. package/src/decorators/hotkey.ts +0 -70
  92. package/src/decorators/index.ts +0 -2
  93. package/src/index.ts +0 -6
@@ -1,44 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,117 +0,0 @@
1
- let _tanstack_hotkeys = require("@tanstack/hotkeys");
2
-
3
- //#region src/controllers/hotkey-sequence-recorder.ts
4
- /**
5
- * A Lit ReactiveController that records multi-chord sequences (Vim-style shortcuts).
6
- *
7
- * Wraps the framework-agnostic `HotkeySequenceRecorder` class, managing store
8
- * subscriptions and host update lifecycle automatically.
9
- *
10
- * @example
11
- * ```ts
12
- * class ShortcutSettings extends LitElement {
13
- * private recorder = new HotkeySequenceRecorderController(this, {
14
- * onRecord: (sequence) => {
15
- * this.sequence = sequence
16
- * this.requestUpdate()
17
- * },
18
- * onCancel: () => {
19
- * console.log('Recording cancelled')
20
- * },
21
- * })
22
- *
23
- * private sequence: HotkeySequence | null = null
24
- *
25
- * render() {
26
- * return html`
27
- * <button @click=${() => this.recorder.startRecording()}>
28
- * ${this.recorder.isRecording ? 'Recording...' : 'Edit Sequence'}
29
- * </button>
30
- * ${this.recorder.steps.length
31
- * ? html`<div>Steps: ${this.recorder.steps.join(' → ')}</div>`
32
- * : nothing}
33
- * ${this.recorder.recordedSequence
34
- * ? html`<div>Recorded: ${this.recorder.recordedSequence.join(' → ')}</div>`
35
- * : nothing}
36
- * `
37
- * }
38
- * }
39
- * ```
40
- */
41
- var HotkeySequenceRecorderController = class {
42
- /** Whether recording is currently active. */
43
- get isRecording() {
44
- return this._isRecording;
45
- }
46
- /** Chords captured in the current session. */
47
- get steps() {
48
- return this._steps;
49
- }
50
- /** Last committed sequence, or null if none. */
51
- get recordedSequence() {
52
- return this._recordedSequence;
53
- }
54
- /**
55
- * @param _host - The Lit component that owns this controller.
56
- * @param _options - Configuration options for the sequence recorder.
57
- */
58
- constructor(_host, _options) {
59
- this._host = _host;
60
- this._options = _options;
61
- this._isRecording = false;
62
- this._steps = [];
63
- this._recordedSequence = null;
64
- this._recorder = new _tanstack_hotkeys.HotkeySequenceRecorder(_options);
65
- this._host.addController(this);
66
- }
67
- /** Subscribes to the recorder store and updates internal state when changes occur. */
68
- hostConnected() {
69
- const subscription = this._recorder.store.subscribe(() => {
70
- const { isRecording, steps, recordedSequence } = this._recorder.store.state;
71
- if (isRecording !== this._isRecording || steps !== this._steps || recordedSequence !== this._recordedSequence) {
72
- this._isRecording = isRecording;
73
- this._steps = steps;
74
- this._recordedSequence = recordedSequence;
75
- this._host.requestUpdate();
76
- }
77
- });
78
- this._unsubscribe = () => subscription.unsubscribe();
79
- }
80
- /** Unsubscribes from the recorder store and destroys the recorder instance to prevent memory leaks. */
81
- hostDisconnected() {
82
- this._unsubscribe?.();
83
- this._unsubscribe = void 0;
84
- this._recorder.stop();
85
- this._isRecording = false;
86
- this._steps = [];
87
- this._recordedSequence = null;
88
- }
89
- /** Updates the recorder options. */
90
- setOptions(options) {
91
- this._options = {
92
- ...this._options,
93
- ...options
94
- };
95
- this._recorder.setOptions(this._options);
96
- }
97
- /** Start recording a new sequence. */
98
- startRecording() {
99
- this._recorder.start();
100
- }
101
- /** Stop recording (same as cancel but without calling onCancel). */
102
- stopRecording() {
103
- this._recorder.stop();
104
- }
105
- /** Cancel recording without saving. */
106
- cancelRecording() {
107
- this._recorder.cancel();
108
- }
109
- /** Commit current steps as a sequence (no-op if empty). */
110
- commitRecording() {
111
- this._recorder.commit();
112
- }
113
- };
114
-
115
- //#endregion
116
- exports.HotkeySequenceRecorderController = HotkeySequenceRecorderController;
117
- //# sourceMappingURL=hotkey-sequence-recorder.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hotkey-sequence-recorder.cjs","names":["HotkeySequenceRecorder"],"sources":["../../src/controllers/hotkey-sequence-recorder.ts"],"sourcesContent":["import { HotkeySequenceRecorder } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type {\n HotkeySequence,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\n\n/**\n * A Lit ReactiveController that records multi-chord sequences (Vim-style shortcuts).\n *\n * Wraps the framework-agnostic `HotkeySequenceRecorder` class, managing store\n * subscriptions and host update lifecycle automatically.\n *\n * @example\n * ```ts\n * class ShortcutSettings extends LitElement {\n * private recorder = new HotkeySequenceRecorderController(this, {\n * onRecord: (sequence) => {\n * this.sequence = sequence\n * this.requestUpdate()\n * },\n * onCancel: () => {\n * console.log('Recording cancelled')\n * },\n * })\n *\n * private sequence: HotkeySequence | null = null\n *\n * render() {\n * return html`\n * <button @click=${() => this.recorder.startRecording()}>\n * ${this.recorder.isRecording ? 'Recording...' : 'Edit Sequence'}\n * </button>\n * ${this.recorder.steps.length\n * ? html`<div>Steps: ${this.recorder.steps.join(' → ')}</div>`\n * : nothing}\n * ${this.recorder.recordedSequence\n * ? html`<div>Recorded: ${this.recorder.recordedSequence.join(' → ')}</div>`\n * : nothing}\n * `\n * }\n * }\n * ```\n */\nexport class HotkeySequenceRecorderController implements ReactiveController {\n /** The recorder instance. */\n private _recorder: HotkeySequenceRecorder\n /** The unsubscribe function. */\n private _unsubscribe: (() => void) | undefined\n /** Whether recording is currently active. */\n private _isRecording = false\n /** Chords captured in the current session. */\n private _steps: HotkeySequence = []\n /** Last committed sequence, or null if none. */\n private _recordedSequence: HotkeySequence | null = null\n\n /** Whether recording is currently active. */\n public get isRecording(): boolean {\n return this._isRecording\n }\n\n /** Chords captured in the current session. */\n public get steps(): HotkeySequence {\n return this._steps\n }\n\n /** Last committed sequence, or null if none. */\n public get recordedSequence(): HotkeySequence | null {\n return this._recordedSequence\n }\n\n /**\n * @param _host - The Lit component that owns this controller.\n * @param _options - Configuration options for the sequence recorder.\n */\n constructor(\n private _host: ReactiveControllerHost,\n private _options: HotkeySequenceRecorderOptions,\n ) {\n this._recorder = new HotkeySequenceRecorder(_options)\n this._host.addController(this)\n }\n\n /** Subscribes to the recorder store and updates internal state when changes occur. */\n public hostConnected(): void {\n const subscription = this._recorder.store.subscribe(() => {\n const { isRecording, steps, recordedSequence } =\n this._recorder.store.state\n\n const hasChanged: boolean =\n isRecording !== this._isRecording ||\n steps !== this._steps ||\n recordedSequence !== this._recordedSequence\n\n if (hasChanged) {\n this._isRecording = isRecording\n this._steps = steps\n this._recordedSequence = recordedSequence\n this._host.requestUpdate()\n }\n })\n\n this._unsubscribe = () => subscription.unsubscribe()\n }\n\n /** Unsubscribes from the recorder store and destroys the recorder instance to prevent memory leaks. */\n public hostDisconnected(): void {\n this._unsubscribe?.()\n this._unsubscribe = undefined\n this._recorder.stop()\n this._isRecording = false\n this._steps = []\n this._recordedSequence = null\n }\n\n /** Updates the recorder options. */\n public setOptions(options: Partial<HotkeySequenceRecorderOptions>): void {\n this._options = { ...this._options, ...options }\n this._recorder.setOptions(this._options)\n }\n\n /** Start recording a new sequence. */\n public startRecording(): void {\n this._recorder.start()\n }\n\n /** Stop recording (same as cancel but without calling onCancel). */\n public stopRecording(): void {\n this._recorder.stop()\n }\n\n /** Cancel recording without saving. */\n public cancelRecording(): void {\n this._recorder.cancel()\n }\n\n /** Commit current steps as a sequence (no-op if empty). */\n public commitRecording(): void {\n this._recorder.commit()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAa,mCAAb,MAA4E;;CAa1E,IAAW,cAAuB;AAChC,SAAO,KAAK;;;CAId,IAAW,QAAwB;AACjC,SAAO,KAAK;;;CAId,IAAW,mBAA0C;AACnD,SAAO,KAAK;;;;;;CAOd,YACE,AAAQ,OACR,AAAQ,UACR;EAFQ;EACA;sBA3Ba;gBAEU,EAAE;2BAEgB;AAyBjD,OAAK,YAAY,IAAIA,yCAAuB,SAAS;AACrD,OAAK,MAAM,cAAc,KAAK;;;CAIhC,AAAO,gBAAsB;EAC3B,MAAM,eAAe,KAAK,UAAU,MAAM,gBAAgB;GACxD,MAAM,EAAE,aAAa,OAAO,qBAC1B,KAAK,UAAU,MAAM;AAOvB,OAJE,gBAAgB,KAAK,gBACrB,UAAU,KAAK,UACf,qBAAqB,KAAK,mBAEZ;AACd,SAAK,eAAe;AACpB,SAAK,SAAS;AACd,SAAK,oBAAoB;AACzB,SAAK,MAAM,eAAe;;IAE5B;AAEF,OAAK,qBAAqB,aAAa,aAAa;;;CAItD,AAAO,mBAAyB;AAC9B,OAAK,gBAAgB;AACrB,OAAK,eAAe;AACpB,OAAK,UAAU,MAAM;AACrB,OAAK,eAAe;AACpB,OAAK,SAAS,EAAE;AAChB,OAAK,oBAAoB;;;CAI3B,AAAO,WAAW,SAAuD;AACvE,OAAK,WAAW;GAAE,GAAG,KAAK;GAAU,GAAG;GAAS;AAChD,OAAK,UAAU,WAAW,KAAK,SAAS;;;CAI1C,AAAO,iBAAuB;AAC5B,OAAK,UAAU,OAAO;;;CAIxB,AAAO,gBAAsB;AAC3B,OAAK,UAAU,MAAM;;;CAIvB,AAAO,kBAAwB;AAC7B,OAAK,UAAU,QAAQ;;;CAIzB,AAAO,kBAAwB;AAC7B,OAAK,UAAU,QAAQ"}
@@ -1,83 +0,0 @@
1
- import { HotkeySequence, HotkeySequenceRecorderOptions } from "@tanstack/hotkeys";
2
- import { ReactiveController, ReactiveControllerHost } from "lit";
3
-
4
- //#region src/controllers/hotkey-sequence-recorder.d.ts
5
- /**
6
- * A Lit ReactiveController that records multi-chord sequences (Vim-style shortcuts).
7
- *
8
- * Wraps the framework-agnostic `HotkeySequenceRecorder` class, managing store
9
- * subscriptions and host update lifecycle automatically.
10
- *
11
- * @example
12
- * ```ts
13
- * class ShortcutSettings extends LitElement {
14
- * private recorder = new HotkeySequenceRecorderController(this, {
15
- * onRecord: (sequence) => {
16
- * this.sequence = sequence
17
- * this.requestUpdate()
18
- * },
19
- * onCancel: () => {
20
- * console.log('Recording cancelled')
21
- * },
22
- * })
23
- *
24
- * private sequence: HotkeySequence | null = null
25
- *
26
- * render() {
27
- * return html`
28
- * <button @click=${() => this.recorder.startRecording()}>
29
- * ${this.recorder.isRecording ? 'Recording...' : 'Edit Sequence'}
30
- * </button>
31
- * ${this.recorder.steps.length
32
- * ? html`<div>Steps: ${this.recorder.steps.join(' → ')}</div>`
33
- * : nothing}
34
- * ${this.recorder.recordedSequence
35
- * ? html`<div>Recorded: ${this.recorder.recordedSequence.join(' → ')}</div>`
36
- * : nothing}
37
- * `
38
- * }
39
- * }
40
- * ```
41
- */
42
- declare class HotkeySequenceRecorderController implements ReactiveController {
43
- private _host;
44
- private _options;
45
- /** The recorder instance. */
46
- private _recorder;
47
- /** The unsubscribe function. */
48
- private _unsubscribe;
49
- /** Whether recording is currently active. */
50
- private _isRecording;
51
- /** Chords captured in the current session. */
52
- private _steps;
53
- /** Last committed sequence, or null if none. */
54
- private _recordedSequence;
55
- /** Whether recording is currently active. */
56
- get isRecording(): boolean;
57
- /** Chords captured in the current session. */
58
- get steps(): HotkeySequence;
59
- /** Last committed sequence, or null if none. */
60
- get recordedSequence(): HotkeySequence | null;
61
- /**
62
- * @param _host - The Lit component that owns this controller.
63
- * @param _options - Configuration options for the sequence recorder.
64
- */
65
- constructor(_host: ReactiveControllerHost, _options: HotkeySequenceRecorderOptions);
66
- /** Subscribes to the recorder store and updates internal state when changes occur. */
67
- hostConnected(): void;
68
- /** Unsubscribes from the recorder store and destroys the recorder instance to prevent memory leaks. */
69
- hostDisconnected(): void;
70
- /** Updates the recorder options. */
71
- setOptions(options: Partial<HotkeySequenceRecorderOptions>): void;
72
- /** Start recording a new sequence. */
73
- startRecording(): void;
74
- /** Stop recording (same as cancel but without calling onCancel). */
75
- stopRecording(): void;
76
- /** Cancel recording without saving. */
77
- cancelRecording(): void;
78
- /** Commit current steps as a sequence (no-op if empty). */
79
- commitRecording(): void;
80
- }
81
- //#endregion
82
- export { HotkeySequenceRecorderController };
83
- //# sourceMappingURL=hotkey-sequence-recorder.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hotkey-sequence-recorder.js","names":[],"sources":["../../src/controllers/hotkey-sequence-recorder.ts"],"sourcesContent":["import { HotkeySequenceRecorder } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type {\n HotkeySequence,\n HotkeySequenceRecorderOptions,\n} from '@tanstack/hotkeys'\n\n/**\n * A Lit ReactiveController that records multi-chord sequences (Vim-style shortcuts).\n *\n * Wraps the framework-agnostic `HotkeySequenceRecorder` class, managing store\n * subscriptions and host update lifecycle automatically.\n *\n * @example\n * ```ts\n * class ShortcutSettings extends LitElement {\n * private recorder = new HotkeySequenceRecorderController(this, {\n * onRecord: (sequence) => {\n * this.sequence = sequence\n * this.requestUpdate()\n * },\n * onCancel: () => {\n * console.log('Recording cancelled')\n * },\n * })\n *\n * private sequence: HotkeySequence | null = null\n *\n * render() {\n * return html`\n * <button @click=${() => this.recorder.startRecording()}>\n * ${this.recorder.isRecording ? 'Recording...' : 'Edit Sequence'}\n * </button>\n * ${this.recorder.steps.length\n * ? html`<div>Steps: ${this.recorder.steps.join(' → ')}</div>`\n * : nothing}\n * ${this.recorder.recordedSequence\n * ? html`<div>Recorded: ${this.recorder.recordedSequence.join(' → ')}</div>`\n * : nothing}\n * `\n * }\n * }\n * ```\n */\nexport class HotkeySequenceRecorderController implements ReactiveController {\n /** The recorder instance. */\n private _recorder: HotkeySequenceRecorder\n /** The unsubscribe function. */\n private _unsubscribe: (() => void) | undefined\n /** Whether recording is currently active. */\n private _isRecording = false\n /** Chords captured in the current session. */\n private _steps: HotkeySequence = []\n /** Last committed sequence, or null if none. */\n private _recordedSequence: HotkeySequence | null = null\n\n /** Whether recording is currently active. */\n public get isRecording(): boolean {\n return this._isRecording\n }\n\n /** Chords captured in the current session. */\n public get steps(): HotkeySequence {\n return this._steps\n }\n\n /** Last committed sequence, or null if none. */\n public get recordedSequence(): HotkeySequence | null {\n return this._recordedSequence\n }\n\n /**\n * @param _host - The Lit component that owns this controller.\n * @param _options - Configuration options for the sequence recorder.\n */\n constructor(\n private _host: ReactiveControllerHost,\n private _options: HotkeySequenceRecorderOptions,\n ) {\n this._recorder = new HotkeySequenceRecorder(_options)\n this._host.addController(this)\n }\n\n /** Subscribes to the recorder store and updates internal state when changes occur. */\n public hostConnected(): void {\n const subscription = this._recorder.store.subscribe(() => {\n const { isRecording, steps, recordedSequence } =\n this._recorder.store.state\n\n const hasChanged: boolean =\n isRecording !== this._isRecording ||\n steps !== this._steps ||\n recordedSequence !== this._recordedSequence\n\n if (hasChanged) {\n this._isRecording = isRecording\n this._steps = steps\n this._recordedSequence = recordedSequence\n this._host.requestUpdate()\n }\n })\n\n this._unsubscribe = () => subscription.unsubscribe()\n }\n\n /** Unsubscribes from the recorder store and destroys the recorder instance to prevent memory leaks. */\n public hostDisconnected(): void {\n this._unsubscribe?.()\n this._unsubscribe = undefined\n this._recorder.stop()\n this._isRecording = false\n this._steps = []\n this._recordedSequence = null\n }\n\n /** Updates the recorder options. */\n public setOptions(options: Partial<HotkeySequenceRecorderOptions>): void {\n this._options = { ...this._options, ...options }\n this._recorder.setOptions(this._options)\n }\n\n /** Start recording a new sequence. */\n public startRecording(): void {\n this._recorder.start()\n }\n\n /** Stop recording (same as cancel but without calling onCancel). */\n public stopRecording(): void {\n this._recorder.stop()\n }\n\n /** Cancel recording without saving. */\n public cancelRecording(): void {\n this._recorder.cancel()\n }\n\n /** Commit current steps as a sequence (no-op if empty). */\n public commitRecording(): void {\n this._recorder.commit()\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4CA,IAAa,mCAAb,MAA4E;;CAa1E,IAAW,cAAuB;AAChC,SAAO,KAAK;;;CAId,IAAW,QAAwB;AACjC,SAAO,KAAK;;;CAId,IAAW,mBAA0C;AACnD,SAAO,KAAK;;;;;;CAOd,YACE,AAAQ,OACR,AAAQ,UACR;EAFQ;EACA;sBA3Ba;gBAEU,EAAE;2BAEgB;AAyBjD,OAAK,YAAY,IAAI,uBAAuB,SAAS;AACrD,OAAK,MAAM,cAAc,KAAK;;;CAIhC,AAAO,gBAAsB;EAC3B,MAAM,eAAe,KAAK,UAAU,MAAM,gBAAgB;GACxD,MAAM,EAAE,aAAa,OAAO,qBAC1B,KAAK,UAAU,MAAM;AAOvB,OAJE,gBAAgB,KAAK,gBACrB,UAAU,KAAK,UACf,qBAAqB,KAAK,mBAEZ;AACd,SAAK,eAAe;AACpB,SAAK,SAAS;AACd,SAAK,oBAAoB;AACzB,SAAK,MAAM,eAAe;;IAE5B;AAEF,OAAK,qBAAqB,aAAa,aAAa;;;CAItD,AAAO,mBAAyB;AAC9B,OAAK,gBAAgB;AACrB,OAAK,eAAe;AACpB,OAAK,UAAU,MAAM;AACrB,OAAK,eAAe;AACpB,OAAK,SAAS,EAAE;AAChB,OAAK,oBAAoB;;;CAI3B,AAAO,WAAW,SAAuD;AACvE,OAAK,WAAW;GAAE,GAAG,KAAK;GAAU,GAAG;GAAS;AAChD,OAAK,UAAU,WAAW,KAAK,SAAS;;;CAI1C,AAAO,iBAAuB;AAC5B,OAAK,UAAU,OAAO;;;CAIxB,AAAO,gBAAsB;AAC3B,OAAK,UAAU,MAAM;;;CAIvB,AAAO,kBAAwB;AAC7B,OAAK,UAAU,QAAQ;;;CAIzB,AAAO,kBAAwB;AAC7B,OAAK,UAAU,QAAQ"}
@@ -1,58 +0,0 @@
1
- const require_constants = require('../constants.cjs');
2
- let _tanstack_hotkeys = require("@tanstack/hotkeys");
3
-
4
- //#region src/controllers/hotkey-sequence.ts
5
- /**
6
- * A Lit ReactiveController that registers a keyboard sequence (e.g. Vim-style)
7
- * when the host element is connected and unregisters it when the host is disconnected.
8
- *
9
- * @example
10
- * ```ts
11
- * class MyElement extends LitElement {
12
- * private seq = new HotkeySequenceController(this, ['G', 'G'], () => this.goToTop())
13
- *
14
- * constructor() {
15
- * super()
16
- * this.addController(this.seq)
17
- * }
18
- * }
19
- * ```
20
- */
21
- var HotkeySequenceController = class {
22
- /**
23
- * @param _host - The Lit component that owns this controller (use `this` and pass it to `addController()`).
24
- * @param _sequence - The key sequence to listen for (e.g. `['G', 'G']`).
25
- * @param _callback - Function to run when the sequence is completed; called with the host as `this`.
26
- * @param _options - Optional sequence options (target, timeout, enabled, etc.).
27
- */
28
- constructor(_host, _sequence, _callback, _options = require_constants.HOTKEY_SEQUENCE_DEFAULT_OPTIONS) {
29
- this._host = _host;
30
- this._sequence = _sequence;
31
- this._callback = _callback;
32
- this._options = _options;
33
- }
34
- /**
35
- * Registers the sequence with the global sequence manager when the host is connected to the DOM.
36
- * Skips registration if disabled, sequence is empty, or no target is available.
37
- */
38
- hostConnected() {
39
- const { target: _target, ...optionsWithoutTarget } = this._options;
40
- const manager = (0, _tanstack_hotkeys.getSequenceManager)();
41
- const resolvedTarget = "target" in this._options ? this._options.target ?? null : typeof document !== "undefined" ? document : null;
42
- if (!resolvedTarget) return;
43
- const boundCallback = this._callback.bind(this._host);
44
- this._registration = manager.register(this._sequence, boundCallback, {
45
- ...optionsWithoutTarget,
46
- target: resolvedTarget
47
- });
48
- }
49
- /** Unregisters the sequence when the host is disconnected from the DOM. */
50
- hostDisconnected() {
51
- if (this._registration?.isActive) this._registration.unregister();
52
- this._registration = void 0;
53
- }
54
- };
55
-
56
- //#endregion
57
- exports.HotkeySequenceController = HotkeySequenceController;
58
- //# sourceMappingURL=hotkey-sequence.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hotkey-sequence.cjs","names":["HOTKEY_SEQUENCE_DEFAULT_OPTIONS"],"sources":["../../src/controllers/hotkey-sequence.ts"],"sourcesContent":["import { getSequenceManager } from '@tanstack/hotkeys'\nimport { HOTKEY_SEQUENCE_DEFAULT_OPTIONS } from '../constants'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type {\n HotkeyCallback,\n HotkeySequence,\n SequenceManager,\n SequenceOptions,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\n/**\n * A Lit ReactiveController that registers a keyboard sequence (e.g. Vim-style)\n * when the host element is connected and unregisters it when the host is disconnected.\n *\n * @example\n * ```ts\n * class MyElement extends LitElement {\n * private seq = new HotkeySequenceController(this, ['G', 'G'], () => this.goToTop())\n *\n * constructor() {\n * super()\n * this.addController(this.seq)\n * }\n * }\n * ```\n */\nexport class HotkeySequenceController implements ReactiveController {\n /** The sequence registration handle. */\n private _registration: SequenceRegistrationHandle | undefined\n\n /**\n * @param _host - The Lit component that owns this controller (use `this` and pass it to `addController()`).\n * @param _sequence - The key sequence to listen for (e.g. `['G', 'G']`).\n * @param _callback - Function to run when the sequence is completed; called with the host as `this`.\n * @param _options - Optional sequence options (target, timeout, enabled, etc.).\n */\n constructor(\n private _host: ReactiveControllerHost,\n private _sequence: HotkeySequence,\n private _callback: HotkeyCallback,\n private _options: SequenceOptions = HOTKEY_SEQUENCE_DEFAULT_OPTIONS,\n ) {}\n\n /**\n * Registers the sequence with the global sequence manager when the host is connected to the DOM.\n * Skips registration if disabled, sequence is empty, or no target is available.\n */\n public hostConnected(): void {\n const { target: _target, ...optionsWithoutTarget } = this._options\n\n const manager: SequenceManager = getSequenceManager()\n\n const hasExplicitTarget = 'target' in this._options\n const resolvedTarget = hasExplicitTarget\n ? (this._options.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n return\n }\n\n const boundCallback: HotkeyCallback = this._callback.bind(\n this._host as unknown as object,\n )\n\n this._registration = manager.register(this._sequence, boundCallback, {\n ...optionsWithoutTarget,\n target: resolvedTarget,\n })\n }\n\n /** Unregisters the sequence when the host is disconnected from the DOM. */\n public hostDisconnected(): void {\n if (this._registration?.isActive) {\n this._registration.unregister()\n }\n this._registration = undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,IAAa,2BAAb,MAAoE;;;;;;;CAUlE,YACE,AAAQ,OACR,AAAQ,WACR,AAAQ,WACR,AAAQ,WAA4BA,mDACpC;EAJQ;EACA;EACA;EACA;;;;;;CAOV,AAAO,gBAAsB;EAC3B,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,KAAK;EAE1D,MAAM,qDAA+C;EAGrD,MAAM,iBADoB,YAAY,KAAK,WAEtC,KAAK,SAAS,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAEN,MAAI,CAAC,eACH;EAGF,MAAM,gBAAgC,KAAK,UAAU,KACnD,KAAK,MACN;AAED,OAAK,gBAAgB,QAAQ,SAAS,KAAK,WAAW,eAAe;GACnE,GAAG;GACH,QAAQ;GACT,CAAC;;;CAIJ,AAAO,mBAAyB;AAC9B,MAAI,KAAK,eAAe,SACtB,MAAK,cAAc,YAAY;AAEjC,OAAK,gBAAgB"}
@@ -1,45 +0,0 @@
1
- import { HotkeyCallback, HotkeySequence, SequenceOptions } from "@tanstack/hotkeys";
2
- import { ReactiveController, ReactiveControllerHost } from "lit";
3
-
4
- //#region src/controllers/hotkey-sequence.d.ts
5
- /**
6
- * A Lit ReactiveController that registers a keyboard sequence (e.g. Vim-style)
7
- * when the host element is connected and unregisters it when the host is disconnected.
8
- *
9
- * @example
10
- * ```ts
11
- * class MyElement extends LitElement {
12
- * private seq = new HotkeySequenceController(this, ['G', 'G'], () => this.goToTop())
13
- *
14
- * constructor() {
15
- * super()
16
- * this.addController(this.seq)
17
- * }
18
- * }
19
- * ```
20
- */
21
- declare class HotkeySequenceController implements ReactiveController {
22
- private _host;
23
- private _sequence;
24
- private _callback;
25
- private _options;
26
- /** The sequence registration handle. */
27
- private _registration;
28
- /**
29
- * @param _host - The Lit component that owns this controller (use `this` and pass it to `addController()`).
30
- * @param _sequence - The key sequence to listen for (e.g. `['G', 'G']`).
31
- * @param _callback - Function to run when the sequence is completed; called with the host as `this`.
32
- * @param _options - Optional sequence options (target, timeout, enabled, etc.).
33
- */
34
- constructor(_host: ReactiveControllerHost, _sequence: HotkeySequence, _callback: HotkeyCallback, _options?: SequenceOptions);
35
- /**
36
- * Registers the sequence with the global sequence manager when the host is connected to the DOM.
37
- * Skips registration if disabled, sequence is empty, or no target is available.
38
- */
39
- hostConnected(): void;
40
- /** Unregisters the sequence when the host is disconnected from the DOM. */
41
- hostDisconnected(): void;
42
- }
43
- //#endregion
44
- export { HotkeySequenceController };
45
- //# sourceMappingURL=hotkey-sequence.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hotkey-sequence.js","names":[],"sources":["../../src/controllers/hotkey-sequence.ts"],"sourcesContent":["import { getSequenceManager } from '@tanstack/hotkeys'\nimport { HOTKEY_SEQUENCE_DEFAULT_OPTIONS } from '../constants'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type {\n HotkeyCallback,\n HotkeySequence,\n SequenceManager,\n SequenceOptions,\n SequenceRegistrationHandle,\n} from '@tanstack/hotkeys'\n\n/**\n * A Lit ReactiveController that registers a keyboard sequence (e.g. Vim-style)\n * when the host element is connected and unregisters it when the host is disconnected.\n *\n * @example\n * ```ts\n * class MyElement extends LitElement {\n * private seq = new HotkeySequenceController(this, ['G', 'G'], () => this.goToTop())\n *\n * constructor() {\n * super()\n * this.addController(this.seq)\n * }\n * }\n * ```\n */\nexport class HotkeySequenceController implements ReactiveController {\n /** The sequence registration handle. */\n private _registration: SequenceRegistrationHandle | undefined\n\n /**\n * @param _host - The Lit component that owns this controller (use `this` and pass it to `addController()`).\n * @param _sequence - The key sequence to listen for (e.g. `['G', 'G']`).\n * @param _callback - Function to run when the sequence is completed; called with the host as `this`.\n * @param _options - Optional sequence options (target, timeout, enabled, etc.).\n */\n constructor(\n private _host: ReactiveControllerHost,\n private _sequence: HotkeySequence,\n private _callback: HotkeyCallback,\n private _options: SequenceOptions = HOTKEY_SEQUENCE_DEFAULT_OPTIONS,\n ) {}\n\n /**\n * Registers the sequence with the global sequence manager when the host is connected to the DOM.\n * Skips registration if disabled, sequence is empty, or no target is available.\n */\n public hostConnected(): void {\n const { target: _target, ...optionsWithoutTarget } = this._options\n\n const manager: SequenceManager = getSequenceManager()\n\n const hasExplicitTarget = 'target' in this._options\n const resolvedTarget = hasExplicitTarget\n ? (this._options.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n return\n }\n\n const boundCallback: HotkeyCallback = this._callback.bind(\n this._host as unknown as object,\n )\n\n this._registration = manager.register(this._sequence, boundCallback, {\n ...optionsWithoutTarget,\n target: resolvedTarget,\n })\n }\n\n /** Unregisters the sequence when the host is disconnected from the DOM. */\n public hostDisconnected(): void {\n if (this._registration?.isActive) {\n this._registration.unregister()\n }\n this._registration = undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2BA,IAAa,2BAAb,MAAoE;;;;;;;CAUlE,YACE,AAAQ,OACR,AAAQ,WACR,AAAQ,WACR,AAAQ,WAA4B,iCACpC;EAJQ;EACA;EACA;EACA;;;;;;CAOV,AAAO,gBAAsB;EAC3B,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,KAAK;EAE1D,MAAM,UAA2B,oBAAoB;EAGrD,MAAM,iBADoB,YAAY,KAAK,WAEtC,KAAK,SAAS,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAEN,MAAI,CAAC,eACH;EAGF,MAAM,gBAAgC,KAAK,UAAU,KACnD,KAAK,MACN;AAED,OAAK,gBAAgB,QAAQ,SAAS,KAAK,WAAW,eAAe;GACnE,GAAG;GACH,QAAQ;GACT,CAAC;;;CAIJ,AAAO,mBAAyB;AAC9B,MAAI,KAAK,eAAe,SACtB,MAAK,cAAc,YAAY;AAEjC,OAAK,gBAAgB"}
@@ -1,60 +0,0 @@
1
- const require_constants = require('../constants.cjs');
2
- let _tanstack_hotkeys = require("@tanstack/hotkeys");
3
-
4
- //#region src/controllers/hotkey.ts
5
- /**
6
- * A Lit ReactiveController that registers a keyboard hotkey when the host
7
- * element is connected and unregisters it when the host is disconnected.
8
- *
9
- * @example
10
- * ```ts
11
- * class MyElement extends LitElement {
12
- * private hotkey = new HotkeyController(this, 'Mod+S', () => this.save())
13
- *
14
- * constructor() {
15
- * super()
16
- * this.addController(this.hotkey)
17
- * }
18
- * }
19
- * ```
20
- */
21
- var HotkeyController = class {
22
- /**
23
- * @param _host - The Lit component that owns this controller (use `this` and pass it to `addController()`).
24
- * @param _hotkey - The key or key combo to listen for (e.g. `'Mod+S'` or a raw hotkey object).
25
- * @param _callback - Function to run when the hotkey is pressed; called with the host as `this`.
26
- * @param _options - Optional registration options (target, platform, enabled, etc.).
27
- */
28
- constructor(_host, _hotkey, _callback, _options = require_constants.HOTKEY_DEFAULT_OPTIONS) {
29
- this._host = _host;
30
- this._hotkey = _hotkey;
31
- this._callback = _callback;
32
- this._options = _options;
33
- }
34
- /**
35
- * Registers the hotkey with the global manager when the host is connected to the DOM.
36
- * Skips registration if no target is available (e.g. no document or options.target is null).
37
- */
38
- hostConnected() {
39
- const manager = (0, _tanstack_hotkeys.getHotkeyManager)();
40
- const platform = this._options.platform ?? (0, _tanstack_hotkeys.detectPlatform)();
41
- const hotkeyString = typeof this._hotkey === "string" ? this._hotkey : (0, _tanstack_hotkeys.formatHotkey)((0, _tanstack_hotkeys.rawHotkeyToParsedHotkey)(this._hotkey, platform));
42
- const resolvedTarget = "target" in this._options ? this._options.target ?? null : typeof document !== "undefined" ? document : null;
43
- if (!resolvedTarget) return;
44
- const { target: _target, ...optionsWithoutTarget } = this._options;
45
- const boundCallback = this._callback.bind(this._host);
46
- this._registration = manager.register(hotkeyString, boundCallback, {
47
- ...optionsWithoutTarget,
48
- target: resolvedTarget
49
- });
50
- }
51
- /** Unregisters the hotkey when the host is disconnected from the DOM. */
52
- hostDisconnected() {
53
- if (this._registration?.isActive) this._registration.unregister();
54
- this._registration = void 0;
55
- }
56
- };
57
-
58
- //#endregion
59
- exports.HotkeyController = HotkeyController;
60
- //# sourceMappingURL=hotkey.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hotkey.cjs","names":["HOTKEY_DEFAULT_OPTIONS"],"sources":["../../src/controllers/hotkey.ts"],"sourcesContent":["import {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { HOTKEY_DEFAULT_OPTIONS } from '../constants'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyManager,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\n/**\n * A Lit ReactiveController that registers a keyboard hotkey when the host\n * element is connected and unregisters it when the host is disconnected.\n *\n * @example\n * ```ts\n * class MyElement extends LitElement {\n * private hotkey = new HotkeyController(this, 'Mod+S', () => this.save())\n *\n * constructor() {\n * super()\n * this.addController(this.hotkey)\n * }\n * }\n * ```\n */\nexport class HotkeyController implements ReactiveController {\n /** The hotkey registration handle. */\n private _registration: HotkeyRegistrationHandle | undefined\n\n /**\n * @param _host - The Lit component that owns this controller (use `this` and pass it to `addController()`).\n * @param _hotkey - The key or key combo to listen for (e.g. `'Mod+S'` or a raw hotkey object).\n * @param _callback - Function to run when the hotkey is pressed; called with the host as `this`.\n * @param _options - Optional registration options (target, platform, enabled, etc.).\n */\n constructor(\n private _host: ReactiveControllerHost,\n private _hotkey: RegisterableHotkey,\n private _callback: HotkeyCallback,\n private _options: HotkeyOptions = HOTKEY_DEFAULT_OPTIONS,\n ) {}\n\n /**\n * Registers the hotkey with the global manager when the host is connected to the DOM.\n * Skips registration if no target is available (e.g. no document or options.target is null).\n */\n public hostConnected(): void {\n const manager: HotkeyManager = getHotkeyManager()\n\n const platform = this._options.platform ?? detectPlatform()\n const hotkeyString: Hotkey =\n typeof this._hotkey === 'string'\n ? this._hotkey\n : (formatHotkey(\n rawHotkeyToParsedHotkey(this._hotkey, platform),\n ) as Hotkey)\n\n const hasExplicitTarget = 'target' in this._options\n const resolvedTarget = hasExplicitTarget\n ? (this._options.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n return\n }\n\n const { target: _target, ...optionsWithoutTarget } = this._options\n\n const boundCallback: HotkeyCallback = this._callback.bind(\n this._host as unknown as object,\n )\n\n this._registration = manager.register(hotkeyString, boundCallback, {\n ...optionsWithoutTarget,\n target: resolvedTarget,\n })\n }\n\n /** Unregisters the hotkey when the host is disconnected from the DOM. */\n public hostDisconnected(): void {\n if (this._registration?.isActive) {\n this._registration.unregister()\n }\n this._registration = undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiCA,IAAa,mBAAb,MAA4D;;;;;;;CAU1D,YACE,AAAQ,OACR,AAAQ,SACR,AAAQ,WACR,AAAQ,WAA0BA,0CAClC;EAJQ;EACA;EACA;EACA;;;;;;CAOV,AAAO,gBAAsB;EAC3B,MAAM,mDAA2C;EAEjD,MAAM,WAAW,KAAK,SAAS,mDAA4B;EAC3D,MAAM,eACJ,OAAO,KAAK,YAAY,WACpB,KAAK,6FAEqB,KAAK,SAAS,SAAS,CAChD;EAGP,MAAM,iBADoB,YAAY,KAAK,WAEtC,KAAK,SAAS,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAEN,MAAI,CAAC,eACH;EAGF,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,KAAK;EAE1D,MAAM,gBAAgC,KAAK,UAAU,KACnD,KAAK,MACN;AAED,OAAK,gBAAgB,QAAQ,SAAS,cAAc,eAAe;GACjE,GAAG;GACH,QAAQ;GACT,CAAC;;;CAIJ,AAAO,mBAAyB;AAC9B,MAAI,KAAK,eAAe,SACtB,MAAK,cAAc,YAAY;AAEjC,OAAK,gBAAgB"}
@@ -1,45 +0,0 @@
1
- import { HotkeyCallback, HotkeyOptions, RegisterableHotkey } from "@tanstack/hotkeys";
2
- import { ReactiveController, ReactiveControllerHost } from "lit";
3
-
4
- //#region src/controllers/hotkey.d.ts
5
- /**
6
- * A Lit ReactiveController that registers a keyboard hotkey when the host
7
- * element is connected and unregisters it when the host is disconnected.
8
- *
9
- * @example
10
- * ```ts
11
- * class MyElement extends LitElement {
12
- * private hotkey = new HotkeyController(this, 'Mod+S', () => this.save())
13
- *
14
- * constructor() {
15
- * super()
16
- * this.addController(this.hotkey)
17
- * }
18
- * }
19
- * ```
20
- */
21
- declare class HotkeyController implements ReactiveController {
22
- private _host;
23
- private _hotkey;
24
- private _callback;
25
- private _options;
26
- /** The hotkey registration handle. */
27
- private _registration;
28
- /**
29
- * @param _host - The Lit component that owns this controller (use `this` and pass it to `addController()`).
30
- * @param _hotkey - The key or key combo to listen for (e.g. `'Mod+S'` or a raw hotkey object).
31
- * @param _callback - Function to run when the hotkey is pressed; called with the host as `this`.
32
- * @param _options - Optional registration options (target, platform, enabled, etc.).
33
- */
34
- constructor(_host: ReactiveControllerHost, _hotkey: RegisterableHotkey, _callback: HotkeyCallback, _options?: HotkeyOptions);
35
- /**
36
- * Registers the hotkey with the global manager when the host is connected to the DOM.
37
- * Skips registration if no target is available (e.g. no document or options.target is null).
38
- */
39
- hostConnected(): void;
40
- /** Unregisters the hotkey when the host is disconnected from the DOM. */
41
- hostDisconnected(): void;
42
- }
43
- //#endregion
44
- export { HotkeyController };
45
- //# sourceMappingURL=hotkey.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hotkey.js","names":[],"sources":["../../src/controllers/hotkey.ts"],"sourcesContent":["import {\n detectPlatform,\n formatHotkey,\n getHotkeyManager,\n rawHotkeyToParsedHotkey,\n} from '@tanstack/hotkeys'\nimport { HOTKEY_DEFAULT_OPTIONS } from '../constants'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type {\n Hotkey,\n HotkeyCallback,\n HotkeyManager,\n HotkeyOptions,\n HotkeyRegistrationHandle,\n RegisterableHotkey,\n} from '@tanstack/hotkeys'\n\n/**\n * A Lit ReactiveController that registers a keyboard hotkey when the host\n * element is connected and unregisters it when the host is disconnected.\n *\n * @example\n * ```ts\n * class MyElement extends LitElement {\n * private hotkey = new HotkeyController(this, 'Mod+S', () => this.save())\n *\n * constructor() {\n * super()\n * this.addController(this.hotkey)\n * }\n * }\n * ```\n */\nexport class HotkeyController implements ReactiveController {\n /** The hotkey registration handle. */\n private _registration: HotkeyRegistrationHandle | undefined\n\n /**\n * @param _host - The Lit component that owns this controller (use `this` and pass it to `addController()`).\n * @param _hotkey - The key or key combo to listen for (e.g. `'Mod+S'` or a raw hotkey object).\n * @param _callback - Function to run when the hotkey is pressed; called with the host as `this`.\n * @param _options - Optional registration options (target, platform, enabled, etc.).\n */\n constructor(\n private _host: ReactiveControllerHost,\n private _hotkey: RegisterableHotkey,\n private _callback: HotkeyCallback,\n private _options: HotkeyOptions = HOTKEY_DEFAULT_OPTIONS,\n ) {}\n\n /**\n * Registers the hotkey with the global manager when the host is connected to the DOM.\n * Skips registration if no target is available (e.g. no document or options.target is null).\n */\n public hostConnected(): void {\n const manager: HotkeyManager = getHotkeyManager()\n\n const platform = this._options.platform ?? detectPlatform()\n const hotkeyString: Hotkey =\n typeof this._hotkey === 'string'\n ? this._hotkey\n : (formatHotkey(\n rawHotkeyToParsedHotkey(this._hotkey, platform),\n ) as Hotkey)\n\n const hasExplicitTarget = 'target' in this._options\n const resolvedTarget = hasExplicitTarget\n ? (this._options.target ?? null)\n : typeof document !== 'undefined'\n ? document\n : null\n\n if (!resolvedTarget) {\n return\n }\n\n const { target: _target, ...optionsWithoutTarget } = this._options\n\n const boundCallback: HotkeyCallback = this._callback.bind(\n this._host as unknown as object,\n )\n\n this._registration = manager.register(hotkeyString, boundCallback, {\n ...optionsWithoutTarget,\n target: resolvedTarget,\n })\n }\n\n /** Unregisters the hotkey when the host is disconnected from the DOM. */\n public hostDisconnected(): void {\n if (this._registration?.isActive) {\n this._registration.unregister()\n }\n this._registration = undefined\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAiCA,IAAa,mBAAb,MAA4D;;;;;;;CAU1D,YACE,AAAQ,OACR,AAAQ,SACR,AAAQ,WACR,AAAQ,WAA0B,wBAClC;EAJQ;EACA;EACA;EACA;;;;;;CAOV,AAAO,gBAAsB;EAC3B,MAAM,UAAyB,kBAAkB;EAEjD,MAAM,WAAW,KAAK,SAAS,YAAY,gBAAgB;EAC3D,MAAM,eACJ,OAAO,KAAK,YAAY,WACpB,KAAK,UACJ,aACC,wBAAwB,KAAK,SAAS,SAAS,CAChD;EAGP,MAAM,iBADoB,YAAY,KAAK,WAEtC,KAAK,SAAS,UAAU,OACzB,OAAO,aAAa,cAClB,WACA;AAEN,MAAI,CAAC,eACH;EAGF,MAAM,EAAE,QAAQ,SAAS,GAAG,yBAAyB,KAAK;EAE1D,MAAM,gBAAgC,KAAK,UAAU,KACnD,KAAK,MACN;AAED,OAAK,gBAAgB,QAAQ,SAAS,cAAc,eAAe;GACjE,GAAG;GACH,QAAQ;GACT,CAAC;;;CAIJ,AAAO,mBAAyB;AAC9B,MAAI,KAAK,eAAe,SACtB,MAAK,cAAc,YAAY;AAEjC,OAAK,gBAAgB"}
@@ -1,9 +0,0 @@
1
- import { HeldKeyCodesController } from "./held-key-codes.cjs";
2
- import { HeldKeysController } from "./held-keys.cjs";
3
- import { HotkeyController } from "./hotkey.cjs";
4
- import { HotkeyRecorderController } from "./hotkey-recorder.cjs";
5
- import { HotkeyRegistrationsController } from "./hotkey-registrations.cjs";
6
- import { HotkeySequenceController } from "./hotkey-sequence.cjs";
7
- import { HotkeySequenceRecorderController } from "./hotkey-sequence-recorder.cjs";
8
- import { KeyHoldController } from "./key-hold.cjs";
9
- import { HotkeyHintController } from "./hotkey-hint.cjs";
@@ -1,78 +0,0 @@
1
- let _tanstack_hotkeys = require("@tanstack/hotkeys");
2
-
3
- //#region src/controllers/key-hold.ts
4
- /**
5
- * A Lit ReactiveController that tracks whether a specific key is currently held.
6
- *
7
- * Subscribes to the global KeyStateTracker and triggers host updates
8
- * when the held state of the specified key changes.
9
- *
10
- * @example
11
- * ```ts
12
- * class MyElement extends LitElement {
13
- * private shiftHold = new KeyHoldController(this, 'Shift')
14
- *
15
- * render() {
16
- * return html`
17
- * <div style="opacity: ${this.shiftHold.value ? 1 : 0.5}">
18
- * ${this.shiftHold.value ? 'Shift is pressed!' : 'Press Shift'}
19
- * </div>
20
- * `
21
- * }
22
- * }
23
- * ```
24
- *
25
- * @example
26
- * ```ts
27
- * class ModifierIndicators extends LitElement {
28
- * private ctrl = new KeyHoldController(this, 'Control')
29
- * private shift = new KeyHoldController(this, 'Shift')
30
- * private alt = new KeyHoldController(this, 'Alt')
31
- *
32
- * render() {
33
- * return html`
34
- * <span style="opacity: ${this.ctrl.value ? 1 : 0.3}">Ctrl</span>
35
- * <span style="opacity: ${this.shift.value ? 1 : 0.3}">Shift</span>
36
- * <span style="opacity: ${this.alt.value ? 1 : 0.3}">Alt</span>
37
- * `
38
- * }
39
- * }
40
- * ```
41
- */
42
- var KeyHoldController = class {
43
- /** Whether the tracked key is currently held down. */
44
- get value() {
45
- return this._value;
46
- }
47
- /**
48
- * @param host - The Lit component that owns this controller.
49
- * @param key - The key to track (e.g. 'Shift', 'Control', 'A').
50
- */
51
- constructor(_host, _key) {
52
- this._host = _host;
53
- this._key = _key;
54
- this._value = false;
55
- this._host.addController(this);
56
- }
57
- hostConnected() {
58
- const tracker = (0, _tanstack_hotkeys.getKeyStateTracker)();
59
- const normalizedKey = this._key.toLowerCase();
60
- const subscription = tracker.store.subscribe(() => {
61
- const isHeld = tracker.store.state.heldKeys.some((heldKey) => heldKey.toLowerCase() === normalizedKey);
62
- if (isHeld !== this._value) {
63
- this._value = isHeld;
64
- this._host.requestUpdate();
65
- }
66
- });
67
- this._unsubscribe = () => subscription.unsubscribe();
68
- }
69
- hostDisconnected() {
70
- this._unsubscribe?.();
71
- this._unsubscribe = void 0;
72
- this._value = false;
73
- }
74
- };
75
-
76
- //#endregion
77
- exports.KeyHoldController = KeyHoldController;
78
- //# sourceMappingURL=key-hold.cjs.map
@@ -1 +0,0 @@
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"}