@lobehub/editor
Version:
A powerful and extensible rich text editor built on Meta's Lexical framework, providing a modern editing experience with React integration.
42 lines • 1.21 kB
JavaScript
import { isApple } from "../../common/sys";
var reservedModifierKeywords = new Set(['shift', 'alt', 'meta', 'mod', 'ctrl', 'control']);
var mappedKeys = {
AltLeft: 'alt',
AltRight: 'alt',
ControlLeft: 'ctrl',
ControlRight: 'ctrl',
MetaLeft: 'meta',
MetaRight: 'meta',
OSLeft: 'meta',
OSRight: 'meta',
ShiftLeft: 'shift',
ShiftRight: 'shift',
down: 'arrowdown',
esc: 'escape',
left: 'arrowleft',
return: 'enter',
right: 'arrowright',
up: 'arrowup'
};
export function mapCode(key) {
return (mappedKeys[key.trim()] || key.trim()).toLowerCase().replace(/key|digit|numpad/, '');
}
export function parseHotkey(hotkey) {
var keys = [];
keys = hotkey.toLocaleLowerCase().split('+').map(function (k) {
return mapCode(k);
});
var modifiers = {
altKey: keys.includes('alt'),
ctrlKey: keys.includes('ctrl') || keys.includes('control') || (!isApple ? keys.includes('mod') : false),
metaKey: keys.includes('meta') || (isApple ? keys.includes('mod') : false),
shiftKey: keys.includes('shift')
};
var singleCharKeys = keys.find(function (k) {
return !reservedModifierKeywords.has(k);
});
return {
key: singleCharKeys,
modifiers: modifiers
};
}