clean: Optimize `getAllKeyCodes` method & compatible with older browers. (#439)

pull/441/head
jaywcjlove 2 years ago
parent edfd3ef372
commit f26f95c63b

@ -9,32 +9,6 @@
'use strict';
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false;
// 绑定事件
@ -216,21 +190,24 @@ function getPressedKeyString() {
});
}
function getAllKeyCodes() {
var _ref;
return (_ref = []).concat.apply(_ref, _toConsumableArray(Object.values(_handlers))).map(function (_ref2) {
var key = _ref2.key,
scope = _ref2.scope,
mods = _ref2.mods,
shortcut = _ref2.shortcut;
return {
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;
result.push({
scope: scope,
shortcut: shortcut,
mods: mods,
keys: key.split('+').map(function (k) {
return code(k);
keys: key.split('+').map(function (v) {
return code(v);
})
};
});
});
});
return result;
}
// 表单控件控件判断 返回 Boolean
@ -334,12 +311,12 @@ function unbind(keysInfo) {
}
// 解除绑定某个范围的快捷键
var eachUnbind = function eachUnbind(_ref3) {
var key = _ref3.key,
scope = _ref3.scope,
method = _ref3.method,
_ref3$splitKey = _ref3.splitKey,
splitKey = _ref3$splitKey === void 0 ? '+' : _ref3$splitKey;
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);

@ -7,32 +7,6 @@
* Licensed under the MIT license
*/
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false;
// 绑定事件
@ -214,21 +188,24 @@ function getPressedKeyString() {
});
}
function getAllKeyCodes() {
var _ref;
return (_ref = []).concat.apply(_ref, _toConsumableArray(Object.values(_handlers))).map(function (_ref2) {
var key = _ref2.key,
scope = _ref2.scope,
mods = _ref2.mods,
shortcut = _ref2.shortcut;
return {
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;
result.push({
scope: scope,
shortcut: shortcut,
mods: mods,
keys: key.split('+').map(function (k) {
return code(k);
keys: key.split('+').map(function (v) {
return code(v);
})
};
});
});
});
return result;
}
// 表单控件控件判断 返回 Boolean
@ -332,12 +309,12 @@ function unbind(keysInfo) {
}
// 解除绑定某个范围的快捷键
var eachUnbind = function eachUnbind(_ref3) {
var key = _ref3.key,
scope = _ref3.scope,
method = _ref3.method,
_ref3$splitKey = _ref3.splitKey,
splitKey = _ref3$splitKey === void 0 ? '+' : _ref3$splitKey;
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);

61
dist/hotkeys.js vendored

@ -13,32 +13,6 @@
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.hotkeys = factory());
})(this, (function () { 'use strict';
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var isff = typeof navigator !== 'undefined' ? navigator.userAgent.toLowerCase().indexOf('firefox') > 0 : false;
// 绑定事件
@ -220,21 +194,24 @@
});
}
function getAllKeyCodes() {
var _ref;
return (_ref = []).concat.apply(_ref, _toConsumableArray(Object.values(_handlers))).map(function (_ref2) {
var key = _ref2.key,
scope = _ref2.scope,
mods = _ref2.mods,
shortcut = _ref2.shortcut;
return {
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;
result.push({
scope: scope,
shortcut: shortcut,
mods: mods,
keys: key.split('+').map(function (k) {
return code(k);
keys: key.split('+').map(function (v) {
return code(v);
})
};
});
});
});
return result;
}
// 表单控件控件判断 返回 Boolean
@ -338,12 +315,12 @@
}
// 解除绑定某个范围的快捷键
var eachUnbind = function eachUnbind(_ref3) {
var key = _ref3.key,
scope = _ref3.scope,
method = _ref3.method,
_ref3$splitKey = _ref3.splitKey,
splitKey = _ref3$splitKey === void 0 ? '+' : _ref3$splitKey;
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);

2
index.d.ts vendored

@ -37,7 +37,7 @@ export interface Hotkeys {
modifier: Record<string, number>;
modifierMap: Record<string, number | string>;
getAllKeyCodes(): Omit<HotkeysEvent, 'method'>;
getAllKeyCodes(): Omit<HotkeysEvent, 'method' | 'key'>;
setScope(scopeName: string): void;
getScope(): string;

@ -32,18 +32,18 @@ function getPressedKeyString() {
}
function getAllKeyCodes() {
return []
.concat(...Object.values(_handlers))
.map(({ key, scope, mods, shortcut }) => {
return {
const result = [];
Object.keys(_handlers).forEach((k) => {
_handlers[k].forEach(({ key, scope, mods, shortcut }) => {
result.push({
scope,
shortcut,
mods,
keys: key.split('+').map((k) => {
return code(k);
}),
};
keys: key.split('+').map((v) => code(v)),
});
});
});
return result;
}
// 表单控件控件判断 返回 Boolean

Loading…
Cancel
Save