🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

react-hotkeys-hook

Package Overview
Dependencies
Maintainers
1
Versions
118
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hotkeys-hook - npm Package Compare versions

Comparing version

to
4.4.0

2

dist/parseHotkeys.d.ts

@@ -5,2 +5,2 @@ import { Hotkey } from './types';

export declare function parseKeysHookInput(keys: string, splitKey?: string): string[];
export declare function parseHotkey(hotkey: string, combinationKey?: string): Hotkey;
export declare function parseHotkey(hotkey: string, combinationKey?: string, description?: string): Hotkey;

@@ -55,3 +55,3 @@ 'use strict';

}
function parseHotkey(hotkey, combinationKey) {
function parseHotkey(hotkey, combinationKey, description) {
if (combinationKey === void 0) {

@@ -74,3 +74,4 @@ combinationKey = '+';

return _extends({}, modifiers, {
keys: singleCharKeys
keys: singleCharKeys,
description: description
});

@@ -396,2 +397,5 @@ }

}
if (memoisedOptions != null && memoisedOptions.ignoreEventWhen != null && memoisedOptions.ignoreEventWhen(e)) {
return;
}
// TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE

@@ -454,3 +458,3 @@ // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WON'T TRIGGER THE HOTKEY.

parseKeysHookInput(_keys, memoisedOptions == null ? void 0 : memoisedOptions.splitKey).forEach(function (key) {
return proxy.addHotkey(parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey));
return proxy.addHotkey(parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey, memoisedOptions == null ? void 0 : memoisedOptions.description));
});

@@ -465,3 +469,3 @@ }

parseKeysHookInput(_keys, memoisedOptions == null ? void 0 : memoisedOptions.splitKey).forEach(function (key) {
return proxy.removeHotkey(parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey));
return proxy.removeHotkey(parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey, memoisedOptions == null ? void 0 : memoisedOptions.description));
});

@@ -468,0 +472,0 @@ }

@@ -1,2 +0,2 @@

"use strict";var e=require("react"),t=require("react/jsx-runtime");function n(){return(n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}var o=["shift","alt","meta","mod","ctrl"],r={esc:"escape",return:"enter",".":"period",",":"comma","-":"slash"," ":"space","`":"backquote","#":"backslash","+":"bracketright",ShiftLeft:"shift",ShiftRight:"shift",AltLeft:"alt",AltRight:"alt",MetaLeft:"meta",MetaRight:"meta",OSLeft:"meta",OSRight:"meta",ControlLeft:"ctrl",ControlRight:"ctrl"};function i(e){return(r[e]||e).trim().toLowerCase().replace(/key|digit|numpad|arrow/,"")}function u(e,t){return void 0===t&&(t=","),e.split(t)}function c(e,t){void 0===t&&(t="+");var r=e.toLocaleLowerCase().split(t).map((function(e){return i(e)}));return n({},{alt:r.includes("alt"),ctrl:r.includes("ctrl")||r.includes("control"),shift:r.includes("shift"),meta:r.includes("meta"),mod:r.includes("mod")},{keys:r.filter((function(e){return!o.includes(e)}))})}"undefined"!=typeof document&&(document.addEventListener("keydown",(function(e){void 0!==e.key&&s([i(e.key),i(e.code)])})),document.addEventListener("keyup",(function(e){void 0!==e.key&&d([i(e.key),i(e.code)])}))),"undefined"!=typeof window&&window.addEventListener("blur",(function(){a.clear()}));var a=new Set;function l(e,t){return void 0===t&&(t=","),(Array.isArray(e)?e:e.split(t)).every((function(e){return a.has(e.trim().toLowerCase())}))}function s(e){var t=Array.isArray(e)?e:[e];a.has("meta")&&a.forEach((function(e){return!function(e){return o.includes(e)}(e)&&a.delete(e.toLowerCase())})),t.forEach((function(e){return a.add(e.toLowerCase())}))}function d(e){var t=Array.isArray(e)?e:[e];"meta"===e?a.clear():t.forEach((function(e){return a.delete(e.toLowerCase())}))}function f(e,t){var n=e.target;void 0===t&&(t=!1);var o=n&&n.tagName;return t instanceof Array?Boolean(o&&t&&t.some((function(e){return e.toLowerCase()===o.toLowerCase()}))):Boolean(o&&t&&!0===t)}var v=e.createContext(void 0);function y(e){return t.jsx(v.Provider,{value:{addHotkey:e.addHotkey,removeHotkey:e.removeHotkey},children:e.children})}function p(e,t){return e&&t&&"object"==typeof e&&"object"==typeof t?Object.keys(e).length===Object.keys(t).length&&Object.keys(e).reduce((function(n,o){return n&&p(e[o],t[o])}),!0):e===t}var k=e.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),m=function(){return e.useContext(k)},h=function(e){e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},b="undefined"!=typeof window?e.useLayoutEffect:e.useEffect;exports.HotkeysProvider=function(n){var o=n.initiallyActiveScopes,r=void 0===o?["*"]:o,i=n.children,u=e.useState((null==r?void 0:r.length)>0?r:["*"]),c=u[0],a=u[1],l=e.useState([]),s=l[0],d=l[1],f=e.useCallback((function(e){a((function(t){return t.includes("*")?[e]:Array.from(new Set([].concat(t,[e])))}))}),[]),v=e.useCallback((function(e){a((function(t){return 0===t.filter((function(t){return t!==e})).length?["*"]:t.filter((function(t){return t!==e}))}))}),[]),m=e.useCallback((function(e){a((function(t){return t.includes(e)?0===t.filter((function(t){return t!==e})).length?["*"]:t.filter((function(t){return t!==e})):t.includes("*")?[e]:Array.from(new Set([].concat(t,[e])))}))}),[]),h=e.useCallback((function(e){d((function(t){return[].concat(t,[e])}))}),[]),b=e.useCallback((function(e){d((function(t){return t.filter((function(t){return!p(t,e)}))}))}),[]);return t.jsx(k.Provider,{value:{enabledScopes:c,hotkeys:s,enableScope:f,disableScope:v,toggleScope:m},children:t.jsx(y,{addHotkey:h,removeHotkey:b,children:i})})},exports.isHotkeyPressed=l,exports.useHotkeys=function(t,n,o,r){var a=e.useRef(null),y=e.useRef(!1),k=o instanceof Array?r instanceof Array?void 0:r:o,w=t instanceof Array?t.join(null==k?void 0:k.splitKey):t,g=o instanceof Array?o:r instanceof Array?r:void 0,C=e.useCallback(n,null!=g?g:[]),L=e.useRef(C);L.current=g?C:n;var S=function(t){var n=e.useRef(void 0);return p(n.current,t)||(n.current=t),n.current}(k),E=m().enabledScopes,A=e.useContext(v);return b((function(){if(!1!==(null==S?void 0:S.enabled)&&(t=null==S?void 0:S.scopes,0===(e=E).length&&t?(console.warn('A hotkey has the "scopes" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'),1):!t||e.some((function(e){return t.includes(e)}))||e.includes("*"))){var e,t,n=function(e,t){var n;void 0===t&&(t=!1),(!f(e,["input","textarea","select"])||f(e,null==S?void 0:S.enableOnFormTags))&&(null===a.current||document.activeElement===a.current||a.current.contains(document.activeElement)?(null==(n=e.target)||!n.isContentEditable||null!=S&&S.enableOnContentEditable)&&u(w,null==S?void 0:S.splitKey).forEach((function(n){var o,r=c(n,null==S?void 0:S.combinationKey);if(function(e,t,n){void 0===n&&(n=!1);var o=t.alt,r=t.meta,u=t.mod,c=t.shift,a=t.ctrl,s=t.keys,d=e.key,f=e.ctrlKey,v=e.metaKey,y=e.shiftKey,p=e.altKey,k=i(e.code),m=d.toLowerCase();if(!n){if(o===!p&&"alt"!==m)return!1;if(c===!y&&"shift"!==m)return!1;if(u){if(!v&&!f)return!1}else{if(r===!v&&"meta"!==m&&"os"!==m)return!1;if(a===!f&&"ctrl"!==m&&"control"!==m)return!1}}return!(!s||1!==s.length||!s.includes(m)&&!s.includes(k))||(s?l(s):!s)}(e,r,null==S?void 0:S.ignoreModifiers)||null!=(o=r.keys)&&o.includes("*")){if(t&&y.current)return;if(function(e,t,n){("function"==typeof n&&n(e,t)||!0===n)&&e.preventDefault()}(e,r,null==S?void 0:S.preventDefault),!function(e,t,n){return"function"==typeof n?n(e,t):!0===n||void 0===n}(e,r,null==S?void 0:S.enabled))return void h(e);L.current(e,r),t||(y.current=!0)}})):h(e))},o=function(e){void 0!==e.key&&(s(i(e.code)),(void 0===(null==S?void 0:S.keydown)&&!0!==(null==S?void 0:S.keyup)||null!=S&&S.keydown)&&n(e))},r=function(e){void 0!==e.key&&(d(i(e.code)),y.current=!1,null!=S&&S.keyup&&n(e,!0))},v=a.current||(null==k?void 0:k.document)||document;return v.addEventListener("keyup",r),v.addEventListener("keydown",o),A&&u(w,null==S?void 0:S.splitKey).forEach((function(e){return A.addHotkey(c(e,null==S?void 0:S.combinationKey))})),function(){v.removeEventListener("keyup",r),v.removeEventListener("keydown",o),A&&u(w,null==S?void 0:S.splitKey).forEach((function(e){return A.removeHotkey(c(e,null==S?void 0:S.combinationKey))}))}}}),[w,S,E]),a},exports.useHotkeysContext=m,exports.useRecordHotkeys=function(){var t=e.useState(new Set),n=t[0],o=t[1],r=e.useState(!1),u=r[0],c=r[1],a=e.useCallback((function(e){void 0!==e.key&&(e.preventDefault(),e.stopPropagation(),o((function(t){var n=new Set(t);return n.add(i(e.code)),n})))}),[]),l=e.useCallback((function(){"undefined"!=typeof document&&(document.removeEventListener("keydown",a),c(!1))}),[a]);return[n,{start:e.useCallback((function(){o(new Set),"undefined"!=typeof document&&(l(),document.addEventListener("keydown",a),c(!0))}),[a,l]),stop:l,isRecording:u}]};
"use strict";var e=require("react"),t=require("react/jsx-runtime");function n(){return(n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])}return e}).apply(this,arguments)}var o=["shift","alt","meta","mod","ctrl"],r={esc:"escape",return:"enter",".":"period",",":"comma","-":"slash"," ":"space","`":"backquote","#":"backslash","+":"bracketright",ShiftLeft:"shift",ShiftRight:"shift",AltLeft:"alt",AltRight:"alt",MetaLeft:"meta",MetaRight:"meta",OSLeft:"meta",OSRight:"meta",ControlLeft:"ctrl",ControlRight:"ctrl"};function i(e){return(r[e]||e).trim().toLowerCase().replace(/key|digit|numpad|arrow/,"")}function u(e,t){return void 0===t&&(t=","),e.split(t)}function c(e,t,r){void 0===t&&(t="+");var u=e.toLocaleLowerCase().split(t).map((function(e){return i(e)}));return n({},{alt:u.includes("alt"),ctrl:u.includes("ctrl")||u.includes("control"),shift:u.includes("shift"),meta:u.includes("meta"),mod:u.includes("mod")},{keys:u.filter((function(e){return!o.includes(e)})),description:r})}"undefined"!=typeof document&&(document.addEventListener("keydown",(function(e){void 0!==e.key&&s([i(e.key),i(e.code)])})),document.addEventListener("keyup",(function(e){void 0!==e.key&&d([i(e.key),i(e.code)])}))),"undefined"!=typeof window&&window.addEventListener("blur",(function(){a.clear()}));var a=new Set;function l(e,t){return void 0===t&&(t=","),(Array.isArray(e)?e:e.split(t)).every((function(e){return a.has(e.trim().toLowerCase())}))}function s(e){var t=Array.isArray(e)?e:[e];a.has("meta")&&a.forEach((function(e){return!function(e){return o.includes(e)}(e)&&a.delete(e.toLowerCase())})),t.forEach((function(e){return a.add(e.toLowerCase())}))}function d(e){var t=Array.isArray(e)?e:[e];"meta"===e?a.clear():t.forEach((function(e){return a.delete(e.toLowerCase())}))}function f(e,t){var n=e.target;void 0===t&&(t=!1);var o=n&&n.tagName;return t instanceof Array?Boolean(o&&t&&t.some((function(e){return e.toLowerCase()===o.toLowerCase()}))):Boolean(o&&t&&!0===t)}var v=e.createContext(void 0);function y(e){return t.jsx(v.Provider,{value:{addHotkey:e.addHotkey,removeHotkey:e.removeHotkey},children:e.children})}function p(e,t){return e&&t&&"object"==typeof e&&"object"==typeof t?Object.keys(e).length===Object.keys(t).length&&Object.keys(e).reduce((function(n,o){return n&&p(e[o],t[o])}),!0):e===t}var k=e.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),m=function(){return e.useContext(k)},h=function(e){e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},b="undefined"!=typeof window?e.useLayoutEffect:e.useEffect;exports.HotkeysProvider=function(n){var o=n.initiallyActiveScopes,r=void 0===o?["*"]:o,i=n.children,u=e.useState((null==r?void 0:r.length)>0?r:["*"]),c=u[0],a=u[1],l=e.useState([]),s=l[0],d=l[1],f=e.useCallback((function(e){a((function(t){return t.includes("*")?[e]:Array.from(new Set([].concat(t,[e])))}))}),[]),v=e.useCallback((function(e){a((function(t){return 0===t.filter((function(t){return t!==e})).length?["*"]:t.filter((function(t){return t!==e}))}))}),[]),m=e.useCallback((function(e){a((function(t){return t.includes(e)?0===t.filter((function(t){return t!==e})).length?["*"]:t.filter((function(t){return t!==e})):t.includes("*")?[e]:Array.from(new Set([].concat(t,[e])))}))}),[]),h=e.useCallback((function(e){d((function(t){return[].concat(t,[e])}))}),[]),b=e.useCallback((function(e){d((function(t){return t.filter((function(t){return!p(t,e)}))}))}),[]);return t.jsx(k.Provider,{value:{enabledScopes:c,hotkeys:s,enableScope:f,disableScope:v,toggleScope:m},children:t.jsx(y,{addHotkey:h,removeHotkey:b,children:i})})},exports.isHotkeyPressed=l,exports.useHotkeys=function(t,n,o,r){var a=e.useRef(null),y=e.useRef(!1),k=o instanceof Array?r instanceof Array?void 0:r:o,w=t instanceof Array?t.join(null==k?void 0:k.splitKey):t,g=o instanceof Array?o:r instanceof Array?r:void 0,C=e.useCallback(n,null!=g?g:[]),L=e.useRef(C);L.current=g?C:n;var S=function(t){var n=e.useRef(void 0);return p(n.current,t)||(n.current=t),n.current}(k),E=m().enabledScopes,A=e.useContext(v);return b((function(){if(!1!==(null==S?void 0:S.enabled)&&(t=null==S?void 0:S.scopes,0===(e=E).length&&t?(console.warn('A hotkey has the "scopes" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>'),1):!t||e.some((function(e){return t.includes(e)}))||e.includes("*"))){var e,t,n=function(e,t){var n;void 0===t&&(t=!1),(!f(e,["input","textarea","select"])||f(e,null==S?void 0:S.enableOnFormTags))&&(null!=S&&null!=S.ignoreEventWhen&&S.ignoreEventWhen(e)||(null===a.current||document.activeElement===a.current||a.current.contains(document.activeElement)?(null==(n=e.target)||!n.isContentEditable||null!=S&&S.enableOnContentEditable)&&u(w,null==S?void 0:S.splitKey).forEach((function(n){var o,r=c(n,null==S?void 0:S.combinationKey);if(function(e,t,n){void 0===n&&(n=!1);var o=t.alt,r=t.meta,u=t.mod,c=t.shift,a=t.ctrl,s=t.keys,d=e.key,f=e.ctrlKey,v=e.metaKey,y=e.shiftKey,p=e.altKey,k=i(e.code),m=d.toLowerCase();if(!n){if(o===!p&&"alt"!==m)return!1;if(c===!y&&"shift"!==m)return!1;if(u){if(!v&&!f)return!1}else{if(r===!v&&"meta"!==m&&"os"!==m)return!1;if(a===!f&&"ctrl"!==m&&"control"!==m)return!1}}return!(!s||1!==s.length||!s.includes(m)&&!s.includes(k))||(s?l(s):!s)}(e,r,null==S?void 0:S.ignoreModifiers)||null!=(o=r.keys)&&o.includes("*")){if(t&&y.current)return;if(function(e,t,n){("function"==typeof n&&n(e,t)||!0===n)&&e.preventDefault()}(e,r,null==S?void 0:S.preventDefault),!function(e,t,n){return"function"==typeof n?n(e,t):!0===n||void 0===n}(e,r,null==S?void 0:S.enabled))return void h(e);L.current(e,r),t||(y.current=!0)}})):h(e)))},o=function(e){void 0!==e.key&&(s(i(e.code)),(void 0===(null==S?void 0:S.keydown)&&!0!==(null==S?void 0:S.keyup)||null!=S&&S.keydown)&&n(e))},r=function(e){void 0!==e.key&&(d(i(e.code)),y.current=!1,null!=S&&S.keyup&&n(e,!0))},v=a.current||(null==k?void 0:k.document)||document;return v.addEventListener("keyup",r),v.addEventListener("keydown",o),A&&u(w,null==S?void 0:S.splitKey).forEach((function(e){return A.addHotkey(c(e,null==S?void 0:S.combinationKey,null==S?void 0:S.description))})),function(){v.removeEventListener("keyup",r),v.removeEventListener("keydown",o),A&&u(w,null==S?void 0:S.splitKey).forEach((function(e){return A.removeHotkey(c(e,null==S?void 0:S.combinationKey,null==S?void 0:S.description))}))}}}),[w,S,E]),a},exports.useHotkeysContext=m,exports.useRecordHotkeys=function(){var t=e.useState(new Set),n=t[0],o=t[1],r=e.useState(!1),u=r[0],c=r[1],a=e.useCallback((function(e){void 0!==e.key&&(e.preventDefault(),e.stopPropagation(),o((function(t){var n=new Set(t);return n.add(i(e.code)),n})))}),[]),l=e.useCallback((function(){"undefined"!=typeof document&&(document.removeEventListener("keydown",a),c(!1))}),[a]);return[n,{start:e.useCallback((function(){o(new Set),"undefined"!=typeof document&&(l(),document.addEventListener("keydown",a),c(!0))}),[a,l]),stop:l,isRecording:u}]};
//# sourceMappingURL=react-hotkeys-hook.cjs.production.min.js.map

@@ -53,3 +53,3 @@ import { useContext, createContext, useState, useCallback, useRef, useLayoutEffect, useEffect } from 'react';

}
function parseHotkey(hotkey, combinationKey) {
function parseHotkey(hotkey, combinationKey, description) {
if (combinationKey === void 0) {

@@ -72,3 +72,4 @@ combinationKey = '+';

return _extends({}, modifiers, {
keys: singleCharKeys
keys: singleCharKeys,
description: description
});

@@ -394,2 +395,5 @@ }

}
if (memoisedOptions != null && memoisedOptions.ignoreEventWhen != null && memoisedOptions.ignoreEventWhen(e)) {
return;
}
// TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE

@@ -452,3 +456,3 @@ // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WON'T TRIGGER THE HOTKEY.

parseKeysHookInput(_keys, memoisedOptions == null ? void 0 : memoisedOptions.splitKey).forEach(function (key) {
return proxy.addHotkey(parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey));
return proxy.addHotkey(parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey, memoisedOptions == null ? void 0 : memoisedOptions.description));
});

@@ -463,3 +467,3 @@ }

parseKeysHookInput(_keys, memoisedOptions == null ? void 0 : memoisedOptions.splitKey).forEach(function (key) {
return proxy.removeHotkey(parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey));
return proxy.removeHotkey(parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey, memoisedOptions == null ? void 0 : memoisedOptions.description));
});

@@ -466,0 +470,0 @@ }

@@ -16,2 +16,3 @@ import type { DependencyList } from 'react';

scopes?: Scopes;
description?: string;
};

@@ -25,2 +26,3 @@ export declare type HotkeysEvent = Hotkey;

enableOnContentEditable?: boolean;
ignoreEventWhen?: (e: KeyboardEvent) => boolean;
combinationKey?: string;

@@ -27,0 +29,0 @@ splitKey?: string;

{
"name": "react-hotkeys-hook",
"description": "React hook for handling keyboard shortcuts",
"version": "4.3.8",
"version": "4.4.0",
"repository": "https://JohannesKlauss@github.com/JohannesKlauss/react-keymap-hook.git",

@@ -78,17 +78,16 @@ "homepage": "https://johannesklauss.github.io/react-hotkeys-hook/",

"devDependencies": {
"@babel/core": "7.21.0",
"@babel/core": "7.21.4",
"@babel/plugin-proposal-class-properties": "7.18.6",
"@babel/plugin-transform-react-jsx": "7.21.0",
"@babel/preset-env": "7.20.2",
"@babel/preset-env": "7.21.4",
"@babel/preset-react": "7.18.6",
"@babel/preset-typescript": "7.21.0",
"@babel/preset-typescript": "7.21.4",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/react": "14.0.0",
"@testing-library/react-hooks": "8.0.1",
"@testing-library/user-event": "14.4.3",
"@types/jest": "29.4.0",
"@types/react": "18.0.28",
"@types/jest": "29.5.0",
"@types/react": "18.0.35",
"@types/react-dom": "18.0.11",
"@typescript-eslint/eslint-plugin": "5.54.1",
"@typescript-eslint/parser": "5.54.1",
"@typescript-eslint/eslint-plugin": "5.58.0",
"@typescript-eslint/parser": "5.58.0",
"eslint": "^8.34.0",

@@ -99,3 +98,3 @@ "eslint-plugin-prettier": "4.2.1",

"jest-environment-jsdom": "29.5.0",
"prettier": "2.8.4",
"prettier": "2.8.7",
"react": "18.2.0",

@@ -106,3 +105,3 @@ "react-dom": "18.2.0",

"tslib": "2.5.0",
"typescript": "4.9.5"
"typescript": "5.0.4"
},

@@ -109,0 +108,0 @@ "peerDependencies": {

@@ -1,2 +0,2 @@

import { Hotkey, KeyboardModifiers, Keys } from './types'
import { Hotkey, KeyboardModifiers } from './types'

@@ -38,7 +38,7 @@ const reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod', 'ctrl']

export function parseKeysHookInput(keys: string, splitKey: string = ','): string[] {
export function parseKeysHookInput(keys: string, splitKey = ','): string[] {
return keys.split(splitKey)
}
export function parseHotkey(hotkey: string, combinationKey = '+'): Hotkey {
export function parseHotkey(hotkey: string, combinationKey = '+', description?: string): Hotkey {
const keys = hotkey

@@ -62,3 +62,4 @@ .toLocaleLowerCase()

keys: singleCharKeys,
description,
}
}

@@ -20,2 +20,3 @@ import type { DependencyList } from 'react'

scopes?: Scopes
description?: string
}

@@ -33,2 +34,3 @@

enableOnContentEditable?: boolean // Enable hotkeys on tags with contentEditable props. (Default: false)
ignoreEventWhen?: (e: KeyboardEvent) => boolean // Ignore evenets based on a condition (Default: undefined)
combinationKey?: string // Character to split keys in hotkeys combinations. (Default: +)

@@ -35,0 +37,0 @@ splitKey?: string // Character to separate different hotkeys. (Default: ,)

@@ -67,2 +67,6 @@ import { HotkeyCallback, Keys, Options, OptionsOrDependencyArray, RefType } from './types'

if (memoisedOptions?.ignoreEventWhen?.(e)) {
return
}
// TODO: SINCE THE EVENT IS NOW ATTACHED TO THE REF, THE ACTIVE ELEMENT CAN NEVER BE INSIDE THE REF. THE HOTKEY ONLY TRIGGERS IF THE

@@ -147,3 +151,3 @@ // REF IS THE ACTIVE ELEMENT. THIS IS A PROBLEM SINCE FOCUSED SUB COMPONENTS WON'T TRIGGER THE HOTKEY.

parseKeysHookInput(_keys, memoisedOptions?.splitKey).forEach((key) =>
proxy.addHotkey(parseHotkey(key, memoisedOptions?.combinationKey))
proxy.addHotkey(parseHotkey(key, memoisedOptions?.combinationKey, memoisedOptions?.description))
)

@@ -160,3 +164,3 @@ }

parseKeysHookInput(_keys, memoisedOptions?.splitKey).forEach((key) =>
proxy.removeHotkey(parseHotkey(key, memoisedOptions?.combinationKey))
proxy.removeHotkey(parseHotkey(key, memoisedOptions?.combinationKey, memoisedOptions?.description))
)

@@ -163,0 +167,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet