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

react-shortcuts

Package Overview
Dependencies
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-shortcuts - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

component/index.js

50

lib/component/shortcuts.js

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

if (event.timeStamp === _this._lastTimestamp) {
return;
}
_this._lastTimestamp = event.timeStamp;
if (e.target !== _reactDom2.default.findDOMNode(_this) && e.target !== targetNode) {

@@ -98,4 +92,9 @@ _this._combokeys.handleKey(character, modifiers, event, true);

_this._combokeys.handleKey = function (character, modifiers, event, customEvent) {
if (!customEvent) {
_this._combokeys.handleKey = function (character, modifiers, event, isGlobalHandler) {
if (event.timeStamp === _this._lastTimestamp) {
return;
}
_this._lastTimestamp = event.timeStamp;
if (!isGlobalHandler) {
element.dispatchEvent(new CustomEvent('shortcuts:global', {

@@ -108,17 +107,36 @@ detail: { character: character, modifiers: modifiers, event: event },

if (_this.props.preventDefault) {
event.preventDefault();
// NOTE: works normally if it's not a React event
if (!_this._isReactEvent(event)) {
if (_this.props.preventDefault) {
event.preventDefault();
}
if (_this.props.stopPropagation && !isGlobalHandler) {
event.stopPropagation();
}
originalHandleKey(character, modifiers, event);
return;
}
if (_this.props.stopPropagation && !customEvent) {
event.stopPropagation();
// NOTE: global shortcuts should work even if it's a React event
if (_this.props.global) {
originalHandleKey(character, modifiers, event);
}
};
}, _this._isReactEvent = function (event) {
var result = false;
if (event && event.target && event.target._reactInternalComponent && event.target._reactInternalComponent._currentElement && event.target._reactInternalComponent._currentElement.props) {
var props = event.target._reactInternalComponent._currentElement.props;
originalHandleKey(character, modifiers, event);
};
if (props.onKeyDown || props.onKeyPress || props.onKeyUp) {
result = true;
}
}
return result;
}, _this._getElementToBind = function () {
var element = null;
if (_this.props.targetNodeSelector) {
var element = document.querySelector(_this.props.targetNodeSelector);
element = document.querySelector(_this.props.targetNodeSelector);
(0, _invariant2.default)(element, 'Node selector \'' + _this.props.targetNodeSelector + '\' was not found.');
} else {
var element = _reactDom2.default.findDOMNode(_this);
element = _reactDom2.default.findDOMNode(_this);
}

@@ -125,0 +143,0 @@

{
"name": "react-shortcuts",
"description": "React shortcuts",
"version": "1.0.2",
"version": "1.0.3",
"license": "MIT",

@@ -6,0 +6,0 @@ "main": "./lib/",

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