From 9e45061d5f5dd1997dc0a7332aa75780ff106f4d Mon Sep 17 00:00:00 2001 From: cangSDARM <648384410li@gmail.com> Date: Fri, 8 Dec 2023 18:47:34 +0800 Subject: [PATCH 1/2] feat: single callback --- dist/hotkeys.common.js | 3 ++- dist/hotkeys.common.min.js | 2 +- dist/hotkeys.esm.js | 3 ++- dist/hotkeys.js | 3 ++- dist/hotkeys.min.js | 2 +- package-lock.json | 7 +++++-- src/index.js | 5 +++++ 7 files changed, 18 insertions(+), 7 deletions(-) diff --git a/dist/hotkeys.common.js b/dist/hotkeys.common.js index 51415021..64f0a34a 100644 --- a/dist/hotkeys.common.js +++ b/dist/hotkeys.common.js @@ -1,5 +1,5 @@ /**! - * hotkeys-js v3.12.0 + * hotkeys-js v3.12.2 * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. * * Copyright (c) 2023 kenny wong @@ -501,6 +501,7 @@ function hotkeys(key, option, method) { if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line if (option.capture !== undefined) capture = option.capture; // eslint-disable-line if (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line + if (option.singleton === true) ; // eslint-disable-line } if (typeof option === 'string') scope = option; diff --git a/dist/hotkeys.common.min.js b/dist/hotkeys.common.min.js index 5ff7002f..7b878e7f 100644 --- a/dist/hotkeys.common.min.js +++ b/dist/hotkeys.common.min.js @@ -1,2 +1,2 @@ -/*! hotkeys-js v3.12.0 | MIT © 2023 kenny wong https://jaywcjlove.github.io/hotkeys-js */ +/*! hotkeys-js v3.12.2 | MIT © 2023 kenny wong https://jaywcjlove.github.io/hotkeys-js */ "use strict";var isff="undefined"!=typeof navigator&&0 @@ -499,6 +499,7 @@ function hotkeys(key, option, method) { if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line if (option.capture !== undefined) capture = option.capture; // eslint-disable-line if (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line + if (option.singleton === true) ; // eslint-disable-line } if (typeof option === 'string') scope = option; diff --git a/dist/hotkeys.js b/dist/hotkeys.js index 23c12b31..7c333a2a 100644 --- a/dist/hotkeys.js +++ b/dist/hotkeys.js @@ -1,5 +1,5 @@ /**! - * hotkeys-js v3.12.0 + * hotkeys-js v3.12.2 * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies. * * Copyright (c) 2023 kenny wong @@ -505,6 +505,7 @@ if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line if (option.capture !== undefined) capture = option.capture; // eslint-disable-line if (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line + if (option.singleton === true) ; // eslint-disable-line } if (typeof option === 'string') scope = option; diff --git a/dist/hotkeys.min.js b/dist/hotkeys.min.js index 47b5ac7f..68379a49 100644 --- a/dist/hotkeys.min.js +++ b/dist/hotkeys.min.js @@ -1,2 +1,2 @@ -/*! hotkeys-js v3.12.0 | MIT © 2023 kenny wong https://jaywcjlove.github.io/hotkeys-js */ +/*! hotkeys-js v3.12.2 | MIT © 2023 kenny wong 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 Date: Fri, 8 Dec 2023 18:52:45 +0800 Subject: [PATCH 2/2] type: Option.single --- index.d.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/index.d.ts b/index.d.ts index 298839b2..2a6651ca 100644 --- a/index.d.ts +++ b/index.d.ts @@ -18,6 +18,7 @@ type Options = { keydown?: boolean | null; capture?: boolean splitKey?: string; + single?: boolean; } export interface Hotkeys { @@ -39,7 +40,7 @@ export interface Hotkeys { /** * Use the `hotkeys.setScope` method to set scope. There can only be one active scope besides 'all'. By default 'all' is always active. - * + * * ```js * // Define shortcuts with a scope * hotkeys('ctrl+o, ctrl+alt+enter', 'issues', function() { @@ -48,7 +49,7 @@ export interface Hotkeys { * hotkeys('o, enter', 'files', function() { * console.log('do something else'); * }); - * + * * // Set the scope (only 'all' and 'issues' shortcuts will be honored) * hotkeys.setScope('issues'); // default scope is 'all' * ``` @@ -56,7 +57,7 @@ export interface Hotkeys { setScope(scopeName: string): void; /** * Use the `hotkeys.getScope` method to get scope. - * + * * ```js * hotkeys.getScope(); * ``` @@ -64,12 +65,12 @@ export interface Hotkeys { getScope(): string; /** * Use the `hotkeys.deleteScope` method to delete a scope. This will also remove all associated hotkeys with it. - * + * * ```js * hotkeys.deleteScope('issues'); * ``` * You can use second argument, if need set new scope after deleting. - * + * * ```js * hotkeys.deleteScope('issues', 'newScopeName'); * ``` @@ -78,13 +79,13 @@ export interface Hotkeys { /** * Relinquish HotKeys’s control of the `hotkeys` variable. - * + * * ```js * var k = hotkeys.noConflict(); * k('a', function() { * console.log("do something") * }); - * + * * hotkeys() * // -->Uncaught TypeError: hotkeys is not a function(anonymous function) * // @ VM2170:2InjectedScript._evaluateOn @@ -96,7 +97,7 @@ export interface Hotkeys { /** * trigger shortcut key event - * + * * ```js * hotkeys.trigger('ctrl+o'); * hotkeys.trigger('ctrl+o', 'scope2'); @@ -115,7 +116,7 @@ export interface Hotkeys { isPressed(keyCode: string): boolean; /** * Returns an array of key codes currently pressed. - * + * * ```js * hotkeys('command+ctrl+shift+a,f', function() { * console.log(hotkeys.getPressedKeyCodes()); //=> [17, 65] or [70] @@ -125,7 +126,7 @@ export interface Hotkeys { getPressedKeyCodes(): number[]; /** * Returns an array of key codes currently pressed. - * + * * ```js * hotkeys('command+ctrl+shift+a,f', function() { * console.log(hotkeys.getPressedKeyString()); //=> ['⌘', '⌃', '⇧', 'A', 'F'] @@ -135,7 +136,7 @@ export interface Hotkeys { getPressedKeyString(): string[]; /** * Get a list of all registration codes. - * + * * ```js * hotkeys('command+ctrl+shift+a,f', function() { * console.log(hotkeys.getAllKeyCodes()); @@ -145,7 +146,7 @@ export interface Hotkeys { * // ] * }) * ``` - * + * */ getAllKeyCodes(): Omit; @@ -153,7 +154,7 @@ export interface Hotkeys { * By default hotkeys are not enabled for `INPUT` `SELECT` `TEXTAREA` elements. * `Hotkeys.filter` to return to the `true` shortcut keys set to play a role, * `false` shortcut keys set up failure. - * + * * ```js * hotkeys.filter = function(event){ * return true; @@ -165,7 +166,7 @@ export interface Hotkeys { * var tagName = target.tagName; * return !(target.isContentEditable || tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA'); * } - * + * * hotkeys.filter = function(event){ * var tagName = (event.target || event.srcElement).tagName; * hotkeys.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other');