1 import { isDialogOpen, isDropdownOpen, isEditing, isModalOpen } from '../busy';
2 import { isMac } from '../helpers/browser';
3 import type { KeyboardKeyType } from '../interfaces';
5 const HTML_TAGS_TO_IGNORE = ['input', 'select', 'textarea', 'button', 'a'];
7 export const isBusy = (e: KeyboardEvent) => {
8 const { tagName, isContentEditable } = e.target as HTMLElement;
11 HTML_TAGS_TO_IGNORE.includes(tagName.toLowerCase()) ||
20 export const isValidShortcut = (shortcut: KeyboardKeyType[], event: KeyboardEvent): boolean => {
21 const shortcutKeys = shortcut.map((key) => key.toLowerCase());
22 const eventKey = event.key.toLowerCase();
23 const eventMetaKeyPressed = isMac() ? event.metaKey : event.ctrlKey;
24 const eventShiftKeyPressed = event.shiftKey;
26 const shouldNotPressMetaKey = !shortcutKeys.includes('meta') && eventMetaKeyPressed;
27 const shouldNotPressShiftKey = !shortcutKeys.includes('shift') && eventShiftKeyPressed;
29 if (shouldNotPressMetaKey || shouldNotPressShiftKey) {
33 let isOk = shortcut.map(() => false);
34 shortcutKeys.forEach((shortcutKey, index) => {
36 (shortcutKey === 'shift' && eventShiftKeyPressed) ||
37 (shortcutKey === 'meta' && eventMetaKeyPressed) ||
38 shortcutKey === eventKey
47 if (isOk.every((item) => item === true)) {