Няма описание

compose.js 148KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725
  1. /******/ (function() { // webpackBootstrap
  2. /******/ var __webpack_modules__ = ({
  3. /***/ 8294:
  4. /***/ (function(module) {
  5. /*!
  6. * clipboard.js v2.0.10
  7. * https://clipboardjs.com/
  8. *
  9. * Licensed MIT © Zeno Rocha
  10. */
  11. (function webpackUniversalModuleDefinition(root, factory) {
  12. if(true)
  13. module.exports = factory();
  14. else {}
  15. })(this, function() {
  16. return /******/ (function() { // webpackBootstrap
  17. /******/ var __webpack_modules__ = ({
  18. /***/ 686:
  19. /***/ (function(__unused_webpack_module, __webpack_exports__, __nested_webpack_require_623__) {
  20. "use strict";
  21. // EXPORTS
  22. __nested_webpack_require_623__.d(__webpack_exports__, {
  23. "default": function() { return /* binding */ clipboard; }
  24. });
  25. // EXTERNAL MODULE: ./node_modules/tiny-emitter/index.js
  26. var tiny_emitter = __nested_webpack_require_623__(279);
  27. var tiny_emitter_default = /*#__PURE__*/__nested_webpack_require_623__.n(tiny_emitter);
  28. // EXTERNAL MODULE: ./node_modules/good-listener/src/listen.js
  29. var listen = __nested_webpack_require_623__(370);
  30. var listen_default = /*#__PURE__*/__nested_webpack_require_623__.n(listen);
  31. // EXTERNAL MODULE: ./node_modules/select/src/select.js
  32. var src_select = __nested_webpack_require_623__(817);
  33. var select_default = /*#__PURE__*/__nested_webpack_require_623__.n(src_select);
  34. ;// CONCATENATED MODULE: ./src/common/command.js
  35. /**
  36. * Executes a given operation type.
  37. * @param {String} type
  38. * @return {Boolean}
  39. */
  40. function command(type) {
  41. try {
  42. return document.execCommand(type);
  43. } catch (err) {
  44. return false;
  45. }
  46. }
  47. ;// CONCATENATED MODULE: ./src/actions/cut.js
  48. /**
  49. * Cut action wrapper.
  50. * @param {String|HTMLElement} target
  51. * @return {String}
  52. */
  53. var ClipboardActionCut = function ClipboardActionCut(target) {
  54. var selectedText = select_default()(target);
  55. command('cut');
  56. return selectedText;
  57. };
  58. /* harmony default export */ var actions_cut = (ClipboardActionCut);
  59. ;// CONCATENATED MODULE: ./src/common/create-fake-element.js
  60. /**
  61. * Creates a fake textarea element with a value.
  62. * @param {String} value
  63. * @return {HTMLElement}
  64. */
  65. function createFakeElement(value) {
  66. var isRTL = document.documentElement.getAttribute('dir') === 'rtl';
  67. var fakeElement = document.createElement('textarea'); // Prevent zooming on iOS
  68. fakeElement.style.fontSize = '12pt'; // Reset box model
  69. fakeElement.style.border = '0';
  70. fakeElement.style.padding = '0';
  71. fakeElement.style.margin = '0'; // Move element out of screen horizontally
  72. fakeElement.style.position = 'absolute';
  73. fakeElement.style[isRTL ? 'right' : 'left'] = '-9999px'; // Move element to the same position vertically
  74. var yPosition = window.pageYOffset || document.documentElement.scrollTop;
  75. fakeElement.style.top = "".concat(yPosition, "px");
  76. fakeElement.setAttribute('readonly', '');
  77. fakeElement.value = value;
  78. return fakeElement;
  79. }
  80. ;// CONCATENATED MODULE: ./src/actions/copy.js
  81. /**
  82. * Copy action wrapper.
  83. * @param {String|HTMLElement} target
  84. * @param {Object} options
  85. * @return {String}
  86. */
  87. var ClipboardActionCopy = function ClipboardActionCopy(target) {
  88. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  89. container: document.body
  90. };
  91. var selectedText = '';
  92. if (typeof target === 'string') {
  93. var fakeElement = createFakeElement(target);
  94. options.container.appendChild(fakeElement);
  95. selectedText = select_default()(fakeElement);
  96. command('copy');
  97. fakeElement.remove();
  98. } else {
  99. selectedText = select_default()(target);
  100. command('copy');
  101. }
  102. return selectedText;
  103. };
  104. /* harmony default export */ var actions_copy = (ClipboardActionCopy);
  105. ;// CONCATENATED MODULE: ./src/actions/default.js
  106. function _typeof(obj) { "@babel/helpers - typeof"; 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); }
  107. /**
  108. * Inner function which performs selection from either `text` or `target`
  109. * properties and then executes copy or cut operations.
  110. * @param {Object} options
  111. */
  112. var ClipboardActionDefault = function ClipboardActionDefault() {
  113. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  114. // Defines base properties passed from constructor.
  115. var _options$action = options.action,
  116. action = _options$action === void 0 ? 'copy' : _options$action,
  117. container = options.container,
  118. target = options.target,
  119. text = options.text; // Sets the `action` to be performed which can be either 'copy' or 'cut'.
  120. if (action !== 'copy' && action !== 'cut') {
  121. throw new Error('Invalid "action" value, use either "copy" or "cut"');
  122. } // Sets the `target` property using an element that will be have its content copied.
  123. if (target !== undefined) {
  124. if (target && _typeof(target) === 'object' && target.nodeType === 1) {
  125. if (action === 'copy' && target.hasAttribute('disabled')) {
  126. throw new Error('Invalid "target" attribute. Please use "readonly" instead of "disabled" attribute');
  127. }
  128. if (action === 'cut' && (target.hasAttribute('readonly') || target.hasAttribute('disabled'))) {
  129. throw new Error('Invalid "target" attribute. You can\'t cut text from elements with "readonly" or "disabled" attributes');
  130. }
  131. } else {
  132. throw new Error('Invalid "target" value, use a valid Element');
  133. }
  134. } // Define selection strategy based on `text` property.
  135. if (text) {
  136. return actions_copy(text, {
  137. container: container
  138. });
  139. } // Defines which selection strategy based on `target` property.
  140. if (target) {
  141. return action === 'cut' ? actions_cut(target) : actions_copy(target, {
  142. container: container
  143. });
  144. }
  145. };
  146. /* harmony default export */ var actions_default = (ClipboardActionDefault);
  147. ;// CONCATENATED MODULE: ./src/clipboard.js
  148. function clipboard_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { clipboard_typeof = function _typeof(obj) { return typeof obj; }; } else { clipboard_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return clipboard_typeof(obj); }
  149. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  150. function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  151. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  152. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  153. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  154. function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
  155. function _possibleConstructorReturn(self, call) { if (call && (clipboard_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  156. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  157. function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  158. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  159. /**
  160. * Helper function to retrieve attribute value.
  161. * @param {String} suffix
  162. * @param {Element} element
  163. */
  164. function getAttributeValue(suffix, element) {
  165. var attribute = "data-clipboard-".concat(suffix);
  166. if (!element.hasAttribute(attribute)) {
  167. return;
  168. }
  169. return element.getAttribute(attribute);
  170. }
  171. /**
  172. * Base class which takes one or more elements, adds event listeners to them,
  173. * and instantiates a new `ClipboardAction` on each click.
  174. */
  175. var Clipboard = /*#__PURE__*/function (_Emitter) {
  176. _inherits(Clipboard, _Emitter);
  177. var _super = _createSuper(Clipboard);
  178. /**
  179. * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
  180. * @param {Object} options
  181. */
  182. function Clipboard(trigger, options) {
  183. var _this;
  184. _classCallCheck(this, Clipboard);
  185. _this = _super.call(this);
  186. _this.resolveOptions(options);
  187. _this.listenClick(trigger);
  188. return _this;
  189. }
  190. /**
  191. * Defines if attributes would be resolved using internal setter functions
  192. * or custom functions that were passed in the constructor.
  193. * @param {Object} options
  194. */
  195. _createClass(Clipboard, [{
  196. key: "resolveOptions",
  197. value: function resolveOptions() {
  198. var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  199. this.action = typeof options.action === 'function' ? options.action : this.defaultAction;
  200. this.target = typeof options.target === 'function' ? options.target : this.defaultTarget;
  201. this.text = typeof options.text === 'function' ? options.text : this.defaultText;
  202. this.container = clipboard_typeof(options.container) === 'object' ? options.container : document.body;
  203. }
  204. /**
  205. * Adds a click event listener to the passed trigger.
  206. * @param {String|HTMLElement|HTMLCollection|NodeList} trigger
  207. */
  208. }, {
  209. key: "listenClick",
  210. value: function listenClick(trigger) {
  211. var _this2 = this;
  212. this.listener = listen_default()(trigger, 'click', function (e) {
  213. return _this2.onClick(e);
  214. });
  215. }
  216. /**
  217. * Defines a new `ClipboardAction` on each click event.
  218. * @param {Event} e
  219. */
  220. }, {
  221. key: "onClick",
  222. value: function onClick(e) {
  223. var trigger = e.delegateTarget || e.currentTarget;
  224. var action = this.action(trigger) || 'copy';
  225. var text = actions_default({
  226. action: action,
  227. container: this.container,
  228. target: this.target(trigger),
  229. text: this.text(trigger)
  230. }); // Fires an event based on the copy operation result.
  231. this.emit(text ? 'success' : 'error', {
  232. action: action,
  233. text: text,
  234. trigger: trigger,
  235. clearSelection: function clearSelection() {
  236. if (trigger) {
  237. trigger.focus();
  238. }
  239. document.activeElement.blur();
  240. window.getSelection().removeAllRanges();
  241. }
  242. });
  243. }
  244. /**
  245. * Default `action` lookup function.
  246. * @param {Element} trigger
  247. */
  248. }, {
  249. key: "defaultAction",
  250. value: function defaultAction(trigger) {
  251. return getAttributeValue('action', trigger);
  252. }
  253. /**
  254. * Default `target` lookup function.
  255. * @param {Element} trigger
  256. */
  257. }, {
  258. key: "defaultTarget",
  259. value: function defaultTarget(trigger) {
  260. var selector = getAttributeValue('target', trigger);
  261. if (selector) {
  262. return document.querySelector(selector);
  263. }
  264. }
  265. /**
  266. * Allow fire programmatically a copy action
  267. * @param {String|HTMLElement} target
  268. * @param {Object} options
  269. * @returns Text copied.
  270. */
  271. }, {
  272. key: "defaultText",
  273. /**
  274. * Default `text` lookup function.
  275. * @param {Element} trigger
  276. */
  277. value: function defaultText(trigger) {
  278. return getAttributeValue('text', trigger);
  279. }
  280. /**
  281. * Destroy lifecycle.
  282. */
  283. }, {
  284. key: "destroy",
  285. value: function destroy() {
  286. this.listener.destroy();
  287. }
  288. }], [{
  289. key: "copy",
  290. value: function copy(target) {
  291. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  292. container: document.body
  293. };
  294. return actions_copy(target, options);
  295. }
  296. /**
  297. * Allow fire programmatically a cut action
  298. * @param {String|HTMLElement} target
  299. * @returns Text cutted.
  300. */
  301. }, {
  302. key: "cut",
  303. value: function cut(target) {
  304. return actions_cut(target);
  305. }
  306. /**
  307. * Returns the support of the given action, or all actions if no action is
  308. * given.
  309. * @param {String} [action]
  310. */
  311. }, {
  312. key: "isSupported",
  313. value: function isSupported() {
  314. var action = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : ['copy', 'cut'];
  315. var actions = typeof action === 'string' ? [action] : action;
  316. var support = !!document.queryCommandSupported;
  317. actions.forEach(function (action) {
  318. support = support && !!document.queryCommandSupported(action);
  319. });
  320. return support;
  321. }
  322. }]);
  323. return Clipboard;
  324. }((tiny_emitter_default()));
  325. /* harmony default export */ var clipboard = (Clipboard);
  326. /***/ }),
  327. /***/ 828:
  328. /***/ (function(module) {
  329. var DOCUMENT_NODE_TYPE = 9;
  330. /**
  331. * A polyfill for Element.matches()
  332. */
  333. if (typeof Element !== 'undefined' && !Element.prototype.matches) {
  334. var proto = Element.prototype;
  335. proto.matches = proto.matchesSelector ||
  336. proto.mozMatchesSelector ||
  337. proto.msMatchesSelector ||
  338. proto.oMatchesSelector ||
  339. proto.webkitMatchesSelector;
  340. }
  341. /**
  342. * Finds the closest parent that matches a selector.
  343. *
  344. * @param {Element} element
  345. * @param {String} selector
  346. * @return {Function}
  347. */
  348. function closest (element, selector) {
  349. while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {
  350. if (typeof element.matches === 'function' &&
  351. element.matches(selector)) {
  352. return element;
  353. }
  354. element = element.parentNode;
  355. }
  356. }
  357. module.exports = closest;
  358. /***/ }),
  359. /***/ 438:
  360. /***/ (function(module, __unused_webpack_exports, __nested_webpack_require_15133__) {
  361. var closest = __nested_webpack_require_15133__(828);
  362. /**
  363. * Delegates event to a selector.
  364. *
  365. * @param {Element} element
  366. * @param {String} selector
  367. * @param {String} type
  368. * @param {Function} callback
  369. * @param {Boolean} useCapture
  370. * @return {Object}
  371. */
  372. function _delegate(element, selector, type, callback, useCapture) {
  373. var listenerFn = listener.apply(this, arguments);
  374. element.addEventListener(type, listenerFn, useCapture);
  375. return {
  376. destroy: function() {
  377. element.removeEventListener(type, listenerFn, useCapture);
  378. }
  379. }
  380. }
  381. /**
  382. * Delegates event to a selector.
  383. *
  384. * @param {Element|String|Array} [elements]
  385. * @param {String} selector
  386. * @param {String} type
  387. * @param {Function} callback
  388. * @param {Boolean} useCapture
  389. * @return {Object}
  390. */
  391. function delegate(elements, selector, type, callback, useCapture) {
  392. // Handle the regular Element usage
  393. if (typeof elements.addEventListener === 'function') {
  394. return _delegate.apply(null, arguments);
  395. }
  396. // Handle Element-less usage, it defaults to global delegation
  397. if (typeof type === 'function') {
  398. // Use `document` as the first parameter, then apply arguments
  399. // This is a short way to .unshift `arguments` without running into deoptimizations
  400. return _delegate.bind(null, document).apply(null, arguments);
  401. }
  402. // Handle Selector-based usage
  403. if (typeof elements === 'string') {
  404. elements = document.querySelectorAll(elements);
  405. }
  406. // Handle Array-like based usage
  407. return Array.prototype.map.call(elements, function (element) {
  408. return _delegate(element, selector, type, callback, useCapture);
  409. });
  410. }
  411. /**
  412. * Finds closest match and invokes callback.
  413. *
  414. * @param {Element} element
  415. * @param {String} selector
  416. * @param {String} type
  417. * @param {Function} callback
  418. * @return {Function}
  419. */
  420. function listener(element, selector, type, callback) {
  421. return function(e) {
  422. e.delegateTarget = closest(e.target, selector);
  423. if (e.delegateTarget) {
  424. callback.call(element, e);
  425. }
  426. }
  427. }
  428. module.exports = delegate;
  429. /***/ }),
  430. /***/ 879:
  431. /***/ (function(__unused_webpack_module, exports) {
  432. /**
  433. * Check if argument is a HTML element.
  434. *
  435. * @param {Object} value
  436. * @return {Boolean}
  437. */
  438. exports.node = function(value) {
  439. return value !== undefined
  440. && value instanceof HTMLElement
  441. && value.nodeType === 1;
  442. };
  443. /**
  444. * Check if argument is a list of HTML elements.
  445. *
  446. * @param {Object} value
  447. * @return {Boolean}
  448. */
  449. exports.nodeList = function(value) {
  450. var type = Object.prototype.toString.call(value);
  451. return value !== undefined
  452. && (type === '[object NodeList]' || type === '[object HTMLCollection]')
  453. && ('length' in value)
  454. && (value.length === 0 || exports.node(value[0]));
  455. };
  456. /**
  457. * Check if argument is a string.
  458. *
  459. * @param {Object} value
  460. * @return {Boolean}
  461. */
  462. exports.string = function(value) {
  463. return typeof value === 'string'
  464. || value instanceof String;
  465. };
  466. /**
  467. * Check if argument is a function.
  468. *
  469. * @param {Object} value
  470. * @return {Boolean}
  471. */
  472. exports.fn = function(value) {
  473. var type = Object.prototype.toString.call(value);
  474. return type === '[object Function]';
  475. };
  476. /***/ }),
  477. /***/ 370:
  478. /***/ (function(module, __unused_webpack_exports, __nested_webpack_require_18497__) {
  479. var is = __nested_webpack_require_18497__(879);
  480. var delegate = __nested_webpack_require_18497__(438);
  481. /**
  482. * Validates all params and calls the right
  483. * listener function based on its target type.
  484. *
  485. * @param {String|HTMLElement|HTMLCollection|NodeList} target
  486. * @param {String} type
  487. * @param {Function} callback
  488. * @return {Object}
  489. */
  490. function listen(target, type, callback) {
  491. if (!target && !type && !callback) {
  492. throw new Error('Missing required arguments');
  493. }
  494. if (!is.string(type)) {
  495. throw new TypeError('Second argument must be a String');
  496. }
  497. if (!is.fn(callback)) {
  498. throw new TypeError('Third argument must be a Function');
  499. }
  500. if (is.node(target)) {
  501. return listenNode(target, type, callback);
  502. }
  503. else if (is.nodeList(target)) {
  504. return listenNodeList(target, type, callback);
  505. }
  506. else if (is.string(target)) {
  507. return listenSelector(target, type, callback);
  508. }
  509. else {
  510. throw new TypeError('First argument must be a String, HTMLElement, HTMLCollection, or NodeList');
  511. }
  512. }
  513. /**
  514. * Adds an event listener to a HTML element
  515. * and returns a remove listener function.
  516. *
  517. * @param {HTMLElement} node
  518. * @param {String} type
  519. * @param {Function} callback
  520. * @return {Object}
  521. */
  522. function listenNode(node, type, callback) {
  523. node.addEventListener(type, callback);
  524. return {
  525. destroy: function() {
  526. node.removeEventListener(type, callback);
  527. }
  528. }
  529. }
  530. /**
  531. * Add an event listener to a list of HTML elements
  532. * and returns a remove listener function.
  533. *
  534. * @param {NodeList|HTMLCollection} nodeList
  535. * @param {String} type
  536. * @param {Function} callback
  537. * @return {Object}
  538. */
  539. function listenNodeList(nodeList, type, callback) {
  540. Array.prototype.forEach.call(nodeList, function(node) {
  541. node.addEventListener(type, callback);
  542. });
  543. return {
  544. destroy: function() {
  545. Array.prototype.forEach.call(nodeList, function(node) {
  546. node.removeEventListener(type, callback);
  547. });
  548. }
  549. }
  550. }
  551. /**
  552. * Add an event listener to a selector
  553. * and returns a remove listener function.
  554. *
  555. * @param {String} selector
  556. * @param {String} type
  557. * @param {Function} callback
  558. * @return {Object}
  559. */
  560. function listenSelector(selector, type, callback) {
  561. return delegate(document.body, selector, type, callback);
  562. }
  563. module.exports = listen;
  564. /***/ }),
  565. /***/ 817:
  566. /***/ (function(module) {
  567. function select(element) {
  568. var selectedText;
  569. if (element.nodeName === 'SELECT') {
  570. element.focus();
  571. selectedText = element.value;
  572. }
  573. else if (element.nodeName === 'INPUT' || element.nodeName === 'TEXTAREA') {
  574. var isReadOnly = element.hasAttribute('readonly');
  575. if (!isReadOnly) {
  576. element.setAttribute('readonly', '');
  577. }
  578. element.select();
  579. element.setSelectionRange(0, element.value.length);
  580. if (!isReadOnly) {
  581. element.removeAttribute('readonly');
  582. }
  583. selectedText = element.value;
  584. }
  585. else {
  586. if (element.hasAttribute('contenteditable')) {
  587. element.focus();
  588. }
  589. var selection = window.getSelection();
  590. var range = document.createRange();
  591. range.selectNodeContents(element);
  592. selection.removeAllRanges();
  593. selection.addRange(range);
  594. selectedText = selection.toString();
  595. }
  596. return selectedText;
  597. }
  598. module.exports = select;
  599. /***/ }),
  600. /***/ 279:
  601. /***/ (function(module) {
  602. function E () {
  603. // Keep this empty so it's easier to inherit from
  604. // (via https://github.com/lipsmack from https://github.com/scottcorgan/tiny-emitter/issues/3)
  605. }
  606. E.prototype = {
  607. on: function (name, callback, ctx) {
  608. var e = this.e || (this.e = {});
  609. (e[name] || (e[name] = [])).push({
  610. fn: callback,
  611. ctx: ctx
  612. });
  613. return this;
  614. },
  615. once: function (name, callback, ctx) {
  616. var self = this;
  617. function listener () {
  618. self.off(name, listener);
  619. callback.apply(ctx, arguments);
  620. };
  621. listener._ = callback
  622. return this.on(name, listener, ctx);
  623. },
  624. emit: function (name) {
  625. var data = [].slice.call(arguments, 1);
  626. var evtArr = ((this.e || (this.e = {}))[name] || []).slice();
  627. var i = 0;
  628. var len = evtArr.length;
  629. for (i; i < len; i++) {
  630. evtArr[i].fn.apply(evtArr[i].ctx, data);
  631. }
  632. return this;
  633. },
  634. off: function (name, callback) {
  635. var e = this.e || (this.e = {});
  636. var evts = e[name];
  637. var liveEvents = [];
  638. if (evts && callback) {
  639. for (var i = 0, len = evts.length; i < len; i++) {
  640. if (evts[i].fn !== callback && evts[i].fn._ !== callback)
  641. liveEvents.push(evts[i]);
  642. }
  643. }
  644. // Remove event from queue to prevent memory leak
  645. // Suggested by https://github.com/lazd
  646. // Ref: https://github.com/scottcorgan/tiny-emitter/commit/c6ebfaa9bc973b33d110a84a307742b7cf94c953#commitcomment-5024910
  647. (liveEvents.length)
  648. ? e[name] = liveEvents
  649. : delete e[name];
  650. return this;
  651. }
  652. };
  653. module.exports = E;
  654. module.exports.TinyEmitter = E;
  655. /***/ })
  656. /******/ });
  657. /************************************************************************/
  658. /******/ // The module cache
  659. /******/ var __webpack_module_cache__ = {};
  660. /******/
  661. /******/ // The require function
  662. /******/ function __nested_webpack_require_23879__(moduleId) {
  663. /******/ // Check if module is in cache
  664. /******/ if(__webpack_module_cache__[moduleId]) {
  665. /******/ return __webpack_module_cache__[moduleId].exports;
  666. /******/ }
  667. /******/ // Create a new module (and put it into the cache)
  668. /******/ var module = __webpack_module_cache__[moduleId] = {
  669. /******/ // no module.id needed
  670. /******/ // no module.loaded needed
  671. /******/ exports: {}
  672. /******/ };
  673. /******/
  674. /******/ // Execute the module function
  675. /******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_23879__);
  676. /******/
  677. /******/ // Return the exports of the module
  678. /******/ return module.exports;
  679. /******/ }
  680. /******/
  681. /************************************************************************/
  682. /******/ /* webpack/runtime/compat get default export */
  683. /******/ !function() {
  684. /******/ // getDefaultExport function for compatibility with non-harmony modules
  685. /******/ __nested_webpack_require_23879__.n = function(module) {
  686. /******/ var getter = module && module.__esModule ?
  687. /******/ function() { return module['default']; } :
  688. /******/ function() { return module; };
  689. /******/ __nested_webpack_require_23879__.d(getter, { a: getter });
  690. /******/ return getter;
  691. /******/ };
  692. /******/ }();
  693. /******/
  694. /******/ /* webpack/runtime/define property getters */
  695. /******/ !function() {
  696. /******/ // define getter functions for harmony exports
  697. /******/ __nested_webpack_require_23879__.d = function(exports, definition) {
  698. /******/ for(var key in definition) {
  699. /******/ if(__nested_webpack_require_23879__.o(definition, key) && !__nested_webpack_require_23879__.o(exports, key)) {
  700. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  701. /******/ }
  702. /******/ }
  703. /******/ };
  704. /******/ }();
  705. /******/
  706. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  707. /******/ !function() {
  708. /******/ __nested_webpack_require_23879__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  709. /******/ }();
  710. /******/
  711. /************************************************************************/
  712. /******/ // module exports must be returned from runtime so entry inlining is disabled
  713. /******/ // startup
  714. /******/ // Load entry module and return exports
  715. /******/ return __nested_webpack_require_23879__(686);
  716. /******/ })()
  717. .default;
  718. });
  719. /***/ }),
  720. /***/ 7973:
  721. /***/ (function(module, exports, __webpack_require__) {
  722. var __WEBPACK_AMD_DEFINE_RESULT__;/*global define:false */
  723. /**
  724. * Copyright 2012-2017 Craig Campbell
  725. *
  726. * Licensed under the Apache License, Version 2.0 (the "License");
  727. * you may not use this file except in compliance with the License.
  728. * You may obtain a copy of the License at
  729. *
  730. * http://www.apache.org/licenses/LICENSE-2.0
  731. *
  732. * Unless required by applicable law or agreed to in writing, software
  733. * distributed under the License is distributed on an "AS IS" BASIS,
  734. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  735. * See the License for the specific language governing permissions and
  736. * limitations under the License.
  737. *
  738. * Mousetrap is a simple keyboard shortcut library for Javascript with
  739. * no external dependencies
  740. *
  741. * @version 1.6.5
  742. * @url craig.is/killing/mice
  743. */
  744. (function(window, document, undefined) {
  745. // Check if mousetrap is used inside browser, if not, return
  746. if (!window) {
  747. return;
  748. }
  749. /**
  750. * mapping of special keycodes to their corresponding keys
  751. *
  752. * everything in this dictionary cannot use keypress events
  753. * so it has to be here to map to the correct keycodes for
  754. * keyup/keydown events
  755. *
  756. * @type {Object}
  757. */
  758. var _MAP = {
  759. 8: 'backspace',
  760. 9: 'tab',
  761. 13: 'enter',
  762. 16: 'shift',
  763. 17: 'ctrl',
  764. 18: 'alt',
  765. 20: 'capslock',
  766. 27: 'esc',
  767. 32: 'space',
  768. 33: 'pageup',
  769. 34: 'pagedown',
  770. 35: 'end',
  771. 36: 'home',
  772. 37: 'left',
  773. 38: 'up',
  774. 39: 'right',
  775. 40: 'down',
  776. 45: 'ins',
  777. 46: 'del',
  778. 91: 'meta',
  779. 93: 'meta',
  780. 224: 'meta'
  781. };
  782. /**
  783. * mapping for special characters so they can support
  784. *
  785. * this dictionary is only used incase you want to bind a
  786. * keyup or keydown event to one of these keys
  787. *
  788. * @type {Object}
  789. */
  790. var _KEYCODE_MAP = {
  791. 106: '*',
  792. 107: '+',
  793. 109: '-',
  794. 110: '.',
  795. 111 : '/',
  796. 186: ';',
  797. 187: '=',
  798. 188: ',',
  799. 189: '-',
  800. 190: '.',
  801. 191: '/',
  802. 192: '`',
  803. 219: '[',
  804. 220: '\\',
  805. 221: ']',
  806. 222: '\''
  807. };
  808. /**
  809. * this is a mapping of keys that require shift on a US keypad
  810. * back to the non shift equivelents
  811. *
  812. * this is so you can use keyup events with these keys
  813. *
  814. * note that this will only work reliably on US keyboards
  815. *
  816. * @type {Object}
  817. */
  818. var _SHIFT_MAP = {
  819. '~': '`',
  820. '!': '1',
  821. '@': '2',
  822. '#': '3',
  823. '$': '4',
  824. '%': '5',
  825. '^': '6',
  826. '&': '7',
  827. '*': '8',
  828. '(': '9',
  829. ')': '0',
  830. '_': '-',
  831. '+': '=',
  832. ':': ';',
  833. '\"': '\'',
  834. '<': ',',
  835. '>': '.',
  836. '?': '/',
  837. '|': '\\'
  838. };
  839. /**
  840. * this is a list of special strings you can use to map
  841. * to modifier keys when you specify your keyboard shortcuts
  842. *
  843. * @type {Object}
  844. */
  845. var _SPECIAL_ALIASES = {
  846. 'option': 'alt',
  847. 'command': 'meta',
  848. 'return': 'enter',
  849. 'escape': 'esc',
  850. 'plus': '+',
  851. 'mod': /Mac|iPod|iPhone|iPad/.test(navigator.platform) ? 'meta' : 'ctrl'
  852. };
  853. /**
  854. * variable to store the flipped version of _MAP from above
  855. * needed to check if we should use keypress or not when no action
  856. * is specified
  857. *
  858. * @type {Object|undefined}
  859. */
  860. var _REVERSE_MAP;
  861. /**
  862. * loop through the f keys, f1 to f19 and add them to the map
  863. * programatically
  864. */
  865. for (var i = 1; i < 20; ++i) {
  866. _MAP[111 + i] = 'f' + i;
  867. }
  868. /**
  869. * loop through to map numbers on the numeric keypad
  870. */
  871. for (i = 0; i <= 9; ++i) {
  872. // This needs to use a string cause otherwise since 0 is falsey
  873. // mousetrap will never fire for numpad 0 pressed as part of a keydown
  874. // event.
  875. //
  876. // @see https://github.com/ccampbell/mousetrap/pull/258
  877. _MAP[i + 96] = i.toString();
  878. }
  879. /**
  880. * cross browser add event method
  881. *
  882. * @param {Element|HTMLDocument} object
  883. * @param {string} type
  884. * @param {Function} callback
  885. * @returns void
  886. */
  887. function _addEvent(object, type, callback) {
  888. if (object.addEventListener) {
  889. object.addEventListener(type, callback, false);
  890. return;
  891. }
  892. object.attachEvent('on' + type, callback);
  893. }
  894. /**
  895. * takes the event and returns the key character
  896. *
  897. * @param {Event} e
  898. * @return {string}
  899. */
  900. function _characterFromEvent(e) {
  901. // for keypress events we should return the character as is
  902. if (e.type == 'keypress') {
  903. var character = String.fromCharCode(e.which);
  904. // if the shift key is not pressed then it is safe to assume
  905. // that we want the character to be lowercase. this means if
  906. // you accidentally have caps lock on then your key bindings
  907. // will continue to work
  908. //
  909. // the only side effect that might not be desired is if you
  910. // bind something like 'A' cause you want to trigger an
  911. // event when capital A is pressed caps lock will no longer
  912. // trigger the event. shift+a will though.
  913. if (!e.shiftKey) {
  914. character = character.toLowerCase();
  915. }
  916. return character;
  917. }
  918. // for non keypress events the special maps are needed
  919. if (_MAP[e.which]) {
  920. return _MAP[e.which];
  921. }
  922. if (_KEYCODE_MAP[e.which]) {
  923. return _KEYCODE_MAP[e.which];
  924. }
  925. // if it is not in the special map
  926. // with keydown and keyup events the character seems to always
  927. // come in as an uppercase character whether you are pressing shift
  928. // or not. we should make sure it is always lowercase for comparisons
  929. return String.fromCharCode(e.which).toLowerCase();
  930. }
  931. /**
  932. * checks if two arrays are equal
  933. *
  934. * @param {Array} modifiers1
  935. * @param {Array} modifiers2
  936. * @returns {boolean}
  937. */
  938. function _modifiersMatch(modifiers1, modifiers2) {
  939. return modifiers1.sort().join(',') === modifiers2.sort().join(',');
  940. }
  941. /**
  942. * takes a key event and figures out what the modifiers are
  943. *
  944. * @param {Event} e
  945. * @returns {Array}
  946. */
  947. function _eventModifiers(e) {
  948. var modifiers = [];
  949. if (e.shiftKey) {
  950. modifiers.push('shift');
  951. }
  952. if (e.altKey) {
  953. modifiers.push('alt');
  954. }
  955. if (e.ctrlKey) {
  956. modifiers.push('ctrl');
  957. }
  958. if (e.metaKey) {
  959. modifiers.push('meta');
  960. }
  961. return modifiers;
  962. }
  963. /**
  964. * prevents default for this event
  965. *
  966. * @param {Event} e
  967. * @returns void
  968. */
  969. function _preventDefault(e) {
  970. if (e.preventDefault) {
  971. e.preventDefault();
  972. return;
  973. }
  974. e.returnValue = false;
  975. }
  976. /**
  977. * stops propogation for this event
  978. *
  979. * @param {Event} e
  980. * @returns void
  981. */
  982. function _stopPropagation(e) {
  983. if (e.stopPropagation) {
  984. e.stopPropagation();
  985. return;
  986. }
  987. e.cancelBubble = true;
  988. }
  989. /**
  990. * determines if the keycode specified is a modifier key or not
  991. *
  992. * @param {string} key
  993. * @returns {boolean}
  994. */
  995. function _isModifier(key) {
  996. return key == 'shift' || key == 'ctrl' || key == 'alt' || key == 'meta';
  997. }
  998. /**
  999. * reverses the map lookup so that we can look for specific keys
  1000. * to see what can and can't use keypress
  1001. *
  1002. * @return {Object}
  1003. */
  1004. function _getReverseMap() {
  1005. if (!_REVERSE_MAP) {
  1006. _REVERSE_MAP = {};
  1007. for (var key in _MAP) {
  1008. // pull out the numeric keypad from here cause keypress should
  1009. // be able to detect the keys from the character
  1010. if (key > 95 && key < 112) {
  1011. continue;
  1012. }
  1013. if (_MAP.hasOwnProperty(key)) {
  1014. _REVERSE_MAP[_MAP[key]] = key;
  1015. }
  1016. }
  1017. }
  1018. return _REVERSE_MAP;
  1019. }
  1020. /**
  1021. * picks the best action based on the key combination
  1022. *
  1023. * @param {string} key - character for key
  1024. * @param {Array} modifiers
  1025. * @param {string=} action passed in
  1026. */
  1027. function _pickBestAction(key, modifiers, action) {
  1028. // if no action was picked in we should try to pick the one
  1029. // that we think would work best for this key
  1030. if (!action) {
  1031. action = _getReverseMap()[key] ? 'keydown' : 'keypress';
  1032. }
  1033. // modifier keys don't work as expected with keypress,
  1034. // switch to keydown
  1035. if (action == 'keypress' && modifiers.length) {
  1036. action = 'keydown';
  1037. }
  1038. return action;
  1039. }
  1040. /**
  1041. * Converts from a string key combination to an array
  1042. *
  1043. * @param {string} combination like "command+shift+l"
  1044. * @return {Array}
  1045. */
  1046. function _keysFromString(combination) {
  1047. if (combination === '+') {
  1048. return ['+'];
  1049. }
  1050. combination = combination.replace(/\+{2}/g, '+plus');
  1051. return combination.split('+');
  1052. }
  1053. /**
  1054. * Gets info for a specific key combination
  1055. *
  1056. * @param {string} combination key combination ("command+s" or "a" or "*")
  1057. * @param {string=} action
  1058. * @returns {Object}
  1059. */
  1060. function _getKeyInfo(combination, action) {
  1061. var keys;
  1062. var key;
  1063. var i;
  1064. var modifiers = [];
  1065. // take the keys from this pattern and figure out what the actual
  1066. // pattern is all about
  1067. keys = _keysFromString(combination);
  1068. for (i = 0; i < keys.length; ++i) {
  1069. key = keys[i];
  1070. // normalize key names
  1071. if (_SPECIAL_ALIASES[key]) {
  1072. key = _SPECIAL_ALIASES[key];
  1073. }
  1074. // if this is not a keypress event then we should
  1075. // be smart about using shift keys
  1076. // this will only work for US keyboards however
  1077. if (action && action != 'keypress' && _SHIFT_MAP[key]) {
  1078. key = _SHIFT_MAP[key];
  1079. modifiers.push('shift');
  1080. }
  1081. // if this key is a modifier then add it to the list of modifiers
  1082. if (_isModifier(key)) {
  1083. modifiers.push(key);
  1084. }
  1085. }
  1086. // depending on what the key combination is
  1087. // we will try to pick the best event for it
  1088. action = _pickBestAction(key, modifiers, action);
  1089. return {
  1090. key: key,
  1091. modifiers: modifiers,
  1092. action: action
  1093. };
  1094. }
  1095. function _belongsTo(element, ancestor) {
  1096. if (element === null || element === document) {
  1097. return false;
  1098. }
  1099. if (element === ancestor) {
  1100. return true;
  1101. }
  1102. return _belongsTo(element.parentNode, ancestor);
  1103. }
  1104. function Mousetrap(targetElement) {
  1105. var self = this;
  1106. targetElement = targetElement || document;
  1107. if (!(self instanceof Mousetrap)) {
  1108. return new Mousetrap(targetElement);
  1109. }
  1110. /**
  1111. * element to attach key events to
  1112. *
  1113. * @type {Element}
  1114. */
  1115. self.target = targetElement;
  1116. /**
  1117. * a list of all the callbacks setup via Mousetrap.bind()
  1118. *
  1119. * @type {Object}
  1120. */
  1121. self._callbacks = {};
  1122. /**
  1123. * direct map of string combinations to callbacks used for trigger()
  1124. *
  1125. * @type {Object}
  1126. */
  1127. self._directMap = {};
  1128. /**
  1129. * keeps track of what level each sequence is at since multiple
  1130. * sequences can start out with the same sequence
  1131. *
  1132. * @type {Object}
  1133. */
  1134. var _sequenceLevels = {};
  1135. /**
  1136. * variable to store the setTimeout call
  1137. *
  1138. * @type {null|number}
  1139. */
  1140. var _resetTimer;
  1141. /**
  1142. * temporary state where we will ignore the next keyup
  1143. *
  1144. * @type {boolean|string}
  1145. */
  1146. var _ignoreNextKeyup = false;
  1147. /**
  1148. * temporary state where we will ignore the next keypress
  1149. *
  1150. * @type {boolean}
  1151. */
  1152. var _ignoreNextKeypress = false;
  1153. /**
  1154. * are we currently inside of a sequence?
  1155. * type of action ("keyup" or "keydown" or "keypress") or false
  1156. *
  1157. * @type {boolean|string}
  1158. */
  1159. var _nextExpectedAction = false;
  1160. /**
  1161. * resets all sequence counters except for the ones passed in
  1162. *
  1163. * @param {Object} doNotReset
  1164. * @returns void
  1165. */
  1166. function _resetSequences(doNotReset) {
  1167. doNotReset = doNotReset || {};
  1168. var activeSequences = false,
  1169. key;
  1170. for (key in _sequenceLevels) {
  1171. if (doNotReset[key]) {
  1172. activeSequences = true;
  1173. continue;
  1174. }
  1175. _sequenceLevels[key] = 0;
  1176. }
  1177. if (!activeSequences) {
  1178. _nextExpectedAction = false;
  1179. }
  1180. }
  1181. /**
  1182. * finds all callbacks that match based on the keycode, modifiers,
  1183. * and action
  1184. *
  1185. * @param {string} character
  1186. * @param {Array} modifiers
  1187. * @param {Event|Object} e
  1188. * @param {string=} sequenceName - name of the sequence we are looking for
  1189. * @param {string=} combination
  1190. * @param {number=} level
  1191. * @returns {Array}
  1192. */
  1193. function _getMatches(character, modifiers, e, sequenceName, combination, level) {
  1194. var i;
  1195. var callback;
  1196. var matches = [];
  1197. var action = e.type;
  1198. // if there are no events related to this keycode
  1199. if (!self._callbacks[character]) {
  1200. return [];
  1201. }
  1202. // if a modifier key is coming up on its own we should allow it
  1203. if (action == 'keyup' && _isModifier(character)) {
  1204. modifiers = [character];
  1205. }
  1206. // loop through all callbacks for the key that was pressed
  1207. // and see if any of them match
  1208. for (i = 0; i < self._callbacks[character].length; ++i) {
  1209. callback = self._callbacks[character][i];
  1210. // if a sequence name is not specified, but this is a sequence at
  1211. // the wrong level then move onto the next match
  1212. if (!sequenceName && callback.seq && _sequenceLevels[callback.seq] != callback.level) {
  1213. continue;
  1214. }
  1215. // if the action we are looking for doesn't match the action we got
  1216. // then we should keep going
  1217. if (action != callback.action) {
  1218. continue;
  1219. }
  1220. // if this is a keypress event and the meta key and control key
  1221. // are not pressed that means that we need to only look at the
  1222. // character, otherwise check the modifiers as well
  1223. //
  1224. // chrome will not fire a keypress if meta or control is down
  1225. // safari will fire a keypress if meta or meta+shift is down
  1226. // firefox will fire a keypress if meta or control is down
  1227. if ((action == 'keypress' && !e.metaKey && !e.ctrlKey) || _modifiersMatch(modifiers, callback.modifiers)) {
  1228. // when you bind a combination or sequence a second time it
  1229. // should overwrite the first one. if a sequenceName or
  1230. // combination is specified in this call it does just that
  1231. //
  1232. // @todo make deleting its own method?
  1233. var deleteCombo = !sequenceName && callback.combo == combination;
  1234. var deleteSequence = sequenceName && callback.seq == sequenceName && callback.level == level;
  1235. if (deleteCombo || deleteSequence) {
  1236. self._callbacks[character].splice(i, 1);
  1237. }
  1238. matches.push(callback);
  1239. }
  1240. }
  1241. return matches;
  1242. }
  1243. /**
  1244. * actually calls the callback function
  1245. *
  1246. * if your callback function returns false this will use the jquery
  1247. * convention - prevent default and stop propogation on the event
  1248. *
  1249. * @param {Function} callback
  1250. * @param {Event} e
  1251. * @returns void
  1252. */
  1253. function _fireCallback(callback, e, combo, sequence) {
  1254. // if this event should not happen stop here
  1255. if (self.stopCallback(e, e.target || e.srcElement, combo, sequence)) {
  1256. return;
  1257. }
  1258. if (callback(e, combo) === false) {
  1259. _preventDefault(e);
  1260. _stopPropagation(e);
  1261. }
  1262. }
  1263. /**
  1264. * handles a character key event
  1265. *
  1266. * @param {string} character
  1267. * @param {Array} modifiers
  1268. * @param {Event} e
  1269. * @returns void
  1270. */
  1271. self._handleKey = function(character, modifiers, e) {
  1272. var callbacks = _getMatches(character, modifiers, e);
  1273. var i;
  1274. var doNotReset = {};
  1275. var maxLevel = 0;
  1276. var processedSequenceCallback = false;
  1277. // Calculate the maxLevel for sequences so we can only execute the longest callback sequence
  1278. for (i = 0; i < callbacks.length; ++i) {
  1279. if (callbacks[i].seq) {
  1280. maxLevel = Math.max(maxLevel, callbacks[i].level);
  1281. }
  1282. }
  1283. // loop through matching callbacks for this key event
  1284. for (i = 0; i < callbacks.length; ++i) {
  1285. // fire for all sequence callbacks
  1286. // this is because if for example you have multiple sequences
  1287. // bound such as "g i" and "g t" they both need to fire the
  1288. // callback for matching g cause otherwise you can only ever
  1289. // match the first one
  1290. if (callbacks[i].seq) {
  1291. // only fire callbacks for the maxLevel to prevent
  1292. // subsequences from also firing
  1293. //
  1294. // for example 'a option b' should not cause 'option b' to fire
  1295. // even though 'option b' is part of the other sequence
  1296. //
  1297. // any sequences that do not match here will be discarded
  1298. // below by the _resetSequences call
  1299. if (callbacks[i].level != maxLevel) {
  1300. continue;
  1301. }
  1302. processedSequenceCallback = true;
  1303. // keep a list of which sequences were matches for later
  1304. doNotReset[callbacks[i].seq] = 1;
  1305. _fireCallback(callbacks[i].callback, e, callbacks[i].combo, callbacks[i].seq);
  1306. continue;
  1307. }
  1308. // if there were no sequence matches but we are still here
  1309. // that means this is a regular match so we should fire that
  1310. if (!processedSequenceCallback) {
  1311. _fireCallback(callbacks[i].callback, e, callbacks[i].combo);
  1312. }
  1313. }
  1314. // if the key you pressed matches the type of sequence without
  1315. // being a modifier (ie "keyup" or "keypress") then we should
  1316. // reset all sequences that were not matched by this event
  1317. //
  1318. // this is so, for example, if you have the sequence "h a t" and you
  1319. // type "h e a r t" it does not match. in this case the "e" will
  1320. // cause the sequence to reset
  1321. //
  1322. // modifier keys are ignored because you can have a sequence
  1323. // that contains modifiers such as "enter ctrl+space" and in most
  1324. // cases the modifier key will be pressed before the next key
  1325. //
  1326. // also if you have a sequence such as "ctrl+b a" then pressing the
  1327. // "b" key will trigger a "keypress" and a "keydown"
  1328. //
  1329. // the "keydown" is expected when there is a modifier, but the
  1330. // "keypress" ends up matching the _nextExpectedAction since it occurs
  1331. // after and that causes the sequence to reset
  1332. //
  1333. // we ignore keypresses in a sequence that directly follow a keydown
  1334. // for the same character
  1335. var ignoreThisKeypress = e.type == 'keypress' && _ignoreNextKeypress;
  1336. if (e.type == _nextExpectedAction && !_isModifier(character) && !ignoreThisKeypress) {
  1337. _resetSequences(doNotReset);
  1338. }
  1339. _ignoreNextKeypress = processedSequenceCallback && e.type == 'keydown';
  1340. };
  1341. /**
  1342. * handles a keydown event
  1343. *
  1344. * @param {Event} e
  1345. * @returns void
  1346. */
  1347. function _handleKeyEvent(e) {
  1348. // normalize e.which for key events
  1349. // @see http://stackoverflow.com/questions/4285627/javascript-keycode-vs-charcode-utter-confusion
  1350. if (typeof e.which !== 'number') {
  1351. e.which = e.keyCode;
  1352. }
  1353. var character = _characterFromEvent(e);
  1354. // no character found then stop
  1355. if (!character) {
  1356. return;
  1357. }
  1358. // need to use === for the character check because the character can be 0
  1359. if (e.type == 'keyup' && _ignoreNextKeyup === character) {
  1360. _ignoreNextKeyup = false;
  1361. return;
  1362. }
  1363. self.handleKey(character, _eventModifiers(e), e);
  1364. }
  1365. /**
  1366. * called to set a 1 second timeout on the specified sequence
  1367. *
  1368. * this is so after each key press in the sequence you have 1 second
  1369. * to press the next key before you have to start over
  1370. *
  1371. * @returns void
  1372. */
  1373. function _resetSequenceTimer() {
  1374. clearTimeout(_resetTimer);
  1375. _resetTimer = setTimeout(_resetSequences, 1000);
  1376. }
  1377. /**
  1378. * binds a key sequence to an event
  1379. *
  1380. * @param {string} combo - combo specified in bind call
  1381. * @param {Array} keys
  1382. * @param {Function} callback
  1383. * @param {string=} action
  1384. * @returns void
  1385. */
  1386. function _bindSequence(combo, keys, callback, action) {
  1387. // start off by adding a sequence level record for this combination
  1388. // and setting the level to 0
  1389. _sequenceLevels[combo] = 0;
  1390. /**
  1391. * callback to increase the sequence level for this sequence and reset
  1392. * all other sequences that were active
  1393. *
  1394. * @param {string} nextAction
  1395. * @returns {Function}
  1396. */
  1397. function _increaseSequence(nextAction) {
  1398. return function() {
  1399. _nextExpectedAction = nextAction;
  1400. ++_sequenceLevels[combo];
  1401. _resetSequenceTimer();
  1402. };
  1403. }
  1404. /**
  1405. * wraps the specified callback inside of another function in order
  1406. * to reset all sequence counters as soon as this sequence is done
  1407. *
  1408. * @param {Event} e
  1409. * @returns void
  1410. */
  1411. function _callbackAndReset(e) {
  1412. _fireCallback(callback, e, combo);
  1413. // we should ignore the next key up if the action is key down
  1414. // or keypress. this is so if you finish a sequence and
  1415. // release the key the final key will not trigger a keyup
  1416. if (action !== 'keyup') {
  1417. _ignoreNextKeyup = _characterFromEvent(e);
  1418. }
  1419. // weird race condition if a sequence ends with the key
  1420. // another sequence begins with
  1421. setTimeout(_resetSequences, 10);
  1422. }
  1423. // loop through keys one at a time and bind the appropriate callback
  1424. // function. for any key leading up to the final one it should
  1425. // increase the sequence. after the final, it should reset all sequences
  1426. //
  1427. // if an action is specified in the original bind call then that will
  1428. // be used throughout. otherwise we will pass the action that the
  1429. // next key in the sequence should match. this allows a sequence
  1430. // to mix and match keypress and keydown events depending on which
  1431. // ones are better suited to the key provided
  1432. for (var i = 0; i < keys.length; ++i) {
  1433. var isFinal = i + 1 === keys.length;
  1434. var wrappedCallback = isFinal ? _callbackAndReset : _increaseSequence(action || _getKeyInfo(keys[i + 1]).action);
  1435. _bindSingle(keys[i], wrappedCallback, action, combo, i);
  1436. }
  1437. }
  1438. /**
  1439. * binds a single keyboard combination
  1440. *
  1441. * @param {string} combination
  1442. * @param {Function} callback
  1443. * @param {string=} action
  1444. * @param {string=} sequenceName - name of sequence if part of sequence
  1445. * @param {number=} level - what part of the sequence the command is
  1446. * @returns void
  1447. */
  1448. function _bindSingle(combination, callback, action, sequenceName, level) {
  1449. // store a direct mapped reference for use with Mousetrap.trigger
  1450. self._directMap[combination + ':' + action] = callback;
  1451. // make sure multiple spaces in a row become a single space
  1452. combination = combination.replace(/\s+/g, ' ');
  1453. var sequence = combination.split(' ');
  1454. var info;
  1455. // if this pattern is a sequence of keys then run through this method
  1456. // to reprocess each pattern one key at a time
  1457. if (sequence.length > 1) {
  1458. _bindSequence(combination, sequence, callback, action);
  1459. return;
  1460. }
  1461. info = _getKeyInfo(combination, action);
  1462. // make sure to initialize array if this is the first time
  1463. // a callback is added for this key
  1464. self._callbacks[info.key] = self._callbacks[info.key] || [];
  1465. // remove an existing match if there is one
  1466. _getMatches(info.key, info.modifiers, {type: info.action}, sequenceName, combination, level);
  1467. // add this call back to the array
  1468. // if it is a sequence put it at the beginning
  1469. // if not put it at the end
  1470. //
  1471. // this is important because the way these are processed expects
  1472. // the sequence ones to come first
  1473. self._callbacks[info.key][sequenceName ? 'unshift' : 'push']({
  1474. callback: callback,
  1475. modifiers: info.modifiers,
  1476. action: info.action,
  1477. seq: sequenceName,
  1478. level: level,
  1479. combo: combination
  1480. });
  1481. }
  1482. /**
  1483. * binds multiple combinations to the same callback
  1484. *
  1485. * @param {Array} combinations
  1486. * @param {Function} callback
  1487. * @param {string|undefined} action
  1488. * @returns void
  1489. */
  1490. self._bindMultiple = function(combinations, callback, action) {
  1491. for (var i = 0; i < combinations.length; ++i) {
  1492. _bindSingle(combinations[i], callback, action);
  1493. }
  1494. };
  1495. // start!
  1496. _addEvent(targetElement, 'keypress', _handleKeyEvent);
  1497. _addEvent(targetElement, 'keydown', _handleKeyEvent);
  1498. _addEvent(targetElement, 'keyup', _handleKeyEvent);
  1499. }
  1500. /**
  1501. * binds an event to mousetrap
  1502. *
  1503. * can be a single key, a combination of keys separated with +,
  1504. * an array of keys, or a sequence of keys separated by spaces
  1505. *
  1506. * be sure to list the modifier keys first to make sure that the
  1507. * correct key ends up getting bound (the last key in the pattern)
  1508. *
  1509. * @param {string|Array} keys
  1510. * @param {Function} callback
  1511. * @param {string=} action - 'keypress', 'keydown', or 'keyup'
  1512. * @returns void
  1513. */
  1514. Mousetrap.prototype.bind = function(keys, callback, action) {
  1515. var self = this;
  1516. keys = keys instanceof Array ? keys : [keys];
  1517. self._bindMultiple.call(self, keys, callback, action);
  1518. return self;
  1519. };
  1520. /**
  1521. * unbinds an event to mousetrap
  1522. *
  1523. * the unbinding sets the callback function of the specified key combo
  1524. * to an empty function and deletes the corresponding key in the
  1525. * _directMap dict.
  1526. *
  1527. * TODO: actually remove this from the _callbacks dictionary instead
  1528. * of binding an empty function
  1529. *
  1530. * the keycombo+action has to be exactly the same as
  1531. * it was defined in the bind method
  1532. *
  1533. * @param {string|Array} keys
  1534. * @param {string} action
  1535. * @returns void
  1536. */
  1537. Mousetrap.prototype.unbind = function(keys, action) {
  1538. var self = this;
  1539. return self.bind.call(self, keys, function() {}, action);
  1540. };
  1541. /**
  1542. * triggers an event that has already been bound
  1543. *
  1544. * @param {string} keys
  1545. * @param {string=} action
  1546. * @returns void
  1547. */
  1548. Mousetrap.prototype.trigger = function(keys, action) {
  1549. var self = this;
  1550. if (self._directMap[keys + ':' + action]) {
  1551. self._directMap[keys + ':' + action]({}, keys);
  1552. }
  1553. return self;
  1554. };
  1555. /**
  1556. * resets the library back to its initial state. this is useful
  1557. * if you want to clear out the current keyboard shortcuts and bind
  1558. * new ones - for example if you switch to another page
  1559. *
  1560. * @returns void
  1561. */
  1562. Mousetrap.prototype.reset = function() {
  1563. var self = this;
  1564. self._callbacks = {};
  1565. self._directMap = {};
  1566. return self;
  1567. };
  1568. /**
  1569. * should we stop this event before firing off callbacks
  1570. *
  1571. * @param {Event} e
  1572. * @param {Element} element
  1573. * @return {boolean}
  1574. */
  1575. Mousetrap.prototype.stopCallback = function(e, element) {
  1576. var self = this;
  1577. // if the element has the class "mousetrap" then no need to stop
  1578. if ((' ' + element.className + ' ').indexOf(' mousetrap ') > -1) {
  1579. return false;
  1580. }
  1581. if (_belongsTo(element, self.target)) {
  1582. return false;
  1583. }
  1584. // Events originating from a shadow DOM are re-targetted and `e.target` is the shadow host,
  1585. // not the initial event target in the shadow tree. Note that not all events cross the
  1586. // shadow boundary.
  1587. // For shadow trees with `mode: 'open'`, the initial event target is the first element in
  1588. // the event’s composed path. For shadow trees with `mode: 'closed'`, the initial event
  1589. // target cannot be obtained.
  1590. if ('composedPath' in e && typeof e.composedPath === 'function') {
  1591. // For open shadow trees, update `element` so that the following check works.
  1592. var initialEventTarget = e.composedPath()[0];
  1593. if (initialEventTarget !== e.target) {
  1594. element = initialEventTarget;
  1595. }
  1596. }
  1597. // stop for input, select, and textarea
  1598. return element.tagName == 'INPUT' || element.tagName == 'SELECT' || element.tagName == 'TEXTAREA' || element.isContentEditable;
  1599. };
  1600. /**
  1601. * exposes _handleKey publicly so it can be overwritten by extensions
  1602. */
  1603. Mousetrap.prototype.handleKey = function() {
  1604. var self = this;
  1605. return self._handleKey.apply(self, arguments);
  1606. };
  1607. /**
  1608. * allow custom key mappings
  1609. */
  1610. Mousetrap.addKeycodes = function(object) {
  1611. for (var key in object) {
  1612. if (object.hasOwnProperty(key)) {
  1613. _MAP[key] = object[key];
  1614. }
  1615. }
  1616. _REVERSE_MAP = null;
  1617. };
  1618. /**
  1619. * Init the global mousetrap functions
  1620. *
  1621. * This method is needed to allow the global mousetrap functions to work
  1622. * now that mousetrap is a constructor function.
  1623. */
  1624. Mousetrap.init = function() {
  1625. var documentMousetrap = Mousetrap(document);
  1626. for (var method in documentMousetrap) {
  1627. if (method.charAt(0) !== '_') {
  1628. Mousetrap[method] = (function(method) {
  1629. return function() {
  1630. return documentMousetrap[method].apply(documentMousetrap, arguments);
  1631. };
  1632. } (method));
  1633. }
  1634. }
  1635. };
  1636. Mousetrap.init();
  1637. // expose mousetrap to the global object
  1638. window.Mousetrap = Mousetrap;
  1639. // expose as a common js module
  1640. if ( true && module.exports) {
  1641. module.exports = Mousetrap;
  1642. }
  1643. // expose mousetrap as an AMD module
  1644. if (true) {
  1645. !(__WEBPACK_AMD_DEFINE_RESULT__ = (function() {
  1646. return Mousetrap;
  1647. }).call(exports, __webpack_require__, exports, module),
  1648. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  1649. }
  1650. }) (typeof window !== 'undefined' ? window : null, typeof window !== 'undefined' ? document : null);
  1651. /***/ }),
  1652. /***/ 5538:
  1653. /***/ (function() {
  1654. /**
  1655. * adds a bindGlobal method to Mousetrap that allows you to
  1656. * bind specific keyboard shortcuts that will still work
  1657. * inside a text input field
  1658. *
  1659. * usage:
  1660. * Mousetrap.bindGlobal('ctrl+s', _saveChanges);
  1661. */
  1662. /* global Mousetrap:true */
  1663. (function(Mousetrap) {
  1664. if (! Mousetrap) {
  1665. return;
  1666. }
  1667. var _globalCallbacks = {};
  1668. var _originalStopCallback = Mousetrap.prototype.stopCallback;
  1669. Mousetrap.prototype.stopCallback = function(e, element, combo, sequence) {
  1670. var self = this;
  1671. if (self.paused) {
  1672. return true;
  1673. }
  1674. if (_globalCallbacks[combo] || _globalCallbacks[sequence]) {
  1675. return false;
  1676. }
  1677. return _originalStopCallback.call(self, e, element, combo);
  1678. };
  1679. Mousetrap.prototype.bindGlobal = function(keys, callback, action) {
  1680. var self = this;
  1681. self.bind(keys, callback, action);
  1682. if (keys instanceof Array) {
  1683. for (var i = 0; i < keys.length; i++) {
  1684. _globalCallbacks[keys[i]] = true;
  1685. }
  1686. return;
  1687. }
  1688. _globalCallbacks[keys] = true;
  1689. };
  1690. Mousetrap.init();
  1691. }) (typeof Mousetrap !== "undefined" ? Mousetrap : undefined);
  1692. /***/ }),
  1693. /***/ 235:
  1694. /***/ (function(module, __unused_webpack_exports, __webpack_require__) {
  1695. var e=__webpack_require__(9196),n={display:"block",opacity:0,position:"absolute",top:0,left:0,height:"100%",width:"100%",overflow:"hidden",pointerEvents:"none",zIndex:-1},t=function(t){var r=t.onResize,u=e.useRef();return function(n,t){var r=function(){return n.current&&n.current.contentDocument&&n.current.contentDocument.defaultView};function u(){t();var e=r();e&&e.addEventListener("resize",t)}e.useEffect((function(){return r()?u():n.current&&n.current.addEventListener&&n.current.addEventListener("load",u),function(){var e=r();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("resize",t)}}),[])}(u,(function(){return r(u)})),e.createElement("iframe",{style:n,src:"about:blank",ref:u,"aria-hidden":!0,tabIndex:-1,frameBorder:0})},r=function(e){return{width:null!=e?e.offsetWidth:null,height:null!=e?e.offsetHeight:null}};module.exports=function(n){void 0===n&&(n=r);var u=e.useState(n(null)),o=u[0],i=u[1],c=e.useCallback((function(e){return i(n(e.current))}),[n]);return[e.useMemo((function(){return e.createElement(t,{onResize:c})}),[c]),o]};
  1696. /***/ }),
  1697. /***/ 9196:
  1698. /***/ (function(module) {
  1699. "use strict";
  1700. module.exports = window["React"];
  1701. /***/ })
  1702. /******/ });
  1703. /************************************************************************/
  1704. /******/ // The module cache
  1705. /******/ var __webpack_module_cache__ = {};
  1706. /******/
  1707. /******/ // The require function
  1708. /******/ function __webpack_require__(moduleId) {
  1709. /******/ // Check if module is in cache
  1710. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  1711. /******/ if (cachedModule !== undefined) {
  1712. /******/ return cachedModule.exports;
  1713. /******/ }
  1714. /******/ // Create a new module (and put it into the cache)
  1715. /******/ var module = __webpack_module_cache__[moduleId] = {
  1716. /******/ // no module.id needed
  1717. /******/ // no module.loaded needed
  1718. /******/ exports: {}
  1719. /******/ };
  1720. /******/
  1721. /******/ // Execute the module function
  1722. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  1723. /******/
  1724. /******/ // Return the exports of the module
  1725. /******/ return module.exports;
  1726. /******/ }
  1727. /******/
  1728. /************************************************************************/
  1729. /******/ /* webpack/runtime/compat get default export */
  1730. /******/ !function() {
  1731. /******/ // getDefaultExport function for compatibility with non-harmony modules
  1732. /******/ __webpack_require__.n = function(module) {
  1733. /******/ var getter = module && module.__esModule ?
  1734. /******/ function() { return module['default']; } :
  1735. /******/ function() { return module; };
  1736. /******/ __webpack_require__.d(getter, { a: getter });
  1737. /******/ return getter;
  1738. /******/ };
  1739. /******/ }();
  1740. /******/
  1741. /******/ /* webpack/runtime/define property getters */
  1742. /******/ !function() {
  1743. /******/ // define getter functions for harmony exports
  1744. /******/ __webpack_require__.d = function(exports, definition) {
  1745. /******/ for(var key in definition) {
  1746. /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
  1747. /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
  1748. /******/ }
  1749. /******/ }
  1750. /******/ };
  1751. /******/ }();
  1752. /******/
  1753. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  1754. /******/ !function() {
  1755. /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
  1756. /******/ }();
  1757. /******/
  1758. /******/ /* webpack/runtime/make namespace object */
  1759. /******/ !function() {
  1760. /******/ // define __esModule on exports
  1761. /******/ __webpack_require__.r = function(exports) {
  1762. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  1763. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  1764. /******/ }
  1765. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  1766. /******/ };
  1767. /******/ }();
  1768. /******/
  1769. /************************************************************************/
  1770. var __webpack_exports__ = {};
  1771. // This entry need to be wrapped in an IIFE because it need to be in strict mode.
  1772. !function() {
  1773. "use strict";
  1774. // ESM COMPAT FLAG
  1775. __webpack_require__.r(__webpack_exports__);
  1776. // EXPORTS
  1777. __webpack_require__.d(__webpack_exports__, {
  1778. "__experimentalUseDialog": function() { return /* reexport */ use_dialog; },
  1779. "__experimentalUseDisabled": function() { return /* reexport */ useDisabled; },
  1780. "__experimentalUseDragging": function() { return /* reexport */ useDragging; },
  1781. "__experimentalUseDropZone": function() { return /* reexport */ useDropZone; },
  1782. "__experimentalUseFixedWindowList": function() { return /* reexport */ useFixedWindowList; },
  1783. "__experimentalUseFocusOutside": function() { return /* reexport */ useFocusOutside; },
  1784. "compose": function() { return /* reexport */ compose; },
  1785. "createHigherOrderComponent": function() { return /* reexport */ create_higher_order_component; },
  1786. "ifCondition": function() { return /* reexport */ if_condition; },
  1787. "pure": function() { return /* reexport */ higher_order_pure; },
  1788. "useAsyncList": function() { return /* reexport */ use_async_list; },
  1789. "useConstrainedTabbing": function() { return /* reexport */ use_constrained_tabbing; },
  1790. "useCopyOnClick": function() { return /* reexport */ useCopyOnClick; },
  1791. "useCopyToClipboard": function() { return /* reexport */ useCopyToClipboard; },
  1792. "useDebounce": function() { return /* reexport */ useDebounce; },
  1793. "useFocusOnMount": function() { return /* reexport */ useFocusOnMount; },
  1794. "useFocusReturn": function() { return /* reexport */ use_focus_return; },
  1795. "useFocusableIframe": function() { return /* reexport */ useFocusableIframe; },
  1796. "useInstanceId": function() { return /* reexport */ useInstanceId; },
  1797. "useIsomorphicLayoutEffect": function() { return /* reexport */ use_isomorphic_layout_effect; },
  1798. "useKeyboardShortcut": function() { return /* reexport */ use_keyboard_shortcut; },
  1799. "useMediaQuery": function() { return /* reexport */ useMediaQuery; },
  1800. "useMergeRefs": function() { return /* reexport */ useMergeRefs; },
  1801. "usePrevious": function() { return /* reexport */ usePrevious; },
  1802. "useReducedMotion": function() { return /* reexport */ use_reduced_motion; },
  1803. "useRefEffect": function() { return /* reexport */ useRefEffect; },
  1804. "useResizeObserver": function() { return /* reexport */ use_resize_observer; },
  1805. "useThrottle": function() { return /* reexport */ useThrottle; },
  1806. "useViewportMatch": function() { return /* reexport */ use_viewport_match; },
  1807. "useWarnOnChange": function() { return /* reexport */ use_warn_on_change; },
  1808. "withGlobalEvents": function() { return /* reexport */ withGlobalEvents; },
  1809. "withInstanceId": function() { return /* reexport */ with_instance_id; },
  1810. "withSafeTimeout": function() { return /* reexport */ with_safe_timeout; },
  1811. "withState": function() { return /* reexport */ withState; }
  1812. });
  1813. ;// CONCATENATED MODULE: external "lodash"
  1814. var external_lodash_namespaceObject = window["lodash"];
  1815. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/utils/create-higher-order-component/index.js
  1816. /**
  1817. * External dependencies
  1818. */
  1819. /**
  1820. * Given a function mapping a component to an enhanced component and modifier
  1821. * name, returns the enhanced component augmented with a generated displayName.
  1822. *
  1823. * @param mapComponent Function mapping component to enhanced component.
  1824. * @param modifierName Seed name from which to generated display name.
  1825. *
  1826. * @return Component class with generated display name assigned.
  1827. */
  1828. function createHigherOrderComponent(mapComponent, modifierName) {
  1829. return Inner => {
  1830. const Outer = mapComponent(Inner);
  1831. const displayName = Inner.displayName || Inner.name || 'Component';
  1832. Outer.displayName = `${(0,external_lodash_namespaceObject.upperFirst)((0,external_lodash_namespaceObject.camelCase)(modifierName))}(${displayName})`;
  1833. return Outer;
  1834. };
  1835. }
  1836. /* harmony default export */ var create_higher_order_component = (createHigherOrderComponent);
  1837. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/compose.js
  1838. /**
  1839. * External dependencies
  1840. */
  1841. /**
  1842. * Composes multiple higher-order components into a single higher-order component. Performs right-to-left function
  1843. * composition, where each successive invocation is supplied the return value of the previous.
  1844. *
  1845. * This is just a re-export of `lodash`'s `flowRight` function.
  1846. *
  1847. * @see https://docs-lodash.com/v4/flow-right/
  1848. */
  1849. /* harmony default export */ var compose = (external_lodash_namespaceObject.flowRight);
  1850. ;// CONCATENATED MODULE: external ["wp","element"]
  1851. var external_wp_element_namespaceObject = window["wp"]["element"];
  1852. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/if-condition/index.js
  1853. /**
  1854. * Internal dependencies
  1855. */
  1856. /**
  1857. * Higher-order component creator, creating a new component which renders if
  1858. * the given condition is satisfied or with the given optional prop name.
  1859. *
  1860. * @example
  1861. * ```ts
  1862. * type Props = { foo: string };
  1863. * const Component = ( props: Props ) => <div>{ props.foo }</div>;
  1864. * const ConditionalComponent = ifCondition( ( props: Props ) => props.foo.length !== 0 )( Component );
  1865. * <ConditionalComponent foo="" />; // => null
  1866. * <ConditionalComponent foo="bar" />; // => <div>bar</div>;
  1867. * ```
  1868. *
  1869. * @param predicate Function to test condition.
  1870. *
  1871. * @return Higher-order component.
  1872. */
  1873. const ifCondition = predicate => create_higher_order_component(WrappedComponent => props => {
  1874. if (!predicate(props)) {
  1875. return null;
  1876. }
  1877. return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, props);
  1878. }, 'ifCondition');
  1879. /* harmony default export */ var if_condition = (ifCondition);
  1880. ;// CONCATENATED MODULE: external ["wp","isShallowEqual"]
  1881. var external_wp_isShallowEqual_namespaceObject = window["wp"]["isShallowEqual"];
  1882. var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_namespaceObject);
  1883. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/pure/index.js
  1884. /**
  1885. * WordPress dependencies
  1886. */
  1887. /**
  1888. * Internal dependencies
  1889. */
  1890. /**
  1891. * External dependencies
  1892. */
  1893. /**
  1894. * Given a component returns the enhanced component augmented with a component
  1895. * only re-rendering when its props/state change
  1896. */
  1897. const pure = create_higher_order_component(Wrapped => {
  1898. if (Wrapped.prototype instanceof external_wp_element_namespaceObject.Component) {
  1899. return class extends Wrapped {
  1900. shouldComponentUpdate(nextProps, nextState) {
  1901. return !external_wp_isShallowEqual_default()(nextProps, this.props) || !external_wp_isShallowEqual_default()(nextState, this.state);
  1902. }
  1903. };
  1904. }
  1905. return class extends external_wp_element_namespaceObject.Component {
  1906. shouldComponentUpdate(nextProps) {
  1907. return !external_wp_isShallowEqual_default()(nextProps, this.props);
  1908. }
  1909. render() {
  1910. return (0,external_wp_element_namespaceObject.createElement)(Wrapped, this.props);
  1911. }
  1912. };
  1913. }, 'pure');
  1914. /* harmony default export */ var higher_order_pure = (pure);
  1915. ;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
  1916. function _extends() {
  1917. _extends = Object.assign || function (target) {
  1918. for (var i = 1; i < arguments.length; i++) {
  1919. var source = arguments[i];
  1920. for (var key in source) {
  1921. if (Object.prototype.hasOwnProperty.call(source, key)) {
  1922. target[key] = source[key];
  1923. }
  1924. }
  1925. }
  1926. return target;
  1927. };
  1928. return _extends.apply(this, arguments);
  1929. }
  1930. ;// CONCATENATED MODULE: external ["wp","deprecated"]
  1931. var external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
  1932. var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject);
  1933. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/listener.js
  1934. /**
  1935. * External dependencies
  1936. */
  1937. /**
  1938. * Class responsible for orchestrating event handling on the global window,
  1939. * binding a single event to be shared across all handling instances, and
  1940. * removing the handler when no instances are listening for the event.
  1941. */
  1942. class Listener {
  1943. constructor() {
  1944. /** @type {any} */
  1945. this.listeners = {};
  1946. this.handleEvent = this.handleEvent.bind(this);
  1947. }
  1948. add(
  1949. /** @type {any} */
  1950. eventType,
  1951. /** @type {any} */
  1952. instance) {
  1953. if (!this.listeners[eventType]) {
  1954. // Adding first listener for this type, so bind event.
  1955. window.addEventListener(eventType, this.handleEvent);
  1956. this.listeners[eventType] = [];
  1957. }
  1958. this.listeners[eventType].push(instance);
  1959. }
  1960. remove(
  1961. /** @type {any} */
  1962. eventType,
  1963. /** @type {any} */
  1964. instance) {
  1965. this.listeners[eventType] = (0,external_lodash_namespaceObject.without)(this.listeners[eventType], instance);
  1966. if (!this.listeners[eventType].length) {
  1967. // Removing last listener for this type, so unbind event.
  1968. window.removeEventListener(eventType, this.handleEvent);
  1969. delete this.listeners[eventType];
  1970. }
  1971. }
  1972. handleEvent(
  1973. /** @type {any} */
  1974. event) {
  1975. (0,external_lodash_namespaceObject.forEach)(this.listeners[event.type], instance => {
  1976. instance.handleEvent(event);
  1977. });
  1978. }
  1979. }
  1980. /* harmony default export */ var listener = (Listener);
  1981. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-global-events/index.js
  1982. /**
  1983. * External dependencies
  1984. */
  1985. /**
  1986. * WordPress dependencies
  1987. */
  1988. /**
  1989. * Internal dependencies
  1990. */
  1991. /**
  1992. * Listener instance responsible for managing document event handling.
  1993. */
  1994. const with_global_events_listener = new listener();
  1995. /* eslint-disable jsdoc/no-undefined-types */
  1996. /**
  1997. * Higher-order component creator which, given an object of DOM event types and
  1998. * values corresponding to a callback function name on the component, will
  1999. * create or update a window event handler to invoke the callback when an event
  2000. * occurs. On behalf of the consuming developer, the higher-order component
  2001. * manages unbinding when the component unmounts, and binding at most a single
  2002. * event handler for the entire application.
  2003. *
  2004. * @deprecated
  2005. *
  2006. * @param {Record<keyof GlobalEventHandlersEventMap, string>} eventTypesToHandlers Object with keys of DOM
  2007. * event type, the value a
  2008. * name of the function on
  2009. * the original component's
  2010. * instance which handles
  2011. * the event.
  2012. *
  2013. * @return {any} Higher-order component.
  2014. */
  2015. function withGlobalEvents(eventTypesToHandlers) {
  2016. external_wp_deprecated_default()('wp.compose.withGlobalEvents', {
  2017. since: '5.7',
  2018. alternative: 'useEffect'
  2019. }); // @ts-ignore We don't need to fix the type-related issues because this is deprecated.
  2020. return create_higher_order_component(WrappedComponent => {
  2021. class Wrapper extends external_wp_element_namespaceObject.Component {
  2022. constructor(
  2023. /** @type {any} */
  2024. props) {
  2025. super(props);
  2026. this.handleEvent = this.handleEvent.bind(this);
  2027. this.handleRef = this.handleRef.bind(this);
  2028. }
  2029. componentDidMount() {
  2030. (0,external_lodash_namespaceObject.forEach)(eventTypesToHandlers, (_, eventType) => {
  2031. with_global_events_listener.add(eventType, this);
  2032. });
  2033. }
  2034. componentWillUnmount() {
  2035. (0,external_lodash_namespaceObject.forEach)(eventTypesToHandlers, (_, eventType) => {
  2036. with_global_events_listener.remove(eventType, this);
  2037. });
  2038. }
  2039. handleEvent(
  2040. /** @type {any} */
  2041. event) {
  2042. const handler = eventTypesToHandlers[
  2043. /** @type {keyof GlobalEventHandlersEventMap} */
  2044. event.type
  2045. /* eslint-enable jsdoc/no-undefined-types */
  2046. ];
  2047. if (typeof this.wrappedRef[handler] === 'function') {
  2048. this.wrappedRef[handler](event);
  2049. }
  2050. }
  2051. handleRef(
  2052. /** @type {any} */
  2053. el) {
  2054. this.wrappedRef = el; // Any component using `withGlobalEvents` that is not setting a `ref`
  2055. // will cause `this.props.forwardedRef` to be `null`, so we need this
  2056. // check.
  2057. if (this.props.forwardedRef) {
  2058. this.props.forwardedRef(el);
  2059. }
  2060. }
  2061. render() {
  2062. return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, _extends({}, this.props.ownProps, {
  2063. ref: this.handleRef
  2064. }));
  2065. }
  2066. }
  2067. return (0,external_wp_element_namespaceObject.forwardRef)((props, ref) => {
  2068. return (0,external_wp_element_namespaceObject.createElement)(Wrapper, {
  2069. ownProps: props,
  2070. forwardedRef: ref
  2071. });
  2072. });
  2073. }, 'withGlobalEvents');
  2074. }
  2075. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-instance-id/index.js
  2076. // Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case
  2077. // but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript
  2078. /* eslint-disable jsdoc/check-types */
  2079. /**
  2080. * WordPress dependencies
  2081. */
  2082. /**
  2083. * @type {WeakMap<object, number>}
  2084. */
  2085. const instanceMap = new WeakMap();
  2086. /**
  2087. * Creates a new id for a given object.
  2088. *
  2089. * @param {object} object Object reference to create an id for.
  2090. * @return {number} The instance id (index).
  2091. */
  2092. function createId(object) {
  2093. const instances = instanceMap.get(object) || 0;
  2094. instanceMap.set(object, instances + 1);
  2095. return instances;
  2096. }
  2097. /**
  2098. * Provides a unique instance ID.
  2099. *
  2100. * @param {object} object Object reference to create an id for.
  2101. * @param {string} [prefix] Prefix for the unique id.
  2102. * @param {string | number} [preferredId=''] Default ID to use.
  2103. * @return {string | number} The unique instance id.
  2104. */
  2105. function useInstanceId(object, prefix) {
  2106. let preferredId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
  2107. return (0,external_wp_element_namespaceObject.useMemo)(() => {
  2108. if (preferredId) return preferredId;
  2109. const id = createId(object);
  2110. return prefix ? `${prefix}-${id}` : id;
  2111. }, [object]);
  2112. }
  2113. /* eslint-enable jsdoc/check-types */
  2114. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-instance-id/index.js
  2115. /**
  2116. * Internal dependencies
  2117. */
  2118. /**
  2119. * A Higher Order Component used to be provide a unique instance ID by
  2120. * component.
  2121. */
  2122. const withInstanceId = create_higher_order_component(WrappedComponent => {
  2123. return props => {
  2124. const instanceId = useInstanceId(WrappedComponent); // @ts-ignore
  2125. return (0,external_wp_element_namespaceObject.createElement)(WrappedComponent, _extends({}, props, {
  2126. instanceId: instanceId
  2127. }));
  2128. };
  2129. }, 'withInstanceId');
  2130. /* harmony default export */ var with_instance_id = (withInstanceId);
  2131. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-safe-timeout/index.js
  2132. /**
  2133. * External dependencies
  2134. */
  2135. /**
  2136. * WordPress dependencies
  2137. */
  2138. /**
  2139. * Internal dependencies
  2140. */
  2141. /**
  2142. * We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`
  2143. * types here because those functions include functionality that is not handled
  2144. * by this component, like the ability to pass extra arguments.
  2145. *
  2146. * In the case of this component, we only handle the simplest case where
  2147. * `setTimeout` only accepts a function (not a string) and an optional delay.
  2148. */
  2149. /**
  2150. * A higher-order component used to provide and manage delayed function calls
  2151. * that ought to be bound to a component's lifecycle.
  2152. */
  2153. const withSafeTimeout = create_higher_order_component(OriginalComponent => {
  2154. return class WrappedComponent extends external_wp_element_namespaceObject.Component {
  2155. constructor(props) {
  2156. super(props);
  2157. this.timeouts = [];
  2158. this.setTimeout = this.setTimeout.bind(this);
  2159. this.clearTimeout = this.clearTimeout.bind(this);
  2160. }
  2161. componentWillUnmount() {
  2162. this.timeouts.forEach(clearTimeout);
  2163. }
  2164. setTimeout(fn, delay) {
  2165. const id = setTimeout(() => {
  2166. fn();
  2167. this.clearTimeout(id);
  2168. }, delay);
  2169. this.timeouts.push(id);
  2170. return id;
  2171. }
  2172. clearTimeout(id) {
  2173. clearTimeout(id);
  2174. this.timeouts = (0,external_lodash_namespaceObject.without)(this.timeouts, id);
  2175. }
  2176. render() {
  2177. const props = { ...this.props,
  2178. setTimeout: this.setTimeout,
  2179. clearTimeout: this.clearTimeout
  2180. };
  2181. return (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, props);
  2182. }
  2183. };
  2184. }, 'withSafeTimeout');
  2185. /* harmony default export */ var with_safe_timeout = (withSafeTimeout);
  2186. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/higher-order/with-state/index.js
  2187. /**
  2188. * WordPress dependencies
  2189. */
  2190. /**
  2191. * Internal dependencies
  2192. */
  2193. /**
  2194. * A Higher Order Component used to provide and manage internal component state
  2195. * via props.
  2196. *
  2197. * @deprecated Use `useState` instead.
  2198. *
  2199. * @param {any} initialState Optional initial state of the component.
  2200. *
  2201. * @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props.
  2202. */
  2203. function withState() {
  2204. let initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  2205. external_wp_deprecated_default()('wp.compose.withState', {
  2206. since: '5.8',
  2207. alternative: 'wp.element.useState'
  2208. });
  2209. return create_higher_order_component(OriginalComponent => {
  2210. return class WrappedComponent extends external_wp_element_namespaceObject.Component {
  2211. constructor(
  2212. /** @type {any} */
  2213. props) {
  2214. super(props);
  2215. this.setState = this.setState.bind(this);
  2216. this.state = initialState;
  2217. }
  2218. render() {
  2219. return (0,external_wp_element_namespaceObject.createElement)(OriginalComponent, _extends({}, this.props, this.state, {
  2220. setState: this.setState
  2221. }));
  2222. }
  2223. };
  2224. }, 'withState');
  2225. }
  2226. ;// CONCATENATED MODULE: external ["wp","keycodes"]
  2227. var external_wp_keycodes_namespaceObject = window["wp"]["keycodes"];
  2228. ;// CONCATENATED MODULE: external ["wp","dom"]
  2229. var external_wp_dom_namespaceObject = window["wp"]["dom"];
  2230. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-ref-effect/index.js
  2231. /**
  2232. * External dependencies
  2233. */
  2234. /**
  2235. * WordPress dependencies
  2236. */
  2237. /**
  2238. * Effect-like ref callback. Just like with `useEffect`, this allows you to
  2239. * return a cleanup function to be run if the ref changes or one of the
  2240. * dependencies changes. The ref is provided as an argument to the callback
  2241. * functions. The main difference between this and `useEffect` is that
  2242. * the `useEffect` callback is not called when the ref changes, but this is.
  2243. * Pass the returned ref callback as the component's ref and merge multiple refs
  2244. * with `useMergeRefs`.
  2245. *
  2246. * It's worth noting that if the dependencies array is empty, there's not
  2247. * strictly a need to clean up event handlers for example, because the node is
  2248. * to be removed. It *is* necessary if you add dependencies because the ref
  2249. * callback will be called multiple times for the same node.
  2250. *
  2251. * @param callback Callback with ref as argument.
  2252. * @param dependencies Dependencies of the callback.
  2253. *
  2254. * @return Ref callback.
  2255. */
  2256. function useRefEffect(callback, dependencies) {
  2257. const cleanup = (0,external_wp_element_namespaceObject.useRef)();
  2258. return (0,external_wp_element_namespaceObject.useCallback)(node => {
  2259. if (node) {
  2260. cleanup.current = callback(node);
  2261. } else if (cleanup.current) {
  2262. cleanup.current();
  2263. }
  2264. }, dependencies);
  2265. }
  2266. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-constrained-tabbing/index.js
  2267. /**
  2268. * WordPress dependencies
  2269. */
  2270. /**
  2271. * Internal dependencies
  2272. */
  2273. /**
  2274. * In Dialogs/modals, the tabbing must be constrained to the content of
  2275. * the wrapper element. This hook adds the behavior to the returned ref.
  2276. *
  2277. * @return {import('react').RefCallback<Element>} Element Ref.
  2278. *
  2279. * @example
  2280. * ```js
  2281. * import { useConstrainedTabbing } from '@wordpress/compose';
  2282. *
  2283. * const ConstrainedTabbingExample = () => {
  2284. * const constrainedTabbingRef = useConstrainedTabbing()
  2285. * return (
  2286. * <div ref={ constrainedTabbingRef }>
  2287. * <Button />
  2288. * <Button />
  2289. * </div>
  2290. * );
  2291. * }
  2292. * ```
  2293. */
  2294. function useConstrainedTabbing() {
  2295. return useRefEffect((
  2296. /** @type {HTMLElement} */
  2297. node) => {
  2298. /** @type {number|undefined} */
  2299. let timeoutId;
  2300. function onKeyDown(
  2301. /** @type {KeyboardEvent} */
  2302. event) {
  2303. const {
  2304. keyCode,
  2305. shiftKey,
  2306. target
  2307. } = event;
  2308. if (keyCode !== external_wp_keycodes_namespaceObject.TAB) {
  2309. return;
  2310. }
  2311. const action = shiftKey ? 'findPrevious' : 'findNext';
  2312. const nextElement = external_wp_dom_namespaceObject.focus.tabbable[action](
  2313. /** @type {HTMLElement} */
  2314. target) || null; // If the element that is about to receive focus is outside the
  2315. // area, move focus to a div and insert it at the start or end of
  2316. // the area, depending on the direction. Without preventing default
  2317. // behaviour, the browser will then move focus to the next element.
  2318. if (node.contains(nextElement)) {
  2319. return;
  2320. }
  2321. const domAction = shiftKey ? 'append' : 'prepend';
  2322. const {
  2323. ownerDocument
  2324. } = node;
  2325. const trap = ownerDocument.createElement('div');
  2326. trap.tabIndex = -1;
  2327. node[domAction](trap);
  2328. trap.focus(); // Remove after the browser moves focus to the next element.
  2329. timeoutId = setTimeout(() => node.removeChild(trap));
  2330. }
  2331. node.addEventListener('keydown', onKeyDown);
  2332. return () => {
  2333. node.removeEventListener('keydown', onKeyDown);
  2334. clearTimeout(timeoutId);
  2335. };
  2336. }, []);
  2337. }
  2338. /* harmony default export */ var use_constrained_tabbing = (useConstrainedTabbing);
  2339. // EXTERNAL MODULE: ./node_modules/clipboard/dist/clipboard.js
  2340. var dist_clipboard = __webpack_require__(8294);
  2341. var clipboard_default = /*#__PURE__*/__webpack_require__.n(dist_clipboard);
  2342. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-copy-on-click/index.js
  2343. /**
  2344. * External dependencies
  2345. */
  2346. /**
  2347. * WordPress dependencies
  2348. */
  2349. /* eslint-disable jsdoc/no-undefined-types */
  2350. /**
  2351. * Copies the text to the clipboard when the element is clicked.
  2352. *
  2353. * @deprecated
  2354. *
  2355. * @param {import('react').RefObject<string | Element | NodeListOf<Element>>} ref Reference with the element.
  2356. * @param {string|Function} text The text to copy.
  2357. * @param {number} [timeout] Optional timeout to reset the returned
  2358. * state. 4 seconds by default.
  2359. *
  2360. * @return {boolean} Whether or not the text has been copied. Resets after the
  2361. * timeout.
  2362. */
  2363. function useCopyOnClick(ref, text) {
  2364. let timeout = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 4000;
  2365. /* eslint-enable jsdoc/no-undefined-types */
  2366. external_wp_deprecated_default()('wp.compose.useCopyOnClick', {
  2367. since: '5.8',
  2368. alternative: 'wp.compose.useCopyToClipboard'
  2369. });
  2370. /** @type {import('react').MutableRefObject<Clipboard | undefined>} */
  2371. const clipboard = (0,external_wp_element_namespaceObject.useRef)();
  2372. const [hasCopied, setHasCopied] = (0,external_wp_element_namespaceObject.useState)(false);
  2373. (0,external_wp_element_namespaceObject.useEffect)(() => {
  2374. /** @type {number | undefined} */
  2375. let timeoutId;
  2376. if (!ref.current) {
  2377. return;
  2378. } // Clipboard listens to click events.
  2379. clipboard.current = new (clipboard_default())(ref.current, {
  2380. text: () => typeof text === 'function' ? text() : text
  2381. });
  2382. clipboard.current.on('success', _ref => {
  2383. let {
  2384. clearSelection,
  2385. trigger
  2386. } = _ref;
  2387. // Clearing selection will move focus back to the triggering button,
  2388. // ensuring that it is not reset to the body, and further that it is
  2389. // kept within the rendered node.
  2390. clearSelection(); // Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680
  2391. if (trigger) {
  2392. /** @type {HTMLElement} */
  2393. trigger.focus();
  2394. }
  2395. if (timeout) {
  2396. setHasCopied(true);
  2397. clearTimeout(timeoutId);
  2398. timeoutId = setTimeout(() => setHasCopied(false), timeout);
  2399. }
  2400. });
  2401. return () => {
  2402. if (clipboard.current) {
  2403. clipboard.current.destroy();
  2404. }
  2405. clearTimeout(timeoutId);
  2406. };
  2407. }, [text, timeout, setHasCopied]);
  2408. return hasCopied;
  2409. }
  2410. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-copy-to-clipboard/index.js
  2411. /**
  2412. * External dependencies
  2413. */
  2414. /**
  2415. * WordPress dependencies
  2416. */
  2417. /**
  2418. * Internal dependencies
  2419. */
  2420. /**
  2421. * @template T
  2422. * @param {T} value
  2423. * @return {import('react').RefObject<T>} The updated ref
  2424. */
  2425. function useUpdatedRef(value) {
  2426. const ref = (0,external_wp_element_namespaceObject.useRef)(value);
  2427. ref.current = value;
  2428. return ref;
  2429. }
  2430. /**
  2431. * Copies the given text to the clipboard when the element is clicked.
  2432. *
  2433. * @template {HTMLElement} TElementType
  2434. * @param {string | (() => string)} text The text to copy. Use a function if not
  2435. * already available and expensive to compute.
  2436. * @param {Function} onSuccess Called when to text is copied.
  2437. *
  2438. * @return {import('react').Ref<TElementType>} A ref to assign to the target element.
  2439. */
  2440. function useCopyToClipboard(text, onSuccess) {
  2441. // Store the dependencies as refs and continuesly update them so they're
  2442. // fresh when the callback is called.
  2443. const textRef = useUpdatedRef(text);
  2444. const onSuccessRef = useUpdatedRef(onSuccess);
  2445. return useRefEffect(node => {
  2446. // Clipboard listens to click events.
  2447. const clipboard = new (clipboard_default())(node, {
  2448. text() {
  2449. return typeof textRef.current === 'function' ? textRef.current() : textRef.current || '';
  2450. }
  2451. });
  2452. clipboard.on('success', _ref => {
  2453. let {
  2454. clearSelection
  2455. } = _ref;
  2456. // Clearing selection will move focus back to the triggering
  2457. // button, ensuring that it is not reset to the body, and
  2458. // further that it is kept within the rendered node.
  2459. clearSelection(); // Handle ClipboardJS focus bug, see
  2460. // https://github.com/zenorocha/clipboard.js/issues/680
  2461. node.focus();
  2462. if (onSuccessRef.current) {
  2463. onSuccessRef.current();
  2464. }
  2465. });
  2466. return () => {
  2467. clipboard.destroy();
  2468. };
  2469. }, []);
  2470. }
  2471. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-on-mount/index.js
  2472. /**
  2473. * WordPress dependencies
  2474. */
  2475. /**
  2476. * Hook used to focus the first tabbable element on mount.
  2477. *
  2478. * @param {boolean | 'firstElement'} focusOnMount Focus on mount mode.
  2479. * @return {import('react').RefCallback<HTMLElement>} Ref callback.
  2480. *
  2481. * @example
  2482. * ```js
  2483. * import { useFocusOnMount } from '@wordpress/compose';
  2484. *
  2485. * const WithFocusOnMount = () => {
  2486. * const ref = useFocusOnMount()
  2487. * return (
  2488. * <div ref={ ref }>
  2489. * <Button />
  2490. * <Button />
  2491. * </div>
  2492. * );
  2493. * }
  2494. * ```
  2495. */
  2496. function useFocusOnMount() {
  2497. let focusOnMount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'firstElement';
  2498. const focusOnMountRef = (0,external_wp_element_namespaceObject.useRef)(focusOnMount);
  2499. (0,external_wp_element_namespaceObject.useEffect)(() => {
  2500. focusOnMountRef.current = focusOnMount;
  2501. }, [focusOnMount]);
  2502. return (0,external_wp_element_namespaceObject.useCallback)(node => {
  2503. var _node$ownerDocument$a, _node$ownerDocument;
  2504. if (!node || focusOnMountRef.current === false) {
  2505. return;
  2506. }
  2507. if (node.contains((_node$ownerDocument$a = (_node$ownerDocument = node.ownerDocument) === null || _node$ownerDocument === void 0 ? void 0 : _node$ownerDocument.activeElement) !== null && _node$ownerDocument$a !== void 0 ? _node$ownerDocument$a : null)) {
  2508. return;
  2509. }
  2510. let target = node;
  2511. if (focusOnMountRef.current === 'firstElement') {
  2512. const firstTabbable = external_wp_dom_namespaceObject.focus.tabbable.find(node)[0];
  2513. if (firstTabbable) {
  2514. target =
  2515. /** @type {HTMLElement} */
  2516. firstTabbable;
  2517. }
  2518. }
  2519. target.focus();
  2520. }, []);
  2521. }
  2522. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-return/index.js
  2523. /**
  2524. * WordPress dependencies
  2525. */
  2526. /**
  2527. * When opening modals/sidebars/dialogs, the focus
  2528. * must move to the opened area and return to the
  2529. * previously focused element when closed.
  2530. * The current hook implements the returning behavior.
  2531. *
  2532. * @param {() => void} [onFocusReturn] Overrides the default return behavior.
  2533. * @return {import('react').RefCallback<HTMLElement>} Element Ref.
  2534. *
  2535. * @example
  2536. * ```js
  2537. * import { useFocusReturn } from '@wordpress/compose';
  2538. *
  2539. * const WithFocusReturn = () => {
  2540. * const ref = useFocusReturn()
  2541. * return (
  2542. * <div ref={ ref }>
  2543. * <Button />
  2544. * <Button />
  2545. * </div>
  2546. * );
  2547. * }
  2548. * ```
  2549. */
  2550. function useFocusReturn(onFocusReturn) {
  2551. /** @type {import('react').MutableRefObject<null | HTMLElement>} */
  2552. const ref = (0,external_wp_element_namespaceObject.useRef)(null);
  2553. /** @type {import('react').MutableRefObject<null | Element>} */
  2554. const focusedBeforeMount = (0,external_wp_element_namespaceObject.useRef)(null);
  2555. const onFocusReturnRef = (0,external_wp_element_namespaceObject.useRef)(onFocusReturn);
  2556. (0,external_wp_element_namespaceObject.useEffect)(() => {
  2557. onFocusReturnRef.current = onFocusReturn;
  2558. }, [onFocusReturn]);
  2559. return (0,external_wp_element_namespaceObject.useCallback)(node => {
  2560. if (node) {
  2561. // Set ref to be used when unmounting.
  2562. ref.current = node; // Only set when the node mounts.
  2563. if (focusedBeforeMount.current) {
  2564. return;
  2565. }
  2566. focusedBeforeMount.current = node.ownerDocument.activeElement;
  2567. } else if (focusedBeforeMount.current) {
  2568. var _ref$current, _ref$current2, _ref$current3;
  2569. const isFocused = (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.contains((_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.ownerDocument.activeElement);
  2570. if ((_ref$current3 = ref.current) !== null && _ref$current3 !== void 0 && _ref$current3.isConnected && !isFocused) {
  2571. return;
  2572. } // Defer to the component's own explicit focus return behavior, if
  2573. // specified. This allows for support that the `onFocusReturn`
  2574. // decides to allow the default behavior to occur under some
  2575. // conditions.
  2576. if (onFocusReturnRef.current) {
  2577. onFocusReturnRef.current();
  2578. } else {
  2579. var _focusedBeforeMount$c;
  2580. /** @type {null | HTMLElement} */
  2581. (_focusedBeforeMount$c = focusedBeforeMount.current) === null || _focusedBeforeMount$c === void 0 ? void 0 : _focusedBeforeMount$c.focus();
  2582. }
  2583. }
  2584. }, []);
  2585. }
  2586. /* harmony default export */ var use_focus_return = (useFocusReturn);
  2587. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focus-outside/index.js
  2588. /**
  2589. * External dependencies
  2590. */
  2591. /**
  2592. * WordPress dependencies
  2593. */
  2594. /**
  2595. * Input types which are classified as button types, for use in considering
  2596. * whether element is a (focus-normalized) button.
  2597. *
  2598. * @type {string[]}
  2599. */
  2600. const INPUT_BUTTON_TYPES = ['button', 'submit'];
  2601. /**
  2602. * @typedef {HTMLButtonElement | HTMLLinkElement | HTMLInputElement} FocusNormalizedButton
  2603. */
  2604. // Disable reason: Rule doesn't support predicate return types.
  2605. /* eslint-disable jsdoc/valid-types */
  2606. /**
  2607. * Returns true if the given element is a button element subject to focus
  2608. * normalization, or false otherwise.
  2609. *
  2610. * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
  2611. *
  2612. * @param {EventTarget} eventTarget The target from a mouse or touch event.
  2613. *
  2614. * @return {eventTarget is FocusNormalizedButton} Whether element is a button.
  2615. */
  2616. function isFocusNormalizedButton(eventTarget) {
  2617. if (!(eventTarget instanceof window.HTMLElement)) {
  2618. return false;
  2619. }
  2620. switch (eventTarget.nodeName) {
  2621. case 'A':
  2622. case 'BUTTON':
  2623. return true;
  2624. case 'INPUT':
  2625. return (0,external_lodash_namespaceObject.includes)(INPUT_BUTTON_TYPES,
  2626. /** @type {HTMLInputElement} */
  2627. eventTarget.type);
  2628. }
  2629. return false;
  2630. }
  2631. /* eslint-enable jsdoc/valid-types */
  2632. /**
  2633. * @typedef {import('react').SyntheticEvent} SyntheticEvent
  2634. */
  2635. /**
  2636. * @callback EventCallback
  2637. * @param {SyntheticEvent} event input related event.
  2638. */
  2639. /**
  2640. * @typedef FocusOutsideReactElement
  2641. * @property {EventCallback} handleFocusOutside callback for a focus outside event.
  2642. */
  2643. /**
  2644. * @typedef {import('react').MutableRefObject<FocusOutsideReactElement | undefined>} FocusOutsideRef
  2645. */
  2646. /**
  2647. * @typedef {Object} FocusOutsideReturnValue
  2648. * @property {EventCallback} onFocus An event handler for focus events.
  2649. * @property {EventCallback} onBlur An event handler for blur events.
  2650. * @property {EventCallback} onMouseDown An event handler for mouse down events.
  2651. * @property {EventCallback} onMouseUp An event handler for mouse up events.
  2652. * @property {EventCallback} onTouchStart An event handler for touch start events.
  2653. * @property {EventCallback} onTouchEnd An event handler for touch end events.
  2654. */
  2655. /**
  2656. * A react hook that can be used to check whether focus has moved outside the
  2657. * element the event handlers are bound to.
  2658. *
  2659. * @param {EventCallback} onFocusOutside A callback triggered when focus moves outside
  2660. * the element the event handlers are bound to.
  2661. *
  2662. * @return {FocusOutsideReturnValue} An object containing event handlers. Bind the event handlers
  2663. * to a wrapping element element to capture when focus moves
  2664. * outside that element.
  2665. */
  2666. function useFocusOutside(onFocusOutside) {
  2667. const currentOnFocusOutside = (0,external_wp_element_namespaceObject.useRef)(onFocusOutside);
  2668. (0,external_wp_element_namespaceObject.useEffect)(() => {
  2669. currentOnFocusOutside.current = onFocusOutside;
  2670. }, [onFocusOutside]);
  2671. const preventBlurCheck = (0,external_wp_element_namespaceObject.useRef)(false);
  2672. /**
  2673. * @type {import('react').MutableRefObject<number | undefined>}
  2674. */
  2675. const blurCheckTimeoutId = (0,external_wp_element_namespaceObject.useRef)();
  2676. /**
  2677. * Cancel a blur check timeout.
  2678. */
  2679. const cancelBlurCheck = (0,external_wp_element_namespaceObject.useCallback)(() => {
  2680. clearTimeout(blurCheckTimeoutId.current);
  2681. }, []); // Cancel blur checks on unmount.
  2682. (0,external_wp_element_namespaceObject.useEffect)(() => {
  2683. return () => cancelBlurCheck();
  2684. }, []); // Cancel a blur check if the callback or ref is no longer provided.
  2685. (0,external_wp_element_namespaceObject.useEffect)(() => {
  2686. if (!onFocusOutside) {
  2687. cancelBlurCheck();
  2688. }
  2689. }, [onFocusOutside, cancelBlurCheck]);
  2690. /**
  2691. * Handles a mousedown or mouseup event to respectively assign and
  2692. * unassign a flag for preventing blur check on button elements. Some
  2693. * browsers, namely Firefox and Safari, do not emit a focus event on
  2694. * button elements when clicked, while others do. The logic here
  2695. * intends to normalize this as treating click on buttons as focus.
  2696. *
  2697. * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus
  2698. *
  2699. * @param {SyntheticEvent} event Event for mousedown or mouseup.
  2700. */
  2701. const normalizeButtonFocus = (0,external_wp_element_namespaceObject.useCallback)(event => {
  2702. const {
  2703. type,
  2704. target
  2705. } = event;
  2706. const isInteractionEnd = (0,external_lodash_namespaceObject.includes)(['mouseup', 'touchend'], type);
  2707. if (isInteractionEnd) {
  2708. preventBlurCheck.current = false;
  2709. } else if (isFocusNormalizedButton(target)) {
  2710. preventBlurCheck.current = true;
  2711. }
  2712. }, []);
  2713. /**
  2714. * A callback triggered when a blur event occurs on the element the handler
  2715. * is bound to.
  2716. *
  2717. * Calls the `onFocusOutside` callback in an immediate timeout if focus has
  2718. * move outside the bound element and is still within the document.
  2719. *
  2720. * @param {SyntheticEvent} event Blur event.
  2721. */
  2722. const queueBlurCheck = (0,external_wp_element_namespaceObject.useCallback)(event => {
  2723. // React does not allow using an event reference asynchronously
  2724. // due to recycling behavior, except when explicitly persisted.
  2725. event.persist(); // Skip blur check if clicking button. See `normalizeButtonFocus`.
  2726. if (preventBlurCheck.current) {
  2727. return;
  2728. }
  2729. blurCheckTimeoutId.current = setTimeout(() => {
  2730. // If document is not focused then focus should remain
  2731. // inside the wrapped component and therefore we cancel
  2732. // this blur event thereby leaving focus in place.
  2733. // https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus.
  2734. if (!document.hasFocus()) {
  2735. event.preventDefault();
  2736. return;
  2737. }
  2738. if ('function' === typeof currentOnFocusOutside.current) {
  2739. currentOnFocusOutside.current(event);
  2740. }
  2741. }, 0);
  2742. }, []);
  2743. return {
  2744. onFocus: cancelBlurCheck,
  2745. onMouseDown: normalizeButtonFocus,
  2746. onMouseUp: normalizeButtonFocus,
  2747. onTouchStart: normalizeButtonFocus,
  2748. onTouchEnd: normalizeButtonFocus,
  2749. onBlur: queueBlurCheck
  2750. };
  2751. }
  2752. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-merge-refs/index.js
  2753. /**
  2754. * WordPress dependencies
  2755. */
  2756. /* eslint-disable jsdoc/valid-types */
  2757. /**
  2758. * @template T
  2759. * @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef
  2760. */
  2761. /* eslint-enable jsdoc/valid-types */
  2762. /**
  2763. * @template T
  2764. * @param {import('react').Ref<T>} ref
  2765. * @param {T} value
  2766. */
  2767. function assignRef(ref, value) {
  2768. if (typeof ref === 'function') {
  2769. ref(value);
  2770. } else if (ref && ref.hasOwnProperty('current')) {
  2771. /* eslint-disable jsdoc/no-undefined-types */
  2772. /** @type {import('react').MutableRefObject<T>} */
  2773. ref.current = value;
  2774. /* eslint-enable jsdoc/no-undefined-types */
  2775. }
  2776. }
  2777. /**
  2778. * Merges refs into one ref callback.
  2779. *
  2780. * It also ensures that the merged ref callbacks are only called when they
  2781. * change (as a result of a `useCallback` dependency update) OR when the ref
  2782. * value changes, just as React does when passing a single ref callback to the
  2783. * component.
  2784. *
  2785. * As expected, if you pass a new function on every render, the ref callback
  2786. * will be called after every render.
  2787. *
  2788. * If you don't wish a ref callback to be called after every render, wrap it
  2789. * with `useCallback( callback, dependencies )`. When a dependency changes, the
  2790. * old ref callback will be called with `null` and the new ref callback will be
  2791. * called with the same value.
  2792. *
  2793. * To make ref callbacks easier to use, you can also pass the result of
  2794. * `useRefEffect`, which makes cleanup easier by allowing you to return a
  2795. * cleanup function instead of handling `null`.
  2796. *
  2797. * It's also possible to _disable_ a ref (and its behaviour) by simply not
  2798. * passing the ref.
  2799. *
  2800. * ```jsx
  2801. * const ref = useRefEffect( ( node ) => {
  2802. * node.addEventListener( ... );
  2803. * return () => {
  2804. * node.removeEventListener( ... );
  2805. * };
  2806. * }, [ ...dependencies ] );
  2807. * const otherRef = useRef();
  2808. * const mergedRefs useMergeRefs( [
  2809. * enabled && ref,
  2810. * otherRef,
  2811. * ] );
  2812. * return <div ref={ mergedRefs } />;
  2813. * ```
  2814. *
  2815. * @template {import('react').Ref<any>} TRef
  2816. * @param {Array<TRef>} refs The refs to be merged.
  2817. *
  2818. * @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback.
  2819. */
  2820. function useMergeRefs(refs) {
  2821. const element = (0,external_wp_element_namespaceObject.useRef)();
  2822. const didElementChange = (0,external_wp_element_namespaceObject.useRef)(false);
  2823. /* eslint-disable jsdoc/no-undefined-types */
  2824. /** @type {import('react').MutableRefObject<TRef[]>} */
  2825. /* eslint-enable jsdoc/no-undefined-types */
  2826. const previousRefs = (0,external_wp_element_namespaceObject.useRef)([]);
  2827. const currentRefs = (0,external_wp_element_namespaceObject.useRef)(refs); // Update on render before the ref callback is called, so the ref callback
  2828. // always has access to the current refs.
  2829. currentRefs.current = refs; // If any of the refs change, call the previous ref with `null` and the new
  2830. // ref with the node, except when the element changes in the same cycle, in
  2831. // which case the ref callbacks will already have been called.
  2832. (0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
  2833. if (didElementChange.current === false) {
  2834. refs.forEach((ref, index) => {
  2835. const previousRef = previousRefs.current[index];
  2836. if (ref !== previousRef) {
  2837. assignRef(previousRef, null);
  2838. assignRef(ref, element.current);
  2839. }
  2840. });
  2841. }
  2842. previousRefs.current = refs;
  2843. }, refs); // No dependencies, must be reset after every render so ref callbacks are
  2844. // correctly called after a ref change.
  2845. (0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
  2846. didElementChange.current = false;
  2847. }); // There should be no dependencies so that `callback` is only called when
  2848. // the node changes.
  2849. return (0,external_wp_element_namespaceObject.useCallback)(value => {
  2850. // Update the element so it can be used when calling ref callbacks on a
  2851. // dependency change.
  2852. assignRef(element, value);
  2853. didElementChange.current = true; // When an element changes, the current ref callback should be called
  2854. // with the new element and the previous one with `null`.
  2855. const refsToAssign = value ? currentRefs.current : previousRefs.current; // Update the latest refs.
  2856. for (const ref of refsToAssign) {
  2857. assignRef(ref, value);
  2858. }
  2859. }, []);
  2860. }
  2861. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-dialog/index.js
  2862. /**
  2863. * WordPress dependencies
  2864. */
  2865. /**
  2866. * Internal dependencies
  2867. */
  2868. /* eslint-disable jsdoc/valid-types */
  2869. /**
  2870. * @typedef DialogOptions
  2871. * @property {Parameters<useFocusOnMount>[0]} focusOnMount Focus on mount arguments.
  2872. * @property {() => void} onClose Function to call when the dialog is closed.
  2873. */
  2874. /* eslint-enable jsdoc/valid-types */
  2875. /**
  2876. * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:
  2877. * - constrained tabbing.
  2878. * - focus on mount.
  2879. * - return focus on unmount.
  2880. * - focus outside.
  2881. *
  2882. * @param {DialogOptions} options Dialog Options.
  2883. */
  2884. function useDialog(options) {
  2885. /**
  2886. * @type {import('react').MutableRefObject<DialogOptions | undefined>}
  2887. */
  2888. const currentOptions = (0,external_wp_element_namespaceObject.useRef)();
  2889. (0,external_wp_element_namespaceObject.useEffect)(() => {
  2890. currentOptions.current = options;
  2891. }, Object.values(options));
  2892. const constrainedTabbingRef = use_constrained_tabbing();
  2893. const focusOnMountRef = useFocusOnMount(options.focusOnMount);
  2894. const focusReturnRef = use_focus_return();
  2895. const focusOutsideProps = useFocusOutside(event => {
  2896. var _currentOptions$curre, _currentOptions$curre2;
  2897. // This unstable prop is here only to manage backward compatibility
  2898. // for the Popover component otherwise, the onClose should be enough.
  2899. // @ts-ignore unstable property
  2900. if ((_currentOptions$curre = currentOptions.current) !== null && _currentOptions$curre !== void 0 && _currentOptions$curre.__unstableOnClose) {
  2901. // @ts-ignore unstable property
  2902. currentOptions.current.__unstableOnClose('focus-outside', event);
  2903. } else if ((_currentOptions$curre2 = currentOptions.current) !== null && _currentOptions$curre2 !== void 0 && _currentOptions$curre2.onClose) {
  2904. currentOptions.current.onClose();
  2905. }
  2906. });
  2907. const closeOnEscapeRef = (0,external_wp_element_namespaceObject.useCallback)(node => {
  2908. if (!node) {
  2909. return;
  2910. }
  2911. node.addEventListener('keydown', (
  2912. /** @type {KeyboardEvent} */
  2913. event) => {
  2914. var _currentOptions$curre3;
  2915. // Close on escape.
  2916. if (event.keyCode === external_wp_keycodes_namespaceObject.ESCAPE && !event.defaultPrevented && (_currentOptions$curre3 = currentOptions.current) !== null && _currentOptions$curre3 !== void 0 && _currentOptions$curre3.onClose) {
  2917. event.preventDefault();
  2918. currentOptions.current.onClose();
  2919. }
  2920. });
  2921. }, []);
  2922. return [useMergeRefs([options.focusOnMount !== false ? constrainedTabbingRef : null, options.focusOnMount !== false ? focusReturnRef : null, options.focusOnMount !== false ? focusOnMountRef : null, closeOnEscapeRef]), { ...focusOutsideProps,
  2923. tabIndex: '-1'
  2924. }];
  2925. }
  2926. /* harmony default export */ var use_dialog = (useDialog);
  2927. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-disabled/index.js
  2928. /**
  2929. * External dependencies
  2930. */
  2931. /**
  2932. * WordPress dependencies
  2933. */
  2934. /**
  2935. * Names of control nodes which qualify for disabled behavior.
  2936. *
  2937. * See WHATWG HTML Standard: 4.10.18.5: "Enabling and disabling form controls: the disabled attribute".
  2938. *
  2939. * @see https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#enabling-and-disabling-form-controls:-the-disabled-attribute
  2940. *
  2941. * @type {string[]}
  2942. */
  2943. const DISABLED_ELIGIBLE_NODE_NAMES = ['BUTTON', 'FIELDSET', 'INPUT', 'OPTGROUP', 'OPTION', 'SELECT', 'TEXTAREA'];
  2944. /**
  2945. * In some circumstances, such as block previews, all focusable DOM elements
  2946. * (input fields, links, buttons, etc.) need to be disabled. This hook adds the
  2947. * behavior to disable nested DOM elements to the returned ref.
  2948. *
  2949. * @return {import('react').RefObject<HTMLElement>} Element Ref.
  2950. *
  2951. * @example
  2952. * ```js
  2953. * import { __experimentalUseDisabled as useDisabled } from '@wordpress/compose';
  2954. * const DisabledExample = () => {
  2955. * const disabledRef = useDisabled();
  2956. * return (
  2957. * <div ref={ disabledRef }>
  2958. * <a href="#">This link will have tabindex set to -1</a>
  2959. * <input placeholder="This input will have the disabled attribute added to it." type="text" />
  2960. * </div>
  2961. * );
  2962. * };
  2963. * ```
  2964. */
  2965. function useDisabled() {
  2966. /** @type {import('react').RefObject<HTMLElement>} */
  2967. const node = (0,external_wp_element_namespaceObject.useRef)(null);
  2968. const disable = () => {
  2969. if (!node.current) {
  2970. return;
  2971. }
  2972. external_wp_dom_namespaceObject.focus.focusable.find(node.current).forEach(focusable => {
  2973. if ((0,external_lodash_namespaceObject.includes)(DISABLED_ELIGIBLE_NODE_NAMES, focusable.nodeName)) {
  2974. focusable.setAttribute('disabled', '');
  2975. }
  2976. if (focusable.nodeName === 'A') {
  2977. focusable.setAttribute('tabindex', '-1');
  2978. }
  2979. const tabIndex = focusable.getAttribute('tabindex');
  2980. if (tabIndex !== null && tabIndex !== '-1') {
  2981. focusable.removeAttribute('tabindex');
  2982. }
  2983. if (focusable.hasAttribute('contenteditable')) {
  2984. focusable.setAttribute('contenteditable', 'false');
  2985. }
  2986. });
  2987. }; // Debounce re-disable since disabling process itself will incur
  2988. // additional mutations which should be ignored.
  2989. const debouncedDisable = (0,external_wp_element_namespaceObject.useCallback)((0,external_lodash_namespaceObject.debounce)(disable, undefined, {
  2990. leading: true
  2991. }), []);
  2992. (0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
  2993. disable();
  2994. /** @type {MutationObserver | undefined} */
  2995. let observer;
  2996. if (node.current) {
  2997. observer = new window.MutationObserver(debouncedDisable);
  2998. observer.observe(node.current, {
  2999. childList: true,
  3000. attributes: true,
  3001. subtree: true
  3002. });
  3003. }
  3004. return () => {
  3005. if (observer) {
  3006. observer.disconnect();
  3007. }
  3008. debouncedDisable.cancel();
  3009. };
  3010. }, []);
  3011. return node;
  3012. }
  3013. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-isomorphic-layout-effect/index.js
  3014. /**
  3015. * WordPress dependencies
  3016. */
  3017. /**
  3018. * Preferred over direct usage of `useLayoutEffect` when supporting
  3019. * server rendered components (SSR) because currently React
  3020. * throws a warning when using useLayoutEffect in that environment.
  3021. */
  3022. const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? external_wp_element_namespaceObject.useLayoutEffect : external_wp_element_namespaceObject.useEffect;
  3023. /* harmony default export */ var use_isomorphic_layout_effect = (useIsomorphicLayoutEffect);
  3024. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-dragging/index.js
  3025. /**
  3026. * WordPress dependencies
  3027. */
  3028. /**
  3029. * Internal dependencies
  3030. */
  3031. /**
  3032. * @param {Object} props
  3033. * @param {(e: MouseEvent) => void} props.onDragStart
  3034. * @param {(e: MouseEvent) => void} props.onDragMove
  3035. * @param {(e: MouseEvent) => void} props.onDragEnd
  3036. */
  3037. function useDragging(_ref) {
  3038. let {
  3039. onDragStart,
  3040. onDragMove,
  3041. onDragEnd
  3042. } = _ref;
  3043. const [isDragging, setIsDragging] = (0,external_wp_element_namespaceObject.useState)(false);
  3044. const eventsRef = (0,external_wp_element_namespaceObject.useRef)({
  3045. onDragStart,
  3046. onDragMove,
  3047. onDragEnd
  3048. });
  3049. use_isomorphic_layout_effect(() => {
  3050. eventsRef.current.onDragStart = onDragStart;
  3051. eventsRef.current.onDragMove = onDragMove;
  3052. eventsRef.current.onDragEnd = onDragEnd;
  3053. }, [onDragStart, onDragMove, onDragEnd]);
  3054. const onMouseMove = (0,external_wp_element_namespaceObject.useCallback)((
  3055. /** @type {MouseEvent} */
  3056. event) => eventsRef.current.onDragMove && eventsRef.current.onDragMove(event), []);
  3057. const endDrag = (0,external_wp_element_namespaceObject.useCallback)((
  3058. /** @type {MouseEvent} */
  3059. event) => {
  3060. if (eventsRef.current.onDragEnd) {
  3061. eventsRef.current.onDragEnd(event);
  3062. }
  3063. document.removeEventListener('mousemove', onMouseMove);
  3064. document.removeEventListener('mouseup', endDrag);
  3065. setIsDragging(false);
  3066. }, []);
  3067. const startDrag = (0,external_wp_element_namespaceObject.useCallback)((
  3068. /** @type {MouseEvent} */
  3069. event) => {
  3070. if (eventsRef.current.onDragStart) {
  3071. eventsRef.current.onDragStart(event);
  3072. }
  3073. document.addEventListener('mousemove', onMouseMove);
  3074. document.addEventListener('mouseup', endDrag);
  3075. setIsDragging(true);
  3076. }, []); // Remove the global events when unmounting if needed.
  3077. (0,external_wp_element_namespaceObject.useEffect)(() => {
  3078. return () => {
  3079. if (isDragging) {
  3080. document.removeEventListener('mousemove', onMouseMove);
  3081. document.removeEventListener('mouseup', endDrag);
  3082. }
  3083. };
  3084. }, [isDragging]);
  3085. return {
  3086. startDrag,
  3087. endDrag,
  3088. isDragging
  3089. };
  3090. }
  3091. // EXTERNAL MODULE: ./node_modules/mousetrap/mousetrap.js
  3092. var mousetrap_mousetrap = __webpack_require__(7973);
  3093. var mousetrap_default = /*#__PURE__*/__webpack_require__.n(mousetrap_mousetrap);
  3094. // EXTERNAL MODULE: ./node_modules/mousetrap/plugins/global-bind/mousetrap-global-bind.js
  3095. var mousetrap_global_bind = __webpack_require__(5538);
  3096. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-keyboard-shortcut/index.js
  3097. /**
  3098. * External dependencies
  3099. */
  3100. /**
  3101. * WordPress dependencies
  3102. */
  3103. /**
  3104. * A block selection object.
  3105. *
  3106. * @typedef {Object} WPKeyboardShortcutConfig
  3107. *
  3108. * @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields.
  3109. * @property {string} [eventName] Event name used to trigger the handler, defaults to keydown.
  3110. * @property {boolean} [isDisabled] Disables the keyboard handler if the value is true.
  3111. * @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event.
  3112. */
  3113. /**
  3114. * Return true if platform is MacOS.
  3115. *
  3116. * @param {Window} [_window] window object by default; used for DI testing.
  3117. *
  3118. * @return {boolean} True if MacOS; false otherwise.
  3119. */
  3120. function isAppleOS() {
  3121. let _window = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
  3122. const {
  3123. platform
  3124. } = _window.navigator;
  3125. return platform.indexOf('Mac') !== -1 || (0,external_lodash_namespaceObject.includes)(['iPad', 'iPhone'], platform);
  3126. }
  3127. /* eslint-disable jsdoc/valid-types */
  3128. /**
  3129. * Attach a keyboard shortcut handler.
  3130. *
  3131. * @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter.
  3132. *
  3133. * @param {string[]|string} shortcuts Keyboard Shortcuts.
  3134. * @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback.
  3135. * @param {WPKeyboardShortcutConfig} options Shortcut options.
  3136. */
  3137. function useKeyboardShortcut(
  3138. /* eslint-enable jsdoc/valid-types */
  3139. shortcuts, callback) {
  3140. let {
  3141. bindGlobal = false,
  3142. eventName = 'keydown',
  3143. isDisabled = false,
  3144. // This is important for performance considerations.
  3145. target
  3146. } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  3147. const currentCallback = (0,external_wp_element_namespaceObject.useRef)(callback);
  3148. (0,external_wp_element_namespaceObject.useEffect)(() => {
  3149. currentCallback.current = callback;
  3150. }, [callback]);
  3151. (0,external_wp_element_namespaceObject.useEffect)(() => {
  3152. if (isDisabled) {
  3153. return;
  3154. }
  3155. const mousetrap = new (mousetrap_default())(target && target.current ? target.current : // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.
  3156. // Not sure if this is a mistake but it was the behavior previous to the addition of types so we're just doing what's
  3157. // necessary to maintain the existing behavior.
  3158. /** @type {Element} */
  3159. /** @type {unknown} */
  3160. document);
  3161. (0,external_lodash_namespaceObject.castArray)(shortcuts).forEach(shortcut => {
  3162. const keys = shortcut.split('+'); // Determines whether a key is a modifier by the length of the string.
  3163. // E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that
  3164. // the modifiers are Shift and Cmd because they're not a single character.
  3165. const modifiers = new Set(keys.filter(value => value.length > 1));
  3166. const hasAlt = modifiers.has('alt');
  3167. const hasShift = modifiers.has('shift'); // This should be better moved to the shortcut registration instead.
  3168. if (isAppleOS() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) {
  3169. throw new Error(`Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`);
  3170. }
  3171. const bindFn = bindGlobal ? 'bindGlobal' : 'bind'; // @ts-ignore `bindGlobal` is an undocumented property
  3172. mousetrap[bindFn](shortcut, function () {
  3173. return (
  3174. /* eslint-enable jsdoc/valid-types */
  3175. currentCallback.current(...arguments)
  3176. );
  3177. }, eventName);
  3178. });
  3179. return () => {
  3180. mousetrap.reset();
  3181. };
  3182. }, [shortcuts, bindGlobal, eventName, target, isDisabled]);
  3183. }
  3184. /* harmony default export */ var use_keyboard_shortcut = (useKeyboardShortcut);
  3185. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-media-query/index.js
  3186. /**
  3187. * WordPress dependencies
  3188. */
  3189. /**
  3190. * Runs a media query and returns its value when it changes.
  3191. *
  3192. * @param {string} [query] Media Query.
  3193. * @return {boolean} return value of the media query.
  3194. */
  3195. function useMediaQuery(query) {
  3196. const [match, setMatch] = (0,external_wp_element_namespaceObject.useState)(() => !!(query && typeof window !== 'undefined' && window.matchMedia(query).matches));
  3197. (0,external_wp_element_namespaceObject.useEffect)(() => {
  3198. if (!query) {
  3199. return;
  3200. }
  3201. const updateMatch = () => setMatch(window.matchMedia(query).matches);
  3202. updateMatch();
  3203. const list = window.matchMedia(query);
  3204. list.addListener(updateMatch);
  3205. return () => {
  3206. list.removeListener(updateMatch);
  3207. };
  3208. }, [query]);
  3209. return !!query && match;
  3210. }
  3211. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-previous/index.js
  3212. /**
  3213. * WordPress dependencies
  3214. */
  3215. /**
  3216. * Use something's value from the previous render.
  3217. * Based on https://usehooks.com/usePrevious/.
  3218. *
  3219. * @param value The value to track.
  3220. *
  3221. * @return The value from the previous render.
  3222. */
  3223. function usePrevious(value) {
  3224. const ref = (0,external_wp_element_namespaceObject.useRef)(); // Store current value in ref.
  3225. (0,external_wp_element_namespaceObject.useEffect)(() => {
  3226. ref.current = value;
  3227. }, [value]); // Re-run when value changes.
  3228. // Return previous value (happens before update in useEffect above).
  3229. return ref.current;
  3230. }
  3231. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-reduced-motion/index.js
  3232. /**
  3233. * Internal dependencies
  3234. */
  3235. /**
  3236. * Hook returning whether the user has a preference for reduced motion.
  3237. *
  3238. * @return {boolean} Reduced motion preference value.
  3239. */
  3240. const useReducedMotion = () => useMediaQuery('(prefers-reduced-motion: reduce)');
  3241. /* harmony default export */ var use_reduced_motion = (useReducedMotion);
  3242. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-viewport-match/index.js
  3243. /**
  3244. * WordPress dependencies
  3245. */
  3246. /**
  3247. * Internal dependencies
  3248. */
  3249. /**
  3250. * @typedef {"huge" | "wide" | "large" | "medium" | "small" | "mobile"} WPBreakpoint
  3251. */
  3252. /**
  3253. * Hash of breakpoint names with pixel width at which it becomes effective.
  3254. *
  3255. * @see _breakpoints.scss
  3256. *
  3257. * @type {Record<WPBreakpoint, number>}
  3258. */
  3259. const BREAKPOINTS = {
  3260. huge: 1440,
  3261. wide: 1280,
  3262. large: 960,
  3263. medium: 782,
  3264. small: 600,
  3265. mobile: 480
  3266. };
  3267. /**
  3268. * @typedef {">=" | "<"} WPViewportOperator
  3269. */
  3270. /**
  3271. * Object mapping media query operators to the condition to be used.
  3272. *
  3273. * @type {Record<WPViewportOperator, string>}
  3274. */
  3275. const CONDITIONS = {
  3276. '>=': 'min-width',
  3277. '<': 'max-width'
  3278. };
  3279. /**
  3280. * Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values.
  3281. *
  3282. * @type {Record<WPViewportOperator, (breakpointValue: number, width: number) => boolean>}
  3283. */
  3284. const OPERATOR_EVALUATORS = {
  3285. '>=': (breakpointValue, width) => width >= breakpointValue,
  3286. '<': (breakpointValue, width) => width < breakpointValue
  3287. };
  3288. const ViewportMatchWidthContext = (0,external_wp_element_namespaceObject.createContext)(
  3289. /** @type {null | number} */
  3290. null);
  3291. /**
  3292. * Returns true if the viewport matches the given query, or false otherwise.
  3293. *
  3294. * @param {WPBreakpoint} breakpoint Breakpoint size name.
  3295. * @param {WPViewportOperator} [operator=">="] Viewport operator.
  3296. *
  3297. * @example
  3298. *
  3299. * ```js
  3300. * useViewportMatch( 'huge', '<' );
  3301. * useViewportMatch( 'medium' );
  3302. * ```
  3303. *
  3304. * @return {boolean} Whether viewport matches query.
  3305. */
  3306. const useViewportMatch = function (breakpoint) {
  3307. let operator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '>=';
  3308. const simulatedWidth = (0,external_wp_element_namespaceObject.useContext)(ViewportMatchWidthContext);
  3309. const mediaQuery = !simulatedWidth && `(${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`;
  3310. const mediaQueryResult = useMediaQuery(mediaQuery || undefined);
  3311. if (simulatedWidth) {
  3312. return OPERATOR_EVALUATORS[operator](BREAKPOINTS[breakpoint], simulatedWidth);
  3313. }
  3314. return mediaQueryResult;
  3315. };
  3316. useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider;
  3317. /* harmony default export */ var use_viewport_match = (useViewportMatch);
  3318. // EXTERNAL MODULE: ./node_modules/react-resize-aware/dist/index.js
  3319. var dist = __webpack_require__(235);
  3320. var dist_default = /*#__PURE__*/__webpack_require__.n(dist);
  3321. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-resize-observer/index.js
  3322. /**
  3323. * External dependencies
  3324. */
  3325. /**
  3326. * Hook which allows to listen the resize event of any target element when it changes sizes.
  3327. * _Note: `useResizeObserver` will report `null` until after first render_
  3328. *
  3329. * Simply a re-export of `react-resize-aware` so refer to its documentation <https://github.com/FezVrasta/react-resize-aware>
  3330. * for more details.
  3331. *
  3332. * @see https://github.com/FezVrasta/react-resize-aware
  3333. *
  3334. * @example
  3335. *
  3336. * ```js
  3337. * const App = () => {
  3338. * const [ resizeListener, sizes ] = useResizeObserver();
  3339. *
  3340. * return (
  3341. * <div>
  3342. * { resizeListener }
  3343. * Your content here
  3344. * </div>
  3345. * );
  3346. * };
  3347. * ```
  3348. *
  3349. */
  3350. /* harmony default export */ var use_resize_observer = ((dist_default()));
  3351. ;// CONCATENATED MODULE: external ["wp","priorityQueue"]
  3352. var external_wp_priorityQueue_namespaceObject = window["wp"]["priorityQueue"];
  3353. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-async-list/index.js
  3354. /**
  3355. * WordPress dependencies
  3356. */
  3357. /**
  3358. * Returns the first items from list that are present on state.
  3359. *
  3360. * @param list New array.
  3361. * @param state Current state.
  3362. * @return First items present iin state.
  3363. */
  3364. function getFirstItemsPresentInState(list, state) {
  3365. const firstItems = [];
  3366. for (let i = 0; i < list.length; i++) {
  3367. const item = list[i];
  3368. if (!state.includes(item)) {
  3369. break;
  3370. }
  3371. firstItems.push(item);
  3372. }
  3373. return firstItems;
  3374. }
  3375. /**
  3376. * React hook returns an array which items get asynchronously appended from a source array.
  3377. * This behavior is useful if we want to render a list of items asynchronously for performance reasons.
  3378. *
  3379. * @param list Source array.
  3380. * @param config Configuration object.
  3381. *
  3382. * @return Async array.
  3383. */
  3384. function useAsyncList(list) {
  3385. let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
  3386. step: 1
  3387. };
  3388. const {
  3389. step = 1
  3390. } = config;
  3391. const [current, setCurrent] = (0,external_wp_element_namespaceObject.useState)([]);
  3392. (0,external_wp_element_namespaceObject.useEffect)(() => {
  3393. // On reset, we keep the first items that were previously rendered.
  3394. let firstItems = getFirstItemsPresentInState(list, current);
  3395. if (firstItems.length < step) {
  3396. firstItems = firstItems.concat(list.slice(firstItems.length, step));
  3397. }
  3398. setCurrent(firstItems);
  3399. let nextIndex = firstItems.length;
  3400. const asyncQueue = (0,external_wp_priorityQueue_namespaceObject.createQueue)();
  3401. const append = () => {
  3402. if (list.length <= nextIndex) {
  3403. return;
  3404. }
  3405. setCurrent(state => [...state, ...list.slice(nextIndex, nextIndex + step)]);
  3406. nextIndex += step;
  3407. asyncQueue.add({}, append);
  3408. };
  3409. asyncQueue.add({}, append);
  3410. return () => asyncQueue.reset();
  3411. }, [list]);
  3412. return current;
  3413. }
  3414. /* harmony default export */ var use_async_list = (useAsyncList);
  3415. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-warn-on-change/index.js
  3416. /**
  3417. * Internal dependencies
  3418. */
  3419. // Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in thise case
  3420. // but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript
  3421. /* eslint-disable jsdoc/check-types */
  3422. /**
  3423. * Hook that performs a shallow comparison between the preview value of an object
  3424. * and the new one, if there's a difference, it prints it to the console.
  3425. * this is useful in performance related work, to check why a component re-renders.
  3426. *
  3427. * @example
  3428. *
  3429. * ```jsx
  3430. * function MyComponent(props) {
  3431. * useWarnOnChange(props);
  3432. *
  3433. * return "Something";
  3434. * }
  3435. * ```
  3436. *
  3437. * @param {object} object Object which changes to compare.
  3438. * @param {string} prefix Just a prefix to show when console logging.
  3439. */
  3440. function useWarnOnChange(object) {
  3441. let prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Change detection';
  3442. const previousValues = usePrevious(object);
  3443. Object.entries(previousValues !== null && previousValues !== void 0 ? previousValues : []).forEach(_ref => {
  3444. let [key, value] = _ref;
  3445. if (value !== object[
  3446. /** @type {keyof typeof object} */
  3447. key]) {
  3448. // eslint-disable-next-line no-console
  3449. console.warn(`${prefix}: ${key} key changed:`, value, object[
  3450. /** @type {keyof typeof object} */
  3451. key]
  3452. /* eslint-enable jsdoc/check-types */
  3453. );
  3454. }
  3455. });
  3456. }
  3457. /* harmony default export */ var use_warn_on_change = (useWarnOnChange);
  3458. // EXTERNAL MODULE: external "React"
  3459. var external_React_ = __webpack_require__(9196);
  3460. ;// CONCATENATED MODULE: ./node_modules/use-memo-one/dist/use-memo-one.esm.js
  3461. function areInputsEqual(newInputs, lastInputs) {
  3462. if (newInputs.length !== lastInputs.length) {
  3463. return false;
  3464. }
  3465. for (var i = 0; i < newInputs.length; i++) {
  3466. if (newInputs[i] !== lastInputs[i]) {
  3467. return false;
  3468. }
  3469. }
  3470. return true;
  3471. }
  3472. function useMemoOne(getResult, inputs) {
  3473. var initial = (0,external_React_.useState)(function () {
  3474. return {
  3475. inputs: inputs,
  3476. result: getResult()
  3477. };
  3478. })[0];
  3479. var isFirstRun = (0,external_React_.useRef)(true);
  3480. var committed = (0,external_React_.useRef)(initial);
  3481. var useCache = isFirstRun.current || Boolean(inputs && committed.current.inputs && areInputsEqual(inputs, committed.current.inputs));
  3482. var cache = useCache ? committed.current : {
  3483. inputs: inputs,
  3484. result: getResult()
  3485. };
  3486. (0,external_React_.useEffect)(function () {
  3487. isFirstRun.current = false;
  3488. committed.current = cache;
  3489. }, [cache]);
  3490. return cache.result;
  3491. }
  3492. function useCallbackOne(callback, inputs) {
  3493. return useMemoOne(function () {
  3494. return callback;
  3495. }, inputs);
  3496. }
  3497. var useMemo = (/* unused pure expression or super */ null && (useMemoOne));
  3498. var useCallback = (/* unused pure expression or super */ null && (useCallbackOne));
  3499. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-debounce/index.js
  3500. /**
  3501. * External dependencies
  3502. */
  3503. /**
  3504. * WordPress dependencies
  3505. */
  3506. /* eslint-disable jsdoc/valid-types */
  3507. /**
  3508. * Debounces a function with Lodash's `debounce`. A new debounced function will
  3509. * be returned and any scheduled calls cancelled if any of the arguments change,
  3510. * including the function to debounce, so please wrap functions created on
  3511. * render in components in `useCallback`.
  3512. *
  3513. * @see https://docs-lodash.com/v4/debounce/
  3514. *
  3515. * @template {(...args: any[]) => void} TFunc
  3516. *
  3517. * @param {TFunc} fn The function to debounce.
  3518. * @param {number} [wait] The number of milliseconds to delay.
  3519. * @param {import('lodash').DebounceSettings} [options] The options object.
  3520. * @return {import('lodash').DebouncedFunc<TFunc>} Debounced function.
  3521. */
  3522. function useDebounce(fn, wait, options) {
  3523. /* eslint-enable jsdoc/valid-types */
  3524. const debounced = useMemoOne(() => (0,external_lodash_namespaceObject.debounce)(fn, wait, options), [fn, wait, options]);
  3525. (0,external_wp_element_namespaceObject.useEffect)(() => () => debounced.cancel(), [debounced]);
  3526. return debounced;
  3527. }
  3528. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-throttle/index.js
  3529. /**
  3530. * External dependencies
  3531. */
  3532. /**
  3533. * WordPress dependencies
  3534. */
  3535. /**
  3536. * Throttles a function with Lodash's `throttle`. A new throttled function will
  3537. * be returned and any scheduled calls cancelled if any of the arguments change,
  3538. * including the function to throttle, so please wrap functions created on
  3539. * render in components in `useCallback`.
  3540. *
  3541. * @see https://docs-lodash.com/v4/throttle/
  3542. *
  3543. * @template {(...args: any[]) => void} TFunc
  3544. *
  3545. * @param {TFunc} fn The function to throttle.
  3546. * @param {number} [wait] The number of milliseconds to throttle invocations to.
  3547. * @param {import('lodash').ThrottleSettings} [options] The options object. See linked documentation for details.
  3548. * @return {import('lodash').DebouncedFunc<TFunc>} Throttled function.
  3549. */
  3550. function useThrottle(fn, wait, options) {
  3551. const throttled = useMemoOne(() => (0,external_lodash_namespaceObject.throttle)(fn, wait, options), [fn, wait, options]);
  3552. (0,external_wp_element_namespaceObject.useEffect)(() => () => throttled.cancel(), [throttled]);
  3553. return throttled;
  3554. }
  3555. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-drop-zone/index.js
  3556. /**
  3557. * WordPress dependencies
  3558. */
  3559. /**
  3560. * Internal dependencies
  3561. */
  3562. /* eslint-disable jsdoc/valid-types */
  3563. /**
  3564. * @template T
  3565. * @param {T} value
  3566. * @return {import('react').MutableRefObject<T|null>} A ref with the value.
  3567. */
  3568. function useFreshRef(value) {
  3569. /* eslint-enable jsdoc/valid-types */
  3570. /* eslint-disable jsdoc/no-undefined-types */
  3571. /** @type {import('react').MutableRefObject<T>} */
  3572. /* eslint-enable jsdoc/no-undefined-types */
  3573. // Disable reason: We're doing something pretty JavaScript-y here where the
  3574. // ref will always have a current value that is not null or undefined but it
  3575. // needs to start as undefined. We don't want to change the return type so
  3576. // it's easier to just ts-ignore this specific line that's complaining about
  3577. // undefined not being part of T.
  3578. // @ts-ignore
  3579. const ref = (0,external_wp_element_namespaceObject.useRef)();
  3580. ref.current = value;
  3581. return ref;
  3582. }
  3583. /**
  3584. * A hook to facilitate drag and drop handling.
  3585. *
  3586. * @param {Object} props Named parameters.
  3587. * @param {boolean} props.isDisabled Whether or not to disable the drop zone.
  3588. * @param {(e: DragEvent) => void} props.onDragStart Called when dragging has started.
  3589. * @param {(e: DragEvent) => void} props.onDragEnter Called when the zone is entered.
  3590. * @param {(e: DragEvent) => void} props.onDragOver Called when the zone is moved within.
  3591. * @param {(e: DragEvent) => void} props.onDragLeave Called when the zone is left.
  3592. * @param {(e: MouseEvent) => void} props.onDragEnd Called when dragging has ended.
  3593. * @param {(e: DragEvent) => void} props.onDrop Called when dropping in the zone.
  3594. *
  3595. * @return {import('react').RefCallback<HTMLElement>} Ref callback to be passed to the drop zone element.
  3596. */
  3597. function useDropZone(_ref) {
  3598. let {
  3599. isDisabled,
  3600. onDrop: _onDrop,
  3601. onDragStart: _onDragStart,
  3602. onDragEnter: _onDragEnter,
  3603. onDragLeave: _onDragLeave,
  3604. onDragEnd: _onDragEnd,
  3605. onDragOver: _onDragOver
  3606. } = _ref;
  3607. const onDropRef = useFreshRef(_onDrop);
  3608. const onDragStartRef = useFreshRef(_onDragStart);
  3609. const onDragEnterRef = useFreshRef(_onDragEnter);
  3610. const onDragLeaveRef = useFreshRef(_onDragLeave);
  3611. const onDragEndRef = useFreshRef(_onDragEnd);
  3612. const onDragOverRef = useFreshRef(_onDragOver);
  3613. return useRefEffect(element => {
  3614. if (isDisabled) {
  3615. return;
  3616. }
  3617. let isDragging = false;
  3618. const {
  3619. ownerDocument
  3620. } = element;
  3621. /**
  3622. * Checks if an element is in the drop zone.
  3623. *
  3624. * @param {EventTarget|null} targetToCheck
  3625. *
  3626. * @return {boolean} True if in drop zone, false if not.
  3627. */
  3628. function isElementInZone(targetToCheck) {
  3629. const {
  3630. defaultView
  3631. } = ownerDocument;
  3632. if (!targetToCheck || !defaultView || !(targetToCheck instanceof defaultView.HTMLElement) || !element.contains(targetToCheck)) {
  3633. return false;
  3634. }
  3635. /** @type {HTMLElement|null} */
  3636. let elementToCheck = targetToCheck;
  3637. do {
  3638. if (elementToCheck.dataset.isDropZone) {
  3639. return elementToCheck === element;
  3640. }
  3641. } while (elementToCheck = elementToCheck.parentElement);
  3642. return false;
  3643. }
  3644. function maybeDragStart(
  3645. /** @type {DragEvent} */
  3646. event) {
  3647. if (isDragging) {
  3648. return;
  3649. }
  3650. isDragging = true;
  3651. ownerDocument.removeEventListener('dragenter', maybeDragStart); // Note that `dragend` doesn't fire consistently for file and
  3652. // HTML drag events where the drag origin is outside the browser
  3653. // window. In Firefox it may also not fire if the originating
  3654. // node is removed.
  3655. ownerDocument.addEventListener('dragend', maybeDragEnd);
  3656. ownerDocument.addEventListener('mousemove', maybeDragEnd);
  3657. if (onDragStartRef.current) {
  3658. onDragStartRef.current(event);
  3659. }
  3660. }
  3661. function onDragEnter(
  3662. /** @type {DragEvent} */
  3663. event) {
  3664. event.preventDefault(); // The `dragenter` event will also fire when entering child
  3665. // elements, but we only want to call `onDragEnter` when
  3666. // entering the drop zone, which means the `relatedTarget`
  3667. // (element that has been left) should be outside the drop zone.
  3668. if (element.contains(
  3669. /** @type {Node} */
  3670. event.relatedTarget)) {
  3671. return;
  3672. }
  3673. if (onDragEnterRef.current) {
  3674. onDragEnterRef.current(event);
  3675. }
  3676. }
  3677. function onDragOver(
  3678. /** @type {DragEvent} */
  3679. event) {
  3680. // Only call onDragOver for the innermost hovered drop zones.
  3681. if (!event.defaultPrevented && onDragOverRef.current) {
  3682. onDragOverRef.current(event);
  3683. } // Prevent the browser default while also signalling to parent
  3684. // drop zones that `onDragOver` is already handled.
  3685. event.preventDefault();
  3686. }
  3687. function onDragLeave(
  3688. /** @type {DragEvent} */
  3689. event) {
  3690. // The `dragleave` event will also fire when leaving child
  3691. // elements, but we only want to call `onDragLeave` when
  3692. // leaving the drop zone, which means the `relatedTarget`
  3693. // (element that has been entered) should be outside the drop
  3694. // zone.
  3695. if (isElementInZone(event.relatedTarget)) {
  3696. return;
  3697. }
  3698. if (onDragLeaveRef.current) {
  3699. onDragLeaveRef.current(event);
  3700. }
  3701. }
  3702. function onDrop(
  3703. /** @type {DragEvent} */
  3704. event) {
  3705. // Don't handle drop if an inner drop zone already handled it.
  3706. if (event.defaultPrevented) {
  3707. return;
  3708. } // Prevent the browser default while also signalling to parent
  3709. // drop zones that `onDrop` is already handled.
  3710. event.preventDefault(); // This seemingly useless line has been shown to resolve a
  3711. // Safari issue where files dragged directly from the dock are
  3712. // not recognized.
  3713. // eslint-disable-next-line no-unused-expressions
  3714. event.dataTransfer && event.dataTransfer.files.length;
  3715. if (onDropRef.current) {
  3716. onDropRef.current(event);
  3717. }
  3718. maybeDragEnd(event);
  3719. }
  3720. function maybeDragEnd(
  3721. /** @type {MouseEvent} */
  3722. event) {
  3723. if (!isDragging) {
  3724. return;
  3725. }
  3726. isDragging = false;
  3727. ownerDocument.addEventListener('dragenter', maybeDragStart);
  3728. ownerDocument.removeEventListener('dragend', maybeDragEnd);
  3729. ownerDocument.removeEventListener('mousemove', maybeDragEnd);
  3730. if (onDragEndRef.current) {
  3731. onDragEndRef.current(event);
  3732. }
  3733. }
  3734. element.dataset.isDropZone = 'true';
  3735. element.addEventListener('drop', onDrop);
  3736. element.addEventListener('dragenter', onDragEnter);
  3737. element.addEventListener('dragover', onDragOver);
  3738. element.addEventListener('dragleave', onDragLeave); // The `dragstart` event doesn't fire if the drag started outside
  3739. // the document.
  3740. ownerDocument.addEventListener('dragenter', maybeDragStart);
  3741. return () => {
  3742. onDropRef.current = null;
  3743. onDragStartRef.current = null;
  3744. onDragEnterRef.current = null;
  3745. onDragLeaveRef.current = null;
  3746. onDragEndRef.current = null;
  3747. onDragOverRef.current = null;
  3748. delete element.dataset.isDropZone;
  3749. element.removeEventListener('drop', onDrop);
  3750. element.removeEventListener('dragenter', onDragEnter);
  3751. element.removeEventListener('dragover', onDragOver);
  3752. element.removeEventListener('dragleave', onDragLeave);
  3753. ownerDocument.removeEventListener('dragend', maybeDragEnd);
  3754. ownerDocument.removeEventListener('mousemove', maybeDragEnd);
  3755. ownerDocument.addEventListener('dragenter', maybeDragStart);
  3756. };
  3757. }, [isDisabled]);
  3758. }
  3759. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-focusable-iframe/index.js
  3760. /**
  3761. * Internal dependencies
  3762. */
  3763. /**
  3764. * Dispatches a bubbling focus event when the iframe receives focus. Use
  3765. * `onFocus` as usual on the iframe or a parent element.
  3766. *
  3767. * @return {Object} Ref to pass to the iframe.
  3768. */
  3769. function useFocusableIframe() {
  3770. return useRefEffect(element => {
  3771. const {
  3772. ownerDocument
  3773. } = element;
  3774. if (!ownerDocument) return;
  3775. const {
  3776. defaultView
  3777. } = ownerDocument;
  3778. if (!defaultView) return;
  3779. /**
  3780. * Checks whether the iframe is the activeElement, inferring that it has
  3781. * then received focus, and dispatches a focus event.
  3782. */
  3783. function checkFocus() {
  3784. if (ownerDocument && ownerDocument.activeElement === element) {
  3785. /** @type {HTMLElement} */
  3786. element.focus();
  3787. }
  3788. }
  3789. defaultView.addEventListener('blur', checkFocus);
  3790. return () => {
  3791. defaultView.removeEventListener('blur', checkFocus);
  3792. };
  3793. }, []);
  3794. }
  3795. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/hooks/use-fixed-window-list/index.js
  3796. /**
  3797. * External dependencies
  3798. */
  3799. /**
  3800. * WordPress dependencies
  3801. */
  3802. const DEFAULT_INIT_WINDOW_SIZE = 30;
  3803. /**
  3804. * @typedef {Object} WPFixedWindowList
  3805. *
  3806. * @property {number} visibleItems Items visible in the current viewport
  3807. * @property {number} start Start index of the window
  3808. * @property {number} end End index of the window
  3809. * @property {(index:number)=>boolean} itemInView Returns true if item is in the window
  3810. */
  3811. /**
  3812. * @typedef {Object} WPFixedWindowListOptions
  3813. *
  3814. * @property {number} [windowOverscan] Renders windowOverscan number of items before and after the calculated visible window.
  3815. * @property {boolean} [useWindowing] When false avoids calculating the window size
  3816. * @property {number} [initWindowSize] Initial window size to use on first render before we can calculate the window size.
  3817. */
  3818. /**
  3819. *
  3820. * @param {import('react').RefObject<HTMLElement>} elementRef Used to find the closest scroll container that contains element.
  3821. * @param { number } itemHeight Fixed item height in pixels
  3822. * @param { number } totalItems Total items in list
  3823. * @param { WPFixedWindowListOptions } [options] Options object
  3824. * @return {[ WPFixedWindowList, setFixedListWindow:(nextWindow:WPFixedWindowList)=>void]} Array with the fixed window list and setter
  3825. */
  3826. function useFixedWindowList(elementRef, itemHeight, totalItems, options) {
  3827. var _options$initWindowSi, _options$useWindowing;
  3828. const initWindowSize = (_options$initWindowSi = options === null || options === void 0 ? void 0 : options.initWindowSize) !== null && _options$initWindowSi !== void 0 ? _options$initWindowSi : DEFAULT_INIT_WINDOW_SIZE;
  3829. const useWindowing = (_options$useWindowing = options === null || options === void 0 ? void 0 : options.useWindowing) !== null && _options$useWindowing !== void 0 ? _options$useWindowing : true;
  3830. const [fixedListWindow, setFixedListWindow] = (0,external_wp_element_namespaceObject.useState)({
  3831. visibleItems: initWindowSize,
  3832. start: 0,
  3833. end: initWindowSize,
  3834. itemInView: (
  3835. /** @type {number} */
  3836. index) => {
  3837. return index >= 0 && index <= initWindowSize;
  3838. }
  3839. });
  3840. (0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
  3841. var _scrollContainer$owne, _scrollContainer$owne2, _scrollContainer$owne3, _scrollContainer$owne4;
  3842. if (!useWindowing) {
  3843. return;
  3844. }
  3845. const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current);
  3846. const measureWindow = (
  3847. /** @type {boolean | undefined} */
  3848. initRender) => {
  3849. var _options$windowOversc;
  3850. if (!scrollContainer) {
  3851. return;
  3852. }
  3853. const visibleItems = Math.ceil(scrollContainer.clientHeight / itemHeight); // Aim to keep opening list view fast, afterward we can optimize for scrolling.
  3854. const windowOverscan = initRender ? visibleItems : (_options$windowOversc = options === null || options === void 0 ? void 0 : options.windowOverscan) !== null && _options$windowOversc !== void 0 ? _options$windowOversc : visibleItems;
  3855. const firstViewableIndex = Math.floor(scrollContainer.scrollTop / itemHeight);
  3856. const start = Math.max(0, firstViewableIndex - windowOverscan);
  3857. const end = Math.min(totalItems - 1, firstViewableIndex + visibleItems + windowOverscan);
  3858. setFixedListWindow(lastWindow => {
  3859. const nextWindow = {
  3860. visibleItems,
  3861. start,
  3862. end,
  3863. itemInView: (
  3864. /** @type {number} */
  3865. index) => {
  3866. return start <= index && index <= end;
  3867. }
  3868. };
  3869. if (lastWindow.start !== nextWindow.start || lastWindow.end !== nextWindow.end || lastWindow.visibleItems !== nextWindow.visibleItems) {
  3870. return nextWindow;
  3871. }
  3872. return lastWindow;
  3873. });
  3874. };
  3875. measureWindow(true);
  3876. const debounceMeasureList = (0,external_lodash_namespaceObject.debounce)(() => {
  3877. measureWindow();
  3878. }, 16);
  3879. scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.addEventListener('scroll', debounceMeasureList);
  3880. scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne = scrollContainer.ownerDocument) === null || _scrollContainer$owne === void 0 ? void 0 : (_scrollContainer$owne2 = _scrollContainer$owne.defaultView) === null || _scrollContainer$owne2 === void 0 ? void 0 : _scrollContainer$owne2.addEventListener('resize', debounceMeasureList);
  3881. scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne3 = scrollContainer.ownerDocument) === null || _scrollContainer$owne3 === void 0 ? void 0 : (_scrollContainer$owne4 = _scrollContainer$owne3.defaultView) === null || _scrollContainer$owne4 === void 0 ? void 0 : _scrollContainer$owne4.addEventListener('resize', debounceMeasureList);
  3882. return () => {
  3883. var _scrollContainer$owne5, _scrollContainer$owne6;
  3884. scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.removeEventListener('scroll', debounceMeasureList);
  3885. scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne5 = scrollContainer.ownerDocument) === null || _scrollContainer$owne5 === void 0 ? void 0 : (_scrollContainer$owne6 = _scrollContainer$owne5.defaultView) === null || _scrollContainer$owne6 === void 0 ? void 0 : _scrollContainer$owne6.removeEventListener('resize', debounceMeasureList);
  3886. };
  3887. }, [itemHeight, elementRef, totalItems]);
  3888. (0,external_wp_element_namespaceObject.useLayoutEffect)(() => {
  3889. var _scrollContainer$owne7, _scrollContainer$owne8;
  3890. if (!useWindowing) {
  3891. return;
  3892. }
  3893. const scrollContainer = (0,external_wp_dom_namespaceObject.getScrollContainer)(elementRef.current);
  3894. const handleKeyDown = (
  3895. /** @type {KeyboardEvent} */
  3896. event) => {
  3897. switch (event.keyCode) {
  3898. case external_wp_keycodes_namespaceObject.HOME:
  3899. {
  3900. return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
  3901. top: 0
  3902. });
  3903. }
  3904. case external_wp_keycodes_namespaceObject.END:
  3905. {
  3906. return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
  3907. top: totalItems * itemHeight
  3908. });
  3909. }
  3910. case external_wp_keycodes_namespaceObject.PAGEUP:
  3911. {
  3912. return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
  3913. top: scrollContainer.scrollTop - fixedListWindow.visibleItems * itemHeight
  3914. });
  3915. }
  3916. case external_wp_keycodes_namespaceObject.PAGEDOWN:
  3917. {
  3918. return scrollContainer === null || scrollContainer === void 0 ? void 0 : scrollContainer.scrollTo({
  3919. top: scrollContainer.scrollTop + fixedListWindow.visibleItems * itemHeight
  3920. });
  3921. }
  3922. }
  3923. };
  3924. scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne7 = scrollContainer.ownerDocument) === null || _scrollContainer$owne7 === void 0 ? void 0 : (_scrollContainer$owne8 = _scrollContainer$owne7.defaultView) === null || _scrollContainer$owne8 === void 0 ? void 0 : _scrollContainer$owne8.addEventListener('keydown', handleKeyDown);
  3925. return () => {
  3926. var _scrollContainer$owne9, _scrollContainer$owne10;
  3927. scrollContainer === null || scrollContainer === void 0 ? void 0 : (_scrollContainer$owne9 = scrollContainer.ownerDocument) === null || _scrollContainer$owne9 === void 0 ? void 0 : (_scrollContainer$owne10 = _scrollContainer$owne9.defaultView) === null || _scrollContainer$owne10 === void 0 ? void 0 : _scrollContainer$owne10.removeEventListener('keydown', handleKeyDown);
  3928. };
  3929. }, [totalItems, itemHeight, elementRef, fixedListWindow.visibleItems]);
  3930. return [fixedListWindow, setFixedListWindow];
  3931. }
  3932. ;// CONCATENATED MODULE: ./node_modules/@wordpress/compose/build-module/index.js
  3933. // Utils.
  3934. // Compose helper (aliased flowRight from Lodash)
  3935. // Higher-order components.
  3936. // Hooks.
  3937. }();
  3938. (window.wp = window.wp || {}).compose = __webpack_exports__;
  3939. /******/ })()
  3940. ;