export type Command = { /** * Command handler. */ trigger: (event: Event) => (Promise | void); /** * Checks whether the context in which the command is triggering is permitted. * * The function is passed the associated `KeyboardEvent`. The event’s [`event.composedPath()`][1] method is convenient to check where an event originates (e.g. does it come within the code block?). * * [1]: https://developer.mozilla.org/en-US/docs/Web/API/Event/composedPath */ isAllowedContext?: (event: Event) => boolean; /** * Disables the shortcut dynamically. */ isDisabled?: () => boolean; /** * Whether to prevent the default action of a command. For example, when adding auto complete features to a text input, one might want to prevent the default action associated with pressing the up and down arrow keys. */ shouldPreventDefaultAction?: boolean; }; /** * A small utility class for managing keyboard shortcuts. * * **Usage**: * * ```js * const keyMap = { * 'alt+f': 'toggleFilterMode', * 'alt+g': 'toggleFilterMode', * } * * const commands = { * toggleFilterMode: { * trigger: toggleFilterMode, * shouldPreventDefaultAction: true, * }, * } * * function toggleFilterMode() { * // Do something … * } * * const shortcutManager = new ShortcutManager(keyMap, commands) * * shortcutManager.registerListener() * ``` */ export declare class ShortcutManager { commands: Record; keyMap: Record; boundTriggerShortcuts: typeof this.triggerShortcuts; constructor(keyMap: Record, commands: Record); registerListener(): void; unRegisterListener(): void; triggerShortcuts(event: KeyboardEvent): void; }