compose.js 148 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724
  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 ? Object.assign.bind() : 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. ;