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

react-hot-keys

Package Overview
Dependencies
Maintainers
1
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-hot-keys - npm Package Compare versions

Comparing version 1.2.2 to 1.3.0

14

es/index.js

@@ -11,8 +11,2 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

Hotkeys.filter = function (event) {
var tagName = (event.target || event.srcElement).tagName;
Hotkeys.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other');
return true;
};
var ReactHotkeys = function (_Component) {

@@ -35,2 +29,5 @@ _inherits(ReactHotkeys, _Component);

ReactHotkeys.prototype.componentDidMount = function componentDidMount() {
var filter = this.props.filter;
Hotkeys.filter = filter;
Hotkeys.unbind(this.props.keyName);

@@ -83,2 +80,3 @@ Hotkeys(this.props.keyName, this.onKeyDown);

keyName: PropTypes.string,
filter: PropTypes.func,
onKeyDown: PropTypes.func,

@@ -89,4 +87,8 @@ onKeyUp: PropTypes.func

ReactHotkeys.defaultProps = {
filter: function filter(event) {
var tagName = (event.target || event.srcElement).tagName;
return !(tagName.isContentEditable || tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA');
},
onKeyUp: function onKeyUp() {},
onKeyDown: function onKeyDown() {}
};

@@ -26,8 +26,2 @@ 'use strict';

_hotkeysJs2.default.filter = function (event) {
var tagName = (event.target || event.srcElement).tagName;
_hotkeysJs2.default.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other');
return true;
};
var ReactHotkeys = function (_Component) {

@@ -50,2 +44,5 @@ _inherits(ReactHotkeys, _Component);

ReactHotkeys.prototype.componentDidMount = function componentDidMount() {
var filter = this.props.filter;
_hotkeysJs2.default.filter = filter;
_hotkeysJs2.default.unbind(this.props.keyName);

@@ -98,2 +95,3 @@ (0, _hotkeysJs2.default)(this.props.keyName, this.onKeyDown);

keyName: _propTypes2.default.string,
filter: _propTypes2.default.func,
onKeyDown: _propTypes2.default.func,

@@ -104,2 +102,6 @@ onKeyUp: _propTypes2.default.func

ReactHotkeys.defaultProps = {
filter: function filter(event) {
var tagName = (event.target || event.srcElement).tagName;
return !(tagName.isContentEditable || tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA');
},
onKeyUp: function onKeyUp() {},

@@ -106,0 +108,0 @@ onKeyDown: function onKeyDown() {}

{
"name": "react-hot-keys",
"version": "1.2.2",
"version": "1.3.0",
"description": "React component to listen to keydown and keyup keyboard events, defining and dispatching keyboard shortcuts.",

@@ -24,3 +24,3 @@ "author": "kenny wang <wowohoo@qq.com>",

"dependencies": {
"hotkeys-js": "^3.3.8"
"hotkeys-js": "^3.4.4"
},

@@ -27,0 +27,0 @@ "peerDependencies": {

@@ -92,4 +92,19 @@ react-hotkeys

### filter
`INPUT` `SELECT` `TEXTAREA` default does not handle. `filter` to return to the true shortcut keys set to play a role, flase shortcut keys set up failure.
```diff
<Hotkeys
keyName="shift+a,alt+s"
+ filter={(event) => {
+ return true;
+ }}
onKeyDown={this.onKeyDown.bind(this)}
onKeyUp={this.onKeyUp.bind(this)}
/>
```
## License
MIT

@@ -327,6 +327,6 @@ /*!

/*!
* hotkeys-js v3.3.8
* hotkeys-js v3.4.4
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
*
* Copyright (c) 2018 kenny wong <wowohoo@qq.com>
* Copyright (c) 2019 kenny wong <wowohoo@qq.com>
* http://jaywcjlove.github.io/hotkeys

@@ -477,3 +477,3 @@ *

// 表单控件控件判断 返回 Boolean
function filter(event) {
function hotkeys_esm_filter(event) {
var target = event.target || event.srcElement;

@@ -536,3 +536,3 @@ var tagName = target.tagName;

// 解除绑定某个范围的快捷键
function unbind(key, scope) {
function unbind(key, scope, method) {
var multipleKeys = getKeys(key);

@@ -542,2 +542,8 @@ var keys = void 0;

var obj = void 0;
// 通过函数判断,是否解除绑定
// https://github.com/jaywcjlove/hotkeys/issues/44
if (typeof scope === 'function') {
method = scope;
scope = 'all';
}

@@ -565,4 +571,7 @@ for (var i = 0; i < multipleKeys.length; i++) {

obj = _handlers[key][r];
// 通过函数判断,是否解除绑定,函数相等直接返回
var isMatchingMethod = method ? obj.method === method : true;
// 判断是否在范围内并且键值相同
if (obj.scope === scope && compareArray(obj.mods, mods)) {
if (isMatchingMethod && obj.scope === scope && compareArray(obj.mods, mods)) {
_handlers[key][r] = {};

@@ -711,3 +720,3 @@ }

isPressed: isPressed,
filter: filter,
filter: hotkeys_esm_filter,
unbind: unbind

@@ -746,8 +755,2 @@ };

hotkeys_esm.filter = function (event) {
var tagName = (event.target || event.srcElement).tagName;
hotkeys_esm.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(tagName) ? 'input' : 'other');
return true;
};
var src_ReactHotkeys = function (_Component) {

@@ -770,2 +773,5 @@ _inherits(ReactHotkeys, _Component);

ReactHotkeys.prototype.componentDidMount = function componentDidMount() {
var filter = this.props.filter;
hotkeys_esm.filter = filter;
hotkeys_esm.unbind(this.props.keyName);

@@ -818,2 +824,3 @@ hotkeys_esm(this.props.keyName, this.onKeyDown);

keyName: prop_types_default.a.string,
filter: prop_types_default.a.func,
onKeyDown: prop_types_default.a.func,

@@ -824,2 +831,6 @@ onKeyUp: prop_types_default.a.func

src_ReactHotkeys.defaultProps = {
filter: function filter(event) {
var tagName = (event.target || event.srcElement).tagName;
return !(tagName.isContentEditable || tagName == 'INPUT' || tagName == 'SELECT' || tagName == 'TEXTAREA');
},
onKeyUp: function onKeyUp() {},

@@ -826,0 +837,0 @@ onKeyDown: function onKeyDown() {}

@@ -7,10 +7,10 @@ /*!

/*!
* hotkeys-js v3.3.8
* hotkeys-js v3.4.4
* A simple micro-library for defining and dispatching keyboard shortcuts. It has no dependencies.
*
* Copyright (c) 2018 kenny wong <wowohoo@qq.com>
* Copyright (c) 2019 kenny wong <wowohoo@qq.com>
* http://jaywcjlove.github.io/hotkeys
*
* Licensed under the MIT license.
*/function i(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,function(){n(window.event)})}function a(e,t){for(var n=t.slice(0,t.length-1),o=0;o<n.length;o++)n[o]=e[n[o].toLowerCase()];return n}function c(e){e||(e="");for(var t=(e=e.replace(/\s/g,"")).split(","),n=t.lastIndexOf("");n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function s(e,t){for(var n=e.length>=t.length?e:t,o=e.length>=t.length?t:e,r=!0,i=0;i<n.length;i++)-1===o.indexOf(n[i])&&(r=!1);return r}for(var f={backspace:8,tab:9,clear:12,enter:13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,"⇪":20,",":188,".":190,"/":191,"`":192,"-":r?173:189,"=":r?61:187,";":r?59:186,"'":222,"[":219,"]":221,"\\":220},u={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":r?224:91,cmd:r?224:91,command:r?224:91},p=[],l={16:"shiftKey",18:"altKey",17:"ctrlKey"},d={16:!1,18:!1,17:!1},h={},y=1;y<20;y++)f["f"+y]=111+y;l[r?224:91]="metaKey",d[r?224:91]=!1;var v="all",w=!1,b=function(e){return f[e.toLowerCase()]||u[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)};function g(e){v=e||"all"}function m(){return v||"all"}function O(e,t,n){var o=void 0;if(t.scope===n||"all"===t.scope){for(var r in o=t.mods.length>0,d)Object.prototype.hasOwnProperty.call(d,r)&&(!d[r]&&t.mods.indexOf(+r)>-1||d[r]&&-1===t.mods.indexOf(+r))&&(o=!1);(0!==t.mods.length||d[16]||d[18]||d[17]||d[91])&&!o&&"*"!==t.shortcut||!1===t.method(e,t)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0))}}function K(e,t,n){var o=c(e),r=[],s="all",f=document,y=0;for(void 0===n&&"function"==typeof t&&(n=t),"[object Object]"===Object.prototype.toString.call(t)&&(t.scope&&(s=t.scope),t.element&&(f=t.element)),"string"==typeof t&&(s=t);y<o.length;y++)r=[],(e=o[y].split("+")).length>1&&(r=a(u,e)),(e="*"===(e=e[e.length-1])?"*":b(e))in h||(h[e]=[]),h[e].push({scope:s,mods:r,shortcut:o[y],method:n,key:o[y]});void 0===f||w||(w=!0,i(f,"keydown",function(e){!function(e){var t=h["*"],n=e.keyCode||e.which||e.charCode;if(-1===p.indexOf(n)&&p.push(n),93!==n&&224!==n||(n=91),n in d){for(var o in d[n]=!0,u)u[o]===n&&(K[o]=!0);if(!t)return}for(var r in d)Object.prototype.hasOwnProperty.call(d,r)&&(d[r]=e[l[r]]);if(K.filter.call(this,e)){var i=m();if(t)for(var a=0;a<t.length;a++)t[a].scope===i&&O(e,t[a],i);if(n in h)for(var c=0;c<h[n].length;c++)O(e,h[n][c],i)}}(e)}),i(f,"keyup",function(e){!function(e){var t=e.keyCode||e.which||e.charCode,n=p.indexOf(t);if(n>=0&&p.splice(n,1),93!==t&&224!==t||(t=91),t in d)for(var o in d[t]=!1,u)u[o]===t&&(K[o]=!1)}(e)}))}var E={setScope:g,getScope:m,deleteScope:function(e,t){var n=void 0,o=void 0;for(var r in e||(e=m()),h)if(Object.prototype.hasOwnProperty.call(h,r))for(n=h[r],o=0;o<n.length;)n[o].scope===e?n.splice(o,1):o++;m()===e&&g(t||"all")},getPressedKeyCodes:function(){return p.slice(0)},isPressed:function(e){return"string"==typeof e&&(e=b(e)),-1!==p.indexOf(e)},filter:function(e){var t=e.target||e.srcElement,n=t.tagName;return!("INPUT"===n||"SELECT"===n||"TEXTAREA"===n||t.isContentEditable)},unbind:function(e,t){for(var n=c(e),o=void 0,r=[],i=void 0,f=0;f<n.length;f++){if((o=n[f].split("+")).length>1&&(r=a(u,o)),e="*"===(e=o[o.length-1])?"*":b(e),t||(t=m()),!h[e])return;for(var p=0;p<h[e].length;p++)(i=h[e][p]).scope===t&&s(i.mods,r)&&(h[e][p]={})}}};for(var x in E)Object.prototype.hasOwnProperty.call(E,x)&&(K[x]=E[x]);if("undefined"!=typeof window){var j=window.hotkeys;K.noConflict=function(e){return e&&window.hotkeys===K&&(window.hotkeys=j),K},window.hotkeys=K}var k=K;n.d(t,"default",function(){return P}),k.filter=function(e){var t=(e.target||e.srcElement).tagName;return k.setScope(/^(INPUT|TEXTAREA|SELECT)$/.test(t)?"input":"other"),!0};var P=function(e){function t(n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var o=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.call(this,n));return o.onKeyDown=o.onKeyDown.bind(o),o.onKeyUp=o.onKeyUp.bind(o),o.handleKeyUpEvent=o.handleKeyUpEvent.bind(o),o.isKeyDown=!1,o.handle={},o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t.prototype.componentDidMount=function(){k.unbind(this.props.keyName),k(this.props.keyName,this.onKeyDown),document.addEventListener("keyup",this.handleKeyUpEvent)},t.prototype.componentWillUnmount=function(){k.unbind(this.props.keyName),this.isKeyDown=!0,this.handle={},document.removeEventListener("keyup",this.handleKeyUpEvent)},t.prototype.onKeyUp=function(e,t){var n=this.props.onKeyUp;n(t.shortcut,e,t)},t.prototype.onKeyDown=function(e,t){var n=this.props.onKeyDown;this.isKeyDown||(this.isKeyDown=!0,this.handle=t,n(t.shortcut,e,t))},t.prototype.handleKeyUpEvent=function(e){this.isKeyDown&&(this.isKeyDown=!1,this.props.keyName.indexOf(this.handle.shortcut)<0||(this.onKeyUp(e,this.handle),this.handle={}))},t.prototype.render=function(){return this.props.children||null},t}(o.Component);P.defaultProps={onKeyUp:function(){},onKeyDown:function(){}}}]).default});
*/function i(e,t,n){e.addEventListener?e.addEventListener(t,n,!1):e.attachEvent&&e.attachEvent("on"+t,function(){n(window.event)})}function a(e,t){for(var n=t.slice(0,t.length-1),o=0;o<n.length;o++)n[o]=e[n[o].toLowerCase()];return n}function c(e){e||(e="");for(var t=(e=e.replace(/\s/g,"")).split(","),n=t.lastIndexOf("");n>=0;)t[n-1]+=",",t.splice(n,1),n=t.lastIndexOf("");return t}function f(e,t){for(var n=e.length>=t.length?e:t,o=e.length>=t.length?t:e,r=!0,i=0;i<n.length;i++)-1===o.indexOf(n[i])&&(r=!1);return r}for(var s={backspace:8,tab:9,clear:12,enter:13,return:13,esc:27,escape:27,space:32,left:37,up:38,right:39,down:40,del:46,delete:46,ins:45,insert:45,home:36,end:35,pageup:33,pagedown:34,capslock:20,"⇪":20,",":188,".":190,"/":191,"`":192,"-":r?173:189,"=":r?61:187,";":r?59:186,"'":222,"[":219,"]":221,"\\":220},u={"⇧":16,shift:16,"⌥":18,alt:18,option:18,"⌃":17,ctrl:17,control:17,"⌘":r?224:91,cmd:r?224:91,command:r?224:91},l=[],p={16:"shiftKey",18:"altKey",17:"ctrlKey"},d={16:!1,18:!1,17:!1},h={},y=1;y<20;y++)s["f"+y]=111+y;p[r?224:91]="metaKey",d[r?224:91]=!1;var v="all",b=!1,w=function(e){return s[e.toLowerCase()]||u[e.toLowerCase()]||e.toUpperCase().charCodeAt(0)};function g(e){v=e||"all"}function m(){return v||"all"}function O(e,t,n){var o=void 0;if(t.scope===n||"all"===t.scope){for(var r in o=t.mods.length>0,d)Object.prototype.hasOwnProperty.call(d,r)&&(!d[r]&&t.mods.indexOf(+r)>-1||d[r]&&-1===t.mods.indexOf(+r))&&(o=!1);(0!==t.mods.length||d[16]||d[18]||d[17]||d[91])&&!o&&"*"!==t.shortcut||!1===t.method(e,t)&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0))}}function K(e,t,n){var o=c(e),r=[],f="all",s=document,y=0;for(void 0===n&&"function"==typeof t&&(n=t),"[object Object]"===Object.prototype.toString.call(t)&&(t.scope&&(f=t.scope),t.element&&(s=t.element)),"string"==typeof t&&(f=t);y<o.length;y++)r=[],(e=o[y].split("+")).length>1&&(r=a(u,e)),(e="*"===(e=e[e.length-1])?"*":w(e))in h||(h[e]=[]),h[e].push({scope:f,mods:r,shortcut:o[y],method:n,key:o[y]});void 0===s||b||(b=!0,i(s,"keydown",function(e){!function(e){var t=h["*"],n=e.keyCode||e.which||e.charCode;if(-1===l.indexOf(n)&&l.push(n),93!==n&&224!==n||(n=91),n in d){for(var o in d[n]=!0,u)u[o]===n&&(K[o]=!0);if(!t)return}for(var r in d)Object.prototype.hasOwnProperty.call(d,r)&&(d[r]=e[p[r]]);if(K.filter.call(this,e)){var i=m();if(t)for(var a=0;a<t.length;a++)t[a].scope===i&&O(e,t[a],i);if(n in h)for(var c=0;c<h[n].length;c++)O(e,h[n][c],i)}}(e)}),i(s,"keyup",function(e){!function(e){var t=e.keyCode||e.which||e.charCode,n=l.indexOf(t);if(n>=0&&l.splice(n,1),93!==t&&224!==t||(t=91),t in d)for(var o in d[t]=!1,u)u[o]===t&&(K[o]=!1)}(e)}))}var E={setScope:g,getScope:m,deleteScope:function(e,t){var n=void 0,o=void 0;for(var r in e||(e=m()),h)if(Object.prototype.hasOwnProperty.call(h,r))for(n=h[r],o=0;o<n.length;)n[o].scope===e?n.splice(o,1):o++;m()===e&&g(t||"all")},getPressedKeyCodes:function(){return l.slice(0)},isPressed:function(e){return"string"==typeof e&&(e=w(e)),-1!==l.indexOf(e)},filter:function(e){var t=e.target||e.srcElement,n=t.tagName;return!("INPUT"===n||"SELECT"===n||"TEXTAREA"===n||t.isContentEditable)},unbind:function(e,t,n){var o=c(e),r=void 0,i=[],s=void 0;"function"==typeof t&&(n=t,t="all");for(var l=0;l<o.length;l++){if((r=o[l].split("+")).length>1&&(i=a(u,r)),e="*"===(e=r[r.length-1])?"*":w(e),t||(t=m()),!h[e])return;for(var p=0;p<h[e].length;p++)s=h[e][p],(!n||s.method===n)&&s.scope===t&&f(s.mods,i)&&(h[e][p]={})}}};for(var x in E)Object.prototype.hasOwnProperty.call(E,x)&&(K[x]=E[x]);if("undefined"!=typeof window){var j=window.hotkeys;K.noConflict=function(e){return e&&window.hotkeys===K&&(window.hotkeys=j),K},window.hotkeys=K}var k=K;n.d(t,"default",function(){return C});var C=function(e){function t(n){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t);var o=function(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}(this,e.call(this,n));return o.onKeyDown=o.onKeyDown.bind(o),o.onKeyUp=o.onKeyUp.bind(o),o.handleKeyUpEvent=o.handleKeyUpEvent.bind(o),o.isKeyDown=!1,o.handle={},o}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}(t,e),t.prototype.componentDidMount=function(){var e=this.props.filter;k.filter=e,k.unbind(this.props.keyName),k(this.props.keyName,this.onKeyDown),document.addEventListener("keyup",this.handleKeyUpEvent)},t.prototype.componentWillUnmount=function(){k.unbind(this.props.keyName),this.isKeyDown=!0,this.handle={},document.removeEventListener("keyup",this.handleKeyUpEvent)},t.prototype.onKeyUp=function(e,t){var n=this.props.onKeyUp;n(t.shortcut,e,t)},t.prototype.onKeyDown=function(e,t){var n=this.props.onKeyDown;this.isKeyDown||(this.isKeyDown=!0,this.handle=t,n(t.shortcut,e,t))},t.prototype.handleKeyUpEvent=function(e){this.isKeyDown&&(this.isKeyDown=!1,this.props.keyName.indexOf(this.handle.shortcut)<0||(this.onKeyUp(e,this.handle),this.handle={}))},t.prototype.render=function(){return this.props.children||null},t}(o.Component);C.defaultProps={filter:function(e){var t=(e.target||e.srcElement).tagName;return!(t.isContentEditable||"INPUT"==t||"SELECT"==t||"TEXTAREA"==t)},onKeyUp:function(){},onKeyDown:function(){}}}]).default});
//# sourceMappingURL=react-hot-keys.min.js.map

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