@inklu/keys 2.1.0 → 3.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/README.md +106 -135
- package/dist/attributes.d.mts +1 -1
- package/dist/attributes.mjs +15 -18
- package/dist/index-BnB38jCF.d.mts +139 -0
- package/dist/index.d.mts +3 -3
- package/dist/index.mjs +2 -2
- package/dist/react.d.mts +19 -41
- package/dist/react.mjs +26 -145
- package/dist/src-CGKvYKjd.mjs +1333 -0
- package/dist/types-BxMI3b4a.d.mts +256 -0
- package/package.json +2 -3
- package/dist/index-3d9f54ln.d.mts +0 -156
- package/dist/src-B76YvObL.mjs +0 -1687
- package/dist/types-QEXldPnL.d.mts +0 -398
|
@@ -1,398 +0,0 @@
|
|
|
1
|
-
//#region src/chord.d.ts
|
|
2
|
-
/**
|
|
3
|
-
* One chord: its spelling, reading it from a string or a keypress, comparing
|
|
4
|
-
* the two, and writing it back. Everything else in the package handles chords
|
|
5
|
-
* through here, so there is one grammar and one idea of which key was pressed.
|
|
6
|
-
*/
|
|
7
|
-
/** Supported platforms for hotkey resolution and display formatting. */
|
|
8
|
-
type Platform = "mac" | "windows" | "linux";
|
|
9
|
-
/**
|
|
10
|
-
* Named keys with a place in the `Key` type, as `KeyboardEvent.key` spells
|
|
11
|
-
* them. Any other name still works as a key; `validateChord` only remarks on it.
|
|
12
|
-
*/
|
|
13
|
-
declare const NAMED_KEYS: readonly ["ArrowUp", "ArrowDown", "ArrowLeft", "ArrowRight", "Home", "End", "PageUp", "PageDown", "Enter", "Escape", "Space", "Tab", "Backspace", "Delete", "Insert", "CapsLock", "ContextMenu", "PrintScreen", "ScrollLock", "Pause", "NumLock", "Help", "Clear", "MediaPlayPause", "MediaStop", "MediaTrackNext", "MediaTrackPrevious", "AudioVolumeUp", "AudioVolumeDown", "AudioVolumeMute", "BrowserBack", "BrowserForward", "BrowserRefresh", "BrowserSearch", "BrowserHome"];
|
|
14
|
-
type Letter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z";
|
|
15
|
-
type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
|
|
16
|
-
type FunctionKey = `F${Exclude<Digit, "0">}` | `F1${Digit}` | `F2${"0" | "1" | "2" | "3" | "4"}`;
|
|
17
|
-
type Punctuation = "/" | "[" | "]" | "\\" | "=" | "-" | "," | "." | ";" | "`" | "'" | "+" | "?" | "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "_" | "{" | "}" | "|" | ":" | '"' | "<" | ">" | "~";
|
|
18
|
-
/**
|
|
19
|
-
* The key of a chord: the character or named key it produces (`"K"`,
|
|
20
|
-
* `"Escape"`), or a physical key by its `KeyboardEvent.code` in brackets
|
|
21
|
-
* (`"[KeyK]"`), which stays put whatever the keyboard layout.
|
|
22
|
-
*/
|
|
23
|
-
type Key = Letter | Digit | FunctionKey | Punctuation | (typeof NAMED_KEYS)[number] | `[${string}]`;
|
|
24
|
-
type Held<Modifier extends string> = "" | `${Modifier}+`;
|
|
25
|
-
type Modifiers = `${Held<"Control">}${Held<"Alt">}${Held<"Shift">}${Held<"Meta">}` | `Mod+${Held<"Alt">}${Held<"Shift">}`;
|
|
26
|
-
/**
|
|
27
|
-
* A single hotkey chord, e.g. `"Mod+K"`: modifiers in the order Control, Alt,
|
|
28
|
-
* Shift, Meta, then one key. `Mod` is Command on macOS and Control elsewhere.
|
|
29
|
-
*/
|
|
30
|
-
type Chord = `${Modifiers}${Key}`;
|
|
31
|
-
//#endregion
|
|
32
|
-
//#region src/types.d.ts
|
|
33
|
-
/** A sequence of chords pressed in order, e.g. `G` then `I`. */
|
|
34
|
-
interface SequenceBinding {
|
|
35
|
-
readonly sequence: ReadonlyArray<Chord>;
|
|
36
|
-
}
|
|
37
|
-
/** A hotkey chord or sequence that triggers a command. */
|
|
38
|
-
type Binding = Chord | SequenceBinding;
|
|
39
|
-
/** One binding or an array of alternative bindings. */
|
|
40
|
-
type BindingInput = Binding | ReadonlyArray<Binding>;
|
|
41
|
-
/** JSON-serializable form of a binding. */
|
|
42
|
-
type SerializedBinding = string | Array<string>;
|
|
43
|
-
/** An arbitrary JSON-compatible value, e.g. from `JSON.parse` or persisted storage. */
|
|
44
|
-
type Json = string | number | boolean | null | ReadonlyArray<Json> | {
|
|
45
|
-
readonly [key: string]: Json;
|
|
46
|
-
};
|
|
47
|
-
/** Display options for formatting hotkeys. */
|
|
48
|
-
interface DisplayOptions {
|
|
49
|
-
/** Platform to write for. Defaults to the one detected. */
|
|
50
|
-
platform?: Platform;
|
|
51
|
-
/** Symbols such as `⌘` and `↵` rather than names such as `Cmd`. Defaults to `true`. */
|
|
52
|
-
useSymbols?: boolean;
|
|
53
|
-
}
|
|
54
|
-
/** Trigger source for a command. */
|
|
55
|
-
type CommandSource = "keyboard" | "api" | "dom";
|
|
56
|
-
/** Context passed to a command's handler. */
|
|
57
|
-
interface CommandContext<Id extends string = string> {
|
|
58
|
-
/** ID of the command being run. */
|
|
59
|
-
readonly id: Id;
|
|
60
|
-
/** How the command was triggered. */
|
|
61
|
-
readonly source: CommandSource;
|
|
62
|
-
/** Originating DOM event, if triggered by user interaction. */
|
|
63
|
-
readonly event?: Event;
|
|
64
|
-
/** Specific binding that triggered the command. */
|
|
65
|
-
readonly binding?: Binding;
|
|
66
|
-
/**
|
|
67
|
-
* The commands registry instance.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* ```ts
|
|
71
|
-
* run: ({ commands }) => {
|
|
72
|
-
* commands.run("doc.save");
|
|
73
|
-
* }
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
readonly commands: Commands<Id>;
|
|
77
|
-
}
|
|
78
|
-
/** What a command does when it runs. */
|
|
79
|
-
type CommandHandler<Id extends string = string> = (context: CommandContext<Id>) => void | Promise<void>;
|
|
80
|
-
/**
|
|
81
|
-
* A command: what it is called, which keys reach it, and where it is live.
|
|
82
|
-
*
|
|
83
|
-
* `Id` is the registry's id union. `createCommands` fills it in, so
|
|
84
|
-
* `commands.run(...)` inside a handler is checked against the registry's own
|
|
85
|
-
* ids; a definition written on its own defaults to plain `string`.
|
|
86
|
-
*/
|
|
87
|
-
interface CommandDefinition<Id extends string = string> {
|
|
88
|
-
/** Human-readable title. */
|
|
89
|
-
title: string;
|
|
90
|
-
/** Longer explanation, such as a palette's secondary line or a tooltip. */
|
|
91
|
-
description?: string;
|
|
92
|
-
/** Heading to list the command under in a palette or shortcut sheet, e.g. `"Navigate"`. */
|
|
93
|
-
group?: string;
|
|
94
|
-
/** Extra search terms `matchCommands` checks besides the title, e.g. `["find", "search"]`. */
|
|
95
|
-
keywords?: ReadonlyArray<string>;
|
|
96
|
-
/**
|
|
97
|
-
* Leave the command out of `matchCommands` — for commands that only make
|
|
98
|
-
* sense from their key, like a palette's own Close. It still runs and
|
|
99
|
-
* still appears in `list()`. Defaults to `false`.
|
|
100
|
-
*/
|
|
101
|
-
hidden?: boolean;
|
|
102
|
-
/** Default key binding(s). */
|
|
103
|
-
keys?: BindingInput;
|
|
104
|
-
/** Scope required for this command to fire. Omit for global, or `"*"` to bypass exclusive scopes. */
|
|
105
|
-
scope?: string;
|
|
106
|
-
/**
|
|
107
|
-
* Prevent default event behavior when run. Defaults to `true`. For a
|
|
108
|
-
* sequence this also covers each step as it matches, so a first step such
|
|
109
|
-
* as `Mod+K` does not trigger the browser's own shortcut on the way.
|
|
110
|
-
*/
|
|
111
|
-
preventDefault?: boolean;
|
|
112
|
-
/**
|
|
113
|
-
* Whether to ignore key events from text inputs, textareas, selects and
|
|
114
|
-
* contenteditable elements. When omitted it is decided per binding: chords
|
|
115
|
-
* holding Control or Meta (so `Mod+…`) and bare `Escape` still fire inside
|
|
116
|
-
* inputs, while everything else — bare keys, Shift/Alt chords, and
|
|
117
|
-
* sequences starting with one — is ignored there, so typing is never
|
|
118
|
-
* hijacked.
|
|
119
|
-
*/
|
|
120
|
-
ignoreInputs?: boolean;
|
|
121
|
-
/** Timeout in milliseconds between sequence steps. Defaults to `1000`. */
|
|
122
|
-
sequenceTimeout?: number;
|
|
123
|
-
/**
|
|
124
|
-
* What the command does, when that needs nothing a component owns. Leave
|
|
125
|
-
* it out and attach the behaviour where the state lives, with
|
|
126
|
-
* `commands.handle()` or `useCommandHandler`: a command with no handler
|
|
127
|
-
* cannot run and leaves its key alone.
|
|
128
|
-
*/
|
|
129
|
-
run?: CommandHandler<Id>;
|
|
130
|
-
}
|
|
131
|
-
/** Resolved command snapshot including effective bindings, display tokens, and reachability. */
|
|
132
|
-
interface Command<Id extends string = string> {
|
|
133
|
-
readonly id: Id;
|
|
134
|
-
readonly title: string;
|
|
135
|
-
readonly description?: string;
|
|
136
|
-
readonly group?: string;
|
|
137
|
-
/** Extra search terms; empty when the definition gave none. */
|
|
138
|
-
readonly keywords: ReadonlyArray<string>;
|
|
139
|
-
/** Whether `matchCommands` leaves the command out. */
|
|
140
|
-
readonly hidden: boolean;
|
|
141
|
-
readonly scope?: string;
|
|
142
|
-
/** Active bindings after user overrides. */
|
|
143
|
-
readonly bindings: ReadonlyArray<Binding>;
|
|
144
|
-
/** Formatted display strings for active bindings. */
|
|
145
|
-
readonly display: ReadonlyArray<string>;
|
|
146
|
-
/** Formatted tokens per binding for rendering `<kbd>` elements. */
|
|
147
|
-
readonly tokens: ReadonlyArray<ReadonlyArray<string>>;
|
|
148
|
-
/**
|
|
149
|
-
* Value for the `aria-keyshortcuts` attribute. Only chords appear here: the
|
|
150
|
-
* attribute separates alternatives with spaces, so it cannot express a
|
|
151
|
-
* sequence. Use `spoken` to announce those.
|
|
152
|
-
*/
|
|
153
|
-
readonly aria: string;
|
|
154
|
-
/**
|
|
155
|
-
* Every binding phrased for a screen reader, alternatives joined by
|
|
156
|
-
* `" or "` — e.g. `"Control+K"` or `"G then I"`. Suited to visually hidden
|
|
157
|
-
* text or `aria-description`, and the only accessible form of a sequence.
|
|
158
|
-
*/
|
|
159
|
-
readonly spoken: string;
|
|
160
|
-
/** Whether its keys work right now: it has a handler and its scope is active. */
|
|
161
|
-
readonly reachable: boolean;
|
|
162
|
-
/** Whether the command has a user keymap override. */
|
|
163
|
-
readonly overridden: boolean;
|
|
164
|
-
}
|
|
165
|
-
/** Storage interface for persisting keymap overrides. */
|
|
166
|
-
interface KeymapStorage {
|
|
167
|
-
getItem: (key: string) => string | null;
|
|
168
|
-
setItem: (key: string, value: string) => void;
|
|
169
|
-
removeItem: (key: string) => void;
|
|
170
|
-
}
|
|
171
|
-
/** Configuration for persisting keymap overrides. */
|
|
172
|
-
interface KeymapPersistence {
|
|
173
|
-
/** Storage key name. Defaults to `"inklu.keys"`. */
|
|
174
|
-
key?: string;
|
|
175
|
-
/** Getter returning the storage implementation lazily. */
|
|
176
|
-
storage: () => KeymapStorage | null;
|
|
177
|
-
}
|
|
178
|
-
/** One command's stored override: an array replaces the default, `{ add }` extends it. */
|
|
179
|
-
type SerializedOverride = Array<SerializedBinding> | {
|
|
180
|
-
add: Array<SerializedBinding>;
|
|
181
|
-
};
|
|
182
|
-
/**
|
|
183
|
-
* Persisted user overrides, keyed by command id. `version` lets a release
|
|
184
|
-
* skip a format it does not know instead of misreading it.
|
|
185
|
-
*/
|
|
186
|
-
type SerializedKeymap = {
|
|
187
|
-
version: 1;
|
|
188
|
-
overrides: Record<string, SerializedOverride>;
|
|
189
|
-
};
|
|
190
|
-
/** Keymap interface for querying, modifying, and persisting keybindings. */
|
|
191
|
-
interface CommandKeymap<Id extends string = string> {
|
|
192
|
-
/** Active bindings in effect: the default, with any user override applied. */
|
|
193
|
-
get(id: Id): ReadonlyArray<Binding>;
|
|
194
|
-
/**
|
|
195
|
-
* Replaces a command's bindings. Passing `null` unbinds it without
|
|
196
|
-
* restoring the default; passing exactly the default forgets the override,
|
|
197
|
-
* so the command follows the default again if the app changes it.
|
|
198
|
-
*/
|
|
199
|
-
set(id: Id, input: BindingInput | null): void;
|
|
200
|
-
/**
|
|
201
|
-
* Appends an additional binding. On a command the user has not replaced,
|
|
202
|
-
* it is stored on top of the default rather than as a copy of it, so a
|
|
203
|
-
* default the app changes later still applies alongside the added keys.
|
|
204
|
-
*/
|
|
205
|
-
add(id: Id, input: BindingInput): void;
|
|
206
|
-
/** Resets user overrides back to defaults for a specific command or all commands. */
|
|
207
|
-
reset(id?: Id): void;
|
|
208
|
-
/** Exports user overrides as JSON-serializable data. */
|
|
209
|
-
export(): SerializedKeymap;
|
|
210
|
-
/**
|
|
211
|
-
* Imports user overrides, replacing current overrides and saving to
|
|
212
|
-
* storage. Accepts `export()` output from this and earlier releases.
|
|
213
|
-
*/
|
|
214
|
-
import(data: Json): void;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* How two bindings collide: `"exact"` when they are the same keys, `"prefix"`
|
|
218
|
-
* when one is the start of the other — chord `G` against `G then I` — so the
|
|
219
|
-
* shorter one fires on the way to the longer one.
|
|
220
|
-
*/
|
|
221
|
-
type ConflictKind = "exact" | "prefix";
|
|
222
|
-
/** Details of a conflict between commands whose bindings collide in overlapping scopes. */
|
|
223
|
-
interface Conflict<Id extends string = string> {
|
|
224
|
-
/** ID of the conflicting command. */
|
|
225
|
-
readonly id: Id;
|
|
226
|
-
/** The conflicting command's binding. */
|
|
227
|
-
readonly binding: Binding;
|
|
228
|
-
/** Whether the bindings are identical or one is a prefix of the other. */
|
|
229
|
-
readonly kind: ConflictKind;
|
|
230
|
-
/** Formatted display representation of the binding. */
|
|
231
|
-
readonly display: string;
|
|
232
|
-
/** Overlapping scope where conflict occurs, if any. */
|
|
233
|
-
readonly scope?: string;
|
|
234
|
-
}
|
|
235
|
-
/** Options for conflict detection. */
|
|
236
|
-
interface ConflictOptions<Id extends string = string> {
|
|
237
|
-
/** Command ID to ignore during conflict checking. */
|
|
238
|
-
ignore?: Id;
|
|
239
|
-
/** Scope to evaluate conflicts in. Defaults to global. */
|
|
240
|
-
scope?: string;
|
|
241
|
-
}
|
|
242
|
-
/** Options for activating a scope. */
|
|
243
|
-
interface ScopeOptions {
|
|
244
|
-
/** Silence the keys of commands in lower scopes, including global commands. */
|
|
245
|
-
exclusive?: boolean;
|
|
246
|
-
}
|
|
247
|
-
/**
|
|
248
|
-
* Receives each keypress while the keyboard is captured: the event, and the
|
|
249
|
-
* chord it expresses (`null` for a modifier on its own). It decides what the
|
|
250
|
-
* key means, including whether to `preventDefault()` it.
|
|
251
|
-
*/
|
|
252
|
-
type KeyCapture = (event: KeyboardEvent, chord: Chord | null) => void;
|
|
253
|
-
/** Options passed when manually running a command. */
|
|
254
|
-
interface RunOptions {
|
|
255
|
-
/** Trigger source. Defaults to `"api"`. */
|
|
256
|
-
source?: CommandSource;
|
|
257
|
-
/** Originating DOM event. */
|
|
258
|
-
event?: Event;
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Why a command cannot run: its id is not registered, nothing has attached a
|
|
262
|
-
* handler to it, or its scope is not open.
|
|
263
|
-
*/
|
|
264
|
-
type RunBlockReason = "unknown" | "unhandled" | "out-of-scope";
|
|
265
|
-
/** Represents a partially completed key sequence. */
|
|
266
|
-
interface PendingSequence<Id extends string = string> {
|
|
267
|
-
/** Command ID. */
|
|
268
|
-
readonly id: Id;
|
|
269
|
-
/** Sequence binding being typed. */
|
|
270
|
-
readonly binding: SequenceBinding;
|
|
271
|
-
/** Number of steps matched so far. */
|
|
272
|
-
readonly matched: number;
|
|
273
|
-
/** Total steps in the sequence. */
|
|
274
|
-
readonly total: number;
|
|
275
|
-
/** Formatted remaining steps. */
|
|
276
|
-
readonly remaining: ReadonlyArray<string>;
|
|
277
|
-
}
|
|
278
|
-
/** Configuration options for a commands registry. */
|
|
279
|
-
interface CommandsOptions<Id extends string = string> {
|
|
280
|
-
/**
|
|
281
|
-
* Replaces the default `keys` a command was defined with, keyed by command
|
|
282
|
-
* id. Lets an app rebind commands it did not define — a package ships the
|
|
283
|
-
* behaviour, the app decides which key reaches it — and an unknown id is a
|
|
284
|
-
* compile error rather than a silent no-op. `null` ships the command with
|
|
285
|
-
* no default binding at all.
|
|
286
|
-
*
|
|
287
|
-
* These are defaults, applied before persisted overrides load, so a user's
|
|
288
|
-
* own rebinding still wins.
|
|
289
|
-
*
|
|
290
|
-
* @example
|
|
291
|
-
* ```ts
|
|
292
|
-
* createCommands(commands, {
|
|
293
|
-
* bindings: { "palette.open": "Mod+P", "doc.publish": null },
|
|
294
|
-
* });
|
|
295
|
-
* ```
|
|
296
|
-
*/
|
|
297
|
-
bindings?: Partial<Record<Id, BindingInput | null>>;
|
|
298
|
-
/** Platform for modifier resolution and display formatting. Defaults to auto-detection. */
|
|
299
|
-
platform?: Platform;
|
|
300
|
-
/** Target element for key events. Defaults to `document`. */
|
|
301
|
-
target?: HTMLElement | Document | Window | null;
|
|
302
|
-
/**
|
|
303
|
-
* Persistence configuration for user keymap overrides. Overrides are read
|
|
304
|
-
* on the first `mount()` rather than at creation, so the server render and
|
|
305
|
-
* the client's first render agree and hydration never mismatches; the
|
|
306
|
-
* registry notifies subscribers once they load.
|
|
307
|
-
*/
|
|
308
|
-
persist?: KeymapPersistence;
|
|
309
|
-
/**
|
|
310
|
-
* Whether single-key shortcuts — bindings where every step is a printable
|
|
311
|
-
* character with no Control, Alt or Meta, such as `?` or `G then I` — are
|
|
312
|
-
* active. Defaults to `true`. WCAG 2.1.4 requires a way to turn these off
|
|
313
|
-
* for speech-input and motor-impaired users; wire a setting to
|
|
314
|
-
* `commands.setSingleKeyShortcuts()`.
|
|
315
|
-
*/
|
|
316
|
-
singleKeyShortcuts?: boolean;
|
|
317
|
-
/** Display options for rendering shortcuts. */
|
|
318
|
-
display?: DisplayOptions;
|
|
319
|
-
/**
|
|
320
|
-
* Callback fired whenever a command runs.
|
|
321
|
-
*
|
|
322
|
-
* @example
|
|
323
|
-
* ```ts
|
|
324
|
-
* createCommands(definitions, {
|
|
325
|
-
* onRun: ({ id }) => logRun(id),
|
|
326
|
-
* });
|
|
327
|
-
* ```
|
|
328
|
-
*/
|
|
329
|
-
onRun?: (context: CommandContext<Id>) => void;
|
|
330
|
-
/**
|
|
331
|
-
* Error handler called when a handler or `onRun` throws. Defaults to
|
|
332
|
-
* `console.error`.
|
|
333
|
-
*/
|
|
334
|
-
onError?: (error: Error, context: CommandContext<Id>) => void;
|
|
335
|
-
}
|
|
336
|
-
/** The commands registry. */
|
|
337
|
-
interface Commands<Id extends string = string> {
|
|
338
|
-
/** Keymap holding default and user bindings. */
|
|
339
|
-
readonly keymap: CommandKeymap<Id>;
|
|
340
|
-
/** Retrieves a command's snapshot, or `undefined` if unregistered. */
|
|
341
|
-
get(id: Id): Command<Id> | undefined;
|
|
342
|
-
/** Returns all commands in definition order. */
|
|
343
|
-
list(): ReadonlyArray<Command<Id>>;
|
|
344
|
-
/**
|
|
345
|
-
* The list as the server rendered it: default bindings in the
|
|
346
|
-
* platform-neutral form, no scope, user override or attached handler
|
|
347
|
-
* applied. Referentially stable. Hand it to a framework as the server
|
|
348
|
-
* snapshot (`useSyncExternalStore`'s third argument), so a subtree that
|
|
349
|
-
* hydrates after the client state moved on still matches the server's HTML.
|
|
350
|
-
*/
|
|
351
|
-
serverList(): ReadonlyArray<Command<Id>>;
|
|
352
|
-
/**
|
|
353
|
-
* Runs a command by ID. Returns `true` if executed. A direct call is not
|
|
354
|
-
* a keypress, so it passes `exclusive` barriers: a palette can run what it
|
|
355
|
-
* lists while its own scope silences the keyboard.
|
|
356
|
-
*/
|
|
357
|
-
run(id: Id, options?: RunOptions): boolean;
|
|
358
|
-
/** Checks whether `run` would execute the command right now. */
|
|
359
|
-
canRun(id: Id): boolean;
|
|
360
|
-
/** Returns why `run` would refuse the command, or `null` if it would run. */
|
|
361
|
-
whyNotRun(id: Id): RunBlockReason | null;
|
|
362
|
-
/**
|
|
363
|
-
* Attaches what a command does until the returned function is called.
|
|
364
|
-
* The most recently attached handler runs; disposing it hands the command
|
|
365
|
-
* back to the one before, or to the definition's own `run`.
|
|
366
|
-
*/
|
|
367
|
-
handle(id: Id, run: CommandHandler<Id>): () => void;
|
|
368
|
-
/** Activates a scope until the returned disposal function is called. */
|
|
369
|
-
pushScope(name: string, options?: ScopeOptions): () => void;
|
|
370
|
-
/**
|
|
371
|
-
* Takes the whole keyboard until the returned function is called: every
|
|
372
|
-
* keypress goes to `onKey` first and no command's keys are live, `"*"`
|
|
373
|
-
* ones included. This is what recording a new shortcut is built on.
|
|
374
|
-
*/
|
|
375
|
-
capture(onKey: KeyCapture): () => void;
|
|
376
|
-
/**
|
|
377
|
-
* Finds commands in overlapping scopes whose bindings collide with the given
|
|
378
|
-
* one — the same keys (`kind: "exact"`), or one a prefix of the other, like
|
|
379
|
-
* chord `G` against `G then I` (`kind: "prefix"`).
|
|
380
|
-
*/
|
|
381
|
-
conflicts(binding: BindingInput, options?: ConflictOptions<Id>): Array<Conflict<Id>>;
|
|
382
|
-
/** Returns the partially-typed sequences. Tracked only while something is subscribed. */
|
|
383
|
-
pending(): ReadonlyArray<PendingSequence<Id>>;
|
|
384
|
-
/** Subscribes to sequence progress changes. */
|
|
385
|
-
subscribePending(listener: () => void): () => void;
|
|
386
|
-
/** Starts listening for key events. Returns an unmount function. */
|
|
387
|
-
mount(): () => void;
|
|
388
|
-
/** Subscribes to registry changes. Returns an unsubscribe function. */
|
|
389
|
-
subscribe(listener: () => void): () => void;
|
|
390
|
-
/** Whether single-key shortcuts are active. See `CommandsOptions.singleKeyShortcuts`. */
|
|
391
|
-
readonly singleKeyShortcuts: boolean;
|
|
392
|
-
/** Turns single-key shortcuts on or off for every command (WCAG 2.1.4). */
|
|
393
|
-
setSingleKeyShortcuts(enabled: boolean): void;
|
|
394
|
-
/** Tears down listeners and clears all commands. */
|
|
395
|
-
destroy(): void;
|
|
396
|
-
}
|
|
397
|
-
//#endregion
|
|
398
|
-
export { SequenceBinding as C, Chord as D, SerializedOverride as E, Key as O, ScopeOptions as S, SerializedKeymap as T, KeymapPersistence as _, CommandDefinition as a, RunBlockReason as b, CommandSource as c, Conflict as d, ConflictKind as f, KeyCapture as g, Json as h, CommandContext as i, Platform as k, Commands as l, DisplayOptions as m, BindingInput as n, CommandHandler as o, ConflictOptions as p, Command as r, CommandKeymap as s, Binding as t, CommandsOptions as u, KeymapStorage as v, SerializedBinding as w, RunOptions as x, PendingSequence as y };
|