diff --git a/dist/hotkeys.common.js b/dist/hotkeys.common.js index 80c7513..1a78f14 100644 --- a/dist/hotkeys.common.js +++ b/dist/hotkeys.common.js @@ -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 { - scope: scope, - shortcut: shortcut, - mods: mods, - keys: key.split('+').map(function (k) { - return code(k); - }) - }; + 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 (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); diff --git a/dist/hotkeys.esm.js b/dist/hotkeys.esm.js index 15655ed..b5519bb 100644 --- a/dist/hotkeys.esm.js +++ b/dist/hotkeys.esm.js @@ -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 { - scope: scope, - shortcut: shortcut, - mods: mods, - keys: key.split('+').map(function (k) { - return code(k); - }) - }; + 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 (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); diff --git a/dist/hotkeys.js b/dist/hotkeys.js index 9790b82..e233127 100644 --- a/dist/hotkeys.js +++ b/dist/hotkeys.js @@ -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 { - scope: scope, - shortcut: shortcut, - mods: mods, - keys: key.split('+').map(function (k) { - return code(k); - }) - }; + 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 (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); diff --git a/index.d.ts b/index.d.ts index 7cb6fd4..c5d1fb4 100644 --- a/index.d.ts +++ b/index.d.ts @@ -37,7 +37,7 @@ export interface Hotkeys { modifier: Record; modifierMap: Record; - getAllKeyCodes(): Omit; + getAllKeyCodes(): Omit; setScope(scopeName: string): void; getScope(): string; diff --git a/src/index.js b/src/index.js index 363c1b2..922c82f 100644 --- a/src/index.js +++ b/src/index.js @@ -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