Socket
Socket
Sign inDemoInstall

react-hotkeys-hook

Package Overview
Dependencies
Maintainers
1
Versions
111
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.0.5 to 4.0.6

9

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

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

var reservedModifierKeywords = ['ctrl', 'shift', 'alt', 'meta', 'mod'];
var reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod'];
var mappedKeys = {

@@ -91,3 +91,2 @@ esc: 'escape',

alt: keys.includes('alt'),
ctrl: keys.includes('ctrl'),
shift: keys.includes('shift'),

@@ -146,3 +145,2 @@ meta: keys.includes('meta'),

var alt = hotkey.alt,
ctrl = hotkey.ctrl,
meta = hotkey.meta,

@@ -172,8 +170,5 @@ mod = hotkey.mod,

} else {
if (metaKey !== meta && keyCode !== 'meta') {
if (metaKey !== meta && ctrlKey !== meta && keyCode !== 'meta' && keyCode !== 'ctrl') {
return false;
}
if (ctrlKey !== ctrl && keyCode !== 'ctrl') {
return false;
}
}

@@ -180,0 +175,0 @@ // All modifiers are correct, now check the key

@@ -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 r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function o(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i=["ctrl","shift","alt","meta","mod"],u={esc:"escape",return:"enter",left:"arrowleft",up:"arrowup",right:"arrowright",down:"arrowdown",1:"digit1",2:"digit2",3:"digit3",4:"digit4",5:"digit5",6:"digit6",7:"digit7",8:"digit8",9:"digit9"};function a(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 e.trim()})).map((function(e){return u[e]||e}));return n({},{alt:r.includes("alt"),ctrl:r.includes("ctrl"),shift:r.includes("shift"),meta:r.includes("meta"),mod:r.includes("mod")},{keys:r.filter((function(e){return!i.includes(e)}))})}function l(e,t){var n=e.target;void 0===t&&(t=!1);var r=n&&n.tagName;return t instanceof Array?Boolean(r&&t&&t.some((function(e){return e.toLowerCase()===r.toLowerCase()}))):Boolean(r&&t&&!0===t)}var d=e.createContext(void 0);function s(e){return t.jsx(d.Provider,{value:{addHotkey:e.addHotkey,removeHotkey:e.removeHotkey},children:e.children})}var f=e.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),y=function(){return e.useContext(f)};function v(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,r){return n&&v(e[r],t[r])}),!0):e===t}var p=function(e){e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},m="undefined"!=typeof window?e.useLayoutEffect:e.useEffect,k=new Set,h=new Set;"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",(function(){document.addEventListener("keydown",(function(e){var t;void 0!==e.key&&(t=e.key,(Array.isArray(t)?t:[t]).forEach((function(e){return h.add(c(e))})))})),document.addEventListener("keyup",(function(e){var t;void 0!==e.key&&(t=e.key,(Array.isArray(t)?t:[t]).forEach((function(e){for(var t,n=c(e),r=o(h);!(t=r()).done;){var i,u=t.value;null!=(i=u.keys)&&i.every((function(e){var t;return null==(t=n.keys)?void 0:t.includes(e)}))&&h.delete(u)}})))}))})),exports.HotkeysProvider=function(n){var r=n.initiallyActiveScopes,o=void 0===r?["*"]:r,i=n.children,u=e.useState((null==o?void 0:o.length)>0?o:["*"]),a=u[0],c=u[1],l=e.useState([]),d=l[0],y=l[1],v=e.useMemo((function(){return a.includes("*")}),[a]),p=function(e){c(v?[e]:Array.from(new Set([].concat(a,[e]))))},m=function(e){var t=a.filter((function(t){return t!==e}));c(0===t.length?["*"]:t)};return t.jsx(f.Provider,{value:{enabledScopes:a,hotkeys:d,enableScope:p,disableScope:m,toggleScope:function(e){a.includes(e)?m(e):p(e)}},children:t.jsx(s,{addHotkey:function(e){y([].concat(d,[e]))},removeHotkey:function(e){y(d.filter((function(t){return t.keys!==e.keys})))},children:i})})},exports.isHotkeyPressed=function(e,t){return void 0===t&&(t=","),(Array.isArray(e)?e:e.split(t)).every((function(e){for(var t,n=c(e),r=o(h);!(t=r()).done;)if(v(n,t.value))return!0}))},exports.useHotkeys=function(t,n,r,o){var i=e.useRef(null),u=r instanceof Array?o instanceof Array?void 0:o:r,s=e.useCallback(n,[].concat(r instanceof Array?r:o instanceof Array?o:[])),f=function(t){var n=e.useRef(void 0);return v(n.current,t)||(n.current=t),n.current}(u),h=y().enabledScopes,g=e.useContext(d);return m((function(){if(!1!==(null==f?void 0:f.enabled)&&(n=null==f?void 0:f.scopes,0===(e=h).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,r=function(e){var n;l(e,["input","textarea","select"])&&!l(e,null==f?void 0:f.enableOnFormTags)||(null===i.current||document.activeElement===i.current||i.current.contains(document.activeElement)?(null==(n=e.target)||!n.isContentEditable||null!=f&&f.enableOnContentEditable)&&a(t,null==f?void 0:f.splitKey).forEach((function(t){var n,r=c(t,null==f?void 0:f.combinationKey);if(function(e,t,n){var r=t.alt,o=t.ctrl,i=t.meta,u=t.mod,a=t.shift,c=t.keys,l=e.altKey,d=e.ctrlKey,s=e.metaKey,f=e.shiftKey,y=e.key,v=e.code.toLowerCase().replace("key",""),p=y.toLowerCase();if(l!==r&&"alt"!==p)return!1;if(f!==a&&"shift"!==p)return!1;if(u){if(!s&&!d)return!1}else{if(s!==i&&"meta"!==v)return!1;if(d!==o&&"ctrl"!==v)return!1}return!(!c||1!==c.length||!c.includes(p)&&!c.includes(v))||(c?c.every((function(e){return n.has(e)})):!c)}(e,r,k)||null!=(n=r.keys)&&n.includes("*")){if(function(e,t,n){("function"==typeof n&&n(e,t)||!0===n)&&e.preventDefault()}(e,r,null==f?void 0:f.preventDefault),!function(e,t,n){return"function"==typeof n?n(e,t):!0===n||void 0===n}(e,r,null==f?void 0:f.enabled))return void p(e);s(e,r)}})):p(e))},o=function(e){void 0!==e.key&&(k.add(e.key.toLowerCase()),(void 0===(null==f?void 0:f.keydown)&&!0!==(null==f?void 0:f.keyup)||null!=f&&f.keydown)&&r(e))},u=function(e){void 0!==e.key&&("meta"!==e.key.toLowerCase()?k.delete(e.key.toLowerCase()):k.clear(),null!=f&&f.keyup&&r(e))};return(i.current||document).addEventListener("keyup",u),(i.current||document).addEventListener("keydown",o),g&&a(t,null==f?void 0:f.splitKey).forEach((function(e){return g.addHotkey(c(e,null==f?void 0:f.combinationKey))})),function(){(i.current||document).removeEventListener("keyup",u),(i.current||document).removeEventListener("keydown",o),g&&a(t,null==f?void 0:f.splitKey).forEach((function(e){return g.removeHotkey(c(e,null==f?void 0:f.combinationKey))}))}}}),[t,s,f,h]),i},exports.useHotkeysContext=y;
"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 r in n)Object.prototype.hasOwnProperty.call(n,r)&&(e[r]=n[r])}return e}).apply(this,arguments)}function r(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function o(e,t){var n="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(n)return(n=n.call(e)).next.bind(n);if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return r(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?r(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var o=0;return function(){return o>=e.length?{done:!0}:{done:!1,value:e[o++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i=["shift","alt","meta","mod"],u={esc:"escape",return:"enter",left:"arrowleft",up:"arrowup",right:"arrowright",down:"arrowdown",1:"digit1",2:"digit2",3:"digit3",4:"digit4",5:"digit5",6:"digit6",7:"digit7",8:"digit8",9:"digit9"};function a(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 e.trim()})).map((function(e){return u[e]||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!i.includes(e)}))})}function l(e,t){var n=e.target;void 0===t&&(t=!1);var r=n&&n.tagName;return t instanceof Array?Boolean(r&&t&&t.some((function(e){return e.toLowerCase()===r.toLowerCase()}))):Boolean(r&&t&&!0===t)}var d=e.createContext(void 0);function s(e){return t.jsx(d.Provider,{value:{addHotkey:e.addHotkey,removeHotkey:e.removeHotkey},children:e.children})}var f=e.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),y=function(){return e.useContext(f)};function v(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,r){return n&&v(e[r],t[r])}),!0):e===t}var p=function(e){e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},m="undefined"!=typeof window?e.useLayoutEffect:e.useEffect,k=new Set,h=new Set;"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",(function(){document.addEventListener("keydown",(function(e){var t;void 0!==e.key&&(t=e.key,(Array.isArray(t)?t:[t]).forEach((function(e){return h.add(c(e))})))})),document.addEventListener("keyup",(function(e){var t;void 0!==e.key&&(t=e.key,(Array.isArray(t)?t:[t]).forEach((function(e){for(var t,n=c(e),r=o(h);!(t=r()).done;){var i,u=t.value;null!=(i=u.keys)&&i.every((function(e){var t;return null==(t=n.keys)?void 0:t.includes(e)}))&&h.delete(u)}})))}))})),exports.HotkeysProvider=function(n){var r=n.initiallyActiveScopes,o=void 0===r?["*"]:r,i=n.children,u=e.useState((null==o?void 0:o.length)>0?o:["*"]),a=u[0],c=u[1],l=e.useState([]),d=l[0],y=l[1],v=e.useMemo((function(){return a.includes("*")}),[a]),p=function(e){c(v?[e]:Array.from(new Set([].concat(a,[e]))))},m=function(e){var t=a.filter((function(t){return t!==e}));c(0===t.length?["*"]:t)};return t.jsx(f.Provider,{value:{enabledScopes:a,hotkeys:d,enableScope:p,disableScope:m,toggleScope:function(e){a.includes(e)?m(e):p(e)}},children:t.jsx(s,{addHotkey:function(e){y([].concat(d,[e]))},removeHotkey:function(e){y(d.filter((function(t){return t.keys!==e.keys})))},children:i})})},exports.isHotkeyPressed=function(e,t){return void 0===t&&(t=","),(Array.isArray(e)?e:e.split(t)).every((function(e){for(var t,n=c(e),r=o(h);!(t=r()).done;)if(v(n,t.value))return!0}))},exports.useHotkeys=function(t,n,r,o){var i=e.useRef(null),u=r instanceof Array?o instanceof Array?void 0:o:r,s=e.useCallback(n,[].concat(r instanceof Array?r:o instanceof Array?o:[])),f=function(t){var n=e.useRef(void 0);return v(n.current,t)||(n.current=t),n.current}(u),h=y().enabledScopes,g=e.useContext(d);return m((function(){if(!1!==(null==f?void 0:f.enabled)&&(n=null==f?void 0:f.scopes,0===(e=h).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,r=function(e){var n;l(e,["input","textarea","select"])&&!l(e,null==f?void 0:f.enableOnFormTags)||(null===i.current||document.activeElement===i.current||i.current.contains(document.activeElement)?(null==(n=e.target)||!n.isContentEditable||null!=f&&f.enableOnContentEditable)&&a(t,null==f?void 0:f.splitKey).forEach((function(t){var n,r=c(t,null==f?void 0:f.combinationKey);if(function(e,t,n){var r=t.alt,o=t.meta,i=t.mod,u=t.shift,a=t.keys,c=e.altKey,l=e.ctrlKey,d=e.metaKey,s=e.shiftKey,f=e.key,y=e.code.toLowerCase().replace("key",""),v=f.toLowerCase();if(c!==r&&"alt"!==v)return!1;if(s!==u&&"shift"!==v)return!1;if(i){if(!d&&!l)return!1}else if(d!==o&&l!==o&&"meta"!==y&&"ctrl"!==y)return!1;return!(!a||1!==a.length||!a.includes(v)&&!a.includes(y))||(a?a.every((function(e){return n.has(e)})):!a)}(e,r,k)||null!=(n=r.keys)&&n.includes("*")){if(function(e,t,n){("function"==typeof n&&n(e,t)||!0===n)&&e.preventDefault()}(e,r,null==f?void 0:f.preventDefault),!function(e,t,n){return"function"==typeof n?n(e,t):!0===n||void 0===n}(e,r,null==f?void 0:f.enabled))return void p(e);s(e,r)}})):p(e))},o=function(e){void 0!==e.key&&(k.add(e.key.toLowerCase()),(void 0===(null==f?void 0:f.keydown)&&!0!==(null==f?void 0:f.keyup)||null!=f&&f.keydown)&&r(e))},u=function(e){void 0!==e.key&&("meta"!==e.key.toLowerCase()?k.delete(e.key.toLowerCase()):k.clear(),null!=f&&f.keyup&&r(e))};return(i.current||document).addEventListener("keyup",u),(i.current||document).addEventListener("keydown",o),g&&a(t,null==f?void 0:f.splitKey).forEach((function(e){return g.addHotkey(c(e,null==f?void 0:f.combinationKey))})),function(){(i.current||document).removeEventListener("keyup",u),(i.current||document).removeEventListener("keydown",o),g&&a(t,null==f?void 0:f.splitKey).forEach((function(e){return g.removeHotkey(c(e,null==f?void 0:f.combinationKey))}))}}}),[t,s,f,h]),i},exports.useHotkeysContext=y;
//# sourceMappingURL=react-hotkeys-hook.cjs.production.min.js.map

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

var reservedModifierKeywords = ['ctrl', 'shift', 'alt', 'meta', 'mod'];
var reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod'];
var mappedKeys = {

@@ -89,3 +89,2 @@ esc: 'escape',

alt: keys.includes('alt'),
ctrl: keys.includes('ctrl'),
shift: keys.includes('shift'),

@@ -144,3 +143,2 @@ meta: keys.includes('meta'),

var alt = hotkey.alt,
ctrl = hotkey.ctrl,
meta = hotkey.meta,

@@ -170,8 +168,5 @@ mod = hotkey.mod,

} else {
if (metaKey !== meta && keyCode !== 'meta') {
if (metaKey !== meta && ctrlKey !== meta && keyCode !== 'meta' && keyCode !== 'ctrl') {
return false;
}
if (ctrlKey !== ctrl && keyCode !== 'ctrl') {
return false;
}
}

@@ -178,0 +173,0 @@ // All modifiers are correct, now check the key

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

alt?: boolean;
ctrl?: boolean;
meta?: boolean;

@@ -11,0 +10,0 @@ shift?: boolean;

{
"name": "react-hotkeys-hook",
"version": "4.0.5",
"version": "4.0.6",
"repository": "https://JohannesKlauss@github.com/JohannesKlauss/react-keymap-hook.git",

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

import { Hotkey, KeyboardModifiers, Keys } from './types'
const reservedModifierKeywords = ['ctrl', 'shift', 'alt', 'meta', 'mod']
const reservedModifierKeywords = ['shift', 'alt', 'meta', 'mod']

@@ -40,3 +40,2 @@ const mappedKeys: Record<string, string> = {

alt: keys.includes('alt'),
ctrl: keys.includes('ctrl'),
shift: keys.includes('shift'),

@@ -43,0 +42,0 @@ meta: keys.includes('meta'),

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

alt?: boolean
ctrl?: boolean
meta?: boolean

@@ -14,0 +13,0 @@ shift?: boolean

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

export const isHotkeyMatchingKeyboardEvent = (e: KeyboardEvent, hotkey: Hotkey, pressedDownKeys: Set<string>): boolean => {
const { alt, ctrl, meta, mod, shift, keys } = hotkey
const { alt, meta, mod, shift, keys } = hotkey
const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKeyUppercase, code } = e

@@ -69,9 +69,5 @@

} else {
if (metaKey !== meta && keyCode !== 'meta') {
if (metaKey !== meta && ctrlKey !== meta && keyCode !== 'meta' && keyCode !== 'ctrl') {
return false
}
if (ctrlKey !== ctrl && keyCode !== 'ctrl') {
return false
}
}

@@ -78,0 +74,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

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