@remcostoeten/use-shortcut 1.3.0 → 2.0.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/CHANGELOG.md +8 -0
- package/README.md +33 -313
- package/dist/cli/index.mjs +88 -216
- package/dist/index.d.mts +39 -68
- package/dist/index.d.ts +39 -68
- package/dist/index.js +350 -361
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +351 -354
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
- package/src/__tests__/features.test.ts +43 -12
- package/src/builder.ts +37 -476
- package/src/constants.ts +59 -13
- package/src/formatter.ts +37 -22
- package/src/hook.ts +150 -31
- package/src/index.ts +1 -12
- package/src/parser.ts +6 -3
- package/src/runtime/binding.ts +136 -0
- package/src/runtime/conflicts.ts +43 -0
- package/src/runtime/debug.ts +6 -0
- package/src/runtime/guards.ts +82 -0
- package/src/runtime/keys.ts +63 -0
- package/src/runtime/listener.ts +142 -0
- package/src/runtime/recording.ts +39 -0
- package/src/runtime/types.ts +48 -0
- package/src/types.ts +16 -19
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
/** Supported runtime OS identifiers used by formatter and parser normalization. */
|
|
2
|
+
declare const OS: {
|
|
3
|
+
readonly MAC: "mac";
|
|
4
|
+
readonly WINDOWS: "windows";
|
|
5
|
+
readonly LINUX: "linux";
|
|
6
|
+
};
|
|
7
|
+
type PlatformType = (typeof OS)[keyof typeof OS];
|
|
8
|
+
/** Public platform constant alias (`Platform.MAC`, `Platform.WINDOWS`, `Platform.LINUX`). */
|
|
1
9
|
declare const Platform: {
|
|
2
10
|
readonly MAC: "mac";
|
|
3
11
|
readonly WINDOWS: "windows";
|
|
4
12
|
readonly LINUX: "linux";
|
|
5
13
|
};
|
|
6
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Detect the current OS platform for modifier normalization and display formatting.
|
|
16
|
+
* Result is memoized for the page lifecycle.
|
|
17
|
+
*/
|
|
7
18
|
declare function detectPlatform(): PlatformType;
|
|
19
|
+
/** Canonical modifier token names used internally across parsing/formatting. */
|
|
8
20
|
declare const ModifierKey: {
|
|
9
21
|
readonly META: "meta";
|
|
10
22
|
readonly CTRL: "ctrl";
|
|
@@ -12,9 +24,13 @@ declare const ModifierKey: {
|
|
|
12
24
|
readonly SHIFT: "shift";
|
|
13
25
|
};
|
|
14
26
|
type ModifierKeyType = (typeof ModifierKey)[keyof typeof ModifierKey];
|
|
27
|
+
/** Alias map from user-facing modifier tokens to canonical modifier keys. */
|
|
15
28
|
declare const ModifierAliases: Record<string, ModifierKeyType>;
|
|
29
|
+
/** Alias map from human shortcut key tokens to `KeyboardEvent.key`-compatible values. */
|
|
16
30
|
declare const SpecialKeyMap: Record<string, string>;
|
|
31
|
+
/** Platform-specific display labels/symbols for modifier keys. */
|
|
17
32
|
declare const ModifierDisplaySymbols: Record<PlatformType, Record<ModifierKeyType, string>>;
|
|
33
|
+
/** Platform-specific canonical order for modifier rendering and combo normalization. */
|
|
18
34
|
declare const ModifierDisplayOrder: Record<PlatformType, ModifierKeyType[]>;
|
|
19
35
|
|
|
20
36
|
/** Lowercase letter keys a-z */
|
|
@@ -77,7 +93,9 @@ type ExceptPredicate = (event: KeyboardEvent) => boolean;
|
|
|
77
93
|
* - "disabled" - Skip when focused element is disabled
|
|
78
94
|
*/
|
|
79
95
|
type ExceptPreset = "input" | "editable" | "typing" | "modal" | "disabled";
|
|
96
|
+
/** Scope selector used to enable/disable subsets of shortcuts at runtime. */
|
|
80
97
|
type ShortcutScope = string | string[];
|
|
98
|
+
/** Conflict metadata emitted when two registered shortcuts overlap. */
|
|
81
99
|
type ShortcutConflict = {
|
|
82
100
|
combo: string;
|
|
83
101
|
existingCombo: string;
|
|
@@ -97,8 +115,6 @@ type HandlerOptions = {
|
|
|
97
115
|
description?: string;
|
|
98
116
|
/** Disable this specific shortcut */
|
|
99
117
|
disabled?: boolean;
|
|
100
|
-
/** Limit shortcut to a specific DOM element */
|
|
101
|
-
scope?: HTMLElement | null;
|
|
102
118
|
/** Conditions to skip the shortcut */
|
|
103
119
|
except?: ExceptPreset | ExceptPreset[] | ExceptPredicate;
|
|
104
120
|
/** Required named scopes that must be active */
|
|
@@ -152,13 +168,13 @@ type ModifierChain<Used extends Partial<ModifierFlags>> = {
|
|
|
152
168
|
mod: Used["cmd"] extends true ? never : ModifierChain<Used & {
|
|
153
169
|
cmd: true;
|
|
154
170
|
}>;
|
|
155
|
-
key: <K extends ActionKey>(key: K) => KeyChain<
|
|
171
|
+
key: <K extends ActionKey>(key: K) => KeyChain<K>;
|
|
156
172
|
in: (scopes: ShortcutScope) => ModifierChain<Used>;
|
|
157
173
|
};
|
|
158
174
|
/**
|
|
159
175
|
* Chain state after calling `.key()` - ready to attach a handler
|
|
160
176
|
*/
|
|
161
|
-
type KeyChain<
|
|
177
|
+
type KeyChain<Key extends string> = {
|
|
162
178
|
/** Attach a handler to this shortcut */
|
|
163
179
|
on: (handler: ShortcutHandler, options?: HandlerOptions) => ShortcutResult;
|
|
164
180
|
/** Attach a handler with inline options */
|
|
@@ -166,20 +182,21 @@ type KeyChain<Used extends Partial<ModifierFlags>, Key extends string> = {
|
|
|
166
182
|
handler: ShortcutHandler;
|
|
167
183
|
}) => ShortcutResult;
|
|
168
184
|
/** Add exception conditions before attaching handler */
|
|
169
|
-
except: (condition: ExceptPreset | ExceptPreset[] | ExceptPredicate) => KeyChainWithExcept<
|
|
185
|
+
except: (condition: ExceptPreset | ExceptPreset[] | ExceptPredicate) => KeyChainWithExcept<Key>;
|
|
170
186
|
/** Add required named scopes */
|
|
171
|
-
in: (scopes: ShortcutScope) => KeyChain<
|
|
187
|
+
in: (scopes: ShortcutScope) => KeyChain<Key>;
|
|
172
188
|
/** Add the next step in a sequence */
|
|
173
|
-
then: <K extends ActionKey | string>(key: K) => KeyChain
|
|
189
|
+
then: <K extends ActionKey | string>(key: K) => KeyChain<`${Key} ${K}`>;
|
|
174
190
|
};
|
|
175
191
|
/**
|
|
176
192
|
* Chain state after calling `.except()` - ready to attach handler
|
|
177
193
|
*/
|
|
178
|
-
type KeyChainWithExcept<
|
|
194
|
+
type KeyChainWithExcept<Key extends string> = {
|
|
179
195
|
on: (handler: ShortcutHandler, options?: Omit<HandlerOptions, "except">) => ShortcutResult;
|
|
180
|
-
in: (scopes: ShortcutScope) => KeyChainWithExcept<
|
|
181
|
-
then: <K extends ActionKey | string>(key: K) => KeyChainWithExcept
|
|
196
|
+
in: (scopes: ShortcutScope) => KeyChainWithExcept<Key>;
|
|
197
|
+
then: <K extends ActionKey | string>(key: K) => KeyChainWithExcept<`${Key} ${K}`>;
|
|
182
198
|
};
|
|
199
|
+
/** Options for `ShortcutBuilder.record()` and low-level recording flows. */
|
|
183
200
|
type ShortcutRecordingOptions = {
|
|
184
201
|
target?: HTMLElement | Window | null;
|
|
185
202
|
eventType?: "keydown" | "keyup";
|
|
@@ -204,7 +221,7 @@ type ShortcutBuilder = ModifierChain<EmptyModifiers> & {
|
|
|
204
221
|
mod: ModifierChain<{
|
|
205
222
|
cmd: true;
|
|
206
223
|
}>;
|
|
207
|
-
key: <K extends ActionKey>(key: K) => KeyChain<
|
|
224
|
+
key: <K extends ActionKey>(key: K) => KeyChain<K>;
|
|
208
225
|
/** Set required scopes for upcoming chain calls */
|
|
209
226
|
in: (scopes: ShortcutScope) => ShortcutBuilder;
|
|
210
227
|
/** Update active scopes at runtime */
|
|
@@ -247,22 +264,6 @@ type UseShortcutOptions = {
|
|
|
247
264
|
/** Global event filter; return false to skip all shortcuts for the event */
|
|
248
265
|
eventFilter?: (event: KeyboardEvent) => boolean;
|
|
249
266
|
};
|
|
250
|
-
type ShortcutMapEntry = {
|
|
251
|
-
keys: string | string[];
|
|
252
|
-
handler: ShortcutHandler;
|
|
253
|
-
options?: HandlerOptions;
|
|
254
|
-
};
|
|
255
|
-
type ShortcutMap = Record<string, ShortcutMapEntry>;
|
|
256
|
-
type ShortcutMapResult<T extends ShortcutMap = ShortcutMap> = {
|
|
257
|
-
[K in keyof T]: ShortcutResult;
|
|
258
|
-
};
|
|
259
|
-
type ShortcutGroup = {
|
|
260
|
-
add: (...results: ShortcutResult[]) => void;
|
|
261
|
-
addMany: (results: ShortcutResult[] | Record<string, ShortcutResult>) => void;
|
|
262
|
-
unbindAll: () => void;
|
|
263
|
-
clear: () => void;
|
|
264
|
-
getResults: () => ShortcutResult[];
|
|
265
|
-
};
|
|
266
267
|
|
|
267
268
|
/**
|
|
268
269
|
* Parse a shortcut string into its components
|
|
@@ -284,13 +285,6 @@ declare function parseShortcut(shortcut: string): ParsedShortcut;
|
|
|
284
285
|
* @returns Array of parsed shortcuts
|
|
285
286
|
*/
|
|
286
287
|
declare function parseShortcuts(shortcuts: string | string[]): ParsedShortcut[];
|
|
287
|
-
/**
|
|
288
|
-
* Extract modifier state from a keyboard event
|
|
289
|
-
*
|
|
290
|
-
* @param event - The keyboard event
|
|
291
|
-
* @returns Object with meta, ctrl, alt, shift boolean flags
|
|
292
|
-
*/
|
|
293
|
-
declare function getModifiersFromEvent(event: KeyboardEvent): ModifierState;
|
|
294
288
|
/**
|
|
295
289
|
* Check if a keyboard event matches a parsed shortcut
|
|
296
290
|
*
|
|
@@ -322,45 +316,22 @@ declare function matchesAnyShortcut(event: KeyboardEvent, parsedShortcuts: Parse
|
|
|
322
316
|
* ```
|
|
323
317
|
*/
|
|
324
318
|
declare function formatShortcut(shortcut: string, platform?: PlatformType): string;
|
|
325
|
-
/**
|
|
326
|
-
* Get the modifier key symbols for a platform
|
|
327
|
-
*
|
|
328
|
-
* @param platform - Optional platform override (default: auto-detect)
|
|
329
|
-
* @returns Object mapping modifier keys to display symbols
|
|
330
|
-
*
|
|
331
|
-
* @example
|
|
332
|
-
* ```ts
|
|
333
|
-
* getModifierSymbols("mac") // { meta: "⌘", ctrl: "⌃", alt: "⌥", shift: "⇧" }
|
|
334
|
-
* ```
|
|
335
|
-
*/
|
|
336
|
-
declare function getModifierSymbols(platform?: PlatformType): Record<ModifierKeyType, string>;
|
|
337
319
|
|
|
338
|
-
declare function registerShortcutMap<T extends ShortcutMap>(builder: ShortcutBuilder, shortcutMap: T): ShortcutMapResult<T>;
|
|
339
320
|
/**
|
|
340
321
|
* React hook for registering chainable keyboard shortcuts
|
|
341
322
|
*
|
|
342
323
|
* @param options - Configuration options for the hook
|
|
343
324
|
* @returns A chainable shortcut builder (`$`)
|
|
344
|
-
*/
|
|
345
|
-
declare function useShortcut(options?: UseShortcutOptions): ShortcutBuilder;
|
|
346
|
-
/**
|
|
347
|
-
* Bulk registration helper for shortcut maps.
|
|
348
|
-
*/
|
|
349
|
-
declare function useShortcutMap<T extends ShortcutMap>(shortcutMap: T, options?: UseShortcutOptions): ShortcutMapResult<T>;
|
|
350
|
-
/**
|
|
351
|
-
* Create a shortcut builder for non-React usage
|
|
352
|
-
*
|
|
353
|
-
* Unlike `useShortcut`, this does not auto-cleanup - you must call `.unbind()` manually.
|
|
354
325
|
*
|
|
355
|
-
* @
|
|
356
|
-
*
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* const $ = useShortcut({ activeScopes: ["editor"] })
|
|
329
|
+
* $.mod.key("s").on((event) => {
|
|
330
|
+
* event.preventDefault()
|
|
331
|
+
* saveDocument()
|
|
332
|
+
* })
|
|
333
|
+
* ```
|
|
361
334
|
*/
|
|
362
|
-
declare function
|
|
363
|
-
declare function createShortcutGroup(): ShortcutGroup;
|
|
364
|
-
declare function useShortcutGroup(): ShortcutGroup;
|
|
335
|
+
declare function useShortcut(options?: UseShortcutOptions): ShortcutBuilder;
|
|
365
336
|
|
|
366
|
-
export { type ActionKey, type AlphaKey, type ExceptPredicate, type ExceptPreset, type FunctionKey, type HandlerOptions, type KeyChain, ModifierAliases, type ModifierChain, ModifierDisplayOrder, ModifierDisplaySymbols, type ModifierFlags, ModifierKey, type ModifierName, type ModifierState, type NavigationKey, type NumericKey, type ParsedShortcut, Platform, type ShortcutBuilder, type ShortcutConflict, type
|
|
337
|
+
export { type ActionKey, type AlphaKey, type ExceptPredicate, type ExceptPreset, type FunctionKey, type HandlerOptions, type KeyChain, ModifierAliases, type ModifierChain, ModifierDisplayOrder, ModifierDisplaySymbols, type ModifierFlags, ModifierKey, type ModifierName, type ModifierState, type NavigationKey, type NumericKey, type ParsedShortcut, Platform, type ShortcutBuilder, type ShortcutConflict, type ShortcutHandler, type ShortcutRecordingOptions, type ShortcutResult, type ShortcutScope, type SpecialKey, SpecialKeyMap, type SymbolKey, type UseShortcutOptions, detectPlatform, formatShortcut, matchesAnyShortcut, matchesShortcut, parseShortcut, parseShortcuts, useShortcut };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
/** Supported runtime OS identifiers used by formatter and parser normalization. */
|
|
2
|
+
declare const OS: {
|
|
3
|
+
readonly MAC: "mac";
|
|
4
|
+
readonly WINDOWS: "windows";
|
|
5
|
+
readonly LINUX: "linux";
|
|
6
|
+
};
|
|
7
|
+
type PlatformType = (typeof OS)[keyof typeof OS];
|
|
8
|
+
/** Public platform constant alias (`Platform.MAC`, `Platform.WINDOWS`, `Platform.LINUX`). */
|
|
1
9
|
declare const Platform: {
|
|
2
10
|
readonly MAC: "mac";
|
|
3
11
|
readonly WINDOWS: "windows";
|
|
4
12
|
readonly LINUX: "linux";
|
|
5
13
|
};
|
|
6
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Detect the current OS platform for modifier normalization and display formatting.
|
|
16
|
+
* Result is memoized for the page lifecycle.
|
|
17
|
+
*/
|
|
7
18
|
declare function detectPlatform(): PlatformType;
|
|
19
|
+
/** Canonical modifier token names used internally across parsing/formatting. */
|
|
8
20
|
declare const ModifierKey: {
|
|
9
21
|
readonly META: "meta";
|
|
10
22
|
readonly CTRL: "ctrl";
|
|
@@ -12,9 +24,13 @@ declare const ModifierKey: {
|
|
|
12
24
|
readonly SHIFT: "shift";
|
|
13
25
|
};
|
|
14
26
|
type ModifierKeyType = (typeof ModifierKey)[keyof typeof ModifierKey];
|
|
27
|
+
/** Alias map from user-facing modifier tokens to canonical modifier keys. */
|
|
15
28
|
declare const ModifierAliases: Record<string, ModifierKeyType>;
|
|
29
|
+
/** Alias map from human shortcut key tokens to `KeyboardEvent.key`-compatible values. */
|
|
16
30
|
declare const SpecialKeyMap: Record<string, string>;
|
|
31
|
+
/** Platform-specific display labels/symbols for modifier keys. */
|
|
17
32
|
declare const ModifierDisplaySymbols: Record<PlatformType, Record<ModifierKeyType, string>>;
|
|
33
|
+
/** Platform-specific canonical order for modifier rendering and combo normalization. */
|
|
18
34
|
declare const ModifierDisplayOrder: Record<PlatformType, ModifierKeyType[]>;
|
|
19
35
|
|
|
20
36
|
/** Lowercase letter keys a-z */
|
|
@@ -77,7 +93,9 @@ type ExceptPredicate = (event: KeyboardEvent) => boolean;
|
|
|
77
93
|
* - "disabled" - Skip when focused element is disabled
|
|
78
94
|
*/
|
|
79
95
|
type ExceptPreset = "input" | "editable" | "typing" | "modal" | "disabled";
|
|
96
|
+
/** Scope selector used to enable/disable subsets of shortcuts at runtime. */
|
|
80
97
|
type ShortcutScope = string | string[];
|
|
98
|
+
/** Conflict metadata emitted when two registered shortcuts overlap. */
|
|
81
99
|
type ShortcutConflict = {
|
|
82
100
|
combo: string;
|
|
83
101
|
existingCombo: string;
|
|
@@ -97,8 +115,6 @@ type HandlerOptions = {
|
|
|
97
115
|
description?: string;
|
|
98
116
|
/** Disable this specific shortcut */
|
|
99
117
|
disabled?: boolean;
|
|
100
|
-
/** Limit shortcut to a specific DOM element */
|
|
101
|
-
scope?: HTMLElement | null;
|
|
102
118
|
/** Conditions to skip the shortcut */
|
|
103
119
|
except?: ExceptPreset | ExceptPreset[] | ExceptPredicate;
|
|
104
120
|
/** Required named scopes that must be active */
|
|
@@ -152,13 +168,13 @@ type ModifierChain<Used extends Partial<ModifierFlags>> = {
|
|
|
152
168
|
mod: Used["cmd"] extends true ? never : ModifierChain<Used & {
|
|
153
169
|
cmd: true;
|
|
154
170
|
}>;
|
|
155
|
-
key: <K extends ActionKey>(key: K) => KeyChain<
|
|
171
|
+
key: <K extends ActionKey>(key: K) => KeyChain<K>;
|
|
156
172
|
in: (scopes: ShortcutScope) => ModifierChain<Used>;
|
|
157
173
|
};
|
|
158
174
|
/**
|
|
159
175
|
* Chain state after calling `.key()` - ready to attach a handler
|
|
160
176
|
*/
|
|
161
|
-
type KeyChain<
|
|
177
|
+
type KeyChain<Key extends string> = {
|
|
162
178
|
/** Attach a handler to this shortcut */
|
|
163
179
|
on: (handler: ShortcutHandler, options?: HandlerOptions) => ShortcutResult;
|
|
164
180
|
/** Attach a handler with inline options */
|
|
@@ -166,20 +182,21 @@ type KeyChain<Used extends Partial<ModifierFlags>, Key extends string> = {
|
|
|
166
182
|
handler: ShortcutHandler;
|
|
167
183
|
}) => ShortcutResult;
|
|
168
184
|
/** Add exception conditions before attaching handler */
|
|
169
|
-
except: (condition: ExceptPreset | ExceptPreset[] | ExceptPredicate) => KeyChainWithExcept<
|
|
185
|
+
except: (condition: ExceptPreset | ExceptPreset[] | ExceptPredicate) => KeyChainWithExcept<Key>;
|
|
170
186
|
/** Add required named scopes */
|
|
171
|
-
in: (scopes: ShortcutScope) => KeyChain<
|
|
187
|
+
in: (scopes: ShortcutScope) => KeyChain<Key>;
|
|
172
188
|
/** Add the next step in a sequence */
|
|
173
|
-
then: <K extends ActionKey | string>(key: K) => KeyChain
|
|
189
|
+
then: <K extends ActionKey | string>(key: K) => KeyChain<`${Key} ${K}`>;
|
|
174
190
|
};
|
|
175
191
|
/**
|
|
176
192
|
* Chain state after calling `.except()` - ready to attach handler
|
|
177
193
|
*/
|
|
178
|
-
type KeyChainWithExcept<
|
|
194
|
+
type KeyChainWithExcept<Key extends string> = {
|
|
179
195
|
on: (handler: ShortcutHandler, options?: Omit<HandlerOptions, "except">) => ShortcutResult;
|
|
180
|
-
in: (scopes: ShortcutScope) => KeyChainWithExcept<
|
|
181
|
-
then: <K extends ActionKey | string>(key: K) => KeyChainWithExcept
|
|
196
|
+
in: (scopes: ShortcutScope) => KeyChainWithExcept<Key>;
|
|
197
|
+
then: <K extends ActionKey | string>(key: K) => KeyChainWithExcept<`${Key} ${K}`>;
|
|
182
198
|
};
|
|
199
|
+
/** Options for `ShortcutBuilder.record()` and low-level recording flows. */
|
|
183
200
|
type ShortcutRecordingOptions = {
|
|
184
201
|
target?: HTMLElement | Window | null;
|
|
185
202
|
eventType?: "keydown" | "keyup";
|
|
@@ -204,7 +221,7 @@ type ShortcutBuilder = ModifierChain<EmptyModifiers> & {
|
|
|
204
221
|
mod: ModifierChain<{
|
|
205
222
|
cmd: true;
|
|
206
223
|
}>;
|
|
207
|
-
key: <K extends ActionKey>(key: K) => KeyChain<
|
|
224
|
+
key: <K extends ActionKey>(key: K) => KeyChain<K>;
|
|
208
225
|
/** Set required scopes for upcoming chain calls */
|
|
209
226
|
in: (scopes: ShortcutScope) => ShortcutBuilder;
|
|
210
227
|
/** Update active scopes at runtime */
|
|
@@ -247,22 +264,6 @@ type UseShortcutOptions = {
|
|
|
247
264
|
/** Global event filter; return false to skip all shortcuts for the event */
|
|
248
265
|
eventFilter?: (event: KeyboardEvent) => boolean;
|
|
249
266
|
};
|
|
250
|
-
type ShortcutMapEntry = {
|
|
251
|
-
keys: string | string[];
|
|
252
|
-
handler: ShortcutHandler;
|
|
253
|
-
options?: HandlerOptions;
|
|
254
|
-
};
|
|
255
|
-
type ShortcutMap = Record<string, ShortcutMapEntry>;
|
|
256
|
-
type ShortcutMapResult<T extends ShortcutMap = ShortcutMap> = {
|
|
257
|
-
[K in keyof T]: ShortcutResult;
|
|
258
|
-
};
|
|
259
|
-
type ShortcutGroup = {
|
|
260
|
-
add: (...results: ShortcutResult[]) => void;
|
|
261
|
-
addMany: (results: ShortcutResult[] | Record<string, ShortcutResult>) => void;
|
|
262
|
-
unbindAll: () => void;
|
|
263
|
-
clear: () => void;
|
|
264
|
-
getResults: () => ShortcutResult[];
|
|
265
|
-
};
|
|
266
267
|
|
|
267
268
|
/**
|
|
268
269
|
* Parse a shortcut string into its components
|
|
@@ -284,13 +285,6 @@ declare function parseShortcut(shortcut: string): ParsedShortcut;
|
|
|
284
285
|
* @returns Array of parsed shortcuts
|
|
285
286
|
*/
|
|
286
287
|
declare function parseShortcuts(shortcuts: string | string[]): ParsedShortcut[];
|
|
287
|
-
/**
|
|
288
|
-
* Extract modifier state from a keyboard event
|
|
289
|
-
*
|
|
290
|
-
* @param event - The keyboard event
|
|
291
|
-
* @returns Object with meta, ctrl, alt, shift boolean flags
|
|
292
|
-
*/
|
|
293
|
-
declare function getModifiersFromEvent(event: KeyboardEvent): ModifierState;
|
|
294
288
|
/**
|
|
295
289
|
* Check if a keyboard event matches a parsed shortcut
|
|
296
290
|
*
|
|
@@ -322,45 +316,22 @@ declare function matchesAnyShortcut(event: KeyboardEvent, parsedShortcuts: Parse
|
|
|
322
316
|
* ```
|
|
323
317
|
*/
|
|
324
318
|
declare function formatShortcut(shortcut: string, platform?: PlatformType): string;
|
|
325
|
-
/**
|
|
326
|
-
* Get the modifier key symbols for a platform
|
|
327
|
-
*
|
|
328
|
-
* @param platform - Optional platform override (default: auto-detect)
|
|
329
|
-
* @returns Object mapping modifier keys to display symbols
|
|
330
|
-
*
|
|
331
|
-
* @example
|
|
332
|
-
* ```ts
|
|
333
|
-
* getModifierSymbols("mac") // { meta: "⌘", ctrl: "⌃", alt: "⌥", shift: "⇧" }
|
|
334
|
-
* ```
|
|
335
|
-
*/
|
|
336
|
-
declare function getModifierSymbols(platform?: PlatformType): Record<ModifierKeyType, string>;
|
|
337
319
|
|
|
338
|
-
declare function registerShortcutMap<T extends ShortcutMap>(builder: ShortcutBuilder, shortcutMap: T): ShortcutMapResult<T>;
|
|
339
320
|
/**
|
|
340
321
|
* React hook for registering chainable keyboard shortcuts
|
|
341
322
|
*
|
|
342
323
|
* @param options - Configuration options for the hook
|
|
343
324
|
* @returns A chainable shortcut builder (`$`)
|
|
344
|
-
*/
|
|
345
|
-
declare function useShortcut(options?: UseShortcutOptions): ShortcutBuilder;
|
|
346
|
-
/**
|
|
347
|
-
* Bulk registration helper for shortcut maps.
|
|
348
|
-
*/
|
|
349
|
-
declare function useShortcutMap<T extends ShortcutMap>(shortcutMap: T, options?: UseShortcutOptions): ShortcutMapResult<T>;
|
|
350
|
-
/**
|
|
351
|
-
* Create a shortcut builder for non-React usage
|
|
352
|
-
*
|
|
353
|
-
* Unlike `useShortcut`, this does not auto-cleanup - you must call `.unbind()` manually.
|
|
354
325
|
*
|
|
355
|
-
* @
|
|
356
|
-
*
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* const $ = useShortcut({ activeScopes: ["editor"] })
|
|
329
|
+
* $.mod.key("s").on((event) => {
|
|
330
|
+
* event.preventDefault()
|
|
331
|
+
* saveDocument()
|
|
332
|
+
* })
|
|
333
|
+
* ```
|
|
361
334
|
*/
|
|
362
|
-
declare function
|
|
363
|
-
declare function createShortcutGroup(): ShortcutGroup;
|
|
364
|
-
declare function useShortcutGroup(): ShortcutGroup;
|
|
335
|
+
declare function useShortcut(options?: UseShortcutOptions): ShortcutBuilder;
|
|
365
336
|
|
|
366
|
-
export { type ActionKey, type AlphaKey, type ExceptPredicate, type ExceptPreset, type FunctionKey, type HandlerOptions, type KeyChain, ModifierAliases, type ModifierChain, ModifierDisplayOrder, ModifierDisplaySymbols, type ModifierFlags, ModifierKey, type ModifierName, type ModifierState, type NavigationKey, type NumericKey, type ParsedShortcut, Platform, type ShortcutBuilder, type ShortcutConflict, type
|
|
337
|
+
export { type ActionKey, type AlphaKey, type ExceptPredicate, type ExceptPreset, type FunctionKey, type HandlerOptions, type KeyChain, ModifierAliases, type ModifierChain, ModifierDisplayOrder, ModifierDisplaySymbols, type ModifierFlags, ModifierKey, type ModifierName, type ModifierState, type NavigationKey, type NumericKey, type ParsedShortcut, Platform, type ShortcutBuilder, type ShortcutConflict, type ShortcutHandler, type ShortcutRecordingOptions, type ShortcutResult, type ShortcutScope, type SpecialKey, SpecialKeyMap, type SymbolKey, type UseShortcutOptions, detectPlatform, formatShortcut, matchesAnyShortcut, matchesShortcut, parseShortcut, parseShortcuts, useShortcut };
|