react-shortcuts
Advanced tools
Comparing version 1.0.2 to 1.0.3
@@ -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/", |
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
32810
14
569