Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-hotkeys-hook

Package Overview
Dependencies
Maintainers
1
Versions
113
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 4.3.1 to 4.3.2

31

dist/react-hotkeys-hook.cjs.development.js

@@ -180,3 +180,6 @@ 'use strict';

}
var isHotkeyMatchingKeyboardEvent = function isHotkeyMatchingKeyboardEvent(e, hotkey) {
var isHotkeyMatchingKeyboardEvent = function isHotkeyMatchingKeyboardEvent(e, hotkey, ignoreModifiers) {
if (ignoreModifiers === void 0) {
ignoreModifiers = false;
}
var alt = hotkey.alt,

@@ -195,17 +198,19 @@ meta = hotkey.meta,

var pressedKey = pressedKeyUppercase.toLowerCase();
if (altKey !== alt && pressedKey !== 'alt') {
return false;
}
if (shiftKey !== shift && pressedKey !== 'shift') {
return false;
}
// Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
if (mod) {
if (!metaKey && !ctrlKey) {
if (!ignoreModifiers) {
if (altKey !== alt && pressedKey !== 'alt') {
return false;
}
} else {
if (metaKey !== meta && ctrlKey !== meta && keyCode !== 'meta' && keyCode !== 'ctrl') {
if (shiftKey !== shift && pressedKey !== 'shift') {
return false;
}
// Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
if (mod) {
if (!metaKey && !ctrlKey) {
return false;
}
} else {
if (metaKey !== meta && ctrlKey !== meta && keyCode !== 'meta' && keyCode !== 'ctrl') {
return false;
}
}
}

@@ -390,3 +395,3 @@ // All modifiers are correct, now check the key

var hotkey = parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey);
if ((isHotkeyMatchingKeyboardEvent(e, hotkey) || (_hotkey$keys = hotkey.keys) != null && _hotkey$keys.includes('*')) && !hasTriggeredRef.current) {
if ((isHotkeyMatchingKeyboardEvent(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.ignoreModifiers) || (_hotkey$keys = hotkey.keys) != null && _hotkey$keys.includes('*')) && !hasTriggeredRef.current) {
maybePreventDefault(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.preventDefault);

@@ -393,0 +398,0 @@ if (!isHotkeyEnabled(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.enabled)) {

@@ -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"],r={esc:"escape",return:"enter",".":"period",",":"comma","-":"slash"," ":"space","#":"backslash","+":"bracketright",ShiftLeft:"shift",ShiftRight:"shift",AltLeft:"alt",AltRight:"alt",MetaLeft:"meta",MetaRight:"meta",ControlLeft:"ctrl",ControlRight:"ctrl"};function u(e){return(r[e]||e).trim().toLowerCase().replace("key","").replace("digit","").replace("numpad","").replace("arrow","")}function i(e,t){return void 0===t&&(t=","),"string"==typeof e?e.split(t):e}function c(e,t){void 0===t&&(t="+");var r=e.toLocaleLowerCase().split(t).map((function(e){return u(e)}));return n({},{alt:r.includes("alt"),shift:r.includes("shift"),meta:r.includes("meta"),mod:r.includes("mod")},{keys:r.filter((function(e){return!o.includes(e)}))})}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 d(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 s(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)}"undefined"!=typeof document&&(document.addEventListener("keydown",(function(e){void 0!==e.key&&d([u(e.key),u(e.code)])})),document.addEventListener("keyup",(function(e){void 0!==e.key&&s([u(e.key),u(e.code)])}))),"undefined"!=typeof window&&window.addEventListener("blur",(function(){a.clear()}));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 m=e.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),k=function(){return e.useContext(m)},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,u=n.children,i=e.useState((null==r?void 0:r.length)>0?r:["*"]),c=i[0],a=i[1],l=e.useState([]),d=l[0],s=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}))}))}),[]),k=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){s((function(t){return[].concat(t,[e])}))}),[]),b=e.useCallback((function(e){s((function(t){return t.filter((function(t){return!p(t,e)}))}))}),[]);return t.jsx(m.Provider,{value:{enabledScopes:c,hotkeys:d,enableScope:f,disableScope:v,toggleScope:k},children:t.jsx(y,{addHotkey:h,removeHotkey:b,children:u})})},exports.isHotkeyPressed=l,exports.useHotkeys=function(t,n,o,r){var a=e.useRef(null),y=e.useRef(!1),m=o instanceof Array?r instanceof Array?void 0:r:o,w=e.useCallback(n,[].concat(o instanceof Array?o:r instanceof Array?r:[])),g=function(t){var n=e.useRef(void 0);return p(n.current,t)||(n.current=t),n.current}(m),C=k().enabledScopes,L=e.useContext(v);return b((function(){if(!1!==(null==g?void 0:g.enabled)&&(n=null==g?void 0:g.scopes,0===(e=C).length&&n?(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):!n||e.some((function(e){return n.includes(e)}))||e.includes("*"))){var e,n,o=function(e,n){var o;void 0===n&&(n=!1),(!f(e,["input","textarea","select"])||f(e,null==g?void 0:g.enableOnFormTags))&&(null===a.current||document.activeElement===a.current||a.current.contains(document.activeElement)?(null==(o=e.target)||!o.isContentEditable||null!=g&&g.enableOnContentEditable)&&i(t,null==g?void 0:g.splitKey).forEach((function(t){var o,r=c(t,null==g?void 0:g.combinationKey);if((function(e,t){var n=t.alt,o=t.meta,r=t.mod,i=t.shift,c=t.keys,a=e.key,d=e.code,s=l("alt"),f=l("shift"),v=l("meta"),y=l("ctrl"),p=u(d),m=a.toLowerCase();if(s!==n&&"alt"!==m)return!1;if(f!==i&&"shift"!==m)return!1;if(r){if(!v&&!y)return!1}else if(v!==o&&y!==o&&"meta"!==p&&"ctrl"!==p)return!1;return!(!c||1!==c.length||!c.includes(m)&&!c.includes(p))||(c?l(c):!c)}(e,r)||null!=(o=r.keys)&&o.includes("*"))&&!y.current){if(function(e,t,n){("function"==typeof n&&n(e,t)||!0===n)&&e.preventDefault()}(e,r,null==g?void 0:g.preventDefault),!function(e,t,n){return"function"==typeof n?n(e,t):!0===n||void 0===n}(e,r,null==g?void 0:g.enabled))return void h(e);w(e,r),n||(y.current=!0)}})):h(e))},r=function(e){void 0!==e.key&&(d(u(e.code)),(void 0===(null==g?void 0:g.keydown)&&!0!==(null==g?void 0:g.keyup)||null!=g&&g.keydown)&&o(e))},v=function(e){void 0!==e.key&&(s(u(e.code)),y.current=!1,null!=g&&g.keyup&&o(e,!0))};return(a.current||(null==m?void 0:m.document)||document).addEventListener("keyup",v),(a.current||(null==m?void 0:m.document)||document).addEventListener("keydown",r),L&&i(t,null==g?void 0:g.splitKey).forEach((function(e){return L.addHotkey(c(e,null==g?void 0:g.combinationKey))})),function(){(a.current||(null==m?void 0:m.document)||document).removeEventListener("keyup",v),(a.current||(null==m?void 0:m.document)||document).removeEventListener("keydown",r),L&&i(t,null==g?void 0:g.splitKey).forEach((function(e){return L.removeHotkey(c(e,null==g?void 0:g.combinationKey))}))}}}),[t,w,g,C]),a},exports.useHotkeysContext=k,exports.useRecordHotkeys=function(){var t=e.useState(new Set),n=t[0],o=t[1],r=e.useState(!1),i=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(u(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:i}]};
"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"],r={esc:"escape",return:"enter",".":"period",",":"comma","-":"slash"," ":"space","#":"backslash","+":"bracketright",ShiftLeft:"shift",ShiftRight:"shift",AltLeft:"alt",AltRight:"alt",MetaLeft:"meta",MetaRight:"meta",ControlLeft:"ctrl",ControlRight:"ctrl"};function u(e){return(r[e]||e).trim().toLowerCase().replace("key","").replace("digit","").replace("numpad","").replace("arrow","")}function i(e,t){return void 0===t&&(t=","),"string"==typeof e?e.split(t):e}function c(e,t){void 0===t&&(t="+");var r=e.toLocaleLowerCase().split(t).map((function(e){return u(e)}));return n({},{alt:r.includes("alt"),shift:r.includes("shift"),meta:r.includes("meta"),mod:r.includes("mod")},{keys:r.filter((function(e){return!o.includes(e)}))})}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 d(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 s(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)}"undefined"!=typeof document&&(document.addEventListener("keydown",(function(e){void 0!==e.key&&d([u(e.key),u(e.code)])})),document.addEventListener("keyup",(function(e){void 0!==e.key&&s([u(e.key),u(e.code)])}))),"undefined"!=typeof window&&window.addEventListener("blur",(function(){a.clear()}));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 m=e.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),k=function(){return e.useContext(m)},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,u=n.children,i=e.useState((null==r?void 0:r.length)>0?r:["*"]),c=i[0],a=i[1],l=e.useState([]),d=l[0],s=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}))}))}),[]),k=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){s((function(t){return[].concat(t,[e])}))}),[]),b=e.useCallback((function(e){s((function(t){return t.filter((function(t){return!p(t,e)}))}))}),[]);return t.jsx(m.Provider,{value:{enabledScopes:c,hotkeys:d,enableScope:f,disableScope:v,toggleScope:k},children:t.jsx(y,{addHotkey:h,removeHotkey:b,children:u})})},exports.isHotkeyPressed=l,exports.useHotkeys=function(t,n,o,r){var a=e.useRef(null),y=e.useRef(!1),m=o instanceof Array?r instanceof Array?void 0:r:o,w=e.useCallback(n,[].concat(o instanceof Array?o:r instanceof Array?r:[])),g=function(t){var n=e.useRef(void 0);return p(n.current,t)||(n.current=t),n.current}(m),C=k().enabledScopes,L=e.useContext(v);return b((function(){if(!1!==(null==g?void 0:g.enabled)&&(n=null==g?void 0:g.scopes,0===(e=C).length&&n?(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):!n||e.some((function(e){return n.includes(e)}))||e.includes("*"))){var e,n,o=function(e,n){var o;void 0===n&&(n=!1),(!f(e,["input","textarea","select"])||f(e,null==g?void 0:g.enableOnFormTags))&&(null===a.current||document.activeElement===a.current||a.current.contains(document.activeElement)?(null==(o=e.target)||!o.isContentEditable||null!=g&&g.enableOnContentEditable)&&i(t,null==g?void 0:g.splitKey).forEach((function(t){var o,r=c(t,null==g?void 0:g.combinationKey);if((function(e,t,n){void 0===n&&(n=!1);var o=t.alt,r=t.meta,i=t.mod,c=t.shift,a=t.keys,d=e.key,s=e.code,f=l("alt"),v=l("shift"),y=l("meta"),p=l("ctrl"),m=u(s),k=d.toLowerCase();if(!n){if(f!==o&&"alt"!==k)return!1;if(v!==c&&"shift"!==k)return!1;if(i){if(!y&&!p)return!1}else if(y!==r&&p!==r&&"meta"!==m&&"ctrl"!==m)return!1}return!(!a||1!==a.length||!a.includes(k)&&!a.includes(m))||(a?l(a):!a)}(e,r,null==g?void 0:g.ignoreModifiers)||null!=(o=r.keys)&&o.includes("*"))&&!y.current){if(function(e,t,n){("function"==typeof n&&n(e,t)||!0===n)&&e.preventDefault()}(e,r,null==g?void 0:g.preventDefault),!function(e,t,n){return"function"==typeof n?n(e,t):!0===n||void 0===n}(e,r,null==g?void 0:g.enabled))return void h(e);w(e,r),n||(y.current=!0)}})):h(e))},r=function(e){void 0!==e.key&&(d(u(e.code)),(void 0===(null==g?void 0:g.keydown)&&!0!==(null==g?void 0:g.keyup)||null!=g&&g.keydown)&&o(e))},v=function(e){void 0!==e.key&&(s(u(e.code)),y.current=!1,null!=g&&g.keyup&&o(e,!0))};return(a.current||(null==m?void 0:m.document)||document).addEventListener("keyup",v),(a.current||(null==m?void 0:m.document)||document).addEventListener("keydown",r),L&&i(t,null==g?void 0:g.splitKey).forEach((function(e){return L.addHotkey(c(e,null==g?void 0:g.combinationKey))})),function(){(a.current||(null==m?void 0:m.document)||document).removeEventListener("keyup",v),(a.current||(null==m?void 0:m.document)||document).removeEventListener("keydown",r),L&&i(t,null==g?void 0:g.splitKey).forEach((function(e){return L.removeHotkey(c(e,null==g?void 0:g.combinationKey))}))}}}),[t,w,g,C]),a},exports.useHotkeysContext=k,exports.useRecordHotkeys=function(){var t=e.useState(new Set),n=t[0],o=t[1],r=e.useState(!1),i=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(u(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:i}]};
//# sourceMappingURL=react-hotkeys-hook.cjs.production.min.js.map

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

}
var isHotkeyMatchingKeyboardEvent = function isHotkeyMatchingKeyboardEvent(e, hotkey) {
var isHotkeyMatchingKeyboardEvent = function isHotkeyMatchingKeyboardEvent(e, hotkey, ignoreModifiers) {
if (ignoreModifiers === void 0) {
ignoreModifiers = false;
}
var alt = hotkey.alt,

@@ -193,17 +196,19 @@ meta = hotkey.meta,

var pressedKey = pressedKeyUppercase.toLowerCase();
if (altKey !== alt && pressedKey !== 'alt') {
return false;
}
if (shiftKey !== shift && pressedKey !== 'shift') {
return false;
}
// Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
if (mod) {
if (!metaKey && !ctrlKey) {
if (!ignoreModifiers) {
if (altKey !== alt && pressedKey !== 'alt') {
return false;
}
} else {
if (metaKey !== meta && ctrlKey !== meta && keyCode !== 'meta' && keyCode !== 'ctrl') {
if (shiftKey !== shift && pressedKey !== 'shift') {
return false;
}
// Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
if (mod) {
if (!metaKey && !ctrlKey) {
return false;
}
} else {
if (metaKey !== meta && ctrlKey !== meta && keyCode !== 'meta' && keyCode !== 'ctrl') {
return false;
}
}
}

@@ -388,3 +393,3 @@ // All modifiers are correct, now check the key

var hotkey = parseHotkey(key, memoisedOptions == null ? void 0 : memoisedOptions.combinationKey);
if ((isHotkeyMatchingKeyboardEvent(e, hotkey) || (_hotkey$keys = hotkey.keys) != null && _hotkey$keys.includes('*')) && !hasTriggeredRef.current) {
if ((isHotkeyMatchingKeyboardEvent(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.ignoreModifiers) || (_hotkey$keys = hotkey.keys) != null && _hotkey$keys.includes('*')) && !hasTriggeredRef.current) {
maybePreventDefault(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.preventDefault);

@@ -391,0 +396,0 @@ if (!isHotkeyEnabled(e, hotkey, memoisedOptions == null ? void 0 : memoisedOptions.enabled)) {

@@ -31,3 +31,4 @@ import type { DependencyList } from 'react';

document?: Document;
ignoreModifiers?: boolean;
};
export declare type OptionsOrDependencyArray = Options | DependencyList;

@@ -7,2 +7,2 @@ import { FormTags, Hotkey, Scopes, Trigger } from './types';

export declare function isScopeActive(activeScopes: string[], scopes?: Scopes): boolean;
export declare const isHotkeyMatchingKeyboardEvent: (e: KeyboardEvent, hotkey: Hotkey) => boolean;
export declare const isHotkeyMatchingKeyboardEvent: (e: KeyboardEvent, hotkey: Hotkey, ignoreModifiers?: boolean) => boolean;
{
"name": "react-hotkeys-hook",
"version": "4.3.1",
"version": "4.3.2",
"repository": "https://JohannesKlauss@github.com/JohannesKlauss/react-keymap-hook.git",

@@ -5,0 +5,0 @@ "homepage": "https://johannesklauss.github.io/react-hotkeys-hook/",

@@ -39,4 +39,5 @@ import type { DependencyList } from 'react'

document?: Document // Listen to events on the document instead of the window. (Default: false)
ignoreModifiers?: boolean // Ignore modifiers when matching hotkeys. (Default: false)
}
export type OptionsOrDependencyArray = Options | DependencyList

@@ -68,3 +68,3 @@ import { HotkeyCallback, Keys, Options, OptionsOrDependencyArray, RefType } from './types'

if ((isHotkeyMatchingKeyboardEvent(e, hotkey) || hotkey.keys?.includes('*')) && !hasTriggeredRef.current) {
if ((isHotkeyMatchingKeyboardEvent(e, hotkey, memoisedOptions?.ignoreModifiers) || hotkey.keys?.includes('*')) && !hasTriggeredRef.current) {
maybePreventDefault(e, hotkey, memoisedOptions?.preventDefault)

@@ -71,0 +71,0 @@

@@ -36,3 +36,3 @@ import { FormTags, Hotkey, Scopes, Trigger } from './types'

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>'
'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>',
)

@@ -50,3 +50,3 @@

export const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey): boolean => {
export const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey, ignoreModifiers: boolean = false): boolean => {
const { alt, meta, mod, shift, keys } = hotkey

@@ -63,19 +63,21 @@ const { key: pressedKeyUppercase, code } = e

if (altKey !== alt && pressedKey !== 'alt') {
return false
}
if (shiftKey !== shift && pressedKey !== 'shift') {
return false
}
// Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
if (mod) {
if (!metaKey && !ctrlKey) {
if (!ignoreModifiers) {
if (altKey !== alt && pressedKey !== 'alt') {
return false
}
} else {
if (metaKey !== meta && ctrlKey !== meta && keyCode !== 'meta' && keyCode !== 'ctrl') {
if (shiftKey !== shift && pressedKey !== 'shift') {
return false
}
// Mod is a special key name that is checking for meta on macOS and ctrl on other platforms
if (mod) {
if (!metaKey && !ctrlKey) {
return false
}
} else {
if (metaKey !== meta && ctrlKey !== meta && keyCode !== 'meta' && keyCode !== 'ctrl') {
return false
}
}
}

@@ -90,4 +92,3 @@

return isHotkeyPressed(keys)
}
else if (!keys) {
} else if (!keys) {
// If the key is not set, we only listen for modifiers, that check went alright, so we return true

@@ -94,0 +95,0 @@ return true

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc