UNPKG

@finos/legend-shared

Version:
71 lines 2.4 kB
/** * Copyright (c) 2020-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * List of keyboard named key * See https://www.w3.org/TR/uievents-key/#named-key-attribute-values * See https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values */ export declare enum KEYBOARD_NAMED_KEY { TAB = "Tab", CAPSLOCK = "CapsLock", SHIFT = "Shift", META = "Meta", ALT = "Alt", CONTROL = "Control", SPACE = "Space", ESC = "Escape", LEFT = "ArrowLeft", RIGHT = "ArrowRight", UP = "ArrowUp", DOWN = "ArrowDown", ENTER = "Enter", DELETE = "Delete", BACKSPACE = "Backspace", BACKQUOTE = "Backquote" } type KeyPressData = { modifiers: string[]; key: string; }; export type KeyBindingConfig = { [key: string]: { combinations: string[]; handler: (keyCombination: string, event: KeyboardEvent) => void; }; }; /** * Parses key bindings and pack them into parts * * grammar = `<sequence>` * <sequence> = `<press> <press> <press> ...` * <press> = `<key>` or `<mods>+<key>` * <mods> = `<mod>+<mod>+...` */ export declare function parseKeybinding(value: string): KeyPressData[]; /** * Checks if a series of keypress events matches a key binding sequence either partially or exactly. */ export declare const isMatchingKeyPressData: (event: KeyboardEvent, keyPressData: KeyPressData) => boolean; export declare const isMatchingKeyCombination: (event: KeyboardEvent, keyCombination: string) => boolean; /** * Create event listener for keyboard event (recommended to be used with `keydown/keyup` event) * * This succinct logic is adapted from `tinykeys` * See https://github.com/jamiebuilds/tinykeys */ export declare function createKeybindingsHandler(config: KeyBindingConfig): EventListener; export {}; //# sourceMappingURL=KeyBinding.d.ts.map