hotkeys-js
Advanced tools
Comparing version 3.12.2 to 3.13.0
/**! | ||
* hotkeys-js v3.12.2 | ||
* hotkeys-js v3.13.0 | ||
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. | ||
* | ||
* Copyright (c) 2023 kenny wong <wowohoo@qq.com> | ||
* https://jaywcjlove.github.io/hotkeys-js | ||
* https://github.com/jaywcjlove/hotkeys-js.git | ||
* | ||
* @website: https://jaywcjlove.github.io/hotkeys-js | ||
* Licensed under the MIT license | ||
@@ -12,3 +15,3 @@ */ | ||
var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; | ||
const isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; | ||
@@ -20,3 +23,3 @@ // 绑定事件 | ||
} else if (object.attachEvent) { | ||
object.attachEvent("on".concat(event), function () { | ||
object.attachEvent("on".concat(event), () => { | ||
method(window.event); | ||
@@ -29,4 +32,4 @@ }); | ||
function getMods(modifier, key) { | ||
var mods = key.slice(0, key.length - 1); | ||
for (var i = 0; i < mods.length; i++) mods[i] = modifier[mods[i].toLowerCase()]; | ||
const mods = key.slice(0, key.length - 1); | ||
for (let i = 0; i < mods.length; i++) mods[i] = modifier[mods[i].toLowerCase()]; | ||
return mods; | ||
@@ -39,4 +42,4 @@ } | ||
key = key.replace(/\s/g, ''); // 匹配任何空白字符,包括空格、制表符、换页符等等 | ||
var keys = key.split(','); // 同时设置多个快捷键,以','分割 | ||
var index = keys.lastIndexOf(''); | ||
const keys = key.split(','); // 同时设置多个快捷键,以','分割 | ||
let index = keys.lastIndexOf(''); | ||
@@ -54,6 +57,6 @@ // 快捷键可能包含',',需特殊处理 | ||
function compareArray(a1, a2) { | ||
var arr1 = a1.length >= a2.length ? a1 : a2; | ||
var arr2 = a1.length >= a2.length ? a2 : a1; | ||
var isIndex = true; | ||
for (var i = 0; i < arr1.length; i++) { | ||
const arr1 = a1.length >= a2.length ? a1 : a2; | ||
const arr2 = a1.length >= a2.length ? a2 : a1; | ||
let isIndex = true; | ||
for (let i = 0; i < arr1.length; i++) { | ||
if (arr2.indexOf(arr1[i]) === -1) isIndex = false; | ||
@@ -65,3 +68,3 @@ } | ||
// Special Keys | ||
var _keyMap = { | ||
const _keyMap = { | ||
backspace: 8, | ||
@@ -121,3 +124,3 @@ '⌫': 8, | ||
// Modifier Keys | ||
var _modifier = { | ||
const _modifier = { | ||
// shiftKey | ||
@@ -139,3 +142,3 @@ '⇧': 16, | ||
}; | ||
var modifierMap = { | ||
const modifierMap = { | ||
16: 'shiftKey', | ||
@@ -150,3 +153,3 @@ 18: 'altKey', | ||
}; | ||
var _mods = { | ||
const _mods = { | ||
16: false, | ||
@@ -157,28 +160,18 @@ 18: false, | ||
}; | ||
var _handlers = {}; | ||
const _handlers = {}; | ||
// F1~F12 special key | ||
for (var k = 1; k < 20; k++) { | ||
for (let k = 1; k < 20; k++) { | ||
_keyMap["f".concat(k)] = 111 + k; | ||
} | ||
var _downKeys = []; // 记录摁下的绑定键 | ||
var winListendFocus = false; // window是否已经监听了focus事件 | ||
var _scope = 'all'; // 默认热键范围 | ||
var elementHasBindEvent = []; // 已绑定事件的节点记录 | ||
let _downKeys = []; // 记录摁下的绑定键 | ||
let winListendFocus = false; // window是否已经监听了focus事件 | ||
let _scope = 'all'; // 默认热键范围 | ||
const elementHasBindEvent = []; // 已绑定事件的节点记录 | ||
// 返回键码 | ||
var code = function code(x) { | ||
return _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0); | ||
}; | ||
var getKey = function getKey(x) { | ||
return Object.keys(_keyMap).find(function (k) { | ||
return _keyMap[k] === x; | ||
}); | ||
}; | ||
var getModifier = function getModifier(x) { | ||
return Object.keys(_modifier).find(function (k) { | ||
return _modifier[k] === x; | ||
}); | ||
}; | ||
const code = x => _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0); | ||
const getKey = x => Object.keys(_keyMap).find(k => _keyMap[k] === x); | ||
const getModifier = x => Object.keys(_modifier).find(k => _modifier[k] === x); | ||
@@ -198,21 +191,19 @@ // 设置获取当前范围(默认为'所有') | ||
function getPressedKeyString() { | ||
return _downKeys.map(function (c) { | ||
return getKey(c) || getModifier(c) || String.fromCharCode(c); | ||
}); | ||
return _downKeys.map(c => getKey(c) || getModifier(c) || String.fromCharCode(c)); | ||
} | ||
function getAllKeyCodes() { | ||
var result = []; | ||
Object.keys(_handlers).forEach(function (k) { | ||
_handlers[k].forEach(function (_ref) { | ||
var key = _ref.key, | ||
scope = _ref.scope, | ||
mods = _ref.mods, | ||
shortcut = _ref.shortcut; | ||
const result = []; | ||
Object.keys(_handlers).forEach(k => { | ||
_handlers[k].forEach(_ref => { | ||
let { | ||
key, | ||
scope, | ||
mods, | ||
shortcut | ||
} = _ref; | ||
result.push({ | ||
scope: scope, | ||
shortcut: shortcut, | ||
mods: mods, | ||
keys: key.split('+').map(function (v) { | ||
return code(v); | ||
}) | ||
scope, | ||
shortcut, | ||
mods, | ||
keys: key.split('+').map(v => code(v)) | ||
}); | ||
@@ -227,5 +218,7 @@ }); | ||
function filter(event) { | ||
var target = event.target || event.srcElement; | ||
var tagName = target.tagName; | ||
var flag = true; | ||
const target = event.target || event.srcElement; | ||
const { | ||
tagName | ||
} = target; | ||
let flag = true; | ||
// ignore: isContentEditable === 'true', <input> and <textarea> when readOnly state is false, <select> | ||
@@ -243,3 +236,2 @@ if (target.isContentEditable || (tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT') && !target.readOnly) { | ||
} | ||
return _downKeys.indexOf(keyCode) !== -1; | ||
@@ -250,8 +242,8 @@ } | ||
function deleteScope(scope, newScope) { | ||
var handlers; | ||
var i; | ||
let handlers; | ||
let i; | ||
// 没有指定scope,获取scope | ||
if (!scope) scope = getScope(); | ||
for (var key in _handlers) { | ||
for (const key in _handlers) { | ||
if (Object.prototype.hasOwnProperty.call(_handlers, key)) { | ||
@@ -271,4 +263,4 @@ handlers = _handlers[key]; | ||
function clearModifier(event) { | ||
var key = event.keyCode || event.which || event.charCode; | ||
var i = _downKeys.indexOf(key); | ||
let key = event.keyCode || event.which || event.charCode; | ||
const i = _downKeys.indexOf(key); | ||
@@ -290,3 +282,3 @@ // 从列表中清除按压过的键 | ||
// 将修饰键重置为false | ||
for (var k in _modifier) if (_modifier[k] === key) hotkeys[k] = false; | ||
for (const k in _modifier) if (_modifier[k] === key) hotkeys[k] = false; | ||
} | ||
@@ -297,8 +289,6 @@ } | ||
if (typeof keysInfo === 'undefined') { | ||
Object.keys(_handlers).forEach(function (key) { | ||
return delete _handlers[key]; | ||
}); | ||
Object.keys(_handlers).forEach(key => delete _handlers[key]); | ||
} else if (Array.isArray(keysInfo)) { | ||
// support like : unbind([{key: 'ctrl+a', scope: 's1'}, {key: 'ctrl-a', scope: 's2', splitKey: '-'}]) | ||
keysInfo.forEach(function (info) { | ||
keysInfo.forEach(info => { | ||
if (info.key) eachUnbind(info); | ||
@@ -315,4 +305,3 @@ }); | ||
// eslint-disable-line | ||
var scope = args[0], | ||
method = args[1]; | ||
let [scope, method] = args; | ||
if (typeof scope === 'function') { | ||
@@ -324,4 +313,4 @@ method = scope; | ||
key: keysInfo, | ||
scope: scope, | ||
method: method, | ||
scope, | ||
method, | ||
splitKey: '+' | ||
@@ -333,21 +322,22 @@ }); | ||
// 解除绑定某个范围的快捷键 | ||
var eachUnbind = function eachUnbind(_ref2) { | ||
var key = _ref2.key, | ||
scope = _ref2.scope, | ||
method = _ref2.method, | ||
_ref2$splitKey = _ref2.splitKey, | ||
splitKey = _ref2$splitKey === void 0 ? '+' : _ref2$splitKey; | ||
var multipleKeys = getKeys(key); | ||
multipleKeys.forEach(function (originKey) { | ||
var unbindKeys = originKey.split(splitKey); | ||
var len = unbindKeys.length; | ||
var lastKey = unbindKeys[len - 1]; | ||
var keyCode = lastKey === '*' ? '*' : code(lastKey); | ||
const eachUnbind = _ref2 => { | ||
let { | ||
key, | ||
scope, | ||
method, | ||
splitKey = '+' | ||
} = _ref2; | ||
const multipleKeys = getKeys(key); | ||
multipleKeys.forEach(originKey => { | ||
const unbindKeys = originKey.split(splitKey); | ||
const len = unbindKeys.length; | ||
const lastKey = unbindKeys[len - 1]; | ||
const keyCode = lastKey === '*' ? '*' : code(lastKey); | ||
if (!_handlers[keyCode]) return; | ||
// 判断是否传入范围,没有就获取范围 | ||
if (!scope) scope = getScope(); | ||
var mods = len > 1 ? getMods(_modifier, unbindKeys) : []; | ||
_handlers[keyCode] = _handlers[keyCode].filter(function (record) { | ||
const mods = len > 1 ? getMods(_modifier, unbindKeys) : []; | ||
_handlers[keyCode] = _handlers[keyCode].filter(record => { | ||
// 通过函数判断,是否解除绑定,函数相等直接返回 | ||
var isMatchingMethod = method ? record.method === method : true; | ||
const isMatchingMethod = method ? record.method === method : true; | ||
return !(isMatchingMethod && record.scope === scope && compareArray(record.mods, mods)); | ||
@@ -363,3 +353,3 @@ }); | ||
} | ||
var modifiersMatch; | ||
let modifiersMatch; | ||
@@ -370,3 +360,3 @@ // 看它是否在当前范围 | ||
modifiersMatch = handler.mods.length > 0; | ||
for (var y in _mods) { | ||
for (const y in _mods) { | ||
if (Object.prototype.hasOwnProperty.call(_mods, y)) { | ||
@@ -394,4 +384,4 @@ if (!_mods[y] && handler.mods.indexOf(+y) > -1 || _mods[y] && handler.mods.indexOf(+y) === -1) { | ||
function dispatch(event, element) { | ||
var asterisk = _handlers['*']; | ||
var key = event.keyCode || event.which || event.charCode; | ||
const asterisk = _handlers['*']; | ||
let key = event.keyCode || event.which || event.charCode; | ||
@@ -416,4 +406,4 @@ // 表单控件过滤 默认表单控件不触发快捷键 | ||
*/ | ||
['ctrlKey', 'altKey', 'shiftKey', 'metaKey'].forEach(function (keyName) { | ||
var keyNum = modifierMap[keyName]; | ||
['ctrlKey', 'altKey', 'shiftKey', 'metaKey'].forEach(keyName => { | ||
const keyNum = modifierMap[keyName]; | ||
if (event[keyName] && _downKeys.indexOf(keyNum) === -1) { | ||
@@ -441,3 +431,3 @@ _downKeys.push(keyNum); | ||
// 将特殊字符的key注册到 hotkeys 上 | ||
for (var k in _modifier) { | ||
for (const k in _modifier) { | ||
if (_modifier[k] === key) hotkeys[k] = true; | ||
@@ -449,3 +439,3 @@ } | ||
// 将 modifierMap 里面的修饰键绑定到 event 中 | ||
for (var e in _mods) { | ||
for (const e in _mods) { | ||
if (Object.prototype.hasOwnProperty.call(_mods, e)) { | ||
@@ -473,6 +463,6 @@ _mods[e] = event[modifierMap[e]]; | ||
// 获取范围 默认为 `all` | ||
var scope = getScope(); | ||
const scope = getScope(); | ||
// 对任何快捷键都需要做的处理 | ||
if (asterisk) { | ||
for (var i = 0; i < asterisk.length; i++) { | ||
for (let i = 0; i < asterisk.length; i++) { | ||
if (asterisk[i].scope === scope && (event.type === 'keydown' && asterisk[i].keydown || event.type === 'keyup' && asterisk[i].keyup)) { | ||
@@ -485,10 +475,12 @@ eventHandler(event, asterisk[i], scope, element); | ||
if (!(key in _handlers)) return; | ||
for (var _i = 0; _i < _handlers[key].length; _i++) { | ||
if (event.type === 'keydown' && _handlers[key][_i].keydown || event.type === 'keyup' && _handlers[key][_i].keyup) { | ||
if (_handlers[key][_i].key) { | ||
var record = _handlers[key][_i]; | ||
var splitKey = record.splitKey; | ||
var keyShortcut = record.key.split(splitKey); | ||
var _downKeysCurrent = []; // 记录当前按键键值 | ||
for (var a = 0; a < keyShortcut.length; a++) { | ||
for (let i = 0; i < _handlers[key].length; i++) { | ||
if (event.type === 'keydown' && _handlers[key][i].keydown || event.type === 'keyup' && _handlers[key][i].keyup) { | ||
if (_handlers[key][i].key) { | ||
const record = _handlers[key][i]; | ||
const { | ||
splitKey | ||
} = record; | ||
const keyShortcut = record.key.split(splitKey); | ||
const _downKeysCurrent = []; // 记录当前按键键值 | ||
for (let a = 0; a < keyShortcut.length; a++) { | ||
_downKeysCurrent.push(code(keyShortcut[a])); | ||
@@ -511,11 +503,12 @@ } | ||
_downKeys = []; | ||
var keys = getKeys(key); // 需要处理的快捷键列表 | ||
var mods = []; | ||
var scope = 'all'; // scope默认为all,所有范围都有效 | ||
var element = document; // 快捷键事件绑定节点 | ||
var i = 0; | ||
var keyup = false; | ||
var keydown = true; | ||
var splitKey = '+'; | ||
var capture = false; | ||
const keys = getKeys(key); // 需要处理的快捷键列表 | ||
let mods = []; | ||
let scope = 'all'; // scope默认为all,所有范围都有效 | ||
let element = document; // 快捷键事件绑定节点 | ||
let i = 0; | ||
let keyup = false; | ||
let keydown = true; | ||
let splitKey = '+'; | ||
let capture = false; | ||
let single = false; // 单个callback | ||
@@ -533,4 +526,4 @@ // 对为设定范围的判断 | ||
if (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line | ||
if (option.single === true) single = true; // eslint-disable-line | ||
} | ||
if (typeof option === 'string') scope = option; | ||
@@ -552,12 +545,14 @@ | ||
if (!(key in _handlers)) _handlers[key] = []; | ||
// 如果只允许单个callback,重新设置_handlers | ||
if (single) _handlers[key] = []; | ||
_handlers[key].push({ | ||
keyup: keyup, | ||
keydown: keydown, | ||
scope: scope, | ||
mods: mods, | ||
keyup, | ||
keydown, | ||
scope, | ||
mods, | ||
shortcut: keys[i], | ||
method: method, | ||
method, | ||
key: keys[i], | ||
splitKey: splitKey, | ||
element: element | ||
splitKey, | ||
element | ||
}); | ||
@@ -568,3 +563,3 @@ } | ||
elementHasBindEvent.push(element); | ||
addEvent(element, 'keydown', function (e) { | ||
addEvent(element, 'keydown', e => { | ||
dispatch(e, element); | ||
@@ -574,7 +569,7 @@ }, capture); | ||
winListendFocus = true; | ||
addEvent(window, 'focus', function () { | ||
addEvent(window, 'focus', () => { | ||
_downKeys = []; | ||
}, capture); | ||
} | ||
addEvent(element, 'keyup', function (e) { | ||
addEvent(element, 'keyup', e => { | ||
dispatch(e, element); | ||
@@ -586,8 +581,6 @@ clearModifier(e); | ||
function trigger(shortcut) { | ||
var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'all'; | ||
Object.keys(_handlers).forEach(function (key) { | ||
var dataList = _handlers[key].filter(function (item) { | ||
return item.scope === scope && item.shortcut === shortcut; | ||
}); | ||
dataList.forEach(function (data) { | ||
let scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'all'; | ||
Object.keys(_handlers).forEach(key => { | ||
const dataList = _handlers[key].filter(item => item.scope === scope && item.shortcut === shortcut); | ||
dataList.forEach(data => { | ||
if (data && data.method) { | ||
@@ -599,18 +592,18 @@ data.method(); | ||
} | ||
var _api = { | ||
getPressedKeyString: getPressedKeyString, | ||
setScope: setScope, | ||
getScope: getScope, | ||
deleteScope: deleteScope, | ||
getPressedKeyCodes: getPressedKeyCodes, | ||
getAllKeyCodes: getAllKeyCodes, | ||
isPressed: isPressed, | ||
filter: filter, | ||
trigger: trigger, | ||
unbind: unbind, | ||
const _api = { | ||
getPressedKeyString, | ||
setScope, | ||
getScope, | ||
deleteScope, | ||
getPressedKeyCodes, | ||
getAllKeyCodes, | ||
isPressed, | ||
filter, | ||
trigger, | ||
unbind, | ||
keyMap: _keyMap, | ||
modifier: _modifier, | ||
modifierMap: modifierMap | ||
modifierMap | ||
}; | ||
for (var a in _api) { | ||
for (const a in _api) { | ||
if (Object.prototype.hasOwnProperty.call(_api, a)) { | ||
@@ -621,4 +614,4 @@ hotkeys[a] = _api[a]; | ||
if (typeof window !== 'undefined') { | ||
var _hotkeys = window.hotkeys; | ||
hotkeys.noConflict = function (deep) { | ||
const _hotkeys = window.hotkeys; | ||
hotkeys.noConflict = deep => { | ||
if (deep && window.hotkeys === hotkeys) { | ||
@@ -625,0 +618,0 @@ window.hotkeys = _hotkeys; |
@@ -1,2 +0,2 @@ | ||
/*! hotkeys-js v3.12.2 | MIT © 2023 kenny wong <wowohoo@qq.com> https://jaywcjlove.github.io/hotkeys-js */ | ||
"use strict";var isff="undefined"!=typeof navigator&&0<navigator.userAgent.toLowerCase().indexOf("firefox");function addEvent(e,n,t,o){e.addEventListener?e.addEventListener(n,t,o):e.attachEvent&&e.attachEvent("on".concat(n),function(){t(window.event)})}function getMods(e,n){for(var t=n.slice(0,n.length-1),o=0;o<t.length;o++)t[o]=e[t[o].toLowerCase()];return t}function getKeys(e){for(var n=(e=(e="string"!=typeof e?"":e).replace(/\s/g,"")).split(","),t=n.lastIndexOf("");0<=t;)n[t-1]+=",",n.splice(t,1),t=n.lastIndexOf("");return n}function compareArray(e,n){for(var t=e.length<n.length?n:e,o=e.length<n.length?e:n,r=!0,s=0;s<t.length;s++)~o.indexOf(t[s])||(r=!1);return r}for(var _keyMap={backspace:8,"\u232b":8,tab:9,clear:12,enter:13,"\u21a9":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"\u21ea":20,",":188,".":190,"/":191,"`":192,"-":isff?173:189,"=":isff?61:187,";":isff?59:186,"'":222,"[":219,"]":221,"\\":220},_modifier={"\u21e7":16,shift:16,"\u2325":18,alt:18,option:18,"\u2303":17,ctrl:17,control:17,"\u2318":91,cmd:91,command:91},modifierMap={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},_mods={16:!1,18:!1,17:!1,91:!1},_handlers={},k=1;k<20;k++)_keyMap["f".concat(k)]=111+k;var _downKeys=[],winListendFocus=!1,_scope="all",elementHasBindEvent=[],code=function(e){return _keyMap[e.toLowerCase()]||_modifier[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)},getKey=function(n){return Object.keys(_keyMap).find(function(e){return _keyMap[e]===n})},getModifier=function(n){return Object.keys(_modifier).find(function(e){return _modifier[e]===n})};function setScope(e){_scope=e||"all"}function getScope(){return _scope||"all"}function getPressedKeyCodes(){return _downKeys.slice(0)}function getPressedKeyString(){return _downKeys.map(function(e){return getKey(e)||getModifier(e)||String.fromCharCode(e)})}function getAllKeyCodes(){var t=[];return Object.keys(_handlers).forEach(function(e){_handlers[e].forEach(function(e){var n=e.key;t.push({scope:e.scope,shortcut:e.shortcut,mods:e.mods,keys:n.split("+").map(function(e){return code(e)})})})}),t}function filter(e){var e=e.target||e.srcElement,n=e.tagName;return!e.isContentEditable&&("INPUT"!==n&&"TEXTAREA"!==n&&"SELECT"!==n||e.readOnly)?!0:!1}function isPressed(e){return"string"==typeof e&&(e=code(e)),!!~_downKeys.indexOf(e)}function deleteScope(e,n){var t,o,r;for(r in e=e||getScope(),_handlers)if(Object.prototype.hasOwnProperty.call(_handlers,r))for(t=_handlers[r],o=0;o<t.length;)t[o].scope===e?t.splice(o,1):o++;getScope()===e&&setScope(n||"all")}function clearModifier(e){var n=e.keyCode||e.which||e.charCode,t=_downKeys.indexOf(n);if(t<0||_downKeys.splice(t,1),e.key&&"meta"==e.key.toLowerCase()&&_downKeys.splice(0,_downKeys.length),(n=93!==n&&224!==n?n:91)in _mods)for(var o in _mods[n]=!1,_modifier)_modifier[o]===n&&(hotkeys[o]=!1)}function unbind(e){if(void 0===e)Object.keys(_handlers).forEach(function(e){return delete _handlers[e]});else if(Array.isArray(e))e.forEach(function(e){e.key&&eachUnbind(e)});else if("object"==typeof e)e.key&&eachUnbind(e);else if("string"==typeof e){for(var n=arguments.length,t=Array(1<n?n-1:0),o=1;o<n;o++)t[o-1]=arguments[o];var r=t[0],s=t[1];"function"==typeof r&&(s=r,r=""),eachUnbind({key:e,scope:r,method:s,splitKey:"+"})}}var eachUnbind=function(e){var r=e.scope,s=e.method,n=e.splitKey,i=void 0===n?"+":n;getKeys(e.key).forEach(function(e){var n,e=e.split(i),t=e.length,o=e[t-1],o="*"===o?"*":code(o);_handlers[o]&&(r=r||getScope(),n=1<t?getMods(_modifier,e):[],_handlers[o]=_handlers[o].filter(function(e){return!((!s||e.method===s)&&e.scope===r&&compareArray(e.mods,n))}))})};function eventHandler(e,n,t,o){var r;if(n.element===o&&(n.scope===t||"all"===n.scope)){for(var s in r=0<n.mods.length,_mods)Object.prototype.hasOwnProperty.call(_mods,s)&&(!_mods[s]&&~n.mods.indexOf(+s)||_mods[s]&&!~n.mods.indexOf(+s))&&(r=!1);(0!==n.mods.length||_mods[16]||_mods[18]||_mods[17]||_mods[91])&&!r&&"*"!==n.shortcut||(n.keys=[],n.keys=n.keys.concat(_downKeys),!1===n.method(e,n)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble)&&(e.cancelBubble=!0))}}function dispatch(t,e){var n=_handlers["*"],o=t.keyCode||t.which||t.charCode;if(hotkeys.filter.call(this,t)){if(~_downKeys.indexOf(o=93!==o&&224!==o?o:91)||229===o||_downKeys.push(o),["ctrlKey","altKey","shiftKey","metaKey"].forEach(function(e){var n=modifierMap[e];t[e]&&!~_downKeys.indexOf(n)?_downKeys.push(n):!t[e]&&~_downKeys.indexOf(n)?_downKeys.splice(_downKeys.indexOf(n),1):"metaKey"!==e||!t[e]||3!==_downKeys.length||t.ctrlKey||t.shiftKey||t.altKey||(_downKeys=_downKeys.slice(_downKeys.indexOf(n)))}),o in _mods){for(var r in _mods[o]=!0,_modifier)_modifier[r]===o&&(hotkeys[r]=!0);if(!n)return}for(var s in _mods)Object.prototype.hasOwnProperty.call(_mods,s)&&(_mods[s]=t[modifierMap[s]]);t.getModifierState&&(!t.altKey||t.ctrlKey)&&t.getModifierState("AltGraph")&&(~_downKeys.indexOf(17)||_downKeys.push(17),~_downKeys.indexOf(18)||_downKeys.push(18),_mods[17]=!0,_mods[18]=!0);var i=getScope();if(n)for(var d=0;d<n.length;d++)n[d].scope===i&&("keydown"===t.type&&n[d].keydown||"keyup"===t.type&&n[d].keyup)&&eventHandler(t,n[d],i,e);if(o in _handlers)for(var a=0;a<_handlers[o].length;a++)if(("keydown"===t.type&&_handlers[o][a].keydown||"keyup"===t.type&&_handlers[o][a].keyup)&&_handlers[o][a].key){for(var c=_handlers[o][a],f=c.key.split(c.splitKey),l=[],y=0;y<f.length;y++)l.push(code(f[y]));l.sort().join("")===_downKeys.sort().join("")&&eventHandler(t,c,i,e)}}}function isElementBind(e){return!!~elementHasBindEvent.indexOf(e)}function hotkeys(e,n,t){_downKeys=[];var o=getKeys(e),r=[],s="all",i=document,d=0,a=!1,c=!0,f="+",l=!1;for(void 0===t&&"function"==typeof n&&(t=n),"[object Object]"===Object.prototype.toString.call(n)&&(n.scope&&(s=n.scope),n.element&&(i=n.element),n.keyup&&(a=n.keyup),void 0!==n.keydown&&(c=n.keydown),void 0!==n.capture&&(l=n.capture),"string"==typeof n.splitKey)&&(f=n.splitKey),"string"==typeof n&&(s=n);d<o.length;d++)r=[],1<(e=o[d].split(f)).length&&(r=getMods(_modifier,e)),(e="*"===(e=e[e.length-1])?"*":code(e))in _handlers||(_handlers[e]=[]),_handlers[e].push({keyup:a,keydown:c,scope:s,mods:r,shortcut:o[d],method:t,key:o[d],splitKey:f,element:i});void 0!==i&&!isElementBind(i)&&window&&(elementHasBindEvent.push(i),addEvent(i,"keydown",function(e){dispatch(e,i)},l),winListendFocus||(winListendFocus=!0,addEvent(window,"focus",function(){_downKeys=[]},l)),addEvent(i,"keyup",function(e){dispatch(e,i),clearModifier(e)},l))}function trigger(n){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(_handlers).forEach(function(e){_handlers[e].filter(function(e){return e.scope===t&&e.shortcut===n}).forEach(function(e){e&&e.method&&e.method()})})}var a,_hotkeys,_api={getPressedKeyString:getPressedKeyString,setScope:setScope,getScope:getScope,deleteScope:deleteScope,getPressedKeyCodes:getPressedKeyCodes,getAllKeyCodes:getAllKeyCodes,isPressed:isPressed,filter:filter,trigger:trigger,unbind:unbind,keyMap:_keyMap,modifier:_modifier,modifierMap:modifierMap};for(a in _api)Object.prototype.hasOwnProperty.call(_api,a)&&(hotkeys[a]=_api[a]);"undefined"!=typeof window&&(_hotkeys=window.hotkeys,hotkeys.noConflict=function(e){return e&&window.hotkeys===hotkeys&&(window.hotkeys=_hotkeys),hotkeys},window.hotkeys=hotkeys),module.exports=hotkeys; | ||
/*! hotkeys-js v3.13.0 | MIT © 2023 kenny wong <wowohoo@qq.com> https://jaywcjlove.github.io/hotkeys-js */ | ||
"use strict";const isff="undefined"!=typeof navigator&&0<navigator.userAgent.toLowerCase().indexOf("firefox");function addEvent(e,t,o,n){e.addEventListener?e.addEventListener(t,o,n):e.attachEvent&&e.attachEvent("on".concat(t),()=>{o(window.event)})}function getMods(t,e){var o=e.slice(0,e.length-1);for(let e=0;e<o.length;e++)o[e]=t[o[e].toLowerCase()];return o}function getKeys(e){var t=(e=(e="string"!=typeof e?"":e).replace(/\s/g,"")).split(",");let o=t.lastIndexOf("");for(;0<=o;)t[o-1]+=",",t.splice(o,1),o=t.lastIndexOf("");return t}function compareArray(e,t){var o=e.length<t.length?t:e,n=e.length<t.length?e:t;let s=!0;for(let e=0;e<o.length;e++)~n.indexOf(o[e])||(s=!1);return s}const _keyMap={backspace:8,"\u232b":8,tab:9,clear:12,enter:13,"\u21a9":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"\u21ea":20,",":188,".":190,"/":191,"`":192,"-":isff?173:189,"=":isff?61:187,";":isff?59:186,"'":222,"[":219,"]":221,"\\":220},_modifier={"\u21e7":16,shift:16,"\u2325":18,alt:18,option:18,"\u2303":17,ctrl:17,control:17,"\u2318":91,cmd:91,command:91},modifierMap={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},_mods={16:!1,18:!1,17:!1,91:!1},_handlers={};for(let e=1;e<20;e++)_keyMap["f".concat(e)]=111+e;let _downKeys=[],winListendFocus=!1,_scope="all";const elementHasBindEvent=[],code=e=>_keyMap[e.toLowerCase()]||_modifier[e.toLowerCase()]||e.toUpperCase().charCodeAt(0),getKey=t=>Object.keys(_keyMap).find(e=>_keyMap[e]===t),getModifier=t=>Object.keys(_modifier).find(e=>_modifier[e]===t);function setScope(e){_scope=e||"all"}function getScope(){return _scope||"all"}function getPressedKeyCodes(){return _downKeys.slice(0)}function getPressedKeyString(){return _downKeys.map(e=>getKey(e)||getModifier(e)||String.fromCharCode(e))}function getAllKeyCodes(){const s=[];return Object.keys(_handlers).forEach(e=>{_handlers[e].forEach(e=>{var{key:e,scope:t,mods:o,shortcut:n}=e;s.push({scope:t,shortcut:n,mods:o,keys:e.split("+").map(e=>code(e))})})}),s}function filter(e){var e=e.target||e.srcElement,t=e["tagName"];let o=!e.isContentEditable&&("INPUT"!==t&&"TEXTAREA"!==t&&"SELECT"!==t||e.readOnly)?!0:!1;return o}function isPressed(e){return"string"==typeof e&&(e=code(e)),!!~_downKeys.indexOf(e)}function deleteScope(e,t){var o;let n;e=e||getScope();for(const s in _handlers)if(Object.prototype.hasOwnProperty.call(_handlers,s))for(o=_handlers[s],n=0;n<o.length;)o[n].scope===e?o.splice(n,1):n++;getScope()===e&&setScope(t||"all")}function clearModifier(e){let t=e.keyCode||e.which||e.charCode;var o=_downKeys.indexOf(t);if(o<0||_downKeys.splice(o,1),e.key&&"meta"==e.key.toLowerCase()&&_downKeys.splice(0,_downKeys.length),(t=93!==t&&224!==t?t:91)in _mods){_mods[t]=!1;for(const n in _modifier)_modifier[n]===t&&(hotkeys[n]=!1)}}function unbind(o){if(void 0===o)Object.keys(_handlers).forEach(e=>delete _handlers[e]);else if(Array.isArray(o))o.forEach(e=>{e.key&&eachUnbind(e)});else if("object"==typeof o)o.key&&eachUnbind(o);else if("string"==typeof o){for(var n=arguments.length,s=Array(1<n?n-1:0),d=1;d<n;d++)s[d-1]=arguments[d];let[e,t]=s;"function"==typeof e&&(t=e,e=""),eachUnbind({key:o,scope:e,method:t,splitKey:"+"})}}const eachUnbind=e=>{let{key:t,scope:s,method:d,splitKey:i="+"}=e;getKeys(t).forEach(e=>{var e=e.split(i),t=e.length,o=e[t-1],o="*"===o?"*":code(o);if(_handlers[o]){s=s||getScope();const n=1<t?getMods(_modifier,e):[];_handlers[o]=_handlers[o].filter(e=>{return!((!d||e.method===d)&&e.scope===s&&compareArray(e.mods,n))})}})};function eventHandler(t,o,n,e){if(o.element===e){let e;if(o.scope===n||"all"===o.scope){e=0<o.mods.length;for(const s in _mods)Object.prototype.hasOwnProperty.call(_mods,s)&&(!_mods[s]&&~o.mods.indexOf(+s)||_mods[s]&&!~o.mods.indexOf(+s))&&(e=!1);(0!==o.mods.length||_mods[16]||_mods[18]||_mods[17]||_mods[91])&&!e&&"*"!==o.shortcut||(o.keys=[],o.keys=o.keys.concat(_downKeys),!1===o.method(t,o)&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble)&&(t.cancelBubble=!0))}}}function dispatch(o,t){var n=_handlers["*"];let s=o.keyCode||o.which||o.charCode;if(hotkeys.filter.call(this,o)){if(93!==s&&224!==s||(s=91),~_downKeys.indexOf(s)||229===s||_downKeys.push(s),["ctrlKey","altKey","shiftKey","metaKey"].forEach(e=>{var t=modifierMap[e];o[e]&&!~_downKeys.indexOf(t)?_downKeys.push(t):!o[e]&&~_downKeys.indexOf(t)?_downKeys.splice(_downKeys.indexOf(t),1):"metaKey"!==e||!o[e]||3!==_downKeys.length||o.ctrlKey||o.shiftKey||o.altKey||(_downKeys=_downKeys.slice(_downKeys.indexOf(t)))}),s in _mods){_mods[s]=!0;for(const e in _modifier)_modifier[e]===s&&(hotkeys[e]=!0);if(!n)return}for(const c in _mods)Object.prototype.hasOwnProperty.call(_mods,c)&&(_mods[c]=o[modifierMap[c]]);o.getModifierState&&(!o.altKey||o.ctrlKey)&&o.getModifierState("AltGraph")&&(~_downKeys.indexOf(17)||_downKeys.push(17),~_downKeys.indexOf(18)||_downKeys.push(18),_mods[17]=!0,_mods[18]=!0);var d=getScope();if(n)for(let e=0;e<n.length;e++)n[e].scope===d&&("keydown"===o.type&&n[e].keydown||"keyup"===o.type&&n[e].keyup)&&eventHandler(o,n[e],d,t);if(s in _handlers)for(let e=0;e<_handlers[s].length;e++)if(("keydown"===o.type&&_handlers[s][e].keydown||"keyup"===o.type&&_handlers[s][e].keyup)&&_handlers[s][e].key){var i=_handlers[s][e],r=i["splitKey"],l=i.key.split(r),a=[];for(let e=0;e<l.length;e++)a.push(code(l[e]));a.sort().join("")===_downKeys.sort().join("")&&eventHandler(o,i,d,t)}}}function isElementBind(e){return!!~elementHasBindEvent.indexOf(e)}function hotkeys(e,t,o){_downKeys=[];var n=getKeys(e);let s=[],d="all",i=document,r=0,l=!1,a=!0,c="+",y=!1,f=!1;for(void 0===o&&"function"==typeof t&&(o=t),"[object Object]"===Object.prototype.toString.call(t)&&(t.scope&&(d=t.scope),t.element&&(i=t.element),t.keyup&&(l=t.keyup),void 0!==t.keydown&&(a=t.keydown),void 0!==t.capture&&(y=t.capture),"string"==typeof t.splitKey&&(c=t.splitKey),!0===t.single)&&(f=!0),"string"==typeof t&&(d=t);r<n.length;r++)e=n[r].split(c),s=[],1<e.length&&(s=getMods(_modifier,e)),(e="*"===(e=e[e.length-1])?"*":code(e))in _handlers||(_handlers[e]=[]),f&&(_handlers[e]=[]),_handlers[e].push({keyup:l,keydown:a,scope:d,mods:s,shortcut:n[r],method:o,key:n[r],splitKey:c,element:i});void 0!==i&&!isElementBind(i)&&window&&(elementHasBindEvent.push(i),addEvent(i,"keydown",e=>{dispatch(e,i)},y),winListendFocus||(winListendFocus=!0,addEvent(window,"focus",()=>{_downKeys=[]},y)),addEvent(i,"keyup",e=>{dispatch(e,i),clearModifier(e)},y))}function trigger(t){let o=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(_handlers).forEach(e=>{_handlers[e].filter(e=>e.scope===o&&e.shortcut===t).forEach(e=>{e&&e.method&&e.method()})})}const _api={getPressedKeyString:getPressedKeyString,setScope:setScope,getScope:getScope,deleteScope:deleteScope,getPressedKeyCodes:getPressedKeyCodes,getAllKeyCodes:getAllKeyCodes,isPressed:isPressed,filter:filter,trigger:trigger,unbind:unbind,keyMap:_keyMap,modifier:_modifier,modifierMap:modifierMap};for(const f0 in _api)Object.prototype.hasOwnProperty.call(_api,f0)&&(hotkeys[f0]=_api[f0]);if("undefined"!=typeof window){const g0=window.hotkeys;hotkeys.noConflict=e=>(e&&window.hotkeys===hotkeys&&(window.hotkeys=g0),hotkeys),window.hotkeys=hotkeys}module.exports=hotkeys; |
/**! | ||
* hotkeys-js v3.12.2 | ||
* hotkeys-js v3.13.0 | ||
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. | ||
* | ||
* Copyright (c) 2023 kenny wong <wowohoo@qq.com> | ||
* https://jaywcjlove.github.io/hotkeys-js | ||
* https://github.com/jaywcjlove/hotkeys-js.git | ||
* | ||
* @website: https://jaywcjlove.github.io/hotkeys-js | ||
* Licensed under the MIT license | ||
*/ | ||
var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; | ||
const isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; | ||
@@ -17,3 +20,3 @@ // 绑定事件 | ||
} else if (object.attachEvent) { | ||
object.attachEvent("on".concat(event), function () { | ||
object.attachEvent("on".concat(event), () => { | ||
method(window.event); | ||
@@ -26,4 +29,4 @@ }); | ||
function getMods(modifier, key) { | ||
var mods = key.slice(0, key.length - 1); | ||
for (var i = 0; i < mods.length; i++) mods[i] = modifier[mods[i].toLowerCase()]; | ||
const mods = key.slice(0, key.length - 1); | ||
for (let i = 0; i < mods.length; i++) mods[i] = modifier[mods[i].toLowerCase()]; | ||
return mods; | ||
@@ -36,4 +39,4 @@ } | ||
key = key.replace(/\s/g, ''); // 匹配任何空白字符,包括空格、制表符、换页符等等 | ||
var keys = key.split(','); // 同时设置多个快捷键,以','分割 | ||
var index = keys.lastIndexOf(''); | ||
const keys = key.split(','); // 同时设置多个快捷键,以','分割 | ||
let index = keys.lastIndexOf(''); | ||
@@ -51,6 +54,6 @@ // 快捷键可能包含',',需特殊处理 | ||
function compareArray(a1, a2) { | ||
var arr1 = a1.length >= a2.length ? a1 : a2; | ||
var arr2 = a1.length >= a2.length ? a2 : a1; | ||
var isIndex = true; | ||
for (var i = 0; i < arr1.length; i++) { | ||
const arr1 = a1.length >= a2.length ? a1 : a2; | ||
const arr2 = a1.length >= a2.length ? a2 : a1; | ||
let isIndex = true; | ||
for (let i = 0; i < arr1.length; i++) { | ||
if (arr2.indexOf(arr1[i]) === -1) isIndex = false; | ||
@@ -62,3 +65,3 @@ } | ||
// Special Keys | ||
var _keyMap = { | ||
const _keyMap = { | ||
backspace: 8, | ||
@@ -118,3 +121,3 @@ '⌫': 8, | ||
// Modifier Keys | ||
var _modifier = { | ||
const _modifier = { | ||
// shiftKey | ||
@@ -136,3 +139,3 @@ '⇧': 16, | ||
}; | ||
var modifierMap = { | ||
const modifierMap = { | ||
16: 'shiftKey', | ||
@@ -147,3 +150,3 @@ 18: 'altKey', | ||
}; | ||
var _mods = { | ||
const _mods = { | ||
16: false, | ||
@@ -154,28 +157,18 @@ 18: false, | ||
}; | ||
var _handlers = {}; | ||
const _handlers = {}; | ||
// F1~F12 special key | ||
for (var k = 1; k < 20; k++) { | ||
for (let k = 1; k < 20; k++) { | ||
_keyMap["f".concat(k)] = 111 + k; | ||
} | ||
var _downKeys = []; // 记录摁下的绑定键 | ||
var winListendFocus = false; // window是否已经监听了focus事件 | ||
var _scope = 'all'; // 默认热键范围 | ||
var elementHasBindEvent = []; // 已绑定事件的节点记录 | ||
let _downKeys = []; // 记录摁下的绑定键 | ||
let winListendFocus = false; // window是否已经监听了focus事件 | ||
let _scope = 'all'; // 默认热键范围 | ||
const elementHasBindEvent = []; // 已绑定事件的节点记录 | ||
// 返回键码 | ||
var code = function code(x) { | ||
return _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0); | ||
}; | ||
var getKey = function getKey(x) { | ||
return Object.keys(_keyMap).find(function (k) { | ||
return _keyMap[k] === x; | ||
}); | ||
}; | ||
var getModifier = function getModifier(x) { | ||
return Object.keys(_modifier).find(function (k) { | ||
return _modifier[k] === x; | ||
}); | ||
}; | ||
const code = x => _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0); | ||
const getKey = x => Object.keys(_keyMap).find(k => _keyMap[k] === x); | ||
const getModifier = x => Object.keys(_modifier).find(k => _modifier[k] === x); | ||
@@ -195,21 +188,19 @@ // 设置获取当前范围(默认为'所有') | ||
function getPressedKeyString() { | ||
return _downKeys.map(function (c) { | ||
return getKey(c) || getModifier(c) || String.fromCharCode(c); | ||
}); | ||
return _downKeys.map(c => getKey(c) || getModifier(c) || String.fromCharCode(c)); | ||
} | ||
function getAllKeyCodes() { | ||
var result = []; | ||
Object.keys(_handlers).forEach(function (k) { | ||
_handlers[k].forEach(function (_ref) { | ||
var key = _ref.key, | ||
scope = _ref.scope, | ||
mods = _ref.mods, | ||
shortcut = _ref.shortcut; | ||
const result = []; | ||
Object.keys(_handlers).forEach(k => { | ||
_handlers[k].forEach(_ref => { | ||
let { | ||
key, | ||
scope, | ||
mods, | ||
shortcut | ||
} = _ref; | ||
result.push({ | ||
scope: scope, | ||
shortcut: shortcut, | ||
mods: mods, | ||
keys: key.split('+').map(function (v) { | ||
return code(v); | ||
}) | ||
scope, | ||
shortcut, | ||
mods, | ||
keys: key.split('+').map(v => code(v)) | ||
}); | ||
@@ -224,5 +215,7 @@ }); | ||
function filter(event) { | ||
var target = event.target || event.srcElement; | ||
var tagName = target.tagName; | ||
var flag = true; | ||
const target = event.target || event.srcElement; | ||
const { | ||
tagName | ||
} = target; | ||
let flag = true; | ||
// ignore: isContentEditable === 'true', <input> and <textarea> when readOnly state is false, <select> | ||
@@ -240,3 +233,2 @@ if (target.isContentEditable || (tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT') && !target.readOnly) { | ||
} | ||
return _downKeys.indexOf(keyCode) !== -1; | ||
@@ -247,8 +239,8 @@ } | ||
function deleteScope(scope, newScope) { | ||
var handlers; | ||
var i; | ||
let handlers; | ||
let i; | ||
// 没有指定scope,获取scope | ||
if (!scope) scope = getScope(); | ||
for (var key in _handlers) { | ||
for (const key in _handlers) { | ||
if (Object.prototype.hasOwnProperty.call(_handlers, key)) { | ||
@@ -268,4 +260,4 @@ handlers = _handlers[key]; | ||
function clearModifier(event) { | ||
var key = event.keyCode || event.which || event.charCode; | ||
var i = _downKeys.indexOf(key); | ||
let key = event.keyCode || event.which || event.charCode; | ||
const i = _downKeys.indexOf(key); | ||
@@ -287,3 +279,3 @@ // 从列表中清除按压过的键 | ||
// 将修饰键重置为false | ||
for (var k in _modifier) if (_modifier[k] === key) hotkeys[k] = false; | ||
for (const k in _modifier) if (_modifier[k] === key) hotkeys[k] = false; | ||
} | ||
@@ -294,8 +286,6 @@ } | ||
if (typeof keysInfo === 'undefined') { | ||
Object.keys(_handlers).forEach(function (key) { | ||
return delete _handlers[key]; | ||
}); | ||
Object.keys(_handlers).forEach(key => delete _handlers[key]); | ||
} else if (Array.isArray(keysInfo)) { | ||
// support like : unbind([{key: 'ctrl+a', scope: 's1'}, {key: 'ctrl-a', scope: 's2', splitKey: '-'}]) | ||
keysInfo.forEach(function (info) { | ||
keysInfo.forEach(info => { | ||
if (info.key) eachUnbind(info); | ||
@@ -312,4 +302,3 @@ }); | ||
// eslint-disable-line | ||
var scope = args[0], | ||
method = args[1]; | ||
let [scope, method] = args; | ||
if (typeof scope === 'function') { | ||
@@ -321,4 +310,4 @@ method = scope; | ||
key: keysInfo, | ||
scope: scope, | ||
method: method, | ||
scope, | ||
method, | ||
splitKey: '+' | ||
@@ -330,21 +319,22 @@ }); | ||
// 解除绑定某个范围的快捷键 | ||
var eachUnbind = function eachUnbind(_ref2) { | ||
var key = _ref2.key, | ||
scope = _ref2.scope, | ||
method = _ref2.method, | ||
_ref2$splitKey = _ref2.splitKey, | ||
splitKey = _ref2$splitKey === void 0 ? '+' : _ref2$splitKey; | ||
var multipleKeys = getKeys(key); | ||
multipleKeys.forEach(function (originKey) { | ||
var unbindKeys = originKey.split(splitKey); | ||
var len = unbindKeys.length; | ||
var lastKey = unbindKeys[len - 1]; | ||
var keyCode = lastKey === '*' ? '*' : code(lastKey); | ||
const eachUnbind = _ref2 => { | ||
let { | ||
key, | ||
scope, | ||
method, | ||
splitKey = '+' | ||
} = _ref2; | ||
const multipleKeys = getKeys(key); | ||
multipleKeys.forEach(originKey => { | ||
const unbindKeys = originKey.split(splitKey); | ||
const len = unbindKeys.length; | ||
const lastKey = unbindKeys[len - 1]; | ||
const keyCode = lastKey === '*' ? '*' : code(lastKey); | ||
if (!_handlers[keyCode]) return; | ||
// 判断是否传入范围,没有就获取范围 | ||
if (!scope) scope = getScope(); | ||
var mods = len > 1 ? getMods(_modifier, unbindKeys) : []; | ||
_handlers[keyCode] = _handlers[keyCode].filter(function (record) { | ||
const mods = len > 1 ? getMods(_modifier, unbindKeys) : []; | ||
_handlers[keyCode] = _handlers[keyCode].filter(record => { | ||
// 通过函数判断,是否解除绑定,函数相等直接返回 | ||
var isMatchingMethod = method ? record.method === method : true; | ||
const isMatchingMethod = method ? record.method === method : true; | ||
return !(isMatchingMethod && record.scope === scope && compareArray(record.mods, mods)); | ||
@@ -360,3 +350,3 @@ }); | ||
} | ||
var modifiersMatch; | ||
let modifiersMatch; | ||
@@ -367,3 +357,3 @@ // 看它是否在当前范围 | ||
modifiersMatch = handler.mods.length > 0; | ||
for (var y in _mods) { | ||
for (const y in _mods) { | ||
if (Object.prototype.hasOwnProperty.call(_mods, y)) { | ||
@@ -391,4 +381,4 @@ if (!_mods[y] && handler.mods.indexOf(+y) > -1 || _mods[y] && handler.mods.indexOf(+y) === -1) { | ||
function dispatch(event, element) { | ||
var asterisk = _handlers['*']; | ||
var key = event.keyCode || event.which || event.charCode; | ||
const asterisk = _handlers['*']; | ||
let key = event.keyCode || event.which || event.charCode; | ||
@@ -413,4 +403,4 @@ // 表单控件过滤 默认表单控件不触发快捷键 | ||
*/ | ||
['ctrlKey', 'altKey', 'shiftKey', 'metaKey'].forEach(function (keyName) { | ||
var keyNum = modifierMap[keyName]; | ||
['ctrlKey', 'altKey', 'shiftKey', 'metaKey'].forEach(keyName => { | ||
const keyNum = modifierMap[keyName]; | ||
if (event[keyName] && _downKeys.indexOf(keyNum) === -1) { | ||
@@ -438,3 +428,3 @@ _downKeys.push(keyNum); | ||
// 将特殊字符的key注册到 hotkeys 上 | ||
for (var k in _modifier) { | ||
for (const k in _modifier) { | ||
if (_modifier[k] === key) hotkeys[k] = true; | ||
@@ -446,3 +436,3 @@ } | ||
// 将 modifierMap 里面的修饰键绑定到 event 中 | ||
for (var e in _mods) { | ||
for (const e in _mods) { | ||
if (Object.prototype.hasOwnProperty.call(_mods, e)) { | ||
@@ -470,6 +460,6 @@ _mods[e] = event[modifierMap[e]]; | ||
// 获取范围 默认为 `all` | ||
var scope = getScope(); | ||
const scope = getScope(); | ||
// 对任何快捷键都需要做的处理 | ||
if (asterisk) { | ||
for (var i = 0; i < asterisk.length; i++) { | ||
for (let i = 0; i < asterisk.length; i++) { | ||
if (asterisk[i].scope === scope && (event.type === 'keydown' && asterisk[i].keydown || event.type === 'keyup' && asterisk[i].keyup)) { | ||
@@ -482,10 +472,12 @@ eventHandler(event, asterisk[i], scope, element); | ||
if (!(key in _handlers)) return; | ||
for (var _i = 0; _i < _handlers[key].length; _i++) { | ||
if (event.type === 'keydown' && _handlers[key][_i].keydown || event.type === 'keyup' && _handlers[key][_i].keyup) { | ||
if (_handlers[key][_i].key) { | ||
var record = _handlers[key][_i]; | ||
var splitKey = record.splitKey; | ||
var keyShortcut = record.key.split(splitKey); | ||
var _downKeysCurrent = []; // 记录当前按键键值 | ||
for (var a = 0; a < keyShortcut.length; a++) { | ||
for (let i = 0; i < _handlers[key].length; i++) { | ||
if (event.type === 'keydown' && _handlers[key][i].keydown || event.type === 'keyup' && _handlers[key][i].keyup) { | ||
if (_handlers[key][i].key) { | ||
const record = _handlers[key][i]; | ||
const { | ||
splitKey | ||
} = record; | ||
const keyShortcut = record.key.split(splitKey); | ||
const _downKeysCurrent = []; // 记录当前按键键值 | ||
for (let a = 0; a < keyShortcut.length; a++) { | ||
_downKeysCurrent.push(code(keyShortcut[a])); | ||
@@ -508,11 +500,12 @@ } | ||
_downKeys = []; | ||
var keys = getKeys(key); // 需要处理的快捷键列表 | ||
var mods = []; | ||
var scope = 'all'; // scope默认为all,所有范围都有效 | ||
var element = document; // 快捷键事件绑定节点 | ||
var i = 0; | ||
var keyup = false; | ||
var keydown = true; | ||
var splitKey = '+'; | ||
var capture = false; | ||
const keys = getKeys(key); // 需要处理的快捷键列表 | ||
let mods = []; | ||
let scope = 'all'; // scope默认为all,所有范围都有效 | ||
let element = document; // 快捷键事件绑定节点 | ||
let i = 0; | ||
let keyup = false; | ||
let keydown = true; | ||
let splitKey = '+'; | ||
let capture = false; | ||
let single = false; // 单个callback | ||
@@ -530,4 +523,4 @@ // 对为设定范围的判断 | ||
if (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line | ||
if (option.single === true) single = true; // eslint-disable-line | ||
} | ||
if (typeof option === 'string') scope = option; | ||
@@ -549,12 +542,14 @@ | ||
if (!(key in _handlers)) _handlers[key] = []; | ||
// 如果只允许单个callback,重新设置_handlers | ||
if (single) _handlers[key] = []; | ||
_handlers[key].push({ | ||
keyup: keyup, | ||
keydown: keydown, | ||
scope: scope, | ||
mods: mods, | ||
keyup, | ||
keydown, | ||
scope, | ||
mods, | ||
shortcut: keys[i], | ||
method: method, | ||
method, | ||
key: keys[i], | ||
splitKey: splitKey, | ||
element: element | ||
splitKey, | ||
element | ||
}); | ||
@@ -565,3 +560,3 @@ } | ||
elementHasBindEvent.push(element); | ||
addEvent(element, 'keydown', function (e) { | ||
addEvent(element, 'keydown', e => { | ||
dispatch(e, element); | ||
@@ -571,7 +566,7 @@ }, capture); | ||
winListendFocus = true; | ||
addEvent(window, 'focus', function () { | ||
addEvent(window, 'focus', () => { | ||
_downKeys = []; | ||
}, capture); | ||
} | ||
addEvent(element, 'keyup', function (e) { | ||
addEvent(element, 'keyup', e => { | ||
dispatch(e, element); | ||
@@ -583,8 +578,6 @@ clearModifier(e); | ||
function trigger(shortcut) { | ||
var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'all'; | ||
Object.keys(_handlers).forEach(function (key) { | ||
var dataList = _handlers[key].filter(function (item) { | ||
return item.scope === scope && item.shortcut === shortcut; | ||
}); | ||
dataList.forEach(function (data) { | ||
let scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'all'; | ||
Object.keys(_handlers).forEach(key => { | ||
const dataList = _handlers[key].filter(item => item.scope === scope && item.shortcut === shortcut); | ||
dataList.forEach(data => { | ||
if (data && data.method) { | ||
@@ -596,18 +589,18 @@ data.method(); | ||
} | ||
var _api = { | ||
getPressedKeyString: getPressedKeyString, | ||
setScope: setScope, | ||
getScope: getScope, | ||
deleteScope: deleteScope, | ||
getPressedKeyCodes: getPressedKeyCodes, | ||
getAllKeyCodes: getAllKeyCodes, | ||
isPressed: isPressed, | ||
filter: filter, | ||
trigger: trigger, | ||
unbind: unbind, | ||
const _api = { | ||
getPressedKeyString, | ||
setScope, | ||
getScope, | ||
deleteScope, | ||
getPressedKeyCodes, | ||
getAllKeyCodes, | ||
isPressed, | ||
filter, | ||
trigger, | ||
unbind, | ||
keyMap: _keyMap, | ||
modifier: _modifier, | ||
modifierMap: modifierMap | ||
modifierMap | ||
}; | ||
for (var a in _api) { | ||
for (const a in _api) { | ||
if (Object.prototype.hasOwnProperty.call(_api, a)) { | ||
@@ -618,4 +611,4 @@ hotkeys[a] = _api[a]; | ||
if (typeof window !== 'undefined') { | ||
var _hotkeys = window.hotkeys; | ||
hotkeys.noConflict = function (deep) { | ||
const _hotkeys = window.hotkeys; | ||
hotkeys.noConflict = deep => { | ||
if (deep && window.hotkeys === hotkeys) { | ||
@@ -622,0 +615,0 @@ window.hotkeys = _hotkeys; |
/**! | ||
* hotkeys-js v3.12.2 | ||
* hotkeys-js v3.13.0 | ||
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. | ||
* | ||
* Copyright (c) 2023 kenny wong <wowohoo@qq.com> | ||
* https://jaywcjlove.github.io/hotkeys-js | ||
* https://github.com/jaywcjlove/hotkeys-js.git | ||
* | ||
* @website: https://jaywcjlove.github.io/hotkeys-js | ||
* Licensed under the MIT license | ||
@@ -16,3 +19,3 @@ */ | ||
var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; | ||
const isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false; | ||
@@ -24,3 +27,3 @@ // 绑定事件 | ||
} else if (object.attachEvent) { | ||
object.attachEvent("on".concat(event), function () { | ||
object.attachEvent("on".concat(event), () => { | ||
method(window.event); | ||
@@ -33,4 +36,4 @@ }); | ||
function getMods(modifier, key) { | ||
var mods = key.slice(0, key.length - 1); | ||
for (var i = 0; i < mods.length; i++) mods[i] = modifier[mods[i].toLowerCase()]; | ||
const mods = key.slice(0, key.length - 1); | ||
for (let i = 0; i < mods.length; i++) mods[i] = modifier[mods[i].toLowerCase()]; | ||
return mods; | ||
@@ -43,4 +46,4 @@ } | ||
key = key.replace(/\s/g, ''); // 匹配任何空白字符,包括空格、制表符、换页符等等 | ||
var keys = key.split(','); // 同时设置多个快捷键,以','分割 | ||
var index = keys.lastIndexOf(''); | ||
const keys = key.split(','); // 同时设置多个快捷键,以','分割 | ||
let index = keys.lastIndexOf(''); | ||
@@ -58,6 +61,6 @@ // 快捷键可能包含',',需特殊处理 | ||
function compareArray(a1, a2) { | ||
var arr1 = a1.length >= a2.length ? a1 : a2; | ||
var arr2 = a1.length >= a2.length ? a2 : a1; | ||
var isIndex = true; | ||
for (var i = 0; i < arr1.length; i++) { | ||
const arr1 = a1.length >= a2.length ? a1 : a2; | ||
const arr2 = a1.length >= a2.length ? a2 : a1; | ||
let isIndex = true; | ||
for (let i = 0; i < arr1.length; i++) { | ||
if (arr2.indexOf(arr1[i]) === -1) isIndex = false; | ||
@@ -69,3 +72,3 @@ } | ||
// Special Keys | ||
var _keyMap = { | ||
const _keyMap = { | ||
backspace: 8, | ||
@@ -125,3 +128,3 @@ '⌫': 8, | ||
// Modifier Keys | ||
var _modifier = { | ||
const _modifier = { | ||
// shiftKey | ||
@@ -143,3 +146,3 @@ '⇧': 16, | ||
}; | ||
var modifierMap = { | ||
const modifierMap = { | ||
16: 'shiftKey', | ||
@@ -154,3 +157,3 @@ 18: 'altKey', | ||
}; | ||
var _mods = { | ||
const _mods = { | ||
16: false, | ||
@@ -161,28 +164,18 @@ 18: false, | ||
}; | ||
var _handlers = {}; | ||
const _handlers = {}; | ||
// F1~F12 special key | ||
for (var k = 1; k < 20; k++) { | ||
for (let k = 1; k < 20; k++) { | ||
_keyMap["f".concat(k)] = 111 + k; | ||
} | ||
var _downKeys = []; // 记录摁下的绑定键 | ||
var winListendFocus = false; // window是否已经监听了focus事件 | ||
var _scope = 'all'; // 默认热键范围 | ||
var elementHasBindEvent = []; // 已绑定事件的节点记录 | ||
let _downKeys = []; // 记录摁下的绑定键 | ||
let winListendFocus = false; // window是否已经监听了focus事件 | ||
let _scope = 'all'; // 默认热键范围 | ||
const elementHasBindEvent = []; // 已绑定事件的节点记录 | ||
// 返回键码 | ||
var code = function code(x) { | ||
return _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0); | ||
}; | ||
var getKey = function getKey(x) { | ||
return Object.keys(_keyMap).find(function (k) { | ||
return _keyMap[k] === x; | ||
}); | ||
}; | ||
var getModifier = function getModifier(x) { | ||
return Object.keys(_modifier).find(function (k) { | ||
return _modifier[k] === x; | ||
}); | ||
}; | ||
const code = x => _keyMap[x.toLowerCase()] || _modifier[x.toLowerCase()] || x.toUpperCase().charCodeAt(0); | ||
const getKey = x => Object.keys(_keyMap).find(k => _keyMap[k] === x); | ||
const getModifier = x => Object.keys(_modifier).find(k => _modifier[k] === x); | ||
@@ -202,21 +195,19 @@ // 设置获取当前范围(默认为'所有') | ||
function getPressedKeyString() { | ||
return _downKeys.map(function (c) { | ||
return getKey(c) || getModifier(c) || String.fromCharCode(c); | ||
}); | ||
return _downKeys.map(c => getKey(c) || getModifier(c) || String.fromCharCode(c)); | ||
} | ||
function getAllKeyCodes() { | ||
var result = []; | ||
Object.keys(_handlers).forEach(function (k) { | ||
_handlers[k].forEach(function (_ref) { | ||
var key = _ref.key, | ||
scope = _ref.scope, | ||
mods = _ref.mods, | ||
shortcut = _ref.shortcut; | ||
const result = []; | ||
Object.keys(_handlers).forEach(k => { | ||
_handlers[k].forEach(_ref => { | ||
let { | ||
key, | ||
scope, | ||
mods, | ||
shortcut | ||
} = _ref; | ||
result.push({ | ||
scope: scope, | ||
shortcut: shortcut, | ||
mods: mods, | ||
keys: key.split('+').map(function (v) { | ||
return code(v); | ||
}) | ||
scope, | ||
shortcut, | ||
mods, | ||
keys: key.split('+').map(v => code(v)) | ||
}); | ||
@@ -231,5 +222,7 @@ }); | ||
function filter(event) { | ||
var target = event.target || event.srcElement; | ||
var tagName = target.tagName; | ||
var flag = true; | ||
const target = event.target || event.srcElement; | ||
const { | ||
tagName | ||
} = target; | ||
let flag = true; | ||
// ignore: isContentEditable === 'true', <input> and <textarea> when readOnly state is false, <select> | ||
@@ -247,3 +240,2 @@ if (target.isContentEditable || (tagName === 'INPUT' || tagName === 'TEXTAREA' || tagName === 'SELECT') && !target.readOnly) { | ||
} | ||
return _downKeys.indexOf(keyCode) !== -1; | ||
@@ -254,8 +246,8 @@ } | ||
function deleteScope(scope, newScope) { | ||
var handlers; | ||
var i; | ||
let handlers; | ||
let i; | ||
// 没有指定scope,获取scope | ||
if (!scope) scope = getScope(); | ||
for (var key in _handlers) { | ||
for (const key in _handlers) { | ||
if (Object.prototype.hasOwnProperty.call(_handlers, key)) { | ||
@@ -275,4 +267,4 @@ handlers = _handlers[key]; | ||
function clearModifier(event) { | ||
var key = event.keyCode || event.which || event.charCode; | ||
var i = _downKeys.indexOf(key); | ||
let key = event.keyCode || event.which || event.charCode; | ||
const i = _downKeys.indexOf(key); | ||
@@ -294,3 +286,3 @@ // 从列表中清除按压过的键 | ||
// 将修饰键重置为false | ||
for (var k in _modifier) if (_modifier[k] === key) hotkeys[k] = false; | ||
for (const k in _modifier) if (_modifier[k] === key) hotkeys[k] = false; | ||
} | ||
@@ -301,8 +293,6 @@ } | ||
if (typeof keysInfo === 'undefined') { | ||
Object.keys(_handlers).forEach(function (key) { | ||
return delete _handlers[key]; | ||
}); | ||
Object.keys(_handlers).forEach(key => delete _handlers[key]); | ||
} else if (Array.isArray(keysInfo)) { | ||
// support like : unbind([{key: 'ctrl+a', scope: 's1'}, {key: 'ctrl-a', scope: 's2', splitKey: '-'}]) | ||
keysInfo.forEach(function (info) { | ||
keysInfo.forEach(info => { | ||
if (info.key) eachUnbind(info); | ||
@@ -319,4 +309,3 @@ }); | ||
// eslint-disable-line | ||
var scope = args[0], | ||
method = args[1]; | ||
let [scope, method] = args; | ||
if (typeof scope === 'function') { | ||
@@ -328,4 +317,4 @@ method = scope; | ||
key: keysInfo, | ||
scope: scope, | ||
method: method, | ||
scope, | ||
method, | ||
splitKey: '+' | ||
@@ -337,21 +326,22 @@ }); | ||
// 解除绑定某个范围的快捷键 | ||
var eachUnbind = function eachUnbind(_ref2) { | ||
var key = _ref2.key, | ||
scope = _ref2.scope, | ||
method = _ref2.method, | ||
_ref2$splitKey = _ref2.splitKey, | ||
splitKey = _ref2$splitKey === void 0 ? '+' : _ref2$splitKey; | ||
var multipleKeys = getKeys(key); | ||
multipleKeys.forEach(function (originKey) { | ||
var unbindKeys = originKey.split(splitKey); | ||
var len = unbindKeys.length; | ||
var lastKey = unbindKeys[len - 1]; | ||
var keyCode = lastKey === '*' ? '*' : code(lastKey); | ||
const eachUnbind = _ref2 => { | ||
let { | ||
key, | ||
scope, | ||
method, | ||
splitKey = '+' | ||
} = _ref2; | ||
const multipleKeys = getKeys(key); | ||
multipleKeys.forEach(originKey => { | ||
const unbindKeys = originKey.split(splitKey); | ||
const len = unbindKeys.length; | ||
const lastKey = unbindKeys[len - 1]; | ||
const keyCode = lastKey === '*' ? '*' : code(lastKey); | ||
if (!_handlers[keyCode]) return; | ||
// 判断是否传入范围,没有就获取范围 | ||
if (!scope) scope = getScope(); | ||
var mods = len > 1 ? getMods(_modifier, unbindKeys) : []; | ||
_handlers[keyCode] = _handlers[keyCode].filter(function (record) { | ||
const mods = len > 1 ? getMods(_modifier, unbindKeys) : []; | ||
_handlers[keyCode] = _handlers[keyCode].filter(record => { | ||
// 通过函数判断,是否解除绑定,函数相等直接返回 | ||
var isMatchingMethod = method ? record.method === method : true; | ||
const isMatchingMethod = method ? record.method === method : true; | ||
return !(isMatchingMethod && record.scope === scope && compareArray(record.mods, mods)); | ||
@@ -367,3 +357,3 @@ }); | ||
} | ||
var modifiersMatch; | ||
let modifiersMatch; | ||
@@ -374,3 +364,3 @@ // 看它是否在当前范围 | ||
modifiersMatch = handler.mods.length > 0; | ||
for (var y in _mods) { | ||
for (const y in _mods) { | ||
if (Object.prototype.hasOwnProperty.call(_mods, y)) { | ||
@@ -398,4 +388,4 @@ if (!_mods[y] && handler.mods.indexOf(+y) > -1 || _mods[y] && handler.mods.indexOf(+y) === -1) { | ||
function dispatch(event, element) { | ||
var asterisk = _handlers['*']; | ||
var key = event.keyCode || event.which || event.charCode; | ||
const asterisk = _handlers['*']; | ||
let key = event.keyCode || event.which || event.charCode; | ||
@@ -420,4 +410,4 @@ // 表单控件过滤 默认表单控件不触发快捷键 | ||
*/ | ||
['ctrlKey', 'altKey', 'shiftKey', 'metaKey'].forEach(function (keyName) { | ||
var keyNum = modifierMap[keyName]; | ||
['ctrlKey', 'altKey', 'shiftKey', 'metaKey'].forEach(keyName => { | ||
const keyNum = modifierMap[keyName]; | ||
if (event[keyName] && _downKeys.indexOf(keyNum) === -1) { | ||
@@ -445,3 +435,3 @@ _downKeys.push(keyNum); | ||
// 将特殊字符的key注册到 hotkeys 上 | ||
for (var k in _modifier) { | ||
for (const k in _modifier) { | ||
if (_modifier[k] === key) hotkeys[k] = true; | ||
@@ -453,3 +443,3 @@ } | ||
// 将 modifierMap 里面的修饰键绑定到 event 中 | ||
for (var e in _mods) { | ||
for (const e in _mods) { | ||
if (Object.prototype.hasOwnProperty.call(_mods, e)) { | ||
@@ -477,6 +467,6 @@ _mods[e] = event[modifierMap[e]]; | ||
// 获取范围 默认为 `all` | ||
var scope = getScope(); | ||
const scope = getScope(); | ||
// 对任何快捷键都需要做的处理 | ||
if (asterisk) { | ||
for (var i = 0; i < asterisk.length; i++) { | ||
for (let i = 0; i < asterisk.length; i++) { | ||
if (asterisk[i].scope === scope && (event.type === 'keydown' && asterisk[i].keydown || event.type === 'keyup' && asterisk[i].keyup)) { | ||
@@ -489,10 +479,12 @@ eventHandler(event, asterisk[i], scope, element); | ||
if (!(key in _handlers)) return; | ||
for (var _i = 0; _i < _handlers[key].length; _i++) { | ||
if (event.type === 'keydown' && _handlers[key][_i].keydown || event.type === 'keyup' && _handlers[key][_i].keyup) { | ||
if (_handlers[key][_i].key) { | ||
var record = _handlers[key][_i]; | ||
var splitKey = record.splitKey; | ||
var keyShortcut = record.key.split(splitKey); | ||
var _downKeysCurrent = []; // 记录当前按键键值 | ||
for (var a = 0; a < keyShortcut.length; a++) { | ||
for (let i = 0; i < _handlers[key].length; i++) { | ||
if (event.type === 'keydown' && _handlers[key][i].keydown || event.type === 'keyup' && _handlers[key][i].keyup) { | ||
if (_handlers[key][i].key) { | ||
const record = _handlers[key][i]; | ||
const { | ||
splitKey | ||
} = record; | ||
const keyShortcut = record.key.split(splitKey); | ||
const _downKeysCurrent = []; // 记录当前按键键值 | ||
for (let a = 0; a < keyShortcut.length; a++) { | ||
_downKeysCurrent.push(code(keyShortcut[a])); | ||
@@ -515,11 +507,12 @@ } | ||
_downKeys = []; | ||
var keys = getKeys(key); // 需要处理的快捷键列表 | ||
var mods = []; | ||
var scope = 'all'; // scope默认为all,所有范围都有效 | ||
var element = document; // 快捷键事件绑定节点 | ||
var i = 0; | ||
var keyup = false; | ||
var keydown = true; | ||
var splitKey = '+'; | ||
var capture = false; | ||
const keys = getKeys(key); // 需要处理的快捷键列表 | ||
let mods = []; | ||
let scope = 'all'; // scope默认为all,所有范围都有效 | ||
let element = document; // 快捷键事件绑定节点 | ||
let i = 0; | ||
let keyup = false; | ||
let keydown = true; | ||
let splitKey = '+'; | ||
let capture = false; | ||
let single = false; // 单个callback | ||
@@ -537,4 +530,4 @@ // 对为设定范围的判断 | ||
if (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line | ||
if (option.single === true) single = true; // eslint-disable-line | ||
} | ||
if (typeof option === 'string') scope = option; | ||
@@ -556,12 +549,14 @@ | ||
if (!(key in _handlers)) _handlers[key] = []; | ||
// 如果只允许单个callback,重新设置_handlers | ||
if (single) _handlers[key] = []; | ||
_handlers[key].push({ | ||
keyup: keyup, | ||
keydown: keydown, | ||
scope: scope, | ||
mods: mods, | ||
keyup, | ||
keydown, | ||
scope, | ||
mods, | ||
shortcut: keys[i], | ||
method: method, | ||
method, | ||
key: keys[i], | ||
splitKey: splitKey, | ||
element: element | ||
splitKey, | ||
element | ||
}); | ||
@@ -572,3 +567,3 @@ } | ||
elementHasBindEvent.push(element); | ||
addEvent(element, 'keydown', function (e) { | ||
addEvent(element, 'keydown', e => { | ||
dispatch(e, element); | ||
@@ -578,7 +573,7 @@ }, capture); | ||
winListendFocus = true; | ||
addEvent(window, 'focus', function () { | ||
addEvent(window, 'focus', () => { | ||
_downKeys = []; | ||
}, capture); | ||
} | ||
addEvent(element, 'keyup', function (e) { | ||
addEvent(element, 'keyup', e => { | ||
dispatch(e, element); | ||
@@ -590,8 +585,6 @@ clearModifier(e); | ||
function trigger(shortcut) { | ||
var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'all'; | ||
Object.keys(_handlers).forEach(function (key) { | ||
var dataList = _handlers[key].filter(function (item) { | ||
return item.scope === scope && item.shortcut === shortcut; | ||
}); | ||
dataList.forEach(function (data) { | ||
let scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'all'; | ||
Object.keys(_handlers).forEach(key => { | ||
const dataList = _handlers[key].filter(item => item.scope === scope && item.shortcut === shortcut); | ||
dataList.forEach(data => { | ||
if (data && data.method) { | ||
@@ -603,18 +596,18 @@ data.method(); | ||
} | ||
var _api = { | ||
getPressedKeyString: getPressedKeyString, | ||
setScope: setScope, | ||
getScope: getScope, | ||
deleteScope: deleteScope, | ||
getPressedKeyCodes: getPressedKeyCodes, | ||
getAllKeyCodes: getAllKeyCodes, | ||
isPressed: isPressed, | ||
filter: filter, | ||
trigger: trigger, | ||
unbind: unbind, | ||
const _api = { | ||
getPressedKeyString, | ||
setScope, | ||
getScope, | ||
deleteScope, | ||
getPressedKeyCodes, | ||
getAllKeyCodes, | ||
isPressed, | ||
filter, | ||
trigger, | ||
unbind, | ||
keyMap: _keyMap, | ||
modifier: _modifier, | ||
modifierMap: modifierMap | ||
modifierMap | ||
}; | ||
for (var a in _api) { | ||
for (const a in _api) { | ||
if (Object.prototype.hasOwnProperty.call(_api, a)) { | ||
@@ -625,4 +618,4 @@ hotkeys[a] = _api[a]; | ||
if (typeof window !== 'undefined') { | ||
var _hotkeys = window.hotkeys; | ||
hotkeys.noConflict = function (deep) { | ||
const _hotkeys = window.hotkeys; | ||
hotkeys.noConflict = deep => { | ||
if (deep && window.hotkeys === hotkeys) { | ||
@@ -629,0 +622,0 @@ window.hotkeys = _hotkeys; |
@@ -1,2 +0,2 @@ | ||
/*! hotkeys-js v3.12.2 | MIT © 2023 kenny wong <wowohoo@qq.com> https://jaywcjlove.github.io/hotkeys-js */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).hotkeys=t()}(this,function(){"use strict";var e="undefined"!=typeof navigator&&0<navigator.userAgent.toLowerCase().indexOf("firefox");function p(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent("on".concat(t),function(){n(window.event)})}function d(e,t){for(var n=t.slice(0,t.length-1),o=0;o<n.length;o++)n[o]=e[n[o].toLowerCase()];return n}function y(e){for(var t=(e=(e="string"!=typeof e?"":e).replace(/\s/g,"")).split(","),n=t.lastIndexOf("");0<=n;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}for(var o={backspace:8,"\u232b":8,tab:9,clear:12,enter:13,"\u21a9":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"\u21ea":20,",":188,".":190,"/":191,"`":192,"-":e?173:189,"=":e?61:187,";":e?59:186,"'":222,"[":219,"]":221,"\\":220},h={"\u21e7":16,shift:16,"\u2325":18,alt:18,option:18,"\u2303":17,ctrl:17,control:17,"\u2318":91,cmd:91,command:91},m={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},g={16:!1,18:!1,17:!1,91:!1},v={},t=1;t<20;t++)o["f".concat(t)]=111+t;var k=[],w=!1,n="all",O=[],K=function(e){return o[e.toLowerCase()]||h[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)};function i(e){n=e||"all"}function b(){return n||"all"}function c(e){var r=e.scope,i=e.method,t=e.splitKey,c=void 0===t?"+":t;y(e.key).forEach(function(e){var t,e=e.split(c),n=e.length,o=e[n-1],o="*"===o?"*":K(o);v[o]&&(r=r||b(),t=1<n?d(h,e):[],v[o]=v[o].filter(function(e){return!((!i||e.method===i)&&e.scope===r&&function(e,t){for(var n=e.length<t.length?t:e,o=e.length<t.length?e:t,r=!0,i=0;i<n.length;i++)~o.indexOf(n[i])||(r=!1);return r}(e.mods,t))}))})}function x(e,t,n,o){var r;if(t.element===o&&(t.scope===n||"all"===t.scope)){for(var i in r=0<t.mods.length,g)Object.prototype.hasOwnProperty.call(g,i)&&(!g[i]&&~t.mods.indexOf(+i)||g[i]&&!~t.mods.indexOf(+i))&&(r=!1);(0!==t.mods.length||g[16]||g[18]||g[17]||g[91])&&!r&&"*"!==t.shortcut||(t.keys=[],t.keys=t.keys.concat(k),!1===t.method(e,t)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble)&&(e.cancelBubble=!0))}}function C(n,e){var t=v["*"],o=n.keyCode||n.which||n.charCode;if(E.filter.call(this,n)){if(~k.indexOf(o=93!==o&&224!==o?o:91)||229===o||k.push(o),["ctrlKey","altKey","shiftKey","metaKey"].forEach(function(e){var t=m[e];n[e]&&!~k.indexOf(t)?k.push(t):!n[e]&&~k.indexOf(t)?k.splice(k.indexOf(t),1):"metaKey"!==e||!n[e]||3!==k.length||n.ctrlKey||n.shiftKey||n.altKey||(k=k.slice(k.indexOf(t)))}),o in g){for(var r in g[o]=!0,h)h[r]===o&&(E[r]=!0);if(!t)return}for(var i in g)Object.prototype.hasOwnProperty.call(g,i)&&(g[i]=n[m[i]]);n.getModifierState&&(!n.altKey||n.ctrlKey)&&n.getModifierState("AltGraph")&&(~k.indexOf(17)||k.push(17),~k.indexOf(18)||k.push(18),g[17]=!0,g[18]=!0);var c=b();if(t)for(var f=0;f<t.length;f++)t[f].scope===c&&("keydown"===n.type&&t[f].keydown||"keyup"===n.type&&t[f].keyup)&&x(n,t[f],c,e);if(o in v)for(var a=0;a<v[o].length;a++)if(("keydown"===n.type&&v[o][a].keydown||"keyup"===n.type&&v[o][a].keyup)&&v[o][a].key){for(var s=v[o][a],l=s.key.split(s.splitKey),u=[],p=0;p<l.length;p++)u.push(K(l[p]));u.sort().join("")===k.sort().join("")&&x(n,s,c,e)}}}function E(e,t,n){k=[];var o=y(e),r=[],i="all",c=document,f=0,a=!1,s=!0,l="+",u=!1;for(void 0===n&&"function"==typeof t&&(n=t),"[object Object]"===Object.prototype.toString.call(t)&&(t.scope&&(i=t.scope),t.element&&(c=t.element),t.keyup&&(a=t.keyup),void 0!==t.keydown&&(s=t.keydown),void 0!==t.capture&&(u=t.capture),"string"==typeof t.splitKey)&&(l=t.splitKey),"string"==typeof t&&(i=t);f<o.length;f++)r=[],1<(e=o[f].split(l)).length&&(r=d(h,e)),(e="*"===(e=e[e.length-1])?"*":K(e))in v||(v[e]=[]),v[e].push({keyup:a,keydown:s,scope:i,mods:r,shortcut:o[f],method:n,key:o[f],splitKey:l,element:c});void 0!==c&&(t=c,!~O.indexOf(t))&&window&&(O.push(c),p(c,"keydown",function(e){C(e,c)},u),w||(w=!0,p(window,"focus",function(){k=[]},u)),p(c,"keyup",function(e){C(e,c);var t=e.keyCode||e.which||e.charCode,n=k.indexOf(t);if(n<0||k.splice(n,1),e.key&&"meta"==e.key.toLowerCase()&&k.splice(0,k.length),(t=93!==t&&224!==t?t:91)in g)for(var o in g[t]=!1,h)h[o]===t&&(E[o]=!1)},u))}var r,f,a={getPressedKeyString:function(){return k.map(function(e){return n=e,Object.keys(o).find(function(e){return o[e]===n})||(t=e,Object.keys(h).find(function(e){return h[e]===t}))||String.fromCharCode(e);var t,n})},setScope:i,getScope:b,deleteScope:function(e,t){var n,o,r;for(r in e=e||b(),v)if(Object.prototype.hasOwnProperty.call(v,r))for(n=v[r],o=0;o<n.length;)n[o].scope===e?n.splice(o,1):o++;b()===e&&i(t||"all")},getPressedKeyCodes:function(){return k.slice(0)},getAllKeyCodes:function(){var n=[];return Object.keys(v).forEach(function(e){v[e].forEach(function(e){var t=e.key;n.push({scope:e.scope,shortcut:e.shortcut,mods:e.mods,keys:t.split("+").map(function(e){return K(e)})})})}),n},isPressed:function(e){return"string"==typeof e&&(e=K(e)),!!~k.indexOf(e)},filter:function(e){var t=(e=e.target||e.srcElement).tagName;return!e.isContentEditable&&("INPUT"!==t&&"TEXTAREA"!==t&&"SELECT"!==t||e.readOnly)?!0:!1},trigger:function(t){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(v).forEach(function(e){v[e].filter(function(e){return e.scope===n&&e.shortcut===t}).forEach(function(e){e&&e.method&&e.method()})})},unbind:function(e){if(void 0===e)Object.keys(v).forEach(function(e){return delete v[e]});else if(Array.isArray(e))e.forEach(function(e){e.key&&c(e)});else if("object"==typeof e)e.key&&c(e);else if("string"==typeof e){for(var t=arguments.length,n=Array(1<t?t-1:0),o=1;o<t;o++)n[o-1]=arguments[o];var r=n[0],i=n[1];"function"==typeof r&&(i=r,r=""),c({key:e,scope:r,method:i,splitKey:"+"})}},keyMap:o,modifier:h,modifierMap:m};for(r in a)Object.prototype.hasOwnProperty.call(a,r)&&(E[r]=a[r]);return"undefined"!=typeof window&&(f=window.hotkeys,E.noConflict=function(e){return e&&window.hotkeys===E&&(window.hotkeys=f),E},window.hotkeys=E),E}); | ||
/*! hotkeys-js v3.13.0 | MIT © 2023 kenny wong <wowohoo@qq.com> https://jaywcjlove.github.io/hotkeys-js */ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).hotkeys=t()}(this,function(){"use strict";var e="undefined"!=typeof navigator&&0<navigator.userAgent.toLowerCase().indexOf("firefox");function y(e,t,n,o){e.addEventListener?e.addEventListener(t,n,o):e.attachEvent&&e.attachEvent("on".concat(t),()=>{n(window.event)})}function u(t,e){var n=e.slice(0,e.length-1);for(let e=0;e<n.length;e++)n[e]=t[n[e].toLowerCase()];return n}function h(e){var t=(e=(e="string"!=typeof e?"":e).replace(/\s/g,"")).split(",");let n=t.lastIndexOf("");for(;0<=n;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}const o={backspace:8,"\u232b":8,tab:9,clear:12,enter:13,"\u21a9":13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,num_0:96,num_1:97,num_2:98,num_3:99,num_4:100,num_5:101,num_6:102,num_7:103,num_8:104,num_9:105,num_multiply:106,num_add:107,num_enter:108,num_subtract:109,num_decimal:110,num_divide:111,"\u21ea":20,",":188,".":190,"/":191,"`":192,"-":e?173:189,"=":e?61:187,";":e?59:186,"'":222,"[":219,"]":221,"\\":220},m={"\u21e7":16,shift:16,"\u2325":18,alt:18,option:18,"\u2303":17,ctrl:17,control:17,"\u2318":91,cmd:91,command:91},p={16:"shiftKey",18:"altKey",17:"ctrlKey",91:"metaKey",shiftKey:16,ctrlKey:17,altKey:18,metaKey:91},g={16:!1,18:!1,17:!1,91:!1},k={};for(let e=1;e<20;e++)o["f".concat(e)]=111+e;let w=[],v=!1,t="all";const O=[],K=e=>o[e.toLowerCase()]||m[e.toLowerCase()]||e.toUpperCase().charCodeAt(0);function i(e){t=e||"all"}function d(){return t||"all"}const s=e=>{let{key:t,scope:r,method:i,splitKey:s="+"}=e;h(t).forEach(e=>{var e=e.split(s),t=e.length,n=e[t-1],n="*"===n?"*":K(n);if(k[n]){r=r||d();const o=1<t?u(m,e):[];k[n]=k[n].filter(e=>{return!((!i||e.method===i)&&e.scope===r&&function(e,t){var n=e.length<t.length?t:e,o=e.length<t.length?e:t;let r=!0;for(let e=0;e<n.length;e++)~o.indexOf(n[e])||(r=!1);return r}(e.mods,o))})}})};function b(t,n,o,e){if(n.element===e){let e;if(n.scope===o||"all"===n.scope){e=0<n.mods.length;for(const r in g)Object.prototype.hasOwnProperty.call(g,r)&&(!g[r]&&~n.mods.indexOf(+r)||g[r]&&!~n.mods.indexOf(+r))&&(e=!1);(0!==n.mods.length||g[16]||g[18]||g[17]||g[91])&&!e&&"*"!==n.shortcut||(n.keys=[],n.keys=n.keys.concat(w),!1===n.method(t,n)&&(t.preventDefault?t.preventDefault():t.returnValue=!1,t.stopPropagation&&t.stopPropagation(),t.cancelBubble)&&(t.cancelBubble=!0))}}}function x(n,t){var o=k["*"];let r=n.keyCode||n.which||n.charCode;if(C.filter.call(this,n)){if(93!==r&&224!==r||(r=91),~w.indexOf(r)||229===r||w.push(r),["ctrlKey","altKey","shiftKey","metaKey"].forEach(e=>{var t=p[e];n[e]&&!~w.indexOf(t)?w.push(t):!n[e]&&~w.indexOf(t)?w.splice(w.indexOf(t),1):"metaKey"!==e||!n[e]||3!==w.length||n.ctrlKey||n.shiftKey||n.altKey||(w=w.slice(w.indexOf(t)))}),r in g){g[r]=!0;for(const e in m)m[e]===r&&(C[e]=!0);if(!o)return}for(const a in g)Object.prototype.hasOwnProperty.call(g,a)&&(g[a]=n[p[a]]);n.getModifierState&&(!n.altKey||n.ctrlKey)&&n.getModifierState("AltGraph")&&(~w.indexOf(17)||w.push(17),~w.indexOf(18)||w.push(18),g[17]=!0,g[18]=!0);var i=d();if(o)for(let e=0;e<o.length;e++)o[e].scope===i&&("keydown"===n.type&&o[e].keydown||"keyup"===n.type&&o[e].keyup)&&b(n,o[e],i,t);if(r in k)for(let e=0;e<k[r].length;e++)if(("keydown"===n.type&&k[r][e].keydown||"keyup"===n.type&&k[r][e].keyup)&&k[r][e].key){var s=k[r][e],l=s["splitKey"],c=s.key.split(l),f=[];for(let e=0;e<c.length;e++)f.push(K(c[e]));f.sort().join("")===w.sort().join("")&&b(n,s,i,t)}}}function C(e,t,n){w=[];var o=h(e);let r=[],i="all",s=document,l=0,c=!1,f=!0,a="+",p=!1,d=!1;for(void 0===n&&"function"==typeof t&&(n=t),"[object Object]"===Object.prototype.toString.call(t)&&(t.scope&&(i=t.scope),t.element&&(s=t.element),t.keyup&&(c=t.keyup),void 0!==t.keydown&&(f=t.keydown),void 0!==t.capture&&(p=t.capture),"string"==typeof t.splitKey&&(a=t.splitKey),!0===t.single)&&(d=!0),"string"==typeof t&&(i=t);l<o.length;l++)e=o[l].split(a),r=[],1<e.length&&(r=u(m,e)),(e="*"===(e=e[e.length-1])?"*":K(e))in k||(k[e]=[]),d&&(k[e]=[]),k[e].push({keyup:c,keydown:f,scope:i,mods:r,shortcut:o[l],method:n,key:o[l],splitKey:a,element:s});void 0!==s&&(t=s,!~O.indexOf(t))&&window&&(O.push(s),y(s,"keydown",e=>{x(e,s)},p),v||(v=!0,y(window,"focus",()=>{w=[]},p)),y(s,"keyup",t=>{x(t,s);{let e=t.keyCode||t.which||t.charCode;var n=w.indexOf(e);if(n<0||w.splice(n,1),t.key&&"meta"==t.key.toLowerCase()&&w.splice(0,w.length),(e=93!==e&&224!==e?e:91)in g){g[e]=!1;for(const o in m)m[o]===e&&(C[o]=!1)}}},p))}var n={getPressedKeyString:function(){return w.map(e=>{return n=e,Object.keys(o).find(e=>o[e]===n)||(t=e,Object.keys(m).find(e=>m[e]===t))||String.fromCharCode(e);var t,n})},setScope:i,getScope:d,deleteScope:function(e,t){var n;let o;e=e||d();for(const r in k)if(Object.prototype.hasOwnProperty.call(k,r))for(n=k[r],o=0;o<n.length;)n[o].scope===e?n.splice(o,1):o++;d()===e&&i(t||"all")},getPressedKeyCodes:function(){return w.slice(0)},getAllKeyCodes:function(){const r=[];return Object.keys(k).forEach(e=>{k[e].forEach(e=>{var{key:e,scope:t,mods:n,shortcut:o}=e;r.push({scope:t,shortcut:o,mods:n,keys:e.split("+").map(e=>K(e))})})}),r},isPressed:function(e){return"string"==typeof e&&(e=K(e)),!!~w.indexOf(e)},filter:function(e){var t=(e=e.target||e.srcElement)["tagName"];let n=!e.isContentEditable&&("INPUT"!==t&&"TEXTAREA"!==t&&"SELECT"!==t||e.readOnly)?!0:!1;return n},trigger:function(t){let n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:"all";Object.keys(k).forEach(e=>{k[e].filter(e=>e.scope===n&&e.shortcut===t).forEach(e=>{e&&e.method&&e.method()})})},unbind:function(n){if(void 0===n)Object.keys(k).forEach(e=>delete k[e]);else if(Array.isArray(n))n.forEach(e=>{e.key&&s(e)});else if("object"==typeof n)n.key&&s(n);else if("string"==typeof n){for(var o=arguments.length,r=Array(1<o?o-1:0),i=1;i<o;i++)r[i-1]=arguments[i];let[e,t]=r;"function"==typeof e&&(t=e,e=""),s({key:n,scope:e,method:t,splitKey:"+"})}},keyMap:o,modifier:m,modifierMap:p};for(const r in n)Object.prototype.hasOwnProperty.call(n,r)&&(C[r]=n[r]);if("undefined"!=typeof window){const l=window.hotkeys;C.noConflict=e=>(e&&window.hotkeys===C&&(window.hotkeys=l),C),window.hotkeys=C}return C}); |
@@ -21,2 +21,3 @@ export interface HotkeysEvent { | ||
splitKey?: string; | ||
single?: boolean; | ||
} | ||
@@ -43,3 +44,3 @@ | ||
* Use the `hotkeys.setScope` method to set scope. There can only be one active scope besides 'all'. By default 'all' is always active. | ||
* | ||
* | ||
* ```js | ||
@@ -53,3 +54,3 @@ * // Define shortcuts with a scope | ||
* }); | ||
* | ||
* | ||
* // Set the scope (only 'all' and 'issues' shortcuts will be honored) | ||
@@ -62,3 +63,3 @@ * hotkeys.setScope('issues'); // default scope is 'all' | ||
* Use the `hotkeys.getScope` method to get scope. | ||
* | ||
* | ||
* ```js | ||
@@ -71,3 +72,3 @@ * hotkeys.getScope(); | ||
* Use the `hotkeys.deleteScope` method to delete a scope. This will also remove all associated hotkeys with it. | ||
* | ||
* | ||
* ```js | ||
@@ -77,3 +78,3 @@ * hotkeys.deleteScope('issues'); | ||
* You can use second argument, if need set new scope after deleting. | ||
* | ||
* | ||
* ```js | ||
@@ -87,3 +88,3 @@ * hotkeys.deleteScope('issues', 'newScopeName'); | ||
* Relinquish HotKeys’s control of the `hotkeys` variable. | ||
* | ||
* | ||
* ```js | ||
@@ -94,3 +95,3 @@ * var k = hotkeys.noConflict(); | ||
* }); | ||
* | ||
* | ||
* hotkeys() | ||
@@ -107,3 +108,3 @@ * // -->Uncaught TypeError: hotkeys is not a function(anonymous function) | ||
* trigger shortcut key event | ||
* | ||
* | ||
* ```js | ||
@@ -127,3 +128,3 @@ * hotkeys.trigger('ctrl+o'); | ||
* Returns an array of key codes currently pressed. | ||
* | ||
* | ||
* ```js | ||
@@ -138,3 +139,3 @@ * hotkeys('command+ctrl+shift+a,f', function() { | ||
* Returns an array of key codes currently pressed. | ||
* | ||
* | ||
* ```js | ||
@@ -149,3 +150,3 @@ * hotkeys('command+ctrl+shift+a,f', function() { | ||
* Get a list of all registration codes. | ||
* | ||
* | ||
* ```js | ||
@@ -160,3 +161,3 @@ * hotkeys('command+ctrl+shift+a,f', function() { | ||
* ``` | ||
* | ||
* | ||
*/ | ||
@@ -169,3 +170,3 @@ getAllKeyCodes(): Omit<HotkeysEvent, 'method' | 'key'>; | ||
* `false` shortcut keys set up failure. | ||
* | ||
* | ||
* ```js | ||
@@ -182,3 +183,3 @@ * hotkeys.filter = function(event){ | ||
* } | ||
* | ||
* | ||
* hotkeys.filter = function(event){ | ||
@@ -195,2 +196,2 @@ * var tagName = (event.target || event.srcElement).tagName; | ||
declare var hotkeys: Hotkeys; | ||
export default hotkeys; | ||
export = hotkeys; |
{ | ||
"name": "hotkeys-js", | ||
"description": "A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.", | ||
"version": "3.12.2", | ||
"version": "3.13.0", | ||
"main": "index.js", | ||
@@ -6,0 +6,0 @@ "types": "index.d.ts", |
@@ -162,2 +162,3 @@ # Hotkeys | ||
- `capture<Boolean>` | ||
- `single<Boolean>` | ||
@@ -164,0 +165,0 @@ ```js |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
442
86530
1824