Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: single callback #463

Merged
merged 2 commits into from
Dec 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dist/hotkeys.common.js
Original file line number Diff line number Diff line change
@@ -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 <wowohoo@qq.com>
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dist/hotkeys.common.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion dist/hotkeys.esm.js
Original file line number Diff line number Diff line change
@@ -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 <wowohoo@qq.com>
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion dist/hotkeys.js
Original file line number Diff line number Diff line change
@@ -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 <wowohoo@qq.com>
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dist/hotkeys.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 15 additions & 14 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type Options = {
keydown?: boolean | null;
capture?: boolean
splitKey?: string;
single?: boolean;
}

export interface Hotkeys {
Expand All @@ -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() {
Expand All @@ -48,28 +49,28 @@ 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'
* ```
*/
setScope(scopeName: string): void;
/**
* Use the `hotkeys.getScope` method to get scope.
*
*
* ```js
* hotkeys.getScope();
* ```
*/
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');
* ```
Expand All @@ -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
Expand All @@ -96,7 +97,7 @@ export interface Hotkeys {

/**
* trigger shortcut key event
*
*
* ```js
* hotkeys.trigger('ctrl+o');
* hotkeys.trigger('ctrl+o', 'scope2');
Expand All @@ -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]
Expand All @@ -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']
Expand All @@ -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());
Expand All @@ -145,15 +146,15 @@ export interface Hotkeys {
* // ]
* })
* ```
*
*
*/
getAllKeyCodes(): Omit<HotkeysEvent, 'method' | 'key'>;

/**
* 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;
Expand All @@ -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');
Expand Down
Loading