Skip to content

Commit 7bf34e9

Browse files
authored
feat: add single option. (#463)
* feat: single callback * type: Option.single
1 parent 7782744 commit 7bf34e9

File tree

8 files changed

+33
-21
lines changed

8 files changed

+33
-21
lines changed

dist/hotkeys.common.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**!
2-
* hotkeys-js v3.12.0
2+
* hotkeys-js v3.12.2
33
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
44
*
55
* Copyright (c) 2023 kenny wong <wowohoo@qq.com>
@@ -501,6 +501,7 @@ function hotkeys(key, option, method) {
501501
if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line
502502
if (option.capture !== undefined) capture = option.capture; // eslint-disable-line
503503
if (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line
504+
if (option.singleton === true) ; // eslint-disable-line
504505
}
505506

506507
if (typeof option === 'string') scope = option;

dist/hotkeys.common.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/hotkeys.esm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**!
2-
* hotkeys-js v3.12.0
2+
* hotkeys-js v3.12.2
33
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
44
*
55
* Copyright (c) 2023 kenny wong <wowohoo@qq.com>
@@ -499,6 +499,7 @@ function hotkeys(key, option, method) {
499499
if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line
500500
if (option.capture !== undefined) capture = option.capture; // eslint-disable-line
501501
if (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line
502+
if (option.singleton === true) ; // eslint-disable-line
502503
}
503504

504505
if (typeof option === 'string') scope = option;

dist/hotkeys.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**!
2-
* hotkeys-js v3.12.0
2+
* hotkeys-js v3.12.2
33
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
44
*
55
* Copyright (c) 2023 kenny wong <wowohoo@qq.com>
@@ -505,6 +505,7 @@
505505
if (option.keydown !== undefined) keydown = option.keydown; // eslint-disable-line
506506
if (option.capture !== undefined) capture = option.capture; // eslint-disable-line
507507
if (typeof option.splitKey === 'string') splitKey = option.splitKey; // eslint-disable-line
508+
if (option.singleton === true) ; // eslint-disable-line
508509
}
509510

510511
if (typeof option === 'string') scope = option;

dist/hotkeys.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.d.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ type Options = {
1818
keydown?: boolean | null;
1919
capture?: boolean
2020
splitKey?: string;
21+
single?: boolean;
2122
}
2223

2324
export interface Hotkeys {
@@ -39,7 +40,7 @@ export interface Hotkeys {
3940

4041
/**
4142
* Use the `hotkeys.setScope` method to set scope. There can only be one active scope besides 'all'. By default 'all' is always active.
42-
*
43+
*
4344
* ```js
4445
* // Define shortcuts with a scope
4546
* hotkeys('ctrl+o, ctrl+alt+enter', 'issues', function() {
@@ -48,28 +49,28 @@ export interface Hotkeys {
4849
* hotkeys('o, enter', 'files', function() {
4950
* console.log('do something else');
5051
* });
51-
*
52+
*
5253
* // Set the scope (only 'all' and 'issues' shortcuts will be honored)
5354
* hotkeys.setScope('issues'); // default scope is 'all'
5455
* ```
5556
*/
5657
setScope(scopeName: string): void;
5758
/**
5859
* Use the `hotkeys.getScope` method to get scope.
59-
*
60+
*
6061
* ```js
6162
* hotkeys.getScope();
6263
* ```
6364
*/
6465
getScope(): string;
6566
/**
6667
* Use the `hotkeys.deleteScope` method to delete a scope. This will also remove all associated hotkeys with it.
67-
*
68+
*
6869
* ```js
6970
* hotkeys.deleteScope('issues');
7071
* ```
7172
* You can use second argument, if need set new scope after deleting.
72-
*
73+
*
7374
* ```js
7475
* hotkeys.deleteScope('issues', 'newScopeName');
7576
* ```
@@ -78,13 +79,13 @@ export interface Hotkeys {
7879

7980
/**
8081
* Relinquish HotKeys’s control of the `hotkeys` variable.
81-
*
82+
*
8283
* ```js
8384
* var k = hotkeys.noConflict();
8485
* k('a', function() {
8586
* console.log("do something")
8687
* });
87-
*
88+
*
8889
* hotkeys()
8990
* // -->Uncaught TypeError: hotkeys is not a function(anonymous function)
9091
* // @ VM2170:2InjectedScript._evaluateOn
@@ -96,7 +97,7 @@ export interface Hotkeys {
9697

9798
/**
9899
* trigger shortcut key event
99-
*
100+
*
100101
* ```js
101102
* hotkeys.trigger('ctrl+o');
102103
* hotkeys.trigger('ctrl+o', 'scope2');
@@ -115,7 +116,7 @@ export interface Hotkeys {
115116
isPressed(keyCode: string): boolean;
116117
/**
117118
* Returns an array of key codes currently pressed.
118-
*
119+
*
119120
* ```js
120121
* hotkeys('command+ctrl+shift+a,f', function() {
121122
* console.log(hotkeys.getPressedKeyCodes()); //=> [17, 65] or [70]
@@ -125,7 +126,7 @@ export interface Hotkeys {
125126
getPressedKeyCodes(): number[];
126127
/**
127128
* Returns an array of key codes currently pressed.
128-
*
129+
*
129130
* ```js
130131
* hotkeys('command+ctrl+shift+a,f', function() {
131132
* console.log(hotkeys.getPressedKeyString()); //=> ['⌘', '⌃', '⇧', 'A', 'F']
@@ -135,7 +136,7 @@ export interface Hotkeys {
135136
getPressedKeyString(): string[];
136137
/**
137138
* Get a list of all registration codes.
138-
*
139+
*
139140
* ```js
140141
* hotkeys('command+ctrl+shift+a,f', function() {
141142
* console.log(hotkeys.getAllKeyCodes());
@@ -145,15 +146,15 @@ export interface Hotkeys {
145146
* // ]
146147
* })
147148
* ```
148-
*
149+
*
149150
*/
150151
getAllKeyCodes(): Omit<HotkeysEvent, 'method' | 'key'>;
151152

152153
/**
153154
* By default hotkeys are not enabled for `INPUT` `SELECT` `TEXTAREA` elements.
154155
* `Hotkeys.filter` to return to the `true` shortcut keys set to play a role,
155156
* `false` shortcut keys set up failure.
156-
*
157+
*
157158
* ```js
158159
* hotkeys.filter = function(event){
159160
* return true;
@@ -165,7 +166,7 @@ export interface Hotkeys {
165166
* var tagName = target.tagName;
166167
* return !(target.isContentEditable || tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA');
167168
* }
168-
*
169+
*
169170
* hotkeys.filter = function(event){
170171
* var tagName = (event.target || event.srcElement).tagName;
171172
* hotkeys.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other');

0 commit comments

Comments
 (0)