@tanstack/lit-hotkeys 0.13.1 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/controllers/_app-hotkeys.js +11 -0
- package/dist/controllers/app-hotkeys.d.ts +48 -0
- package/dist/controllers/app-hotkeys.js +84 -0
- package/dist/controllers/hotkey-hint.d.ts +2 -2
- package/dist/controllers/hotkey-hint.js +13 -5
- package/dist/controllers/hotkey-recorder.d.ts +22 -9
- package/dist/controllers/hotkey-recorder.js +28 -15
- package/dist/controllers/hotkey-registrations.d.ts +11 -18
- package/dist/controllers/hotkey-registrations.js +19 -37
- package/dist/controllers/hotkey.d.ts +44 -18
- package/dist/controllers/hotkey.js +44 -35
- package/dist/controllers/index.d.ts +3 -4
- package/dist/controllers/key-hold.d.ts +2 -2
- package/dist/controllers/key-hold.js +2 -2
- package/dist/decorators/hotkey.d.ts +11 -7
- package/dist/decorators/hotkey.js +1 -21
- package/dist/decorators/index.d.ts +1 -2
- package/dist/index.d.ts +3 -5
- package/dist/index.js +2 -4
- package/package.json +2 -2
- package/dist/constants.js +0 -24
- package/dist/controllers/hotkey-sequence-recorder.d.ts +0 -80
- package/dist/controllers/hotkey-sequence-recorder.js +0 -125
- package/dist/controllers/hotkey-sequence.d.ts +0 -42
- package/dist/controllers/hotkey-sequence.js +0 -63
- package/dist/decorators/hotkey-sequence.d.ts +0 -25
- package/dist/decorators/hotkey-sequence.js +0 -44
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { HOTKEY_SEQUENCE_DEFAULT_OPTIONS } from "../constants.js";
|
|
2
|
-
import { HotkeySequenceController } from "../controllers/hotkey-sequence.js";
|
|
3
|
-
|
|
4
|
-
//#region src/decorators/hotkey-sequence.ts
|
|
5
|
-
/**
|
|
6
|
-
* Decorator that registers a keyboard sequence (e.g. Vim-style) on the element
|
|
7
|
-
* when it connects and unregisters when it disconnects. Uses
|
|
8
|
-
* {@link HotkeySequenceController} under the hood.
|
|
9
|
-
*
|
|
10
|
-
* @param sequence - The key sequence to listen for (e.g. `['G', 'G']` for "g g").
|
|
11
|
-
* @param options - Optional sequence options (target, timeout, enabled, etc.).
|
|
12
|
-
* @returns A method decorator for use on LitElement methods.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* class MyElement extends LitElement {
|
|
17
|
-
* @hotkeySequence(['G', 'G'])
|
|
18
|
-
* goToTop() { window.scrollTo(0, 0) }
|
|
19
|
-
*
|
|
20
|
-
* @hotkeySequence(['D', 'D'], { timeout: 500 })
|
|
21
|
-
* deleteLine() { this.deleteCurrentLine() }
|
|
22
|
-
* }
|
|
23
|
-
* ```
|
|
24
|
-
*/
|
|
25
|
-
function hotkeySequence(sequence, options = HOTKEY_SEQUENCE_DEFAULT_OPTIONS) {
|
|
26
|
-
return function(proto, methodName, descriptor) {
|
|
27
|
-
const originalConnected = proto.connectedCallback;
|
|
28
|
-
const controllerKey = Symbol(`@hotkeySequence:${methodName}`);
|
|
29
|
-
proto.connectedCallback = function() {
|
|
30
|
-
originalConnected.call(this);
|
|
31
|
-
const host = this;
|
|
32
|
-
if (!host[controllerKey]) {
|
|
33
|
-
const callback = descriptor.value ? descriptor.value.bind(this) : host[methodName].bind(this);
|
|
34
|
-
if (typeof callback !== "function") throw new Error(`@hotkeySequence decorator can only be applied to functions`);
|
|
35
|
-
const controller = new HotkeySequenceController(this, sequence, callback, options);
|
|
36
|
-
host[controllerKey] = controller;
|
|
37
|
-
this.addController(controller);
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
//#endregion
|
|
44
|
-
export { hotkeySequence };
|