main.esm.js 327 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577
  1. /*!
  2. FullCalendar Core Package v4.4.0
  3. Docs & License: https://fullcalendar.io/
  4. (c) 2019 Adam Shaw
  5. */
  6. // Creating
  7. // ----------------------------------------------------------------------------------------------------------------
  8. var elementPropHash = {
  9. className: true,
  10. colSpan: true,
  11. rowSpan: true
  12. };
  13. var containerTagHash = {
  14. '<tr': 'tbody',
  15. '<td': 'tr'
  16. };
  17. function createElement(tagName, attrs, content) {
  18. var el = document.createElement(tagName);
  19. if (attrs) {
  20. for (var attrName in attrs) {
  21. if (attrName === 'style') {
  22. applyStyle(el, attrs[attrName]);
  23. }
  24. else if (elementPropHash[attrName]) {
  25. el[attrName] = attrs[attrName];
  26. }
  27. else {
  28. el.setAttribute(attrName, attrs[attrName]);
  29. }
  30. }
  31. }
  32. if (typeof content === 'string') {
  33. el.innerHTML = content; // shortcut. no need to process HTML in any way
  34. }
  35. else if (content != null) {
  36. appendToElement(el, content);
  37. }
  38. return el;
  39. }
  40. function htmlToElement(html) {
  41. html = html.trim();
  42. var container = document.createElement(computeContainerTag(html));
  43. container.innerHTML = html;
  44. return container.firstChild;
  45. }
  46. function htmlToElements(html) {
  47. return Array.prototype.slice.call(htmlToNodeList(html));
  48. }
  49. function htmlToNodeList(html) {
  50. html = html.trim();
  51. var container = document.createElement(computeContainerTag(html));
  52. container.innerHTML = html;
  53. return container.childNodes;
  54. }
  55. // assumes html already trimmed and tag names are lowercase
  56. function computeContainerTag(html) {
  57. return containerTagHash[html.substr(0, 3) // faster than using regex
  58. ] || 'div';
  59. }
  60. function appendToElement(el, content) {
  61. var childNodes = normalizeContent(content);
  62. for (var i = 0; i < childNodes.length; i++) {
  63. el.appendChild(childNodes[i]);
  64. }
  65. }
  66. function prependToElement(parent, content) {
  67. var newEls = normalizeContent(content);
  68. var afterEl = parent.firstChild || null; // if no firstChild, will append to end, but that's okay, b/c there were no children
  69. for (var i = 0; i < newEls.length; i++) {
  70. parent.insertBefore(newEls[i], afterEl);
  71. }
  72. }
  73. function insertAfterElement(refEl, content) {
  74. var newEls = normalizeContent(content);
  75. var afterEl = refEl.nextSibling || null;
  76. for (var i = 0; i < newEls.length; i++) {
  77. refEl.parentNode.insertBefore(newEls[i], afterEl);
  78. }
  79. }
  80. function normalizeContent(content) {
  81. var els;
  82. if (typeof content === 'string') {
  83. els = htmlToElements(content);
  84. }
  85. else if (content instanceof Node) {
  86. els = [content];
  87. }
  88. else { // Node[] or NodeList
  89. els = Array.prototype.slice.call(content);
  90. }
  91. return els;
  92. }
  93. function removeElement(el) {
  94. if (el.parentNode) {
  95. el.parentNode.removeChild(el);
  96. }
  97. }
  98. // Querying
  99. // ----------------------------------------------------------------------------------------------------------------
  100. // from https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
  101. var matchesMethod = Element.prototype.matches ||
  102. Element.prototype.matchesSelector ||
  103. Element.prototype.msMatchesSelector;
  104. var closestMethod = Element.prototype.closest || function (selector) {
  105. // polyfill
  106. var el = this;
  107. if (!document.documentElement.contains(el)) {
  108. return null;
  109. }
  110. do {
  111. if (elementMatches(el, selector)) {
  112. return el;
  113. }
  114. el = el.parentElement || el.parentNode;
  115. } while (el !== null && el.nodeType === 1);
  116. return null;
  117. };
  118. function elementClosest(el, selector) {
  119. return closestMethod.call(el, selector);
  120. }
  121. function elementMatches(el, selector) {
  122. return matchesMethod.call(el, selector);
  123. }
  124. // accepts multiple subject els
  125. // returns a real array. good for methods like forEach
  126. function findElements(container, selector) {
  127. var containers = container instanceof HTMLElement ? [container] : container;
  128. var allMatches = [];
  129. for (var i = 0; i < containers.length; i++) {
  130. var matches = containers[i].querySelectorAll(selector);
  131. for (var j = 0; j < matches.length; j++) {
  132. allMatches.push(matches[j]);
  133. }
  134. }
  135. return allMatches;
  136. }
  137. // accepts multiple subject els
  138. // only queries direct child elements
  139. function findChildren(parent, selector) {
  140. var parents = parent instanceof HTMLElement ? [parent] : parent;
  141. var allMatches = [];
  142. for (var i = 0; i < parents.length; i++) {
  143. var childNodes = parents[i].children; // only ever elements
  144. for (var j = 0; j < childNodes.length; j++) {
  145. var childNode = childNodes[j];
  146. if (!selector || elementMatches(childNode, selector)) {
  147. allMatches.push(childNode);
  148. }
  149. }
  150. }
  151. return allMatches;
  152. }
  153. // Attributes
  154. // ----------------------------------------------------------------------------------------------------------------
  155. function forceClassName(el, className, bool) {
  156. if (bool) {
  157. el.classList.add(className);
  158. }
  159. else {
  160. el.classList.remove(className);
  161. }
  162. }
  163. // Style
  164. // ----------------------------------------------------------------------------------------------------------------
  165. var PIXEL_PROP_RE = /(top|left|right|bottom|width|height)$/i;
  166. function applyStyle(el, props) {
  167. for (var propName in props) {
  168. applyStyleProp(el, propName, props[propName]);
  169. }
  170. }
  171. function applyStyleProp(el, name, val) {
  172. if (val == null) {
  173. el.style[name] = '';
  174. }
  175. else if (typeof val === 'number' && PIXEL_PROP_RE.test(name)) {
  176. el.style[name] = val + 'px';
  177. }
  178. else {
  179. el.style[name] = val;
  180. }
  181. }
  182. function pointInsideRect(point, rect) {
  183. return point.left >= rect.left &&
  184. point.left < rect.right &&
  185. point.top >= rect.top &&
  186. point.top < rect.bottom;
  187. }
  188. // Returns a new rectangle that is the intersection of the two rectangles. If they don't intersect, returns false
  189. function intersectRects(rect1, rect2) {
  190. var res = {
  191. left: Math.max(rect1.left, rect2.left),
  192. right: Math.min(rect1.right, rect2.right),
  193. top: Math.max(rect1.top, rect2.top),
  194. bottom: Math.min(rect1.bottom, rect2.bottom)
  195. };
  196. if (res.left < res.right && res.top < res.bottom) {
  197. return res;
  198. }
  199. return false;
  200. }
  201. function translateRect(rect, deltaX, deltaY) {
  202. return {
  203. left: rect.left + deltaX,
  204. right: rect.right + deltaX,
  205. top: rect.top + deltaY,
  206. bottom: rect.bottom + deltaY
  207. };
  208. }
  209. // Returns a new point that will have been moved to reside within the given rectangle
  210. function constrainPoint(point, rect) {
  211. return {
  212. left: Math.min(Math.max(point.left, rect.left), rect.right),
  213. top: Math.min(Math.max(point.top, rect.top), rect.bottom)
  214. };
  215. }
  216. // Returns a point that is the center of the given rectangle
  217. function getRectCenter(rect) {
  218. return {
  219. left: (rect.left + rect.right) / 2,
  220. top: (rect.top + rect.bottom) / 2
  221. };
  222. }
  223. // Subtracts point2's coordinates from point1's coordinates, returning a delta
  224. function diffPoints(point1, point2) {
  225. return {
  226. left: point1.left - point2.left,
  227. top: point1.top - point2.top
  228. };
  229. }
  230. // Logic for determining if, when the element is right-to-left, the scrollbar appears on the left side
  231. var isRtlScrollbarOnLeft = null;
  232. function getIsRtlScrollbarOnLeft() {
  233. if (isRtlScrollbarOnLeft === null) {
  234. isRtlScrollbarOnLeft = computeIsRtlScrollbarOnLeft();
  235. }
  236. return isRtlScrollbarOnLeft;
  237. }
  238. function computeIsRtlScrollbarOnLeft() {
  239. var outerEl = createElement('div', {
  240. style: {
  241. position: 'absolute',
  242. top: -1000,
  243. left: 0,
  244. border: 0,
  245. padding: 0,
  246. overflow: 'scroll',
  247. direction: 'rtl'
  248. }
  249. }, '<div></div>');
  250. document.body.appendChild(outerEl);
  251. var innerEl = outerEl.firstChild;
  252. var res = innerEl.getBoundingClientRect().left > outerEl.getBoundingClientRect().left;
  253. removeElement(outerEl);
  254. return res;
  255. }
  256. // The scrollbar width computations in computeEdges are sometimes flawed when it comes to
  257. // retina displays, rounding, and IE11. Massage them into a usable value.
  258. function sanitizeScrollbarWidth(width) {
  259. width = Math.max(0, width); // no negatives
  260. width = Math.round(width);
  261. return width;
  262. }
  263. function computeEdges(el, getPadding) {
  264. if (getPadding === void 0) { getPadding = false; }
  265. var computedStyle = window.getComputedStyle(el);
  266. var borderLeft = parseInt(computedStyle.borderLeftWidth, 10) || 0;
  267. var borderRight = parseInt(computedStyle.borderRightWidth, 10) || 0;
  268. var borderTop = parseInt(computedStyle.borderTopWidth, 10) || 0;
  269. var borderBottom = parseInt(computedStyle.borderBottomWidth, 10) || 0;
  270. // must use offset(Width|Height) because compatible with client(Width|Height)
  271. var scrollbarLeftRight = sanitizeScrollbarWidth(el.offsetWidth - el.clientWidth - borderLeft - borderRight);
  272. var scrollbarBottom = sanitizeScrollbarWidth(el.offsetHeight - el.clientHeight - borderTop - borderBottom);
  273. var res = {
  274. borderLeft: borderLeft,
  275. borderRight: borderRight,
  276. borderTop: borderTop,
  277. borderBottom: borderBottom,
  278. scrollbarBottom: scrollbarBottom,
  279. scrollbarLeft: 0,
  280. scrollbarRight: 0
  281. };
  282. if (getIsRtlScrollbarOnLeft() && computedStyle.direction === 'rtl') { // is the scrollbar on the left side?
  283. res.scrollbarLeft = scrollbarLeftRight;
  284. }
  285. else {
  286. res.scrollbarRight = scrollbarLeftRight;
  287. }
  288. if (getPadding) {
  289. res.paddingLeft = parseInt(computedStyle.paddingLeft, 10) || 0;
  290. res.paddingRight = parseInt(computedStyle.paddingRight, 10) || 0;
  291. res.paddingTop = parseInt(computedStyle.paddingTop, 10) || 0;
  292. res.paddingBottom = parseInt(computedStyle.paddingBottom, 10) || 0;
  293. }
  294. return res;
  295. }
  296. function computeInnerRect(el, goWithinPadding) {
  297. if (goWithinPadding === void 0) { goWithinPadding = false; }
  298. var outerRect = computeRect(el);
  299. var edges = computeEdges(el, goWithinPadding);
  300. var res = {
  301. left: outerRect.left + edges.borderLeft + edges.scrollbarLeft,
  302. right: outerRect.right - edges.borderRight - edges.scrollbarRight,
  303. top: outerRect.top + edges.borderTop,
  304. bottom: outerRect.bottom - edges.borderBottom - edges.scrollbarBottom
  305. };
  306. if (goWithinPadding) {
  307. res.left += edges.paddingLeft;
  308. res.right -= edges.paddingRight;
  309. res.top += edges.paddingTop;
  310. res.bottom -= edges.paddingBottom;
  311. }
  312. return res;
  313. }
  314. function computeRect(el) {
  315. var rect = el.getBoundingClientRect();
  316. return {
  317. left: rect.left + window.pageXOffset,
  318. top: rect.top + window.pageYOffset,
  319. right: rect.right + window.pageXOffset,
  320. bottom: rect.bottom + window.pageYOffset
  321. };
  322. }
  323. function computeViewportRect() {
  324. return {
  325. left: window.pageXOffset,
  326. right: window.pageXOffset + document.documentElement.clientWidth,
  327. top: window.pageYOffset,
  328. bottom: window.pageYOffset + document.documentElement.clientHeight
  329. };
  330. }
  331. function computeHeightAndMargins(el) {
  332. return el.getBoundingClientRect().height + computeVMargins(el);
  333. }
  334. function computeVMargins(el) {
  335. var computed = window.getComputedStyle(el);
  336. return parseInt(computed.marginTop, 10) +
  337. parseInt(computed.marginBottom, 10);
  338. }
  339. // does not return window
  340. function getClippingParents(el) {
  341. var parents = [];
  342. while (el instanceof HTMLElement) { // will stop when gets to document or null
  343. var computedStyle = window.getComputedStyle(el);
  344. if (computedStyle.position === 'fixed') {
  345. break;
  346. }
  347. if ((/(auto|scroll)/).test(computedStyle.overflow + computedStyle.overflowY + computedStyle.overflowX)) {
  348. parents.push(el);
  349. }
  350. el = el.parentNode;
  351. }
  352. return parents;
  353. }
  354. function computeClippingRect(el) {
  355. return getClippingParents(el)
  356. .map(function (el) {
  357. return computeInnerRect(el);
  358. })
  359. .concat(computeViewportRect())
  360. .reduce(function (rect0, rect1) {
  361. return intersectRects(rect0, rect1) || rect1; // should always intersect
  362. });
  363. }
  364. // Stops a mouse/touch event from doing it's native browser action
  365. function preventDefault(ev) {
  366. ev.preventDefault();
  367. }
  368. // Event Delegation
  369. // ----------------------------------------------------------------------------------------------------------------
  370. function listenBySelector(container, eventType, selector, handler) {
  371. function realHandler(ev) {
  372. var matchedChild = elementClosest(ev.target, selector);
  373. if (matchedChild) {
  374. handler.call(matchedChild, ev, matchedChild);
  375. }
  376. }
  377. container.addEventListener(eventType, realHandler);
  378. return function () {
  379. container.removeEventListener(eventType, realHandler);
  380. };
  381. }
  382. function listenToHoverBySelector(container, selector, onMouseEnter, onMouseLeave) {
  383. var currentMatchedChild;
  384. return listenBySelector(container, 'mouseover', selector, function (ev, matchedChild) {
  385. if (matchedChild !== currentMatchedChild) {
  386. currentMatchedChild = matchedChild;
  387. onMouseEnter(ev, matchedChild);
  388. var realOnMouseLeave_1 = function (ev) {
  389. currentMatchedChild = null;
  390. onMouseLeave(ev, matchedChild);
  391. matchedChild.removeEventListener('mouseleave', realOnMouseLeave_1);
  392. };
  393. // listen to the next mouseleave, and then unattach
  394. matchedChild.addEventListener('mouseleave', realOnMouseLeave_1);
  395. }
  396. });
  397. }
  398. // Animation
  399. // ----------------------------------------------------------------------------------------------------------------
  400. var transitionEventNames = [
  401. 'webkitTransitionEnd',
  402. 'otransitionend',
  403. 'oTransitionEnd',
  404. 'msTransitionEnd',
  405. 'transitionend'
  406. ];
  407. // triggered only when the next single subsequent transition finishes
  408. function whenTransitionDone(el, callback) {
  409. var realCallback = function (ev) {
  410. callback(ev);
  411. transitionEventNames.forEach(function (eventName) {
  412. el.removeEventListener(eventName, realCallback);
  413. });
  414. };
  415. transitionEventNames.forEach(function (eventName) {
  416. el.addEventListener(eventName, realCallback); // cross-browser way to determine when the transition finishes
  417. });
  418. }
  419. var DAY_IDS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
  420. // Adding
  421. function addWeeks(m, n) {
  422. var a = dateToUtcArray(m);
  423. a[2] += n * 7;
  424. return arrayToUtcDate(a);
  425. }
  426. function addDays(m, n) {
  427. var a = dateToUtcArray(m);
  428. a[2] += n;
  429. return arrayToUtcDate(a);
  430. }
  431. function addMs(m, n) {
  432. var a = dateToUtcArray(m);
  433. a[6] += n;
  434. return arrayToUtcDate(a);
  435. }
  436. // Diffing (all return floats)
  437. function diffWeeks(m0, m1) {
  438. return diffDays(m0, m1) / 7;
  439. }
  440. function diffDays(m0, m1) {
  441. return (m1.valueOf() - m0.valueOf()) / (1000 * 60 * 60 * 24);
  442. }
  443. function diffHours(m0, m1) {
  444. return (m1.valueOf() - m0.valueOf()) / (1000 * 60 * 60);
  445. }
  446. function diffMinutes(m0, m1) {
  447. return (m1.valueOf() - m0.valueOf()) / (1000 * 60);
  448. }
  449. function diffSeconds(m0, m1) {
  450. return (m1.valueOf() - m0.valueOf()) / 1000;
  451. }
  452. function diffDayAndTime(m0, m1) {
  453. var m0day = startOfDay(m0);
  454. var m1day = startOfDay(m1);
  455. return {
  456. years: 0,
  457. months: 0,
  458. days: Math.round(diffDays(m0day, m1day)),
  459. milliseconds: (m1.valueOf() - m1day.valueOf()) - (m0.valueOf() - m0day.valueOf())
  460. };
  461. }
  462. // Diffing Whole Units
  463. function diffWholeWeeks(m0, m1) {
  464. var d = diffWholeDays(m0, m1);
  465. if (d !== null && d % 7 === 0) {
  466. return d / 7;
  467. }
  468. return null;
  469. }
  470. function diffWholeDays(m0, m1) {
  471. if (timeAsMs(m0) === timeAsMs(m1)) {
  472. return Math.round(diffDays(m0, m1));
  473. }
  474. return null;
  475. }
  476. // Start-Of
  477. function startOfDay(m) {
  478. return arrayToUtcDate([
  479. m.getUTCFullYear(),
  480. m.getUTCMonth(),
  481. m.getUTCDate()
  482. ]);
  483. }
  484. function startOfHour(m) {
  485. return arrayToUtcDate([
  486. m.getUTCFullYear(),
  487. m.getUTCMonth(),
  488. m.getUTCDate(),
  489. m.getUTCHours()
  490. ]);
  491. }
  492. function startOfMinute(m) {
  493. return arrayToUtcDate([
  494. m.getUTCFullYear(),
  495. m.getUTCMonth(),
  496. m.getUTCDate(),
  497. m.getUTCHours(),
  498. m.getUTCMinutes()
  499. ]);
  500. }
  501. function startOfSecond(m) {
  502. return arrayToUtcDate([
  503. m.getUTCFullYear(),
  504. m.getUTCMonth(),
  505. m.getUTCDate(),
  506. m.getUTCHours(),
  507. m.getUTCMinutes(),
  508. m.getUTCSeconds()
  509. ]);
  510. }
  511. // Week Computation
  512. function weekOfYear(marker, dow, doy) {
  513. var y = marker.getUTCFullYear();
  514. var w = weekOfGivenYear(marker, y, dow, doy);
  515. if (w < 1) {
  516. return weekOfGivenYear(marker, y - 1, dow, doy);
  517. }
  518. var nextW = weekOfGivenYear(marker, y + 1, dow, doy);
  519. if (nextW >= 1) {
  520. return Math.min(w, nextW);
  521. }
  522. return w;
  523. }
  524. function weekOfGivenYear(marker, year, dow, doy) {
  525. var firstWeekStart = arrayToUtcDate([year, 0, 1 + firstWeekOffset(year, dow, doy)]);
  526. var dayStart = startOfDay(marker);
  527. var days = Math.round(diffDays(firstWeekStart, dayStart));
  528. return Math.floor(days / 7) + 1; // zero-indexed
  529. }
  530. // start-of-first-week - start-of-year
  531. function firstWeekOffset(year, dow, doy) {
  532. // first-week day -- which january is always in the first week (4 for iso, 1 for other)
  533. var fwd = 7 + dow - doy;
  534. // first-week day local weekday -- which local weekday is fwd
  535. var fwdlw = (7 + arrayToUtcDate([year, 0, fwd]).getUTCDay() - dow) % 7;
  536. return -fwdlw + fwd - 1;
  537. }
  538. // Array Conversion
  539. function dateToLocalArray(date) {
  540. return [
  541. date.getFullYear(),
  542. date.getMonth(),
  543. date.getDate(),
  544. date.getHours(),
  545. date.getMinutes(),
  546. date.getSeconds(),
  547. date.getMilliseconds()
  548. ];
  549. }
  550. function arrayToLocalDate(a) {
  551. return new Date(a[0], a[1] || 0, a[2] == null ? 1 : a[2], // day of month
  552. a[3] || 0, a[4] || 0, a[5] || 0);
  553. }
  554. function dateToUtcArray(date) {
  555. return [
  556. date.getUTCFullYear(),
  557. date.getUTCMonth(),
  558. date.getUTCDate(),
  559. date.getUTCHours(),
  560. date.getUTCMinutes(),
  561. date.getUTCSeconds(),
  562. date.getUTCMilliseconds()
  563. ];
  564. }
  565. function arrayToUtcDate(a) {
  566. // according to web standards (and Safari), a month index is required.
  567. // massage if only given a year.
  568. if (a.length === 1) {
  569. a = a.concat([0]);
  570. }
  571. return new Date(Date.UTC.apply(Date, a));
  572. }
  573. // Other Utils
  574. function isValidDate(m) {
  575. return !isNaN(m.valueOf());
  576. }
  577. function timeAsMs(m) {
  578. return m.getUTCHours() * 1000 * 60 * 60 +
  579. m.getUTCMinutes() * 1000 * 60 +
  580. m.getUTCSeconds() * 1000 +
  581. m.getUTCMilliseconds();
  582. }
  583. var INTERNAL_UNITS = ['years', 'months', 'days', 'milliseconds'];
  584. var PARSE_RE = /^(-?)(?:(\d+)\.)?(\d+):(\d\d)(?::(\d\d)(?:\.(\d\d\d))?)?/;
  585. // Parsing and Creation
  586. function createDuration(input, unit) {
  587. var _a;
  588. if (typeof input === 'string') {
  589. return parseString(input);
  590. }
  591. else if (typeof input === 'object' && input) { // non-null object
  592. return normalizeObject(input);
  593. }
  594. else if (typeof input === 'number') {
  595. return normalizeObject((_a = {}, _a[unit || 'milliseconds'] = input, _a));
  596. }
  597. else {
  598. return null;
  599. }
  600. }
  601. function parseString(s) {
  602. var m = PARSE_RE.exec(s);
  603. if (m) {
  604. var sign = m[1] ? -1 : 1;
  605. return {
  606. years: 0,
  607. months: 0,
  608. days: sign * (m[2] ? parseInt(m[2], 10) : 0),
  609. milliseconds: sign * ((m[3] ? parseInt(m[3], 10) : 0) * 60 * 60 * 1000 + // hours
  610. (m[4] ? parseInt(m[4], 10) : 0) * 60 * 1000 + // minutes
  611. (m[5] ? parseInt(m[5], 10) : 0) * 1000 + // seconds
  612. (m[6] ? parseInt(m[6], 10) : 0) // ms
  613. )
  614. };
  615. }
  616. return null;
  617. }
  618. function normalizeObject(obj) {
  619. return {
  620. years: obj.years || obj.year || 0,
  621. months: obj.months || obj.month || 0,
  622. days: (obj.days || obj.day || 0) +
  623. getWeeksFromInput(obj) * 7,
  624. milliseconds: (obj.hours || obj.hour || 0) * 60 * 60 * 1000 + // hours
  625. (obj.minutes || obj.minute || 0) * 60 * 1000 + // minutes
  626. (obj.seconds || obj.second || 0) * 1000 + // seconds
  627. (obj.milliseconds || obj.millisecond || obj.ms || 0) // ms
  628. };
  629. }
  630. function getWeeksFromInput(obj) {
  631. return obj.weeks || obj.week || 0;
  632. }
  633. // Equality
  634. function durationsEqual(d0, d1) {
  635. return d0.years === d1.years &&
  636. d0.months === d1.months &&
  637. d0.days === d1.days &&
  638. d0.milliseconds === d1.milliseconds;
  639. }
  640. function isSingleDay(dur) {
  641. return dur.years === 0 && dur.months === 0 && dur.days === 1 && dur.milliseconds === 0;
  642. }
  643. // Simple Math
  644. function addDurations(d0, d1) {
  645. return {
  646. years: d0.years + d1.years,
  647. months: d0.months + d1.months,
  648. days: d0.days + d1.days,
  649. milliseconds: d0.milliseconds + d1.milliseconds
  650. };
  651. }
  652. function subtractDurations(d1, d0) {
  653. return {
  654. years: d1.years - d0.years,
  655. months: d1.months - d0.months,
  656. days: d1.days - d0.days,
  657. milliseconds: d1.milliseconds - d0.milliseconds
  658. };
  659. }
  660. function multiplyDuration(d, n) {
  661. return {
  662. years: d.years * n,
  663. months: d.months * n,
  664. days: d.days * n,
  665. milliseconds: d.milliseconds * n
  666. };
  667. }
  668. // Conversions
  669. // "Rough" because they are based on average-case Gregorian months/years
  670. function asRoughYears(dur) {
  671. return asRoughDays(dur) / 365;
  672. }
  673. function asRoughMonths(dur) {
  674. return asRoughDays(dur) / 30;
  675. }
  676. function asRoughDays(dur) {
  677. return asRoughMs(dur) / 864e5;
  678. }
  679. function asRoughMinutes(dur) {
  680. return asRoughMs(dur) / (1000 * 60);
  681. }
  682. function asRoughSeconds(dur) {
  683. return asRoughMs(dur) / 1000;
  684. }
  685. function asRoughMs(dur) {
  686. return dur.years * (365 * 864e5) +
  687. dur.months * (30 * 864e5) +
  688. dur.days * 864e5 +
  689. dur.milliseconds;
  690. }
  691. // Advanced Math
  692. function wholeDivideDurations(numerator, denominator) {
  693. var res = null;
  694. for (var i = 0; i < INTERNAL_UNITS.length; i++) {
  695. var unit = INTERNAL_UNITS[i];
  696. if (denominator[unit]) {
  697. var localRes = numerator[unit] / denominator[unit];
  698. if (!isInt(localRes) || (res !== null && res !== localRes)) {
  699. return null;
  700. }
  701. res = localRes;
  702. }
  703. else if (numerator[unit]) {
  704. // needs to divide by something but can't!
  705. return null;
  706. }
  707. }
  708. return res;
  709. }
  710. function greatestDurationDenominator(dur, dontReturnWeeks) {
  711. var ms = dur.milliseconds;
  712. if (ms) {
  713. if (ms % 1000 !== 0) {
  714. return { unit: 'millisecond', value: ms };
  715. }
  716. if (ms % (1000 * 60) !== 0) {
  717. return { unit: 'second', value: ms / 1000 };
  718. }
  719. if (ms % (1000 * 60 * 60) !== 0) {
  720. return { unit: 'minute', value: ms / (1000 * 60) };
  721. }
  722. if (ms) {
  723. return { unit: 'hour', value: ms / (1000 * 60 * 60) };
  724. }
  725. }
  726. if (dur.days) {
  727. if (!dontReturnWeeks && dur.days % 7 === 0) {
  728. return { unit: 'week', value: dur.days / 7 };
  729. }
  730. return { unit: 'day', value: dur.days };
  731. }
  732. if (dur.months) {
  733. return { unit: 'month', value: dur.months };
  734. }
  735. if (dur.years) {
  736. return { unit: 'year', value: dur.years };
  737. }
  738. return { unit: 'millisecond', value: 0 };
  739. }
  740. /* FullCalendar-specific DOM Utilities
  741. ----------------------------------------------------------------------------------------------------------------------*/
  742. // Given the scrollbar widths of some other container, create borders/margins on rowEls in order to match the left
  743. // and right space that was offset by the scrollbars. A 1-pixel border first, then margin beyond that.
  744. function compensateScroll(rowEl, scrollbarWidths) {
  745. if (scrollbarWidths.left) {
  746. applyStyle(rowEl, {
  747. borderLeftWidth: 1,
  748. marginLeft: scrollbarWidths.left - 1
  749. });
  750. }
  751. if (scrollbarWidths.right) {
  752. applyStyle(rowEl, {
  753. borderRightWidth: 1,
  754. marginRight: scrollbarWidths.right - 1
  755. });
  756. }
  757. }
  758. // Undoes compensateScroll and restores all borders/margins
  759. function uncompensateScroll(rowEl) {
  760. applyStyle(rowEl, {
  761. marginLeft: '',
  762. marginRight: '',
  763. borderLeftWidth: '',
  764. borderRightWidth: ''
  765. });
  766. }
  767. // Make the mouse cursor express that an event is not allowed in the current area
  768. function disableCursor() {
  769. document.body.classList.add('fc-not-allowed');
  770. }
  771. // Returns the mouse cursor to its original look
  772. function enableCursor() {
  773. document.body.classList.remove('fc-not-allowed');
  774. }
  775. // Given a total available height to fill, have `els` (essentially child rows) expand to accomodate.
  776. // By default, all elements that are shorter than the recommended height are expanded uniformly, not considering
  777. // any other els that are already too tall. if `shouldRedistribute` is on, it considers these tall rows and
  778. // reduces the available height.
  779. function distributeHeight(els, availableHeight, shouldRedistribute) {
  780. // *FLOORING NOTE*: we floor in certain places because zoom can give inaccurate floating-point dimensions,
  781. // and it is better to be shorter than taller, to avoid creating unnecessary scrollbars.
  782. var minOffset1 = Math.floor(availableHeight / els.length); // for non-last element
  783. var minOffset2 = Math.floor(availableHeight - minOffset1 * (els.length - 1)); // for last element *FLOORING NOTE*
  784. var flexEls = []; // elements that are allowed to expand. array of DOM nodes
  785. var flexOffsets = []; // amount of vertical space it takes up
  786. var flexHeights = []; // actual css height
  787. var usedHeight = 0;
  788. undistributeHeight(els); // give all elements their natural height
  789. // find elements that are below the recommended height (expandable).
  790. // important to query for heights in a single first pass (to avoid reflow oscillation).
  791. els.forEach(function (el, i) {
  792. var minOffset = i === els.length - 1 ? minOffset2 : minOffset1;
  793. var naturalHeight = el.getBoundingClientRect().height;
  794. var naturalOffset = naturalHeight + computeVMargins(el);
  795. if (naturalOffset < minOffset) {
  796. flexEls.push(el);
  797. flexOffsets.push(naturalOffset);
  798. flexHeights.push(naturalHeight);
  799. }
  800. else {
  801. // this element stretches past recommended height (non-expandable). mark the space as occupied.
  802. usedHeight += naturalOffset;
  803. }
  804. });
  805. // readjust the recommended height to only consider the height available to non-maxed-out rows.
  806. if (shouldRedistribute) {
  807. availableHeight -= usedHeight;
  808. minOffset1 = Math.floor(availableHeight / flexEls.length);
  809. minOffset2 = Math.floor(availableHeight - minOffset1 * (flexEls.length - 1)); // *FLOORING NOTE*
  810. }
  811. // assign heights to all expandable elements
  812. flexEls.forEach(function (el, i) {
  813. var minOffset = i === flexEls.length - 1 ? minOffset2 : minOffset1;
  814. var naturalOffset = flexOffsets[i];
  815. var naturalHeight = flexHeights[i];
  816. var newHeight = minOffset - (naturalOffset - naturalHeight); // subtract the margin/padding
  817. if (naturalOffset < minOffset) { // we check this again because redistribution might have changed things
  818. el.style.height = newHeight + 'px';
  819. }
  820. });
  821. }
  822. // Undoes distrubuteHeight, restoring all els to their natural height
  823. function undistributeHeight(els) {
  824. els.forEach(function (el) {
  825. el.style.height = '';
  826. });
  827. }
  828. // Given `els`, a set of <td> cells, find the cell with the largest natural width and set the widths of all the
  829. // cells to be that width.
  830. // PREREQUISITE: if you want a cell to take up width, it needs to have a single inner element w/ display:inline
  831. function matchCellWidths(els) {
  832. var maxInnerWidth = 0;
  833. els.forEach(function (el) {
  834. var innerEl = el.firstChild; // hopefully an element
  835. if (innerEl instanceof HTMLElement) {
  836. var innerWidth_1 = innerEl.getBoundingClientRect().width;
  837. if (innerWidth_1 > maxInnerWidth) {
  838. maxInnerWidth = innerWidth_1;
  839. }
  840. }
  841. });
  842. maxInnerWidth++; // sometimes not accurate of width the text needs to stay on one line. insurance
  843. els.forEach(function (el) {
  844. el.style.width = maxInnerWidth + 'px';
  845. });
  846. return maxInnerWidth;
  847. }
  848. // Given one element that resides inside another,
  849. // Subtracts the height of the inner element from the outer element.
  850. function subtractInnerElHeight(outerEl, innerEl) {
  851. // effin' IE8/9/10/11 sometimes returns 0 for dimensions. this weird hack was the only thing that worked
  852. var reflowStyleProps = {
  853. position: 'relative',
  854. left: -1 // ensure reflow in case the el was already relative. negative is less likely to cause new scroll
  855. };
  856. applyStyle(outerEl, reflowStyleProps);
  857. applyStyle(innerEl, reflowStyleProps);
  858. var diff = // grab the dimensions
  859. outerEl.getBoundingClientRect().height -
  860. innerEl.getBoundingClientRect().height;
  861. // undo hack
  862. var resetStyleProps = { position: '', left: '' };
  863. applyStyle(outerEl, resetStyleProps);
  864. applyStyle(innerEl, resetStyleProps);
  865. return diff;
  866. }
  867. /* Selection
  868. ----------------------------------------------------------------------------------------------------------------------*/
  869. function preventSelection(el) {
  870. el.classList.add('fc-unselectable');
  871. el.addEventListener('selectstart', preventDefault);
  872. }
  873. function allowSelection(el) {
  874. el.classList.remove('fc-unselectable');
  875. el.removeEventListener('selectstart', preventDefault);
  876. }
  877. /* Context Menu
  878. ----------------------------------------------------------------------------------------------------------------------*/
  879. function preventContextMenu(el) {
  880. el.addEventListener('contextmenu', preventDefault);
  881. }
  882. function allowContextMenu(el) {
  883. el.removeEventListener('contextmenu', preventDefault);
  884. }
  885. /* Object Ordering by Field
  886. ----------------------------------------------------------------------------------------------------------------------*/
  887. function parseFieldSpecs(input) {
  888. var specs = [];
  889. var tokens = [];
  890. var i;
  891. var token;
  892. if (typeof input === 'string') {
  893. tokens = input.split(/\s*,\s*/);
  894. }
  895. else if (typeof input === 'function') {
  896. tokens = [input];
  897. }
  898. else if (Array.isArray(input)) {
  899. tokens = input;
  900. }
  901. for (i = 0; i < tokens.length; i++) {
  902. token = tokens[i];
  903. if (typeof token === 'string') {
  904. specs.push(token.charAt(0) === '-' ?
  905. { field: token.substring(1), order: -1 } :
  906. { field: token, order: 1 });
  907. }
  908. else if (typeof token === 'function') {
  909. specs.push({ func: token });
  910. }
  911. }
  912. return specs;
  913. }
  914. function compareByFieldSpecs(obj0, obj1, fieldSpecs) {
  915. var i;
  916. var cmp;
  917. for (i = 0; i < fieldSpecs.length; i++) {
  918. cmp = compareByFieldSpec(obj0, obj1, fieldSpecs[i]);
  919. if (cmp) {
  920. return cmp;
  921. }
  922. }
  923. return 0;
  924. }
  925. function compareByFieldSpec(obj0, obj1, fieldSpec) {
  926. if (fieldSpec.func) {
  927. return fieldSpec.func(obj0, obj1);
  928. }
  929. return flexibleCompare(obj0[fieldSpec.field], obj1[fieldSpec.field])
  930. * (fieldSpec.order || 1);
  931. }
  932. function flexibleCompare(a, b) {
  933. if (!a && !b) {
  934. return 0;
  935. }
  936. if (b == null) {
  937. return -1;
  938. }
  939. if (a == null) {
  940. return 1;
  941. }
  942. if (typeof a === 'string' || typeof b === 'string') {
  943. return String(a).localeCompare(String(b));
  944. }
  945. return a - b;
  946. }
  947. /* String Utilities
  948. ----------------------------------------------------------------------------------------------------------------------*/
  949. function capitaliseFirstLetter(str) {
  950. return str.charAt(0).toUpperCase() + str.slice(1);
  951. }
  952. function padStart(val, len) {
  953. var s = String(val);
  954. return '000'.substr(0, len - s.length) + s;
  955. }
  956. /* Number Utilities
  957. ----------------------------------------------------------------------------------------------------------------------*/
  958. function compareNumbers(a, b) {
  959. return a - b;
  960. }
  961. function isInt(n) {
  962. return n % 1 === 0;
  963. }
  964. /* Weird Utilities
  965. ----------------------------------------------------------------------------------------------------------------------*/
  966. function applyAll(functions, thisObj, args) {
  967. if (typeof functions === 'function') { // supplied a single function
  968. functions = [functions];
  969. }
  970. if (functions) {
  971. var i = void 0;
  972. var ret = void 0;
  973. for (i = 0; i < functions.length; i++) {
  974. ret = functions[i].apply(thisObj, args) || ret;
  975. }
  976. return ret;
  977. }
  978. }
  979. function firstDefined() {
  980. var args = [];
  981. for (var _i = 0; _i < arguments.length; _i++) {
  982. args[_i] = arguments[_i];
  983. }
  984. for (var i = 0; i < args.length; i++) {
  985. if (args[i] !== undefined) {
  986. return args[i];
  987. }
  988. }
  989. }
  990. // Returns a function, that, as long as it continues to be invoked, will not
  991. // be triggered. The function will be called after it stops being called for
  992. // N milliseconds. If `immediate` is passed, trigger the function on the
  993. // leading edge, instead of the trailing.
  994. // https://github.com/jashkenas/underscore/blob/1.6.0/underscore.js#L714
  995. function debounce(func, wait) {
  996. var timeout;
  997. var args;
  998. var context;
  999. var timestamp;
  1000. var result;
  1001. var later = function () {
  1002. var last = new Date().valueOf() - timestamp;
  1003. if (last < wait) {
  1004. timeout = setTimeout(later, wait - last);
  1005. }
  1006. else {
  1007. timeout = null;
  1008. result = func.apply(context, args);
  1009. context = args = null;
  1010. }
  1011. };
  1012. return function () {
  1013. context = this;
  1014. args = arguments;
  1015. timestamp = new Date().valueOf();
  1016. if (!timeout) {
  1017. timeout = setTimeout(later, wait);
  1018. }
  1019. return result;
  1020. };
  1021. }
  1022. // Number and Boolean are only types that defaults or not computed for
  1023. // TODO: write more comments
  1024. function refineProps(rawProps, processors, defaults, leftoverProps) {
  1025. if (defaults === void 0) { defaults = {}; }
  1026. var refined = {};
  1027. for (var key in processors) {
  1028. var processor = processors[key];
  1029. if (rawProps[key] !== undefined) {
  1030. // found
  1031. if (processor === Function) {
  1032. refined[key] = typeof rawProps[key] === 'function' ? rawProps[key] : null;
  1033. }
  1034. else if (processor) { // a refining function?
  1035. refined[key] = processor(rawProps[key]);
  1036. }
  1037. else {
  1038. refined[key] = rawProps[key];
  1039. }
  1040. }
  1041. else if (defaults[key] !== undefined) {
  1042. // there's an explicit default
  1043. refined[key] = defaults[key];
  1044. }
  1045. else {
  1046. // must compute a default
  1047. if (processor === String) {
  1048. refined[key] = ''; // empty string is default for String
  1049. }
  1050. else if (!processor || processor === Number || processor === Boolean || processor === Function) {
  1051. refined[key] = null; // assign null for other non-custom processor funcs
  1052. }
  1053. else {
  1054. refined[key] = processor(null); // run the custom processor func
  1055. }
  1056. }
  1057. }
  1058. if (leftoverProps) {
  1059. for (var key in rawProps) {
  1060. if (processors[key] === undefined) {
  1061. leftoverProps[key] = rawProps[key];
  1062. }
  1063. }
  1064. }
  1065. return refined;
  1066. }
  1067. /* Date stuff that doesn't belong in datelib core
  1068. ----------------------------------------------------------------------------------------------------------------------*/
  1069. // given a timed range, computes an all-day range that has the same exact duration,
  1070. // but whose start time is aligned with the start of the day.
  1071. function computeAlignedDayRange(timedRange) {
  1072. var dayCnt = Math.floor(diffDays(timedRange.start, timedRange.end)) || 1;
  1073. var start = startOfDay(timedRange.start);
  1074. var end = addDays(start, dayCnt);
  1075. return { start: start, end: end };
  1076. }
  1077. // given a timed range, computes an all-day range based on how for the end date bleeds into the next day
  1078. // TODO: give nextDayThreshold a default arg
  1079. function computeVisibleDayRange(timedRange, nextDayThreshold) {
  1080. if (nextDayThreshold === void 0) { nextDayThreshold = createDuration(0); }
  1081. var startDay = null;
  1082. var endDay = null;
  1083. if (timedRange.end) {
  1084. endDay = startOfDay(timedRange.end);
  1085. var endTimeMS = timedRange.end.valueOf() - endDay.valueOf(); // # of milliseconds into `endDay`
  1086. // If the end time is actually inclusively part of the next day and is equal to or
  1087. // beyond the next day threshold, adjust the end to be the exclusive end of `endDay`.
  1088. // Otherwise, leaving it as inclusive will cause it to exclude `endDay`.
  1089. if (endTimeMS && endTimeMS >= asRoughMs(nextDayThreshold)) {
  1090. endDay = addDays(endDay, 1);
  1091. }
  1092. }
  1093. if (timedRange.start) {
  1094. startDay = startOfDay(timedRange.start); // the beginning of the day the range starts
  1095. // If end is within `startDay` but not past nextDayThreshold, assign the default duration of one day.
  1096. if (endDay && endDay <= startDay) {
  1097. endDay = addDays(startDay, 1);
  1098. }
  1099. }
  1100. return { start: startDay, end: endDay };
  1101. }
  1102. // spans from one day into another?
  1103. function isMultiDayRange(range) {
  1104. var visibleRange = computeVisibleDayRange(range);
  1105. return diffDays(visibleRange.start, visibleRange.end) > 1;
  1106. }
  1107. function diffDates(date0, date1, dateEnv, largeUnit) {
  1108. if (largeUnit === 'year') {
  1109. return createDuration(dateEnv.diffWholeYears(date0, date1), 'year');
  1110. }
  1111. else if (largeUnit === 'month') {
  1112. return createDuration(dateEnv.diffWholeMonths(date0, date1), 'month');
  1113. }
  1114. else {
  1115. return diffDayAndTime(date0, date1); // returns a duration
  1116. }
  1117. }
  1118. /*! *****************************************************************************
  1119. Copyright (c) Microsoft Corporation. All rights reserved.
  1120. Licensed under the Apache License, Version 2.0 (the "License"); you may not use
  1121. this file except in compliance with the License. You may obtain a copy of the
  1122. License at http://www.apache.org/licenses/LICENSE-2.0
  1123. THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  1124. KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
  1125. WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
  1126. MERCHANTABLITY OR NON-INFRINGEMENT.
  1127. See the Apache Version 2.0 License for specific language governing permissions
  1128. and limitations under the License.
  1129. ***************************************************************************** */
  1130. /* global Reflect, Promise */
  1131. var extendStatics = function(d, b) {
  1132. extendStatics = Object.setPrototypeOf ||
  1133. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  1134. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  1135. return extendStatics(d, b);
  1136. };
  1137. function __extends(d, b) {
  1138. extendStatics(d, b);
  1139. function __() { this.constructor = d; }
  1140. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  1141. }
  1142. var __assign = function() {
  1143. __assign = Object.assign || function __assign(t) {
  1144. for (var s, i = 1, n = arguments.length; i < n; i++) {
  1145. s = arguments[i];
  1146. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  1147. }
  1148. return t;
  1149. };
  1150. return __assign.apply(this, arguments);
  1151. };
  1152. function parseRecurring(eventInput, allDayDefault, dateEnv, recurringTypes, leftovers) {
  1153. for (var i = 0; i < recurringTypes.length; i++) {
  1154. var localLeftovers = {};
  1155. var parsed = recurringTypes[i].parse(eventInput, localLeftovers, dateEnv);
  1156. if (parsed) {
  1157. var allDay = localLeftovers.allDay;
  1158. delete localLeftovers.allDay; // remove from leftovers
  1159. if (allDay == null) {
  1160. allDay = allDayDefault;
  1161. if (allDay == null) {
  1162. allDay = parsed.allDayGuess;
  1163. if (allDay == null) {
  1164. allDay = false;
  1165. }
  1166. }
  1167. }
  1168. __assign(leftovers, localLeftovers);
  1169. return {
  1170. allDay: allDay,
  1171. duration: parsed.duration,
  1172. typeData: parsed.typeData,
  1173. typeId: i
  1174. };
  1175. }
  1176. }
  1177. return null;
  1178. }
  1179. /*
  1180. Event MUST have a recurringDef
  1181. */
  1182. function expandRecurringRanges(eventDef, duration, framingRange, dateEnv, recurringTypes) {
  1183. var typeDef = recurringTypes[eventDef.recurringDef.typeId];
  1184. var markers = typeDef.expand(eventDef.recurringDef.typeData, {
  1185. start: dateEnv.subtract(framingRange.start, duration),
  1186. end: framingRange.end
  1187. }, dateEnv);
  1188. // the recurrence plugins don't guarantee that all-day events are start-of-day, so we have to
  1189. if (eventDef.allDay) {
  1190. markers = markers.map(startOfDay);
  1191. }
  1192. return markers;
  1193. }
  1194. var hasOwnProperty = Object.prototype.hasOwnProperty;
  1195. // Merges an array of objects into a single object.
  1196. // The second argument allows for an array of property names who's object values will be merged together.
  1197. function mergeProps(propObjs, complexProps) {
  1198. var dest = {};
  1199. var i;
  1200. var name;
  1201. var complexObjs;
  1202. var j;
  1203. var val;
  1204. var props;
  1205. if (complexProps) {
  1206. for (i = 0; i < complexProps.length; i++) {
  1207. name = complexProps[i];
  1208. complexObjs = [];
  1209. // collect the trailing object values, stopping when a non-object is discovered
  1210. for (j = propObjs.length - 1; j >= 0; j--) {
  1211. val = propObjs[j][name];
  1212. if (typeof val === 'object' && val) { // non-null object
  1213. complexObjs.unshift(val);
  1214. }
  1215. else if (val !== undefined) {
  1216. dest[name] = val; // if there were no objects, this value will be used
  1217. break;
  1218. }
  1219. }
  1220. // if the trailing values were objects, use the merged value
  1221. if (complexObjs.length) {
  1222. dest[name] = mergeProps(complexObjs);
  1223. }
  1224. }
  1225. }
  1226. // copy values into the destination, going from last to first
  1227. for (i = propObjs.length - 1; i >= 0; i--) {
  1228. props = propObjs[i];
  1229. for (name in props) {
  1230. if (!(name in dest)) { // if already assigned by previous props or complex props, don't reassign
  1231. dest[name] = props[name];
  1232. }
  1233. }
  1234. }
  1235. return dest;
  1236. }
  1237. function filterHash(hash, func) {
  1238. var filtered = {};
  1239. for (var key in hash) {
  1240. if (func(hash[key], key)) {
  1241. filtered[key] = hash[key];
  1242. }
  1243. }
  1244. return filtered;
  1245. }
  1246. function mapHash(hash, func) {
  1247. var newHash = {};
  1248. for (var key in hash) {
  1249. newHash[key] = func(hash[key], key);
  1250. }
  1251. return newHash;
  1252. }
  1253. function arrayToHash(a) {
  1254. var hash = {};
  1255. for (var _i = 0, a_1 = a; _i < a_1.length; _i++) {
  1256. var item = a_1[_i];
  1257. hash[item] = true;
  1258. }
  1259. return hash;
  1260. }
  1261. function hashValuesToArray(obj) {
  1262. var a = [];
  1263. for (var key in obj) {
  1264. a.push(obj[key]);
  1265. }
  1266. return a;
  1267. }
  1268. function isPropsEqual(obj0, obj1) {
  1269. for (var key in obj0) {
  1270. if (hasOwnProperty.call(obj0, key)) {
  1271. if (!(key in obj1)) {
  1272. return false;
  1273. }
  1274. }
  1275. }
  1276. for (var key in obj1) {
  1277. if (hasOwnProperty.call(obj1, key)) {
  1278. if (obj0[key] !== obj1[key]) {
  1279. return false;
  1280. }
  1281. }
  1282. }
  1283. return true;
  1284. }
  1285. function parseEvents(rawEvents, sourceId, calendar, allowOpenRange) {
  1286. var eventStore = createEmptyEventStore();
  1287. for (var _i = 0, rawEvents_1 = rawEvents; _i < rawEvents_1.length; _i++) {
  1288. var rawEvent = rawEvents_1[_i];
  1289. var tuple = parseEvent(rawEvent, sourceId, calendar, allowOpenRange);
  1290. if (tuple) {
  1291. eventTupleToStore(tuple, eventStore);
  1292. }
  1293. }
  1294. return eventStore;
  1295. }
  1296. function eventTupleToStore(tuple, eventStore) {
  1297. if (eventStore === void 0) { eventStore = createEmptyEventStore(); }
  1298. eventStore.defs[tuple.def.defId] = tuple.def;
  1299. if (tuple.instance) {
  1300. eventStore.instances[tuple.instance.instanceId] = tuple.instance;
  1301. }
  1302. return eventStore;
  1303. }
  1304. function expandRecurring(eventStore, framingRange, calendar) {
  1305. var dateEnv = calendar.dateEnv;
  1306. var defs = eventStore.defs, instances = eventStore.instances;
  1307. // remove existing recurring instances
  1308. instances = filterHash(instances, function (instance) {
  1309. return !defs[instance.defId].recurringDef;
  1310. });
  1311. for (var defId in defs) {
  1312. var def = defs[defId];
  1313. if (def.recurringDef) {
  1314. var duration = def.recurringDef.duration;
  1315. if (!duration) {
  1316. duration = def.allDay ?
  1317. calendar.defaultAllDayEventDuration :
  1318. calendar.defaultTimedEventDuration;
  1319. }
  1320. var starts = expandRecurringRanges(def, duration, framingRange, calendar.dateEnv, calendar.pluginSystem.hooks.recurringTypes);
  1321. for (var _i = 0, starts_1 = starts; _i < starts_1.length; _i++) {
  1322. var start = starts_1[_i];
  1323. var instance = createEventInstance(defId, {
  1324. start: start,
  1325. end: dateEnv.add(start, duration)
  1326. });
  1327. instances[instance.instanceId] = instance;
  1328. }
  1329. }
  1330. }
  1331. return { defs: defs, instances: instances };
  1332. }
  1333. // retrieves events that have the same groupId as the instance specified by `instanceId`
  1334. // or they are the same as the instance.
  1335. // why might instanceId not be in the store? an event from another calendar?
  1336. function getRelevantEvents(eventStore, instanceId) {
  1337. var instance = eventStore.instances[instanceId];
  1338. if (instance) {
  1339. var def_1 = eventStore.defs[instance.defId];
  1340. // get events/instances with same group
  1341. var newStore = filterEventStoreDefs(eventStore, function (lookDef) {
  1342. return isEventDefsGrouped(def_1, lookDef);
  1343. });
  1344. // add the original
  1345. // TODO: wish we could use eventTupleToStore or something like it
  1346. newStore.defs[def_1.defId] = def_1;
  1347. newStore.instances[instance.instanceId] = instance;
  1348. return newStore;
  1349. }
  1350. return createEmptyEventStore();
  1351. }
  1352. function isEventDefsGrouped(def0, def1) {
  1353. return Boolean(def0.groupId && def0.groupId === def1.groupId);
  1354. }
  1355. function transformRawEvents(rawEvents, eventSource, calendar) {
  1356. var calEachTransform = calendar.opt('eventDataTransform');
  1357. var sourceEachTransform = eventSource ? eventSource.eventDataTransform : null;
  1358. if (sourceEachTransform) {
  1359. rawEvents = transformEachRawEvent(rawEvents, sourceEachTransform);
  1360. }
  1361. if (calEachTransform) {
  1362. rawEvents = transformEachRawEvent(rawEvents, calEachTransform);
  1363. }
  1364. return rawEvents;
  1365. }
  1366. function transformEachRawEvent(rawEvents, func) {
  1367. var refinedEvents;
  1368. if (!func) {
  1369. refinedEvents = rawEvents;
  1370. }
  1371. else {
  1372. refinedEvents = [];
  1373. for (var _i = 0, rawEvents_2 = rawEvents; _i < rawEvents_2.length; _i++) {
  1374. var rawEvent = rawEvents_2[_i];
  1375. var refinedEvent = func(rawEvent);
  1376. if (refinedEvent) {
  1377. refinedEvents.push(refinedEvent);
  1378. }
  1379. else if (refinedEvent == null) {
  1380. refinedEvents.push(rawEvent);
  1381. } // if a different falsy value, do nothing
  1382. }
  1383. }
  1384. return refinedEvents;
  1385. }
  1386. function createEmptyEventStore() {
  1387. return { defs: {}, instances: {} };
  1388. }
  1389. function mergeEventStores(store0, store1) {
  1390. return {
  1391. defs: __assign({}, store0.defs, store1.defs),
  1392. instances: __assign({}, store0.instances, store1.instances)
  1393. };
  1394. }
  1395. function filterEventStoreDefs(eventStore, filterFunc) {
  1396. var defs = filterHash(eventStore.defs, filterFunc);
  1397. var instances = filterHash(eventStore.instances, function (instance) {
  1398. return defs[instance.defId]; // still exists?
  1399. });
  1400. return { defs: defs, instances: instances };
  1401. }
  1402. function parseRange(input, dateEnv) {
  1403. var start = null;
  1404. var end = null;
  1405. if (input.start) {
  1406. start = dateEnv.createMarker(input.start);
  1407. }
  1408. if (input.end) {
  1409. end = dateEnv.createMarker(input.end);
  1410. }
  1411. if (!start && !end) {
  1412. return null;
  1413. }
  1414. if (start && end && end < start) {
  1415. return null;
  1416. }
  1417. return { start: start, end: end };
  1418. }
  1419. // SIDE-EFFECT: will mutate ranges.
  1420. // Will return a new array result.
  1421. function invertRanges(ranges, constraintRange) {
  1422. var invertedRanges = [];
  1423. var start = constraintRange.start; // the end of the previous range. the start of the new range
  1424. var i;
  1425. var dateRange;
  1426. // ranges need to be in order. required for our date-walking algorithm
  1427. ranges.sort(compareRanges);
  1428. for (i = 0; i < ranges.length; i++) {
  1429. dateRange = ranges[i];
  1430. // add the span of time before the event (if there is any)
  1431. if (dateRange.start > start) { // compare millisecond time (skip any ambig logic)
  1432. invertedRanges.push({ start: start, end: dateRange.start });
  1433. }
  1434. if (dateRange.end > start) {
  1435. start = dateRange.end;
  1436. }
  1437. }
  1438. // add the span of time after the last event (if there is any)
  1439. if (start < constraintRange.end) { // compare millisecond time (skip any ambig logic)
  1440. invertedRanges.push({ start: start, end: constraintRange.end });
  1441. }
  1442. return invertedRanges;
  1443. }
  1444. function compareRanges(range0, range1) {
  1445. return range0.start.valueOf() - range1.start.valueOf(); // earlier ranges go first
  1446. }
  1447. function intersectRanges(range0, range1) {
  1448. var start = range0.start;
  1449. var end = range0.end;
  1450. var newRange = null;
  1451. if (range1.start !== null) {
  1452. if (start === null) {
  1453. start = range1.start;
  1454. }
  1455. else {
  1456. start = new Date(Math.max(start.valueOf(), range1.start.valueOf()));
  1457. }
  1458. }
  1459. if (range1.end != null) {
  1460. if (end === null) {
  1461. end = range1.end;
  1462. }
  1463. else {
  1464. end = new Date(Math.min(end.valueOf(), range1.end.valueOf()));
  1465. }
  1466. }
  1467. if (start === null || end === null || start < end) {
  1468. newRange = { start: start, end: end };
  1469. }
  1470. return newRange;
  1471. }
  1472. function rangesEqual(range0, range1) {
  1473. return (range0.start === null ? null : range0.start.valueOf()) === (range1.start === null ? null : range1.start.valueOf()) &&
  1474. (range0.end === null ? null : range0.end.valueOf()) === (range1.end === null ? null : range1.end.valueOf());
  1475. }
  1476. function rangesIntersect(range0, range1) {
  1477. return (range0.end === null || range1.start === null || range0.end > range1.start) &&
  1478. (range0.start === null || range1.end === null || range0.start < range1.end);
  1479. }
  1480. function rangeContainsRange(outerRange, innerRange) {
  1481. return (outerRange.start === null || (innerRange.start !== null && innerRange.start >= outerRange.start)) &&
  1482. (outerRange.end === null || (innerRange.end !== null && innerRange.end <= outerRange.end));
  1483. }
  1484. function rangeContainsMarker(range, date) {
  1485. return (range.start === null || date >= range.start) &&
  1486. (range.end === null || date < range.end);
  1487. }
  1488. // If the given date is not within the given range, move it inside.
  1489. // (If it's past the end, make it one millisecond before the end).
  1490. function constrainMarkerToRange(date, range) {
  1491. if (range.start != null && date < range.start) {
  1492. return range.start;
  1493. }
  1494. if (range.end != null && date >= range.end) {
  1495. return new Date(range.end.valueOf() - 1);
  1496. }
  1497. return date;
  1498. }
  1499. function removeExact(array, exactVal) {
  1500. var removeCnt = 0;
  1501. var i = 0;
  1502. while (i < array.length) {
  1503. if (array[i] === exactVal) {
  1504. array.splice(i, 1);
  1505. removeCnt++;
  1506. }
  1507. else {
  1508. i++;
  1509. }
  1510. }
  1511. return removeCnt;
  1512. }
  1513. function isArraysEqual(a0, a1) {
  1514. var len = a0.length;
  1515. var i;
  1516. if (len !== a1.length) { // not array? or not same length?
  1517. return false;
  1518. }
  1519. for (i = 0; i < len; i++) {
  1520. if (a0[i] !== a1[i]) {
  1521. return false;
  1522. }
  1523. }
  1524. return true;
  1525. }
  1526. function memoize(workerFunc) {
  1527. var args;
  1528. var res;
  1529. return function () {
  1530. if (!args || !isArraysEqual(args, arguments)) {
  1531. args = arguments;
  1532. res = workerFunc.apply(this, arguments);
  1533. }
  1534. return res;
  1535. };
  1536. }
  1537. /*
  1538. always executes the workerFunc, but if the result is equal to the previous result,
  1539. return the previous result instead.
  1540. */
  1541. function memoizeOutput(workerFunc, equalityFunc) {
  1542. var cachedRes = null;
  1543. return function () {
  1544. var newRes = workerFunc.apply(this, arguments);
  1545. if (cachedRes === null || !(cachedRes === newRes || equalityFunc(cachedRes, newRes))) {
  1546. cachedRes = newRes;
  1547. }
  1548. return cachedRes;
  1549. };
  1550. }
  1551. var EXTENDED_SETTINGS_AND_SEVERITIES = {
  1552. week: 3,
  1553. separator: 0,
  1554. omitZeroMinute: 0,
  1555. meridiem: 0,
  1556. omitCommas: 0
  1557. };
  1558. var STANDARD_DATE_PROP_SEVERITIES = {
  1559. timeZoneName: 7,
  1560. era: 6,
  1561. year: 5,
  1562. month: 4,
  1563. day: 2,
  1564. weekday: 2,
  1565. hour: 1,
  1566. minute: 1,
  1567. second: 1
  1568. };
  1569. var MERIDIEM_RE = /\s*([ap])\.?m\.?/i; // eats up leading spaces too
  1570. var COMMA_RE = /,/g; // we need re for globalness
  1571. var MULTI_SPACE_RE = /\s+/g;
  1572. var LTR_RE = /\u200e/g; // control character
  1573. var UTC_RE = /UTC|GMT/;
  1574. var NativeFormatter = /** @class */ (function () {
  1575. function NativeFormatter(formatSettings) {
  1576. var standardDateProps = {};
  1577. var extendedSettings = {};
  1578. var severity = 0;
  1579. for (var name_1 in formatSettings) {
  1580. if (name_1 in EXTENDED_SETTINGS_AND_SEVERITIES) {
  1581. extendedSettings[name_1] = formatSettings[name_1];
  1582. severity = Math.max(EXTENDED_SETTINGS_AND_SEVERITIES[name_1], severity);
  1583. }
  1584. else {
  1585. standardDateProps[name_1] = formatSettings[name_1];
  1586. if (name_1 in STANDARD_DATE_PROP_SEVERITIES) {
  1587. severity = Math.max(STANDARD_DATE_PROP_SEVERITIES[name_1], severity);
  1588. }
  1589. }
  1590. }
  1591. this.standardDateProps = standardDateProps;
  1592. this.extendedSettings = extendedSettings;
  1593. this.severity = severity;
  1594. this.buildFormattingFunc = memoize(buildFormattingFunc);
  1595. }
  1596. NativeFormatter.prototype.format = function (date, context) {
  1597. return this.buildFormattingFunc(this.standardDateProps, this.extendedSettings, context)(date);
  1598. };
  1599. NativeFormatter.prototype.formatRange = function (start, end, context) {
  1600. var _a = this, standardDateProps = _a.standardDateProps, extendedSettings = _a.extendedSettings;
  1601. var diffSeverity = computeMarkerDiffSeverity(start.marker, end.marker, context.calendarSystem);
  1602. if (!diffSeverity) {
  1603. return this.format(start, context);
  1604. }
  1605. var biggestUnitForPartial = diffSeverity;
  1606. if (biggestUnitForPartial > 1 && // the two dates are different in a way that's larger scale than time
  1607. (standardDateProps.year === 'numeric' || standardDateProps.year === '2-digit') &&
  1608. (standardDateProps.month === 'numeric' || standardDateProps.month === '2-digit') &&
  1609. (standardDateProps.day === 'numeric' || standardDateProps.day === '2-digit')) {
  1610. biggestUnitForPartial = 1; // make it look like the dates are only different in terms of time
  1611. }
  1612. var full0 = this.format(start, context);
  1613. var full1 = this.format(end, context);
  1614. if (full0 === full1) {
  1615. return full0;
  1616. }
  1617. var partialDateProps = computePartialFormattingOptions(standardDateProps, biggestUnitForPartial);
  1618. var partialFormattingFunc = buildFormattingFunc(partialDateProps, extendedSettings, context);
  1619. var partial0 = partialFormattingFunc(start);
  1620. var partial1 = partialFormattingFunc(end);
  1621. var insertion = findCommonInsertion(full0, partial0, full1, partial1);
  1622. var separator = extendedSettings.separator || '';
  1623. if (insertion) {
  1624. return insertion.before + partial0 + separator + partial1 + insertion.after;
  1625. }
  1626. return full0 + separator + full1;
  1627. };
  1628. NativeFormatter.prototype.getLargestUnit = function () {
  1629. switch (this.severity) {
  1630. case 7:
  1631. case 6:
  1632. case 5:
  1633. return 'year';
  1634. case 4:
  1635. return 'month';
  1636. case 3:
  1637. return 'week';
  1638. default:
  1639. return 'day';
  1640. }
  1641. };
  1642. return NativeFormatter;
  1643. }());
  1644. function buildFormattingFunc(standardDateProps, extendedSettings, context) {
  1645. var standardDatePropCnt = Object.keys(standardDateProps).length;
  1646. if (standardDatePropCnt === 1 && standardDateProps.timeZoneName === 'short') {
  1647. return function (date) {
  1648. return formatTimeZoneOffset(date.timeZoneOffset);
  1649. };
  1650. }
  1651. if (standardDatePropCnt === 0 && extendedSettings.week) {
  1652. return function (date) {
  1653. return formatWeekNumber(context.computeWeekNumber(date.marker), context.weekLabel, context.locale, extendedSettings.week);
  1654. };
  1655. }
  1656. return buildNativeFormattingFunc(standardDateProps, extendedSettings, context);
  1657. }
  1658. function buildNativeFormattingFunc(standardDateProps, extendedSettings, context) {
  1659. standardDateProps = __assign({}, standardDateProps); // copy
  1660. extendedSettings = __assign({}, extendedSettings); // copy
  1661. sanitizeSettings(standardDateProps, extendedSettings);
  1662. standardDateProps.timeZone = 'UTC'; // we leverage the only guaranteed timeZone for our UTC markers
  1663. var normalFormat = new Intl.DateTimeFormat(context.locale.codes, standardDateProps);
  1664. var zeroFormat; // needed?
  1665. if (extendedSettings.omitZeroMinute) {
  1666. var zeroProps = __assign({}, standardDateProps);
  1667. delete zeroProps.minute; // seconds and ms were already considered in sanitizeSettings
  1668. zeroFormat = new Intl.DateTimeFormat(context.locale.codes, zeroProps);
  1669. }
  1670. return function (date) {
  1671. var marker = date.marker;
  1672. var format;
  1673. if (zeroFormat && !marker.getUTCMinutes()) {
  1674. format = zeroFormat;
  1675. }
  1676. else {
  1677. format = normalFormat;
  1678. }
  1679. var s = format.format(marker);
  1680. return postProcess(s, date, standardDateProps, extendedSettings, context);
  1681. };
  1682. }
  1683. function sanitizeSettings(standardDateProps, extendedSettings) {
  1684. // deal with a browser inconsistency where formatting the timezone
  1685. // requires that the hour/minute be present.
  1686. if (standardDateProps.timeZoneName) {
  1687. if (!standardDateProps.hour) {
  1688. standardDateProps.hour = '2-digit';
  1689. }
  1690. if (!standardDateProps.minute) {
  1691. standardDateProps.minute = '2-digit';
  1692. }
  1693. }
  1694. // only support short timezone names
  1695. if (standardDateProps.timeZoneName === 'long') {
  1696. standardDateProps.timeZoneName = 'short';
  1697. }
  1698. // if requesting to display seconds, MUST display minutes
  1699. if (extendedSettings.omitZeroMinute && (standardDateProps.second || standardDateProps.millisecond)) {
  1700. delete extendedSettings.omitZeroMinute;
  1701. }
  1702. }
  1703. function postProcess(s, date, standardDateProps, extendedSettings, context) {
  1704. s = s.replace(LTR_RE, ''); // remove left-to-right control chars. do first. good for other regexes
  1705. if (standardDateProps.timeZoneName === 'short') {
  1706. s = injectTzoStr(s, (context.timeZone === 'UTC' || date.timeZoneOffset == null) ?
  1707. 'UTC' : // important to normalize for IE, which does "GMT"
  1708. formatTimeZoneOffset(date.timeZoneOffset));
  1709. }
  1710. if (extendedSettings.omitCommas) {
  1711. s = s.replace(COMMA_RE, '').trim();
  1712. }
  1713. if (extendedSettings.omitZeroMinute) {
  1714. s = s.replace(':00', ''); // zeroFormat doesn't always achieve this
  1715. }
  1716. // ^ do anything that might create adjacent spaces before this point,
  1717. // because MERIDIEM_RE likes to eat up loading spaces
  1718. if (extendedSettings.meridiem === false) {
  1719. s = s.replace(MERIDIEM_RE, '').trim();
  1720. }
  1721. else if (extendedSettings.meridiem === 'narrow') { // a/p
  1722. s = s.replace(MERIDIEM_RE, function (m0, m1) {
  1723. return m1.toLocaleLowerCase();
  1724. });
  1725. }
  1726. else if (extendedSettings.meridiem === 'short') { // am/pm
  1727. s = s.replace(MERIDIEM_RE, function (m0, m1) {
  1728. return m1.toLocaleLowerCase() + 'm';
  1729. });
  1730. }
  1731. else if (extendedSettings.meridiem === 'lowercase') { // other meridiem transformers already converted to lowercase
  1732. s = s.replace(MERIDIEM_RE, function (m0) {
  1733. return m0.toLocaleLowerCase();
  1734. });
  1735. }
  1736. s = s.replace(MULTI_SPACE_RE, ' ');
  1737. s = s.trim();
  1738. return s;
  1739. }
  1740. function injectTzoStr(s, tzoStr) {
  1741. var replaced = false;
  1742. s = s.replace(UTC_RE, function () {
  1743. replaced = true;
  1744. return tzoStr;
  1745. });
  1746. // IE11 doesn't include UTC/GMT in the original string, so append to end
  1747. if (!replaced) {
  1748. s += ' ' + tzoStr;
  1749. }
  1750. return s;
  1751. }
  1752. function formatWeekNumber(num, weekLabel, locale, display) {
  1753. var parts = [];
  1754. if (display === 'narrow') {
  1755. parts.push(weekLabel);
  1756. }
  1757. else if (display === 'short') {
  1758. parts.push(weekLabel, ' ');
  1759. }
  1760. // otherwise, considered 'numeric'
  1761. parts.push(locale.simpleNumberFormat.format(num));
  1762. if (locale.options.isRtl) { // TODO: use control characters instead?
  1763. parts.reverse();
  1764. }
  1765. return parts.join('');
  1766. }
  1767. // Range Formatting Utils
  1768. // 0 = exactly the same
  1769. // 1 = different by time
  1770. // and bigger
  1771. function computeMarkerDiffSeverity(d0, d1, ca) {
  1772. if (ca.getMarkerYear(d0) !== ca.getMarkerYear(d1)) {
  1773. return 5;
  1774. }
  1775. if (ca.getMarkerMonth(d0) !== ca.getMarkerMonth(d1)) {
  1776. return 4;
  1777. }
  1778. if (ca.getMarkerDay(d0) !== ca.getMarkerDay(d1)) {
  1779. return 2;
  1780. }
  1781. if (timeAsMs(d0) !== timeAsMs(d1)) {
  1782. return 1;
  1783. }
  1784. return 0;
  1785. }
  1786. function computePartialFormattingOptions(options, biggestUnit) {
  1787. var partialOptions = {};
  1788. for (var name_2 in options) {
  1789. if (!(name_2 in STANDARD_DATE_PROP_SEVERITIES) || // not a date part prop (like timeZone)
  1790. STANDARD_DATE_PROP_SEVERITIES[name_2] <= biggestUnit) {
  1791. partialOptions[name_2] = options[name_2];
  1792. }
  1793. }
  1794. return partialOptions;
  1795. }
  1796. function findCommonInsertion(full0, partial0, full1, partial1) {
  1797. var i0 = 0;
  1798. while (i0 < full0.length) {
  1799. var found0 = full0.indexOf(partial0, i0);
  1800. if (found0 === -1) {
  1801. break;
  1802. }
  1803. var before0 = full0.substr(0, found0);
  1804. i0 = found0 + partial0.length;
  1805. var after0 = full0.substr(i0);
  1806. var i1 = 0;
  1807. while (i1 < full1.length) {
  1808. var found1 = full1.indexOf(partial1, i1);
  1809. if (found1 === -1) {
  1810. break;
  1811. }
  1812. var before1 = full1.substr(0, found1);
  1813. i1 = found1 + partial1.length;
  1814. var after1 = full1.substr(i1);
  1815. if (before0 === before1 && after0 === after1) {
  1816. return {
  1817. before: before0,
  1818. after: after0
  1819. };
  1820. }
  1821. }
  1822. }
  1823. return null;
  1824. }
  1825. /*
  1826. TODO: fix the terminology of "formatter" vs "formatting func"
  1827. */
  1828. /*
  1829. At the time of instantiation, this object does not know which cmd-formatting system it will use.
  1830. It receives this at the time of formatting, as a setting.
  1831. */
  1832. var CmdFormatter = /** @class */ (function () {
  1833. function CmdFormatter(cmdStr, separator) {
  1834. this.cmdStr = cmdStr;
  1835. this.separator = separator;
  1836. }
  1837. CmdFormatter.prototype.format = function (date, context) {
  1838. return context.cmdFormatter(this.cmdStr, createVerboseFormattingArg(date, null, context, this.separator));
  1839. };
  1840. CmdFormatter.prototype.formatRange = function (start, end, context) {
  1841. return context.cmdFormatter(this.cmdStr, createVerboseFormattingArg(start, end, context, this.separator));
  1842. };
  1843. return CmdFormatter;
  1844. }());
  1845. var FuncFormatter = /** @class */ (function () {
  1846. function FuncFormatter(func) {
  1847. this.func = func;
  1848. }
  1849. FuncFormatter.prototype.format = function (date, context) {
  1850. return this.func(createVerboseFormattingArg(date, null, context));
  1851. };
  1852. FuncFormatter.prototype.formatRange = function (start, end, context) {
  1853. return this.func(createVerboseFormattingArg(start, end, context));
  1854. };
  1855. return FuncFormatter;
  1856. }());
  1857. // Formatter Object Creation
  1858. function createFormatter(input, defaultSeparator) {
  1859. if (typeof input === 'object' && input) { // non-null object
  1860. if (typeof defaultSeparator === 'string') {
  1861. input = __assign({ separator: defaultSeparator }, input);
  1862. }
  1863. return new NativeFormatter(input);
  1864. }
  1865. else if (typeof input === 'string') {
  1866. return new CmdFormatter(input, defaultSeparator);
  1867. }
  1868. else if (typeof input === 'function') {
  1869. return new FuncFormatter(input);
  1870. }
  1871. }
  1872. // String Utils
  1873. // timeZoneOffset is in minutes
  1874. function buildIsoString(marker, timeZoneOffset, stripZeroTime) {
  1875. if (stripZeroTime === void 0) { stripZeroTime = false; }
  1876. var s = marker.toISOString();
  1877. s = s.replace('.000', '');
  1878. if (stripZeroTime) {
  1879. s = s.replace('T00:00:00Z', '');
  1880. }
  1881. if (s.length > 10) { // time part wasn't stripped, can add timezone info
  1882. if (timeZoneOffset == null) {
  1883. s = s.replace('Z', '');
  1884. }
  1885. else if (timeZoneOffset !== 0) {
  1886. s = s.replace('Z', formatTimeZoneOffset(timeZoneOffset, true));
  1887. }
  1888. // otherwise, its UTC-0 and we want to keep the Z
  1889. }
  1890. return s;
  1891. }
  1892. function formatIsoTimeString(marker) {
  1893. return padStart(marker.getUTCHours(), 2) + ':' +
  1894. padStart(marker.getUTCMinutes(), 2) + ':' +
  1895. padStart(marker.getUTCSeconds(), 2);
  1896. }
  1897. function formatTimeZoneOffset(minutes, doIso) {
  1898. if (doIso === void 0) { doIso = false; }
  1899. var sign = minutes < 0 ? '-' : '+';
  1900. var abs = Math.abs(minutes);
  1901. var hours = Math.floor(abs / 60);
  1902. var mins = Math.round(abs % 60);
  1903. if (doIso) {
  1904. return sign + padStart(hours, 2) + ':' + padStart(mins, 2);
  1905. }
  1906. else {
  1907. return 'GMT' + sign + hours + (mins ? ':' + padStart(mins, 2) : '');
  1908. }
  1909. }
  1910. // Arg Utils
  1911. function createVerboseFormattingArg(start, end, context, separator) {
  1912. var startInfo = expandZonedMarker(start, context.calendarSystem);
  1913. var endInfo = end ? expandZonedMarker(end, context.calendarSystem) : null;
  1914. return {
  1915. date: startInfo,
  1916. start: startInfo,
  1917. end: endInfo,
  1918. timeZone: context.timeZone,
  1919. localeCodes: context.locale.codes,
  1920. separator: separator
  1921. };
  1922. }
  1923. function expandZonedMarker(dateInfo, calendarSystem) {
  1924. var a = calendarSystem.markerToArray(dateInfo.marker);
  1925. return {
  1926. marker: dateInfo.marker,
  1927. timeZoneOffset: dateInfo.timeZoneOffset,
  1928. array: a,
  1929. year: a[0],
  1930. month: a[1],
  1931. day: a[2],
  1932. hour: a[3],
  1933. minute: a[4],
  1934. second: a[5],
  1935. millisecond: a[6]
  1936. };
  1937. }
  1938. var EventSourceApi = /** @class */ (function () {
  1939. function EventSourceApi(calendar, internalEventSource) {
  1940. this.calendar = calendar;
  1941. this.internalEventSource = internalEventSource;
  1942. }
  1943. EventSourceApi.prototype.remove = function () {
  1944. this.calendar.dispatch({
  1945. type: 'REMOVE_EVENT_SOURCE',
  1946. sourceId: this.internalEventSource.sourceId
  1947. });
  1948. };
  1949. EventSourceApi.prototype.refetch = function () {
  1950. this.calendar.dispatch({
  1951. type: 'FETCH_EVENT_SOURCES',
  1952. sourceIds: [this.internalEventSource.sourceId]
  1953. });
  1954. };
  1955. Object.defineProperty(EventSourceApi.prototype, "id", {
  1956. get: function () {
  1957. return this.internalEventSource.publicId;
  1958. },
  1959. enumerable: true,
  1960. configurable: true
  1961. });
  1962. Object.defineProperty(EventSourceApi.prototype, "url", {
  1963. // only relevant to json-feed event sources
  1964. get: function () {
  1965. return this.internalEventSource.meta.url;
  1966. },
  1967. enumerable: true,
  1968. configurable: true
  1969. });
  1970. return EventSourceApi;
  1971. }());
  1972. var EventApi = /** @class */ (function () {
  1973. function EventApi(calendar, def, instance) {
  1974. this._calendar = calendar;
  1975. this._def = def;
  1976. this._instance = instance || null;
  1977. }
  1978. /*
  1979. TODO: make event struct more responsible for this
  1980. */
  1981. EventApi.prototype.setProp = function (name, val) {
  1982. var _a, _b;
  1983. if (name in DATE_PROPS) ;
  1984. else if (name in NON_DATE_PROPS) {
  1985. if (typeof NON_DATE_PROPS[name] === 'function') {
  1986. val = NON_DATE_PROPS[name](val);
  1987. }
  1988. this.mutate({
  1989. standardProps: (_a = {}, _a[name] = val, _a)
  1990. });
  1991. }
  1992. else if (name in UNSCOPED_EVENT_UI_PROPS) {
  1993. var ui = void 0;
  1994. if (typeof UNSCOPED_EVENT_UI_PROPS[name] === 'function') {
  1995. val = UNSCOPED_EVENT_UI_PROPS[name](val);
  1996. }
  1997. if (name === 'color') {
  1998. ui = { backgroundColor: val, borderColor: val };
  1999. }
  2000. else if (name === 'editable') {
  2001. ui = { startEditable: val, durationEditable: val };
  2002. }
  2003. else {
  2004. ui = (_b = {}, _b[name] = val, _b);
  2005. }
  2006. this.mutate({
  2007. standardProps: { ui: ui }
  2008. });
  2009. }
  2010. };
  2011. EventApi.prototype.setExtendedProp = function (name, val) {
  2012. var _a;
  2013. this.mutate({
  2014. extendedProps: (_a = {}, _a[name] = val, _a)
  2015. });
  2016. };
  2017. EventApi.prototype.setStart = function (startInput, options) {
  2018. if (options === void 0) { options = {}; }
  2019. var dateEnv = this._calendar.dateEnv;
  2020. var start = dateEnv.createMarker(startInput);
  2021. if (start && this._instance) { // TODO: warning if parsed bad
  2022. var instanceRange = this._instance.range;
  2023. var startDelta = diffDates(instanceRange.start, start, dateEnv, options.granularity); // what if parsed bad!?
  2024. if (options.maintainDuration) {
  2025. this.mutate({ datesDelta: startDelta });
  2026. }
  2027. else {
  2028. this.mutate({ startDelta: startDelta });
  2029. }
  2030. }
  2031. };
  2032. EventApi.prototype.setEnd = function (endInput, options) {
  2033. if (options === void 0) { options = {}; }
  2034. var dateEnv = this._calendar.dateEnv;
  2035. var end;
  2036. if (endInput != null) {
  2037. end = dateEnv.createMarker(endInput);
  2038. if (!end) {
  2039. return; // TODO: warning if parsed bad
  2040. }
  2041. }
  2042. if (this._instance) {
  2043. if (end) {
  2044. var endDelta = diffDates(this._instance.range.end, end, dateEnv, options.granularity);
  2045. this.mutate({ endDelta: endDelta });
  2046. }
  2047. else {
  2048. this.mutate({ standardProps: { hasEnd: false } });
  2049. }
  2050. }
  2051. };
  2052. EventApi.prototype.setDates = function (startInput, endInput, options) {
  2053. if (options === void 0) { options = {}; }
  2054. var dateEnv = this._calendar.dateEnv;
  2055. var standardProps = { allDay: options.allDay };
  2056. var start = dateEnv.createMarker(startInput);
  2057. var end;
  2058. if (!start) {
  2059. return; // TODO: warning if parsed bad
  2060. }
  2061. if (endInput != null) {
  2062. end = dateEnv.createMarker(endInput);
  2063. if (!end) { // TODO: warning if parsed bad
  2064. return;
  2065. }
  2066. }
  2067. if (this._instance) {
  2068. var instanceRange = this._instance.range;
  2069. // when computing the diff for an event being converted to all-day,
  2070. // compute diff off of the all-day values the way event-mutation does.
  2071. if (options.allDay === true) {
  2072. instanceRange = computeAlignedDayRange(instanceRange);
  2073. }
  2074. var startDelta = diffDates(instanceRange.start, start, dateEnv, options.granularity);
  2075. if (end) {
  2076. var endDelta = diffDates(instanceRange.end, end, dateEnv, options.granularity);
  2077. if (durationsEqual(startDelta, endDelta)) {
  2078. this.mutate({ datesDelta: startDelta, standardProps: standardProps });
  2079. }
  2080. else {
  2081. this.mutate({ startDelta: startDelta, endDelta: endDelta, standardProps: standardProps });
  2082. }
  2083. }
  2084. else { // means "clear the end"
  2085. standardProps.hasEnd = false;
  2086. this.mutate({ datesDelta: startDelta, standardProps: standardProps });
  2087. }
  2088. }
  2089. };
  2090. EventApi.prototype.moveStart = function (deltaInput) {
  2091. var delta = createDuration(deltaInput);
  2092. if (delta) { // TODO: warning if parsed bad
  2093. this.mutate({ startDelta: delta });
  2094. }
  2095. };
  2096. EventApi.prototype.moveEnd = function (deltaInput) {
  2097. var delta = createDuration(deltaInput);
  2098. if (delta) { // TODO: warning if parsed bad
  2099. this.mutate({ endDelta: delta });
  2100. }
  2101. };
  2102. EventApi.prototype.moveDates = function (deltaInput) {
  2103. var delta = createDuration(deltaInput);
  2104. if (delta) { // TODO: warning if parsed bad
  2105. this.mutate({ datesDelta: delta });
  2106. }
  2107. };
  2108. EventApi.prototype.setAllDay = function (allDay, options) {
  2109. if (options === void 0) { options = {}; }
  2110. var standardProps = { allDay: allDay };
  2111. var maintainDuration = options.maintainDuration;
  2112. if (maintainDuration == null) {
  2113. maintainDuration = this._calendar.opt('allDayMaintainDuration');
  2114. }
  2115. if (this._def.allDay !== allDay) {
  2116. standardProps.hasEnd = maintainDuration;
  2117. }
  2118. this.mutate({ standardProps: standardProps });
  2119. };
  2120. EventApi.prototype.formatRange = function (formatInput) {
  2121. var dateEnv = this._calendar.dateEnv;
  2122. var instance = this._instance;
  2123. var formatter = createFormatter(formatInput, this._calendar.opt('defaultRangeSeparator'));
  2124. if (this._def.hasEnd) {
  2125. return dateEnv.formatRange(instance.range.start, instance.range.end, formatter, {
  2126. forcedStartTzo: instance.forcedStartTzo,
  2127. forcedEndTzo: instance.forcedEndTzo
  2128. });
  2129. }
  2130. else {
  2131. return dateEnv.format(instance.range.start, formatter, {
  2132. forcedTzo: instance.forcedStartTzo
  2133. });
  2134. }
  2135. };
  2136. EventApi.prototype.mutate = function (mutation) {
  2137. var def = this._def;
  2138. var instance = this._instance;
  2139. if (instance) {
  2140. this._calendar.dispatch({
  2141. type: 'MUTATE_EVENTS',
  2142. instanceId: instance.instanceId,
  2143. mutation: mutation,
  2144. fromApi: true
  2145. });
  2146. var eventStore = this._calendar.state.eventStore;
  2147. this._def = eventStore.defs[def.defId];
  2148. this._instance = eventStore.instances[instance.instanceId];
  2149. }
  2150. };
  2151. EventApi.prototype.remove = function () {
  2152. this._calendar.dispatch({
  2153. type: 'REMOVE_EVENT_DEF',
  2154. defId: this._def.defId
  2155. });
  2156. };
  2157. Object.defineProperty(EventApi.prototype, "source", {
  2158. get: function () {
  2159. var sourceId = this._def.sourceId;
  2160. if (sourceId) {
  2161. return new EventSourceApi(this._calendar, this._calendar.state.eventSources[sourceId]);
  2162. }
  2163. return null;
  2164. },
  2165. enumerable: true,
  2166. configurable: true
  2167. });
  2168. Object.defineProperty(EventApi.prototype, "start", {
  2169. get: function () {
  2170. return this._instance ?
  2171. this._calendar.dateEnv.toDate(this._instance.range.start) :
  2172. null;
  2173. },
  2174. enumerable: true,
  2175. configurable: true
  2176. });
  2177. Object.defineProperty(EventApi.prototype, "end", {
  2178. get: function () {
  2179. return (this._instance && this._def.hasEnd) ?
  2180. this._calendar.dateEnv.toDate(this._instance.range.end) :
  2181. null;
  2182. },
  2183. enumerable: true,
  2184. configurable: true
  2185. });
  2186. Object.defineProperty(EventApi.prototype, "id", {
  2187. // computable props that all access the def
  2188. // TODO: find a TypeScript-compatible way to do this at scale
  2189. get: function () { return this._def.publicId; },
  2190. enumerable: true,
  2191. configurable: true
  2192. });
  2193. Object.defineProperty(EventApi.prototype, "groupId", {
  2194. get: function () { return this._def.groupId; },
  2195. enumerable: true,
  2196. configurable: true
  2197. });
  2198. Object.defineProperty(EventApi.prototype, "allDay", {
  2199. get: function () { return this._def.allDay; },
  2200. enumerable: true,
  2201. configurable: true
  2202. });
  2203. Object.defineProperty(EventApi.prototype, "title", {
  2204. get: function () { return this._def.title; },
  2205. enumerable: true,
  2206. configurable: true
  2207. });
  2208. Object.defineProperty(EventApi.prototype, "url", {
  2209. get: function () { return this._def.url; },
  2210. enumerable: true,
  2211. configurable: true
  2212. });
  2213. Object.defineProperty(EventApi.prototype, "rendering", {
  2214. get: function () { return this._def.rendering; },
  2215. enumerable: true,
  2216. configurable: true
  2217. });
  2218. Object.defineProperty(EventApi.prototype, "startEditable", {
  2219. get: function () { return this._def.ui.startEditable; },
  2220. enumerable: true,
  2221. configurable: true
  2222. });
  2223. Object.defineProperty(EventApi.prototype, "durationEditable", {
  2224. get: function () { return this._def.ui.durationEditable; },
  2225. enumerable: true,
  2226. configurable: true
  2227. });
  2228. Object.defineProperty(EventApi.prototype, "constraint", {
  2229. get: function () { return this._def.ui.constraints[0] || null; },
  2230. enumerable: true,
  2231. configurable: true
  2232. });
  2233. Object.defineProperty(EventApi.prototype, "overlap", {
  2234. get: function () { return this._def.ui.overlap; },
  2235. enumerable: true,
  2236. configurable: true
  2237. });
  2238. Object.defineProperty(EventApi.prototype, "allow", {
  2239. get: function () { return this._def.ui.allows[0] || null; },
  2240. enumerable: true,
  2241. configurable: true
  2242. });
  2243. Object.defineProperty(EventApi.prototype, "backgroundColor", {
  2244. get: function () { return this._def.ui.backgroundColor; },
  2245. enumerable: true,
  2246. configurable: true
  2247. });
  2248. Object.defineProperty(EventApi.prototype, "borderColor", {
  2249. get: function () { return this._def.ui.borderColor; },
  2250. enumerable: true,
  2251. configurable: true
  2252. });
  2253. Object.defineProperty(EventApi.prototype, "textColor", {
  2254. get: function () { return this._def.ui.textColor; },
  2255. enumerable: true,
  2256. configurable: true
  2257. });
  2258. Object.defineProperty(EventApi.prototype, "classNames", {
  2259. // NOTE: user can't modify these because Object.freeze was called in event-def parsing
  2260. get: function () { return this._def.ui.classNames; },
  2261. enumerable: true,
  2262. configurable: true
  2263. });
  2264. Object.defineProperty(EventApi.prototype, "extendedProps", {
  2265. get: function () { return this._def.extendedProps; },
  2266. enumerable: true,
  2267. configurable: true
  2268. });
  2269. return EventApi;
  2270. }());
  2271. /*
  2272. Specifying nextDayThreshold signals that all-day ranges should be sliced.
  2273. */
  2274. function sliceEventStore(eventStore, eventUiBases, framingRange, nextDayThreshold) {
  2275. var inverseBgByGroupId = {};
  2276. var inverseBgByDefId = {};
  2277. var defByGroupId = {};
  2278. var bgRanges = [];
  2279. var fgRanges = [];
  2280. var eventUis = compileEventUis(eventStore.defs, eventUiBases);
  2281. for (var defId in eventStore.defs) {
  2282. var def = eventStore.defs[defId];
  2283. if (def.rendering === 'inverse-background') {
  2284. if (def.groupId) {
  2285. inverseBgByGroupId[def.groupId] = [];
  2286. if (!defByGroupId[def.groupId]) {
  2287. defByGroupId[def.groupId] = def;
  2288. }
  2289. }
  2290. else {
  2291. inverseBgByDefId[defId] = [];
  2292. }
  2293. }
  2294. }
  2295. for (var instanceId in eventStore.instances) {
  2296. var instance = eventStore.instances[instanceId];
  2297. var def = eventStore.defs[instance.defId];
  2298. var ui = eventUis[def.defId];
  2299. var origRange = instance.range;
  2300. var normalRange = (!def.allDay && nextDayThreshold) ?
  2301. computeVisibleDayRange(origRange, nextDayThreshold) :
  2302. origRange;
  2303. var slicedRange = intersectRanges(normalRange, framingRange);
  2304. if (slicedRange) {
  2305. if (def.rendering === 'inverse-background') {
  2306. if (def.groupId) {
  2307. inverseBgByGroupId[def.groupId].push(slicedRange);
  2308. }
  2309. else {
  2310. inverseBgByDefId[instance.defId].push(slicedRange);
  2311. }
  2312. }
  2313. else {
  2314. (def.rendering === 'background' ? bgRanges : fgRanges).push({
  2315. def: def,
  2316. ui: ui,
  2317. instance: instance,
  2318. range: slicedRange,
  2319. isStart: normalRange.start && normalRange.start.valueOf() === slicedRange.start.valueOf(),
  2320. isEnd: normalRange.end && normalRange.end.valueOf() === slicedRange.end.valueOf()
  2321. });
  2322. }
  2323. }
  2324. }
  2325. for (var groupId in inverseBgByGroupId) { // BY GROUP
  2326. var ranges = inverseBgByGroupId[groupId];
  2327. var invertedRanges = invertRanges(ranges, framingRange);
  2328. for (var _i = 0, invertedRanges_1 = invertedRanges; _i < invertedRanges_1.length; _i++) {
  2329. var invertedRange = invertedRanges_1[_i];
  2330. var def = defByGroupId[groupId];
  2331. var ui = eventUis[def.defId];
  2332. bgRanges.push({
  2333. def: def,
  2334. ui: ui,
  2335. instance: null,
  2336. range: invertedRange,
  2337. isStart: false,
  2338. isEnd: false
  2339. });
  2340. }
  2341. }
  2342. for (var defId in inverseBgByDefId) {
  2343. var ranges = inverseBgByDefId[defId];
  2344. var invertedRanges = invertRanges(ranges, framingRange);
  2345. for (var _a = 0, invertedRanges_2 = invertedRanges; _a < invertedRanges_2.length; _a++) {
  2346. var invertedRange = invertedRanges_2[_a];
  2347. bgRanges.push({
  2348. def: eventStore.defs[defId],
  2349. ui: eventUis[defId],
  2350. instance: null,
  2351. range: invertedRange,
  2352. isStart: false,
  2353. isEnd: false
  2354. });
  2355. }
  2356. }
  2357. return { bg: bgRanges, fg: fgRanges };
  2358. }
  2359. function hasBgRendering(def) {
  2360. return def.rendering === 'background' || def.rendering === 'inverse-background';
  2361. }
  2362. function filterSegsViaEls(context, segs, isMirror) {
  2363. var calendar = context.calendar, view = context.view;
  2364. if (calendar.hasPublicHandlers('eventRender')) {
  2365. segs = segs.filter(function (seg) {
  2366. var custom = calendar.publiclyTrigger('eventRender', [
  2367. {
  2368. event: new EventApi(calendar, seg.eventRange.def, seg.eventRange.instance),
  2369. isMirror: isMirror,
  2370. isStart: seg.isStart,
  2371. isEnd: seg.isEnd,
  2372. // TODO: include seg.range once all components consistently generate it
  2373. el: seg.el,
  2374. view: view
  2375. }
  2376. ]);
  2377. if (custom === false) { // means don't render at all
  2378. return false;
  2379. }
  2380. else if (custom && custom !== true) {
  2381. seg.el = custom;
  2382. }
  2383. return true;
  2384. });
  2385. }
  2386. for (var _i = 0, segs_1 = segs; _i < segs_1.length; _i++) {
  2387. var seg = segs_1[_i];
  2388. setElSeg(seg.el, seg);
  2389. }
  2390. return segs;
  2391. }
  2392. function setElSeg(el, seg) {
  2393. el.fcSeg = seg;
  2394. }
  2395. function getElSeg(el) {
  2396. return el.fcSeg || null;
  2397. }
  2398. // event ui computation
  2399. function compileEventUis(eventDefs, eventUiBases) {
  2400. return mapHash(eventDefs, function (eventDef) {
  2401. return compileEventUi(eventDef, eventUiBases);
  2402. });
  2403. }
  2404. function compileEventUi(eventDef, eventUiBases) {
  2405. var uis = [];
  2406. if (eventUiBases['']) {
  2407. uis.push(eventUiBases['']);
  2408. }
  2409. if (eventUiBases[eventDef.defId]) {
  2410. uis.push(eventUiBases[eventDef.defId]);
  2411. }
  2412. uis.push(eventDef.ui);
  2413. return combineEventUis(uis);
  2414. }
  2415. // triggers
  2416. function triggerRenderedSegs(context, segs, isMirrors) {
  2417. var calendar = context.calendar, view = context.view;
  2418. if (calendar.hasPublicHandlers('eventPositioned')) {
  2419. for (var _i = 0, segs_2 = segs; _i < segs_2.length; _i++) {
  2420. var seg = segs_2[_i];
  2421. calendar.publiclyTriggerAfterSizing('eventPositioned', [
  2422. {
  2423. event: new EventApi(calendar, seg.eventRange.def, seg.eventRange.instance),
  2424. isMirror: isMirrors,
  2425. isStart: seg.isStart,
  2426. isEnd: seg.isEnd,
  2427. el: seg.el,
  2428. view: view
  2429. }
  2430. ]);
  2431. }
  2432. }
  2433. if (!calendar.state.loadingLevel) { // avoid initial empty state while pending
  2434. calendar.afterSizingTriggers._eventsPositioned = [null]; // fire once
  2435. }
  2436. }
  2437. function triggerWillRemoveSegs(context, segs, isMirrors) {
  2438. var calendar = context.calendar, view = context.view;
  2439. for (var _i = 0, segs_3 = segs; _i < segs_3.length; _i++) {
  2440. var seg = segs_3[_i];
  2441. calendar.trigger('eventElRemove', seg.el);
  2442. }
  2443. if (calendar.hasPublicHandlers('eventDestroy')) {
  2444. for (var _a = 0, segs_4 = segs; _a < segs_4.length; _a++) {
  2445. var seg = segs_4[_a];
  2446. calendar.publiclyTrigger('eventDestroy', [
  2447. {
  2448. event: new EventApi(calendar, seg.eventRange.def, seg.eventRange.instance),
  2449. isMirror: isMirrors,
  2450. el: seg.el,
  2451. view: view
  2452. }
  2453. ]);
  2454. }
  2455. }
  2456. }
  2457. // is-interactable
  2458. function computeEventDraggable(context, eventDef, eventUi) {
  2459. var calendar = context.calendar, view = context.view;
  2460. var transformers = calendar.pluginSystem.hooks.isDraggableTransformers;
  2461. var val = eventUi.startEditable;
  2462. for (var _i = 0, transformers_1 = transformers; _i < transformers_1.length; _i++) {
  2463. var transformer = transformers_1[_i];
  2464. val = transformer(val, eventDef, eventUi, view);
  2465. }
  2466. return val;
  2467. }
  2468. function computeEventStartResizable(context, eventDef, eventUi) {
  2469. return eventUi.durationEditable && context.options.eventResizableFromStart;
  2470. }
  2471. function computeEventEndResizable(context, eventDef, eventUi) {
  2472. return eventUi.durationEditable;
  2473. }
  2474. // applies the mutation to ALL defs/instances within the event store
  2475. function applyMutationToEventStore(eventStore, eventConfigBase, mutation, calendar) {
  2476. var eventConfigs = compileEventUis(eventStore.defs, eventConfigBase);
  2477. var dest = createEmptyEventStore();
  2478. for (var defId in eventStore.defs) {
  2479. var def = eventStore.defs[defId];
  2480. dest.defs[defId] = applyMutationToEventDef(def, eventConfigs[defId], mutation, calendar.pluginSystem.hooks.eventDefMutationAppliers, calendar);
  2481. }
  2482. for (var instanceId in eventStore.instances) {
  2483. var instance = eventStore.instances[instanceId];
  2484. var def = dest.defs[instance.defId]; // important to grab the newly modified def
  2485. dest.instances[instanceId] = applyMutationToEventInstance(instance, def, eventConfigs[instance.defId], mutation, calendar);
  2486. }
  2487. return dest;
  2488. }
  2489. function applyMutationToEventDef(eventDef, eventConfig, mutation, appliers, calendar) {
  2490. var standardProps = mutation.standardProps || {};
  2491. // if hasEnd has not been specified, guess a good value based on deltas.
  2492. // if duration will change, there's no way the default duration will persist,
  2493. // and thus, we need to mark the event as having a real end
  2494. if (standardProps.hasEnd == null &&
  2495. eventConfig.durationEditable &&
  2496. (mutation.startDelta || mutation.endDelta)) {
  2497. standardProps.hasEnd = true; // TODO: is this mutation okay?
  2498. }
  2499. var copy = __assign({}, eventDef, standardProps, { ui: __assign({}, eventDef.ui, standardProps.ui) });
  2500. if (mutation.extendedProps) {
  2501. copy.extendedProps = __assign({}, copy.extendedProps, mutation.extendedProps);
  2502. }
  2503. for (var _i = 0, appliers_1 = appliers; _i < appliers_1.length; _i++) {
  2504. var applier = appliers_1[_i];
  2505. applier(copy, mutation, calendar);
  2506. }
  2507. if (!copy.hasEnd && calendar.opt('forceEventDuration')) {
  2508. copy.hasEnd = true;
  2509. }
  2510. return copy;
  2511. }
  2512. function applyMutationToEventInstance(eventInstance, eventDef, // must first be modified by applyMutationToEventDef
  2513. eventConfig, mutation, calendar) {
  2514. var dateEnv = calendar.dateEnv;
  2515. var forceAllDay = mutation.standardProps && mutation.standardProps.allDay === true;
  2516. var clearEnd = mutation.standardProps && mutation.standardProps.hasEnd === false;
  2517. var copy = __assign({}, eventInstance);
  2518. if (forceAllDay) {
  2519. copy.range = computeAlignedDayRange(copy.range);
  2520. }
  2521. if (mutation.datesDelta && eventConfig.startEditable) {
  2522. copy.range = {
  2523. start: dateEnv.add(copy.range.start, mutation.datesDelta),
  2524. end: dateEnv.add(copy.range.end, mutation.datesDelta)
  2525. };
  2526. }
  2527. if (mutation.startDelta && eventConfig.durationEditable) {
  2528. copy.range = {
  2529. start: dateEnv.add(copy.range.start, mutation.startDelta),
  2530. end: copy.range.end
  2531. };
  2532. }
  2533. if (mutation.endDelta && eventConfig.durationEditable) {
  2534. copy.range = {
  2535. start: copy.range.start,
  2536. end: dateEnv.add(copy.range.end, mutation.endDelta)
  2537. };
  2538. }
  2539. if (clearEnd) {
  2540. copy.range = {
  2541. start: copy.range.start,
  2542. end: calendar.getDefaultEventEnd(eventDef.allDay, copy.range.start)
  2543. };
  2544. }
  2545. // in case event was all-day but the supplied deltas were not
  2546. // better util for this?
  2547. if (eventDef.allDay) {
  2548. copy.range = {
  2549. start: startOfDay(copy.range.start),
  2550. end: startOfDay(copy.range.end)
  2551. };
  2552. }
  2553. // handle invalid durations
  2554. if (copy.range.end < copy.range.start) {
  2555. copy.range.end = calendar.getDefaultEventEnd(eventDef.allDay, copy.range.start);
  2556. }
  2557. return copy;
  2558. }
  2559. function reduceEventStore (eventStore, action, eventSources, dateProfile, calendar) {
  2560. switch (action.type) {
  2561. case 'RECEIVE_EVENTS': // raw
  2562. return receiveRawEvents(eventStore, eventSources[action.sourceId], action.fetchId, action.fetchRange, action.rawEvents, calendar);
  2563. case 'ADD_EVENTS': // already parsed, but not expanded
  2564. return addEvent(eventStore, action.eventStore, // new ones
  2565. dateProfile ? dateProfile.activeRange : null, calendar);
  2566. case 'MERGE_EVENTS': // already parsed and expanded
  2567. return mergeEventStores(eventStore, action.eventStore);
  2568. case 'PREV': // TODO: how do we track all actions that affect dateProfile :(
  2569. case 'NEXT':
  2570. case 'SET_DATE':
  2571. case 'SET_VIEW_TYPE':
  2572. if (dateProfile) {
  2573. return expandRecurring(eventStore, dateProfile.activeRange, calendar);
  2574. }
  2575. else {
  2576. return eventStore;
  2577. }
  2578. case 'CHANGE_TIMEZONE':
  2579. return rezoneDates(eventStore, action.oldDateEnv, calendar.dateEnv);
  2580. case 'MUTATE_EVENTS':
  2581. return applyMutationToRelated(eventStore, action.instanceId, action.mutation, action.fromApi, calendar);
  2582. case 'REMOVE_EVENT_INSTANCES':
  2583. return excludeInstances(eventStore, action.instances);
  2584. case 'REMOVE_EVENT_DEF':
  2585. return filterEventStoreDefs(eventStore, function (eventDef) {
  2586. return eventDef.defId !== action.defId;
  2587. });
  2588. case 'REMOVE_EVENT_SOURCE':
  2589. return excludeEventsBySourceId(eventStore, action.sourceId);
  2590. case 'REMOVE_ALL_EVENT_SOURCES':
  2591. return filterEventStoreDefs(eventStore, function (eventDef) {
  2592. return !eventDef.sourceId; // only keep events with no source id
  2593. });
  2594. case 'REMOVE_ALL_EVENTS':
  2595. return createEmptyEventStore();
  2596. case 'RESET_EVENTS':
  2597. return {
  2598. defs: eventStore.defs,
  2599. instances: eventStore.instances
  2600. };
  2601. default:
  2602. return eventStore;
  2603. }
  2604. }
  2605. function receiveRawEvents(eventStore, eventSource, fetchId, fetchRange, rawEvents, calendar) {
  2606. if (eventSource && // not already removed
  2607. fetchId === eventSource.latestFetchId // TODO: wish this logic was always in event-sources
  2608. ) {
  2609. var subset = parseEvents(transformRawEvents(rawEvents, eventSource, calendar), eventSource.sourceId, calendar);
  2610. if (fetchRange) {
  2611. subset = expandRecurring(subset, fetchRange, calendar);
  2612. }
  2613. return mergeEventStores(excludeEventsBySourceId(eventStore, eventSource.sourceId), subset);
  2614. }
  2615. return eventStore;
  2616. }
  2617. function addEvent(eventStore, subset, expandRange, calendar) {
  2618. if (expandRange) {
  2619. subset = expandRecurring(subset, expandRange, calendar);
  2620. }
  2621. return mergeEventStores(eventStore, subset);
  2622. }
  2623. function rezoneDates(eventStore, oldDateEnv, newDateEnv) {
  2624. var defs = eventStore.defs;
  2625. var instances = mapHash(eventStore.instances, function (instance) {
  2626. var def = defs[instance.defId];
  2627. if (def.allDay || def.recurringDef) {
  2628. return instance; // isn't dependent on timezone
  2629. }
  2630. else {
  2631. return __assign({}, instance, { range: {
  2632. start: newDateEnv.createMarker(oldDateEnv.toDate(instance.range.start, instance.forcedStartTzo)),
  2633. end: newDateEnv.createMarker(oldDateEnv.toDate(instance.range.end, instance.forcedEndTzo))
  2634. }, forcedStartTzo: newDateEnv.canComputeOffset ? null : instance.forcedStartTzo, forcedEndTzo: newDateEnv.canComputeOffset ? null : instance.forcedEndTzo });
  2635. }
  2636. });
  2637. return { defs: defs, instances: instances };
  2638. }
  2639. function applyMutationToRelated(eventStore, instanceId, mutation, fromApi, calendar) {
  2640. var relevant = getRelevantEvents(eventStore, instanceId);
  2641. var eventConfigBase = fromApi ?
  2642. { '': {
  2643. startEditable: true,
  2644. durationEditable: true,
  2645. constraints: [],
  2646. overlap: null,
  2647. allows: [],
  2648. backgroundColor: '',
  2649. borderColor: '',
  2650. textColor: '',
  2651. classNames: []
  2652. } } :
  2653. calendar.eventUiBases;
  2654. relevant = applyMutationToEventStore(relevant, eventConfigBase, mutation, calendar);
  2655. return mergeEventStores(eventStore, relevant);
  2656. }
  2657. function excludeEventsBySourceId(eventStore, sourceId) {
  2658. return filterEventStoreDefs(eventStore, function (eventDef) {
  2659. return eventDef.sourceId !== sourceId;
  2660. });
  2661. }
  2662. // QUESTION: why not just return instances? do a general object-property-exclusion util
  2663. function excludeInstances(eventStore, removals) {
  2664. return {
  2665. defs: eventStore.defs,
  2666. instances: filterHash(eventStore.instances, function (instance) {
  2667. return !removals[instance.instanceId];
  2668. })
  2669. };
  2670. }
  2671. // high-level segmenting-aware tester functions
  2672. // ------------------------------------------------------------------------------------------------------------------------
  2673. function isInteractionValid(interaction, calendar) {
  2674. return isNewPropsValid({ eventDrag: interaction }, calendar); // HACK: the eventDrag props is used for ALL interactions
  2675. }
  2676. function isDateSelectionValid(dateSelection, calendar) {
  2677. return isNewPropsValid({ dateSelection: dateSelection }, calendar);
  2678. }
  2679. function isNewPropsValid(newProps, calendar) {
  2680. var view = calendar.view;
  2681. var props = __assign({ businessHours: view ? view.props.businessHours : createEmptyEventStore(), dateSelection: '', eventStore: calendar.state.eventStore, eventUiBases: calendar.eventUiBases, eventSelection: '', eventDrag: null, eventResize: null }, newProps);
  2682. return (calendar.pluginSystem.hooks.isPropsValid || isPropsValid)(props, calendar);
  2683. }
  2684. function isPropsValid(state, calendar, dateSpanMeta, filterConfig) {
  2685. if (dateSpanMeta === void 0) { dateSpanMeta = {}; }
  2686. if (state.eventDrag && !isInteractionPropsValid(state, calendar, dateSpanMeta, filterConfig)) {
  2687. return false;
  2688. }
  2689. if (state.dateSelection && !isDateSelectionPropsValid(state, calendar, dateSpanMeta, filterConfig)) {
  2690. return false;
  2691. }
  2692. return true;
  2693. }
  2694. // Moving Event Validation
  2695. // ------------------------------------------------------------------------------------------------------------------------
  2696. function isInteractionPropsValid(state, calendar, dateSpanMeta, filterConfig) {
  2697. var interaction = state.eventDrag; // HACK: the eventDrag props is used for ALL interactions
  2698. var subjectEventStore = interaction.mutatedEvents;
  2699. var subjectDefs = subjectEventStore.defs;
  2700. var subjectInstances = subjectEventStore.instances;
  2701. var subjectConfigs = compileEventUis(subjectDefs, interaction.isEvent ?
  2702. state.eventUiBases :
  2703. { '': calendar.selectionConfig } // if not a real event, validate as a selection
  2704. );
  2705. if (filterConfig) {
  2706. subjectConfigs = mapHash(subjectConfigs, filterConfig);
  2707. }
  2708. var otherEventStore = excludeInstances(state.eventStore, interaction.affectedEvents.instances); // exclude the subject events. TODO: exclude defs too?
  2709. var otherDefs = otherEventStore.defs;
  2710. var otherInstances = otherEventStore.instances;
  2711. var otherConfigs = compileEventUis(otherDefs, state.eventUiBases);
  2712. for (var subjectInstanceId in subjectInstances) {
  2713. var subjectInstance = subjectInstances[subjectInstanceId];
  2714. var subjectRange = subjectInstance.range;
  2715. var subjectConfig = subjectConfigs[subjectInstance.defId];
  2716. var subjectDef = subjectDefs[subjectInstance.defId];
  2717. // constraint
  2718. if (!allConstraintsPass(subjectConfig.constraints, subjectRange, otherEventStore, state.businessHours, calendar)) {
  2719. return false;
  2720. }
  2721. // overlap
  2722. var overlapFunc = calendar.opt('eventOverlap');
  2723. if (typeof overlapFunc !== 'function') {
  2724. overlapFunc = null;
  2725. }
  2726. for (var otherInstanceId in otherInstances) {
  2727. var otherInstance = otherInstances[otherInstanceId];
  2728. // intersect! evaluate
  2729. if (rangesIntersect(subjectRange, otherInstance.range)) {
  2730. var otherOverlap = otherConfigs[otherInstance.defId].overlap;
  2731. // consider the other event's overlap. only do this if the subject event is a "real" event
  2732. if (otherOverlap === false && interaction.isEvent) {
  2733. return false;
  2734. }
  2735. if (subjectConfig.overlap === false) {
  2736. return false;
  2737. }
  2738. if (overlapFunc && !overlapFunc(new EventApi(calendar, otherDefs[otherInstance.defId], otherInstance), // still event
  2739. new EventApi(calendar, subjectDef, subjectInstance) // moving event
  2740. )) {
  2741. return false;
  2742. }
  2743. }
  2744. }
  2745. // allow (a function)
  2746. var calendarEventStore = calendar.state.eventStore; // need global-to-calendar, not local to component (splittable)state
  2747. for (var _i = 0, _a = subjectConfig.allows; _i < _a.length; _i++) {
  2748. var subjectAllow = _a[_i];
  2749. var subjectDateSpan = __assign({}, dateSpanMeta, { range: subjectInstance.range, allDay: subjectDef.allDay });
  2750. var origDef = calendarEventStore.defs[subjectDef.defId];
  2751. var origInstance = calendarEventStore.instances[subjectInstanceId];
  2752. var eventApi = void 0;
  2753. if (origDef) { // was previously in the calendar
  2754. eventApi = new EventApi(calendar, origDef, origInstance);
  2755. }
  2756. else { // was an external event
  2757. eventApi = new EventApi(calendar, subjectDef); // no instance, because had no dates
  2758. }
  2759. if (!subjectAllow(calendar.buildDateSpanApi(subjectDateSpan), eventApi)) {
  2760. return false;
  2761. }
  2762. }
  2763. }
  2764. return true;
  2765. }
  2766. // Date Selection Validation
  2767. // ------------------------------------------------------------------------------------------------------------------------
  2768. function isDateSelectionPropsValid(state, calendar, dateSpanMeta, filterConfig) {
  2769. var relevantEventStore = state.eventStore;
  2770. var relevantDefs = relevantEventStore.defs;
  2771. var relevantInstances = relevantEventStore.instances;
  2772. var selection = state.dateSelection;
  2773. var selectionRange = selection.range;
  2774. var selectionConfig = calendar.selectionConfig;
  2775. if (filterConfig) {
  2776. selectionConfig = filterConfig(selectionConfig);
  2777. }
  2778. // constraint
  2779. if (!allConstraintsPass(selectionConfig.constraints, selectionRange, relevantEventStore, state.businessHours, calendar)) {
  2780. return false;
  2781. }
  2782. // overlap
  2783. var overlapFunc = calendar.opt('selectOverlap');
  2784. if (typeof overlapFunc !== 'function') {
  2785. overlapFunc = null;
  2786. }
  2787. for (var relevantInstanceId in relevantInstances) {
  2788. var relevantInstance = relevantInstances[relevantInstanceId];
  2789. // intersect! evaluate
  2790. if (rangesIntersect(selectionRange, relevantInstance.range)) {
  2791. if (selectionConfig.overlap === false) {
  2792. return false;
  2793. }
  2794. if (overlapFunc && !overlapFunc(new EventApi(calendar, relevantDefs[relevantInstance.defId], relevantInstance))) {
  2795. return false;
  2796. }
  2797. }
  2798. }
  2799. // allow (a function)
  2800. for (var _i = 0, _a = selectionConfig.allows; _i < _a.length; _i++) {
  2801. var selectionAllow = _a[_i];
  2802. var fullDateSpan = __assign({}, dateSpanMeta, selection);
  2803. if (!selectionAllow(calendar.buildDateSpanApi(fullDateSpan), null)) {
  2804. return false;
  2805. }
  2806. }
  2807. return true;
  2808. }
  2809. // Constraint Utils
  2810. // ------------------------------------------------------------------------------------------------------------------------
  2811. function allConstraintsPass(constraints, subjectRange, otherEventStore, businessHoursUnexpanded, calendar) {
  2812. for (var _i = 0, constraints_1 = constraints; _i < constraints_1.length; _i++) {
  2813. var constraint = constraints_1[_i];
  2814. if (!anyRangesContainRange(constraintToRanges(constraint, subjectRange, otherEventStore, businessHoursUnexpanded, calendar), subjectRange)) {
  2815. return false;
  2816. }
  2817. }
  2818. return true;
  2819. }
  2820. function constraintToRanges(constraint, subjectRange, // for expanding a recurring constraint, or expanding business hours
  2821. otherEventStore, // for if constraint is an even group ID
  2822. businessHoursUnexpanded, // for if constraint is 'businessHours'
  2823. calendar // for expanding businesshours
  2824. ) {
  2825. if (constraint === 'businessHours') {
  2826. return eventStoreToRanges(expandRecurring(businessHoursUnexpanded, subjectRange, calendar));
  2827. }
  2828. else if (typeof constraint === 'string') { // an group ID
  2829. return eventStoreToRanges(filterEventStoreDefs(otherEventStore, function (eventDef) {
  2830. return eventDef.groupId === constraint;
  2831. }));
  2832. }
  2833. else if (typeof constraint === 'object' && constraint) { // non-null object
  2834. return eventStoreToRanges(expandRecurring(constraint, subjectRange, calendar));
  2835. }
  2836. return []; // if it's false
  2837. }
  2838. // TODO: move to event-store file?
  2839. function eventStoreToRanges(eventStore) {
  2840. var instances = eventStore.instances;
  2841. var ranges = [];
  2842. for (var instanceId in instances) {
  2843. ranges.push(instances[instanceId].range);
  2844. }
  2845. return ranges;
  2846. }
  2847. // TODO: move to geom file?
  2848. function anyRangesContainRange(outerRanges, innerRange) {
  2849. for (var _i = 0, outerRanges_1 = outerRanges; _i < outerRanges_1.length; _i++) {
  2850. var outerRange = outerRanges_1[_i];
  2851. if (rangeContainsRange(outerRange, innerRange)) {
  2852. return true;
  2853. }
  2854. }
  2855. return false;
  2856. }
  2857. // Parsing
  2858. // ------------------------------------------------------------------------------------------------------------------------
  2859. function normalizeConstraint(input, calendar) {
  2860. if (Array.isArray(input)) {
  2861. return parseEvents(input, '', calendar, true); // allowOpenRange=true
  2862. }
  2863. else if (typeof input === 'object' && input) { // non-null object
  2864. return parseEvents([input], '', calendar, true); // allowOpenRange=true
  2865. }
  2866. else if (input != null) {
  2867. return String(input);
  2868. }
  2869. else {
  2870. return null;
  2871. }
  2872. }
  2873. function htmlEscape(s) {
  2874. return (s + '').replace(/&/g, '&amp;')
  2875. .replace(/</g, '&lt;')
  2876. .replace(/>/g, '&gt;')
  2877. .replace(/'/g, '&#039;')
  2878. .replace(/"/g, '&quot;')
  2879. .replace(/\n/g, '<br />');
  2880. }
  2881. // Given a hash of CSS properties, returns a string of CSS.
  2882. // Uses property names as-is (no camel-case conversion). Will not make statements for null/undefined values.
  2883. function cssToStr(cssProps) {
  2884. var statements = [];
  2885. for (var name_1 in cssProps) {
  2886. var val = cssProps[name_1];
  2887. if (val != null && val !== '') {
  2888. statements.push(name_1 + ':' + val);
  2889. }
  2890. }
  2891. return statements.join(';');
  2892. }
  2893. // Given an object hash of HTML attribute names to values,
  2894. // generates a string that can be injected between < > in HTML
  2895. function attrsToStr(attrs) {
  2896. var parts = [];
  2897. for (var name_2 in attrs) {
  2898. var val = attrs[name_2];
  2899. if (val != null) {
  2900. parts.push(name_2 + '="' + htmlEscape(val) + '"');
  2901. }
  2902. }
  2903. return parts.join(' ');
  2904. }
  2905. function parseClassName(raw) {
  2906. if (Array.isArray(raw)) {
  2907. return raw;
  2908. }
  2909. else if (typeof raw === 'string') {
  2910. return raw.split(/\s+/);
  2911. }
  2912. else {
  2913. return [];
  2914. }
  2915. }
  2916. var UNSCOPED_EVENT_UI_PROPS = {
  2917. editable: Boolean,
  2918. startEditable: Boolean,
  2919. durationEditable: Boolean,
  2920. constraint: null,
  2921. overlap: null,
  2922. allow: null,
  2923. className: parseClassName,
  2924. classNames: parseClassName,
  2925. color: String,
  2926. backgroundColor: String,
  2927. borderColor: String,
  2928. textColor: String
  2929. };
  2930. function processUnscopedUiProps(rawProps, calendar, leftovers) {
  2931. var props = refineProps(rawProps, UNSCOPED_EVENT_UI_PROPS, {}, leftovers);
  2932. var constraint = normalizeConstraint(props.constraint, calendar);
  2933. return {
  2934. startEditable: props.startEditable != null ? props.startEditable : props.editable,
  2935. durationEditable: props.durationEditable != null ? props.durationEditable : props.editable,
  2936. constraints: constraint != null ? [constraint] : [],
  2937. overlap: props.overlap,
  2938. allows: props.allow != null ? [props.allow] : [],
  2939. backgroundColor: props.backgroundColor || props.color,
  2940. borderColor: props.borderColor || props.color,
  2941. textColor: props.textColor,
  2942. classNames: props.classNames.concat(props.className)
  2943. };
  2944. }
  2945. function processScopedUiProps(prefix, rawScoped, calendar, leftovers) {
  2946. var rawUnscoped = {};
  2947. var wasFound = {};
  2948. for (var key in UNSCOPED_EVENT_UI_PROPS) {
  2949. var scopedKey = prefix + capitaliseFirstLetter(key);
  2950. rawUnscoped[key] = rawScoped[scopedKey];
  2951. wasFound[scopedKey] = true;
  2952. }
  2953. if (prefix === 'event') {
  2954. rawUnscoped.editable = rawScoped.editable; // special case. there is no 'eventEditable', just 'editable'
  2955. }
  2956. if (leftovers) {
  2957. for (var key in rawScoped) {
  2958. if (!wasFound[key]) {
  2959. leftovers[key] = rawScoped[key];
  2960. }
  2961. }
  2962. }
  2963. return processUnscopedUiProps(rawUnscoped, calendar);
  2964. }
  2965. var EMPTY_EVENT_UI = {
  2966. startEditable: null,
  2967. durationEditable: null,
  2968. constraints: [],
  2969. overlap: null,
  2970. allows: [],
  2971. backgroundColor: '',
  2972. borderColor: '',
  2973. textColor: '',
  2974. classNames: []
  2975. };
  2976. // prevent against problems with <2 args!
  2977. function combineEventUis(uis) {
  2978. return uis.reduce(combineTwoEventUis, EMPTY_EVENT_UI);
  2979. }
  2980. function combineTwoEventUis(item0, item1) {
  2981. return {
  2982. startEditable: item1.startEditable != null ? item1.startEditable : item0.startEditable,
  2983. durationEditable: item1.durationEditable != null ? item1.durationEditable : item0.durationEditable,
  2984. constraints: item0.constraints.concat(item1.constraints),
  2985. overlap: typeof item1.overlap === 'boolean' ? item1.overlap : item0.overlap,
  2986. allows: item0.allows.concat(item1.allows),
  2987. backgroundColor: item1.backgroundColor || item0.backgroundColor,
  2988. borderColor: item1.borderColor || item0.borderColor,
  2989. textColor: item1.textColor || item0.textColor,
  2990. classNames: item0.classNames.concat(item1.classNames)
  2991. };
  2992. }
  2993. var NON_DATE_PROPS = {
  2994. id: String,
  2995. groupId: String,
  2996. title: String,
  2997. url: String,
  2998. rendering: String,
  2999. extendedProps: null
  3000. };
  3001. var DATE_PROPS = {
  3002. start: null,
  3003. date: null,
  3004. end: null,
  3005. allDay: null
  3006. };
  3007. var uid = 0;
  3008. function parseEvent(raw, sourceId, calendar, allowOpenRange) {
  3009. var allDayDefault = computeIsAllDayDefault(sourceId, calendar);
  3010. var leftovers0 = {};
  3011. var recurringRes = parseRecurring(raw, // raw, but with single-event stuff stripped out
  3012. allDayDefault, calendar.dateEnv, calendar.pluginSystem.hooks.recurringTypes, leftovers0 // will populate with non-recurring props
  3013. );
  3014. if (recurringRes) {
  3015. var def = parseEventDef(leftovers0, sourceId, recurringRes.allDay, Boolean(recurringRes.duration), calendar);
  3016. def.recurringDef = {
  3017. typeId: recurringRes.typeId,
  3018. typeData: recurringRes.typeData,
  3019. duration: recurringRes.duration
  3020. };
  3021. return { def: def, instance: null };
  3022. }
  3023. else {
  3024. var leftovers1 = {};
  3025. var singleRes = parseSingle(raw, allDayDefault, calendar, leftovers1, allowOpenRange);
  3026. if (singleRes) {
  3027. var def = parseEventDef(leftovers1, sourceId, singleRes.allDay, singleRes.hasEnd, calendar);
  3028. var instance = createEventInstance(def.defId, singleRes.range, singleRes.forcedStartTzo, singleRes.forcedEndTzo);
  3029. return { def: def, instance: instance };
  3030. }
  3031. }
  3032. return null;
  3033. }
  3034. /*
  3035. Will NOT populate extendedProps with the leftover properties.
  3036. Will NOT populate date-related props.
  3037. The EventNonDateInput has been normalized (id => publicId, etc).
  3038. */
  3039. function parseEventDef(raw, sourceId, allDay, hasEnd, calendar) {
  3040. var leftovers = {};
  3041. var def = pluckNonDateProps(raw, calendar, leftovers);
  3042. def.defId = String(uid++);
  3043. def.sourceId = sourceId;
  3044. def.allDay = allDay;
  3045. def.hasEnd = hasEnd;
  3046. for (var _i = 0, _a = calendar.pluginSystem.hooks.eventDefParsers; _i < _a.length; _i++) {
  3047. var eventDefParser = _a[_i];
  3048. var newLeftovers = {};
  3049. eventDefParser(def, leftovers, newLeftovers);
  3050. leftovers = newLeftovers;
  3051. }
  3052. def.extendedProps = __assign(leftovers, def.extendedProps || {});
  3053. // help out EventApi from having user modify props
  3054. Object.freeze(def.ui.classNames);
  3055. Object.freeze(def.extendedProps);
  3056. return def;
  3057. }
  3058. function createEventInstance(defId, range, forcedStartTzo, forcedEndTzo) {
  3059. return {
  3060. instanceId: String(uid++),
  3061. defId: defId,
  3062. range: range,
  3063. forcedStartTzo: forcedStartTzo == null ? null : forcedStartTzo,
  3064. forcedEndTzo: forcedEndTzo == null ? null : forcedEndTzo
  3065. };
  3066. }
  3067. function parseSingle(raw, allDayDefault, calendar, leftovers, allowOpenRange) {
  3068. var props = pluckDateProps(raw, leftovers);
  3069. var allDay = props.allDay;
  3070. var startMeta;
  3071. var startMarker = null;
  3072. var hasEnd = false;
  3073. var endMeta;
  3074. var endMarker = null;
  3075. startMeta = calendar.dateEnv.createMarkerMeta(props.start);
  3076. if (startMeta) {
  3077. startMarker = startMeta.marker;
  3078. }
  3079. else if (!allowOpenRange) {
  3080. return null;
  3081. }
  3082. if (props.end != null) {
  3083. endMeta = calendar.dateEnv.createMarkerMeta(props.end);
  3084. }
  3085. if (allDay == null) {
  3086. if (allDayDefault != null) {
  3087. allDay = allDayDefault;
  3088. }
  3089. else {
  3090. // fall back to the date props LAST
  3091. allDay = (!startMeta || startMeta.isTimeUnspecified) &&
  3092. (!endMeta || endMeta.isTimeUnspecified);
  3093. }
  3094. }
  3095. if (allDay && startMarker) {
  3096. startMarker = startOfDay(startMarker);
  3097. }
  3098. if (endMeta) {
  3099. endMarker = endMeta.marker;
  3100. if (allDay) {
  3101. endMarker = startOfDay(endMarker);
  3102. }
  3103. if (startMarker && endMarker <= startMarker) {
  3104. endMarker = null;
  3105. }
  3106. }
  3107. if (endMarker) {
  3108. hasEnd = true;
  3109. }
  3110. else if (!allowOpenRange) {
  3111. hasEnd = calendar.opt('forceEventDuration') || false;
  3112. endMarker = calendar.dateEnv.add(startMarker, allDay ?
  3113. calendar.defaultAllDayEventDuration :
  3114. calendar.defaultTimedEventDuration);
  3115. }
  3116. return {
  3117. allDay: allDay,
  3118. hasEnd: hasEnd,
  3119. range: { start: startMarker, end: endMarker },
  3120. forcedStartTzo: startMeta ? startMeta.forcedTzo : null,
  3121. forcedEndTzo: endMeta ? endMeta.forcedTzo : null
  3122. };
  3123. }
  3124. function pluckDateProps(raw, leftovers) {
  3125. var props = refineProps(raw, DATE_PROPS, {}, leftovers);
  3126. props.start = (props.start !== null) ? props.start : props.date;
  3127. delete props.date;
  3128. return props;
  3129. }
  3130. function pluckNonDateProps(raw, calendar, leftovers) {
  3131. var preLeftovers = {};
  3132. var props = refineProps(raw, NON_DATE_PROPS, {}, preLeftovers);
  3133. var ui = processUnscopedUiProps(preLeftovers, calendar, leftovers);
  3134. props.publicId = props.id;
  3135. delete props.id;
  3136. props.ui = ui;
  3137. return props;
  3138. }
  3139. function computeIsAllDayDefault(sourceId, calendar) {
  3140. var res = null;
  3141. if (sourceId) {
  3142. var source = calendar.state.eventSources[sourceId];
  3143. res = source.allDayDefault;
  3144. }
  3145. if (res == null) {
  3146. res = calendar.opt('allDayDefault');
  3147. }
  3148. return res;
  3149. }
  3150. var DEF_DEFAULTS = {
  3151. startTime: '09:00',
  3152. endTime: '17:00',
  3153. daysOfWeek: [1, 2, 3, 4, 5],
  3154. rendering: 'inverse-background',
  3155. classNames: 'fc-nonbusiness',
  3156. groupId: '_businessHours' // so multiple defs get grouped
  3157. };
  3158. /*
  3159. TODO: pass around as EventDefHash!!!
  3160. */
  3161. function parseBusinessHours(input, calendar) {
  3162. return parseEvents(refineInputs(input), '', calendar);
  3163. }
  3164. function refineInputs(input) {
  3165. var rawDefs;
  3166. if (input === true) {
  3167. rawDefs = [{}]; // will get DEF_DEFAULTS verbatim
  3168. }
  3169. else if (Array.isArray(input)) {
  3170. // if specifying an array, every sub-definition NEEDS a day-of-week
  3171. rawDefs = input.filter(function (rawDef) {
  3172. return rawDef.daysOfWeek;
  3173. });
  3174. }
  3175. else if (typeof input === 'object' && input) { // non-null object
  3176. rawDefs = [input];
  3177. }
  3178. else { // is probably false
  3179. rawDefs = [];
  3180. }
  3181. rawDefs = rawDefs.map(function (rawDef) {
  3182. return __assign({}, DEF_DEFAULTS, rawDef);
  3183. });
  3184. return rawDefs;
  3185. }
  3186. function memoizeRendering(renderFunc, unrenderFunc, dependencies) {
  3187. if (dependencies === void 0) { dependencies = []; }
  3188. var dependents = [];
  3189. var thisContext;
  3190. var prevArgs;
  3191. function unrender() {
  3192. if (prevArgs) {
  3193. for (var _i = 0, dependents_1 = dependents; _i < dependents_1.length; _i++) {
  3194. var dependent = dependents_1[_i];
  3195. dependent.unrender();
  3196. }
  3197. if (unrenderFunc) {
  3198. unrenderFunc.apply(thisContext, prevArgs);
  3199. }
  3200. prevArgs = null;
  3201. }
  3202. }
  3203. function res() {
  3204. if (!prevArgs || !isArraysEqual(prevArgs, arguments)) {
  3205. unrender();
  3206. thisContext = this;
  3207. prevArgs = arguments;
  3208. renderFunc.apply(this, arguments);
  3209. }
  3210. }
  3211. res.dependents = dependents;
  3212. res.unrender = unrender;
  3213. for (var _i = 0, dependencies_1 = dependencies; _i < dependencies_1.length; _i++) {
  3214. var dependency = dependencies_1[_i];
  3215. dependency.dependents.push(res);
  3216. }
  3217. return res;
  3218. }
  3219. var EMPTY_EVENT_STORE = createEmptyEventStore(); // for purecomponents. TODO: keep elsewhere
  3220. var Splitter = /** @class */ (function () {
  3221. function Splitter() {
  3222. this.getKeysForEventDefs = memoize(this._getKeysForEventDefs);
  3223. this.splitDateSelection = memoize(this._splitDateSpan);
  3224. this.splitEventStore = memoize(this._splitEventStore);
  3225. this.splitIndividualUi = memoize(this._splitIndividualUi);
  3226. this.splitEventDrag = memoize(this._splitInteraction);
  3227. this.splitEventResize = memoize(this._splitInteraction);
  3228. this.eventUiBuilders = {}; // TODO: typescript protection
  3229. }
  3230. Splitter.prototype.splitProps = function (props) {
  3231. var _this = this;
  3232. var keyInfos = this.getKeyInfo(props);
  3233. var defKeys = this.getKeysForEventDefs(props.eventStore);
  3234. var dateSelections = this.splitDateSelection(props.dateSelection);
  3235. var individualUi = this.splitIndividualUi(props.eventUiBases, defKeys); // the individual *bases*
  3236. var eventStores = this.splitEventStore(props.eventStore, defKeys);
  3237. var eventDrags = this.splitEventDrag(props.eventDrag);
  3238. var eventResizes = this.splitEventResize(props.eventResize);
  3239. var splitProps = {};
  3240. this.eventUiBuilders = mapHash(keyInfos, function (info, key) {
  3241. return _this.eventUiBuilders[key] || memoize(buildEventUiForKey);
  3242. });
  3243. for (var key in keyInfos) {
  3244. var keyInfo = keyInfos[key];
  3245. var eventStore = eventStores[key] || EMPTY_EVENT_STORE;
  3246. var buildEventUi = this.eventUiBuilders[key];
  3247. splitProps[key] = {
  3248. businessHours: keyInfo.businessHours || props.businessHours,
  3249. dateSelection: dateSelections[key] || null,
  3250. eventStore: eventStore,
  3251. eventUiBases: buildEventUi(props.eventUiBases[''], keyInfo.ui, individualUi[key]),
  3252. eventSelection: eventStore.instances[props.eventSelection] ? props.eventSelection : '',
  3253. eventDrag: eventDrags[key] || null,
  3254. eventResize: eventResizes[key] || null
  3255. };
  3256. }
  3257. return splitProps;
  3258. };
  3259. Splitter.prototype._splitDateSpan = function (dateSpan) {
  3260. var dateSpans = {};
  3261. if (dateSpan) {
  3262. var keys = this.getKeysForDateSpan(dateSpan);
  3263. for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
  3264. var key = keys_1[_i];
  3265. dateSpans[key] = dateSpan;
  3266. }
  3267. }
  3268. return dateSpans;
  3269. };
  3270. Splitter.prototype._getKeysForEventDefs = function (eventStore) {
  3271. var _this = this;
  3272. return mapHash(eventStore.defs, function (eventDef) {
  3273. return _this.getKeysForEventDef(eventDef);
  3274. });
  3275. };
  3276. Splitter.prototype._splitEventStore = function (eventStore, defKeys) {
  3277. var defs = eventStore.defs, instances = eventStore.instances;
  3278. var splitStores = {};
  3279. for (var defId in defs) {
  3280. for (var _i = 0, _a = defKeys[defId]; _i < _a.length; _i++) {
  3281. var key = _a[_i];
  3282. if (!splitStores[key]) {
  3283. splitStores[key] = createEmptyEventStore();
  3284. }
  3285. splitStores[key].defs[defId] = defs[defId];
  3286. }
  3287. }
  3288. for (var instanceId in instances) {
  3289. var instance = instances[instanceId];
  3290. for (var _b = 0, _c = defKeys[instance.defId]; _b < _c.length; _b++) {
  3291. var key = _c[_b];
  3292. if (splitStores[key]) { // must have already been created
  3293. splitStores[key].instances[instanceId] = instance;
  3294. }
  3295. }
  3296. }
  3297. return splitStores;
  3298. };
  3299. Splitter.prototype._splitIndividualUi = function (eventUiBases, defKeys) {
  3300. var splitHashes = {};
  3301. for (var defId in eventUiBases) {
  3302. if (defId) { // not the '' key
  3303. for (var _i = 0, _a = defKeys[defId]; _i < _a.length; _i++) {
  3304. var key = _a[_i];
  3305. if (!splitHashes[key]) {
  3306. splitHashes[key] = {};
  3307. }
  3308. splitHashes[key][defId] = eventUiBases[defId];
  3309. }
  3310. }
  3311. }
  3312. return splitHashes;
  3313. };
  3314. Splitter.prototype._splitInteraction = function (interaction) {
  3315. var splitStates = {};
  3316. if (interaction) {
  3317. var affectedStores_1 = this._splitEventStore(interaction.affectedEvents, this._getKeysForEventDefs(interaction.affectedEvents) // can't use cached. might be events from other calendar
  3318. );
  3319. // can't rely on defKeys because event data is mutated
  3320. var mutatedKeysByDefId = this._getKeysForEventDefs(interaction.mutatedEvents);
  3321. var mutatedStores_1 = this._splitEventStore(interaction.mutatedEvents, mutatedKeysByDefId);
  3322. var populate = function (key) {
  3323. if (!splitStates[key]) {
  3324. splitStates[key] = {
  3325. affectedEvents: affectedStores_1[key] || EMPTY_EVENT_STORE,
  3326. mutatedEvents: mutatedStores_1[key] || EMPTY_EVENT_STORE,
  3327. isEvent: interaction.isEvent,
  3328. origSeg: interaction.origSeg
  3329. };
  3330. }
  3331. };
  3332. for (var key in affectedStores_1) {
  3333. populate(key);
  3334. }
  3335. for (var key in mutatedStores_1) {
  3336. populate(key);
  3337. }
  3338. }
  3339. return splitStates;
  3340. };
  3341. return Splitter;
  3342. }());
  3343. function buildEventUiForKey(allUi, eventUiForKey, individualUi) {
  3344. var baseParts = [];
  3345. if (allUi) {
  3346. baseParts.push(allUi);
  3347. }
  3348. if (eventUiForKey) {
  3349. baseParts.push(eventUiForKey);
  3350. }
  3351. var stuff = {
  3352. '': combineEventUis(baseParts)
  3353. };
  3354. if (individualUi) {
  3355. __assign(stuff, individualUi);
  3356. }
  3357. return stuff;
  3358. }
  3359. // Generates HTML for an anchor to another view into the calendar.
  3360. // Will either generate an <a> tag or a non-clickable <span> tag, depending on enabled settings.
  3361. // `gotoOptions` can either be a DateMarker, or an object with the form:
  3362. // { date, type, forceOff }
  3363. // `type` is a view-type like "day" or "week". default value is "day".
  3364. // `attrs` and `innerHtml` are use to generate the rest of the HTML tag.
  3365. function buildGotoAnchorHtml(allOptions, dateEnv, gotoOptions, attrs, innerHtml) {
  3366. var date;
  3367. var type;
  3368. var forceOff;
  3369. var finalOptions;
  3370. if (gotoOptions instanceof Date) {
  3371. date = gotoOptions; // a single date-like input
  3372. }
  3373. else {
  3374. date = gotoOptions.date;
  3375. type = gotoOptions.type;
  3376. forceOff = gotoOptions.forceOff;
  3377. }
  3378. finalOptions = {
  3379. date: dateEnv.formatIso(date, { omitTime: true }),
  3380. type: type || 'day'
  3381. };
  3382. if (typeof attrs === 'string') {
  3383. innerHtml = attrs;
  3384. attrs = null;
  3385. }
  3386. attrs = attrs ? ' ' + attrsToStr(attrs) : ''; // will have a leading space
  3387. innerHtml = innerHtml || '';
  3388. if (!forceOff && allOptions.navLinks) {
  3389. return '<a' + attrs +
  3390. ' data-goto="' + htmlEscape(JSON.stringify(finalOptions)) + '">' +
  3391. innerHtml +
  3392. '</a>';
  3393. }
  3394. else {
  3395. return '<span' + attrs + '>' +
  3396. innerHtml +
  3397. '</span>';
  3398. }
  3399. }
  3400. function getAllDayHtml(allOptions) {
  3401. return allOptions.allDayHtml || htmlEscape(allOptions.allDayText);
  3402. }
  3403. // Computes HTML classNames for a single-day element
  3404. function getDayClasses(date, dateProfile, context, noThemeHighlight) {
  3405. var calendar = context.calendar, options = context.options, theme = context.theme, dateEnv = context.dateEnv;
  3406. var classes = [];
  3407. var todayStart;
  3408. var todayEnd;
  3409. if (!rangeContainsMarker(dateProfile.activeRange, date)) {
  3410. classes.push('fc-disabled-day');
  3411. }
  3412. else {
  3413. classes.push('fc-' + DAY_IDS[date.getUTCDay()]);
  3414. if (options.monthMode &&
  3415. dateEnv.getMonth(date) !== dateEnv.getMonth(dateProfile.currentRange.start)) {
  3416. classes.push('fc-other-month');
  3417. }
  3418. todayStart = startOfDay(calendar.getNow());
  3419. todayEnd = addDays(todayStart, 1);
  3420. if (date < todayStart) {
  3421. classes.push('fc-past');
  3422. }
  3423. else if (date >= todayEnd) {
  3424. classes.push('fc-future');
  3425. }
  3426. else {
  3427. classes.push('fc-today');
  3428. if (noThemeHighlight !== true) {
  3429. classes.push(theme.getClass('today'));
  3430. }
  3431. }
  3432. }
  3433. return classes;
  3434. }
  3435. // given a function that resolves a result asynchronously.
  3436. // the function can either call passed-in success and failure callbacks,
  3437. // or it can return a promise.
  3438. // if you need to pass additional params to func, bind them first.
  3439. function unpromisify(func, success, failure) {
  3440. // guard against success/failure callbacks being called more than once
  3441. // and guard against a promise AND callback being used together.
  3442. var isResolved = false;
  3443. var wrappedSuccess = function () {
  3444. if (!isResolved) {
  3445. isResolved = true;
  3446. success.apply(this, arguments);
  3447. }
  3448. };
  3449. var wrappedFailure = function () {
  3450. if (!isResolved) {
  3451. isResolved = true;
  3452. if (failure) {
  3453. failure.apply(this, arguments);
  3454. }
  3455. }
  3456. };
  3457. var res = func(wrappedSuccess, wrappedFailure);
  3458. if (res && typeof res.then === 'function') {
  3459. res.then(wrappedSuccess, wrappedFailure);
  3460. }
  3461. }
  3462. var Mixin = /** @class */ (function () {
  3463. function Mixin() {
  3464. }
  3465. // mix into a CLASS
  3466. Mixin.mixInto = function (destClass) {
  3467. this.mixIntoObj(destClass.prototype);
  3468. };
  3469. // mix into ANY object
  3470. Mixin.mixIntoObj = function (destObj) {
  3471. var _this = this;
  3472. Object.getOwnPropertyNames(this.prototype).forEach(function (name) {
  3473. if (!destObj[name]) { // if destination doesn't already define it
  3474. destObj[name] = _this.prototype[name];
  3475. }
  3476. });
  3477. };
  3478. /*
  3479. will override existing methods
  3480. TODO: remove! not used anymore
  3481. */
  3482. Mixin.mixOver = function (destClass) {
  3483. var _this = this;
  3484. Object.getOwnPropertyNames(this.prototype).forEach(function (name) {
  3485. destClass.prototype[name] = _this.prototype[name];
  3486. });
  3487. };
  3488. return Mixin;
  3489. }());
  3490. /*
  3491. USAGE:
  3492. import { default as EmitterMixin, EmitterInterface } from './EmitterMixin'
  3493. in class:
  3494. on: EmitterInterface['on']
  3495. one: EmitterInterface['one']
  3496. off: EmitterInterface['off']
  3497. trigger: EmitterInterface['trigger']
  3498. triggerWith: EmitterInterface['triggerWith']
  3499. hasHandlers: EmitterInterface['hasHandlers']
  3500. after class:
  3501. EmitterMixin.mixInto(TheClass)
  3502. */
  3503. var EmitterMixin = /** @class */ (function (_super) {
  3504. __extends(EmitterMixin, _super);
  3505. function EmitterMixin() {
  3506. return _super !== null && _super.apply(this, arguments) || this;
  3507. }
  3508. EmitterMixin.prototype.on = function (type, handler) {
  3509. addToHash(this._handlers || (this._handlers = {}), type, handler);
  3510. return this; // for chaining
  3511. };
  3512. // todo: add comments
  3513. EmitterMixin.prototype.one = function (type, handler) {
  3514. addToHash(this._oneHandlers || (this._oneHandlers = {}), type, handler);
  3515. return this; // for chaining
  3516. };
  3517. EmitterMixin.prototype.off = function (type, handler) {
  3518. if (this._handlers) {
  3519. removeFromHash(this._handlers, type, handler);
  3520. }
  3521. if (this._oneHandlers) {
  3522. removeFromHash(this._oneHandlers, type, handler);
  3523. }
  3524. return this; // for chaining
  3525. };
  3526. EmitterMixin.prototype.trigger = function (type) {
  3527. var args = [];
  3528. for (var _i = 1; _i < arguments.length; _i++) {
  3529. args[_i - 1] = arguments[_i];
  3530. }
  3531. this.triggerWith(type, this, args);
  3532. return this; // for chaining
  3533. };
  3534. EmitterMixin.prototype.triggerWith = function (type, context, args) {
  3535. if (this._handlers) {
  3536. applyAll(this._handlers[type], context, args);
  3537. }
  3538. if (this._oneHandlers) {
  3539. applyAll(this._oneHandlers[type], context, args);
  3540. delete this._oneHandlers[type]; // will never fire again
  3541. }
  3542. return this; // for chaining
  3543. };
  3544. EmitterMixin.prototype.hasHandlers = function (type) {
  3545. return (this._handlers && this._handlers[type] && this._handlers[type].length) ||
  3546. (this._oneHandlers && this._oneHandlers[type] && this._oneHandlers[type].length);
  3547. };
  3548. return EmitterMixin;
  3549. }(Mixin));
  3550. function addToHash(hash, type, handler) {
  3551. (hash[type] || (hash[type] = []))
  3552. .push(handler);
  3553. }
  3554. function removeFromHash(hash, type, handler) {
  3555. if (handler) {
  3556. if (hash[type]) {
  3557. hash[type] = hash[type].filter(function (func) {
  3558. return func !== handler;
  3559. });
  3560. }
  3561. }
  3562. else {
  3563. delete hash[type]; // remove all handler funcs for this type
  3564. }
  3565. }
  3566. /*
  3567. Records offset information for a set of elements, relative to an origin element.
  3568. Can record the left/right OR the top/bottom OR both.
  3569. Provides methods for querying the cache by position.
  3570. */
  3571. var PositionCache = /** @class */ (function () {
  3572. function PositionCache(originEl, els, isHorizontal, isVertical) {
  3573. this.originEl = originEl;
  3574. this.els = els;
  3575. this.isHorizontal = isHorizontal;
  3576. this.isVertical = isVertical;
  3577. }
  3578. // Queries the els for coordinates and stores them.
  3579. // Call this method before using and of the get* methods below.
  3580. PositionCache.prototype.build = function () {
  3581. var originEl = this.originEl;
  3582. var originClientRect = this.originClientRect =
  3583. originEl.getBoundingClientRect(); // relative to viewport top-left
  3584. if (this.isHorizontal) {
  3585. this.buildElHorizontals(originClientRect.left);
  3586. }
  3587. if (this.isVertical) {
  3588. this.buildElVerticals(originClientRect.top);
  3589. }
  3590. };
  3591. // Populates the left/right internal coordinate arrays
  3592. PositionCache.prototype.buildElHorizontals = function (originClientLeft) {
  3593. var lefts = [];
  3594. var rights = [];
  3595. for (var _i = 0, _a = this.els; _i < _a.length; _i++) {
  3596. var el = _a[_i];
  3597. var rect = el.getBoundingClientRect();
  3598. lefts.push(rect.left - originClientLeft);
  3599. rights.push(rect.right - originClientLeft);
  3600. }
  3601. this.lefts = lefts;
  3602. this.rights = rights;
  3603. };
  3604. // Populates the top/bottom internal coordinate arrays
  3605. PositionCache.prototype.buildElVerticals = function (originClientTop) {
  3606. var tops = [];
  3607. var bottoms = [];
  3608. for (var _i = 0, _a = this.els; _i < _a.length; _i++) {
  3609. var el = _a[_i];
  3610. var rect = el.getBoundingClientRect();
  3611. tops.push(rect.top - originClientTop);
  3612. bottoms.push(rect.bottom - originClientTop);
  3613. }
  3614. this.tops = tops;
  3615. this.bottoms = bottoms;
  3616. };
  3617. // Given a left offset (from document left), returns the index of the el that it horizontally intersects.
  3618. // If no intersection is made, returns undefined.
  3619. PositionCache.prototype.leftToIndex = function (leftPosition) {
  3620. var lefts = this.lefts;
  3621. var rights = this.rights;
  3622. var len = lefts.length;
  3623. var i;
  3624. for (i = 0; i < len; i++) {
  3625. if (leftPosition >= lefts[i] && leftPosition < rights[i]) {
  3626. return i;
  3627. }
  3628. }
  3629. };
  3630. // Given a top offset (from document top), returns the index of the el that it vertically intersects.
  3631. // If no intersection is made, returns undefined.
  3632. PositionCache.prototype.topToIndex = function (topPosition) {
  3633. var tops = this.tops;
  3634. var bottoms = this.bottoms;
  3635. var len = tops.length;
  3636. var i;
  3637. for (i = 0; i < len; i++) {
  3638. if (topPosition >= tops[i] && topPosition < bottoms[i]) {
  3639. return i;
  3640. }
  3641. }
  3642. };
  3643. // Gets the width of the element at the given index
  3644. PositionCache.prototype.getWidth = function (leftIndex) {
  3645. return this.rights[leftIndex] - this.lefts[leftIndex];
  3646. };
  3647. // Gets the height of the element at the given index
  3648. PositionCache.prototype.getHeight = function (topIndex) {
  3649. return this.bottoms[topIndex] - this.tops[topIndex];
  3650. };
  3651. return PositionCache;
  3652. }());
  3653. /*
  3654. An object for getting/setting scroll-related information for an element.
  3655. Internally, this is done very differently for window versus DOM element,
  3656. so this object serves as a common interface.
  3657. */
  3658. var ScrollController = /** @class */ (function () {
  3659. function ScrollController() {
  3660. }
  3661. ScrollController.prototype.getMaxScrollTop = function () {
  3662. return this.getScrollHeight() - this.getClientHeight();
  3663. };
  3664. ScrollController.prototype.getMaxScrollLeft = function () {
  3665. return this.getScrollWidth() - this.getClientWidth();
  3666. };
  3667. ScrollController.prototype.canScrollVertically = function () {
  3668. return this.getMaxScrollTop() > 0;
  3669. };
  3670. ScrollController.prototype.canScrollHorizontally = function () {
  3671. return this.getMaxScrollLeft() > 0;
  3672. };
  3673. ScrollController.prototype.canScrollUp = function () {
  3674. return this.getScrollTop() > 0;
  3675. };
  3676. ScrollController.prototype.canScrollDown = function () {
  3677. return this.getScrollTop() < this.getMaxScrollTop();
  3678. };
  3679. ScrollController.prototype.canScrollLeft = function () {
  3680. return this.getScrollLeft() > 0;
  3681. };
  3682. ScrollController.prototype.canScrollRight = function () {
  3683. return this.getScrollLeft() < this.getMaxScrollLeft();
  3684. };
  3685. return ScrollController;
  3686. }());
  3687. var ElementScrollController = /** @class */ (function (_super) {
  3688. __extends(ElementScrollController, _super);
  3689. function ElementScrollController(el) {
  3690. var _this = _super.call(this) || this;
  3691. _this.el = el;
  3692. return _this;
  3693. }
  3694. ElementScrollController.prototype.getScrollTop = function () {
  3695. return this.el.scrollTop;
  3696. };
  3697. ElementScrollController.prototype.getScrollLeft = function () {
  3698. return this.el.scrollLeft;
  3699. };
  3700. ElementScrollController.prototype.setScrollTop = function (top) {
  3701. this.el.scrollTop = top;
  3702. };
  3703. ElementScrollController.prototype.setScrollLeft = function (left) {
  3704. this.el.scrollLeft = left;
  3705. };
  3706. ElementScrollController.prototype.getScrollWidth = function () {
  3707. return this.el.scrollWidth;
  3708. };
  3709. ElementScrollController.prototype.getScrollHeight = function () {
  3710. return this.el.scrollHeight;
  3711. };
  3712. ElementScrollController.prototype.getClientHeight = function () {
  3713. return this.el.clientHeight;
  3714. };
  3715. ElementScrollController.prototype.getClientWidth = function () {
  3716. return this.el.clientWidth;
  3717. };
  3718. return ElementScrollController;
  3719. }(ScrollController));
  3720. var WindowScrollController = /** @class */ (function (_super) {
  3721. __extends(WindowScrollController, _super);
  3722. function WindowScrollController() {
  3723. return _super !== null && _super.apply(this, arguments) || this;
  3724. }
  3725. WindowScrollController.prototype.getScrollTop = function () {
  3726. return window.pageYOffset;
  3727. };
  3728. WindowScrollController.prototype.getScrollLeft = function () {
  3729. return window.pageXOffset;
  3730. };
  3731. WindowScrollController.prototype.setScrollTop = function (n) {
  3732. window.scroll(window.pageXOffset, n);
  3733. };
  3734. WindowScrollController.prototype.setScrollLeft = function (n) {
  3735. window.scroll(n, window.pageYOffset);
  3736. };
  3737. WindowScrollController.prototype.getScrollWidth = function () {
  3738. return document.documentElement.scrollWidth;
  3739. };
  3740. WindowScrollController.prototype.getScrollHeight = function () {
  3741. return document.documentElement.scrollHeight;
  3742. };
  3743. WindowScrollController.prototype.getClientHeight = function () {
  3744. return document.documentElement.clientHeight;
  3745. };
  3746. WindowScrollController.prototype.getClientWidth = function () {
  3747. return document.documentElement.clientWidth;
  3748. };
  3749. return WindowScrollController;
  3750. }(ScrollController));
  3751. /*
  3752. Embodies a div that has potential scrollbars
  3753. */
  3754. var ScrollComponent = /** @class */ (function (_super) {
  3755. __extends(ScrollComponent, _super);
  3756. function ScrollComponent(overflowX, overflowY) {
  3757. var _this = _super.call(this, createElement('div', {
  3758. className: 'fc-scroller'
  3759. })) || this;
  3760. _this.overflowX = overflowX;
  3761. _this.overflowY = overflowY;
  3762. _this.applyOverflow();
  3763. return _this;
  3764. }
  3765. // sets to natural height, unlocks overflow
  3766. ScrollComponent.prototype.clear = function () {
  3767. this.setHeight('auto');
  3768. this.applyOverflow();
  3769. };
  3770. ScrollComponent.prototype.destroy = function () {
  3771. removeElement(this.el);
  3772. };
  3773. // Overflow
  3774. // -----------------------------------------------------------------------------------------------------------------
  3775. ScrollComponent.prototype.applyOverflow = function () {
  3776. applyStyle(this.el, {
  3777. overflowX: this.overflowX,
  3778. overflowY: this.overflowY
  3779. });
  3780. };
  3781. // Causes any 'auto' overflow values to resolves to 'scroll' or 'hidden'.
  3782. // Useful for preserving scrollbar widths regardless of future resizes.
  3783. // Can pass in scrollbarWidths for optimization.
  3784. ScrollComponent.prototype.lockOverflow = function (scrollbarWidths) {
  3785. var overflowX = this.overflowX;
  3786. var overflowY = this.overflowY;
  3787. scrollbarWidths = scrollbarWidths || this.getScrollbarWidths();
  3788. if (overflowX === 'auto') {
  3789. overflowX = (scrollbarWidths.bottom || // horizontal scrollbars?
  3790. this.canScrollHorizontally() // OR scrolling pane with massless scrollbars?
  3791. ) ? 'scroll' : 'hidden';
  3792. }
  3793. if (overflowY === 'auto') {
  3794. overflowY = (scrollbarWidths.left || scrollbarWidths.right || // horizontal scrollbars?
  3795. this.canScrollVertically() // OR scrolling pane with massless scrollbars?
  3796. ) ? 'scroll' : 'hidden';
  3797. }
  3798. applyStyle(this.el, { overflowX: overflowX, overflowY: overflowY });
  3799. };
  3800. ScrollComponent.prototype.setHeight = function (height) {
  3801. applyStyleProp(this.el, 'height', height);
  3802. };
  3803. ScrollComponent.prototype.getScrollbarWidths = function () {
  3804. var edges = computeEdges(this.el);
  3805. return {
  3806. left: edges.scrollbarLeft,
  3807. right: edges.scrollbarRight,
  3808. bottom: edges.scrollbarBottom
  3809. };
  3810. };
  3811. return ScrollComponent;
  3812. }(ElementScrollController));
  3813. var Theme = /** @class */ (function () {
  3814. function Theme(calendarOptions) {
  3815. this.calendarOptions = calendarOptions;
  3816. this.processIconOverride();
  3817. }
  3818. Theme.prototype.processIconOverride = function () {
  3819. if (this.iconOverrideOption) {
  3820. this.setIconOverride(this.calendarOptions[this.iconOverrideOption]);
  3821. }
  3822. };
  3823. Theme.prototype.setIconOverride = function (iconOverrideHash) {
  3824. var iconClassesCopy;
  3825. var buttonName;
  3826. if (typeof iconOverrideHash === 'object' && iconOverrideHash) { // non-null object
  3827. iconClassesCopy = __assign({}, this.iconClasses);
  3828. for (buttonName in iconOverrideHash) {
  3829. iconClassesCopy[buttonName] = this.applyIconOverridePrefix(iconOverrideHash[buttonName]);
  3830. }
  3831. this.iconClasses = iconClassesCopy;
  3832. }
  3833. else if (iconOverrideHash === false) {
  3834. this.iconClasses = {};
  3835. }
  3836. };
  3837. Theme.prototype.applyIconOverridePrefix = function (className) {
  3838. var prefix = this.iconOverridePrefix;
  3839. if (prefix && className.indexOf(prefix) !== 0) { // if not already present
  3840. className = prefix + className;
  3841. }
  3842. return className;
  3843. };
  3844. Theme.prototype.getClass = function (key) {
  3845. return this.classes[key] || '';
  3846. };
  3847. Theme.prototype.getIconClass = function (buttonName) {
  3848. var className = this.iconClasses[buttonName];
  3849. if (className) {
  3850. return this.baseIconClass + ' ' + className;
  3851. }
  3852. return '';
  3853. };
  3854. Theme.prototype.getCustomButtonIconClass = function (customButtonProps) {
  3855. var className;
  3856. if (this.iconOverrideCustomButtonOption) {
  3857. className = customButtonProps[this.iconOverrideCustomButtonOption];
  3858. if (className) {
  3859. return this.baseIconClass + ' ' + this.applyIconOverridePrefix(className);
  3860. }
  3861. }
  3862. return '';
  3863. };
  3864. return Theme;
  3865. }());
  3866. Theme.prototype.classes = {};
  3867. Theme.prototype.iconClasses = {};
  3868. Theme.prototype.baseIconClass = '';
  3869. Theme.prototype.iconOverridePrefix = '';
  3870. var guid = 0;
  3871. var ComponentContext = /** @class */ (function () {
  3872. function ComponentContext(calendar, theme, dateEnv, options, view) {
  3873. this.calendar = calendar;
  3874. this.theme = theme;
  3875. this.dateEnv = dateEnv;
  3876. this.options = options;
  3877. this.view = view;
  3878. this.isRtl = options.dir === 'rtl';
  3879. this.eventOrderSpecs = parseFieldSpecs(options.eventOrder);
  3880. this.nextDayThreshold = createDuration(options.nextDayThreshold);
  3881. }
  3882. ComponentContext.prototype.extend = function (options, view) {
  3883. return new ComponentContext(this.calendar, this.theme, this.dateEnv, options || this.options, view || this.view);
  3884. };
  3885. return ComponentContext;
  3886. }());
  3887. var Component = /** @class */ (function () {
  3888. function Component() {
  3889. this.uid = String(guid++);
  3890. }
  3891. Component.addEqualityFuncs = function (newFuncs) {
  3892. this.prototype.equalityFuncs = __assign({}, this.prototype.equalityFuncs, newFuncs);
  3893. };
  3894. Component.prototype.receiveProps = function (props, context) {
  3895. var oldContext = this.context;
  3896. this.context = context;
  3897. if (!oldContext) {
  3898. this.firstContext(context);
  3899. }
  3900. var _a = recycleProps(this.props || {}, props, this.equalityFuncs), anyChanges = _a.anyChanges, comboProps = _a.comboProps;
  3901. this.props = comboProps;
  3902. if (anyChanges) {
  3903. if (oldContext) {
  3904. this.beforeUpdate();
  3905. }
  3906. this.render(comboProps, context);
  3907. if (oldContext) {
  3908. this.afterUpdate();
  3909. }
  3910. }
  3911. };
  3912. Component.prototype.render = function (props, context) {
  3913. };
  3914. Component.prototype.firstContext = function (context) {
  3915. };
  3916. Component.prototype.beforeUpdate = function () {
  3917. };
  3918. Component.prototype.afterUpdate = function () {
  3919. };
  3920. // after destroy is called, this component won't ever be used again
  3921. Component.prototype.destroy = function () {
  3922. };
  3923. return Component;
  3924. }());
  3925. Component.prototype.equalityFuncs = {};
  3926. /*
  3927. Reuses old values when equal. If anything is unequal, returns newProps as-is.
  3928. Great for PureComponent, but won't be feasible with React, so just eliminate and use React's DOM diffing.
  3929. */
  3930. function recycleProps(oldProps, newProps, equalityFuncs) {
  3931. var comboProps = {}; // some old, some new
  3932. var anyChanges = false;
  3933. for (var key in newProps) {
  3934. if (key in oldProps && (oldProps[key] === newProps[key] ||
  3935. (equalityFuncs[key] && equalityFuncs[key](oldProps[key], newProps[key])))) {
  3936. // equal to old? use old prop
  3937. comboProps[key] = oldProps[key];
  3938. }
  3939. else {
  3940. comboProps[key] = newProps[key];
  3941. anyChanges = true;
  3942. }
  3943. }
  3944. for (var key in oldProps) {
  3945. if (!(key in newProps)) {
  3946. anyChanges = true;
  3947. break;
  3948. }
  3949. }
  3950. return { anyChanges: anyChanges, comboProps: comboProps };
  3951. }
  3952. /*
  3953. PURPOSES:
  3954. - hook up to fg, fill, and mirror renderers
  3955. - interface for dragging and hits
  3956. */
  3957. var DateComponent = /** @class */ (function (_super) {
  3958. __extends(DateComponent, _super);
  3959. function DateComponent(el) {
  3960. var _this = _super.call(this) || this;
  3961. _this.el = el;
  3962. return _this;
  3963. }
  3964. DateComponent.prototype.destroy = function () {
  3965. _super.prototype.destroy.call(this);
  3966. removeElement(this.el);
  3967. };
  3968. // Hit System
  3969. // -----------------------------------------------------------------------------------------------------------------
  3970. DateComponent.prototype.buildPositionCaches = function () {
  3971. };
  3972. DateComponent.prototype.queryHit = function (positionLeft, positionTop, elWidth, elHeight) {
  3973. return null; // this should be abstract
  3974. };
  3975. // Validation
  3976. // -----------------------------------------------------------------------------------------------------------------
  3977. DateComponent.prototype.isInteractionValid = function (interaction) {
  3978. var calendar = this.context.calendar;
  3979. var dateProfile = this.props.dateProfile; // HACK
  3980. var instances = interaction.mutatedEvents.instances;
  3981. if (dateProfile) { // HACK for DayTile
  3982. for (var instanceId in instances) {
  3983. if (!rangeContainsRange(dateProfile.validRange, instances[instanceId].range)) {
  3984. return false;
  3985. }
  3986. }
  3987. }
  3988. return isInteractionValid(interaction, calendar);
  3989. };
  3990. DateComponent.prototype.isDateSelectionValid = function (selection) {
  3991. var calendar = this.context.calendar;
  3992. var dateProfile = this.props.dateProfile; // HACK
  3993. if (dateProfile && // HACK for DayTile
  3994. !rangeContainsRange(dateProfile.validRange, selection.range)) {
  3995. return false;
  3996. }
  3997. return isDateSelectionValid(selection, calendar);
  3998. };
  3999. // Pointer Interaction Utils
  4000. // -----------------------------------------------------------------------------------------------------------------
  4001. DateComponent.prototype.isValidSegDownEl = function (el) {
  4002. return !this.props.eventDrag && // HACK
  4003. !this.props.eventResize && // HACK
  4004. !elementClosest(el, '.fc-mirror') &&
  4005. (this.isPopover() || !this.isInPopover(el));
  4006. // ^above line ensures we don't detect a seg interaction within a nested component.
  4007. // it's a HACK because it only supports a popover as the nested component.
  4008. };
  4009. DateComponent.prototype.isValidDateDownEl = function (el) {
  4010. var segEl = elementClosest(el, this.fgSegSelector);
  4011. return (!segEl || segEl.classList.contains('fc-mirror')) &&
  4012. !elementClosest(el, '.fc-more') && // a "more.." link
  4013. !elementClosest(el, 'a[data-goto]') && // a clickable nav link
  4014. !this.isInPopover(el);
  4015. };
  4016. DateComponent.prototype.isPopover = function () {
  4017. return this.el.classList.contains('fc-popover');
  4018. };
  4019. DateComponent.prototype.isInPopover = function (el) {
  4020. return Boolean(elementClosest(el, '.fc-popover'));
  4021. };
  4022. return DateComponent;
  4023. }(Component));
  4024. DateComponent.prototype.fgSegSelector = '.fc-event-container > *';
  4025. DateComponent.prototype.bgSegSelector = '.fc-bgevent:not(.fc-nonbusiness)';
  4026. var uid$1 = 0;
  4027. function createPlugin(input) {
  4028. return {
  4029. id: String(uid$1++),
  4030. deps: input.deps || [],
  4031. reducers: input.reducers || [],
  4032. eventDefParsers: input.eventDefParsers || [],
  4033. isDraggableTransformers: input.isDraggableTransformers || [],
  4034. eventDragMutationMassagers: input.eventDragMutationMassagers || [],
  4035. eventDefMutationAppliers: input.eventDefMutationAppliers || [],
  4036. dateSelectionTransformers: input.dateSelectionTransformers || [],
  4037. datePointTransforms: input.datePointTransforms || [],
  4038. dateSpanTransforms: input.dateSpanTransforms || [],
  4039. views: input.views || {},
  4040. viewPropsTransformers: input.viewPropsTransformers || [],
  4041. isPropsValid: input.isPropsValid || null,
  4042. externalDefTransforms: input.externalDefTransforms || [],
  4043. eventResizeJoinTransforms: input.eventResizeJoinTransforms || [],
  4044. viewContainerModifiers: input.viewContainerModifiers || [],
  4045. eventDropTransformers: input.eventDropTransformers || [],
  4046. componentInteractions: input.componentInteractions || [],
  4047. calendarInteractions: input.calendarInteractions || [],
  4048. themeClasses: input.themeClasses || {},
  4049. eventSourceDefs: input.eventSourceDefs || [],
  4050. cmdFormatter: input.cmdFormatter,
  4051. recurringTypes: input.recurringTypes || [],
  4052. namedTimeZonedImpl: input.namedTimeZonedImpl,
  4053. defaultView: input.defaultView || '',
  4054. elementDraggingImpl: input.elementDraggingImpl,
  4055. optionChangeHandlers: input.optionChangeHandlers || {}
  4056. };
  4057. }
  4058. var PluginSystem = /** @class */ (function () {
  4059. function PluginSystem() {
  4060. this.hooks = {
  4061. reducers: [],
  4062. eventDefParsers: [],
  4063. isDraggableTransformers: [],
  4064. eventDragMutationMassagers: [],
  4065. eventDefMutationAppliers: [],
  4066. dateSelectionTransformers: [],
  4067. datePointTransforms: [],
  4068. dateSpanTransforms: [],
  4069. views: {},
  4070. viewPropsTransformers: [],
  4071. isPropsValid: null,
  4072. externalDefTransforms: [],
  4073. eventResizeJoinTransforms: [],
  4074. viewContainerModifiers: [],
  4075. eventDropTransformers: [],
  4076. componentInteractions: [],
  4077. calendarInteractions: [],
  4078. themeClasses: {},
  4079. eventSourceDefs: [],
  4080. cmdFormatter: null,
  4081. recurringTypes: [],
  4082. namedTimeZonedImpl: null,
  4083. defaultView: '',
  4084. elementDraggingImpl: null,
  4085. optionChangeHandlers: {}
  4086. };
  4087. this.addedHash = {};
  4088. }
  4089. PluginSystem.prototype.add = function (plugin) {
  4090. if (!this.addedHash[plugin.id]) {
  4091. this.addedHash[plugin.id] = true;
  4092. for (var _i = 0, _a = plugin.deps; _i < _a.length; _i++) {
  4093. var dep = _a[_i];
  4094. this.add(dep);
  4095. }
  4096. this.hooks = combineHooks(this.hooks, plugin);
  4097. }
  4098. };
  4099. return PluginSystem;
  4100. }());
  4101. function combineHooks(hooks0, hooks1) {
  4102. return {
  4103. reducers: hooks0.reducers.concat(hooks1.reducers),
  4104. eventDefParsers: hooks0.eventDefParsers.concat(hooks1.eventDefParsers),
  4105. isDraggableTransformers: hooks0.isDraggableTransformers.concat(hooks1.isDraggableTransformers),
  4106. eventDragMutationMassagers: hooks0.eventDragMutationMassagers.concat(hooks1.eventDragMutationMassagers),
  4107. eventDefMutationAppliers: hooks0.eventDefMutationAppliers.concat(hooks1.eventDefMutationAppliers),
  4108. dateSelectionTransformers: hooks0.dateSelectionTransformers.concat(hooks1.dateSelectionTransformers),
  4109. datePointTransforms: hooks0.datePointTransforms.concat(hooks1.datePointTransforms),
  4110. dateSpanTransforms: hooks0.dateSpanTransforms.concat(hooks1.dateSpanTransforms),
  4111. views: __assign({}, hooks0.views, hooks1.views),
  4112. viewPropsTransformers: hooks0.viewPropsTransformers.concat(hooks1.viewPropsTransformers),
  4113. isPropsValid: hooks1.isPropsValid || hooks0.isPropsValid,
  4114. externalDefTransforms: hooks0.externalDefTransforms.concat(hooks1.externalDefTransforms),
  4115. eventResizeJoinTransforms: hooks0.eventResizeJoinTransforms.concat(hooks1.eventResizeJoinTransforms),
  4116. viewContainerModifiers: hooks0.viewContainerModifiers.concat(hooks1.viewContainerModifiers),
  4117. eventDropTransformers: hooks0.eventDropTransformers.concat(hooks1.eventDropTransformers),
  4118. calendarInteractions: hooks0.calendarInteractions.concat(hooks1.calendarInteractions),
  4119. componentInteractions: hooks0.componentInteractions.concat(hooks1.componentInteractions),
  4120. themeClasses: __assign({}, hooks0.themeClasses, hooks1.themeClasses),
  4121. eventSourceDefs: hooks0.eventSourceDefs.concat(hooks1.eventSourceDefs),
  4122. cmdFormatter: hooks1.cmdFormatter || hooks0.cmdFormatter,
  4123. recurringTypes: hooks0.recurringTypes.concat(hooks1.recurringTypes),
  4124. namedTimeZonedImpl: hooks1.namedTimeZonedImpl || hooks0.namedTimeZonedImpl,
  4125. defaultView: hooks0.defaultView || hooks1.defaultView,
  4126. elementDraggingImpl: hooks0.elementDraggingImpl || hooks1.elementDraggingImpl,
  4127. optionChangeHandlers: __assign({}, hooks0.optionChangeHandlers, hooks1.optionChangeHandlers)
  4128. };
  4129. }
  4130. var eventSourceDef = {
  4131. ignoreRange: true,
  4132. parseMeta: function (raw) {
  4133. if (Array.isArray(raw)) { // short form
  4134. return raw;
  4135. }
  4136. else if (Array.isArray(raw.events)) {
  4137. return raw.events;
  4138. }
  4139. return null;
  4140. },
  4141. fetch: function (arg, success) {
  4142. success({
  4143. rawEvents: arg.eventSource.meta
  4144. });
  4145. }
  4146. };
  4147. var ArrayEventSourcePlugin = createPlugin({
  4148. eventSourceDefs: [eventSourceDef]
  4149. });
  4150. var eventSourceDef$1 = {
  4151. parseMeta: function (raw) {
  4152. if (typeof raw === 'function') { // short form
  4153. return raw;
  4154. }
  4155. else if (typeof raw.events === 'function') {
  4156. return raw.events;
  4157. }
  4158. return null;
  4159. },
  4160. fetch: function (arg, success, failure) {
  4161. var dateEnv = arg.calendar.dateEnv;
  4162. var func = arg.eventSource.meta;
  4163. unpromisify(func.bind(null, {
  4164. start: dateEnv.toDate(arg.range.start),
  4165. end: dateEnv.toDate(arg.range.end),
  4166. startStr: dateEnv.formatIso(arg.range.start),
  4167. endStr: dateEnv.formatIso(arg.range.end),
  4168. timeZone: dateEnv.timeZone
  4169. }), function (rawEvents) {
  4170. success({ rawEvents: rawEvents }); // needs an object response
  4171. }, failure // send errorObj directly to failure callback
  4172. );
  4173. }
  4174. };
  4175. var FuncEventSourcePlugin = createPlugin({
  4176. eventSourceDefs: [eventSourceDef$1]
  4177. });
  4178. function requestJson(method, url, params, successCallback, failureCallback) {
  4179. method = method.toUpperCase();
  4180. var body = null;
  4181. if (method === 'GET') {
  4182. url = injectQueryStringParams(url, params);
  4183. }
  4184. else {
  4185. body = encodeParams(params);
  4186. }
  4187. var xhr = new XMLHttpRequest();
  4188. xhr.open(method, url, true);
  4189. if (method !== 'GET') {
  4190. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4191. }
  4192. xhr.onload = function () {
  4193. if (xhr.status >= 200 && xhr.status < 400) {
  4194. try {
  4195. var res = JSON.parse(xhr.responseText);
  4196. successCallback(res, xhr);
  4197. }
  4198. catch (err) {
  4199. failureCallback('Failure parsing JSON', xhr);
  4200. }
  4201. }
  4202. else {
  4203. failureCallback('Request failed', xhr);
  4204. }
  4205. };
  4206. xhr.onerror = function () {
  4207. failureCallback('Request failed', xhr);
  4208. };
  4209. xhr.send(body);
  4210. }
  4211. function injectQueryStringParams(url, params) {
  4212. return url +
  4213. (url.indexOf('?') === -1 ? '?' : '&') +
  4214. encodeParams(params);
  4215. }
  4216. function encodeParams(params) {
  4217. var parts = [];
  4218. for (var key in params) {
  4219. parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]));
  4220. }
  4221. return parts.join('&');
  4222. }
  4223. var eventSourceDef$2 = {
  4224. parseMeta: function (raw) {
  4225. if (typeof raw === 'string') { // short form
  4226. raw = { url: raw };
  4227. }
  4228. else if (!raw || typeof raw !== 'object' || !raw.url) {
  4229. return null;
  4230. }
  4231. return {
  4232. url: raw.url,
  4233. method: (raw.method || 'GET').toUpperCase(),
  4234. extraParams: raw.extraParams,
  4235. startParam: raw.startParam,
  4236. endParam: raw.endParam,
  4237. timeZoneParam: raw.timeZoneParam
  4238. };
  4239. },
  4240. fetch: function (arg, success, failure) {
  4241. var meta = arg.eventSource.meta;
  4242. var requestParams = buildRequestParams(meta, arg.range, arg.calendar);
  4243. requestJson(meta.method, meta.url, requestParams, function (rawEvents, xhr) {
  4244. success({ rawEvents: rawEvents, xhr: xhr });
  4245. }, function (errorMessage, xhr) {
  4246. failure({ message: errorMessage, xhr: xhr });
  4247. });
  4248. }
  4249. };
  4250. var JsonFeedEventSourcePlugin = createPlugin({
  4251. eventSourceDefs: [eventSourceDef$2]
  4252. });
  4253. function buildRequestParams(meta, range, calendar) {
  4254. var dateEnv = calendar.dateEnv;
  4255. var startParam;
  4256. var endParam;
  4257. var timeZoneParam;
  4258. var customRequestParams;
  4259. var params = {};
  4260. startParam = meta.startParam;
  4261. if (startParam == null) {
  4262. startParam = calendar.opt('startParam');
  4263. }
  4264. endParam = meta.endParam;
  4265. if (endParam == null) {
  4266. endParam = calendar.opt('endParam');
  4267. }
  4268. timeZoneParam = meta.timeZoneParam;
  4269. if (timeZoneParam == null) {
  4270. timeZoneParam = calendar.opt('timeZoneParam');
  4271. }
  4272. // retrieve any outbound GET/POST data from the options
  4273. if (typeof meta.extraParams === 'function') {
  4274. // supplied as a function that returns a key/value object
  4275. customRequestParams = meta.extraParams();
  4276. }
  4277. else {
  4278. // probably supplied as a straight key/value object
  4279. customRequestParams = meta.extraParams || {};
  4280. }
  4281. __assign(params, customRequestParams);
  4282. params[startParam] = dateEnv.formatIso(range.start);
  4283. params[endParam] = dateEnv.formatIso(range.end);
  4284. if (dateEnv.timeZone !== 'local') {
  4285. params[timeZoneParam] = dateEnv.timeZone;
  4286. }
  4287. return params;
  4288. }
  4289. var recurring = {
  4290. parse: function (rawEvent, leftoverProps, dateEnv) {
  4291. var createMarker = dateEnv.createMarker.bind(dateEnv);
  4292. var processors = {
  4293. daysOfWeek: null,
  4294. startTime: createDuration,
  4295. endTime: createDuration,
  4296. startRecur: createMarker,
  4297. endRecur: createMarker
  4298. };
  4299. var props = refineProps(rawEvent, processors, {}, leftoverProps);
  4300. var anyValid = false;
  4301. for (var propName in props) {
  4302. if (props[propName] != null) {
  4303. anyValid = true;
  4304. break;
  4305. }
  4306. }
  4307. if (anyValid) {
  4308. var duration = null;
  4309. if ('duration' in leftoverProps) {
  4310. duration = createDuration(leftoverProps.duration);
  4311. delete leftoverProps.duration;
  4312. }
  4313. if (!duration && props.startTime && props.endTime) {
  4314. duration = subtractDurations(props.endTime, props.startTime);
  4315. }
  4316. return {
  4317. allDayGuess: Boolean(!props.startTime && !props.endTime),
  4318. duration: duration,
  4319. typeData: props // doesn't need endTime anymore but oh well
  4320. };
  4321. }
  4322. return null;
  4323. },
  4324. expand: function (typeData, framingRange, dateEnv) {
  4325. var clippedFramingRange = intersectRanges(framingRange, { start: typeData.startRecur, end: typeData.endRecur });
  4326. if (clippedFramingRange) {
  4327. return expandRanges(typeData.daysOfWeek, typeData.startTime, clippedFramingRange, dateEnv);
  4328. }
  4329. else {
  4330. return [];
  4331. }
  4332. }
  4333. };
  4334. var SimpleRecurrencePlugin = createPlugin({
  4335. recurringTypes: [recurring]
  4336. });
  4337. function expandRanges(daysOfWeek, startTime, framingRange, dateEnv) {
  4338. var dowHash = daysOfWeek ? arrayToHash(daysOfWeek) : null;
  4339. var dayMarker = startOfDay(framingRange.start);
  4340. var endMarker = framingRange.end;
  4341. var instanceStarts = [];
  4342. while (dayMarker < endMarker) {
  4343. var instanceStart
  4344. // if everyday, or this particular day-of-week
  4345. = void 0;
  4346. // if everyday, or this particular day-of-week
  4347. if (!dowHash || dowHash[dayMarker.getUTCDay()]) {
  4348. if (startTime) {
  4349. instanceStart = dateEnv.add(dayMarker, startTime);
  4350. }
  4351. else {
  4352. instanceStart = dayMarker;
  4353. }
  4354. instanceStarts.push(instanceStart);
  4355. }
  4356. dayMarker = addDays(dayMarker, 1);
  4357. }
  4358. return instanceStarts;
  4359. }
  4360. var DefaultOptionChangeHandlers = createPlugin({
  4361. optionChangeHandlers: {
  4362. events: function (events, calendar, deepEqual) {
  4363. handleEventSources([events], calendar, deepEqual);
  4364. },
  4365. eventSources: handleEventSources,
  4366. plugins: handlePlugins
  4367. }
  4368. });
  4369. function handleEventSources(inputs, calendar, deepEqual) {
  4370. var unfoundSources = hashValuesToArray(calendar.state.eventSources);
  4371. var newInputs = [];
  4372. for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {
  4373. var input = inputs_1[_i];
  4374. var inputFound = false;
  4375. for (var i = 0; i < unfoundSources.length; i++) {
  4376. if (deepEqual(unfoundSources[i]._raw, input)) {
  4377. unfoundSources.splice(i, 1); // delete
  4378. inputFound = true;
  4379. break;
  4380. }
  4381. }
  4382. if (!inputFound) {
  4383. newInputs.push(input);
  4384. }
  4385. }
  4386. for (var _a = 0, unfoundSources_1 = unfoundSources; _a < unfoundSources_1.length; _a++) {
  4387. var unfoundSource = unfoundSources_1[_a];
  4388. calendar.dispatch({
  4389. type: 'REMOVE_EVENT_SOURCE',
  4390. sourceId: unfoundSource.sourceId
  4391. });
  4392. }
  4393. for (var _b = 0, newInputs_1 = newInputs; _b < newInputs_1.length; _b++) {
  4394. var newInput = newInputs_1[_b];
  4395. calendar.addEventSource(newInput);
  4396. }
  4397. }
  4398. // shortcoming: won't remove plugins
  4399. function handlePlugins(inputs, calendar) {
  4400. calendar.addPluginInputs(inputs); // will gracefully handle duplicates
  4401. }
  4402. var config = {}; // TODO: make these options
  4403. var globalDefaults = {
  4404. defaultRangeSeparator: ' - ',
  4405. titleRangeSeparator: ' \u2013 ',
  4406. defaultTimedEventDuration: '01:00:00',
  4407. defaultAllDayEventDuration: { day: 1 },
  4408. forceEventDuration: false,
  4409. nextDayThreshold: '00:00:00',
  4410. // display
  4411. columnHeader: true,
  4412. defaultView: '',
  4413. aspectRatio: 1.35,
  4414. header: {
  4415. left: 'title',
  4416. center: '',
  4417. right: 'today prev,next'
  4418. },
  4419. weekends: true,
  4420. weekNumbers: false,
  4421. weekNumberCalculation: 'local',
  4422. editable: false,
  4423. // nowIndicator: false,
  4424. scrollTime: '06:00:00',
  4425. minTime: '00:00:00',
  4426. maxTime: '24:00:00',
  4427. showNonCurrentDates: true,
  4428. // event ajax
  4429. lazyFetching: true,
  4430. startParam: 'start',
  4431. endParam: 'end',
  4432. timeZoneParam: 'timeZone',
  4433. timeZone: 'local',
  4434. // allDayDefault: undefined,
  4435. // locale
  4436. locales: [],
  4437. locale: '',
  4438. // dir: will get this from the default locale
  4439. // buttonIcons: null,
  4440. // allows setting a min-height to the event segment to prevent short events overlapping each other
  4441. timeGridEventMinHeight: 0,
  4442. themeSystem: 'standard',
  4443. // eventResizableFromStart: false,
  4444. dragRevertDuration: 500,
  4445. dragScroll: true,
  4446. allDayMaintainDuration: false,
  4447. // selectable: false,
  4448. unselectAuto: true,
  4449. // selectMinDistance: 0,
  4450. dropAccept: '*',
  4451. eventOrder: 'start,-duration,allDay,title',
  4452. // ^ if start tie, longer events go before shorter. final tie-breaker is title text
  4453. // rerenderDelay: null,
  4454. eventLimit: false,
  4455. eventLimitClick: 'popover',
  4456. dayPopoverFormat: { month: 'long', day: 'numeric', year: 'numeric' },
  4457. handleWindowResize: true,
  4458. windowResizeDelay: 100,
  4459. longPressDelay: 1000,
  4460. eventDragMinDistance: 5 // only applies to mouse
  4461. };
  4462. var rtlDefaults = {
  4463. header: {
  4464. left: 'next,prev today',
  4465. center: '',
  4466. right: 'title'
  4467. },
  4468. buttonIcons: {
  4469. // TODO: make RTL support the responibility of the theme
  4470. prev: 'fc-icon-chevron-right',
  4471. next: 'fc-icon-chevron-left',
  4472. prevYear: 'fc-icon-chevrons-right',
  4473. nextYear: 'fc-icon-chevrons-left'
  4474. }
  4475. };
  4476. var complexOptions = [
  4477. 'header',
  4478. 'footer',
  4479. 'buttonText',
  4480. 'buttonIcons'
  4481. ];
  4482. // Merges an array of option objects into a single object
  4483. function mergeOptions(optionObjs) {
  4484. return mergeProps(optionObjs, complexOptions);
  4485. }
  4486. // TODO: move this stuff to a "plugin"-related file...
  4487. var INTERNAL_PLUGINS = [
  4488. ArrayEventSourcePlugin,
  4489. FuncEventSourcePlugin,
  4490. JsonFeedEventSourcePlugin,
  4491. SimpleRecurrencePlugin,
  4492. DefaultOptionChangeHandlers
  4493. ];
  4494. function refinePluginDefs(pluginInputs) {
  4495. var plugins = [];
  4496. for (var _i = 0, pluginInputs_1 = pluginInputs; _i < pluginInputs_1.length; _i++) {
  4497. var pluginInput = pluginInputs_1[_i];
  4498. if (typeof pluginInput === 'string') {
  4499. var globalName = 'FullCalendar' + capitaliseFirstLetter(pluginInput);
  4500. if (!window[globalName]) {
  4501. console.warn('Plugin file not loaded for ' + pluginInput);
  4502. }
  4503. else {
  4504. plugins.push(window[globalName].default); // is an ES6 module
  4505. }
  4506. }
  4507. else {
  4508. plugins.push(pluginInput);
  4509. }
  4510. }
  4511. return INTERNAL_PLUGINS.concat(plugins);
  4512. }
  4513. var RAW_EN_LOCALE = {
  4514. code: 'en',
  4515. week: {
  4516. dow: 0,
  4517. doy: 4 // 4 days need to be within the year to be considered the first week
  4518. },
  4519. dir: 'ltr',
  4520. buttonText: {
  4521. prev: 'prev',
  4522. next: 'next',
  4523. prevYear: 'prev year',
  4524. nextYear: 'next year',
  4525. year: 'year',
  4526. today: 'today',
  4527. month: 'month',
  4528. week: 'week',
  4529. day: 'day',
  4530. list: 'list'
  4531. },
  4532. weekLabel: 'W',
  4533. allDayText: 'all-day',
  4534. eventLimitText: 'more',
  4535. noEventsMessage: 'No events to display'
  4536. };
  4537. function parseRawLocales(explicitRawLocales) {
  4538. var defaultCode = explicitRawLocales.length > 0 ? explicitRawLocales[0].code : 'en';
  4539. var globalArray = window['FullCalendarLocalesAll'] || []; // from locales-all.js
  4540. var globalObject = window['FullCalendarLocales'] || {}; // from locales/*.js. keys are meaningless
  4541. var allRawLocales = globalArray.concat(// globalArray is low prio
  4542. hashValuesToArray(globalObject), // medium prio
  4543. explicitRawLocales // highest prio
  4544. );
  4545. var rawLocaleMap = {
  4546. en: RAW_EN_LOCALE // necessary?
  4547. };
  4548. for (var _i = 0, allRawLocales_1 = allRawLocales; _i < allRawLocales_1.length; _i++) {
  4549. var rawLocale = allRawLocales_1[_i];
  4550. rawLocaleMap[rawLocale.code] = rawLocale;
  4551. }
  4552. return {
  4553. map: rawLocaleMap,
  4554. defaultCode: defaultCode
  4555. };
  4556. }
  4557. function buildLocale(inputSingular, available) {
  4558. if (typeof inputSingular === 'object' && !Array.isArray(inputSingular)) {
  4559. return parseLocale(inputSingular.code, [inputSingular.code], inputSingular);
  4560. }
  4561. else {
  4562. return queryLocale(inputSingular, available);
  4563. }
  4564. }
  4565. function queryLocale(codeArg, available) {
  4566. var codes = [].concat(codeArg || []); // will convert to array
  4567. var raw = queryRawLocale(codes, available) || RAW_EN_LOCALE;
  4568. return parseLocale(codeArg, codes, raw);
  4569. }
  4570. function queryRawLocale(codes, available) {
  4571. for (var i = 0; i < codes.length; i++) {
  4572. var parts = codes[i].toLocaleLowerCase().split('-');
  4573. for (var j = parts.length; j > 0; j--) {
  4574. var simpleId = parts.slice(0, j).join('-');
  4575. if (available[simpleId]) {
  4576. return available[simpleId];
  4577. }
  4578. }
  4579. }
  4580. return null;
  4581. }
  4582. function parseLocale(codeArg, codes, raw) {
  4583. var merged = mergeProps([RAW_EN_LOCALE, raw], ['buttonText']);
  4584. delete merged.code; // don't want this part of the options
  4585. var week = merged.week;
  4586. delete merged.week;
  4587. return {
  4588. codeArg: codeArg,
  4589. codes: codes,
  4590. week: week,
  4591. simpleNumberFormat: new Intl.NumberFormat(codeArg),
  4592. options: merged
  4593. };
  4594. }
  4595. var OptionsManager = /** @class */ (function () {
  4596. function OptionsManager(overrides) {
  4597. this.overrides = __assign({}, overrides); // make a copy
  4598. this.dynamicOverrides = {};
  4599. this.compute();
  4600. }
  4601. OptionsManager.prototype.mutate = function (updates, removals, isDynamic) {
  4602. if (!Object.keys(updates).length && !removals.length) {
  4603. return;
  4604. }
  4605. var overrideHash = isDynamic ? this.dynamicOverrides : this.overrides;
  4606. __assign(overrideHash, updates);
  4607. for (var _i = 0, removals_1 = removals; _i < removals_1.length; _i++) {
  4608. var propName = removals_1[_i];
  4609. delete overrideHash[propName];
  4610. }
  4611. this.compute();
  4612. };
  4613. // Computes the flattened options hash for the calendar and assigns to `this.options`.
  4614. // Assumes this.overrides and this.dynamicOverrides have already been initialized.
  4615. OptionsManager.prototype.compute = function () {
  4616. // TODO: not a very efficient system
  4617. var locales = firstDefined(// explicit locale option given?
  4618. this.dynamicOverrides.locales, this.overrides.locales, globalDefaults.locales);
  4619. var locale = firstDefined(// explicit locales option given?
  4620. this.dynamicOverrides.locale, this.overrides.locale, globalDefaults.locale);
  4621. var available = parseRawLocales(locales);
  4622. var localeDefaults = buildLocale(locale || available.defaultCode, available.map).options;
  4623. var dir = firstDefined(// based on options computed so far, is direction RTL?
  4624. this.dynamicOverrides.dir, this.overrides.dir, localeDefaults.dir);
  4625. var dirDefaults = dir === 'rtl' ? rtlDefaults : {};
  4626. this.dirDefaults = dirDefaults;
  4627. this.localeDefaults = localeDefaults;
  4628. this.computed = mergeOptions([
  4629. globalDefaults,
  4630. dirDefaults,
  4631. localeDefaults,
  4632. this.overrides,
  4633. this.dynamicOverrides
  4634. ]);
  4635. };
  4636. return OptionsManager;
  4637. }());
  4638. var calendarSystemClassMap = {};
  4639. function registerCalendarSystem(name, theClass) {
  4640. calendarSystemClassMap[name] = theClass;
  4641. }
  4642. function createCalendarSystem(name) {
  4643. return new calendarSystemClassMap[name]();
  4644. }
  4645. var GregorianCalendarSystem = /** @class */ (function () {
  4646. function GregorianCalendarSystem() {
  4647. }
  4648. GregorianCalendarSystem.prototype.getMarkerYear = function (d) {
  4649. return d.getUTCFullYear();
  4650. };
  4651. GregorianCalendarSystem.prototype.getMarkerMonth = function (d) {
  4652. return d.getUTCMonth();
  4653. };
  4654. GregorianCalendarSystem.prototype.getMarkerDay = function (d) {
  4655. return d.getUTCDate();
  4656. };
  4657. GregorianCalendarSystem.prototype.arrayToMarker = function (arr) {
  4658. return arrayToUtcDate(arr);
  4659. };
  4660. GregorianCalendarSystem.prototype.markerToArray = function (marker) {
  4661. return dateToUtcArray(marker);
  4662. };
  4663. return GregorianCalendarSystem;
  4664. }());
  4665. registerCalendarSystem('gregory', GregorianCalendarSystem);
  4666. var ISO_RE = /^\s*(\d{4})(-(\d{2})(-(\d{2})([T ](\d{2}):(\d{2})(:(\d{2})(\.(\d+))?)?(Z|(([-+])(\d{2})(:?(\d{2}))?))?)?)?)?$/;
  4667. function parse(str) {
  4668. var m = ISO_RE.exec(str);
  4669. if (m) {
  4670. var marker = new Date(Date.UTC(Number(m[1]), m[3] ? Number(m[3]) - 1 : 0, Number(m[5] || 1), Number(m[7] || 0), Number(m[8] || 0), Number(m[10] || 0), m[12] ? Number('0.' + m[12]) * 1000 : 0));
  4671. if (isValidDate(marker)) {
  4672. var timeZoneOffset = null;
  4673. if (m[13]) {
  4674. timeZoneOffset = (m[15] === '-' ? -1 : 1) * (Number(m[16] || 0) * 60 +
  4675. Number(m[18] || 0));
  4676. }
  4677. return {
  4678. marker: marker,
  4679. isTimeUnspecified: !m[6],
  4680. timeZoneOffset: timeZoneOffset
  4681. };
  4682. }
  4683. }
  4684. return null;
  4685. }
  4686. var DateEnv = /** @class */ (function () {
  4687. function DateEnv(settings) {
  4688. var timeZone = this.timeZone = settings.timeZone;
  4689. var isNamedTimeZone = timeZone !== 'local' && timeZone !== 'UTC';
  4690. if (settings.namedTimeZoneImpl && isNamedTimeZone) {
  4691. this.namedTimeZoneImpl = new settings.namedTimeZoneImpl(timeZone);
  4692. }
  4693. this.canComputeOffset = Boolean(!isNamedTimeZone || this.namedTimeZoneImpl);
  4694. this.calendarSystem = createCalendarSystem(settings.calendarSystem);
  4695. this.locale = settings.locale;
  4696. this.weekDow = settings.locale.week.dow;
  4697. this.weekDoy = settings.locale.week.doy;
  4698. if (settings.weekNumberCalculation === 'ISO') {
  4699. this.weekDow = 1;
  4700. this.weekDoy = 4;
  4701. }
  4702. if (typeof settings.firstDay === 'number') {
  4703. this.weekDow = settings.firstDay;
  4704. }
  4705. if (typeof settings.weekNumberCalculation === 'function') {
  4706. this.weekNumberFunc = settings.weekNumberCalculation;
  4707. }
  4708. this.weekLabel = settings.weekLabel != null ? settings.weekLabel : settings.locale.options.weekLabel;
  4709. this.cmdFormatter = settings.cmdFormatter;
  4710. }
  4711. // Creating / Parsing
  4712. DateEnv.prototype.createMarker = function (input) {
  4713. var meta = this.createMarkerMeta(input);
  4714. if (meta === null) {
  4715. return null;
  4716. }
  4717. return meta.marker;
  4718. };
  4719. DateEnv.prototype.createNowMarker = function () {
  4720. if (this.canComputeOffset) {
  4721. return this.timestampToMarker(new Date().valueOf());
  4722. }
  4723. else {
  4724. // if we can't compute the current date val for a timezone,
  4725. // better to give the current local date vals than UTC
  4726. return arrayToUtcDate(dateToLocalArray(new Date()));
  4727. }
  4728. };
  4729. DateEnv.prototype.createMarkerMeta = function (input) {
  4730. if (typeof input === 'string') {
  4731. return this.parse(input);
  4732. }
  4733. var marker = null;
  4734. if (typeof input === 'number') {
  4735. marker = this.timestampToMarker(input);
  4736. }
  4737. else if (input instanceof Date) {
  4738. input = input.valueOf();
  4739. if (!isNaN(input)) {
  4740. marker = this.timestampToMarker(input);
  4741. }
  4742. }
  4743. else if (Array.isArray(input)) {
  4744. marker = arrayToUtcDate(input);
  4745. }
  4746. if (marker === null || !isValidDate(marker)) {
  4747. return null;
  4748. }
  4749. return { marker: marker, isTimeUnspecified: false, forcedTzo: null };
  4750. };
  4751. DateEnv.prototype.parse = function (s) {
  4752. var parts = parse(s);
  4753. if (parts === null) {
  4754. return null;
  4755. }
  4756. var marker = parts.marker;
  4757. var forcedTzo = null;
  4758. if (parts.timeZoneOffset !== null) {
  4759. if (this.canComputeOffset) {
  4760. marker = this.timestampToMarker(marker.valueOf() - parts.timeZoneOffset * 60 * 1000);
  4761. }
  4762. else {
  4763. forcedTzo = parts.timeZoneOffset;
  4764. }
  4765. }
  4766. return { marker: marker, isTimeUnspecified: parts.isTimeUnspecified, forcedTzo: forcedTzo };
  4767. };
  4768. // Accessors
  4769. DateEnv.prototype.getYear = function (marker) {
  4770. return this.calendarSystem.getMarkerYear(marker);
  4771. };
  4772. DateEnv.prototype.getMonth = function (marker) {
  4773. return this.calendarSystem.getMarkerMonth(marker);
  4774. };
  4775. // Adding / Subtracting
  4776. DateEnv.prototype.add = function (marker, dur) {
  4777. var a = this.calendarSystem.markerToArray(marker);
  4778. a[0] += dur.years;
  4779. a[1] += dur.months;
  4780. a[2] += dur.days;
  4781. a[6] += dur.milliseconds;
  4782. return this.calendarSystem.arrayToMarker(a);
  4783. };
  4784. DateEnv.prototype.subtract = function (marker, dur) {
  4785. var a = this.calendarSystem.markerToArray(marker);
  4786. a[0] -= dur.years;
  4787. a[1] -= dur.months;
  4788. a[2] -= dur.days;
  4789. a[6] -= dur.milliseconds;
  4790. return this.calendarSystem.arrayToMarker(a);
  4791. };
  4792. DateEnv.prototype.addYears = function (marker, n) {
  4793. var a = this.calendarSystem.markerToArray(marker);
  4794. a[0] += n;
  4795. return this.calendarSystem.arrayToMarker(a);
  4796. };
  4797. DateEnv.prototype.addMonths = function (marker, n) {
  4798. var a = this.calendarSystem.markerToArray(marker);
  4799. a[1] += n;
  4800. return this.calendarSystem.arrayToMarker(a);
  4801. };
  4802. // Diffing Whole Units
  4803. DateEnv.prototype.diffWholeYears = function (m0, m1) {
  4804. var calendarSystem = this.calendarSystem;
  4805. if (timeAsMs(m0) === timeAsMs(m1) &&
  4806. calendarSystem.getMarkerDay(m0) === calendarSystem.getMarkerDay(m1) &&
  4807. calendarSystem.getMarkerMonth(m0) === calendarSystem.getMarkerMonth(m1)) {
  4808. return calendarSystem.getMarkerYear(m1) - calendarSystem.getMarkerYear(m0);
  4809. }
  4810. return null;
  4811. };
  4812. DateEnv.prototype.diffWholeMonths = function (m0, m1) {
  4813. var calendarSystem = this.calendarSystem;
  4814. if (timeAsMs(m0) === timeAsMs(m1) &&
  4815. calendarSystem.getMarkerDay(m0) === calendarSystem.getMarkerDay(m1)) {
  4816. return (calendarSystem.getMarkerMonth(m1) - calendarSystem.getMarkerMonth(m0)) +
  4817. (calendarSystem.getMarkerYear(m1) - calendarSystem.getMarkerYear(m0)) * 12;
  4818. }
  4819. return null;
  4820. };
  4821. // Range / Duration
  4822. DateEnv.prototype.greatestWholeUnit = function (m0, m1) {
  4823. var n = this.diffWholeYears(m0, m1);
  4824. if (n !== null) {
  4825. return { unit: 'year', value: n };
  4826. }
  4827. n = this.diffWholeMonths(m0, m1);
  4828. if (n !== null) {
  4829. return { unit: 'month', value: n };
  4830. }
  4831. n = diffWholeWeeks(m0, m1);
  4832. if (n !== null) {
  4833. return { unit: 'week', value: n };
  4834. }
  4835. n = diffWholeDays(m0, m1);
  4836. if (n !== null) {
  4837. return { unit: 'day', value: n };
  4838. }
  4839. n = diffHours(m0, m1);
  4840. if (isInt(n)) {
  4841. return { unit: 'hour', value: n };
  4842. }
  4843. n = diffMinutes(m0, m1);
  4844. if (isInt(n)) {
  4845. return { unit: 'minute', value: n };
  4846. }
  4847. n = diffSeconds(m0, m1);
  4848. if (isInt(n)) {
  4849. return { unit: 'second', value: n };
  4850. }
  4851. return { unit: 'millisecond', value: m1.valueOf() - m0.valueOf() };
  4852. };
  4853. DateEnv.prototype.countDurationsBetween = function (m0, m1, d) {
  4854. // TODO: can use greatestWholeUnit
  4855. var diff;
  4856. if (d.years) {
  4857. diff = this.diffWholeYears(m0, m1);
  4858. if (diff !== null) {
  4859. return diff / asRoughYears(d);
  4860. }
  4861. }
  4862. if (d.months) {
  4863. diff = this.diffWholeMonths(m0, m1);
  4864. if (diff !== null) {
  4865. return diff / asRoughMonths(d);
  4866. }
  4867. }
  4868. if (d.days) {
  4869. diff = diffWholeDays(m0, m1);
  4870. if (diff !== null) {
  4871. return diff / asRoughDays(d);
  4872. }
  4873. }
  4874. return (m1.valueOf() - m0.valueOf()) / asRoughMs(d);
  4875. };
  4876. // Start-Of
  4877. DateEnv.prototype.startOf = function (m, unit) {
  4878. if (unit === 'year') {
  4879. return this.startOfYear(m);
  4880. }
  4881. else if (unit === 'month') {
  4882. return this.startOfMonth(m);
  4883. }
  4884. else if (unit === 'week') {
  4885. return this.startOfWeek(m);
  4886. }
  4887. else if (unit === 'day') {
  4888. return startOfDay(m);
  4889. }
  4890. else if (unit === 'hour') {
  4891. return startOfHour(m);
  4892. }
  4893. else if (unit === 'minute') {
  4894. return startOfMinute(m);
  4895. }
  4896. else if (unit === 'second') {
  4897. return startOfSecond(m);
  4898. }
  4899. };
  4900. DateEnv.prototype.startOfYear = function (m) {
  4901. return this.calendarSystem.arrayToMarker([
  4902. this.calendarSystem.getMarkerYear(m)
  4903. ]);
  4904. };
  4905. DateEnv.prototype.startOfMonth = function (m) {
  4906. return this.calendarSystem.arrayToMarker([
  4907. this.calendarSystem.getMarkerYear(m),
  4908. this.calendarSystem.getMarkerMonth(m)
  4909. ]);
  4910. };
  4911. DateEnv.prototype.startOfWeek = function (m) {
  4912. return this.calendarSystem.arrayToMarker([
  4913. this.calendarSystem.getMarkerYear(m),
  4914. this.calendarSystem.getMarkerMonth(m),
  4915. m.getUTCDate() - ((m.getUTCDay() - this.weekDow + 7) % 7)
  4916. ]);
  4917. };
  4918. // Week Number
  4919. DateEnv.prototype.computeWeekNumber = function (marker) {
  4920. if (this.weekNumberFunc) {
  4921. return this.weekNumberFunc(this.toDate(marker));
  4922. }
  4923. else {
  4924. return weekOfYear(marker, this.weekDow, this.weekDoy);
  4925. }
  4926. };
  4927. // TODO: choke on timeZoneName: long
  4928. DateEnv.prototype.format = function (marker, formatter, dateOptions) {
  4929. if (dateOptions === void 0) { dateOptions = {}; }
  4930. return formatter.format({
  4931. marker: marker,
  4932. timeZoneOffset: dateOptions.forcedTzo != null ?
  4933. dateOptions.forcedTzo :
  4934. this.offsetForMarker(marker)
  4935. }, this);
  4936. };
  4937. DateEnv.prototype.formatRange = function (start, end, formatter, dateOptions) {
  4938. if (dateOptions === void 0) { dateOptions = {}; }
  4939. if (dateOptions.isEndExclusive) {
  4940. end = addMs(end, -1);
  4941. }
  4942. return formatter.formatRange({
  4943. marker: start,
  4944. timeZoneOffset: dateOptions.forcedStartTzo != null ?
  4945. dateOptions.forcedStartTzo :
  4946. this.offsetForMarker(start)
  4947. }, {
  4948. marker: end,
  4949. timeZoneOffset: dateOptions.forcedEndTzo != null ?
  4950. dateOptions.forcedEndTzo :
  4951. this.offsetForMarker(end)
  4952. }, this);
  4953. };
  4954. DateEnv.prototype.formatIso = function (marker, extraOptions) {
  4955. if (extraOptions === void 0) { extraOptions = {}; }
  4956. var timeZoneOffset = null;
  4957. if (!extraOptions.omitTimeZoneOffset) {
  4958. if (extraOptions.forcedTzo != null) {
  4959. timeZoneOffset = extraOptions.forcedTzo;
  4960. }
  4961. else {
  4962. timeZoneOffset = this.offsetForMarker(marker);
  4963. }
  4964. }
  4965. return buildIsoString(marker, timeZoneOffset, extraOptions.omitTime);
  4966. };
  4967. // TimeZone
  4968. DateEnv.prototype.timestampToMarker = function (ms) {
  4969. if (this.timeZone === 'local') {
  4970. return arrayToUtcDate(dateToLocalArray(new Date(ms)));
  4971. }
  4972. else if (this.timeZone === 'UTC' || !this.namedTimeZoneImpl) {
  4973. return new Date(ms);
  4974. }
  4975. else {
  4976. return arrayToUtcDate(this.namedTimeZoneImpl.timestampToArray(ms));
  4977. }
  4978. };
  4979. DateEnv.prototype.offsetForMarker = function (m) {
  4980. if (this.timeZone === 'local') {
  4981. return -arrayToLocalDate(dateToUtcArray(m)).getTimezoneOffset(); // convert "inverse" offset to "normal" offset
  4982. }
  4983. else if (this.timeZone === 'UTC') {
  4984. return 0;
  4985. }
  4986. else if (this.namedTimeZoneImpl) {
  4987. return this.namedTimeZoneImpl.offsetForArray(dateToUtcArray(m));
  4988. }
  4989. return null;
  4990. };
  4991. // Conversion
  4992. DateEnv.prototype.toDate = function (m, forcedTzo) {
  4993. if (this.timeZone === 'local') {
  4994. return arrayToLocalDate(dateToUtcArray(m));
  4995. }
  4996. else if (this.timeZone === 'UTC') {
  4997. return new Date(m.valueOf()); // make sure it's a copy
  4998. }
  4999. else if (!this.namedTimeZoneImpl) {
  5000. return new Date(m.valueOf() - (forcedTzo || 0));
  5001. }
  5002. else {
  5003. return new Date(m.valueOf() -
  5004. this.namedTimeZoneImpl.offsetForArray(dateToUtcArray(m)) * 1000 * 60 // convert minutes -> ms
  5005. );
  5006. }
  5007. };
  5008. return DateEnv;
  5009. }());
  5010. var SIMPLE_SOURCE_PROPS = {
  5011. id: String,
  5012. allDayDefault: Boolean,
  5013. eventDataTransform: Function,
  5014. success: Function,
  5015. failure: Function
  5016. };
  5017. var uid$2 = 0;
  5018. function doesSourceNeedRange(eventSource, calendar) {
  5019. var defs = calendar.pluginSystem.hooks.eventSourceDefs;
  5020. return !defs[eventSource.sourceDefId].ignoreRange;
  5021. }
  5022. function parseEventSource(raw, calendar) {
  5023. var defs = calendar.pluginSystem.hooks.eventSourceDefs;
  5024. for (var i = defs.length - 1; i >= 0; i--) { // later-added plugins take precedence
  5025. var def = defs[i];
  5026. var meta = def.parseMeta(raw);
  5027. if (meta) {
  5028. var res = parseEventSourceProps(typeof raw === 'object' ? raw : {}, meta, i, calendar);
  5029. res._raw = raw;
  5030. return res;
  5031. }
  5032. }
  5033. return null;
  5034. }
  5035. function parseEventSourceProps(raw, meta, sourceDefId, calendar) {
  5036. var leftovers0 = {};
  5037. var props = refineProps(raw, SIMPLE_SOURCE_PROPS, {}, leftovers0);
  5038. var leftovers1 = {};
  5039. var ui = processUnscopedUiProps(leftovers0, calendar, leftovers1);
  5040. props.isFetching = false;
  5041. props.latestFetchId = '';
  5042. props.fetchRange = null;
  5043. props.publicId = String(raw.id || '');
  5044. props.sourceId = String(uid$2++);
  5045. props.sourceDefId = sourceDefId;
  5046. props.meta = meta;
  5047. props.ui = ui;
  5048. props.extendedProps = leftovers1;
  5049. return props;
  5050. }
  5051. function reduceEventSources (eventSources, action, dateProfile, calendar) {
  5052. switch (action.type) {
  5053. case 'ADD_EVENT_SOURCES': // already parsed
  5054. return addSources(eventSources, action.sources, dateProfile ? dateProfile.activeRange : null, calendar);
  5055. case 'REMOVE_EVENT_SOURCE':
  5056. return removeSource(eventSources, action.sourceId);
  5057. case 'PREV': // TODO: how do we track all actions that affect dateProfile :(
  5058. case 'NEXT':
  5059. case 'SET_DATE':
  5060. case 'SET_VIEW_TYPE':
  5061. if (dateProfile) {
  5062. return fetchDirtySources(eventSources, dateProfile.activeRange, calendar);
  5063. }
  5064. else {
  5065. return eventSources;
  5066. }
  5067. case 'FETCH_EVENT_SOURCES':
  5068. case 'CHANGE_TIMEZONE':
  5069. return fetchSourcesByIds(eventSources, action.sourceIds ?
  5070. arrayToHash(action.sourceIds) :
  5071. excludeStaticSources(eventSources, calendar), dateProfile ? dateProfile.activeRange : null, calendar);
  5072. case 'RECEIVE_EVENTS':
  5073. case 'RECEIVE_EVENT_ERROR':
  5074. return receiveResponse(eventSources, action.sourceId, action.fetchId, action.fetchRange);
  5075. case 'REMOVE_ALL_EVENT_SOURCES':
  5076. return {};
  5077. default:
  5078. return eventSources;
  5079. }
  5080. }
  5081. var uid$3 = 0;
  5082. function addSources(eventSourceHash, sources, fetchRange, calendar) {
  5083. var hash = {};
  5084. for (var _i = 0, sources_1 = sources; _i < sources_1.length; _i++) {
  5085. var source = sources_1[_i];
  5086. hash[source.sourceId] = source;
  5087. }
  5088. if (fetchRange) {
  5089. hash = fetchDirtySources(hash, fetchRange, calendar);
  5090. }
  5091. return __assign({}, eventSourceHash, hash);
  5092. }
  5093. function removeSource(eventSourceHash, sourceId) {
  5094. return filterHash(eventSourceHash, function (eventSource) {
  5095. return eventSource.sourceId !== sourceId;
  5096. });
  5097. }
  5098. function fetchDirtySources(sourceHash, fetchRange, calendar) {
  5099. return fetchSourcesByIds(sourceHash, filterHash(sourceHash, function (eventSource) {
  5100. return isSourceDirty(eventSource, fetchRange, calendar);
  5101. }), fetchRange, calendar);
  5102. }
  5103. function isSourceDirty(eventSource, fetchRange, calendar) {
  5104. if (!doesSourceNeedRange(eventSource, calendar)) {
  5105. return !eventSource.latestFetchId;
  5106. }
  5107. else {
  5108. return !calendar.opt('lazyFetching') ||
  5109. !eventSource.fetchRange ||
  5110. eventSource.isFetching || // always cancel outdated in-progress fetches
  5111. fetchRange.start < eventSource.fetchRange.start ||
  5112. fetchRange.end > eventSource.fetchRange.end;
  5113. }
  5114. }
  5115. function fetchSourcesByIds(prevSources, sourceIdHash, fetchRange, calendar) {
  5116. var nextSources = {};
  5117. for (var sourceId in prevSources) {
  5118. var source = prevSources[sourceId];
  5119. if (sourceIdHash[sourceId]) {
  5120. nextSources[sourceId] = fetchSource(source, fetchRange, calendar);
  5121. }
  5122. else {
  5123. nextSources[sourceId] = source;
  5124. }
  5125. }
  5126. return nextSources;
  5127. }
  5128. function fetchSource(eventSource, fetchRange, calendar) {
  5129. var sourceDef = calendar.pluginSystem.hooks.eventSourceDefs[eventSource.sourceDefId];
  5130. var fetchId = String(uid$3++);
  5131. sourceDef.fetch({
  5132. eventSource: eventSource,
  5133. calendar: calendar,
  5134. range: fetchRange
  5135. }, function (res) {
  5136. var rawEvents = res.rawEvents;
  5137. var calSuccess = calendar.opt('eventSourceSuccess');
  5138. var calSuccessRes;
  5139. var sourceSuccessRes;
  5140. if (eventSource.success) {
  5141. sourceSuccessRes = eventSource.success(rawEvents, res.xhr);
  5142. }
  5143. if (calSuccess) {
  5144. calSuccessRes = calSuccess(rawEvents, res.xhr);
  5145. }
  5146. rawEvents = sourceSuccessRes || calSuccessRes || rawEvents;
  5147. calendar.dispatch({
  5148. type: 'RECEIVE_EVENTS',
  5149. sourceId: eventSource.sourceId,
  5150. fetchId: fetchId,
  5151. fetchRange: fetchRange,
  5152. rawEvents: rawEvents
  5153. });
  5154. }, function (error) {
  5155. var callFailure = calendar.opt('eventSourceFailure');
  5156. console.warn(error.message, error);
  5157. if (eventSource.failure) {
  5158. eventSource.failure(error);
  5159. }
  5160. if (callFailure) {
  5161. callFailure(error);
  5162. }
  5163. calendar.dispatch({
  5164. type: 'RECEIVE_EVENT_ERROR',
  5165. sourceId: eventSource.sourceId,
  5166. fetchId: fetchId,
  5167. fetchRange: fetchRange,
  5168. error: error
  5169. });
  5170. });
  5171. return __assign({}, eventSource, { isFetching: true, latestFetchId: fetchId });
  5172. }
  5173. function receiveResponse(sourceHash, sourceId, fetchId, fetchRange) {
  5174. var _a;
  5175. var eventSource = sourceHash[sourceId];
  5176. if (eventSource && // not already removed
  5177. fetchId === eventSource.latestFetchId) {
  5178. return __assign({}, sourceHash, (_a = {}, _a[sourceId] = __assign({}, eventSource, { isFetching: false, fetchRange: fetchRange // also serves as a marker that at least one fetch has completed
  5179. }), _a));
  5180. }
  5181. return sourceHash;
  5182. }
  5183. function excludeStaticSources(eventSources, calendar) {
  5184. return filterHash(eventSources, function (eventSource) {
  5185. return doesSourceNeedRange(eventSource, calendar);
  5186. });
  5187. }
  5188. var DateProfileGenerator = /** @class */ (function () {
  5189. function DateProfileGenerator(viewSpec, calendar) {
  5190. this.viewSpec = viewSpec;
  5191. this.options = viewSpec.options;
  5192. this.dateEnv = calendar.dateEnv;
  5193. this.calendar = calendar;
  5194. this.initHiddenDays();
  5195. }
  5196. /* Date Range Computation
  5197. ------------------------------------------------------------------------------------------------------------------*/
  5198. // Builds a structure with info about what the dates/ranges will be for the "prev" view.
  5199. DateProfileGenerator.prototype.buildPrev = function (currentDateProfile, currentDate) {
  5200. var dateEnv = this.dateEnv;
  5201. var prevDate = dateEnv.subtract(dateEnv.startOf(currentDate, currentDateProfile.currentRangeUnit), // important for start-of-month
  5202. currentDateProfile.dateIncrement);
  5203. return this.build(prevDate, -1);
  5204. };
  5205. // Builds a structure with info about what the dates/ranges will be for the "next" view.
  5206. DateProfileGenerator.prototype.buildNext = function (currentDateProfile, currentDate) {
  5207. var dateEnv = this.dateEnv;
  5208. var nextDate = dateEnv.add(dateEnv.startOf(currentDate, currentDateProfile.currentRangeUnit), // important for start-of-month
  5209. currentDateProfile.dateIncrement);
  5210. return this.build(nextDate, 1);
  5211. };
  5212. // Builds a structure holding dates/ranges for rendering around the given date.
  5213. // Optional direction param indicates whether the date is being incremented/decremented
  5214. // from its previous value. decremented = -1, incremented = 1 (default).
  5215. DateProfileGenerator.prototype.build = function (currentDate, direction, forceToValid) {
  5216. if (forceToValid === void 0) { forceToValid = false; }
  5217. var validRange;
  5218. var minTime = null;
  5219. var maxTime = null;
  5220. var currentInfo;
  5221. var isRangeAllDay;
  5222. var renderRange;
  5223. var activeRange;
  5224. var isValid;
  5225. validRange = this.buildValidRange();
  5226. validRange = this.trimHiddenDays(validRange);
  5227. if (forceToValid) {
  5228. currentDate = constrainMarkerToRange(currentDate, validRange);
  5229. }
  5230. currentInfo = this.buildCurrentRangeInfo(currentDate, direction);
  5231. isRangeAllDay = /^(year|month|week|day)$/.test(currentInfo.unit);
  5232. renderRange = this.buildRenderRange(this.trimHiddenDays(currentInfo.range), currentInfo.unit, isRangeAllDay);
  5233. renderRange = this.trimHiddenDays(renderRange);
  5234. activeRange = renderRange;
  5235. if (!this.options.showNonCurrentDates) {
  5236. activeRange = intersectRanges(activeRange, currentInfo.range);
  5237. }
  5238. minTime = createDuration(this.options.minTime);
  5239. maxTime = createDuration(this.options.maxTime);
  5240. activeRange = this.adjustActiveRange(activeRange, minTime, maxTime);
  5241. activeRange = intersectRanges(activeRange, validRange); // might return null
  5242. // it's invalid if the originally requested date is not contained,
  5243. // or if the range is completely outside of the valid range.
  5244. isValid = rangesIntersect(currentInfo.range, validRange);
  5245. return {
  5246. // constraint for where prev/next operations can go and where events can be dragged/resized to.
  5247. // an object with optional start and end properties.
  5248. validRange: validRange,
  5249. // range the view is formally responsible for.
  5250. // for example, a month view might have 1st-31st, excluding padded dates
  5251. currentRange: currentInfo.range,
  5252. // name of largest unit being displayed, like "month" or "week"
  5253. currentRangeUnit: currentInfo.unit,
  5254. isRangeAllDay: isRangeAllDay,
  5255. // dates that display events and accept drag-n-drop
  5256. // will be `null` if no dates accept events
  5257. activeRange: activeRange,
  5258. // date range with a rendered skeleton
  5259. // includes not-active days that need some sort of DOM
  5260. renderRange: renderRange,
  5261. // Duration object that denotes the first visible time of any given day
  5262. minTime: minTime,
  5263. // Duration object that denotes the exclusive visible end time of any given day
  5264. maxTime: maxTime,
  5265. isValid: isValid,
  5266. // how far the current date will move for a prev/next operation
  5267. dateIncrement: this.buildDateIncrement(currentInfo.duration)
  5268. // pass a fallback (might be null) ^
  5269. };
  5270. };
  5271. // Builds an object with optional start/end properties.
  5272. // Indicates the minimum/maximum dates to display.
  5273. // not responsible for trimming hidden days.
  5274. DateProfileGenerator.prototype.buildValidRange = function () {
  5275. return this.getRangeOption('validRange', this.calendar.getNow()) ||
  5276. { start: null, end: null }; // completely open-ended
  5277. };
  5278. // Builds a structure with info about the "current" range, the range that is
  5279. // highlighted as being the current month for example.
  5280. // See build() for a description of `direction`.
  5281. // Guaranteed to have `range` and `unit` properties. `duration` is optional.
  5282. DateProfileGenerator.prototype.buildCurrentRangeInfo = function (date, direction) {
  5283. var _a = this, viewSpec = _a.viewSpec, dateEnv = _a.dateEnv;
  5284. var duration = null;
  5285. var unit = null;
  5286. var range = null;
  5287. var dayCount;
  5288. if (viewSpec.duration) {
  5289. duration = viewSpec.duration;
  5290. unit = viewSpec.durationUnit;
  5291. range = this.buildRangeFromDuration(date, direction, duration, unit);
  5292. }
  5293. else if ((dayCount = this.options.dayCount)) {
  5294. unit = 'day';
  5295. range = this.buildRangeFromDayCount(date, direction, dayCount);
  5296. }
  5297. else if ((range = this.buildCustomVisibleRange(date))) {
  5298. unit = dateEnv.greatestWholeUnit(range.start, range.end).unit;
  5299. }
  5300. else {
  5301. duration = this.getFallbackDuration();
  5302. unit = greatestDurationDenominator(duration).unit;
  5303. range = this.buildRangeFromDuration(date, direction, duration, unit);
  5304. }
  5305. return { duration: duration, unit: unit, range: range };
  5306. };
  5307. DateProfileGenerator.prototype.getFallbackDuration = function () {
  5308. return createDuration({ day: 1 });
  5309. };
  5310. // Returns a new activeRange to have time values (un-ambiguate)
  5311. // minTime or maxTime causes the range to expand.
  5312. DateProfileGenerator.prototype.adjustActiveRange = function (range, minTime, maxTime) {
  5313. var dateEnv = this.dateEnv;
  5314. var start = range.start;
  5315. var end = range.end;
  5316. if (this.viewSpec.class.prototype.usesMinMaxTime) {
  5317. // expand active range if minTime is negative (why not when positive?)
  5318. if (asRoughDays(minTime) < 0) {
  5319. start = startOfDay(start); // necessary?
  5320. start = dateEnv.add(start, minTime);
  5321. }
  5322. // expand active range if maxTime is beyond one day (why not when positive?)
  5323. if (asRoughDays(maxTime) > 1) {
  5324. end = startOfDay(end); // necessary?
  5325. end = addDays(end, -1);
  5326. end = dateEnv.add(end, maxTime);
  5327. }
  5328. }
  5329. return { start: start, end: end };
  5330. };
  5331. // Builds the "current" range when it is specified as an explicit duration.
  5332. // `unit` is the already-computed greatestDurationDenominator unit of duration.
  5333. DateProfileGenerator.prototype.buildRangeFromDuration = function (date, direction, duration, unit) {
  5334. var dateEnv = this.dateEnv;
  5335. var alignment = this.options.dateAlignment;
  5336. var dateIncrementInput;
  5337. var dateIncrementDuration;
  5338. var start;
  5339. var end;
  5340. var res;
  5341. // compute what the alignment should be
  5342. if (!alignment) {
  5343. dateIncrementInput = this.options.dateIncrement;
  5344. if (dateIncrementInput) {
  5345. dateIncrementDuration = createDuration(dateIncrementInput);
  5346. // use the smaller of the two units
  5347. if (asRoughMs(dateIncrementDuration) < asRoughMs(duration)) {
  5348. alignment = greatestDurationDenominator(dateIncrementDuration, !getWeeksFromInput(dateIncrementInput)).unit;
  5349. }
  5350. else {
  5351. alignment = unit;
  5352. }
  5353. }
  5354. else {
  5355. alignment = unit;
  5356. }
  5357. }
  5358. // if the view displays a single day or smaller
  5359. if (asRoughDays(duration) <= 1) {
  5360. if (this.isHiddenDay(start)) {
  5361. start = this.skipHiddenDays(start, direction);
  5362. start = startOfDay(start);
  5363. }
  5364. }
  5365. function computeRes() {
  5366. start = dateEnv.startOf(date, alignment);
  5367. end = dateEnv.add(start, duration);
  5368. res = { start: start, end: end };
  5369. }
  5370. computeRes();
  5371. // if range is completely enveloped by hidden days, go past the hidden days
  5372. if (!this.trimHiddenDays(res)) {
  5373. date = this.skipHiddenDays(date, direction);
  5374. computeRes();
  5375. }
  5376. return res;
  5377. };
  5378. // Builds the "current" range when a dayCount is specified.
  5379. DateProfileGenerator.prototype.buildRangeFromDayCount = function (date, direction, dayCount) {
  5380. var dateEnv = this.dateEnv;
  5381. var customAlignment = this.options.dateAlignment;
  5382. var runningCount = 0;
  5383. var start = date;
  5384. var end;
  5385. if (customAlignment) {
  5386. start = dateEnv.startOf(start, customAlignment);
  5387. }
  5388. start = startOfDay(start);
  5389. start = this.skipHiddenDays(start, direction);
  5390. end = start;
  5391. do {
  5392. end = addDays(end, 1);
  5393. if (!this.isHiddenDay(end)) {
  5394. runningCount++;
  5395. }
  5396. } while (runningCount < dayCount);
  5397. return { start: start, end: end };
  5398. };
  5399. // Builds a normalized range object for the "visible" range,
  5400. // which is a way to define the currentRange and activeRange at the same time.
  5401. DateProfileGenerator.prototype.buildCustomVisibleRange = function (date) {
  5402. var dateEnv = this.dateEnv;
  5403. var visibleRange = this.getRangeOption('visibleRange', dateEnv.toDate(date));
  5404. if (visibleRange && (visibleRange.start == null || visibleRange.end == null)) {
  5405. return null;
  5406. }
  5407. return visibleRange;
  5408. };
  5409. // Computes the range that will represent the element/cells for *rendering*,
  5410. // but which may have voided days/times.
  5411. // not responsible for trimming hidden days.
  5412. DateProfileGenerator.prototype.buildRenderRange = function (currentRange, currentRangeUnit, isRangeAllDay) {
  5413. return currentRange;
  5414. };
  5415. // Compute the duration value that should be added/substracted to the current date
  5416. // when a prev/next operation happens.
  5417. DateProfileGenerator.prototype.buildDateIncrement = function (fallback) {
  5418. var dateIncrementInput = this.options.dateIncrement;
  5419. var customAlignment;
  5420. if (dateIncrementInput) {
  5421. return createDuration(dateIncrementInput);
  5422. }
  5423. else if ((customAlignment = this.options.dateAlignment)) {
  5424. return createDuration(1, customAlignment);
  5425. }
  5426. else if (fallback) {
  5427. return fallback;
  5428. }
  5429. else {
  5430. return createDuration({ days: 1 });
  5431. }
  5432. };
  5433. // Arguments after name will be forwarded to a hypothetical function value
  5434. // WARNING: passed-in arguments will be given to generator functions as-is and can cause side-effects.
  5435. // Always clone your objects if you fear mutation.
  5436. DateProfileGenerator.prototype.getRangeOption = function (name) {
  5437. var otherArgs = [];
  5438. for (var _i = 1; _i < arguments.length; _i++) {
  5439. otherArgs[_i - 1] = arguments[_i];
  5440. }
  5441. var val = this.options[name];
  5442. if (typeof val === 'function') {
  5443. val = val.apply(null, otherArgs);
  5444. }
  5445. if (val) {
  5446. val = parseRange(val, this.dateEnv);
  5447. }
  5448. if (val) {
  5449. val = computeVisibleDayRange(val);
  5450. }
  5451. return val;
  5452. };
  5453. /* Hidden Days
  5454. ------------------------------------------------------------------------------------------------------------------*/
  5455. // Initializes internal variables related to calculating hidden days-of-week
  5456. DateProfileGenerator.prototype.initHiddenDays = function () {
  5457. var hiddenDays = this.options.hiddenDays || []; // array of day-of-week indices that are hidden
  5458. var isHiddenDayHash = []; // is the day-of-week hidden? (hash with day-of-week-index -> bool)
  5459. var dayCnt = 0;
  5460. var i;
  5461. if (this.options.weekends === false) {
  5462. hiddenDays.push(0, 6); // 0=sunday, 6=saturday
  5463. }
  5464. for (i = 0; i < 7; i++) {
  5465. if (!(isHiddenDayHash[i] = hiddenDays.indexOf(i) !== -1)) {
  5466. dayCnt++;
  5467. }
  5468. }
  5469. if (!dayCnt) {
  5470. throw new Error('invalid hiddenDays'); // all days were hidden? bad.
  5471. }
  5472. this.isHiddenDayHash = isHiddenDayHash;
  5473. };
  5474. // Remove days from the beginning and end of the range that are computed as hidden.
  5475. // If the whole range is trimmed off, returns null
  5476. DateProfileGenerator.prototype.trimHiddenDays = function (range) {
  5477. var start = range.start;
  5478. var end = range.end;
  5479. if (start) {
  5480. start = this.skipHiddenDays(start);
  5481. }
  5482. if (end) {
  5483. end = this.skipHiddenDays(end, -1, true);
  5484. }
  5485. if (start == null || end == null || start < end) {
  5486. return { start: start, end: end };
  5487. }
  5488. return null;
  5489. };
  5490. // Is the current day hidden?
  5491. // `day` is a day-of-week index (0-6), or a Date (used for UTC)
  5492. DateProfileGenerator.prototype.isHiddenDay = function (day) {
  5493. if (day instanceof Date) {
  5494. day = day.getUTCDay();
  5495. }
  5496. return this.isHiddenDayHash[day];
  5497. };
  5498. // Incrementing the current day until it is no longer a hidden day, returning a copy.
  5499. // DOES NOT CONSIDER validRange!
  5500. // If the initial value of `date` is not a hidden day, don't do anything.
  5501. // Pass `isExclusive` as `true` if you are dealing with an end date.
  5502. // `inc` defaults to `1` (increment one day forward each time)
  5503. DateProfileGenerator.prototype.skipHiddenDays = function (date, inc, isExclusive) {
  5504. if (inc === void 0) { inc = 1; }
  5505. if (isExclusive === void 0) { isExclusive = false; }
  5506. while (this.isHiddenDayHash[(date.getUTCDay() + (isExclusive ? inc : 0) + 7) % 7]) {
  5507. date = addDays(date, inc);
  5508. }
  5509. return date;
  5510. };
  5511. return DateProfileGenerator;
  5512. }());
  5513. // TODO: find a way to avoid comparing DateProfiles. it's tedious
  5514. function isDateProfilesEqual(p0, p1) {
  5515. return rangesEqual(p0.validRange, p1.validRange) &&
  5516. rangesEqual(p0.activeRange, p1.activeRange) &&
  5517. rangesEqual(p0.renderRange, p1.renderRange) &&
  5518. durationsEqual(p0.minTime, p1.minTime) &&
  5519. durationsEqual(p0.maxTime, p1.maxTime);
  5520. /*
  5521. TODO: compare more?
  5522. currentRange: DateRange
  5523. currentRangeUnit: string
  5524. isRangeAllDay: boolean
  5525. isValid: boolean
  5526. dateIncrement: Duration
  5527. */
  5528. }
  5529. function reduce (state, action, calendar) {
  5530. var viewType = reduceViewType(state.viewType, action);
  5531. var dateProfile = reduceDateProfile(state.dateProfile, action, state.currentDate, viewType, calendar);
  5532. var eventSources = reduceEventSources(state.eventSources, action, dateProfile, calendar);
  5533. var nextState = __assign({}, state, { viewType: viewType,
  5534. dateProfile: dateProfile, currentDate: reduceCurrentDate(state.currentDate, action, dateProfile), eventSources: eventSources, eventStore: reduceEventStore(state.eventStore, action, eventSources, dateProfile, calendar), dateSelection: reduceDateSelection(state.dateSelection, action, calendar), eventSelection: reduceSelectedEvent(state.eventSelection, action), eventDrag: reduceEventDrag(state.eventDrag, action, eventSources, calendar), eventResize: reduceEventResize(state.eventResize, action, eventSources, calendar), eventSourceLoadingLevel: computeLoadingLevel(eventSources), loadingLevel: computeLoadingLevel(eventSources) });
  5535. for (var _i = 0, _a = calendar.pluginSystem.hooks.reducers; _i < _a.length; _i++) {
  5536. var reducerFunc = _a[_i];
  5537. nextState = reducerFunc(nextState, action, calendar);
  5538. }
  5539. // console.log(action.type, nextState)
  5540. return nextState;
  5541. }
  5542. function reduceViewType(currentViewType, action) {
  5543. switch (action.type) {
  5544. case 'SET_VIEW_TYPE':
  5545. return action.viewType;
  5546. default:
  5547. return currentViewType;
  5548. }
  5549. }
  5550. function reduceDateProfile(currentDateProfile, action, currentDate, viewType, calendar) {
  5551. var newDateProfile;
  5552. switch (action.type) {
  5553. case 'PREV':
  5554. newDateProfile = calendar.dateProfileGenerators[viewType].buildPrev(currentDateProfile, currentDate);
  5555. break;
  5556. case 'NEXT':
  5557. newDateProfile = calendar.dateProfileGenerators[viewType].buildNext(currentDateProfile, currentDate);
  5558. break;
  5559. case 'SET_DATE':
  5560. if (!currentDateProfile.activeRange ||
  5561. !rangeContainsMarker(currentDateProfile.currentRange, action.dateMarker)) {
  5562. newDateProfile = calendar.dateProfileGenerators[viewType].build(action.dateMarker, undefined, true // forceToValid
  5563. );
  5564. }
  5565. break;
  5566. case 'SET_VIEW_TYPE':
  5567. var generator = calendar.dateProfileGenerators[viewType];
  5568. if (!generator) {
  5569. throw new Error(viewType ?
  5570. 'The FullCalendar view "' + viewType + '" does not exist. Make sure your plugins are loaded correctly.' :
  5571. 'No available FullCalendar view plugins.');
  5572. }
  5573. newDateProfile = generator.build(action.dateMarker || currentDate, undefined, true // forceToValid
  5574. );
  5575. break;
  5576. }
  5577. if (newDateProfile &&
  5578. newDateProfile.isValid &&
  5579. !(currentDateProfile && isDateProfilesEqual(currentDateProfile, newDateProfile))) {
  5580. return newDateProfile;
  5581. }
  5582. else {
  5583. return currentDateProfile;
  5584. }
  5585. }
  5586. function reduceCurrentDate(currentDate, action, dateProfile) {
  5587. switch (action.type) {
  5588. case 'PREV':
  5589. case 'NEXT':
  5590. if (!rangeContainsMarker(dateProfile.currentRange, currentDate)) {
  5591. return dateProfile.currentRange.start;
  5592. }
  5593. else {
  5594. return currentDate;
  5595. }
  5596. case 'SET_DATE':
  5597. case 'SET_VIEW_TYPE':
  5598. var newDate = action.dateMarker || currentDate;
  5599. if (dateProfile.activeRange && !rangeContainsMarker(dateProfile.activeRange, newDate)) {
  5600. return dateProfile.currentRange.start;
  5601. }
  5602. else {
  5603. return newDate;
  5604. }
  5605. default:
  5606. return currentDate;
  5607. }
  5608. }
  5609. function reduceDateSelection(currentSelection, action, calendar) {
  5610. switch (action.type) {
  5611. case 'SELECT_DATES':
  5612. return action.selection;
  5613. case 'UNSELECT_DATES':
  5614. return null;
  5615. default:
  5616. return currentSelection;
  5617. }
  5618. }
  5619. function reduceSelectedEvent(currentInstanceId, action) {
  5620. switch (action.type) {
  5621. case 'SELECT_EVENT':
  5622. return action.eventInstanceId;
  5623. case 'UNSELECT_EVENT':
  5624. return '';
  5625. default:
  5626. return currentInstanceId;
  5627. }
  5628. }
  5629. function reduceEventDrag(currentDrag, action, sources, calendar) {
  5630. switch (action.type) {
  5631. case 'SET_EVENT_DRAG':
  5632. var newDrag = action.state;
  5633. return {
  5634. affectedEvents: newDrag.affectedEvents,
  5635. mutatedEvents: newDrag.mutatedEvents,
  5636. isEvent: newDrag.isEvent,
  5637. origSeg: newDrag.origSeg
  5638. };
  5639. case 'UNSET_EVENT_DRAG':
  5640. return null;
  5641. default:
  5642. return currentDrag;
  5643. }
  5644. }
  5645. function reduceEventResize(currentResize, action, sources, calendar) {
  5646. switch (action.type) {
  5647. case 'SET_EVENT_RESIZE':
  5648. var newResize = action.state;
  5649. return {
  5650. affectedEvents: newResize.affectedEvents,
  5651. mutatedEvents: newResize.mutatedEvents,
  5652. isEvent: newResize.isEvent,
  5653. origSeg: newResize.origSeg
  5654. };
  5655. case 'UNSET_EVENT_RESIZE':
  5656. return null;
  5657. default:
  5658. return currentResize;
  5659. }
  5660. }
  5661. function computeLoadingLevel(eventSources) {
  5662. var cnt = 0;
  5663. for (var sourceId in eventSources) {
  5664. if (eventSources[sourceId].isFetching) {
  5665. cnt++;
  5666. }
  5667. }
  5668. return cnt;
  5669. }
  5670. var STANDARD_PROPS = {
  5671. start: null,
  5672. end: null,
  5673. allDay: Boolean
  5674. };
  5675. function parseDateSpan(raw, dateEnv, defaultDuration) {
  5676. var span = parseOpenDateSpan(raw, dateEnv);
  5677. var range = span.range;
  5678. if (!range.start) {
  5679. return null;
  5680. }
  5681. if (!range.end) {
  5682. if (defaultDuration == null) {
  5683. return null;
  5684. }
  5685. else {
  5686. range.end = dateEnv.add(range.start, defaultDuration);
  5687. }
  5688. }
  5689. return span;
  5690. }
  5691. /*
  5692. TODO: somehow combine with parseRange?
  5693. Will return null if the start/end props were present but parsed invalidly.
  5694. */
  5695. function parseOpenDateSpan(raw, dateEnv) {
  5696. var leftovers = {};
  5697. var standardProps = refineProps(raw, STANDARD_PROPS, {}, leftovers);
  5698. var startMeta = standardProps.start ? dateEnv.createMarkerMeta(standardProps.start) : null;
  5699. var endMeta = standardProps.end ? dateEnv.createMarkerMeta(standardProps.end) : null;
  5700. var allDay = standardProps.allDay;
  5701. if (allDay == null) {
  5702. allDay = (startMeta && startMeta.isTimeUnspecified) &&
  5703. (!endMeta || endMeta.isTimeUnspecified);
  5704. }
  5705. // use this leftover object as the selection object
  5706. leftovers.range = {
  5707. start: startMeta ? startMeta.marker : null,
  5708. end: endMeta ? endMeta.marker : null
  5709. };
  5710. leftovers.allDay = allDay;
  5711. return leftovers;
  5712. }
  5713. function isDateSpansEqual(span0, span1) {
  5714. return rangesEqual(span0.range, span1.range) &&
  5715. span0.allDay === span1.allDay &&
  5716. isSpanPropsEqual(span0, span1);
  5717. }
  5718. // the NON-DATE-RELATED props
  5719. function isSpanPropsEqual(span0, span1) {
  5720. for (var propName in span1) {
  5721. if (propName !== 'range' && propName !== 'allDay') {
  5722. if (span0[propName] !== span1[propName]) {
  5723. return false;
  5724. }
  5725. }
  5726. }
  5727. // are there any props that span0 has that span1 DOESN'T have?
  5728. // both have range/allDay, so no need to special-case.
  5729. for (var propName in span0) {
  5730. if (!(propName in span1)) {
  5731. return false;
  5732. }
  5733. }
  5734. return true;
  5735. }
  5736. function buildDateSpanApi(span, dateEnv) {
  5737. return {
  5738. start: dateEnv.toDate(span.range.start),
  5739. end: dateEnv.toDate(span.range.end),
  5740. startStr: dateEnv.formatIso(span.range.start, { omitTime: span.allDay }),
  5741. endStr: dateEnv.formatIso(span.range.end, { omitTime: span.allDay }),
  5742. allDay: span.allDay
  5743. };
  5744. }
  5745. function buildDatePointApi(span, dateEnv) {
  5746. return {
  5747. date: dateEnv.toDate(span.range.start),
  5748. dateStr: dateEnv.formatIso(span.range.start, { omitTime: span.allDay }),
  5749. allDay: span.allDay
  5750. };
  5751. }
  5752. function fabricateEventRange(dateSpan, eventUiBases, calendar) {
  5753. var def = parseEventDef({ editable: false }, '', // sourceId
  5754. dateSpan.allDay, true, // hasEnd
  5755. calendar);
  5756. return {
  5757. def: def,
  5758. ui: compileEventUi(def, eventUiBases),
  5759. instance: createEventInstance(def.defId, dateSpan.range),
  5760. range: dateSpan.range,
  5761. isStart: true,
  5762. isEnd: true
  5763. };
  5764. }
  5765. function compileViewDefs(defaultConfigs, overrideConfigs) {
  5766. var hash = {};
  5767. var viewType;
  5768. for (viewType in defaultConfigs) {
  5769. ensureViewDef(viewType, hash, defaultConfigs, overrideConfigs);
  5770. }
  5771. for (viewType in overrideConfigs) {
  5772. ensureViewDef(viewType, hash, defaultConfigs, overrideConfigs);
  5773. }
  5774. return hash;
  5775. }
  5776. function ensureViewDef(viewType, hash, defaultConfigs, overrideConfigs) {
  5777. if (hash[viewType]) {
  5778. return hash[viewType];
  5779. }
  5780. var viewDef = buildViewDef(viewType, hash, defaultConfigs, overrideConfigs);
  5781. if (viewDef) {
  5782. hash[viewType] = viewDef;
  5783. }
  5784. return viewDef;
  5785. }
  5786. function buildViewDef(viewType, hash, defaultConfigs, overrideConfigs) {
  5787. var defaultConfig = defaultConfigs[viewType];
  5788. var overrideConfig = overrideConfigs[viewType];
  5789. var queryProp = function (name) {
  5790. return (defaultConfig && defaultConfig[name] !== null) ? defaultConfig[name] :
  5791. ((overrideConfig && overrideConfig[name] !== null) ? overrideConfig[name] : null);
  5792. };
  5793. var theClass = queryProp('class');
  5794. var superType = queryProp('superType');
  5795. if (!superType && theClass) {
  5796. superType =
  5797. findViewNameBySubclass(theClass, overrideConfigs) ||
  5798. findViewNameBySubclass(theClass, defaultConfigs);
  5799. }
  5800. var superDef = null;
  5801. if (superType) {
  5802. if (superType === viewType) {
  5803. throw new Error('Can\'t have a custom view type that references itself');
  5804. }
  5805. superDef = ensureViewDef(superType, hash, defaultConfigs, overrideConfigs);
  5806. }
  5807. if (!theClass && superDef) {
  5808. theClass = superDef.class;
  5809. }
  5810. if (!theClass) {
  5811. return null; // don't throw a warning, might be settings for a single-unit view
  5812. }
  5813. return {
  5814. type: viewType,
  5815. class: theClass,
  5816. defaults: __assign({}, (superDef ? superDef.defaults : {}), (defaultConfig ? defaultConfig.options : {})),
  5817. overrides: __assign({}, (superDef ? superDef.overrides : {}), (overrideConfig ? overrideConfig.options : {}))
  5818. };
  5819. }
  5820. function findViewNameBySubclass(viewSubclass, configs) {
  5821. var superProto = Object.getPrototypeOf(viewSubclass.prototype);
  5822. for (var viewType in configs) {
  5823. var parsed = configs[viewType];
  5824. // need DIRECT subclass, so instanceof won't do it
  5825. if (parsed.class && parsed.class.prototype === superProto) {
  5826. return viewType;
  5827. }
  5828. }
  5829. return '';
  5830. }
  5831. function parseViewConfigs(inputs) {
  5832. return mapHash(inputs, parseViewConfig);
  5833. }
  5834. var VIEW_DEF_PROPS = {
  5835. type: String,
  5836. class: null
  5837. };
  5838. function parseViewConfig(input) {
  5839. if (typeof input === 'function') {
  5840. input = { class: input };
  5841. }
  5842. var options = {};
  5843. var props = refineProps(input, VIEW_DEF_PROPS, {}, options);
  5844. return {
  5845. superType: props.type,
  5846. class: props.class,
  5847. options: options
  5848. };
  5849. }
  5850. function buildViewSpecs(defaultInputs, optionsManager) {
  5851. var defaultConfigs = parseViewConfigs(defaultInputs);
  5852. var overrideConfigs = parseViewConfigs(optionsManager.overrides.views);
  5853. var viewDefs = compileViewDefs(defaultConfigs, overrideConfigs);
  5854. return mapHash(viewDefs, function (viewDef) {
  5855. return buildViewSpec(viewDef, overrideConfigs, optionsManager);
  5856. });
  5857. }
  5858. function buildViewSpec(viewDef, overrideConfigs, optionsManager) {
  5859. var durationInput = viewDef.overrides.duration ||
  5860. viewDef.defaults.duration ||
  5861. optionsManager.dynamicOverrides.duration ||
  5862. optionsManager.overrides.duration;
  5863. var duration = null;
  5864. var durationUnit = '';
  5865. var singleUnit = '';
  5866. var singleUnitOverrides = {};
  5867. if (durationInput) {
  5868. duration = createDuration(durationInput);
  5869. if (duration) { // valid?
  5870. var denom = greatestDurationDenominator(duration, !getWeeksFromInput(durationInput));
  5871. durationUnit = denom.unit;
  5872. if (denom.value === 1) {
  5873. singleUnit = durationUnit;
  5874. singleUnitOverrides = overrideConfigs[durationUnit] ? overrideConfigs[durationUnit].options : {};
  5875. }
  5876. }
  5877. }
  5878. var queryButtonText = function (options) {
  5879. var buttonTextMap = options.buttonText || {};
  5880. var buttonTextKey = viewDef.defaults.buttonTextKey;
  5881. if (buttonTextKey != null && buttonTextMap[buttonTextKey] != null) {
  5882. return buttonTextMap[buttonTextKey];
  5883. }
  5884. if (buttonTextMap[viewDef.type] != null) {
  5885. return buttonTextMap[viewDef.type];
  5886. }
  5887. if (buttonTextMap[singleUnit] != null) {
  5888. return buttonTextMap[singleUnit];
  5889. }
  5890. };
  5891. return {
  5892. type: viewDef.type,
  5893. class: viewDef.class,
  5894. duration: duration,
  5895. durationUnit: durationUnit,
  5896. singleUnit: singleUnit,
  5897. options: __assign({}, globalDefaults, viewDef.defaults, optionsManager.dirDefaults, optionsManager.localeDefaults, optionsManager.overrides, singleUnitOverrides, viewDef.overrides, optionsManager.dynamicOverrides),
  5898. buttonTextOverride: queryButtonText(optionsManager.dynamicOverrides) ||
  5899. queryButtonText(optionsManager.overrides) || // constructor-specified buttonText lookup hash takes precedence
  5900. viewDef.overrides.buttonText,
  5901. buttonTextDefault: queryButtonText(optionsManager.localeDefaults) ||
  5902. queryButtonText(optionsManager.dirDefaults) ||
  5903. viewDef.defaults.buttonText ||
  5904. queryButtonText(globalDefaults) ||
  5905. viewDef.type // fall back to given view name
  5906. };
  5907. }
  5908. var Toolbar = /** @class */ (function (_super) {
  5909. __extends(Toolbar, _super);
  5910. function Toolbar(extraClassName) {
  5911. var _this = _super.call(this) || this;
  5912. _this._renderLayout = memoizeRendering(_this.renderLayout, _this.unrenderLayout);
  5913. _this._updateTitle = memoizeRendering(_this.updateTitle, null, [_this._renderLayout]);
  5914. _this._updateActiveButton = memoizeRendering(_this.updateActiveButton, null, [_this._renderLayout]);
  5915. _this._updateToday = memoizeRendering(_this.updateToday, null, [_this._renderLayout]);
  5916. _this._updatePrev = memoizeRendering(_this.updatePrev, null, [_this._renderLayout]);
  5917. _this._updateNext = memoizeRendering(_this.updateNext, null, [_this._renderLayout]);
  5918. _this.el = createElement('div', { className: 'fc-toolbar ' + extraClassName });
  5919. return _this;
  5920. }
  5921. Toolbar.prototype.destroy = function () {
  5922. _super.prototype.destroy.call(this);
  5923. this._renderLayout.unrender(); // should unrender everything else
  5924. removeElement(this.el);
  5925. };
  5926. Toolbar.prototype.render = function (props) {
  5927. this._renderLayout(props.layout);
  5928. this._updateTitle(props.title);
  5929. this._updateActiveButton(props.activeButton);
  5930. this._updateToday(props.isTodayEnabled);
  5931. this._updatePrev(props.isPrevEnabled);
  5932. this._updateNext(props.isNextEnabled);
  5933. };
  5934. Toolbar.prototype.renderLayout = function (layout) {
  5935. var el = this.el;
  5936. this.viewsWithButtons = [];
  5937. appendToElement(el, this.renderSection('left', layout.left));
  5938. appendToElement(el, this.renderSection('center', layout.center));
  5939. appendToElement(el, this.renderSection('right', layout.right));
  5940. };
  5941. Toolbar.prototype.unrenderLayout = function () {
  5942. this.el.innerHTML = '';
  5943. };
  5944. Toolbar.prototype.renderSection = function (position, buttonStr) {
  5945. var _this = this;
  5946. var _a = this.context, theme = _a.theme, calendar = _a.calendar;
  5947. var optionsManager = calendar.optionsManager;
  5948. var viewSpecs = calendar.viewSpecs;
  5949. var sectionEl = createElement('div', { className: 'fc-' + position });
  5950. var calendarCustomButtons = optionsManager.computed.customButtons || {};
  5951. var calendarButtonTextOverrides = optionsManager.overrides.buttonText || {};
  5952. var calendarButtonText = optionsManager.computed.buttonText || {};
  5953. if (buttonStr) {
  5954. buttonStr.split(' ').forEach(function (buttonGroupStr, i) {
  5955. var groupChildren = [];
  5956. var isOnlyButtons = true;
  5957. var groupEl;
  5958. buttonGroupStr.split(',').forEach(function (buttonName, j) {
  5959. var customButtonProps;
  5960. var viewSpec;
  5961. var buttonClick;
  5962. var buttonIcon; // only one of these will be set
  5963. var buttonText; // "
  5964. var buttonInnerHtml;
  5965. var buttonClasses;
  5966. var buttonEl;
  5967. var buttonAriaAttr;
  5968. if (buttonName === 'title') {
  5969. groupChildren.push(htmlToElement('<h2>&nbsp;</h2>')); // we always want it to take up height
  5970. isOnlyButtons = false;
  5971. }
  5972. else {
  5973. if ((customButtonProps = calendarCustomButtons[buttonName])) {
  5974. buttonClick = function (ev) {
  5975. if (customButtonProps.click) {
  5976. customButtonProps.click.call(buttonEl, ev);
  5977. }
  5978. };
  5979. (buttonIcon = theme.getCustomButtonIconClass(customButtonProps)) ||
  5980. (buttonIcon = theme.getIconClass(buttonName)) ||
  5981. (buttonText = customButtonProps.text);
  5982. }
  5983. else if ((viewSpec = viewSpecs[buttonName])) {
  5984. _this.viewsWithButtons.push(buttonName);
  5985. buttonClick = function () {
  5986. calendar.changeView(buttonName);
  5987. };
  5988. (buttonText = viewSpec.buttonTextOverride) ||
  5989. (buttonIcon = theme.getIconClass(buttonName)) ||
  5990. (buttonText = viewSpec.buttonTextDefault);
  5991. }
  5992. else if (calendar[buttonName]) { // a calendar method
  5993. buttonClick = function () {
  5994. calendar[buttonName]();
  5995. };
  5996. (buttonText = calendarButtonTextOverrides[buttonName]) ||
  5997. (buttonIcon = theme.getIconClass(buttonName)) ||
  5998. (buttonText = calendarButtonText[buttonName]);
  5999. // ^ everything else is considered default
  6000. }
  6001. if (buttonClick) {
  6002. buttonClasses = [
  6003. 'fc-' + buttonName + '-button',
  6004. theme.getClass('button')
  6005. ];
  6006. if (buttonText) {
  6007. buttonInnerHtml = htmlEscape(buttonText);
  6008. buttonAriaAttr = '';
  6009. }
  6010. else if (buttonIcon) {
  6011. buttonInnerHtml = "<span class='" + buttonIcon + "'></span>";
  6012. buttonAriaAttr = ' aria-label="' + buttonName + '"';
  6013. }
  6014. buttonEl = htmlToElement(// type="button" so that it doesn't submit a form
  6015. '<button type="button" class="' + buttonClasses.join(' ') + '"' +
  6016. buttonAriaAttr +
  6017. '>' + buttonInnerHtml + '</button>');
  6018. buttonEl.addEventListener('click', buttonClick);
  6019. groupChildren.push(buttonEl);
  6020. }
  6021. }
  6022. });
  6023. if (groupChildren.length > 1) {
  6024. groupEl = document.createElement('div');
  6025. var buttonGroupClassName = theme.getClass('buttonGroup');
  6026. if (isOnlyButtons && buttonGroupClassName) {
  6027. groupEl.classList.add(buttonGroupClassName);
  6028. }
  6029. appendToElement(groupEl, groupChildren);
  6030. sectionEl.appendChild(groupEl);
  6031. }
  6032. else {
  6033. appendToElement(sectionEl, groupChildren); // 1 or 0 children
  6034. }
  6035. });
  6036. }
  6037. return sectionEl;
  6038. };
  6039. Toolbar.prototype.updateToday = function (isTodayEnabled) {
  6040. this.toggleButtonEnabled('today', isTodayEnabled);
  6041. };
  6042. Toolbar.prototype.updatePrev = function (isPrevEnabled) {
  6043. this.toggleButtonEnabled('prev', isPrevEnabled);
  6044. };
  6045. Toolbar.prototype.updateNext = function (isNextEnabled) {
  6046. this.toggleButtonEnabled('next', isNextEnabled);
  6047. };
  6048. Toolbar.prototype.updateTitle = function (text) {
  6049. findElements(this.el, 'h2').forEach(function (titleEl) {
  6050. titleEl.innerText = text;
  6051. });
  6052. };
  6053. Toolbar.prototype.updateActiveButton = function (buttonName) {
  6054. var theme = this.context.theme;
  6055. var className = theme.getClass('buttonActive');
  6056. findElements(this.el, 'button').forEach(function (buttonEl) {
  6057. if (buttonName && buttonEl.classList.contains('fc-' + buttonName + '-button')) {
  6058. buttonEl.classList.add(className);
  6059. }
  6060. else {
  6061. buttonEl.classList.remove(className);
  6062. }
  6063. });
  6064. };
  6065. Toolbar.prototype.toggleButtonEnabled = function (buttonName, bool) {
  6066. findElements(this.el, '.fc-' + buttonName + '-button').forEach(function (buttonEl) {
  6067. buttonEl.disabled = !bool;
  6068. });
  6069. };
  6070. return Toolbar;
  6071. }(Component));
  6072. var CalendarComponent = /** @class */ (function (_super) {
  6073. __extends(CalendarComponent, _super);
  6074. function CalendarComponent(el) {
  6075. var _this = _super.call(this) || this;
  6076. _this.elClassNames = [];
  6077. _this.renderSkeleton = memoizeRendering(_this._renderSkeleton, _this._unrenderSkeleton);
  6078. _this.renderToolbars = memoizeRendering(_this._renderToolbars, _this._unrenderToolbars, [_this.renderSkeleton]);
  6079. _this.buildComponentContext = memoize(buildComponentContext);
  6080. _this.buildViewPropTransformers = memoize(buildViewPropTransformers);
  6081. _this.el = el;
  6082. _this.computeTitle = memoize(computeTitle);
  6083. _this.parseBusinessHours = memoize(function (input) {
  6084. return parseBusinessHours(input, _this.context.calendar);
  6085. });
  6086. return _this;
  6087. }
  6088. CalendarComponent.prototype.render = function (props, context) {
  6089. this.freezeHeight();
  6090. var title = this.computeTitle(props.dateProfile, props.viewSpec.options);
  6091. this.renderSkeleton(context);
  6092. this.renderToolbars(props.viewSpec, props.dateProfile, props.currentDate, title);
  6093. this.renderView(props, title);
  6094. this.updateSize();
  6095. this.thawHeight();
  6096. };
  6097. CalendarComponent.prototype.destroy = function () {
  6098. if (this.header) {
  6099. this.header.destroy();
  6100. }
  6101. if (this.footer) {
  6102. this.footer.destroy();
  6103. }
  6104. this.renderSkeleton.unrender(); // will call destroyView
  6105. _super.prototype.destroy.call(this);
  6106. };
  6107. CalendarComponent.prototype._renderSkeleton = function (context) {
  6108. this.updateElClassNames(context);
  6109. prependToElement(this.el, this.contentEl = createElement('div', { className: 'fc-view-container' }));
  6110. var calendar = context.calendar;
  6111. for (var _i = 0, _a = calendar.pluginSystem.hooks.viewContainerModifiers; _i < _a.length; _i++) {
  6112. var modifyViewContainer = _a[_i];
  6113. modifyViewContainer(this.contentEl, calendar);
  6114. }
  6115. };
  6116. CalendarComponent.prototype._unrenderSkeleton = function () {
  6117. // weird to have this here
  6118. if (this.view) {
  6119. this.savedScroll = this.view.queryScroll();
  6120. this.view.destroy();
  6121. this.view = null;
  6122. }
  6123. removeElement(this.contentEl);
  6124. this.removeElClassNames();
  6125. };
  6126. CalendarComponent.prototype.removeElClassNames = function () {
  6127. var classList = this.el.classList;
  6128. for (var _i = 0, _a = this.elClassNames; _i < _a.length; _i++) {
  6129. var className = _a[_i];
  6130. classList.remove(className);
  6131. }
  6132. this.elClassNames = [];
  6133. };
  6134. CalendarComponent.prototype.updateElClassNames = function (context) {
  6135. this.removeElClassNames();
  6136. var theme = context.theme, options = context.options;
  6137. this.elClassNames = [
  6138. 'fc',
  6139. 'fc-' + options.dir,
  6140. theme.getClass('widget')
  6141. ];
  6142. var classList = this.el.classList;
  6143. for (var _i = 0, _a = this.elClassNames; _i < _a.length; _i++) {
  6144. var className = _a[_i];
  6145. classList.add(className);
  6146. }
  6147. };
  6148. CalendarComponent.prototype._renderToolbars = function (viewSpec, dateProfile, currentDate, title) {
  6149. var _a = this, context = _a.context, header = _a.header, footer = _a.footer;
  6150. var options = context.options, calendar = context.calendar;
  6151. var headerLayout = options.header;
  6152. var footerLayout = options.footer;
  6153. var dateProfileGenerator = this.props.dateProfileGenerator;
  6154. var now = calendar.getNow();
  6155. var todayInfo = dateProfileGenerator.build(now);
  6156. var prevInfo = dateProfileGenerator.buildPrev(dateProfile, currentDate);
  6157. var nextInfo = dateProfileGenerator.buildNext(dateProfile, currentDate);
  6158. var toolbarProps = {
  6159. title: title,
  6160. activeButton: viewSpec.type,
  6161. isTodayEnabled: todayInfo.isValid && !rangeContainsMarker(dateProfile.currentRange, now),
  6162. isPrevEnabled: prevInfo.isValid,
  6163. isNextEnabled: nextInfo.isValid
  6164. };
  6165. if (headerLayout) {
  6166. if (!header) {
  6167. header = this.header = new Toolbar('fc-header-toolbar');
  6168. prependToElement(this.el, header.el);
  6169. }
  6170. header.receiveProps(__assign({ layout: headerLayout }, toolbarProps), context);
  6171. }
  6172. else if (header) {
  6173. header.destroy();
  6174. header = this.header = null;
  6175. }
  6176. if (footerLayout) {
  6177. if (!footer) {
  6178. footer = this.footer = new Toolbar('fc-footer-toolbar');
  6179. appendToElement(this.el, footer.el);
  6180. }
  6181. footer.receiveProps(__assign({ layout: footerLayout }, toolbarProps), context);
  6182. }
  6183. else if (footer) {
  6184. footer.destroy();
  6185. footer = this.footer = null;
  6186. }
  6187. };
  6188. CalendarComponent.prototype._unrenderToolbars = function () {
  6189. if (this.header) {
  6190. this.header.destroy();
  6191. this.header = null;
  6192. }
  6193. if (this.footer) {
  6194. this.footer.destroy();
  6195. this.footer = null;
  6196. }
  6197. };
  6198. CalendarComponent.prototype.renderView = function (props, title) {
  6199. var view = this.view;
  6200. var _a = this.context, calendar = _a.calendar, options = _a.options;
  6201. var viewSpec = props.viewSpec, dateProfileGenerator = props.dateProfileGenerator;
  6202. if (!view || view.viewSpec !== viewSpec) {
  6203. if (view) {
  6204. view.destroy();
  6205. }
  6206. view = this.view = new viewSpec['class'](viewSpec, this.contentEl);
  6207. if (this.savedScroll) {
  6208. view.addScroll(this.savedScroll, true);
  6209. this.savedScroll = null;
  6210. }
  6211. }
  6212. view.title = title; // for the API
  6213. var viewProps = {
  6214. dateProfileGenerator: dateProfileGenerator,
  6215. dateProfile: props.dateProfile,
  6216. businessHours: this.parseBusinessHours(viewSpec.options.businessHours),
  6217. eventStore: props.eventStore,
  6218. eventUiBases: props.eventUiBases,
  6219. dateSelection: props.dateSelection,
  6220. eventSelection: props.eventSelection,
  6221. eventDrag: props.eventDrag,
  6222. eventResize: props.eventResize
  6223. };
  6224. var transformers = this.buildViewPropTransformers(calendar.pluginSystem.hooks.viewPropsTransformers);
  6225. for (var _i = 0, transformers_1 = transformers; _i < transformers_1.length; _i++) {
  6226. var transformer = transformers_1[_i];
  6227. __assign(viewProps, transformer.transform(viewProps, viewSpec, props, options));
  6228. }
  6229. view.receiveProps(viewProps, this.buildComponentContext(this.context, viewSpec, view));
  6230. };
  6231. // Sizing
  6232. // -----------------------------------------------------------------------------------------------------------------
  6233. CalendarComponent.prototype.updateSize = function (isResize) {
  6234. if (isResize === void 0) { isResize = false; }
  6235. var view = this.view;
  6236. if (!view) {
  6237. return; // why?
  6238. }
  6239. if (isResize || this.isHeightAuto == null) {
  6240. this.computeHeightVars();
  6241. }
  6242. view.updateSize(isResize, this.viewHeight, this.isHeightAuto);
  6243. view.updateNowIndicator(); // we need to guarantee this will run after updateSize
  6244. view.popScroll(isResize);
  6245. };
  6246. CalendarComponent.prototype.computeHeightVars = function () {
  6247. var calendar = this.context.calendar; // yuck. need to handle dynamic options
  6248. var heightInput = calendar.opt('height');
  6249. var contentHeightInput = calendar.opt('contentHeight');
  6250. this.isHeightAuto = heightInput === 'auto' || contentHeightInput === 'auto';
  6251. if (typeof contentHeightInput === 'number') { // exists and not 'auto'
  6252. this.viewHeight = contentHeightInput;
  6253. }
  6254. else if (typeof contentHeightInput === 'function') { // exists and is a function
  6255. this.viewHeight = contentHeightInput();
  6256. }
  6257. else if (typeof heightInput === 'number') { // exists and not 'auto'
  6258. this.viewHeight = heightInput - this.queryToolbarsHeight();
  6259. }
  6260. else if (typeof heightInput === 'function') { // exists and is a function
  6261. this.viewHeight = heightInput() - this.queryToolbarsHeight();
  6262. }
  6263. else if (heightInput === 'parent') { // set to height of parent element
  6264. var parentEl = this.el.parentNode;
  6265. this.viewHeight = parentEl.getBoundingClientRect().height - this.queryToolbarsHeight();
  6266. }
  6267. else {
  6268. this.viewHeight = Math.round(this.contentEl.getBoundingClientRect().width /
  6269. Math.max(calendar.opt('aspectRatio'), .5));
  6270. }
  6271. };
  6272. CalendarComponent.prototype.queryToolbarsHeight = function () {
  6273. var height = 0;
  6274. if (this.header) {
  6275. height += computeHeightAndMargins(this.header.el);
  6276. }
  6277. if (this.footer) {
  6278. height += computeHeightAndMargins(this.footer.el);
  6279. }
  6280. return height;
  6281. };
  6282. // Height "Freezing"
  6283. // -----------------------------------------------------------------------------------------------------------------
  6284. CalendarComponent.prototype.freezeHeight = function () {
  6285. applyStyle(this.el, {
  6286. height: this.el.getBoundingClientRect().height,
  6287. overflow: 'hidden'
  6288. });
  6289. };
  6290. CalendarComponent.prototype.thawHeight = function () {
  6291. applyStyle(this.el, {
  6292. height: '',
  6293. overflow: ''
  6294. });
  6295. };
  6296. return CalendarComponent;
  6297. }(Component));
  6298. // Title and Date Formatting
  6299. // -----------------------------------------------------------------------------------------------------------------
  6300. // Computes what the title at the top of the calendar should be for this view
  6301. function computeTitle(dateProfile, viewOptions) {
  6302. var range;
  6303. // for views that span a large unit of time, show the proper interval, ignoring stray days before and after
  6304. if (/^(year|month)$/.test(dateProfile.currentRangeUnit)) {
  6305. range = dateProfile.currentRange;
  6306. }
  6307. else { // for day units or smaller, use the actual day range
  6308. range = dateProfile.activeRange;
  6309. }
  6310. return this.context.dateEnv.formatRange(range.start, range.end, createFormatter(viewOptions.titleFormat || computeTitleFormat(dateProfile), viewOptions.titleRangeSeparator), { isEndExclusive: dateProfile.isRangeAllDay });
  6311. }
  6312. // Generates the format string that should be used to generate the title for the current date range.
  6313. // Attempts to compute the most appropriate format if not explicitly specified with `titleFormat`.
  6314. function computeTitleFormat(dateProfile) {
  6315. var currentRangeUnit = dateProfile.currentRangeUnit;
  6316. if (currentRangeUnit === 'year') {
  6317. return { year: 'numeric' };
  6318. }
  6319. else if (currentRangeUnit === 'month') {
  6320. return { year: 'numeric', month: 'long' }; // like "September 2014"
  6321. }
  6322. else {
  6323. var days = diffWholeDays(dateProfile.currentRange.start, dateProfile.currentRange.end);
  6324. if (days !== null && days > 1) {
  6325. // multi-day range. shorter, like "Sep 9 - 10 2014"
  6326. return { year: 'numeric', month: 'short', day: 'numeric' };
  6327. }
  6328. else {
  6329. // one day. longer, like "September 9 2014"
  6330. return { year: 'numeric', month: 'long', day: 'numeric' };
  6331. }
  6332. }
  6333. }
  6334. // build a context scoped to the view
  6335. function buildComponentContext(context, viewSpec, view) {
  6336. return context.extend(viewSpec.options, view);
  6337. }
  6338. // Plugin
  6339. // -----------------------------------------------------------------------------------------------------------------
  6340. function buildViewPropTransformers(theClasses) {
  6341. return theClasses.map(function (theClass) {
  6342. return new theClass();
  6343. });
  6344. }
  6345. var Interaction = /** @class */ (function () {
  6346. function Interaction(settings) {
  6347. this.component = settings.component;
  6348. }
  6349. Interaction.prototype.destroy = function () {
  6350. };
  6351. return Interaction;
  6352. }());
  6353. function parseInteractionSettings(component, input) {
  6354. return {
  6355. component: component,
  6356. el: input.el,
  6357. useEventCenter: input.useEventCenter != null ? input.useEventCenter : true
  6358. };
  6359. }
  6360. function interactionSettingsToStore(settings) {
  6361. var _a;
  6362. return _a = {},
  6363. _a[settings.component.uid] = settings,
  6364. _a;
  6365. }
  6366. // global state
  6367. var interactionSettingsStore = {};
  6368. /*
  6369. Detects when the user clicks on an event within a DateComponent
  6370. */
  6371. var EventClicking = /** @class */ (function (_super) {
  6372. __extends(EventClicking, _super);
  6373. function EventClicking(settings) {
  6374. var _this = _super.call(this, settings) || this;
  6375. _this.handleSegClick = function (ev, segEl) {
  6376. var component = _this.component;
  6377. var _a = component.context, calendar = _a.calendar, view = _a.view;
  6378. var seg = getElSeg(segEl);
  6379. if (seg && // might be the <div> surrounding the more link
  6380. component.isValidSegDownEl(ev.target)) {
  6381. // our way to simulate a link click for elements that can't be <a> tags
  6382. // grab before trigger fired in case trigger trashes DOM thru rerendering
  6383. var hasUrlContainer = elementClosest(ev.target, '.fc-has-url');
  6384. var url = hasUrlContainer ? hasUrlContainer.querySelector('a[href]').href : '';
  6385. calendar.publiclyTrigger('eventClick', [
  6386. {
  6387. el: segEl,
  6388. event: new EventApi(component.context.calendar, seg.eventRange.def, seg.eventRange.instance),
  6389. jsEvent: ev,
  6390. view: view
  6391. }
  6392. ]);
  6393. if (url && !ev.defaultPrevented) {
  6394. window.location.href = url;
  6395. }
  6396. }
  6397. };
  6398. var component = settings.component;
  6399. _this.destroy = listenBySelector(component.el, 'click', component.fgSegSelector + ',' + component.bgSegSelector, _this.handleSegClick);
  6400. return _this;
  6401. }
  6402. return EventClicking;
  6403. }(Interaction));
  6404. /*
  6405. Triggers events and adds/removes core classNames when the user's pointer
  6406. enters/leaves event-elements of a component.
  6407. */
  6408. var EventHovering = /** @class */ (function (_super) {
  6409. __extends(EventHovering, _super);
  6410. function EventHovering(settings) {
  6411. var _this = _super.call(this, settings) || this;
  6412. // for simulating an eventMouseLeave when the event el is destroyed while mouse is over it
  6413. _this.handleEventElRemove = function (el) {
  6414. if (el === _this.currentSegEl) {
  6415. _this.handleSegLeave(null, _this.currentSegEl);
  6416. }
  6417. };
  6418. _this.handleSegEnter = function (ev, segEl) {
  6419. if (getElSeg(segEl)) { // TODO: better way to make sure not hovering over more+ link or its wrapper
  6420. segEl.classList.add('fc-allow-mouse-resize');
  6421. _this.currentSegEl = segEl;
  6422. _this.triggerEvent('eventMouseEnter', ev, segEl);
  6423. }
  6424. };
  6425. _this.handleSegLeave = function (ev, segEl) {
  6426. if (_this.currentSegEl) {
  6427. segEl.classList.remove('fc-allow-mouse-resize');
  6428. _this.currentSegEl = null;
  6429. _this.triggerEvent('eventMouseLeave', ev, segEl);
  6430. }
  6431. };
  6432. var component = settings.component;
  6433. _this.removeHoverListeners = listenToHoverBySelector(component.el, component.fgSegSelector + ',' + component.bgSegSelector, _this.handleSegEnter, _this.handleSegLeave);
  6434. // how to make sure component already has context?
  6435. component.context.calendar.on('eventElRemove', _this.handleEventElRemove);
  6436. return _this;
  6437. }
  6438. EventHovering.prototype.destroy = function () {
  6439. this.removeHoverListeners();
  6440. this.component.context.calendar.off('eventElRemove', this.handleEventElRemove);
  6441. };
  6442. EventHovering.prototype.triggerEvent = function (publicEvName, ev, segEl) {
  6443. var component = this.component;
  6444. var _a = component.context, calendar = _a.calendar, view = _a.view;
  6445. var seg = getElSeg(segEl);
  6446. if (!ev || component.isValidSegDownEl(ev.target)) {
  6447. calendar.publiclyTrigger(publicEvName, [
  6448. {
  6449. el: segEl,
  6450. event: new EventApi(calendar, seg.eventRange.def, seg.eventRange.instance),
  6451. jsEvent: ev,
  6452. view: view
  6453. }
  6454. ]);
  6455. }
  6456. };
  6457. return EventHovering;
  6458. }(Interaction));
  6459. var StandardTheme = /** @class */ (function (_super) {
  6460. __extends(StandardTheme, _super);
  6461. function StandardTheme() {
  6462. return _super !== null && _super.apply(this, arguments) || this;
  6463. }
  6464. return StandardTheme;
  6465. }(Theme));
  6466. StandardTheme.prototype.classes = {
  6467. widget: 'fc-unthemed',
  6468. widgetHeader: 'fc-widget-header',
  6469. widgetContent: 'fc-widget-content',
  6470. buttonGroup: 'fc-button-group',
  6471. button: 'fc-button fc-button-primary',
  6472. buttonActive: 'fc-button-active',
  6473. popoverHeader: 'fc-widget-header',
  6474. popoverContent: 'fc-widget-content',
  6475. // day grid
  6476. headerRow: 'fc-widget-header',
  6477. dayRow: 'fc-widget-content',
  6478. // list view
  6479. listView: 'fc-widget-content'
  6480. };
  6481. StandardTheme.prototype.baseIconClass = 'fc-icon';
  6482. StandardTheme.prototype.iconClasses = {
  6483. close: 'fc-icon-x',
  6484. prev: 'fc-icon-chevron-left',
  6485. next: 'fc-icon-chevron-right',
  6486. prevYear: 'fc-icon-chevrons-left',
  6487. nextYear: 'fc-icon-chevrons-right'
  6488. };
  6489. StandardTheme.prototype.iconOverrideOption = 'buttonIcons';
  6490. StandardTheme.prototype.iconOverrideCustomButtonOption = 'icon';
  6491. StandardTheme.prototype.iconOverridePrefix = 'fc-icon-';
  6492. var Calendar = /** @class */ (function () {
  6493. function Calendar(el, overrides) {
  6494. var _this = this;
  6495. this.buildComponentContext = memoize(buildComponentContext$1);
  6496. this.parseRawLocales = memoize(parseRawLocales);
  6497. this.buildLocale = memoize(buildLocale);
  6498. this.buildDateEnv = memoize(buildDateEnv);
  6499. this.buildTheme = memoize(buildTheme);
  6500. this.buildEventUiSingleBase = memoize(this._buildEventUiSingleBase);
  6501. this.buildSelectionConfig = memoize(this._buildSelectionConfig);
  6502. this.buildEventUiBySource = memoizeOutput(buildEventUiBySource, isPropsEqual);
  6503. this.buildEventUiBases = memoize(buildEventUiBases);
  6504. this.interactionsStore = {};
  6505. this.actionQueue = [];
  6506. this.isReducing = false;
  6507. // isDisplaying: boolean = false // installed in DOM? accepting renders?
  6508. this.needsRerender = false; // needs a render?
  6509. this.isRendering = false; // currently in the executeRender function?
  6510. this.renderingPauseDepth = 0;
  6511. this.buildDelayedRerender = memoize(buildDelayedRerender);
  6512. this.afterSizingTriggers = {};
  6513. this.isViewUpdated = false;
  6514. this.isDatesUpdated = false;
  6515. this.isEventsUpdated = false;
  6516. this.el = el;
  6517. this.optionsManager = new OptionsManager(overrides || {});
  6518. this.pluginSystem = new PluginSystem();
  6519. // only do once. don't do in handleOptions. because can't remove plugins
  6520. this.addPluginInputs(this.optionsManager.computed.plugins || []);
  6521. this.handleOptions(this.optionsManager.computed);
  6522. this.publiclyTrigger('_init'); // for tests
  6523. this.hydrate();
  6524. this.calendarInteractions = this.pluginSystem.hooks.calendarInteractions
  6525. .map(function (calendarInteractionClass) {
  6526. return new calendarInteractionClass(_this);
  6527. });
  6528. }
  6529. Calendar.prototype.addPluginInputs = function (pluginInputs) {
  6530. var pluginDefs = refinePluginDefs(pluginInputs);
  6531. for (var _i = 0, pluginDefs_1 = pluginDefs; _i < pluginDefs_1.length; _i++) {
  6532. var pluginDef = pluginDefs_1[_i];
  6533. this.pluginSystem.add(pluginDef);
  6534. }
  6535. };
  6536. Object.defineProperty(Calendar.prototype, "view", {
  6537. // public API
  6538. get: function () {
  6539. return this.component ? this.component.view : null;
  6540. },
  6541. enumerable: true,
  6542. configurable: true
  6543. });
  6544. // Public API for rendering
  6545. // -----------------------------------------------------------------------------------------------------------------
  6546. Calendar.prototype.render = function () {
  6547. if (!this.component) {
  6548. this.component = new CalendarComponent(this.el);
  6549. this.renderableEventStore = createEmptyEventStore();
  6550. this.bindHandlers();
  6551. this.executeRender();
  6552. }
  6553. else {
  6554. this.requestRerender();
  6555. }
  6556. };
  6557. Calendar.prototype.destroy = function () {
  6558. if (this.component) {
  6559. this.unbindHandlers();
  6560. this.component.destroy(); // don't null-out. in case API needs access
  6561. this.component = null; // umm ???
  6562. for (var _i = 0, _a = this.calendarInteractions; _i < _a.length; _i++) {
  6563. var interaction = _a[_i];
  6564. interaction.destroy();
  6565. }
  6566. this.publiclyTrigger('_destroyed');
  6567. }
  6568. };
  6569. // Handlers
  6570. // -----------------------------------------------------------------------------------------------------------------
  6571. Calendar.prototype.bindHandlers = function () {
  6572. var _this = this;
  6573. // event delegation for nav links
  6574. this.removeNavLinkListener = listenBySelector(this.el, 'click', 'a[data-goto]', function (ev, anchorEl) {
  6575. var gotoOptions = anchorEl.getAttribute('data-goto');
  6576. gotoOptions = gotoOptions ? JSON.parse(gotoOptions) : {};
  6577. var dateEnv = _this.dateEnv;
  6578. var dateMarker = dateEnv.createMarker(gotoOptions.date);
  6579. var viewType = gotoOptions.type;
  6580. // property like "navLinkDayClick". might be a string or a function
  6581. var customAction = _this.viewOpt('navLink' + capitaliseFirstLetter(viewType) + 'Click');
  6582. if (typeof customAction === 'function') {
  6583. customAction(dateEnv.toDate(dateMarker), ev);
  6584. }
  6585. else {
  6586. if (typeof customAction === 'string') {
  6587. viewType = customAction;
  6588. }
  6589. _this.zoomTo(dateMarker, viewType);
  6590. }
  6591. });
  6592. if (this.opt('handleWindowResize')) {
  6593. window.addEventListener('resize', this.windowResizeProxy = debounce(// prevents rapid calls
  6594. this.windowResize.bind(this), this.opt('windowResizeDelay')));
  6595. }
  6596. };
  6597. Calendar.prototype.unbindHandlers = function () {
  6598. this.removeNavLinkListener();
  6599. if (this.windowResizeProxy) {
  6600. window.removeEventListener('resize', this.windowResizeProxy);
  6601. this.windowResizeProxy = null;
  6602. }
  6603. };
  6604. // Dispatcher
  6605. // -----------------------------------------------------------------------------------------------------------------
  6606. Calendar.prototype.hydrate = function () {
  6607. var _this = this;
  6608. this.state = this.buildInitialState();
  6609. var rawSources = this.opt('eventSources') || [];
  6610. var singleRawSource = this.opt('events');
  6611. var sources = []; // parsed
  6612. if (singleRawSource) {
  6613. rawSources.unshift(singleRawSource);
  6614. }
  6615. for (var _i = 0, rawSources_1 = rawSources; _i < rawSources_1.length; _i++) {
  6616. var rawSource = rawSources_1[_i];
  6617. var source = parseEventSource(rawSource, this);
  6618. if (source) {
  6619. sources.push(source);
  6620. }
  6621. }
  6622. this.batchRendering(function () {
  6623. _this.dispatch({ type: 'INIT' }); // pass in sources here?
  6624. _this.dispatch({ type: 'ADD_EVENT_SOURCES', sources: sources });
  6625. _this.dispatch({
  6626. type: 'SET_VIEW_TYPE',
  6627. viewType: _this.opt('defaultView') || _this.pluginSystem.hooks.defaultView
  6628. });
  6629. });
  6630. };
  6631. Calendar.prototype.buildInitialState = function () {
  6632. return {
  6633. viewType: null,
  6634. loadingLevel: 0,
  6635. eventSourceLoadingLevel: 0,
  6636. currentDate: this.getInitialDate(),
  6637. dateProfile: null,
  6638. eventSources: {},
  6639. eventStore: createEmptyEventStore(),
  6640. dateSelection: null,
  6641. eventSelection: '',
  6642. eventDrag: null,
  6643. eventResize: null
  6644. };
  6645. };
  6646. Calendar.prototype.dispatch = function (action) {
  6647. this.actionQueue.push(action);
  6648. if (!this.isReducing) {
  6649. this.isReducing = true;
  6650. var oldState = this.state;
  6651. while (this.actionQueue.length) {
  6652. this.state = this.reduce(this.state, this.actionQueue.shift(), this);
  6653. }
  6654. var newState = this.state;
  6655. this.isReducing = false;
  6656. if (!oldState.loadingLevel && newState.loadingLevel) {
  6657. this.publiclyTrigger('loading', [true]);
  6658. }
  6659. else if (oldState.loadingLevel && !newState.loadingLevel) {
  6660. this.publiclyTrigger('loading', [false]);
  6661. }
  6662. var view = this.component && this.component.view;
  6663. if (oldState.eventStore !== newState.eventStore) {
  6664. if (oldState.eventStore) {
  6665. this.isEventsUpdated = true;
  6666. }
  6667. }
  6668. if (oldState.dateProfile !== newState.dateProfile) {
  6669. if (oldState.dateProfile && view) { // why would view be null!?
  6670. this.publiclyTrigger('datesDestroy', [
  6671. {
  6672. view: view,
  6673. el: view.el
  6674. }
  6675. ]);
  6676. }
  6677. this.isDatesUpdated = true;
  6678. }
  6679. if (oldState.viewType !== newState.viewType) {
  6680. if (oldState.viewType && view) { // why would view be null!?
  6681. this.publiclyTrigger('viewSkeletonDestroy', [
  6682. {
  6683. view: view,
  6684. el: view.el
  6685. }
  6686. ]);
  6687. }
  6688. this.isViewUpdated = true;
  6689. }
  6690. this.requestRerender();
  6691. }
  6692. };
  6693. Calendar.prototype.reduce = function (state, action, calendar) {
  6694. return reduce(state, action, calendar);
  6695. };
  6696. // Render Queue
  6697. // -----------------------------------------------------------------------------------------------------------------
  6698. Calendar.prototype.requestRerender = function () {
  6699. this.needsRerender = true;
  6700. this.delayedRerender(); // will call a debounced-version of tryRerender
  6701. };
  6702. Calendar.prototype.tryRerender = function () {
  6703. if (this.component && // must be accepting renders
  6704. this.needsRerender && // indicates that a rerender was requested
  6705. !this.renderingPauseDepth && // not paused
  6706. !this.isRendering // not currently in the render loop
  6707. ) {
  6708. this.executeRender();
  6709. }
  6710. };
  6711. Calendar.prototype.batchRendering = function (func) {
  6712. this.renderingPauseDepth++;
  6713. func();
  6714. this.renderingPauseDepth--;
  6715. if (this.needsRerender) {
  6716. this.requestRerender();
  6717. }
  6718. };
  6719. // Rendering
  6720. // -----------------------------------------------------------------------------------------------------------------
  6721. Calendar.prototype.executeRender = function () {
  6722. // clear these BEFORE the render so that new values will accumulate during render
  6723. this.needsRerender = false;
  6724. this.isRendering = true;
  6725. this.renderComponent();
  6726. this.isRendering = false;
  6727. // received a rerender request while rendering
  6728. if (this.needsRerender) {
  6729. this.delayedRerender();
  6730. }
  6731. };
  6732. /*
  6733. don't call this directly. use executeRender instead
  6734. */
  6735. Calendar.prototype.renderComponent = function () {
  6736. var _a = this, state = _a.state, component = _a.component;
  6737. var viewType = state.viewType;
  6738. var viewSpec = this.viewSpecs[viewType];
  6739. if (!viewSpec) {
  6740. throw new Error("View type \"" + viewType + "\" is not valid");
  6741. }
  6742. // if event sources are still loading and progressive rendering hasn't been enabled,
  6743. // keep rendering the last fully loaded set of events
  6744. var renderableEventStore = this.renderableEventStore =
  6745. (state.eventSourceLoadingLevel && !this.opt('progressiveEventRendering')) ?
  6746. this.renderableEventStore :
  6747. state.eventStore;
  6748. var eventUiSingleBase = this.buildEventUiSingleBase(viewSpec.options);
  6749. var eventUiBySource = this.buildEventUiBySource(state.eventSources);
  6750. var eventUiBases = this.eventUiBases = this.buildEventUiBases(renderableEventStore.defs, eventUiSingleBase, eventUiBySource);
  6751. component.receiveProps(__assign({}, state, { viewSpec: viewSpec, dateProfileGenerator: this.dateProfileGenerators[viewType], dateProfile: state.dateProfile, eventStore: renderableEventStore, eventUiBases: eventUiBases, dateSelection: state.dateSelection, eventSelection: state.eventSelection, eventDrag: state.eventDrag, eventResize: state.eventResize }), this.buildComponentContext(this.theme, this.dateEnv, this.optionsManager.computed));
  6752. if (this.isViewUpdated) {
  6753. this.isViewUpdated = false;
  6754. this.publiclyTrigger('viewSkeletonRender', [
  6755. {
  6756. view: component.view,
  6757. el: component.view.el
  6758. }
  6759. ]);
  6760. }
  6761. if (this.isDatesUpdated) {
  6762. this.isDatesUpdated = false;
  6763. this.publiclyTrigger('datesRender', [
  6764. {
  6765. view: component.view,
  6766. el: component.view.el
  6767. }
  6768. ]);
  6769. }
  6770. if (this.isEventsUpdated) {
  6771. this.isEventsUpdated = false;
  6772. }
  6773. this.releaseAfterSizingTriggers();
  6774. };
  6775. // Options
  6776. // -----------------------------------------------------------------------------------------------------------------
  6777. Calendar.prototype.setOption = function (name, val) {
  6778. var _a;
  6779. this.mutateOptions((_a = {}, _a[name] = val, _a), [], true);
  6780. };
  6781. Calendar.prototype.getOption = function (name) {
  6782. return this.optionsManager.computed[name];
  6783. };
  6784. Calendar.prototype.opt = function (name) {
  6785. return this.optionsManager.computed[name];
  6786. };
  6787. Calendar.prototype.viewOpt = function (name) {
  6788. return this.viewOpts()[name];
  6789. };
  6790. Calendar.prototype.viewOpts = function () {
  6791. return this.viewSpecs[this.state.viewType].options;
  6792. };
  6793. /*
  6794. handles option changes (like a diff)
  6795. */
  6796. Calendar.prototype.mutateOptions = function (updates, removals, isDynamic, deepEqual) {
  6797. var _this = this;
  6798. var changeHandlers = this.pluginSystem.hooks.optionChangeHandlers;
  6799. var normalUpdates = {};
  6800. var specialUpdates = {};
  6801. var oldDateEnv = this.dateEnv; // do this before handleOptions
  6802. var isTimeZoneDirty = false;
  6803. var isSizeDirty = false;
  6804. var anyDifficultOptions = Boolean(removals.length);
  6805. for (var name_1 in updates) {
  6806. if (changeHandlers[name_1]) {
  6807. specialUpdates[name_1] = updates[name_1];
  6808. }
  6809. else {
  6810. normalUpdates[name_1] = updates[name_1];
  6811. }
  6812. }
  6813. for (var name_2 in normalUpdates) {
  6814. if (/^(height|contentHeight|aspectRatio)$/.test(name_2)) {
  6815. isSizeDirty = true;
  6816. }
  6817. else if (/^(defaultDate|defaultView)$/.test(name_2)) ;
  6818. else {
  6819. anyDifficultOptions = true;
  6820. if (name_2 === 'timeZone') {
  6821. isTimeZoneDirty = true;
  6822. }
  6823. }
  6824. }
  6825. this.optionsManager.mutate(normalUpdates, removals, isDynamic);
  6826. if (anyDifficultOptions) {
  6827. this.handleOptions(this.optionsManager.computed);
  6828. }
  6829. this.batchRendering(function () {
  6830. if (anyDifficultOptions) {
  6831. if (isTimeZoneDirty) {
  6832. _this.dispatch({
  6833. type: 'CHANGE_TIMEZONE',
  6834. oldDateEnv: oldDateEnv
  6835. });
  6836. }
  6837. /* HACK
  6838. has the same effect as calling this.requestRerender()
  6839. but recomputes the state's dateProfile
  6840. */
  6841. _this.dispatch({
  6842. type: 'SET_VIEW_TYPE',
  6843. viewType: _this.state.viewType
  6844. });
  6845. }
  6846. else if (isSizeDirty) {
  6847. _this.updateSize();
  6848. }
  6849. // special updates
  6850. if (deepEqual) {
  6851. for (var name_3 in specialUpdates) {
  6852. changeHandlers[name_3](specialUpdates[name_3], _this, deepEqual);
  6853. }
  6854. }
  6855. });
  6856. };
  6857. /*
  6858. rebuilds things based off of a complete set of refined options
  6859. */
  6860. Calendar.prototype.handleOptions = function (options) {
  6861. var _this = this;
  6862. var pluginHooks = this.pluginSystem.hooks;
  6863. this.defaultAllDayEventDuration = createDuration(options.defaultAllDayEventDuration);
  6864. this.defaultTimedEventDuration = createDuration(options.defaultTimedEventDuration);
  6865. this.delayedRerender = this.buildDelayedRerender(options.rerenderDelay);
  6866. this.theme = this.buildTheme(options);
  6867. var available = this.parseRawLocales(options.locales);
  6868. this.availableRawLocales = available.map;
  6869. var locale = this.buildLocale(options.locale || available.defaultCode, available.map);
  6870. this.dateEnv = this.buildDateEnv(locale, options.timeZone, pluginHooks.namedTimeZonedImpl, options.firstDay, options.weekNumberCalculation, options.weekLabel, pluginHooks.cmdFormatter);
  6871. this.selectionConfig = this.buildSelectionConfig(options); // needs dateEnv. do after :(
  6872. // ineffecient to do every time?
  6873. this.viewSpecs = buildViewSpecs(pluginHooks.views, this.optionsManager);
  6874. // ineffecient to do every time?
  6875. this.dateProfileGenerators = mapHash(this.viewSpecs, function (viewSpec) {
  6876. return new viewSpec.class.prototype.dateProfileGeneratorClass(viewSpec, _this);
  6877. });
  6878. };
  6879. Calendar.prototype.getAvailableLocaleCodes = function () {
  6880. return Object.keys(this.availableRawLocales);
  6881. };
  6882. Calendar.prototype._buildSelectionConfig = function (rawOpts) {
  6883. return processScopedUiProps('select', rawOpts, this);
  6884. };
  6885. Calendar.prototype._buildEventUiSingleBase = function (rawOpts) {
  6886. if (rawOpts.editable) { // so 'editable' affected events
  6887. rawOpts = __assign({}, rawOpts, { eventEditable: true });
  6888. }
  6889. return processScopedUiProps('event', rawOpts, this);
  6890. };
  6891. // Trigger
  6892. // -----------------------------------------------------------------------------------------------------------------
  6893. Calendar.prototype.hasPublicHandlers = function (name) {
  6894. return this.hasHandlers(name) ||
  6895. this.opt(name); // handler specified in options
  6896. };
  6897. Calendar.prototype.publiclyTrigger = function (name, args) {
  6898. var optHandler = this.opt(name);
  6899. this.triggerWith(name, this, args);
  6900. if (optHandler) {
  6901. return optHandler.apply(this, args);
  6902. }
  6903. };
  6904. Calendar.prototype.publiclyTriggerAfterSizing = function (name, args) {
  6905. var afterSizingTriggers = this.afterSizingTriggers;
  6906. (afterSizingTriggers[name] || (afterSizingTriggers[name] = [])).push(args);
  6907. };
  6908. Calendar.prototype.releaseAfterSizingTriggers = function () {
  6909. var afterSizingTriggers = this.afterSizingTriggers;
  6910. for (var name_4 in afterSizingTriggers) {
  6911. for (var _i = 0, _a = afterSizingTriggers[name_4]; _i < _a.length; _i++) {
  6912. var args = _a[_i];
  6913. this.publiclyTrigger(name_4, args);
  6914. }
  6915. }
  6916. this.afterSizingTriggers = {};
  6917. };
  6918. // View
  6919. // -----------------------------------------------------------------------------------------------------------------
  6920. // Returns a boolean about whether the view is okay to instantiate at some point
  6921. Calendar.prototype.isValidViewType = function (viewType) {
  6922. return Boolean(this.viewSpecs[viewType]);
  6923. };
  6924. Calendar.prototype.changeView = function (viewType, dateOrRange) {
  6925. var dateMarker = null;
  6926. if (dateOrRange) {
  6927. if (dateOrRange.start && dateOrRange.end) { // a range
  6928. this.optionsManager.mutate({ visibleRange: dateOrRange }, []); // will not rerender
  6929. this.handleOptions(this.optionsManager.computed); // ...but yuck
  6930. }
  6931. else { // a date
  6932. dateMarker = this.dateEnv.createMarker(dateOrRange); // just like gotoDate
  6933. }
  6934. }
  6935. this.unselect();
  6936. this.dispatch({
  6937. type: 'SET_VIEW_TYPE',
  6938. viewType: viewType,
  6939. dateMarker: dateMarker
  6940. });
  6941. };
  6942. // Forces navigation to a view for the given date.
  6943. // `viewType` can be a specific view name or a generic one like "week" or "day".
  6944. // needs to change
  6945. Calendar.prototype.zoomTo = function (dateMarker, viewType) {
  6946. var spec;
  6947. viewType = viewType || 'day'; // day is default zoom
  6948. spec = this.viewSpecs[viewType] ||
  6949. this.getUnitViewSpec(viewType);
  6950. this.unselect();
  6951. if (spec) {
  6952. this.dispatch({
  6953. type: 'SET_VIEW_TYPE',
  6954. viewType: spec.type,
  6955. dateMarker: dateMarker
  6956. });
  6957. }
  6958. else {
  6959. this.dispatch({
  6960. type: 'SET_DATE',
  6961. dateMarker: dateMarker
  6962. });
  6963. }
  6964. };
  6965. // Given a duration singular unit, like "week" or "day", finds a matching view spec.
  6966. // Preference is given to views that have corresponding buttons.
  6967. Calendar.prototype.getUnitViewSpec = function (unit) {
  6968. var component = this.component;
  6969. var viewTypes = [];
  6970. var i;
  6971. var spec;
  6972. // put views that have buttons first. there will be duplicates, but oh
  6973. if (component.header) {
  6974. viewTypes.push.apply(viewTypes, component.header.viewsWithButtons);
  6975. }
  6976. if (component.footer) {
  6977. viewTypes.push.apply(viewTypes, component.footer.viewsWithButtons);
  6978. }
  6979. for (var viewType in this.viewSpecs) {
  6980. viewTypes.push(viewType);
  6981. }
  6982. for (i = 0; i < viewTypes.length; i++) {
  6983. spec = this.viewSpecs[viewTypes[i]];
  6984. if (spec) {
  6985. if (spec.singleUnit === unit) {
  6986. return spec;
  6987. }
  6988. }
  6989. }
  6990. };
  6991. // Current Date
  6992. // -----------------------------------------------------------------------------------------------------------------
  6993. Calendar.prototype.getInitialDate = function () {
  6994. var defaultDateInput = this.opt('defaultDate');
  6995. // compute the initial ambig-timezone date
  6996. if (defaultDateInput != null) {
  6997. return this.dateEnv.createMarker(defaultDateInput);
  6998. }
  6999. else {
  7000. return this.getNow(); // getNow already returns unzoned
  7001. }
  7002. };
  7003. Calendar.prototype.prev = function () {
  7004. this.unselect();
  7005. this.dispatch({ type: 'PREV' });
  7006. };
  7007. Calendar.prototype.next = function () {
  7008. this.unselect();
  7009. this.dispatch({ type: 'NEXT' });
  7010. };
  7011. Calendar.prototype.prevYear = function () {
  7012. this.unselect();
  7013. this.dispatch({
  7014. type: 'SET_DATE',
  7015. dateMarker: this.dateEnv.addYears(this.state.currentDate, -1)
  7016. });
  7017. };
  7018. Calendar.prototype.nextYear = function () {
  7019. this.unselect();
  7020. this.dispatch({
  7021. type: 'SET_DATE',
  7022. dateMarker: this.dateEnv.addYears(this.state.currentDate, 1)
  7023. });
  7024. };
  7025. Calendar.prototype.today = function () {
  7026. this.unselect();
  7027. this.dispatch({
  7028. type: 'SET_DATE',
  7029. dateMarker: this.getNow()
  7030. });
  7031. };
  7032. Calendar.prototype.gotoDate = function (zonedDateInput) {
  7033. this.unselect();
  7034. this.dispatch({
  7035. type: 'SET_DATE',
  7036. dateMarker: this.dateEnv.createMarker(zonedDateInput)
  7037. });
  7038. };
  7039. Calendar.prototype.incrementDate = function (deltaInput) {
  7040. var delta = createDuration(deltaInput);
  7041. if (delta) { // else, warn about invalid input?
  7042. this.unselect();
  7043. this.dispatch({
  7044. type: 'SET_DATE',
  7045. dateMarker: this.dateEnv.add(this.state.currentDate, delta)
  7046. });
  7047. }
  7048. };
  7049. // for external API
  7050. Calendar.prototype.getDate = function () {
  7051. return this.dateEnv.toDate(this.state.currentDate);
  7052. };
  7053. // Date Formatting Utils
  7054. // -----------------------------------------------------------------------------------------------------------------
  7055. Calendar.prototype.formatDate = function (d, formatter) {
  7056. var dateEnv = this.dateEnv;
  7057. return dateEnv.format(dateEnv.createMarker(d), createFormatter(formatter));
  7058. };
  7059. // `settings` is for formatter AND isEndExclusive
  7060. Calendar.prototype.formatRange = function (d0, d1, settings) {
  7061. var dateEnv = this.dateEnv;
  7062. return dateEnv.formatRange(dateEnv.createMarker(d0), dateEnv.createMarker(d1), createFormatter(settings, this.opt('defaultRangeSeparator')), settings);
  7063. };
  7064. Calendar.prototype.formatIso = function (d, omitTime) {
  7065. var dateEnv = this.dateEnv;
  7066. return dateEnv.formatIso(dateEnv.createMarker(d), { omitTime: omitTime });
  7067. };
  7068. // Sizing
  7069. // -----------------------------------------------------------------------------------------------------------------
  7070. Calendar.prototype.windowResize = function (ev) {
  7071. if (!this.isHandlingWindowResize &&
  7072. this.component && // why?
  7073. ev.target === window // not a jqui resize event
  7074. ) {
  7075. this.isHandlingWindowResize = true;
  7076. this.updateSize();
  7077. this.publiclyTrigger('windowResize', [this.view]);
  7078. this.isHandlingWindowResize = false;
  7079. }
  7080. };
  7081. Calendar.prototype.updateSize = function () {
  7082. if (this.component) { // when?
  7083. this.component.updateSize(true);
  7084. }
  7085. };
  7086. // Component Registration
  7087. // -----------------------------------------------------------------------------------------------------------------
  7088. Calendar.prototype.registerInteractiveComponent = function (component, settingsInput) {
  7089. var settings = parseInteractionSettings(component, settingsInput);
  7090. var DEFAULT_INTERACTIONS = [
  7091. EventClicking,
  7092. EventHovering
  7093. ];
  7094. var interactionClasses = DEFAULT_INTERACTIONS.concat(this.pluginSystem.hooks.componentInteractions);
  7095. var interactions = interactionClasses.map(function (interactionClass) {
  7096. return new interactionClass(settings);
  7097. });
  7098. this.interactionsStore[component.uid] = interactions;
  7099. interactionSettingsStore[component.uid] = settings;
  7100. };
  7101. Calendar.prototype.unregisterInteractiveComponent = function (component) {
  7102. for (var _i = 0, _a = this.interactionsStore[component.uid]; _i < _a.length; _i++) {
  7103. var listener = _a[_i];
  7104. listener.destroy();
  7105. }
  7106. delete this.interactionsStore[component.uid];
  7107. delete interactionSettingsStore[component.uid];
  7108. };
  7109. // Date Selection / Event Selection / DayClick
  7110. // -----------------------------------------------------------------------------------------------------------------
  7111. // this public method receives start/end dates in any format, with any timezone
  7112. // NOTE: args were changed from v3
  7113. Calendar.prototype.select = function (dateOrObj, endDate) {
  7114. var selectionInput;
  7115. if (endDate == null) {
  7116. if (dateOrObj.start != null) {
  7117. selectionInput = dateOrObj;
  7118. }
  7119. else {
  7120. selectionInput = {
  7121. start: dateOrObj,
  7122. end: null
  7123. };
  7124. }
  7125. }
  7126. else {
  7127. selectionInput = {
  7128. start: dateOrObj,
  7129. end: endDate
  7130. };
  7131. }
  7132. var selection = parseDateSpan(selectionInput, this.dateEnv, createDuration({ days: 1 }) // TODO: cache this?
  7133. );
  7134. if (selection) { // throw parse error otherwise?
  7135. this.dispatch({ type: 'SELECT_DATES', selection: selection });
  7136. this.triggerDateSelect(selection);
  7137. }
  7138. };
  7139. // public method
  7140. Calendar.prototype.unselect = function (pev) {
  7141. if (this.state.dateSelection) {
  7142. this.dispatch({ type: 'UNSELECT_DATES' });
  7143. this.triggerDateUnselect(pev);
  7144. }
  7145. };
  7146. Calendar.prototype.triggerDateSelect = function (selection, pev) {
  7147. var arg = __assign({}, this.buildDateSpanApi(selection), { jsEvent: pev ? pev.origEvent : null, view: this.view });
  7148. this.publiclyTrigger('select', [arg]);
  7149. };
  7150. Calendar.prototype.triggerDateUnselect = function (pev) {
  7151. this.publiclyTrigger('unselect', [
  7152. {
  7153. jsEvent: pev ? pev.origEvent : null,
  7154. view: this.view
  7155. }
  7156. ]);
  7157. };
  7158. // TODO: receive pev?
  7159. Calendar.prototype.triggerDateClick = function (dateSpan, dayEl, view, ev) {
  7160. var arg = __assign({}, this.buildDatePointApi(dateSpan), { dayEl: dayEl, jsEvent: ev, // Is this always a mouse event? See #4655
  7161. view: view });
  7162. this.publiclyTrigger('dateClick', [arg]);
  7163. };
  7164. Calendar.prototype.buildDatePointApi = function (dateSpan) {
  7165. var props = {};
  7166. for (var _i = 0, _a = this.pluginSystem.hooks.datePointTransforms; _i < _a.length; _i++) {
  7167. var transform = _a[_i];
  7168. __assign(props, transform(dateSpan, this));
  7169. }
  7170. __assign(props, buildDatePointApi(dateSpan, this.dateEnv));
  7171. return props;
  7172. };
  7173. Calendar.prototype.buildDateSpanApi = function (dateSpan) {
  7174. var props = {};
  7175. for (var _i = 0, _a = this.pluginSystem.hooks.dateSpanTransforms; _i < _a.length; _i++) {
  7176. var transform = _a[_i];
  7177. __assign(props, transform(dateSpan, this));
  7178. }
  7179. __assign(props, buildDateSpanApi(dateSpan, this.dateEnv));
  7180. return props;
  7181. };
  7182. // Date Utils
  7183. // -----------------------------------------------------------------------------------------------------------------
  7184. // Returns a DateMarker for the current date, as defined by the client's computer or from the `now` option
  7185. Calendar.prototype.getNow = function () {
  7186. var now = this.opt('now');
  7187. if (typeof now === 'function') {
  7188. now = now();
  7189. }
  7190. if (now == null) {
  7191. return this.dateEnv.createNowMarker();
  7192. }
  7193. return this.dateEnv.createMarker(now);
  7194. };
  7195. // Event-Date Utilities
  7196. // -----------------------------------------------------------------------------------------------------------------
  7197. // Given an event's allDay status and start date, return what its fallback end date should be.
  7198. // TODO: rename to computeDefaultEventEnd
  7199. Calendar.prototype.getDefaultEventEnd = function (allDay, marker) {
  7200. var end = marker;
  7201. if (allDay) {
  7202. end = startOfDay(end);
  7203. end = this.dateEnv.add(end, this.defaultAllDayEventDuration);
  7204. }
  7205. else {
  7206. end = this.dateEnv.add(end, this.defaultTimedEventDuration);
  7207. }
  7208. return end;
  7209. };
  7210. // Public Events API
  7211. // -----------------------------------------------------------------------------------------------------------------
  7212. Calendar.prototype.addEvent = function (eventInput, sourceInput) {
  7213. if (eventInput instanceof EventApi) {
  7214. var def = eventInput._def;
  7215. var instance = eventInput._instance;
  7216. // not already present? don't want to add an old snapshot
  7217. if (!this.state.eventStore.defs[def.defId]) {
  7218. this.dispatch({
  7219. type: 'ADD_EVENTS',
  7220. eventStore: eventTupleToStore({ def: def, instance: instance }) // TODO: better util for two args?
  7221. });
  7222. }
  7223. return eventInput;
  7224. }
  7225. var sourceId;
  7226. if (sourceInput instanceof EventSourceApi) {
  7227. sourceId = sourceInput.internalEventSource.sourceId;
  7228. }
  7229. else if (sourceInput != null) {
  7230. var sourceApi = this.getEventSourceById(sourceInput); // TODO: use an internal function
  7231. if (!sourceApi) {
  7232. console.warn('Could not find an event source with ID "' + sourceInput + '"'); // TODO: test
  7233. return null;
  7234. }
  7235. else {
  7236. sourceId = sourceApi.internalEventSource.sourceId;
  7237. }
  7238. }
  7239. var tuple = parseEvent(eventInput, sourceId, this);
  7240. if (tuple) {
  7241. this.dispatch({
  7242. type: 'ADD_EVENTS',
  7243. eventStore: eventTupleToStore(tuple)
  7244. });
  7245. return new EventApi(this, tuple.def, tuple.def.recurringDef ? null : tuple.instance);
  7246. }
  7247. return null;
  7248. };
  7249. // TODO: optimize
  7250. Calendar.prototype.getEventById = function (id) {
  7251. var _a = this.state.eventStore, defs = _a.defs, instances = _a.instances;
  7252. id = String(id);
  7253. for (var defId in defs) {
  7254. var def = defs[defId];
  7255. if (def.publicId === id) {
  7256. if (def.recurringDef) {
  7257. return new EventApi(this, def, null);
  7258. }
  7259. else {
  7260. for (var instanceId in instances) {
  7261. var instance = instances[instanceId];
  7262. if (instance.defId === def.defId) {
  7263. return new EventApi(this, def, instance);
  7264. }
  7265. }
  7266. }
  7267. }
  7268. }
  7269. return null;
  7270. };
  7271. Calendar.prototype.getEvents = function () {
  7272. var _a = this.state.eventStore, defs = _a.defs, instances = _a.instances;
  7273. var eventApis = [];
  7274. for (var id in instances) {
  7275. var instance = instances[id];
  7276. var def = defs[instance.defId];
  7277. eventApis.push(new EventApi(this, def, instance));
  7278. }
  7279. return eventApis;
  7280. };
  7281. Calendar.prototype.removeAllEvents = function () {
  7282. this.dispatch({ type: 'REMOVE_ALL_EVENTS' });
  7283. };
  7284. Calendar.prototype.rerenderEvents = function () {
  7285. this.dispatch({ type: 'RESET_EVENTS' });
  7286. };
  7287. // Public Event Sources API
  7288. // -----------------------------------------------------------------------------------------------------------------
  7289. Calendar.prototype.getEventSources = function () {
  7290. var sourceHash = this.state.eventSources;
  7291. var sourceApis = [];
  7292. for (var internalId in sourceHash) {
  7293. sourceApis.push(new EventSourceApi(this, sourceHash[internalId]));
  7294. }
  7295. return sourceApis;
  7296. };
  7297. Calendar.prototype.getEventSourceById = function (id) {
  7298. var sourceHash = this.state.eventSources;
  7299. id = String(id);
  7300. for (var sourceId in sourceHash) {
  7301. if (sourceHash[sourceId].publicId === id) {
  7302. return new EventSourceApi(this, sourceHash[sourceId]);
  7303. }
  7304. }
  7305. return null;
  7306. };
  7307. Calendar.prototype.addEventSource = function (sourceInput) {
  7308. if (sourceInput instanceof EventSourceApi) {
  7309. // not already present? don't want to add an old snapshot
  7310. if (!this.state.eventSources[sourceInput.internalEventSource.sourceId]) {
  7311. this.dispatch({
  7312. type: 'ADD_EVENT_SOURCES',
  7313. sources: [sourceInput.internalEventSource]
  7314. });
  7315. }
  7316. return sourceInput;
  7317. }
  7318. var eventSource = parseEventSource(sourceInput, this);
  7319. if (eventSource) { // TODO: error otherwise?
  7320. this.dispatch({ type: 'ADD_EVENT_SOURCES', sources: [eventSource] });
  7321. return new EventSourceApi(this, eventSource);
  7322. }
  7323. return null;
  7324. };
  7325. Calendar.prototype.removeAllEventSources = function () {
  7326. this.dispatch({ type: 'REMOVE_ALL_EVENT_SOURCES' });
  7327. };
  7328. Calendar.prototype.refetchEvents = function () {
  7329. this.dispatch({ type: 'FETCH_EVENT_SOURCES' });
  7330. };
  7331. // Scroll
  7332. // -----------------------------------------------------------------------------------------------------------------
  7333. Calendar.prototype.scrollToTime = function (timeInput) {
  7334. var duration = createDuration(timeInput);
  7335. if (duration) {
  7336. this.component.view.scrollToDuration(duration);
  7337. }
  7338. };
  7339. return Calendar;
  7340. }());
  7341. EmitterMixin.mixInto(Calendar);
  7342. // for memoizers
  7343. // -----------------------------------------------------------------------------------------------------------------
  7344. function buildComponentContext$1(theme, dateEnv, options) {
  7345. return new ComponentContext(this, theme, dateEnv, options, null);
  7346. }
  7347. function buildDateEnv(locale, timeZone, namedTimeZoneImpl, firstDay, weekNumberCalculation, weekLabel, cmdFormatter) {
  7348. return new DateEnv({
  7349. calendarSystem: 'gregory',
  7350. timeZone: timeZone,
  7351. namedTimeZoneImpl: namedTimeZoneImpl,
  7352. locale: locale,
  7353. weekNumberCalculation: weekNumberCalculation,
  7354. firstDay: firstDay,
  7355. weekLabel: weekLabel,
  7356. cmdFormatter: cmdFormatter
  7357. });
  7358. }
  7359. function buildTheme(calendarOptions) {
  7360. var themeClass = this.pluginSystem.hooks.themeClasses[calendarOptions.themeSystem] || StandardTheme;
  7361. return new themeClass(calendarOptions);
  7362. }
  7363. function buildDelayedRerender(wait) {
  7364. var func = this.tryRerender.bind(this);
  7365. if (wait != null) {
  7366. func = debounce(func, wait);
  7367. }
  7368. return func;
  7369. }
  7370. function buildEventUiBySource(eventSources) {
  7371. return mapHash(eventSources, function (eventSource) {
  7372. return eventSource.ui;
  7373. });
  7374. }
  7375. function buildEventUiBases(eventDefs, eventUiSingleBase, eventUiBySource) {
  7376. var eventUiBases = { '': eventUiSingleBase };
  7377. for (var defId in eventDefs) {
  7378. var def = eventDefs[defId];
  7379. if (def.sourceId && eventUiBySource[def.sourceId]) {
  7380. eventUiBases[defId] = eventUiBySource[def.sourceId];
  7381. }
  7382. }
  7383. return eventUiBases;
  7384. }
  7385. var View = /** @class */ (function (_super) {
  7386. __extends(View, _super);
  7387. function View(viewSpec, parentEl) {
  7388. var _this = _super.call(this, createElement('div', { className: 'fc-view fc-' + viewSpec.type + '-view' })) || this;
  7389. _this.renderDatesMem = memoizeRendering(_this.renderDatesWrap, _this.unrenderDatesWrap);
  7390. _this.renderBusinessHoursMem = memoizeRendering(_this.renderBusinessHours, _this.unrenderBusinessHours, [_this.renderDatesMem]);
  7391. _this.renderDateSelectionMem = memoizeRendering(_this.renderDateSelectionWrap, _this.unrenderDateSelectionWrap, [_this.renderDatesMem]);
  7392. _this.renderEventsMem = memoizeRendering(_this.renderEvents, _this.unrenderEvents, [_this.renderDatesMem]);
  7393. _this.renderEventSelectionMem = memoizeRendering(_this.renderEventSelectionWrap, _this.unrenderEventSelectionWrap, [_this.renderEventsMem]);
  7394. _this.renderEventDragMem = memoizeRendering(_this.renderEventDragWrap, _this.unrenderEventDragWrap, [_this.renderDatesMem]);
  7395. _this.renderEventResizeMem = memoizeRendering(_this.renderEventResizeWrap, _this.unrenderEventResizeWrap, [_this.renderDatesMem]);
  7396. _this.viewSpec = viewSpec;
  7397. _this.type = viewSpec.type;
  7398. parentEl.appendChild(_this.el);
  7399. _this.initialize();
  7400. return _this;
  7401. }
  7402. View.prototype.initialize = function () {
  7403. };
  7404. Object.defineProperty(View.prototype, "activeStart", {
  7405. // Date Setting/Unsetting
  7406. // -----------------------------------------------------------------------------------------------------------------
  7407. get: function () {
  7408. return this.context.dateEnv.toDate(this.props.dateProfile.activeRange.start);
  7409. },
  7410. enumerable: true,
  7411. configurable: true
  7412. });
  7413. Object.defineProperty(View.prototype, "activeEnd", {
  7414. get: function () {
  7415. return this.context.dateEnv.toDate(this.props.dateProfile.activeRange.end);
  7416. },
  7417. enumerable: true,
  7418. configurable: true
  7419. });
  7420. Object.defineProperty(View.prototype, "currentStart", {
  7421. get: function () {
  7422. return this.context.dateEnv.toDate(this.props.dateProfile.currentRange.start);
  7423. },
  7424. enumerable: true,
  7425. configurable: true
  7426. });
  7427. Object.defineProperty(View.prototype, "currentEnd", {
  7428. get: function () {
  7429. return this.context.dateEnv.toDate(this.props.dateProfile.currentRange.end);
  7430. },
  7431. enumerable: true,
  7432. configurable: true
  7433. });
  7434. // General Rendering
  7435. // -----------------------------------------------------------------------------------------------------------------
  7436. View.prototype.render = function (props, context) {
  7437. this.renderDatesMem(props.dateProfile);
  7438. this.renderBusinessHoursMem(props.businessHours);
  7439. this.renderDateSelectionMem(props.dateSelection);
  7440. this.renderEventsMem(props.eventStore);
  7441. this.renderEventSelectionMem(props.eventSelection);
  7442. this.renderEventDragMem(props.eventDrag);
  7443. this.renderEventResizeMem(props.eventResize);
  7444. };
  7445. View.prototype.beforeUpdate = function () {
  7446. this.addScroll(this.queryScroll());
  7447. };
  7448. View.prototype.destroy = function () {
  7449. _super.prototype.destroy.call(this);
  7450. this.renderDatesMem.unrender(); // should unrender everything else
  7451. };
  7452. // Sizing
  7453. // -----------------------------------------------------------------------------------------------------------------
  7454. View.prototype.updateSize = function (isResize, viewHeight, isAuto) {
  7455. var calendar = this.context.calendar;
  7456. if (isResize) {
  7457. this.addScroll(this.queryScroll()); // NOTE: same code as in beforeUpdate
  7458. }
  7459. if (isResize || // HACKS...
  7460. calendar.isViewUpdated ||
  7461. calendar.isDatesUpdated ||
  7462. calendar.isEventsUpdated) {
  7463. // sort of the catch-all sizing
  7464. // anything that might cause dimension changes
  7465. this.updateBaseSize(isResize, viewHeight, isAuto);
  7466. }
  7467. // NOTE: popScroll is called by CalendarComponent
  7468. };
  7469. View.prototype.updateBaseSize = function (isResize, viewHeight, isAuto) {
  7470. };
  7471. // Date Rendering
  7472. // -----------------------------------------------------------------------------------------------------------------
  7473. View.prototype.renderDatesWrap = function (dateProfile) {
  7474. this.renderDates(dateProfile);
  7475. this.addScroll({
  7476. duration: createDuration(this.context.options.scrollTime)
  7477. });
  7478. };
  7479. View.prototype.unrenderDatesWrap = function () {
  7480. this.stopNowIndicator();
  7481. this.unrenderDates();
  7482. };
  7483. View.prototype.renderDates = function (dateProfile) { };
  7484. View.prototype.unrenderDates = function () { };
  7485. // Business Hours
  7486. // -----------------------------------------------------------------------------------------------------------------
  7487. View.prototype.renderBusinessHours = function (businessHours) { };
  7488. View.prototype.unrenderBusinessHours = function () { };
  7489. // Date Selection
  7490. // -----------------------------------------------------------------------------------------------------------------
  7491. View.prototype.renderDateSelectionWrap = function (selection) {
  7492. if (selection) {
  7493. this.renderDateSelection(selection);
  7494. }
  7495. };
  7496. View.prototype.unrenderDateSelectionWrap = function (selection) {
  7497. if (selection) {
  7498. this.unrenderDateSelection(selection);
  7499. }
  7500. };
  7501. View.prototype.renderDateSelection = function (selection) { };
  7502. View.prototype.unrenderDateSelection = function (selection) { };
  7503. // Event Rendering
  7504. // -----------------------------------------------------------------------------------------------------------------
  7505. View.prototype.renderEvents = function (eventStore) { };
  7506. View.prototype.unrenderEvents = function () { };
  7507. // util for subclasses
  7508. View.prototype.sliceEvents = function (eventStore, allDay) {
  7509. var props = this.props;
  7510. return sliceEventStore(eventStore, props.eventUiBases, props.dateProfile.activeRange, allDay ? this.context.nextDayThreshold : null).fg;
  7511. };
  7512. // Event Selection
  7513. // -----------------------------------------------------------------------------------------------------------------
  7514. View.prototype.renderEventSelectionWrap = function (instanceId) {
  7515. if (instanceId) {
  7516. this.renderEventSelection(instanceId);
  7517. }
  7518. };
  7519. View.prototype.unrenderEventSelectionWrap = function (instanceId) {
  7520. if (instanceId) {
  7521. this.unrenderEventSelection(instanceId);
  7522. }
  7523. };
  7524. View.prototype.renderEventSelection = function (instanceId) { };
  7525. View.prototype.unrenderEventSelection = function (instanceId) { };
  7526. // Event Drag
  7527. // -----------------------------------------------------------------------------------------------------------------
  7528. View.prototype.renderEventDragWrap = function (state) {
  7529. if (state) {
  7530. this.renderEventDrag(state);
  7531. }
  7532. };
  7533. View.prototype.unrenderEventDragWrap = function (state) {
  7534. if (state) {
  7535. this.unrenderEventDrag(state);
  7536. }
  7537. };
  7538. View.prototype.renderEventDrag = function (state) { };
  7539. View.prototype.unrenderEventDrag = function (state) { };
  7540. // Event Resize
  7541. // -----------------------------------------------------------------------------------------------------------------
  7542. View.prototype.renderEventResizeWrap = function (state) {
  7543. if (state) {
  7544. this.renderEventResize(state);
  7545. }
  7546. };
  7547. View.prototype.unrenderEventResizeWrap = function (state) {
  7548. if (state) {
  7549. this.unrenderEventResize(state);
  7550. }
  7551. };
  7552. View.prototype.renderEventResize = function (state) { };
  7553. View.prototype.unrenderEventResize = function (state) { };
  7554. /* Now Indicator
  7555. ------------------------------------------------------------------------------------------------------------------*/
  7556. // Immediately render the current time indicator and begins re-rendering it at an interval,
  7557. // which is defined by this.getNowIndicatorUnit().
  7558. // TODO: somehow do this for the current whole day's background too
  7559. // USAGE: must be called manually from subclasses' render methods! don't need to call stopNowIndicator tho
  7560. View.prototype.startNowIndicator = function (dateProfile, dateProfileGenerator) {
  7561. var _this = this;
  7562. var _a = this.context, calendar = _a.calendar, dateEnv = _a.dateEnv, options = _a.options;
  7563. var unit;
  7564. var update;
  7565. var delay; // ms wait value
  7566. if (options.nowIndicator && !this.initialNowDate) {
  7567. unit = this.getNowIndicatorUnit(dateProfile, dateProfileGenerator);
  7568. if (unit) {
  7569. update = this.updateNowIndicator.bind(this);
  7570. this.initialNowDate = calendar.getNow();
  7571. this.initialNowQueriedMs = new Date().valueOf();
  7572. // wait until the beginning of the next interval
  7573. delay = dateEnv.add(dateEnv.startOf(this.initialNowDate, unit), createDuration(1, unit)).valueOf() - this.initialNowDate.valueOf();
  7574. // TODO: maybe always use setTimeout, waiting until start of next unit
  7575. this.nowIndicatorTimeoutID = setTimeout(function () {
  7576. _this.nowIndicatorTimeoutID = null;
  7577. update();
  7578. if (unit === 'second') {
  7579. delay = 1000; // every second
  7580. }
  7581. else {
  7582. delay = 1000 * 60; // otherwise, every minute
  7583. }
  7584. _this.nowIndicatorIntervalID = setInterval(update, delay); // update every interval
  7585. }, delay);
  7586. }
  7587. // rendering will be initiated in updateSize
  7588. }
  7589. };
  7590. // rerenders the now indicator, computing the new current time from the amount of time that has passed
  7591. // since the initial getNow call.
  7592. View.prototype.updateNowIndicator = function () {
  7593. if (this.props.dateProfile && // a way to determine if dates were rendered yet
  7594. this.initialNowDate // activated before?
  7595. ) {
  7596. this.unrenderNowIndicator(); // won't unrender if unnecessary
  7597. this.renderNowIndicator(addMs(this.initialNowDate, new Date().valueOf() - this.initialNowQueriedMs));
  7598. this.isNowIndicatorRendered = true;
  7599. }
  7600. };
  7601. // Immediately unrenders the view's current time indicator and stops any re-rendering timers.
  7602. // Won't cause side effects if indicator isn't rendered.
  7603. View.prototype.stopNowIndicator = function () {
  7604. if (this.nowIndicatorTimeoutID) {
  7605. clearTimeout(this.nowIndicatorTimeoutID);
  7606. this.nowIndicatorTimeoutID = null;
  7607. }
  7608. if (this.nowIndicatorIntervalID) {
  7609. clearInterval(this.nowIndicatorIntervalID);
  7610. this.nowIndicatorIntervalID = null;
  7611. }
  7612. if (this.isNowIndicatorRendered) {
  7613. this.unrenderNowIndicator();
  7614. this.isNowIndicatorRendered = false;
  7615. }
  7616. };
  7617. View.prototype.getNowIndicatorUnit = function (dateProfile, dateProfileGenerator) {
  7618. // subclasses should implement
  7619. };
  7620. // Renders a current time indicator at the given datetime
  7621. View.prototype.renderNowIndicator = function (date) {
  7622. // SUBCLASSES MUST PASS TO CHILDREN!
  7623. };
  7624. // Undoes the rendering actions from renderNowIndicator
  7625. View.prototype.unrenderNowIndicator = function () {
  7626. // SUBCLASSES MUST PASS TO CHILDREN!
  7627. };
  7628. /* Scroller
  7629. ------------------------------------------------------------------------------------------------------------------*/
  7630. View.prototype.addScroll = function (scroll, isForced) {
  7631. if (isForced) {
  7632. scroll.isForced = isForced;
  7633. }
  7634. __assign(this.queuedScroll || (this.queuedScroll = {}), scroll);
  7635. };
  7636. View.prototype.popScroll = function (isResize) {
  7637. this.applyQueuedScroll(isResize);
  7638. this.queuedScroll = null;
  7639. };
  7640. View.prototype.applyQueuedScroll = function (isResize) {
  7641. if (this.queuedScroll) {
  7642. this.applyScroll(this.queuedScroll, isResize);
  7643. }
  7644. };
  7645. View.prototype.queryScroll = function () {
  7646. var scroll = {};
  7647. if (this.props.dateProfile) { // dates rendered yet?
  7648. __assign(scroll, this.queryDateScroll());
  7649. }
  7650. return scroll;
  7651. };
  7652. View.prototype.applyScroll = function (scroll, isResize) {
  7653. var duration = scroll.duration, isForced = scroll.isForced;
  7654. if (duration != null && !isForced) {
  7655. delete scroll.duration;
  7656. if (this.props.dateProfile) { // dates rendered yet?
  7657. __assign(scroll, this.computeDateScroll(duration));
  7658. }
  7659. }
  7660. if (this.props.dateProfile) { // dates rendered yet?
  7661. this.applyDateScroll(scroll);
  7662. }
  7663. };
  7664. View.prototype.computeDateScroll = function (duration) {
  7665. return {}; // subclasses must implement
  7666. };
  7667. View.prototype.queryDateScroll = function () {
  7668. return {}; // subclasses must implement
  7669. };
  7670. View.prototype.applyDateScroll = function (scroll) {
  7671. // subclasses must implement
  7672. };
  7673. // for API
  7674. View.prototype.scrollToDuration = function (duration) {
  7675. this.applyScroll({ duration: duration }, false);
  7676. };
  7677. return View;
  7678. }(DateComponent));
  7679. EmitterMixin.mixInto(View);
  7680. View.prototype.usesMinMaxTime = false;
  7681. View.prototype.dateProfileGeneratorClass = DateProfileGenerator;
  7682. var FgEventRenderer = /** @class */ (function () {
  7683. function FgEventRenderer() {
  7684. this.segs = [];
  7685. this.isSizeDirty = false;
  7686. }
  7687. FgEventRenderer.prototype.renderSegs = function (context, segs, mirrorInfo) {
  7688. this.context = context;
  7689. this.rangeUpdated(); // called too frequently :(
  7690. // render an `.el` on each seg
  7691. // returns a subset of the segs. segs that were actually rendered
  7692. segs = this.renderSegEls(segs, mirrorInfo);
  7693. this.segs = segs;
  7694. this.attachSegs(segs, mirrorInfo);
  7695. this.isSizeDirty = true;
  7696. triggerRenderedSegs(this.context, this.segs, Boolean(mirrorInfo));
  7697. };
  7698. FgEventRenderer.prototype.unrender = function (context, _segs, mirrorInfo) {
  7699. triggerWillRemoveSegs(this.context, this.segs, Boolean(mirrorInfo));
  7700. this.detachSegs(this.segs);
  7701. this.segs = [];
  7702. };
  7703. // Updates values that rely on options and also relate to range
  7704. FgEventRenderer.prototype.rangeUpdated = function () {
  7705. var options = this.context.options;
  7706. var displayEventTime;
  7707. var displayEventEnd;
  7708. this.eventTimeFormat = createFormatter(options.eventTimeFormat || this.computeEventTimeFormat(), options.defaultRangeSeparator);
  7709. displayEventTime = options.displayEventTime;
  7710. if (displayEventTime == null) {
  7711. displayEventTime = this.computeDisplayEventTime(); // might be based off of range
  7712. }
  7713. displayEventEnd = options.displayEventEnd;
  7714. if (displayEventEnd == null) {
  7715. displayEventEnd = this.computeDisplayEventEnd(); // might be based off of range
  7716. }
  7717. this.displayEventTime = displayEventTime;
  7718. this.displayEventEnd = displayEventEnd;
  7719. };
  7720. // Renders and assigns an `el` property for each foreground event segment.
  7721. // Only returns segments that successfully rendered.
  7722. FgEventRenderer.prototype.renderSegEls = function (segs, mirrorInfo) {
  7723. var html = '';
  7724. var i;
  7725. if (segs.length) { // don't build an empty html string
  7726. // build a large concatenation of event segment HTML
  7727. for (i = 0; i < segs.length; i++) {
  7728. html += this.renderSegHtml(segs[i], mirrorInfo);
  7729. }
  7730. // Grab individual elements from the combined HTML string. Use each as the default rendering.
  7731. // Then, compute the 'el' for each segment. An el might be null if the eventRender callback returned false.
  7732. htmlToElements(html).forEach(function (el, i) {
  7733. var seg = segs[i];
  7734. if (el) {
  7735. seg.el = el;
  7736. }
  7737. });
  7738. segs = filterSegsViaEls(this.context, segs, Boolean(mirrorInfo));
  7739. }
  7740. return segs;
  7741. };
  7742. // Generic utility for generating the HTML classNames for an event segment's element
  7743. FgEventRenderer.prototype.getSegClasses = function (seg, isDraggable, isResizable, mirrorInfo) {
  7744. var classes = [
  7745. 'fc-event',
  7746. seg.isStart ? 'fc-start' : 'fc-not-start',
  7747. seg.isEnd ? 'fc-end' : 'fc-not-end'
  7748. ].concat(seg.eventRange.ui.classNames);
  7749. if (isDraggable) {
  7750. classes.push('fc-draggable');
  7751. }
  7752. if (isResizable) {
  7753. classes.push('fc-resizable');
  7754. }
  7755. if (mirrorInfo) {
  7756. classes.push('fc-mirror');
  7757. if (mirrorInfo.isDragging) {
  7758. classes.push('fc-dragging');
  7759. }
  7760. if (mirrorInfo.isResizing) {
  7761. classes.push('fc-resizing');
  7762. }
  7763. }
  7764. return classes;
  7765. };
  7766. // Compute the text that should be displayed on an event's element.
  7767. // `range` can be the Event object itself, or something range-like, with at least a `start`.
  7768. // If event times are disabled, or the event has no time, will return a blank string.
  7769. // If not specified, formatter will default to the eventTimeFormat setting,
  7770. // and displayEnd will default to the displayEventEnd setting.
  7771. FgEventRenderer.prototype.getTimeText = function (eventRange, formatter, displayEnd) {
  7772. var def = eventRange.def, instance = eventRange.instance;
  7773. return this._getTimeText(instance.range.start, def.hasEnd ? instance.range.end : null, def.allDay, formatter, displayEnd, instance.forcedStartTzo, instance.forcedEndTzo);
  7774. };
  7775. FgEventRenderer.prototype._getTimeText = function (start, end, allDay, formatter, displayEnd, forcedStartTzo, forcedEndTzo) {
  7776. var dateEnv = this.context.dateEnv;
  7777. if (formatter == null) {
  7778. formatter = this.eventTimeFormat;
  7779. }
  7780. if (displayEnd == null) {
  7781. displayEnd = this.displayEventEnd;
  7782. }
  7783. if (this.displayEventTime && !allDay) {
  7784. if (displayEnd && end) {
  7785. return dateEnv.formatRange(start, end, formatter, {
  7786. forcedStartTzo: forcedStartTzo,
  7787. forcedEndTzo: forcedEndTzo
  7788. });
  7789. }
  7790. else {
  7791. return dateEnv.format(start, formatter, {
  7792. forcedTzo: forcedStartTzo
  7793. });
  7794. }
  7795. }
  7796. return '';
  7797. };
  7798. FgEventRenderer.prototype.computeEventTimeFormat = function () {
  7799. return {
  7800. hour: 'numeric',
  7801. minute: '2-digit',
  7802. omitZeroMinute: true
  7803. };
  7804. };
  7805. FgEventRenderer.prototype.computeDisplayEventTime = function () {
  7806. return true;
  7807. };
  7808. FgEventRenderer.prototype.computeDisplayEventEnd = function () {
  7809. return true;
  7810. };
  7811. // Utility for generating event skin-related CSS properties
  7812. FgEventRenderer.prototype.getSkinCss = function (ui) {
  7813. return {
  7814. 'background-color': ui.backgroundColor,
  7815. 'border-color': ui.borderColor,
  7816. color: ui.textColor
  7817. };
  7818. };
  7819. FgEventRenderer.prototype.sortEventSegs = function (segs) {
  7820. var specs = this.context.eventOrderSpecs;
  7821. var objs = segs.map(buildSegCompareObj);
  7822. objs.sort(function (obj0, obj1) {
  7823. return compareByFieldSpecs(obj0, obj1, specs);
  7824. });
  7825. return objs.map(function (c) {
  7826. return c._seg;
  7827. });
  7828. };
  7829. FgEventRenderer.prototype.computeSizes = function (force) {
  7830. if (force || this.isSizeDirty) {
  7831. this.computeSegSizes(this.segs);
  7832. }
  7833. };
  7834. FgEventRenderer.prototype.assignSizes = function (force) {
  7835. if (force || this.isSizeDirty) {
  7836. this.assignSegSizes(this.segs);
  7837. this.isSizeDirty = false;
  7838. }
  7839. };
  7840. FgEventRenderer.prototype.computeSegSizes = function (segs) {
  7841. };
  7842. FgEventRenderer.prototype.assignSegSizes = function (segs) {
  7843. };
  7844. // Manipulation on rendered segs
  7845. FgEventRenderer.prototype.hideByHash = function (hash) {
  7846. if (hash) {
  7847. for (var _i = 0, _a = this.segs; _i < _a.length; _i++) {
  7848. var seg = _a[_i];
  7849. if (hash[seg.eventRange.instance.instanceId]) {
  7850. seg.el.style.visibility = 'hidden';
  7851. }
  7852. }
  7853. }
  7854. };
  7855. FgEventRenderer.prototype.showByHash = function (hash) {
  7856. if (hash) {
  7857. for (var _i = 0, _a = this.segs; _i < _a.length; _i++) {
  7858. var seg = _a[_i];
  7859. if (hash[seg.eventRange.instance.instanceId]) {
  7860. seg.el.style.visibility = '';
  7861. }
  7862. }
  7863. }
  7864. };
  7865. FgEventRenderer.prototype.selectByInstanceId = function (instanceId) {
  7866. if (instanceId) {
  7867. for (var _i = 0, _a = this.segs; _i < _a.length; _i++) {
  7868. var seg = _a[_i];
  7869. var eventInstance = seg.eventRange.instance;
  7870. if (eventInstance && eventInstance.instanceId === instanceId &&
  7871. seg.el // necessary?
  7872. ) {
  7873. seg.el.classList.add('fc-selected');
  7874. }
  7875. }
  7876. }
  7877. };
  7878. FgEventRenderer.prototype.unselectByInstanceId = function (instanceId) {
  7879. if (instanceId) {
  7880. for (var _i = 0, _a = this.segs; _i < _a.length; _i++) {
  7881. var seg = _a[_i];
  7882. if (seg.el) { // necessary?
  7883. seg.el.classList.remove('fc-selected');
  7884. }
  7885. }
  7886. }
  7887. };
  7888. return FgEventRenderer;
  7889. }());
  7890. // returns a object with all primitive props that can be compared
  7891. function buildSegCompareObj(seg) {
  7892. var eventDef = seg.eventRange.def;
  7893. var range = seg.eventRange.instance.range;
  7894. var start = range.start ? range.start.valueOf() : 0; // TODO: better support for open-range events
  7895. var end = range.end ? range.end.valueOf() : 0; // "
  7896. return __assign({}, eventDef.extendedProps, eventDef, { id: eventDef.publicId, start: start,
  7897. end: end, duration: end - start, allDay: Number(eventDef.allDay), _seg: seg // for later retrieval
  7898. });
  7899. }
  7900. /*
  7901. TODO: when refactoring this class, make a new FillRenderer instance for each `type`
  7902. */
  7903. var FillRenderer = /** @class */ (function () {
  7904. function FillRenderer() {
  7905. this.fillSegTag = 'div';
  7906. this.dirtySizeFlags = {};
  7907. this.containerElsByType = {};
  7908. this.segsByType = {};
  7909. }
  7910. FillRenderer.prototype.getSegsByType = function (type) {
  7911. return this.segsByType[type] || [];
  7912. };
  7913. FillRenderer.prototype.renderSegs = function (type, context, segs) {
  7914. var _a;
  7915. this.context = context;
  7916. var renderedSegs = this.renderSegEls(type, segs); // assignes `.el` to each seg. returns successfully rendered segs
  7917. var containerEls = this.attachSegs(type, renderedSegs);
  7918. if (containerEls) {
  7919. (_a = (this.containerElsByType[type] || (this.containerElsByType[type] = []))).push.apply(_a, containerEls);
  7920. }
  7921. this.segsByType[type] = renderedSegs;
  7922. if (type === 'bgEvent') {
  7923. triggerRenderedSegs(context, renderedSegs, false); // isMirror=false
  7924. }
  7925. this.dirtySizeFlags[type] = true;
  7926. };
  7927. // Unrenders a specific type of fill that is currently rendered on the grid
  7928. FillRenderer.prototype.unrender = function (type, context) {
  7929. var segs = this.segsByType[type];
  7930. if (segs) {
  7931. if (type === 'bgEvent') {
  7932. triggerWillRemoveSegs(context, segs, false); // isMirror=false
  7933. }
  7934. this.detachSegs(type, segs);
  7935. }
  7936. };
  7937. // Renders and assigns an `el` property for each fill segment. Generic enough to work with different types.
  7938. // Only returns segments that successfully rendered.
  7939. FillRenderer.prototype.renderSegEls = function (type, segs) {
  7940. var _this = this;
  7941. var html = '';
  7942. var i;
  7943. if (segs.length) {
  7944. // build a large concatenation of segment HTML
  7945. for (i = 0; i < segs.length; i++) {
  7946. html += this.renderSegHtml(type, segs[i]);
  7947. }
  7948. // Grab individual elements from the combined HTML string. Use each as the default rendering.
  7949. // Then, compute the 'el' for each segment.
  7950. htmlToElements(html).forEach(function (el, i) {
  7951. var seg = segs[i];
  7952. if (el) {
  7953. seg.el = el;
  7954. }
  7955. });
  7956. if (type === 'bgEvent') {
  7957. segs = filterSegsViaEls(this.context, segs, false // isMirror. background events can never be mirror elements
  7958. );
  7959. }
  7960. // correct element type? (would be bad if a non-TD were inserted into a table for example)
  7961. segs = segs.filter(function (seg) {
  7962. return elementMatches(seg.el, _this.fillSegTag);
  7963. });
  7964. }
  7965. return segs;
  7966. };
  7967. // Builds the HTML needed for one fill segment. Generic enough to work with different types.
  7968. FillRenderer.prototype.renderSegHtml = function (type, seg) {
  7969. var css = null;
  7970. var classNames = [];
  7971. if (type !== 'highlight' && type !== 'businessHours') {
  7972. css = {
  7973. 'background-color': seg.eventRange.ui.backgroundColor
  7974. };
  7975. }
  7976. if (type !== 'highlight') {
  7977. classNames = classNames.concat(seg.eventRange.ui.classNames);
  7978. }
  7979. if (type === 'businessHours') {
  7980. classNames.push('fc-bgevent');
  7981. }
  7982. else {
  7983. classNames.push('fc-' + type.toLowerCase());
  7984. }
  7985. return '<' + this.fillSegTag +
  7986. (classNames.length ? ' class="' + classNames.join(' ') + '"' : '') +
  7987. (css ? ' style="' + cssToStr(css) + '"' : '') +
  7988. '></' + this.fillSegTag + '>';
  7989. };
  7990. FillRenderer.prototype.detachSegs = function (type, segs) {
  7991. var containerEls = this.containerElsByType[type];
  7992. if (containerEls) {
  7993. containerEls.forEach(removeElement);
  7994. delete this.containerElsByType[type];
  7995. }
  7996. };
  7997. FillRenderer.prototype.computeSizes = function (force) {
  7998. for (var type in this.segsByType) {
  7999. if (force || this.dirtySizeFlags[type]) {
  8000. this.computeSegSizes(this.segsByType[type]);
  8001. }
  8002. }
  8003. };
  8004. FillRenderer.prototype.assignSizes = function (force) {
  8005. for (var type in this.segsByType) {
  8006. if (force || this.dirtySizeFlags[type]) {
  8007. this.assignSegSizes(this.segsByType[type]);
  8008. }
  8009. }
  8010. this.dirtySizeFlags = {};
  8011. };
  8012. FillRenderer.prototype.computeSegSizes = function (segs) {
  8013. };
  8014. FillRenderer.prototype.assignSegSizes = function (segs) {
  8015. };
  8016. return FillRenderer;
  8017. }());
  8018. var NamedTimeZoneImpl = /** @class */ (function () {
  8019. function NamedTimeZoneImpl(timeZoneName) {
  8020. this.timeZoneName = timeZoneName;
  8021. }
  8022. return NamedTimeZoneImpl;
  8023. }());
  8024. /*
  8025. An abstraction for a dragging interaction originating on an event.
  8026. Does higher-level things than PointerDragger, such as possibly:
  8027. - a "mirror" that moves with the pointer
  8028. - a minimum number of pixels or other criteria for a true drag to begin
  8029. subclasses must emit:
  8030. - pointerdown
  8031. - dragstart
  8032. - dragmove
  8033. - pointerup
  8034. - dragend
  8035. */
  8036. var ElementDragging = /** @class */ (function () {
  8037. function ElementDragging(el) {
  8038. this.emitter = new EmitterMixin();
  8039. }
  8040. ElementDragging.prototype.destroy = function () {
  8041. };
  8042. ElementDragging.prototype.setMirrorIsVisible = function (bool) {
  8043. // optional if subclass doesn't want to support a mirror
  8044. };
  8045. ElementDragging.prototype.setMirrorNeedsRevert = function (bool) {
  8046. // optional if subclass doesn't want to support a mirror
  8047. };
  8048. ElementDragging.prototype.setAutoScrollEnabled = function (bool) {
  8049. // optional
  8050. };
  8051. return ElementDragging;
  8052. }());
  8053. function formatDate(dateInput, settings) {
  8054. if (settings === void 0) { settings = {}; }
  8055. var dateEnv = buildDateEnv$1(settings);
  8056. var formatter = createFormatter(settings);
  8057. var dateMeta = dateEnv.createMarkerMeta(dateInput);
  8058. if (!dateMeta) { // TODO: warning?
  8059. return '';
  8060. }
  8061. return dateEnv.format(dateMeta.marker, formatter, {
  8062. forcedTzo: dateMeta.forcedTzo
  8063. });
  8064. }
  8065. function formatRange(startInput, endInput, settings // mixture of env and formatter settings
  8066. ) {
  8067. var dateEnv = buildDateEnv$1(typeof settings === 'object' && settings ? settings : {}); // pass in if non-null object
  8068. var formatter = createFormatter(settings, globalDefaults.defaultRangeSeparator);
  8069. var startMeta = dateEnv.createMarkerMeta(startInput);
  8070. var endMeta = dateEnv.createMarkerMeta(endInput);
  8071. if (!startMeta || !endMeta) { // TODO: warning?
  8072. return '';
  8073. }
  8074. return dateEnv.formatRange(startMeta.marker, endMeta.marker, formatter, {
  8075. forcedStartTzo: startMeta.forcedTzo,
  8076. forcedEndTzo: endMeta.forcedTzo,
  8077. isEndExclusive: settings.isEndExclusive
  8078. });
  8079. }
  8080. // TODO: more DRY and optimized
  8081. function buildDateEnv$1(settings) {
  8082. var locale = buildLocale(settings.locale || 'en', parseRawLocales([]).map); // TODO: don't hardcode 'en' everywhere
  8083. // ensure required settings
  8084. settings = __assign({ timeZone: globalDefaults.timeZone, calendarSystem: 'gregory' }, settings, { locale: locale });
  8085. return new DateEnv(settings);
  8086. }
  8087. var DRAG_META_PROPS = {
  8088. startTime: createDuration,
  8089. duration: createDuration,
  8090. create: Boolean,
  8091. sourceId: String
  8092. };
  8093. var DRAG_META_DEFAULTS = {
  8094. create: true
  8095. };
  8096. function parseDragMeta(raw) {
  8097. var leftoverProps = {};
  8098. var refined = refineProps(raw, DRAG_META_PROPS, DRAG_META_DEFAULTS, leftoverProps);
  8099. refined.leftoverProps = leftoverProps;
  8100. return refined;
  8101. }
  8102. // Computes a default column header formatting string if `colFormat` is not explicitly defined
  8103. function computeFallbackHeaderFormat(datesRepDistinctDays, dayCnt) {
  8104. // if more than one week row, or if there are a lot of columns with not much space,
  8105. // put just the day numbers will be in each cell
  8106. if (!datesRepDistinctDays || dayCnt > 10) {
  8107. return { weekday: 'short' }; // "Sat"
  8108. }
  8109. else if (dayCnt > 1) {
  8110. return { weekday: 'short', month: 'numeric', day: 'numeric', omitCommas: true }; // "Sat 11/12"
  8111. }
  8112. else {
  8113. return { weekday: 'long' }; // "Saturday"
  8114. }
  8115. }
  8116. function renderDateCell(dateMarker, dateProfile, datesRepDistinctDays, colCnt, colHeadFormat, context, colspan, otherAttrs) {
  8117. var dateEnv = context.dateEnv, theme = context.theme, options = context.options;
  8118. var isDateValid = rangeContainsMarker(dateProfile.activeRange, dateMarker); // TODO: called too frequently. cache somehow.
  8119. var classNames = [
  8120. 'fc-day-header',
  8121. theme.getClass('widgetHeader')
  8122. ];
  8123. var innerHtml;
  8124. if (typeof options.columnHeaderHtml === 'function') {
  8125. innerHtml = options.columnHeaderHtml(dateEnv.toDate(dateMarker));
  8126. }
  8127. else if (typeof options.columnHeaderText === 'function') {
  8128. innerHtml = htmlEscape(options.columnHeaderText(dateEnv.toDate(dateMarker)));
  8129. }
  8130. else {
  8131. innerHtml = htmlEscape(dateEnv.format(dateMarker, colHeadFormat));
  8132. }
  8133. // if only one row of days, the classNames on the header can represent the specific days beneath
  8134. if (datesRepDistinctDays) {
  8135. classNames = classNames.concat(
  8136. // includes the day-of-week class
  8137. // noThemeHighlight=true (don't highlight the header)
  8138. getDayClasses(dateMarker, dateProfile, context, true));
  8139. }
  8140. else {
  8141. classNames.push('fc-' + DAY_IDS[dateMarker.getUTCDay()]); // only add the day-of-week class
  8142. }
  8143. return '' +
  8144. '<th class="' + classNames.join(' ') + '"' +
  8145. ((isDateValid && datesRepDistinctDays) ?
  8146. ' data-date="' + dateEnv.formatIso(dateMarker, { omitTime: true }) + '"' :
  8147. '') +
  8148. (colspan > 1 ?
  8149. ' colspan="' + colspan + '"' :
  8150. '') +
  8151. (otherAttrs ?
  8152. ' ' + otherAttrs :
  8153. '') +
  8154. '>' +
  8155. (isDateValid ?
  8156. // don't make a link if the heading could represent multiple days, or if there's only one day (forceOff)
  8157. buildGotoAnchorHtml(options, dateEnv, { date: dateMarker, forceOff: !datesRepDistinctDays || colCnt === 1 }, innerHtml) :
  8158. // if not valid, display text, but no link
  8159. innerHtml) +
  8160. '</th>';
  8161. }
  8162. var DayHeader = /** @class */ (function (_super) {
  8163. __extends(DayHeader, _super);
  8164. function DayHeader(parentEl) {
  8165. var _this = _super.call(this) || this;
  8166. _this.renderSkeleton = memoizeRendering(_this._renderSkeleton, _this._unrenderSkeleton);
  8167. _this.parentEl = parentEl;
  8168. return _this;
  8169. }
  8170. DayHeader.prototype.render = function (props, context) {
  8171. var dates = props.dates, datesRepDistinctDays = props.datesRepDistinctDays;
  8172. var parts = [];
  8173. this.renderSkeleton(context);
  8174. if (props.renderIntroHtml) {
  8175. parts.push(props.renderIntroHtml());
  8176. }
  8177. var colHeadFormat = createFormatter(context.options.columnHeaderFormat ||
  8178. computeFallbackHeaderFormat(datesRepDistinctDays, dates.length));
  8179. for (var _i = 0, dates_1 = dates; _i < dates_1.length; _i++) {
  8180. var date = dates_1[_i];
  8181. parts.push(renderDateCell(date, props.dateProfile, datesRepDistinctDays, dates.length, colHeadFormat, context));
  8182. }
  8183. if (context.isRtl) {
  8184. parts.reverse();
  8185. }
  8186. this.thead.innerHTML = '<tr>' + parts.join('') + '</tr>';
  8187. };
  8188. DayHeader.prototype.destroy = function () {
  8189. _super.prototype.destroy.call(this);
  8190. this.renderSkeleton.unrender();
  8191. };
  8192. DayHeader.prototype._renderSkeleton = function (context) {
  8193. var theme = context.theme;
  8194. var parentEl = this.parentEl;
  8195. parentEl.innerHTML = ''; // because might be nbsp
  8196. parentEl.appendChild(this.el = htmlToElement('<div class="fc-row ' + theme.getClass('headerRow') + '">' +
  8197. '<table class="' + theme.getClass('tableGrid') + '">' +
  8198. '<thead></thead>' +
  8199. '</table>' +
  8200. '</div>'));
  8201. this.thead = this.el.querySelector('thead');
  8202. };
  8203. DayHeader.prototype._unrenderSkeleton = function () {
  8204. removeElement(this.el);
  8205. };
  8206. return DayHeader;
  8207. }(Component));
  8208. var DaySeries = /** @class */ (function () {
  8209. function DaySeries(range, dateProfileGenerator) {
  8210. var date = range.start;
  8211. var end = range.end;
  8212. var indices = [];
  8213. var dates = [];
  8214. var dayIndex = -1;
  8215. while (date < end) { // loop each day from start to end
  8216. if (dateProfileGenerator.isHiddenDay(date)) {
  8217. indices.push(dayIndex + 0.5); // mark that it's between indices
  8218. }
  8219. else {
  8220. dayIndex++;
  8221. indices.push(dayIndex);
  8222. dates.push(date);
  8223. }
  8224. date = addDays(date, 1);
  8225. }
  8226. this.dates = dates;
  8227. this.indices = indices;
  8228. this.cnt = dates.length;
  8229. }
  8230. DaySeries.prototype.sliceRange = function (range) {
  8231. var firstIndex = this.getDateDayIndex(range.start); // inclusive first index
  8232. var lastIndex = this.getDateDayIndex(addDays(range.end, -1)); // inclusive last index
  8233. var clippedFirstIndex = Math.max(0, firstIndex);
  8234. var clippedLastIndex = Math.min(this.cnt - 1, lastIndex);
  8235. // deal with in-between indices
  8236. clippedFirstIndex = Math.ceil(clippedFirstIndex); // in-between starts round to next cell
  8237. clippedLastIndex = Math.floor(clippedLastIndex); // in-between ends round to prev cell
  8238. if (clippedFirstIndex <= clippedLastIndex) {
  8239. return {
  8240. firstIndex: clippedFirstIndex,
  8241. lastIndex: clippedLastIndex,
  8242. isStart: firstIndex === clippedFirstIndex,
  8243. isEnd: lastIndex === clippedLastIndex
  8244. };
  8245. }
  8246. else {
  8247. return null;
  8248. }
  8249. };
  8250. // Given a date, returns its chronolocial cell-index from the first cell of the grid.
  8251. // If the date lies between cells (because of hiddenDays), returns a floating-point value between offsets.
  8252. // If before the first offset, returns a negative number.
  8253. // If after the last offset, returns an offset past the last cell offset.
  8254. // Only works for *start* dates of cells. Will not work for exclusive end dates for cells.
  8255. DaySeries.prototype.getDateDayIndex = function (date) {
  8256. var indices = this.indices;
  8257. var dayOffset = Math.floor(diffDays(this.dates[0], date));
  8258. if (dayOffset < 0) {
  8259. return indices[0] - 1;
  8260. }
  8261. else if (dayOffset >= indices.length) {
  8262. return indices[indices.length - 1] + 1;
  8263. }
  8264. else {
  8265. return indices[dayOffset];
  8266. }
  8267. };
  8268. return DaySeries;
  8269. }());
  8270. var DayTable = /** @class */ (function () {
  8271. function DayTable(daySeries, breakOnWeeks) {
  8272. var dates = daySeries.dates;
  8273. var daysPerRow;
  8274. var firstDay;
  8275. var rowCnt;
  8276. if (breakOnWeeks) {
  8277. // count columns until the day-of-week repeats
  8278. firstDay = dates[0].getUTCDay();
  8279. for (daysPerRow = 1; daysPerRow < dates.length; daysPerRow++) {
  8280. if (dates[daysPerRow].getUTCDay() === firstDay) {
  8281. break;
  8282. }
  8283. }
  8284. rowCnt = Math.ceil(dates.length / daysPerRow);
  8285. }
  8286. else {
  8287. rowCnt = 1;
  8288. daysPerRow = dates.length;
  8289. }
  8290. this.rowCnt = rowCnt;
  8291. this.colCnt = daysPerRow;
  8292. this.daySeries = daySeries;
  8293. this.cells = this.buildCells();
  8294. this.headerDates = this.buildHeaderDates();
  8295. }
  8296. DayTable.prototype.buildCells = function () {
  8297. var rows = [];
  8298. for (var row = 0; row < this.rowCnt; row++) {
  8299. var cells = [];
  8300. for (var col = 0; col < this.colCnt; col++) {
  8301. cells.push(this.buildCell(row, col));
  8302. }
  8303. rows.push(cells);
  8304. }
  8305. return rows;
  8306. };
  8307. DayTable.prototype.buildCell = function (row, col) {
  8308. return {
  8309. date: this.daySeries.dates[row * this.colCnt + col]
  8310. };
  8311. };
  8312. DayTable.prototype.buildHeaderDates = function () {
  8313. var dates = [];
  8314. for (var col = 0; col < this.colCnt; col++) {
  8315. dates.push(this.cells[0][col].date);
  8316. }
  8317. return dates;
  8318. };
  8319. DayTable.prototype.sliceRange = function (range) {
  8320. var colCnt = this.colCnt;
  8321. var seriesSeg = this.daySeries.sliceRange(range);
  8322. var segs = [];
  8323. if (seriesSeg) {
  8324. var firstIndex = seriesSeg.firstIndex, lastIndex = seriesSeg.lastIndex;
  8325. var index = firstIndex;
  8326. while (index <= lastIndex) {
  8327. var row = Math.floor(index / colCnt);
  8328. var nextIndex = Math.min((row + 1) * colCnt, lastIndex + 1);
  8329. segs.push({
  8330. row: row,
  8331. firstCol: index % colCnt,
  8332. lastCol: (nextIndex - 1) % colCnt,
  8333. isStart: seriesSeg.isStart && index === firstIndex,
  8334. isEnd: seriesSeg.isEnd && (nextIndex - 1) === lastIndex
  8335. });
  8336. index = nextIndex;
  8337. }
  8338. }
  8339. return segs;
  8340. };
  8341. return DayTable;
  8342. }());
  8343. var Slicer = /** @class */ (function () {
  8344. function Slicer() {
  8345. this.sliceBusinessHours = memoize(this._sliceBusinessHours);
  8346. this.sliceDateSelection = memoize(this._sliceDateSpan);
  8347. this.sliceEventStore = memoize(this._sliceEventStore);
  8348. this.sliceEventDrag = memoize(this._sliceInteraction);
  8349. this.sliceEventResize = memoize(this._sliceInteraction);
  8350. }
  8351. Slicer.prototype.sliceProps = function (props, dateProfile, nextDayThreshold, calendar, component) {
  8352. var extraArgs = [];
  8353. for (var _i = 5; _i < arguments.length; _i++) {
  8354. extraArgs[_i - 5] = arguments[_i];
  8355. }
  8356. var eventUiBases = props.eventUiBases;
  8357. var eventSegs = this.sliceEventStore.apply(this, [props.eventStore, eventUiBases, dateProfile, nextDayThreshold, component].concat(extraArgs));
  8358. return {
  8359. dateSelectionSegs: this.sliceDateSelection.apply(this, [props.dateSelection, eventUiBases, component].concat(extraArgs)),
  8360. businessHourSegs: this.sliceBusinessHours.apply(this, [props.businessHours, dateProfile, nextDayThreshold, calendar, component].concat(extraArgs)),
  8361. fgEventSegs: eventSegs.fg,
  8362. bgEventSegs: eventSegs.bg,
  8363. eventDrag: this.sliceEventDrag.apply(this, [props.eventDrag, eventUiBases, dateProfile, nextDayThreshold, component].concat(extraArgs)),
  8364. eventResize: this.sliceEventResize.apply(this, [props.eventResize, eventUiBases, dateProfile, nextDayThreshold, component].concat(extraArgs)),
  8365. eventSelection: props.eventSelection
  8366. }; // TODO: give interactionSegs?
  8367. };
  8368. Slicer.prototype.sliceNowDate = function (// does not memoize
  8369. date, component) {
  8370. var extraArgs = [];
  8371. for (var _i = 2; _i < arguments.length; _i++) {
  8372. extraArgs[_i - 2] = arguments[_i];
  8373. }
  8374. return this._sliceDateSpan.apply(this, [{ range: { start: date, end: addMs(date, 1) }, allDay: false },
  8375. {},
  8376. component].concat(extraArgs));
  8377. };
  8378. Slicer.prototype._sliceBusinessHours = function (businessHours, dateProfile, nextDayThreshold, calendar, component) {
  8379. var extraArgs = [];
  8380. for (var _i = 5; _i < arguments.length; _i++) {
  8381. extraArgs[_i - 5] = arguments[_i];
  8382. }
  8383. if (!businessHours) {
  8384. return [];
  8385. }
  8386. return this._sliceEventStore.apply(this, [expandRecurring(businessHours, computeActiveRange(dateProfile, Boolean(nextDayThreshold)), calendar),
  8387. {},
  8388. dateProfile,
  8389. nextDayThreshold,
  8390. component].concat(extraArgs)).bg;
  8391. };
  8392. Slicer.prototype._sliceEventStore = function (eventStore, eventUiBases, dateProfile, nextDayThreshold, component) {
  8393. var extraArgs = [];
  8394. for (var _i = 5; _i < arguments.length; _i++) {
  8395. extraArgs[_i - 5] = arguments[_i];
  8396. }
  8397. if (eventStore) {
  8398. var rangeRes = sliceEventStore(eventStore, eventUiBases, computeActiveRange(dateProfile, Boolean(nextDayThreshold)), nextDayThreshold);
  8399. return {
  8400. bg: this.sliceEventRanges(rangeRes.bg, component, extraArgs),
  8401. fg: this.sliceEventRanges(rangeRes.fg, component, extraArgs)
  8402. };
  8403. }
  8404. else {
  8405. return { bg: [], fg: [] };
  8406. }
  8407. };
  8408. Slicer.prototype._sliceInteraction = function (interaction, eventUiBases, dateProfile, nextDayThreshold, component) {
  8409. var extraArgs = [];
  8410. for (var _i = 5; _i < arguments.length; _i++) {
  8411. extraArgs[_i - 5] = arguments[_i];
  8412. }
  8413. if (!interaction) {
  8414. return null;
  8415. }
  8416. var rangeRes = sliceEventStore(interaction.mutatedEvents, eventUiBases, computeActiveRange(dateProfile, Boolean(nextDayThreshold)), nextDayThreshold);
  8417. return {
  8418. segs: this.sliceEventRanges(rangeRes.fg, component, extraArgs),
  8419. affectedInstances: interaction.affectedEvents.instances,
  8420. isEvent: interaction.isEvent,
  8421. sourceSeg: interaction.origSeg
  8422. };
  8423. };
  8424. Slicer.prototype._sliceDateSpan = function (dateSpan, eventUiBases, component) {
  8425. var extraArgs = [];
  8426. for (var _i = 3; _i < arguments.length; _i++) {
  8427. extraArgs[_i - 3] = arguments[_i];
  8428. }
  8429. if (!dateSpan) {
  8430. return [];
  8431. }
  8432. var eventRange = fabricateEventRange(dateSpan, eventUiBases, component.context.calendar);
  8433. var segs = this.sliceRange.apply(this, [dateSpan.range].concat(extraArgs));
  8434. for (var _a = 0, segs_1 = segs; _a < segs_1.length; _a++) {
  8435. var seg = segs_1[_a];
  8436. seg.component = component;
  8437. seg.eventRange = eventRange;
  8438. }
  8439. return segs;
  8440. };
  8441. /*
  8442. "complete" seg means it has component and eventRange
  8443. */
  8444. Slicer.prototype.sliceEventRanges = function (eventRanges, component, // TODO: kill
  8445. extraArgs) {
  8446. var segs = [];
  8447. for (var _i = 0, eventRanges_1 = eventRanges; _i < eventRanges_1.length; _i++) {
  8448. var eventRange = eventRanges_1[_i];
  8449. segs.push.apply(segs, this.sliceEventRange(eventRange, component, extraArgs));
  8450. }
  8451. return segs;
  8452. };
  8453. /*
  8454. "complete" seg means it has component and eventRange
  8455. */
  8456. Slicer.prototype.sliceEventRange = function (eventRange, component, // TODO: kill
  8457. extraArgs) {
  8458. var segs = this.sliceRange.apply(this, [eventRange.range].concat(extraArgs));
  8459. for (var _i = 0, segs_2 = segs; _i < segs_2.length; _i++) {
  8460. var seg = segs_2[_i];
  8461. seg.component = component;
  8462. seg.eventRange = eventRange;
  8463. seg.isStart = eventRange.isStart && seg.isStart;
  8464. seg.isEnd = eventRange.isEnd && seg.isEnd;
  8465. }
  8466. return segs;
  8467. };
  8468. return Slicer;
  8469. }());
  8470. /*
  8471. for incorporating minTime/maxTime if appropriate
  8472. TODO: should be part of DateProfile!
  8473. TimelineDateProfile already does this btw
  8474. */
  8475. function computeActiveRange(dateProfile, isComponentAllDay) {
  8476. var range = dateProfile.activeRange;
  8477. if (isComponentAllDay) {
  8478. return range;
  8479. }
  8480. return {
  8481. start: addMs(range.start, dateProfile.minTime.milliseconds),
  8482. end: addMs(range.end, dateProfile.maxTime.milliseconds - 864e5) // 864e5 = ms in a day
  8483. };
  8484. }
  8485. // exports
  8486. // --------------------------------------------------------------------------------------------------
  8487. var version = '4.4.0';
  8488. export { Calendar, Component, ComponentContext, DateComponent, DateEnv, DateProfileGenerator, DayHeader, DaySeries, DayTable, ElementDragging, ElementScrollController, EmitterMixin, EventApi, FgEventRenderer, FillRenderer, Interaction, Mixin, NamedTimeZoneImpl, PositionCache, ScrollComponent, ScrollController, Slicer, Splitter, Theme, View, WindowScrollController, addDays, addDurations, addMs, addWeeks, allowContextMenu, allowSelection, appendToElement, applyAll, applyMutationToEventStore, applyStyle, applyStyleProp, asRoughMinutes, asRoughMs, asRoughSeconds, buildGotoAnchorHtml, buildSegCompareObj, capitaliseFirstLetter, combineEventUis, compareByFieldSpec, compareByFieldSpecs, compareNumbers, compensateScroll, computeClippingRect, computeEdges, computeEventDraggable, computeEventEndResizable, computeEventStartResizable, computeFallbackHeaderFormat, computeHeightAndMargins, computeInnerRect, computeRect, computeVisibleDayRange, config, constrainPoint, createDuration, createElement, createEmptyEventStore, createEventInstance, createFormatter, createPlugin, cssToStr, debounce, diffDates, diffDayAndTime, diffDays, diffPoints, diffWeeks, diffWholeDays, diffWholeWeeks, disableCursor, distributeHeight, elementClosest, elementMatches, enableCursor, eventTupleToStore, filterEventStoreDefs, filterHash, findChildren, findElements, flexibleCompare, forceClassName, formatDate, formatIsoTimeString, formatRange, getAllDayHtml, getClippingParents, getDayClasses, getElSeg, getRectCenter, getRelevantEvents, globalDefaults, greatestDurationDenominator, hasBgRendering, htmlEscape, htmlToElement, insertAfterElement, interactionSettingsStore, interactionSettingsToStore, intersectRanges, intersectRects, isArraysEqual, isDateSpansEqual, isInt, isInteractionValid, isMultiDayRange, isPropsEqual, isPropsValid, isSingleDay, isValidDate, listenBySelector, mapHash, matchCellWidths, memoize, memoizeOutput, memoizeRendering, mergeEventStores, multiplyDuration, padStart, parseBusinessHours, parseDragMeta, parseEventDef, parseFieldSpecs, parse as parseMarker, pointInsideRect, prependToElement, preventContextMenu, preventDefault, preventSelection, processScopedUiProps, rangeContainsMarker, rangeContainsRange, rangesEqual, rangesIntersect, refineProps, removeElement, removeExact, renderDateCell, requestJson, sliceEventStore, startOfDay, subtractInnerElHeight, translateRect, uncompensateScroll, undistributeHeight, unpromisify, version, whenTransitionDone, wholeDivideDurations };