Socket
Socket
Sign inDemoInstall

react-hotkeys

Package Overview
Dependencies
6
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 2.0.0-pre9 to 2.0.0

cjs/const/KeyEventState.js

2

cjs/configure.js

@@ -8,3 +8,3 @@ "use strict";

var _Configuration = _interopRequireDefault(require("./lib/Configuration"));
var _Configuration = _interopRequireDefault(require("./lib/config/Configuration"));

@@ -11,0 +11,0 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -9,3 +9,3 @@ "use strict";

/**
* @typedef {Number} EventResponseType
* @typedef {number} EventResponseType
*/

@@ -12,0 +12,0 @@

@@ -9,5 +9,5 @@ "use strict";

/**
* Enum for index values for KeyEventRecords
* Enum for index values for KeyEvents
* @readonly
* @enum {Number}
* @enum {number}
*/

@@ -14,0 +14,0 @@ var KeyEventSequenceIndex = {

@@ -12,3 +12,3 @@ "use strict";

var _Configuration = _interopRequireDefault(require("./lib/Configuration"));
var _Configuration = _interopRequireDefault(require("./lib/config/Configuration"));

@@ -143,3 +143,3 @@ var _KeyEventManager = _interopRequireDefault(require("./lib/KeyEventManager"));

* A map from action names to event handler functions
* @typedef {Object<ActionName, Function>} HandlersMap
* @typedef {Object.<ActionName, Function>} HandlersMap
*/

@@ -146,0 +146,0 @@

@@ -12,4 +12,4 @@ "use strict";

function describeKeyEvent(event, keyName, keyEventRecordIndex) {
var eventDescription = "'".concat(keyName, "' ").concat((0, _describeKeyEventType.default)(keyEventRecordIndex));
function describeKeyEvent(event, keyName, keyEventType) {
var eventDescription = "'".concat(keyName, "' ").concat((0, _describeKeyEventType.default)(keyEventType));

@@ -16,0 +16,0 @@ if (event.simulated) {

@@ -10,7 +10,7 @@ "use strict";

* Returns the name of the event at a specified event record index
* @param {KeyEventRecordIndex} eventRecordIndex
* @param {KeyEventType} keyEventType
* @returns {KeyEventName} Name of the key event
*/
function describeKeyEventType(eventRecordIndex) {
switch (parseInt(eventRecordIndex, 10)) {
function describeKeyEventType(keyEventType) {
switch (parseInt(keyEventType, 10)) {
case 0:

@@ -17,0 +17,0 @@ return 'keydown';

@@ -8,3 +8,3 @@ "use strict";

var _Configuration = _interopRequireDefault(require("../../lib/Configuration"));
var _Configuration = _interopRequireDefault(require("../../lib/config/Configuration"));

@@ -16,3 +16,3 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

* @param {ReactKeyName} keyName Name of the key
* @return {Boolean} true if keyName matches a custom key name
* @returns {boolean} true if keyName matches a custom key name
*/

@@ -19,0 +19,0 @@ function isCustomKeyName(keyName) {

@@ -15,7 +15,7 @@ "use strict";

/**
* @typedef {String} KeyName Name of the keyboard key
* @typedef {string} KeyName Name of the keyboard key
*/
/**
* @typedef {String} ReactKeyName Name used by React to refer to key
* @typedef {string} ReactKeyName Name used by React to refer to key
*/

@@ -22,0 +22,0 @@

@@ -10,3 +10,3 @@ "use strict";

var _Configuration = _interopRequireDefault(require("../../lib/Configuration"));
var _Configuration = _interopRequireDefault(require("../../lib/config/Configuration"));

@@ -19,3 +19,3 @@ var _hasKey = _interopRequireDefault(require("../../utils/object/hasKey"));

* Lowercased string representing a particular keyboard key
* @typedef {String} NormalizedKeyName
* @typedef {string} NormalizedKeyName
*/

@@ -22,0 +22,0 @@

@@ -15,3 +15,3 @@ "use strict";

* @param {NormalizedKeyName} keyName Name of the key
* @returns {Boolean} Whether the key has a native keypress event
* @returns {boolean} Whether the key has a native keypress event
*/

@@ -18,0 +18,0 @@ function hasKeyPressEvent(keyName) {

@@ -16,3 +16,3 @@ "use strict";

* @param {FocusTreeId} focusTreeId The focus tree id for the component
* @returns {Boolean} Whether the HotKeys component is focus-only
* @returns {boolean} Whether the HotKeys component is focus-only
*/

@@ -19,0 +19,0 @@ function isFromFocusOnlyComponent(focusTreeId) {

@@ -8,3 +8,3 @@ "use strict";

var _KeysWithKeyupHiddenByCmd = _interopRequireDefault(require("../../const/KeysWithKeyupHiddenByCmd"));
var _KeysWithKeyUpHiddenByCmd = _interopRequireDefault(require("../../const/KeysWithKeyUpHiddenByCmd"));

@@ -19,6 +19,6 @@ var _hasKey = _interopRequireDefault(require("../../utils/object/hasKey"));

* @param {NormalizedKeyName} keyName Name of the key
* @returns {Boolean} Whether the key has its keyup event hidden by cmd
* @returns {boolean} Whether the key has its keyup event hidden by cmd
*/
function keyupIsHiddenByCmd(keyName) {
return keyName.length === 1 || (0, _hasKey.default)(_KeysWithKeyupHiddenByCmd.default, keyName);
return keyName.length === 1 || (0, _hasKey.default)(_KeysWithKeyUpHiddenByCmd.default, keyName);
}

@@ -25,0 +25,0 @@

@@ -12,3 +12,3 @@ "use strict";

var _Configuration = _interopRequireDefault(require("./lib/Configuration"));
var _Configuration = _interopRequireDefault(require("./lib/config/Configuration"));

@@ -15,0 +15,0 @@ var _withHotKeys = _interopRequireDefault(require("./withHotKeys"));

@@ -10,3 +10,3 @@ "use strict";

var _Configuration = _interopRequireDefault(require("./lib/Configuration"));
var _Configuration = _interopRequireDefault(require("./lib/config/Configuration"));

@@ -13,0 +13,0 @@ var _withHotKeysIgnoreOverride = _interopRequireDefault(require("./withHotKeysIgnoreOverride"));

@@ -8,3 +8,3 @@ "use strict";

var _Logger = _interopRequireDefault(require("./Logger"));
var _Logger = _interopRequireDefault(require("./logging/Logger"));

@@ -17,3 +17,3 @@ var _FocusOnlyKeyEventStrategy = _interopRequireDefault(require("./strategies/FocusOnlyKeyEventStrategy"));

var _Configuration = _interopRequireDefault(require("./Configuration"));
var _Configuration = _interopRequireDefault(require("./config/Configuration"));

@@ -185,7 +185,7 @@ var _EventResponse = _interopRequireDefault(require("../const/EventResponse"));

this._focusOnlyEventStrategy.resetKeyCombinationHistory({
this._focusOnlyEventStrategy.resetKeyHistory({
force: true
});
this._globalEventStrategy.resetKeyCombinationHistory({
this._globalEventStrategy.resetKeyHistory({
force: true

@@ -313,3 +313,3 @@ });

* @param {ComponentId} componentId - Index of component that is blurring
* @returns {Boolean} Whether the component still has event propagation yet to handle
* @returns {boolean} Whether the component still has event propagation yet to handle
*/

@@ -364,6 +364,6 @@

}, {
key: "handleKeypress",
value: function handleKeypress(event, focusTreeId, componentId, options) {
key: "handleKeyPress",
value: function handleKeyPress(event, focusTreeId, componentId, options) {
if ((0, _isFromFocusOnlyComponent.default)(focusTreeId)) {
return this._focusOnlyEventStrategy.handleKeypress(event, focusTreeId, componentId, options);
return this._focusOnlyEventStrategy.handleKeyPress(event, focusTreeId, componentId, options);
}

@@ -389,6 +389,6 @@ }

}, {
key: "handleKeyup",
value: function handleKeyup(event, focusTreeId, componentId, options) {
key: "handleKeyUp",
value: function handleKeyUp(event, focusTreeId, componentId, options) {
if ((0, _isFromFocusOnlyComponent.default)(focusTreeId)) {
return this._focusOnlyEventStrategy.handleKeyup(event, focusTreeId, componentId, options);
return this._focusOnlyEventStrategy.handleKeyUp(event, focusTreeId, componentId, options);
}

@@ -463,4 +463,4 @@ }

}, {
key: "handleGlobalKeydown",
value: function handleGlobalKeydown(event) {
key: "handleGlobalKeyDown",
value: function handleGlobalKeyDown(event) {
return this._globalEventStrategy.handleKeydown(event);

@@ -479,5 +479,5 @@ }

}, {
key: "handleGlobalKeypress",
value: function handleGlobalKeypress(event) {
return this._globalEventStrategy.handleKeypress(event);
key: "handleGlobalKeyPress",
value: function handleGlobalKeyPress(event) {
return this._globalEventStrategy.handleKeyPress(event);
}

@@ -495,5 +495,5 @@ /**

}, {
key: "handleGlobalKeyup",
value: function handleGlobalKeyup(event) {
return this._globalEventStrategy.handleKeyup(event);
key: "handleGlobalKeyUp",
value: function handleGlobalKeyUp(event) {
return this._globalEventStrategy.handleKeyUp(event);
}

@@ -510,3 +510,3 @@ /**

value: function ignoreEvent(event) {
this._focusOnlyEventStrategy.ignoreEvent(event);
this._focusOnlyEventStrategy.getEventPropagator().ignoreEvent(event);
}

@@ -521,5 +521,5 @@ /**

}, {
key: "forceObserveEvent",
value: function forceObserveEvent(event) {
this._focusOnlyEventStrategy.forceObserveEvent(event);
key: "observeIgnoredEvents",
value: function observeIgnoredEvents(event) {
this._focusOnlyEventStrategy.getEventPropagator().observeIgnoredEvents(event);
}

@@ -531,3 +531,3 @@ /**

* is currently set to keydown or keypress.
* @param {KeyEventRecordIndex} recordIndex Index of key event to move the key state
* @param {KeyEventType} recordIndex Index of key event to move the key state
* up to.

@@ -544,8 +544,8 @@ */

value: function reactAppHistoryWithEvent(key, type) {
var currentEvent = this._focusOnlyEventStrategy.currentEvent;
var previousPropagation = this._focusOnlyEventStrategy.eventPropagator.getPreviousPropagation();
if (currentEvent.key === key && currentEvent.type === type) {
if (currentEvent.handled) {
if (previousPropagation.isForKey(key) && previousPropagation.isForEventType(type)) {
if (previousPropagation.isHandled()) {
return _EventResponse.default.handled;
} else if (currentEvent.ignored) {
} else if (previousPropagation.isIgnoringEvent()) {
return _EventResponse.default.ignored;

@@ -552,0 +552,0 @@ } else {

@@ -8,61 +8,41 @@ "use strict";

var _KeyEventRecordManager = _interopRequireDefault(require("../KeyEventRecordManager"));
var _KeyEventType = _interopRequireDefault(require("../../const/KeyEventType"));
var _KeyEventRecordIndex = _interopRequireDefault(require("../../const/KeyEventRecordIndex"));
var _ModifierFlagsDictionary = _interopRequireDefault(require("../../const/ModifierFlagsDictionary"));
var _Logger = _interopRequireDefault(require("../Logger"));
var _Logger = _interopRequireDefault(require("../logging/Logger"));
var _KeyCombinationSerializer = _interopRequireDefault(require("../KeyCombinationSerializer"));
var _KeyCombinationSerializer = _interopRequireDefault(require("../shared/KeyCombinationSerializer"));
var _arrayFrom = _interopRequireDefault(require("../../utils/array/arrayFrom"));
var _Configuration = _interopRequireDefault(require("../config/Configuration"));
var _indexFromEnd = _interopRequireDefault(require("../../utils/array/indexFromEnd"));
var _KeyHistory = _interopRequireDefault(require("../listening/KeyHistory"));
var _isObject = _interopRequireDefault(require("../../utils/object/isObject"));
var _KeyCombination = _interopRequireDefault(require("../listening/KeyCombination"));
var _isUndefined = _interopRequireDefault(require("../../utils/isUndefined"));
var _ComponentTree = _interopRequireDefault(require("../definitions/ComponentTree"));
var _isEmpty = _interopRequireDefault(require("../../utils/collection/isEmpty"));
var _ComponentOptionsList = _interopRequireDefault(require("../definitions/ComponentOptionsList"));
var _describeKeyEventType = _interopRequireDefault(require("../../helpers/logging/describeKeyEventType"));
var _ActionResolver = _interopRequireDefault(require("../matching/ActionResolver"));
var _KeyEventSequenceIndex = _interopRequireDefault(require("../../const/KeyEventSequenceIndex"));
var _arrayFrom = _interopRequireDefault(require("../../utils/array/arrayFrom"));
var _KeySequenceParser = _interopRequireDefault(require("../KeySequenceParser"));
var _isObject = _interopRequireDefault(require("../../utils/object/isObject"));
var _printComponent = _interopRequireDefault(require("../../helpers/logging/printComponent"));
var _isUndefined = _interopRequireDefault(require("../../utils/isUndefined"));
var _resolveUnaltShiftedAlias = _interopRequireDefault(require("../../helpers/resolving-handlers/resolveUnaltShiftedAlias"));
var _copyAttributes = _interopRequireDefault(require("../../utils/object/copyAttributes"));
var _resolveUnshiftedAlias = _interopRequireDefault(require("../../helpers/resolving-handlers/resolveUnshiftedAlias"));
var _hasKey = _interopRequireDefault(require("../../utils/object/hasKey"));
var _resolveUnaltedAlias = _interopRequireDefault(require("../../helpers/resolving-handlers/resolveUnaltedAlias"));
var _describeKeyEventType = _interopRequireDefault(require("../../helpers/logging/describeKeyEventType"));
var _resolveKeyAlias = _interopRequireDefault(require("../../helpers/resolving-handlers/resolveKeyAlias"));
var _printComponent = _interopRequireDefault(require("../../helpers/logging/printComponent"));
var _resolveAltShiftedAlias = _interopRequireDefault(require("../../helpers/resolving-handlers/resolveAltShiftedAlias"));
var _resolveShiftedAlias = _interopRequireDefault(require("../../helpers/resolving-handlers/resolveShiftedAlias"));
var _resolveAltedAlias = _interopRequireDefault(require("../../helpers/resolving-handlers/resolveAltedAlias"));
var _Configuration = _interopRequireDefault(require("../Configuration"));
var _ModifierFlagsDictionary = _interopRequireDefault(require("../../const/ModifierFlagsDictionary"));
var _without = _interopRequireDefault(require("../../utils/collection/without"));
var _hasKeyPressEvent = _interopRequireDefault(require("../../helpers/resolving-handlers/hasKeyPressEvent"));
var _keyIsCurrentlyTriggeringEvent = _interopRequireDefault(require("../../helpers/parsing-key-maps/keyIsCurrentlyTriggeringEvent"));
var _isMatchPossibleBasedOnNumberOfKeys = _interopRequireDefault(require("../../helpers/resolving-handlers/isMatchPossibleBasedOnNumberOfKeys"));
var _copyAttributes = _interopRequireDefault(require("../../utils/object/copyAttributes"));
var _hasKey = _interopRequireDefault(require("../../utils/object/hasKey"));
var _keyupIsHiddenByCmd = _interopRequireDefault(require("../../helpers/resolving-handlers/keyupIsHiddenByCmd"));
var _KeyEventRecordState = _interopRequireDefault(require("../../const/KeyEventRecordState"));
var _stateFromEvent = _interopRequireDefault(require("../../helpers/parsing-key-maps/stateFromEvent"));

@@ -92,31 +72,14 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function () {
_createClass(AbstractKeyEventStrategy, null, [{
key: "emptyKeyCombination",
/********************************************************************************
* Init & Reset
********************************************************************************/
/********************************************************************************
* Init & Reset
********************************************************************************/
/**
* Returns a new, empty key combination
* @returns {KeyCombinationRecord} A new, empty key combination
*/
value: function emptyKeyCombination() {
return {
keys: {},
ids: [''],
keyAliases: {}
};
}
/**
* Creates a new instance of a event strategy (this class is an abstract one and
* not intended to be instantiated directly)
* @param {Object} options Options for how event strategy should behave
* @param {Logger} options.logger The Logger to use to report event strategy actions
* @param {KeyEventManager} keyEventManager KeyEventManager used for passing
* messages between key event strategies
*/
}]);
/**
* Creates a new instance of an event strategy (this class is an abstract one and
* not intended to be instantiated directly).
* @param {Object} options Options for how event strategy should behave
* @param {Logger} options.logger The Logger to use to report event strategy actions
* @param {KeyEventManager} keyEventManager KeyEventManager used for passing
* messages between key event strategies
*/
function AbstractKeyEventStrategy() {

@@ -130,3 +93,3 @@ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

/**
* @typedef {Number} ComponentId Unique index associated with every HotKeys component
* @typedef {number} ComponentId Unique index associated with every HotKeys component
* as it becomes active.

@@ -159,4 +122,3 @@ *

this.keyEventManager = keyEventManager;
this.keyMapRegistry = {};
this.componentRegistry = {};
this._componentTree = new _ComponentTree.default();
this.rootComponentId = null;

@@ -166,3 +128,3 @@

this.resetKeyCombinationHistory();
this.resetKeyHistory();
}

@@ -178,65 +140,23 @@ /**

value: function _reset() {
this._initRegisteredKeyMapsState();
this.componentList = new _ComponentOptionsList.default();
this._initHandlerResolutionState();
}
/**
* Resets all state used to record information about the keymaps that HotKey
* components have registered.
*
* After initialization, this state is generally maintained manually by
* the _buildKeyMatcherMap() method and this method should not be called.
*/
}, {
key: "_initRegisteredKeyMapsState",
value: function _initRegisteredKeyMapsState() {
/**
* Object containing a component's defined key maps and handlers
* @typedef {Object} ComponentOptions
* @property {ActionDictionary} actions - Dictionary of actions the component
* has defined in its keymap
* @property {HandlersMap} handlers - Dictionary of handler functions the
* component has defined
* @property {ComponentId} componentId - Index of the component the options
* correspond with
*/
key: "_newKeyHistory",
value: function _newKeyHistory() {
return new _KeyHistory.default({
maxLength: this.componentList.getLongestSequence()
});
}
}, {
key: "getKeyHistory",
value: function getKeyHistory() {
if (this._keyHistory) {
return this._keyHistory;
} else {
this._keyHistory = this._newKeyHistory();
}
/**
* List of actions and handlers registered by each component currently in focus.
* The component closest to the element in focus is last in the list.
* @type {ComponentOptions[]}
*/
this.componentList = [];
/**
* Counter for the longest sequence registered by the HotKeys components currently
* in focus. Allows setting an upper bound on the length of the key event history
* that must be kept.
* @type {Number}
*/
this.longestSequence = 1;
/**
* The component index of the component that defines the longest key sequence, so
* we can quickly determine if the longest sequence needs to be re-calculated when
* that component is updated or removed.
* @type {ComponentId}
*/
this.longestSequenceComponentIndex = null;
/**
* Record to record whether there is at least one keymap bound to each event type
* (keydown, keypress or keyup) so that we can skip trying to find a matching keymap
* on events where we know there is none to find
* @type {KeyEventRecord}
*/
this.keyMapEventRecord = _KeyEventRecordManager.default.newRecord();
/**
* Set of ComponentOptions indexed by ComponentId to allow efficient retrieval
* when components need to be updated or unmounted by their ComponentId
* @type {Object<ComponentId, ComponentOptions>}
*/
this.componentIdDict = {};
return this._keyHistory;
}

@@ -252,45 +172,3 @@ /**

value: function _initHandlerResolutionState() {
if (this.keyMaps === null) {
/**
* If this.keyMaps is already set to null, then the state has already been reset
* and we need not do it again
*/
return;
}
/**
* List of mappings from key sequences to handlers that is constructed on-the-fly
* as key events propagate up the render tree
*/
this.keyMaps = null;
/**
* Index marking the number of places from the end of componentList for which the
* keyMaps have been matched with event handlers. Used to build this.keyMaps as
* key events propagate up the React tree.
* @type {Number}
*/
this.handlerResolutionSearchIndex = 0;
/**
* Array of counters - one for each component - to keep track of how many handlers
* for that component still need actions assigned to them
* @type {Number[]}
*/
this.unmatchedHandlerStatus = null;
/**
* A dictionary of handlers to the components that register them. This is populated
* as this.handlerResolutionSearchIndex increases, moving from the end of this.componentList to the
* front, populating this.keyMaps as needed
* @type {Object<ActionName, ComponentId>}
*/
this.handlersDictionary = {};
/**
* A dictionary of sequences already encountered in the process of building the
* list of keyMaps on the fly, as key events propagate up the component tree
*/
this.keySequencesDictionary = {};
this._actionResolver = null;
}

@@ -300,3 +178,3 @@ /**

* @param {Object} options An options hash
* @param {Boolean} options.force Whether to force a hard reset of the key
* @param {boolean} options.force Whether to force a hard reset of the key
* combination history.

@@ -306,34 +184,14 @@ */

}, {
key: "resetKeyCombinationHistory",
value: function resetKeyCombinationHistory() {
key: "resetKeyHistory",
value: function resetKeyHistory() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
/**
* Whether the current key combination includes at least one keyup event - indicating
* that the current combination is ending (and keys are being released)
*/
this.keyCombinationIncludesKeyUp = false;
this.keypressEventsToSimulate = [];
this.keyupEventsToSimulate = [];
if (!this.keyCombinationHistory || this.keyCombinationHistory.length < 1 || options.force) {
this.keyCombinationHistory = [];
if (this.getKeyHistory().any() && !options.force) {
this._keyHistory = new _KeyHistory.default({
maxLength: this.componentList.getLongestSequence()
}, new _KeyCombination.default(this.getCurrentCombination().keysStillPressedDict()));
} else {
var currentKeyCombination = this._getCurrentKeyCombination();
var keysStillPressed = Object.keys(currentKeyCombination.keys).reduce(function (memo, keyName) {
var keyState = currentKeyCombination.keys[keyName];
var currentKeyState = keyState[_KeyEventSequenceIndex.default.current];
if (currentKeyState[_KeyEventRecordIndex.default.keydown] && !currentKeyState[_KeyEventRecordIndex.default.keyup]) {
memo[keyName] = keyState;
}
return memo;
}, {});
this.keyCombinationHistory = [{
keys: keysStillPressed,
ids: _KeyCombinationSerializer.default.serialize(keysStillPressed),
keyAliases: this._buildCombinationKeyAliases(keysStillPressed)
}];
this._keyHistory = this._newKeyHistory();
}

@@ -367,4 +225,5 @@ }

componentIds.forEach(function (componentId) {
var component = _this.componentRegistry[componentId];
var keyMap = _this.keyMapRegistry[componentId];
var _this$_componentTree$ = _this._componentTree.get(componentId),
childIds = _this$_componentTree$.childIds,
keyMap = _this$_componentTree$.keyMap;

@@ -408,3 +267,3 @@ if (keyMap) {

_this._buildApplicationKeyMap(component.childIds, keyMapSummary);
_this._buildApplicationKeyMap(childIds, keyMapSummary);
});

@@ -453,6 +312,6 @@ return keyMapSummary;

this.componentId += 1;
this.keyMapRegistry[this.componentId] = keyMap;
this.logger.verbose(this._logPrefix(this.componentId), 'Registered keyMap:\n', "".concat((0, _printComponent.default)(keyMap)));
this.componentRegistry[this.componentId] = newComponentRegistryItem();
this.logger.verbose(this._logPrefix(this.componentId), 'Registered component:\n', "".concat((0, _printComponent.default)(this.componentRegistry[this.componentId])));
this._componentTree.add(this.componentId, keyMap);
this.logger.verbose(this._logPrefix(this.componentId), 'Registered component:\n', "".concat((0, _printComponent.default)(this._componentTree.get(this.componentId))));
return this.componentId;

@@ -469,3 +328,3 @@ }

value: function reregisterKeyMap(componentId, keyMap) {
this.keyMapRegistry[componentId] = keyMap;
this._componentTree.update(componentId, keyMap);
}

@@ -483,4 +342,3 @@ /**

if (!(0, _isUndefined.default)(parentId)) {
this.componentRegistry[componentId].parentId = parentId;
this.componentRegistry[parentId].childIds.push(componentId);
this._componentTree.setParent(componentId, parentId);
} else {

@@ -490,3 +348,3 @@ this.rootComponentId = componentId;

this.logger.verbose(this._logPrefix(componentId), 'Registered component mount:\n', "".concat((0, _printComponent.default)(this.componentRegistry[componentId])));
this.logger.verbose(this._logPrefix(componentId), 'Registered component mount:\n', "".concat((0, _printComponent.default)(this._componentTree.get(componentId))));
}

@@ -502,14 +360,6 @@ /**

value: function deregisterKeyMap(componentId) {
var parentId = this.componentRegistry[componentId].parentId;
var parent = this.componentRegistry[parentId];
this._componentTree.remove(componentId);
if (parent) {
parent.childIds = (0, _without.default)(parent.childIds, componentId);
}
this.logger.verbose(this._logPrefix(componentId), 'De-registered component. Remaining component Registry:\n', "".concat((0, _printComponent.default)(this._componentTree.toJSON())));
delete this.componentRegistry[componentId];
this.logger.verbose(this._logPrefix(componentId), 'De-registered component. Remaining component Registry:\n', "".concat((0, _printComponent.default)(this.componentRegistry)));
delete this.keyMapRegistry[componentId];
this.logger.verbose(this._logPrefix(componentId), 'De-registered key map. Remaining key map Registry:\n', "".concat((0, _printComponent.default)(this.keyMapRegistry)));
if (componentId === this.rootComponentId) {

@@ -535,177 +385,10 @@ this.rootComponentId = null;

}, {
key: "_addComponentToList",
value: function _addComponentToList(componentId) {
key: "_addComponent",
value: function _addComponent(componentId) {
var actionNameToKeyMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var actionNameToHandlersMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var options = arguments.length > 3 ? arguments[3] : undefined;
var componentOptions = this._buildComponentOptions(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this.componentList.push(componentOptions);
this._setComponentPosition(componentId, this.componentList.length - 1);
this.componentList.add(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this.getKeyHistory().setMaxLength(this.componentList.getLongestSequence());
}
/**
* Builds the internal representation that described the options passed to a HotKeys
* component
* @param {ComponentId} componentId - Index of the component
* @param {KeyMap} actionNameToKeyMap - Definition of actions and key maps defined
* in the HotKeys component
* @param {HandlersMap} actionNameToHandlersMap - Map of ActionNames to handlers
* defined in the HotKeys component
* @param {Object} options - Hash of options that configure how the key map is built.
* @param {String} options.defaultKeyEvent - The default key event to use for any
* action that does not explicitly define one.
* @returns {ComponentOptions} Options for the specified component
* @protected
*/
}, {
key: "_buildComponentOptions",
value: function _buildComponentOptions(componentId, actionNameToKeyMap, actionNameToHandlersMap, options) {
var _this$_applyHardSeque = this._applyHardSequences(actionNameToKeyMap, actionNameToHandlersMap),
hardSequenceKeyMap = _this$_applyHardSeque.keyMap,
includingHardSequenceHandlers = _this$_applyHardSeque.handlers;
return {
actions: this._buildActionDictionary(_objectSpread({}, actionNameToKeyMap, hardSequenceKeyMap), options, componentId),
handlers: includingHardSequenceHandlers,
componentId: componentId,
options: options
};
}
/**
* Applies hard sequences (handlers attached to actions with names that are valid
* KeySequenceStrings) that implicitly define a corresponding action name.
* @param {KeyMap} actionNameToKeyMap - KeyMap specified by HotKeys component
* @param {HandlersMap} actionNameToHandlersMap - HandlersMap specified by HotKeys
* component
* @returns {{keyMap: {}, handlers: {}}} Object containing keymap and handlers map
* with the hard sequence actions applied
* @private
*/
}, {
key: "_applyHardSequences",
value: function _applyHardSequences(actionNameToKeyMap, actionNameToHandlersMap) {
if (_Configuration.default.option('enableHardSequences')) {
return Object.keys(actionNameToHandlersMap).reduce(function (memo, actionNameOrKeyExpression) {
var actionNameIsInKeyMap = !!actionNameToKeyMap[actionNameOrKeyExpression];
if (!actionNameIsInKeyMap && _KeyCombinationSerializer.default.isValidKeySerialization(actionNameOrKeyExpression)) {
memo.keyMap[actionNameOrKeyExpression] = actionNameOrKeyExpression;
}
memo.handlers[actionNameOrKeyExpression] = actionNameToHandlersMap[actionNameOrKeyExpression];
return memo;
}, {
keyMap: {},
handlers: {}
});
} else {
return {
keyMap: actionNameToKeyMap,
handlers: actionNameToHandlersMap
};
}
}
/**
* Object containing all the information required to match a key event to an action
* @typedef {Object} ActionConfiguration
* @property {KeyCombinationString} id - String description of keys involved in the
* final key combination in the sequence
* @property {ActionName} actionName - Name of the action associated with the key map
* @property {NormalizedKeySequenceId} prefix - String describing sequence of key
* combinations involved key map, before the final key combination
* @property {Number} sequenceLength - Number of combinations involved in the
* sequence
* @property {Number} size - Number of keys involved in the combination
* @property {Object.<KeyName, Boolean>} keyDictionary - Dictionary of key names involved
* in the key combination
* @property {KeyEventRecordIndex} eventRecordIndex - Record index for key event that
* the matcher should match on
*/
/**
* A mapping between ActionNames and FullKeyEventOptions
* @typedef {Object<ActionName,ActionConfiguration>} ActionDictionary
*/
/**
* Returns a mapping between ActionNames and FullKeyEventOptions
* @param {KeyMap} actionNameToKeyMap - Mapping of ActionNames to key sequences.
* @param {Object} options - Hash of options that configure how the key map is built.
* @param {String} options.defaultKeyEvent - The default key event to use for any
* action that does not explicitly define one.
* @param {ComponentId} componentId Index of the component the matcher belongs to
* @return {ActionDictionary} Map from ActionNames to FullKeyEventOptions
* @private
*/
}, {
key: "_buildActionDictionary",
value: function _buildActionDictionary(actionNameToKeyMap, options, componentId) {
var _this2 = this;
return Object.keys(actionNameToKeyMap).reduce(function (keyMapMemo, actionName) {
var keyMapConfig = actionNameToKeyMap[actionName];
var keyMapOptions = function () {
if ((0, _isObject.default)(keyMapConfig) && (0, _hasKey.default)(keyMapConfig, 'sequences')) {
return (0, _arrayFrom.default)(keyMapConfig.sequences);
} else {
return (0, _arrayFrom.default)(keyMapConfig);
}
}();
keyMapOptions.forEach(function (keyMapOption) {
var _ref = function () {
if ((0, _isObject.default)(keyMapOption)) {
var _sequence = keyMapOption.sequence,
action = keyMapOption.action;
return {
keySequence: _sequence,
eventRecordIndex: (0, _isUndefined.default)(action) ? _KeyEventRecordIndex.default[options.defaultKeyEvent] : _KeyEventRecordIndex.default[action]
};
} else {
return {
keySequence: keyMapOption,
eventRecordIndex: _KeyEventRecordIndex.default[options.defaultKeyEvent]
};
}
}(),
keySequence = _ref.keySequence,
eventRecordIndex = _ref.eventRecordIndex;
var _KeySequenceParser$pa = _KeySequenceParser.default.parse(keySequence, {
eventRecordIndex: eventRecordIndex
}),
sequence = _KeySequenceParser$pa.sequence,
combination = _KeySequenceParser$pa.combination;
if (sequence.size > _this2.longestSequence) {
_this2.longestSequence = sequence.size;
_this2.longestSequenceComponentIndex = componentId;
}
/**
* Record that there is at least one key sequence in the focus tree bound to
* the keyboard event
*/
_this2.keyMapEventRecord[eventRecordIndex] = true;
if (!keyMapMemo[actionName]) {
keyMapMemo[actionName] = [];
}
keyMapMemo[actionName].push(_objectSpread({
prefix: sequence.prefix,
actionName: actionName,
sequenceLength: sequence.size
}, combination));
});
return keyMapMemo;
}, {});
}
/********************************************************************************

@@ -716,106 +399,4 @@ * Recording key events

/**
* Record of the combination of keys that are currently being pressed
* @typedef {Object} KeyCombinationRecord
* @property {Object<ReactKeyName, KeyEventRecord[]>} keys - A dictionary
* of keys that have been pressed down at once. The keys of the map are the lowercase
* names of the keyboard keys. May contain 1 or more keyboard keys.
* @property {KeySequenceString} ids - Serialization of keys currently pressed in
* combination
* @property {Object<ReactKeyName, ReactKeyName>} keyAliases - Dictionary of key
* aliases, when modifier keys like alt or shift are pressed.
*/
/**
* Returns the current key combination, i.e. the key combination that represents
* the current key events.
* @returns {KeyCombinationRecord} The current key combination
* @protected
*/
}, {
key: "_getCurrentKeyCombination",
value: function _getCurrentKeyCombination() {
if (this.keyCombinationHistory.length > 0) {
return this.keyCombinationHistory[this.keyCombinationHistory.length - 1];
} else {
return this.constructor.emptyKeyCombination();
}
}
/**
* Adds a key event to the current key combination (as opposed to starting a new
* keyboard combination).
* @param {ReactKeyName} keyName - Name of the key to add to the current combination
* @param {KeyEventRecordIndex} recordIndex - Index in record to set to true
* @param {KeyEventRecordState} keyEventState The state to set the key event to
* @protected
*/
}, {
key: "_addToCurrentKeyCombination",
value: function _addToCurrentKeyCombination(keyName, recordIndex, keyEventState) {
if (this.keyCombinationHistory.length === 0) {
this.keyCombinationHistory.push(this.constructor.emptyKeyCombination());
}
var keyCombination = this._getCurrentKeyCombination();
var keyAlias = getKeyAlias(keyCombination, keyName);
var existingRecord = getKeyState(keyCombination, keyName);
if (!existingRecord) {
keyCombination.keys[keyAlias] = [_KeyEventRecordManager.default.newRecord(), _KeyEventRecordManager.default.newRecord(recordIndex, keyEventState)];
} else {
var previous = _KeyEventRecordManager.default.clone(existingRecord[1]);
var current = _KeyEventRecordManager.default.clone(previous);
_KeyEventRecordManager.default.setBit(current, recordIndex, keyEventState);
keyCombination.keys[keyAlias] = [previous, current];
}
keyCombination.ids = _KeyCombinationSerializer.default.serialize(keyCombination.keys);
keyCombination.keyAliases = this._buildCombinationKeyAliases(keyCombination.keys);
if (recordIndex === _KeyEventRecordIndex.default.keyup) {
this.keyCombinationIncludesKeyUp = true;
}
}
/**
* Adds a new KeyCombinationRecord to the event history and resets the
* keyCombinationIncludesKeyUp flag to false.
* @param {ReactKeyName} keyName - Name of the keyboard key to add to the new
* KeyCombinationRecord
* @param {KeyEventRecordIndex} eventRecordIndex - Index of bit to set to true in new
* KeyEventRecord
* @param {KeyEventRecordState} keyEventState The state to set the key event to
* @protected
*/
}, {
key: "_startNewKeyCombination",
value: function _startNewKeyCombination(keyName, eventRecordIndex, keyEventState) {
if (this.keyCombinationHistory.length > this.longestSequence) {
/**
* We know the longest key sequence registered for the currently focused
* components, so we don't need to keep a record of history longer than
* that
*/
this.keyCombinationHistory.shift();
}
var lastKeyCombination = this._getCurrentKeyCombination();
var keys = _objectSpread({}, this._withoutKeyUps(lastKeyCombination), _defineProperty({}, keyName, [_KeyEventRecordManager.default.newRecord(), _KeyEventRecordManager.default.newRecord(eventRecordIndex, keyEventState)]));
this.keyCombinationHistory.push({
keys: keys,
ids: _KeyCombinationSerializer.default.serialize(keys),
keyAliases: this._buildCombinationKeyAliases(keys)
});
this.keyCombinationIncludesKeyUp = false;
}
/**
* Whether there are any keys in the current combination still being pressed
* @return {Boolean} True if all keys in the current combination are released
* @returns {boolean} True if all keys in the current combination are released
* @protected

@@ -827,33 +408,8 @@ */

value: function _allKeysAreReleased() {
var _this3 = this;
var currentCombination = this._getCurrentKeyCombination();
return Object.keys(currentCombination.keys).every(function (keyName) {
return !_this3._keyIsCurrentlyDown(keyName);
});
return this.getCurrentCombination().hasEnded();
}
/**
* Returns a new KeyCombinationRecord without the keys that have been
* released (had the keyup event recorded). Essentially, the keys that are
* currently still pressed down at the time a key event is being handled.
* @param {KeyCombinationRecord} keyCombinationRecord Record of keys currently
* pressed down that should have the release keyed omitted from
* @returns {KeyCombinationRecord} New KeyCombinationRecord with all of the
* keys with keyup events omitted
* @private
*/
}, {
key: "_withoutKeyUps",
value: function _withoutKeyUps(keyCombinationRecord) {
return Object.keys(keyCombinationRecord.keys).reduce(function (memo, keyName) {
var keyState = keyCombinationRecord.keys[keyName];
if (!keyState[_KeyEventSequenceIndex.default.current][_KeyEventRecordIndex.default.keyup]) {
memo[keyName] = keyState;
}
return memo;
}, {});
key: "getCurrentCombination",
value: function getCurrentCombination() {
return this.getKeyHistory().getCurrentCombination();
}

@@ -863,8 +419,9 @@ }, {

value: function _shouldSimulate(eventType, keyName) {
var keyHasNativeKeypress = (0, _hasKeyPressEvent.default)(keyName);
var keyHasNativeKeyPress = (0, _hasKeyPressEvent.default)(keyName);
var currentCombination = this.getCurrentCombination();
if (eventType === _KeyEventRecordIndex.default.keypress) {
return !keyHasNativeKeypress || keyHasNativeKeypress && this._keyIsCurrentlyDown('Meta');
} else if (eventType === _KeyEventRecordIndex.default.keyup) {
return (0, _keyupIsHiddenByCmd.default)(keyName) && (0, _keyIsCurrentlyTriggeringEvent.default)(this._getCurrentKeyState('Meta'), _KeyEventRecordIndex.default.keyup);
if (eventType === _KeyEventType.default.keypress) {
return !keyHasNativeKeyPress || keyHasNativeKeyPress && currentCombination.isKeyStillPressed('Meta');
} else if (eventType === _KeyEventType.default.keyup) {
return (0, _keyupIsHiddenByCmd.default)(keyName) && currentCombination.isKeyReleased('Meta');
}

@@ -883,9 +440,2 @@

}
}, {
key: "_alreadySimulatedEvent",
value: function _alreadySimulatedEvent(recordIndex, keyName) {
var keyState = this._getCurrentKeyState(keyName);
return (0, _keyIsCurrentlyTriggeringEvent.default)(keyState, recordIndex) === _KeyEventRecordState.default.simulated;
}
/********************************************************************************

@@ -896,287 +446,40 @@ * Matching and calling handlers

}, {
key: "_callMatchingHandlerClosestToEventTarget",
value: function _callMatchingHandlerClosestToEventTarget(event, keyName, eventRecordIndex, componentPosition, componentSearchIndex) {
var _this4 = this;
if (!this.keyMaps || !this.unmatchedHandlerStatus) {
this.keyMaps = [];
this.unmatchedHandlerStatus = [];
this.componentList.forEach(function (_ref2) {
var handlers = _ref2.handlers;
_this4.unmatchedHandlerStatus.push([Object.keys(handlers).length, {}]);
_this4.keyMaps.push({});
});
key: "_callClosestMatchingHandler",
value: function _callClosestMatchingHandler(event, keyName, keyEventType, componentPosition, componentSearchIndex) {
if (!this._actionResolver) {
this._actionResolver = new _ActionResolver.default(this.componentList);
}
while (componentSearchIndex <= componentPosition) {
var unmatchedHandlersStatus = this.unmatchedHandlerStatus[componentSearchIndex];
var unmatchedHandlersCount = unmatchedHandlersStatus[0];
var keyHistoryMatcher = this._actionResolver.getKeyHistoryMatcher(componentSearchIndex);
if (unmatchedHandlersCount > 0) {
var _loop = function _loop() {
var _this4$componentList$ = _this4.componentList[_this4.handlerResolutionSearchIndex],
handlers = _this4$componentList$.handlers,
actions = _this4$componentList$.actions;
/**
* Add current component's handlers to the handlersDictionary so we know
* which component has defined them
*/
this.logger.verbose(this._logPrefix(componentSearchIndex), 'Internal key mapping:\n', "".concat((0, _printComponent.default)(keyHistoryMatcher.toJSON())));
Object.keys(handlers).forEach(function (actionName) {
if (!_this4.handlersDictionary[actionName]) {
_this4.handlersDictionary[actionName] = [];
}
var sequenceMatch = this._actionResolver.findMatchingKeySequenceInComponent(componentSearchIndex, this.getKeyHistory(), keyName, keyEventType);
_this4.handlersDictionary[actionName].push(_this4.handlerResolutionSearchIndex);
});
/**
* Iterate over the actions of a component (starting with the current component
* and working through its ancestors), matching them to the current component's
* handlers
*/
var currentCombination = this.getCurrentCombination();
Object.keys(actions).forEach(function (actionName) {
var handlerComponentIndexArray = _this4.handlersDictionary[actionName];
if (sequenceMatch) {
var eventSchema = sequenceMatch.events[keyEventType];
if (handlerComponentIndexArray) {
/**
* Get action handler closest to the event target
*/
var handlerComponentIndex = handlerComponentIndexArray[0];
var handler = _this4.componentList[handlerComponentIndex].handlers[actionName];
/**
* Get key map that corresponds with the component that defines the handler
* closest to the event target
*/
if (_Configuration.default.option('allowCombinationSubmatches')) {
var subMatchDescription = _KeyCombinationSerializer.default.serialize(sequenceMatch.keyDictionary);
var _keyMap = _this4.keyMaps[handlerComponentIndex];
/**
* Store the key sequence with the handler that it should call at
* a given component level
*/
this.logger.debug(this._logPrefix(componentSearchIndex), "Found action that matches '".concat(currentCombination.describe(), "' (sub-match: '").concat(subMatchDescription, "'): ").concat(eventSchema.actionName, ". Calling handler . . ."));
} else {
this.logger.debug(this._logPrefix(componentSearchIndex), "Found action that matches '".concat(currentCombination.describe(), "': ").concat(eventSchema.actionName, ". Calling handler . . ."));
}
if (!_keyMap.sequences) {
_keyMap.sequences = {};
}
/**
* At least one child HotKeys component (or the component itself) has
* defined a handler for the action, so now we need to associate them
*/
eventSchema.handler(event);
this._stopEventPropagationAfterHandlingIfEnabled(event, componentSearchIndex);
var keyMatchers = actions[actionName];
keyMatchers.forEach(function (keyMatcher) {
var keySequence = [keyMatcher.prefix, keyMatcher.id].join(' ');
var closestSequenceHandlerAlreadyFound = _this4.keySequencesDictionary[keySequence] && _this4.keySequencesDictionary[keySequence].some(function (dictEntry) {
return dictEntry[1] === keyMatcher.eventRecordIndex;
});
if (closestSequenceHandlerAlreadyFound) {
/**
* Return if there is already a component with handlers for the current
* key sequence closer to the event target
*/
return;
}
if (!_keyMap.sequences[keyMatcher.prefix]) {
_keyMap.sequences[keyMatcher.prefix] = {
combinations: {}
};
}
var prefix = keyMatcher.prefix,
sequenceLength = keyMatcher.sequenceLength,
id = keyMatcher.id,
keyDictionary = keyMatcher.keyDictionary,
size = keyMatcher.size,
matcherEventRecordIndex = keyMatcher.eventRecordIndex,
actionName = keyMatcher.actionName;
var combination = _keyMap.sequences[keyMatcher.prefix].combinations[keyMatcher.id];
if (!combination) {
_keyMap.sequences[keyMatcher.prefix].combinations[keyMatcher.id] = {
prefix: prefix,
sequenceLength: sequenceLength,
id: id,
keyDictionary: keyDictionary,
size: size,
events: _defineProperty({}, matcherEventRecordIndex, {
actionName: actionName,
eventRecordIndex: matcherEventRecordIndex,
handler: handler
})
};
} else {
_keyMap.sequences[keyMatcher.prefix].combinations[keyMatcher.id] = _objectSpread({}, combination, {
events: _objectSpread({}, combination.events, _defineProperty({}, matcherEventRecordIndex, {
actionName: actionName,
eventRecordIndex: matcherEventRecordIndex,
handler: handler
}))
});
}
/**
* Merge event records so we can quickly determine if a given component
* has any handlers bound to particular key events
*/
if (!_keyMap.eventRecord) {
_keyMap.eventRecord = _KeyEventRecordManager.default.newRecord();
}
_KeyEventRecordManager.default.setBit(_keyMap.eventRecord, keyMatcher.eventRecordIndex, _this4._stateFromEvent(event));
/**
* Record the longest sequence length so we know to only check for sequences
* of that length or shorter for a particular component
*/
if (!_keyMap.longestSequence || _keyMap.longestSequence < keyMatcher.sequenceLength) {
_keyMap.longestSequence = keyMatcher.sequenceLength;
}
/**
* Record that we have already found a handler for the current action so
* that we do not override handlers for an action closest to the event target
* with handlers further up the tree
*/
if (!_this4.keySequencesDictionary[keySequence]) {
_this4.keySequencesDictionary[keySequence] = [];
}
_this4.keySequencesDictionary[keySequence].push([handlerComponentIndex, keyMatcher.eventRecordIndex]);
});
handlerComponentIndexArray.forEach(function (handlerComponentIndex) {
var handlerComponentStatus = _this4.unmatchedHandlerStatus[handlerComponentIndex];
if (!handlerComponentStatus[1][actionName]) {
handlerComponentStatus[1][actionName] = true;
/**
* Decrement the number of remaining unmatched handlers for the
* component currently handling the propagating key event, so we know
* when all handlers have been matched to sequences and we can move on
* to matching them against the current key event
*/
handlerComponentStatus[0]--;
}
});
}
});
/**
* Search next component up in the hierarchy for actions that match outstanding
* handlers
*/
_this4.handlerResolutionSearchIndex++;
};
/**
* Component currently handling key event has handlers that have not yet been
* associated with a key sequence. We need to continue walking up the component
* tree in search of the matching actions that describe the applicable key
* sequence.
*/
while (this.handlerResolutionSearchIndex < this.componentList.length && unmatchedHandlersCount > 0) {
_loop();
}
}
var keyMap = this.keyMaps[componentSearchIndex];
this.logger.verbose(this._logPrefix(componentSearchIndex), 'Internal key mapping:\n', "".concat((0, _printComponent.default)(keyMap)));
if (!keyMap || (0, _isEmpty.default)(keyMap.sequences) || !keyMap.eventRecord[eventRecordIndex]) {
/**
* Component doesn't define any matchers for the current key event
*/
this.logger.debug(this._logPrefix(componentSearchIndex), "Doesn't define a handler for '".concat(this._describeCurrentKeyCombination(), "' ").concat((0, _describeKeyEventType.default)(eventRecordIndex), "."));
return true;
} else {
var sequences = keyMap.sequences,
longestSequence = keyMap.longestSequence;
var currentKeyState = this._getCurrentKeyCombination();
var normalizedKeyName = getKeyAlias(currentKeyState, keyName);
var sequenceLengthCounter = longestSequence;
while (sequenceLengthCounter >= 0) {
var sequenceHistory = this.keyCombinationHistory.slice(-sequenceLengthCounter, -1);
var sequenceHistoryIds = sequenceHistory.map(function (_ref3) {
var ids = _ref3.ids;
return ids;
});
var matchingSequence = this._tryMatchSequenceWithKeyAliases(sequences, sequenceHistoryIds);
if (matchingSequence) {
if (!matchingSequence.order) {
(function () {
/**
* The first time the component that is currently handling the key event has
* its handlers searched for a match, order the combinations based on their
* size so that they may be applied in the correct priority order
*/
var combinationsPartitionedBySize = Object.values(matchingSequence.combinations).reduce(function (memo, _ref4) {
var id = _ref4.id,
size = _ref4.size;
if (!memo[size]) {
memo[size] = [];
}
memo[size].push(id);
return memo;
}, {});
matchingSequence.order = Object.keys(combinationsPartitionedBySize).sort(function (a, b) {
return b - a;
}).reduce(function (memo, key) {
return memo.concat(combinationsPartitionedBySize[key]);
}, []);
})();
}
var combinationOrder = matchingSequence.order;
var combinationIndex = 0;
while (combinationIndex < combinationOrder.length) {
var combinationId = combinationOrder[combinationIndex];
var combinationMatcher = matchingSequence.combinations[combinationId];
var cmdKeyIsPressed = this._getCurrentKeyState('Meta') && !(0, _keyIsCurrentlyTriggeringEvent.default)(this._getCurrentKeyState('Meta'), _KeyEventRecordIndex.default.keyup);
var keyupIsHidden = cmdKeyIsPressed && Object.keys(combinationMatcher.keyDictionary).some(function (keyName) {
return (0, _keyupIsHiddenByCmd.default)(keyName);
});
if ((0, _isMatchPossibleBasedOnNumberOfKeys.default)(currentKeyState, combinationMatcher, keyupIsHidden)) {
if (this._combinationMatchesKeys(normalizedKeyName, currentKeyState, combinationMatcher, eventRecordIndex)) {
if (_Configuration.default.option('allowCombinationSubmatches')) {
var subMatchDescription = _KeyCombinationSerializer.default.serialize(combinationMatcher.keyDictionary);
this.logger.debug(this._logPrefix(componentSearchIndex), "Found action that matches '".concat(this._describeCurrentKeyCombination(), "' (sub-match: '").concat(subMatchDescription, "'): ").concat(combinationMatcher.events[eventRecordIndex].actionName, ". Calling handler . . ."));
} else {
this.logger.debug(this._logPrefix(componentSearchIndex), "Found action that matches '".concat(this._describeCurrentKeyCombination(), "': ").concat(combinationMatcher.events[eventRecordIndex].actionName, ". Calling handler . . ."));
}
combinationMatcher.events[eventRecordIndex].handler(event);
this._stopEventPropagationAfterHandlingIfEnabled(event, componentSearchIndex);
return true;
}
}
combinationIndex++;
}
}
sequenceLengthCounter--;
if (this._actionResolver.componentHasActionsBoundToEventType(componentSearchIndex, keyEventType)) {
var eventName = (0, _describeKeyEventType.default)(keyEventType);
this.logger.debug(this._logPrefix(componentSearchIndex), "No matching actions found for '".concat(currentCombination.describe(), "' ").concat(eventName, "."));
} else {
this.logger.debug(this._logPrefix(componentSearchIndex), "Doesn't define a handler for '".concat(currentCombination.describe(), "' ").concat((0, _describeKeyEventType.default)(keyEventType), "."));
}
var eventName = (0, _describeKeyEventType.default)(eventRecordIndex);
this.logger.debug(this._logPrefix(componentSearchIndex), "No matching actions found for '".concat(this._describeCurrentKeyCombination(), "' ").concat(eventName, "."));
}

@@ -1188,7 +491,2 @@

}, {
key: "_stateFromEvent",
value: function _stateFromEvent(event) {
return event.simulated ? _KeyEventRecordState.default.simulated : _KeyEventRecordState.default.seen;
}
}, {
key: "_stopEventPropagationAfterHandlingIfEnabled",

@@ -1205,93 +503,6 @@ value: function _stopEventPropagationAfterHandlingIfEnabled(event, componentId) {

}, {
key: "_stopEventPropagationAfterIgnoringIfEnabled",
value: function _stopEventPropagationAfterIgnoringIfEnabled(event, componentId) {
if (_Configuration.default.option('stopEventPropagationAfterIgnoring')) {
this._stopEventPropagation(event, componentId);
return true;
}
return false;
key: "_stopEventPropagation",
value: function _stopEventPropagation(event, componentId) {
throw new Error('_stopEventPropagation must be overridden by a subclass');
}
}, {
key: "_describeCurrentKeyCombination",
value: function _describeCurrentKeyCombination() {
return this._getCurrentKeyCombination().ids[0];
}
}, {
key: "_tryMatchSequenceWithKeyAliases",
value: function _tryMatchSequenceWithKeyAliases(keyMatcher, sequenceIds) {
if (sequenceIds.length === 0) {
return keyMatcher[''];
}
var idSizes = sequenceIds.map(function (ids) {
return ids.length;
});
var indexCounters = sequenceIds.map(function () {
return 0;
});
var triedAllPossiblePermutations = false;
while (!triedAllPossiblePermutations) {
var sequenceIdPermutation = indexCounters.map(function (sequenceIdIndex, index) {
return sequenceIds[index][sequenceIdIndex];
});
var candidateId = sequenceIdPermutation.join(' ');
if (keyMatcher[candidateId]) {
return keyMatcher[candidateId];
}
var incrementer = 0;
var carry = true;
while (carry && incrementer < indexCounters.length) {
var count = (0, _indexFromEnd.default)(indexCounters, incrementer);
var newIndex = (count + 1) % ((0, _indexFromEnd.default)(idSizes, incrementer) || 1);
indexCounters[indexCounters.length - (incrementer + 1)] = newIndex;
carry = newIndex === 0;
if (carry) {
incrementer++;
}
}
triedAllPossiblePermutations = incrementer === indexCounters.length;
}
}
}, {
key: "_combinationMatchesKeys",
value: function _combinationMatchesKeys(keyBeingPressed, keyCombination, combinationMatch, eventRecordIndex) {
var combinationHasHandlerForEventType = combinationMatch.events[eventRecordIndex];
if (!combinationHasHandlerForEventType) {
/**
* If the combination does not have any actions bound to the key event we are
* currently processing, we skip checking if it matches the current keys being
* pressed.
*/
return false;
}
var keyCompletesCombination = false;
var combinationMatchesKeysPressed = Object.keys(combinationMatch.keyDictionary).every(function (candidateKeyName) {
var keyState = getKeyState(keyCombination, candidateKeyName);
if (keyState) {
if ((0, _keyIsCurrentlyTriggeringEvent.default)(keyState, eventRecordIndex)) {
if (keyBeingPressed && keyBeingPressed === getKeyAlias(keyCombination, candidateKeyName)) {
keyCompletesCombination = !keyAlreadyTriggeredEvent(keyState, eventRecordIndex);
}
return true;
} else {
return false;
}
} else {
return false;
}
});
return combinationMatchesKeysPressed && keyCompletesCombination;
}
/**

@@ -1301,4 +512,4 @@ * Synchronises the key combination history to match the modifier key flag attributes

* @param {KeyboardEvent} event - Event to check the modifier flags for
* @param {String} key - Name of key that events relates to
* @param {KeyEventRecordIndex} keyEventRecordIndex - The record index of the current
* @param {string} key - Name of key that events relates to
* @param {KeyEventType} keyEventType - The record index of the current
* key event type

@@ -1310,4 +521,4 @@ * @protected

key: "_checkForModifierFlagDiscrepancies",
value: function _checkForModifierFlagDiscrepancies(event, key, keyEventRecordIndex) {
var _this5 = this;
value: function _checkForModifierFlagDiscrepancies(event, key, keyEventType) {
var _this2 = this;

@@ -1327,11 +538,13 @@ /**

*/
if (key === modifierKey && keyEventRecordIndex === _KeyEventRecordIndex.default.keyup) {
if (key === modifierKey && keyEventType === _KeyEventType.default.keyup) {
return;
}
var modifierStillPressed = _this5._keyIsCurrentlyDown(modifierKey);
var currentCombination = _this2.getCurrentCombination();
var modifierStillPressed = currentCombination.isKeyStillPressed(modifierKey);
_ModifierFlagsDictionary.default[modifierKey].forEach(function (attributeName) {
if (event[attributeName] === false && modifierStillPressed) {
_this5._addToCurrentKeyCombination(modifierKey, _KeyEventRecordIndex.default.keyup, _this5._stateFromEvent(event));
currentCombination.setKeyState(modifierKey, _KeyEventType.default.keyup, (0, _stateFromEvent.default)(event));
}

@@ -1341,77 +554,2 @@ });

}
}, {
key: "_keyIsCurrentlyDown",
value: function _keyIsCurrentlyDown(keyName) {
var keyState = this._getCurrentKeyState(keyName);
var keyIsDown = (0, _keyIsCurrentlyTriggeringEvent.default)(keyState, _KeyEventRecordIndex.default.keypress) && !(0, _keyIsCurrentlyTriggeringEvent.default)(keyState, _KeyEventRecordIndex.default.keyup);
return !!keyIsDown;
}
}, {
key: "_getCurrentKeyState",
value: function _getCurrentKeyState(keyName) {
var currentCombination = this._getCurrentKeyCombination();
return getKeyState(currentCombination, keyName);
}
}, {
key: "_buildCombinationKeyAliases",
value: function _buildCombinationKeyAliases(keyDictionary) {
var aliasFunctions = function () {
if (keyDictionary['Shift']) {
if (keyDictionary['Alt']) {
return [_resolveAltShiftedAlias.default, _resolveUnaltShiftedAlias.default];
} else {
return [_resolveShiftedAlias.default, _resolveUnshiftedAlias.default];
}
} else {
if (keyDictionary['Alt']) {
return [_resolveAltedAlias.default, _resolveUnaltedAlias.default];
} else {
var nop = function nop(keyName) {
return [keyName];
};
return [nop, nop];
}
}
}();
return Object.keys(keyDictionary).reduce(function (memo, keyName) {
(0, _resolveKeyAlias.default)(keyName).forEach(function (normalizedKey) {
aliasFunctions.forEach(function (aliasFunction) {
aliasFunction(normalizedKey).forEach(function (keyAlias) {
if (keyAlias !== keyName || keyName !== normalizedKey) {
memo[keyAlias] = keyName;
}
});
});
});
return memo;
}, {});
}
}, {
key: "_setComponentPosition",
value: function _setComponentPosition(componentId, position) {
this.componentIdDict[componentId] = position;
}
}, {
key: "_getComponentPosition",
value: function _getComponentPosition(componentId) {
return this.componentIdDict[componentId];
}
}, {
key: "_getComponent",
value: function _getComponent(componentId) {
var componentPosition = this._getComponentPosition(componentId);
return this.componentList[componentPosition];
}
}, {
key: "_getComponentAndPosition",
value: function _getComponentAndPosition(componentId) {
var componentPosition = this._getComponentPosition(componentId);
return [this.componentList[componentPosition], componentPosition];
}
/**

@@ -1431,44 +569,3 @@ * Returns a prefix for all log entries related to the current event strategy

function getKeyAlias(keyCombination, keyName) {
var keyState = keyCombination.keys[keyName];
if (keyState) {
return keyName;
} else {
var keyAlias = keyCombination.keyAliases[keyName];
if (keyAlias) {
return keyAlias;
} else {
return keyName;
}
}
}
function getKeyState(keyCombination, keyName) {
var keyState = keyCombination.keys[keyName];
if (keyState) {
return keyState;
} else {
var keyAlias = keyCombination.keyAliases[keyName];
if (keyAlias) {
return keyCombination.keys[keyAlias];
}
}
}
function newComponentRegistryItem() {
return {
childIds: [],
parentId: null
};
}
function keyAlreadyTriggeredEvent(keyState, eventRecordIndex) {
return keyState && keyState[_KeyEventSequenceIndex.default.previous][eventRecordIndex];
}
var _default = AbstractKeyEventStrategy;
exports.default = _default;

@@ -10,11 +10,11 @@ "use strict";

var _KeyEventRecordIndex = _interopRequireDefault(require("../../const/KeyEventRecordIndex"));
var _KeyEventType = _interopRequireDefault(require("../../const/KeyEventType"));
var _KeyEventCounter = _interopRequireDefault(require("../KeyEventCounter"));
var _KeyEventCounter = _interopRequireDefault(require("../listening/KeyEventCounter"));
var _describeKeyEventType = _interopRequireDefault(require("../../helpers/logging/describeKeyEventType"));
var _Configuration = _interopRequireDefault(require("../Configuration"));
var _Configuration = _interopRequireDefault(require("../config/Configuration"));
var _Logger = _interopRequireDefault(require("../Logger"));
var _Logger = _interopRequireDefault(require("../logging/Logger"));

@@ -29,4 +29,2 @@ var _printComponent = _interopRequireDefault(require("../../helpers/logging/printComponent"));

var _keyIsCurrentlyTriggeringEvent = _interopRequireDefault(require("../../helpers/parsing-key-maps/keyIsCurrentlyTriggeringEvent"));
var _describeKeyEvent = _interopRequireDefault(require("../../helpers/logging/describeKeyEvent"));

@@ -36,4 +34,8 @@

var _KeyEventRecordState = _interopRequireDefault(require("../../const/KeyEventRecordState"));
var _KeyEventState = _interopRequireDefault(require("../../const/KeyEventState"));
var _stateFromEvent = _interopRequireDefault(require("../../helpers/parsing-key-maps/stateFromEvent"));
var _EventPropagator = _interopRequireDefault(require("../listening/EventPropagator"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -94,3 +96,3 @@

* changes, and a different tree of elements are focused, a new id is allocated
* @typedef {Number} FocusTreeId
* @typedef {number} FocusTreeId
*/

@@ -104,25 +106,2 @@

_this.focusTreeId = 0;
/**
* Record of the event currently bubbling up through the React application (and
* beyond). This state is *not* cleared when the event propagation is finished
* or when the component focus tree changes. It persists until it is overridden
* by a new event, so that the global strategy is able to inspect the last
* event seen by the React application, even after focus is lost.
*/
_this.currentEvent = {
/**
* The name of the key the event belongs to
* @type {ReactKeyName}
*/
key: null,
/**
* The event record index of the type of key event
* @type {KeyEventRecordIndex}
*/
type: null,
handled: false,
ignored: false
};
return _this;

@@ -149,54 +128,7 @@ }

this.focusTreeId += 1;
this._clearEventPropagationState();
this.eventPropagator = new _EventPropagator.default(this.componentList, {
logger: this.logger,
logPrefix: this._logPrefix.bind(this)
});
}
/**
* Clears the history that is maintained for the duration of a single keyboard event's
* propagation up the React component tree towards the root component, so that the
* next keyboard event starts with a clean state.
* @private
*/
}, {
key: "_clearEventPropagationState",
value: function _clearEventPropagationState() {
/**
* Object containing state of a key events propagation up the render tree towards
* the document root
* @type {{previousComponentPosition: number, actionHandled: boolean}}}
*/
this.eventPropagationState = {
/**
* Index of the component last seen to be handling a key event
* @type {ComponentId}
*/
previousComponentPosition: -1,
/**
* Whether the keyboard event currently being handled has already matched a
* handler function that has been called
* @type {Boolean}
*/
actionHandled: false,
/**
* Whether the keyboard event current being handled should be ignored
* @type {Boolean}
*/
ignoreEvent: false,
/**
* Whether the keyboard event current being handled should be observed, even
* if matches the ignoreEventCondition
* @type {Boolean}
*/
forceObserveEvent: false,
/**
* Whether the strategy is in the process of stopping propagation and tidying
* up
*/
stopping: false
};
}
/********************************************************************************

@@ -225,3 +157,3 @@ * Registering key maps and handlers

if (this.resetOnNextFocus || this.keyMaps) {
if (this.resetOnNextFocus) {
/**

@@ -238,3 +170,3 @@ * We know components have just lost focus or keymaps have already been built,

if (this._getComponent(componentId)) {
if (this.componentList.containsId(componentId)) {
/**

@@ -250,3 +182,3 @@ * The <tt>componentId</tt> has already been registered - this occurs when the

this._addComponentToList(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this._addComponent(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);

@@ -256,8 +188,5 @@ this.logger.debug(this._logPrefix(componentId, {

}), 'Focused. \n');
var component = this._getComponent(componentId);
this.logger.verbose(this._logPrefix(componentId, {
eventId: false
}), 'Component options:\n', (0, _printComponent.default)(component));
}), 'Component options:\n', (0, _printComponent.default)(this.componentList.get(componentId)));
return this.focusTreeId;

@@ -286,9 +215,8 @@ }

var componentPosition = this._getComponentPosition(componentId);
if (focusTreeId !== this.focusTreeId || (0, _isUndefined.default)(componentPosition)) {
if (focusTreeId !== this.focusTreeId || !this.componentList.containsId(componentId)) {
return;
}
this.componentList[componentPosition] = this._buildComponentOptions(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this.componentList.update(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this.getKeyHistory().setMaxLength(this.componentList.getLongestSequence());
this.logger.debug(this._logPrefix(componentId, {

@@ -304,8 +232,6 @@ focusTreeId: focusTreeId,

var component = this._getComponent(componentId);
this.logger.verbose(this._logPrefix(componentId, {
focusTreeId: focusTreeId,
eventId: false
}), 'Component options:\n', (0, _printComponent.default)(component));
}), 'Component options:\n', (0, _printComponent.default)(this.componentList.get(componentId)));
}

@@ -318,3 +244,3 @@ /**

* @param {ComponentId} componentId - Index of component that is blurring
* @returns {Boolean} Whether the component still has event propagation yet to handle
* @returns {boolean} Whether the component still has event propagation yet to handle
*/

@@ -329,6 +255,3 @@

var componentPosition = this._getComponentPosition(componentId);
var previousComponentPosition = this.eventPropagationState.previousComponentPosition;
var outstandingEventPropagation = previousComponentPosition !== -1 && previousComponentPosition + 1 < componentPosition;
var outstandingEventPropagation = this.eventPropagator.isPendingPropagation();
this.logger.debug("".concat(this._logPrefix(componentId, {

@@ -346,3 +269,3 @@ focusTreeId: focusTreeId,

* @typedef {KeyboardEvent} SyntheticKeyboardEvent
* @property {Function} persist
* @property {function} persist
*/

@@ -371,50 +294,34 @@

var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var key = (0, _getKeyName.default)(event);
var _key = (0, _getKeyName.default)(event);
if (event.repeat && _Configuration.default.option('ignoreRepeatedEventsWhenKeyHeldDown')) {
this.logger.debug(this._logPrefix(componentId), "Ignored repeated ".concat((0, _describeKeyEvent.default)(event, _key, _KeyEventRecordIndex.default.keydown), " event."));
this._ignoreEvent(event, componentId);
if (focusTreeId !== this.focusTreeId) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventType.default.keydown), " event because it had an old focus tree id: ").concat(focusTreeId, "."));
this.eventPropagator.ignoreEvent(event);
return true;
}
if (focusTreeId !== this.focusTreeId) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat((0, _describeKeyEvent.default)(event, _key, _KeyEventRecordIndex.default.keydown), " event because it had an old focus tree id: ").concat(focusTreeId, "."));
var started = this.eventPropagator.startNewPropagationStep(componentId, event, key, _KeyEventType.default.keydown);
this._ignoreEvent(event, componentId);
return true;
if (!started) {
return;
}
var responseAction = this._howToHandleKeyEvent(event, focusTreeId, componentId, _key, options, _KeyEventRecordIndex.default.keydown);
/**
* We need to record the position of the component that is currently dealing with
* the event, in case the component defines a handler for that event that changes
* the focus or content in the render tree, causing the component to be de-registered
* and have its position lost
*/
var responseAction = this._howToHandleKeyEvent(event, focusTreeId, componentId, key, options, _KeyEventType.default.keydown);
var componentPosition = this._getComponentPosition(componentId);
if (responseAction === _EventResponse.default.handled) {
var keyInCurrentCombination = !!this._getCurrentKeyState(_key);
var keyEventState = (0, _stateFromEvent.default)(event);
var currentCombination = this.getCurrentCombination();
var keyEventState = this._stateFromEvent(event);
if (keyInCurrentCombination || this.keyCombinationIncludesKeyUp) {
this._startAndLogNewKeyCombination(_key, _KeyEventRecordIndex.default.keydown, focusTreeId, componentId, keyEventState);
if (currentCombination.isKeyIncluded(key) || currentCombination.isEnding()) {
this._startAndLogNewKeyCombination(key, focusTreeId, componentId, keyEventState);
} else {
this._addToAndLogCurrentKeyCombination(_key, _KeyEventRecordIndex.default.keydown, focusTreeId, componentId, keyEventState);
this._addToAndLogCurrentKeyCombination(key, _KeyEventType.default.keydown, focusTreeId, componentId, keyEventState);
}
this._callHandlerIfActionNotHandled(event, _key, _KeyEventRecordIndex.default.keydown, componentId, focusTreeId);
this._callHandlerIfActionNotHandled(event, key, _KeyEventType.default.keydown, componentId, focusTreeId);
}
this._simulateKeypressForNonPrintableKeys(event, _key, focusTreeId, componentId, options);
this._simulateKeyPressForNonPrintableKeys(event, key, focusTreeId, componentId, options);
this._updateEventPropagationHistory(componentId, componentPosition);
this.eventPropagator.finishPropagationStep();
return false;

@@ -424,33 +331,13 @@ }

key: "_howToHandleKeyEvent",
value: function _howToHandleKeyEvent(event, focusTreeId, componentId, key, options, keyEventRecordIndex) {
if (this._shouldIgnoreEvent()) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, keyEventRecordIndex), " event because ignoreEventsFilter rejected it."));
this._ignoreEvent(event, componentId);
return _EventResponse.default.ignored;
}
if (this._isNewKeyEvent(componentId)) {
this._setNewEventParameters(event, keyEventRecordIndex);
/**
* We know that this is a new key event and not the same event bubbling up
* the React render tree towards the document root, so perform actions specific
* to the first time an event is seen
*/
this._setIgnoreEventFlag(event, options);
if (this._shouldIgnoreEvent()) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, keyEventRecordIndex), " event because ignoreEventsFilter rejected it."));
this._ignoreEvent(event, componentId);
return _EventResponse.default.ignored;
value: function _howToHandleKeyEvent(event, focusTreeId, componentId, key, options, keyEventType) {
if (this.eventPropagator.isFirstPropagationStep()) {
if (options.ignoreEventsCondition(event) && this.eventPropagator.ignoreEvent(event)) {
return this._eventIsToBeIgnored(event, componentId, key, keyEventType);
}
this.logger.debug(this._logPrefix(componentId), "New ".concat((0, _describeKeyEvent.default)(event, key, keyEventRecordIndex), " event."));
this.logger.debug(this._logPrefix(componentId), "New ".concat((0, _describeKeyEvent.default)(event, key, keyEventType), " event."));
this._checkForModifierFlagDiscrepancies(event, key, keyEventRecordIndex);
this._checkForModifierFlagDiscrepancies(event, key, keyEventType);
} else if (this.eventPropagator.isIgnoringEvent()) {
return this._eventIsToBeIgnored(event, componentId, key, keyEventType);
}

@@ -460,2 +347,8 @@

}
}, {
key: "_eventIsToBeIgnored",
value: function _eventIsToBeIgnored(event, componentId, key, keyEventType) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, keyEventType), " event because ignoreEventsFilter rejected it."));
return _EventResponse.default.ignored;
}
/**

@@ -476,3 +369,3 @@ * Records a keypress keyboard event and matches it against the list of pre-registered

* is handled.
* @return {Boolean} Whether the HotKeys component should discard its current focus
* @returns {boolean} Whether the HotKeys component should discard its current focus
* tree Id, because it belongs to an old focus tree.

@@ -482,20 +375,17 @@ */

}, {
key: "handleKeypress",
value: function handleKeypress(event, focusTreeId, componentId, options) {
var _key = (0, _getKeyName.default)(event);
key: "handleKeyPress",
value: function handleKeyPress(event, focusTreeId, componentId, options) {
var key = (0, _getKeyName.default)(event);
var currentCombination = this.getCurrentCombination();
if (event.repeat && _Configuration.default.option('ignoreRepeatedEventsWhenKeyHeldDown')) {
this.logger.debug(this._logPrefix(componentId), "Ignored repeated ".concat((0, _describeKeyEvent.default)(event, _key, _KeyEventRecordIndex.default.keypress), " event."));
this._ignoreEvent(event, componentId);
if (currentCombination.isKeyPressSimulated(key)) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventType.default.keypress), " as it was not expected, and has already been simulated."));
this.eventPropagator.ignoreEvent(event);
return true;
}
if (this._alreadySimulatedEvent(_KeyEventRecordIndex.default.keypress, _key)) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat((0, _describeKeyEvent.default)(event, _key, _KeyEventRecordIndex.default.keypress), " as it was not expected, and has already been simulated."));
var started = this.eventPropagator.startNewPropagationStep(componentId, event, key, _KeyEventType.default.keypress);
this._ignoreEvent(event, componentId);
return true;
if (!started) {
return;
}

@@ -509,17 +399,8 @@

var responseAction = this._howToHandleKeyEvent(event, focusTreeId, componentId, _key, options, _KeyEventRecordIndex.default.keypress);
var responseAction = this._howToHandleKeyEvent(event, focusTreeId, componentId, key, options, _KeyEventType.default.keypress);
if (this._isNewKeyEvent(componentId) && this._getCurrentKeyState(_key)) {
this._addToAndLogCurrentKeyCombination(_key, _KeyEventRecordIndex.default.keypress, focusTreeId, componentId, this._stateFromEvent(event));
if (this.eventPropagator.isFirstPropagationStep(componentId) && currentCombination.isKeyIncluded(key)) {
this._addToAndLogCurrentKeyCombination(key, _KeyEventType.default.keypress, focusTreeId, componentId, (0, _stateFromEvent.default)(event));
}
/**
* We need to record the position of the component that is currently dealing with
* the event, in case the component defines a handler for that event that changes
* the focus or content in the render tree, causing the component to be de-registered
* and have its position lost
*/
var componentPosition = this._getComponentPosition(componentId);
/**
* We attempt to find a handler of the event, only if it has not already

@@ -531,7 +412,6 @@ * been handled and should not be ignored

if (responseAction === _EventResponse.default.handled) {
this._callHandlerIfActionNotHandled(event, _key, _KeyEventRecordIndex.default.keypress, componentId, focusTreeId);
this._callHandlerIfActionNotHandled(event, key, _KeyEventType.default.keypress, componentId, focusTreeId);
}
this._updateEventPropagationHistory(componentId, componentPosition);
this.eventPropagator.finishPropagationStep();
return shouldDiscardFocusTreeId;

@@ -554,3 +434,3 @@ }

* is handled.
* @return {Boolean} Whether HotKeys component should discard its current focusTreeId
* @returns {boolean} Whether HotKeys component should discard its current focusTreeId
* because it's stale (part of an old focus tree)

@@ -560,12 +440,17 @@ */

}, {
key: "handleKeyup",
value: function handleKeyup(event, focusTreeId, componentId, options) {
var _key = (0, _getKeyName.default)(event);
key: "handleKeyUp",
value: function handleKeyUp(event, focusTreeId, componentId, options) {
var key = (0, _getKeyName.default)(event);
var currentCombination = this.getCurrentCombination();
if (this._alreadySimulatedEvent(_KeyEventRecordIndex.default.keyup, _key)) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat((0, _describeKeyEvent.default)(event, _key, _KeyEventRecordIndex.default.keyup), " as it was not expected, and has already been simulated."));
if (currentCombination.isKeyUpSimulated(key)) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventType.default.keyup), " as it was not expected, and has already been simulated."));
this.eventPropagator.ignoreEvent(event);
return true;
}
this._ignoreEvent(event, componentId);
var started = this.eventPropagator.startNewPropagationStep(componentId, event, key, _KeyEventType.default.keyup);
return true;
if (!started) {
return;
}

@@ -579,3 +464,3 @@

var responseAction = this._howToHandleKeyEvent(event, focusTreeId, componentId, _key, options, _KeyEventRecordIndex.default.keyup);
var responseAction = this._howToHandleKeyEvent(event, focusTreeId, componentId, key, options, _KeyEventType.default.keyup);
/**

@@ -589,15 +474,6 @@ * We then add the keyup to our current combination - regardless of whether

if (this._isNewKeyEvent(componentId) && this._getCurrentKeyState(_key)) {
this._addToAndLogCurrentKeyCombination(_key, _KeyEventRecordIndex.default.keyup, focusTreeId, componentId, this._stateFromEvent(event));
if (this.eventPropagator.isFirstPropagationStep(componentId) && currentCombination.isKeyIncluded(key)) {
this._addToAndLogCurrentKeyCombination(key, _KeyEventType.default.keyup, focusTreeId, componentId, (0, _stateFromEvent.default)(event));
}
/**
* We need to record the position of the component that is currently dealing with
* the event, in case the component defines a handler for that event that changes
* the focus or content in the render tree, causing the component to be de-registered
* and have its position lost
*/
var componentPosition = this._getComponentPosition(componentId);
/**
* We attempt to find a handler of the event, only if it has not already

@@ -609,3 +485,3 @@ * been handled and should not be ignored

if (responseAction === _EventResponse.default.handled) {
this._callHandlerIfActionNotHandled(event, _key, _KeyEventRecordIndex.default.keyup, componentId, focusTreeId);
this._callHandlerIfActionNotHandled(event, key, _KeyEventType.default.keyup, componentId, focusTreeId);
}

@@ -618,6 +494,5 @@ /**

this._simulateKeyUpEventsHiddenByCmd(event, _key, focusTreeId, componentId, options);
this._simulateKeyUpEventsHiddenByCmd(event, key, focusTreeId, componentId, options);
this._updateEventPropagationHistory(componentId, componentPosition);
this.eventPropagator.finishPropagationStep();
return shouldDiscardFocusId;

@@ -630,3 +505,3 @@ }

* is currently set to keydown or keypress.
* @param {KeyEventRecordIndex} recordIndex Index of key event to move the key state
* @param {KeyEventType} recordIndex Index of key event to move the key state
* up to.

@@ -638,5 +513,5 @@ */

value: function closeHangingKeyCombination(keyName, recordIndex) {
var keyState = this._getCurrentKeyState(keyName);
var currentCombination = this.getCurrentCombination();
if ((0, _keyIsCurrentlyTriggeringEvent.default)(keyState, _KeyEventRecordIndex.default.keydown) && !(0, _keyIsCurrentlyTriggeringEvent.default)(keyState, recordIndex)) {
if (currentCombination.isKeyIncluded(keyName) && !currentCombination.isEventTriggered(keyName, recordIndex)) {
/**

@@ -647,9 +522,9 @@ * If the key is in the current combination and recorded as still being pressed

*/
this._addToCurrentKeyCombination(keyName, recordIndex, _KeyEventRecordState.default.simulated);
currentCombination.setKeyState(keyName, recordIndex, _KeyEventState.default.simulated);
}
}
}, {
key: "_simulateKeypressForNonPrintableKeys",
value: function _simulateKeypressForNonPrintableKeys(event, key, focusTreeId, componentId, options) {
this._handleEventSimulation('keypressEventsToSimulate', 'simulatePendingKeyPressEvents', this._shouldSimulate(_KeyEventRecordIndex.default.keypress, key), {
key: "_simulateKeyPressForNonPrintableKeys",
value: function _simulateKeyPressForNonPrintableKeys(event, key, focusTreeId, componentId, options) {
this._handleEventSimulation('keypressEventsToSimulate', 'simulatePendingKeyPressEvents', this._shouldSimulate(_KeyEventType.default.keypress, key), {
event: event,

@@ -668,8 +543,3 @@ key: key,

if ((0, _isCmdKey.default)(key)) {
/**
* When the command key is pressed down with other non-modifier keys, the browser
* does not trigger the keyup event of those keys, so we simulate them when the
* command key is released
*/
Object.keys(this._getCurrentKeyCombination().keys).forEach(function (keyName) {
this.getCurrentCombination().forEachKey(function (keyName) {
if ((0, _isCmdKey.default)(keyName)) {

@@ -679,3 +549,3 @@ return;

_this2._handleEventSimulation('keyupEventsToSimulate', 'simulatePendingKeyUpEvents', _this2._shouldSimulate(_KeyEventRecordIndex.default.keyup, keyName), {
_this2._handleEventSimulation('keyupEventsToSimulate', 'simulatePendingKeyUpEvents', _this2._shouldSimulate(_KeyEventType.default.keyup, keyName), {
event: event,

@@ -691,109 +561,17 @@ key: keyName,

}, {
key: "_ignoreEvent",
value: function _ignoreEvent(event, componentId) {
this.currentEvent.ignored = true;
var componentPosition = this._getComponentPosition(componentId);
if (this._stopEventPropagationAfterIgnoringIfEnabled(event, componentId)) {
this._updateEventPropagationHistory(componentId, componentPosition, {
forceReset: true
});
} else {
this._updateEventPropagationHistory(componentId, componentPosition);
key: "_stopEventPropagation",
value: function _stopEventPropagation(event, componentId) {
if (this.eventPropagator.stop(event)) {
this.logger.debug(this._logPrefix(componentId), 'Stopping further event propagation.');
}
}
/**
* Whether KeyEventManager should ignore the event that is currently being handled
* @returns {Boolean} Whether to ignore the event
*
* Do not override this method. Use setIgnoreEventsCondition() instead.
* @private
*/
}, {
key: "_shouldIgnoreEvent",
value: function _shouldIgnoreEvent() {
var _this$eventPropagatio = this.eventPropagationState,
ignoreEvent = _this$eventPropagatio.ignoreEvent,
forceObserveEvent = _this$eventPropagatio.forceObserveEvent;
return !forceObserveEvent && ignoreEvent;
key: "getEventPropagator",
value: function getEventPropagator() {
return this.eventPropagator;
}
/**
* Returns whether this is a previously seen event bubbling up to render tree towards
* the document root, or whether it is a new event that has not previously been seen.
* @param {ComponentId} componentId Index of the component currently handling
* the keyboard event
* @return {Boolean} If the event has been seen before
* @private
*/
}, {
key: "_isNewKeyEvent",
value: function _isNewKeyEvent(componentId) {
var previousComponentPosition = this.eventPropagationState.previousComponentPosition;
return previousComponentPosition === -1 || previousComponentPosition >= this._getComponentPosition(componentId);
}
}, {
key: "_updateEventPropagationHistory",
value: function _updateEventPropagationHistory(componentId, componentPosition) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
forceReset: false
};
if (options.forceReset || this._isFocusTreeRoot(componentId)) {
this._clearEventPropagationState();
} else {
this.eventPropagationState.previousComponentPosition = componentPosition;
}
}
/**
* Sets the ignoreEvent flag so that subsequent handlers of the same event
* do not have to re-evaluate whether to ignore the event or not as it bubbles
* up towards the document root
* @param {KeyboardEvent} event The event to decide whether to ignore
* @param {Object} options Options containing the function to use
* to set the ignoreEvent flag
* @param {Function} options.ignoreEventsCondition Function used to for setting
* the ignoreEvent flag
* @private
*/
}, {
key: "_setIgnoreEventFlag",
value: function _setIgnoreEventFlag(event, options) {
this.eventPropagationState.ignoreEvent = options.ignoreEventsCondition(event);
}
}, {
key: "ignoreEvent",
value: function ignoreEvent() {
this.eventPropagationState.ignoreEvent = true;
}
}, {
key: "forceObserveEvent",
value: function forceObserveEvent() {
this.eventPropagationState.forceObserveEvent = true;
}
}, {
key: "_isFocusTreeRoot",
value: function _isFocusTreeRoot(componentId) {
return this._getComponentPosition(componentId) >= this.componentList.length - 1;
}
}, {
key: "_setNewEventParameters",
value: function _setNewEventParameters(event, type) {
_KeyEventCounter.default.incrementId();
this.currentEvent = {
key: event.key,
type: type,
handled: false,
ignored: false
};
}
}, {
key: "_startAndLogNewKeyCombination",
value: function _startAndLogNewKeyCombination(keyName, eventRecordIndex, focusTreeId, componentId, keyEventState) {
this._startNewKeyCombination(keyName, eventRecordIndex, keyEventState);
value: function _startAndLogNewKeyCombination(keyName, focusTreeId, componentId, keyEventState) {
this.getKeyHistory().startNewKeyCombination(keyName, keyEventState);
this.logger.verbose(this._logPrefix(componentId, {

@@ -804,13 +582,13 @@ focusTreeId: focusTreeId

focusTreeId: focusTreeId
}), "Key history: ".concat((0, _printComponent.default)(this.keyCombinationHistory), "."));
}), "Key history: ".concat((0, _printComponent.default)(this.getKeyHistory().toJSON()), "."));
}
}, {
key: "_addToAndLogCurrentKeyCombination",
value: function _addToAndLogCurrentKeyCombination(keyName, eventRecordIndex, focusTreeId, componentId, keyEventState) {
this._addToCurrentKeyCombination(keyName, eventRecordIndex, keyEventState);
value: function _addToAndLogCurrentKeyCombination(keyName, keyEventType, focusTreeId, componentId, keyEventState) {
this.getKeyHistory().addKeyToCurrentCombination(keyName, keyEventType, keyEventState);
if (eventRecordIndex === _KeyEventRecordIndex.default.keydown) {
if (keyEventType === _KeyEventType.default.keydown) {
this.logger.verbose(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Added '".concat(keyName, "' to current combination: '").concat(this._getCurrentKeyCombination().ids[0], "'."));
}), "Added '".concat(keyName, "' to current combination: '").concat(this.getCurrentCombination().describe(), "'."));
}

@@ -820,3 +598,3 @@

focusTreeId: focusTreeId
}), "Key history: ".concat((0, _printComponent.default)(this.keyCombinationHistory), "."));
}), "Key history: ".concat((0, _printComponent.default)(this.getKeyHistory().toJSON()), "."));
}

@@ -828,14 +606,2 @@ /********************************************************************************

}, {
key: "_stopEventPropagation",
value: function _stopEventPropagation(event, componentId) {
if (!this.eventPropagationState.stopping) {
this.eventPropagationState.stopping = true;
this.logger.debug(this._logPrefix(componentId), 'Stopping further event propagation.');
if (!event.simulated) {
event.stopPropagation();
}
}
}
}, {
key: "_handleEventSimulation",

@@ -868,3 +634,3 @@ value: function _handleEventSimulation(listName, handlerName, shouldSimulate, _ref) {

if (this._isFocusTreeRoot(componentId) || this.eventPropagationState.stopping) {
if (this.componentList.isRoot(componentId) || this.eventPropagator.isStopped()) {
if (!this.keyEventManager.isGlobalListenersBound()) {

@@ -883,3 +649,3 @@ this[handlerName]();

value: function simulatePendingKeyPressEvents() {
this._simulatePendingKeyEvents('keypressEventsToSimulate', 'handleKeypress');
this._simulatePendingKeyEvents('keypressEventsToSimulate', 'handleKeyPress');
}

@@ -889,3 +655,3 @@ }, {

value: function simulatePendingKeyUpEvents() {
this._simulatePendingKeyEvents('keyupEventsToSimulate', 'handleKeyup');
this._simulatePendingKeyEvents('keyupEventsToSimulate', 'handleKeyUp');
}

@@ -910,10 +676,2 @@ }, {

this[listName] = [];
/**
* If an event gets handled and causes a focus shift, then subsequent components
* will ignore the event (including the root component) and the conditions to
* reset the propagation state are never met - so we ensure that after we are done
* simulating the keypress event, the propagation state is reset
*/
this._clearEventPropagationState();
}

@@ -929,3 +687,3 @@ /********************************************************************************

* @param {NormalizedKeyName} keyName Normalized key name
* @param {KeyEventRecordIndex} eventRecordIndex The record index of the current key event type
* @param {KeyEventType} keyEventType The record index of the current key event type
* @param {FocusTreeId} focusTreeId Id of focus tree component thinks it's apart of

@@ -939,31 +697,29 @@ * @param {ComponentId} componentId Index of the component that is currently handling

key: "_callHandlerIfActionNotHandled",
value: function _callHandlerIfActionNotHandled(event, keyName, eventRecordIndex, componentId, focusTreeId) {
var eventName = (0, _describeKeyEventType.default)(eventRecordIndex);
value: function _callHandlerIfActionNotHandled(event, keyName, keyEventType, componentId, focusTreeId) {
var eventName = (0, _describeKeyEventType.default)(keyEventType);
var combinationName = this.getCurrentCombination().describe();
var combinationName = this._describeCurrentKeyCombination();
if (!this.componentList.anyActionsForEventType(keyEventType)) {
this.logger.verbose(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Ignored '".concat(combinationName, "' ").concat(eventName, " because it doesn't have any ").concat(eventName, " handlers."));
return;
}
if (this.keyMapEventRecord[eventRecordIndex]) {
if (this.eventPropagationState.actionHandled) {
this.logger.debug(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Ignored '".concat(combinationName, "' ").concat(eventName, " as it has already been handled."));
} else {
this.logger.verbose(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Attempting to find action matching '".concat(combinationName, "' ").concat(eventName, " . . ."));
var previousComponentPosition = this.eventPropagationState.previousComponentPosition;
if (this.eventPropagator.isHandled()) {
this.logger.debug(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Ignored '".concat(combinationName, "' ").concat(eventName, " as it has already been handled."));
} else {
this.logger.verbose(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Attempting to find action matching '".concat(combinationName, "' ").concat(eventName, " . . ."));
var previousComponentPosition = this.eventPropagator.getPreviousPosition();
var componentPosition = this.componentList.getIndexById(componentId);
var componentPosition = this._getComponentPosition(componentId);
var handlerWasCalled = this._callClosestMatchingHandler(event, keyName, keyEventType, componentPosition, previousComponentPosition === -1 ? 0 : previousComponentPosition);
var handlerWasCalled = this._callMatchingHandlerClosestToEventTarget(event, keyName, eventRecordIndex, componentPosition, previousComponentPosition === -1 ? 0 : previousComponentPosition);
if (handlerWasCalled) {
this.eventPropagationState.actionHandled = true;
this.currentEvent.handled = true;
}
if (handlerWasCalled) {
this.eventPropagator.setHandled();
}
} else {
this.logger.verbose(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Ignored '".concat(combinationName, "' ").concat(eventName, " because it doesn't have any ").concat(eventName, " handlers."));
}

@@ -995,5 +751,4 @@ }

base += "C".concat(componentId).concat(componentIcons[componentId % componentIcons.length]);
var position = this.componentList.getIndexById(componentId);
var position = this._getComponentPosition(componentId);
if (!(0, _isUndefined.default)(position)) {

@@ -1000,0 +755,0 @@ base += "-P".concat(position).concat(componentIcons[position % componentIcons.length], ":");

@@ -8,18 +8,12 @@ "use strict";

var _KeyEventRecordManager = _interopRequireDefault(require("../KeyEventRecordManager"));
var _KeyEventType = _interopRequireDefault(require("../../const/KeyEventType"));
var _KeyEventRecordIndex = _interopRequireDefault(require("../../const/KeyEventRecordIndex"));
var _AbstractKeyEventStrategy = _interopRequireDefault(require("./AbstractKeyEventStrategy"));
var _capitalize = _interopRequireDefault(require("../../utils/string/capitalize"));
var _describeKeyEventType = _interopRequireDefault(require("../../helpers/logging/describeKeyEventType"));
var _KeyEventCounter = _interopRequireDefault(require("../KeyEventCounter"));
var _KeyEventCounter = _interopRequireDefault(require("../listening/KeyEventCounter"));
var _Logger = _interopRequireDefault(require("../Logger"));
var _Logger = _interopRequireDefault(require("../logging/Logger"));
var _removeAtIndex = _interopRequireDefault(require("../../utils/array/removeAtIndex"));
var _isUndefined = _interopRequireDefault(require("../../utils/isUndefined"));

@@ -31,3 +25,3 @@

var _Configuration = _interopRequireDefault(require("../Configuration"));
var _Configuration = _interopRequireDefault(require("../config/Configuration"));

@@ -42,4 +36,6 @@ var _describeKeyEvent = _interopRequireDefault(require("../../helpers/logging/describeKeyEvent"));

var _dictionaryFrom = _interopRequireDefault(require("../../utils/object/dictionaryFrom"));
var _stateFromEvent = _interopRequireDefault(require("../../helpers/parsing-key-maps/stateFromEvent"));
var _normalizeEventName = _interopRequireDefault(require("../../utils/string/normalizeEventName"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

@@ -49,10 +45,2 @@

function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -149,3 +137,3 @@

this._addComponentToList(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this._addComponent(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);

@@ -165,3 +153,3 @@ this._updateDocumentHandlers();

eventId: false
}), 'Component options: \n', (0, _printComponent.default)(this._getComponent(componentId)));
}), 'Component options: \n', (0, _printComponent.default)(this.componentList.get(componentId)));
}

@@ -188,18 +176,8 @@ /**

this.eventOptions = eventOptions;
var componentPosition = this._getComponentPosition(componentId);
this.componentList.update(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this.getKeyHistory().setMaxLength(this.componentList.getLongestSequence());
/**
* Manually update the registered key map state, usually reset using
* _resetRegisteredKeyMapsState() method
*/
this.componentList[componentPosition] = this._buildComponentOptions(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this._updateLongestKeySequenceIfNecessary(componentId);
/**
* Reset strategy state specific to the global strategy
*/
this._updateDocumentHandlers();

@@ -218,3 +196,3 @@ /**

eventId: false
}), 'Component options: \n', (0, _printComponent.default)(this._getComponent(componentId)));
}), 'Component options: \n', (0, _printComponent.default)(this.componentList.get(componentId)));
}

@@ -229,6 +207,2 @@ /**

value: function disableHotKeys(componentId) {
var _this$_getComponentAn = this._getComponentAndPosition(componentId),
_this$_getComponentAn2 = _slicedToArray(_this$_getComponentAn, 2),
keyMapEventRecord = _this$_getComponentAn2[0].keyMapEventRecord,
componentPosition = _this$_getComponentAn2[1];
/**

@@ -238,18 +212,7 @@ * Manually update the registered key map state, usually reset using

*/
this.componentList.remove(componentId);
this.getKeyHistory().setMaxLength(this.componentList.getLongestSequence());
this.componentList = (0, _removeAtIndex.default)(this.componentList, componentPosition);
this._updateLongestKeySequenceIfNecessary(componentId);
this._updateDocumentHandlers();
/**
* Reset strategy state specific to the global strategy
*/
this._updateComponentIndexDictFromList({
startingAt: componentPosition
});
this._updateDocumentHandlers(keyMapEventRecord, _KeyEventRecordManager.default.newRecord());
/**
* Reset handler resolution state

@@ -266,35 +229,5 @@ */

}, {
key: "_updateLongestKeySequenceIfNecessary",
value: function _updateLongestKeySequenceIfNecessary(componentId) {
var _this2 = this;
if (componentId === this.longestSequenceComponentIndex) {
this.longestSequence = 1;
this.componentList.forEach(function (_ref) {
var longestSequence = _ref.longestSequence;
if (longestSequence > _this2.longestSequence) {
_this2.longestSequence = longestSequence;
}
});
}
}
}, {
key: "_updateComponentIndexDictFromList",
value: function _updateComponentIndexDictFromList() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
startingAt: 0
};
var counter = options.startingAt;
while (counter < this.componentList.length) {
this._setComponentPosition(this.componentList[counter].componentId, counter);
counter++;
}
}
}, {
key: "_updateDocumentHandlers",
value: function _updateDocumentHandlers() {
var _this3 = this;
var _this2 = this;

@@ -304,28 +237,23 @@ var listenersShouldBeBound = this._listenersShouldBeBound();

if (!this.listenersBound && listenersShouldBeBound) {
var _loop = function _loop(recordIndex) {
Object.values(_KeyEventType.default).forEach(function (recordIndex) {
var eventName = (0, _describeKeyEventType.default)(recordIndex);
document["on".concat(eventName)] = function (keyEvent) {
_this3.keyEventManager["handleGlobal".concat((0, _capitalize.default)(eventName))](keyEvent);
_this2.keyEventManager["handleGlobal".concat((0, _normalizeEventName.default)(eventName))](keyEvent);
};
_this3.logger.debug(_this3._logPrefix(_this3.componentId, {
_this2.logger.debug(_this2._logPrefix(_this2.componentId, {
eventId: false
}), "Bound handler handleGlobal".concat((0, _capitalize.default)(eventName), "() to document.on").concat(eventName, "()"));
};
for (var recordIndex = 0; recordIndex < this.keyMapEventRecord.length; recordIndex++) {
_loop(recordIndex);
}
}), "Bound handler handleGlobal".concat((0, _normalizeEventName.default)(eventName), "() to document.on").concat(eventName, "()"));
});
this.listenersBound = true;
} else if (this.listenersBound && !listenersShouldBeBound) {
for (var recordIndex = 0; recordIndex < this.keyMapEventRecord.length; recordIndex++) {
Object.values(_KeyEventType.default).forEach(function (recordIndex) {
var eventName = (0, _describeKeyEventType.default)(recordIndex);
delete document["on".concat(eventName)];
this.logger.debug(this._logPrefix(this.componentId, {
_this2.logger.debug(_this2._logPrefix(_this2.componentId, {
eventId: false
}), "Removed handler handleGlobal".concat((0, _capitalize.default)(eventName), "() from document.on").concat(eventName, "()"));
}
}), "Removed handler handleGlobal".concat((0, _normalizeEventName.default)(eventName), "() from document.on").concat(eventName, "()"));
});
this.listenersBound = false;

@@ -345,3 +273,3 @@ }

value: function _listenersShouldBeBound() {
return this.componentList.length > 0 || this.listeners.keyCombination;
return this.componentList.any() || this.listeners.keyCombination;
}

@@ -368,12 +296,12 @@ /********************************************************************************

if (event.repeat && _Configuration.default.option('ignoreRepeatedEventsWhenKeyHeldDown')) {
this.logger.debug(this._logPrefix(), "Ignored repeated ".concat((0, _describeKeyEvent.default)(event, _key, _KeyEventRecordIndex.default.keydown), " event."));
this.logger.debug(this._logPrefix(), "Ignored repeated ".concat((0, _describeKeyEvent.default)(event, _key, _KeyEventType.default.keydown), " event."));
return true;
}
this._checkForModifierFlagDiscrepancies(event, _key, _KeyEventRecordIndex.default.keydown);
this._checkForModifierFlagDiscrepancies(event, _key, _KeyEventType.default.keydown);
var reactAppResponse = this._howReactAppRespondedTo(event, _key, _KeyEventRecordIndex.default.keydown);
var reactAppResponse = this._howReactAppRespondedTo(event, _key, _KeyEventType.default.keydown);
if (reactAppResponse === _EventResponse.default.unseen && this.eventOptions.ignoreEventsCondition(event)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, _key, _KeyEventRecordIndex.default.keydown), " event because ignoreEventsFilter rejected it."));
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, _key, _KeyEventType.default.keydown), " event because ignoreEventsFilter rejected it."));
return;

@@ -383,10 +311,9 @@ }

if (reactAppResponse !== _EventResponse.default.ignored) {
var keyInCurrentCombination = !!this._getCurrentKeyState(_key);
var keyEventState = (0, _stateFromEvent.default)(event);
var currentCombination = this.getCurrentCombination();
var keyEventState = this._stateFromEvent(event);
if (keyInCurrentCombination || this.keyCombinationIncludesKeyUp) {
this._startAndLogNewKeyCombination(_key, _KeyEventRecordIndex.default.keydown, keyEventState);
if (currentCombination.isKeyIncluded(_key) || currentCombination.isEnding()) {
this._startAndLogNewKeyCombination(_key, keyEventState);
} else {
this._addToAndLogCurrentKeyCombination(_key, _KeyEventRecordIndex.default.keydown, keyEventState);
this._addToAndLogCurrentKeyCombination(_key, _KeyEventType.default.keydown, keyEventState);
}

@@ -396,23 +323,23 @@ }

if (!(0, _contains.default)([_EventResponse.default.ignored, _EventResponse.default.handled], reactAppResponse)) {
this._callHandlerIfExists(event, _key, _KeyEventRecordIndex.default.keydown);
this._callHandlerIfExists(event, _key, _KeyEventType.default.keydown);
}
this._simulateKeypressForNonPrintableKeys(event, _key);
this._simulateKeyPressForNonPrintableKeys(event, _key);
}
}, {
key: "_howReactAppRespondedTo",
value: function _howReactAppRespondedTo(event, key, eventRecordIndex) {
var reactAppHistoryWithEvent = this.keyEventManager.reactAppHistoryWithEvent(key, eventRecordIndex);
value: function _howReactAppRespondedTo(event, key, keyEventType) {
var reactAppHistoryWithEvent = this.keyEventManager.reactAppHistoryWithEvent(key, keyEventType);
switch (reactAppHistoryWithEvent) {
case _EventResponse.default.handled:
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, eventRecordIndex), " event because React app has already handled it."));
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, keyEventType), " event because React app has already handled it."));
break;
case _EventResponse.default.ignored:
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, eventRecordIndex), " event because React app has declared it should be ignored."));
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, keyEventType), " event because React app has declared it should be ignored."));
break;
case _EventResponse.default.seen:
this.logger.debug(this._logPrefix(), "Received ".concat((0, _describeKeyEvent.default)(event, key, eventRecordIndex), " event (that has already passed through React app)."));
this.logger.debug(this._logPrefix(), "Received ".concat((0, _describeKeyEvent.default)(event, key, keyEventType), " event (that has already passed through React app)."));
break;

@@ -423,3 +350,3 @@

this.logger.debug(this._logPrefix(), "New ".concat((0, _describeKeyEvent.default)(event, key, eventRecordIndex), " event (that has NOT passed through React app)."));
this.logger.debug(this._logPrefix(), "New ".concat((0, _describeKeyEvent.default)(event, key, keyEventType), " event (that has NOT passed through React app)."));
}

@@ -440,13 +367,15 @@

}, {
key: "handleKeypress",
value: function handleKeypress(event) {
key: "handleKeyPress",
value: function handleKeyPress(event) {
var key = (0, _getKeyName.default)(event);
if (event.repeat && _Configuration.default.option('ignoreRepeatedEventsWhenKeyHeldDown')) {
this.logger.debug(this._logPrefix(), "Ignored repeated ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventRecordIndex.default.keypress), " event."));
this.logger.debug(this._logPrefix(), "Ignored repeated ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventType.default.keypress), " event."));
return true;
}
if (this._alreadySimulatedEvent(_KeyEventRecordIndex.default.keypress, key)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventRecordIndex.default.keypress), " as it was not expected, and has already been simulated."));
var currentCombination = this.getCurrentCombination();
if (currentCombination.isKeyPressSimulated(key)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventType.default.keypress), " as it was not expected, and has already been simulated."));
return true;

@@ -460,3 +389,3 @@ }

var reactAppResponse = this._howReactAppRespondedTo(event, key, _KeyEventRecordIndex.default.keypress);
var reactAppResponse = this._howReactAppRespondedTo(event, key, _KeyEventType.default.keypress);
/**

@@ -467,4 +396,4 @@ * Add new key event to key combination history

if (this._getCurrentKeyState(key)) {
this._addToAndLogCurrentKeyCombination(key, _KeyEventRecordIndex.default.keypress, this._stateFromEvent(event));
if (currentCombination.isKeyIncluded(key)) {
this._addToAndLogCurrentKeyCombination(key, _KeyEventType.default.keypress, (0, _stateFromEvent.default)(event));
}

@@ -479,6 +408,6 @@

*/
this.keyEventManager.closeHangingKeyCombination(key, _KeyEventRecordIndex.default.keypress);
this.keyEventManager.closeHangingKeyCombination(key, _KeyEventType.default.keypress);
if (this.eventOptions.ignoreEventsCondition(event)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventRecordIndex.default.keypress), " event because ignoreEventsFilter rejected it."));
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventType.default.keypress), " event because ignoreEventsFilter rejected it."));
return;

@@ -489,3 +418,3 @@ }

if (!(0, _contains.default)([_EventResponse.default.ignored, _EventResponse.default.handled], reactAppResponse)) {
this._callHandlerIfExists(event, key, _KeyEventRecordIndex.default.keypress);
this._callHandlerIfExists(event, key, _KeyEventType.default.keypress);
}

@@ -504,8 +433,9 @@ }

}, {
key: "handleKeyup",
value: function handleKeyup(event) {
key: "handleKeyUp",
value: function handleKeyUp(event) {
var key = (0, _getKeyName.default)(event);
var currentCombination = this.getCurrentCombination();
if (this._alreadySimulatedEvent(_KeyEventRecordIndex.default.keyup, key)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventRecordIndex.default.keyup), " as it was not expected, and has already been simulated."));
if (currentCombination.isKeyUpSimulated(key)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventType.default.keyup), " as it was not expected, and has already been simulated."));
return true;

@@ -519,3 +449,3 @@ }

var reactAppResponse = this._howReactAppRespondedTo(event, key, _KeyEventRecordIndex.default.keyup);
var reactAppResponse = this._howReactAppRespondedTo(event, key, _KeyEventType.default.keyup);
/**

@@ -529,4 +459,4 @@ * We then add the keyup to our current combination - regardless of whether

if (this._getCurrentKeyState(key)) {
this._addToAndLogCurrentKeyCombination(key, _KeyEventRecordIndex.default.keyup, this._stateFromEvent(event));
if (currentCombination.isKeyIncluded(key)) {
this._addToAndLogCurrentKeyCombination(key, _KeyEventType.default.keyup, (0, _stateFromEvent.default)(event));
}

@@ -540,6 +470,6 @@

*/
this.keyEventManager.closeHangingKeyCombination(key, _KeyEventRecordIndex.default.keyup);
this.keyEventManager.closeHangingKeyCombination(key, _KeyEventType.default.keyup);
if (this.eventOptions.ignoreEventsCondition(event)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventRecordIndex.default.keyup), " event because ignoreEventsFilter rejected it."));
this.logger.debug(this._logPrefix(), "Ignored ".concat((0, _describeKeyEvent.default)(event, key, _KeyEventType.default.keyup), " event because ignoreEventsFilter rejected it."));
} else {

@@ -551,3 +481,3 @@ /**

if (!(0, _contains.default)([_EventResponse.default.ignored, _EventResponse.default.handled], reactAppResponse)) {
this._callHandlerIfExists(event, key, _KeyEventRecordIndex.default.keyup);
this._callHandlerIfExists(event, key, _KeyEventType.default.keyup);
}

@@ -561,3 +491,3 @@ }

if (!(0, _contains.default)([_EventResponse.default.ignored, _EventResponse.default.handled], reactAppResponse)) {
this._callHandlerIfExists(event, key, _KeyEventRecordIndex.default.keyup);
this._callHandlerIfExists(event, key, _KeyEventType.default.keyup);
}

@@ -574,9 +504,5 @@ }

if (this.listeners.keyCombination && this._allKeysAreReleased()) {
var _this$_getCurrentKeyC = this._getCurrentKeyCombination(),
keys = _this$_getCurrentKeyC.keys,
ids = _this$_getCurrentKeyC.ids;
this.listeners.keyCombination({
keys: (0, _dictionaryFrom.default)(Object.keys(keys), true),
id: ids[0]
keys: currentCombination.getKeyDictionary(),
id: currentCombination.describe()
});

@@ -586,7 +512,7 @@ }

}, {
key: "_simulateKeypressForNonPrintableKeys",
value: function _simulateKeypressForNonPrintableKeys(event, key) {
key: "_simulateKeyPressForNonPrintableKeys",
value: function _simulateKeyPressForNonPrintableKeys(event, key) {
this.keyEventManager.simulatePendingKeyPressEvents();
this._handleEventSimulation('handleKeypress', this._shouldSimulate(_KeyEventRecordIndex.default.keypress, key), {
this._handleEventSimulation('handleKeyPress', this._shouldSimulate(_KeyEventType.default.keypress, key), {
event: event,

@@ -599,3 +525,3 @@ key: key

value: function _simulateKeyUpEventsHiddenByCmd(event, key) {
var _this4 = this;
var _this3 = this;

@@ -607,3 +533,3 @@ if ((0, _isCmdKey.default)(key)) {

this.keyEventManager.simulatePendingKeyUpEvents();
Object.keys(this._getCurrentKeyCombination().keys).forEach(function (keyName) {
this.getCurrentCombination().forEachKey(function (keyName) {
if ((0, _isCmdKey.default)(keyName)) {

@@ -613,3 +539,3 @@ return;

_this4._handleEventSimulation('handleKeyup', _this4._shouldSimulate(_KeyEventRecordIndex.default.keyup, keyName), {
_this3._handleEventSimulation('handleKeyUp', _this3._shouldSimulate(_KeyEventType.default.keyup, keyName), {
event: event,

@@ -623,18 +549,17 @@ key: keyName

key: "_startAndLogNewKeyCombination",
value: function _startAndLogNewKeyCombination(keyName, eventRecordIndex, keyEventState) {
this._startNewKeyCombination(keyName, eventRecordIndex, keyEventState);
value: function _startAndLogNewKeyCombination(keyName, keyEventState) {
this.getKeyHistory().startNewKeyCombination(keyName, keyEventState);
this.logger.verbose(this._logPrefix(), "Started a new combination with '".concat(keyName, "'."));
this.logger.verbose(this._logPrefix(), "Key history: ".concat((0, _printComponent.default)(this.keyCombinationHistory), "."));
this.logger.verbose(this._logPrefix(), "Key history: ".concat((0, _printComponent.default)(this.getKeyHistory().toJSON()), "."));
}
}, {
key: "_addToAndLogCurrentKeyCombination",
value: function _addToAndLogCurrentKeyCombination(keyName, eventRecordIndex, keyEventState) {
this._addToCurrentKeyCombination(keyName, eventRecordIndex, keyEventState);
value: function _addToAndLogCurrentKeyCombination(keyName, keyEventType, keyEventState) {
this.getKeyHistory().addKeyToCurrentCombination(keyName, keyEventType, keyEventState);
if (eventRecordIndex === _KeyEventRecordIndex.default.keydown) {
this.logger.verbose(this._logPrefix(), "Added '".concat(keyName, "' to current combination: '").concat(this._getCurrentKeyCombination().ids[0], "'."));
if (keyEventType === _KeyEventType.default.keydown) {
this.logger.verbose(this._logPrefix(), "Added '".concat(keyName, "' to current combination: '").concat(this.getCurrentCombination().describe(), "'."));
}
this.logger.verbose(this._logPrefix(), "Key history: ".concat((0, _printComponent.default)(this.keyCombinationHistory), "."));
this.logger.verbose(this._logPrefix(), "Key history: ".concat((0, _printComponent.default)(this.getKeyHistory().toJSON()), "."));
}

@@ -647,5 +572,5 @@ /********************************************************************************

key: "_handleEventSimulation",
value: function _handleEventSimulation(handlerName, shouldSimulate, _ref2) {
var event = _ref2.event,
key = _ref2.key;
value: function _handleEventSimulation(handlerName, shouldSimulate, _ref) {
var event = _ref.event,
key = _ref.key;

@@ -671,18 +596,8 @@ if (shouldSimulate && _Configuration.default.option('simulateMissingKeyPressEvents')) {

key: "_callHandlerIfExists",
value: function _callHandlerIfExists(event, keyName, eventRecordIndex) {
var eventName = (0, _describeKeyEventType.default)(eventRecordIndex);
value: function _callHandlerIfExists(event, keyName, keyEventType) {
var eventName = (0, _describeKeyEventType.default)(keyEventType);
var combinationName = this.getCurrentCombination().describe();
var combinationName = this._describeCurrentKeyCombination();
if (this.keyMapEventRecord[eventRecordIndex]) {
if (!this.componentList.anyActionsForEventType(keyEventType)) {
/**
* If there is at least one handler for the specified key event type (keydown,
* keypress, keyup), then attempt to find a handler that matches the current
* key combination
*/
this.logger.verbose(this._logPrefix(), "Attempting to find action matching '".concat(combinationName, "' ").concat(eventName, " . . ."));
this._callMatchingHandlerClosestToEventTarget(event, keyName, eventRecordIndex);
} else {
/**
* If there are no handlers registered for the particular key event type

@@ -693,10 +608,23 @@ * (keydown, keypress, keyup) then skip trying to find a matching handler

this.logger.debug(this._logPrefix(), "Ignored '".concat(combinationName, "' ").concat(eventName, " because it doesn't have any ").concat(eventName, " handlers."));
return;
}
/**
* If there is at least one handler for the specified key event type (keydown,
* keypress, keyup), then attempt to find a handler that matches the current
* key combination
*/
this.logger.verbose(this._logPrefix(), "Attempting to find action matching '".concat(combinationName, "' ").concat(eventName, " . . ."));
this._callClosestMatchingHandler(event, keyName, keyEventType);
}
}, {
key: "_callMatchingHandlerClosestToEventTarget",
value: function _callMatchingHandlerClosestToEventTarget(event, keyName, eventRecordIndex) {
for (var componentPosition = 0; componentPosition < this.componentList.length; componentPosition++) {
var matchFound = _get(_getPrototypeOf(GlobalKeyEventStrategy.prototype), "_callMatchingHandlerClosestToEventTarget", this).call(this, event, keyName, eventRecordIndex, componentPosition, 0);
key: "_callClosestMatchingHandler",
value: function _callClosestMatchingHandler(event, keyName, keyEventType) {
var componentListIterator = this.componentList.getNewIterator();
while (componentListIterator.next()) {
var matchFound = _get(_getPrototypeOf(GlobalKeyEventStrategy.prototype), "_callClosestMatchingHandler", this).call(this, event, keyName, keyEventType, componentListIterator.getPosition(), 0);
if (matchFound) {

@@ -733,6 +661,6 @@ this.logger.debug(this._logPrefix(), "Searching no further, as handler has been found (and called).");

value: function addKeyCombinationListener(callbackFunction) {
var _this5 = this;
var _this4 = this;
var cancel = function cancel() {
delete _this5.listeners.keyCombination;
delete _this4.listeners.keyCombination;
};

@@ -739,0 +667,0 @@

@@ -10,3 +10,3 @@ "use strict";

var _Configuration = _interopRequireDefault(require("./lib/Configuration"));
var _Configuration = _interopRequireDefault(require("./lib/config/Configuration"));

@@ -80,4 +80,4 @@ var _withHotKeysIgnoreOverride = _interopRequireDefault(require("./withHotKeysIgnoreOverride"));

var _default = (0, _withHotKeysIgnoreOverride.default)(ObserveKeys, {}, 'forceObserveEvent');
var _default = (0, _withHotKeysIgnoreOverride.default)(ObserveKeys, {}, 'observeIgnoredEvents');
exports.default = _default;

@@ -11,3 +11,3 @@ "use strict";

* @param {Array.<T>} array Array to iterate over to find the item
* @param {Number} placesFromEnd Number of places from the end of the array to find
* @param {number} placesFromEnd Number of places from the end of the array to find
* the item to return

@@ -14,0 +14,0 @@ * @returns {T} The item found in the array at the particular index

@@ -34,3 +34,3 @@ "use strict";

* values of the context instance used provide context to descendant components
* @returns {Component} Component that has now had the specified context applied
* @returns {React.Component} Component that has now had the specified context applied
*/

@@ -37,0 +37,0 @@ function backwardsCompatibleContext(Component, _ref) {

@@ -18,3 +18,3 @@ "use strict";

* @param {String[]} attributes List of attributes to copy
* @return {Object} The target object, now with the copied attributes
* @returns {Object} The target object, now with the copied attributes
*/

@@ -21,0 +21,0 @@ function copyAttributes(source, target, attributes) {

@@ -23,3 +23,3 @@ "use strict";

* @param {object} nativeEvent Native browser event.
* @return {number} Normalized `charCode` property.
* @returns {number} Normalized `charCode` property.
*/

@@ -26,0 +26,0 @@ function getEventCharCode(nativeEvent) {

@@ -43,3 +43,3 @@ "use strict";

* @param {object} nativeEvent Native browser event.
* @return {string} Normalized `key` property.
* @returns {string} Normalized `key` property.
*/

@@ -46,0 +46,0 @@

@@ -12,3 +12,3 @@ "use strict";

var _Configuration = _interopRequireDefault(require("./lib/Configuration"));
var _Configuration = _interopRequireDefault(require("./lib/config/Configuration"));

@@ -19,3 +19,3 @@ var _KeyEventManager = _interopRequireDefault(require("./lib/KeyEventManager"));

var _KeyCombinationSerializer = _interopRequireDefault(require("./lib/KeyCombinationSerializer"));
var _KeyCombinationSerializer = _interopRequireDefault(require("./lib/shared/KeyCombinationSerializer"));

@@ -89,2 +89,3 @@ var _backwardsCompatibleContext = _interopRequireDefault(require("./utils/backwardsCompatibleContext"));

* sequence of events matches a list of pre-defined sequences or combinations
* @class
*/

@@ -211,3 +212,3 @@

key: "componentDidUpdate",
value: function componentDidUpdate(previousProps) {
value: function componentDidUpdate() {
var keyEventManager = _KeyEventManager.default.getInstance();

@@ -325,3 +326,3 @@

value: function _handleKeyPress(event) {
var discardFocusTreeId = _KeyEventManager.default.getInstance().handleKeypress(event, this._getFocusTreeId(), this._id, this._getEventOptions());
var discardFocusTreeId = _KeyEventManager.default.getInstance().handleKeyPress(event, this._getFocusTreeId(), this._id, this._getEventOptions());

@@ -341,3 +342,3 @@ if (discardFocusTreeId) {

value: function _handleKeyUp(event) {
var discardFocusTreeId = _KeyEventManager.default.getInstance().handleKeyup(event, this._getFocusTreeId(), this._id, this._getEventOptions());
var discardFocusTreeId = _KeyEventManager.default.getInstance().handleKeyUp(event, this._getFocusTreeId(), this._id, this._getEventOptions());

@@ -371,3 +372,3 @@ if (discardFocusTreeId) {

* functions at a later stage
* @typedef {String} ActionName
* @typedef {string} ActionName
*/

@@ -393,6 +394,6 @@

* KeyEventDescription
* @property {String} name - The name of the action, to be displayed to the end user
* @property {String} description - A description of the action, to be displayed to
* @property {string} name - The name of the action, to be displayed to the end user
* @property {string} description - A description of the action, to be displayed to
* the end user
* @property {String} group - A group the action belongs to, to aid in showing similar
* @property {string} group - A group the action belongs to, to aid in showing similar
* actions to the user

@@ -403,3 +404,3 @@ */

* A description of key sequence of one or more key combinations
* @typedef {MouseTrapKeySequence|KeyEventOptions|Array<MouseTrapKeySequence>} KeyEventDescription
* @typedef {MouseTrapKeySequence|KeyEventOptions|Array.<MouseTrapKeySequence>} KeyEventDescription
*/

@@ -420,3 +421,3 @@

* A map from action names to event handler functions
* @typedef {Object<ActionName, Function>} HandlersMap
* @typedef {Object.<ActionName, Function>} HandlersMap
*/

@@ -432,3 +433,3 @@

* Function to call when this component gains focus in the browser
* @type {Function}
* @type {function}
*/

@@ -439,3 +440,3 @@ onFocus: _propTypes.default.func,

* Function to call when this component loses focus in the browser
* @type {Function}
* @type {function}
*/

@@ -442,0 +443,0 @@ onBlur: _propTypes.default.func,

@@ -34,2 +34,4 @@ "use strict";

var _hasKey = _interopRequireDefault(require("./utils/object/hasKey"));
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

@@ -75,2 +77,4 @@

* default prop values
* @param {string} eventManagerMethod - Name of EventManager method to use to handle a
* key event
* @returns {React.ComponentClass} Wrapped component that is passed all of the React

@@ -93,2 +97,3 @@ * hotkeys props in a single value, hotkeys.

* the only prop to provide a whitelist, or the except prop to pass a blacklist.
* @class
*/

@@ -147,9 +152,9 @@ return _temp = _class =

} else {
return !this._exceptDict[key];
return !(0, _hasKey.default)(this._exceptDict, key);
}
} else {
if ((0, _isEmpty.default)(this._exceptDict)) {
return this._onlyDict[key];
return (0, _hasKey.default)(this._onlyDict, key);
} else {
return this._onlyDict[key] && !this._exceptDict[key];
return (0, _hasKey.default)(this._onlyDict, key) && !(0, _hasKey.default)(this._exceptDict, key);
}

@@ -156,0 +161,0 @@ }

@@ -24,3 +24,3 @@ "use strict";

};
return (0, _withHotKeysIgnoreOverride.default)(Component, hotKeysIgnoreOptions, 'forceObserveEvent');
return (0, _withHotKeysIgnoreOverride.default)(Component, hotKeysIgnoreOptions, 'observeIgnoredEvents');
}

@@ -27,0 +27,0 @@

@@ -6,3 +6,3 @@ /**

*/
import Configuration from './lib/Configuration';
import Configuration from './lib/config/Configuration';

@@ -9,0 +9,0 @@ function configure() {

/**
* @typedef {Number} EventResponseType
* @typedef {number} EventResponseType
*/

@@ -4,0 +4,0 @@

/**
* Enum for index values for KeyEventRecords
* Enum for index values for KeyEvents
* @readonly
* @enum {Number}
* @enum {number}
*/

@@ -6,0 +6,0 @@ var KeyEventSequenceIndex = {

@@ -23,3 +23,3 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

import { Component } from 'react';
import Configuration from './lib/Configuration';
import Configuration from './lib/config/Configuration';
import KeyEventManager from './lib/KeyEventManager';

@@ -126,3 +126,3 @@ import backwardsCompatibleContext from './utils/backwardsCompatibleContext';

* A map from action names to event handler functions
* @typedef {Object<ActionName, Function>} HandlersMap
* @typedef {Object.<ActionName, Function>} HandlersMap
*/

@@ -129,0 +129,0 @@

import describeKeyEventType from './describeKeyEventType';
function describeKeyEvent(event, keyName, keyEventRecordIndex) {
var eventDescription = "'".concat(keyName, "' ").concat(describeKeyEventType(keyEventRecordIndex));
function describeKeyEvent(event, keyName, keyEventType) {
var eventDescription = "'".concat(keyName, "' ").concat(describeKeyEventType(keyEventType));

@@ -6,0 +6,0 @@ if (event.simulated) {

/**
* Returns the name of the event at a specified event record index
* @param {KeyEventRecordIndex} eventRecordIndex
* @param {KeyEventType} keyEventType
* @returns {KeyEventName} Name of the key event
*/
function describeKeyEventType(eventRecordIndex) {
switch (parseInt(eventRecordIndex, 10)) {
function describeKeyEventType(keyEventType) {
switch (parseInt(keyEventType, 10)) {
case 0:

@@ -9,0 +9,0 @@ return 'keydown';

@@ -1,6 +0,6 @@

import Configuration from '../../lib/Configuration';
import Configuration from '../../lib/config/Configuration';
/**
* Whether the specified key name is among those defined as custom key codes
* @param {ReactKeyName} keyName Name of the key
* @return {Boolean} true if keyName matches a custom key name
* @returns {boolean} true if keyName matches a custom key name
*/

@@ -7,0 +7,0 @@

import MousetrapToReactKeyNamesDictionary from '../../const/MousetrapToReactKeyNamesDictionary';
import KeyShorthandDictionary from '../../const/KeyShorthandDictionary';
/**
* @typedef {String} KeyName Name of the keyboard key
* @typedef {string} KeyName Name of the keyboard key
*/
/**
* @typedef {String} ReactKeyName Name used by React to refer to key
* @typedef {string} ReactKeyName Name used by React to refer to key
*/

@@ -10,0 +10,0 @@

/**
* Lowercased string representing a particular keyboard key
* @typedef {String} NormalizedKeyName
* @typedef {string} NormalizedKeyName
*/
import reactsGetEventKey from '../../vendor/react-dom/reactsGetEventKey';
import Configuration from '../../lib/Configuration';
import Configuration from '../../lib/config/Configuration';
import hasKey from '../../utils/object/hasKey';

@@ -8,0 +8,0 @@ /**

@@ -5,3 +5,3 @@ import isNonPrintableKeyName from '../parsing-key-maps/isNonPrintableKeyName';

* @param {NormalizedKeyName} keyName Name of the key
* @returns {Boolean} Whether the key has a native keypress event
* @returns {boolean} Whether the key has a native keypress event
*/

@@ -8,0 +8,0 @@

@@ -6,3 +6,3 @@ import isUndefined from '../../utils/isUndefined';

* @param {FocusTreeId} focusTreeId The focus tree id for the component
* @returns {Boolean} Whether the HotKeys component is focus-only
* @returns {boolean} Whether the HotKeys component is focus-only
*/

@@ -9,0 +9,0 @@

@@ -1,2 +0,2 @@

import KeysWithKeyupHiddenByCmd from '../../const/KeysWithKeyupHiddenByCmd';
import KeysWithKeyUpHiddenByCmd from '../../const/KeysWithKeyUpHiddenByCmd';
import hasKey from '../../utils/object/hasKey';

@@ -7,9 +7,9 @@ /**

* @param {NormalizedKeyName} keyName Name of the key
* @returns {Boolean} Whether the key has its keyup event hidden by cmd
* @returns {boolean} Whether the key has its keyup event hidden by cmd
*/
function keyupIsHiddenByCmd(keyName) {
return keyName.length === 1 || hasKey(KeysWithKeyupHiddenByCmd, keyName);
return keyName.length === 1 || hasKey(KeysWithKeyUpHiddenByCmd, keyName);
}
export default keyupIsHiddenByCmd;

@@ -29,3 +29,3 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

import React, { Component } from 'react';
import Configuration from './lib/Configuration';
import Configuration from './lib/config/Configuration';
import withHotKeys from './withHotKeys';

@@ -32,0 +32,0 @@ /**

@@ -28,3 +28,3 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

import React, { Component } from 'react';
import Configuration from './lib/Configuration';
import Configuration from './lib/config/Configuration';
import withHotKeysIgnoreOverride from './withHotKeysIgnoreOverride';

@@ -31,0 +31,0 @@ /**

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

import Logger from './Logger';
import Logger from './logging/Logger';
import FocusOnlyKeyEventStrategy from './strategies/FocusOnlyKeyEventStrategy';
import GlobalKeyEventStrategy from './strategies/GlobalKeyEventStrategy';
import isFromFocusOnlyComponent from '../helpers/resolving-handlers/isFromFocusOnlyComponent';
import Configuration from './Configuration';
import Configuration from './config/Configuration';
import EventResponse from '../const/EventResponse';

@@ -170,7 +170,7 @@ /**

this._focusOnlyEventStrategy.resetKeyCombinationHistory({
this._focusOnlyEventStrategy.resetKeyHistory({
force: true
});
this._globalEventStrategy.resetKeyCombinationHistory({
this._globalEventStrategy.resetKeyHistory({
force: true

@@ -298,3 +298,3 @@ });

* @param {ComponentId} componentId - Index of component that is blurring
* @returns {Boolean} Whether the component still has event propagation yet to handle
* @returns {boolean} Whether the component still has event propagation yet to handle
*/

@@ -349,6 +349,6 @@

}, {
key: "handleKeypress",
value: function handleKeypress(event, focusTreeId, componentId, options) {
key: "handleKeyPress",
value: function handleKeyPress(event, focusTreeId, componentId, options) {
if (isFromFocusOnlyComponent(focusTreeId)) {
return this._focusOnlyEventStrategy.handleKeypress(event, focusTreeId, componentId, options);
return this._focusOnlyEventStrategy.handleKeyPress(event, focusTreeId, componentId, options);
}

@@ -374,6 +374,6 @@ }

}, {
key: "handleKeyup",
value: function handleKeyup(event, focusTreeId, componentId, options) {
key: "handleKeyUp",
value: function handleKeyUp(event, focusTreeId, componentId, options) {
if (isFromFocusOnlyComponent(focusTreeId)) {
return this._focusOnlyEventStrategy.handleKeyup(event, focusTreeId, componentId, options);
return this._focusOnlyEventStrategy.handleKeyUp(event, focusTreeId, componentId, options);
}

@@ -448,4 +448,4 @@ }

}, {
key: "handleGlobalKeydown",
value: function handleGlobalKeydown(event) {
key: "handleGlobalKeyDown",
value: function handleGlobalKeyDown(event) {
return this._globalEventStrategy.handleKeydown(event);

@@ -464,5 +464,5 @@ }

}, {
key: "handleGlobalKeypress",
value: function handleGlobalKeypress(event) {
return this._globalEventStrategy.handleKeypress(event);
key: "handleGlobalKeyPress",
value: function handleGlobalKeyPress(event) {
return this._globalEventStrategy.handleKeyPress(event);
}

@@ -480,5 +480,5 @@ /**

}, {
key: "handleGlobalKeyup",
value: function handleGlobalKeyup(event) {
return this._globalEventStrategy.handleKeyup(event);
key: "handleGlobalKeyUp",
value: function handleGlobalKeyUp(event) {
return this._globalEventStrategy.handleKeyUp(event);
}

@@ -495,3 +495,3 @@ /**

value: function ignoreEvent(event) {
this._focusOnlyEventStrategy.ignoreEvent(event);
this._focusOnlyEventStrategy.getEventPropagator().ignoreEvent(event);
}

@@ -506,5 +506,5 @@ /**

}, {
key: "forceObserveEvent",
value: function forceObserveEvent(event) {
this._focusOnlyEventStrategy.forceObserveEvent(event);
key: "observeIgnoredEvents",
value: function observeIgnoredEvents(event) {
this._focusOnlyEventStrategy.getEventPropagator().observeIgnoredEvents(event);
}

@@ -516,3 +516,3 @@ /**

* is currently set to keydown or keypress.
* @param {KeyEventRecordIndex} recordIndex Index of key event to move the key state
* @param {KeyEventType} recordIndex Index of key event to move the key state
* up to.

@@ -529,8 +529,8 @@ */

value: function reactAppHistoryWithEvent(key, type) {
var currentEvent = this._focusOnlyEventStrategy.currentEvent;
var previousPropagation = this._focusOnlyEventStrategy.eventPropagator.getPreviousPropagation();
if (currentEvent.key === key && currentEvent.type === type) {
if (currentEvent.handled) {
if (previousPropagation.isForKey(key) && previousPropagation.isForEventType(type)) {
if (previousPropagation.isHandled()) {
return EventResponse.handled;
} else if (currentEvent.ignored) {
} else if (previousPropagation.isIgnoringEvent()) {
return EventResponse.ignored;

@@ -537,0 +537,0 @@ } else {

@@ -11,32 +11,22 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

import KeyEventRecordManager from '../KeyEventRecordManager';
import KeyEventRecordIndex from '../../const/KeyEventRecordIndex';
import Logger from '../Logger';
import KeyCombinationSerializer from '../KeyCombinationSerializer';
import KeyEventType from '../../const/KeyEventType';
import ModifierFlagsDictionary from '../../const/ModifierFlagsDictionary';
import Logger from '../logging/Logger';
import KeyCombinationSerializer from '../shared/KeyCombinationSerializer';
import Configuration from '../config/Configuration';
import KeyHistory from '../listening/KeyHistory';
import KeyCombination from '../listening/KeyCombination';
import ComponentTree from '../definitions/ComponentTree';
import ComponentOptionsList from '../definitions/ComponentOptionsList';
import ActionResolver from '../matching/ActionResolver';
import arrayFrom from '../../utils/array/arrayFrom';
import indexFromEnd from '../../utils/array/indexFromEnd';
import isObject from '../../utils/object/isObject';
import isUndefined from '../../utils/isUndefined';
import isEmpty from '../../utils/collection/isEmpty';
import copyAttributes from '../../utils/object/copyAttributes';
import hasKey from '../../utils/object/hasKey';
import describeKeyEventType from '../../helpers/logging/describeKeyEventType';
import KeyEventSequenceIndex from '../../const/KeyEventSequenceIndex';
import KeySequenceParser from '../KeySequenceParser';
import printComponent from '../../helpers/logging/printComponent';
import resolveUnaltShiftedAlias from '../../helpers/resolving-handlers/resolveUnaltShiftedAlias';
import resolveUnshiftedAlias from '../../helpers/resolving-handlers/resolveUnshiftedAlias';
import resolveUnaltedAlias from '../../helpers/resolving-handlers/resolveUnaltedAlias';
import resolveKeyAlias from '../../helpers/resolving-handlers/resolveKeyAlias';
import resolveAltShiftedAlias from '../../helpers/resolving-handlers/resolveAltShiftedAlias';
import resolveShiftedAlias from '../../helpers/resolving-handlers/resolveShiftedAlias';
import resolveAltedAlias from '../../helpers/resolving-handlers/resolveAltedAlias';
import Configuration from '../Configuration';
import ModifierFlagsDictionary from '../../const/ModifierFlagsDictionary';
import without from '../../utils/collection/without';
import hasKeyPressEvent from '../../helpers/resolving-handlers/hasKeyPressEvent';
import keyIsCurrentlyTriggeringEvent from '../../helpers/parsing-key-maps/keyIsCurrentlyTriggeringEvent';
import isMatchPossibleBasedOnNumberOfKeys from '../../helpers/resolving-handlers/isMatchPossibleBasedOnNumberOfKeys';
import copyAttributes from '../../utils/object/copyAttributes';
import hasKey from '../../utils/object/hasKey';
import keyupIsHiddenByCmd from '../../helpers/resolving-handlers/keyupIsHiddenByCmd';
import KeyEventRecordState from '../../const/KeyEventRecordState';
import stateFromEvent from '../../helpers/parsing-key-maps/stateFromEvent';
var SEQUENCE_ATTRIBUTES = ['sequence', 'action'];

@@ -53,31 +43,14 @@ var KEYMAP_ATTRIBUTES = ['name', 'description', 'group'];

function () {
_createClass(AbstractKeyEventStrategy, null, [{
key: "emptyKeyCombination",
/********************************************************************************
* Init & Reset
********************************************************************************/
/********************************************************************************
* Init & Reset
********************************************************************************/
/**
* Returns a new, empty key combination
* @returns {KeyCombinationRecord} A new, empty key combination
*/
value: function emptyKeyCombination() {
return {
keys: {},
ids: [''],
keyAliases: {}
};
}
/**
* Creates a new instance of a event strategy (this class is an abstract one and
* not intended to be instantiated directly)
* @param {Object} options Options for how event strategy should behave
* @param {Logger} options.logger The Logger to use to report event strategy actions
* @param {KeyEventManager} keyEventManager KeyEventManager used for passing
* messages between key event strategies
*/
}]);
/**
* Creates a new instance of an event strategy (this class is an abstract one and
* not intended to be instantiated directly).
* @param {Object} options Options for how event strategy should behave
* @param {Logger} options.logger The Logger to use to report event strategy actions
* @param {KeyEventManager} keyEventManager KeyEventManager used for passing
* messages between key event strategies
*/
function AbstractKeyEventStrategy() {

@@ -91,3 +64,3 @@ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};

/**
* @typedef {Number} ComponentId Unique index associated with every HotKeys component
* @typedef {number} ComponentId Unique index associated with every HotKeys component
* as it becomes active.

@@ -120,4 +93,3 @@ *

this.keyEventManager = keyEventManager;
this.keyMapRegistry = {};
this.componentRegistry = {};
this._componentTree = new ComponentTree();
this.rootComponentId = null;

@@ -127,3 +99,3 @@

this.resetKeyCombinationHistory();
this.resetKeyHistory();
}

@@ -139,65 +111,23 @@ /**

value: function _reset() {
this._initRegisteredKeyMapsState();
this.componentList = new ComponentOptionsList();
this._initHandlerResolutionState();
}
/**
* Resets all state used to record information about the keymaps that HotKey
* components have registered.
*
* After initialization, this state is generally maintained manually by
* the _buildKeyMatcherMap() method and this method should not be called.
*/
}, {
key: "_initRegisteredKeyMapsState",
value: function _initRegisteredKeyMapsState() {
/**
* Object containing a component's defined key maps and handlers
* @typedef {Object} ComponentOptions
* @property {ActionDictionary} actions - Dictionary of actions the component
* has defined in its keymap
* @property {HandlersMap} handlers - Dictionary of handler functions the
* component has defined
* @property {ComponentId} componentId - Index of the component the options
* correspond with
*/
key: "_newKeyHistory",
value: function _newKeyHistory() {
return new KeyHistory({
maxLength: this.componentList.getLongestSequence()
});
}
}, {
key: "getKeyHistory",
value: function getKeyHistory() {
if (this._keyHistory) {
return this._keyHistory;
} else {
this._keyHistory = this._newKeyHistory();
}
/**
* List of actions and handlers registered by each component currently in focus.
* The component closest to the element in focus is last in the list.
* @type {ComponentOptions[]}
*/
this.componentList = [];
/**
* Counter for the longest sequence registered by the HotKeys components currently
* in focus. Allows setting an upper bound on the length of the key event history
* that must be kept.
* @type {Number}
*/
this.longestSequence = 1;
/**
* The component index of the component that defines the longest key sequence, so
* we can quickly determine if the longest sequence needs to be re-calculated when
* that component is updated or removed.
* @type {ComponentId}
*/
this.longestSequenceComponentIndex = null;
/**
* Record to record whether there is at least one keymap bound to each event type
* (keydown, keypress or keyup) so that we can skip trying to find a matching keymap
* on events where we know there is none to find
* @type {KeyEventRecord}
*/
this.keyMapEventRecord = KeyEventRecordManager.newRecord();
/**
* Set of ComponentOptions indexed by ComponentId to allow efficient retrieval
* when components need to be updated or unmounted by their ComponentId
* @type {Object<ComponentId, ComponentOptions>}
*/
this.componentIdDict = {};
return this._keyHistory;
}

@@ -213,45 +143,3 @@ /**

value: function _initHandlerResolutionState() {
if (this.keyMaps === null) {
/**
* If this.keyMaps is already set to null, then the state has already been reset
* and we need not do it again
*/
return;
}
/**
* List of mappings from key sequences to handlers that is constructed on-the-fly
* as key events propagate up the render tree
*/
this.keyMaps = null;
/**
* Index marking the number of places from the end of componentList for which the
* keyMaps have been matched with event handlers. Used to build this.keyMaps as
* key events propagate up the React tree.
* @type {Number}
*/
this.handlerResolutionSearchIndex = 0;
/**
* Array of counters - one for each component - to keep track of how many handlers
* for that component still need actions assigned to them
* @type {Number[]}
*/
this.unmatchedHandlerStatus = null;
/**
* A dictionary of handlers to the components that register them. This is populated
* as this.handlerResolutionSearchIndex increases, moving from the end of this.componentList to the
* front, populating this.keyMaps as needed
* @type {Object<ActionName, ComponentId>}
*/
this.handlersDictionary = {};
/**
* A dictionary of sequences already encountered in the process of building the
* list of keyMaps on the fly, as key events propagate up the component tree
*/
this.keySequencesDictionary = {};
this._actionResolver = null;
}

@@ -261,3 +149,3 @@ /**

* @param {Object} options An options hash
* @param {Boolean} options.force Whether to force a hard reset of the key
* @param {boolean} options.force Whether to force a hard reset of the key
* combination history.

@@ -267,34 +155,14 @@ */

}, {
key: "resetKeyCombinationHistory",
value: function resetKeyCombinationHistory() {
key: "resetKeyHistory",
value: function resetKeyHistory() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
/**
* Whether the current key combination includes at least one keyup event - indicating
* that the current combination is ending (and keys are being released)
*/
this.keyCombinationIncludesKeyUp = false;
this.keypressEventsToSimulate = [];
this.keyupEventsToSimulate = [];
if (!this.keyCombinationHistory || this.keyCombinationHistory.length < 1 || options.force) {
this.keyCombinationHistory = [];
if (this.getKeyHistory().any() && !options.force) {
this._keyHistory = new KeyHistory({
maxLength: this.componentList.getLongestSequence()
}, new KeyCombination(this.getCurrentCombination().keysStillPressedDict()));
} else {
var currentKeyCombination = this._getCurrentKeyCombination();
var keysStillPressed = Object.keys(currentKeyCombination.keys).reduce(function (memo, keyName) {
var keyState = currentKeyCombination.keys[keyName];
var currentKeyState = keyState[KeyEventSequenceIndex.current];
if (currentKeyState[KeyEventRecordIndex.keydown] && !currentKeyState[KeyEventRecordIndex.keyup]) {
memo[keyName] = keyState;
}
return memo;
}, {});
this.keyCombinationHistory = [{
keys: keysStillPressed,
ids: KeyCombinationSerializer.serialize(keysStillPressed),
keyAliases: this._buildCombinationKeyAliases(keysStillPressed)
}];
this._keyHistory = this._newKeyHistory();
}

@@ -328,4 +196,5 @@ }

componentIds.forEach(function (componentId) {
var component = _this.componentRegistry[componentId];
var keyMap = _this.keyMapRegistry[componentId];
var _this$_componentTree$ = _this._componentTree.get(componentId),
childIds = _this$_componentTree$.childIds,
keyMap = _this$_componentTree$.keyMap;

@@ -369,3 +238,3 @@ if (keyMap) {

_this._buildApplicationKeyMap(component.childIds, keyMapSummary);
_this._buildApplicationKeyMap(childIds, keyMapSummary);
});

@@ -414,6 +283,6 @@ return keyMapSummary;

this.componentId += 1;
this.keyMapRegistry[this.componentId] = keyMap;
this.logger.verbose(this._logPrefix(this.componentId), 'Registered keyMap:\n', "".concat(printComponent(keyMap)));
this.componentRegistry[this.componentId] = newComponentRegistryItem();
this.logger.verbose(this._logPrefix(this.componentId), 'Registered component:\n', "".concat(printComponent(this.componentRegistry[this.componentId])));
this._componentTree.add(this.componentId, keyMap);
this.logger.verbose(this._logPrefix(this.componentId), 'Registered component:\n', "".concat(printComponent(this._componentTree.get(this.componentId))));
return this.componentId;

@@ -430,3 +299,3 @@ }

value: function reregisterKeyMap(componentId, keyMap) {
this.keyMapRegistry[componentId] = keyMap;
this._componentTree.update(componentId, keyMap);
}

@@ -444,4 +313,3 @@ /**

if (!isUndefined(parentId)) {
this.componentRegistry[componentId].parentId = parentId;
this.componentRegistry[parentId].childIds.push(componentId);
this._componentTree.setParent(componentId, parentId);
} else {

@@ -451,3 +319,3 @@ this.rootComponentId = componentId;

this.logger.verbose(this._logPrefix(componentId), 'Registered component mount:\n', "".concat(printComponent(this.componentRegistry[componentId])));
this.logger.verbose(this._logPrefix(componentId), 'Registered component mount:\n', "".concat(printComponent(this._componentTree.get(componentId))));
}

@@ -463,14 +331,6 @@ /**

value: function deregisterKeyMap(componentId) {
var parentId = this.componentRegistry[componentId].parentId;
var parent = this.componentRegistry[parentId];
this._componentTree.remove(componentId);
if (parent) {
parent.childIds = without(parent.childIds, componentId);
}
this.logger.verbose(this._logPrefix(componentId), 'De-registered component. Remaining component Registry:\n', "".concat(printComponent(this._componentTree.toJSON())));
delete this.componentRegistry[componentId];
this.logger.verbose(this._logPrefix(componentId), 'De-registered component. Remaining component Registry:\n', "".concat(printComponent(this.componentRegistry)));
delete this.keyMapRegistry[componentId];
this.logger.verbose(this._logPrefix(componentId), 'De-registered key map. Remaining key map Registry:\n', "".concat(printComponent(this.keyMapRegistry)));
if (componentId === this.rootComponentId) {

@@ -496,177 +356,10 @@ this.rootComponentId = null;

}, {
key: "_addComponentToList",
value: function _addComponentToList(componentId) {
key: "_addComponent",
value: function _addComponent(componentId) {
var actionNameToKeyMap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var actionNameToHandlersMap = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var options = arguments.length > 3 ? arguments[3] : undefined;
var componentOptions = this._buildComponentOptions(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this.componentList.push(componentOptions);
this._setComponentPosition(componentId, this.componentList.length - 1);
this.componentList.add(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this.getKeyHistory().setMaxLength(this.componentList.getLongestSequence());
}
/**
* Builds the internal representation that described the options passed to a HotKeys
* component
* @param {ComponentId} componentId - Index of the component
* @param {KeyMap} actionNameToKeyMap - Definition of actions and key maps defined
* in the HotKeys component
* @param {HandlersMap} actionNameToHandlersMap - Map of ActionNames to handlers
* defined in the HotKeys component
* @param {Object} options - Hash of options that configure how the key map is built.
* @param {String} options.defaultKeyEvent - The default key event to use for any
* action that does not explicitly define one.
* @returns {ComponentOptions} Options for the specified component
* @protected
*/
}, {
key: "_buildComponentOptions",
value: function _buildComponentOptions(componentId, actionNameToKeyMap, actionNameToHandlersMap, options) {
var _this$_applyHardSeque = this._applyHardSequences(actionNameToKeyMap, actionNameToHandlersMap),
hardSequenceKeyMap = _this$_applyHardSeque.keyMap,
includingHardSequenceHandlers = _this$_applyHardSeque.handlers;
return {
actions: this._buildActionDictionary(_objectSpread({}, actionNameToKeyMap, hardSequenceKeyMap), options, componentId),
handlers: includingHardSequenceHandlers,
componentId: componentId,
options: options
};
}
/**
* Applies hard sequences (handlers attached to actions with names that are valid
* KeySequenceStrings) that implicitly define a corresponding action name.
* @param {KeyMap} actionNameToKeyMap - KeyMap specified by HotKeys component
* @param {HandlersMap} actionNameToHandlersMap - HandlersMap specified by HotKeys
* component
* @returns {{keyMap: {}, handlers: {}}} Object containing keymap and handlers map
* with the hard sequence actions applied
* @private
*/
}, {
key: "_applyHardSequences",
value: function _applyHardSequences(actionNameToKeyMap, actionNameToHandlersMap) {
if (Configuration.option('enableHardSequences')) {
return Object.keys(actionNameToHandlersMap).reduce(function (memo, actionNameOrKeyExpression) {
var actionNameIsInKeyMap = !!actionNameToKeyMap[actionNameOrKeyExpression];
if (!actionNameIsInKeyMap && KeyCombinationSerializer.isValidKeySerialization(actionNameOrKeyExpression)) {
memo.keyMap[actionNameOrKeyExpression] = actionNameOrKeyExpression;
}
memo.handlers[actionNameOrKeyExpression] = actionNameToHandlersMap[actionNameOrKeyExpression];
return memo;
}, {
keyMap: {},
handlers: {}
});
} else {
return {
keyMap: actionNameToKeyMap,
handlers: actionNameToHandlersMap
};
}
}
/**
* Object containing all the information required to match a key event to an action
* @typedef {Object} ActionConfiguration
* @property {KeyCombinationString} id - String description of keys involved in the
* final key combination in the sequence
* @property {ActionName} actionName - Name of the action associated with the key map
* @property {NormalizedKeySequenceId} prefix - String describing sequence of key
* combinations involved key map, before the final key combination
* @property {Number} sequenceLength - Number of combinations involved in the
* sequence
* @property {Number} size - Number of keys involved in the combination
* @property {Object.<KeyName, Boolean>} keyDictionary - Dictionary of key names involved
* in the key combination
* @property {KeyEventRecordIndex} eventRecordIndex - Record index for key event that
* the matcher should match on
*/
/**
* A mapping between ActionNames and FullKeyEventOptions
* @typedef {Object<ActionName,ActionConfiguration>} ActionDictionary
*/
/**
* Returns a mapping between ActionNames and FullKeyEventOptions
* @param {KeyMap} actionNameToKeyMap - Mapping of ActionNames to key sequences.
* @param {Object} options - Hash of options that configure how the key map is built.
* @param {String} options.defaultKeyEvent - The default key event to use for any
* action that does not explicitly define one.
* @param {ComponentId} componentId Index of the component the matcher belongs to
* @return {ActionDictionary} Map from ActionNames to FullKeyEventOptions
* @private
*/
}, {
key: "_buildActionDictionary",
value: function _buildActionDictionary(actionNameToKeyMap, options, componentId) {
var _this2 = this;
return Object.keys(actionNameToKeyMap).reduce(function (keyMapMemo, actionName) {
var keyMapConfig = actionNameToKeyMap[actionName];
var keyMapOptions = function () {
if (isObject(keyMapConfig) && hasKey(keyMapConfig, 'sequences')) {
return arrayFrom(keyMapConfig.sequences);
} else {
return arrayFrom(keyMapConfig);
}
}();
keyMapOptions.forEach(function (keyMapOption) {
var _ref = function () {
if (isObject(keyMapOption)) {
var _sequence = keyMapOption.sequence,
action = keyMapOption.action;
return {
keySequence: _sequence,
eventRecordIndex: isUndefined(action) ? KeyEventRecordIndex[options.defaultKeyEvent] : KeyEventRecordIndex[action]
};
} else {
return {
keySequence: keyMapOption,
eventRecordIndex: KeyEventRecordIndex[options.defaultKeyEvent]
};
}
}(),
keySequence = _ref.keySequence,
eventRecordIndex = _ref.eventRecordIndex;
var _KeySequenceParser$pa = KeySequenceParser.parse(keySequence, {
eventRecordIndex: eventRecordIndex
}),
sequence = _KeySequenceParser$pa.sequence,
combination = _KeySequenceParser$pa.combination;
if (sequence.size > _this2.longestSequence) {
_this2.longestSequence = sequence.size;
_this2.longestSequenceComponentIndex = componentId;
}
/**
* Record that there is at least one key sequence in the focus tree bound to
* the keyboard event
*/
_this2.keyMapEventRecord[eventRecordIndex] = true;
if (!keyMapMemo[actionName]) {
keyMapMemo[actionName] = [];
}
keyMapMemo[actionName].push(_objectSpread({
prefix: sequence.prefix,
actionName: actionName,
sequenceLength: sequence.size
}, combination));
});
return keyMapMemo;
}, {});
}
/********************************************************************************

@@ -677,103 +370,4 @@ * Recording key events

/**
* Record of the combination of keys that are currently being pressed
* @typedef {Object} KeyCombinationRecord
* @property {Object<ReactKeyName, KeyEventRecord[]>} keys - A dictionary
* of keys that have been pressed down at once. The keys of the map are the lowercase
* names of the keyboard keys. May contain 1 or more keyboard keys.
* @property {KeySequenceString} ids - Serialization of keys currently pressed in
* combination
* @property {Object<ReactKeyName, ReactKeyName>} keyAliases - Dictionary of key
* aliases, when modifier keys like alt or shift are pressed.
*/
/**
* Returns the current key combination, i.e. the key combination that represents
* the current key events.
* @returns {KeyCombinationRecord} The current key combination
* @protected
*/
}, {
key: "_getCurrentKeyCombination",
value: function _getCurrentKeyCombination() {
if (this.keyCombinationHistory.length > 0) {
return this.keyCombinationHistory[this.keyCombinationHistory.length - 1];
} else {
return this.constructor.emptyKeyCombination();
}
}
/**
* Adds a key event to the current key combination (as opposed to starting a new
* keyboard combination).
* @param {ReactKeyName} keyName - Name of the key to add to the current combination
* @param {KeyEventRecordIndex} recordIndex - Index in record to set to true
* @param {KeyEventRecordState} keyEventState The state to set the key event to
* @protected
*/
}, {
key: "_addToCurrentKeyCombination",
value: function _addToCurrentKeyCombination(keyName, recordIndex, keyEventState) {
if (this.keyCombinationHistory.length === 0) {
this.keyCombinationHistory.push(this.constructor.emptyKeyCombination());
}
var keyCombination = this._getCurrentKeyCombination();
var keyAlias = getKeyAlias(keyCombination, keyName);
var existingRecord = getKeyState(keyCombination, keyName);
if (!existingRecord) {
keyCombination.keys[keyAlias] = [KeyEventRecordManager.newRecord(), KeyEventRecordManager.newRecord(recordIndex, keyEventState)];
} else {
var previous = KeyEventRecordManager.clone(existingRecord[1]);
var current = KeyEventRecordManager.clone(previous);
KeyEventRecordManager.setBit(current, recordIndex, keyEventState);
keyCombination.keys[keyAlias] = [previous, current];
}
keyCombination.ids = KeyCombinationSerializer.serialize(keyCombination.keys);
keyCombination.keyAliases = this._buildCombinationKeyAliases(keyCombination.keys);
if (recordIndex === KeyEventRecordIndex.keyup) {
this.keyCombinationIncludesKeyUp = true;
}
}
/**
* Adds a new KeyCombinationRecord to the event history and resets the
* keyCombinationIncludesKeyUp flag to false.
* @param {ReactKeyName} keyName - Name of the keyboard key to add to the new
* KeyCombinationRecord
* @param {KeyEventRecordIndex} eventRecordIndex - Index of bit to set to true in new
* KeyEventRecord
* @param {KeyEventRecordState} keyEventState The state to set the key event to
* @protected
*/
}, {
key: "_startNewKeyCombination",
value: function _startNewKeyCombination(keyName, eventRecordIndex, keyEventState) {
if (this.keyCombinationHistory.length > this.longestSequence) {
/**
* We know the longest key sequence registered for the currently focused
* components, so we don't need to keep a record of history longer than
* that
*/
this.keyCombinationHistory.shift();
}
var lastKeyCombination = this._getCurrentKeyCombination();
var keys = _objectSpread({}, this._withoutKeyUps(lastKeyCombination), _defineProperty({}, keyName, [KeyEventRecordManager.newRecord(), KeyEventRecordManager.newRecord(eventRecordIndex, keyEventState)]));
this.keyCombinationHistory.push({
keys: keys,
ids: KeyCombinationSerializer.serialize(keys),
keyAliases: this._buildCombinationKeyAliases(keys)
});
this.keyCombinationIncludesKeyUp = false;
}
/**
* Whether there are any keys in the current combination still being pressed
* @return {Boolean} True if all keys in the current combination are released
* @returns {boolean} True if all keys in the current combination are released
* @protected

@@ -785,33 +379,8 @@ */

value: function _allKeysAreReleased() {
var _this3 = this;
var currentCombination = this._getCurrentKeyCombination();
return Object.keys(currentCombination.keys).every(function (keyName) {
return !_this3._keyIsCurrentlyDown(keyName);
});
return this.getCurrentCombination().hasEnded();
}
/**
* Returns a new KeyCombinationRecord without the keys that have been
* released (had the keyup event recorded). Essentially, the keys that are
* currently still pressed down at the time a key event is being handled.
* @param {KeyCombinationRecord} keyCombinationRecord Record of keys currently
* pressed down that should have the release keyed omitted from
* @returns {KeyCombinationRecord} New KeyCombinationRecord with all of the
* keys with keyup events omitted
* @private
*/
}, {
key: "_withoutKeyUps",
value: function _withoutKeyUps(keyCombinationRecord) {
return Object.keys(keyCombinationRecord.keys).reduce(function (memo, keyName) {
var keyState = keyCombinationRecord.keys[keyName];
if (!keyState[KeyEventSequenceIndex.current][KeyEventRecordIndex.keyup]) {
memo[keyName] = keyState;
}
return memo;
}, {});
key: "getCurrentCombination",
value: function getCurrentCombination() {
return this.getKeyHistory().getCurrentCombination();
}

@@ -821,8 +390,9 @@ }, {

value: function _shouldSimulate(eventType, keyName) {
var keyHasNativeKeypress = hasKeyPressEvent(keyName);
var keyHasNativeKeyPress = hasKeyPressEvent(keyName);
var currentCombination = this.getCurrentCombination();
if (eventType === KeyEventRecordIndex.keypress) {
return !keyHasNativeKeypress || keyHasNativeKeypress && this._keyIsCurrentlyDown('Meta');
} else if (eventType === KeyEventRecordIndex.keyup) {
return keyupIsHiddenByCmd(keyName) && keyIsCurrentlyTriggeringEvent(this._getCurrentKeyState('Meta'), KeyEventRecordIndex.keyup);
if (eventType === KeyEventType.keypress) {
return !keyHasNativeKeyPress || keyHasNativeKeyPress && currentCombination.isKeyStillPressed('Meta');
} else if (eventType === KeyEventType.keyup) {
return keyupIsHiddenByCmd(keyName) && currentCombination.isKeyReleased('Meta');
}

@@ -841,9 +411,2 @@

}
}, {
key: "_alreadySimulatedEvent",
value: function _alreadySimulatedEvent(recordIndex, keyName) {
var keyState = this._getCurrentKeyState(keyName);
return keyIsCurrentlyTriggeringEvent(keyState, recordIndex) === KeyEventRecordState.simulated;
}
/********************************************************************************

@@ -854,285 +417,39 @@ * Matching and calling handlers

}, {
key: "_callMatchingHandlerClosestToEventTarget",
value: function _callMatchingHandlerClosestToEventTarget(event, keyName, eventRecordIndex, componentPosition, componentSearchIndex) {
var _this4 = this;
if (!this.keyMaps || !this.unmatchedHandlerStatus) {
this.keyMaps = [];
this.unmatchedHandlerStatus = [];
this.componentList.forEach(function (_ref2) {
var handlers = _ref2.handlers;
_this4.unmatchedHandlerStatus.push([Object.keys(handlers).length, {}]);
_this4.keyMaps.push({});
});
key: "_callClosestMatchingHandler",
value: function _callClosestMatchingHandler(event, keyName, keyEventType, componentPosition, componentSearchIndex) {
if (!this._actionResolver) {
this._actionResolver = new ActionResolver(this.componentList);
}
while (componentSearchIndex <= componentPosition) {
var unmatchedHandlersStatus = this.unmatchedHandlerStatus[componentSearchIndex];
var unmatchedHandlersCount = unmatchedHandlersStatus[0];
var keyHistoryMatcher = this._actionResolver.getKeyHistoryMatcher(componentSearchIndex);
if (unmatchedHandlersCount > 0) {
var _loop = function _loop() {
var _this4$componentList$ = _this4.componentList[_this4.handlerResolutionSearchIndex],
handlers = _this4$componentList$.handlers,
actions = _this4$componentList$.actions;
/**
* Add current component's handlers to the handlersDictionary so we know
* which component has defined them
*/
this.logger.verbose(this._logPrefix(componentSearchIndex), 'Internal key mapping:\n', "".concat(printComponent(keyHistoryMatcher.toJSON())));
Object.keys(handlers).forEach(function (actionName) {
if (!_this4.handlersDictionary[actionName]) {
_this4.handlersDictionary[actionName] = [];
}
var sequenceMatch = this._actionResolver.findMatchingKeySequenceInComponent(componentSearchIndex, this.getKeyHistory(), keyName, keyEventType);
_this4.handlersDictionary[actionName].push(_this4.handlerResolutionSearchIndex);
});
/**
* Iterate over the actions of a component (starting with the current component
* and working through its ancestors), matching them to the current component's
* handlers
*/
var currentCombination = this.getCurrentCombination();
Object.keys(actions).forEach(function (actionName) {
var handlerComponentIndexArray = _this4.handlersDictionary[actionName];
if (sequenceMatch) {
var eventSchema = sequenceMatch.events[keyEventType];
if (handlerComponentIndexArray) {
/**
* Get action handler closest to the event target
*/
var handlerComponentIndex = handlerComponentIndexArray[0];
var handler = _this4.componentList[handlerComponentIndex].handlers[actionName];
/**
* Get key map that corresponds with the component that defines the handler
* closest to the event target
*/
if (Configuration.option('allowCombinationSubmatches')) {
var subMatchDescription = KeyCombinationSerializer.serialize(sequenceMatch.keyDictionary);
this.logger.debug(this._logPrefix(componentSearchIndex), "Found action that matches '".concat(currentCombination.describe(), "' (sub-match: '").concat(subMatchDescription, "'): ").concat(eventSchema.actionName, ". Calling handler . . ."));
} else {
this.logger.debug(this._logPrefix(componentSearchIndex), "Found action that matches '".concat(currentCombination.describe(), "': ").concat(eventSchema.actionName, ". Calling handler . . ."));
}
var _keyMap = _this4.keyMaps[handlerComponentIndex];
/**
* Store the key sequence with the handler that it should call at
* a given component level
*/
eventSchema.handler(event);
if (!_keyMap.sequences) {
_keyMap.sequences = {};
}
/**
* At least one child HotKeys component (or the component itself) has
* defined a handler for the action, so now we need to associate them
*/
this._stopEventPropagationAfterHandlingIfEnabled(event, componentSearchIndex);
var keyMatchers = actions[actionName];
keyMatchers.forEach(function (keyMatcher) {
var keySequence = [keyMatcher.prefix, keyMatcher.id].join(' ');
var closestSequenceHandlerAlreadyFound = _this4.keySequencesDictionary[keySequence] && _this4.keySequencesDictionary[keySequence].some(function (dictEntry) {
return dictEntry[1] === keyMatcher.eventRecordIndex;
});
if (closestSequenceHandlerAlreadyFound) {
/**
* Return if there is already a component with handlers for the current
* key sequence closer to the event target
*/
return;
}
if (!_keyMap.sequences[keyMatcher.prefix]) {
_keyMap.sequences[keyMatcher.prefix] = {
combinations: {}
};
}
var prefix = keyMatcher.prefix,
sequenceLength = keyMatcher.sequenceLength,
id = keyMatcher.id,
keyDictionary = keyMatcher.keyDictionary,
size = keyMatcher.size,
matcherEventRecordIndex = keyMatcher.eventRecordIndex,
actionName = keyMatcher.actionName;
var combination = _keyMap.sequences[keyMatcher.prefix].combinations[keyMatcher.id];
if (!combination) {
_keyMap.sequences[keyMatcher.prefix].combinations[keyMatcher.id] = {
prefix: prefix,
sequenceLength: sequenceLength,
id: id,
keyDictionary: keyDictionary,
size: size,
events: _defineProperty({}, matcherEventRecordIndex, {
actionName: actionName,
eventRecordIndex: matcherEventRecordIndex,
handler: handler
})
};
} else {
_keyMap.sequences[keyMatcher.prefix].combinations[keyMatcher.id] = _objectSpread({}, combination, {
events: _objectSpread({}, combination.events, _defineProperty({}, matcherEventRecordIndex, {
actionName: actionName,
eventRecordIndex: matcherEventRecordIndex,
handler: handler
}))
});
}
/**
* Merge event records so we can quickly determine if a given component
* has any handlers bound to particular key events
*/
if (!_keyMap.eventRecord) {
_keyMap.eventRecord = KeyEventRecordManager.newRecord();
}
KeyEventRecordManager.setBit(_keyMap.eventRecord, keyMatcher.eventRecordIndex, _this4._stateFromEvent(event));
/**
* Record the longest sequence length so we know to only check for sequences
* of that length or shorter for a particular component
*/
if (!_keyMap.longestSequence || _keyMap.longestSequence < keyMatcher.sequenceLength) {
_keyMap.longestSequence = keyMatcher.sequenceLength;
}
/**
* Record that we have already found a handler for the current action so
* that we do not override handlers for an action closest to the event target
* with handlers further up the tree
*/
if (!_this4.keySequencesDictionary[keySequence]) {
_this4.keySequencesDictionary[keySequence] = [];
}
_this4.keySequencesDictionary[keySequence].push([handlerComponentIndex, keyMatcher.eventRecordIndex]);
});
handlerComponentIndexArray.forEach(function (handlerComponentIndex) {
var handlerComponentStatus = _this4.unmatchedHandlerStatus[handlerComponentIndex];
if (!handlerComponentStatus[1][actionName]) {
handlerComponentStatus[1][actionName] = true;
/**
* Decrement the number of remaining unmatched handlers for the
* component currently handling the propagating key event, so we know
* when all handlers have been matched to sequences and we can move on
* to matching them against the current key event
*/
handlerComponentStatus[0]--;
}
});
}
});
/**
* Search next component up in the hierarchy for actions that match outstanding
* handlers
*/
_this4.handlerResolutionSearchIndex++;
};
/**
* Component currently handling key event has handlers that have not yet been
* associated with a key sequence. We need to continue walking up the component
* tree in search of the matching actions that describe the applicable key
* sequence.
*/
while (this.handlerResolutionSearchIndex < this.componentList.length && unmatchedHandlersCount > 0) {
_loop();
}
}
var keyMap = this.keyMaps[componentSearchIndex];
this.logger.verbose(this._logPrefix(componentSearchIndex), 'Internal key mapping:\n', "".concat(printComponent(keyMap)));
if (!keyMap || isEmpty(keyMap.sequences) || !keyMap.eventRecord[eventRecordIndex]) {
/**
* Component doesn't define any matchers for the current key event
*/
this.logger.debug(this._logPrefix(componentSearchIndex), "Doesn't define a handler for '".concat(this._describeCurrentKeyCombination(), "' ").concat(describeKeyEventType(eventRecordIndex), "."));
return true;
} else {
var sequences = keyMap.sequences,
longestSequence = keyMap.longestSequence;
var currentKeyState = this._getCurrentKeyCombination();
var normalizedKeyName = getKeyAlias(currentKeyState, keyName);
var sequenceLengthCounter = longestSequence;
while (sequenceLengthCounter >= 0) {
var sequenceHistory = this.keyCombinationHistory.slice(-sequenceLengthCounter, -1);
var sequenceHistoryIds = sequenceHistory.map(function (_ref3) {
var ids = _ref3.ids;
return ids;
});
var matchingSequence = this._tryMatchSequenceWithKeyAliases(sequences, sequenceHistoryIds);
if (matchingSequence) {
if (!matchingSequence.order) {
(function () {
/**
* The first time the component that is currently handling the key event has
* its handlers searched for a match, order the combinations based on their
* size so that they may be applied in the correct priority order
*/
var combinationsPartitionedBySize = Object.values(matchingSequence.combinations).reduce(function (memo, _ref4) {
var id = _ref4.id,
size = _ref4.size;
if (!memo[size]) {
memo[size] = [];
}
memo[size].push(id);
return memo;
}, {});
matchingSequence.order = Object.keys(combinationsPartitionedBySize).sort(function (a, b) {
return b - a;
}).reduce(function (memo, key) {
return memo.concat(combinationsPartitionedBySize[key]);
}, []);
})();
}
var combinationOrder = matchingSequence.order;
var combinationIndex = 0;
while (combinationIndex < combinationOrder.length) {
var combinationId = combinationOrder[combinationIndex];
var combinationMatcher = matchingSequence.combinations[combinationId];
var cmdKeyIsPressed = this._getCurrentKeyState('Meta') && !keyIsCurrentlyTriggeringEvent(this._getCurrentKeyState('Meta'), KeyEventRecordIndex.keyup);
var keyupIsHidden = cmdKeyIsPressed && Object.keys(combinationMatcher.keyDictionary).some(function (keyName) {
return keyupIsHiddenByCmd(keyName);
});
if (isMatchPossibleBasedOnNumberOfKeys(currentKeyState, combinationMatcher, keyupIsHidden)) {
if (this._combinationMatchesKeys(normalizedKeyName, currentKeyState, combinationMatcher, eventRecordIndex)) {
if (Configuration.option('allowCombinationSubmatches')) {
var subMatchDescription = KeyCombinationSerializer.serialize(combinationMatcher.keyDictionary);
this.logger.debug(this._logPrefix(componentSearchIndex), "Found action that matches '".concat(this._describeCurrentKeyCombination(), "' (sub-match: '").concat(subMatchDescription, "'): ").concat(combinationMatcher.events[eventRecordIndex].actionName, ". Calling handler . . ."));
} else {
this.logger.debug(this._logPrefix(componentSearchIndex), "Found action that matches '".concat(this._describeCurrentKeyCombination(), "': ").concat(combinationMatcher.events[eventRecordIndex].actionName, ". Calling handler . . ."));
}
combinationMatcher.events[eventRecordIndex].handler(event);
this._stopEventPropagationAfterHandlingIfEnabled(event, componentSearchIndex);
return true;
}
}
combinationIndex++;
}
}
sequenceLengthCounter--;
if (this._actionResolver.componentHasActionsBoundToEventType(componentSearchIndex, keyEventType)) {
var eventName = describeKeyEventType(keyEventType);
this.logger.debug(this._logPrefix(componentSearchIndex), "No matching actions found for '".concat(currentCombination.describe(), "' ").concat(eventName, "."));
} else {
this.logger.debug(this._logPrefix(componentSearchIndex), "Doesn't define a handler for '".concat(currentCombination.describe(), "' ").concat(describeKeyEventType(keyEventType), "."));
}
var eventName = describeKeyEventType(eventRecordIndex);
this.logger.debug(this._logPrefix(componentSearchIndex), "No matching actions found for '".concat(this._describeCurrentKeyCombination(), "' ").concat(eventName, "."));
}

@@ -1144,7 +461,2 @@

}, {
key: "_stateFromEvent",
value: function _stateFromEvent(event) {
return event.simulated ? KeyEventRecordState.simulated : KeyEventRecordState.seen;
}
}, {
key: "_stopEventPropagationAfterHandlingIfEnabled",

@@ -1161,93 +473,6 @@ value: function _stopEventPropagationAfterHandlingIfEnabled(event, componentId) {

}, {
key: "_stopEventPropagationAfterIgnoringIfEnabled",
value: function _stopEventPropagationAfterIgnoringIfEnabled(event, componentId) {
if (Configuration.option('stopEventPropagationAfterIgnoring')) {
this._stopEventPropagation(event, componentId);
return true;
}
return false;
key: "_stopEventPropagation",
value: function _stopEventPropagation(event, componentId) {
throw new Error('_stopEventPropagation must be overridden by a subclass');
}
}, {
key: "_describeCurrentKeyCombination",
value: function _describeCurrentKeyCombination() {
return this._getCurrentKeyCombination().ids[0];
}
}, {
key: "_tryMatchSequenceWithKeyAliases",
value: function _tryMatchSequenceWithKeyAliases(keyMatcher, sequenceIds) {
if (sequenceIds.length === 0) {
return keyMatcher[''];
}
var idSizes = sequenceIds.map(function (ids) {
return ids.length;
});
var indexCounters = sequenceIds.map(function () {
return 0;
});
var triedAllPossiblePermutations = false;
while (!triedAllPossiblePermutations) {
var sequenceIdPermutation = indexCounters.map(function (sequenceIdIndex, index) {
return sequenceIds[index][sequenceIdIndex];
});
var candidateId = sequenceIdPermutation.join(' ');
if (keyMatcher[candidateId]) {
return keyMatcher[candidateId];
}
var incrementer = 0;
var carry = true;
while (carry && incrementer < indexCounters.length) {
var count = indexFromEnd(indexCounters, incrementer);
var newIndex = (count + 1) % (indexFromEnd(idSizes, incrementer) || 1);
indexCounters[indexCounters.length - (incrementer + 1)] = newIndex;
carry = newIndex === 0;
if (carry) {
incrementer++;
}
}
triedAllPossiblePermutations = incrementer === indexCounters.length;
}
}
}, {
key: "_combinationMatchesKeys",
value: function _combinationMatchesKeys(keyBeingPressed, keyCombination, combinationMatch, eventRecordIndex) {
var combinationHasHandlerForEventType = combinationMatch.events[eventRecordIndex];
if (!combinationHasHandlerForEventType) {
/**
* If the combination does not have any actions bound to the key event we are
* currently processing, we skip checking if it matches the current keys being
* pressed.
*/
return false;
}
var keyCompletesCombination = false;
var combinationMatchesKeysPressed = Object.keys(combinationMatch.keyDictionary).every(function (candidateKeyName) {
var keyState = getKeyState(keyCombination, candidateKeyName);
if (keyState) {
if (keyIsCurrentlyTriggeringEvent(keyState, eventRecordIndex)) {
if (keyBeingPressed && keyBeingPressed === getKeyAlias(keyCombination, candidateKeyName)) {
keyCompletesCombination = !keyAlreadyTriggeredEvent(keyState, eventRecordIndex);
}
return true;
} else {
return false;
}
} else {
return false;
}
});
return combinationMatchesKeysPressed && keyCompletesCombination;
}
/**

@@ -1257,4 +482,4 @@ * Synchronises the key combination history to match the modifier key flag attributes

* @param {KeyboardEvent} event - Event to check the modifier flags for
* @param {String} key - Name of key that events relates to
* @param {KeyEventRecordIndex} keyEventRecordIndex - The record index of the current
* @param {string} key - Name of key that events relates to
* @param {KeyEventType} keyEventType - The record index of the current
* key event type

@@ -1266,4 +491,4 @@ * @protected

key: "_checkForModifierFlagDiscrepancies",
value: function _checkForModifierFlagDiscrepancies(event, key, keyEventRecordIndex) {
var _this5 = this;
value: function _checkForModifierFlagDiscrepancies(event, key, keyEventType) {
var _this2 = this;

@@ -1283,11 +508,12 @@ /**

*/
if (key === modifierKey && keyEventRecordIndex === KeyEventRecordIndex.keyup) {
if (key === modifierKey && keyEventType === KeyEventType.keyup) {
return;
}
var modifierStillPressed = _this5._keyIsCurrentlyDown(modifierKey);
var currentCombination = _this2.getCurrentCombination();
var modifierStillPressed = currentCombination.isKeyStillPressed(modifierKey);
ModifierFlagsDictionary[modifierKey].forEach(function (attributeName) {
if (event[attributeName] === false && modifierStillPressed) {
_this5._addToCurrentKeyCombination(modifierKey, KeyEventRecordIndex.keyup, _this5._stateFromEvent(event));
currentCombination.setKeyState(modifierKey, KeyEventType.keyup, stateFromEvent(event));
}

@@ -1297,77 +523,2 @@ });

}
}, {
key: "_keyIsCurrentlyDown",
value: function _keyIsCurrentlyDown(keyName) {
var keyState = this._getCurrentKeyState(keyName);
var keyIsDown = keyIsCurrentlyTriggeringEvent(keyState, KeyEventRecordIndex.keypress) && !keyIsCurrentlyTriggeringEvent(keyState, KeyEventRecordIndex.keyup);
return !!keyIsDown;
}
}, {
key: "_getCurrentKeyState",
value: function _getCurrentKeyState(keyName) {
var currentCombination = this._getCurrentKeyCombination();
return getKeyState(currentCombination, keyName);
}
}, {
key: "_buildCombinationKeyAliases",
value: function _buildCombinationKeyAliases(keyDictionary) {
var aliasFunctions = function () {
if (keyDictionary['Shift']) {
if (keyDictionary['Alt']) {
return [resolveAltShiftedAlias, resolveUnaltShiftedAlias];
} else {
return [resolveShiftedAlias, resolveUnshiftedAlias];
}
} else {
if (keyDictionary['Alt']) {
return [resolveAltedAlias, resolveUnaltedAlias];
} else {
var nop = function nop(keyName) {
return [keyName];
};
return [nop, nop];
}
}
}();
return Object.keys(keyDictionary).reduce(function (memo, keyName) {
resolveKeyAlias(keyName).forEach(function (normalizedKey) {
aliasFunctions.forEach(function (aliasFunction) {
aliasFunction(normalizedKey).forEach(function (keyAlias) {
if (keyAlias !== keyName || keyName !== normalizedKey) {
memo[keyAlias] = keyName;
}
});
});
});
return memo;
}, {});
}
}, {
key: "_setComponentPosition",
value: function _setComponentPosition(componentId, position) {
this.componentIdDict[componentId] = position;
}
}, {
key: "_getComponentPosition",
value: function _getComponentPosition(componentId) {
return this.componentIdDict[componentId];
}
}, {
key: "_getComponent",
value: function _getComponent(componentId) {
var componentPosition = this._getComponentPosition(componentId);
return this.componentList[componentPosition];
}
}, {
key: "_getComponentAndPosition",
value: function _getComponentAndPosition(componentId) {
var componentPosition = this._getComponentPosition(componentId);
return [this.componentList[componentPosition], componentPosition];
}
/**

@@ -1387,43 +538,2 @@ * Returns a prefix for all log entries related to the current event strategy

function getKeyAlias(keyCombination, keyName) {
var keyState = keyCombination.keys[keyName];
if (keyState) {
return keyName;
} else {
var keyAlias = keyCombination.keyAliases[keyName];
if (keyAlias) {
return keyAlias;
} else {
return keyName;
}
}
}
function getKeyState(keyCombination, keyName) {
var keyState = keyCombination.keys[keyName];
if (keyState) {
return keyState;
} else {
var keyAlias = keyCombination.keyAliases[keyName];
if (keyAlias) {
return keyCombination.keys[keyAlias];
}
}
}
function newComponentRegistryItem() {
return {
childIds: [],
parentId: null
};
}
function keyAlreadyTriggeredEvent(keyState, eventRecordIndex) {
return keyState && keyState[KeyEventSequenceIndex.previous][eventRecordIndex];
}
export default AbstractKeyEventStrategy;

@@ -24,7 +24,7 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

import AbstractKeyEventStrategy from './AbstractKeyEventStrategy';
import KeyEventRecordIndex from '../../const/KeyEventRecordIndex';
import KeyEventCounter from '../KeyEventCounter';
import KeyEventType from '../../const/KeyEventType';
import KeyEventCounter from '../listening/KeyEventCounter';
import describeKeyEventType from '../../helpers/logging/describeKeyEventType';
import Configuration from '../Configuration';
import Logger from '../Logger';
import Configuration from '../config/Configuration';
import Logger from '../logging/Logger';
import printComponent from '../../helpers/logging/printComponent';

@@ -34,6 +34,7 @@ import isUndefined from '../../utils/isUndefined';

import isCmdKey from '../../helpers/parsing-key-maps/isCmdKey';
import keyIsCurrentlyTriggeringEvent from '../../helpers/parsing-key-maps/keyIsCurrentlyTriggeringEvent';
import describeKeyEvent from '../../helpers/logging/describeKeyEvent';
import EventResponse from '../../const/EventResponse';
import KeyEventRecordState from '../../const/KeyEventRecordState';
import KeyEventState from '../../const/KeyEventState';
import stateFromEvent from '../../helpers/parsing-key-maps/stateFromEvent';
import EventPropagator from '../listening/EventPropagator';
/**

@@ -71,3 +72,3 @@ * Defines behaviour for dealing with key maps defined in focus-only HotKey components

* changes, and a different tree of elements are focused, a new id is allocated
* @typedef {Number} FocusTreeId
* @typedef {number} FocusTreeId
*/

@@ -81,25 +82,2 @@

_this.focusTreeId = 0;
/**
* Record of the event currently bubbling up through the React application (and
* beyond). This state is *not* cleared when the event propagation is finished
* or when the component focus tree changes. It persists until it is overridden
* by a new event, so that the global strategy is able to inspect the last
* event seen by the React application, even after focus is lost.
*/
_this.currentEvent = {
/**
* The name of the key the event belongs to
* @type {ReactKeyName}
*/
key: null,
/**
* The event record index of the type of key event
* @type {KeyEventRecordIndex}
*/
type: null,
handled: false,
ignored: false
};
return _this;

@@ -126,54 +104,7 @@ }

this.focusTreeId += 1;
this._clearEventPropagationState();
this.eventPropagator = new EventPropagator(this.componentList, {
logger: this.logger,
logPrefix: this._logPrefix.bind(this)
});
}
/**
* Clears the history that is maintained for the duration of a single keyboard event's
* propagation up the React component tree towards the root component, so that the
* next keyboard event starts with a clean state.
* @private
*/
}, {
key: "_clearEventPropagationState",
value: function _clearEventPropagationState() {
/**
* Object containing state of a key events propagation up the render tree towards
* the document root
* @type {{previousComponentPosition: number, actionHandled: boolean}}}
*/
this.eventPropagationState = {
/**
* Index of the component last seen to be handling a key event
* @type {ComponentId}
*/
previousComponentPosition: -1,
/**
* Whether the keyboard event currently being handled has already matched a
* handler function that has been called
* @type {Boolean}
*/
actionHandled: false,
/**
* Whether the keyboard event current being handled should be ignored
* @type {Boolean}
*/
ignoreEvent: false,
/**
* Whether the keyboard event current being handled should be observed, even
* if matches the ignoreEventCondition
* @type {Boolean}
*/
forceObserveEvent: false,
/**
* Whether the strategy is in the process of stopping propagation and tidying
* up
*/
stopping: false
};
}
/********************************************************************************

@@ -202,3 +133,3 @@ * Registering key maps and handlers

if (this.resetOnNextFocus || this.keyMaps) {
if (this.resetOnNextFocus) {
/**

@@ -215,3 +146,3 @@ * We know components have just lost focus or keymaps have already been built,

if (this._getComponent(componentId)) {
if (this.componentList.containsId(componentId)) {
/**

@@ -227,3 +158,3 @@ * The <tt>componentId</tt> has already been registered - this occurs when the

this._addComponentToList(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this._addComponent(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);

@@ -233,8 +164,5 @@ this.logger.debug(this._logPrefix(componentId, {

}), 'Focused. \n');
var component = this._getComponent(componentId);
this.logger.verbose(this._logPrefix(componentId, {
eventId: false
}), 'Component options:\n', printComponent(component));
}), 'Component options:\n', printComponent(this.componentList.get(componentId)));
return this.focusTreeId;

@@ -263,9 +191,8 @@ }

var componentPosition = this._getComponentPosition(componentId);
if (focusTreeId !== this.focusTreeId || isUndefined(componentPosition)) {
if (focusTreeId !== this.focusTreeId || !this.componentList.containsId(componentId)) {
return;
}
this.componentList[componentPosition] = this._buildComponentOptions(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this.componentList.update(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this.getKeyHistory().setMaxLength(this.componentList.getLongestSequence());
this.logger.debug(this._logPrefix(componentId, {

@@ -281,8 +208,6 @@ focusTreeId: focusTreeId,

var component = this._getComponent(componentId);
this.logger.verbose(this._logPrefix(componentId, {
focusTreeId: focusTreeId,
eventId: false
}), 'Component options:\n', printComponent(component));
}), 'Component options:\n', printComponent(this.componentList.get(componentId)));
}

@@ -295,3 +220,3 @@ /**

* @param {ComponentId} componentId - Index of component that is blurring
* @returns {Boolean} Whether the component still has event propagation yet to handle
* @returns {boolean} Whether the component still has event propagation yet to handle
*/

@@ -306,6 +231,3 @@

var componentPosition = this._getComponentPosition(componentId);
var previousComponentPosition = this.eventPropagationState.previousComponentPosition;
var outstandingEventPropagation = previousComponentPosition !== -1 && previousComponentPosition + 1 < componentPosition;
var outstandingEventPropagation = this.eventPropagator.isPendingPropagation();
this.logger.debug("".concat(this._logPrefix(componentId, {

@@ -323,3 +245,3 @@ focusTreeId: focusTreeId,

* @typedef {KeyboardEvent} SyntheticKeyboardEvent
* @property {Function} persist
* @property {function} persist
*/

@@ -348,50 +270,34 @@

var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
var key = getKeyName(event);
var _key = getKeyName(event);
if (event.repeat && Configuration.option('ignoreRepeatedEventsWhenKeyHeldDown')) {
this.logger.debug(this._logPrefix(componentId), "Ignored repeated ".concat(describeKeyEvent(event, _key, KeyEventRecordIndex.keydown), " event."));
this._ignoreEvent(event, componentId);
if (focusTreeId !== this.focusTreeId) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat(describeKeyEvent(event, key, KeyEventType.keydown), " event because it had an old focus tree id: ").concat(focusTreeId, "."));
this.eventPropagator.ignoreEvent(event);
return true;
}
if (focusTreeId !== this.focusTreeId) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat(describeKeyEvent(event, _key, KeyEventRecordIndex.keydown), " event because it had an old focus tree id: ").concat(focusTreeId, "."));
var started = this.eventPropagator.startNewPropagationStep(componentId, event, key, KeyEventType.keydown);
this._ignoreEvent(event, componentId);
return true;
if (!started) {
return;
}
var responseAction = this._howToHandleKeyEvent(event, focusTreeId, componentId, _key, options, KeyEventRecordIndex.keydown);
/**
* We need to record the position of the component that is currently dealing with
* the event, in case the component defines a handler for that event that changes
* the focus or content in the render tree, causing the component to be de-registered
* and have its position lost
*/
var responseAction = this._howToHandleKeyEvent(event, focusTreeId, componentId, key, options, KeyEventType.keydown);
var componentPosition = this._getComponentPosition(componentId);
if (responseAction === EventResponse.handled) {
var keyInCurrentCombination = !!this._getCurrentKeyState(_key);
var keyEventState = stateFromEvent(event);
var currentCombination = this.getCurrentCombination();
var keyEventState = this._stateFromEvent(event);
if (keyInCurrentCombination || this.keyCombinationIncludesKeyUp) {
this._startAndLogNewKeyCombination(_key, KeyEventRecordIndex.keydown, focusTreeId, componentId, keyEventState);
if (currentCombination.isKeyIncluded(key) || currentCombination.isEnding()) {
this._startAndLogNewKeyCombination(key, focusTreeId, componentId, keyEventState);
} else {
this._addToAndLogCurrentKeyCombination(_key, KeyEventRecordIndex.keydown, focusTreeId, componentId, keyEventState);
this._addToAndLogCurrentKeyCombination(key, KeyEventType.keydown, focusTreeId, componentId, keyEventState);
}
this._callHandlerIfActionNotHandled(event, _key, KeyEventRecordIndex.keydown, componentId, focusTreeId);
this._callHandlerIfActionNotHandled(event, key, KeyEventType.keydown, componentId, focusTreeId);
}
this._simulateKeypressForNonPrintableKeys(event, _key, focusTreeId, componentId, options);
this._simulateKeyPressForNonPrintableKeys(event, key, focusTreeId, componentId, options);
this._updateEventPropagationHistory(componentId, componentPosition);
this.eventPropagator.finishPropagationStep();
return false;

@@ -401,33 +307,13 @@ }

key: "_howToHandleKeyEvent",
value: function _howToHandleKeyEvent(event, focusTreeId, componentId, key, options, keyEventRecordIndex) {
if (this._shouldIgnoreEvent()) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat(describeKeyEvent(event, key, keyEventRecordIndex), " event because ignoreEventsFilter rejected it."));
this._ignoreEvent(event, componentId);
return EventResponse.ignored;
}
if (this._isNewKeyEvent(componentId)) {
this._setNewEventParameters(event, keyEventRecordIndex);
/**
* We know that this is a new key event and not the same event bubbling up
* the React render tree towards the document root, so perform actions specific
* to the first time an event is seen
*/
this._setIgnoreEventFlag(event, options);
if (this._shouldIgnoreEvent()) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat(describeKeyEvent(event, key, keyEventRecordIndex), " event because ignoreEventsFilter rejected it."));
this._ignoreEvent(event, componentId);
return EventResponse.ignored;
value: function _howToHandleKeyEvent(event, focusTreeId, componentId, key, options, keyEventType) {
if (this.eventPropagator.isFirstPropagationStep()) {
if (options.ignoreEventsCondition(event) && this.eventPropagator.ignoreEvent(event)) {
return this._eventIsToBeIgnored(event, componentId, key, keyEventType);
}
this.logger.debug(this._logPrefix(componentId), "New ".concat(describeKeyEvent(event, key, keyEventRecordIndex), " event."));
this.logger.debug(this._logPrefix(componentId), "New ".concat(describeKeyEvent(event, key, keyEventType), " event."));
this._checkForModifierFlagDiscrepancies(event, key, keyEventRecordIndex);
this._checkForModifierFlagDiscrepancies(event, key, keyEventType);
} else if (this.eventPropagator.isIgnoringEvent()) {
return this._eventIsToBeIgnored(event, componentId, key, keyEventType);
}

@@ -437,2 +323,8 @@

}
}, {
key: "_eventIsToBeIgnored",
value: function _eventIsToBeIgnored(event, componentId, key, keyEventType) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat(describeKeyEvent(event, key, keyEventType), " event because ignoreEventsFilter rejected it."));
return EventResponse.ignored;
}
/**

@@ -453,3 +345,3 @@ * Records a keypress keyboard event and matches it against the list of pre-registered

* is handled.
* @return {Boolean} Whether the HotKeys component should discard its current focus
* @returns {boolean} Whether the HotKeys component should discard its current focus
* tree Id, because it belongs to an old focus tree.

@@ -459,20 +351,17 @@ */

}, {
key: "handleKeypress",
value: function handleKeypress(event, focusTreeId, componentId, options) {
var _key = getKeyName(event);
key: "handleKeyPress",
value: function handleKeyPress(event, focusTreeId, componentId, options) {
var key = getKeyName(event);
var currentCombination = this.getCurrentCombination();
if (event.repeat && Configuration.option('ignoreRepeatedEventsWhenKeyHeldDown')) {
this.logger.debug(this._logPrefix(componentId), "Ignored repeated ".concat(describeKeyEvent(event, _key, KeyEventRecordIndex.keypress), " event."));
this._ignoreEvent(event, componentId);
if (currentCombination.isKeyPressSimulated(key)) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat(describeKeyEvent(event, key, KeyEventType.keypress), " as it was not expected, and has already been simulated."));
this.eventPropagator.ignoreEvent(event);
return true;
}
if (this._alreadySimulatedEvent(KeyEventRecordIndex.keypress, _key)) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat(describeKeyEvent(event, _key, KeyEventRecordIndex.keypress), " as it was not expected, and has already been simulated."));
var started = this.eventPropagator.startNewPropagationStep(componentId, event, key, KeyEventType.keypress);
this._ignoreEvent(event, componentId);
return true;
if (!started) {
return;
}

@@ -486,17 +375,8 @@

var responseAction = this._howToHandleKeyEvent(event, focusTreeId, componentId, _key, options, KeyEventRecordIndex.keypress);
var responseAction = this._howToHandleKeyEvent(event, focusTreeId, componentId, key, options, KeyEventType.keypress);
if (this._isNewKeyEvent(componentId) && this._getCurrentKeyState(_key)) {
this._addToAndLogCurrentKeyCombination(_key, KeyEventRecordIndex.keypress, focusTreeId, componentId, this._stateFromEvent(event));
if (this.eventPropagator.isFirstPropagationStep(componentId) && currentCombination.isKeyIncluded(key)) {
this._addToAndLogCurrentKeyCombination(key, KeyEventType.keypress, focusTreeId, componentId, stateFromEvent(event));
}
/**
* We need to record the position of the component that is currently dealing with
* the event, in case the component defines a handler for that event that changes
* the focus or content in the render tree, causing the component to be de-registered
* and have its position lost
*/
var componentPosition = this._getComponentPosition(componentId);
/**
* We attempt to find a handler of the event, only if it has not already

@@ -508,7 +388,6 @@ * been handled and should not be ignored

if (responseAction === EventResponse.handled) {
this._callHandlerIfActionNotHandled(event, _key, KeyEventRecordIndex.keypress, componentId, focusTreeId);
this._callHandlerIfActionNotHandled(event, key, KeyEventType.keypress, componentId, focusTreeId);
}
this._updateEventPropagationHistory(componentId, componentPosition);
this.eventPropagator.finishPropagationStep();
return shouldDiscardFocusTreeId;

@@ -531,3 +410,3 @@ }

* is handled.
* @return {Boolean} Whether HotKeys component should discard its current focusTreeId
* @returns {boolean} Whether HotKeys component should discard its current focusTreeId
* because it's stale (part of an old focus tree)

@@ -537,12 +416,17 @@ */

}, {
key: "handleKeyup",
value: function handleKeyup(event, focusTreeId, componentId, options) {
var _key = getKeyName(event);
key: "handleKeyUp",
value: function handleKeyUp(event, focusTreeId, componentId, options) {
var key = getKeyName(event);
var currentCombination = this.getCurrentCombination();
if (this._alreadySimulatedEvent(KeyEventRecordIndex.keyup, _key)) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat(describeKeyEvent(event, _key, KeyEventRecordIndex.keyup), " as it was not expected, and has already been simulated."));
if (currentCombination.isKeyUpSimulated(key)) {
this.logger.debug(this._logPrefix(componentId), "Ignored ".concat(describeKeyEvent(event, key, KeyEventType.keyup), " as it was not expected, and has already been simulated."));
this.eventPropagator.ignoreEvent(event);
return true;
}
this._ignoreEvent(event, componentId);
var started = this.eventPropagator.startNewPropagationStep(componentId, event, key, KeyEventType.keyup);
return true;
if (!started) {
return;
}

@@ -556,3 +440,3 @@

var responseAction = this._howToHandleKeyEvent(event, focusTreeId, componentId, _key, options, KeyEventRecordIndex.keyup);
var responseAction = this._howToHandleKeyEvent(event, focusTreeId, componentId, key, options, KeyEventType.keyup);
/**

@@ -566,15 +450,6 @@ * We then add the keyup to our current combination - regardless of whether

if (this._isNewKeyEvent(componentId) && this._getCurrentKeyState(_key)) {
this._addToAndLogCurrentKeyCombination(_key, KeyEventRecordIndex.keyup, focusTreeId, componentId, this._stateFromEvent(event));
if (this.eventPropagator.isFirstPropagationStep(componentId) && currentCombination.isKeyIncluded(key)) {
this._addToAndLogCurrentKeyCombination(key, KeyEventType.keyup, focusTreeId, componentId, stateFromEvent(event));
}
/**
* We need to record the position of the component that is currently dealing with
* the event, in case the component defines a handler for that event that changes
* the focus or content in the render tree, causing the component to be de-registered
* and have its position lost
*/
var componentPosition = this._getComponentPosition(componentId);
/**
* We attempt to find a handler of the event, only if it has not already

@@ -586,3 +461,3 @@ * been handled and should not be ignored

if (responseAction === EventResponse.handled) {
this._callHandlerIfActionNotHandled(event, _key, KeyEventRecordIndex.keyup, componentId, focusTreeId);
this._callHandlerIfActionNotHandled(event, key, KeyEventType.keyup, componentId, focusTreeId);
}

@@ -595,6 +470,5 @@ /**

this._simulateKeyUpEventsHiddenByCmd(event, _key, focusTreeId, componentId, options);
this._simulateKeyUpEventsHiddenByCmd(event, key, focusTreeId, componentId, options);
this._updateEventPropagationHistory(componentId, componentPosition);
this.eventPropagator.finishPropagationStep();
return shouldDiscardFocusId;

@@ -607,3 +481,3 @@ }

* is currently set to keydown or keypress.
* @param {KeyEventRecordIndex} recordIndex Index of key event to move the key state
* @param {KeyEventType} recordIndex Index of key event to move the key state
* up to.

@@ -615,5 +489,5 @@ */

value: function closeHangingKeyCombination(keyName, recordIndex) {
var keyState = this._getCurrentKeyState(keyName);
var currentCombination = this.getCurrentCombination();
if (keyIsCurrentlyTriggeringEvent(keyState, KeyEventRecordIndex.keydown) && !keyIsCurrentlyTriggeringEvent(keyState, recordIndex)) {
if (currentCombination.isKeyIncluded(keyName) && !currentCombination.isEventTriggered(keyName, recordIndex)) {
/**

@@ -624,9 +498,9 @@ * If the key is in the current combination and recorded as still being pressed

*/
this._addToCurrentKeyCombination(keyName, recordIndex, KeyEventRecordState.simulated);
currentCombination.setKeyState(keyName, recordIndex, KeyEventState.simulated);
}
}
}, {
key: "_simulateKeypressForNonPrintableKeys",
value: function _simulateKeypressForNonPrintableKeys(event, key, focusTreeId, componentId, options) {
this._handleEventSimulation('keypressEventsToSimulate', 'simulatePendingKeyPressEvents', this._shouldSimulate(KeyEventRecordIndex.keypress, key), {
key: "_simulateKeyPressForNonPrintableKeys",
value: function _simulateKeyPressForNonPrintableKeys(event, key, focusTreeId, componentId, options) {
this._handleEventSimulation('keypressEventsToSimulate', 'simulatePendingKeyPressEvents', this._shouldSimulate(KeyEventType.keypress, key), {
event: event,

@@ -645,8 +519,3 @@ key: key,

if (isCmdKey(key)) {
/**
* When the command key is pressed down with other non-modifier keys, the browser
* does not trigger the keyup event of those keys, so we simulate them when the
* command key is released
*/
Object.keys(this._getCurrentKeyCombination().keys).forEach(function (keyName) {
this.getCurrentCombination().forEachKey(function (keyName) {
if (isCmdKey(keyName)) {

@@ -656,3 +525,3 @@ return;

_this2._handleEventSimulation('keyupEventsToSimulate', 'simulatePendingKeyUpEvents', _this2._shouldSimulate(KeyEventRecordIndex.keyup, keyName), {
_this2._handleEventSimulation('keyupEventsToSimulate', 'simulatePendingKeyUpEvents', _this2._shouldSimulate(KeyEventType.keyup, keyName), {
event: event,

@@ -668,108 +537,17 @@ key: keyName,

}, {
key: "_ignoreEvent",
value: function _ignoreEvent(event, componentId) {
this.currentEvent.ignored = true;
var componentPosition = this._getComponentPosition(componentId);
if (this._stopEventPropagationAfterIgnoringIfEnabled(event, componentId)) {
this._updateEventPropagationHistory(componentId, componentPosition, {
forceReset: true
});
} else {
this._updateEventPropagationHistory(componentId, componentPosition);
key: "_stopEventPropagation",
value: function _stopEventPropagation(event, componentId) {
if (this.eventPropagator.stop(event)) {
this.logger.debug(this._logPrefix(componentId), 'Stopping further event propagation.');
}
}
/**
* Whether KeyEventManager should ignore the event that is currently being handled
* @returns {Boolean} Whether to ignore the event
*
* Do not override this method. Use setIgnoreEventsCondition() instead.
* @private
*/
}, {
key: "_shouldIgnoreEvent",
value: function _shouldIgnoreEvent() {
var _this$eventPropagatio = this.eventPropagationState,
ignoreEvent = _this$eventPropagatio.ignoreEvent,
forceObserveEvent = _this$eventPropagatio.forceObserveEvent;
return !forceObserveEvent && ignoreEvent;
key: "getEventPropagator",
value: function getEventPropagator() {
return this.eventPropagator;
}
/**
* Returns whether this is a previously seen event bubbling up to render tree towards
* the document root, or whether it is a new event that has not previously been seen.
* @param {ComponentId} componentId Index of the component currently handling
* the keyboard event
* @return {Boolean} If the event has been seen before
* @private
*/
}, {
key: "_isNewKeyEvent",
value: function _isNewKeyEvent(componentId) {
var previousComponentPosition = this.eventPropagationState.previousComponentPosition;
return previousComponentPosition === -1 || previousComponentPosition >= this._getComponentPosition(componentId);
}
}, {
key: "_updateEventPropagationHistory",
value: function _updateEventPropagationHistory(componentId, componentPosition) {
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
forceReset: false
};
if (options.forceReset || this._isFocusTreeRoot(componentId)) {
this._clearEventPropagationState();
} else {
this.eventPropagationState.previousComponentPosition = componentPosition;
}
}
/**
* Sets the ignoreEvent flag so that subsequent handlers of the same event
* do not have to re-evaluate whether to ignore the event or not as it bubbles
* up towards the document root
* @param {KeyboardEvent} event The event to decide whether to ignore
* @param {Object} options Options containing the function to use
* to set the ignoreEvent flag
* @param {Function} options.ignoreEventsCondition Function used to for setting
* the ignoreEvent flag
* @private
*/
}, {
key: "_setIgnoreEventFlag",
value: function _setIgnoreEventFlag(event, options) {
this.eventPropagationState.ignoreEvent = options.ignoreEventsCondition(event);
}
}, {
key: "ignoreEvent",
value: function ignoreEvent() {
this.eventPropagationState.ignoreEvent = true;
}
}, {
key: "forceObserveEvent",
value: function forceObserveEvent() {
this.eventPropagationState.forceObserveEvent = true;
}
}, {
key: "_isFocusTreeRoot",
value: function _isFocusTreeRoot(componentId) {
return this._getComponentPosition(componentId) >= this.componentList.length - 1;
}
}, {
key: "_setNewEventParameters",
value: function _setNewEventParameters(event, type) {
KeyEventCounter.incrementId();
this.currentEvent = {
key: event.key,
type: type,
handled: false,
ignored: false
};
}
}, {
key: "_startAndLogNewKeyCombination",
value: function _startAndLogNewKeyCombination(keyName, eventRecordIndex, focusTreeId, componentId, keyEventState) {
this._startNewKeyCombination(keyName, eventRecordIndex, keyEventState);
value: function _startAndLogNewKeyCombination(keyName, focusTreeId, componentId, keyEventState) {
this.getKeyHistory().startNewKeyCombination(keyName, keyEventState);
this.logger.verbose(this._logPrefix(componentId, {

@@ -780,13 +558,13 @@ focusTreeId: focusTreeId

focusTreeId: focusTreeId
}), "Key history: ".concat(printComponent(this.keyCombinationHistory), "."));
}), "Key history: ".concat(printComponent(this.getKeyHistory().toJSON()), "."));
}
}, {
key: "_addToAndLogCurrentKeyCombination",
value: function _addToAndLogCurrentKeyCombination(keyName, eventRecordIndex, focusTreeId, componentId, keyEventState) {
this._addToCurrentKeyCombination(keyName, eventRecordIndex, keyEventState);
value: function _addToAndLogCurrentKeyCombination(keyName, keyEventType, focusTreeId, componentId, keyEventState) {
this.getKeyHistory().addKeyToCurrentCombination(keyName, keyEventType, keyEventState);
if (eventRecordIndex === KeyEventRecordIndex.keydown) {
if (keyEventType === KeyEventType.keydown) {
this.logger.verbose(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Added '".concat(keyName, "' to current combination: '").concat(this._getCurrentKeyCombination().ids[0], "'."));
}), "Added '".concat(keyName, "' to current combination: '").concat(this.getCurrentCombination().describe(), "'."));
}

@@ -796,3 +574,3 @@

focusTreeId: focusTreeId
}), "Key history: ".concat(printComponent(this.keyCombinationHistory), "."));
}), "Key history: ".concat(printComponent(this.getKeyHistory().toJSON()), "."));
}

@@ -804,14 +582,2 @@ /********************************************************************************

}, {
key: "_stopEventPropagation",
value: function _stopEventPropagation(event, componentId) {
if (!this.eventPropagationState.stopping) {
this.eventPropagationState.stopping = true;
this.logger.debug(this._logPrefix(componentId), 'Stopping further event propagation.');
if (!event.simulated) {
event.stopPropagation();
}
}
}
}, {
key: "_handleEventSimulation",

@@ -844,3 +610,3 @@ value: function _handleEventSimulation(listName, handlerName, shouldSimulate, _ref) {

if (this._isFocusTreeRoot(componentId) || this.eventPropagationState.stopping) {
if (this.componentList.isRoot(componentId) || this.eventPropagator.isStopped()) {
if (!this.keyEventManager.isGlobalListenersBound()) {

@@ -859,3 +625,3 @@ this[handlerName]();

value: function simulatePendingKeyPressEvents() {
this._simulatePendingKeyEvents('keypressEventsToSimulate', 'handleKeypress');
this._simulatePendingKeyEvents('keypressEventsToSimulate', 'handleKeyPress');
}

@@ -865,3 +631,3 @@ }, {

value: function simulatePendingKeyUpEvents() {
this._simulatePendingKeyEvents('keyupEventsToSimulate', 'handleKeyup');
this._simulatePendingKeyEvents('keyupEventsToSimulate', 'handleKeyUp');
}

@@ -886,10 +652,2 @@ }, {

this[listName] = [];
/**
* If an event gets handled and causes a focus shift, then subsequent components
* will ignore the event (including the root component) and the conditions to
* reset the propagation state are never met - so we ensure that after we are done
* simulating the keypress event, the propagation state is reset
*/
this._clearEventPropagationState();
}

@@ -905,3 +663,3 @@ /********************************************************************************

* @param {NormalizedKeyName} keyName Normalized key name
* @param {KeyEventRecordIndex} eventRecordIndex The record index of the current key event type
* @param {KeyEventType} keyEventType The record index of the current key event type
* @param {FocusTreeId} focusTreeId Id of focus tree component thinks it's apart of

@@ -915,31 +673,29 @@ * @param {ComponentId} componentId Index of the component that is currently handling

key: "_callHandlerIfActionNotHandled",
value: function _callHandlerIfActionNotHandled(event, keyName, eventRecordIndex, componentId, focusTreeId) {
var eventName = describeKeyEventType(eventRecordIndex);
value: function _callHandlerIfActionNotHandled(event, keyName, keyEventType, componentId, focusTreeId) {
var eventName = describeKeyEventType(keyEventType);
var combinationName = this.getCurrentCombination().describe();
var combinationName = this._describeCurrentKeyCombination();
if (!this.componentList.anyActionsForEventType(keyEventType)) {
this.logger.verbose(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Ignored '".concat(combinationName, "' ").concat(eventName, " because it doesn't have any ").concat(eventName, " handlers."));
return;
}
if (this.keyMapEventRecord[eventRecordIndex]) {
if (this.eventPropagationState.actionHandled) {
this.logger.debug(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Ignored '".concat(combinationName, "' ").concat(eventName, " as it has already been handled."));
} else {
this.logger.verbose(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Attempting to find action matching '".concat(combinationName, "' ").concat(eventName, " . . ."));
var previousComponentPosition = this.eventPropagationState.previousComponentPosition;
if (this.eventPropagator.isHandled()) {
this.logger.debug(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Ignored '".concat(combinationName, "' ").concat(eventName, " as it has already been handled."));
} else {
this.logger.verbose(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Attempting to find action matching '".concat(combinationName, "' ").concat(eventName, " . . ."));
var previousComponentPosition = this.eventPropagator.getPreviousPosition();
var componentPosition = this.componentList.getIndexById(componentId);
var componentPosition = this._getComponentPosition(componentId);
var handlerWasCalled = this._callClosestMatchingHandler(event, keyName, keyEventType, componentPosition, previousComponentPosition === -1 ? 0 : previousComponentPosition);
var handlerWasCalled = this._callMatchingHandlerClosestToEventTarget(event, keyName, eventRecordIndex, componentPosition, previousComponentPosition === -1 ? 0 : previousComponentPosition);
if (handlerWasCalled) {
this.eventPropagationState.actionHandled = true;
this.currentEvent.handled = true;
}
if (handlerWasCalled) {
this.eventPropagator.setHandled();
}
} else {
this.logger.verbose(this._logPrefix(componentId, {
focusTreeId: focusTreeId
}), "Ignored '".concat(combinationName, "' ").concat(eventName, " because it doesn't have any ").concat(eventName, " handlers."));
}

@@ -971,5 +727,4 @@ }

base += "C".concat(componentId).concat(componentIcons[componentId % componentIcons.length]);
var position = this.componentList.getIndexById(componentId);
var position = this._getComponentPosition(componentId);
if (!isUndefined(position)) {

@@ -976,0 +731,0 @@ base += "-P".concat(position).concat(componentIcons[position % componentIcons.length], ":");

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -31,14 +23,11 @@

import KeyEventRecordManager from '../KeyEventRecordManager';
import KeyEventRecordIndex from '../../const/KeyEventRecordIndex';
import KeyEventType from '../../const/KeyEventType';
import AbstractKeyEventStrategy from './AbstractKeyEventStrategy';
import capitalize from '../../utils/string/capitalize';
import describeKeyEventType from '../../helpers/logging/describeKeyEventType';
import KeyEventCounter from '../KeyEventCounter';
import Logger from '../Logger';
import removeAtIndex from '../../utils/array/removeAtIndex';
import KeyEventCounter from '../listening/KeyEventCounter';
import Logger from '../logging/Logger';
import isUndefined from '../../utils/isUndefined';
import printComponent from '../../helpers/logging/printComponent';
import getKeyName from '../../helpers/resolving-handlers/getKeyName';
import Configuration from '../Configuration';
import Configuration from '../config/Configuration';
import describeKeyEvent from '../../helpers/logging/describeKeyEvent';

@@ -48,3 +37,4 @@ import isCmdKey from '../../helpers/parsing-key-maps/isCmdKey';

import contains from '../../utils/collection/contains';
import dictionaryFrom from '../../utils/object/dictionaryFrom';
import stateFromEvent from '../../helpers/parsing-key-maps/stateFromEvent';
import normalizeEventName from '../../utils/string/normalizeEventName';
/**

@@ -122,3 +112,3 @@ * Defines behaviour for dealing with key maps defined in global HotKey components

this._addComponentToList(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this._addComponent(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);

@@ -138,3 +128,3 @@ this._updateDocumentHandlers();

eventId: false
}), 'Component options: \n', printComponent(this._getComponent(componentId)));
}), 'Component options: \n', printComponent(this.componentList.get(componentId)));
}

@@ -161,18 +151,8 @@ /**

this.eventOptions = eventOptions;
var componentPosition = this._getComponentPosition(componentId);
this.componentList.update(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this.getKeyHistory().setMaxLength(this.componentList.getLongestSequence());
/**
* Manually update the registered key map state, usually reset using
* _resetRegisteredKeyMapsState() method
*/
this.componentList[componentPosition] = this._buildComponentOptions(componentId, actionNameToKeyMap, actionNameToHandlersMap, options);
this._updateLongestKeySequenceIfNecessary(componentId);
/**
* Reset strategy state specific to the global strategy
*/
this._updateDocumentHandlers();

@@ -191,3 +171,3 @@ /**

eventId: false
}), 'Component options: \n', printComponent(this._getComponent(componentId)));
}), 'Component options: \n', printComponent(this.componentList.get(componentId)));
}

@@ -202,6 +182,2 @@ /**

value: function disableHotKeys(componentId) {
var _this$_getComponentAn = this._getComponentAndPosition(componentId),
_this$_getComponentAn2 = _slicedToArray(_this$_getComponentAn, 2),
keyMapEventRecord = _this$_getComponentAn2[0].keyMapEventRecord,
componentPosition = _this$_getComponentAn2[1];
/**

@@ -211,18 +187,7 @@ * Manually update the registered key map state, usually reset using

*/
this.componentList.remove(componentId);
this.getKeyHistory().setMaxLength(this.componentList.getLongestSequence());
this.componentList = removeAtIndex(this.componentList, componentPosition);
this._updateLongestKeySequenceIfNecessary(componentId);
this._updateDocumentHandlers();
/**
* Reset strategy state specific to the global strategy
*/
this._updateComponentIndexDictFromList({
startingAt: componentPosition
});
this._updateDocumentHandlers(keyMapEventRecord, KeyEventRecordManager.newRecord());
/**
* Reset handler resolution state

@@ -239,35 +204,5 @@ */

}, {
key: "_updateLongestKeySequenceIfNecessary",
value: function _updateLongestKeySequenceIfNecessary(componentId) {
var _this2 = this;
if (componentId === this.longestSequenceComponentIndex) {
this.longestSequence = 1;
this.componentList.forEach(function (_ref) {
var longestSequence = _ref.longestSequence;
if (longestSequence > _this2.longestSequence) {
_this2.longestSequence = longestSequence;
}
});
}
}
}, {
key: "_updateComponentIndexDictFromList",
value: function _updateComponentIndexDictFromList() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
startingAt: 0
};
var counter = options.startingAt;
while (counter < this.componentList.length) {
this._setComponentPosition(this.componentList[counter].componentId, counter);
counter++;
}
}
}, {
key: "_updateDocumentHandlers",
value: function _updateDocumentHandlers() {
var _this3 = this;
var _this2 = this;

@@ -277,28 +212,23 @@ var listenersShouldBeBound = this._listenersShouldBeBound();

if (!this.listenersBound && listenersShouldBeBound) {
var _loop = function _loop(recordIndex) {
Object.values(KeyEventType).forEach(function (recordIndex) {
var eventName = describeKeyEventType(recordIndex);
document["on".concat(eventName)] = function (keyEvent) {
_this3.keyEventManager["handleGlobal".concat(capitalize(eventName))](keyEvent);
_this2.keyEventManager["handleGlobal".concat(normalizeEventName(eventName))](keyEvent);
};
_this3.logger.debug(_this3._logPrefix(_this3.componentId, {
_this2.logger.debug(_this2._logPrefix(_this2.componentId, {
eventId: false
}), "Bound handler handleGlobal".concat(capitalize(eventName), "() to document.on").concat(eventName, "()"));
};
for (var recordIndex = 0; recordIndex < this.keyMapEventRecord.length; recordIndex++) {
_loop(recordIndex);
}
}), "Bound handler handleGlobal".concat(normalizeEventName(eventName), "() to document.on").concat(eventName, "()"));
});
this.listenersBound = true;
} else if (this.listenersBound && !listenersShouldBeBound) {
for (var recordIndex = 0; recordIndex < this.keyMapEventRecord.length; recordIndex++) {
Object.values(KeyEventType).forEach(function (recordIndex) {
var eventName = describeKeyEventType(recordIndex);
delete document["on".concat(eventName)];
this.logger.debug(this._logPrefix(this.componentId, {
_this2.logger.debug(_this2._logPrefix(_this2.componentId, {
eventId: false
}), "Removed handler handleGlobal".concat(capitalize(eventName), "() from document.on").concat(eventName, "()"));
}
}), "Removed handler handleGlobal".concat(normalizeEventName(eventName), "() from document.on").concat(eventName, "()"));
});
this.listenersBound = false;

@@ -318,3 +248,3 @@ }

value: function _listenersShouldBeBound() {
return this.componentList.length > 0 || this.listeners.keyCombination;
return this.componentList.any() || this.listeners.keyCombination;
}

@@ -341,12 +271,12 @@ /********************************************************************************

if (event.repeat && Configuration.option('ignoreRepeatedEventsWhenKeyHeldDown')) {
this.logger.debug(this._logPrefix(), "Ignored repeated ".concat(describeKeyEvent(event, _key, KeyEventRecordIndex.keydown), " event."));
this.logger.debug(this._logPrefix(), "Ignored repeated ".concat(describeKeyEvent(event, _key, KeyEventType.keydown), " event."));
return true;
}
this._checkForModifierFlagDiscrepancies(event, _key, KeyEventRecordIndex.keydown);
this._checkForModifierFlagDiscrepancies(event, _key, KeyEventType.keydown);
var reactAppResponse = this._howReactAppRespondedTo(event, _key, KeyEventRecordIndex.keydown);
var reactAppResponse = this._howReactAppRespondedTo(event, _key, KeyEventType.keydown);
if (reactAppResponse === EventResponse.unseen && this.eventOptions.ignoreEventsCondition(event)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, _key, KeyEventRecordIndex.keydown), " event because ignoreEventsFilter rejected it."));
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, _key, KeyEventType.keydown), " event because ignoreEventsFilter rejected it."));
return;

@@ -356,10 +286,9 @@ }

if (reactAppResponse !== EventResponse.ignored) {
var keyInCurrentCombination = !!this._getCurrentKeyState(_key);
var keyEventState = stateFromEvent(event);
var currentCombination = this.getCurrentCombination();
var keyEventState = this._stateFromEvent(event);
if (keyInCurrentCombination || this.keyCombinationIncludesKeyUp) {
this._startAndLogNewKeyCombination(_key, KeyEventRecordIndex.keydown, keyEventState);
if (currentCombination.isKeyIncluded(_key) || currentCombination.isEnding()) {
this._startAndLogNewKeyCombination(_key, keyEventState);
} else {
this._addToAndLogCurrentKeyCombination(_key, KeyEventRecordIndex.keydown, keyEventState);
this._addToAndLogCurrentKeyCombination(_key, KeyEventType.keydown, keyEventState);
}

@@ -369,23 +298,23 @@ }

if (!contains([EventResponse.ignored, EventResponse.handled], reactAppResponse)) {
this._callHandlerIfExists(event, _key, KeyEventRecordIndex.keydown);
this._callHandlerIfExists(event, _key, KeyEventType.keydown);
}
this._simulateKeypressForNonPrintableKeys(event, _key);
this._simulateKeyPressForNonPrintableKeys(event, _key);
}
}, {
key: "_howReactAppRespondedTo",
value: function _howReactAppRespondedTo(event, key, eventRecordIndex) {
var reactAppHistoryWithEvent = this.keyEventManager.reactAppHistoryWithEvent(key, eventRecordIndex);
value: function _howReactAppRespondedTo(event, key, keyEventType) {
var reactAppHistoryWithEvent = this.keyEventManager.reactAppHistoryWithEvent(key, keyEventType);
switch (reactAppHistoryWithEvent) {
case EventResponse.handled:
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, key, eventRecordIndex), " event because React app has already handled it."));
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, key, keyEventType), " event because React app has already handled it."));
break;
case EventResponse.ignored:
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, key, eventRecordIndex), " event because React app has declared it should be ignored."));
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, key, keyEventType), " event because React app has declared it should be ignored."));
break;
case EventResponse.seen:
this.logger.debug(this._logPrefix(), "Received ".concat(describeKeyEvent(event, key, eventRecordIndex), " event (that has already passed through React app)."));
this.logger.debug(this._logPrefix(), "Received ".concat(describeKeyEvent(event, key, keyEventType), " event (that has already passed through React app)."));
break;

@@ -395,3 +324,3 @@

KeyEventCounter.incrementId();
this.logger.debug(this._logPrefix(), "New ".concat(describeKeyEvent(event, key, eventRecordIndex), " event (that has NOT passed through React app)."));
this.logger.debug(this._logPrefix(), "New ".concat(describeKeyEvent(event, key, keyEventType), " event (that has NOT passed through React app)."));
}

@@ -412,13 +341,15 @@

}, {
key: "handleKeypress",
value: function handleKeypress(event) {
key: "handleKeyPress",
value: function handleKeyPress(event) {
var key = getKeyName(event);
if (event.repeat && Configuration.option('ignoreRepeatedEventsWhenKeyHeldDown')) {
this.logger.debug(this._logPrefix(), "Ignored repeated ".concat(describeKeyEvent(event, key, KeyEventRecordIndex.keypress), " event."));
this.logger.debug(this._logPrefix(), "Ignored repeated ".concat(describeKeyEvent(event, key, KeyEventType.keypress), " event."));
return true;
}
if (this._alreadySimulatedEvent(KeyEventRecordIndex.keypress, key)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, key, KeyEventRecordIndex.keypress), " as it was not expected, and has already been simulated."));
var currentCombination = this.getCurrentCombination();
if (currentCombination.isKeyPressSimulated(key)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, key, KeyEventType.keypress), " as it was not expected, and has already been simulated."));
return true;

@@ -432,3 +363,3 @@ }

var reactAppResponse = this._howReactAppRespondedTo(event, key, KeyEventRecordIndex.keypress);
var reactAppResponse = this._howReactAppRespondedTo(event, key, KeyEventType.keypress);
/**

@@ -439,4 +370,4 @@ * Add new key event to key combination history

if (this._getCurrentKeyState(key)) {
this._addToAndLogCurrentKeyCombination(key, KeyEventRecordIndex.keypress, this._stateFromEvent(event));
if (currentCombination.isKeyIncluded(key)) {
this._addToAndLogCurrentKeyCombination(key, KeyEventType.keypress, stateFromEvent(event));
}

@@ -451,6 +382,6 @@

*/
this.keyEventManager.closeHangingKeyCombination(key, KeyEventRecordIndex.keypress);
this.keyEventManager.closeHangingKeyCombination(key, KeyEventType.keypress);
if (this.eventOptions.ignoreEventsCondition(event)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, key, KeyEventRecordIndex.keypress), " event because ignoreEventsFilter rejected it."));
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, key, KeyEventType.keypress), " event because ignoreEventsFilter rejected it."));
return;

@@ -461,3 +392,3 @@ }

if (!contains([EventResponse.ignored, EventResponse.handled], reactAppResponse)) {
this._callHandlerIfExists(event, key, KeyEventRecordIndex.keypress);
this._callHandlerIfExists(event, key, KeyEventType.keypress);
}

@@ -476,8 +407,9 @@ }

}, {
key: "handleKeyup",
value: function handleKeyup(event) {
key: "handleKeyUp",
value: function handleKeyUp(event) {
var key = getKeyName(event);
var currentCombination = this.getCurrentCombination();
if (this._alreadySimulatedEvent(KeyEventRecordIndex.keyup, key)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, key, KeyEventRecordIndex.keyup), " as it was not expected, and has already been simulated."));
if (currentCombination.isKeyUpSimulated(key)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, key, KeyEventType.keyup), " as it was not expected, and has already been simulated."));
return true;

@@ -491,3 +423,3 @@ }

var reactAppResponse = this._howReactAppRespondedTo(event, key, KeyEventRecordIndex.keyup);
var reactAppResponse = this._howReactAppRespondedTo(event, key, KeyEventType.keyup);
/**

@@ -501,4 +433,4 @@ * We then add the keyup to our current combination - regardless of whether

if (this._getCurrentKeyState(key)) {
this._addToAndLogCurrentKeyCombination(key, KeyEventRecordIndex.keyup, this._stateFromEvent(event));
if (currentCombination.isKeyIncluded(key)) {
this._addToAndLogCurrentKeyCombination(key, KeyEventType.keyup, stateFromEvent(event));
}

@@ -512,6 +444,6 @@

*/
this.keyEventManager.closeHangingKeyCombination(key, KeyEventRecordIndex.keyup);
this.keyEventManager.closeHangingKeyCombination(key, KeyEventType.keyup);
if (this.eventOptions.ignoreEventsCondition(event)) {
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, key, KeyEventRecordIndex.keyup), " event because ignoreEventsFilter rejected it."));
this.logger.debug(this._logPrefix(), "Ignored ".concat(describeKeyEvent(event, key, KeyEventType.keyup), " event because ignoreEventsFilter rejected it."));
} else {

@@ -523,3 +455,3 @@ /**

if (!contains([EventResponse.ignored, EventResponse.handled], reactAppResponse)) {
this._callHandlerIfExists(event, key, KeyEventRecordIndex.keyup);
this._callHandlerIfExists(event, key, KeyEventType.keyup);
}

@@ -533,3 +465,3 @@ }

if (!contains([EventResponse.ignored, EventResponse.handled], reactAppResponse)) {
this._callHandlerIfExists(event, key, KeyEventRecordIndex.keyup);
this._callHandlerIfExists(event, key, KeyEventType.keyup);
}

@@ -546,9 +478,5 @@ }

if (this.listeners.keyCombination && this._allKeysAreReleased()) {
var _this$_getCurrentKeyC = this._getCurrentKeyCombination(),
keys = _this$_getCurrentKeyC.keys,
ids = _this$_getCurrentKeyC.ids;
this.listeners.keyCombination({
keys: dictionaryFrom(Object.keys(keys), true),
id: ids[0]
keys: currentCombination.getKeyDictionary(),
id: currentCombination.describe()
});

@@ -558,7 +486,7 @@ }

}, {
key: "_simulateKeypressForNonPrintableKeys",
value: function _simulateKeypressForNonPrintableKeys(event, key) {
key: "_simulateKeyPressForNonPrintableKeys",
value: function _simulateKeyPressForNonPrintableKeys(event, key) {
this.keyEventManager.simulatePendingKeyPressEvents();
this._handleEventSimulation('handleKeypress', this._shouldSimulate(KeyEventRecordIndex.keypress, key), {
this._handleEventSimulation('handleKeyPress', this._shouldSimulate(KeyEventType.keypress, key), {
event: event,

@@ -571,3 +499,3 @@ key: key

value: function _simulateKeyUpEventsHiddenByCmd(event, key) {
var _this4 = this;
var _this3 = this;

@@ -579,3 +507,3 @@ if (isCmdKey(key)) {

this.keyEventManager.simulatePendingKeyUpEvents();
Object.keys(this._getCurrentKeyCombination().keys).forEach(function (keyName) {
this.getCurrentCombination().forEachKey(function (keyName) {
if (isCmdKey(keyName)) {

@@ -585,3 +513,3 @@ return;

_this4._handleEventSimulation('handleKeyup', _this4._shouldSimulate(KeyEventRecordIndex.keyup, keyName), {
_this3._handleEventSimulation('handleKeyUp', _this3._shouldSimulate(KeyEventType.keyup, keyName), {
event: event,

@@ -595,18 +523,17 @@ key: keyName

key: "_startAndLogNewKeyCombination",
value: function _startAndLogNewKeyCombination(keyName, eventRecordIndex, keyEventState) {
this._startNewKeyCombination(keyName, eventRecordIndex, keyEventState);
value: function _startAndLogNewKeyCombination(keyName, keyEventState) {
this.getKeyHistory().startNewKeyCombination(keyName, keyEventState);
this.logger.verbose(this._logPrefix(), "Started a new combination with '".concat(keyName, "'."));
this.logger.verbose(this._logPrefix(), "Key history: ".concat(printComponent(this.keyCombinationHistory), "."));
this.logger.verbose(this._logPrefix(), "Key history: ".concat(printComponent(this.getKeyHistory().toJSON()), "."));
}
}, {
key: "_addToAndLogCurrentKeyCombination",
value: function _addToAndLogCurrentKeyCombination(keyName, eventRecordIndex, keyEventState) {
this._addToCurrentKeyCombination(keyName, eventRecordIndex, keyEventState);
value: function _addToAndLogCurrentKeyCombination(keyName, keyEventType, keyEventState) {
this.getKeyHistory().addKeyToCurrentCombination(keyName, keyEventType, keyEventState);
if (eventRecordIndex === KeyEventRecordIndex.keydown) {
this.logger.verbose(this._logPrefix(), "Added '".concat(keyName, "' to current combination: '").concat(this._getCurrentKeyCombination().ids[0], "'."));
if (keyEventType === KeyEventType.keydown) {
this.logger.verbose(this._logPrefix(), "Added '".concat(keyName, "' to current combination: '").concat(this.getCurrentCombination().describe(), "'."));
}
this.logger.verbose(this._logPrefix(), "Key history: ".concat(printComponent(this.keyCombinationHistory), "."));
this.logger.verbose(this._logPrefix(), "Key history: ".concat(printComponent(this.getKeyHistory().toJSON()), "."));
}

@@ -619,5 +546,5 @@ /********************************************************************************

key: "_handleEventSimulation",
value: function _handleEventSimulation(handlerName, shouldSimulate, _ref2) {
var event = _ref2.event,
key = _ref2.key;
value: function _handleEventSimulation(handlerName, shouldSimulate, _ref) {
var event = _ref.event,
key = _ref.key;

@@ -643,18 +570,8 @@ if (shouldSimulate && Configuration.option('simulateMissingKeyPressEvents')) {

key: "_callHandlerIfExists",
value: function _callHandlerIfExists(event, keyName, eventRecordIndex) {
var eventName = describeKeyEventType(eventRecordIndex);
value: function _callHandlerIfExists(event, keyName, keyEventType) {
var eventName = describeKeyEventType(keyEventType);
var combinationName = this.getCurrentCombination().describe();
var combinationName = this._describeCurrentKeyCombination();
if (this.keyMapEventRecord[eventRecordIndex]) {
if (!this.componentList.anyActionsForEventType(keyEventType)) {
/**
* If there is at least one handler for the specified key event type (keydown,
* keypress, keyup), then attempt to find a handler that matches the current
* key combination
*/
this.logger.verbose(this._logPrefix(), "Attempting to find action matching '".concat(combinationName, "' ").concat(eventName, " . . ."));
this._callMatchingHandlerClosestToEventTarget(event, keyName, eventRecordIndex);
} else {
/**
* If there are no handlers registered for the particular key event type

@@ -665,10 +582,23 @@ * (keydown, keypress, keyup) then skip trying to find a matching handler

this.logger.debug(this._logPrefix(), "Ignored '".concat(combinationName, "' ").concat(eventName, " because it doesn't have any ").concat(eventName, " handlers."));
return;
}
/**
* If there is at least one handler for the specified key event type (keydown,
* keypress, keyup), then attempt to find a handler that matches the current
* key combination
*/
this.logger.verbose(this._logPrefix(), "Attempting to find action matching '".concat(combinationName, "' ").concat(eventName, " . . ."));
this._callClosestMatchingHandler(event, keyName, keyEventType);
}
}, {
key: "_callMatchingHandlerClosestToEventTarget",
value: function _callMatchingHandlerClosestToEventTarget(event, keyName, eventRecordIndex) {
for (var componentPosition = 0; componentPosition < this.componentList.length; componentPosition++) {
var matchFound = _get(_getPrototypeOf(GlobalKeyEventStrategy.prototype), "_callMatchingHandlerClosestToEventTarget", this).call(this, event, keyName, eventRecordIndex, componentPosition, 0);
key: "_callClosestMatchingHandler",
value: function _callClosestMatchingHandler(event, keyName, keyEventType) {
var componentListIterator = this.componentList.getNewIterator();
while (componentListIterator.next()) {
var matchFound = _get(_getPrototypeOf(GlobalKeyEventStrategy.prototype), "_callClosestMatchingHandler", this).call(this, event, keyName, keyEventType, componentListIterator.getPosition(), 0);
if (matchFound) {

@@ -705,6 +635,6 @@ this.logger.debug(this._logPrefix(), "Searching no further, as handler has been found (and called).");

value: function addKeyCombinationListener(callbackFunction) {
var _this5 = this;
var _this4 = this;
var cancel = function cancel() {
delete _this5.listeners.keyCombination;
delete _this4.listeners.keyCombination;
};

@@ -711,0 +641,0 @@

@@ -28,3 +28,3 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

import React, { Component } from 'react';
import Configuration from './lib/Configuration';
import Configuration from './lib/config/Configuration';
import withHotKeysIgnoreOverride from './withHotKeysIgnoreOverride';

@@ -66,2 +66,2 @@ /**

export default withHotKeysIgnoreOverride(ObserveKeys, {}, 'forceObserveEvent');
export default withHotKeysIgnoreOverride(ObserveKeys, {}, 'observeIgnoredEvents');
/**
* Returns the element in an array at a particular index from the end
* @param {Array.<T>} array Array to iterate over to find the item
* @param {Number} placesFromEnd Number of places from the end of the array to find
* @param {number} placesFromEnd Number of places from the end of the array to find
* the item to return

@@ -6,0 +6,0 @@ * @returns {T} The item found in the array at the particular index

@@ -24,3 +24,3 @@ import React from 'react';

* values of the context instance used provide context to descendant components
* @returns {Component} Component that has now had the specified context applied
* @returns {React.Component} Component that has now had the specified context applied
*/

@@ -27,0 +27,0 @@

@@ -8,3 +8,3 @@ import hasKey from './hasKey';

* @param {String[]} attributes List of attributes to copy
* @return {Object} The target object, now with the copied attributes
* @returns {Object} The target object, now with the copied attributes
*/

@@ -11,0 +11,0 @@

@@ -16,3 +16,3 @@ /**

* @param {object} nativeEvent Native browser event.
* @return {number} Normalized `charCode` property.
* @returns {number} Normalized `charCode` property.
*/

@@ -19,0 +19,0 @@ function getEventCharCode(nativeEvent) {

@@ -32,3 +32,3 @@ /**

* @param {object} nativeEvent Native browser event.
* @return {string} Normalized `key` property.
* @returns {string} Normalized `key` property.
*/

@@ -35,0 +35,0 @@

@@ -31,6 +31,6 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

import React, { PureComponent } from 'react';
import Configuration from './lib/Configuration';
import Configuration from './lib/config/Configuration';
import KeyEventManager from './lib/KeyEventManager';
import isEmpty from './utils/collection/isEmpty';
import KeyCombinationSerializer from './lib/KeyCombinationSerializer';
import KeyCombinationSerializer from './lib/shared/KeyCombinationSerializer';
import backwardsCompatibleContext from './utils/backwardsCompatibleContext';

@@ -70,2 +70,3 @@ import isUndefined from './utils/isUndefined';

* sequence of events matches a list of pre-defined sequences or combinations
* @class
*/

@@ -192,3 +193,3 @@

key: "componentDidUpdate",
value: function componentDidUpdate(previousProps) {
value: function componentDidUpdate() {
var keyEventManager = KeyEventManager.getInstance();

@@ -303,3 +304,3 @@ keyEventManager.reregisterKeyMap(this._id, this.props.keyMap);

value: function _handleKeyPress(event) {
var discardFocusTreeId = KeyEventManager.getInstance().handleKeypress(event, this._getFocusTreeId(), this._id, this._getEventOptions());
var discardFocusTreeId = KeyEventManager.getInstance().handleKeyPress(event, this._getFocusTreeId(), this._id, this._getEventOptions());

@@ -319,3 +320,3 @@ if (discardFocusTreeId) {

value: function _handleKeyUp(event) {
var discardFocusTreeId = KeyEventManager.getInstance().handleKeyup(event, this._getFocusTreeId(), this._id, this._getEventOptions());
var discardFocusTreeId = KeyEventManager.getInstance().handleKeyUp(event, this._getFocusTreeId(), this._id, this._getEventOptions());

@@ -349,3 +350,3 @@ if (discardFocusTreeId) {

* functions at a later stage
* @typedef {String} ActionName
* @typedef {string} ActionName
*/

@@ -371,6 +372,6 @@

* KeyEventDescription
* @property {String} name - The name of the action, to be displayed to the end user
* @property {String} description - A description of the action, to be displayed to
* @property {string} name - The name of the action, to be displayed to the end user
* @property {string} description - A description of the action, to be displayed to
* the end user
* @property {String} group - A group the action belongs to, to aid in showing similar
* @property {string} group - A group the action belongs to, to aid in showing similar
* actions to the user

@@ -381,3 +382,3 @@ */

* A description of key sequence of one or more key combinations
* @typedef {MouseTrapKeySequence|KeyEventOptions|Array<MouseTrapKeySequence>} KeyEventDescription
* @typedef {MouseTrapKeySequence|KeyEventOptions|Array.<MouseTrapKeySequence>} KeyEventDescription
*/

@@ -398,3 +399,3 @@

* A map from action names to event handler functions
* @typedef {Object<ActionName, Function>} HandlersMap
* @typedef {Object.<ActionName, Function>} HandlersMap
*/

@@ -410,3 +411,3 @@

* Function to call when this component gains focus in the browser
* @type {Function}
* @type {function}
*/

@@ -417,3 +418,3 @@ onFocus: PropTypes.func,

* Function to call when this component loses focus in the browser
* @type {Function}
* @type {function}
*/

@@ -420,0 +421,0 @@ onBlur: PropTypes.func,

@@ -40,2 +40,3 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

import resolveUnaltedAlias from './helpers/resolving-handlers/resolveUnaltedAlias';
import hasKey from './utils/object/hasKey';
/**

@@ -51,2 +52,4 @@ * Wraps a React component in a HotKeysIgnoreOverride component, which passes down the

* default prop values
* @param {string} eventManagerMethod - Name of EventManager method to use to handle a
* key event
* @returns {React.ComponentClass} Wrapped component that is passed all of the React

@@ -70,2 +73,3 @@ * hotkeys props in a single value, hotkeys.

* the only prop to provide a whitelist, or the except prop to pass a blacklist.
* @class
*/

@@ -124,9 +128,9 @@ return _temp = _class =

} else {
return !this._exceptDict[key];
return !hasKey(this._exceptDict, key);
}
} else {
if (isEmpty(this._exceptDict)) {
return this._onlyDict[key];
return hasKey(this._onlyDict, key);
} else {
return this._onlyDict[key] && !this._exceptDict[key];
return hasKey(this._onlyDict, key) && !hasKey(this._exceptDict, key);
}

@@ -133,0 +137,0 @@ }

@@ -15,5 +15,5 @@ import withHotKeysIgnoreOverride from './withHotKeysIgnoreOverride';

};
return withHotKeysIgnoreOverride(Component, hotKeysIgnoreOptions, 'forceObserveEvent');
return withHotKeysIgnoreOverride(Component, hotKeysIgnoreOptions, 'observeIgnoredEvents');
}
export default withObserveKeys;
{
"name": "react-hotkeys",
"version": "2.0.0-pre9",
"version": "2.0.0",
"description": "A declarative library for handling hotkeys and focus within a React application",

@@ -5,0 +5,0 @@ "main": "index",

@@ -14,7 +14,5 @@ <p align="center">

> 🚨 🚨 Warning: This Readme is for the latest pre-release. The documentation for the latest stable release is available [here](https://github.com/greena13/react-hotkeys/tree/v1.1.4). 🚨 🚨
### Upgrading from 1.\*.\* ?
See the [upgrade notes](https://github.com/greena13/react-hotkeys/releases/tag/v2.0.0-pre1).
See the [upgrade notes](https://github.com/greena13/react-hotkeys/releases/tag/v2.0.0).

@@ -44,2 +42,3 @@ ## Feature Overview

import MyNode from "./MyNode";
import React from 'react';

@@ -69,2 +68,3 @@ const keyMap = {

import { HotKeys } from "react-hotkeys";
import React from 'react';

@@ -328,6 +328,8 @@ const MyNode = () => {

```javascript
SHOW_DIALOG: {
name: 'Display keyboard shortcuts',
sequence: 'shift+?',
action: 'keyup'
{
SHOW_DIALOG: {
name: 'Display keyboard shortcuts',
sequence: 'shift+?',
action: 'keyup'
}
}

@@ -339,6 +341,8 @@ ```

```javascript
SHOW_DIALOG: {
name: 'Display keyboard shortcuts',
sequences: ['shift+?', { sequence: '`', action: 'keyup' }],
action: 'keyup'
{
SHOW_DIALOG: {
name: 'Display keyboard shortcuts',
sequences: ['shift+?', { sequence: '`', action: 'keyup' }],
action: 'keyup'
}
}

@@ -423,2 +427,3 @@ ```

import { recordKeyCombination } from 'react-hotkeys';
import React from 'react';

@@ -458,3 +463,3 @@ renderDialog(){

return memo;
}
})
}

@@ -519,2 +524,3 @@ </tbody>

import { HotKeys } from "react-hotkeys";
import React from 'react';

@@ -538,2 +544,3 @@ const keyMap = {

import { HotKeys } from "react-hotkeys";
import React from 'react';

@@ -717,2 +724,3 @@ const keyMap = {

import { withHotKeys } from "react-hotkeys";
import React from 'react';

@@ -881,2 +889,3 @@ class MyComponent extends Component {

import { getApplicationKeyMap } from 'react-hotkeys';
import React from 'react';

@@ -909,4 +918,6 @@ // ...

</tr>
)
}
);
return memo;
})
}

@@ -957,2 +968,3 @@ </tbody>

import { IgnoreKeys } from "react-hotkeys";
import React from 'react';

@@ -1004,2 +1016,3 @@ <IgnoreKeys>

import { withHotKeysIgnore } from "react-hotkeys";
import React from 'react';

@@ -1035,2 +1048,3 @@ class MyComponent extends Component {

import { withHotKeysIgnore } from "react-hotkeys";
import React from 'react';

@@ -1070,2 +1084,3 @@ class MyComponent extends Component {

import {ObserveKeys} from 'react-hotkeys';
import React from 'react';

@@ -1120,2 +1135,3 @@ <ObserveKeys>

import {withObserveKeys} from 'react-hotkeys';
import React from 'react';

@@ -1153,2 +1169,3 @@ class MyComponent extends Component {

import {withObserveKeys} from 'react-hotkeys';
import React from 'react';

@@ -1244,3 +1261,3 @@ class MyComponent extends Component {

* internal state)
* @type {Boolean}
* @type {boolean}
*/

@@ -1251,3 +1268,3 @@ ignoreKeymapAndHandlerChangesByDefault: true,

* Whether to ignore repeated keyboard events when a key is being held down
* @type {Boolean}
* @type {boolean}
*/

@@ -1259,3 +1276,3 @@ ignoreRepeatedEventsWhenKeyHeldDown: true,

* natively emit them.
* @type {Boolean}
* @type {boolean}
*/

@@ -1262,0 +1279,0 @@ simulateMissingKeyPressEvents: true,

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc