@tanstack/alpine-hotkeys 0.2.0 → 0.3.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/dist/createAppHotkeys.js +33 -0
- package/dist/createHotkey.js +3 -2
- package/dist/createHotkeyHint.js +6 -2
- package/dist/createHotkeyRecorder.js +5 -1
- package/dist/createHotkeyRegistrations.js +5 -11
- package/dist/createHotkeys.js +7 -5
- package/dist/createHotkeysScope.d.ts +5 -1
- package/dist/createHotkeysScope.js +10 -8
- package/dist/index.d.ts +2 -3
- package/dist/scope.js +17 -0
- package/dist/types.d.ts +70 -41
- package/package.json +2 -2
- package/dist/createHotkeySequence.js +0 -13
- package/dist/createHotkeySequenceRecorder.js +0 -33
- package/dist/createHotkeySequences.js +0 -16
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
|
|
2
|
+
|
|
3
|
+
//#region src/createAppHotkeys.ts
|
|
4
|
+
function requireStore(scope) {
|
|
5
|
+
const store = scope.appHotkeys();
|
|
6
|
+
if (!store) throw new Error("App hotkeys require provideAppHotkeys()");
|
|
7
|
+
return store;
|
|
8
|
+
}
|
|
9
|
+
function createAppHotkeys(scope) {
|
|
10
|
+
return { get value() {
|
|
11
|
+
return requireStore(scope).appHotkeys;
|
|
12
|
+
} };
|
|
13
|
+
}
|
|
14
|
+
function createAppHotkeyList(scope) {
|
|
15
|
+
const registrations = createHotkeyRegistrations(scope);
|
|
16
|
+
return { get value() {
|
|
17
|
+
return requireStore(scope).getList(registrations.hotkeys);
|
|
18
|
+
} };
|
|
19
|
+
}
|
|
20
|
+
function createCustomHotkeys(scope) {
|
|
21
|
+
return {
|
|
22
|
+
get value() {
|
|
23
|
+
return requireStore(scope).customHotkeys;
|
|
24
|
+
},
|
|
25
|
+
setCustomHotkey: (id, hotkey) => requireStore(scope).setCustomHotkey(id, hotkey),
|
|
26
|
+
resetCustomHotkey: (id) => requireStore(scope).resetCustomHotkey(id),
|
|
27
|
+
resetCustomHotkeys: () => requireStore(scope).resetCustomHotkeys(),
|
|
28
|
+
findConflicts: (id, hotkey) => requireStore(scope).findConflicts(id, hotkey)
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
//#endregion
|
|
33
|
+
export { createAppHotkeyList, createAppHotkeys, createCustomHotkeys };
|
package/dist/createHotkey.js
CHANGED
|
@@ -5,8 +5,9 @@ import { createHotkeys } from "./createHotkeys.js";
|
|
|
5
5
|
function createHotkey(scope, hotkey, callback, options = {}) {
|
|
6
6
|
createHotkeys(scope, () => [{
|
|
7
7
|
hotkey: read(hotkey),
|
|
8
|
-
callback
|
|
9
|
-
|
|
8
|
+
callback,
|
|
9
|
+
options: read(options)
|
|
10
|
+
}]);
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
//#endregion
|
package/dist/createHotkeyHint.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { read } from "./scope.js";
|
|
2
|
-
import { getKeyStateTracker, matchesHeldModifiers } from "@tanstack/hotkeys";
|
|
2
|
+
import { getKeyStateTracker, isAppHotkey, matchesHeldModifiers, resolveAppHotkey } from "@tanstack/hotkeys";
|
|
3
3
|
|
|
4
4
|
//#region src/createHotkeyHint.ts
|
|
5
5
|
function createHotkeyHint(scope, hotkey, options = {}) {
|
|
6
|
-
return scope.select(getKeyStateTracker().store, (state) =>
|
|
6
|
+
return scope.select(getKeyStateTracker().store, (state) => {
|
|
7
|
+
const value = read(hotkey);
|
|
8
|
+
const resolved = isAppHotkey(value) ? resolveAppHotkey(value, scope.appHotkeys()).hotkey : value;
|
|
9
|
+
return resolved !== null && matchesHeldModifiers(resolved, state.heldKeys, read(options));
|
|
10
|
+
});
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
//#endregion
|
|
@@ -14,6 +14,9 @@ function createHotkeyRecorder(scope, options) {
|
|
|
14
14
|
get isRecording() {
|
|
15
15
|
return state.value.isRecording;
|
|
16
16
|
},
|
|
17
|
+
get steps() {
|
|
18
|
+
return state.value.steps;
|
|
19
|
+
},
|
|
17
20
|
get recordedHotkey() {
|
|
18
21
|
return state.value.recordedHotkey;
|
|
19
22
|
},
|
|
@@ -21,7 +24,8 @@ function createHotkeyRecorder(scope, options) {
|
|
|
21
24
|
if (!scope.destroyed) instance.start();
|
|
22
25
|
},
|
|
23
26
|
stopRecording: () => instance.stop(),
|
|
24
|
-
cancelRecording: () => instance.cancel()
|
|
27
|
+
cancelRecording: () => instance.cancel(),
|
|
28
|
+
commitRecording: () => instance.commit()
|
|
25
29
|
};
|
|
26
30
|
}
|
|
27
31
|
|
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import { getHotkeyManager,
|
|
1
|
+
import { getHotkeyManager, toHotkeyRegistrationView } from "@tanstack/hotkeys";
|
|
2
2
|
|
|
3
3
|
//#region src/createHotkeyRegistrations.ts
|
|
4
4
|
function createHotkeyRegistrations(scope) {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return hotkeyState.value;
|
|
10
|
-
},
|
|
11
|
-
get sequences() {
|
|
12
|
-
return sequenceState.value;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
5
|
+
const state = scope.select(getHotkeyManager().registrations, (value) => Array.from(value.values()).map(toHotkeyRegistrationView));
|
|
6
|
+
return { get hotkeys() {
|
|
7
|
+
return state.value;
|
|
8
|
+
} };
|
|
15
9
|
}
|
|
16
10
|
|
|
17
11
|
//#endregion
|
package/dist/createHotkeys.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { read } from "./scope.js";
|
|
2
|
-
import { createHotkeyBindings } from "@tanstack/hotkeys/adapter";
|
|
2
|
+
import { createHotkeyBindings, prepareHotkeyDefinitions } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
|
|
4
4
|
//#region src/createHotkeys.ts
|
|
5
5
|
function createHotkeys(scope, definitions, options = {}) {
|
|
6
6
|
scope.assertActive();
|
|
7
7
|
const bindings = createHotkeyBindings();
|
|
8
8
|
scope.addCleanup(bindings.destroy);
|
|
9
|
-
scope.effect(() => bindings.update(read(definitions), {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
scope.effect(() => bindings.update(prepareHotkeyDefinitions(read(definitions), {
|
|
10
|
+
appHotkeysStore: scope.appHotkeys(),
|
|
11
|
+
defaults: scope.defaultOptions().hotkey,
|
|
12
|
+
commonOptions: read(options),
|
|
13
|
+
resolveTarget: (target) => target
|
|
14
|
+
})));
|
|
13
15
|
}
|
|
14
16
|
|
|
15
17
|
//#endregion
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { AlpineHotkeys, DefaultHotkeysOptions, MaybeGetter } from "./types.js";
|
|
2
2
|
//#region src/createHotkeysScope.d.ts
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Owns Alpine effects and Store subscriptions, with optional shared defaults.
|
|
5
|
+
* App hotkeys come from `provideAppHotkeys`. Call destroy from x-data's
|
|
6
|
+
* destroy hook.
|
|
7
|
+
*/
|
|
4
8
|
export declare function createHotkeysScope(defaultOptions?: MaybeGetter<DefaultHotkeysOptions>): AlpineHotkeys;
|
|
5
9
|
//#endregion
|
|
6
10
|
export type { AlpineHotkeys, DefaultHotkeysOptions, MaybeGetter };
|
|
@@ -1,32 +1,34 @@
|
|
|
1
1
|
import { createScope } from "./scope.js";
|
|
2
2
|
import { createHotkeys } from "./createHotkeys.js";
|
|
3
3
|
import { createHotkey } from "./createHotkey.js";
|
|
4
|
-
import { createHotkeySequences } from "./createHotkeySequences.js";
|
|
5
|
-
import { createHotkeySequence } from "./createHotkeySequence.js";
|
|
6
4
|
import { createHeldKeys } from "./createHeldKeys.js";
|
|
7
5
|
import { createHeldKeyCodes } from "./createHeldKeyCodes.js";
|
|
8
6
|
import { createKeyHold } from "./createKeyHold.js";
|
|
9
7
|
import { createHotkeyHint } from "./createHotkeyHint.js";
|
|
10
8
|
import { createHotkeyRegistrations } from "./createHotkeyRegistrations.js";
|
|
11
9
|
import { createHotkeyRecorder } from "./createHotkeyRecorder.js";
|
|
12
|
-
import {
|
|
10
|
+
import { createAppHotkeyList, createAppHotkeys, createCustomHotkeys } from "./createAppHotkeys.js";
|
|
13
11
|
|
|
14
12
|
//#region src/createHotkeysScope.ts
|
|
15
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Owns Alpine effects and Store subscriptions, with optional shared defaults.
|
|
15
|
+
* App hotkeys come from `provideAppHotkeys`. Call destroy from x-data's
|
|
16
|
+
* destroy hook.
|
|
17
|
+
*/
|
|
16
18
|
function createHotkeysScope(defaultOptions = {}) {
|
|
17
19
|
const scope = createScope(defaultOptions);
|
|
18
20
|
return {
|
|
19
21
|
createHotkey: (...args) => createHotkey(scope, ...args),
|
|
20
22
|
createHotkeys: (...args) => createHotkeys(scope, ...args),
|
|
21
|
-
createHotkeySequence: (...args) => createHotkeySequence(scope, ...args),
|
|
22
|
-
createHotkeySequences: (...args) => createHotkeySequences(scope, ...args),
|
|
23
23
|
createHeldKeys: (...args) => createHeldKeys(scope, ...args),
|
|
24
24
|
createHeldKeyCodes: (...args) => createHeldKeyCodes(scope, ...args),
|
|
25
25
|
createKeyHold: (...args) => createKeyHold(scope, ...args),
|
|
26
26
|
createHotkeyHint: (...args) => createHotkeyHint(scope, ...args),
|
|
27
27
|
createHotkeyRegistrations: (...args) => createHotkeyRegistrations(scope, ...args),
|
|
28
|
-
createHotkeyRecorder: (
|
|
29
|
-
|
|
28
|
+
createHotkeyRecorder: ((options) => createHotkeyRecorder(scope, options)),
|
|
29
|
+
createAppHotkeys: () => createAppHotkeys(scope),
|
|
30
|
+
createAppHotkeyList: () => createAppHotkeyList(scope),
|
|
31
|
+
createCustomHotkeys: () => createCustomHotkeys(scope),
|
|
30
32
|
destroy: scope.destroy
|
|
31
33
|
};
|
|
32
34
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AlpineAppHotkeyOptions, AlpineCreateHotkey, AlpineCreateHotkeyRecorder, AlpineCustomHotkeys, AlpineHotkeyCommonOptions, AlpineHotkeyDefinition, AlpineHotkeyOptionsFor, AlpineHotkeyRecorder, AlpineHotkeyState, AlpineHotkeyTarget, AlpineHotkeys, DefaultHotkeysOptions, HotkeyRegistrationsResult, MaybeGetter } from "./types.js";
|
|
2
2
|
import { createHotkeysScope } from "./createHotkeysScope.js";
|
|
3
3
|
import { hotkeysPlugin } from "./hotkeysPlugin.js";
|
|
4
|
-
import { HotkeyDefinition, HotkeySequenceDefinition } from "@tanstack/hotkeys/adapter";
|
|
5
4
|
export * from "@tanstack/hotkeys";
|
|
6
|
-
export {
|
|
5
|
+
export { AlpineAppHotkeyOptions, AlpineCreateHotkey, AlpineCreateHotkeyRecorder, AlpineCustomHotkeys, AlpineHotkeyCommonOptions, AlpineHotkeyDefinition, AlpineHotkeyOptionsFor, AlpineHotkeyRecorder, AlpineHotkeyState, AlpineHotkeyTarget, AlpineHotkeys, DefaultHotkeysOptions, HotkeyRegistrationsResult, MaybeGetter, createHotkeysScope, hotkeysPlugin };
|
package/dist/scope.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { getHotkeyManager } from "@tanstack/hotkeys";
|
|
1
2
|
import Alpine from "alpinejs";
|
|
3
|
+
import { subscribePublishedAppHotkeys } from "@tanstack/hotkeys/adapter";
|
|
2
4
|
|
|
3
5
|
//#region src/scope.ts
|
|
4
6
|
function read(value) {
|
|
@@ -28,10 +30,25 @@ function createScope(defaultOptions) {
|
|
|
28
30
|
return selector(state.snapshot);
|
|
29
31
|
} };
|
|
30
32
|
}
|
|
33
|
+
let appHotkeysState;
|
|
34
|
+
/**
|
|
35
|
+
* Returns the store published by `provideAppHotkeys`. Reading it inside an
|
|
36
|
+
* effect or reactive getter tracks app hotkey and custom hotkey changes.
|
|
37
|
+
*/
|
|
38
|
+
function appHotkeys() {
|
|
39
|
+
if (!appHotkeysState) {
|
|
40
|
+
const state = Alpine.reactive({ version: 0 });
|
|
41
|
+
appHotkeysState = state;
|
|
42
|
+
cleanups.add(subscribePublishedAppHotkeys(() => state.version++));
|
|
43
|
+
}
|
|
44
|
+
appHotkeysState.version;
|
|
45
|
+
return getHotkeyManager().appHotkeys.state;
|
|
46
|
+
}
|
|
31
47
|
return {
|
|
32
48
|
assertActive,
|
|
33
49
|
effect,
|
|
34
50
|
select,
|
|
51
|
+
appHotkeys,
|
|
35
52
|
defaultOptions: () => read(defaultOptions),
|
|
36
53
|
addCleanup: (cleanup) => cleanups.add(cleanup),
|
|
37
54
|
get destroyed() {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,79 +1,108 @@
|
|
|
1
|
-
import { HeldModifierOptions, Hotkey, HotkeyCallback,
|
|
2
|
-
import {
|
|
1
|
+
import { AppHotkey, AppHotkeyListItem, CustomHotkeys, HeldModifierOptions, Hotkey, HotkeyCallback, HotkeyChord, HotkeyChordRecorderOptions, HotkeyRecorderOptions, HotkeyRegistrationView, HotkeySequence, HotkeySequenceRecorderOptions, IndividualKey, RegisterableHotkey, RegisteredAppHotkeys, Target } from "@tanstack/hotkeys";
|
|
2
|
+
import { AdapterAppHotkeyOptions, AdapterCommonOptions, AdapterHotkeyDefinition, AdapterOptionsFor } from "@tanstack/hotkeys/adapter";
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
/** A reactive value. Read `.value` where the framework tracks dependencies. */
|
|
5
5
|
export interface AlpineHotkeyState<T> {
|
|
6
6
|
readonly value: T;
|
|
7
7
|
}
|
|
8
|
+
/** The element to listen on. A `null` target skips registration until it is set. */
|
|
9
|
+
export type AlpineHotkeyTarget = Target | null;
|
|
10
|
+
/** One hotkey for `createHotkeys`: a chord, a sequence, or an app hotkey. */
|
|
11
|
+
export type AlpineHotkeyDefinition = AdapterHotkeyDefinition<AlpineHotkeyTarget>;
|
|
12
|
+
/** Options for every kind; each applies to the kinds that support it. */
|
|
13
|
+
export type AlpineHotkeyCommonOptions = AdapterCommonOptions<AlpineHotkeyTarget>;
|
|
14
|
+
/** The options type for a hotkey: chord options for chords, sequence options for sequences. */
|
|
15
|
+
export type AlpineHotkeyOptionsFor<T extends RegisterableHotkey> = AdapterOptionsFor<T, AlpineHotkeyTarget>;
|
|
16
|
+
/** Call-site options for an app hotkey, typed by its declared default kind. */
|
|
17
|
+
export type AlpineAppHotkeyOptions<T extends AppHotkey = AppHotkey> = AdapterAppHotkeyOptions<T, AlpineHotkeyTarget>;
|
|
8
18
|
/** Recording state and controls owned by the containing scope. */
|
|
9
|
-
export interface AlpineHotkeyRecorder {
|
|
19
|
+
export interface AlpineHotkeyRecorder<THotkey extends Hotkey = Hotkey> {
|
|
10
20
|
/** Whether the recorder is listening for a shortcut. */
|
|
11
21
|
readonly isRecording: boolean;
|
|
12
|
-
/**
|
|
13
|
-
readonly
|
|
22
|
+
/** Chords captured so far in a multi-step recording. */
|
|
23
|
+
readonly steps: HotkeySequence;
|
|
24
|
+
/** The last committed hotkey, including brackets for physical codes. */
|
|
25
|
+
readonly recordedHotkey: THotkey | null;
|
|
14
26
|
/** Start a new recording session. */
|
|
15
27
|
startRecording: () => void;
|
|
16
28
|
/** Stop and clear recorder state without calling onRecord or onCancel. */
|
|
17
29
|
stopRecording: () => void;
|
|
18
30
|
/** Stop, clear recorder state, and call onCancel. */
|
|
19
31
|
cancelRecording: () => void;
|
|
20
|
-
|
|
21
|
-
/** Sequence recording state and controls. */
|
|
22
|
-
export interface AlpineHotkeySequenceRecorder {
|
|
23
|
-
/** Whether the recorder is listening for chords. */
|
|
24
|
-
readonly isRecording: boolean;
|
|
25
|
-
/** Chords captured in the current session. */
|
|
26
|
-
readonly steps: HotkeySequence;
|
|
27
|
-
/** The last committed sequence. */
|
|
28
|
-
readonly recordedSequence: HotkeySequence | null;
|
|
29
|
-
/** Start a new recording session. */
|
|
30
|
-
startRecording: () => void;
|
|
31
|
-
/** Stop without committing or calling onCancel. */
|
|
32
|
-
stopRecording: () => void;
|
|
33
|
-
/** Discard the current session and call onCancel. */
|
|
34
|
-
cancelRecording: () => void;
|
|
35
|
-
/** Commit the current steps. Does nothing when no steps are recorded. */
|
|
32
|
+
/** Commit the current steps (multi-step recordings). */
|
|
36
33
|
commitRecording: () => void;
|
|
37
34
|
}
|
|
38
|
-
/** Live registration views from the shared hotkey
|
|
35
|
+
/** Live registration views from the shared hotkey manager. */
|
|
39
36
|
export interface HotkeyRegistrationsResult {
|
|
37
|
+
/** Every registration, chords and sequences. Narrow each view with `kind`. */
|
|
40
38
|
readonly hotkeys: Array<HotkeyRegistrationView>;
|
|
41
|
-
|
|
39
|
+
}
|
|
40
|
+
/** Custom hotkey state and actions. */
|
|
41
|
+
export interface AlpineCustomHotkeys {
|
|
42
|
+
/** The user's hotkeys that differ from the defaults. */
|
|
43
|
+
readonly value: CustomHotkeys;
|
|
44
|
+
/**
|
|
45
|
+
* Sets the user's hotkey for an app hotkey. `null` unbinds it.
|
|
46
|
+
* Returns conflicting app hotkeys; when any exist, nothing changes.
|
|
47
|
+
*/
|
|
48
|
+
setCustomHotkey: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey | null) => Array<AppHotkey>;
|
|
49
|
+
/** Restores the default hotkey for an app hotkey. */
|
|
50
|
+
resetCustomHotkey: (id: keyof RegisteredAppHotkeys & string) => void;
|
|
51
|
+
/** Restores every default hotkey. */
|
|
52
|
+
resetCustomHotkeys: () => void;
|
|
53
|
+
/** Other app hotkeys that would collide if `id` used `hotkey`. */
|
|
54
|
+
findConflicts: (id: keyof RegisteredAppHotkeys & string, hotkey: Hotkey) => Array<AppHotkey>;
|
|
42
55
|
}
|
|
43
56
|
/** A value or a getter evaluated within an Alpine effect or reactive read. */
|
|
44
57
|
export type MaybeGetter<T> = T | (() => T);
|
|
58
|
+
/** Registers a hotkey: a chord, a sequence, or an app hotkey. */
|
|
59
|
+
export interface AlpineCreateHotkey {
|
|
60
|
+
<T extends AppHotkey>(hotkey: MaybeGetter<T>, callback: HotkeyCallback, options?: MaybeGetter<AlpineAppHotkeyOptions<T>>): void;
|
|
61
|
+
<T extends RegisterableHotkey>(hotkey: MaybeGetter<T>, callback: HotkeyCallback, options?: MaybeGetter<AlpineHotkeyOptionsFor<T>>): void;
|
|
62
|
+
}
|
|
63
|
+
/** Creates a recorder; `maxSteps` (default 1) selects chords or sequences. */
|
|
64
|
+
export interface AlpineCreateHotkeyRecorder {
|
|
65
|
+
(options: HotkeyChordRecorderOptions): AlpineHotkeyRecorder<HotkeyChord>;
|
|
66
|
+
(options: HotkeySequenceRecorderOptions): AlpineHotkeyRecorder;
|
|
67
|
+
(options: () => HotkeySequenceRecorderOptions): AlpineHotkeyRecorder;
|
|
68
|
+
(options: () => HotkeyChordRecorderOptions): AlpineHotkeyRecorder<HotkeyChord>;
|
|
69
|
+
(options: () => HotkeyRecorderOptions): AlpineHotkeyRecorder;
|
|
70
|
+
}
|
|
45
71
|
/** Registrations, recorders, and reactive state owned by one Alpine component. */
|
|
46
72
|
export interface AlpineHotkeys {
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
createHotkeySequences: (definitions: MaybeGetter<Array<HotkeySequenceDefinition>>, options?: MaybeGetter<SequenceOptions>) => void;
|
|
73
|
+
/**
|
|
74
|
+
* Register one hotkey: a chord such as `'Mod+S'`, a sequence such as
|
|
75
|
+
* `['G', 'G']`, or an app hotkey. Getters track changing hotkeys and options.
|
|
76
|
+
*/
|
|
77
|
+
createHotkey: AlpineCreateHotkey;
|
|
78
|
+
/** Reconcile a list of hotkeys. Definition options override common options. */
|
|
79
|
+
createHotkeys: (definitions: MaybeGetter<ReadonlyArray<AlpineHotkeyDefinition>>, options?: MaybeGetter<AlpineHotkeyCommonOptions>) => void;
|
|
55
80
|
/** Read held logical key names through `.value`. */
|
|
56
81
|
createHeldKeys: () => AlpineHotkeyState<Array<string>>;
|
|
57
82
|
/** Read the mapping of held logical names to physical codes through `.value`. */
|
|
58
83
|
createHeldKeyCodes: () => AlpineHotkeyState<Record<string, string>>;
|
|
59
84
|
/** Read whether a key is held through `.value`. */
|
|
60
85
|
createKeyHold: (key: MaybeGetter<IndividualKey>) => AlpineHotkeyState<boolean>;
|
|
61
|
-
/** Read whether held modifiers reveal a
|
|
62
|
-
createHotkeyHint: (hotkey: MaybeGetter<RegisterableHotkey>, options?: MaybeGetter<HeldModifierOptions>) => AlpineHotkeyState<boolean>;
|
|
63
|
-
/** Read live
|
|
86
|
+
/** Read whether held modifiers reveal a hotkey through `.value`. */
|
|
87
|
+
createHotkeyHint: (hotkey: MaybeGetter<RegisterableHotkey | AppHotkey>, options?: MaybeGetter<HeldModifierOptions>) => AlpineHotkeyState<boolean>;
|
|
88
|
+
/** Read live registrations, including disabled entries. */
|
|
64
89
|
createHotkeyRegistrations: () => HotkeyRegistrationsResult;
|
|
65
90
|
/** Create a recorder whose options can follow Alpine state. */
|
|
66
|
-
createHotkeyRecorder:
|
|
67
|
-
/**
|
|
68
|
-
|
|
91
|
+
createHotkeyRecorder: AlpineCreateHotkeyRecorder;
|
|
92
|
+
/** Read the effective app hotkeys from `provideAppHotkeys` through `.value`. */
|
|
93
|
+
createAppHotkeys: () => AlpineHotkeyState<RegisteredAppHotkeys>;
|
|
94
|
+
/** Read every app hotkey with its live status through `.value`. */
|
|
95
|
+
createAppHotkeyList: () => AlpineHotkeyState<Array<AppHotkeyListItem<RegisteredAppHotkeys[keyof RegisteredAppHotkeys]>>>;
|
|
96
|
+
/** Read and change the user's custom hotkeys. */
|
|
97
|
+
createCustomHotkeys: () => AlpineCustomHotkeys;
|
|
69
98
|
/** Release every registration, subscription, effect, and recorder. Idempotent. */
|
|
70
99
|
destroy: () => void;
|
|
71
100
|
}
|
|
72
101
|
/** Shared defaults; call-specific options take precedence. */
|
|
73
102
|
export interface DefaultHotkeysOptions {
|
|
74
|
-
hotkey
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
103
|
+
/** Defaults for every hotkey. `requireReset` applies to chords and `timeout` to sequences. */
|
|
104
|
+
hotkey?: AlpineHotkeyCommonOptions;
|
|
105
|
+
/** Defaults for every recorder. */
|
|
106
|
+
hotkeyRecorder?: Partial<Omit<HotkeyChordRecorderOptions & HotkeySequenceRecorderOptions, 'maxSteps' | 'onRecord' | 'validate'>>;
|
|
78
107
|
}
|
|
79
108
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/alpine-hotkeys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Alpine adapter for TanStack Hotkeys",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@tanstack/hotkeys": "0.
|
|
36
|
+
"@tanstack/hotkeys": "0.12.1",
|
|
37
37
|
"@tanstack/store": "^0.11.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { read } from "./scope.js";
|
|
2
|
-
import { createHotkeySequences } from "./createHotkeySequences.js";
|
|
3
|
-
|
|
4
|
-
//#region src/createHotkeySequence.ts
|
|
5
|
-
function createHotkeySequence(scope, sequence, callback, options = {}) {
|
|
6
|
-
createHotkeySequences(scope, () => [{
|
|
7
|
-
sequence: read(sequence),
|
|
8
|
-
callback
|
|
9
|
-
}], options);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
//#endregion
|
|
13
|
-
export { createHotkeySequence };
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { read } from "./scope.js";
|
|
2
|
-
import { HotkeySequenceRecorder } from "@tanstack/hotkeys";
|
|
3
|
-
|
|
4
|
-
//#region src/createHotkeySequenceRecorder.ts
|
|
5
|
-
function createHotkeySequenceRecorder(scope, options) {
|
|
6
|
-
scope.assertActive();
|
|
7
|
-
const instance = new HotkeySequenceRecorder(() => ({
|
|
8
|
-
...scope.defaultOptions().hotkeySequenceRecorder,
|
|
9
|
-
...read(options)
|
|
10
|
-
}));
|
|
11
|
-
const state = scope.select(instance.store, (value) => value);
|
|
12
|
-
scope.addCleanup(() => instance.destroy());
|
|
13
|
-
return {
|
|
14
|
-
get isRecording() {
|
|
15
|
-
return state.value.isRecording;
|
|
16
|
-
},
|
|
17
|
-
get steps() {
|
|
18
|
-
return state.value.steps;
|
|
19
|
-
},
|
|
20
|
-
get recordedSequence() {
|
|
21
|
-
return state.value.recordedSequence;
|
|
22
|
-
},
|
|
23
|
-
startRecording: () => {
|
|
24
|
-
if (!scope.destroyed) instance.start();
|
|
25
|
-
},
|
|
26
|
-
stopRecording: () => instance.stop(),
|
|
27
|
-
cancelRecording: () => instance.cancel(),
|
|
28
|
-
commitRecording: () => instance.commit()
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
//#endregion
|
|
33
|
-
export { createHotkeySequenceRecorder };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { read } from "./scope.js";
|
|
2
|
-
import { createHotkeySequenceBindings } from "@tanstack/hotkeys/adapter";
|
|
3
|
-
|
|
4
|
-
//#region src/createHotkeySequences.ts
|
|
5
|
-
function createHotkeySequences(scope, definitions, options = {}) {
|
|
6
|
-
scope.assertActive();
|
|
7
|
-
const bindings = createHotkeySequenceBindings();
|
|
8
|
-
scope.addCleanup(bindings.destroy);
|
|
9
|
-
scope.effect(() => bindings.update(read(definitions), {
|
|
10
|
-
...scope.defaultOptions().hotkeySequence,
|
|
11
|
-
...read(options)
|
|
12
|
-
}));
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
|
-
export { createHotkeySequences };
|