@tanstack/lit-hotkeys 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +123 -0
- package/dist/constants.cjs +27 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/constants.js +25 -0
- package/dist/constants.js.map +1 -0
- package/dist/controllers/held-key-codes.cjs +61 -0
- package/dist/controllers/held-key-codes.cjs.map +1 -0
- package/dist/controllers/held-key-codes.d.cts +45 -0
- package/dist/controllers/held-key-codes.d.ts +45 -0
- package/dist/controllers/held-key-codes.js +61 -0
- package/dist/controllers/held-key-codes.js.map +1 -0
- package/dist/controllers/held-keys.cjs +58 -0
- package/dist/controllers/held-keys.cjs.map +1 -0
- package/dist/controllers/held-keys.d.cts +44 -0
- package/dist/controllers/held-keys.d.ts +44 -0
- package/dist/controllers/held-keys.js +58 -0
- package/dist/controllers/held-keys.js.map +1 -0
- package/dist/controllers/hotkey-recorder.cjs +104 -0
- package/dist/controllers/hotkey-recorder.cjs.map +1 -0
- package/dist/controllers/hotkey-recorder.d.cts +75 -0
- package/dist/controllers/hotkey-recorder.d.ts +75 -0
- package/dist/controllers/hotkey-recorder.js +104 -0
- package/dist/controllers/hotkey-recorder.js.map +1 -0
- package/dist/controllers/hotkey-sequence-recorder.cjs +117 -0
- package/dist/controllers/hotkey-sequence-recorder.cjs.map +1 -0
- package/dist/controllers/hotkey-sequence-recorder.d.cts +83 -0
- package/dist/controllers/hotkey-sequence-recorder.d.ts +83 -0
- package/dist/controllers/hotkey-sequence-recorder.js +117 -0
- package/dist/controllers/hotkey-sequence-recorder.js.map +1 -0
- package/dist/controllers/hotkey-sequence.cjs +58 -0
- package/dist/controllers/hotkey-sequence.cjs.map +1 -0
- package/dist/controllers/hotkey-sequence.d.cts +45 -0
- package/dist/controllers/hotkey-sequence.d.ts +45 -0
- package/dist/controllers/hotkey-sequence.js +58 -0
- package/dist/controllers/hotkey-sequence.js.map +1 -0
- package/dist/controllers/hotkey.cjs +60 -0
- package/dist/controllers/hotkey.cjs.map +1 -0
- package/dist/controllers/hotkey.d.cts +45 -0
- package/dist/controllers/hotkey.d.ts +45 -0
- package/dist/controllers/hotkey.js +60 -0
- package/dist/controllers/hotkey.js.map +1 -0
- package/dist/controllers/index.d.cts +7 -0
- package/dist/controllers/index.d.ts +7 -0
- package/dist/controllers/key-hold.cjs +78 -0
- package/dist/controllers/key-hold.cjs.map +1 -0
- package/dist/controllers/key-hold.d.cts +62 -0
- package/dist/controllers/key-hold.d.ts +62 -0
- package/dist/controllers/key-hold.js +78 -0
- package/dist/controllers/key-hold.js.map +1 -0
- package/dist/decorators/hotkey-sequence.cjs +45 -0
- package/dist/decorators/hotkey-sequence.cjs.map +1 -0
- package/dist/decorators/hotkey-sequence.d.cts +28 -0
- package/dist/decorators/hotkey-sequence.d.ts +28 -0
- package/dist/decorators/hotkey-sequence.js +45 -0
- package/dist/decorators/hotkey-sequence.js.map +1 -0
- package/dist/decorators/hotkey.cjs +44 -0
- package/dist/decorators/hotkey.cjs.map +1 -0
- package/dist/decorators/hotkey.d.cts +27 -0
- package/dist/decorators/hotkey.d.ts +27 -0
- package/dist/decorators/hotkey.js +44 -0
- package/dist/decorators/hotkey.js.map +1 -0
- package/dist/decorators/index.d.cts +2 -0
- package/dist/decorators/index.d.ts +2 -0
- package/dist/index.cjs +27 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +13 -0
- package/package.json +60 -0
- package/src/constants.ts +23 -0
- package/src/controllers/held-key-codes.ts +67 -0
- package/src/controllers/held-keys.ts +64 -0
- package/src/controllers/hotkey-recorder.ts +120 -0
- package/src/controllers/hotkey-sequence-recorder.ts +141 -0
- package/src/controllers/hotkey-sequence.ts +82 -0
- package/src/controllers/hotkey.ts +96 -0
- package/src/controllers/index.ts +7 -0
- package/src/controllers/key-hold.ts +88 -0
- package/src/decorators/hotkey-sequence.ts +68 -0
- package/src/decorators/hotkey.ts +70 -0
- package/src/decorators/index.ts +2 -0
- package/src/index.ts +6 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
let _tanstack_hotkeys = require("@tanstack/hotkeys");
|
|
2
|
+
|
|
3
|
+
//#region src/controllers/hotkey-recorder.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Lit ReactiveController that records keyboard shortcuts.
|
|
6
|
+
*
|
|
7
|
+
* Wraps the framework-agnostic `HotkeyRecorder` class, managing all the
|
|
8
|
+
* complexity of capturing keyboard events, converting them to hotkey strings,
|
|
9
|
+
* and handling edge cases like Escape to cancel or Backspace/Delete to clear.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* class ShortcutSettings extends LitElement {
|
|
14
|
+
* private recorder = new HotkeyRecorderController(this, {
|
|
15
|
+
* onRecord: (hotkey) => {
|
|
16
|
+
* this.shortcut = hotkey
|
|
17
|
+
* this.requestUpdate()
|
|
18
|
+
* },
|
|
19
|
+
* onCancel: () => {
|
|
20
|
+
* console.log('Recording cancelled')
|
|
21
|
+
* },
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* private shortcut: Hotkey | null = null
|
|
25
|
+
*
|
|
26
|
+
* render() {
|
|
27
|
+
* return html`
|
|
28
|
+
* <button @click=${() => this.recorder.startRecording()}>
|
|
29
|
+
* ${this.recorder.isRecording ? 'Recording...' : 'Edit Shortcut'}
|
|
30
|
+
* </button>
|
|
31
|
+
* ${this.recorder.recordedHotkey
|
|
32
|
+
* ? html`<div>Recording: ${this.recorder.recordedHotkey}</div>`
|
|
33
|
+
* : nothing}
|
|
34
|
+
* `
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
var HotkeyRecorderController = class {
|
|
40
|
+
/** Whether recording is currently active. */
|
|
41
|
+
get isRecording() {
|
|
42
|
+
return this._isRecording;
|
|
43
|
+
}
|
|
44
|
+
/** The currently recorded hotkey (for live preview). */
|
|
45
|
+
get recordedHotkey() {
|
|
46
|
+
return this._recordedHotkey;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @param _host - The Lit component that owns this controller.
|
|
50
|
+
* @param _options - Configuration options for the recorder.
|
|
51
|
+
*/
|
|
52
|
+
constructor(_host, _options) {
|
|
53
|
+
this._host = _host;
|
|
54
|
+
this._options = _options;
|
|
55
|
+
this._isRecording = false;
|
|
56
|
+
this._recordedHotkey = null;
|
|
57
|
+
this._recorder = new _tanstack_hotkeys.HotkeyRecorder(_options);
|
|
58
|
+
this._host.addController(this);
|
|
59
|
+
}
|
|
60
|
+
/** Subscribes to the recorder store and updates the internal state when changes occur. */
|
|
61
|
+
hostConnected() {
|
|
62
|
+
const subscription = this._recorder.store.subscribe(() => {
|
|
63
|
+
const { isRecording, recordedHotkey } = this._recorder.store.state;
|
|
64
|
+
if (isRecording !== this._isRecording || recordedHotkey !== this._recordedHotkey) {
|
|
65
|
+
this._isRecording = isRecording;
|
|
66
|
+
this._recordedHotkey = recordedHotkey;
|
|
67
|
+
this._host.requestUpdate();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this._unsubscribe = () => subscription.unsubscribe();
|
|
71
|
+
}
|
|
72
|
+
/** Unsubscribes from the recorder store and destroys the recorder instance to prevent memory leaks. */
|
|
73
|
+
hostDisconnected() {
|
|
74
|
+
this._unsubscribe?.();
|
|
75
|
+
this._unsubscribe = void 0;
|
|
76
|
+
this._recorder.stop();
|
|
77
|
+
this._isRecording = false;
|
|
78
|
+
this._recordedHotkey = null;
|
|
79
|
+
}
|
|
80
|
+
/** Updates the recorder options (e.g. callbacks). */
|
|
81
|
+
setOptions(options) {
|
|
82
|
+
this._options = {
|
|
83
|
+
...this._options,
|
|
84
|
+
...options
|
|
85
|
+
};
|
|
86
|
+
this._recorder.setOptions(this._options);
|
|
87
|
+
}
|
|
88
|
+
/** Start recording a new hotkey. */
|
|
89
|
+
startRecording() {
|
|
90
|
+
this._recorder.start();
|
|
91
|
+
}
|
|
92
|
+
/** Stop recording (same as cancel but without calling onCancel). */
|
|
93
|
+
stopRecording() {
|
|
94
|
+
this._recorder.stop();
|
|
95
|
+
}
|
|
96
|
+
/** Cancel recording without saving. */
|
|
97
|
+
cancelRecording() {
|
|
98
|
+
this._recorder.cancel();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
exports.HotkeyRecorderController = HotkeyRecorderController;
|
|
104
|
+
//# sourceMappingURL=hotkey-recorder.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hotkey-recorder.cjs","names":["HotkeyRecorder"],"sources":["../../src/controllers/hotkey-recorder.ts"],"sourcesContent":["import { HotkeyRecorder } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type { Hotkey, HotkeyRecorderOptions } from '@tanstack/hotkeys'\n\n/**\n * A Lit ReactiveController that records keyboard shortcuts.\n *\n * Wraps the framework-agnostic `HotkeyRecorder` class, managing all the\n * complexity of capturing keyboard events, converting them to hotkey strings,\n * and handling edge cases like Escape to cancel or Backspace/Delete to clear.\n *\n * @example\n * ```ts\n * class ShortcutSettings extends LitElement {\n * private recorder = new HotkeyRecorderController(this, {\n * onRecord: (hotkey) => {\n * this.shortcut = hotkey\n * this.requestUpdate()\n * },\n * onCancel: () => {\n * console.log('Recording cancelled')\n * },\n * })\n *\n * private shortcut: Hotkey | null = null\n *\n * render() {\n * return html`\n * <button @click=${() => this.recorder.startRecording()}>\n * ${this.recorder.isRecording ? 'Recording...' : 'Edit Shortcut'}\n * </button>\n * ${this.recorder.recordedHotkey\n * ? html`<div>Recording: ${this.recorder.recordedHotkey}</div>`\n * : nothing}\n * `\n * }\n * }\n * ```\n */\nexport class HotkeyRecorderController implements ReactiveController {\n /** The recorder instance. */\n private _recorder: HotkeyRecorder\n /** The unsubscribe function to unsubscribe from the recorder store. */\n private _unsubscribe: (() => void) | undefined\n /** Whether recording is currently active. */\n private _isRecording = false\n /** The currently recorded hotkey (for live preview). */\n private _recordedHotkey: Hotkey | null = null\n\n /** Whether recording is currently active. */\n public get isRecording(): boolean {\n return this._isRecording\n }\n\n /** The currently recorded hotkey (for live preview). */\n public get recordedHotkey(): Hotkey | null {\n return this._recordedHotkey\n }\n\n /**\n * @param _host - The Lit component that owns this controller.\n * @param _options - Configuration options for the recorder.\n */\n constructor(\n private _host: ReactiveControllerHost,\n private _options: HotkeyRecorderOptions,\n ) {\n this._recorder = new HotkeyRecorder(_options)\n this._host.addController(this)\n }\n\n /** Subscribes to the recorder store and updates the internal state when changes occur. */\n public hostConnected(): void {\n const subscription = this._recorder.store.subscribe(() => {\n const { isRecording, recordedHotkey } = this._recorder.store.state\n\n const hasChanged: boolean =\n isRecording !== this._isRecording ||\n recordedHotkey !== this._recordedHotkey\n\n if (hasChanged) {\n this._isRecording = isRecording\n this._recordedHotkey = recordedHotkey\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._recordedHotkey = null\n }\n\n /** Updates the recorder options (e.g. callbacks). */\n public setOptions(options: Partial<HotkeyRecorderOptions>): void {\n this._options = { ...this._options, ...options }\n this._recorder.setOptions(this._options)\n }\n\n /** Start recording a new hotkey. */\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,2BAAb,MAAoE;;CAWlE,IAAW,cAAuB;AAChC,SAAO,KAAK;;;CAId,IAAW,iBAAgC;AACzC,SAAO,KAAK;;;;;;CAOd,YACE,AAAQ,OACR,AAAQ,UACR;EAFQ;EACA;sBApBa;yBAEkB;AAoBvC,OAAK,YAAY,IAAIA,iCAAe,SAAS;AAC7C,OAAK,MAAM,cAAc,KAAK;;;CAIhC,AAAO,gBAAsB;EAC3B,MAAM,eAAe,KAAK,UAAU,MAAM,gBAAgB;GACxD,MAAM,EAAE,aAAa,mBAAmB,KAAK,UAAU,MAAM;AAM7D,OAHE,gBAAgB,KAAK,gBACrB,mBAAmB,KAAK,iBAEV;AACd,SAAK,eAAe;AACpB,SAAK,kBAAkB;AACvB,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,kBAAkB;;;CAIzB,AAAO,WAAW,SAA+C;AAC/D,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"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Hotkey, HotkeyRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
+
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
3
|
+
|
|
4
|
+
//#region src/controllers/hotkey-recorder.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A Lit ReactiveController that records keyboard shortcuts.
|
|
7
|
+
*
|
|
8
|
+
* Wraps the framework-agnostic `HotkeyRecorder` class, managing all the
|
|
9
|
+
* complexity of capturing keyboard events, converting them to hotkey strings,
|
|
10
|
+
* and handling edge cases like Escape to cancel or Backspace/Delete to clear.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* class ShortcutSettings extends LitElement {
|
|
15
|
+
* private recorder = new HotkeyRecorderController(this, {
|
|
16
|
+
* onRecord: (hotkey) => {
|
|
17
|
+
* this.shortcut = hotkey
|
|
18
|
+
* this.requestUpdate()
|
|
19
|
+
* },
|
|
20
|
+
* onCancel: () => {
|
|
21
|
+
* console.log('Recording cancelled')
|
|
22
|
+
* },
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* private shortcut: Hotkey | null = null
|
|
26
|
+
*
|
|
27
|
+
* render() {
|
|
28
|
+
* return html`
|
|
29
|
+
* <button @click=${() => this.recorder.startRecording()}>
|
|
30
|
+
* ${this.recorder.isRecording ? 'Recording...' : 'Edit Shortcut'}
|
|
31
|
+
* </button>
|
|
32
|
+
* ${this.recorder.recordedHotkey
|
|
33
|
+
* ? html`<div>Recording: ${this.recorder.recordedHotkey}</div>`
|
|
34
|
+
* : nothing}
|
|
35
|
+
* `
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare class HotkeyRecorderController implements ReactiveController {
|
|
41
|
+
private _host;
|
|
42
|
+
private _options;
|
|
43
|
+
/** The recorder instance. */
|
|
44
|
+
private _recorder;
|
|
45
|
+
/** The unsubscribe function to unsubscribe from the recorder store. */
|
|
46
|
+
private _unsubscribe;
|
|
47
|
+
/** Whether recording is currently active. */
|
|
48
|
+
private _isRecording;
|
|
49
|
+
/** The currently recorded hotkey (for live preview). */
|
|
50
|
+
private _recordedHotkey;
|
|
51
|
+
/** Whether recording is currently active. */
|
|
52
|
+
get isRecording(): boolean;
|
|
53
|
+
/** The currently recorded hotkey (for live preview). */
|
|
54
|
+
get recordedHotkey(): Hotkey | null;
|
|
55
|
+
/**
|
|
56
|
+
* @param _host - The Lit component that owns this controller.
|
|
57
|
+
* @param _options - Configuration options for the recorder.
|
|
58
|
+
*/
|
|
59
|
+
constructor(_host: ReactiveControllerHost, _options: HotkeyRecorderOptions);
|
|
60
|
+
/** Subscribes to the recorder store and updates the internal state when changes occur. */
|
|
61
|
+
hostConnected(): void;
|
|
62
|
+
/** Unsubscribes from the recorder store and destroys the recorder instance to prevent memory leaks. */
|
|
63
|
+
hostDisconnected(): void;
|
|
64
|
+
/** Updates the recorder options (e.g. callbacks). */
|
|
65
|
+
setOptions(options: Partial<HotkeyRecorderOptions>): void;
|
|
66
|
+
/** Start recording a new hotkey. */
|
|
67
|
+
startRecording(): void;
|
|
68
|
+
/** Stop recording (same as cancel but without calling onCancel). */
|
|
69
|
+
stopRecording(): void;
|
|
70
|
+
/** Cancel recording without saving. */
|
|
71
|
+
cancelRecording(): void;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { HotkeyRecorderController };
|
|
75
|
+
//# sourceMappingURL=hotkey-recorder.d.cts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Hotkey, HotkeyRecorderOptions } from "@tanstack/hotkeys";
|
|
2
|
+
import { ReactiveController, ReactiveControllerHost } from "lit";
|
|
3
|
+
|
|
4
|
+
//#region src/controllers/hotkey-recorder.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* A Lit ReactiveController that records keyboard shortcuts.
|
|
7
|
+
*
|
|
8
|
+
* Wraps the framework-agnostic `HotkeyRecorder` class, managing all the
|
|
9
|
+
* complexity of capturing keyboard events, converting them to hotkey strings,
|
|
10
|
+
* and handling edge cases like Escape to cancel or Backspace/Delete to clear.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* class ShortcutSettings extends LitElement {
|
|
15
|
+
* private recorder = new HotkeyRecorderController(this, {
|
|
16
|
+
* onRecord: (hotkey) => {
|
|
17
|
+
* this.shortcut = hotkey
|
|
18
|
+
* this.requestUpdate()
|
|
19
|
+
* },
|
|
20
|
+
* onCancel: () => {
|
|
21
|
+
* console.log('Recording cancelled')
|
|
22
|
+
* },
|
|
23
|
+
* })
|
|
24
|
+
*
|
|
25
|
+
* private shortcut: Hotkey | null = null
|
|
26
|
+
*
|
|
27
|
+
* render() {
|
|
28
|
+
* return html`
|
|
29
|
+
* <button @click=${() => this.recorder.startRecording()}>
|
|
30
|
+
* ${this.recorder.isRecording ? 'Recording...' : 'Edit Shortcut'}
|
|
31
|
+
* </button>
|
|
32
|
+
* ${this.recorder.recordedHotkey
|
|
33
|
+
* ? html`<div>Recording: ${this.recorder.recordedHotkey}</div>`
|
|
34
|
+
* : nothing}
|
|
35
|
+
* `
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
declare class HotkeyRecorderController implements ReactiveController {
|
|
41
|
+
private _host;
|
|
42
|
+
private _options;
|
|
43
|
+
/** The recorder instance. */
|
|
44
|
+
private _recorder;
|
|
45
|
+
/** The unsubscribe function to unsubscribe from the recorder store. */
|
|
46
|
+
private _unsubscribe;
|
|
47
|
+
/** Whether recording is currently active. */
|
|
48
|
+
private _isRecording;
|
|
49
|
+
/** The currently recorded hotkey (for live preview). */
|
|
50
|
+
private _recordedHotkey;
|
|
51
|
+
/** Whether recording is currently active. */
|
|
52
|
+
get isRecording(): boolean;
|
|
53
|
+
/** The currently recorded hotkey (for live preview). */
|
|
54
|
+
get recordedHotkey(): Hotkey | null;
|
|
55
|
+
/**
|
|
56
|
+
* @param _host - The Lit component that owns this controller.
|
|
57
|
+
* @param _options - Configuration options for the recorder.
|
|
58
|
+
*/
|
|
59
|
+
constructor(_host: ReactiveControllerHost, _options: HotkeyRecorderOptions);
|
|
60
|
+
/** Subscribes to the recorder store and updates the internal state when changes occur. */
|
|
61
|
+
hostConnected(): void;
|
|
62
|
+
/** Unsubscribes from the recorder store and destroys the recorder instance to prevent memory leaks. */
|
|
63
|
+
hostDisconnected(): void;
|
|
64
|
+
/** Updates the recorder options (e.g. callbacks). */
|
|
65
|
+
setOptions(options: Partial<HotkeyRecorderOptions>): void;
|
|
66
|
+
/** Start recording a new hotkey. */
|
|
67
|
+
startRecording(): void;
|
|
68
|
+
/** Stop recording (same as cancel but without calling onCancel). */
|
|
69
|
+
stopRecording(): void;
|
|
70
|
+
/** Cancel recording without saving. */
|
|
71
|
+
cancelRecording(): void;
|
|
72
|
+
}
|
|
73
|
+
//#endregion
|
|
74
|
+
export { HotkeyRecorderController };
|
|
75
|
+
//# sourceMappingURL=hotkey-recorder.d.ts.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { HotkeyRecorder } from "@tanstack/hotkeys";
|
|
2
|
+
|
|
3
|
+
//#region src/controllers/hotkey-recorder.ts
|
|
4
|
+
/**
|
|
5
|
+
* A Lit ReactiveController that records keyboard shortcuts.
|
|
6
|
+
*
|
|
7
|
+
* Wraps the framework-agnostic `HotkeyRecorder` class, managing all the
|
|
8
|
+
* complexity of capturing keyboard events, converting them to hotkey strings,
|
|
9
|
+
* and handling edge cases like Escape to cancel or Backspace/Delete to clear.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* class ShortcutSettings extends LitElement {
|
|
14
|
+
* private recorder = new HotkeyRecorderController(this, {
|
|
15
|
+
* onRecord: (hotkey) => {
|
|
16
|
+
* this.shortcut = hotkey
|
|
17
|
+
* this.requestUpdate()
|
|
18
|
+
* },
|
|
19
|
+
* onCancel: () => {
|
|
20
|
+
* console.log('Recording cancelled')
|
|
21
|
+
* },
|
|
22
|
+
* })
|
|
23
|
+
*
|
|
24
|
+
* private shortcut: Hotkey | null = null
|
|
25
|
+
*
|
|
26
|
+
* render() {
|
|
27
|
+
* return html`
|
|
28
|
+
* <button @click=${() => this.recorder.startRecording()}>
|
|
29
|
+
* ${this.recorder.isRecording ? 'Recording...' : 'Edit Shortcut'}
|
|
30
|
+
* </button>
|
|
31
|
+
* ${this.recorder.recordedHotkey
|
|
32
|
+
* ? html`<div>Recording: ${this.recorder.recordedHotkey}</div>`
|
|
33
|
+
* : nothing}
|
|
34
|
+
* `
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
var HotkeyRecorderController = class {
|
|
40
|
+
/** Whether recording is currently active. */
|
|
41
|
+
get isRecording() {
|
|
42
|
+
return this._isRecording;
|
|
43
|
+
}
|
|
44
|
+
/** The currently recorded hotkey (for live preview). */
|
|
45
|
+
get recordedHotkey() {
|
|
46
|
+
return this._recordedHotkey;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* @param _host - The Lit component that owns this controller.
|
|
50
|
+
* @param _options - Configuration options for the recorder.
|
|
51
|
+
*/
|
|
52
|
+
constructor(_host, _options) {
|
|
53
|
+
this._host = _host;
|
|
54
|
+
this._options = _options;
|
|
55
|
+
this._isRecording = false;
|
|
56
|
+
this._recordedHotkey = null;
|
|
57
|
+
this._recorder = new HotkeyRecorder(_options);
|
|
58
|
+
this._host.addController(this);
|
|
59
|
+
}
|
|
60
|
+
/** Subscribes to the recorder store and updates the internal state when changes occur. */
|
|
61
|
+
hostConnected() {
|
|
62
|
+
const subscription = this._recorder.store.subscribe(() => {
|
|
63
|
+
const { isRecording, recordedHotkey } = this._recorder.store.state;
|
|
64
|
+
if (isRecording !== this._isRecording || recordedHotkey !== this._recordedHotkey) {
|
|
65
|
+
this._isRecording = isRecording;
|
|
66
|
+
this._recordedHotkey = recordedHotkey;
|
|
67
|
+
this._host.requestUpdate();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
this._unsubscribe = () => subscription.unsubscribe();
|
|
71
|
+
}
|
|
72
|
+
/** Unsubscribes from the recorder store and destroys the recorder instance to prevent memory leaks. */
|
|
73
|
+
hostDisconnected() {
|
|
74
|
+
this._unsubscribe?.();
|
|
75
|
+
this._unsubscribe = void 0;
|
|
76
|
+
this._recorder.stop();
|
|
77
|
+
this._isRecording = false;
|
|
78
|
+
this._recordedHotkey = null;
|
|
79
|
+
}
|
|
80
|
+
/** Updates the recorder options (e.g. callbacks). */
|
|
81
|
+
setOptions(options) {
|
|
82
|
+
this._options = {
|
|
83
|
+
...this._options,
|
|
84
|
+
...options
|
|
85
|
+
};
|
|
86
|
+
this._recorder.setOptions(this._options);
|
|
87
|
+
}
|
|
88
|
+
/** Start recording a new hotkey. */
|
|
89
|
+
startRecording() {
|
|
90
|
+
this._recorder.start();
|
|
91
|
+
}
|
|
92
|
+
/** Stop recording (same as cancel but without calling onCancel). */
|
|
93
|
+
stopRecording() {
|
|
94
|
+
this._recorder.stop();
|
|
95
|
+
}
|
|
96
|
+
/** Cancel recording without saving. */
|
|
97
|
+
cancelRecording() {
|
|
98
|
+
this._recorder.cancel();
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
export { HotkeyRecorderController };
|
|
104
|
+
//# sourceMappingURL=hotkey-recorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hotkey-recorder.js","names":[],"sources":["../../src/controllers/hotkey-recorder.ts"],"sourcesContent":["import { HotkeyRecorder } from '@tanstack/hotkeys'\nimport type { ReactiveController, ReactiveControllerHost } from 'lit'\nimport type { Hotkey, HotkeyRecorderOptions } from '@tanstack/hotkeys'\n\n/**\n * A Lit ReactiveController that records keyboard shortcuts.\n *\n * Wraps the framework-agnostic `HotkeyRecorder` class, managing all the\n * complexity of capturing keyboard events, converting them to hotkey strings,\n * and handling edge cases like Escape to cancel or Backspace/Delete to clear.\n *\n * @example\n * ```ts\n * class ShortcutSettings extends LitElement {\n * private recorder = new HotkeyRecorderController(this, {\n * onRecord: (hotkey) => {\n * this.shortcut = hotkey\n * this.requestUpdate()\n * },\n * onCancel: () => {\n * console.log('Recording cancelled')\n * },\n * })\n *\n * private shortcut: Hotkey | null = null\n *\n * render() {\n * return html`\n * <button @click=${() => this.recorder.startRecording()}>\n * ${this.recorder.isRecording ? 'Recording...' : 'Edit Shortcut'}\n * </button>\n * ${this.recorder.recordedHotkey\n * ? html`<div>Recording: ${this.recorder.recordedHotkey}</div>`\n * : nothing}\n * `\n * }\n * }\n * ```\n */\nexport class HotkeyRecorderController implements ReactiveController {\n /** The recorder instance. */\n private _recorder: HotkeyRecorder\n /** The unsubscribe function to unsubscribe from the recorder store. */\n private _unsubscribe: (() => void) | undefined\n /** Whether recording is currently active. */\n private _isRecording = false\n /** The currently recorded hotkey (for live preview). */\n private _recordedHotkey: Hotkey | null = null\n\n /** Whether recording is currently active. */\n public get isRecording(): boolean {\n return this._isRecording\n }\n\n /** The currently recorded hotkey (for live preview). */\n public get recordedHotkey(): Hotkey | null {\n return this._recordedHotkey\n }\n\n /**\n * @param _host - The Lit component that owns this controller.\n * @param _options - Configuration options for the recorder.\n */\n constructor(\n private _host: ReactiveControllerHost,\n private _options: HotkeyRecorderOptions,\n ) {\n this._recorder = new HotkeyRecorder(_options)\n this._host.addController(this)\n }\n\n /** Subscribes to the recorder store and updates the internal state when changes occur. */\n public hostConnected(): void {\n const subscription = this._recorder.store.subscribe(() => {\n const { isRecording, recordedHotkey } = this._recorder.store.state\n\n const hasChanged: boolean =\n isRecording !== this._isRecording ||\n recordedHotkey !== this._recordedHotkey\n\n if (hasChanged) {\n this._isRecording = isRecording\n this._recordedHotkey = recordedHotkey\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._recordedHotkey = null\n }\n\n /** Updates the recorder options (e.g. callbacks). */\n public setOptions(options: Partial<HotkeyRecorderOptions>): void {\n this._options = { ...this._options, ...options }\n this._recorder.setOptions(this._options)\n }\n\n /** Start recording a new hotkey. */\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,IAAa,2BAAb,MAAoE;;CAWlE,IAAW,cAAuB;AAChC,SAAO,KAAK;;;CAId,IAAW,iBAAgC;AACzC,SAAO,KAAK;;;;;;CAOd,YACE,AAAQ,OACR,AAAQ,UACR;EAFQ;EACA;sBApBa;yBAEkB;AAoBvC,OAAK,YAAY,IAAI,eAAe,SAAS;AAC7C,OAAK,MAAM,cAAc,KAAK;;;CAIhC,AAAO,gBAAsB;EAC3B,MAAM,eAAe,KAAK,UAAU,MAAM,gBAAgB;GACxD,MAAM,EAAE,aAAa,mBAAmB,KAAK,UAAU,MAAM;AAM7D,OAHE,gBAAgB,KAAK,gBACrB,mBAAmB,KAAK,iBAEV;AACd,SAAK,eAAe;AACpB,SAAK,kBAAkB;AACvB,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,kBAAkB;;;CAIzB,AAAO,WAAW,SAA+C;AAC/D,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"}
|
|
@@ -0,0 +1,117 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,83 @@
|
|
|
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
|
|
@@ -0,0 +1,83 @@
|
|
|
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.ts.map
|