feat: add single option. (#463)

* feat: single callback

* type: Option.single
pull/459/head
AllenLee 1 year ago committed by GitHub
parent 7782744eaa
commit 7bf34e9dfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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. * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
* *
* Copyright (c) 2023 kenny wong <wowohoo@qq.com> * Copyright (c) 2023 kenny wong <wowohoo@qq.com>
@ -501,6 +501,7 @@ function hotkeys(key, option, method) {
if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line
if (option.capture !== undefined) capture = option.capture; // 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 (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line
if (option.singleton === true) ; // eslint-disable-line
} }
if (typeof option === 'string') scope = option; if (typeof option === 'string') scope = option;

File diff suppressed because one or more lines are too long

@ -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. * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
* *
* Copyright (c) 2023 kenny wong <wowohoo@qq.com> * Copyright (c) 2023 kenny wong <wowohoo@qq.com>
@ -499,6 +499,7 @@ function hotkeys(key, option, method) {
if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line
if (option.capture !== undefined) capture = option.capture; // 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 (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line
if (option.singleton === true) ; // eslint-disable-line
} }
if (typeof option === 'string') scope = option; if (typeof option === 'string') scope = option;

3
dist/hotkeys.js vendored

@ -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. * A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
* *
* Copyright (c) 2023 kenny wong <wowohoo@qq.com> * Copyright (c) 2023 kenny wong <wowohoo@qq.com>
@ -505,6 +505,7 @@
if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line
if (option.capture !== undefined) capture = option.capture; // 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 (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line
if (option.singleton === true) ; // eslint-disable-line
} }
if (typeof option === 'string') scope = option; if (typeof option === 'string') scope = option;

File diff suppressed because one or more lines are too long

1
index.d.ts vendored

@ -18,6 +18,7 @@ type Options = {
keydown?: boolean | null; keydown?: boolean | null;
capture?: boolean capture?: boolean
splitKey?: string; splitKey?: string;
single?: boolean;
} }
export interface Hotkeys { export interface Hotkeys {

7
package-lock.json generated

@ -1,12 +1,12 @@
{ {
"name": "hotkeys-js", "name": "hotkeys-js",
"version": "3.11.2", "version": "3.12.2",
"lockfileVersion": 3, "lockfileVersion": 3,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"name": "hotkeys-js", "name": "hotkeys-js",
"version": "3.11.2", "version": "3.12.2",
"license": "MIT", "license": "MIT",
"devDependencies": { "devDependencies": {
"@babel/eslint-parser": "^7.18.9", "@babel/eslint-parser": "^7.18.9",
@ -39,6 +39,9 @@
"rimraf": "^5.0.1", "rimraf": "^5.0.1",
"rollup": "^3.26.2", "rollup": "^3.26.2",
"uglify-js": "^3.17.4" "uglify-js": "^3.17.4"
},
"funding": {
"url": "https://jaywcjlove.github.io/#/sponsor"
} }
}, },
"node_modules/@aashutoshrathi/word-wrap": { "node_modules/@aashutoshrathi/word-wrap": {

@ -350,6 +350,7 @@ function hotkeys(key, option, method) {
let keydown = true; let keydown = true;
let splitKey = '+'; let splitKey = '+';
let capture = false; let capture = false;
let single = false; // 单个callback
// 对为设定范围的判断 // 对为设定范围的判断
if (method === undefined && typeof option === 'function') { if (method === undefined && typeof option === 'function') {
@ -363,6 +364,7 @@ function hotkeys(key, option, method) {
if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line
if (option.capture !== undefined) capture = option.capture; // 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 (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; if (typeof option === 'string') scope = option;
@ -381,6 +383,9 @@ function hotkeys(key, option, method) {
// 判断key是否在_handlers中不在就赋一个空数组 // 判断key是否在_handlers中不在就赋一个空数组
if (!(key in _handlers)) _handlers[key] = []; if (!(key in _handlers)) _handlers[key] = [];
// 如果只允许单个callback重新设置_handlers
if (single) _handlers[key] = [];
_handlers[key].push({ _handlers[key].push({
keyup, keyup,
keydown, keydown,

Loading…
Cancel
Save