UNPKG

react-hotkeys

Version:

A declarative library for handling hotkeys and focus within a React application

11 lines (10 loc) 64.3 kB
/** * ISC License * * Copyright (c) 2018, Aleck Greenham * * Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("prop-types"),require("react")):"function"==typeof define&&define.amd?define(["exports","prop-types","react"],t):t((e=e||self).ReactHotkeys={},e.PropTypes,e.React)}(this,function(e,s,a){"use strict";s=s&&s.hasOwnProperty("default")?s.default:s;var u="default"in a?a.default:a;function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function c(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function l(e,t,n){return t&&i(e.prototype,t),n&&i(e,n),e}function d(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h(){return(h=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(e[i]=n[i])}return e}).apply(this,arguments)}function v(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{},i=Object.keys(n);"function"==typeof Object.getOwnPropertySymbols&&(i=i.concat(Object.getOwnPropertySymbols(n).filter(function(e){return Object.getOwnPropertyDescriptor(n,e).enumerable}))),i.forEach(function(e){d(t,e,n[e])})}return t}function y(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&r(e,t)}function p(e){return(p=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function o(e,t,n){return(o=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}()?Reflect.construct:function(e,t,n){var i=[null];i.push.apply(i,t);var o=new(Function.bind.apply(e,i));return n&&r(o,n.prototype),o}).apply(null,arguments)}function n(e){var i="function"==typeof Map?new Map:void 0;return(n=function(e){if(null===e||(t=e,-1===Function.toString.call(t).indexOf("[native code]")))return e;var t;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==i){if(i.has(e))return i.get(e);i.set(e,n)}function n(){return o(e,arguments,p(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),r(n,e)})(e)}function f(e,t){if(null==e)return{};var n,i,o=function(e,t){if(null==e)return{};var n,i,o={},r=Object.keys(e);for(i=0;i<r.length;i++)n=r[i],0<=t.indexOf(n)||(o[n]=e[n]);return o}(e,t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);for(i=0;i<r.length;i++)n=r[i],0<=t.indexOf(n)||Object.prototype.propertyIsEnumerable.call(e,n)&&(o[n]=e[n])}return o}function g(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function _(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?g(e):t}function k(e,t,n){return(k="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(e,t,n){var i=function(e,t){for(;!Object.prototype.hasOwnProperty.call(e,t)&&null!==(e=p(e)););return e}(e,t);if(i){var o=Object.getOwnPropertyDescriptor(i,t);return o.get?o.get.call(n):o.value}})(e,t,n||e)}function m(e){return function(e){if(Array.isArray(e)){for(var t=0,n=new Array(e.length);t<e.length;t++)n[t]=e[t];return n}}(e)||function(e){if(Symbol.iterator in Object(e)||"[object Arguments]"===Object.prototype.toString.call(e))return Array.from(e)}(e)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function b(e){var n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;return e.reduce(function(e,t){return e[t]=n||{value:t},e},{})}var K={logLevel:"warn",defaultKeyEvent:"keydown",defaultComponent:"div",defaultTabIndex:"-1",ignoreTags:["input","select","textarea"],enableHardSequences:!1,ignoreKeymapAndHandlerChangesByDefault:!0,ignoreEventsCondition:function(e){var t=e.target;if(t&&t.tagName){var n=t.tagName.toLowerCase();return E.option("_ignoreTagsDict")[n]||t.isContentEditable}return!1},ignoreRepeatedEventsWhenKeyHeldDown:!0,simulateMissingKeyPressEvents:!0,stopEventPropagationAfterHandling:!0,stopEventPropagationAfterIgnoring:!0,allowCombinationSubmatches:!1,customKeyCodes:{}},C=v({},K);C._ignoreTagsDict=b(C.ignoreTags,!0);var E=function(){function e(){c(this,e)}return l(e,null,[{key:"init",value:function(t){var n=this,e=t.ignoreTags,i=t.customKeyCodes;e&&(t._ignoreTagsDict=b(t.ignoreTags)),i&&(t._customKeyNamesDict=b(Object.values(t.customKeyCodes))),-1!==["verbose","debug","info"].indexOf(t.logLevel)&&console.warn("React HotKeys: You have requested log level '".concat(t.logLevel,"' but for performance reasons, logging below severity level 'warning' is disabled in production. Please use the development build for complete logs.")),Object.keys(t).forEach(function(e){n.set(e,t[e])})}},{key:"set",value:function(e,t){C[e]=t}},{key:"reset",value:function(e){C[e]=K[e]}},{key:"option",value:function(e){return C[e]}}]),e}(),I=function(){function n(){var t=this,e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:"warn";c(this,n),d(this,"verbose",this.noop),d(this,"debug",this.noop),d(this,"info",this.noop),d(this,"warn",this.noop),d(this,"error",this.noop),this.logLevel=this.constructor.levels[e],this.logLevel>=this.constructor.levels.error&&(this.error=console.error,this.logLevel>=this.constructor.levels.warn&&(this.warn=console.warn,["info","debug","verbose"].some(function(e){return!(t.logLevel>=t.constructor.levels[e])||(t[e]=console.log,!1)})))}return l(n,[{key:"noop",value:function(){}}]),n}();d(I,"logIcons",["📕","📗","📘","📙"]),d(I,"componentIcons",["🔺","⭐️","🔷","🔶","⬛️"]),d(I,"eventIcons",["❤️","💚","💙","💛","💜","🧡"]),d(I,"levels",{none:0,error:1,warn:2,info:3,debug:4,verbose:5});var S={keydown:0,keypress:1,keyup:2},P={Shift:["shiftKey"],Meta:["metaKey"],Control:["ctrlKey"],Alt:["altKey"]},w={"`":["~"],1:["!"],2:["@",'"'],3:["#","£"],4:["$"],5:["%"],6:["^"],7:["&"],8:["*"],9:["("],0:[")"],"-":["_"],"=":["plus"],";":[":"],"'":['"',"@"],",":["<"],".":[">"],"/":["?"],"\\":["|"],"[":["{"],"]":["}"],"#":["~"]};function H(e){return w[e]||[1===e.length?e.toUpperCase():e]}function M(e,t){return e.hasOwnProperty(t)}function T(i){var o=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return Object.keys(i).reduce(function(t,n){var e=i[n];return e.forEach(function(e){M(t,e)||(t[e]=[]),t[e].push(n)}),o.includeOriginal&&(M(t,n)||(t[n]=[]),t[n]=[].concat(m(t[n]),m(e))),t},{})}var O=T(w);function L(e){return O[e]||[1===e.length?e.toLowerCase():e]}var A=T({},{includeOriginal:!0});function x(e){return"string"==typeof e}var D={tab:"Tab",capslock:"CapsLock",shift:"Shift",meta:"Meta",alt:"Alt",ctrl:"Control",space:" ",spacebar:" ",escape:"Escape",esc:"Escape",left:"ArrowLeft",right:"ArrowRight",up:"ArrowUp",down:"ArrowDown",return:"Enter",del:"Delete",command:"Meta",option:"Alt",enter:"Enter",backspace:"Backspace",ins:"Insert",pageup:"PageUp",pagedown:"PageDown",end:"End",home:"Home",contextmenu:"ContextMenu",numlock:"Clear"},q={cmd:"Meta"};function F(e){var t=e.toLowerCase();return D[t]||q[t]||(e.match(/^f\d+$/)?e.toUpperCase():e)}var j={8:"Backspace",9:"Tab",12:"Clear",13:"Enter",16:"Shift",17:"Control",18:"Alt",19:"Pause",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",45:"Insert",46:"Delete",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"NumLock",145:"ScrollLock",224:"Meta"},R=b(Object.values(j),!0);function N(e){return!!R[e]}function U(e){return N(e)||String.fromCharCode(e.charCodeAt(0))===e||(t=e,E.option("_customKeyNamesDict")[t]);var t}var B=function(e){function r(){var e,t;c(this,r);for(var n=arguments.length,i=new Array(n),o=0;o<n;o++)i[o]=arguments[o];return d(g(g(t=_(this,(e=p(r)).call.apply(e,[this].concat(i))))),"name","InvalidKeyNameError"),t}return y(r,n(Error)),r}();function G(e){return e.sort().join("+")}var z=function(){function e(){c(this,e)}return l(e,null,[{key:"parse",value:function(e){var t,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},i=(x(t=e)?t.trim().replace(/\s+/g," "):t).split(" ");try{var o=i.slice(0,i.length-1),r=i[i.length-1],s=o.map(function(e){var t=W(e,n);return G(Object.keys(t))}).join(" "),a=W(r,n),u={id:G(Object.keys(a)),keyDictionary:a,keyEventType:n.keyEventType,size:Object.keys(a).length};return{sequence:{prefix:s,size:o.length+1},combination:u}}catch(e){return{sequence:null,combination:null}}}}]),e}();function W(e){var i=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};return e.replace(/^\+|(\s|[^+]\+)\+/,"$1plus").split("+").reduce(function(e,t){var n=F(t);if(i.ensureValidKeys&&!U(n))throw new B;return e[n]=!0,e},{})}var J={"`":["`"],1:["¡"],2:["™"],3:["£"],4:["¢"],5:["∞"],6:["§"],7:["¶"],8:["•"],9:["ª"],0:["º"],"-":["–"],"=":["≠"],a:["å"],b:["∫"],c:["ç"],d:["∂"],e:["´"],f:["ƒ"],g:["©"],h:["˙"],i:["ˆ"],j:["∆"],k:["˚"],l:["¬"],m:["µ"],n:["˜"],o:["ø"],p:["π"],q:["œ"],r:["®"],s:["ß"],t:["†"],u:["¨"],v:["√"],w:["∑"],x:["≈"],y:["¥"],z:["Ω"],"[":["“"],"]":["‘"],"\\":["«"],"'":["æ"],";":["…"],",":["≤"],".":["≥"],"/":["÷"]},V=T(J);function $(e){return V[e]||[e]}function Y(e){return J[e]||[e]}var Q={"`":["`"],1:["⁄"],2:["€"],3:["‹"],4:["›"],5:["fi"],6:["fl"],7:["‡"],8:["°"],9:["·"],0:["‚"],"-":["—"],"=":["±"],a:["Å"],b:["ı"],c:["Ç"],d:["Î"],e:["´"],f:["Ï"],g:["˝"],h:["Ó"],i:["ˆ"],j:["Ô"],k:[""],l:["Ò"],m:["Â"],n:["˜"],o:["Ø"],p:["π"],q:["Œ"],r:["‰"],s:["Í"],t:["Î"],u:["¨"],v:["◊"],w:["„"],x:["˛"],y:["Á"],z:["¸"],"[":["”"],"]":["’"],"\\":["»"],"'":["Æ"],";":["Ú"],",":["¯"],".":["˘"]},X=T(Q);function Z(e){return X[e]||L(e)}function ee(e){return Q[e]||[e]}var te=function(){function e(){c(this,e)}return l(e,null,[{key:"serialize",value:function(e){var l=e.Shift,h=e.Alt,y={};return Object.keys(e).sort().forEach(function(e){var n=[];if(l)if(h){var t=Z(e),i=ee(e);n=[].concat(m(n),[e],m(t),m(i))}else{var o=L(e),r=H(e);n=[].concat(m(n),[e],m(o),m(r))}else if(h){var s=$(e),a=Y(e);n=[].concat(m(n),[e],m(s),m(a))}else{n.push(e);var u=A[e];u&&(n=[].concat(m(n),m(u)))}var c=Object.keys(y);0<c.length?c.forEach(function(t){n.forEach(function(e){y[t+"+".concat(e)]=v({},y[t],d({},e,!0))}),delete y[t]}):n.forEach(function(e){y[e]=d({},e,!0)})}),Object.values(y).map(function(e){return Object.keys(e).sort().join("+")})}},{key:"isValidKeySerialization",value:function(e){return 0<e.length&&!!z.parse(e,{ensureValidKeys:!0}).combination}}]),e}(),ne=0,ie=1;function oe(e){return void 0===e}var re=0,se=1,ae=2,ue=function(){function e(){c(this,e)}return l(e,null,[{key:"newRecord",value:function(e,t){var n=[re,re,re];if(!oe(e))for(var i=0;i<=e;i++)n[i]=t;return n}},{key:"setBit",value:function(e,t,n){return e[t]=n,e}},{key:"clone",value:function(e){for(var t=this.newRecord(),n=0;n<e.length;n++)t[n]=e[n];return t}}]),e}();function ce(e){return!Array.isArray(e)&&"object"===t(e)&&null!==e}function le(e){return ce(e)?0===Object.keys(e).length:!e||0===e.length}function he(e){return ce(e)?Object.keys(e).length:e.length}var ye=function(){function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};c(this,t),this._keys=e,this._includesKeyUp=!1,this._update()}return l(t,[{key:"getIds",value:function(){return this._ids}},{key:"getKeyAliases",value:function(){return this._keyAliases}},{key:"getNormalizedKeyName",value:function(e){if(this._keys[e])return e;var t=this._keyAliases[e];return t||e}},{key:"getNumberOfKeys",value:function(){return he(this._keys)}},{key:"any",value:function(){return 0<Object.keys(this._getKeyStates()).length}},{key:"isEnding",value:function(){return this._includesKeyUp}},{key:"hasEnded",value:function(){return le(this.keysStillPressedDict())}},{key:"addKey",value:function(e,t){this._setKeyState(e,[ue.newRecord(),ue.newRecord(S.keydown,t)])}},{key:"setKeyState",value:function(e,t,n){var i=this._getKeyState(e);if(this.isKeyIncluded(e)){var o=ue.clone(i[1]),r=ue.clone(o);ue.setBit(r,t,n),this._setKeyState(e,[o,r])}else this.addKey(e,n);t===S.keyup&&(this._includesKeyUp=!0)}},{key:"forEachKey",value:function(e){return Object.keys(this._keys).forEach(e)}},{key:"some",value:function(e){return Object.keys(this._keys).some(e)}},{key:"getKeyDictionary",value:function(){return b(Object.keys(this._getKeyStates()),!0)}},{key:"keysStillPressedDict",value:function(){var n=this;return Object.keys(this._keys).reduce(function(e,t){return n.isKeyStillPressed(t)&&(e[t]=n._getKeyState(t)),e},{})}},{key:"isKeyIncluded",value:function(e){return!!this._getKeyState(e)}},{key:"isKeyStillPressed",value:function(e){return this.isEventTriggered(e,S.keypress)&&!this.isKeyReleased(e)}},{key:"isKeyReleased",value:function(e){return this.isEventTriggered(e,S.keyup)}},{key:"isEventTriggered",value:function(e,t){return this._getKeyStateType(e,ie,t)}},{key:"wasEventPreviouslyTriggered",value:function(e,t){return this._getKeyStateType(e,ne,t)}},{key:"isKeyPressSimulated",value:function(e){return this._isKeyEventSimulated(e,S.keypress)}},{key:"isKeyUpSimulated",value:function(e){return this._isKeyEventSimulated(e,S.keyup)}},{key:"describe",value:function(){return this.getIds()[0]}},{key:"toJSON",value:function(){return{keys:this._getKeyStates(),ids:this.getIds(),keyAliases:this.getKeyAliases()}}},{key:"_getKeyStateType",value:function(e,t,n){var i=this._getKeyState(e);return i&&i[t][n]}},{key:"_update",value:function(){var o;this._ids=te.serialize(this._keys),this._keyAliases=(o=this._keys,Object.keys(o).reduce(function(n,i){var e;return(e=i,A[e]||[e]).forEach(function(t){(function(e){if(e.Shift)return e.Alt?[ee,Z]:[H,L];if(e.Alt)return[Y,$];var t=function(e){return[e]};return[t,t]})(o).forEach(function(e){e(t).forEach(function(e){e===i&&i===t||(n[e]=i)})})}),n},{}))}},{key:"_isKeyEventSimulated",value:function(e,t){return this.isEventTriggered(e,t)===ae}},{key:"_getKeyStates",value:function(){return this._keys}},{key:"_getKeyState",value:function(e){var t=this._keys[e];if(t)return t;var n=this._keyAliases[e];return n?this._keys[n]:void 0}},{key:"_setKeyState",value:function(e,t){var n=this.getNormalizedKeyName(e);this._keys[n]=t,this._update()}}]),t}();var de=function(){function i(e){var t=e.maxLength,n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:null;c(this,i),this._records=[],this._maxLength=t,n?this._push(n):this._push(new ye)}return l(i,[{key:"getMostRecentCombinations",value:function(e){return this._records.slice(-e,-1)}},{key:"any",value:function(){return this._records.some(function(e){return e.any()})}},{key:"getLength",value:function(){return this._records.length}},{key:"getCurrentCombination",value:function(){return this._records[this.getLength()-1]}},{key:"addKeyToCurrentCombination",value:function(e,t,n){this._ensureInitialKeyCombination(),this.getCurrentCombination().setKeyState(e,t,n)}},{key:"setMaxLength",value:function(e){this._maxLength=e,this._trimHistory()}},{key:"startNewKeyCombination",value:function(e,t){this._ensureInitialKeyCombination();var n=new ye(this.getCurrentCombination().keysStillPressedDict());n.addKey(e,t),this._push(n)}},{key:"toJSON",value:function(){return this._records.map(function(e){return e.toJSON()})}},{key:"_ensureInitialKeyCombination",value:function(){0===this.getLength()&&this._push(new ye)}},{key:"_push",value:function(e){this._trimHistory(),this._records.push(e)}},{key:"_trimHistory",value:function(){for(;this.getLength()>this._maxLength;)this._shift()}},{key:"_shift",value:function(){this._records.shift()}}]),i}(),ve=function(){function e(){c(this,e),this._registry={}}return l(e,[{key:"get",value:function(e){return this._registry[e]}},{key:"set",value:function(e,t){this._registry[e]=t}},{key:"remove",value:function(e){delete this._registry[e]}},{key:"toJSON",value:function(){return this._registry}}]),e}();function pe(e){return Array.isArray(e)?e:e?[e]:[]}var fe=function(e){function i(){return c(this,i),_(this,p(i).apply(this,arguments))}return y(i,ve),l(i,[{key:"add",value:function(e,t){k(p(i.prototype),"set",this).call(this,e,{childIds:[],parentId:null,keyMap:t})}},{key:"update",value:function(e,t){var n=k(p(i.prototype),"get",this).call(this,e);k(p(i.prototype),"set",this).call(this,e,v({},n,{keyMap:t}))}},{key:"setParent",value:function(e,t){this.get(e).parentId=t,this._addChildId(t,e)}},{key:"remove",value:function(e){var t=this._getParentId(e);this._removeChildId(t,e),k(p(i.prototype),"remove",this).call(this,e)}},{key:"_getParentId",value:function(e){var t=this.get(e);return t&&t.parentId}},{key:"_addChildId",value:function(e,t){this.get(e).childIds.push(t)}},{key:"_removeChildId",value:function(e,t){var n=this.get(e);n&&(n.childIds=function(n){var e=1<arguments.length&&void 0!==arguments[1]?arguments[1]:[],i=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},o=b(pe(e));return Array.isArray(n)?n.reduce(function(e,t){return o[t]&&(i.stringifyFirst||o[t].value===t)||e.push(t),e},[]):ce(n)?Object.keys(n).reduce(function(e,t){return o[t]||(e[t]=n[t]),e},{}):n}(n.childIds,t))}}]),i}();var ge=function(){function t(e){c(this,t),this._list=e,this._position=-1}return l(t,[{key:"getPosition",value:function(){return this._position}},{key:"getComponent",value:function(){return this._list.getAtPosition(this.getPosition())}},{key:"next",value:function(){return this.getPosition()+1<this._list.getLength()?(this._position++,this.getComponent()):null}}]),t}(),_e=function(){function e(){c(this,e),this._list=[],this._idToIndex={},this._longestSequence=1,this._longestSequenceComponentId=null,this._keyMapEventRecord=ue.newRecord()}return l(e,[{key:"getNewIterator",value:function(){return new ge(this)}},{key:"add",value:function(e,t,n,i){if(this.containsId(e))return this.update(e,t,n,i);var o=this._build(e,t,n,i);this._list.push(o);var r=this._getLastIndex();return this._idToIndex[e]=r}},{key:"containsId",value:function(e){return!!this.get(e)}},{key:"get",value:function(e){return this.getAtPosition(this.getIndexById(e))}},{key:"getIndexById",value:function(e){return this._idToIndex[e]}},{key:"update",value:function(e,t,n,i){var o=this._isUpdatingComponentWithLongestSequence(e),r=this.getLongestSequence(),s=this._build(e,t,n,i);o&&s.sequenceLength!==r&&(s.sequenceLength>r?this._longestSequence=s.sequenceLength:this._recalculateLongestSequence()),this._list[this.getIndexById(e)]=s}},{key:"remove",value:function(e){var t=this._isUpdatingComponentWithLongestSequence(e);this.removeAtPosition(this.getIndexById(e)),t&&this._recalculateLongestSequence()}},{key:"any",value:function(){return 0!==this.getLength()}},{key:"isRoot",value:function(e){return this.getIndexById(e)>=this.getLength()-1}},{key:"getLongestSequence",value:function(){return this._longestSequence}},{key:"anyActionsForEventType",value:function(e){return!!this._keyMapEventRecord[e]}},{key:"getLength",value:function(){return this._list.length}},{key:"getAtPosition",value:function(e){return this._list[e]}},{key:"removeAtPosition",value:function(e){var t,n;this._list=(t=this._list,n=e,[].concat(m(t.slice(0,n)),m(t.slice(n+1))));for(var i=e;i<this.getLength();)this._idToIndex[this.getAtPosition(i).componentId]=i,i++}},{key:"toJSON",value:function(){return this._list}},{key:"_getLastIndex",value:function(){return this.getLength()-1}},{key:"_build",value:function(e,t,n,i){var o=this._applyHardSequences(t,n),r=o.keyMap,s=o.handlers;return{actions:this._buildActionDictionary(v({},t,r),i,e),handlers:s,componentId:e,options:i}}},{key:"_isUpdatingComponentWithLongestSequence",value:function(e){return e===this._getLongestSequenceComponentId()}},{key:"_getLongestSequenceComponentId",value:function(){return this._longestSequenceComponentId}},{key:"_recalculateLongestSequence",value:function(){for(var e=this.getNewIterator();e.next();){var t=e.getComponent(),n=t.longestSequence,i=t.componentId;n>this.getLongestSequence()&&(this._longestSequenceComponentId=i,this._longestSequence=n)}}},{key:"_applyHardSequences",value:function(n,i){return E.option("enableHardSequences")?Object.keys(i).reduce(function(e,t){return!!!n[t]&&te.isValidKeySerialization(t)&&(e.keyMap[t]=t),e.handlers[t]=i[t],e},{keyMap:{},handlers:{}}):{keyMap:n,handlers:i}}},{key:"_buildActionDictionary",value:function(t,s,a){var u=this;return Object.keys(t).reduce(function(o,r){var e=t[r];return(ce(e)&&M(e,"sequences")?pe(e.sequences):pe(e)).forEach(function(e){var t=function(e,t){{if(ce(e)){var n=e.sequence,i=e.action;return{keySequence:n,keyEventType:oe(i)?S[t.defaultKeyEvent]:S[i]}}return{keySequence:e,keyEventType:S[t.defaultKeyEvent]}}}(e,s),n=t.keySequence,i=t.keyEventType;u._addActionOptions(o,a,r,n,i)}),o},{})}},{key:"_addActionOptions",value:function(e,t,n,i,o){var r=z.parse(i,{keyEventType:o}),s=r.sequence,a=r.combination;s.size>this.getLongestSequence()&&(this._longestSequence=s.size,this._longestSequenceComponentId=t),this._keyMapEventRecord[o]=se,e[n]||(e[n]=[]),e[n].push(v({prefix:s.prefix,actionName:n,sequenceLength:s.size},a))}}]),e}();function ke(e,t){return e[e.length-(t+1)]}for(var me={Enter:!0,Backspace:!0,ArrowRight:!0,ArrowLeft:!0,ArrowUp:!0,ArrowDown:!0,CapsLock:!0},be=1;be<13;be++)me["F".concat(be)]=!0;function Ke(e){return 1===e.length||M(me,e)}var Ce=function(){function e(){c(this,e),this._actionConfigs={},this._order=null}return l(e,[{key:"addMatch",value:function(e,t){if(this._includesMatcherForCombination(e.id)){var n=e.keyEventType,i=e.actionName,o=e.id;this._addHandlerToActionConfig(o,{keyEventType:n,actionName:i,handler:t})}else this._addNewActionConfig(e,t)}},{key:"findMatch",value:function(e,t,n){this._order||this._setOrder();var i=!0,o=!1,r=void 0;try{for(var s,a=this._order[Symbol.iterator]();!(i=(s=a.next()).done);i=!0){var u=s.value,c=this._actionConfigs[u];if(this._matchesActionConfig(e,t,n,c))return c}}catch(e){o=!0,r=e}finally{try{i||null==a.return||a.return()}finally{if(o)throw r}}return null}},{key:"toJSON",value:function(){return{actionConfigs:this._actionConfigs,order:this._order}}},{key:"_matchesActionConfig",value:function(t,n,i,e){if(r=t,s=he(e.keyDictionary),!(E.option("allowCombinationSubmatches")||(o=r).isKeyStillPressed("Meta")&&o.some(function(e){return Ke(e)})?r.getNumberOfKeys()>=s:r.getNumberOfKeys()===s))return!1;var o,r,s;if(!e.events[i])return!1;var a=!1;return Object.keys(e.keyDictionary).every(function(e){return!!t.isEventTriggered(e,i)&&(n&&n===t.getNormalizedKeyName(e)&&(a=!t.wasEventPreviouslyTriggered(e,i)),!0)})&&a}},{key:"_setOrder",value:function(){var n=Object.values(this._actionConfigs).reduce(function(e,t){var n=t.id,i=t.size;return e[i]||(e[i]=[]),e[i].push(n),e},{});this._order=Object.keys(n).sort(function(e,t){return t-e}).reduce(function(e,t){return e.concat(n[t])},[])}},{key:"_addNewActionConfig",value:function(e,t){var n=e.prefix,i=e.sequenceLength,o=e.id,r=e.keyDictionary,s=e.size,a=e.keyEventType,u=e.actionName;this._setCombinationMatcher(o,{prefix:n,sequenceLength:i,id:o,keyDictionary:r,size:s,events:{}}),this._addHandlerToActionConfig(o,{keyEventType:a,actionName:u,handler:t})}},{key:"_addHandlerToActionConfig",value:function(e,t){var n=t.keyEventType,i=t.actionName,o=t.handler,r=this._getCombinationMatcher(e);this._setCombinationMatcher(e,v({},r,{events:v({},r.events,d({},n,{actionName:i,handler:o}))}))}},{key:"_setCombinationMatcher",value:function(e,t){this._actionConfigs[e]=t}},{key:"_getCombinationMatcher",value:function(e){return this._actionConfigs[e]}},{key:"_includesMatcherForCombination",value:function(e){return!!this._getCombinationMatcher(e)}}]),e}();var Ee=function(){function e(){c(this,e),this._combinationMatchers={},this._eventRecord=ue.newRecord()}return l(e,[{key:"addMatch",value:function(e,t){this._getOrCreateCombinationMatcher(e.prefix).addMatch(e,t),ue.setBit(this._eventRecord,e.keyEventType,se),(!this._longestSequence||this._longestSequence<e.sequenceLength)&&(this._longestSequence=e.sequenceLength)}},{key:"findMatch",value:function(e,t,n){var i=this._findCombinationMatcher(e);return i?i.findMatch(e.getCurrentCombination(),e.getCurrentCombination().getNormalizedKeyName(t),n):null}},{key:"hasMatchesForEventType",value:function(e){return!!this._eventRecord[e]}},{key:"getLongestSequence",value:function(){return this._longestSequence}},{key:"toJSON",value:function(){var i=this;return Object.keys(this._combinationMatchers).reduce(function(e,t){var n=i._combinationMatchers[t];return e[t]=n.toJSON(),e},{})}},{key:"_getOrCreateCombinationMatcher",value:function(e){return this._combinationMatchers[e]||(this._combinationMatchers[e]=new Ce),this._combinationMatchers[e]}},{key:"_findCombinationMatcher",value:function(e){var t=e.getMostRecentCombinations(this.getLongestSequence());if(0===t.length)return this._combinationMatchers[""];for(var n=t.map(function(e){return e.getIds()}),i=n.map(function(e){return e.length}),o=new Array(n.length).fill(0),r=!1;!r;){var s=o.map(function(e,t){return n[t][e]}).join(" ");if(this._combinationMatchers[s])return this._combinationMatchers[s];for(var a=0,u=!0;u&&a<o.length;){var c=(ke(o,a)+1)%(ke(i,a)||1);(u=0===(o[o.length-(a+1)]=c))&&a++}r=a===o.length}}}]),e}(),Ie=function(){function i(e){c(this,i),this._keyMapMatchers=[],this._unmatchedHandlerStatus=[],this._handlersDictionary={},this._keySequencesDictionary={};for(var t=e.getNewIterator();t.next();){var n=t.getComponent().handlers;this._unmatchedHandlerStatus.push([Object.keys(n).length,{}]),this._keyMapMatchers.push(new Ee)}this._componentList=e,this._componentListIterator=e.getNewIterator()}return l(i,[{key:"getKeyHistoryMatcher",value:function(e){if(this._componentHasUnmatchedHandlers(e))for(;this._componentListIterator.next();)this._addHandlersFromComponent(),this._addActionsFromComponent();return this._getKeyHistoryMatcher(e)}},{key:"componentHasActionsBoundToEventType",value:function(e,t){return this.getKeyHistoryMatcher(e).hasMatchesForEventType(t)}},{key:"findMatchingKeySequenceInComponent",value:function(e,t,n,i){return this.componentHasActionsBoundToEventType(e,i)?this.getKeyHistoryMatcher(e).findMatch(t,n,i):null}},{key:"_getKeyHistoryMatcher",value:function(e){return this._keyMapMatchers[e]}},{key:"_addActionsFromComponent",value:function(){var s=this,t=this._componentListIterator.getComponent().actions;Object.keys(t).forEach(function(n){var e=s._getHandlers(n);if(e){var i=e[0],o=s._componentList.getAtPosition(i).handlers[n],r=s._getKeyHistoryMatcher(i);t[n].forEach(function(e){var t=[e.prefix,e.id].join(" ");s._isClosestHandlerFound(t,e)||(r.addMatch(e,o),s._addKeySequence(t,[i,e.keyEventType]))}),e.forEach(function(e){var t=s._getUnmatchedHandlerStatus(e);t[1][n]||(t[1][n]=!0,t[0]--)})}})}},{key:"_getHandlers",value:function(e){return this._handlersDictionary[e]}},{key:"_addHandlersFromComponent",value:function(){var t=this,e=this._componentListIterator.getComponent().handlers;Object.keys(e).forEach(function(e){t._addHandler(e)})}},{key:"_addHandler",value:function(e){this._handlersDictionary[e]||(this._handlersDictionary[e]=[]),this._handlersDictionary[e].push(this._componentListIterator.getPosition())}},{key:"_addKeySequence",value:function(e,t){this._keySequencesDictionary[e]||(this._keySequencesDictionary[e]=[]),this._keySequencesDictionary[e].push(t)}},{key:"_componentHasUnmatchedHandlers",value:function(e){return 0<this._getUnmatchedHandlerStatus(e)[0]}},{key:"_getUnmatchedHandlerStatus",value:function(e){return this._unmatchedHandlerStatus[e]}},{key:"_isClosestHandlerFound",value:function(e,t){return this._keySequencesDictionary[e]&&this._keySequencesDictionary[e].some(function(e){return e[1]===t.keyEventType})}}]),i}();function Se(t,n,e){return e.forEach(function(e){M(t,e)&&(n[e]=t[e])}),n}function Pe(e){switch(parseInt(e,10)){case 0:return"keydown";case 1:return"keypress";default:return"keyup"}}function we(e){return e.simulated?ae:se}var He=["sequence","action"],Me=["name","description","group"],Te=function(){function n(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},t=1<arguments.length?arguments[1]:void 0;c(this,n),this.logger=e.logger||new I("warn"),this.componentId=-1,this.keyEventManager=t,this._componentTree=new fe,this.rootComponentId=null,this._reset(),this.resetKeyHistory()}return l(n,[{key:"_reset",value:function(){this.componentList=new _e,this._initHandlerResolutionState()}},{key:"_newKeyHistory",value:function(){return new de({maxLength:this.componentList.getLongestSequence()})}},{key:"getKeyHistory",value:function(){return this._keyHistory||(this._keyHistory=this._newKeyHistory()),this._keyHistory}},{key:"_initHandlerResolutionState",value:function(){this._actionResolver=null}},{key:"resetKeyHistory",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};this.keypressEventsToSimulate=[],this.keyupEventsToSimulate=[],this.getKeyHistory().any()&&!e.force?this._keyHistory=new de({maxLength:this.componentList.getLongestSequence()},new ye(this.getCurrentCombination().keysStillPressedDict())):this._keyHistory=this._newKeyHistory()}},{key:"getApplicationKeyMap",value:function(){return null===this.rootComponentId?{}:this._buildApplicationKeyMap([this.rootComponentId],{})}},{key:"_buildApplicationKeyMap",value:function(e,o){var r=this;return e.forEach(function(e){var t=r._componentTree.get(e),n=t.childIds,i=t.keyMap;i&&Object.keys(i).forEach(function(e){var t=i[e];o[e]={},ce(t)?M(t,"sequences")?(Se(t,o[e],Me),o[e].sequences=r._createSequenceFromConfig(t.sequences)):(Se(t,o[e],Me),o[e].sequences=[Se(t,{},He)]):o[e].sequences=r._createSequenceFromConfig(t)}),r._buildApplicationKeyMap(n,o)}),o}},{key:"_createSequenceFromConfig",value:function(e){return pe(e).map(function(e){return ce(e)?Se(e,{},He):{sequence:e}})}},{key:"registerKeyMap",value:function(e){return this.componentId+=1,this._componentTree.add(this.componentId,e),this.componentId}},{key:"reregisterKeyMap",value:function(e,t){this._componentTree.update(e,t)}},{key:"registerComponentMount",value:function(e,t){oe(t)?this.rootComponentId=e:this._componentTree.setParent(e,t)}},{key:"deregisterKeyMap",value:function(e){this._componentTree.remove(e),e===this.rootComponentId&&(this.rootComponentId=null)}},{key:"_addComponent",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},i=3<arguments.length?arguments[3]:void 0;this.componentList.add(e,t,n,i),this.getKeyHistory().setMaxLength(this.componentList.getLongestSequence())}},{key:"_allKeysAreReleased",value:function(){return this.getCurrentCombination().hasEnded()}},{key:"getCurrentCombination",value:function(){return this.getKeyHistory().getCurrentCombination()}},{key:"_shouldSimulate",value:function(e,t){var n=!N(t),i=this.getCurrentCombination();return e===S.keypress?!n||n&&i.isKeyStillPressed("Meta"):e===S.keyup&&(Ke(t)&&i.isKeyReleased("Meta"))}},{key:"_cloneAndMergeEvent",value:function(n,e){return v({},Object.keys(P).reduce(function(e,t){return e[t]=n[t],e},{}),e)}},{key:"_callClosestMatchingHandler",value:function(e,t,n,i,o){for(this._actionResolver||(this._actionResolver=new Ie(this.componentList));o<=i;){this._actionResolver.getKeyHistoryMatcher(o);var r=this._actionResolver.findMatchingKeySequenceInComponent(o,this.getKeyHistory(),t,n);this.getCurrentCombination();if(r){var s=r.events[n];if(E.option("allowCombinationSubmatches"))te.serialize(r.keyDictionary);return s.handler(e),this._stopEventPropagationAfterHandlingIfEnabled(e,o),!0}this._actionResolver.componentHasActionsBoundToEventType(o,n),o++}}},{key:"_stopEventPropagationAfterHandlingIfEnabled",value:function(e,t){return!!E.option("stopEventPropagationAfterHandling")&&(this._stopEventPropagation(e,t),!0)}},{key:"_stopEventPropagation",value:function(e,t){throw new Error("_stopEventPropagation must be overridden by a subclass")}},{key:"_checkForModifierFlagDiscrepancies",value:function(o,e,r){var s=this;Object.keys(P).forEach(function(t){if(e!==t||r!==S.keyup){var n=s.getCurrentCombination(),i=n.isKeyStillPressed(t);P[t].forEach(function(e){!1===o[e]&&i&&n.setKeyState(t,S.keyup,we(o))})}})}},{key:"_logPrefix",value:function(){}}]),n}(),Oe=function(){function e(){c(this,e)}return l(e,null,[{key:"getId",value:function(){return oe(this._id)&&(this._id=0),this._id}},{key:"incrementId",value:function(){this._id=this.getId()+1}}]),e}();var Le={Esc:"Escape",Spacebar:" ",Left:"ArrowLeft",Up:"ArrowUp",Right:"ArrowRight",Down:"ArrowDown",Del:"Delete",Win:"OS",Menu:"ContextMenu",Apps:"ContextMenu",Scroll:"ScrollLock",MozPrintableKey:"Unidentified"};function Ae(e){var t,n,i=(t=E.option("customKeyCodes"),n=e.keyCode||e.charCode,M(t,n)?t[n]:e.nativeEvent?e.key:function(e){if(e.key){var t=Le[e.key]||e.key;if("Unidentified"!==t)return t}if("keypress"!==e.type)return"keydown"===e.type||"keyup"===e.type?j[e.keyCode]||"Unidentified":"";var n,i,o,r=(o=(n=e).keyCode,"charCode"in n?0===(i=n.charCode)&&13===o&&(i=13):i=o,10===i&&(i=13),32<=i||13===i?i:0);return 13===r?"Enter":String.fromCharCode(r)}(e));return"+"===i?"plus":i}function xe(e){return"Meta"===e}var De=0,qe=1,Fe=2,je=4,Re=function(){function o(e,t){var n=t.logger,i=t.logPrefix;c(this,o),this._componentList=e,this._previousPropagation=null,this.logger=n,this._logPrefix=i,this._reset()}return l(o,[{key:"_reset",value:function(){this._previousPosition=-1,this._position=-1,this._actionHandled=!1,this._ignoreEvent=!1,this._observeIgnoredEvents=!1,this._stopping=!1,this._componentId=null,this._key=null,this._type=null}},{key:"isFirstPropagationStep",value:function(){var e=this.getPreviousPosition();return-1===e||e>=this._position}},{key:"isForKey",value:function(e){return this._key===e}},{key:"isForEventType",value:function(e){return this._type===e}},{key:"startNewPropagationStep",value:function(e,t,n,i){return this._position=this._componentList.getIndexById(e),this._componentId=e,this.isFirstPropagationStep()&&(Oe.incrementId(),this._key=t.key,this._type=i),!t.repeat||!E.option("ignoreRepeatedEventsWhenKeyHeldDown")||(this.ignoreEvent(t),!1)}},{key:"finishPropagationStep",value:function(){this.isStopped()||this._componentList.isRoot(this._componentId)?(this._previousPropagation=this._clone(),this._reset()):this._previousPosition=this._position}},{key:"getPreviousPropagation",value:function(){return this._previousPropagation||(this._previousPropagation=this._clone({copyState:!1})),this._previousPropagation}},{key:"getPreviousPosition",value:function(){return this._previousPosition}},{key:"observeIgnoredEvents",value:function(){this._observeIgnoredEvents=!0}},{key:"ignoreEvent",value:function(e){return this.setIgnoreEvent(!0),!(!this.isIgnoringEvent()||!E.option("stopEventPropagationAfterIgnoring"))&&(this.stop(e),this.finishPropagationStep(),!0)}},{key:"setIgnoreEvent",value:function(e){this._ignoreEvent=e}},{key:"isIgnoringEvent",value:function(){return!this._observeIgnoredEvents&&this._ignoreEvent}},{key:"isStopped",value:function(){return this._stopping}},{key:"stop",value:function(e){return!this.isStopped()&&(this._stopping=!0,e.simulated||e.stopPropagation(),!0)}},{key:"isPendingPropagation",value:function(){var e=this.getPreviousPosition();return-1!==e&&e+1<this._position}},{key:"isHandled",value:function(){return this._actionHandled}},{key:"setHandled",value:function(){this._actionHandled=!0}},{key:"_clone",value:function(){var e=(0<arguments.length&&void 0!==arguments[0]?arguments[0]:{}).copyState,t=void 0===e||e,n=new o(this._componentList,{logger:this.logger,logPrefix:this._logPrefix});return t&&Object.assign(n,this),n}}]),o}(),Ne=function(e){function i(){var e,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=1<arguments.length?arguments[1]:void 0;return c(this,i),(e=_(this,p(i).call(this,t,n))).focusTreeId=0,e}return y(i,Te),l(i,[{key:"_reset",value:function(){k(p(i.prototype),"_reset",this).call(this),this.keypressEventsToSimulate=[],this.focusTreeId+=1,this.eventPropagator=new Re(this.componentList,{logger:this.logger,logPrefix:this._logPrefix.bind(this)})}},{key:"enableHotKeys",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},i=3<arguments.length?arguments[3]:void 0;if(this.resetOnNextFocus&&(this._reset(),this.resetOnNextFocus=!1),!this.componentList.containsId(e))return this._addComponent(e,t,n,i),this.focusTreeId}},{key:"updateEnabledHotKeys",value:function(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},i=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},o=4<arguments.length?arguments[4]:void 0;e===this.focusTreeId&&this.componentList.containsId(t)&&(this.componentList.update(t,n,i,o),this.getKeyHistory().setMaxLength(this.componentList.getLongestSequence()),this._initHandlerResolutionState())}},{key:"disableHotKeys",value:function(e,t){return this.resetOnNextFocus||(this.resetOnNextFocus=!0),this.eventPropagator.isPendingPropagation()}},{key:"handleKeydown",value:function(e,t,n){var i=3<arguments.length&&void 0!==arguments[3]?arguments[3]:{},o=Ae(e);if(t!==this.focusTreeId)return this.eventPropagator.ignoreEvent(e),!0;if(this.eventPropagator.startNewPropagationStep(n,e,o,S.keydown)){if(this._howToHandleKeyEvent(e,t,n,o,i,S.keydown)===je){var r=we(e),s=this.getCurrentCombination();s.isKeyIncluded(o)||s.isEnding()?this._startAndLogNewKeyCombination(o,t,n,r):this._addToAndLogCurrentKeyCombination(o,S.keydown,t,n,r),this._callHandlerIfActionNotHandled(e,o,S.keydown,n,t)}return this._simulateKeyPressForNonPrintableKeys(e,o,t,n,i),this.eventPropagator.finishPropagationStep(),!1}}},{key:"_howToHandleKeyEvent",value:function(e,t,n,i,o,r){if(this.eventPropagator.isFirstPropagationStep()){if(o.ignoreEventsCondition(e)&&this.eventPropagator.ignoreEvent(e))return this._eventIsToBeIgnored(e,n,i,r);this._checkForModifierFlagDiscrepancies(e,i,r)}else if(this.eventPropagator.isIgnoringEvent())return this._eventIsToBeIgnored(e,n,i,r);return je}},{key:"_eventIsToBeIgnored",value:function(e,t,n,i){return qe}},{key:"handleKeyPress",value:function(e,t,n,i){var o=Ae(e),r=this.getCurrentCombination();if(r.isKeyPressSimulated(o))return this.eventPropagator.ignoreEvent(e),!0;if(this.eventPropagator.startNewPropagationStep(n,e,o,S.keypress)){var s=t!==this.focusTreeId,a=this._howToHandleKeyEvent(e,t,n,o,i,S.keypress);return this.eventPropagator.isFirstPropagationStep(n)&&r.isKeyIncluded(o)&&this._addToAndLogCurrentKeyCombination(o,S.keypress,t,n,we(e)),a===je&&this._callHandlerIfActionNotHandled(e,o,S.keypress,n,t),this.eventPropagator.finishPropagationStep(),s}}},{key:"handleKeyUp",value:function(e,t,n,i){var o=Ae(e),r=this.getCurrentCombination();if(r.isKeyUpSimulated(o))return this.eventPropagator.ignoreEvent(e),!0;if(this.eventPropagator.startNewPropagationStep(n,e,o,S.keyup)){var s=t!==this.focusTreeId,a=this._howToHandleKeyEvent(e,t,n,o,i,S.keyup);return this.eventPropagator.isFirstPropagationStep(n)&&r.isKeyIncluded(o)&&this._addToAndLogCurrentKeyCombination(o,S.keyup,t,n,we(e)),a===je&&this._callHandlerIfActionNotHandled(e,o,S.keyup,n,t),this._simulateKeyUpEventsHiddenByCmd(e,o,t,n,i),this.eventPropagator.finishPropagationStep(),s}}},{key:"closeHangingKeyCombination",value:function(e,t){var n=this.getCurrentCombination();n.isKeyIncluded(e)&&!n.isEventTriggered(e,t)&&n.setKeyState(e,t,ae)}},{key:"_simulateKeyPressForNonPrintableKeys",value:function(e,t,n,i,o){this._handleEventSimulation("keypressEventsToSimulate","simulatePendingKeyPressEvents",this._shouldSimulate(S.keypress,t),{event:e,key:t,focusTreeId:n,componentId:i,options:o})}},{key:"_simulateKeyUpEventsHiddenByCmd",value:function(t,e,n,i,o){var r=this;xe(e)&&this.getCurrentCombination().forEachKey(function(e){xe(e)||r._handleEventSimulation("keyupEventsToSimulate","simulatePendingKeyUpEvents",r._shouldSimulate(S.keyup,e),{event:t,key:e,focusTreeId:n,componentId:i,options:o})})}},{key:"_stopEventPropagation",value:function(e,t){this.eventPropagator.stop(e)}},{key:"getEventPropagator",value:function(){return this.eventPropagator}},{key:"_startAndLogNewKeyCombination",value:function(e,t,n,i){this.getKeyHistory().startNewKeyCombination(e,i)}},{key:"_addToAndLogCurrentKeyCombination",value:function(e,t,n,i,o){this.getKeyHistory().addKeyToCurrentCombination(e,t,o)}},{key:"_handleEventSimulation",value:function(e,t,n,i){var o=i.event,r=i.key,s=i.focusTreeId,a=i.componentId,u=i.options;if(n&&E.option("simulateMissingKeyPressEvents")){var c=this._cloneAndMergeEvent(o,{key:r,simulated:!0});this[e].push({event:c,focusTreeId:s,componentId:a,options:u})}(this.componentList.isRoot(a)||this.eventPropagator.isStopped())&&(this.keyEventManager.isGlobalListenersBound()||this[t]())}},{key:"simulatePendingKeyPressEvents",value:function(){this._simulatePendingKeyEvents("keypressEventsToSimulate","handleKeyPress")}},{key:"simulatePendingKeyUpEvents",value:function(){this._simulatePendingKeyEvents("keyupEventsToSimulate","handleKeyUp")}},{key:"_simulatePendingKeyEvents",value:function(e,r){var s=this;0<this[e].length&&Oe.incrementId(),this[e].forEach(function(e){var t=e.event,n=e.focusTreeId,i=e.componentId,o=e.options;s[r](t,n,i,o)}),this[e]=[]}},{key:"_callHandlerIfActionNotHandled",value:function(e,t,n,i,o){this.getCurrentCombination().describe();if(this.componentList.anyActionsForEventType(n))if(this.eventPropagator.isHandled());else{var r=this.eventPropagator.getPreviousPosition(),s=this.componentList.getIndexById(i);this._callClosestMatchingHandler(e,t,n,s,-1===r?0:r)&&this.eventPropagator.setHandled()}}},{key:"_logPrefix",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=I.logIcons,i=I.eventIcons,o=I.componentIcons,r="HotKeys (";if(!1!==t.focusTreeId){var s=oe(t.focusTreeId)?this.focusTreeId:t.focusTreeId;r+="F".concat(s).concat(n[s%n.length],"-")}if(!1!==t.eventId){var a=oe(t.eventId)?Oe.getId():t.eventId;r+="E".concat(a).concat(i[a%i.length],"-")}r+="C".concat(e).concat(o[e%o.length]);var u=this.componentList.getIndexById(e);return oe(u)||(r+="-P".concat(u).concat(o[u%o.length],":")),"".concat(r,")")}}]),i}();function Ue(e,t){var n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{};return Array.isArray(e)||x(e)?n.stringifyFirst?!oe(e.find(function(e){return e.toString()===t.toString()})):-1!==e.indexOf(t):ce(e)?M(e,t):n.stringifyFirst?e.toString()===t.toString():e===t}function Be(e){return e.replace(/\b\w/g,function(e){return e.toUpperCase()})}var Ge=function(e){function o(){var e,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},n=1<arguments.length?arguments[1]:void 0;return c(this,o),(e=_(this,p(o).call(this,t,n))).listenersBound=!1,e.eventOptions={ignoreEventsCondition:E.option("ignoreEventsCondition")},e.listeners={},e}return y(o,Te),l(o,[{key:"enableHotKeys",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},i=3<arguments.length?arguments[3]:void 0,o=4<arguments.length?arguments[4]:void 0;this.eventOptions=o,this._addComponent(e,t,n,i),this._updateDocumentHandlers(),this._initHandlerResolutionState()}},{key:"updateEnabledHotKeys",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=2<arguments.length&&void 0!==arguments[2]?arguments[2]:{},i=3<arguments.length?arguments[3]:void 0,o=4<arguments.length?arguments[4]:void 0;this.eventOptions=o,this.componentList.update(e,t,n,i),this.getKeyHistory().setMaxLength(this.componentList.getLongestSequence()),this._updateDocumentHandlers(),this._initHandlerResolutionState()}},{key:"disableHotKeys",value:function(e){this.componentList.remove(e),this.getKeyHistory().setMaxLength(this.componentList.getLongestSequence()),this._updateDocumentHandlers(),this._initHandlerResolutionState()}},{key:"_updateDocumentHandlers",value:function(){var i=this,e=this._listenersShouldBeBound();!this.listenersBound&&e?(Object.values(S).forEach(function(e){var n=Pe(e);document["on".concat(n)]=function(e){var t;i.keyEventManager["handleGlobal".concat((t=n,"".concat(Be(t.slice(0,3))).concat(Be(t.slice(3)))))](e)}}),this.listenersBound=!0):this.listenersBound&&!e&&(Object.values(S).forEach(function(e){var t=Pe(e);delete document["on".concat(t)]}),this.listenersBound=!1)}},{key:"_listenersShouldBeBound",value:function(){return this.componentList.any()||this.listeners.keyCombination}},{key:"handleKeydown",value:function(e){var t=Ae(e);if(e.repeat&&E.option("ignoreRepeatedEventsWhenKeyHeldDown"))return!0;this._checkForModifierFlagDiscrepancies(e,t,S.keydown);var n=this._howReactAppRespondedTo(e,t,S.keydown);if(n!==De||!this.eventOptions.ignoreEventsCondition(e)){if(n!==qe){var i=we(e),o=this.getCurrentCombination();o.isKeyIncluded(t)||o.isEnding()?this._startAndLogNewKeyCombination(t,i):this._addToAndLogCurrentKeyCombination(t,S.keydown,i)}Ue([qe,je],n)||this._callHandlerIfExists(e,t,S.keydown),this._simulateKeyPressForNonPrintableKeys(e,t)}}},{key:"_howReactAppRespondedTo",value:function(e,t,n){var i=this.keyEventManager.reactAppHistoryWithEvent(t,n);switch(i){case je:case qe:case Fe:break;default:Oe.incrementId()}return i}},{key:"handleKeyPress",value:function(e){var t=Ae(e);if(e.repeat&&E.option("ignoreRepeatedEventsWhenKeyHeldDown"))return!0;var n=this.getCurrentCombination();if(n.isKeyPressSimulated(t))return!0;var i=this._howReactAppRespondedTo(e,t,S.keypress);n.isKeyIncluded(t)&&this._addToAndLogCurrentKeyCombination(t,S.keypress,we(e)),i===De&&(this.keyEventManager.closeHangingKeyCombination(t,S.keypress),this.eventOptions.ignoreEventsCondition(e))||Ue([qe,je],i)||this._callHandlerIfExists(e,t,S.keypress)}},{key:"handleKeyUp",value:function(e){var t=Ae(e),n=this.getCurrentCombination();if(n.isKeyUpSimulated(t))return!0;var i=this._howReactAppRespondedTo(e,t,S.keyup);n.isKeyIncluded(t)&&this._addToAndLogCurrentKeyCombination(t,S.keyup,we(e)),i===De?(this.keyEventManager.closeHangingKeyCombination(t,S.keyup),this.eventOptions.ignoreEventsCondition(e)||Ue([qe,je],i)||this._callHandlerIfExists(e,t,S.keyup)):Ue([qe,je],i)||this._callHandlerIfExists(e,t,S.keyup),this._simulateKeyUpEventsHiddenByCmd(e,t),this.listeners.keyCombination&&this._allKeysAreReleased()&&this.listeners.keyCombination({keys:n.getKeyDictionary(),id:n.describe()})}},{key:"_simulateKeyPressForNonPrintableKeys",value:function(e,t){this.keyEventManager.simulatePendingKeyPressEvents(),this._handleEventSimulation("handleKeyPress",this._shouldSimulate(S.keypress,t),{event:e,key:t})}},{key:"_simulateKeyUpEventsHiddenByCmd",value:function(t,e){var n=this;xe(e)&&(this.keyEventManager.simulatePendingKeyUpEvents(),this.getCurrentCombination().forEachKey(function(e){xe(e)||n._handleEventSimulation("handleKeyUp",n._shouldSimulate(S.keyup,e),{event:t,key:e})}))}},{key:"_startAndLogNewKeyCombination",value:function(e,t){this.getKeyHistory().startNewKeyCombination(e,t)}},{key:"_addToAndLogCurrentKeyCombination",value:function(e,t,n){this.getKeyHistory().addKeyToCurrentCombination(e,t,n)}},{key:"_handleEventSimulation",value:function(e,t,n){var i=n.event,o=n.key;if(t&&E.option("simulateMissingKeyPressEvents")){var r=this._cloneAndMergeEvent(i,{key:o,simulated:!0});this[e](r)}}},{key:"_callHandlerIfExists",value:function(e,t,n){this.getCurrentCombination().describe();this.componentList.anyActionsForEventType(n)&&this._callClosestMatchingHandler(e,t,n)}},{key:"_callClosestMatchingHandler",value:function(e,t,n){for(var i=this.componentList.getNewIterator();i.next();){if(k(p(o.prototype),"_callClosestMatchingHandler",this).call(this,e,t,n,i.getPosition(),0))return}}},{key:"_stopEventPropagation",value:function(e,t){e.simulated||e.stopPropagation()}},{key:"addKeyCombinationListener",value:function(t){var e=this,n=function(){delete e.listeners.keyCombination};return this.listeners.keyCombination=function(e){t(e),n()},this._updateDocumentHandlers(),n}},{key:"_logPrefix",value:function(e){var t=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},n=I.eventIcons,i=I.componentIcons,o="HotKeys (GLOBAL";if(!1!==t.eventId){var r=oe(t.eventId)?Oe.getId():t.eventId;o="".concat(o,"-E").concat(r).concat(n[r%n.length])}return oe(e)?"".concat(o,"):"):"".concat(o,"-C").concat(e).concat(i[e%i.length],"):")}}]),o}();function ze(e){return!oe(e)}var We=function(){function t(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};c(this,t),this.logger=e.logger||new I(E.option("logLevel")),this._focusOnlyEventStrategy=new Ne({configuration:e,logger:this.logger},this),this._globalEventStrategy=new Ge({configuration:e,logger:this.logger},this),this.mountedComponentsCount=0}return l(t,null,[{key:"getInstance",value:function(){var e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};return this.instance||(this.instance=ne