Нет описания

core-data.js 161KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406
  1. this["wp"] = this["wp"] || {}; this["wp"]["coreData"] =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = "dsJ0");
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ "1ZqX":
  90. /***/ (function(module, exports) {
  91. (function() { module.exports = window["wp"]["data"]; }());
  92. /***/ }),
  93. /***/ "51Zz":
  94. /***/ (function(module, exports) {
  95. (function() { module.exports = window["wp"]["dataControls"]; }());
  96. /***/ }),
  97. /***/ "7Cbv":
  98. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  99. "use strict";
  100. // CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/rng.js
  101. // Unique ID creation requires a high quality random # generator. In the browser we therefore
  102. // require the crypto API and do not support built-in fallback to lower quality random number
  103. // generators (like Math.random()).
  104. var getRandomValues;
  105. var rnds8 = new Uint8Array(16);
  106. function rng() {
  107. // lazy load so that environments that need to polyfill have a chance to do so
  108. if (!getRandomValues) {
  109. // getRandomValues needs to be invoked in a context where "this" is a Crypto implementation. Also,
  110. // find the complete implementation of crypto (msCrypto) on IE11.
  111. getRandomValues = typeof crypto !== 'undefined' && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto !== 'undefined' && typeof msCrypto.getRandomValues === 'function' && msCrypto.getRandomValues.bind(msCrypto);
  112. if (!getRandomValues) {
  113. throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
  114. }
  115. }
  116. return getRandomValues(rnds8);
  117. }
  118. // CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/regex.js
  119. /* harmony default export */ var regex = (/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i);
  120. // CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/validate.js
  121. function validate(uuid) {
  122. return typeof uuid === 'string' && regex.test(uuid);
  123. }
  124. /* harmony default export */ var esm_browser_validate = (validate);
  125. // CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/stringify.js
  126. /**
  127. * Convert array of 16 byte values to UUID string format of the form:
  128. * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
  129. */
  130. var byteToHex = [];
  131. for (var stringify_i = 0; stringify_i < 256; ++stringify_i) {
  132. byteToHex.push((stringify_i + 0x100).toString(16).substr(1));
  133. }
  134. function stringify(arr) {
  135. var offset = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
  136. // Note: Be careful editing this code! It's been tuned for performance
  137. // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
  138. var uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one
  139. // of the following:
  140. // - One or more input array values don't map to a hex octet (leading to
  141. // "undefined" in the uuid)
  142. // - Invalid input values for the RFC `version` or `variant` fields
  143. if (!esm_browser_validate(uuid)) {
  144. throw TypeError('Stringified UUID is invalid');
  145. }
  146. return uuid;
  147. }
  148. /* harmony default export */ var esm_browser_stringify = (stringify);
  149. // CONCATENATED MODULE: ./node_modules/uuid/dist/esm-browser/v4.js
  150. function v4(options, buf, offset) {
  151. options = options || {};
  152. var rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
  153. rnds[6] = rnds[6] & 0x0f | 0x40;
  154. rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided
  155. if (buf) {
  156. offset = offset || 0;
  157. for (var i = 0; i < 16; ++i) {
  158. buf[offset + i] = rnds[i];
  159. }
  160. return buf;
  161. }
  162. return esm_browser_stringify(rnds);
  163. }
  164. /* harmony default export */ var esm_browser_v4 = __webpack_exports__["a"] = (v4);
  165. /***/ }),
  166. /***/ "FtRg":
  167. /***/ (function(module, exports, __webpack_require__) {
  168. "use strict";
  169. function _typeof(obj) {
  170. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  171. _typeof = function (obj) {
  172. return typeof obj;
  173. };
  174. } else {
  175. _typeof = function (obj) {
  176. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  177. };
  178. }
  179. return _typeof(obj);
  180. }
  181. function _classCallCheck(instance, Constructor) {
  182. if (!(instance instanceof Constructor)) {
  183. throw new TypeError("Cannot call a class as a function");
  184. }
  185. }
  186. function _defineProperties(target, props) {
  187. for (var i = 0; i < props.length; i++) {
  188. var descriptor = props[i];
  189. descriptor.enumerable = descriptor.enumerable || false;
  190. descriptor.configurable = true;
  191. if ("value" in descriptor) descriptor.writable = true;
  192. Object.defineProperty(target, descriptor.key, descriptor);
  193. }
  194. }
  195. function _createClass(Constructor, protoProps, staticProps) {
  196. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  197. if (staticProps) _defineProperties(Constructor, staticProps);
  198. return Constructor;
  199. }
  200. /**
  201. * Given an instance of EquivalentKeyMap, returns its internal value pair tuple
  202. * for a key, if one exists. The tuple members consist of the last reference
  203. * value for the key (used in efficient subsequent lookups) and the value
  204. * assigned for the key at the leaf node.
  205. *
  206. * @param {EquivalentKeyMap} instance EquivalentKeyMap instance.
  207. * @param {*} key The key for which to return value pair.
  208. *
  209. * @return {?Array} Value pair, if exists.
  210. */
  211. function getValuePair(instance, key) {
  212. var _map = instance._map,
  213. _arrayTreeMap = instance._arrayTreeMap,
  214. _objectTreeMap = instance._objectTreeMap; // Map keeps a reference to the last object-like key used to set the
  215. // value, which can be used to shortcut immediately to the value.
  216. if (_map.has(key)) {
  217. return _map.get(key);
  218. } // Sort keys to ensure stable retrieval from tree.
  219. var properties = Object.keys(key).sort(); // Tree by type to avoid conflicts on numeric object keys, empty value.
  220. var map = Array.isArray(key) ? _arrayTreeMap : _objectTreeMap;
  221. for (var i = 0; i < properties.length; i++) {
  222. var property = properties[i];
  223. map = map.get(property);
  224. if (map === undefined) {
  225. return;
  226. }
  227. var propertyValue = key[property];
  228. map = map.get(propertyValue);
  229. if (map === undefined) {
  230. return;
  231. }
  232. }
  233. var valuePair = map.get('_ekm_value');
  234. if (!valuePair) {
  235. return;
  236. } // If reached, it implies that an object-like key was set with another
  237. // reference, so delete the reference and replace with the current.
  238. _map.delete(valuePair[0]);
  239. valuePair[0] = key;
  240. map.set('_ekm_value', valuePair);
  241. _map.set(key, valuePair);
  242. return valuePair;
  243. }
  244. /**
  245. * Variant of a Map object which enables lookup by equivalent (deeply equal)
  246. * object and array keys.
  247. */
  248. var EquivalentKeyMap =
  249. /*#__PURE__*/
  250. function () {
  251. /**
  252. * Constructs a new instance of EquivalentKeyMap.
  253. *
  254. * @param {Iterable.<*>} iterable Initial pair of key, value for map.
  255. */
  256. function EquivalentKeyMap(iterable) {
  257. _classCallCheck(this, EquivalentKeyMap);
  258. this.clear();
  259. if (iterable instanceof EquivalentKeyMap) {
  260. // Map#forEach is only means of iterating with support for IE11.
  261. var iterablePairs = [];
  262. iterable.forEach(function (value, key) {
  263. iterablePairs.push([key, value]);
  264. });
  265. iterable = iterablePairs;
  266. }
  267. if (iterable != null) {
  268. for (var i = 0; i < iterable.length; i++) {
  269. this.set(iterable[i][0], iterable[i][1]);
  270. }
  271. }
  272. }
  273. /**
  274. * Accessor property returning the number of elements.
  275. *
  276. * @return {number} Number of elements.
  277. */
  278. _createClass(EquivalentKeyMap, [{
  279. key: "set",
  280. /**
  281. * Add or update an element with a specified key and value.
  282. *
  283. * @param {*} key The key of the element to add.
  284. * @param {*} value The value of the element to add.
  285. *
  286. * @return {EquivalentKeyMap} Map instance.
  287. */
  288. value: function set(key, value) {
  289. // Shortcut non-object-like to set on internal Map.
  290. if (key === null || _typeof(key) !== 'object') {
  291. this._map.set(key, value);
  292. return this;
  293. } // Sort keys to ensure stable assignment into tree.
  294. var properties = Object.keys(key).sort();
  295. var valuePair = [key, value]; // Tree by type to avoid conflicts on numeric object keys, empty value.
  296. var map = Array.isArray(key) ? this._arrayTreeMap : this._objectTreeMap;
  297. for (var i = 0; i < properties.length; i++) {
  298. var property = properties[i];
  299. if (!map.has(property)) {
  300. map.set(property, new EquivalentKeyMap());
  301. }
  302. map = map.get(property);
  303. var propertyValue = key[property];
  304. if (!map.has(propertyValue)) {
  305. map.set(propertyValue, new EquivalentKeyMap());
  306. }
  307. map = map.get(propertyValue);
  308. } // If an _ekm_value exists, there was already an equivalent key. Before
  309. // overriding, ensure that the old key reference is removed from map to
  310. // avoid memory leak of accumulating equivalent keys. This is, in a
  311. // sense, a poor man's WeakMap, while still enabling iterability.
  312. var previousValuePair = map.get('_ekm_value');
  313. if (previousValuePair) {
  314. this._map.delete(previousValuePair[0]);
  315. }
  316. map.set('_ekm_value', valuePair);
  317. this._map.set(key, valuePair);
  318. return this;
  319. }
  320. /**
  321. * Returns a specified element.
  322. *
  323. * @param {*} key The key of the element to return.
  324. *
  325. * @return {?*} The element associated with the specified key or undefined
  326. * if the key can't be found.
  327. */
  328. }, {
  329. key: "get",
  330. value: function get(key) {
  331. // Shortcut non-object-like to get from internal Map.
  332. if (key === null || _typeof(key) !== 'object') {
  333. return this._map.get(key);
  334. }
  335. var valuePair = getValuePair(this, key);
  336. if (valuePair) {
  337. return valuePair[1];
  338. }
  339. }
  340. /**
  341. * Returns a boolean indicating whether an element with the specified key
  342. * exists or not.
  343. *
  344. * @param {*} key The key of the element to test for presence.
  345. *
  346. * @return {boolean} Whether an element with the specified key exists.
  347. */
  348. }, {
  349. key: "has",
  350. value: function has(key) {
  351. if (key === null || _typeof(key) !== 'object') {
  352. return this._map.has(key);
  353. } // Test on the _presence_ of the pair, not its value, as even undefined
  354. // can be a valid member value for a key.
  355. return getValuePair(this, key) !== undefined;
  356. }
  357. /**
  358. * Removes the specified element.
  359. *
  360. * @param {*} key The key of the element to remove.
  361. *
  362. * @return {boolean} Returns true if an element existed and has been
  363. * removed, or false if the element does not exist.
  364. */
  365. }, {
  366. key: "delete",
  367. value: function _delete(key) {
  368. if (!this.has(key)) {
  369. return false;
  370. } // This naive implementation will leave orphaned child trees. A better
  371. // implementation should traverse and remove orphans.
  372. this.set(key, undefined);
  373. return true;
  374. }
  375. /**
  376. * Executes a provided function once per each key/value pair, in insertion
  377. * order.
  378. *
  379. * @param {Function} callback Function to execute for each element.
  380. * @param {*} thisArg Value to use as `this` when executing
  381. * `callback`.
  382. */
  383. }, {
  384. key: "forEach",
  385. value: function forEach(callback) {
  386. var _this = this;
  387. var thisArg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this;
  388. this._map.forEach(function (value, key) {
  389. // Unwrap value from object-like value pair.
  390. if (key !== null && _typeof(key) === 'object') {
  391. value = value[1];
  392. }
  393. callback.call(thisArg, value, key, _this);
  394. });
  395. }
  396. /**
  397. * Removes all elements.
  398. */
  399. }, {
  400. key: "clear",
  401. value: function clear() {
  402. this._map = new Map();
  403. this._arrayTreeMap = new Map();
  404. this._objectTreeMap = new Map();
  405. }
  406. }, {
  407. key: "size",
  408. get: function get() {
  409. return this._map.size;
  410. }
  411. }]);
  412. return EquivalentKeyMap;
  413. }();
  414. module.exports = EquivalentKeyMap;
  415. /***/ }),
  416. /***/ "GRId":
  417. /***/ (function(module, exports) {
  418. (function() { module.exports = window["wp"]["element"]; }());
  419. /***/ }),
  420. /***/ "HSyU":
  421. /***/ (function(module, exports) {
  422. (function() { module.exports = window["wp"]["blocks"]; }());
  423. /***/ }),
  424. /***/ "Mmq9":
  425. /***/ (function(module, exports) {
  426. (function() { module.exports = window["wp"]["url"]; }());
  427. /***/ }),
  428. /***/ "YLtl":
  429. /***/ (function(module, exports) {
  430. (function() { module.exports = window["lodash"]; }());
  431. /***/ }),
  432. /***/ "dsJ0":
  433. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  434. "use strict";
  435. // ESM COMPAT FLAG
  436. __webpack_require__.r(__webpack_exports__);
  437. // EXPORTS
  438. __webpack_require__.d(__webpack_exports__, "store", function() { return /* binding */ build_module_store; });
  439. __webpack_require__.d(__webpack_exports__, "EntityProvider", function() { return /* reexport */ EntityProvider; });
  440. __webpack_require__.d(__webpack_exports__, "useEntityId", function() { return /* reexport */ useEntityId; });
  441. __webpack_require__.d(__webpack_exports__, "useEntityProp", function() { return /* reexport */ useEntityProp; });
  442. __webpack_require__.d(__webpack_exports__, "useEntityBlockEditor", function() { return /* reexport */ useEntityBlockEditor; });
  443. __webpack_require__.d(__webpack_exports__, "__experimentalFetchLinkSuggestions", function() { return /* reexport */ _experimental_fetch_link_suggestions; });
  444. __webpack_require__.d(__webpack_exports__, "__experimentalFetchRemoteUrlData", function() { return /* reexport */ _experimental_fetch_remote_url_data; });
  445. // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/locks/actions.js
  446. var locks_actions_namespaceObject = {};
  447. __webpack_require__.r(locks_actions_namespaceObject);
  448. __webpack_require__.d(locks_actions_namespaceObject, "__unstableAcquireStoreLock", function() { return __unstableAcquireStoreLock; });
  449. __webpack_require__.d(locks_actions_namespaceObject, "__unstableEnqueueLockRequest", function() { return __unstableEnqueueLockRequest; });
  450. __webpack_require__.d(locks_actions_namespaceObject, "__unstableReleaseStoreLock", function() { return __unstableReleaseStoreLock; });
  451. __webpack_require__.d(locks_actions_namespaceObject, "__unstableProcessPendingLockRequests", function() { return __unstableProcessPendingLockRequests; });
  452. // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/actions.js
  453. var build_module_actions_namespaceObject = {};
  454. __webpack_require__.r(build_module_actions_namespaceObject);
  455. __webpack_require__.d(build_module_actions_namespaceObject, "receiveUserQuery", function() { return receiveUserQuery; });
  456. __webpack_require__.d(build_module_actions_namespaceObject, "receiveCurrentUser", function() { return receiveCurrentUser; });
  457. __webpack_require__.d(build_module_actions_namespaceObject, "addEntities", function() { return addEntities; });
  458. __webpack_require__.d(build_module_actions_namespaceObject, "receiveEntityRecords", function() { return receiveEntityRecords; });
  459. __webpack_require__.d(build_module_actions_namespaceObject, "receiveCurrentTheme", function() { return receiveCurrentTheme; });
  460. __webpack_require__.d(build_module_actions_namespaceObject, "receiveThemeSupports", function() { return receiveThemeSupports; });
  461. __webpack_require__.d(build_module_actions_namespaceObject, "receiveEmbedPreview", function() { return receiveEmbedPreview; });
  462. __webpack_require__.d(build_module_actions_namespaceObject, "deleteEntityRecord", function() { return deleteEntityRecord; });
  463. __webpack_require__.d(build_module_actions_namespaceObject, "editEntityRecord", function() { return actions_editEntityRecord; });
  464. __webpack_require__.d(build_module_actions_namespaceObject, "undo", function() { return undo; });
  465. __webpack_require__.d(build_module_actions_namespaceObject, "redo", function() { return redo; });
  466. __webpack_require__.d(build_module_actions_namespaceObject, "__unstableCreateUndoLevel", function() { return actions_unstableCreateUndoLevel; });
  467. __webpack_require__.d(build_module_actions_namespaceObject, "saveEntityRecord", function() { return saveEntityRecord; });
  468. __webpack_require__.d(build_module_actions_namespaceObject, "__experimentalBatch", function() { return __experimentalBatch; });
  469. __webpack_require__.d(build_module_actions_namespaceObject, "saveEditedEntityRecord", function() { return saveEditedEntityRecord; });
  470. __webpack_require__.d(build_module_actions_namespaceObject, "__experimentalSaveSpecifiedEntityEdits", function() { return __experimentalSaveSpecifiedEntityEdits; });
  471. __webpack_require__.d(build_module_actions_namespaceObject, "receiveUploadPermissions", function() { return receiveUploadPermissions; });
  472. __webpack_require__.d(build_module_actions_namespaceObject, "receiveUserPermission", function() { return receiveUserPermission; });
  473. __webpack_require__.d(build_module_actions_namespaceObject, "receiveAutosaves", function() { return receiveAutosaves; });
  474. // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/selectors.js
  475. var build_module_selectors_namespaceObject = {};
  476. __webpack_require__.r(build_module_selectors_namespaceObject);
  477. __webpack_require__.d(build_module_selectors_namespaceObject, "isRequestingEmbedPreview", function() { return isRequestingEmbedPreview; });
  478. __webpack_require__.d(build_module_selectors_namespaceObject, "getAuthors", function() { return getAuthors; });
  479. __webpack_require__.d(build_module_selectors_namespaceObject, "__unstableGetAuthor", function() { return __unstableGetAuthor; });
  480. __webpack_require__.d(build_module_selectors_namespaceObject, "getCurrentUser", function() { return getCurrentUser; });
  481. __webpack_require__.d(build_module_selectors_namespaceObject, "getUserQueryResults", function() { return getUserQueryResults; });
  482. __webpack_require__.d(build_module_selectors_namespaceObject, "getEntitiesByKind", function() { return getEntitiesByKind; });
  483. __webpack_require__.d(build_module_selectors_namespaceObject, "getEntity", function() { return getEntity; });
  484. __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecord", function() { return getEntityRecord; });
  485. __webpack_require__.d(build_module_selectors_namespaceObject, "__experimentalGetEntityRecordNoResolver", function() { return __experimentalGetEntityRecordNoResolver; });
  486. __webpack_require__.d(build_module_selectors_namespaceObject, "getRawEntityRecord", function() { return getRawEntityRecord; });
  487. __webpack_require__.d(build_module_selectors_namespaceObject, "hasEntityRecords", function() { return hasEntityRecords; });
  488. __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecords", function() { return getEntityRecords; });
  489. __webpack_require__.d(build_module_selectors_namespaceObject, "__experimentalGetDirtyEntityRecords", function() { return __experimentalGetDirtyEntityRecords; });
  490. __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecordEdits", function() { return getEntityRecordEdits; });
  491. __webpack_require__.d(build_module_selectors_namespaceObject, "getEntityRecordNonTransientEdits", function() { return getEntityRecordNonTransientEdits; });
  492. __webpack_require__.d(build_module_selectors_namespaceObject, "hasEditsForEntityRecord", function() { return hasEditsForEntityRecord; });
  493. __webpack_require__.d(build_module_selectors_namespaceObject, "getEditedEntityRecord", function() { return getEditedEntityRecord; });
  494. __webpack_require__.d(build_module_selectors_namespaceObject, "isAutosavingEntityRecord", function() { return isAutosavingEntityRecord; });
  495. __webpack_require__.d(build_module_selectors_namespaceObject, "isSavingEntityRecord", function() { return isSavingEntityRecord; });
  496. __webpack_require__.d(build_module_selectors_namespaceObject, "isDeletingEntityRecord", function() { return isDeletingEntityRecord; });
  497. __webpack_require__.d(build_module_selectors_namespaceObject, "getLastEntitySaveError", function() { return getLastEntitySaveError; });
  498. __webpack_require__.d(build_module_selectors_namespaceObject, "getLastEntityDeleteError", function() { return getLastEntityDeleteError; });
  499. __webpack_require__.d(build_module_selectors_namespaceObject, "getUndoEdit", function() { return getUndoEdit; });
  500. __webpack_require__.d(build_module_selectors_namespaceObject, "getRedoEdit", function() { return getRedoEdit; });
  501. __webpack_require__.d(build_module_selectors_namespaceObject, "hasUndo", function() { return hasUndo; });
  502. __webpack_require__.d(build_module_selectors_namespaceObject, "hasRedo", function() { return hasRedo; });
  503. __webpack_require__.d(build_module_selectors_namespaceObject, "getCurrentTheme", function() { return getCurrentTheme; });
  504. __webpack_require__.d(build_module_selectors_namespaceObject, "getThemeSupports", function() { return getThemeSupports; });
  505. __webpack_require__.d(build_module_selectors_namespaceObject, "getEmbedPreview", function() { return getEmbedPreview; });
  506. __webpack_require__.d(build_module_selectors_namespaceObject, "isPreviewEmbedFallback", function() { return isPreviewEmbedFallback; });
  507. __webpack_require__.d(build_module_selectors_namespaceObject, "canUser", function() { return canUser; });
  508. __webpack_require__.d(build_module_selectors_namespaceObject, "canUserEditEntityRecord", function() { return canUserEditEntityRecord; });
  509. __webpack_require__.d(build_module_selectors_namespaceObject, "getAutosaves", function() { return getAutosaves; });
  510. __webpack_require__.d(build_module_selectors_namespaceObject, "getAutosave", function() { return getAutosave; });
  511. __webpack_require__.d(build_module_selectors_namespaceObject, "hasFetchedAutosaves", function() { return hasFetchedAutosaves; });
  512. __webpack_require__.d(build_module_selectors_namespaceObject, "getReferenceByDistinctEdits", function() { return getReferenceByDistinctEdits; });
  513. __webpack_require__.d(build_module_selectors_namespaceObject, "__experimentalGetTemplateForLink", function() { return __experimentalGetTemplateForLink; });
  514. // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/resolvers.js
  515. var resolvers_namespaceObject = {};
  516. __webpack_require__.r(resolvers_namespaceObject);
  517. __webpack_require__.d(resolvers_namespaceObject, "getAuthors", function() { return resolvers_getAuthors; });
  518. __webpack_require__.d(resolvers_namespaceObject, "__unstableGetAuthor", function() { return resolvers_unstableGetAuthor; });
  519. __webpack_require__.d(resolvers_namespaceObject, "getCurrentUser", function() { return resolvers_getCurrentUser; });
  520. __webpack_require__.d(resolvers_namespaceObject, "getEntityRecord", function() { return resolvers_getEntityRecord; });
  521. __webpack_require__.d(resolvers_namespaceObject, "getRawEntityRecord", function() { return resolvers_getRawEntityRecord; });
  522. __webpack_require__.d(resolvers_namespaceObject, "getEditedEntityRecord", function() { return resolvers_getEditedEntityRecord; });
  523. __webpack_require__.d(resolvers_namespaceObject, "getEntityRecords", function() { return resolvers_getEntityRecords; });
  524. __webpack_require__.d(resolvers_namespaceObject, "getCurrentTheme", function() { return resolvers_getCurrentTheme; });
  525. __webpack_require__.d(resolvers_namespaceObject, "getThemeSupports", function() { return resolvers_getThemeSupports; });
  526. __webpack_require__.d(resolvers_namespaceObject, "getEmbedPreview", function() { return resolvers_getEmbedPreview; });
  527. __webpack_require__.d(resolvers_namespaceObject, "canUser", function() { return resolvers_canUser; });
  528. __webpack_require__.d(resolvers_namespaceObject, "canUserEditEntityRecord", function() { return resolvers_canUserEditEntityRecord; });
  529. __webpack_require__.d(resolvers_namespaceObject, "getAutosaves", function() { return resolvers_getAutosaves; });
  530. __webpack_require__.d(resolvers_namespaceObject, "getAutosave", function() { return resolvers_getAutosave; });
  531. __webpack_require__.d(resolvers_namespaceObject, "__experimentalGetTemplateForLink", function() { return resolvers_experimentalGetTemplateForLink; });
  532. // NAMESPACE OBJECT: ./node_modules/@wordpress/core-data/build-module/locks/selectors.js
  533. var locks_selectors_namespaceObject = {};
  534. __webpack_require__.r(locks_selectors_namespaceObject);
  535. __webpack_require__.d(locks_selectors_namespaceObject, "__unstableGetPendingLockRequests", function() { return __unstableGetPendingLockRequests; });
  536. __webpack_require__.d(locks_selectors_namespaceObject, "__unstableIsLockAvailable", function() { return __unstableIsLockAvailable; });
  537. // EXTERNAL MODULE: external ["wp","data"]
  538. var external_wp_data_ = __webpack_require__("1ZqX");
  539. // EXTERNAL MODULE: external ["wp","dataControls"]
  540. var external_wp_dataControls_ = __webpack_require__("51Zz");
  541. // EXTERNAL MODULE: external "lodash"
  542. var external_lodash_ = __webpack_require__("YLtl");
  543. // EXTERNAL MODULE: external ["wp","isShallowEqual"]
  544. var external_wp_isShallowEqual_ = __webpack_require__("rl8x");
  545. var external_wp_isShallowEqual_default = /*#__PURE__*/__webpack_require__.n(external_wp_isShallowEqual_);
  546. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/if-matching-action.js
  547. /**
  548. * A higher-order reducer creator which invokes the original reducer only if
  549. * the dispatching action matches the given predicate, **OR** if state is
  550. * initializing (undefined).
  551. *
  552. * @param {Function} isMatch Function predicate for allowing reducer call.
  553. *
  554. * @return {Function} Higher-order reducer.
  555. */
  556. const ifMatchingAction = isMatch => reducer => (state, action) => {
  557. if (state === undefined || isMatch(action)) {
  558. return reducer(state, action);
  559. }
  560. return state;
  561. };
  562. /* harmony default export */ var if_matching_action = (ifMatchingAction);
  563. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/replace-action.js
  564. /**
  565. * Higher-order reducer creator which substitutes the action object before
  566. * passing to the original reducer.
  567. *
  568. * @param {Function} replacer Function mapping original action to replacement.
  569. *
  570. * @return {Function} Higher-order reducer.
  571. */
  572. const replaceAction = replacer => reducer => (state, action) => {
  573. return reducer(state, replacer(action));
  574. };
  575. /* harmony default export */ var replace_action = (replaceAction);
  576. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/conservative-map-item.js
  577. /**
  578. * External dependencies
  579. */
  580. /**
  581. * Given the current and next item entity, returns the minimally "modified"
  582. * result of the next item, preferring value references from the original item
  583. * if equal. If all values match, the original item is returned.
  584. *
  585. * @param {Object} item Original item.
  586. * @param {Object} nextItem Next item.
  587. *
  588. * @return {Object} Minimally modified merged item.
  589. */
  590. function conservativeMapItem(item, nextItem) {
  591. // Return next item in its entirety if there is no original item.
  592. if (!item) {
  593. return nextItem;
  594. }
  595. let hasChanges = false;
  596. const result = {};
  597. for (const key in nextItem) {
  598. if (Object(external_lodash_["isEqual"])(item[key], nextItem[key])) {
  599. result[key] = item[key];
  600. } else {
  601. hasChanges = true;
  602. result[key] = nextItem[key];
  603. }
  604. }
  605. if (!hasChanges) {
  606. return item;
  607. } // Only at this point, backfill properties from the original item which
  608. // weren't explicitly set into the result above. This is an optimization
  609. // to allow `hasChanges` to return early.
  610. for (const key in item) {
  611. if (!result.hasOwnProperty(key)) {
  612. result[key] = item[key];
  613. }
  614. }
  615. return result;
  616. }
  617. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/on-sub-key.js
  618. /**
  619. * Higher-order reducer creator which creates a combined reducer object, keyed
  620. * by a property on the action object.
  621. *
  622. * @param {string} actionProperty Action property by which to key object.
  623. *
  624. * @return {Function} Higher-order reducer.
  625. */
  626. const onSubKey = actionProperty => reducer => (state = {}, action) => {
  627. // Retrieve subkey from action. Do not track if undefined; useful for cases
  628. // where reducer is scoped by action shape.
  629. const key = action[actionProperty];
  630. if (key === undefined) {
  631. return state;
  632. } // Avoid updating state if unchanged. Note that this also accounts for a
  633. // reducer which returns undefined on a key which is not yet tracked.
  634. const nextKeyState = reducer(state[key], action);
  635. if (nextKeyState === state[key]) {
  636. return state;
  637. }
  638. return { ...state,
  639. [key]: nextKeyState
  640. };
  641. };
  642. /* harmony default export */ var on_sub_key = (onSubKey);
  643. // EXTERNAL MODULE: external ["wp","i18n"]
  644. var external_wp_i18n_ = __webpack_require__("l3Sj");
  645. // EXTERNAL MODULE: ./node_modules/uuid/dist/esm-browser/v4.js + 4 modules
  646. var v4 = __webpack_require__("7Cbv");
  647. // EXTERNAL MODULE: external ["wp","url"]
  648. var external_wp_url_ = __webpack_require__("Mmq9");
  649. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/actions.js
  650. /**
  651. * External dependencies
  652. */
  653. /**
  654. * Returns an action object used in signalling that items have been received.
  655. *
  656. * @param {Array} items Items received.
  657. * @param {?Object} edits Optional edits to reset.
  658. *
  659. * @return {Object} Action object.
  660. */
  661. function receiveItems(items, edits) {
  662. return {
  663. type: 'RECEIVE_ITEMS',
  664. items: Object(external_lodash_["castArray"])(items),
  665. persistedEdits: edits
  666. };
  667. }
  668. /**
  669. * Returns an action object used in signalling that entity records have been
  670. * deleted and they need to be removed from entities state.
  671. *
  672. * @param {string} kind Kind of the removed entities.
  673. * @param {string} name Name of the removed entities.
  674. * @param {Array|number} records Record IDs of the removed entities.
  675. * @param {boolean} invalidateCache Controls whether we want to invalidate the cache.
  676. * @return {Object} Action object.
  677. */
  678. function removeItems(kind, name, records, invalidateCache = false) {
  679. return {
  680. type: 'REMOVE_ITEMS',
  681. itemIds: Object(external_lodash_["castArray"])(records),
  682. kind,
  683. name,
  684. invalidateCache
  685. };
  686. }
  687. /**
  688. * Returns an action object used in signalling that queried data has been
  689. * received.
  690. *
  691. * @param {Array} items Queried items received.
  692. * @param {?Object} query Optional query object.
  693. * @param {?Object} edits Optional edits to reset.
  694. *
  695. * @return {Object} Action object.
  696. */
  697. function receiveQueriedItems(items, query = {}, edits) {
  698. return { ...receiveItems(items, edits),
  699. query
  700. };
  701. }
  702. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/actions.js
  703. /**
  704. * WordPress dependencies
  705. */
  706. function* __unstableAcquireStoreLock(store, path, {
  707. exclusive
  708. }) {
  709. const promise = yield* __unstableEnqueueLockRequest(store, path, {
  710. exclusive
  711. });
  712. yield* __unstableProcessPendingLockRequests();
  713. return yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(promise);
  714. }
  715. function* __unstableEnqueueLockRequest(store, path, {
  716. exclusive
  717. }) {
  718. let notifyAcquired;
  719. const promise = new Promise(resolve => {
  720. notifyAcquired = resolve;
  721. });
  722. yield {
  723. type: 'ENQUEUE_LOCK_REQUEST',
  724. request: {
  725. store,
  726. path,
  727. exclusive,
  728. notifyAcquired
  729. }
  730. };
  731. return promise;
  732. }
  733. function* __unstableReleaseStoreLock(lock) {
  734. yield {
  735. type: 'RELEASE_LOCK',
  736. lock
  737. };
  738. yield* __unstableProcessPendingLockRequests();
  739. }
  740. function* __unstableProcessPendingLockRequests() {
  741. yield {
  742. type: 'PROCESS_PENDING_LOCK_REQUESTS'
  743. };
  744. const lockRequests = yield external_wp_data_["controls"].select('core', '__unstableGetPendingLockRequests');
  745. for (const request of lockRequests) {
  746. const {
  747. store,
  748. path,
  749. exclusive,
  750. notifyAcquired
  751. } = request;
  752. const isAvailable = yield external_wp_data_["controls"].select('core', '__unstableIsLockAvailable', store, path, {
  753. exclusive
  754. });
  755. if (isAvailable) {
  756. const lock = {
  757. store,
  758. path,
  759. exclusive
  760. };
  761. yield {
  762. type: 'GRANT_LOCK_REQUEST',
  763. lock,
  764. request
  765. };
  766. notifyAcquired(lock);
  767. }
  768. }
  769. }
  770. // EXTERNAL MODULE: external ["wp","apiFetch"]
  771. var external_wp_apiFetch_ = __webpack_require__("ywyh");
  772. var external_wp_apiFetch_default = /*#__PURE__*/__webpack_require__.n(external_wp_apiFetch_);
  773. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/batch/default-processor.js
  774. /**
  775. * External dependencies
  776. */
  777. /**
  778. * WordPress dependencies
  779. */
  780. /**
  781. * Maximum number of requests to place in a single batch request. Obtained by
  782. * sending a preflight OPTIONS request to /batch/v1/.
  783. *
  784. * @type {number?}
  785. */
  786. let maxItems = null;
  787. /**
  788. * Default batch processor. Sends its input requests to /batch/v1.
  789. *
  790. * @param {Array} requests List of API requests to perform at once.
  791. *
  792. * @return {Promise} Promise that resolves to a list of objects containing
  793. * either `output` (if that request was succesful) or `error`
  794. * (if not ).
  795. */
  796. async function defaultProcessor(requests) {
  797. if (maxItems === null) {
  798. const preflightResponse = await external_wp_apiFetch_default()({
  799. path: '/batch/v1',
  800. method: 'OPTIONS'
  801. });
  802. maxItems = preflightResponse.endpoints[0].args.requests.maxItems;
  803. }
  804. const results = [];
  805. for (const batchRequests of Object(external_lodash_["chunk"])(requests, maxItems)) {
  806. const batchResponse = await external_wp_apiFetch_default()({
  807. path: '/batch/v1',
  808. method: 'POST',
  809. data: {
  810. validation: 'require-all-validate',
  811. requests: batchRequests.map(request => ({
  812. path: request.path,
  813. body: request.data,
  814. // Rename 'data' to 'body'.
  815. method: request.method,
  816. headers: request.headers
  817. }))
  818. }
  819. });
  820. let batchResults;
  821. if (batchResponse.failed) {
  822. batchResults = batchResponse.responses.map(response => ({
  823. error: response === null || response === void 0 ? void 0 : response.body
  824. }));
  825. } else {
  826. batchResults = batchResponse.responses.map(response => {
  827. const result = {};
  828. if (response.status >= 200 && response.status < 300) {
  829. result.output = response.body;
  830. } else {
  831. result.error = response.body;
  832. }
  833. return result;
  834. });
  835. }
  836. results.push(...batchResults);
  837. }
  838. return results;
  839. }
  840. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/batch/create-batch.js
  841. /**
  842. * External dependencies
  843. */
  844. /**
  845. * Internal dependencies
  846. */
  847. /**
  848. * Creates a batch, which can be used to combine multiple API requests into one
  849. * API request using the WordPress batch processing API (/v1/batch).
  850. *
  851. * ```
  852. * const batch = createBatch();
  853. * const dunePromise = batch.add( {
  854. * path: '/v1/books',
  855. * method: 'POST',
  856. * data: { title: 'Dune' }
  857. * } );
  858. * const lotrPromise = batch.add( {
  859. * path: '/v1/books',
  860. * method: 'POST',
  861. * data: { title: 'Lord of the Rings' }
  862. * } );
  863. * const isSuccess = await batch.run(); // Sends one POST to /v1/batch.
  864. * if ( isSuccess ) {
  865. * console.log(
  866. * 'Saved two books:',
  867. * await dunePromise,
  868. * await lotrPromise
  869. * );
  870. * }
  871. * ```
  872. *
  873. * @param {Function} [processor] Processor function. Can be used to replace the
  874. * default functionality which is to send an API
  875. * request to /v1/batch. Is given an array of
  876. * inputs and must return a promise that
  877. * resolves to an array of objects containing
  878. * either `output` or `error`.
  879. */
  880. function createBatch(processor = defaultProcessor) {
  881. let lastId = 0;
  882. let queue = [];
  883. const pending = new ObservableSet();
  884. return {
  885. /**
  886. * Adds an input to the batch and returns a promise that is resolved or
  887. * rejected when the input is processed by `batch.run()`.
  888. *
  889. * You may also pass a thunk which allows inputs to be added
  890. * asychronously.
  891. *
  892. * ```
  893. * // Both are allowed:
  894. * batch.add( { path: '/v1/books', ... } );
  895. * batch.add( ( add ) => add( { path: '/v1/books', ... } ) );
  896. * ```
  897. *
  898. * If a thunk is passed, `batch.run()` will pause until either:
  899. *
  900. * - The thunk calls its `add` argument, or;
  901. * - The thunk returns a promise and that promise resolves, or;
  902. * - The thunk returns a non-promise.
  903. *
  904. * @param {any|Function} inputOrThunk Input to add or thunk to execute.
  905. * @return {Promise|any} If given an input, returns a promise that
  906. * is resolved or rejected when the batch is
  907. * processed. If given a thunk, returns the return
  908. * value of that thunk.
  909. */
  910. add(inputOrThunk) {
  911. const id = ++lastId;
  912. pending.add(id);
  913. const add = input => new Promise((resolve, reject) => {
  914. queue.push({
  915. input,
  916. resolve,
  917. reject
  918. });
  919. pending.delete(id);
  920. });
  921. if (Object(external_lodash_["isFunction"])(inputOrThunk)) {
  922. return Promise.resolve(inputOrThunk(add)).finally(() => {
  923. pending.delete(id);
  924. });
  925. }
  926. return add(inputOrThunk);
  927. },
  928. /**
  929. * Runs the batch. This calls `batchProcessor` and resolves or rejects
  930. * all promises returned by `add()`.
  931. *
  932. * @return {Promise} A promise that resolves to a boolean that is true
  933. * if the processor returned no errors.
  934. */
  935. async run() {
  936. if (pending.size) {
  937. await new Promise(resolve => {
  938. const unsubscribe = pending.subscribe(() => {
  939. if (!pending.size) {
  940. unsubscribe();
  941. resolve();
  942. }
  943. });
  944. });
  945. }
  946. let results;
  947. try {
  948. results = await processor(queue.map(({
  949. input
  950. }) => input));
  951. if (results.length !== queue.length) {
  952. throw new Error('run: Array returned by processor must be same size as input array.');
  953. }
  954. } catch (error) {
  955. for (const {
  956. reject
  957. } of queue) {
  958. reject(error);
  959. }
  960. throw error;
  961. }
  962. let isSuccess = true;
  963. for (const [result, {
  964. resolve,
  965. reject
  966. }] of Object(external_lodash_["zip"])(results, queue)) {
  967. if (result !== null && result !== void 0 && result.error) {
  968. reject(result.error);
  969. isSuccess = false;
  970. } else {
  971. var _result$output;
  972. resolve((_result$output = result === null || result === void 0 ? void 0 : result.output) !== null && _result$output !== void 0 ? _result$output : result);
  973. }
  974. }
  975. queue = [];
  976. return isSuccess;
  977. }
  978. };
  979. }
  980. class ObservableSet {
  981. constructor(...args) {
  982. this.set = new Set(...args);
  983. this.subscribers = new Set();
  984. }
  985. get size() {
  986. return this.set.size;
  987. }
  988. add(...args) {
  989. this.set.add(...args);
  990. this.subscribers.forEach(subscriber => subscriber());
  991. return this;
  992. }
  993. delete(...args) {
  994. const isSuccess = this.set.delete(...args);
  995. this.subscribers.forEach(subscriber => subscriber());
  996. return isSuccess;
  997. }
  998. subscribe(subscriber) {
  999. this.subscribers.add(subscriber);
  1000. return () => {
  1001. this.subscribers.delete(subscriber);
  1002. };
  1003. }
  1004. }
  1005. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/controls.js
  1006. /**
  1007. * WordPress dependencies
  1008. */
  1009. function regularFetch(url) {
  1010. return {
  1011. type: 'REGULAR_FETCH',
  1012. url
  1013. };
  1014. }
  1015. function getDispatch() {
  1016. return {
  1017. type: 'GET_DISPATCH'
  1018. };
  1019. }
  1020. const controls = {
  1021. async REGULAR_FETCH({
  1022. url
  1023. }) {
  1024. const {
  1025. data
  1026. } = await window.fetch(url).then(res => res.json());
  1027. return data;
  1028. },
  1029. GET_DISPATCH: Object(external_wp_data_["createRegistryControl"])(({
  1030. dispatch
  1031. }) => () => dispatch)
  1032. };
  1033. /* harmony default export */ var build_module_controls = (controls);
  1034. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/actions.js
  1035. /**
  1036. * External dependencies
  1037. */
  1038. /**
  1039. * WordPress dependencies
  1040. */
  1041. /**
  1042. * Internal dependencies
  1043. */
  1044. /**
  1045. * Returns an action object used in signalling that authors have been received.
  1046. *
  1047. * @param {string} queryID Query ID.
  1048. * @param {Array|Object} users Users received.
  1049. *
  1050. * @return {Object} Action object.
  1051. */
  1052. function receiveUserQuery(queryID, users) {
  1053. return {
  1054. type: 'RECEIVE_USER_QUERY',
  1055. users: Object(external_lodash_["castArray"])(users),
  1056. queryID
  1057. };
  1058. }
  1059. /**
  1060. * Returns an action used in signalling that the current user has been received.
  1061. *
  1062. * @param {Object} currentUser Current user object.
  1063. *
  1064. * @return {Object} Action object.
  1065. */
  1066. function receiveCurrentUser(currentUser) {
  1067. return {
  1068. type: 'RECEIVE_CURRENT_USER',
  1069. currentUser
  1070. };
  1071. }
  1072. /**
  1073. * Returns an action object used in adding new entities.
  1074. *
  1075. * @param {Array} entities Entities received.
  1076. *
  1077. * @return {Object} Action object.
  1078. */
  1079. function addEntities(entities) {
  1080. return {
  1081. type: 'ADD_ENTITIES',
  1082. entities
  1083. };
  1084. }
  1085. /**
  1086. * Returns an action object used in signalling that entity records have been received.
  1087. *
  1088. * @param {string} kind Kind of the received entity.
  1089. * @param {string} name Name of the received entity.
  1090. * @param {Array|Object} records Records received.
  1091. * @param {?Object} query Query Object.
  1092. * @param {?boolean} invalidateCache Should invalidate query caches.
  1093. * @param {?Object} edits Edits to reset.
  1094. * @return {Object} Action object.
  1095. */
  1096. function receiveEntityRecords(kind, name, records, query, invalidateCache = false, edits) {
  1097. // Auto drafts should not have titles, but some plugins rely on them so we can't filter this
  1098. // on the server.
  1099. if (kind === 'postType') {
  1100. records = Object(external_lodash_["castArray"])(records).map(record => record.status === 'auto-draft' ? { ...record,
  1101. title: ''
  1102. } : record);
  1103. }
  1104. let action;
  1105. if (query) {
  1106. action = receiveQueriedItems(records, query, edits);
  1107. } else {
  1108. action = receiveItems(records, edits);
  1109. }
  1110. return { ...action,
  1111. kind,
  1112. name,
  1113. invalidateCache
  1114. };
  1115. }
  1116. /**
  1117. * Returns an action object used in signalling that the current theme has been received.
  1118. *
  1119. * @param {Object} currentTheme The current theme.
  1120. *
  1121. * @return {Object} Action object.
  1122. */
  1123. function receiveCurrentTheme(currentTheme) {
  1124. return {
  1125. type: 'RECEIVE_CURRENT_THEME',
  1126. currentTheme
  1127. };
  1128. }
  1129. /**
  1130. * Returns an action object used in signalling that the index has been received.
  1131. *
  1132. * @param {Object} themeSupports Theme support for the current theme.
  1133. *
  1134. * @return {Object} Action object.
  1135. */
  1136. function receiveThemeSupports(themeSupports) {
  1137. return {
  1138. type: 'RECEIVE_THEME_SUPPORTS',
  1139. themeSupports
  1140. };
  1141. }
  1142. /**
  1143. * Returns an action object used in signalling that the preview data for
  1144. * a given URl has been received.
  1145. *
  1146. * @param {string} url URL to preview the embed for.
  1147. * @param {*} preview Preview data.
  1148. *
  1149. * @return {Object} Action object.
  1150. */
  1151. function receiveEmbedPreview(url, preview) {
  1152. return {
  1153. type: 'RECEIVE_EMBED_PREVIEW',
  1154. url,
  1155. preview
  1156. };
  1157. }
  1158. /**
  1159. * Action triggered to delete an entity record.
  1160. *
  1161. * @param {string} kind Kind of the deleted entity.
  1162. * @param {string} name Name of the deleted entity.
  1163. * @param {string} recordId Record ID of the deleted entity.
  1164. * @param {?Object} query Special query parameters for the
  1165. * DELETE API call.
  1166. * @param {Object} [options] Delete options.
  1167. * @param {Function} [options.__unstableFetch] Internal use only. Function to
  1168. * call instead of `apiFetch()`.
  1169. * Must return a control descriptor.
  1170. */
  1171. function* deleteEntityRecord(kind, name, recordId, query, {
  1172. __unstableFetch = null
  1173. } = {}) {
  1174. const entities = yield getKindEntities(kind);
  1175. const entity = Object(external_lodash_["find"])(entities, {
  1176. kind,
  1177. name
  1178. });
  1179. let error;
  1180. let deletedRecord = false;
  1181. if (!entity) {
  1182. return;
  1183. }
  1184. const lock = yield* __unstableAcquireStoreLock('core', ['entities', 'data', kind, name, recordId], {
  1185. exclusive: true
  1186. });
  1187. try {
  1188. yield {
  1189. type: 'DELETE_ENTITY_RECORD_START',
  1190. kind,
  1191. name,
  1192. recordId
  1193. };
  1194. try {
  1195. let path = `${entity.baseURL}/${recordId}`;
  1196. if (query) {
  1197. path = Object(external_wp_url_["addQueryArgs"])(path, query);
  1198. }
  1199. const options = {
  1200. path,
  1201. method: 'DELETE'
  1202. };
  1203. if (__unstableFetch) {
  1204. deletedRecord = yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(__unstableFetch(options));
  1205. } else {
  1206. deletedRecord = yield Object(external_wp_dataControls_["apiFetch"])(options);
  1207. }
  1208. yield removeItems(kind, name, recordId, true);
  1209. } catch (_error) {
  1210. error = _error;
  1211. }
  1212. yield {
  1213. type: 'DELETE_ENTITY_RECORD_FINISH',
  1214. kind,
  1215. name,
  1216. recordId,
  1217. error
  1218. };
  1219. return deletedRecord;
  1220. } finally {
  1221. yield* __unstableReleaseStoreLock(lock);
  1222. }
  1223. }
  1224. /**
  1225. * Returns an action object that triggers an
  1226. * edit to an entity record.
  1227. *
  1228. * @param {string} kind Kind of the edited entity record.
  1229. * @param {string} name Name of the edited entity record.
  1230. * @param {number} recordId Record ID of the edited entity record.
  1231. * @param {Object} edits The edits.
  1232. * @param {Object} options Options for the edit.
  1233. * @param {boolean} options.undoIgnore Whether to ignore the edit in undo history or not.
  1234. *
  1235. * @return {Object} Action object.
  1236. */
  1237. function* actions_editEntityRecord(kind, name, recordId, edits, options = {}) {
  1238. const entity = yield external_wp_data_["controls"].select('core', 'getEntity', kind, name);
  1239. if (!entity) {
  1240. throw new Error(`The entity being edited (${kind}, ${name}) does not have a loaded config.`);
  1241. }
  1242. const {
  1243. transientEdits = {},
  1244. mergedEdits = {}
  1245. } = entity;
  1246. const record = yield external_wp_data_["controls"].select('core', 'getRawEntityRecord', kind, name, recordId);
  1247. const editedRecord = yield external_wp_data_["controls"].select('core', 'getEditedEntityRecord', kind, name, recordId);
  1248. const edit = {
  1249. kind,
  1250. name,
  1251. recordId,
  1252. // Clear edits when they are equal to their persisted counterparts
  1253. // so that the property is not considered dirty.
  1254. edits: Object.keys(edits).reduce((acc, key) => {
  1255. const recordValue = record[key];
  1256. const editedRecordValue = editedRecord[key];
  1257. const value = mergedEdits[key] ? { ...editedRecordValue,
  1258. ...edits[key]
  1259. } : edits[key];
  1260. acc[key] = Object(external_lodash_["isEqual"])(recordValue, value) ? undefined : value;
  1261. return acc;
  1262. }, {}),
  1263. transientEdits
  1264. };
  1265. return {
  1266. type: 'EDIT_ENTITY_RECORD',
  1267. ...edit,
  1268. meta: {
  1269. undo: !options.undoIgnore && { ...edit,
  1270. // Send the current values for things like the first undo stack entry.
  1271. edits: Object.keys(edits).reduce((acc, key) => {
  1272. acc[key] = editedRecord[key];
  1273. return acc;
  1274. }, {})
  1275. }
  1276. }
  1277. };
  1278. }
  1279. /**
  1280. * Action triggered to undo the last edit to
  1281. * an entity record, if any.
  1282. */
  1283. function* undo() {
  1284. const undoEdit = yield external_wp_data_["controls"].select('core', 'getUndoEdit');
  1285. if (!undoEdit) {
  1286. return;
  1287. }
  1288. yield {
  1289. type: 'EDIT_ENTITY_RECORD',
  1290. ...undoEdit,
  1291. meta: {
  1292. isUndo: true
  1293. }
  1294. };
  1295. }
  1296. /**
  1297. * Action triggered to redo the last undoed
  1298. * edit to an entity record, if any.
  1299. */
  1300. function* redo() {
  1301. const redoEdit = yield external_wp_data_["controls"].select('core', 'getRedoEdit');
  1302. if (!redoEdit) {
  1303. return;
  1304. }
  1305. yield {
  1306. type: 'EDIT_ENTITY_RECORD',
  1307. ...redoEdit,
  1308. meta: {
  1309. isRedo: true
  1310. }
  1311. };
  1312. }
  1313. /**
  1314. * Forces the creation of a new undo level.
  1315. *
  1316. * @return {Object} Action object.
  1317. */
  1318. function actions_unstableCreateUndoLevel() {
  1319. return {
  1320. type: 'CREATE_UNDO_LEVEL'
  1321. };
  1322. }
  1323. /**
  1324. * Action triggered to save an entity record.
  1325. *
  1326. * @param {string} kind Kind of the received entity.
  1327. * @param {string} name Name of the received entity.
  1328. * @param {Object} record Record to be saved.
  1329. * @param {Object} options Saving options.
  1330. * @param {boolean} [options.isAutosave=false] Whether this is an autosave.
  1331. * @param {Function} [options.__unstableFetch] Internal use only. Function to
  1332. * call instead of `apiFetch()`.
  1333. * Must return a control
  1334. * descriptor.
  1335. */
  1336. function* saveEntityRecord(kind, name, record, {
  1337. isAutosave = false,
  1338. __unstableFetch = null
  1339. } = {}) {
  1340. const entities = yield getKindEntities(kind);
  1341. const entity = Object(external_lodash_["find"])(entities, {
  1342. kind,
  1343. name
  1344. });
  1345. if (!entity) {
  1346. return;
  1347. }
  1348. const entityIdKey = entity.key || DEFAULT_ENTITY_KEY;
  1349. const recordId = record[entityIdKey];
  1350. const lock = yield* __unstableAcquireStoreLock('core', ['entities', 'data', kind, name, recordId || Object(v4["a" /* default */])()], {
  1351. exclusive: true
  1352. });
  1353. try {
  1354. // Evaluate optimized edits.
  1355. // (Function edits that should be evaluated on save to avoid expensive computations on every edit.)
  1356. for (const [key, value] of Object.entries(record)) {
  1357. if (typeof value === 'function') {
  1358. const evaluatedValue = value(yield external_wp_data_["controls"].select('core', 'getEditedEntityRecord', kind, name, recordId));
  1359. yield actions_editEntityRecord(kind, name, recordId, {
  1360. [key]: evaluatedValue
  1361. }, {
  1362. undoIgnore: true
  1363. });
  1364. record[key] = evaluatedValue;
  1365. }
  1366. }
  1367. yield {
  1368. type: 'SAVE_ENTITY_RECORD_START',
  1369. kind,
  1370. name,
  1371. recordId,
  1372. isAutosave
  1373. };
  1374. let updatedRecord;
  1375. let error;
  1376. try {
  1377. const path = `${entity.baseURL}${recordId ? '/' + recordId : ''}`;
  1378. const persistedRecord = yield external_wp_data_["controls"].select('core', 'getRawEntityRecord', kind, name, recordId);
  1379. if (isAutosave) {
  1380. // Most of this autosave logic is very specific to posts.
  1381. // This is fine for now as it is the only supported autosave,
  1382. // but ideally this should all be handled in the back end,
  1383. // so the client just sends and receives objects.
  1384. const currentUser = yield external_wp_data_["controls"].select('core', 'getCurrentUser');
  1385. const currentUserId = currentUser ? currentUser.id : undefined;
  1386. const autosavePost = yield external_wp_data_["controls"].select('core', 'getAutosave', persistedRecord.type, persistedRecord.id, currentUserId); // Autosaves need all expected fields to be present.
  1387. // So we fallback to the previous autosave and then
  1388. // to the actual persisted entity if the edits don't
  1389. // have a value.
  1390. let data = { ...persistedRecord,
  1391. ...autosavePost,
  1392. ...record
  1393. };
  1394. data = Object.keys(data).reduce((acc, key) => {
  1395. if (['title', 'excerpt', 'content'].includes(key)) {
  1396. // Edits should be the "raw" attribute values.
  1397. acc[key] = Object(external_lodash_["get"])(data[key], 'raw', data[key]);
  1398. }
  1399. return acc;
  1400. }, {
  1401. status: data.status === 'auto-draft' ? 'draft' : data.status
  1402. });
  1403. const options = {
  1404. path: `${path}/autosaves`,
  1405. method: 'POST',
  1406. data
  1407. };
  1408. if (__unstableFetch) {
  1409. updatedRecord = yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(__unstableFetch(options));
  1410. } else {
  1411. updatedRecord = yield Object(external_wp_dataControls_["apiFetch"])(options);
  1412. } // An autosave may be processed by the server as a regular save
  1413. // when its update is requested by the author and the post had
  1414. // draft or auto-draft status.
  1415. if (persistedRecord.id === updatedRecord.id) {
  1416. let newRecord = { ...persistedRecord,
  1417. ...data,
  1418. ...updatedRecord
  1419. };
  1420. newRecord = Object.keys(newRecord).reduce((acc, key) => {
  1421. // These properties are persisted in autosaves.
  1422. if (['title', 'excerpt', 'content'].includes(key)) {
  1423. // Edits should be the "raw" attribute values.
  1424. acc[key] = Object(external_lodash_["get"])(newRecord[key], 'raw', newRecord[key]);
  1425. } else if (key === 'status') {
  1426. // Status is only persisted in autosaves when going from
  1427. // "auto-draft" to "draft".
  1428. acc[key] = persistedRecord.status === 'auto-draft' && newRecord.status === 'draft' ? newRecord.status : persistedRecord.status;
  1429. } else {
  1430. // These properties are not persisted in autosaves.
  1431. acc[key] = Object(external_lodash_["get"])(persistedRecord[key], 'raw', persistedRecord[key]);
  1432. }
  1433. return acc;
  1434. }, {});
  1435. yield receiveEntityRecords(kind, name, newRecord, undefined, true);
  1436. } else {
  1437. yield receiveAutosaves(persistedRecord.id, updatedRecord);
  1438. }
  1439. } else {
  1440. let edits = record;
  1441. if (entity.__unstablePrePersist) {
  1442. edits = { ...edits,
  1443. ...entity.__unstablePrePersist(persistedRecord, edits)
  1444. };
  1445. }
  1446. const options = {
  1447. path,
  1448. method: recordId ? 'PUT' : 'POST',
  1449. data: edits
  1450. };
  1451. if (__unstableFetch) {
  1452. updatedRecord = yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(__unstableFetch(options));
  1453. } else {
  1454. updatedRecord = yield Object(external_wp_dataControls_["apiFetch"])(options);
  1455. }
  1456. yield receiveEntityRecords(kind, name, updatedRecord, undefined, true, edits);
  1457. }
  1458. } catch (_error) {
  1459. error = _error;
  1460. }
  1461. yield {
  1462. type: 'SAVE_ENTITY_RECORD_FINISH',
  1463. kind,
  1464. name,
  1465. recordId,
  1466. error,
  1467. isAutosave
  1468. };
  1469. return updatedRecord;
  1470. } finally {
  1471. yield* __unstableReleaseStoreLock(lock);
  1472. }
  1473. }
  1474. /**
  1475. * Runs multiple core-data actions at the same time using one API request.
  1476. *
  1477. * Example:
  1478. *
  1479. * ```
  1480. * const [ savedRecord, updatedRecord, deletedRecord ] =
  1481. * await dispatch( 'core' ).__experimentalBatch( [
  1482. * ( { saveEntityRecord } ) => saveEntityRecord( 'root', 'widget', widget ),
  1483. * ( { saveEditedEntityRecord } ) => saveEntityRecord( 'root', 'widget', 123 ),
  1484. * ( { deleteEntityRecord } ) => deleteEntityRecord( 'root', 'widget', 123, null ),
  1485. * ] );
  1486. * ```
  1487. *
  1488. * @param {Array} requests Array of functions which are invoked simultaneously.
  1489. * Each function is passed an object containing
  1490. * `saveEntityRecord`, `saveEditedEntityRecord`, and
  1491. * `deleteEntityRecord`.
  1492. *
  1493. * @return {Promise} A promise that resolves to an array containing the return
  1494. * values of each function given in `requests`.
  1495. */
  1496. function* __experimentalBatch(requests) {
  1497. const batch = createBatch();
  1498. const dispatch = yield getDispatch();
  1499. const api = {
  1500. saveEntityRecord(kind, name, record, options) {
  1501. return batch.add(add => dispatch('core').saveEntityRecord(kind, name, record, { ...options,
  1502. __unstableFetch: add
  1503. }));
  1504. },
  1505. saveEditedEntityRecord(kind, name, recordId, options) {
  1506. return batch.add(add => dispatch('core').saveEditedEntityRecord(kind, name, recordId, { ...options,
  1507. __unstableFetch: add
  1508. }));
  1509. },
  1510. deleteEntityRecord(kind, name, recordId, query, options) {
  1511. return batch.add(add => dispatch('core').deleteEntityRecord(kind, name, recordId, query, { ...options,
  1512. __unstableFetch: add
  1513. }));
  1514. }
  1515. };
  1516. const resultPromises = requests.map(request => request(api));
  1517. const [, ...results] = yield Object(external_wp_dataControls_["__unstableAwaitPromise"])(Promise.all([batch.run(), ...resultPromises]));
  1518. return results;
  1519. }
  1520. /**
  1521. * Action triggered to save an entity record's edits.
  1522. *
  1523. * @param {string} kind Kind of the entity.
  1524. * @param {string} name Name of the entity.
  1525. * @param {Object} recordId ID of the record.
  1526. * @param {Object} options Saving options.
  1527. */
  1528. function* saveEditedEntityRecord(kind, name, recordId, options) {
  1529. if (!(yield external_wp_data_["controls"].select('core', 'hasEditsForEntityRecord', kind, name, recordId))) {
  1530. return;
  1531. }
  1532. const edits = yield external_wp_data_["controls"].select('core', 'getEntityRecordNonTransientEdits', kind, name, recordId);
  1533. const record = {
  1534. id: recordId,
  1535. ...edits
  1536. };
  1537. return yield* saveEntityRecord(kind, name, record, options);
  1538. }
  1539. /**
  1540. * Action triggered to save only specified properties for the entity.
  1541. *
  1542. * @param {string} kind Kind of the entity.
  1543. * @param {string} name Name of the entity.
  1544. * @param {Object} recordId ID of the record.
  1545. * @param {Array} itemsToSave List of entity properties to save.
  1546. * @param {Object} options Saving options.
  1547. */
  1548. function* __experimentalSaveSpecifiedEntityEdits(kind, name, recordId, itemsToSave, options) {
  1549. if (!(yield external_wp_data_["controls"].select('core', 'hasEditsForEntityRecord', kind, name, recordId))) {
  1550. return;
  1551. }
  1552. const edits = yield external_wp_data_["controls"].select('core', 'getEntityRecordNonTransientEdits', kind, name, recordId);
  1553. const editsToSave = {};
  1554. for (const edit in edits) {
  1555. if (itemsToSave.some(item => item === edit)) {
  1556. editsToSave[edit] = edits[edit];
  1557. }
  1558. }
  1559. return yield* saveEntityRecord(kind, name, editsToSave, options);
  1560. }
  1561. /**
  1562. * Returns an action object used in signalling that Upload permissions have been received.
  1563. *
  1564. * @param {boolean} hasUploadPermissions Does the user have permission to upload files?
  1565. *
  1566. * @return {Object} Action object.
  1567. */
  1568. function receiveUploadPermissions(hasUploadPermissions) {
  1569. return {
  1570. type: 'RECEIVE_USER_PERMISSION',
  1571. key: 'create/media',
  1572. isAllowed: hasUploadPermissions
  1573. };
  1574. }
  1575. /**
  1576. * Returns an action object used in signalling that the current user has
  1577. * permission to perform an action on a REST resource.
  1578. *
  1579. * @param {string} key A key that represents the action and REST resource.
  1580. * @param {boolean} isAllowed Whether or not the user can perform the action.
  1581. *
  1582. * @return {Object} Action object.
  1583. */
  1584. function receiveUserPermission(key, isAllowed) {
  1585. return {
  1586. type: 'RECEIVE_USER_PERMISSION',
  1587. key,
  1588. isAllowed
  1589. };
  1590. }
  1591. /**
  1592. * Returns an action object used in signalling that the autosaves for a
  1593. * post have been received.
  1594. *
  1595. * @param {number} postId The id of the post that is parent to the autosave.
  1596. * @param {Array|Object} autosaves An array of autosaves or singular autosave object.
  1597. *
  1598. * @return {Object} Action object.
  1599. */
  1600. function receiveAutosaves(postId, autosaves) {
  1601. return {
  1602. type: 'RECEIVE_AUTOSAVES',
  1603. postId,
  1604. autosaves: Object(external_lodash_["castArray"])(autosaves)
  1605. };
  1606. }
  1607. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/entities.js
  1608. /**
  1609. * External dependencies
  1610. */
  1611. /**
  1612. * WordPress dependencies
  1613. */
  1614. /**
  1615. * Internal dependencies
  1616. */
  1617. const DEFAULT_ENTITY_KEY = 'id';
  1618. const defaultEntities = [{
  1619. label: Object(external_wp_i18n_["__"])('Base'),
  1620. name: '__unstableBase',
  1621. kind: 'root',
  1622. baseURL: ''
  1623. }, {
  1624. label: Object(external_wp_i18n_["__"])('Site'),
  1625. name: 'site',
  1626. kind: 'root',
  1627. baseURL: '/wp/v2/settings',
  1628. getTitle: record => {
  1629. return Object(external_lodash_["get"])(record, ['title'], Object(external_wp_i18n_["__"])('Site Title'));
  1630. }
  1631. }, {
  1632. label: Object(external_wp_i18n_["__"])('Post Type'),
  1633. name: 'postType',
  1634. kind: 'root',
  1635. key: 'slug',
  1636. baseURL: '/wp/v2/types',
  1637. baseURLParams: {
  1638. context: 'edit'
  1639. }
  1640. }, {
  1641. name: 'media',
  1642. kind: 'root',
  1643. baseURL: '/wp/v2/media',
  1644. baseURLParams: {
  1645. context: 'edit'
  1646. },
  1647. plural: 'mediaItems',
  1648. label: Object(external_wp_i18n_["__"])('Media')
  1649. }, {
  1650. name: 'taxonomy',
  1651. kind: 'root',
  1652. key: 'slug',
  1653. baseURL: '/wp/v2/taxonomies',
  1654. baseURLParams: {
  1655. context: 'edit'
  1656. },
  1657. plural: 'taxonomies',
  1658. label: Object(external_wp_i18n_["__"])('Taxonomy')
  1659. }, {
  1660. name: 'sidebar',
  1661. kind: 'root',
  1662. baseURL: '/wp/v2/sidebars',
  1663. plural: 'sidebars',
  1664. transientEdits: {
  1665. blocks: true
  1666. },
  1667. label: Object(external_wp_i18n_["__"])('Widget areas')
  1668. }, {
  1669. name: 'widget',
  1670. kind: 'root',
  1671. baseURL: '/wp/v2/widgets',
  1672. baseURLParams: {
  1673. context: 'edit'
  1674. },
  1675. plural: 'widgets',
  1676. transientEdits: {
  1677. blocks: true
  1678. },
  1679. label: Object(external_wp_i18n_["__"])('Widgets')
  1680. }, {
  1681. name: 'widgetType',
  1682. kind: 'root',
  1683. baseURL: '/wp/v2/widget-types',
  1684. baseURLParams: {
  1685. context: 'edit'
  1686. },
  1687. plural: 'widgetTypes',
  1688. label: Object(external_wp_i18n_["__"])('Widget types')
  1689. }, {
  1690. label: Object(external_wp_i18n_["__"])('User'),
  1691. name: 'user',
  1692. kind: 'root',
  1693. baseURL: '/wp/v2/users',
  1694. baseURLParams: {
  1695. context: 'edit'
  1696. },
  1697. plural: 'users'
  1698. }, {
  1699. name: 'comment',
  1700. kind: 'root',
  1701. baseURL: '/wp/v2/comments',
  1702. baseURLParams: {
  1703. context: 'edit'
  1704. },
  1705. plural: 'comments',
  1706. label: Object(external_wp_i18n_["__"])('Comment')
  1707. }, {
  1708. name: 'menu',
  1709. kind: 'root',
  1710. baseURL: '/__experimental/menus',
  1711. baseURLParams: {
  1712. context: 'edit'
  1713. },
  1714. plural: 'menus',
  1715. label: Object(external_wp_i18n_["__"])('Menu')
  1716. }, {
  1717. name: 'menuItem',
  1718. kind: 'root',
  1719. baseURL: '/__experimental/menu-items',
  1720. baseURLParams: {
  1721. context: 'edit'
  1722. },
  1723. plural: 'menuItems',
  1724. label: Object(external_wp_i18n_["__"])('Menu Item')
  1725. }, {
  1726. name: 'menuLocation',
  1727. kind: 'root',
  1728. baseURL: '/__experimental/menu-locations',
  1729. baseURLParams: {
  1730. context: 'edit'
  1731. },
  1732. plural: 'menuLocations',
  1733. label: Object(external_wp_i18n_["__"])('Menu Location'),
  1734. key: 'name'
  1735. }];
  1736. const kinds = [{
  1737. name: 'postType',
  1738. loadEntities: loadPostTypeEntities
  1739. }, {
  1740. name: 'taxonomy',
  1741. loadEntities: loadTaxonomyEntities
  1742. }];
  1743. /**
  1744. * Returns a function to be used to retrieve extra edits to apply before persisting a post type.
  1745. *
  1746. * @param {Object} persistedRecord Already persisted Post
  1747. * @param {Object} edits Edits.
  1748. * @return {Object} Updated edits.
  1749. */
  1750. const prePersistPostType = (persistedRecord, edits) => {
  1751. const newEdits = {};
  1752. if ((persistedRecord === null || persistedRecord === void 0 ? void 0 : persistedRecord.status) === 'auto-draft') {
  1753. // Saving an auto-draft should create a draft by default.
  1754. if (!edits.status && !newEdits.status) {
  1755. newEdits.status = 'draft';
  1756. } // Fix the auto-draft default title.
  1757. if ((!edits.title || edits.title === 'Auto Draft') && !newEdits.title && (!(persistedRecord !== null && persistedRecord !== void 0 && persistedRecord.title) || (persistedRecord === null || persistedRecord === void 0 ? void 0 : persistedRecord.title) === 'Auto Draft')) {
  1758. newEdits.title = '';
  1759. }
  1760. }
  1761. return newEdits;
  1762. };
  1763. /**
  1764. * Returns the list of post type entities.
  1765. *
  1766. * @return {Promise} Entities promise
  1767. */
  1768. function* loadPostTypeEntities() {
  1769. const postTypes = yield Object(external_wp_dataControls_["apiFetch"])({
  1770. path: '/wp/v2/types?context=edit'
  1771. });
  1772. return Object(external_lodash_["map"])(postTypes, (postType, name) => {
  1773. const isTemplate = ['wp_template', 'wp_template_part'].includes(name);
  1774. return {
  1775. kind: 'postType',
  1776. baseURL: '/wp/v2/' + postType.rest_base,
  1777. baseURLParams: {
  1778. context: 'edit'
  1779. },
  1780. name,
  1781. label: postType.labels.singular_name,
  1782. transientEdits: {
  1783. blocks: true,
  1784. selection: true
  1785. },
  1786. mergedEdits: {
  1787. meta: true
  1788. },
  1789. getTitle: record => {
  1790. var _record$title;
  1791. return (record === null || record === void 0 ? void 0 : (_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) || (record === null || record === void 0 ? void 0 : record.title) || (isTemplate ? Object(external_lodash_["startCase"])(record.slug) : String(record.id));
  1792. },
  1793. __unstablePrePersist: isTemplate ? undefined : prePersistPostType,
  1794. __unstable_rest_base: postType.rest_base
  1795. };
  1796. });
  1797. }
  1798. /**
  1799. * Returns the list of the taxonomies entities.
  1800. *
  1801. * @return {Promise} Entities promise
  1802. */
  1803. function* loadTaxonomyEntities() {
  1804. const taxonomies = yield Object(external_wp_dataControls_["apiFetch"])({
  1805. path: '/wp/v2/taxonomies?context=edit'
  1806. });
  1807. return Object(external_lodash_["map"])(taxonomies, (taxonomy, name) => {
  1808. return {
  1809. kind: 'taxonomy',
  1810. baseURL: '/wp/v2/' + taxonomy.rest_base,
  1811. baseURLParams: {
  1812. context: 'edit'
  1813. },
  1814. name,
  1815. label: taxonomy.labels.singular_name
  1816. };
  1817. });
  1818. }
  1819. /**
  1820. * Returns the entity's getter method name given its kind and name.
  1821. *
  1822. * @param {string} kind Entity kind.
  1823. * @param {string} name Entity name.
  1824. * @param {string} prefix Function prefix.
  1825. * @param {boolean} usePlural Whether to use the plural form or not.
  1826. *
  1827. * @return {string} Method name
  1828. */
  1829. const getMethodName = (kind, name, prefix = 'get', usePlural = false) => {
  1830. const entity = Object(external_lodash_["find"])(defaultEntities, {
  1831. kind,
  1832. name
  1833. });
  1834. const kindPrefix = kind === 'root' ? '' : Object(external_lodash_["upperFirst"])(Object(external_lodash_["camelCase"])(kind));
  1835. const nameSuffix = Object(external_lodash_["upperFirst"])(Object(external_lodash_["camelCase"])(name)) + (usePlural ? 's' : '');
  1836. const suffix = usePlural && entity.plural ? Object(external_lodash_["upperFirst"])(Object(external_lodash_["camelCase"])(entity.plural)) : nameSuffix;
  1837. return `${prefix}${kindPrefix}${suffix}`;
  1838. };
  1839. /**
  1840. * Loads the kind entities into the store.
  1841. *
  1842. * @param {string} kind Kind
  1843. *
  1844. * @return {Array} Entities
  1845. */
  1846. function* getKindEntities(kind) {
  1847. let entities = yield external_wp_data_["controls"].select('core', 'getEntitiesByKind', kind);
  1848. if (entities && entities.length !== 0) {
  1849. return entities;
  1850. }
  1851. const kindConfig = Object(external_lodash_["find"])(kinds, {
  1852. name: kind
  1853. });
  1854. if (!kindConfig) {
  1855. return [];
  1856. }
  1857. entities = yield kindConfig.loadEntities();
  1858. yield addEntities(entities);
  1859. return entities;
  1860. }
  1861. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/get-normalized-comma-separable.js
  1862. /**
  1863. * Given a value which can be specified as one or the other of a comma-separated
  1864. * string or an array, returns a value normalized to an array of strings, or
  1865. * null if the value cannot be interpreted as either.
  1866. *
  1867. * @param {string|string[]|*} value
  1868. *
  1869. * @return {?(string[])} Normalized field value.
  1870. */
  1871. function getNormalizedCommaSeparable(value) {
  1872. if (typeof value === 'string') {
  1873. return value.split(',');
  1874. } else if (Array.isArray(value)) {
  1875. return value;
  1876. }
  1877. return null;
  1878. }
  1879. /* harmony default export */ var get_normalized_comma_separable = (getNormalizedCommaSeparable);
  1880. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/with-weak-map-cache.js
  1881. /**
  1882. * External dependencies
  1883. */
  1884. /**
  1885. * Given a function, returns an enhanced function which caches the result and
  1886. * tracks in WeakMap. The result is only cached if the original function is
  1887. * passed a valid object-like argument (requirement for WeakMap key).
  1888. *
  1889. * @param {Function} fn Original function.
  1890. *
  1891. * @return {Function} Enhanced caching function.
  1892. */
  1893. function withWeakMapCache(fn) {
  1894. const cache = new WeakMap();
  1895. return key => {
  1896. let value;
  1897. if (cache.has(key)) {
  1898. value = cache.get(key);
  1899. } else {
  1900. value = fn(key); // Can reach here if key is not valid for WeakMap, since `has`
  1901. // will return false for invalid key. Since `set` will throw,
  1902. // ensure that key is valid before setting into cache.
  1903. if (Object(external_lodash_["isObjectLike"])(key)) {
  1904. cache.set(key, value);
  1905. }
  1906. }
  1907. return value;
  1908. };
  1909. }
  1910. /* harmony default export */ var with_weak_map_cache = (withWeakMapCache);
  1911. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/get-query-parts.js
  1912. /**
  1913. * WordPress dependencies
  1914. */
  1915. /**
  1916. * Internal dependencies
  1917. */
  1918. /**
  1919. * An object of properties describing a specific query.
  1920. *
  1921. * @typedef {Object} WPQueriedDataQueryParts
  1922. *
  1923. * @property {number} page The query page (1-based index, default 1).
  1924. * @property {number} perPage Items per page for query (default 10).
  1925. * @property {string} stableKey An encoded stable string of all non-
  1926. * pagination, non-fields query parameters.
  1927. * @property {?(string[])} fields Target subset of fields to derive from
  1928. * item objects.
  1929. * @property {?(number[])} include Specific item IDs to include.
  1930. */
  1931. /**
  1932. * Given a query object, returns an object of parts, including pagination
  1933. * details (`page` and `perPage`, or default values). All other properties are
  1934. * encoded into a stable (idempotent) `stableKey` value.
  1935. *
  1936. * @param {Object} query Optional query object.
  1937. *
  1938. * @return {WPQueriedDataQueryParts} Query parts.
  1939. */
  1940. function getQueryParts(query) {
  1941. /**
  1942. * @type {WPQueriedDataQueryParts}
  1943. */
  1944. const parts = {
  1945. stableKey: '',
  1946. page: 1,
  1947. perPage: 10,
  1948. fields: null,
  1949. include: null,
  1950. context: 'default'
  1951. }; // Ensure stable key by sorting keys. Also more efficient for iterating.
  1952. const keys = Object.keys(query).sort();
  1953. for (let i = 0; i < keys.length; i++) {
  1954. const key = keys[i];
  1955. let value = query[key];
  1956. switch (key) {
  1957. case 'page':
  1958. parts[key] = Number(value);
  1959. break;
  1960. case 'per_page':
  1961. parts.perPage = Number(value);
  1962. break;
  1963. case 'include':
  1964. parts.include = get_normalized_comma_separable(value).map(Number);
  1965. break;
  1966. case 'context':
  1967. parts.context = value;
  1968. break;
  1969. default:
  1970. // While in theory, we could exclude "_fields" from the stableKey
  1971. // because two request with different fields have the same results
  1972. // We're not able to ensure that because the server can decide to omit
  1973. // fields from the response even if we explicitely asked for it.
  1974. // Example: Asking for titles in posts without title support.
  1975. if (key === '_fields') {
  1976. parts.fields = get_normalized_comma_separable(value); // Make sure to normalize value for `stableKey`
  1977. value = parts.fields.join();
  1978. } // While it could be any deterministic string, for simplicity's
  1979. // sake mimic querystring encoding for stable key.
  1980. //
  1981. // TODO: For consistency with PHP implementation, addQueryArgs
  1982. // should accept a key value pair, which may optimize its
  1983. // implementation for our use here, vs. iterating an object
  1984. // with only a single key.
  1985. parts.stableKey += (parts.stableKey ? '&' : '') + Object(external_wp_url_["addQueryArgs"])('', {
  1986. [key]: value
  1987. }).slice(1);
  1988. }
  1989. }
  1990. return parts;
  1991. }
  1992. /* harmony default export */ var get_query_parts = (with_weak_map_cache(getQueryParts));
  1993. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/reducer.js
  1994. /**
  1995. * External dependencies
  1996. */
  1997. /**
  1998. * WordPress dependencies
  1999. */
  2000. /**
  2001. * Internal dependencies
  2002. */
  2003. function getContextFromAction(action) {
  2004. const {
  2005. query
  2006. } = action;
  2007. if (!query) {
  2008. return 'default';
  2009. }
  2010. const queryParts = get_query_parts(query);
  2011. return queryParts.context;
  2012. }
  2013. /**
  2014. * Returns a merged array of item IDs, given details of the received paginated
  2015. * items. The array is sparse-like with `undefined` entries where holes exist.
  2016. *
  2017. * @param {?Array<number>} itemIds Original item IDs (default empty array).
  2018. * @param {number[]} nextItemIds Item IDs to merge.
  2019. * @param {number} page Page of items merged.
  2020. * @param {number} perPage Number of items per page.
  2021. *
  2022. * @return {number[]} Merged array of item IDs.
  2023. */
  2024. function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
  2025. const receivedAllIds = page === 1 && perPage === -1;
  2026. if (receivedAllIds) {
  2027. return nextItemIds;
  2028. }
  2029. const nextItemIdsStartIndex = (page - 1) * perPage; // If later page has already been received, default to the larger known
  2030. // size of the existing array, else calculate as extending the existing.
  2031. const size = Math.max(itemIds.length, nextItemIdsStartIndex + nextItemIds.length); // Preallocate array since size is known.
  2032. const mergedItemIds = new Array(size);
  2033. for (let i = 0; i < size; i++) {
  2034. // Preserve existing item ID except for subset of range of next items.
  2035. const isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + nextItemIds.length;
  2036. mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds[i];
  2037. }
  2038. return mergedItemIds;
  2039. }
  2040. /**
  2041. * Reducer tracking items state, keyed by ID. Items are assumed to be normal,
  2042. * where identifiers are common across all queries.
  2043. *
  2044. * @param {Object} state Current state.
  2045. * @param {Object} action Dispatched action.
  2046. *
  2047. * @return {Object} Next state.
  2048. */
  2049. function reducer_items(state = {}, action) {
  2050. switch (action.type) {
  2051. case 'RECEIVE_ITEMS':
  2052. {
  2053. const context = getContextFromAction(action);
  2054. const key = action.key || DEFAULT_ENTITY_KEY;
  2055. return { ...state,
  2056. [context]: { ...state[context],
  2057. ...action.items.reduce((accumulator, value) => {
  2058. var _state$context;
  2059. const itemId = value[key];
  2060. accumulator[itemId] = conservativeMapItem(state === null || state === void 0 ? void 0 : (_state$context = state[context]) === null || _state$context === void 0 ? void 0 : _state$context[itemId], value);
  2061. return accumulator;
  2062. }, {})
  2063. }
  2064. };
  2065. }
  2066. case 'REMOVE_ITEMS':
  2067. return Object(external_lodash_["mapValues"])(state, contextState => Object(external_lodash_["omit"])(contextState, action.itemIds));
  2068. }
  2069. return state;
  2070. }
  2071. /**
  2072. * Reducer tracking item completeness, keyed by ID. A complete item is one for
  2073. * which all fields are known. This is used in supporting `_fields` queries,
  2074. * where not all properties associated with an entity are necessarily returned.
  2075. * In such cases, completeness is used as an indication of whether it would be
  2076. * safe to use queried data for a non-`_fields`-limited request.
  2077. *
  2078. * @param {Object<string,boolean>} state Current state.
  2079. * @param {Object} action Dispatched action.
  2080. *
  2081. * @return {Object<string,boolean>} Next state.
  2082. */
  2083. function itemIsComplete(state = {}, action) {
  2084. switch (action.type) {
  2085. case 'RECEIVE_ITEMS':
  2086. {
  2087. const context = getContextFromAction(action);
  2088. const {
  2089. query,
  2090. key = DEFAULT_ENTITY_KEY
  2091. } = action; // An item is considered complete if it is received without an associated
  2092. // fields query. Ideally, this would be implemented in such a way where the
  2093. // complete aggregate of all fields would satisfy completeness. Since the
  2094. // fields are not consistent across all entity types, this would require
  2095. // introspection on the REST schema for each entity to know which fields
  2096. // compose a complete item for that entity.
  2097. const queryParts = query ? get_query_parts(query) : {};
  2098. const isCompleteQuery = !query || !Array.isArray(queryParts.fields);
  2099. return { ...state,
  2100. [context]: { ...state[context],
  2101. ...action.items.reduce((result, item) => {
  2102. var _state$context2;
  2103. const itemId = item[key]; // Defer to completeness if already assigned. Technically the
  2104. // data may be outdated if receiving items for a field subset.
  2105. result[itemId] = (state === null || state === void 0 ? void 0 : (_state$context2 = state[context]) === null || _state$context2 === void 0 ? void 0 : _state$context2[itemId]) || isCompleteQuery;
  2106. return result;
  2107. }, {})
  2108. }
  2109. };
  2110. }
  2111. case 'REMOVE_ITEMS':
  2112. return Object(external_lodash_["mapValues"])(state, contextState => Object(external_lodash_["omit"])(contextState, action.itemIds));
  2113. }
  2114. return state;
  2115. }
  2116. /**
  2117. * Reducer tracking queries state, keyed by stable query key. Each reducer
  2118. * query object includes `itemIds` and `requestingPageByPerPage`.
  2119. *
  2120. * @param {Object} state Current state.
  2121. * @param {Object} action Dispatched action.
  2122. *
  2123. * @return {Object} Next state.
  2124. */
  2125. const receiveQueries = Object(external_lodash_["flowRight"])([// Limit to matching action type so we don't attempt to replace action on
  2126. // an unhandled action.
  2127. if_matching_action(action => 'query' in action), // Inject query parts into action for use both in `onSubKey` and reducer.
  2128. replace_action(action => {
  2129. // `ifMatchingAction` still passes on initialization, where state is
  2130. // undefined and a query is not assigned. Avoid attempting to parse
  2131. // parts. `onSubKey` will omit by lack of `stableKey`.
  2132. if (action.query) {
  2133. return { ...action,
  2134. ...get_query_parts(action.query)
  2135. };
  2136. }
  2137. return action;
  2138. }), on_sub_key('context'), // Queries shape is shared, but keyed by query `stableKey` part. Original
  2139. // reducer tracks only a single query object.
  2140. on_sub_key('stableKey')])((state = null, action) => {
  2141. const {
  2142. type,
  2143. page,
  2144. perPage,
  2145. key = DEFAULT_ENTITY_KEY
  2146. } = action;
  2147. if (type !== 'RECEIVE_ITEMS') {
  2148. return state;
  2149. }
  2150. return getMergedItemIds(state || [], Object(external_lodash_["map"])(action.items, key), page, perPage);
  2151. });
  2152. /**
  2153. * Reducer tracking queries state.
  2154. *
  2155. * @param {Object} state Current state.
  2156. * @param {Object} action Dispatched action.
  2157. *
  2158. * @return {Object} Next state.
  2159. */
  2160. const reducer_queries = (state = {}, action) => {
  2161. switch (action.type) {
  2162. case 'RECEIVE_ITEMS':
  2163. return receiveQueries(state, action);
  2164. case 'REMOVE_ITEMS':
  2165. const removedItems = action.itemIds.reduce((result, itemId) => {
  2166. result[itemId] = true;
  2167. return result;
  2168. }, {});
  2169. return Object(external_lodash_["mapValues"])(state, contextQueries => {
  2170. return Object(external_lodash_["mapValues"])(contextQueries, queryItems => {
  2171. return Object(external_lodash_["filter"])(queryItems, queryId => {
  2172. return !removedItems[queryId];
  2173. });
  2174. });
  2175. });
  2176. default:
  2177. return state;
  2178. }
  2179. };
  2180. /* harmony default export */ var reducer = (Object(external_wp_data_["combineReducers"])({
  2181. items: reducer_items,
  2182. itemIsComplete,
  2183. queries: reducer_queries
  2184. }));
  2185. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/utils.js
  2186. function deepCopyLocksTreePath(tree, path) {
  2187. const newTree = { ...tree
  2188. };
  2189. let currentNode = newTree;
  2190. for (const branchName of path) {
  2191. currentNode.children = { ...currentNode.children,
  2192. [branchName]: {
  2193. locks: [],
  2194. children: {},
  2195. ...currentNode.children[branchName]
  2196. }
  2197. };
  2198. currentNode = currentNode.children[branchName];
  2199. }
  2200. return newTree;
  2201. }
  2202. function getNode(tree, path) {
  2203. let currentNode = tree;
  2204. for (const branchName of path) {
  2205. const nextNode = currentNode.children[branchName];
  2206. if (!nextNode) {
  2207. return null;
  2208. }
  2209. currentNode = nextNode;
  2210. }
  2211. return currentNode;
  2212. }
  2213. function* iteratePath(tree, path) {
  2214. let currentNode = tree;
  2215. yield currentNode;
  2216. for (const branchName of path) {
  2217. const nextNode = currentNode.children[branchName];
  2218. if (!nextNode) {
  2219. break;
  2220. }
  2221. yield nextNode;
  2222. currentNode = nextNode;
  2223. }
  2224. }
  2225. function* iterateDescendants(node) {
  2226. const stack = Object.values(node.children);
  2227. while (stack.length) {
  2228. const childNode = stack.pop();
  2229. yield childNode;
  2230. stack.push(...Object.values(childNode.children));
  2231. }
  2232. }
  2233. function hasConflictingLock({
  2234. exclusive
  2235. }, locks) {
  2236. if (exclusive && locks.length) {
  2237. return true;
  2238. }
  2239. if (!exclusive && locks.filter(lock => lock.exclusive).length) {
  2240. return true;
  2241. }
  2242. return false;
  2243. }
  2244. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/reducer.js
  2245. /**
  2246. * Internal dependencies
  2247. */
  2248. const DEFAULT_STATE = {
  2249. requests: [],
  2250. tree: {
  2251. locks: [],
  2252. children: {}
  2253. }
  2254. };
  2255. /**
  2256. * Reducer returning locks.
  2257. *
  2258. * @param {Object} state Current state.
  2259. * @param {Object} action Dispatched action.
  2260. *
  2261. * @return {Object} Updated state.
  2262. */
  2263. function reducer_locks(state = DEFAULT_STATE, action) {
  2264. switch (action.type) {
  2265. case 'ENQUEUE_LOCK_REQUEST':
  2266. {
  2267. const {
  2268. request
  2269. } = action;
  2270. return { ...state,
  2271. requests: [request, ...state.requests]
  2272. };
  2273. }
  2274. case 'GRANT_LOCK_REQUEST':
  2275. {
  2276. const {
  2277. lock,
  2278. request
  2279. } = action;
  2280. const {
  2281. store,
  2282. path
  2283. } = request;
  2284. const storePath = [store, ...path];
  2285. const newTree = deepCopyLocksTreePath(state.tree, storePath);
  2286. const node = getNode(newTree, storePath);
  2287. node.locks = [...node.locks, lock];
  2288. return { ...state,
  2289. requests: state.requests.filter(r => r !== request),
  2290. tree: newTree
  2291. };
  2292. }
  2293. case 'RELEASE_LOCK':
  2294. {
  2295. const {
  2296. lock
  2297. } = action;
  2298. const storePath = [lock.store, ...lock.path];
  2299. const newTree = deepCopyLocksTreePath(state.tree, storePath);
  2300. const node = getNode(newTree, storePath);
  2301. node.locks = node.locks.filter(l => l !== lock);
  2302. return { ...state,
  2303. tree: newTree
  2304. };
  2305. }
  2306. }
  2307. return state;
  2308. }
  2309. /* harmony default export */ var locks_reducer = (reducer_locks);
  2310. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/reducer.js
  2311. /**
  2312. * External dependencies
  2313. */
  2314. /**
  2315. * WordPress dependencies
  2316. */
  2317. /**
  2318. * Internal dependencies
  2319. */
  2320. /**
  2321. * Reducer managing terms state. Keyed by taxonomy slug, the value is either
  2322. * undefined (if no request has been made for given taxonomy), null (if a
  2323. * request is in-flight for given taxonomy), or the array of terms for the
  2324. * taxonomy.
  2325. *
  2326. * @param {Object} state Current state.
  2327. * @param {Object} action Dispatched action.
  2328. *
  2329. * @return {Object} Updated state.
  2330. */
  2331. function terms(state = {}, action) {
  2332. switch (action.type) {
  2333. case 'RECEIVE_TERMS':
  2334. return { ...state,
  2335. [action.taxonomy]: action.terms
  2336. };
  2337. }
  2338. return state;
  2339. }
  2340. /**
  2341. * Reducer managing authors state. Keyed by id.
  2342. *
  2343. * @param {Object} state Current state.
  2344. * @param {Object} action Dispatched action.
  2345. *
  2346. * @return {Object} Updated state.
  2347. */
  2348. function reducer_users(state = {
  2349. byId: {},
  2350. queries: {}
  2351. }, action) {
  2352. switch (action.type) {
  2353. case 'RECEIVE_USER_QUERY':
  2354. return {
  2355. byId: { ...state.byId,
  2356. ...Object(external_lodash_["keyBy"])(action.users, 'id')
  2357. },
  2358. queries: { ...state.queries,
  2359. [action.queryID]: Object(external_lodash_["map"])(action.users, user => user.id)
  2360. }
  2361. };
  2362. }
  2363. return state;
  2364. }
  2365. /**
  2366. * Reducer managing current user state.
  2367. *
  2368. * @param {Object} state Current state.
  2369. * @param {Object} action Dispatched action.
  2370. *
  2371. * @return {Object} Updated state.
  2372. */
  2373. function reducer_currentUser(state = {}, action) {
  2374. switch (action.type) {
  2375. case 'RECEIVE_CURRENT_USER':
  2376. return action.currentUser;
  2377. }
  2378. return state;
  2379. }
  2380. /**
  2381. * Reducer managing taxonomies.
  2382. *
  2383. * @param {Object} state Current state.
  2384. * @param {Object} action Dispatched action.
  2385. *
  2386. * @return {Object} Updated state.
  2387. */
  2388. function reducer_taxonomies(state = [], action) {
  2389. switch (action.type) {
  2390. case 'RECEIVE_TAXONOMIES':
  2391. return action.taxonomies;
  2392. }
  2393. return state;
  2394. }
  2395. /**
  2396. * Reducer managing the current theme.
  2397. *
  2398. * @param {string} state Current state.
  2399. * @param {Object} action Dispatched action.
  2400. *
  2401. * @return {string} Updated state.
  2402. */
  2403. function currentTheme(state = undefined, action) {
  2404. switch (action.type) {
  2405. case 'RECEIVE_CURRENT_THEME':
  2406. return action.currentTheme.stylesheet;
  2407. }
  2408. return state;
  2409. }
  2410. /**
  2411. * Reducer managing installed themes.
  2412. *
  2413. * @param {Object} state Current state.
  2414. * @param {Object} action Dispatched action.
  2415. *
  2416. * @return {Object} Updated state.
  2417. */
  2418. function themes(state = {}, action) {
  2419. switch (action.type) {
  2420. case 'RECEIVE_CURRENT_THEME':
  2421. return { ...state,
  2422. [action.currentTheme.stylesheet]: action.currentTheme
  2423. };
  2424. }
  2425. return state;
  2426. }
  2427. /**
  2428. * Reducer managing theme supports data.
  2429. *
  2430. * @param {Object} state Current state.
  2431. * @param {Object} action Dispatched action.
  2432. *
  2433. * @return {Object} Updated state.
  2434. */
  2435. function themeSupports(state = {}, action) {
  2436. switch (action.type) {
  2437. case 'RECEIVE_THEME_SUPPORTS':
  2438. return { ...state,
  2439. ...action.themeSupports
  2440. };
  2441. }
  2442. return state;
  2443. }
  2444. /**
  2445. * Higher Order Reducer for a given entity config. It supports:
  2446. *
  2447. * - Fetching
  2448. * - Editing
  2449. * - Saving
  2450. *
  2451. * @param {Object} entityConfig Entity config.
  2452. *
  2453. * @return {Function} Reducer.
  2454. */
  2455. function reducer_entity(entityConfig) {
  2456. return Object(external_lodash_["flowRight"])([// Limit to matching action type so we don't attempt to replace action on
  2457. // an unhandled action.
  2458. if_matching_action(action => action.name && action.kind && action.name === entityConfig.name && action.kind === entityConfig.kind), // Inject the entity config into the action.
  2459. replace_action(action => {
  2460. return { ...action,
  2461. key: entityConfig.key || DEFAULT_ENTITY_KEY
  2462. };
  2463. })])(Object(external_wp_data_["combineReducers"])({
  2464. queriedData: reducer,
  2465. edits: (state = {}, action) => {
  2466. var _action$query$context, _action$query;
  2467. switch (action.type) {
  2468. case 'RECEIVE_ITEMS':
  2469. const context = (_action$query$context = action === null || action === void 0 ? void 0 : (_action$query = action.query) === null || _action$query === void 0 ? void 0 : _action$query.context) !== null && _action$query$context !== void 0 ? _action$query$context : 'default';
  2470. if (context !== 'default') {
  2471. return state;
  2472. }
  2473. const nextState = { ...state
  2474. };
  2475. for (const record of action.items) {
  2476. const recordId = record[action.key];
  2477. const edits = nextState[recordId];
  2478. if (!edits) {
  2479. continue;
  2480. }
  2481. const nextEdits = Object.keys(edits).reduce((acc, key) => {
  2482. // If the edited value is still different to the persisted value,
  2483. // keep the edited value in edits.
  2484. if ( // Edits are the "raw" attribute values, but records may have
  2485. // objects with more properties, so we use `get` here for the
  2486. // comparison.
  2487. !Object(external_lodash_["isEqual"])(edits[key], Object(external_lodash_["get"])(record[key], 'raw', record[key])) && ( // Sometimes the server alters the sent value which means
  2488. // we need to also remove the edits before the api request.
  2489. !action.persistedEdits || !Object(external_lodash_["isEqual"])(edits[key], action.persistedEdits[key]))) {
  2490. acc[key] = edits[key];
  2491. }
  2492. return acc;
  2493. }, {});
  2494. if (Object.keys(nextEdits).length) {
  2495. nextState[recordId] = nextEdits;
  2496. } else {
  2497. delete nextState[recordId];
  2498. }
  2499. }
  2500. return nextState;
  2501. case 'EDIT_ENTITY_RECORD':
  2502. const nextEdits = { ...state[action.recordId],
  2503. ...action.edits
  2504. };
  2505. Object.keys(nextEdits).forEach(key => {
  2506. // Delete cleared edits so that the properties
  2507. // are not considered dirty.
  2508. if (nextEdits[key] === undefined) {
  2509. delete nextEdits[key];
  2510. }
  2511. });
  2512. return { ...state,
  2513. [action.recordId]: nextEdits
  2514. };
  2515. }
  2516. return state;
  2517. },
  2518. saving: (state = {}, action) => {
  2519. switch (action.type) {
  2520. case 'SAVE_ENTITY_RECORD_START':
  2521. case 'SAVE_ENTITY_RECORD_FINISH':
  2522. return { ...state,
  2523. [action.recordId]: {
  2524. pending: action.type === 'SAVE_ENTITY_RECORD_START',
  2525. error: action.error,
  2526. isAutosave: action.isAutosave
  2527. }
  2528. };
  2529. }
  2530. return state;
  2531. },
  2532. deleting: (state = {}, action) => {
  2533. switch (action.type) {
  2534. case 'DELETE_ENTITY_RECORD_START':
  2535. case 'DELETE_ENTITY_RECORD_FINISH':
  2536. return { ...state,
  2537. [action.recordId]: {
  2538. pending: action.type === 'DELETE_ENTITY_RECORD_START',
  2539. error: action.error
  2540. }
  2541. };
  2542. }
  2543. return state;
  2544. }
  2545. }));
  2546. }
  2547. /**
  2548. * Reducer keeping track of the registered entities.
  2549. *
  2550. * @param {Object} state Current state.
  2551. * @param {Object} action Dispatched action.
  2552. *
  2553. * @return {Object} Updated state.
  2554. */
  2555. function entitiesConfig(state = defaultEntities, action) {
  2556. switch (action.type) {
  2557. case 'ADD_ENTITIES':
  2558. return [...state, ...action.entities];
  2559. }
  2560. return state;
  2561. }
  2562. /**
  2563. * Reducer keeping track of the registered entities config and data.
  2564. *
  2565. * @param {Object} state Current state.
  2566. * @param {Object} action Dispatched action.
  2567. *
  2568. * @return {Object} Updated state.
  2569. */
  2570. const reducer_entities = (state = {}, action) => {
  2571. const newConfig = entitiesConfig(state.config, action); // Generates a dynamic reducer for the entities
  2572. let entitiesDataReducer = state.reducer;
  2573. if (!entitiesDataReducer || newConfig !== state.config) {
  2574. const entitiesByKind = Object(external_lodash_["groupBy"])(newConfig, 'kind');
  2575. entitiesDataReducer = Object(external_wp_data_["combineReducers"])(Object.entries(entitiesByKind).reduce((memo, [kind, subEntities]) => {
  2576. const kindReducer = Object(external_wp_data_["combineReducers"])(subEntities.reduce((kindMemo, entityConfig) => ({ ...kindMemo,
  2577. [entityConfig.name]: reducer_entity(entityConfig)
  2578. }), {}));
  2579. memo[kind] = kindReducer;
  2580. return memo;
  2581. }, {}));
  2582. }
  2583. const newData = entitiesDataReducer(state.data, action);
  2584. if (newData === state.data && newConfig === state.config && entitiesDataReducer === state.reducer) {
  2585. return state;
  2586. }
  2587. return {
  2588. reducer: entitiesDataReducer,
  2589. data: newData,
  2590. config: newConfig
  2591. };
  2592. };
  2593. /**
  2594. * Reducer keeping track of entity edit undo history.
  2595. *
  2596. * @param {Object} state Current state.
  2597. * @param {Object} action Dispatched action.
  2598. *
  2599. * @return {Object} Updated state.
  2600. */
  2601. const UNDO_INITIAL_STATE = [];
  2602. UNDO_INITIAL_STATE.offset = 0;
  2603. let lastEditAction;
  2604. function reducer_undo(state = UNDO_INITIAL_STATE, action) {
  2605. switch (action.type) {
  2606. case 'EDIT_ENTITY_RECORD':
  2607. case 'CREATE_UNDO_LEVEL':
  2608. let isCreateUndoLevel = action.type === 'CREATE_UNDO_LEVEL';
  2609. const isUndoOrRedo = !isCreateUndoLevel && (action.meta.isUndo || action.meta.isRedo);
  2610. if (isCreateUndoLevel) {
  2611. action = lastEditAction;
  2612. } else if (!isUndoOrRedo) {
  2613. // Don't lose the last edit cache if the new one only has transient edits.
  2614. // Transient edits don't create new levels so updating the cache would make
  2615. // us skip an edit later when creating levels explicitly.
  2616. if (Object.keys(action.edits).some(key => !action.transientEdits[key])) {
  2617. lastEditAction = action;
  2618. } else {
  2619. lastEditAction = { ...action,
  2620. edits: { ...(lastEditAction && lastEditAction.edits),
  2621. ...action.edits
  2622. }
  2623. };
  2624. }
  2625. }
  2626. let nextState;
  2627. if (isUndoOrRedo) {
  2628. nextState = [...state];
  2629. nextState.offset = state.offset + (action.meta.isUndo ? -1 : 1);
  2630. if (state.flattenedUndo) {
  2631. // The first undo in a sequence of undos might happen while we have
  2632. // flattened undos in state. If this is the case, we want execution
  2633. // to continue as if we were creating an explicit undo level. This
  2634. // will result in an extra undo level being appended with the flattened
  2635. // undo values.
  2636. isCreateUndoLevel = true;
  2637. action = lastEditAction;
  2638. } else {
  2639. return nextState;
  2640. }
  2641. }
  2642. if (!action.meta.undo) {
  2643. return state;
  2644. } // Transient edits don't create an undo level, but are
  2645. // reachable in the next meaningful edit to which they
  2646. // are merged. They are defined in the entity's config.
  2647. if (!isCreateUndoLevel && !Object.keys(action.edits).some(key => !action.transientEdits[key])) {
  2648. nextState = [...state];
  2649. nextState.flattenedUndo = { ...state.flattenedUndo,
  2650. ...action.edits
  2651. };
  2652. nextState.offset = state.offset;
  2653. return nextState;
  2654. } // Clear potential redos, because this only supports linear history.
  2655. nextState = nextState || state.slice(0, state.offset || undefined);
  2656. nextState.offset = nextState.offset || 0;
  2657. nextState.pop();
  2658. if (!isCreateUndoLevel) {
  2659. nextState.push({
  2660. kind: action.meta.undo.kind,
  2661. name: action.meta.undo.name,
  2662. recordId: action.meta.undo.recordId,
  2663. edits: { ...state.flattenedUndo,
  2664. ...action.meta.undo.edits
  2665. }
  2666. });
  2667. } // When an edit is a function it's an optimization to avoid running some expensive operation.
  2668. // We can't rely on the function references being the same so we opt out of comparing them here.
  2669. const comparisonUndoEdits = Object.values(action.meta.undo.edits).filter(edit => typeof edit !== 'function');
  2670. const comparisonEdits = Object.values(action.edits).filter(edit => typeof edit !== 'function');
  2671. if (!external_wp_isShallowEqual_default()(comparisonUndoEdits, comparisonEdits)) {
  2672. nextState.push({
  2673. kind: action.kind,
  2674. name: action.name,
  2675. recordId: action.recordId,
  2676. edits: isCreateUndoLevel ? { ...state.flattenedUndo,
  2677. ...action.edits
  2678. } : action.edits
  2679. });
  2680. }
  2681. return nextState;
  2682. }
  2683. return state;
  2684. }
  2685. /**
  2686. * Reducer managing embed preview data.
  2687. *
  2688. * @param {Object} state Current state.
  2689. * @param {Object} action Dispatched action.
  2690. *
  2691. * @return {Object} Updated state.
  2692. */
  2693. function embedPreviews(state = {}, action) {
  2694. switch (action.type) {
  2695. case 'RECEIVE_EMBED_PREVIEW':
  2696. const {
  2697. url,
  2698. preview
  2699. } = action;
  2700. return { ...state,
  2701. [url]: preview
  2702. };
  2703. }
  2704. return state;
  2705. }
  2706. /**
  2707. * State which tracks whether the user can perform an action on a REST
  2708. * resource.
  2709. *
  2710. * @param {Object} state Current state.
  2711. * @param {Object} action Dispatched action.
  2712. *
  2713. * @return {Object} Updated state.
  2714. */
  2715. function userPermissions(state = {}, action) {
  2716. switch (action.type) {
  2717. case 'RECEIVE_USER_PERMISSION':
  2718. return { ...state,
  2719. [action.key]: action.isAllowed
  2720. };
  2721. }
  2722. return state;
  2723. }
  2724. /**
  2725. * Reducer returning autosaves keyed by their parent's post id.
  2726. *
  2727. * @param {Object} state Current state.
  2728. * @param {Object} action Dispatched action.
  2729. *
  2730. * @return {Object} Updated state.
  2731. */
  2732. function reducer_autosaves(state = {}, action) {
  2733. switch (action.type) {
  2734. case 'RECEIVE_AUTOSAVES':
  2735. const {
  2736. postId,
  2737. autosaves: autosavesData
  2738. } = action;
  2739. return { ...state,
  2740. [postId]: autosavesData
  2741. };
  2742. }
  2743. return state;
  2744. }
  2745. /* harmony default export */ var build_module_reducer = (Object(external_wp_data_["combineReducers"])({
  2746. terms,
  2747. users: reducer_users,
  2748. currentTheme,
  2749. currentUser: reducer_currentUser,
  2750. taxonomies: reducer_taxonomies,
  2751. themes,
  2752. themeSupports,
  2753. entities: reducer_entities,
  2754. undo: reducer_undo,
  2755. embedPreviews,
  2756. userPermissions,
  2757. autosaves: reducer_autosaves,
  2758. locks: locks_reducer
  2759. }));
  2760. // EXTERNAL MODULE: ./node_modules/rememo/es/rememo.js
  2761. var rememo = __webpack_require__("pPDe");
  2762. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/name.js
  2763. /**
  2764. * The reducer key used by core data in store registration.
  2765. * This is defined in a separate file to avoid cycle-dependency
  2766. *
  2767. * @type {string}
  2768. */
  2769. const STORE_NAME = 'core';
  2770. // EXTERNAL MODULE: ./node_modules/equivalent-key-map/equivalent-key-map.js
  2771. var equivalent_key_map = __webpack_require__("FtRg");
  2772. var equivalent_key_map_default = /*#__PURE__*/__webpack_require__.n(equivalent_key_map);
  2773. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/queried-data/selectors.js
  2774. /**
  2775. * External dependencies
  2776. */
  2777. /**
  2778. * Internal dependencies
  2779. */
  2780. /**
  2781. * Cache of state keys to EquivalentKeyMap where the inner map tracks queries
  2782. * to their resulting items set. WeakMap allows garbage collection on expired
  2783. * state references.
  2784. *
  2785. * @type {WeakMap<Object,EquivalentKeyMap>}
  2786. */
  2787. const queriedItemsCacheByState = new WeakMap();
  2788. /**
  2789. * Returns items for a given query, or null if the items are not known.
  2790. *
  2791. * @param {Object} state State object.
  2792. * @param {?Object} query Optional query.
  2793. *
  2794. * @return {?Array} Query items.
  2795. */
  2796. function getQueriedItemsUncached(state, query) {
  2797. var _state$queries, _state$queries$contex;
  2798. const {
  2799. stableKey,
  2800. page,
  2801. perPage,
  2802. include,
  2803. fields,
  2804. context
  2805. } = get_query_parts(query);
  2806. let itemIds;
  2807. if (Array.isArray(include) && !stableKey) {
  2808. // If the parsed query yields a set of IDs, but otherwise no filtering,
  2809. // it's safe to consider targeted item IDs as the include set. This
  2810. // doesn't guarantee that those objects have been queried, which is
  2811. // accounted for below in the loop `null` return.
  2812. itemIds = include; // TODO: Avoid storing the empty stable string in reducer, since it
  2813. // can be computed dynamically here always.
  2814. } else if ((_state$queries = state.queries) !== null && _state$queries !== void 0 && (_state$queries$contex = _state$queries[context]) !== null && _state$queries$contex !== void 0 && _state$queries$contex[stableKey]) {
  2815. itemIds = state.queries[context][stableKey];
  2816. }
  2817. if (!itemIds) {
  2818. return null;
  2819. }
  2820. const startOffset = perPage === -1 ? 0 : (page - 1) * perPage;
  2821. const endOffset = perPage === -1 ? itemIds.length : Math.min(startOffset + perPage, itemIds.length);
  2822. const items = [];
  2823. for (let i = startOffset; i < endOffset; i++) {
  2824. var _state$items$context;
  2825. const itemId = itemIds[i];
  2826. if (Array.isArray(include) && !include.includes(itemId)) {
  2827. continue;
  2828. }
  2829. if (!((_state$items$context = state.items[context]) !== null && _state$items$context !== void 0 && _state$items$context.hasOwnProperty(itemId))) {
  2830. return null;
  2831. }
  2832. const item = state.items[context][itemId];
  2833. let filteredItem;
  2834. if (Array.isArray(fields)) {
  2835. filteredItem = {};
  2836. for (let f = 0; f < fields.length; f++) {
  2837. const field = fields[f].split('.');
  2838. const value = Object(external_lodash_["get"])(item, field);
  2839. Object(external_lodash_["set"])(filteredItem, field, value);
  2840. }
  2841. } else {
  2842. var _state$itemIsComplete;
  2843. // If expecting a complete item, validate that completeness, or
  2844. // otherwise abort.
  2845. if (!((_state$itemIsComplete = state.itemIsComplete[context]) !== null && _state$itemIsComplete !== void 0 && _state$itemIsComplete[itemId])) {
  2846. return null;
  2847. }
  2848. filteredItem = item;
  2849. }
  2850. items.push(filteredItem);
  2851. }
  2852. return items;
  2853. }
  2854. /**
  2855. * Returns items for a given query, or null if the items are not known. Caches
  2856. * result both per state (by reference) and per query (by deep equality).
  2857. * The caching approach is intended to be durable to query objects which are
  2858. * deeply but not referentially equal, since otherwise:
  2859. *
  2860. * `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )`
  2861. *
  2862. * @param {Object} state State object.
  2863. * @param {?Object} query Optional query.
  2864. *
  2865. * @return {?Array} Query items.
  2866. */
  2867. const getQueriedItems = Object(rememo["a" /* default */])((state, query = {}) => {
  2868. let queriedItemsCache = queriedItemsCacheByState.get(state);
  2869. if (queriedItemsCache) {
  2870. const queriedItems = queriedItemsCache.get(query);
  2871. if (queriedItems !== undefined) {
  2872. return queriedItems;
  2873. }
  2874. } else {
  2875. queriedItemsCache = new equivalent_key_map_default.a();
  2876. queriedItemsCacheByState.set(state, queriedItemsCache);
  2877. }
  2878. const items = getQueriedItemsUncached(state, query);
  2879. queriedItemsCache.set(query, items);
  2880. return items;
  2881. });
  2882. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/selectors.js
  2883. /**
  2884. * External dependencies
  2885. */
  2886. /**
  2887. * WordPress dependencies
  2888. */
  2889. /**
  2890. * Internal dependencies
  2891. */
  2892. /**
  2893. * Shared reference to an empty array for cases where it is important to avoid
  2894. * returning a new array reference on every invocation, as in a connected or
  2895. * other pure component which performs `shouldComponentUpdate` check on props.
  2896. * This should be used as a last resort, since the normalized data should be
  2897. * maintained by the reducer result in state.
  2898. *
  2899. * @type {Array}
  2900. */
  2901. const EMPTY_ARRAY = [];
  2902. /**
  2903. * Returns true if a request is in progress for embed preview data, or false
  2904. * otherwise.
  2905. *
  2906. * @param {Object} state Data state.
  2907. * @param {string} url URL the preview would be for.
  2908. *
  2909. * @return {boolean} Whether a request is in progress for an embed preview.
  2910. */
  2911. const isRequestingEmbedPreview = Object(external_wp_data_["createRegistrySelector"])(select => (state, url) => {
  2912. return select('core/data').isResolving(STORE_NAME, 'getEmbedPreview', [url]);
  2913. });
  2914. /**
  2915. * Returns all available authors.
  2916. *
  2917. * @param {Object} state Data state.
  2918. * @param {Object|undefined} query Optional object of query parameters to
  2919. * include with request.
  2920. * @return {Array} Authors list.
  2921. */
  2922. function getAuthors(state, query) {
  2923. const path = Object(external_wp_url_["addQueryArgs"])('/wp/v2/users/?who=authors&per_page=100', query);
  2924. return getUserQueryResults(state, path);
  2925. }
  2926. /**
  2927. * Returns all available authors.
  2928. *
  2929. * @param {Object} state Data state.
  2930. * @param {number} id The author id.
  2931. *
  2932. * @return {Array} Authors list.
  2933. */
  2934. function __unstableGetAuthor(state, id) {
  2935. return Object(external_lodash_["get"])(state, ['users', 'byId', id], null);
  2936. }
  2937. /**
  2938. * Returns the current user.
  2939. *
  2940. * @param {Object} state Data state.
  2941. *
  2942. * @return {Object} Current user object.
  2943. */
  2944. function getCurrentUser(state) {
  2945. return state.currentUser;
  2946. }
  2947. /**
  2948. * Returns all the users returned by a query ID.
  2949. *
  2950. * @param {Object} state Data state.
  2951. * @param {string} queryID Query ID.
  2952. *
  2953. * @return {Array} Users list.
  2954. */
  2955. const getUserQueryResults = Object(rememo["a" /* default */])((state, queryID) => {
  2956. const queryResults = state.users.queries[queryID];
  2957. return Object(external_lodash_["map"])(queryResults, id => state.users.byId[id]);
  2958. }, (state, queryID) => [state.users.queries[queryID], state.users.byId]);
  2959. /**
  2960. * Returns whether the entities for the give kind are loaded.
  2961. *
  2962. * @param {Object} state Data state.
  2963. * @param {string} kind Entity kind.
  2964. *
  2965. * @return {Array<Object>} Array of entities with config matching kind.
  2966. */
  2967. function getEntitiesByKind(state, kind) {
  2968. return Object(external_lodash_["filter"])(state.entities.config, {
  2969. kind
  2970. });
  2971. }
  2972. /**
  2973. * Returns the entity object given its kind and name.
  2974. *
  2975. * @param {Object} state Data state.
  2976. * @param {string} kind Entity kind.
  2977. * @param {string} name Entity name.
  2978. *
  2979. * @return {Object} Entity
  2980. */
  2981. function getEntity(state, kind, name) {
  2982. return Object(external_lodash_["find"])(state.entities.config, {
  2983. kind,
  2984. name
  2985. });
  2986. }
  2987. /**
  2988. * Returns the Entity's record object by key. Returns `null` if the value is not
  2989. * yet received, undefined if the value entity is known to not exist, or the
  2990. * entity object if it exists and is received.
  2991. *
  2992. * @param {Object} state State tree
  2993. * @param {string} kind Entity kind.
  2994. * @param {string} name Entity name.
  2995. * @param {number} key Record's key
  2996. * @param {?Object} query Optional query.
  2997. *
  2998. * @return {Object?} Record.
  2999. */
  3000. function getEntityRecord(state, kind, name, key, query) {
  3001. var _query$context, _queriedState$items$c;
  3002. const queriedState = Object(external_lodash_["get"])(state.entities.data, [kind, name, 'queriedData']);
  3003. if (!queriedState) {
  3004. return undefined;
  3005. }
  3006. const context = (_query$context = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context !== void 0 ? _query$context : 'default';
  3007. if (query === undefined) {
  3008. var _queriedState$itemIsC;
  3009. // If expecting a complete item, validate that completeness.
  3010. if (!((_queriedState$itemIsC = queriedState.itemIsComplete[context]) !== null && _queriedState$itemIsC !== void 0 && _queriedState$itemIsC[key])) {
  3011. return undefined;
  3012. }
  3013. return queriedState.items[context][key];
  3014. }
  3015. const item = (_queriedState$items$c = queriedState.items[context]) === null || _queriedState$items$c === void 0 ? void 0 : _queriedState$items$c[key];
  3016. if (item && query._fields) {
  3017. const filteredItem = {};
  3018. const fields = get_normalized_comma_separable(query._fields);
  3019. for (let f = 0; f < fields.length; f++) {
  3020. const field = fields[f].split('.');
  3021. const value = Object(external_lodash_["get"])(item, field);
  3022. Object(external_lodash_["set"])(filteredItem, field, value);
  3023. }
  3024. return filteredItem;
  3025. }
  3026. return item;
  3027. }
  3028. /**
  3029. * Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity from the API if the entity record isn't available in the local state.
  3030. *
  3031. * @param {Object} state State tree
  3032. * @param {string} kind Entity kind.
  3033. * @param {string} name Entity name.
  3034. * @param {number} key Record's key
  3035. *
  3036. * @return {Object|null} Record.
  3037. */
  3038. function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
  3039. return getEntityRecord(state, kind, name, key);
  3040. }
  3041. /**
  3042. * Returns the entity's record object by key,
  3043. * with its attributes mapped to their raw values.
  3044. *
  3045. * @param {Object} state State tree.
  3046. * @param {string} kind Entity kind.
  3047. * @param {string} name Entity name.
  3048. * @param {number} key Record's key.
  3049. *
  3050. * @return {Object?} Object with the entity's raw attributes.
  3051. */
  3052. const getRawEntityRecord = Object(rememo["a" /* default */])((state, kind, name, key) => {
  3053. const record = getEntityRecord(state, kind, name, key);
  3054. return record && Object.keys(record).reduce((accumulator, _key) => {
  3055. // Because edits are the "raw" attribute values,
  3056. // we return those from record selectors to make rendering,
  3057. // comparisons, and joins with edits easier.
  3058. accumulator[_key] = Object(external_lodash_["get"])(record[_key], 'raw', record[_key]);
  3059. return accumulator;
  3060. }, {});
  3061. }, state => [state.entities.data]);
  3062. /**
  3063. * Returns true if records have been received for the given set of parameters,
  3064. * or false otherwise.
  3065. *
  3066. * @param {Object} state State tree
  3067. * @param {string} kind Entity kind.
  3068. * @param {string} name Entity name.
  3069. * @param {?Object} query Optional terms query.
  3070. *
  3071. * @return {boolean} Whether entity records have been received.
  3072. */
  3073. function hasEntityRecords(state, kind, name, query) {
  3074. return Array.isArray(getEntityRecords(state, kind, name, query));
  3075. }
  3076. /**
  3077. * Returns the Entity's records.
  3078. *
  3079. * @param {Object} state State tree
  3080. * @param {string} kind Entity kind.
  3081. * @param {string} name Entity name.
  3082. * @param {?Object} query Optional terms query.
  3083. *
  3084. * @return {?Array} Records.
  3085. */
  3086. function getEntityRecords(state, kind, name, query) {
  3087. // Queried data state is prepopulated for all known entities. If this is not
  3088. // assigned for the given parameters, then it is known to not exist. Thus, a
  3089. // return value of an empty array is used instead of `null` (where `null` is
  3090. // otherwise used to represent an unknown state).
  3091. const queriedState = Object(external_lodash_["get"])(state.entities.data, [kind, name, 'queriedData']);
  3092. if (!queriedState) {
  3093. return EMPTY_ARRAY;
  3094. }
  3095. return getQueriedItems(queriedState, query);
  3096. }
  3097. /**
  3098. * Returns the list of dirty entity records.
  3099. *
  3100. * @param {Object} state State tree.
  3101. *
  3102. * @return {[{ title: string, key: string, name: string, kind: string }]} The list of updated records
  3103. */
  3104. const __experimentalGetDirtyEntityRecords = Object(rememo["a" /* default */])(state => {
  3105. const {
  3106. entities: {
  3107. data
  3108. }
  3109. } = state;
  3110. const dirtyRecords = [];
  3111. Object.keys(data).forEach(kind => {
  3112. Object.keys(data[kind]).forEach(name => {
  3113. const primaryKeys = Object.keys(data[kind][name].edits).filter(primaryKey => hasEditsForEntityRecord(state, kind, name, primaryKey));
  3114. if (primaryKeys.length) {
  3115. const entity = getEntity(state, kind, name);
  3116. primaryKeys.forEach(primaryKey => {
  3117. var _entity$getTitle;
  3118. const entityRecord = getEditedEntityRecord(state, kind, name, primaryKey);
  3119. dirtyRecords.push({
  3120. // We avoid using primaryKey because it's transformed into a string
  3121. // when it's used as an object key.
  3122. key: entityRecord[entity.key || DEFAULT_ENTITY_KEY],
  3123. title: (entity === null || entity === void 0 ? void 0 : (_entity$getTitle = entity.getTitle) === null || _entity$getTitle === void 0 ? void 0 : _entity$getTitle.call(entity, entityRecord)) || '',
  3124. name,
  3125. kind
  3126. });
  3127. });
  3128. }
  3129. });
  3130. });
  3131. return dirtyRecords;
  3132. }, state => [state.entities.data]);
  3133. /**
  3134. * Returns the specified entity record's edits.
  3135. *
  3136. * @param {Object} state State tree.
  3137. * @param {string} kind Entity kind.
  3138. * @param {string} name Entity name.
  3139. * @param {number} recordId Record ID.
  3140. *
  3141. * @return {Object?} The entity record's edits.
  3142. */
  3143. function getEntityRecordEdits(state, kind, name, recordId) {
  3144. return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'edits', recordId]);
  3145. }
  3146. /**
  3147. * Returns the specified entity record's non transient edits.
  3148. *
  3149. * Transient edits don't create an undo level, and
  3150. * are not considered for change detection.
  3151. * They are defined in the entity's config.
  3152. *
  3153. * @param {Object} state State tree.
  3154. * @param {string} kind Entity kind.
  3155. * @param {string} name Entity name.
  3156. * @param {number} recordId Record ID.
  3157. *
  3158. * @return {Object?} The entity record's non transient edits.
  3159. */
  3160. const getEntityRecordNonTransientEdits = Object(rememo["a" /* default */])((state, kind, name, recordId) => {
  3161. const {
  3162. transientEdits
  3163. } = getEntity(state, kind, name) || {};
  3164. const edits = getEntityRecordEdits(state, kind, name, recordId) || {};
  3165. if (!transientEdits) {
  3166. return edits;
  3167. }
  3168. return Object.keys(edits).reduce((acc, key) => {
  3169. if (!transientEdits[key]) {
  3170. acc[key] = edits[key];
  3171. }
  3172. return acc;
  3173. }, {});
  3174. }, state => [state.entities.config, state.entities.data]);
  3175. /**
  3176. * Returns true if the specified entity record has edits,
  3177. * and false otherwise.
  3178. *
  3179. * @param {Object} state State tree.
  3180. * @param {string} kind Entity kind.
  3181. * @param {string} name Entity name.
  3182. * @param {number} recordId Record ID.
  3183. *
  3184. * @return {boolean} Whether the entity record has edits or not.
  3185. */
  3186. function hasEditsForEntityRecord(state, kind, name, recordId) {
  3187. return isSavingEntityRecord(state, kind, name, recordId) || Object.keys(getEntityRecordNonTransientEdits(state, kind, name, recordId)).length > 0;
  3188. }
  3189. /**
  3190. * Returns the specified entity record, merged with its edits.
  3191. *
  3192. * @param {Object} state State tree.
  3193. * @param {string} kind Entity kind.
  3194. * @param {string} name Entity name.
  3195. * @param {number} recordId Record ID.
  3196. *
  3197. * @return {Object?} The entity record, merged with its edits.
  3198. */
  3199. const getEditedEntityRecord = Object(rememo["a" /* default */])((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId),
  3200. ...getEntityRecordEdits(state, kind, name, recordId)
  3201. }), state => [state.entities.data]);
  3202. /**
  3203. * Returns true if the specified entity record is autosaving, and false otherwise.
  3204. *
  3205. * @param {Object} state State tree.
  3206. * @param {string} kind Entity kind.
  3207. * @param {string} name Entity name.
  3208. * @param {number} recordId Record ID.
  3209. *
  3210. * @return {boolean} Whether the entity record is autosaving or not.
  3211. */
  3212. function isAutosavingEntityRecord(state, kind, name, recordId) {
  3213. const {
  3214. pending,
  3215. isAutosave
  3216. } = Object(external_lodash_["get"])(state.entities.data, [kind, name, 'saving', recordId], {});
  3217. return Boolean(pending && isAutosave);
  3218. }
  3219. /**
  3220. * Returns true if the specified entity record is saving, and false otherwise.
  3221. *
  3222. * @param {Object} state State tree.
  3223. * @param {string} kind Entity kind.
  3224. * @param {string} name Entity name.
  3225. * @param {number} recordId Record ID.
  3226. *
  3227. * @return {boolean} Whether the entity record is saving or not.
  3228. */
  3229. function isSavingEntityRecord(state, kind, name, recordId) {
  3230. return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'saving', recordId, 'pending'], false);
  3231. }
  3232. /**
  3233. * Returns true if the specified entity record is deleting, and false otherwise.
  3234. *
  3235. * @param {Object} state State tree.
  3236. * @param {string} kind Entity kind.
  3237. * @param {string} name Entity name.
  3238. * @param {number} recordId Record ID.
  3239. *
  3240. * @return {boolean} Whether the entity record is deleting or not.
  3241. */
  3242. function isDeletingEntityRecord(state, kind, name, recordId) {
  3243. return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'deleting', recordId, 'pending'], false);
  3244. }
  3245. /**
  3246. * Returns the specified entity record's last save error.
  3247. *
  3248. * @param {Object} state State tree.
  3249. * @param {string} kind Entity kind.
  3250. * @param {string} name Entity name.
  3251. * @param {number} recordId Record ID.
  3252. *
  3253. * @return {Object?} The entity record's save error.
  3254. */
  3255. function getLastEntitySaveError(state, kind, name, recordId) {
  3256. return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'saving', recordId, 'error']);
  3257. }
  3258. /**
  3259. * Returns the specified entity record's last delete error.
  3260. *
  3261. * @param {Object} state State tree.
  3262. * @param {string} kind Entity kind.
  3263. * @param {string} name Entity name.
  3264. * @param {number} recordId Record ID.
  3265. *
  3266. * @return {Object?} The entity record's save error.
  3267. */
  3268. function getLastEntityDeleteError(state, kind, name, recordId) {
  3269. return Object(external_lodash_["get"])(state.entities.data, [kind, name, 'deleting', recordId, 'error']);
  3270. }
  3271. /**
  3272. * Returns the current undo offset for the
  3273. * entity records edits history. The offset
  3274. * represents how many items from the end
  3275. * of the history stack we are at. 0 is the
  3276. * last edit, -1 is the second last, and so on.
  3277. *
  3278. * @param {Object} state State tree.
  3279. *
  3280. * @return {number} The current undo offset.
  3281. */
  3282. function getCurrentUndoOffset(state) {
  3283. return state.undo.offset;
  3284. }
  3285. /**
  3286. * Returns the previous edit from the current undo offset
  3287. * for the entity records edits history, if any.
  3288. *
  3289. * @param {Object} state State tree.
  3290. *
  3291. * @return {Object?} The edit.
  3292. */
  3293. function getUndoEdit(state) {
  3294. return state.undo[state.undo.length - 2 + getCurrentUndoOffset(state)];
  3295. }
  3296. /**
  3297. * Returns the next edit from the current undo offset
  3298. * for the entity records edits history, if any.
  3299. *
  3300. * @param {Object} state State tree.
  3301. *
  3302. * @return {Object?} The edit.
  3303. */
  3304. function getRedoEdit(state) {
  3305. return state.undo[state.undo.length + getCurrentUndoOffset(state)];
  3306. }
  3307. /**
  3308. * Returns true if there is a previous edit from the current undo offset
  3309. * for the entity records edits history, and false otherwise.
  3310. *
  3311. * @param {Object} state State tree.
  3312. *
  3313. * @return {boolean} Whether there is a previous edit or not.
  3314. */
  3315. function hasUndo(state) {
  3316. return Boolean(getUndoEdit(state));
  3317. }
  3318. /**
  3319. * Returns true if there is a next edit from the current undo offset
  3320. * for the entity records edits history, and false otherwise.
  3321. *
  3322. * @param {Object} state State tree.
  3323. *
  3324. * @return {boolean} Whether there is a next edit or not.
  3325. */
  3326. function hasRedo(state) {
  3327. return Boolean(getRedoEdit(state));
  3328. }
  3329. /**
  3330. * Return the current theme.
  3331. *
  3332. * @param {Object} state Data state.
  3333. *
  3334. * @return {Object} The current theme.
  3335. */
  3336. function getCurrentTheme(state) {
  3337. return state.themes[state.currentTheme];
  3338. }
  3339. /**
  3340. * Return theme supports data in the index.
  3341. *
  3342. * @param {Object} state Data state.
  3343. *
  3344. * @return {*} Index data.
  3345. */
  3346. function getThemeSupports(state) {
  3347. return state.themeSupports;
  3348. }
  3349. /**
  3350. * Returns the embed preview for the given URL.
  3351. *
  3352. * @param {Object} state Data state.
  3353. * @param {string} url Embedded URL.
  3354. *
  3355. * @return {*} Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
  3356. */
  3357. function getEmbedPreview(state, url) {
  3358. return state.embedPreviews[url];
  3359. }
  3360. /**
  3361. * Determines if the returned preview is an oEmbed link fallback.
  3362. *
  3363. * WordPress can be configured to return a simple link to a URL if it is not embeddable.
  3364. * We need to be able to determine if a URL is embeddable or not, based on what we
  3365. * get back from the oEmbed preview API.
  3366. *
  3367. * @param {Object} state Data state.
  3368. * @param {string} url Embedded URL.
  3369. *
  3370. * @return {boolean} Is the preview for the URL an oEmbed link fallback.
  3371. */
  3372. function isPreviewEmbedFallback(state, url) {
  3373. const preview = state.embedPreviews[url];
  3374. const oEmbedLinkCheck = '<a href="' + url + '">' + url + '</a>';
  3375. if (!preview) {
  3376. return false;
  3377. }
  3378. return preview.html === oEmbedLinkCheck;
  3379. }
  3380. /**
  3381. * Returns whether the current user can perform the given action on the given
  3382. * REST resource.
  3383. *
  3384. * Calling this may trigger an OPTIONS request to the REST API via the
  3385. * `canUser()` resolver.
  3386. *
  3387. * https://developer.wordpress.org/rest-api/reference/
  3388. *
  3389. * @param {Object} state Data state.
  3390. * @param {string} action Action to check. One of: 'create', 'read', 'update', 'delete'.
  3391. * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.
  3392. * @param {string=} id Optional ID of the rest resource to check.
  3393. *
  3394. * @return {boolean|undefined} Whether or not the user can perform the action,
  3395. * or `undefined` if the OPTIONS request is still being made.
  3396. */
  3397. function canUser(state, action, resource, id) {
  3398. const key = Object(external_lodash_["compact"])([action, resource, id]).join('/');
  3399. return Object(external_lodash_["get"])(state, ['userPermissions', key]);
  3400. }
  3401. /**
  3402. * Returns whether the current user can edit the given entity.
  3403. *
  3404. * Calling this may trigger an OPTIONS request to the REST API via the
  3405. * `canUser()` resolver.
  3406. *
  3407. * https://developer.wordpress.org/rest-api/reference/
  3408. *
  3409. * @param {Object} state Data state.
  3410. * @param {string} kind Entity kind.
  3411. * @param {string} name Entity name.
  3412. * @param {string} recordId Record's id.
  3413. * @return {boolean|undefined} Whether or not the user can edit,
  3414. * or `undefined` if the OPTIONS request is still being made.
  3415. */
  3416. function canUserEditEntityRecord(state, kind, name, recordId) {
  3417. const entity = getEntity(state, kind, name);
  3418. if (!entity) {
  3419. return false;
  3420. }
  3421. const resource = entity.__unstable_rest_base;
  3422. return canUser(state, 'update', resource, recordId);
  3423. }
  3424. /**
  3425. * Returns the latest autosaves for the post.
  3426. *
  3427. * May return multiple autosaves since the backend stores one autosave per
  3428. * author for each post.
  3429. *
  3430. * @param {Object} state State tree.
  3431. * @param {string} postType The type of the parent post.
  3432. * @param {number} postId The id of the parent post.
  3433. *
  3434. * @return {?Array} An array of autosaves for the post, or undefined if there is none.
  3435. */
  3436. function getAutosaves(state, postType, postId) {
  3437. return state.autosaves[postId];
  3438. }
  3439. /**
  3440. * Returns the autosave for the post and author.
  3441. *
  3442. * @param {Object} state State tree.
  3443. * @param {string} postType The type of the parent post.
  3444. * @param {number} postId The id of the parent post.
  3445. * @param {number} authorId The id of the author.
  3446. *
  3447. * @return {?Object} The autosave for the post and author.
  3448. */
  3449. function getAutosave(state, postType, postId, authorId) {
  3450. if (authorId === undefined) {
  3451. return;
  3452. }
  3453. const autosaves = state.autosaves[postId];
  3454. return Object(external_lodash_["find"])(autosaves, {
  3455. author: authorId
  3456. });
  3457. }
  3458. /**
  3459. * Returns true if the REST request for autosaves has completed.
  3460. *
  3461. * @param {Object} state State tree.
  3462. * @param {string} postType The type of the parent post.
  3463. * @param {number} postId The id of the parent post.
  3464. *
  3465. * @return {boolean} True if the REST request was completed. False otherwise.
  3466. */
  3467. const hasFetchedAutosaves = Object(external_wp_data_["createRegistrySelector"])(select => (state, postType, postId) => {
  3468. return select(STORE_NAME).hasFinishedResolution('getAutosaves', [postType, postId]);
  3469. });
  3470. /**
  3471. * Returns a new reference when edited values have changed. This is useful in
  3472. * inferring where an edit has been made between states by comparison of the
  3473. * return values using strict equality.
  3474. *
  3475. * @example
  3476. *
  3477. * ```
  3478. * const hasEditOccurred = (
  3479. * getReferenceByDistinctEdits( beforeState ) !==
  3480. * getReferenceByDistinctEdits( afterState )
  3481. * );
  3482. * ```
  3483. *
  3484. * @param {Object} state Editor state.
  3485. *
  3486. * @return {*} A value whose reference will change only when an edit occurs.
  3487. */
  3488. const getReferenceByDistinctEdits = Object(rememo["a" /* default */])(() => [], state => [state.undo.length, state.undo.offset, state.undo.flattenedUndo]);
  3489. /**
  3490. * Retrieve the frontend template used for a given link.
  3491. *
  3492. * @param {Object} state Editor state.
  3493. * @param {string} link Link.
  3494. *
  3495. * @return {Object?} The template record.
  3496. */
  3497. function __experimentalGetTemplateForLink(state, link) {
  3498. const records = getEntityRecords(state, 'postType', 'wp_template', {
  3499. 'find-template': link
  3500. });
  3501. const template = records !== null && records !== void 0 && records.length ? records[0] : null;
  3502. if (template) {
  3503. return getEditedEntityRecord(state, 'postType', 'wp_template', template.id);
  3504. }
  3505. return template;
  3506. }
  3507. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/utils/if-not-resolved.js
  3508. /**
  3509. * WordPress dependencies
  3510. */
  3511. /**
  3512. * Higher-order function which invokes the given resolver only if it has not
  3513. * already been resolved with the arguments passed to the enhanced function.
  3514. *
  3515. * This only considers resolution state, and notably does not support resolver
  3516. * custom `isFulfilled` behavior.
  3517. *
  3518. * @param {Function} resolver Original resolver.
  3519. * @param {string} selectorName Selector name associated with resolver.
  3520. *
  3521. * @return {Function} Enhanced resolver.
  3522. */
  3523. const ifNotResolved = (resolver, selectorName) =>
  3524. /**
  3525. * @param {...any} args Original resolver arguments.
  3526. */
  3527. function* resolveIfNotResolved(...args) {
  3528. const hasStartedResolution = yield external_wp_data_["controls"].select('core', 'hasStartedResolution', selectorName, args);
  3529. if (!hasStartedResolution) {
  3530. yield* resolver(...args);
  3531. }
  3532. };
  3533. /* harmony default export */ var if_not_resolved = (ifNotResolved);
  3534. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/resolvers.js
  3535. /**
  3536. * External dependencies
  3537. */
  3538. /**
  3539. * WordPress dependencies
  3540. */
  3541. /**
  3542. * Internal dependencies
  3543. */
  3544. /**
  3545. * Internal dependencies
  3546. */
  3547. /**
  3548. * Requests authors from the REST API.
  3549. *
  3550. * @param {Object|undefined} query Optional object of query parameters to
  3551. * include with request.
  3552. */
  3553. function* resolvers_getAuthors(query) {
  3554. const path = Object(external_wp_url_["addQueryArgs"])('/wp/v2/users/?who=authors&per_page=100', query);
  3555. const users = yield Object(external_wp_dataControls_["apiFetch"])({
  3556. path
  3557. });
  3558. yield receiveUserQuery(path, users);
  3559. }
  3560. /**
  3561. * Temporary approach to resolving editor access to author queries.
  3562. *
  3563. * @param {number} id The author id.
  3564. */
  3565. function* resolvers_unstableGetAuthor(id) {
  3566. const path = `/wp/v2/users?who=authors&include=${id}`;
  3567. const users = yield Object(external_wp_dataControls_["apiFetch"])({
  3568. path
  3569. });
  3570. yield receiveUserQuery('author', users);
  3571. }
  3572. /**
  3573. * Requests the current user from the REST API.
  3574. */
  3575. function* resolvers_getCurrentUser() {
  3576. const currentUser = yield Object(external_wp_dataControls_["apiFetch"])({
  3577. path: '/wp/v2/users/me'
  3578. });
  3579. yield receiveCurrentUser(currentUser);
  3580. }
  3581. /**
  3582. * Requests an entity's record from the REST API.
  3583. *
  3584. * @param {string} kind Entity kind.
  3585. * @param {string} name Entity name.
  3586. * @param {number|string} key Record's key
  3587. * @param {Object|undefined} query Optional object of query parameters to
  3588. * include with request.
  3589. */
  3590. function* resolvers_getEntityRecord(kind, name, key = '', query) {
  3591. const entities = yield getKindEntities(kind);
  3592. const entity = Object(external_lodash_["find"])(entities, {
  3593. kind,
  3594. name
  3595. });
  3596. if (!entity) {
  3597. return;
  3598. }
  3599. const lock = yield* __unstableAcquireStoreLock('core', ['entities', 'data', kind, name, key], {
  3600. exclusive: false
  3601. });
  3602. try {
  3603. if (query !== undefined && query._fields) {
  3604. // If requesting specific fields, items and query assocation to said
  3605. // records are stored by ID reference. Thus, fields must always include
  3606. // the ID.
  3607. query = { ...query,
  3608. _fields: Object(external_lodash_["uniq"])([...(get_normalized_comma_separable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
  3609. };
  3610. } // Disable reason: While true that an early return could leave `path`
  3611. // unused, it's important that path is derived using the query prior to
  3612. // additional query modifications in the condition below, since those
  3613. // modifications are relevant to how the data is tracked in state, and not
  3614. // for how the request is made to the REST API.
  3615. // eslint-disable-next-line @wordpress/no-unused-vars-before-return
  3616. const path = Object(external_wp_url_["addQueryArgs"])(entity.baseURL + '/' + key, { ...entity.baseURLParams,
  3617. ...query
  3618. });
  3619. if (query !== undefined) {
  3620. query = { ...query,
  3621. include: [key]
  3622. }; // The resolution cache won't consider query as reusable based on the
  3623. // fields, so it's tested here, prior to initiating the REST request,
  3624. // and without causing `getEntityRecords` resolution to occur.
  3625. const hasRecords = yield external_wp_data_["controls"].select('core', 'hasEntityRecords', kind, name, query);
  3626. if (hasRecords) {
  3627. return;
  3628. }
  3629. }
  3630. const record = yield Object(external_wp_dataControls_["apiFetch"])({
  3631. path
  3632. });
  3633. yield receiveEntityRecords(kind, name, record, query);
  3634. } catch (error) {// We need a way to handle and access REST API errors in state
  3635. // Until then, catching the error ensures the resolver is marked as resolved.
  3636. } finally {
  3637. yield* __unstableReleaseStoreLock(lock);
  3638. }
  3639. }
  3640. /**
  3641. * Requests an entity's record from the REST API.
  3642. */
  3643. const resolvers_getRawEntityRecord = if_not_resolved(resolvers_getEntityRecord, 'getEntityRecord');
  3644. /**
  3645. * Requests an entity's record from the REST API.
  3646. */
  3647. const resolvers_getEditedEntityRecord = if_not_resolved(resolvers_getRawEntityRecord, 'getRawEntityRecord');
  3648. /**
  3649. * Requests the entity's records from the REST API.
  3650. *
  3651. * @param {string} kind Entity kind.
  3652. * @param {string} name Entity name.
  3653. * @param {Object?} query Query Object.
  3654. */
  3655. function* resolvers_getEntityRecords(kind, name, query = {}) {
  3656. const entities = yield getKindEntities(kind);
  3657. const entity = Object(external_lodash_["find"])(entities, {
  3658. kind,
  3659. name
  3660. });
  3661. if (!entity) {
  3662. return;
  3663. }
  3664. const lock = yield* __unstableAcquireStoreLock('core', ['entities', 'data', kind, name], {
  3665. exclusive: false
  3666. });
  3667. try {
  3668. var _query;
  3669. if (query._fields) {
  3670. // If requesting specific fields, items and query assocation to said
  3671. // records are stored by ID reference. Thus, fields must always include
  3672. // the ID.
  3673. query = { ...query,
  3674. _fields: Object(external_lodash_["uniq"])([...(get_normalized_comma_separable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
  3675. };
  3676. }
  3677. const path = Object(external_wp_url_["addQueryArgs"])(entity.baseURL, { ...entity.baseURLParams,
  3678. ...query
  3679. });
  3680. let records = Object.values(yield Object(external_wp_dataControls_["apiFetch"])({
  3681. path
  3682. })); // If we request fields but the result doesn't contain the fields,
  3683. // explicitely set these fields as "undefined"
  3684. // that way we consider the query "fullfilled".
  3685. if (query._fields) {
  3686. records = records.map(record => {
  3687. query._fields.split(',').forEach(field => {
  3688. if (!record.hasOwnProperty(field)) {
  3689. record[field] = undefined;
  3690. }
  3691. });
  3692. return record;
  3693. });
  3694. }
  3695. yield receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
  3696. // resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
  3697. // See https://github.com/WordPress/gutenberg/pull/26575
  3698. if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
  3699. const key = entity.key || DEFAULT_ENTITY_KEY;
  3700. const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
  3701. yield {
  3702. type: 'START_RESOLUTIONS',
  3703. selectorName: 'getEntityRecord',
  3704. args: resolutionsArgs
  3705. };
  3706. yield {
  3707. type: 'FINISH_RESOLUTIONS',
  3708. selectorName: 'getEntityRecord',
  3709. args: resolutionsArgs
  3710. };
  3711. }
  3712. } finally {
  3713. yield* __unstableReleaseStoreLock(lock);
  3714. }
  3715. }
  3716. resolvers_getEntityRecords.shouldInvalidate = (action, kind, name) => {
  3717. return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && kind === action.kind && name === action.name;
  3718. };
  3719. /**
  3720. * Requests the current theme.
  3721. */
  3722. function* resolvers_getCurrentTheme() {
  3723. const activeThemes = yield Object(external_wp_dataControls_["apiFetch"])({
  3724. path: '/wp/v2/themes?status=active'
  3725. });
  3726. yield receiveCurrentTheme(activeThemes[0]);
  3727. }
  3728. /**
  3729. * Requests theme supports data from the index.
  3730. */
  3731. function* resolvers_getThemeSupports() {
  3732. const activeThemes = yield Object(external_wp_dataControls_["apiFetch"])({
  3733. path: '/wp/v2/themes?status=active'
  3734. });
  3735. yield receiveThemeSupports(activeThemes[0].theme_supports);
  3736. }
  3737. /**
  3738. * Requests a preview from the from the Embed API.
  3739. *
  3740. * @param {string} url URL to get the preview for.
  3741. */
  3742. function* resolvers_getEmbedPreview(url) {
  3743. try {
  3744. const embedProxyResponse = yield Object(external_wp_dataControls_["apiFetch"])({
  3745. path: Object(external_wp_url_["addQueryArgs"])('/oembed/1.0/proxy', {
  3746. url
  3747. })
  3748. });
  3749. yield receiveEmbedPreview(url, embedProxyResponse);
  3750. } catch (error) {
  3751. // Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.
  3752. yield receiveEmbedPreview(url, false);
  3753. }
  3754. }
  3755. /**
  3756. * Checks whether the current user can perform the given action on the given
  3757. * REST resource.
  3758. *
  3759. * @param {string} action Action to check. One of: 'create', 'read', 'update',
  3760. * 'delete'.
  3761. * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.
  3762. * @param {?string} id ID of the rest resource to check.
  3763. */
  3764. function* resolvers_canUser(action, resource, id) {
  3765. const methods = {
  3766. create: 'POST',
  3767. read: 'GET',
  3768. update: 'PUT',
  3769. delete: 'DELETE'
  3770. };
  3771. const method = methods[action];
  3772. if (!method) {
  3773. throw new Error(`'${action}' is not a valid action.`);
  3774. }
  3775. const path = id ? `/wp/v2/${resource}/${id}` : `/wp/v2/${resource}`;
  3776. let response;
  3777. try {
  3778. response = yield Object(external_wp_dataControls_["apiFetch"])({
  3779. path,
  3780. // Ideally this would always be an OPTIONS request, but unfortunately there's
  3781. // a bug in the REST API which causes the Allow header to not be sent on
  3782. // OPTIONS requests to /posts/:id routes.
  3783. // https://core.trac.wordpress.org/ticket/45753
  3784. method: id ? 'GET' : 'OPTIONS',
  3785. parse: false
  3786. });
  3787. } catch (error) {
  3788. // Do nothing if our OPTIONS request comes back with an API error (4xx or
  3789. // 5xx). The previously determined isAllowed value will remain in the store.
  3790. return;
  3791. }
  3792. let allowHeader;
  3793. if (Object(external_lodash_["hasIn"])(response, ['headers', 'get'])) {
  3794. // If the request is fetched using the fetch api, the header can be
  3795. // retrieved using the 'get' method.
  3796. allowHeader = response.headers.get('allow');
  3797. } else {
  3798. // If the request was preloaded server-side and is returned by the
  3799. // preloading middleware, the header will be a simple property.
  3800. allowHeader = Object(external_lodash_["get"])(response, ['headers', 'Allow'], '');
  3801. }
  3802. const key = Object(external_lodash_["compact"])([action, resource, id]).join('/');
  3803. const isAllowed = Object(external_lodash_["includes"])(allowHeader, method);
  3804. yield receiveUserPermission(key, isAllowed);
  3805. }
  3806. /**
  3807. * Checks whether the current user can perform the given action on the given
  3808. * REST resource.
  3809. *
  3810. * @param {string} kind Entity kind.
  3811. * @param {string} name Entity name.
  3812. * @param {string} recordId Record's id.
  3813. */
  3814. function* resolvers_canUserEditEntityRecord(kind, name, recordId) {
  3815. const entities = yield getKindEntities(kind);
  3816. const entity = Object(external_lodash_["find"])(entities, {
  3817. kind,
  3818. name
  3819. });
  3820. if (!entity) {
  3821. return;
  3822. }
  3823. const resource = entity.__unstable_rest_base;
  3824. yield resolvers_canUser('update', resource, recordId);
  3825. }
  3826. /**
  3827. * Request autosave data from the REST API.
  3828. *
  3829. * @param {string} postType The type of the parent post.
  3830. * @param {number} postId The id of the parent post.
  3831. */
  3832. function* resolvers_getAutosaves(postType, postId) {
  3833. const {
  3834. rest_base: restBase
  3835. } = yield external_wp_data_["controls"].resolveSelect('core', 'getPostType', postType);
  3836. const autosaves = yield Object(external_wp_dataControls_["apiFetch"])({
  3837. path: `/wp/v2/${restBase}/${postId}/autosaves?context=edit`
  3838. });
  3839. if (autosaves && autosaves.length) {
  3840. yield receiveAutosaves(postId, autosaves);
  3841. }
  3842. }
  3843. /**
  3844. * Request autosave data from the REST API.
  3845. *
  3846. * This resolver exists to ensure the underlying autosaves are fetched via
  3847. * `getAutosaves` when a call to the `getAutosave` selector is made.
  3848. *
  3849. * @param {string} postType The type of the parent post.
  3850. * @param {number} postId The id of the parent post.
  3851. */
  3852. function* resolvers_getAutosave(postType, postId) {
  3853. yield external_wp_data_["controls"].resolveSelect('core', 'getAutosaves', postType, postId);
  3854. }
  3855. /**
  3856. * Retrieve the frontend template used for a given link.
  3857. *
  3858. * @param {string} link Link.
  3859. */
  3860. function* resolvers_experimentalGetTemplateForLink(link) {
  3861. // Ideally this should be using an apiFetch call
  3862. // We could potentially do so by adding a "filter" to the `wp_template` end point.
  3863. // Also it seems the returned object is not a regular REST API post type.
  3864. let template;
  3865. try {
  3866. template = yield regularFetch(Object(external_wp_url_["addQueryArgs"])(link, {
  3867. '_wp-find-template': true
  3868. }));
  3869. } catch (e) {// For non-FSE themes, it is possible that this request returns an error.
  3870. }
  3871. if (!template) {
  3872. return;
  3873. }
  3874. yield resolvers_getEntityRecord('postType', 'wp_template', template.id);
  3875. const record = yield external_wp_data_["controls"].select('core', 'getEntityRecord', 'postType', 'wp_template', template.id);
  3876. if (record) {
  3877. yield receiveEntityRecords('postType', 'wp_template', [record], {
  3878. 'find-template': link
  3879. });
  3880. }
  3881. }
  3882. resolvers_experimentalGetTemplateForLink.shouldInvalidate = action => {
  3883. return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
  3884. };
  3885. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/locks/selectors.js
  3886. /**
  3887. * Internal dependencies
  3888. */
  3889. function __unstableGetPendingLockRequests(state) {
  3890. return state.locks.requests;
  3891. }
  3892. function __unstableIsLockAvailable(state, store, path, {
  3893. exclusive
  3894. }) {
  3895. const storePath = [store, ...path];
  3896. const locks = state.locks.tree; // Validate all parents and the node itself
  3897. for (const node of iteratePath(locks, storePath)) {
  3898. if (hasConflictingLock({
  3899. exclusive
  3900. }, node.locks)) {
  3901. return false;
  3902. }
  3903. } // iteratePath terminates early if path is unreachable, let's
  3904. // re-fetch the node and check it exists in the tree.
  3905. const node = getNode(locks, storePath);
  3906. if (!node) {
  3907. return true;
  3908. } // Validate all nested nodes
  3909. for (const descendant of iterateDescendants(node)) {
  3910. if (hasConflictingLock({
  3911. exclusive
  3912. }, descendant.locks)) {
  3913. return false;
  3914. }
  3915. }
  3916. return true;
  3917. }
  3918. // EXTERNAL MODULE: external ["wp","element"]
  3919. var external_wp_element_ = __webpack_require__("GRId");
  3920. // EXTERNAL MODULE: external ["wp","blocks"]
  3921. var external_wp_blocks_ = __webpack_require__("HSyU");
  3922. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/entity-provider.js
  3923. /**
  3924. * WordPress dependencies
  3925. */
  3926. const entity_provider_EMPTY_ARRAY = [];
  3927. /**
  3928. * Internal dependencies
  3929. */
  3930. const entity_provider_entities = { ...defaultEntities.reduce((acc, entity) => {
  3931. if (!acc[entity.kind]) {
  3932. acc[entity.kind] = {};
  3933. }
  3934. acc[entity.kind][entity.name] = {
  3935. context: Object(external_wp_element_["createContext"])()
  3936. };
  3937. return acc;
  3938. }, {}),
  3939. ...kinds.reduce((acc, kind) => {
  3940. acc[kind.name] = {};
  3941. return acc;
  3942. }, {})
  3943. };
  3944. const entity_provider_getEntity = (kind, type) => {
  3945. if (!entity_provider_entities[kind]) {
  3946. throw new Error(`Missing entity config for kind: ${kind}.`);
  3947. }
  3948. if (!entity_provider_entities[kind][type]) {
  3949. entity_provider_entities[kind][type] = {
  3950. context: Object(external_wp_element_["createContext"])()
  3951. };
  3952. }
  3953. return entity_provider_entities[kind][type];
  3954. };
  3955. /**
  3956. * Context provider component for providing
  3957. * an entity for a specific entity type.
  3958. *
  3959. * @param {Object} props The component's props.
  3960. * @param {string} props.kind The entity kind.
  3961. * @param {string} props.type The entity type.
  3962. * @param {number} props.id The entity ID.
  3963. * @param {*} props.children The children to wrap.
  3964. *
  3965. * @return {Object} The provided children, wrapped with
  3966. * the entity's context provider.
  3967. */
  3968. function EntityProvider({
  3969. kind,
  3970. type,
  3971. id,
  3972. children
  3973. }) {
  3974. const Provider = entity_provider_getEntity(kind, type).context.Provider;
  3975. return Object(external_wp_element_["createElement"])(Provider, {
  3976. value: id
  3977. }, children);
  3978. }
  3979. /**
  3980. * Hook that returns the ID for the nearest
  3981. * provided entity of the specified type.
  3982. *
  3983. * @param {string} kind The entity kind.
  3984. * @param {string} type The entity type.
  3985. */
  3986. function useEntityId(kind, type) {
  3987. return Object(external_wp_element_["useContext"])(entity_provider_getEntity(kind, type).context);
  3988. }
  3989. /**
  3990. * Hook that returns the value and a setter for the
  3991. * specified property of the nearest provided
  3992. * entity of the specified type.
  3993. *
  3994. * @param {string} kind The entity kind.
  3995. * @param {string} type The entity type.
  3996. * @param {string} prop The property name.
  3997. * @param {string} [_id] An entity ID to use instead of the context-provided one.
  3998. *
  3999. * @return {[*, Function, *]} An array where the first item is the
  4000. * property value, the second is the
  4001. * setter and the third is the full value
  4002. * object from REST API containing more
  4003. * information like `raw`, `rendered` and
  4004. * `protected` props.
  4005. */
  4006. function useEntityProp(kind, type, prop, _id) {
  4007. const providerId = useEntityId(kind, type);
  4008. const id = _id !== null && _id !== void 0 ? _id : providerId;
  4009. const {
  4010. value,
  4011. fullValue
  4012. } = Object(external_wp_data_["useSelect"])(select => {
  4013. const {
  4014. getEntityRecord,
  4015. getEditedEntityRecord
  4016. } = select('core');
  4017. const entity = getEntityRecord(kind, type, id); // Trigger resolver.
  4018. const editedEntity = getEditedEntityRecord(kind, type, id);
  4019. return entity && editedEntity ? {
  4020. value: editedEntity[prop],
  4021. fullValue: entity[prop]
  4022. } : {};
  4023. }, [kind, type, id, prop]);
  4024. const {
  4025. editEntityRecord
  4026. } = Object(external_wp_data_["useDispatch"])('core');
  4027. const setValue = Object(external_wp_element_["useCallback"])(newValue => {
  4028. editEntityRecord(kind, type, id, {
  4029. [prop]: newValue
  4030. });
  4031. }, [kind, type, id, prop]);
  4032. return [value, setValue, fullValue];
  4033. }
  4034. /**
  4035. * Hook that returns block content getters and setters for
  4036. * the nearest provided entity of the specified type.
  4037. *
  4038. * The return value has the shape `[ blocks, onInput, onChange ]`.
  4039. * `onInput` is for block changes that don't create undo levels
  4040. * or dirty the post, non-persistent changes, and `onChange` is for
  4041. * peristent changes. They map directly to the props of a
  4042. * `BlockEditorProvider` and are intended to be used with it,
  4043. * or similar components or hooks.
  4044. *
  4045. * @param {string} kind The entity kind.
  4046. * @param {string} type The entity type.
  4047. * @param {Object} options
  4048. * @param {string} [options.id] An entity ID to use instead of the context-provided one.
  4049. *
  4050. * @return {[WPBlock[], Function, Function]} The block array and setters.
  4051. */
  4052. function useEntityBlockEditor(kind, type, {
  4053. id: _id
  4054. } = {}) {
  4055. const providerId = useEntityId(kind, type);
  4056. const id = _id !== null && _id !== void 0 ? _id : providerId;
  4057. const {
  4058. content,
  4059. blocks
  4060. } = Object(external_wp_data_["useSelect"])(select => {
  4061. const {
  4062. getEditedEntityRecord
  4063. } = select('core');
  4064. const editedEntity = getEditedEntityRecord(kind, type, id);
  4065. return {
  4066. blocks: editedEntity.blocks,
  4067. content: editedEntity.content
  4068. };
  4069. }, [kind, type, id]);
  4070. const {
  4071. __unstableCreateUndoLevel,
  4072. editEntityRecord
  4073. } = Object(external_wp_data_["useDispatch"])('core');
  4074. Object(external_wp_element_["useEffect"])(() => {
  4075. // Load the blocks from the content if not already in state
  4076. // Guard against other instances that might have
  4077. // set content to a function already or the blocks are already in state.
  4078. if (content && typeof content !== 'function' && !blocks) {
  4079. const parsedContent = Object(external_wp_blocks_["parse"])(content);
  4080. editEntityRecord(kind, type, id, {
  4081. blocks: parsedContent
  4082. }, {
  4083. undoIgnore: true
  4084. });
  4085. }
  4086. }, [content]);
  4087. const onChange = Object(external_wp_element_["useCallback"])((newBlocks, options) => {
  4088. const {
  4089. selection
  4090. } = options;
  4091. const edits = {
  4092. blocks: newBlocks,
  4093. selection
  4094. };
  4095. const noChange = blocks === edits.blocks;
  4096. if (noChange) {
  4097. return __unstableCreateUndoLevel(kind, type, id);
  4098. } // We create a new function here on every persistent edit
  4099. // to make sure the edit makes the post dirty and creates
  4100. // a new undo level.
  4101. edits.content = ({
  4102. blocks: blocksForSerialization = []
  4103. }) => Object(external_wp_blocks_["__unstableSerializeAndClean"])(blocksForSerialization);
  4104. editEntityRecord(kind, type, id, edits);
  4105. }, [kind, type, id, blocks]);
  4106. const onInput = Object(external_wp_element_["useCallback"])((newBlocks, options) => {
  4107. const {
  4108. selection
  4109. } = options;
  4110. const edits = {
  4111. blocks: newBlocks,
  4112. selection
  4113. };
  4114. editEntityRecord(kind, type, id, edits);
  4115. }, [kind, type, id]);
  4116. return [blocks !== null && blocks !== void 0 ? blocks : entity_provider_EMPTY_ARRAY, onInput, onChange];
  4117. }
  4118. // EXTERNAL MODULE: external ["wp","htmlEntities"]
  4119. var external_wp_htmlEntities_ = __webpack_require__("rmEH");
  4120. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/__experimental-fetch-link-suggestions.js
  4121. /**
  4122. * WordPress dependencies
  4123. */
  4124. /**
  4125. * Filters the search by type
  4126. *
  4127. * @typedef { 'post' | 'term' | 'post-format' } WPLinkSearchType
  4128. */
  4129. /**
  4130. * A link with an id may be of kind post-type or taxonomy
  4131. *
  4132. * @typedef { 'post-type' | 'taxonomy' } WPKind
  4133. */
  4134. /**
  4135. * @typedef WPLinkSearchOptions
  4136. *
  4137. * @property {boolean} [isInitialSuggestions] Displays initial search suggestions, when true.
  4138. * @property {WPLinkSearchType} [type] Filters by search type.
  4139. * @property {string} [subtype] Slug of the post-type or taxonomy.
  4140. * @property {number} [page] Which page of results to return.
  4141. * @property {number} [perPage] Search results per page.
  4142. */
  4143. /**
  4144. * @typedef WPLinkSearchResult
  4145. *
  4146. * @property {number} id Post or term id.
  4147. * @property {string} url Link url.
  4148. * @property {string} title Title of the link.
  4149. * @property {string} type The taxonomy or post type slug or type URL.
  4150. * @property {WPKind} [kind] Link kind of post-type or taxonomy
  4151. */
  4152. /**
  4153. * @typedef WPEditorSettings
  4154. *
  4155. * @property {boolean} [ disablePostFormats ] Disables post formats, when true.
  4156. */
  4157. /**
  4158. * Fetches link suggestions from the API.
  4159. *
  4160. * @async
  4161. * @param {string} search
  4162. * @param {WPLinkSearchOptions} [searchOptions]
  4163. * @param {WPEditorSettings} [settings]
  4164. *
  4165. * @example
  4166. * ```js
  4167. * import { __experimentalFetchLinkSuggestions as fetchLinkSuggestions } from '@wordpress/core-data';
  4168. *
  4169. * //...
  4170. *
  4171. * export function initialize( id, settings ) {
  4172. *
  4173. * settings.__experimentalFetchLinkSuggestions = (
  4174. * search,
  4175. * searchOptions
  4176. * ) => fetchLinkSuggestions( search, searchOptions, settings );
  4177. * ```
  4178. * @return {Promise< WPLinkSearchResult[] >} List of search suggestions
  4179. */
  4180. const fetchLinkSuggestions = async (search, searchOptions = {}, settings = {}) => {
  4181. const {
  4182. isInitialSuggestions = false,
  4183. type = undefined,
  4184. subtype = undefined,
  4185. page = undefined,
  4186. perPage = isInitialSuggestions ? 3 : 20
  4187. } = searchOptions;
  4188. const {
  4189. disablePostFormats = false
  4190. } = settings;
  4191. const queries = [];
  4192. if (!type || type === 'post') {
  4193. queries.push(external_wp_apiFetch_default()({
  4194. path: Object(external_wp_url_["addQueryArgs"])('/wp/v2/search', {
  4195. search,
  4196. page,
  4197. per_page: perPage,
  4198. type: 'post',
  4199. subtype
  4200. })
  4201. }).then(results => {
  4202. return results.map(result => {
  4203. return { ...result,
  4204. meta: {
  4205. kind: 'post-type',
  4206. subtype
  4207. }
  4208. };
  4209. });
  4210. }).catch(() => []) // fail by returning no results
  4211. );
  4212. }
  4213. if (!type || type === 'term') {
  4214. queries.push(external_wp_apiFetch_default()({
  4215. path: Object(external_wp_url_["addQueryArgs"])('/wp/v2/search', {
  4216. search,
  4217. page,
  4218. per_page: perPage,
  4219. type: 'term',
  4220. subtype
  4221. })
  4222. }).then(results => {
  4223. return results.map(result => {
  4224. return { ...result,
  4225. meta: {
  4226. kind: 'taxonomy',
  4227. subtype
  4228. }
  4229. };
  4230. });
  4231. }).catch(() => []));
  4232. }
  4233. if (!disablePostFormats && (!type || type === 'post-format')) {
  4234. queries.push(external_wp_apiFetch_default()({
  4235. path: Object(external_wp_url_["addQueryArgs"])('/wp/v2/search', {
  4236. search,
  4237. page,
  4238. per_page: perPage,
  4239. type: 'post-format',
  4240. subtype
  4241. })
  4242. }).then(results => {
  4243. return results.map(result => {
  4244. return { ...result,
  4245. meta: {
  4246. kind: 'taxonomy',
  4247. subtype
  4248. }
  4249. };
  4250. });
  4251. }).catch(() => []));
  4252. }
  4253. return Promise.all(queries).then(results => {
  4254. return results.reduce((accumulator, current) => accumulator.concat(current), //flatten list
  4255. []).filter(
  4256. /**
  4257. * @param {{ id: number }} result
  4258. */
  4259. result => {
  4260. return !!result.id;
  4261. }).slice(0, perPage).map(
  4262. /**
  4263. * @param {{ id: number, url:string, title?:string, subtype?: string, type?: string }} result
  4264. */
  4265. result => {
  4266. var _result$meta;
  4267. return {
  4268. id: result.id,
  4269. url: result.url,
  4270. title: Object(external_wp_htmlEntities_["decodeEntities"])(result.title || '') || Object(external_wp_i18n_["__"])('(no title)'),
  4271. type: result.subtype || result.type,
  4272. kind: result === null || result === void 0 ? void 0 : (_result$meta = result.meta) === null || _result$meta === void 0 ? void 0 : _result$meta.kind
  4273. };
  4274. });
  4275. });
  4276. };
  4277. /* harmony default export */ var _experimental_fetch_link_suggestions = (fetchLinkSuggestions);
  4278. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/__experimental-fetch-remote-url-data.js
  4279. /**
  4280. * WordPress dependencies
  4281. */
  4282. /**
  4283. * @typedef WPRemoteUrlData
  4284. *
  4285. * @property {string} title contents of the remote URL's `<title>` tag.
  4286. */
  4287. /**
  4288. * Fetches data about a remote URL.
  4289. * eg: <title> tag, favicon...etc.
  4290. *
  4291. * @async
  4292. * @param {string} url
  4293. *
  4294. * @example
  4295. * ```js
  4296. * import { __experimentalFetchRemoteUrlData as fetchRemoteUrlData } from '@wordpress/core-data';
  4297. *
  4298. * //...
  4299. *
  4300. * export function initialize( id, settings ) {
  4301. *
  4302. * settings.__experimentalFetchRemoteUrlData = (
  4303. * url
  4304. * ) => fetchRemoteUrlData( url );
  4305. * ```
  4306. * @return {Promise< WPRemoteUrlData[] >} Remote URL data.
  4307. */
  4308. const fetchRemoteUrlData = async url => {
  4309. const endpoint = '/__experimental/url-details';
  4310. const args = {
  4311. url: Object(external_wp_url_["prependHTTP"])(url)
  4312. };
  4313. return external_wp_apiFetch_default()({
  4314. path: Object(external_wp_url_["addQueryArgs"])(endpoint, args)
  4315. });
  4316. };
  4317. /* harmony default export */ var _experimental_fetch_remote_url_data = (fetchRemoteUrlData);
  4318. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/fetch/index.js
  4319. // CONCATENATED MODULE: ./node_modules/@wordpress/core-data/build-module/index.js
  4320. /**
  4321. * WordPress dependencies
  4322. */
  4323. /**
  4324. * Internal dependencies
  4325. */
  4326. // The entity selectors/resolvers and actions are shortcuts to their generic equivalents
  4327. // (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecordss)
  4328. // Instead of getEntityRecord, the consumer could use more user-frieldly named selector: getPostType, getTaxonomy...
  4329. // The "kind" and the "name" of the entity are combined to generate these shortcuts.
  4330. const entitySelectors = defaultEntities.reduce((result, entity) => {
  4331. const {
  4332. kind,
  4333. name
  4334. } = entity;
  4335. result[getMethodName(kind, name)] = (state, key) => getEntityRecord(state, kind, name, key);
  4336. result[getMethodName(kind, name, 'get', true)] = (state, ...args) => getEntityRecords(state, kind, name, ...args);
  4337. return result;
  4338. }, {});
  4339. const entityResolvers = defaultEntities.reduce((result, entity) => {
  4340. const {
  4341. kind,
  4342. name
  4343. } = entity;
  4344. result[getMethodName(kind, name)] = key => resolvers_getEntityRecord(kind, name, key);
  4345. const pluralMethodName = getMethodName(kind, name, 'get', true);
  4346. result[pluralMethodName] = (...args) => resolvers_getEntityRecords(kind, name, ...args);
  4347. result[pluralMethodName].shouldInvalidate = (action, ...args) => resolvers_getEntityRecords.shouldInvalidate(action, kind, name, ...args);
  4348. return result;
  4349. }, {});
  4350. const entityActions = defaultEntities.reduce((result, entity) => {
  4351. const {
  4352. kind,
  4353. name
  4354. } = entity;
  4355. result[getMethodName(kind, name, 'save')] = key => saveEntityRecord(kind, name, key);
  4356. result[getMethodName(kind, name, 'delete')] = (key, query) => deleteEntityRecord(kind, name, key, query);
  4357. return result;
  4358. }, {});
  4359. const storeConfig = {
  4360. reducer: build_module_reducer,
  4361. controls: { ...build_module_controls,
  4362. ...external_wp_dataControls_["controls"]
  4363. },
  4364. actions: { ...build_module_actions_namespaceObject,
  4365. ...entityActions,
  4366. ...locks_actions_namespaceObject
  4367. },
  4368. selectors: { ...build_module_selectors_namespaceObject,
  4369. ...entitySelectors,
  4370. ...locks_selectors_namespaceObject
  4371. },
  4372. resolvers: { ...resolvers_namespaceObject,
  4373. ...entityResolvers
  4374. }
  4375. };
  4376. /**
  4377. * Store definition for the code data namespace.
  4378. *
  4379. * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore
  4380. *
  4381. * @type {Object}
  4382. */
  4383. const build_module_store = Object(external_wp_data_["createReduxStore"])(STORE_NAME, storeConfig);
  4384. Object(external_wp_data_["register"])(build_module_store);
  4385. /***/ }),
  4386. /***/ "l3Sj":
  4387. /***/ (function(module, exports) {
  4388. (function() { module.exports = window["wp"]["i18n"]; }());
  4389. /***/ }),
  4390. /***/ "pPDe":
  4391. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  4392. "use strict";
  4393. var LEAF_KEY, hasWeakMap;
  4394. /**
  4395. * Arbitrary value used as key for referencing cache object in WeakMap tree.
  4396. *
  4397. * @type {Object}
  4398. */
  4399. LEAF_KEY = {};
  4400. /**
  4401. * Whether environment supports WeakMap.
  4402. *
  4403. * @type {boolean}
  4404. */
  4405. hasWeakMap = typeof WeakMap !== 'undefined';
  4406. /**
  4407. * Returns the first argument as the sole entry in an array.
  4408. *
  4409. * @param {*} value Value to return.
  4410. *
  4411. * @return {Array} Value returned as entry in array.
  4412. */
  4413. function arrayOf( value ) {
  4414. return [ value ];
  4415. }
  4416. /**
  4417. * Returns true if the value passed is object-like, or false otherwise. A value
  4418. * is object-like if it can support property assignment, e.g. object or array.
  4419. *
  4420. * @param {*} value Value to test.
  4421. *
  4422. * @return {boolean} Whether value is object-like.
  4423. */
  4424. function isObjectLike( value ) {
  4425. return !! value && 'object' === typeof value;
  4426. }
  4427. /**
  4428. * Creates and returns a new cache object.
  4429. *
  4430. * @return {Object} Cache object.
  4431. */
  4432. function createCache() {
  4433. var cache = {
  4434. clear: function() {
  4435. cache.head = null;
  4436. },
  4437. };
  4438. return cache;
  4439. }
  4440. /**
  4441. * Returns true if entries within the two arrays are strictly equal by
  4442. * reference from a starting index.
  4443. *
  4444. * @param {Array} a First array.
  4445. * @param {Array} b Second array.
  4446. * @param {number} fromIndex Index from which to start comparison.
  4447. *
  4448. * @return {boolean} Whether arrays are shallowly equal.
  4449. */
  4450. function isShallowEqual( a, b, fromIndex ) {
  4451. var i;
  4452. if ( a.length !== b.length ) {
  4453. return false;
  4454. }
  4455. for ( i = fromIndex; i < a.length; i++ ) {
  4456. if ( a[ i ] !== b[ i ] ) {
  4457. return false;
  4458. }
  4459. }
  4460. return true;
  4461. }
  4462. /**
  4463. * Returns a memoized selector function. The getDependants function argument is
  4464. * called before the memoized selector and is expected to return an immutable
  4465. * reference or array of references on which the selector depends for computing
  4466. * its own return value. The memoize cache is preserved only as long as those
  4467. * dependant references remain the same. If getDependants returns a different
  4468. * reference(s), the cache is cleared and the selector value regenerated.
  4469. *
  4470. * @param {Function} selector Selector function.
  4471. * @param {Function} getDependants Dependant getter returning an immutable
  4472. * reference or array of reference used in
  4473. * cache bust consideration.
  4474. *
  4475. * @return {Function} Memoized selector.
  4476. */
  4477. /* harmony default export */ __webpack_exports__["a"] = (function( selector, getDependants ) {
  4478. var rootCache, getCache;
  4479. // Use object source as dependant if getter not provided
  4480. if ( ! getDependants ) {
  4481. getDependants = arrayOf;
  4482. }
  4483. /**
  4484. * Returns the root cache. If WeakMap is supported, this is assigned to the
  4485. * root WeakMap cache set, otherwise it is a shared instance of the default
  4486. * cache object.
  4487. *
  4488. * @return {(WeakMap|Object)} Root cache object.
  4489. */
  4490. function getRootCache() {
  4491. return rootCache;
  4492. }
  4493. /**
  4494. * Returns the cache for a given dependants array. When possible, a WeakMap
  4495. * will be used to create a unique cache for each set of dependants. This
  4496. * is feasible due to the nature of WeakMap in allowing garbage collection
  4497. * to occur on entries where the key object is no longer referenced. Since
  4498. * WeakMap requires the key to be an object, this is only possible when the
  4499. * dependant is object-like. The root cache is created as a hierarchy where
  4500. * each top-level key is the first entry in a dependants set, the value a
  4501. * WeakMap where each key is the next dependant, and so on. This continues
  4502. * so long as the dependants are object-like. If no dependants are object-
  4503. * like, then the cache is shared across all invocations.
  4504. *
  4505. * @see isObjectLike
  4506. *
  4507. * @param {Array} dependants Selector dependants.
  4508. *
  4509. * @return {Object} Cache object.
  4510. */
  4511. function getWeakMapCache( dependants ) {
  4512. var caches = rootCache,
  4513. isUniqueByDependants = true,
  4514. i, dependant, map, cache;
  4515. for ( i = 0; i < dependants.length; i++ ) {
  4516. dependant = dependants[ i ];
  4517. // Can only compose WeakMap from object-like key.
  4518. if ( ! isObjectLike( dependant ) ) {
  4519. isUniqueByDependants = false;
  4520. break;
  4521. }
  4522. // Does current segment of cache already have a WeakMap?
  4523. if ( caches.has( dependant ) ) {
  4524. // Traverse into nested WeakMap.
  4525. caches = caches.get( dependant );
  4526. } else {
  4527. // Create, set, and traverse into a new one.
  4528. map = new WeakMap();
  4529. caches.set( dependant, map );
  4530. caches = map;
  4531. }
  4532. }
  4533. // We use an arbitrary (but consistent) object as key for the last item
  4534. // in the WeakMap to serve as our running cache.
  4535. if ( ! caches.has( LEAF_KEY ) ) {
  4536. cache = createCache();
  4537. cache.isUniqueByDependants = isUniqueByDependants;
  4538. caches.set( LEAF_KEY, cache );
  4539. }
  4540. return caches.get( LEAF_KEY );
  4541. }
  4542. // Assign cache handler by availability of WeakMap
  4543. getCache = hasWeakMap ? getWeakMapCache : getRootCache;
  4544. /**
  4545. * Resets root memoization cache.
  4546. */
  4547. function clear() {
  4548. rootCache = hasWeakMap ? new WeakMap() : createCache();
  4549. }
  4550. // eslint-disable-next-line jsdoc/check-param-names
  4551. /**
  4552. * The augmented selector call, considering first whether dependants have
  4553. * changed before passing it to underlying memoize function.
  4554. *
  4555. * @param {Object} source Source object for derivation.
  4556. * @param {...*} extraArgs Additional arguments to pass to selector.
  4557. *
  4558. * @return {*} Selector result.
  4559. */
  4560. function callSelector( /* source, ...extraArgs */ ) {
  4561. var len = arguments.length,
  4562. cache, node, i, args, dependants;
  4563. // Create copy of arguments (avoid leaking deoptimization).
  4564. args = new Array( len );
  4565. for ( i = 0; i < len; i++ ) {
  4566. args[ i ] = arguments[ i ];
  4567. }
  4568. dependants = getDependants.apply( null, args );
  4569. cache = getCache( dependants );
  4570. // If not guaranteed uniqueness by dependants (primitive type or lack
  4571. // of WeakMap support), shallow compare against last dependants and, if
  4572. // references have changed, destroy cache to recalculate result.
  4573. if ( ! cache.isUniqueByDependants ) {
  4574. if ( cache.lastDependants && ! isShallowEqual( dependants, cache.lastDependants, 0 ) ) {
  4575. cache.clear();
  4576. }
  4577. cache.lastDependants = dependants;
  4578. }
  4579. node = cache.head;
  4580. while ( node ) {
  4581. // Check whether node arguments match arguments
  4582. if ( ! isShallowEqual( node.args, args, 1 ) ) {
  4583. node = node.next;
  4584. continue;
  4585. }
  4586. // At this point we can assume we've found a match
  4587. // Surface matched node to head if not already
  4588. if ( node !== cache.head ) {
  4589. // Adjust siblings to point to each other.
  4590. node.prev.next = node.next;
  4591. if ( node.next ) {
  4592. node.next.prev = node.prev;
  4593. }
  4594. node.next = cache.head;
  4595. node.prev = null;
  4596. cache.head.prev = node;
  4597. cache.head = node;
  4598. }
  4599. // Return immediately
  4600. return node.val;
  4601. }
  4602. // No cached value found. Continue to insertion phase:
  4603. node = {
  4604. // Generate the result from original function
  4605. val: selector.apply( null, args ),
  4606. };
  4607. // Avoid including the source object in the cache.
  4608. args[ 0 ] = null;
  4609. node.args = args;
  4610. // Don't need to check whether node is already head, since it would
  4611. // have been returned above already if it was
  4612. // Shift existing head down list
  4613. if ( cache.head ) {
  4614. cache.head.prev = node;
  4615. node.next = cache.head;
  4616. }
  4617. cache.head = node;
  4618. return node.val;
  4619. }
  4620. callSelector.getDependants = getDependants;
  4621. callSelector.clear = clear;
  4622. clear();
  4623. return callSelector;
  4624. });
  4625. /***/ }),
  4626. /***/ "rl8x":
  4627. /***/ (function(module, exports) {
  4628. (function() { module.exports = window["wp"]["isShallowEqual"]; }());
  4629. /***/ }),
  4630. /***/ "rmEH":
  4631. /***/ (function(module, exports) {
  4632. (function() { module.exports = window["wp"]["htmlEntities"]; }());
  4633. /***/ }),
  4634. /***/ "ywyh":
  4635. /***/ (function(module, exports) {
  4636. (function() { module.exports = window["wp"]["apiFetch"]; }());
  4637. /***/ })
  4638. /******/ });