react-hotkeys-hook
Advanced tools
Comparing version 4.0.4-4 to 4.0.4-5
'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var react = require('react'); | ||
var jsxRuntime = require('react/jsx-runtime'); | ||
var isEqual = _interopDefault(require('lodash.isEqual')); | ||
@@ -275,5 +272,14 @@ function _extends() { | ||
function deepEqual(x, y) { | ||
//@ts-ignore | ||
return x && y && typeof x === 'object' && typeof y === 'object' | ||
//@ts-ignore | ||
? Object.keys(x).length === Object.keys(y).length && Object.keys(x).reduce(function (isEqual, key) { | ||
return isEqual && deepEqual(x[key], y[key]); | ||
}, true) : x === y; | ||
} | ||
function useDeepEqualMemo(value) { | ||
var ref = react.useRef(undefined); | ||
if (!isEqual(ref.current, value)) { | ||
if (!deepEqual(ref.current, value)) { | ||
ref.current = value; | ||
@@ -383,3 +389,3 @@ } | ||
var pressedHotkey = _step.value; | ||
if (isEqual(parsedHotkey, pressedHotkey)) { | ||
if (deepEqual(parsedHotkey, pressedHotkey)) { | ||
return true; | ||
@@ -386,0 +392,0 @@ } |
@@ -1,2 +0,2 @@ | ||
"use strict";var e,n=require("react"),t=require("react/jsx-runtime"),r=(e=require("lodash.isEqual"))&&"object"==typeof e&&"default"in e?e.default:e;function o(){return(o=Object.assign?Object.assign.bind():function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e}).apply(this,arguments)}function i(e,n){(null==n||n>e.length)&&(n=e.length);for(var t=0,r=new Array(n);t<n;t++)r[t]=e[t];return r}function u(e,n){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,n){if(e){if("string"==typeof e)return i(e,void 0);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?i(e,void 0):void 0}}(e))||n&&e&&"number"==typeof e.length){t&&(e=t);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[r++]}}}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 a=["ctrl","shift","alt","meta","mod"],c={esc:"escape",return:"enter",left:"arrowleft",up:"arrowup",right:"arrowright",down:"arrowdown"};function l(e,n){return void 0===n&&(n=","),"string"==typeof e?e.split(n):e}function s(e,n){void 0===n&&(n="+");var t=e.toLocaleLowerCase().split(n).map((function(e){return e.trim()})).map((function(e){return c[e]||e}));return o({},{alt:t.includes("alt"),ctrl:t.includes("ctrl"),shift:t.includes("shift"),meta:t.includes("meta"),mod:t.includes("mod")},{keys:t.filter((function(e){return!a.includes(e)}))})}function d(e,n){var t=e.target;void 0===n&&(n=!1);var r=t&&t.tagName;return n instanceof Array?Boolean(r&&n&&n.some((function(e){return e.toLowerCase()===r.toLowerCase()}))):Boolean(r&&n&&!0===n)}var f=n.createContext(void 0);function y(e){return t.jsx(f.Provider,{value:{addHotkey:e.addHotkey,removeHotkey:e.removeHotkey},children:e.children})}var v=n.createContext({hotkeys:[],enabledScopes:[],toggleScope:function(){},enableScope:function(){},disableScope:function(){}}),p=function(){return n.useContext(v)},m=function(e){e.stopPropagation(),e.preventDefault(),e.stopImmediatePropagation()},h="undefined"!=typeof window?n.useLayoutEffect:n.useEffect,k=new Set;"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",(function(){document.addEventListener("keydown",(function(e){var n;n=e.key,(Array.isArray(n)?n:[n]).forEach((function(e){return k.add(s(e))}))})),document.addEventListener("keyup",(function(e){var n;n=e.key,(Array.isArray(n)?n:[n]).forEach((function(e){for(var n,t=s(e),r=u(k);!(n=r()).done;){var o,i=n.value;null!=(o=i.keys)&&o.every((function(e){var n;return null==(n=t.keys)?void 0:n.includes(e)}))&&k.delete(i)}}))}))})),exports.HotkeysProvider=function(e){var r=e.initiallyActiveScopes,o=void 0===r?["*"]:r,i=e.children,u=n.useState((null==o?void 0:o.length)>0?o:["*"]),a=u[0],c=u[1],l=n.useState([]),s=l[0],d=l[1],f=n.useMemo((function(){return a.includes("*")}),[a]),p=function(e){c(f?[e]:Array.from(new Set([].concat(a,[e]))))},m=function(e){var n=a.filter((function(n){return n!==e}));c(0===n.length?["*"]:n)};return t.jsx(v.Provider,{value:{enabledScopes:a,hotkeys:s,enableScope:p,disableScope:m,toggleScope:function(e){a.includes(e)?m(e):p(e)}},children:t.jsx(y,{addHotkey:function(e){d([].concat(s,[e]))},removeHotkey:function(e){d(s.filter((function(n){return n.keys!==e.keys})))},children:i})})},exports.isHotkeyPressed=function(e,n){return void 0===n&&(n=","),(Array.isArray(e)?e:e.split(n)).every((function(e){for(var n,t=s(e),o=u(k);!(n=o()).done;)if(r(t,n.value))return!0}))},exports.useHotkeys=function(e,t,o,i){var u=n.useRef(null),a=n.useRef(new Set).current,c=o instanceof Array?i instanceof Array?void 0:i:o,y=n.useCallback(t,[].concat(o instanceof Array?o:i instanceof Array?i:[])),v=function(e){var t=n.useRef(void 0);return r(t.current,e)||(t.current=e),t.current}(c),k=p().enabledScopes,w=n.useContext(f);return h((function(){if(!1!==(null==v?void 0:v.enabled)&&(t=null==v?void 0:v.scopes,0===(n=k).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||n.some((function(e){return t.includes(e)}))||n.includes("*"))){var n,t,r=function(n){var t;d(n,["input","textarea","select"])&&!d(n,null==v?void 0:v.enableOnFormTags)||(null===u.current||document.activeElement===u.current||u.current.contains(document.activeElement)?(null==(t=n.target)||!t.isContentEditable||null!=v&&v.enableOnContentEditable)&&l(e,null==v?void 0:v.splitKey).forEach((function(e){var t,r=s(e,null==v?void 0:v.combinationKey);if(function(e,n,t){var r=n.alt,o=n.ctrl,i=n.meta,u=n.mod,a=n.shift,c=n.keys,l=e.altKey,s=e.ctrlKey,d=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(!d&&!s)return!1}else{if(d!==i&&"meta"!==v)return!1;if(s!==o&&"ctrl"!==v)return!1}return!(!c||1!==c.length||!c.includes(p)&&!c.includes(v))||(c?c.every((function(e){return t.has(e)})):!c)}(n,r,a)||null!=(t=r.keys)&&t.includes("*")){if(function(e,n,t){("function"==typeof t&&t(e,n)||!0===t)&&e.preventDefault()}(n,r,null==v?void 0:v.preventDefault),!function(e,n,t){return"function"==typeof t?t(e,n):!0===t||void 0===t}(n,r,null==v?void 0:v.enabled))return void m(n);y(n,r)}})):m(n))},o=function(e){a.add(e.key.toLowerCase()),(void 0===(null==v?void 0:v.keydown)&&!0!==(null==v?void 0:v.keyup)||null!=v&&v.keydown)&&r(e)},i=function(e){"meta"!==e.key.toLowerCase()?a.delete(e.key.toLowerCase()):a.clear(),null!=v&&v.keyup&&r(e)};return(u.current||document).addEventListener("keyup",i),(u.current||document).addEventListener("keydown",o),w&&l(e,null==v?void 0:v.splitKey).forEach((function(e){return w.addHotkey(s(e,null==v?void 0:v.combinationKey))})),function(){(u.current||document).removeEventListener("keyup",i),(u.current||document).removeEventListener("keydown",o),w&&l(e,null==v?void 0:v.splitKey).forEach((function(e){return w.removeHotkey(s(e,null==v?void 0:v.combinationKey))}))}}}),[e,y,v,k]),u},exports.useHotkeysContext=p; | ||
"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"};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 s=e.createContext(void 0);function d(e){return t.jsx(s.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;"undefined"!=typeof window&&window.addEventListener("DOMContentLoaded",(function(){document.addEventListener("keydown",(function(e){var t;t=e.key,(Array.isArray(t)?t:[t]).forEach((function(e){return k.add(c(e))}))})),document.addEventListener("keyup",(function(e){var t;t=e.key,(Array.isArray(t)?t:[t]).forEach((function(e){for(var t,n=c(e),r=o(k);!(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)}))&&k.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([]),s=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:s,enableScope:p,disableScope:m,toggleScope:function(e){a.includes(e)?m(e):p(e)}},children:t.jsx(d,{addHotkey:function(e){y([].concat(s,[e]))},removeHotkey:function(e){y(s.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(k);!(t=r()).done;)if(v(n,t.value))return!0}))},exports.useHotkeys=function(t,n,r,o){var i=e.useRef(null),u=e.useRef(new Set).current,d=r instanceof Array?o instanceof Array?void 0:o:r,f=e.useCallback(n,[].concat(r instanceof Array?r:o instanceof Array?o:[])),k=function(t){var n=e.useRef(void 0);return v(n.current,t)||(n.current=t),n.current}(d),h=y().enabledScopes,b=e.useContext(s);return m((function(){if(!1!==(null==k?void 0:k.enabled)&&(n=null==k?void 0:k.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==k?void 0:k.enableOnFormTags)||(null===i.current||document.activeElement===i.current||i.current.contains(document.activeElement)?(null==(n=e.target)||!n.isContentEditable||null!=k&&k.enableOnContentEditable)&&a(t,null==k?void 0:k.splitKey).forEach((function(t){var n,r=c(t,null==k?void 0:k.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,s=e.ctrlKey,d=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(!d&&!s)return!1}else{if(d!==i&&"meta"!==v)return!1;if(s!==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,u)||null!=(n=r.keys)&&n.includes("*")){if(function(e,t,n){("function"==typeof n&&n(e,t)||!0===n)&&e.preventDefault()}(e,r,null==k?void 0:k.preventDefault),!function(e,t,n){return"function"==typeof n?n(e,t):!0===n||void 0===n}(e,r,null==k?void 0:k.enabled))return void p(e);f(e,r)}})):p(e))},o=function(e){u.add(e.key.toLowerCase()),(void 0===(null==k?void 0:k.keydown)&&!0!==(null==k?void 0:k.keyup)||null!=k&&k.keydown)&&r(e)},s=function(e){"meta"!==e.key.toLowerCase()?u.delete(e.key.toLowerCase()):u.clear(),null!=k&&k.keyup&&r(e)};return(i.current||document).addEventListener("keyup",s),(i.current||document).addEventListener("keydown",o),b&&a(t,null==k?void 0:k.splitKey).forEach((function(e){return b.addHotkey(c(e,null==k?void 0:k.combinationKey))})),function(){(i.current||document).removeEventListener("keyup",s),(i.current||document).removeEventListener("keydown",o),b&&a(t,null==k?void 0:k.splitKey).forEach((function(e){return b.removeHotkey(c(e,null==k?void 0:k.combinationKey))}))}}}),[t,f,k,h]),i},exports.useHotkeysContext=y; | ||
//# sourceMappingURL=react-hotkeys-hook.cjs.production.min.js.map |
import { useContext, createContext, useState, useMemo, useRef, useCallback, useLayoutEffect, useEffect } from 'react'; | ||
import { jsx } from 'react/jsx-runtime'; | ||
import isEqual from 'lodash.isEqual'; | ||
@@ -271,5 +270,14 @@ function _extends() { | ||
function deepEqual(x, y) { | ||
//@ts-ignore | ||
return x && y && typeof x === 'object' && typeof y === 'object' | ||
//@ts-ignore | ||
? Object.keys(x).length === Object.keys(y).length && Object.keys(x).reduce(function (isEqual, key) { | ||
return isEqual && deepEqual(x[key], y[key]); | ||
}, true) : x === y; | ||
} | ||
function useDeepEqualMemo(value) { | ||
var ref = useRef(undefined); | ||
if (!isEqual(ref.current, value)) { | ||
if (!deepEqual(ref.current, value)) { | ||
ref.current = value; | ||
@@ -379,3 +387,3 @@ } | ||
var pressedHotkey = _step.value; | ||
if (isEqual(parsedHotkey, pressedHotkey)) { | ||
if (deepEqual(parsedHotkey, pressedHotkey)) { | ||
return true; | ||
@@ -382,0 +390,0 @@ } |
{ | ||
"name": "react-hotkeys-hook", | ||
"version": "4.0.4-4", | ||
"version": "4.0.4-5", | ||
"repository": "https://JohannesKlauss@github.com/JohannesKlauss/react-keymap-hook.git", | ||
@@ -57,3 +57,2 @@ "homepage": "https://johannesklauss.github.io/react-hotkeys-hook/", | ||
"@types/jest": "29.2.2", | ||
"@types/lodash.isequal": "4.5.6", | ||
"@types/react": "18.0.15", | ||
@@ -72,5 +71,2 @@ "@types/react-dom": "18.0.6", | ||
}, | ||
"dependencies": { | ||
"lodash.isequal": "4.5.0" | ||
}, | ||
"peerDependencies": { | ||
@@ -77,0 +73,0 @@ "react": ">=16.8.1", |
import { Hotkey } from './types' | ||
import { parseHotkey } from './parseHotkeys' | ||
import isEqual from 'lodash.isEqual' | ||
import deepEqual from './deepEqual' | ||
@@ -14,3 +14,3 @@ const currentlyPressedKeys: Set<Hotkey> = new Set<Hotkey>() | ||
for (const pressedHotkey of currentlyPressedKeys) { | ||
if (isEqual(parsedHotkey, pressedHotkey)) { | ||
if (deepEqual(parsedHotkey, pressedHotkey)) { | ||
return true | ||
@@ -17,0 +17,0 @@ } |
import { useRef } from 'react' | ||
import isEqual from 'lodash.isEqual' | ||
import deepEqual from './deepEqual' | ||
@@ -7,3 +7,3 @@ export default function useDeepEqualMemo<T>(value: T) { | ||
if (!isEqual(ref.current, value)) { | ||
if (!deepEqual(ref.current, value)) { | ||
ref.current = value | ||
@@ -10,0 +10,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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
159059
2
23
32
1351
0
- Removedlodash.isequal@4.5.0
- Removedlodash.isequal@4.5.0(transitive)