import { EventTarget } from 'event-target-shim'; import type React from 'react'; import { type CustomEventMap } from '@deephaven/utils'; export declare enum MODIFIER { CTRL = "MODIFIER_CTRL", CMD = "MODIFIER_CMD", ALT = "MODIFIER_ALT", OPTION = "MODIFIER_OPTION", SHIFT = "MODIFIER_SHIFT" } export declare enum KEY { A = "A", B = "B", C = "C", D = "D", E = "E", F = "F", G = "G", H = "H", I = "I", J = "J", K = "K", L = "L", M = "M", N = "N", O = "O", P = "P", Q = "Q", R = "R", S = "S", T = "T", U = "U", V = "V", W = "W", X = "X", Y = "Y", Z = "Z", ZERO = "0", ONE = "1", TWO = "2", THREE = "3", FOUR = "4", FIVE = "5", SIX = "6", SEVEN = "7", EIGHT = "8", NINE = "9", BACKSPACE = "Backspace", ESCAPE = "Escape", ENTER = "Enter", DELETE = "Delete", SLASH = "/", QUESTION_MARK = "?", BACKSLASH = "\\", PIPE = "|", MINUS = "-", UNDERSCORE = "_", EQUALS = "=", PLUS = "+", BACKTICK = "`", TILDE = "~", COMMA = ",", LEFT_CHEVRON = "<", PERIOD = ".", RIGHT_CHEVRON = ">", SEMICOLON = ";", COLON = ":", SINGLE_QUOTE = "'", DOUBLE_QUOTE = "\"", LEFT_BRACKET = "[", RIGHT_BRACKET = "]", LEFT_CURLY = "{", RIGHT_CURLY = "}", F1 = "F1", F2 = "F2", F3 = "F3", F4 = "F4", F5 = "F5", F6 = "F6", F7 = "F7", F8 = "F8", F9 = "F9", F10 = "F10", F11 = "F11", F12 = "F12" } type ShortcutKeys = [...MODIFIER[], KEY]; export interface KeyState { /** * This is purposely keyValue and not key to make KeyboardEvents not match the interface * KeyboardEvents need some processing to get the actual value * Use Shortcut.getKeyStateFromEvent to get the right KeyState from an event */ keyValue: string | null; altKey: boolean; ctrlKey: boolean; metaKey: boolean; shiftKey: boolean; } export interface ValidKeyState extends KeyState { keyValue: KEY | null; } type EventMap = CustomEventMap<{ onUpdate: CustomEvent; }>; export default class Shortcut extends EventTarget { readonly id: string; readonly name: string; readonly tooltip?: string; readonly isEditable: boolean; private readonly defaultKeyState; keyState: ValidKeyState; static NULL_KEY_STATE: ValidKeyState; /** * Use to check if a keyCode corresponds to an allowed key for a shortcut * @param keyCode The keyCode to check. This should be the charCode of the key * @returns Type predicate asserting the key is an allowed KEY */ static isAllowedKey(key: string | null): key is KEY; /** * Checks if a KeyState has a valid key. * @param state KeyState with any string as the key * @returns True if KeyState is is using an allowed keyCode */ static isValidKeyState(state: KeyState): state is ValidKeyState; static isMacPlatform: boolean; /** * Creates a KeyState from a valid array of modifier and key constants * @param keys Array of keys in the shortcut. Modifiers first and key last. Should use the MODIFIER and KEY enums * @returns KeyState representing the array of constants */ static createKeyState(keys: ShortcutKeys): ValidKeyState; static getKeyStateFromEvent(e: React.KeyboardEvent | KeyboardEvent): KeyState; /** * Gets display string for Windows (and Linux + any other non-Mac OS) * If the key is not an allowed key, the display will only display the modifiers * @param keyState KeyState to get the display for * @returns The string to display on Windows/non-Mac OS */ private static getWindowsDisplayText; /** * Gets display string Mac OS * If the key is not an allowed key, the display will only display the modifiers * @param keyState KeyState to get the display for * @returns The string to display on Mac OS */ private static getMacDisplayText; /** * Checks if 2 KeyStates match * @param state1 First KeyState to compare * @param state2 Second KeyState to compare * @returns True if the KeyStates match and have non-null keyValues */ static doKeyStatesMatch(state1: KeyState, state2: KeyState): boolean; /** * Gets the display string for the current OS from a KeyState. * @param keyState KeyState to get the display for * @returns Display string for the current OS */ static getDisplayText(keyState: KeyState): string; constructor({ id, shortcut, macShortcut, isEditable, name, tooltip, }: { id: string; shortcut: ShortcutKeys; macShortcut: ShortcutKeys; isEditable?: boolean; name: string; tooltip?: string; }); /** * Gets the display string for the current OS */ getDisplayText(): string; /** * Gets the current keyState for the Shortcut */ getKeyState(): ValidKeyState; /** * Sets the KeyState if it is valid * @param keyState */ setKeyState(keyState: KeyState): void; /** * Gets the default key state of the shortcut * @returns Default key state */ getDefaultKeyState(): ValidKeyState; isDefault(): boolean; /** * Sets the shortcut to have null keyValue */ setToNull(): void; isNull(): boolean; /** * Sets the shortcut to its default key state */ setToDefault(): void; /** * Checks if a KeyState matches the KeyState for the shortcut * @param keyState KeyState to check * @returns True if the passed KeyState matches the Shortcut's KeyState */ matchesKeyState(keyState: KeyState): boolean; /** * Alias for matchesKeyState * @param e KeyboardEvent to check if the Shortcut matches * @returns True if the event matches the Shortcut's KeyState */ matchesEvent(e: React.KeyboardEvent | KeyboardEvent): boolean; } export {}; //# sourceMappingURL=Shortcut.d.ts.map