No Description

core-data.js 190KB

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