UNPKG

@vericus/slate-kit-bind-hotkey

Version:

a slate helper plugin to associate hotkey(s) to slate change

26 lines 912 B
import * as tslib_1 from "tslib"; import isHotkey from "is-hotkey"; function createOnKeyDown(opts) { var hotkeys = opts.hotkeys; var commandName = opts.commandName, commandArgs = opts.commandArgs; var hotkeyArrays = Array.isArray(hotkeys) ? hotkeys : [hotkeys]; function checkHotKey(event) { return hotkeyArrays.some(function (hotkey) { return isHotkey(hotkey)(event); }); } return function (event, editor, next) { if (checkHotKey(event) && editor[commandName]) { event.preventDefault(); event.stopPropagation(); if (commandArgs) { editor[commandName].apply(editor, tslib_1.__spread(commandArgs)); } else { editor[commandName](); } return true; } return next(); }; } export default createOnKeyDown; //# sourceMappingURL=onKeyDown.js.map