UNPKG

apphouse

Version:

Component library for React that uses observable state management and theme-able components.

71 lines (70 loc) 2 kB
import View from '../app/View'; export interface Shortcut { /** * The shortcut combo to trigger the action. * @example * 'ctrl+s' * 'command+s' * ['ctrl+s', 'command+s'] * 'ctrl+shift+s' */ combo: string | string[]; /** * The action to be called when the shortcut is triggered. * @returns */ action: () => void; /** * The description of the shortcut. Added for convenience. * @optional * @example * 'Save the file to disk' * 'Open the preview' */ description?: string; /** * The view where the shortcut should be active. It should match with your view id. * The shortcut will be active in all views if not specified. * @optional */ view?: string; } /** * The Shortcuts class handles all the keyboard shortcuts in the app. * It uses the hotkeys library to handle the shortcuts. */ export declare class Shortcuts { currentView: View; shiftPress: boolean; /** * The scope where the shortcut should be active. * It should match with your scope id. */ scoped: { [key: string]: { [id: string]: () => void; }; }; constructor(view: View); /** * Register a new shortcut * @param shortcut the shortcut combo to trigger the action. * @param callback the action to be called when the shortcut is triggered. */ register: (shortcut: string | string[], callback: () => void) => void; /** * Unregister a current shortcut * @param shortcut the shortcut combo to be unregistered. */ unregister: (shortcut: string | string[]) => void; /** * Register a list of shortcuts to be used in the app. * @param shortcuts the shortcuts to be registered. */ registerAppShortcuts: (shortcuts: Shortcut[]) => void; /** * Set the shift key press state. * @param value boolean if true, the shift key is pressed */ private setShiftPress; }