No Description

main.esm.js 326KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558
  1. /*!
  2. FullCalendar Core Package v4.3.1
  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(view, segs, isMirror) {
  2363. if (view.hasPublicHandlers('eventRender')) {
  2364. segs = segs.filter(function (seg) {
  2365. var custom = view.publiclyTrigger('eventRender', [
  2366. {
  2367. event: new EventApi(view.calendar, seg.eventRange.def, seg.eventRange.instance),
  2368. isMirror: isMirror,
  2369. isStart: seg.isStart,
  2370. isEnd: seg.isEnd,
  2371. // TODO: include seg.range once all components consistently generate it
  2372. el: seg.el,
  2373. view: view
  2374. }
  2375. ]);
  2376. if (custom === false) { // means don't render at all
  2377. return false;
  2378. }
  2379. else if (custom && custom !== true) {
  2380. seg.el = custom;
  2381. }
  2382. return true;
  2383. });
  2384. }
  2385. for (var _i = 0, segs_1 = segs; _i < segs_1.length; _i++) {
  2386. var seg = segs_1[_i];
  2387. setElSeg(seg.el, seg);
  2388. }
  2389. return segs;
  2390. }
  2391. function setElSeg(el, seg) {
  2392. el.fcSeg = seg;
  2393. }
  2394. function getElSeg(el) {
  2395. return el.fcSeg || null;
  2396. }
  2397. // event ui computation
  2398. function compileEventUis(eventDefs, eventUiBases) {
  2399. return mapHash(eventDefs, function (eventDef) {
  2400. return compileEventUi(eventDef, eventUiBases);
  2401. });
  2402. }
  2403. function compileEventUi(eventDef, eventUiBases) {
  2404. var uis = [];
  2405. if (eventUiBases['']) {
  2406. uis.push(eventUiBases['']);
  2407. }
  2408. if (eventUiBases[eventDef.defId]) {
  2409. uis.push(eventUiBases[eventDef.defId]);
  2410. }
  2411. uis.push(eventDef.ui);
  2412. return combineEventUis(uis);
  2413. }
  2414. // applies the mutation to ALL defs/instances within the event store
  2415. function applyMutationToEventStore(eventStore, eventConfigBase, mutation, calendar) {
  2416. var eventConfigs = compileEventUis(eventStore.defs, eventConfigBase);
  2417. var dest = createEmptyEventStore();
  2418. for (var defId in eventStore.defs) {
  2419. var def = eventStore.defs[defId];
  2420. dest.defs[defId] = applyMutationToEventDef(def, eventConfigs[defId], mutation, calendar.pluginSystem.hooks.eventDefMutationAppliers, calendar);
  2421. }
  2422. for (var instanceId in eventStore.instances) {
  2423. var instance = eventStore.instances[instanceId];
  2424. var def = dest.defs[instance.defId]; // important to grab the newly modified def
  2425. dest.instances[instanceId] = applyMutationToEventInstance(instance, def, eventConfigs[instance.defId], mutation, calendar);
  2426. }
  2427. return dest;
  2428. }
  2429. function applyMutationToEventDef(eventDef, eventConfig, mutation, appliers, calendar) {
  2430. var standardProps = mutation.standardProps || {};
  2431. // if hasEnd has not been specified, guess a good value based on deltas.
  2432. // if duration will change, there's no way the default duration will persist,
  2433. // and thus, we need to mark the event as having a real end
  2434. if (standardProps.hasEnd == null &&
  2435. eventConfig.durationEditable &&
  2436. (mutation.startDelta || mutation.endDelta)) {
  2437. standardProps.hasEnd = true; // TODO: is this mutation okay?
  2438. }
  2439. var copy = __assign({}, eventDef, standardProps, { ui: __assign({}, eventDef.ui, standardProps.ui) });
  2440. if (mutation.extendedProps) {
  2441. copy.extendedProps = __assign({}, copy.extendedProps, mutation.extendedProps);
  2442. }
  2443. for (var _i = 0, appliers_1 = appliers; _i < appliers_1.length; _i++) {
  2444. var applier = appliers_1[_i];
  2445. applier(copy, mutation, calendar);
  2446. }
  2447. if (!copy.hasEnd && calendar.opt('forceEventDuration')) {
  2448. copy.hasEnd = true;
  2449. }
  2450. return copy;
  2451. }
  2452. function applyMutationToEventInstance(eventInstance, eventDef, // must first be modified by applyMutationToEventDef
  2453. eventConfig, mutation, calendar) {
  2454. var dateEnv = calendar.dateEnv;
  2455. var forceAllDay = mutation.standardProps && mutation.standardProps.allDay === true;
  2456. var clearEnd = mutation.standardProps && mutation.standardProps.hasEnd === false;
  2457. var copy = __assign({}, eventInstance);
  2458. if (forceAllDay) {
  2459. copy.range = computeAlignedDayRange(copy.range);
  2460. }
  2461. if (mutation.datesDelta && eventConfig.startEditable) {
  2462. copy.range = {
  2463. start: dateEnv.add(copy.range.start, mutation.datesDelta),
  2464. end: dateEnv.add(copy.range.end, mutation.datesDelta)
  2465. };
  2466. }
  2467. if (mutation.startDelta && eventConfig.durationEditable) {
  2468. copy.range = {
  2469. start: dateEnv.add(copy.range.start, mutation.startDelta),
  2470. end: copy.range.end
  2471. };
  2472. }
  2473. if (mutation.endDelta && eventConfig.durationEditable) {
  2474. copy.range = {
  2475. start: copy.range.start,
  2476. end: dateEnv.add(copy.range.end, mutation.endDelta)
  2477. };
  2478. }
  2479. if (clearEnd) {
  2480. copy.range = {
  2481. start: copy.range.start,
  2482. end: calendar.getDefaultEventEnd(eventDef.allDay, copy.range.start)
  2483. };
  2484. }
  2485. // in case event was all-day but the supplied deltas were not
  2486. // better util for this?
  2487. if (eventDef.allDay) {
  2488. copy.range = {
  2489. start: startOfDay(copy.range.start),
  2490. end: startOfDay(copy.range.end)
  2491. };
  2492. }
  2493. // handle invalid durations
  2494. if (copy.range.end < copy.range.start) {
  2495. copy.range.end = calendar.getDefaultEventEnd(eventDef.allDay, copy.range.start);
  2496. }
  2497. return copy;
  2498. }
  2499. function reduceEventStore (eventStore, action, eventSources, dateProfile, calendar) {
  2500. switch (action.type) {
  2501. case 'RECEIVE_EVENTS': // raw
  2502. return receiveRawEvents(eventStore, eventSources[action.sourceId], action.fetchId, action.fetchRange, action.rawEvents, calendar);
  2503. case 'ADD_EVENTS': // already parsed, but not expanded
  2504. return addEvent(eventStore, action.eventStore, // new ones
  2505. dateProfile ? dateProfile.activeRange : null, calendar);
  2506. case 'MERGE_EVENTS': // already parsed and expanded
  2507. return mergeEventStores(eventStore, action.eventStore);
  2508. case 'PREV': // TODO: how do we track all actions that affect dateProfile :(
  2509. case 'NEXT':
  2510. case 'SET_DATE':
  2511. case 'SET_VIEW_TYPE':
  2512. if (dateProfile) {
  2513. return expandRecurring(eventStore, dateProfile.activeRange, calendar);
  2514. }
  2515. else {
  2516. return eventStore;
  2517. }
  2518. case 'CHANGE_TIMEZONE':
  2519. return rezoneDates(eventStore, action.oldDateEnv, calendar.dateEnv);
  2520. case 'MUTATE_EVENTS':
  2521. return applyMutationToRelated(eventStore, action.instanceId, action.mutation, action.fromApi, calendar);
  2522. case 'REMOVE_EVENT_INSTANCES':
  2523. return excludeInstances(eventStore, action.instances);
  2524. case 'REMOVE_EVENT_DEF':
  2525. return filterEventStoreDefs(eventStore, function (eventDef) {
  2526. return eventDef.defId !== action.defId;
  2527. });
  2528. case 'REMOVE_EVENT_SOURCE':
  2529. return excludeEventsBySourceId(eventStore, action.sourceId);
  2530. case 'REMOVE_ALL_EVENT_SOURCES':
  2531. return filterEventStoreDefs(eventStore, function (eventDef) {
  2532. return !eventDef.sourceId; // only keep events with no source id
  2533. });
  2534. case 'REMOVE_ALL_EVENTS':
  2535. return createEmptyEventStore();
  2536. case 'RESET_EVENTS':
  2537. return {
  2538. defs: eventStore.defs,
  2539. instances: eventStore.instances
  2540. };
  2541. default:
  2542. return eventStore;
  2543. }
  2544. }
  2545. function receiveRawEvents(eventStore, eventSource, fetchId, fetchRange, rawEvents, calendar) {
  2546. if (eventSource && // not already removed
  2547. fetchId === eventSource.latestFetchId // TODO: wish this logic was always in event-sources
  2548. ) {
  2549. var subset = parseEvents(transformRawEvents(rawEvents, eventSource, calendar), eventSource.sourceId, calendar);
  2550. if (fetchRange) {
  2551. subset = expandRecurring(subset, fetchRange, calendar);
  2552. }
  2553. return mergeEventStores(excludeEventsBySourceId(eventStore, eventSource.sourceId), subset);
  2554. }
  2555. return eventStore;
  2556. }
  2557. function addEvent(eventStore, subset, expandRange, calendar) {
  2558. if (expandRange) {
  2559. subset = expandRecurring(subset, expandRange, calendar);
  2560. }
  2561. return mergeEventStores(eventStore, subset);
  2562. }
  2563. function rezoneDates(eventStore, oldDateEnv, newDateEnv) {
  2564. var defs = eventStore.defs;
  2565. var instances = mapHash(eventStore.instances, function (instance) {
  2566. var def = defs[instance.defId];
  2567. if (def.allDay || def.recurringDef) {
  2568. return instance; // isn't dependent on timezone
  2569. }
  2570. else {
  2571. return __assign({}, instance, { range: {
  2572. start: newDateEnv.createMarker(oldDateEnv.toDate(instance.range.start, instance.forcedStartTzo)),
  2573. end: newDateEnv.createMarker(oldDateEnv.toDate(instance.range.end, instance.forcedEndTzo))
  2574. }, forcedStartTzo: newDateEnv.canComputeOffset ? null : instance.forcedStartTzo, forcedEndTzo: newDateEnv.canComputeOffset ? null : instance.forcedEndTzo });
  2575. }
  2576. });
  2577. return { defs: defs, instances: instances };
  2578. }
  2579. function applyMutationToRelated(eventStore, instanceId, mutation, fromApi, calendar) {
  2580. var relevant = getRelevantEvents(eventStore, instanceId);
  2581. var eventConfigBase = fromApi ?
  2582. { '': {
  2583. startEditable: true,
  2584. durationEditable: true,
  2585. constraints: [],
  2586. overlap: null,
  2587. allows: [],
  2588. backgroundColor: '',
  2589. borderColor: '',
  2590. textColor: '',
  2591. classNames: []
  2592. } } :
  2593. calendar.eventUiBases;
  2594. relevant = applyMutationToEventStore(relevant, eventConfigBase, mutation, calendar);
  2595. return mergeEventStores(eventStore, relevant);
  2596. }
  2597. function excludeEventsBySourceId(eventStore, sourceId) {
  2598. return filterEventStoreDefs(eventStore, function (eventDef) {
  2599. return eventDef.sourceId !== sourceId;
  2600. });
  2601. }
  2602. // QUESTION: why not just return instances? do a general object-property-exclusion util
  2603. function excludeInstances(eventStore, removals) {
  2604. return {
  2605. defs: eventStore.defs,
  2606. instances: filterHash(eventStore.instances, function (instance) {
  2607. return !removals[instance.instanceId];
  2608. })
  2609. };
  2610. }
  2611. // high-level segmenting-aware tester functions
  2612. // ------------------------------------------------------------------------------------------------------------------------
  2613. function isInteractionValid(interaction, calendar) {
  2614. return isNewPropsValid({ eventDrag: interaction }, calendar); // HACK: the eventDrag props is used for ALL interactions
  2615. }
  2616. function isDateSelectionValid(dateSelection, calendar) {
  2617. return isNewPropsValid({ dateSelection: dateSelection }, calendar);
  2618. }
  2619. function isNewPropsValid(newProps, calendar) {
  2620. var view = calendar.view;
  2621. var props = __assign({ businessHours: view ? view.props.businessHours : createEmptyEventStore(), dateSelection: '', eventStore: calendar.state.eventStore, eventUiBases: calendar.eventUiBases, eventSelection: '', eventDrag: null, eventResize: null }, newProps);
  2622. return (calendar.pluginSystem.hooks.isPropsValid || isPropsValid)(props, calendar);
  2623. }
  2624. function isPropsValid(state, calendar, dateSpanMeta, filterConfig) {
  2625. if (dateSpanMeta === void 0) { dateSpanMeta = {}; }
  2626. if (state.eventDrag && !isInteractionPropsValid(state, calendar, dateSpanMeta, filterConfig)) {
  2627. return false;
  2628. }
  2629. if (state.dateSelection && !isDateSelectionPropsValid(state, calendar, dateSpanMeta, filterConfig)) {
  2630. return false;
  2631. }
  2632. return true;
  2633. }
  2634. // Moving Event Validation
  2635. // ------------------------------------------------------------------------------------------------------------------------
  2636. function isInteractionPropsValid(state, calendar, dateSpanMeta, filterConfig) {
  2637. var interaction = state.eventDrag; // HACK: the eventDrag props is used for ALL interactions
  2638. var subjectEventStore = interaction.mutatedEvents;
  2639. var subjectDefs = subjectEventStore.defs;
  2640. var subjectInstances = subjectEventStore.instances;
  2641. var subjectConfigs = compileEventUis(subjectDefs, interaction.isEvent ?
  2642. state.eventUiBases :
  2643. { '': calendar.selectionConfig } // if not a real event, validate as a selection
  2644. );
  2645. if (filterConfig) {
  2646. subjectConfigs = mapHash(subjectConfigs, filterConfig);
  2647. }
  2648. var otherEventStore = excludeInstances(state.eventStore, interaction.affectedEvents.instances); // exclude the subject events. TODO: exclude defs too?
  2649. var otherDefs = otherEventStore.defs;
  2650. var otherInstances = otherEventStore.instances;
  2651. var otherConfigs = compileEventUis(otherDefs, state.eventUiBases);
  2652. for (var subjectInstanceId in subjectInstances) {
  2653. var subjectInstance = subjectInstances[subjectInstanceId];
  2654. var subjectRange = subjectInstance.range;
  2655. var subjectConfig = subjectConfigs[subjectInstance.defId];
  2656. var subjectDef = subjectDefs[subjectInstance.defId];
  2657. // constraint
  2658. if (!allConstraintsPass(subjectConfig.constraints, subjectRange, otherEventStore, state.businessHours, calendar)) {
  2659. return false;
  2660. }
  2661. // overlap
  2662. var overlapFunc = calendar.opt('eventOverlap');
  2663. if (typeof overlapFunc !== 'function') {
  2664. overlapFunc = null;
  2665. }
  2666. for (var otherInstanceId in otherInstances) {
  2667. var otherInstance = otherInstances[otherInstanceId];
  2668. // intersect! evaluate
  2669. if (rangesIntersect(subjectRange, otherInstance.range)) {
  2670. var otherOverlap = otherConfigs[otherInstance.defId].overlap;
  2671. // consider the other event's overlap. only do this if the subject event is a "real" event
  2672. if (otherOverlap === false && interaction.isEvent) {
  2673. return false;
  2674. }
  2675. if (subjectConfig.overlap === false) {
  2676. return false;
  2677. }
  2678. if (overlapFunc && !overlapFunc(new EventApi(calendar, otherDefs[otherInstance.defId], otherInstance), // still event
  2679. new EventApi(calendar, subjectDef, subjectInstance) // moving event
  2680. )) {
  2681. return false;
  2682. }
  2683. }
  2684. }
  2685. // allow (a function)
  2686. var calendarEventStore = calendar.state.eventStore; // need global-to-calendar, not local to component (splittable)state
  2687. for (var _i = 0, _a = subjectConfig.allows; _i < _a.length; _i++) {
  2688. var subjectAllow = _a[_i];
  2689. var subjectDateSpan = __assign({}, dateSpanMeta, { range: subjectInstance.range, allDay: subjectDef.allDay });
  2690. var origDef = calendarEventStore.defs[subjectDef.defId];
  2691. var origInstance = calendarEventStore.instances[subjectInstanceId];
  2692. var eventApi = void 0;
  2693. if (origDef) { // was previously in the calendar
  2694. eventApi = new EventApi(calendar, origDef, origInstance);
  2695. }
  2696. else { // was an external event
  2697. eventApi = new EventApi(calendar, subjectDef); // no instance, because had no dates
  2698. }
  2699. if (!subjectAllow(calendar.buildDateSpanApi(subjectDateSpan), eventApi)) {
  2700. return false;
  2701. }
  2702. }
  2703. }
  2704. return true;
  2705. }
  2706. // Date Selection Validation
  2707. // ------------------------------------------------------------------------------------------------------------------------
  2708. function isDateSelectionPropsValid(state, calendar, dateSpanMeta, filterConfig) {
  2709. var relevantEventStore = state.eventStore;
  2710. var relevantDefs = relevantEventStore.defs;
  2711. var relevantInstances = relevantEventStore.instances;
  2712. var selection = state.dateSelection;
  2713. var selectionRange = selection.range;
  2714. var selectionConfig = calendar.selectionConfig;
  2715. if (filterConfig) {
  2716. selectionConfig = filterConfig(selectionConfig);
  2717. }
  2718. // constraint
  2719. if (!allConstraintsPass(selectionConfig.constraints, selectionRange, relevantEventStore, state.businessHours, calendar)) {
  2720. return false;
  2721. }
  2722. // overlap
  2723. var overlapFunc = calendar.opt('selectOverlap');
  2724. if (typeof overlapFunc !== 'function') {
  2725. overlapFunc = null;
  2726. }
  2727. for (var relevantInstanceId in relevantInstances) {
  2728. var relevantInstance = relevantInstances[relevantInstanceId];
  2729. // intersect! evaluate
  2730. if (rangesIntersect(selectionRange, relevantInstance.range)) {
  2731. if (selectionConfig.overlap === false) {
  2732. return false;
  2733. }
  2734. if (overlapFunc && !overlapFunc(new EventApi(calendar, relevantDefs[relevantInstance.defId], relevantInstance))) {
  2735. return false;
  2736. }
  2737. }
  2738. }
  2739. // allow (a function)
  2740. for (var _i = 0, _a = selectionConfig.allows; _i < _a.length; _i++) {
  2741. var selectionAllow = _a[_i];
  2742. var fullDateSpan = __assign({}, dateSpanMeta, selection);
  2743. if (!selectionAllow(calendar.buildDateSpanApi(fullDateSpan), null)) {
  2744. return false;
  2745. }
  2746. }
  2747. return true;
  2748. }
  2749. // Constraint Utils
  2750. // ------------------------------------------------------------------------------------------------------------------------
  2751. function allConstraintsPass(constraints, subjectRange, otherEventStore, businessHoursUnexpanded, calendar) {
  2752. for (var _i = 0, constraints_1 = constraints; _i < constraints_1.length; _i++) {
  2753. var constraint = constraints_1[_i];
  2754. if (!anyRangesContainRange(constraintToRanges(constraint, subjectRange, otherEventStore, businessHoursUnexpanded, calendar), subjectRange)) {
  2755. return false;
  2756. }
  2757. }
  2758. return true;
  2759. }
  2760. function constraintToRanges(constraint, subjectRange, // for expanding a recurring constraint, or expanding business hours
  2761. otherEventStore, // for if constraint is an even group ID
  2762. businessHoursUnexpanded, // for if constraint is 'businessHours'
  2763. calendar // for expanding businesshours
  2764. ) {
  2765. if (constraint === 'businessHours') {
  2766. return eventStoreToRanges(expandRecurring(businessHoursUnexpanded, subjectRange, calendar));
  2767. }
  2768. else if (typeof constraint === 'string') { // an group ID
  2769. return eventStoreToRanges(filterEventStoreDefs(otherEventStore, function (eventDef) {
  2770. return eventDef.groupId === constraint;
  2771. }));
  2772. }
  2773. else if (typeof constraint === 'object' && constraint) { // non-null object
  2774. return eventStoreToRanges(expandRecurring(constraint, subjectRange, calendar));
  2775. }
  2776. return []; // if it's false
  2777. }
  2778. // TODO: move to event-store file?
  2779. function eventStoreToRanges(eventStore) {
  2780. var instances = eventStore.instances;
  2781. var ranges = [];
  2782. for (var instanceId in instances) {
  2783. ranges.push(instances[instanceId].range);
  2784. }
  2785. return ranges;
  2786. }
  2787. // TODO: move to geom file?
  2788. function anyRangesContainRange(outerRanges, innerRange) {
  2789. for (var _i = 0, outerRanges_1 = outerRanges; _i < outerRanges_1.length; _i++) {
  2790. var outerRange = outerRanges_1[_i];
  2791. if (rangeContainsRange(outerRange, innerRange)) {
  2792. return true;
  2793. }
  2794. }
  2795. return false;
  2796. }
  2797. // Parsing
  2798. // ------------------------------------------------------------------------------------------------------------------------
  2799. function normalizeConstraint(input, calendar) {
  2800. if (Array.isArray(input)) {
  2801. return parseEvents(input, '', calendar, true); // allowOpenRange=true
  2802. }
  2803. else if (typeof input === 'object' && input) { // non-null object
  2804. return parseEvents([input], '', calendar, true); // allowOpenRange=true
  2805. }
  2806. else if (input != null) {
  2807. return String(input);
  2808. }
  2809. else {
  2810. return null;
  2811. }
  2812. }
  2813. function htmlEscape(s) {
  2814. return (s + '').replace(/&/g, '&amp;')
  2815. .replace(/</g, '&lt;')
  2816. .replace(/>/g, '&gt;')
  2817. .replace(/'/g, '&#039;')
  2818. .replace(/"/g, '&quot;')
  2819. .replace(/\n/g, '<br />');
  2820. }
  2821. // Given a hash of CSS properties, returns a string of CSS.
  2822. // Uses property names as-is (no camel-case conversion). Will not make statements for null/undefined values.
  2823. function cssToStr(cssProps) {
  2824. var statements = [];
  2825. for (var name_1 in cssProps) {
  2826. var val = cssProps[name_1];
  2827. if (val != null && val !== '') {
  2828. statements.push(name_1 + ':' + val);
  2829. }
  2830. }
  2831. return statements.join(';');
  2832. }
  2833. // Given an object hash of HTML attribute names to values,
  2834. // generates a string that can be injected between < > in HTML
  2835. function attrsToStr(attrs) {
  2836. var parts = [];
  2837. for (var name_2 in attrs) {
  2838. var val = attrs[name_2];
  2839. if (val != null) {
  2840. parts.push(name_2 + '="' + htmlEscape(val) + '"');
  2841. }
  2842. }
  2843. return parts.join(' ');
  2844. }
  2845. function parseClassName(raw) {
  2846. if (Array.isArray(raw)) {
  2847. return raw;
  2848. }
  2849. else if (typeof raw === 'string') {
  2850. return raw.split(/\s+/);
  2851. }
  2852. else {
  2853. return [];
  2854. }
  2855. }
  2856. var UNSCOPED_EVENT_UI_PROPS = {
  2857. editable: Boolean,
  2858. startEditable: Boolean,
  2859. durationEditable: Boolean,
  2860. constraint: null,
  2861. overlap: null,
  2862. allow: null,
  2863. className: parseClassName,
  2864. classNames: parseClassName,
  2865. color: String,
  2866. backgroundColor: String,
  2867. borderColor: String,
  2868. textColor: String
  2869. };
  2870. function processUnscopedUiProps(rawProps, calendar, leftovers) {
  2871. var props = refineProps(rawProps, UNSCOPED_EVENT_UI_PROPS, {}, leftovers);
  2872. var constraint = normalizeConstraint(props.constraint, calendar);
  2873. return {
  2874. startEditable: props.startEditable != null ? props.startEditable : props.editable,
  2875. durationEditable: props.durationEditable != null ? props.durationEditable : props.editable,
  2876. constraints: constraint != null ? [constraint] : [],
  2877. overlap: props.overlap,
  2878. allows: props.allow != null ? [props.allow] : [],
  2879. backgroundColor: props.backgroundColor || props.color,
  2880. borderColor: props.borderColor || props.color,
  2881. textColor: props.textColor,
  2882. classNames: props.classNames.concat(props.className)
  2883. };
  2884. }
  2885. function processScopedUiProps(prefix, rawScoped, calendar, leftovers) {
  2886. var rawUnscoped = {};
  2887. var wasFound = {};
  2888. for (var key in UNSCOPED_EVENT_UI_PROPS) {
  2889. var scopedKey = prefix + capitaliseFirstLetter(key);
  2890. rawUnscoped[key] = rawScoped[scopedKey];
  2891. wasFound[scopedKey] = true;
  2892. }
  2893. if (prefix === 'event') {
  2894. rawUnscoped.editable = rawScoped.editable; // special case. there is no 'eventEditable', just 'editable'
  2895. }
  2896. if (leftovers) {
  2897. for (var key in rawScoped) {
  2898. if (!wasFound[key]) {
  2899. leftovers[key] = rawScoped[key];
  2900. }
  2901. }
  2902. }
  2903. return processUnscopedUiProps(rawUnscoped, calendar);
  2904. }
  2905. var EMPTY_EVENT_UI = {
  2906. startEditable: null,
  2907. durationEditable: null,
  2908. constraints: [],
  2909. overlap: null,
  2910. allows: [],
  2911. backgroundColor: '',
  2912. borderColor: '',
  2913. textColor: '',
  2914. classNames: []
  2915. };
  2916. // prevent against problems with <2 args!
  2917. function combineEventUis(uis) {
  2918. return uis.reduce(combineTwoEventUis, EMPTY_EVENT_UI);
  2919. }
  2920. function combineTwoEventUis(item0, item1) {
  2921. return {
  2922. startEditable: item1.startEditable != null ? item1.startEditable : item0.startEditable,
  2923. durationEditable: item1.durationEditable != null ? item1.durationEditable : item0.durationEditable,
  2924. constraints: item0.constraints.concat(item1.constraints),
  2925. overlap: typeof item1.overlap === 'boolean' ? item1.overlap : item0.overlap,
  2926. allows: item0.allows.concat(item1.allows),
  2927. backgroundColor: item1.backgroundColor || item0.backgroundColor,
  2928. borderColor: item1.borderColor || item0.borderColor,
  2929. textColor: item1.textColor || item0.textColor,
  2930. classNames: item0.classNames.concat(item1.classNames)
  2931. };
  2932. }
  2933. var NON_DATE_PROPS = {
  2934. id: String,
  2935. groupId: String,
  2936. title: String,
  2937. url: String,
  2938. rendering: String,
  2939. extendedProps: null
  2940. };
  2941. var DATE_PROPS = {
  2942. start: null,
  2943. date: null,
  2944. end: null,
  2945. allDay: null
  2946. };
  2947. var uid = 0;
  2948. function parseEvent(raw, sourceId, calendar, allowOpenRange) {
  2949. var allDayDefault = computeIsAllDayDefault(sourceId, calendar);
  2950. var leftovers0 = {};
  2951. var recurringRes = parseRecurring(raw, // raw, but with single-event stuff stripped out
  2952. allDayDefault, calendar.dateEnv, calendar.pluginSystem.hooks.recurringTypes, leftovers0 // will populate with non-recurring props
  2953. );
  2954. if (recurringRes) {
  2955. var def = parseEventDef(leftovers0, sourceId, recurringRes.allDay, Boolean(recurringRes.duration), calendar);
  2956. def.recurringDef = {
  2957. typeId: recurringRes.typeId,
  2958. typeData: recurringRes.typeData,
  2959. duration: recurringRes.duration
  2960. };
  2961. return { def: def, instance: null };
  2962. }
  2963. else {
  2964. var leftovers1 = {};
  2965. var singleRes = parseSingle(raw, allDayDefault, calendar, leftovers1, allowOpenRange);
  2966. if (singleRes) {
  2967. var def = parseEventDef(leftovers1, sourceId, singleRes.allDay, singleRes.hasEnd, calendar);
  2968. var instance = createEventInstance(def.defId, singleRes.range, singleRes.forcedStartTzo, singleRes.forcedEndTzo);
  2969. return { def: def, instance: instance };
  2970. }
  2971. }
  2972. return null;
  2973. }
  2974. /*
  2975. Will NOT populate extendedProps with the leftover properties.
  2976. Will NOT populate date-related props.
  2977. The EventNonDateInput has been normalized (id => publicId, etc).
  2978. */
  2979. function parseEventDef(raw, sourceId, allDay, hasEnd, calendar) {
  2980. var leftovers = {};
  2981. var def = pluckNonDateProps(raw, calendar, leftovers);
  2982. def.defId = String(uid++);
  2983. def.sourceId = sourceId;
  2984. def.allDay = allDay;
  2985. def.hasEnd = hasEnd;
  2986. for (var _i = 0, _a = calendar.pluginSystem.hooks.eventDefParsers; _i < _a.length; _i++) {
  2987. var eventDefParser = _a[_i];
  2988. var newLeftovers = {};
  2989. eventDefParser(def, leftovers, newLeftovers);
  2990. leftovers = newLeftovers;
  2991. }
  2992. def.extendedProps = __assign(leftovers, def.extendedProps || {});
  2993. // help out EventApi from having user modify props
  2994. Object.freeze(def.ui.classNames);
  2995. Object.freeze(def.extendedProps);
  2996. return def;
  2997. }
  2998. function createEventInstance(defId, range, forcedStartTzo, forcedEndTzo) {
  2999. return {
  3000. instanceId: String(uid++),
  3001. defId: defId,
  3002. range: range,
  3003. forcedStartTzo: forcedStartTzo == null ? null : forcedStartTzo,
  3004. forcedEndTzo: forcedEndTzo == null ? null : forcedEndTzo
  3005. };
  3006. }
  3007. function parseSingle(raw, allDayDefault, calendar, leftovers, allowOpenRange) {
  3008. var props = pluckDateProps(raw, leftovers);
  3009. var allDay = props.allDay;
  3010. var startMeta;
  3011. var startMarker = null;
  3012. var hasEnd = false;
  3013. var endMeta;
  3014. var endMarker = null;
  3015. startMeta = calendar.dateEnv.createMarkerMeta(props.start);
  3016. if (startMeta) {
  3017. startMarker = startMeta.marker;
  3018. }
  3019. else if (!allowOpenRange) {
  3020. return null;
  3021. }
  3022. if (props.end != null) {
  3023. endMeta = calendar.dateEnv.createMarkerMeta(props.end);
  3024. }
  3025. if (allDay == null) {
  3026. if (allDayDefault != null) {
  3027. allDay = allDayDefault;
  3028. }
  3029. else {
  3030. // fall back to the date props LAST
  3031. allDay = (!startMeta || startMeta.isTimeUnspecified) &&
  3032. (!endMeta || endMeta.isTimeUnspecified);
  3033. }
  3034. }
  3035. if (allDay && startMarker) {
  3036. startMarker = startOfDay(startMarker);
  3037. }
  3038. if (endMeta) {
  3039. endMarker = endMeta.marker;
  3040. if (allDay) {
  3041. endMarker = startOfDay(endMarker);
  3042. }
  3043. if (startMarker && endMarker <= startMarker) {
  3044. endMarker = null;
  3045. }
  3046. }
  3047. if (endMarker) {
  3048. hasEnd = true;
  3049. }
  3050. else if (!allowOpenRange) {
  3051. hasEnd = calendar.opt('forceEventDuration') || false;
  3052. endMarker = calendar.dateEnv.add(startMarker, allDay ?
  3053. calendar.defaultAllDayEventDuration :
  3054. calendar.defaultTimedEventDuration);
  3055. }
  3056. return {
  3057. allDay: allDay,
  3058. hasEnd: hasEnd,
  3059. range: { start: startMarker, end: endMarker },
  3060. forcedStartTzo: startMeta ? startMeta.forcedTzo : null,
  3061. forcedEndTzo: endMeta ? endMeta.forcedTzo : null
  3062. };
  3063. }
  3064. function pluckDateProps(raw, leftovers) {
  3065. var props = refineProps(raw, DATE_PROPS, {}, leftovers);
  3066. props.start = (props.start !== null) ? props.start : props.date;
  3067. delete props.date;
  3068. return props;
  3069. }
  3070. function pluckNonDateProps(raw, calendar, leftovers) {
  3071. var preLeftovers = {};
  3072. var props = refineProps(raw, NON_DATE_PROPS, {}, preLeftovers);
  3073. var ui = processUnscopedUiProps(preLeftovers, calendar, leftovers);
  3074. props.publicId = props.id;
  3075. delete props.id;
  3076. props.ui = ui;
  3077. return props;
  3078. }
  3079. function computeIsAllDayDefault(sourceId, calendar) {
  3080. var res = null;
  3081. if (sourceId) {
  3082. var source = calendar.state.eventSources[sourceId];
  3083. res = source.allDayDefault;
  3084. }
  3085. if (res == null) {
  3086. res = calendar.opt('allDayDefault');
  3087. }
  3088. return res;
  3089. }
  3090. var DEF_DEFAULTS = {
  3091. startTime: '09:00',
  3092. endTime: '17:00',
  3093. daysOfWeek: [1, 2, 3, 4, 5],
  3094. rendering: 'inverse-background',
  3095. classNames: 'fc-nonbusiness',
  3096. groupId: '_businessHours' // so multiple defs get grouped
  3097. };
  3098. /*
  3099. TODO: pass around as EventDefHash!!!
  3100. */
  3101. function parseBusinessHours(input, calendar) {
  3102. return parseEvents(refineInputs(input), '', calendar);
  3103. }
  3104. function refineInputs(input) {
  3105. var rawDefs;
  3106. if (input === true) {
  3107. rawDefs = [{}]; // will get DEF_DEFAULTS verbatim
  3108. }
  3109. else if (Array.isArray(input)) {
  3110. // if specifying an array, every sub-definition NEEDS a day-of-week
  3111. rawDefs = input.filter(function (rawDef) {
  3112. return rawDef.daysOfWeek;
  3113. });
  3114. }
  3115. else if (typeof input === 'object' && input) { // non-null object
  3116. rawDefs = [input];
  3117. }
  3118. else { // is probably false
  3119. rawDefs = [];
  3120. }
  3121. rawDefs = rawDefs.map(function (rawDef) {
  3122. return __assign({}, DEF_DEFAULTS, rawDef);
  3123. });
  3124. return rawDefs;
  3125. }
  3126. function memoizeRendering(renderFunc, unrenderFunc, dependencies) {
  3127. if (dependencies === void 0) { dependencies = []; }
  3128. var dependents = [];
  3129. var thisContext;
  3130. var prevArgs;
  3131. function unrender() {
  3132. if (prevArgs) {
  3133. for (var _i = 0, dependents_1 = dependents; _i < dependents_1.length; _i++) {
  3134. var dependent = dependents_1[_i];
  3135. dependent.unrender();
  3136. }
  3137. if (unrenderFunc) {
  3138. unrenderFunc.apply(thisContext, prevArgs);
  3139. }
  3140. prevArgs = null;
  3141. }
  3142. }
  3143. function res() {
  3144. if (!prevArgs || !isArraysEqual(prevArgs, arguments)) {
  3145. unrender();
  3146. thisContext = this;
  3147. prevArgs = arguments;
  3148. renderFunc.apply(this, arguments);
  3149. }
  3150. }
  3151. res.dependents = dependents;
  3152. res.unrender = unrender;
  3153. for (var _i = 0, dependencies_1 = dependencies; _i < dependencies_1.length; _i++) {
  3154. var dependency = dependencies_1[_i];
  3155. dependency.dependents.push(res);
  3156. }
  3157. return res;
  3158. }
  3159. var EMPTY_EVENT_STORE = createEmptyEventStore(); // for purecomponents. TODO: keep elsewhere
  3160. var Splitter = /** @class */ (function () {
  3161. function Splitter() {
  3162. this.getKeysForEventDefs = memoize(this._getKeysForEventDefs);
  3163. this.splitDateSelection = memoize(this._splitDateSpan);
  3164. this.splitEventStore = memoize(this._splitEventStore);
  3165. this.splitIndividualUi = memoize(this._splitIndividualUi);
  3166. this.splitEventDrag = memoize(this._splitInteraction);
  3167. this.splitEventResize = memoize(this._splitInteraction);
  3168. this.eventUiBuilders = {}; // TODO: typescript protection
  3169. }
  3170. Splitter.prototype.splitProps = function (props) {
  3171. var _this = this;
  3172. var keyInfos = this.getKeyInfo(props);
  3173. var defKeys = this.getKeysForEventDefs(props.eventStore);
  3174. var dateSelections = this.splitDateSelection(props.dateSelection);
  3175. var individualUi = this.splitIndividualUi(props.eventUiBases, defKeys); // the individual *bases*
  3176. var eventStores = this.splitEventStore(props.eventStore, defKeys);
  3177. var eventDrags = this.splitEventDrag(props.eventDrag);
  3178. var eventResizes = this.splitEventResize(props.eventResize);
  3179. var splitProps = {};
  3180. this.eventUiBuilders = mapHash(keyInfos, function (info, key) {
  3181. return _this.eventUiBuilders[key] || memoize(buildEventUiForKey);
  3182. });
  3183. for (var key in keyInfos) {
  3184. var keyInfo = keyInfos[key];
  3185. var eventStore = eventStores[key] || EMPTY_EVENT_STORE;
  3186. var buildEventUi = this.eventUiBuilders[key];
  3187. splitProps[key] = {
  3188. businessHours: keyInfo.businessHours || props.businessHours,
  3189. dateSelection: dateSelections[key] || null,
  3190. eventStore: eventStore,
  3191. eventUiBases: buildEventUi(props.eventUiBases[''], keyInfo.ui, individualUi[key]),
  3192. eventSelection: eventStore.instances[props.eventSelection] ? props.eventSelection : '',
  3193. eventDrag: eventDrags[key] || null,
  3194. eventResize: eventResizes[key] || null
  3195. };
  3196. }
  3197. return splitProps;
  3198. };
  3199. Splitter.prototype._splitDateSpan = function (dateSpan) {
  3200. var dateSpans = {};
  3201. if (dateSpan) {
  3202. var keys = this.getKeysForDateSpan(dateSpan);
  3203. for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
  3204. var key = keys_1[_i];
  3205. dateSpans[key] = dateSpan;
  3206. }
  3207. }
  3208. return dateSpans;
  3209. };
  3210. Splitter.prototype._getKeysForEventDefs = function (eventStore) {
  3211. var _this = this;
  3212. return mapHash(eventStore.defs, function (eventDef) {
  3213. return _this.getKeysForEventDef(eventDef);
  3214. });
  3215. };
  3216. Splitter.prototype._splitEventStore = function (eventStore, defKeys) {
  3217. var defs = eventStore.defs, instances = eventStore.instances;
  3218. var splitStores = {};
  3219. for (var defId in defs) {
  3220. for (var _i = 0, _a = defKeys[defId]; _i < _a.length; _i++) {
  3221. var key = _a[_i];
  3222. if (!splitStores[key]) {
  3223. splitStores[key] = createEmptyEventStore();
  3224. }
  3225. splitStores[key].defs[defId] = defs[defId];
  3226. }
  3227. }
  3228. for (var instanceId in instances) {
  3229. var instance = instances[instanceId];
  3230. for (var _b = 0, _c = defKeys[instance.defId]; _b < _c.length; _b++) {
  3231. var key = _c[_b];
  3232. if (splitStores[key]) { // must have already been created
  3233. splitStores[key].instances[instanceId] = instance;
  3234. }
  3235. }
  3236. }
  3237. return splitStores;
  3238. };
  3239. Splitter.prototype._splitIndividualUi = function (eventUiBases, defKeys) {
  3240. var splitHashes = {};
  3241. for (var defId in eventUiBases) {
  3242. if (defId) { // not the '' key
  3243. for (var _i = 0, _a = defKeys[defId]; _i < _a.length; _i++) {
  3244. var key = _a[_i];
  3245. if (!splitHashes[key]) {
  3246. splitHashes[key] = {};
  3247. }
  3248. splitHashes[key][defId] = eventUiBases[defId];
  3249. }
  3250. }
  3251. }
  3252. return splitHashes;
  3253. };
  3254. Splitter.prototype._splitInteraction = function (interaction) {
  3255. var splitStates = {};
  3256. if (interaction) {
  3257. var affectedStores_1 = this._splitEventStore(interaction.affectedEvents, this._getKeysForEventDefs(interaction.affectedEvents) // can't use cached. might be events from other calendar
  3258. );
  3259. // can't rely on defKeys because event data is mutated
  3260. var mutatedKeysByDefId = this._getKeysForEventDefs(interaction.mutatedEvents);
  3261. var mutatedStores_1 = this._splitEventStore(interaction.mutatedEvents, mutatedKeysByDefId);
  3262. var populate = function (key) {
  3263. if (!splitStates[key]) {
  3264. splitStates[key] = {
  3265. affectedEvents: affectedStores_1[key] || EMPTY_EVENT_STORE,
  3266. mutatedEvents: mutatedStores_1[key] || EMPTY_EVENT_STORE,
  3267. isEvent: interaction.isEvent,
  3268. origSeg: interaction.origSeg
  3269. };
  3270. }
  3271. };
  3272. for (var key in affectedStores_1) {
  3273. populate(key);
  3274. }
  3275. for (var key in mutatedStores_1) {
  3276. populate(key);
  3277. }
  3278. }
  3279. return splitStates;
  3280. };
  3281. return Splitter;
  3282. }());
  3283. function buildEventUiForKey(allUi, eventUiForKey, individualUi) {
  3284. var baseParts = [];
  3285. if (allUi) {
  3286. baseParts.push(allUi);
  3287. }
  3288. if (eventUiForKey) {
  3289. baseParts.push(eventUiForKey);
  3290. }
  3291. var stuff = {
  3292. '': combineEventUis(baseParts)
  3293. };
  3294. if (individualUi) {
  3295. __assign(stuff, individualUi);
  3296. }
  3297. return stuff;
  3298. }
  3299. // Generates HTML for an anchor to another view into the calendar.
  3300. // Will either generate an <a> tag or a non-clickable <span> tag, depending on enabled settings.
  3301. // `gotoOptions` can either be a DateMarker, or an object with the form:
  3302. // { date, type, forceOff }
  3303. // `type` is a view-type like "day" or "week". default value is "day".
  3304. // `attrs` and `innerHtml` are use to generate the rest of the HTML tag.
  3305. function buildGotoAnchorHtml(component, gotoOptions, attrs, innerHtml) {
  3306. var dateEnv = component.dateEnv;
  3307. var date;
  3308. var type;
  3309. var forceOff;
  3310. var finalOptions;
  3311. if (gotoOptions instanceof Date) {
  3312. date = gotoOptions; // a single date-like input
  3313. }
  3314. else {
  3315. date = gotoOptions.date;
  3316. type = gotoOptions.type;
  3317. forceOff = gotoOptions.forceOff;
  3318. }
  3319. finalOptions = {
  3320. date: dateEnv.formatIso(date, { omitTime: true }),
  3321. type: type || 'day'
  3322. };
  3323. if (typeof attrs === 'string') {
  3324. innerHtml = attrs;
  3325. attrs = null;
  3326. }
  3327. attrs = attrs ? ' ' + attrsToStr(attrs) : ''; // will have a leading space
  3328. innerHtml = innerHtml || '';
  3329. if (!forceOff && component.opt('navLinks')) {
  3330. return '<a' + attrs +
  3331. ' data-goto="' + htmlEscape(JSON.stringify(finalOptions)) + '">' +
  3332. innerHtml +
  3333. '</a>';
  3334. }
  3335. else {
  3336. return '<span' + attrs + '>' +
  3337. innerHtml +
  3338. '</span>';
  3339. }
  3340. }
  3341. function getAllDayHtml(component) {
  3342. return component.opt('allDayHtml') || htmlEscape(component.opt('allDayText'));
  3343. }
  3344. // Computes HTML classNames for a single-day element
  3345. function getDayClasses(date, dateProfile, context, noThemeHighlight) {
  3346. var calendar = context.calendar, view = context.view, theme = context.theme, dateEnv = context.dateEnv;
  3347. var classes = [];
  3348. var todayStart;
  3349. var todayEnd;
  3350. if (!rangeContainsMarker(dateProfile.activeRange, date)) {
  3351. classes.push('fc-disabled-day');
  3352. }
  3353. else {
  3354. classes.push('fc-' + DAY_IDS[date.getUTCDay()]);
  3355. if (view.opt('monthMode') &&
  3356. dateEnv.getMonth(date) !== dateEnv.getMonth(dateProfile.currentRange.start)) {
  3357. classes.push('fc-other-month');
  3358. }
  3359. todayStart = startOfDay(calendar.getNow());
  3360. todayEnd = addDays(todayStart, 1);
  3361. if (date < todayStart) {
  3362. classes.push('fc-past');
  3363. }
  3364. else if (date >= todayEnd) {
  3365. classes.push('fc-future');
  3366. }
  3367. else {
  3368. classes.push('fc-today');
  3369. if (noThemeHighlight !== true) {
  3370. classes.push(theme.getClass('today'));
  3371. }
  3372. }
  3373. }
  3374. return classes;
  3375. }
  3376. // given a function that resolves a result asynchronously.
  3377. // the function can either call passed-in success and failure callbacks,
  3378. // or it can return a promise.
  3379. // if you need to pass additional params to func, bind them first.
  3380. function unpromisify(func, success, failure) {
  3381. // guard against success/failure callbacks being called more than once
  3382. // and guard against a promise AND callback being used together.
  3383. var isResolved = false;
  3384. var wrappedSuccess = function () {
  3385. if (!isResolved) {
  3386. isResolved = true;
  3387. success.apply(this, arguments);
  3388. }
  3389. };
  3390. var wrappedFailure = function () {
  3391. if (!isResolved) {
  3392. isResolved = true;
  3393. if (failure) {
  3394. failure.apply(this, arguments);
  3395. }
  3396. }
  3397. };
  3398. var res = func(wrappedSuccess, wrappedFailure);
  3399. if (res && typeof res.then === 'function') {
  3400. res.then(wrappedSuccess, wrappedFailure);
  3401. }
  3402. }
  3403. var Mixin = /** @class */ (function () {
  3404. function Mixin() {
  3405. }
  3406. // mix into a CLASS
  3407. Mixin.mixInto = function (destClass) {
  3408. this.mixIntoObj(destClass.prototype);
  3409. };
  3410. // mix into ANY object
  3411. Mixin.mixIntoObj = function (destObj) {
  3412. var _this = this;
  3413. Object.getOwnPropertyNames(this.prototype).forEach(function (name) {
  3414. if (!destObj[name]) { // if destination doesn't already define it
  3415. destObj[name] = _this.prototype[name];
  3416. }
  3417. });
  3418. };
  3419. /*
  3420. will override existing methods
  3421. TODO: remove! not used anymore
  3422. */
  3423. Mixin.mixOver = function (destClass) {
  3424. var _this = this;
  3425. Object.getOwnPropertyNames(this.prototype).forEach(function (name) {
  3426. destClass.prototype[name] = _this.prototype[name];
  3427. });
  3428. };
  3429. return Mixin;
  3430. }());
  3431. /*
  3432. USAGE:
  3433. import { default as EmitterMixin, EmitterInterface } from './EmitterMixin'
  3434. in class:
  3435. on: EmitterInterface['on']
  3436. one: EmitterInterface['one']
  3437. off: EmitterInterface['off']
  3438. trigger: EmitterInterface['trigger']
  3439. triggerWith: EmitterInterface['triggerWith']
  3440. hasHandlers: EmitterInterface['hasHandlers']
  3441. after class:
  3442. EmitterMixin.mixInto(TheClass)
  3443. */
  3444. var EmitterMixin = /** @class */ (function (_super) {
  3445. __extends(EmitterMixin, _super);
  3446. function EmitterMixin() {
  3447. return _super !== null && _super.apply(this, arguments) || this;
  3448. }
  3449. EmitterMixin.prototype.on = function (type, handler) {
  3450. addToHash(this._handlers || (this._handlers = {}), type, handler);
  3451. return this; // for chaining
  3452. };
  3453. // todo: add comments
  3454. EmitterMixin.prototype.one = function (type, handler) {
  3455. addToHash(this._oneHandlers || (this._oneHandlers = {}), type, handler);
  3456. return this; // for chaining
  3457. };
  3458. EmitterMixin.prototype.off = function (type, handler) {
  3459. if (this._handlers) {
  3460. removeFromHash(this._handlers, type, handler);
  3461. }
  3462. if (this._oneHandlers) {
  3463. removeFromHash(this._oneHandlers, type, handler);
  3464. }
  3465. return this; // for chaining
  3466. };
  3467. EmitterMixin.prototype.trigger = function (type) {
  3468. var args = [];
  3469. for (var _i = 1; _i < arguments.length; _i++) {
  3470. args[_i - 1] = arguments[_i];
  3471. }
  3472. this.triggerWith(type, this, args);
  3473. return this; // for chaining
  3474. };
  3475. EmitterMixin.prototype.triggerWith = function (type, context, args) {
  3476. if (this._handlers) {
  3477. applyAll(this._handlers[type], context, args);
  3478. }
  3479. if (this._oneHandlers) {
  3480. applyAll(this._oneHandlers[type], context, args);
  3481. delete this._oneHandlers[type]; // will never fire again
  3482. }
  3483. return this; // for chaining
  3484. };
  3485. EmitterMixin.prototype.hasHandlers = function (type) {
  3486. return (this._handlers && this._handlers[type] && this._handlers[type].length) ||
  3487. (this._oneHandlers && this._oneHandlers[type] && this._oneHandlers[type].length);
  3488. };
  3489. return EmitterMixin;
  3490. }(Mixin));
  3491. function addToHash(hash, type, handler) {
  3492. (hash[type] || (hash[type] = []))
  3493. .push(handler);
  3494. }
  3495. function removeFromHash(hash, type, handler) {
  3496. if (handler) {
  3497. if (hash[type]) {
  3498. hash[type] = hash[type].filter(function (func) {
  3499. return func !== handler;
  3500. });
  3501. }
  3502. }
  3503. else {
  3504. delete hash[type]; // remove all handler funcs for this type
  3505. }
  3506. }
  3507. /*
  3508. Records offset information for a set of elements, relative to an origin element.
  3509. Can record the left/right OR the top/bottom OR both.
  3510. Provides methods for querying the cache by position.
  3511. */
  3512. var PositionCache = /** @class */ (function () {
  3513. function PositionCache(originEl, els, isHorizontal, isVertical) {
  3514. this.originEl = originEl;
  3515. this.els = els;
  3516. this.isHorizontal = isHorizontal;
  3517. this.isVertical = isVertical;
  3518. }
  3519. // Queries the els for coordinates and stores them.
  3520. // Call this method before using and of the get* methods below.
  3521. PositionCache.prototype.build = function () {
  3522. var originEl = this.originEl;
  3523. var originClientRect = this.originClientRect =
  3524. originEl.getBoundingClientRect(); // relative to viewport top-left
  3525. if (this.isHorizontal) {
  3526. this.buildElHorizontals(originClientRect.left);
  3527. }
  3528. if (this.isVertical) {
  3529. this.buildElVerticals(originClientRect.top);
  3530. }
  3531. };
  3532. // Populates the left/right internal coordinate arrays
  3533. PositionCache.prototype.buildElHorizontals = function (originClientLeft) {
  3534. var lefts = [];
  3535. var rights = [];
  3536. for (var _i = 0, _a = this.els; _i < _a.length; _i++) {
  3537. var el = _a[_i];
  3538. var rect = el.getBoundingClientRect();
  3539. lefts.push(rect.left - originClientLeft);
  3540. rights.push(rect.right - originClientLeft);
  3541. }
  3542. this.lefts = lefts;
  3543. this.rights = rights;
  3544. };
  3545. // Populates the top/bottom internal coordinate arrays
  3546. PositionCache.prototype.buildElVerticals = function (originClientTop) {
  3547. var tops = [];
  3548. var bottoms = [];
  3549. for (var _i = 0, _a = this.els; _i < _a.length; _i++) {
  3550. var el = _a[_i];
  3551. var rect = el.getBoundingClientRect();
  3552. tops.push(rect.top - originClientTop);
  3553. bottoms.push(rect.bottom - originClientTop);
  3554. }
  3555. this.tops = tops;
  3556. this.bottoms = bottoms;
  3557. };
  3558. // Given a left offset (from document left), returns the index of the el that it horizontally intersects.
  3559. // If no intersection is made, returns undefined.
  3560. PositionCache.prototype.leftToIndex = function (leftPosition) {
  3561. var lefts = this.lefts;
  3562. var rights = this.rights;
  3563. var len = lefts.length;
  3564. var i;
  3565. for (i = 0; i < len; i++) {
  3566. if (leftPosition >= lefts[i] && leftPosition < rights[i]) {
  3567. return i;
  3568. }
  3569. }
  3570. };
  3571. // Given a top offset (from document top), returns the index of the el that it vertically intersects.
  3572. // If no intersection is made, returns undefined.
  3573. PositionCache.prototype.topToIndex = function (topPosition) {
  3574. var tops = this.tops;
  3575. var bottoms = this.bottoms;
  3576. var len = tops.length;
  3577. var i;
  3578. for (i = 0; i < len; i++) {
  3579. if (topPosition >= tops[i] && topPosition < bottoms[i]) {
  3580. return i;
  3581. }
  3582. }
  3583. };
  3584. // Gets the width of the element at the given index
  3585. PositionCache.prototype.getWidth = function (leftIndex) {
  3586. return this.rights[leftIndex] - this.lefts[leftIndex];
  3587. };
  3588. // Gets the height of the element at the given index
  3589. PositionCache.prototype.getHeight = function (topIndex) {
  3590. return this.bottoms[topIndex] - this.tops[topIndex];
  3591. };
  3592. return PositionCache;
  3593. }());
  3594. /*
  3595. An object for getting/setting scroll-related information for an element.
  3596. Internally, this is done very differently for window versus DOM element,
  3597. so this object serves as a common interface.
  3598. */
  3599. var ScrollController = /** @class */ (function () {
  3600. function ScrollController() {
  3601. }
  3602. ScrollController.prototype.getMaxScrollTop = function () {
  3603. return this.getScrollHeight() - this.getClientHeight();
  3604. };
  3605. ScrollController.prototype.getMaxScrollLeft = function () {
  3606. return this.getScrollWidth() - this.getClientWidth();
  3607. };
  3608. ScrollController.prototype.canScrollVertically = function () {
  3609. return this.getMaxScrollTop() > 0;
  3610. };
  3611. ScrollController.prototype.canScrollHorizontally = function () {
  3612. return this.getMaxScrollLeft() > 0;
  3613. };
  3614. ScrollController.prototype.canScrollUp = function () {
  3615. return this.getScrollTop() > 0;
  3616. };
  3617. ScrollController.prototype.canScrollDown = function () {
  3618. return this.getScrollTop() < this.getMaxScrollTop();
  3619. };
  3620. ScrollController.prototype.canScrollLeft = function () {
  3621. return this.getScrollLeft() > 0;
  3622. };
  3623. ScrollController.prototype.canScrollRight = function () {
  3624. return this.getScrollLeft() < this.getMaxScrollLeft();
  3625. };
  3626. return ScrollController;
  3627. }());
  3628. var ElementScrollController = /** @class */ (function (_super) {
  3629. __extends(ElementScrollController, _super);
  3630. function ElementScrollController(el) {
  3631. var _this = _super.call(this) || this;
  3632. _this.el = el;
  3633. return _this;
  3634. }
  3635. ElementScrollController.prototype.getScrollTop = function () {
  3636. return this.el.scrollTop;
  3637. };
  3638. ElementScrollController.prototype.getScrollLeft = function () {
  3639. return this.el.scrollLeft;
  3640. };
  3641. ElementScrollController.prototype.setScrollTop = function (top) {
  3642. this.el.scrollTop = top;
  3643. };
  3644. ElementScrollController.prototype.setScrollLeft = function (left) {
  3645. this.el.scrollLeft = left;
  3646. };
  3647. ElementScrollController.prototype.getScrollWidth = function () {
  3648. return this.el.scrollWidth;
  3649. };
  3650. ElementScrollController.prototype.getScrollHeight = function () {
  3651. return this.el.scrollHeight;
  3652. };
  3653. ElementScrollController.prototype.getClientHeight = function () {
  3654. return this.el.clientHeight;
  3655. };
  3656. ElementScrollController.prototype.getClientWidth = function () {
  3657. return this.el.clientWidth;
  3658. };
  3659. return ElementScrollController;
  3660. }(ScrollController));
  3661. var WindowScrollController = /** @class */ (function (_super) {
  3662. __extends(WindowScrollController, _super);
  3663. function WindowScrollController() {
  3664. return _super !== null && _super.apply(this, arguments) || this;
  3665. }
  3666. WindowScrollController.prototype.getScrollTop = function () {
  3667. return window.pageYOffset;
  3668. };
  3669. WindowScrollController.prototype.getScrollLeft = function () {
  3670. return window.pageXOffset;
  3671. };
  3672. WindowScrollController.prototype.setScrollTop = function (n) {
  3673. window.scroll(window.pageXOffset, n);
  3674. };
  3675. WindowScrollController.prototype.setScrollLeft = function (n) {
  3676. window.scroll(n, window.pageYOffset);
  3677. };
  3678. WindowScrollController.prototype.getScrollWidth = function () {
  3679. return document.documentElement.scrollWidth;
  3680. };
  3681. WindowScrollController.prototype.getScrollHeight = function () {
  3682. return document.documentElement.scrollHeight;
  3683. };
  3684. WindowScrollController.prototype.getClientHeight = function () {
  3685. return document.documentElement.clientHeight;
  3686. };
  3687. WindowScrollController.prototype.getClientWidth = function () {
  3688. return document.documentElement.clientWidth;
  3689. };
  3690. return WindowScrollController;
  3691. }(ScrollController));
  3692. /*
  3693. Embodies a div that has potential scrollbars
  3694. */
  3695. var ScrollComponent = /** @class */ (function (_super) {
  3696. __extends(ScrollComponent, _super);
  3697. function ScrollComponent(overflowX, overflowY) {
  3698. var _this = _super.call(this, createElement('div', {
  3699. className: 'fc-scroller'
  3700. })) || this;
  3701. _this.overflowX = overflowX;
  3702. _this.overflowY = overflowY;
  3703. _this.applyOverflow();
  3704. return _this;
  3705. }
  3706. // sets to natural height, unlocks overflow
  3707. ScrollComponent.prototype.clear = function () {
  3708. this.setHeight('auto');
  3709. this.applyOverflow();
  3710. };
  3711. ScrollComponent.prototype.destroy = function () {
  3712. removeElement(this.el);
  3713. };
  3714. // Overflow
  3715. // -----------------------------------------------------------------------------------------------------------------
  3716. ScrollComponent.prototype.applyOverflow = function () {
  3717. applyStyle(this.el, {
  3718. overflowX: this.overflowX,
  3719. overflowY: this.overflowY
  3720. });
  3721. };
  3722. // Causes any 'auto' overflow values to resolves to 'scroll' or 'hidden'.
  3723. // Useful for preserving scrollbar widths regardless of future resizes.
  3724. // Can pass in scrollbarWidths for optimization.
  3725. ScrollComponent.prototype.lockOverflow = function (scrollbarWidths) {
  3726. var overflowX = this.overflowX;
  3727. var overflowY = this.overflowY;
  3728. scrollbarWidths = scrollbarWidths || this.getScrollbarWidths();
  3729. if (overflowX === 'auto') {
  3730. overflowX = (scrollbarWidths.bottom || // horizontal scrollbars?
  3731. this.canScrollHorizontally() // OR scrolling pane with massless scrollbars?
  3732. ) ? 'scroll' : 'hidden';
  3733. }
  3734. if (overflowY === 'auto') {
  3735. overflowY = (scrollbarWidths.left || scrollbarWidths.right || // horizontal scrollbars?
  3736. this.canScrollVertically() // OR scrolling pane with massless scrollbars?
  3737. ) ? 'scroll' : 'hidden';
  3738. }
  3739. applyStyle(this.el, { overflowX: overflowX, overflowY: overflowY });
  3740. };
  3741. ScrollComponent.prototype.setHeight = function (height) {
  3742. applyStyleProp(this.el, 'height', height);
  3743. };
  3744. ScrollComponent.prototype.getScrollbarWidths = function () {
  3745. var edges = computeEdges(this.el);
  3746. return {
  3747. left: edges.scrollbarLeft,
  3748. right: edges.scrollbarRight,
  3749. bottom: edges.scrollbarBottom
  3750. };
  3751. };
  3752. return ScrollComponent;
  3753. }(ElementScrollController));
  3754. var Theme = /** @class */ (function () {
  3755. function Theme(calendarOptions) {
  3756. this.calendarOptions = calendarOptions;
  3757. this.processIconOverride();
  3758. }
  3759. Theme.prototype.processIconOverride = function () {
  3760. if (this.iconOverrideOption) {
  3761. this.setIconOverride(this.calendarOptions[this.iconOverrideOption]);
  3762. }
  3763. };
  3764. Theme.prototype.setIconOverride = function (iconOverrideHash) {
  3765. var iconClassesCopy;
  3766. var buttonName;
  3767. if (typeof iconOverrideHash === 'object' && iconOverrideHash) { // non-null object
  3768. iconClassesCopy = __assign({}, this.iconClasses);
  3769. for (buttonName in iconOverrideHash) {
  3770. iconClassesCopy[buttonName] = this.applyIconOverridePrefix(iconOverrideHash[buttonName]);
  3771. }
  3772. this.iconClasses = iconClassesCopy;
  3773. }
  3774. else if (iconOverrideHash === false) {
  3775. this.iconClasses = {};
  3776. }
  3777. };
  3778. Theme.prototype.applyIconOverridePrefix = function (className) {
  3779. var prefix = this.iconOverridePrefix;
  3780. if (prefix && className.indexOf(prefix) !== 0) { // if not already present
  3781. className = prefix + className;
  3782. }
  3783. return className;
  3784. };
  3785. Theme.prototype.getClass = function (key) {
  3786. return this.classes[key] || '';
  3787. };
  3788. Theme.prototype.getIconClass = function (buttonName) {
  3789. var className = this.iconClasses[buttonName];
  3790. if (className) {
  3791. return this.baseIconClass + ' ' + className;
  3792. }
  3793. return '';
  3794. };
  3795. Theme.prototype.getCustomButtonIconClass = function (customButtonProps) {
  3796. var className;
  3797. if (this.iconOverrideCustomButtonOption) {
  3798. className = customButtonProps[this.iconOverrideCustomButtonOption];
  3799. if (className) {
  3800. return this.baseIconClass + ' ' + this.applyIconOverridePrefix(className);
  3801. }
  3802. }
  3803. return '';
  3804. };
  3805. return Theme;
  3806. }());
  3807. Theme.prototype.classes = {};
  3808. Theme.prototype.iconClasses = {};
  3809. Theme.prototype.baseIconClass = '';
  3810. Theme.prototype.iconOverridePrefix = '';
  3811. var guid = 0;
  3812. var Component = /** @class */ (function () {
  3813. function Component(context, isView) {
  3814. // HACK to populate view at top of component instantiation call chain
  3815. if (isView) {
  3816. context.view = this;
  3817. }
  3818. this.uid = String(guid++);
  3819. this.context = context;
  3820. this.dateEnv = context.dateEnv;
  3821. this.theme = context.theme;
  3822. this.view = context.view;
  3823. this.calendar = context.calendar;
  3824. this.isRtl = this.opt('dir') === 'rtl';
  3825. }
  3826. Component.addEqualityFuncs = function (newFuncs) {
  3827. this.prototype.equalityFuncs = __assign({}, this.prototype.equalityFuncs, newFuncs);
  3828. };
  3829. Component.prototype.opt = function (name) {
  3830. return this.context.options[name];
  3831. };
  3832. Component.prototype.receiveProps = function (props) {
  3833. var _a = recycleProps(this.props || {}, props, this.equalityFuncs), anyChanges = _a.anyChanges, comboProps = _a.comboProps;
  3834. this.props = comboProps;
  3835. if (anyChanges) {
  3836. this.render(comboProps);
  3837. }
  3838. };
  3839. Component.prototype.render = function (props) {
  3840. };
  3841. // after destroy is called, this component won't ever be used again
  3842. Component.prototype.destroy = function () {
  3843. };
  3844. return Component;
  3845. }());
  3846. Component.prototype.equalityFuncs = {};
  3847. /*
  3848. Reuses old values when equal. If anything is unequal, returns newProps as-is.
  3849. Great for PureComponent, but won't be feasible with React, so just eliminate and use React's DOM diffing.
  3850. */
  3851. function recycleProps(oldProps, newProps, equalityFuncs) {
  3852. var comboProps = {}; // some old, some new
  3853. var anyChanges = false;
  3854. for (var key in newProps) {
  3855. if (key in oldProps && (oldProps[key] === newProps[key] ||
  3856. (equalityFuncs[key] && equalityFuncs[key](oldProps[key], newProps[key])))) {
  3857. // equal to old? use old prop
  3858. comboProps[key] = oldProps[key];
  3859. }
  3860. else {
  3861. comboProps[key] = newProps[key];
  3862. anyChanges = true;
  3863. }
  3864. }
  3865. for (var key in oldProps) {
  3866. if (!(key in newProps)) {
  3867. anyChanges = true;
  3868. break;
  3869. }
  3870. }
  3871. return { anyChanges: anyChanges, comboProps: comboProps };
  3872. }
  3873. /*
  3874. PURPOSES:
  3875. - hook up to fg, fill, and mirror renderers
  3876. - interface for dragging and hits
  3877. */
  3878. var DateComponent = /** @class */ (function (_super) {
  3879. __extends(DateComponent, _super);
  3880. function DateComponent(context, el, isView) {
  3881. var _this = _super.call(this, context, isView) || this;
  3882. _this.el = el;
  3883. return _this;
  3884. }
  3885. DateComponent.prototype.destroy = function () {
  3886. _super.prototype.destroy.call(this);
  3887. removeElement(this.el);
  3888. };
  3889. // TODO: WHAT ABOUT (sourceSeg && sourceSeg.component.doesDragMirror)
  3890. //
  3891. // Event Drag-n-Drop Rendering (for both events and external elements)
  3892. // ---------------------------------------------------------------------------------------------------------------
  3893. /*
  3894. renderEventDragSegs(state: EventSegUiInteractionState) {
  3895. if (state) {
  3896. let { isEvent, segs, sourceSeg } = state
  3897. if (this.eventRenderer) {
  3898. this.eventRenderer.hideByHash(state.affectedInstances)
  3899. }
  3900. // if the user is dragging something that is considered an event with real event data,
  3901. // and this component likes to do drag mirrors OR the component where the seg came from
  3902. // likes to do drag mirrors, then render a drag mirror.
  3903. if (isEvent && (this.doesDragMirror || sourceSeg && sourceSeg.component.doesDragMirror)) {
  3904. if (this.mirrorRenderer) {
  3905. this.mirrorRenderer.renderSegs(segs, { isDragging: true, sourceSeg })
  3906. }
  3907. }
  3908. // if it would be impossible to render a drag mirror OR this component likes to render
  3909. // highlights, then render a highlight.
  3910. if (!isEvent || this.doesDragHighlight) {
  3911. if (this.fillRenderer) {
  3912. this.fillRenderer.renderSegs('highlight', segs)
  3913. }
  3914. }
  3915. }
  3916. }
  3917. */
  3918. // Hit System
  3919. // -----------------------------------------------------------------------------------------------------------------
  3920. DateComponent.prototype.buildPositionCaches = function () {
  3921. };
  3922. DateComponent.prototype.queryHit = function (positionLeft, positionTop, elWidth, elHeight) {
  3923. return null; // this should be abstract
  3924. };
  3925. // Validation
  3926. // -----------------------------------------------------------------------------------------------------------------
  3927. DateComponent.prototype.isInteractionValid = function (interaction) {
  3928. var calendar = this.calendar;
  3929. var dateProfile = this.props.dateProfile; // HACK
  3930. var instances = interaction.mutatedEvents.instances;
  3931. if (dateProfile) { // HACK for DayTile
  3932. for (var instanceId in instances) {
  3933. if (!rangeContainsRange(dateProfile.validRange, instances[instanceId].range)) {
  3934. return false;
  3935. }
  3936. }
  3937. }
  3938. return isInteractionValid(interaction, calendar);
  3939. };
  3940. DateComponent.prototype.isDateSelectionValid = function (selection) {
  3941. var dateProfile = this.props.dateProfile; // HACK
  3942. if (dateProfile && // HACK for DayTile
  3943. !rangeContainsRange(dateProfile.validRange, selection.range)) {
  3944. return false;
  3945. }
  3946. return isDateSelectionValid(selection, this.calendar);
  3947. };
  3948. // Triggering
  3949. // -----------------------------------------------------------------------------------------------------------------
  3950. // TODO: move to Calendar
  3951. DateComponent.prototype.publiclyTrigger = function (name, args) {
  3952. var calendar = this.calendar;
  3953. return calendar.publiclyTrigger(name, args);
  3954. };
  3955. DateComponent.prototype.publiclyTriggerAfterSizing = function (name, args) {
  3956. var calendar = this.calendar;
  3957. return calendar.publiclyTriggerAfterSizing(name, args);
  3958. };
  3959. DateComponent.prototype.hasPublicHandlers = function (name) {
  3960. var calendar = this.calendar;
  3961. return calendar.hasPublicHandlers(name);
  3962. };
  3963. DateComponent.prototype.triggerRenderedSegs = function (segs, isMirrors) {
  3964. var calendar = this.calendar;
  3965. if (this.hasPublicHandlers('eventPositioned')) {
  3966. for (var _i = 0, segs_1 = segs; _i < segs_1.length; _i++) {
  3967. var seg = segs_1[_i];
  3968. this.publiclyTriggerAfterSizing('eventPositioned', [
  3969. {
  3970. event: new EventApi(calendar, seg.eventRange.def, seg.eventRange.instance),
  3971. isMirror: isMirrors,
  3972. isStart: seg.isStart,
  3973. isEnd: seg.isEnd,
  3974. el: seg.el,
  3975. view: this // safe to cast because this method is only called on context.view
  3976. }
  3977. ]);
  3978. }
  3979. }
  3980. if (!calendar.state.loadingLevel) { // avoid initial empty state while pending
  3981. calendar.afterSizingTriggers._eventsPositioned = [null]; // fire once
  3982. }
  3983. };
  3984. DateComponent.prototype.triggerWillRemoveSegs = function (segs, isMirrors) {
  3985. var calendar = this.calendar;
  3986. for (var _i = 0, segs_2 = segs; _i < segs_2.length; _i++) {
  3987. var seg = segs_2[_i];
  3988. calendar.trigger('eventElRemove', seg.el);
  3989. }
  3990. if (this.hasPublicHandlers('eventDestroy')) {
  3991. for (var _a = 0, segs_3 = segs; _a < segs_3.length; _a++) {
  3992. var seg = segs_3[_a];
  3993. this.publiclyTrigger('eventDestroy', [
  3994. {
  3995. event: new EventApi(calendar, seg.eventRange.def, seg.eventRange.instance),
  3996. isMirror: isMirrors,
  3997. el: seg.el,
  3998. view: this // safe to cast because this method is only called on context.view
  3999. }
  4000. ]);
  4001. }
  4002. }
  4003. };
  4004. // Pointer Interaction Utils
  4005. // -----------------------------------------------------------------------------------------------------------------
  4006. DateComponent.prototype.isValidSegDownEl = function (el) {
  4007. return !this.props.eventDrag && // HACK
  4008. !this.props.eventResize && // HACK
  4009. !elementClosest(el, '.fc-mirror') &&
  4010. (this.isPopover() || !this.isInPopover(el));
  4011. // ^above line ensures we don't detect a seg interaction within a nested component.
  4012. // it's a HACK because it only supports a popover as the nested component.
  4013. };
  4014. DateComponent.prototype.isValidDateDownEl = function (el) {
  4015. var segEl = elementClosest(el, this.fgSegSelector);
  4016. return (!segEl || segEl.classList.contains('fc-mirror')) &&
  4017. !elementClosest(el, '.fc-more') && // a "more.." link
  4018. !elementClosest(el, 'a[data-goto]') && // a clickable nav link
  4019. !this.isInPopover(el);
  4020. };
  4021. DateComponent.prototype.isPopover = function () {
  4022. return this.el.classList.contains('fc-popover');
  4023. };
  4024. DateComponent.prototype.isInPopover = function (el) {
  4025. return Boolean(elementClosest(el, '.fc-popover'));
  4026. };
  4027. return DateComponent;
  4028. }(Component));
  4029. DateComponent.prototype.fgSegSelector = '.fc-event-container > *';
  4030. DateComponent.prototype.bgSegSelector = '.fc-bgevent:not(.fc-nonbusiness)';
  4031. var uid$1 = 0;
  4032. function createPlugin(input) {
  4033. return {
  4034. id: String(uid$1++),
  4035. deps: input.deps || [],
  4036. reducers: input.reducers || [],
  4037. eventDefParsers: input.eventDefParsers || [],
  4038. isDraggableTransformers: input.isDraggableTransformers || [],
  4039. eventDragMutationMassagers: input.eventDragMutationMassagers || [],
  4040. eventDefMutationAppliers: input.eventDefMutationAppliers || [],
  4041. dateSelectionTransformers: input.dateSelectionTransformers || [],
  4042. datePointTransforms: input.datePointTransforms || [],
  4043. dateSpanTransforms: input.dateSpanTransforms || [],
  4044. views: input.views || {},
  4045. viewPropsTransformers: input.viewPropsTransformers || [],
  4046. isPropsValid: input.isPropsValid || null,
  4047. externalDefTransforms: input.externalDefTransforms || [],
  4048. eventResizeJoinTransforms: input.eventResizeJoinTransforms || [],
  4049. viewContainerModifiers: input.viewContainerModifiers || [],
  4050. eventDropTransformers: input.eventDropTransformers || [],
  4051. componentInteractions: input.componentInteractions || [],
  4052. calendarInteractions: input.calendarInteractions || [],
  4053. themeClasses: input.themeClasses || {},
  4054. eventSourceDefs: input.eventSourceDefs || [],
  4055. cmdFormatter: input.cmdFormatter,
  4056. recurringTypes: input.recurringTypes || [],
  4057. namedTimeZonedImpl: input.namedTimeZonedImpl,
  4058. defaultView: input.defaultView || '',
  4059. elementDraggingImpl: input.elementDraggingImpl,
  4060. optionChangeHandlers: input.optionChangeHandlers || {}
  4061. };
  4062. }
  4063. var PluginSystem = /** @class */ (function () {
  4064. function PluginSystem() {
  4065. this.hooks = {
  4066. reducers: [],
  4067. eventDefParsers: [],
  4068. isDraggableTransformers: [],
  4069. eventDragMutationMassagers: [],
  4070. eventDefMutationAppliers: [],
  4071. dateSelectionTransformers: [],
  4072. datePointTransforms: [],
  4073. dateSpanTransforms: [],
  4074. views: {},
  4075. viewPropsTransformers: [],
  4076. isPropsValid: null,
  4077. externalDefTransforms: [],
  4078. eventResizeJoinTransforms: [],
  4079. viewContainerModifiers: [],
  4080. eventDropTransformers: [],
  4081. componentInteractions: [],
  4082. calendarInteractions: [],
  4083. themeClasses: {},
  4084. eventSourceDefs: [],
  4085. cmdFormatter: null,
  4086. recurringTypes: [],
  4087. namedTimeZonedImpl: null,
  4088. defaultView: '',
  4089. elementDraggingImpl: null,
  4090. optionChangeHandlers: {}
  4091. };
  4092. this.addedHash = {};
  4093. }
  4094. PluginSystem.prototype.add = function (plugin) {
  4095. if (!this.addedHash[plugin.id]) {
  4096. this.addedHash[plugin.id] = true;
  4097. for (var _i = 0, _a = plugin.deps; _i < _a.length; _i++) {
  4098. var dep = _a[_i];
  4099. this.add(dep);
  4100. }
  4101. this.hooks = combineHooks(this.hooks, plugin);
  4102. }
  4103. };
  4104. return PluginSystem;
  4105. }());
  4106. function combineHooks(hooks0, hooks1) {
  4107. return {
  4108. reducers: hooks0.reducers.concat(hooks1.reducers),
  4109. eventDefParsers: hooks0.eventDefParsers.concat(hooks1.eventDefParsers),
  4110. isDraggableTransformers: hooks0.isDraggableTransformers.concat(hooks1.isDraggableTransformers),
  4111. eventDragMutationMassagers: hooks0.eventDragMutationMassagers.concat(hooks1.eventDragMutationMassagers),
  4112. eventDefMutationAppliers: hooks0.eventDefMutationAppliers.concat(hooks1.eventDefMutationAppliers),
  4113. dateSelectionTransformers: hooks0.dateSelectionTransformers.concat(hooks1.dateSelectionTransformers),
  4114. datePointTransforms: hooks0.datePointTransforms.concat(hooks1.datePointTransforms),
  4115. dateSpanTransforms: hooks0.dateSpanTransforms.concat(hooks1.dateSpanTransforms),
  4116. views: __assign({}, hooks0.views, hooks1.views),
  4117. viewPropsTransformers: hooks0.viewPropsTransformers.concat(hooks1.viewPropsTransformers),
  4118. isPropsValid: hooks1.isPropsValid || hooks0.isPropsValid,
  4119. externalDefTransforms: hooks0.externalDefTransforms.concat(hooks1.externalDefTransforms),
  4120. eventResizeJoinTransforms: hooks0.eventResizeJoinTransforms.concat(hooks1.eventResizeJoinTransforms),
  4121. viewContainerModifiers: hooks0.viewContainerModifiers.concat(hooks1.viewContainerModifiers),
  4122. eventDropTransformers: hooks0.eventDropTransformers.concat(hooks1.eventDropTransformers),
  4123. calendarInteractions: hooks0.calendarInteractions.concat(hooks1.calendarInteractions),
  4124. componentInteractions: hooks0.componentInteractions.concat(hooks1.componentInteractions),
  4125. themeClasses: __assign({}, hooks0.themeClasses, hooks1.themeClasses),
  4126. eventSourceDefs: hooks0.eventSourceDefs.concat(hooks1.eventSourceDefs),
  4127. cmdFormatter: hooks1.cmdFormatter || hooks0.cmdFormatter,
  4128. recurringTypes: hooks0.recurringTypes.concat(hooks1.recurringTypes),
  4129. namedTimeZonedImpl: hooks1.namedTimeZonedImpl || hooks0.namedTimeZonedImpl,
  4130. defaultView: hooks0.defaultView || hooks1.defaultView,
  4131. elementDraggingImpl: hooks0.elementDraggingImpl || hooks1.elementDraggingImpl,
  4132. optionChangeHandlers: __assign({}, hooks0.optionChangeHandlers, hooks1.optionChangeHandlers)
  4133. };
  4134. }
  4135. var eventSourceDef = {
  4136. ignoreRange: true,
  4137. parseMeta: function (raw) {
  4138. if (Array.isArray(raw)) { // short form
  4139. return raw;
  4140. }
  4141. else if (Array.isArray(raw.events)) {
  4142. return raw.events;
  4143. }
  4144. return null;
  4145. },
  4146. fetch: function (arg, success) {
  4147. success({
  4148. rawEvents: arg.eventSource.meta
  4149. });
  4150. }
  4151. };
  4152. var ArrayEventSourcePlugin = createPlugin({
  4153. eventSourceDefs: [eventSourceDef]
  4154. });
  4155. var eventSourceDef$1 = {
  4156. parseMeta: function (raw) {
  4157. if (typeof raw === 'function') { // short form
  4158. return raw;
  4159. }
  4160. else if (typeof raw.events === 'function') {
  4161. return raw.events;
  4162. }
  4163. return null;
  4164. },
  4165. fetch: function (arg, success, failure) {
  4166. var dateEnv = arg.calendar.dateEnv;
  4167. var func = arg.eventSource.meta;
  4168. unpromisify(func.bind(null, {
  4169. start: dateEnv.toDate(arg.range.start),
  4170. end: dateEnv.toDate(arg.range.end),
  4171. startStr: dateEnv.formatIso(arg.range.start),
  4172. endStr: dateEnv.formatIso(arg.range.end),
  4173. timeZone: dateEnv.timeZone
  4174. }), function (rawEvents) {
  4175. success({ rawEvents: rawEvents }); // needs an object response
  4176. }, failure // send errorObj directly to failure callback
  4177. );
  4178. }
  4179. };
  4180. var FuncEventSourcePlugin = createPlugin({
  4181. eventSourceDefs: [eventSourceDef$1]
  4182. });
  4183. function requestJson(method, url, params, successCallback, failureCallback) {
  4184. method = method.toUpperCase();
  4185. var body = null;
  4186. if (method === 'GET') {
  4187. url = injectQueryStringParams(url, params);
  4188. }
  4189. else {
  4190. body = encodeParams(params);
  4191. }
  4192. var xhr = new XMLHttpRequest();
  4193. xhr.open(method, url, true);
  4194. if (method !== 'GET') {
  4195. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  4196. }
  4197. xhr.onload = function () {
  4198. if (xhr.status >= 200 && xhr.status < 400) {
  4199. try {
  4200. var res = JSON.parse(xhr.responseText);
  4201. successCallback(res, xhr);
  4202. }
  4203. catch (err) {
  4204. failureCallback('Failure parsing JSON', xhr);
  4205. }
  4206. }
  4207. else {
  4208. failureCallback('Request failed', xhr);
  4209. }
  4210. };
  4211. xhr.onerror = function () {
  4212. failureCallback('Request failed', xhr);
  4213. };
  4214. xhr.send(body);
  4215. }
  4216. function injectQueryStringParams(url, params) {
  4217. return url +
  4218. (url.indexOf('?') === -1 ? '?' : '&') +
  4219. encodeParams(params);
  4220. }
  4221. function encodeParams(params) {
  4222. var parts = [];
  4223. for (var key in params) {
  4224. parts.push(encodeURIComponent(key) + '=' + encodeURIComponent(params[key]));
  4225. }
  4226. return parts.join('&');
  4227. }
  4228. var eventSourceDef$2 = {
  4229. parseMeta: function (raw) {
  4230. if (typeof raw === 'string') { // short form
  4231. raw = { url: raw };
  4232. }
  4233. else if (!raw || typeof raw !== 'object' || !raw.url) {
  4234. return null;
  4235. }
  4236. return {
  4237. url: raw.url,
  4238. method: (raw.method || 'GET').toUpperCase(),
  4239. extraParams: raw.extraParams,
  4240. startParam: raw.startParam,
  4241. endParam: raw.endParam,
  4242. timeZoneParam: raw.timeZoneParam
  4243. };
  4244. },
  4245. fetch: function (arg, success, failure) {
  4246. var meta = arg.eventSource.meta;
  4247. var requestParams = buildRequestParams(meta, arg.range, arg.calendar);
  4248. requestJson(meta.method, meta.url, requestParams, function (rawEvents, xhr) {
  4249. success({ rawEvents: rawEvents, xhr: xhr });
  4250. }, function (errorMessage, xhr) {
  4251. failure({ message: errorMessage, xhr: xhr });
  4252. });
  4253. }
  4254. };
  4255. var JsonFeedEventSourcePlugin = createPlugin({
  4256. eventSourceDefs: [eventSourceDef$2]
  4257. });
  4258. function buildRequestParams(meta, range, calendar) {
  4259. var dateEnv = calendar.dateEnv;
  4260. var startParam;
  4261. var endParam;
  4262. var timeZoneParam;
  4263. var customRequestParams;
  4264. var params = {};
  4265. startParam = meta.startParam;
  4266. if (startParam == null) {
  4267. startParam = calendar.opt('startParam');
  4268. }
  4269. endParam = meta.endParam;
  4270. if (endParam == null) {
  4271. endParam = calendar.opt('endParam');
  4272. }
  4273. timeZoneParam = meta.timeZoneParam;
  4274. if (timeZoneParam == null) {
  4275. timeZoneParam = calendar.opt('timeZoneParam');
  4276. }
  4277. // retrieve any outbound GET/POST data from the options
  4278. if (typeof meta.extraParams === 'function') {
  4279. // supplied as a function that returns a key/value object
  4280. customRequestParams = meta.extraParams();
  4281. }
  4282. else {
  4283. // probably supplied as a straight key/value object
  4284. customRequestParams = meta.extraParams || {};
  4285. }
  4286. __assign(params, customRequestParams);
  4287. params[startParam] = dateEnv.formatIso(range.start);
  4288. params[endParam] = dateEnv.formatIso(range.end);
  4289. if (dateEnv.timeZone !== 'local') {
  4290. params[timeZoneParam] = dateEnv.timeZone;
  4291. }
  4292. return params;
  4293. }
  4294. var recurring = {
  4295. parse: function (rawEvent, leftoverProps, dateEnv) {
  4296. var createMarker = dateEnv.createMarker.bind(dateEnv);
  4297. var processors = {
  4298. daysOfWeek: null,
  4299. startTime: createDuration,
  4300. endTime: createDuration,
  4301. startRecur: createMarker,
  4302. endRecur: createMarker
  4303. };
  4304. var props = refineProps(rawEvent, processors, {}, leftoverProps);
  4305. var anyValid = false;
  4306. for (var propName in props) {
  4307. if (props[propName] != null) {
  4308. anyValid = true;
  4309. break;
  4310. }
  4311. }
  4312. if (anyValid) {
  4313. var duration = null;
  4314. if ('duration' in leftoverProps) {
  4315. duration = createDuration(leftoverProps.duration);
  4316. delete leftoverProps.duration;
  4317. }
  4318. if (!duration && props.startTime && props.endTime) {
  4319. duration = subtractDurations(props.endTime, props.startTime);
  4320. }
  4321. return {
  4322. allDayGuess: Boolean(!props.startTime && !props.endTime),
  4323. duration: duration,
  4324. typeData: props // doesn't need endTime anymore but oh well
  4325. };
  4326. }
  4327. return null;
  4328. },
  4329. expand: function (typeData, framingRange, dateEnv) {
  4330. var clippedFramingRange = intersectRanges(framingRange, { start: typeData.startRecur, end: typeData.endRecur });
  4331. if (clippedFramingRange) {
  4332. return expandRanges(typeData.daysOfWeek, typeData.startTime, clippedFramingRange, dateEnv);
  4333. }
  4334. else {
  4335. return [];
  4336. }
  4337. }
  4338. };
  4339. var SimpleRecurrencePlugin = createPlugin({
  4340. recurringTypes: [recurring]
  4341. });
  4342. function expandRanges(daysOfWeek, startTime, framingRange, dateEnv) {
  4343. var dowHash = daysOfWeek ? arrayToHash(daysOfWeek) : null;
  4344. var dayMarker = startOfDay(framingRange.start);
  4345. var endMarker = framingRange.end;
  4346. var instanceStarts = [];
  4347. while (dayMarker < endMarker) {
  4348. var instanceStart
  4349. // if everyday, or this particular day-of-week
  4350. = void 0;
  4351. // if everyday, or this particular day-of-week
  4352. if (!dowHash || dowHash[dayMarker.getUTCDay()]) {
  4353. if (startTime) {
  4354. instanceStart = dateEnv.add(dayMarker, startTime);
  4355. }
  4356. else {
  4357. instanceStart = dayMarker;
  4358. }
  4359. instanceStarts.push(instanceStart);
  4360. }
  4361. dayMarker = addDays(dayMarker, 1);
  4362. }
  4363. return instanceStarts;
  4364. }
  4365. var DefaultOptionChangeHandlers = createPlugin({
  4366. optionChangeHandlers: {
  4367. events: function (events, calendar, deepEqual) {
  4368. handleEventSources([events], calendar, deepEqual);
  4369. },
  4370. eventSources: handleEventSources,
  4371. plugins: handlePlugins
  4372. }
  4373. });
  4374. function handleEventSources(inputs, calendar, deepEqual) {
  4375. var unfoundSources = hashValuesToArray(calendar.state.eventSources);
  4376. var newInputs = [];
  4377. for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {
  4378. var input = inputs_1[_i];
  4379. var inputFound = false;
  4380. for (var i = 0; i < unfoundSources.length; i++) {
  4381. if (deepEqual(unfoundSources[i]._raw, input)) {
  4382. unfoundSources.splice(i, 1); // delete
  4383. inputFound = true;
  4384. break;
  4385. }
  4386. }
  4387. if (!inputFound) {
  4388. newInputs.push(input);
  4389. }
  4390. }
  4391. for (var _a = 0, unfoundSources_1 = unfoundSources; _a < unfoundSources_1.length; _a++) {
  4392. var unfoundSource = unfoundSources_1[_a];
  4393. calendar.dispatch({
  4394. type: 'REMOVE_EVENT_SOURCE',
  4395. sourceId: unfoundSource.sourceId
  4396. });
  4397. }
  4398. for (var _b = 0, newInputs_1 = newInputs; _b < newInputs_1.length; _b++) {
  4399. var newInput = newInputs_1[_b];
  4400. calendar.addEventSource(newInput);
  4401. }
  4402. }
  4403. // shortcoming: won't remove plugins
  4404. function handlePlugins(inputs, calendar) {
  4405. calendar.addPluginInputs(inputs); // will gracefully handle duplicates
  4406. }
  4407. var config = {}; // TODO: make these options
  4408. var globalDefaults = {
  4409. defaultRangeSeparator: ' - ',
  4410. titleRangeSeparator: ' \u2013 ',
  4411. defaultTimedEventDuration: '01:00:00',
  4412. defaultAllDayEventDuration: { day: 1 },
  4413. forceEventDuration: false,
  4414. nextDayThreshold: '00:00:00',
  4415. // display
  4416. columnHeader: true,
  4417. defaultView: '',
  4418. aspectRatio: 1.35,
  4419. header: {
  4420. left: 'title',
  4421. center: '',
  4422. right: 'today prev,next'
  4423. },
  4424. weekends: true,
  4425. weekNumbers: false,
  4426. weekNumberCalculation: 'local',
  4427. editable: false,
  4428. // nowIndicator: false,
  4429. scrollTime: '06:00:00',
  4430. minTime: '00:00:00',
  4431. maxTime: '24:00:00',
  4432. showNonCurrentDates: true,
  4433. // event ajax
  4434. lazyFetching: true,
  4435. startParam: 'start',
  4436. endParam: 'end',
  4437. timeZoneParam: 'timeZone',
  4438. timeZone: 'local',
  4439. // allDayDefault: undefined,
  4440. // locale
  4441. locales: [],
  4442. locale: '',
  4443. // dir: will get this from the default locale
  4444. // buttonIcons: null,
  4445. // allows setting a min-height to the event segment to prevent short events overlapping each other
  4446. timeGridEventMinHeight: 0,
  4447. themeSystem: 'standard',
  4448. // eventResizableFromStart: false,
  4449. dragRevertDuration: 500,
  4450. dragScroll: true,
  4451. allDayMaintainDuration: false,
  4452. // selectable: false,
  4453. unselectAuto: true,
  4454. // selectMinDistance: 0,
  4455. dropAccept: '*',
  4456. eventOrder: 'start,-duration,allDay,title',
  4457. // ^ if start tie, longer events go before shorter. final tie-breaker is title text
  4458. // rerenderDelay: null,
  4459. eventLimit: false,
  4460. eventLimitClick: 'popover',
  4461. dayPopoverFormat: { month: 'long', day: 'numeric', year: 'numeric' },
  4462. handleWindowResize: true,
  4463. windowResizeDelay: 100,
  4464. longPressDelay: 1000,
  4465. eventDragMinDistance: 5 // only applies to mouse
  4466. };
  4467. var rtlDefaults = {
  4468. header: {
  4469. left: 'next,prev today',
  4470. center: '',
  4471. right: 'title'
  4472. },
  4473. buttonIcons: {
  4474. // TODO: make RTL support the responibility of the theme
  4475. prev: 'fc-icon-chevron-right',
  4476. next: 'fc-icon-chevron-left',
  4477. prevYear: 'fc-icon-chevrons-right',
  4478. nextYear: 'fc-icon-chevrons-left'
  4479. }
  4480. };
  4481. var complexOptions = [
  4482. 'header',
  4483. 'footer',
  4484. 'buttonText',
  4485. 'buttonIcons'
  4486. ];
  4487. // Merges an array of option objects into a single object
  4488. function mergeOptions(optionObjs) {
  4489. return mergeProps(optionObjs, complexOptions);
  4490. }
  4491. // TODO: move this stuff to a "plugin"-related file...
  4492. var INTERNAL_PLUGINS = [
  4493. ArrayEventSourcePlugin,
  4494. FuncEventSourcePlugin,
  4495. JsonFeedEventSourcePlugin,
  4496. SimpleRecurrencePlugin,
  4497. DefaultOptionChangeHandlers
  4498. ];
  4499. function refinePluginDefs(pluginInputs) {
  4500. var plugins = [];
  4501. for (var _i = 0, pluginInputs_1 = pluginInputs; _i < pluginInputs_1.length; _i++) {
  4502. var pluginInput = pluginInputs_1[_i];
  4503. if (typeof pluginInput === 'string') {
  4504. var globalName = 'FullCalendar' + capitaliseFirstLetter(pluginInput);
  4505. if (!window[globalName]) {
  4506. console.warn('Plugin file not loaded for ' + pluginInput);
  4507. }
  4508. else {
  4509. plugins.push(window[globalName].default); // is an ES6 module
  4510. }
  4511. }
  4512. else {
  4513. plugins.push(pluginInput);
  4514. }
  4515. }
  4516. return INTERNAL_PLUGINS.concat(plugins);
  4517. }
  4518. var RAW_EN_LOCALE = {
  4519. code: 'en',
  4520. week: {
  4521. dow: 0,
  4522. doy: 4 // 4 days need to be within the year to be considered the first week
  4523. },
  4524. dir: 'ltr',
  4525. buttonText: {
  4526. prev: 'prev',
  4527. next: 'next',
  4528. prevYear: 'prev year',
  4529. nextYear: 'next year',
  4530. year: 'year',
  4531. today: 'today',
  4532. month: 'month',
  4533. week: 'week',
  4534. day: 'day',
  4535. list: 'list'
  4536. },
  4537. weekLabel: 'W',
  4538. allDayText: 'all-day',
  4539. eventLimitText: 'more',
  4540. noEventsMessage: 'No events to display'
  4541. };
  4542. function parseRawLocales(explicitRawLocales) {
  4543. var defaultCode = explicitRawLocales.length > 0 ? explicitRawLocales[0].code : 'en';
  4544. var globalArray = window['FullCalendarLocalesAll'] || []; // from locales-all.js
  4545. var globalObject = window['FullCalendarLocales'] || {}; // from locales/*.js. keys are meaningless
  4546. var allRawLocales = globalArray.concat(// globalArray is low prio
  4547. hashValuesToArray(globalObject), // medium prio
  4548. explicitRawLocales // highest prio
  4549. );
  4550. var rawLocaleMap = {
  4551. en: RAW_EN_LOCALE // necessary?
  4552. };
  4553. for (var _i = 0, allRawLocales_1 = allRawLocales; _i < allRawLocales_1.length; _i++) {
  4554. var rawLocale = allRawLocales_1[_i];
  4555. rawLocaleMap[rawLocale.code] = rawLocale;
  4556. }
  4557. return {
  4558. map: rawLocaleMap,
  4559. defaultCode: defaultCode
  4560. };
  4561. }
  4562. function buildLocale(inputSingular, available) {
  4563. if (typeof inputSingular === 'object' && !Array.isArray(inputSingular)) {
  4564. return parseLocale(inputSingular.code, [inputSingular.code], inputSingular);
  4565. }
  4566. else {
  4567. return queryLocale(inputSingular, available);
  4568. }
  4569. }
  4570. function queryLocale(codeArg, available) {
  4571. var codes = [].concat(codeArg || []); // will convert to array
  4572. var raw = queryRawLocale(codes, available) || RAW_EN_LOCALE;
  4573. return parseLocale(codeArg, codes, raw);
  4574. }
  4575. function queryRawLocale(codes, available) {
  4576. for (var i = 0; i < codes.length; i++) {
  4577. var parts = codes[i].toLocaleLowerCase().split('-');
  4578. for (var j = parts.length; j > 0; j--) {
  4579. var simpleId = parts.slice(0, j).join('-');
  4580. if (available[simpleId]) {
  4581. return available[simpleId];
  4582. }
  4583. }
  4584. }
  4585. return null;
  4586. }
  4587. function parseLocale(codeArg, codes, raw) {
  4588. var merged = mergeProps([RAW_EN_LOCALE, raw], ['buttonText']);
  4589. delete merged.code; // don't want this part of the options
  4590. var week = merged.week;
  4591. delete merged.week;
  4592. return {
  4593. codeArg: codeArg,
  4594. codes: codes,
  4595. week: week,
  4596. simpleNumberFormat: new Intl.NumberFormat(codeArg),
  4597. options: merged
  4598. };
  4599. }
  4600. var OptionsManager = /** @class */ (function () {
  4601. function OptionsManager(overrides) {
  4602. this.overrides = __assign({}, overrides); // make a copy
  4603. this.dynamicOverrides = {};
  4604. this.compute();
  4605. }
  4606. OptionsManager.prototype.mutate = function (updates, removals, isDynamic) {
  4607. var overrideHash = isDynamic ? this.dynamicOverrides : this.overrides;
  4608. __assign(overrideHash, updates);
  4609. for (var _i = 0, removals_1 = removals; _i < removals_1.length; _i++) {
  4610. var propName = removals_1[_i];
  4611. delete overrideHash[propName];
  4612. }
  4613. this.compute();
  4614. };
  4615. // Computes the flattened options hash for the calendar and assigns to `this.options`.
  4616. // Assumes this.overrides and this.dynamicOverrides have already been initialized.
  4617. OptionsManager.prototype.compute = function () {
  4618. // TODO: not a very efficient system
  4619. var locales = firstDefined(// explicit locale option given?
  4620. this.dynamicOverrides.locales, this.overrides.locales, globalDefaults.locales);
  4621. var locale = firstDefined(// explicit locales option given?
  4622. this.dynamicOverrides.locale, this.overrides.locale, globalDefaults.locale);
  4623. var available = parseRawLocales(locales);
  4624. var localeDefaults = buildLocale(locale || available.defaultCode, available.map).options;
  4625. var dir = firstDefined(// based on options computed so far, is direction RTL?
  4626. this.dynamicOverrides.dir, this.overrides.dir, localeDefaults.dir);
  4627. var dirDefaults = dir === 'rtl' ? rtlDefaults : {};
  4628. this.dirDefaults = dirDefaults;
  4629. this.localeDefaults = localeDefaults;
  4630. this.computed = mergeOptions([
  4631. globalDefaults,
  4632. dirDefaults,
  4633. localeDefaults,
  4634. this.overrides,
  4635. this.dynamicOverrides
  4636. ]);
  4637. };
  4638. return OptionsManager;
  4639. }());
  4640. var calendarSystemClassMap = {};
  4641. function registerCalendarSystem(name, theClass) {
  4642. calendarSystemClassMap[name] = theClass;
  4643. }
  4644. function createCalendarSystem(name) {
  4645. return new calendarSystemClassMap[name]();
  4646. }
  4647. var GregorianCalendarSystem = /** @class */ (function () {
  4648. function GregorianCalendarSystem() {
  4649. }
  4650. GregorianCalendarSystem.prototype.getMarkerYear = function (d) {
  4651. return d.getUTCFullYear();
  4652. };
  4653. GregorianCalendarSystem.prototype.getMarkerMonth = function (d) {
  4654. return d.getUTCMonth();
  4655. };
  4656. GregorianCalendarSystem.prototype.getMarkerDay = function (d) {
  4657. return d.getUTCDate();
  4658. };
  4659. GregorianCalendarSystem.prototype.arrayToMarker = function (arr) {
  4660. return arrayToUtcDate(arr);
  4661. };
  4662. GregorianCalendarSystem.prototype.markerToArray = function (marker) {
  4663. return dateToUtcArray(marker);
  4664. };
  4665. return GregorianCalendarSystem;
  4666. }());
  4667. registerCalendarSystem('gregory', GregorianCalendarSystem);
  4668. var ISO_RE = /^\s*(\d{4})(-(\d{2})(-(\d{2})([T ](\d{2}):(\d{2})(:(\d{2})(\.(\d+))?)?(Z|(([-+])(\d{2})(:?(\d{2}))?))?)?)?)?$/;
  4669. function parse(str) {
  4670. var m = ISO_RE.exec(str);
  4671. if (m) {
  4672. 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));
  4673. if (isValidDate(marker)) {
  4674. var timeZoneOffset = null;
  4675. if (m[13]) {
  4676. timeZoneOffset = (m[15] === '-' ? -1 : 1) * (Number(m[16] || 0) * 60 +
  4677. Number(m[18] || 0));
  4678. }
  4679. return {
  4680. marker: marker,
  4681. isTimeUnspecified: !m[6],
  4682. timeZoneOffset: timeZoneOffset
  4683. };
  4684. }
  4685. }
  4686. return null;
  4687. }
  4688. var DateEnv = /** @class */ (function () {
  4689. function DateEnv(settings) {
  4690. var timeZone = this.timeZone = settings.timeZone;
  4691. var isNamedTimeZone = timeZone !== 'local' && timeZone !== 'UTC';
  4692. if (settings.namedTimeZoneImpl && isNamedTimeZone) {
  4693. this.namedTimeZoneImpl = new settings.namedTimeZoneImpl(timeZone);
  4694. }
  4695. this.canComputeOffset = Boolean(!isNamedTimeZone || this.namedTimeZoneImpl);
  4696. this.calendarSystem = createCalendarSystem(settings.calendarSystem);
  4697. this.locale = settings.locale;
  4698. this.weekDow = settings.locale.week.dow;
  4699. this.weekDoy = settings.locale.week.doy;
  4700. if (settings.weekNumberCalculation === 'ISO') {
  4701. this.weekDow = 1;
  4702. this.weekDoy = 4;
  4703. }
  4704. if (typeof settings.firstDay === 'number') {
  4705. this.weekDow = settings.firstDay;
  4706. }
  4707. if (typeof settings.weekNumberCalculation === 'function') {
  4708. this.weekNumberFunc = settings.weekNumberCalculation;
  4709. }
  4710. this.weekLabel = settings.weekLabel != null ? settings.weekLabel : settings.locale.options.weekLabel;
  4711. this.cmdFormatter = settings.cmdFormatter;
  4712. }
  4713. // Creating / Parsing
  4714. DateEnv.prototype.createMarker = function (input) {
  4715. var meta = this.createMarkerMeta(input);
  4716. if (meta === null) {
  4717. return null;
  4718. }
  4719. return meta.marker;
  4720. };
  4721. DateEnv.prototype.createNowMarker = function () {
  4722. if (this.canComputeOffset) {
  4723. return this.timestampToMarker(new Date().valueOf());
  4724. }
  4725. else {
  4726. // if we can't compute the current date val for a timezone,
  4727. // better to give the current local date vals than UTC
  4728. return arrayToUtcDate(dateToLocalArray(new Date()));
  4729. }
  4730. };
  4731. DateEnv.prototype.createMarkerMeta = function (input) {
  4732. if (typeof input === 'string') {
  4733. return this.parse(input);
  4734. }
  4735. var marker = null;
  4736. if (typeof input === 'number') {
  4737. marker = this.timestampToMarker(input);
  4738. }
  4739. else if (input instanceof Date) {
  4740. input = input.valueOf();
  4741. if (!isNaN(input)) {
  4742. marker = this.timestampToMarker(input);
  4743. }
  4744. }
  4745. else if (Array.isArray(input)) {
  4746. marker = arrayToUtcDate(input);
  4747. }
  4748. if (marker === null || !isValidDate(marker)) {
  4749. return null;
  4750. }
  4751. return { marker: marker, isTimeUnspecified: false, forcedTzo: null };
  4752. };
  4753. DateEnv.prototype.parse = function (s) {
  4754. var parts = parse(s);
  4755. if (parts === null) {
  4756. return null;
  4757. }
  4758. var marker = parts.marker;
  4759. var forcedTzo = null;
  4760. if (parts.timeZoneOffset !== null) {
  4761. if (this.canComputeOffset) {
  4762. marker = this.timestampToMarker(marker.valueOf() - parts.timeZoneOffset * 60 * 1000);
  4763. }
  4764. else {
  4765. forcedTzo = parts.timeZoneOffset;
  4766. }
  4767. }
  4768. return { marker: marker, isTimeUnspecified: parts.isTimeUnspecified, forcedTzo: forcedTzo };
  4769. };
  4770. // Accessors
  4771. DateEnv.prototype.getYear = function (marker) {
  4772. return this.calendarSystem.getMarkerYear(marker);
  4773. };
  4774. DateEnv.prototype.getMonth = function (marker) {
  4775. return this.calendarSystem.getMarkerMonth(marker);
  4776. };
  4777. // Adding / Subtracting
  4778. DateEnv.prototype.add = function (marker, dur) {
  4779. var a = this.calendarSystem.markerToArray(marker);
  4780. a[0] += dur.years;
  4781. a[1] += dur.months;
  4782. a[2] += dur.days;
  4783. a[6] += dur.milliseconds;
  4784. return this.calendarSystem.arrayToMarker(a);
  4785. };
  4786. DateEnv.prototype.subtract = function (marker, dur) {
  4787. var a = this.calendarSystem.markerToArray(marker);
  4788. a[0] -= dur.years;
  4789. a[1] -= dur.months;
  4790. a[2] -= dur.days;
  4791. a[6] -= dur.milliseconds;
  4792. return this.calendarSystem.arrayToMarker(a);
  4793. };
  4794. DateEnv.prototype.addYears = function (marker, n) {
  4795. var a = this.calendarSystem.markerToArray(marker);
  4796. a[0] += n;
  4797. return this.calendarSystem.arrayToMarker(a);
  4798. };
  4799. DateEnv.prototype.addMonths = function (marker, n) {
  4800. var a = this.calendarSystem.markerToArray(marker);
  4801. a[1] += n;
  4802. return this.calendarSystem.arrayToMarker(a);
  4803. };
  4804. // Diffing Whole Units
  4805. DateEnv.prototype.diffWholeYears = function (m0, m1) {
  4806. var calendarSystem = this.calendarSystem;
  4807. if (timeAsMs(m0) === timeAsMs(m1) &&
  4808. calendarSystem.getMarkerDay(m0) === calendarSystem.getMarkerDay(m1) &&
  4809. calendarSystem.getMarkerMonth(m0) === calendarSystem.getMarkerMonth(m1)) {
  4810. return calendarSystem.getMarkerYear(m1) - calendarSystem.getMarkerYear(m0);
  4811. }
  4812. return null;
  4813. };
  4814. DateEnv.prototype.diffWholeMonths = function (m0, m1) {
  4815. var calendarSystem = this.calendarSystem;
  4816. if (timeAsMs(m0) === timeAsMs(m1) &&
  4817. calendarSystem.getMarkerDay(m0) === calendarSystem.getMarkerDay(m1)) {
  4818. return (calendarSystem.getMarkerMonth(m1) - calendarSystem.getMarkerMonth(m0)) +
  4819. (calendarSystem.getMarkerYear(m1) - calendarSystem.getMarkerYear(m0)) * 12;
  4820. }
  4821. return null;
  4822. };
  4823. // Range / Duration
  4824. DateEnv.prototype.greatestWholeUnit = function (m0, m1) {
  4825. var n = this.diffWholeYears(m0, m1);
  4826. if (n !== null) {
  4827. return { unit: 'year', value: n };
  4828. }
  4829. n = this.diffWholeMonths(m0, m1);
  4830. if (n !== null) {
  4831. return { unit: 'month', value: n };
  4832. }
  4833. n = diffWholeWeeks(m0, m1);
  4834. if (n !== null) {
  4835. return { unit: 'week', value: n };
  4836. }
  4837. n = diffWholeDays(m0, m1);
  4838. if (n !== null) {
  4839. return { unit: 'day', value: n };
  4840. }
  4841. n = diffHours(m0, m1);
  4842. if (isInt(n)) {
  4843. return { unit: 'hour', value: n };
  4844. }
  4845. n = diffMinutes(m0, m1);
  4846. if (isInt(n)) {
  4847. return { unit: 'minute', value: n };
  4848. }
  4849. n = diffSeconds(m0, m1);
  4850. if (isInt(n)) {
  4851. return { unit: 'second', value: n };
  4852. }
  4853. return { unit: 'millisecond', value: m1.valueOf() - m0.valueOf() };
  4854. };
  4855. DateEnv.prototype.countDurationsBetween = function (m0, m1, d) {
  4856. // TODO: can use greatestWholeUnit
  4857. var diff;
  4858. if (d.years) {
  4859. diff = this.diffWholeYears(m0, m1);
  4860. if (diff !== null) {
  4861. return diff / asRoughYears(d);
  4862. }
  4863. }
  4864. if (d.months) {
  4865. diff = this.diffWholeMonths(m0, m1);
  4866. if (diff !== null) {
  4867. return diff / asRoughMonths(d);
  4868. }
  4869. }
  4870. if (d.days) {
  4871. diff = diffWholeDays(m0, m1);
  4872. if (diff !== null) {
  4873. return diff / asRoughDays(d);
  4874. }
  4875. }
  4876. return (m1.valueOf() - m0.valueOf()) / asRoughMs(d);
  4877. };
  4878. // Start-Of
  4879. DateEnv.prototype.startOf = function (m, unit) {
  4880. if (unit === 'year') {
  4881. return this.startOfYear(m);
  4882. }
  4883. else if (unit === 'month') {
  4884. return this.startOfMonth(m);
  4885. }
  4886. else if (unit === 'week') {
  4887. return this.startOfWeek(m);
  4888. }
  4889. else if (unit === 'day') {
  4890. return startOfDay(m);
  4891. }
  4892. else if (unit === 'hour') {
  4893. return startOfHour(m);
  4894. }
  4895. else if (unit === 'minute') {
  4896. return startOfMinute(m);
  4897. }
  4898. else if (unit === 'second') {
  4899. return startOfSecond(m);
  4900. }
  4901. };
  4902. DateEnv.prototype.startOfYear = function (m) {
  4903. return this.calendarSystem.arrayToMarker([
  4904. this.calendarSystem.getMarkerYear(m)
  4905. ]);
  4906. };
  4907. DateEnv.prototype.startOfMonth = function (m) {
  4908. return this.calendarSystem.arrayToMarker([
  4909. this.calendarSystem.getMarkerYear(m),
  4910. this.calendarSystem.getMarkerMonth(m)
  4911. ]);
  4912. };
  4913. DateEnv.prototype.startOfWeek = function (m) {
  4914. return this.calendarSystem.arrayToMarker([
  4915. this.calendarSystem.getMarkerYear(m),
  4916. this.calendarSystem.getMarkerMonth(m),
  4917. m.getUTCDate() - ((m.getUTCDay() - this.weekDow + 7) % 7)
  4918. ]);
  4919. };
  4920. // Week Number
  4921. DateEnv.prototype.computeWeekNumber = function (marker) {
  4922. if (this.weekNumberFunc) {
  4923. return this.weekNumberFunc(this.toDate(marker));
  4924. }
  4925. else {
  4926. return weekOfYear(marker, this.weekDow, this.weekDoy);
  4927. }
  4928. };
  4929. // TODO: choke on timeZoneName: long
  4930. DateEnv.prototype.format = function (marker, formatter, dateOptions) {
  4931. if (dateOptions === void 0) { dateOptions = {}; }
  4932. return formatter.format({
  4933. marker: marker,
  4934. timeZoneOffset: dateOptions.forcedTzo != null ?
  4935. dateOptions.forcedTzo :
  4936. this.offsetForMarker(marker)
  4937. }, this);
  4938. };
  4939. DateEnv.prototype.formatRange = function (start, end, formatter, dateOptions) {
  4940. if (dateOptions === void 0) { dateOptions = {}; }
  4941. if (dateOptions.isEndExclusive) {
  4942. end = addMs(end, -1);
  4943. }
  4944. return formatter.formatRange({
  4945. marker: start,
  4946. timeZoneOffset: dateOptions.forcedStartTzo != null ?
  4947. dateOptions.forcedStartTzo :
  4948. this.offsetForMarker(start)
  4949. }, {
  4950. marker: end,
  4951. timeZoneOffset: dateOptions.forcedEndTzo != null ?
  4952. dateOptions.forcedEndTzo :
  4953. this.offsetForMarker(end)
  4954. }, this);
  4955. };
  4956. DateEnv.prototype.formatIso = function (marker, extraOptions) {
  4957. if (extraOptions === void 0) { extraOptions = {}; }
  4958. var timeZoneOffset = null;
  4959. if (!extraOptions.omitTimeZoneOffset) {
  4960. if (extraOptions.forcedTzo != null) {
  4961. timeZoneOffset = extraOptions.forcedTzo;
  4962. }
  4963. else {
  4964. timeZoneOffset = this.offsetForMarker(marker);
  4965. }
  4966. }
  4967. return buildIsoString(marker, timeZoneOffset, extraOptions.omitTime);
  4968. };
  4969. // TimeZone
  4970. DateEnv.prototype.timestampToMarker = function (ms) {
  4971. if (this.timeZone === 'local') {
  4972. return arrayToUtcDate(dateToLocalArray(new Date(ms)));
  4973. }
  4974. else if (this.timeZone === 'UTC' || !this.namedTimeZoneImpl) {
  4975. return new Date(ms);
  4976. }
  4977. else {
  4978. return arrayToUtcDate(this.namedTimeZoneImpl.timestampToArray(ms));
  4979. }
  4980. };
  4981. DateEnv.prototype.offsetForMarker = function (m) {
  4982. if (this.timeZone === 'local') {
  4983. return -arrayToLocalDate(dateToUtcArray(m)).getTimezoneOffset(); // convert "inverse" offset to "normal" offset
  4984. }
  4985. else if (this.timeZone === 'UTC') {
  4986. return 0;
  4987. }
  4988. else if (this.namedTimeZoneImpl) {
  4989. return this.namedTimeZoneImpl.offsetForArray(dateToUtcArray(m));
  4990. }
  4991. return null;
  4992. };
  4993. // Conversion
  4994. DateEnv.prototype.toDate = function (m, forcedTzo) {
  4995. if (this.timeZone === 'local') {
  4996. return arrayToLocalDate(dateToUtcArray(m));
  4997. }
  4998. else if (this.timeZone === 'UTC') {
  4999. return new Date(m.valueOf()); // make sure it's a copy
  5000. }
  5001. else if (!this.namedTimeZoneImpl) {
  5002. return new Date(m.valueOf() - (forcedTzo || 0));
  5003. }
  5004. else {
  5005. return new Date(m.valueOf() -
  5006. this.namedTimeZoneImpl.offsetForArray(dateToUtcArray(m)) * 1000 * 60 // convert minutes -> ms
  5007. );
  5008. }
  5009. };
  5010. return DateEnv;
  5011. }());
  5012. var SIMPLE_SOURCE_PROPS = {
  5013. id: String,
  5014. allDayDefault: Boolean,
  5015. eventDataTransform: Function,
  5016. success: Function,
  5017. failure: Function
  5018. };
  5019. var uid$2 = 0;
  5020. function doesSourceNeedRange(eventSource, calendar) {
  5021. var defs = calendar.pluginSystem.hooks.eventSourceDefs;
  5022. return !defs[eventSource.sourceDefId].ignoreRange;
  5023. }
  5024. function parseEventSource(raw, calendar) {
  5025. var defs = calendar.pluginSystem.hooks.eventSourceDefs;
  5026. for (var i = defs.length - 1; i >= 0; i--) { // later-added plugins take precedence
  5027. var def = defs[i];
  5028. var meta = def.parseMeta(raw);
  5029. if (meta) {
  5030. var res = parseEventSourceProps(typeof raw === 'object' ? raw : {}, meta, i, calendar);
  5031. res._raw = raw;
  5032. return res;
  5033. }
  5034. }
  5035. return null;
  5036. }
  5037. function parseEventSourceProps(raw, meta, sourceDefId, calendar) {
  5038. var leftovers0 = {};
  5039. var props = refineProps(raw, SIMPLE_SOURCE_PROPS, {}, leftovers0);
  5040. var leftovers1 = {};
  5041. var ui = processUnscopedUiProps(leftovers0, calendar, leftovers1);
  5042. props.isFetching = false;
  5043. props.latestFetchId = '';
  5044. props.fetchRange = null;
  5045. props.publicId = String(raw.id || '');
  5046. props.sourceId = String(uid$2++);
  5047. props.sourceDefId = sourceDefId;
  5048. props.meta = meta;
  5049. props.ui = ui;
  5050. props.extendedProps = leftovers1;
  5051. return props;
  5052. }
  5053. function reduceEventSources (eventSources, action, dateProfile, calendar) {
  5054. switch (action.type) {
  5055. case 'ADD_EVENT_SOURCES': // already parsed
  5056. return addSources(eventSources, action.sources, dateProfile ? dateProfile.activeRange : null, calendar);
  5057. case 'REMOVE_EVENT_SOURCE':
  5058. return removeSource(eventSources, action.sourceId);
  5059. case 'PREV': // TODO: how do we track all actions that affect dateProfile :(
  5060. case 'NEXT':
  5061. case 'SET_DATE':
  5062. case 'SET_VIEW_TYPE':
  5063. if (dateProfile) {
  5064. return fetchDirtySources(eventSources, dateProfile.activeRange, calendar);
  5065. }
  5066. else {
  5067. return eventSources;
  5068. }
  5069. case 'FETCH_EVENT_SOURCES':
  5070. case 'CHANGE_TIMEZONE':
  5071. return fetchSourcesByIds(eventSources, action.sourceIds ?
  5072. arrayToHash(action.sourceIds) :
  5073. excludeStaticSources(eventSources, calendar), dateProfile ? dateProfile.activeRange : null, calendar);
  5074. case 'RECEIVE_EVENTS':
  5075. case 'RECEIVE_EVENT_ERROR':
  5076. return receiveResponse(eventSources, action.sourceId, action.fetchId, action.fetchRange);
  5077. case 'REMOVE_ALL_EVENT_SOURCES':
  5078. return {};
  5079. default:
  5080. return eventSources;
  5081. }
  5082. }
  5083. var uid$3 = 0;
  5084. function addSources(eventSourceHash, sources, fetchRange, calendar) {
  5085. var hash = {};
  5086. for (var _i = 0, sources_1 = sources; _i < sources_1.length; _i++) {
  5087. var source = sources_1[_i];
  5088. hash[source.sourceId] = source;
  5089. }
  5090. if (fetchRange) {
  5091. hash = fetchDirtySources(hash, fetchRange, calendar);
  5092. }
  5093. return __assign({}, eventSourceHash, hash);
  5094. }
  5095. function removeSource(eventSourceHash, sourceId) {
  5096. return filterHash(eventSourceHash, function (eventSource) {
  5097. return eventSource.sourceId !== sourceId;
  5098. });
  5099. }
  5100. function fetchDirtySources(sourceHash, fetchRange, calendar) {
  5101. return fetchSourcesByIds(sourceHash, filterHash(sourceHash, function (eventSource) {
  5102. return isSourceDirty(eventSource, fetchRange, calendar);
  5103. }), fetchRange, calendar);
  5104. }
  5105. function isSourceDirty(eventSource, fetchRange, calendar) {
  5106. if (!doesSourceNeedRange(eventSource, calendar)) {
  5107. return !eventSource.latestFetchId;
  5108. }
  5109. else {
  5110. return !calendar.opt('lazyFetching') ||
  5111. !eventSource.fetchRange ||
  5112. fetchRange.start < eventSource.fetchRange.start ||
  5113. fetchRange.end > eventSource.fetchRange.end;
  5114. }
  5115. }
  5116. function fetchSourcesByIds(prevSources, sourceIdHash, fetchRange, calendar) {
  5117. var nextSources = {};
  5118. for (var sourceId in prevSources) {
  5119. var source = prevSources[sourceId];
  5120. if (sourceIdHash[sourceId]) {
  5121. nextSources[sourceId] = fetchSource(source, fetchRange, calendar);
  5122. }
  5123. else {
  5124. nextSources[sourceId] = source;
  5125. }
  5126. }
  5127. return nextSources;
  5128. }
  5129. function fetchSource(eventSource, fetchRange, calendar) {
  5130. var sourceDef = calendar.pluginSystem.hooks.eventSourceDefs[eventSource.sourceDefId];
  5131. var fetchId = String(uid$3++);
  5132. sourceDef.fetch({
  5133. eventSource: eventSource,
  5134. calendar: calendar,
  5135. range: fetchRange
  5136. }, function (res) {
  5137. var rawEvents = res.rawEvents;
  5138. var calSuccess = calendar.opt('eventSourceSuccess');
  5139. var calSuccessRes;
  5140. var sourceSuccessRes;
  5141. if (eventSource.success) {
  5142. sourceSuccessRes = eventSource.success(rawEvents, res.xhr);
  5143. }
  5144. if (calSuccess) {
  5145. calSuccessRes = calSuccess(rawEvents, res.xhr);
  5146. }
  5147. rawEvents = sourceSuccessRes || calSuccessRes || rawEvents;
  5148. calendar.dispatch({
  5149. type: 'RECEIVE_EVENTS',
  5150. sourceId: eventSource.sourceId,
  5151. fetchId: fetchId,
  5152. fetchRange: fetchRange,
  5153. rawEvents: rawEvents
  5154. });
  5155. }, function (error) {
  5156. var callFailure = calendar.opt('eventSourceFailure');
  5157. console.warn(error.message, error);
  5158. if (eventSource.failure) {
  5159. eventSource.failure(error);
  5160. }
  5161. if (callFailure) {
  5162. callFailure(error);
  5163. }
  5164. calendar.dispatch({
  5165. type: 'RECEIVE_EVENT_ERROR',
  5166. sourceId: eventSource.sourceId,
  5167. fetchId: fetchId,
  5168. fetchRange: fetchRange,
  5169. error: error
  5170. });
  5171. });
  5172. return __assign({}, eventSource, { isFetching: true, latestFetchId: fetchId });
  5173. }
  5174. function receiveResponse(sourceHash, sourceId, fetchId, fetchRange) {
  5175. var _a;
  5176. var eventSource = sourceHash[sourceId];
  5177. if (eventSource && // not already removed
  5178. fetchId === eventSource.latestFetchId) {
  5179. return __assign({}, sourceHash, (_a = {}, _a[sourceId] = __assign({}, eventSource, { isFetching: false, fetchRange: fetchRange }), _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(context, extraClassName) {
  5911. var _this = _super.call(this, context) || 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, 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 className = this.theme.getClass('buttonActive');
  6055. findElements(this.el, 'button').forEach(function (buttonEl) {
  6056. if (buttonName && buttonEl.classList.contains('fc-' + buttonName + '-button')) {
  6057. buttonEl.classList.add(className);
  6058. }
  6059. else {
  6060. buttonEl.classList.remove(className);
  6061. }
  6062. });
  6063. };
  6064. Toolbar.prototype.toggleButtonEnabled = function (buttonName, bool) {
  6065. findElements(this.el, '.fc-' + buttonName + '-button').forEach(function (buttonEl) {
  6066. buttonEl.disabled = !bool;
  6067. });
  6068. };
  6069. return Toolbar;
  6070. }(Component));
  6071. var CalendarComponent = /** @class */ (function (_super) {
  6072. __extends(CalendarComponent, _super);
  6073. function CalendarComponent(context, el) {
  6074. var _this = _super.call(this, context) || this;
  6075. _this._renderToolbars = memoizeRendering(_this.renderToolbars);
  6076. _this.buildViewPropTransformers = memoize(buildViewPropTransformers);
  6077. _this.el = el;
  6078. prependToElement(el, _this.contentEl = createElement('div', { className: 'fc-view-container' }));
  6079. var calendar = _this.calendar;
  6080. for (var _i = 0, _a = calendar.pluginSystem.hooks.viewContainerModifiers; _i < _a.length; _i++) {
  6081. var modifyViewContainer = _a[_i];
  6082. modifyViewContainer(_this.contentEl, calendar);
  6083. }
  6084. _this.toggleElClassNames(true);
  6085. _this.computeTitle = memoize(computeTitle);
  6086. _this.parseBusinessHours = memoize(function (input) {
  6087. return parseBusinessHours(input, _this.calendar);
  6088. });
  6089. return _this;
  6090. }
  6091. CalendarComponent.prototype.destroy = function () {
  6092. if (this.header) {
  6093. this.header.destroy();
  6094. }
  6095. if (this.footer) {
  6096. this.footer.destroy();
  6097. }
  6098. if (this.view) {
  6099. this.view.destroy();
  6100. }
  6101. removeElement(this.contentEl);
  6102. this.toggleElClassNames(false);
  6103. _super.prototype.destroy.call(this);
  6104. };
  6105. CalendarComponent.prototype.toggleElClassNames = function (bool) {
  6106. var classList = this.el.classList;
  6107. var dirClassName = 'fc-' + this.opt('dir');
  6108. var themeClassName = this.theme.getClass('widget');
  6109. if (bool) {
  6110. classList.add('fc');
  6111. classList.add(dirClassName);
  6112. classList.add(themeClassName);
  6113. }
  6114. else {
  6115. classList.remove('fc');
  6116. classList.remove(dirClassName);
  6117. classList.remove(themeClassName);
  6118. }
  6119. };
  6120. CalendarComponent.prototype.render = function (props) {
  6121. this.freezeHeight();
  6122. var title = this.computeTitle(props.dateProfile, props.viewSpec.options);
  6123. this._renderToolbars(props.viewSpec, props.dateProfile, props.currentDate, props.dateProfileGenerator, title);
  6124. this.renderView(props, title);
  6125. this.updateSize();
  6126. this.thawHeight();
  6127. };
  6128. CalendarComponent.prototype.renderToolbars = function (viewSpec, dateProfile, currentDate, dateProfileGenerator, title) {
  6129. var headerLayout = this.opt('header');
  6130. var footerLayout = this.opt('footer');
  6131. var now = this.calendar.getNow();
  6132. var todayInfo = dateProfileGenerator.build(now);
  6133. var prevInfo = dateProfileGenerator.buildPrev(dateProfile, currentDate);
  6134. var nextInfo = dateProfileGenerator.buildNext(dateProfile, currentDate);
  6135. var toolbarProps = {
  6136. title: title,
  6137. activeButton: viewSpec.type,
  6138. isTodayEnabled: todayInfo.isValid && !rangeContainsMarker(dateProfile.currentRange, now),
  6139. isPrevEnabled: prevInfo.isValid,
  6140. isNextEnabled: nextInfo.isValid
  6141. };
  6142. if (headerLayout) {
  6143. if (!this.header) {
  6144. this.header = new Toolbar(this.context, 'fc-header-toolbar');
  6145. prependToElement(this.el, this.header.el);
  6146. }
  6147. this.header.receiveProps(__assign({ layout: headerLayout }, toolbarProps));
  6148. }
  6149. else if (this.header) {
  6150. this.header.destroy();
  6151. this.header = null;
  6152. }
  6153. if (footerLayout) {
  6154. if (!this.footer) {
  6155. this.footer = new Toolbar(this.context, 'fc-footer-toolbar');
  6156. appendToElement(this.el, this.footer.el);
  6157. }
  6158. this.footer.receiveProps(__assign({ layout: footerLayout }, toolbarProps));
  6159. }
  6160. else if (this.footer) {
  6161. this.footer.destroy();
  6162. this.footer = null;
  6163. }
  6164. };
  6165. CalendarComponent.prototype.renderView = function (props, title) {
  6166. var view = this.view;
  6167. var viewSpec = props.viewSpec, dateProfileGenerator = props.dateProfileGenerator;
  6168. if (!view || view.viewSpec !== viewSpec) {
  6169. if (view) {
  6170. view.destroy();
  6171. }
  6172. view = this.view = new viewSpec['class']({
  6173. calendar: this.calendar,
  6174. view: null,
  6175. dateEnv: this.dateEnv,
  6176. theme: this.theme,
  6177. options: viewSpec.options
  6178. }, viewSpec, dateProfileGenerator, this.contentEl);
  6179. }
  6180. else {
  6181. view.addScroll(view.queryScroll());
  6182. }
  6183. view.title = title; // for the API
  6184. var viewProps = {
  6185. dateProfile: props.dateProfile,
  6186. businessHours: this.parseBusinessHours(viewSpec.options.businessHours),
  6187. eventStore: props.eventStore,
  6188. eventUiBases: props.eventUiBases,
  6189. dateSelection: props.dateSelection,
  6190. eventSelection: props.eventSelection,
  6191. eventDrag: props.eventDrag,
  6192. eventResize: props.eventResize
  6193. };
  6194. var transformers = this.buildViewPropTransformers(this.calendar.pluginSystem.hooks.viewPropsTransformers);
  6195. for (var _i = 0, transformers_1 = transformers; _i < transformers_1.length; _i++) {
  6196. var transformer = transformers_1[_i];
  6197. __assign(viewProps, transformer.transform(viewProps, viewSpec, props, view));
  6198. }
  6199. view.receiveProps(viewProps);
  6200. };
  6201. // Sizing
  6202. // -----------------------------------------------------------------------------------------------------------------
  6203. CalendarComponent.prototype.updateSize = function (isResize) {
  6204. if (isResize === void 0) { isResize = false; }
  6205. var view = this.view;
  6206. if (isResize) {
  6207. view.addScroll(view.queryScroll());
  6208. }
  6209. if (isResize || this.isHeightAuto == null) {
  6210. this.computeHeightVars();
  6211. }
  6212. view.updateSize(isResize, this.viewHeight, this.isHeightAuto);
  6213. view.updateNowIndicator(); // we need to guarantee this will run after updateSize
  6214. view.popScroll(isResize);
  6215. };
  6216. CalendarComponent.prototype.computeHeightVars = function () {
  6217. var calendar = this.calendar; // yuck. need to handle dynamic options
  6218. var heightInput = calendar.opt('height');
  6219. var contentHeightInput = calendar.opt('contentHeight');
  6220. this.isHeightAuto = heightInput === 'auto' || contentHeightInput === 'auto';
  6221. if (typeof contentHeightInput === 'number') { // exists and not 'auto'
  6222. this.viewHeight = contentHeightInput;
  6223. }
  6224. else if (typeof contentHeightInput === 'function') { // exists and is a function
  6225. this.viewHeight = contentHeightInput();
  6226. }
  6227. else if (typeof heightInput === 'number') { // exists and not 'auto'
  6228. this.viewHeight = heightInput - this.queryToolbarsHeight();
  6229. }
  6230. else if (typeof heightInput === 'function') { // exists and is a function
  6231. this.viewHeight = heightInput() - this.queryToolbarsHeight();
  6232. }
  6233. else if (heightInput === 'parent') { // set to height of parent element
  6234. var parentEl = this.el.parentNode;
  6235. this.viewHeight = parentEl.getBoundingClientRect().height - this.queryToolbarsHeight();
  6236. }
  6237. else {
  6238. this.viewHeight = Math.round(this.contentEl.getBoundingClientRect().width /
  6239. Math.max(calendar.opt('aspectRatio'), .5));
  6240. }
  6241. };
  6242. CalendarComponent.prototype.queryToolbarsHeight = function () {
  6243. var height = 0;
  6244. if (this.header) {
  6245. height += computeHeightAndMargins(this.header.el);
  6246. }
  6247. if (this.footer) {
  6248. height += computeHeightAndMargins(this.footer.el);
  6249. }
  6250. return height;
  6251. };
  6252. // Height "Freezing"
  6253. // -----------------------------------------------------------------------------------------------------------------
  6254. CalendarComponent.prototype.freezeHeight = function () {
  6255. applyStyle(this.el, {
  6256. height: this.el.getBoundingClientRect().height,
  6257. overflow: 'hidden'
  6258. });
  6259. };
  6260. CalendarComponent.prototype.thawHeight = function () {
  6261. applyStyle(this.el, {
  6262. height: '',
  6263. overflow: ''
  6264. });
  6265. };
  6266. return CalendarComponent;
  6267. }(Component));
  6268. // Title and Date Formatting
  6269. // -----------------------------------------------------------------------------------------------------------------
  6270. // Computes what the title at the top of the calendar should be for this view
  6271. function computeTitle(dateProfile, viewOptions) {
  6272. var range;
  6273. // for views that span a large unit of time, show the proper interval, ignoring stray days before and after
  6274. if (/^(year|month)$/.test(dateProfile.currentRangeUnit)) {
  6275. range = dateProfile.currentRange;
  6276. }
  6277. else { // for day units or smaller, use the actual day range
  6278. range = dateProfile.activeRange;
  6279. }
  6280. return this.dateEnv.formatRange(range.start, range.end, createFormatter(viewOptions.titleFormat || computeTitleFormat(dateProfile), viewOptions.titleRangeSeparator), { isEndExclusive: dateProfile.isRangeAllDay });
  6281. }
  6282. // Generates the format string that should be used to generate the title for the current date range.
  6283. // Attempts to compute the most appropriate format if not explicitly specified with `titleFormat`.
  6284. function computeTitleFormat(dateProfile) {
  6285. var currentRangeUnit = dateProfile.currentRangeUnit;
  6286. if (currentRangeUnit === 'year') {
  6287. return { year: 'numeric' };
  6288. }
  6289. else if (currentRangeUnit === 'month') {
  6290. return { year: 'numeric', month: 'long' }; // like "September 2014"
  6291. }
  6292. else {
  6293. var days = diffWholeDays(dateProfile.currentRange.start, dateProfile.currentRange.end);
  6294. if (days !== null && days > 1) {
  6295. // multi-day range. shorter, like "Sep 9 - 10 2014"
  6296. return { year: 'numeric', month: 'short', day: 'numeric' };
  6297. }
  6298. else {
  6299. // one day. longer, like "September 9 2014"
  6300. return { year: 'numeric', month: 'long', day: 'numeric' };
  6301. }
  6302. }
  6303. }
  6304. // Plugin
  6305. // -----------------------------------------------------------------------------------------------------------------
  6306. function buildViewPropTransformers(theClasses) {
  6307. return theClasses.map(function (theClass) {
  6308. return new theClass();
  6309. });
  6310. }
  6311. var Interaction = /** @class */ (function () {
  6312. function Interaction(settings) {
  6313. this.component = settings.component;
  6314. }
  6315. Interaction.prototype.destroy = function () {
  6316. };
  6317. return Interaction;
  6318. }());
  6319. function parseInteractionSettings(component, input) {
  6320. return {
  6321. component: component,
  6322. el: input.el,
  6323. useEventCenter: input.useEventCenter != null ? input.useEventCenter : true
  6324. };
  6325. }
  6326. function interactionSettingsToStore(settings) {
  6327. var _a;
  6328. return _a = {},
  6329. _a[settings.component.uid] = settings,
  6330. _a;
  6331. }
  6332. // global state
  6333. var interactionSettingsStore = {};
  6334. /*
  6335. Detects when the user clicks on an event within a DateComponent
  6336. */
  6337. var EventClicking = /** @class */ (function (_super) {
  6338. __extends(EventClicking, _super);
  6339. function EventClicking(settings) {
  6340. var _this = _super.call(this, settings) || this;
  6341. _this.handleSegClick = function (ev, segEl) {
  6342. var component = _this.component;
  6343. var seg = getElSeg(segEl);
  6344. if (seg && // might be the <div> surrounding the more link
  6345. component.isValidSegDownEl(ev.target)) {
  6346. // our way to simulate a link click for elements that can't be <a> tags
  6347. // grab before trigger fired in case trigger trashes DOM thru rerendering
  6348. var hasUrlContainer = elementClosest(ev.target, '.fc-has-url');
  6349. var url = hasUrlContainer ? hasUrlContainer.querySelector('a[href]').href : '';
  6350. component.publiclyTrigger('eventClick', [
  6351. {
  6352. el: segEl,
  6353. event: new EventApi(component.calendar, seg.eventRange.def, seg.eventRange.instance),
  6354. jsEvent: ev,
  6355. view: component.view
  6356. }
  6357. ]);
  6358. if (url && !ev.defaultPrevented) {
  6359. window.location.href = url;
  6360. }
  6361. }
  6362. };
  6363. var component = settings.component;
  6364. _this.destroy = listenBySelector(component.el, 'click', component.fgSegSelector + ',' + component.bgSegSelector, _this.handleSegClick);
  6365. return _this;
  6366. }
  6367. return EventClicking;
  6368. }(Interaction));
  6369. /*
  6370. Triggers events and adds/removes core classNames when the user's pointer
  6371. enters/leaves event-elements of a component.
  6372. */
  6373. var EventHovering = /** @class */ (function (_super) {
  6374. __extends(EventHovering, _super);
  6375. function EventHovering(settings) {
  6376. var _this = _super.call(this, settings) || this;
  6377. // for simulating an eventMouseLeave when the event el is destroyed while mouse is over it
  6378. _this.handleEventElRemove = function (el) {
  6379. if (el === _this.currentSegEl) {
  6380. _this.handleSegLeave(null, _this.currentSegEl);
  6381. }
  6382. };
  6383. _this.handleSegEnter = function (ev, segEl) {
  6384. if (getElSeg(segEl)) { // TODO: better way to make sure not hovering over more+ link or its wrapper
  6385. segEl.classList.add('fc-allow-mouse-resize');
  6386. _this.currentSegEl = segEl;
  6387. _this.triggerEvent('eventMouseEnter', ev, segEl);
  6388. }
  6389. };
  6390. _this.handleSegLeave = function (ev, segEl) {
  6391. if (_this.currentSegEl) {
  6392. segEl.classList.remove('fc-allow-mouse-resize');
  6393. _this.currentSegEl = null;
  6394. _this.triggerEvent('eventMouseLeave', ev, segEl);
  6395. }
  6396. };
  6397. var component = settings.component;
  6398. _this.removeHoverListeners = listenToHoverBySelector(component.el, component.fgSegSelector + ',' + component.bgSegSelector, _this.handleSegEnter, _this.handleSegLeave);
  6399. component.calendar.on('eventElRemove', _this.handleEventElRemove);
  6400. return _this;
  6401. }
  6402. EventHovering.prototype.destroy = function () {
  6403. this.removeHoverListeners();
  6404. this.component.calendar.off('eventElRemove', this.handleEventElRemove);
  6405. };
  6406. EventHovering.prototype.triggerEvent = function (publicEvName, ev, segEl) {
  6407. var component = this.component;
  6408. var seg = getElSeg(segEl);
  6409. if (!ev || component.isValidSegDownEl(ev.target)) {
  6410. component.publiclyTrigger(publicEvName, [
  6411. {
  6412. el: segEl,
  6413. event: new EventApi(this.component.calendar, seg.eventRange.def, seg.eventRange.instance),
  6414. jsEvent: ev,
  6415. view: component.view
  6416. }
  6417. ]);
  6418. }
  6419. };
  6420. return EventHovering;
  6421. }(Interaction));
  6422. var StandardTheme = /** @class */ (function (_super) {
  6423. __extends(StandardTheme, _super);
  6424. function StandardTheme() {
  6425. return _super !== null && _super.apply(this, arguments) || this;
  6426. }
  6427. return StandardTheme;
  6428. }(Theme));
  6429. StandardTheme.prototype.classes = {
  6430. widget: 'fc-unthemed',
  6431. widgetHeader: 'fc-widget-header',
  6432. widgetContent: 'fc-widget-content',
  6433. buttonGroup: 'fc-button-group',
  6434. button: 'fc-button fc-button-primary',
  6435. buttonActive: 'fc-button-active',
  6436. popoverHeader: 'fc-widget-header',
  6437. popoverContent: 'fc-widget-content',
  6438. // day grid
  6439. headerRow: 'fc-widget-header',
  6440. dayRow: 'fc-widget-content',
  6441. // list view
  6442. listView: 'fc-widget-content'
  6443. };
  6444. StandardTheme.prototype.baseIconClass = 'fc-icon';
  6445. StandardTheme.prototype.iconClasses = {
  6446. close: 'fc-icon-x',
  6447. prev: 'fc-icon-chevron-left',
  6448. next: 'fc-icon-chevron-right',
  6449. prevYear: 'fc-icon-chevrons-left',
  6450. nextYear: 'fc-icon-chevrons-right'
  6451. };
  6452. StandardTheme.prototype.iconOverrideOption = 'buttonIcons';
  6453. StandardTheme.prototype.iconOverrideCustomButtonOption = 'icon';
  6454. StandardTheme.prototype.iconOverridePrefix = 'fc-icon-';
  6455. var Calendar = /** @class */ (function () {
  6456. function Calendar(el, overrides) {
  6457. var _this = this;
  6458. this.parseRawLocales = memoize(parseRawLocales);
  6459. this.buildLocale = memoize(buildLocale);
  6460. this.buildDateEnv = memoize(buildDateEnv);
  6461. this.buildTheme = memoize(buildTheme);
  6462. this.buildEventUiSingleBase = memoize(this._buildEventUiSingleBase);
  6463. this.buildSelectionConfig = memoize(this._buildSelectionConfig);
  6464. this.buildEventUiBySource = memoizeOutput(buildEventUiBySource, isPropsEqual);
  6465. this.buildEventUiBases = memoize(buildEventUiBases);
  6466. this.interactionsStore = {};
  6467. this.actionQueue = [];
  6468. this.isReducing = false;
  6469. // isDisplaying: boolean = false // installed in DOM? accepting renders?
  6470. this.needsRerender = false; // needs a render?
  6471. this.needsFullRerender = false;
  6472. this.isRendering = false; // currently in the executeRender function?
  6473. this.renderingPauseDepth = 0;
  6474. this.buildDelayedRerender = memoize(buildDelayedRerender);
  6475. this.afterSizingTriggers = {};
  6476. this.isViewUpdated = false;
  6477. this.isDatesUpdated = false;
  6478. this.isEventsUpdated = false;
  6479. this.el = el;
  6480. this.optionsManager = new OptionsManager(overrides || {});
  6481. this.pluginSystem = new PluginSystem();
  6482. // only do once. don't do in handleOptions. because can't remove plugins
  6483. this.addPluginInputs(this.optionsManager.computed.plugins || []);
  6484. this.handleOptions(this.optionsManager.computed);
  6485. this.publiclyTrigger('_init'); // for tests
  6486. this.hydrate();
  6487. this.calendarInteractions = this.pluginSystem.hooks.calendarInteractions
  6488. .map(function (calendarInteractionClass) {
  6489. return new calendarInteractionClass(_this);
  6490. });
  6491. }
  6492. Calendar.prototype.addPluginInputs = function (pluginInputs) {
  6493. var pluginDefs = refinePluginDefs(pluginInputs);
  6494. for (var _i = 0, pluginDefs_1 = pluginDefs; _i < pluginDefs_1.length; _i++) {
  6495. var pluginDef = pluginDefs_1[_i];
  6496. this.pluginSystem.add(pluginDef);
  6497. }
  6498. };
  6499. Object.defineProperty(Calendar.prototype, "view", {
  6500. // public API
  6501. get: function () {
  6502. return this.component ? this.component.view : null;
  6503. },
  6504. enumerable: true,
  6505. configurable: true
  6506. });
  6507. // Public API for rendering
  6508. // -----------------------------------------------------------------------------------------------------------------
  6509. Calendar.prototype.render = function () {
  6510. if (!this.component) {
  6511. this.renderableEventStore = createEmptyEventStore();
  6512. this.bindHandlers();
  6513. this.executeRender();
  6514. }
  6515. else {
  6516. this.requestRerender(true);
  6517. }
  6518. };
  6519. Calendar.prototype.destroy = function () {
  6520. if (this.component) {
  6521. this.unbindHandlers();
  6522. this.component.destroy(); // don't null-out. in case API needs access
  6523. this.component = null; // umm ???
  6524. for (var _i = 0, _a = this.calendarInteractions; _i < _a.length; _i++) {
  6525. var interaction = _a[_i];
  6526. interaction.destroy();
  6527. }
  6528. this.publiclyTrigger('_destroyed');
  6529. }
  6530. };
  6531. // Handlers
  6532. // -----------------------------------------------------------------------------------------------------------------
  6533. Calendar.prototype.bindHandlers = function () {
  6534. var _this = this;
  6535. // event delegation for nav links
  6536. this.removeNavLinkListener = listenBySelector(this.el, 'click', 'a[data-goto]', function (ev, anchorEl) {
  6537. var gotoOptions = anchorEl.getAttribute('data-goto');
  6538. gotoOptions = gotoOptions ? JSON.parse(gotoOptions) : {};
  6539. var dateEnv = _this.dateEnv;
  6540. var dateMarker = dateEnv.createMarker(gotoOptions.date);
  6541. var viewType = gotoOptions.type;
  6542. // property like "navLinkDayClick". might be a string or a function
  6543. var customAction = _this.viewOpt('navLink' + capitaliseFirstLetter(viewType) + 'Click');
  6544. if (typeof customAction === 'function') {
  6545. customAction(dateEnv.toDate(dateMarker), ev);
  6546. }
  6547. else {
  6548. if (typeof customAction === 'string') {
  6549. viewType = customAction;
  6550. }
  6551. _this.zoomTo(dateMarker, viewType);
  6552. }
  6553. });
  6554. if (this.opt('handleWindowResize')) {
  6555. window.addEventListener('resize', this.windowResizeProxy = debounce(// prevents rapid calls
  6556. this.windowResize.bind(this), this.opt('windowResizeDelay')));
  6557. }
  6558. };
  6559. Calendar.prototype.unbindHandlers = function () {
  6560. this.removeNavLinkListener();
  6561. if (this.windowResizeProxy) {
  6562. window.removeEventListener('resize', this.windowResizeProxy);
  6563. this.windowResizeProxy = null;
  6564. }
  6565. };
  6566. // Dispatcher
  6567. // -----------------------------------------------------------------------------------------------------------------
  6568. Calendar.prototype.hydrate = function () {
  6569. var _this = this;
  6570. this.state = this.buildInitialState();
  6571. var rawSources = this.opt('eventSources') || [];
  6572. var singleRawSource = this.opt('events');
  6573. var sources = []; // parsed
  6574. if (singleRawSource) {
  6575. rawSources.unshift(singleRawSource);
  6576. }
  6577. for (var _i = 0, rawSources_1 = rawSources; _i < rawSources_1.length; _i++) {
  6578. var rawSource = rawSources_1[_i];
  6579. var source = parseEventSource(rawSource, this);
  6580. if (source) {
  6581. sources.push(source);
  6582. }
  6583. }
  6584. this.batchRendering(function () {
  6585. _this.dispatch({ type: 'INIT' }); // pass in sources here?
  6586. _this.dispatch({ type: 'ADD_EVENT_SOURCES', sources: sources });
  6587. _this.dispatch({
  6588. type: 'SET_VIEW_TYPE',
  6589. viewType: _this.opt('defaultView') || _this.pluginSystem.hooks.defaultView
  6590. });
  6591. });
  6592. };
  6593. Calendar.prototype.buildInitialState = function () {
  6594. return {
  6595. viewType: null,
  6596. loadingLevel: 0,
  6597. eventSourceLoadingLevel: 0,
  6598. currentDate: this.getInitialDate(),
  6599. dateProfile: null,
  6600. eventSources: {},
  6601. eventStore: createEmptyEventStore(),
  6602. dateSelection: null,
  6603. eventSelection: '',
  6604. eventDrag: null,
  6605. eventResize: null
  6606. };
  6607. };
  6608. Calendar.prototype.dispatch = function (action) {
  6609. this.actionQueue.push(action);
  6610. if (!this.isReducing) {
  6611. this.isReducing = true;
  6612. var oldState = this.state;
  6613. while (this.actionQueue.length) {
  6614. this.state = this.reduce(this.state, this.actionQueue.shift(), this);
  6615. }
  6616. var newState = this.state;
  6617. this.isReducing = false;
  6618. if (!oldState.loadingLevel && newState.loadingLevel) {
  6619. this.publiclyTrigger('loading', [true]);
  6620. }
  6621. else if (oldState.loadingLevel && !newState.loadingLevel) {
  6622. this.publiclyTrigger('loading', [false]);
  6623. }
  6624. var view = this.component && this.component.view;
  6625. if (oldState.eventStore !== newState.eventStore || this.needsFullRerender) {
  6626. if (oldState.eventStore) {
  6627. this.isEventsUpdated = true;
  6628. }
  6629. }
  6630. if (oldState.dateProfile !== newState.dateProfile || this.needsFullRerender) {
  6631. if (oldState.dateProfile && view) { // why would view be null!?
  6632. this.publiclyTrigger('datesDestroy', [
  6633. {
  6634. view: view,
  6635. el: view.el
  6636. }
  6637. ]);
  6638. }
  6639. this.isDatesUpdated = true;
  6640. }
  6641. if (oldState.viewType !== newState.viewType || this.needsFullRerender) {
  6642. if (oldState.viewType && view) { // why would view be null!?
  6643. this.publiclyTrigger('viewSkeletonDestroy', [
  6644. {
  6645. view: view,
  6646. el: view.el
  6647. }
  6648. ]);
  6649. }
  6650. this.isViewUpdated = true;
  6651. }
  6652. this.requestRerender();
  6653. }
  6654. };
  6655. Calendar.prototype.reduce = function (state, action, calendar) {
  6656. return reduce(state, action, calendar);
  6657. };
  6658. // Render Queue
  6659. // -----------------------------------------------------------------------------------------------------------------
  6660. Calendar.prototype.requestRerender = function (needsFull) {
  6661. if (needsFull === void 0) { needsFull = false; }
  6662. this.needsRerender = true;
  6663. this.needsFullRerender = this.needsFullRerender || needsFull;
  6664. this.delayedRerender(); // will call a debounced-version of tryRerender
  6665. };
  6666. Calendar.prototype.tryRerender = function () {
  6667. if (this.component && // must be accepting renders
  6668. this.needsRerender && // indicates that a rerender was requested
  6669. !this.renderingPauseDepth && // not paused
  6670. !this.isRendering // not currently in the render loop
  6671. ) {
  6672. this.executeRender();
  6673. }
  6674. };
  6675. Calendar.prototype.batchRendering = function (func) {
  6676. this.renderingPauseDepth++;
  6677. func();
  6678. this.renderingPauseDepth--;
  6679. if (this.needsRerender) {
  6680. this.requestRerender();
  6681. }
  6682. };
  6683. // Rendering
  6684. // -----------------------------------------------------------------------------------------------------------------
  6685. Calendar.prototype.executeRender = function () {
  6686. var needsFullRerender = this.needsFullRerender; // save before clearing
  6687. // clear these BEFORE the render so that new values will accumulate during render
  6688. this.needsRerender = false;
  6689. this.needsFullRerender = false;
  6690. this.isRendering = true;
  6691. this.renderComponent(needsFullRerender);
  6692. this.isRendering = false;
  6693. // received a rerender request while rendering
  6694. if (this.needsRerender) {
  6695. this.delayedRerender();
  6696. }
  6697. };
  6698. /*
  6699. don't call this directly. use executeRender instead
  6700. */
  6701. Calendar.prototype.renderComponent = function (needsFull) {
  6702. var _a = this, state = _a.state, component = _a.component;
  6703. var viewType = state.viewType;
  6704. var viewSpec = this.viewSpecs[viewType];
  6705. var savedScroll = (needsFull && component) ? component.view.queryScroll() : null;
  6706. if (!viewSpec) {
  6707. throw new Error("View type \"" + viewType + "\" is not valid");
  6708. }
  6709. // if event sources are still loading and progressive rendering hasn't been enabled,
  6710. // keep rendering the last fully loaded set of events
  6711. var renderableEventStore = this.renderableEventStore =
  6712. (state.eventSourceLoadingLevel && !this.opt('progressiveEventRendering')) ?
  6713. this.renderableEventStore :
  6714. state.eventStore;
  6715. var eventUiSingleBase = this.buildEventUiSingleBase(viewSpec.options);
  6716. var eventUiBySource = this.buildEventUiBySource(state.eventSources);
  6717. var eventUiBases = this.eventUiBases = this.buildEventUiBases(renderableEventStore.defs, eventUiSingleBase, eventUiBySource);
  6718. if (needsFull || !component) {
  6719. if (component) {
  6720. component.freezeHeight(); // next component will unfreeze it
  6721. component.destroy();
  6722. }
  6723. component = this.component = new CalendarComponent({
  6724. calendar: this,
  6725. view: null,
  6726. dateEnv: this.dateEnv,
  6727. theme: this.theme,
  6728. options: this.optionsManager.computed
  6729. }, this.el);
  6730. this.isViewUpdated = true;
  6731. this.isDatesUpdated = true;
  6732. this.isEventsUpdated = true;
  6733. }
  6734. component.receiveProps(__assign({}, state, { viewSpec: viewSpec, dateProfile: state.dateProfile, dateProfileGenerator: this.dateProfileGenerators[viewType], eventStore: renderableEventStore, eventUiBases: eventUiBases, dateSelection: state.dateSelection, eventSelection: state.eventSelection, eventDrag: state.eventDrag, eventResize: state.eventResize }));
  6735. if (savedScroll) {
  6736. component.view.applyScroll(savedScroll, false);
  6737. }
  6738. if (this.isViewUpdated) {
  6739. this.isViewUpdated = false;
  6740. this.publiclyTrigger('viewSkeletonRender', [
  6741. {
  6742. view: component.view,
  6743. el: component.view.el
  6744. }
  6745. ]);
  6746. }
  6747. if (this.isDatesUpdated) {
  6748. this.isDatesUpdated = false;
  6749. this.publiclyTrigger('datesRender', [
  6750. {
  6751. view: component.view,
  6752. el: component.view.el
  6753. }
  6754. ]);
  6755. }
  6756. if (this.isEventsUpdated) {
  6757. this.isEventsUpdated = false;
  6758. }
  6759. this.releaseAfterSizingTriggers();
  6760. };
  6761. // Options
  6762. // -----------------------------------------------------------------------------------------------------------------
  6763. Calendar.prototype.setOption = function (name, val) {
  6764. var _a;
  6765. this.mutateOptions((_a = {}, _a[name] = val, _a), [], true);
  6766. };
  6767. Calendar.prototype.getOption = function (name) {
  6768. return this.optionsManager.computed[name];
  6769. };
  6770. Calendar.prototype.opt = function (name) {
  6771. return this.optionsManager.computed[name];
  6772. };
  6773. Calendar.prototype.viewOpt = function (name) {
  6774. return this.viewOpts()[name];
  6775. };
  6776. Calendar.prototype.viewOpts = function () {
  6777. return this.viewSpecs[this.state.viewType].options;
  6778. };
  6779. /*
  6780. handles option changes (like a diff)
  6781. */
  6782. Calendar.prototype.mutateOptions = function (updates, removals, isDynamic, deepEqual) {
  6783. var _this = this;
  6784. var changeHandlers = this.pluginSystem.hooks.optionChangeHandlers;
  6785. var normalUpdates = {};
  6786. var specialUpdates = {};
  6787. var oldDateEnv = this.dateEnv; // do this before handleOptions
  6788. var isTimeZoneDirty = false;
  6789. var isSizeDirty = false;
  6790. var anyDifficultOptions = Boolean(removals.length);
  6791. for (var name_1 in updates) {
  6792. if (changeHandlers[name_1]) {
  6793. specialUpdates[name_1] = updates[name_1];
  6794. }
  6795. else {
  6796. normalUpdates[name_1] = updates[name_1];
  6797. }
  6798. }
  6799. for (var name_2 in normalUpdates) {
  6800. if (/^(height|contentHeight|aspectRatio)$/.test(name_2)) {
  6801. isSizeDirty = true;
  6802. }
  6803. else if (/^(defaultDate|defaultView)$/.test(name_2)) ;
  6804. else {
  6805. anyDifficultOptions = true;
  6806. if (name_2 === 'timeZone') {
  6807. isTimeZoneDirty = true;
  6808. }
  6809. }
  6810. }
  6811. this.optionsManager.mutate(normalUpdates, removals, isDynamic);
  6812. if (anyDifficultOptions) {
  6813. this.handleOptions(this.optionsManager.computed);
  6814. this.needsFullRerender = true;
  6815. }
  6816. this.batchRendering(function () {
  6817. if (anyDifficultOptions) {
  6818. if (isTimeZoneDirty) {
  6819. _this.dispatch({
  6820. type: 'CHANGE_TIMEZONE',
  6821. oldDateEnv: oldDateEnv
  6822. });
  6823. }
  6824. /* HACK
  6825. has the same effect as calling this.requestRerender(true)
  6826. but recomputes the state's dateProfile
  6827. */
  6828. _this.dispatch({
  6829. type: 'SET_VIEW_TYPE',
  6830. viewType: _this.state.viewType
  6831. });
  6832. }
  6833. else if (isSizeDirty) {
  6834. _this.updateSize();
  6835. }
  6836. // special updates
  6837. if (deepEqual) {
  6838. for (var name_3 in specialUpdates) {
  6839. changeHandlers[name_3](specialUpdates[name_3], _this, deepEqual);
  6840. }
  6841. }
  6842. });
  6843. };
  6844. /*
  6845. rebuilds things based off of a complete set of refined options
  6846. */
  6847. Calendar.prototype.handleOptions = function (options) {
  6848. var _this = this;
  6849. var pluginHooks = this.pluginSystem.hooks;
  6850. this.defaultAllDayEventDuration = createDuration(options.defaultAllDayEventDuration);
  6851. this.defaultTimedEventDuration = createDuration(options.defaultTimedEventDuration);
  6852. this.delayedRerender = this.buildDelayedRerender(options.rerenderDelay);
  6853. this.theme = this.buildTheme(options);
  6854. var available = this.parseRawLocales(options.locales);
  6855. this.availableRawLocales = available.map;
  6856. var locale = this.buildLocale(options.locale || available.defaultCode, available.map);
  6857. this.dateEnv = this.buildDateEnv(locale, options.timeZone, pluginHooks.namedTimeZonedImpl, options.firstDay, options.weekNumberCalculation, options.weekLabel, pluginHooks.cmdFormatter);
  6858. this.selectionConfig = this.buildSelectionConfig(options); // needs dateEnv. do after :(
  6859. // ineffecient to do every time?
  6860. this.viewSpecs = buildViewSpecs(pluginHooks.views, this.optionsManager);
  6861. // ineffecient to do every time?
  6862. this.dateProfileGenerators = mapHash(this.viewSpecs, function (viewSpec) {
  6863. return new viewSpec.class.prototype.dateProfileGeneratorClass(viewSpec, _this);
  6864. });
  6865. };
  6866. Calendar.prototype.getAvailableLocaleCodes = function () {
  6867. return Object.keys(this.availableRawLocales);
  6868. };
  6869. Calendar.prototype._buildSelectionConfig = function (rawOpts) {
  6870. return processScopedUiProps('select', rawOpts, this);
  6871. };
  6872. Calendar.prototype._buildEventUiSingleBase = function (rawOpts) {
  6873. if (rawOpts.editable) { // so 'editable' affected events
  6874. rawOpts = __assign({}, rawOpts, { eventEditable: true });
  6875. }
  6876. return processScopedUiProps('event', rawOpts, this);
  6877. };
  6878. // Trigger
  6879. // -----------------------------------------------------------------------------------------------------------------
  6880. Calendar.prototype.hasPublicHandlers = function (name) {
  6881. return this.hasHandlers(name) ||
  6882. this.opt(name); // handler specified in options
  6883. };
  6884. Calendar.prototype.publiclyTrigger = function (name, args) {
  6885. var optHandler = this.opt(name);
  6886. this.triggerWith(name, this, args);
  6887. if (optHandler) {
  6888. return optHandler.apply(this, args);
  6889. }
  6890. };
  6891. Calendar.prototype.publiclyTriggerAfterSizing = function (name, args) {
  6892. var afterSizingTriggers = this.afterSizingTriggers;
  6893. (afterSizingTriggers[name] || (afterSizingTriggers[name] = [])).push(args);
  6894. };
  6895. Calendar.prototype.releaseAfterSizingTriggers = function () {
  6896. var afterSizingTriggers = this.afterSizingTriggers;
  6897. for (var name_4 in afterSizingTriggers) {
  6898. for (var _i = 0, _a = afterSizingTriggers[name_4]; _i < _a.length; _i++) {
  6899. var args = _a[_i];
  6900. this.publiclyTrigger(name_4, args);
  6901. }
  6902. }
  6903. this.afterSizingTriggers = {};
  6904. };
  6905. // View
  6906. // -----------------------------------------------------------------------------------------------------------------
  6907. // Returns a boolean about whether the view is okay to instantiate at some point
  6908. Calendar.prototype.isValidViewType = function (viewType) {
  6909. return Boolean(this.viewSpecs[viewType]);
  6910. };
  6911. Calendar.prototype.changeView = function (viewType, dateOrRange) {
  6912. var dateMarker = null;
  6913. if (dateOrRange) {
  6914. if (dateOrRange.start && dateOrRange.end) { // a range
  6915. this.optionsManager.mutate({ visibleRange: dateOrRange }, []); // will not rerender
  6916. this.handleOptions(this.optionsManager.computed); // ...but yuck
  6917. }
  6918. else { // a date
  6919. dateMarker = this.dateEnv.createMarker(dateOrRange); // just like gotoDate
  6920. }
  6921. }
  6922. this.unselect();
  6923. this.dispatch({
  6924. type: 'SET_VIEW_TYPE',
  6925. viewType: viewType,
  6926. dateMarker: dateMarker
  6927. });
  6928. };
  6929. // Forces navigation to a view for the given date.
  6930. // `viewType` can be a specific view name or a generic one like "week" or "day".
  6931. // needs to change
  6932. Calendar.prototype.zoomTo = function (dateMarker, viewType) {
  6933. var spec;
  6934. viewType = viewType || 'day'; // day is default zoom
  6935. spec = this.viewSpecs[viewType] ||
  6936. this.getUnitViewSpec(viewType);
  6937. this.unselect();
  6938. if (spec) {
  6939. this.dispatch({
  6940. type: 'SET_VIEW_TYPE',
  6941. viewType: spec.type,
  6942. dateMarker: dateMarker
  6943. });
  6944. }
  6945. else {
  6946. this.dispatch({
  6947. type: 'SET_DATE',
  6948. dateMarker: dateMarker
  6949. });
  6950. }
  6951. };
  6952. // Given a duration singular unit, like "week" or "day", finds a matching view spec.
  6953. // Preference is given to views that have corresponding buttons.
  6954. Calendar.prototype.getUnitViewSpec = function (unit) {
  6955. var component = this.component;
  6956. var viewTypes = [];
  6957. var i;
  6958. var spec;
  6959. // put views that have buttons first. there will be duplicates, but oh
  6960. if (component.header) {
  6961. viewTypes.push.apply(viewTypes, component.header.viewsWithButtons);
  6962. }
  6963. if (component.footer) {
  6964. viewTypes.push.apply(viewTypes, component.footer.viewsWithButtons);
  6965. }
  6966. for (var viewType in this.viewSpecs) {
  6967. viewTypes.push(viewType);
  6968. }
  6969. for (i = 0; i < viewTypes.length; i++) {
  6970. spec = this.viewSpecs[viewTypes[i]];
  6971. if (spec) {
  6972. if (spec.singleUnit === unit) {
  6973. return spec;
  6974. }
  6975. }
  6976. }
  6977. };
  6978. // Current Date
  6979. // -----------------------------------------------------------------------------------------------------------------
  6980. Calendar.prototype.getInitialDate = function () {
  6981. var defaultDateInput = this.opt('defaultDate');
  6982. // compute the initial ambig-timezone date
  6983. if (defaultDateInput != null) {
  6984. return this.dateEnv.createMarker(defaultDateInput);
  6985. }
  6986. else {
  6987. return this.getNow(); // getNow already returns unzoned
  6988. }
  6989. };
  6990. Calendar.prototype.prev = function () {
  6991. this.unselect();
  6992. this.dispatch({ type: 'PREV' });
  6993. };
  6994. Calendar.prototype.next = function () {
  6995. this.unselect();
  6996. this.dispatch({ type: 'NEXT' });
  6997. };
  6998. Calendar.prototype.prevYear = function () {
  6999. this.unselect();
  7000. this.dispatch({
  7001. type: 'SET_DATE',
  7002. dateMarker: this.dateEnv.addYears(this.state.currentDate, -1)
  7003. });
  7004. };
  7005. Calendar.prototype.nextYear = function () {
  7006. this.unselect();
  7007. this.dispatch({
  7008. type: 'SET_DATE',
  7009. dateMarker: this.dateEnv.addYears(this.state.currentDate, 1)
  7010. });
  7011. };
  7012. Calendar.prototype.today = function () {
  7013. this.unselect();
  7014. this.dispatch({
  7015. type: 'SET_DATE',
  7016. dateMarker: this.getNow()
  7017. });
  7018. };
  7019. Calendar.prototype.gotoDate = function (zonedDateInput) {
  7020. this.unselect();
  7021. this.dispatch({
  7022. type: 'SET_DATE',
  7023. dateMarker: this.dateEnv.createMarker(zonedDateInput)
  7024. });
  7025. };
  7026. Calendar.prototype.incrementDate = function (deltaInput) {
  7027. var delta = createDuration(deltaInput);
  7028. if (delta) { // else, warn about invalid input?
  7029. this.unselect();
  7030. this.dispatch({
  7031. type: 'SET_DATE',
  7032. dateMarker: this.dateEnv.add(this.state.currentDate, delta)
  7033. });
  7034. }
  7035. };
  7036. // for external API
  7037. Calendar.prototype.getDate = function () {
  7038. return this.dateEnv.toDate(this.state.currentDate);
  7039. };
  7040. // Date Formatting Utils
  7041. // -----------------------------------------------------------------------------------------------------------------
  7042. Calendar.prototype.formatDate = function (d, formatter) {
  7043. var dateEnv = this.dateEnv;
  7044. return dateEnv.format(dateEnv.createMarker(d), createFormatter(formatter));
  7045. };
  7046. // `settings` is for formatter AND isEndExclusive
  7047. Calendar.prototype.formatRange = function (d0, d1, settings) {
  7048. var dateEnv = this.dateEnv;
  7049. return dateEnv.formatRange(dateEnv.createMarker(d0), dateEnv.createMarker(d1), createFormatter(settings, this.opt('defaultRangeSeparator')), settings);
  7050. };
  7051. Calendar.prototype.formatIso = function (d, omitTime) {
  7052. var dateEnv = this.dateEnv;
  7053. return dateEnv.formatIso(dateEnv.createMarker(d), { omitTime: omitTime });
  7054. };
  7055. // Sizing
  7056. // -----------------------------------------------------------------------------------------------------------------
  7057. Calendar.prototype.windowResize = function (ev) {
  7058. if (!this.isHandlingWindowResize &&
  7059. this.component && // why?
  7060. ev.target === window // not a jqui resize event
  7061. ) {
  7062. this.isHandlingWindowResize = true;
  7063. this.updateSize();
  7064. this.publiclyTrigger('windowResize', [this.view]);
  7065. this.isHandlingWindowResize = false;
  7066. }
  7067. };
  7068. Calendar.prototype.updateSize = function () {
  7069. if (this.component) { // when?
  7070. this.component.updateSize(true);
  7071. }
  7072. };
  7073. // Component Registration
  7074. // -----------------------------------------------------------------------------------------------------------------
  7075. Calendar.prototype.registerInteractiveComponent = function (component, settingsInput) {
  7076. var settings = parseInteractionSettings(component, settingsInput);
  7077. var DEFAULT_INTERACTIONS = [
  7078. EventClicking,
  7079. EventHovering
  7080. ];
  7081. var interactionClasses = DEFAULT_INTERACTIONS.concat(this.pluginSystem.hooks.componentInteractions);
  7082. var interactions = interactionClasses.map(function (interactionClass) {
  7083. return new interactionClass(settings);
  7084. });
  7085. this.interactionsStore[component.uid] = interactions;
  7086. interactionSettingsStore[component.uid] = settings;
  7087. };
  7088. Calendar.prototype.unregisterInteractiveComponent = function (component) {
  7089. for (var _i = 0, _a = this.interactionsStore[component.uid]; _i < _a.length; _i++) {
  7090. var listener = _a[_i];
  7091. listener.destroy();
  7092. }
  7093. delete this.interactionsStore[component.uid];
  7094. delete interactionSettingsStore[component.uid];
  7095. };
  7096. // Date Selection / Event Selection / DayClick
  7097. // -----------------------------------------------------------------------------------------------------------------
  7098. // this public method receives start/end dates in any format, with any timezone
  7099. // NOTE: args were changed from v3
  7100. Calendar.prototype.select = function (dateOrObj, endDate) {
  7101. var selectionInput;
  7102. if (endDate == null) {
  7103. if (dateOrObj.start != null) {
  7104. selectionInput = dateOrObj;
  7105. }
  7106. else {
  7107. selectionInput = {
  7108. start: dateOrObj,
  7109. end: null
  7110. };
  7111. }
  7112. }
  7113. else {
  7114. selectionInput = {
  7115. start: dateOrObj,
  7116. end: endDate
  7117. };
  7118. }
  7119. var selection = parseDateSpan(selectionInput, this.dateEnv, createDuration({ days: 1 }) // TODO: cache this?
  7120. );
  7121. if (selection) { // throw parse error otherwise?
  7122. this.dispatch({ type: 'SELECT_DATES', selection: selection });
  7123. this.triggerDateSelect(selection);
  7124. }
  7125. };
  7126. // public method
  7127. Calendar.prototype.unselect = function (pev) {
  7128. if (this.state.dateSelection) {
  7129. this.dispatch({ type: 'UNSELECT_DATES' });
  7130. this.triggerDateUnselect(pev);
  7131. }
  7132. };
  7133. Calendar.prototype.triggerDateSelect = function (selection, pev) {
  7134. var arg = __assign({}, this.buildDateSpanApi(selection), { jsEvent: pev ? pev.origEvent : null, view: this.view });
  7135. this.publiclyTrigger('select', [arg]);
  7136. };
  7137. Calendar.prototype.triggerDateUnselect = function (pev) {
  7138. this.publiclyTrigger('unselect', [
  7139. {
  7140. jsEvent: pev ? pev.origEvent : null,
  7141. view: this.view
  7142. }
  7143. ]);
  7144. };
  7145. // TODO: receive pev?
  7146. Calendar.prototype.triggerDateClick = function (dateSpan, dayEl, view, ev) {
  7147. var arg = __assign({}, this.buildDatePointApi(dateSpan), { dayEl: dayEl, jsEvent: ev, // Is this always a mouse event? See #4655
  7148. view: view });
  7149. this.publiclyTrigger('dateClick', [arg]);
  7150. };
  7151. Calendar.prototype.buildDatePointApi = function (dateSpan) {
  7152. var props = {};
  7153. for (var _i = 0, _a = this.pluginSystem.hooks.datePointTransforms; _i < _a.length; _i++) {
  7154. var transform = _a[_i];
  7155. __assign(props, transform(dateSpan, this));
  7156. }
  7157. __assign(props, buildDatePointApi(dateSpan, this.dateEnv));
  7158. return props;
  7159. };
  7160. Calendar.prototype.buildDateSpanApi = function (dateSpan) {
  7161. var props = {};
  7162. for (var _i = 0, _a = this.pluginSystem.hooks.dateSpanTransforms; _i < _a.length; _i++) {
  7163. var transform = _a[_i];
  7164. __assign(props, transform(dateSpan, this));
  7165. }
  7166. __assign(props, buildDateSpanApi(dateSpan, this.dateEnv));
  7167. return props;
  7168. };
  7169. // Date Utils
  7170. // -----------------------------------------------------------------------------------------------------------------
  7171. // Returns a DateMarker for the current date, as defined by the client's computer or from the `now` option
  7172. Calendar.prototype.getNow = function () {
  7173. var now = this.opt('now');
  7174. if (typeof now === 'function') {
  7175. now = now();
  7176. }
  7177. if (now == null) {
  7178. return this.dateEnv.createNowMarker();
  7179. }
  7180. return this.dateEnv.createMarker(now);
  7181. };
  7182. // Event-Date Utilities
  7183. // -----------------------------------------------------------------------------------------------------------------
  7184. // Given an event's allDay status and start date, return what its fallback end date should be.
  7185. // TODO: rename to computeDefaultEventEnd
  7186. Calendar.prototype.getDefaultEventEnd = function (allDay, marker) {
  7187. var end = marker;
  7188. if (allDay) {
  7189. end = startOfDay(end);
  7190. end = this.dateEnv.add(end, this.defaultAllDayEventDuration);
  7191. }
  7192. else {
  7193. end = this.dateEnv.add(end, this.defaultTimedEventDuration);
  7194. }
  7195. return end;
  7196. };
  7197. // Public Events API
  7198. // -----------------------------------------------------------------------------------------------------------------
  7199. Calendar.prototype.addEvent = function (eventInput, sourceInput) {
  7200. if (eventInput instanceof EventApi) {
  7201. var def = eventInput._def;
  7202. var instance = eventInput._instance;
  7203. // not already present? don't want to add an old snapshot
  7204. if (!this.state.eventStore.defs[def.defId]) {
  7205. this.dispatch({
  7206. type: 'ADD_EVENTS',
  7207. eventStore: eventTupleToStore({ def: def, instance: instance }) // TODO: better util for two args?
  7208. });
  7209. }
  7210. return eventInput;
  7211. }
  7212. var sourceId;
  7213. if (sourceInput instanceof EventSourceApi) {
  7214. sourceId = sourceInput.internalEventSource.sourceId;
  7215. }
  7216. else if (sourceInput != null) {
  7217. var sourceApi = this.getEventSourceById(sourceInput); // TODO: use an internal function
  7218. if (!sourceApi) {
  7219. console.warn('Could not find an event source with ID "' + sourceInput + '"'); // TODO: test
  7220. return null;
  7221. }
  7222. else {
  7223. sourceId = sourceApi.internalEventSource.sourceId;
  7224. }
  7225. }
  7226. var tuple = parseEvent(eventInput, sourceId, this);
  7227. if (tuple) {
  7228. this.dispatch({
  7229. type: 'ADD_EVENTS',
  7230. eventStore: eventTupleToStore(tuple)
  7231. });
  7232. return new EventApi(this, tuple.def, tuple.def.recurringDef ? null : tuple.instance);
  7233. }
  7234. return null;
  7235. };
  7236. // TODO: optimize
  7237. Calendar.prototype.getEventById = function (id) {
  7238. var _a = this.state.eventStore, defs = _a.defs, instances = _a.instances;
  7239. id = String(id);
  7240. for (var defId in defs) {
  7241. var def = defs[defId];
  7242. if (def.publicId === id) {
  7243. if (def.recurringDef) {
  7244. return new EventApi(this, def, null);
  7245. }
  7246. else {
  7247. for (var instanceId in instances) {
  7248. var instance = instances[instanceId];
  7249. if (instance.defId === def.defId) {
  7250. return new EventApi(this, def, instance);
  7251. }
  7252. }
  7253. }
  7254. }
  7255. }
  7256. return null;
  7257. };
  7258. Calendar.prototype.getEvents = function () {
  7259. var _a = this.state.eventStore, defs = _a.defs, instances = _a.instances;
  7260. var eventApis = [];
  7261. for (var id in instances) {
  7262. var instance = instances[id];
  7263. var def = defs[instance.defId];
  7264. eventApis.push(new EventApi(this, def, instance));
  7265. }
  7266. return eventApis;
  7267. };
  7268. Calendar.prototype.removeAllEvents = function () {
  7269. this.dispatch({ type: 'REMOVE_ALL_EVENTS' });
  7270. };
  7271. Calendar.prototype.rerenderEvents = function () {
  7272. this.dispatch({ type: 'RESET_EVENTS' });
  7273. };
  7274. // Public Event Sources API
  7275. // -----------------------------------------------------------------------------------------------------------------
  7276. Calendar.prototype.getEventSources = function () {
  7277. var sourceHash = this.state.eventSources;
  7278. var sourceApis = [];
  7279. for (var internalId in sourceHash) {
  7280. sourceApis.push(new EventSourceApi(this, sourceHash[internalId]));
  7281. }
  7282. return sourceApis;
  7283. };
  7284. Calendar.prototype.getEventSourceById = function (id) {
  7285. var sourceHash = this.state.eventSources;
  7286. id = String(id);
  7287. for (var sourceId in sourceHash) {
  7288. if (sourceHash[sourceId].publicId === id) {
  7289. return new EventSourceApi(this, sourceHash[sourceId]);
  7290. }
  7291. }
  7292. return null;
  7293. };
  7294. Calendar.prototype.addEventSource = function (sourceInput) {
  7295. if (sourceInput instanceof EventSourceApi) {
  7296. // not already present? don't want to add an old snapshot
  7297. if (!this.state.eventSources[sourceInput.internalEventSource.sourceId]) {
  7298. this.dispatch({
  7299. type: 'ADD_EVENT_SOURCES',
  7300. sources: [sourceInput.internalEventSource]
  7301. });
  7302. }
  7303. return sourceInput;
  7304. }
  7305. var eventSource = parseEventSource(sourceInput, this);
  7306. if (eventSource) { // TODO: error otherwise?
  7307. this.dispatch({ type: 'ADD_EVENT_SOURCES', sources: [eventSource] });
  7308. return new EventSourceApi(this, eventSource);
  7309. }
  7310. return null;
  7311. };
  7312. Calendar.prototype.removeAllEventSources = function () {
  7313. this.dispatch({ type: 'REMOVE_ALL_EVENT_SOURCES' });
  7314. };
  7315. Calendar.prototype.refetchEvents = function () {
  7316. this.dispatch({ type: 'FETCH_EVENT_SOURCES' });
  7317. };
  7318. // Scroll
  7319. // -----------------------------------------------------------------------------------------------------------------
  7320. Calendar.prototype.scrollToTime = function (timeInput) {
  7321. var duration = createDuration(timeInput);
  7322. if (duration) {
  7323. this.component.view.scrollToDuration(duration);
  7324. }
  7325. };
  7326. return Calendar;
  7327. }());
  7328. EmitterMixin.mixInto(Calendar);
  7329. // for memoizers
  7330. // -----------------------------------------------------------------------------------------------------------------
  7331. function buildDateEnv(locale, timeZone, namedTimeZoneImpl, firstDay, weekNumberCalculation, weekLabel, cmdFormatter) {
  7332. return new DateEnv({
  7333. calendarSystem: 'gregory',
  7334. timeZone: timeZone,
  7335. namedTimeZoneImpl: namedTimeZoneImpl,
  7336. locale: locale,
  7337. weekNumberCalculation: weekNumberCalculation,
  7338. firstDay: firstDay,
  7339. weekLabel: weekLabel,
  7340. cmdFormatter: cmdFormatter
  7341. });
  7342. }
  7343. function buildTheme(calendarOptions) {
  7344. var themeClass = this.pluginSystem.hooks.themeClasses[calendarOptions.themeSystem] || StandardTheme;
  7345. return new themeClass(calendarOptions);
  7346. }
  7347. function buildDelayedRerender(wait) {
  7348. var func = this.tryRerender.bind(this);
  7349. if (wait != null) {
  7350. func = debounce(func, wait);
  7351. }
  7352. return func;
  7353. }
  7354. function buildEventUiBySource(eventSources) {
  7355. return mapHash(eventSources, function (eventSource) {
  7356. return eventSource.ui;
  7357. });
  7358. }
  7359. function buildEventUiBases(eventDefs, eventUiSingleBase, eventUiBySource) {
  7360. var eventUiBases = { '': eventUiSingleBase };
  7361. for (var defId in eventDefs) {
  7362. var def = eventDefs[defId];
  7363. if (def.sourceId && eventUiBySource[def.sourceId]) {
  7364. eventUiBases[defId] = eventUiBySource[def.sourceId];
  7365. }
  7366. }
  7367. return eventUiBases;
  7368. }
  7369. var View = /** @class */ (function (_super) {
  7370. __extends(View, _super);
  7371. function View(context, viewSpec, dateProfileGenerator, parentEl) {
  7372. var _this = _super.call(this, context, createElement('div', { className: 'fc-view fc-' + viewSpec.type + '-view' }), true // isView (HACK)
  7373. ) || this;
  7374. _this.renderDatesMem = memoizeRendering(_this.renderDatesWrap, _this.unrenderDatesWrap);
  7375. _this.renderBusinessHoursMem = memoizeRendering(_this.renderBusinessHours, _this.unrenderBusinessHours, [_this.renderDatesMem]);
  7376. _this.renderDateSelectionMem = memoizeRendering(_this.renderDateSelectionWrap, _this.unrenderDateSelectionWrap, [_this.renderDatesMem]);
  7377. _this.renderEventsMem = memoizeRendering(_this.renderEvents, _this.unrenderEvents, [_this.renderDatesMem]);
  7378. _this.renderEventSelectionMem = memoizeRendering(_this.renderEventSelectionWrap, _this.unrenderEventSelectionWrap, [_this.renderEventsMem]);
  7379. _this.renderEventDragMem = memoizeRendering(_this.renderEventDragWrap, _this.unrenderEventDragWrap, [_this.renderDatesMem]);
  7380. _this.renderEventResizeMem = memoizeRendering(_this.renderEventResizeWrap, _this.unrenderEventResizeWrap, [_this.renderDatesMem]);
  7381. _this.viewSpec = viewSpec;
  7382. _this.dateProfileGenerator = dateProfileGenerator;
  7383. _this.type = viewSpec.type;
  7384. _this.eventOrderSpecs = parseFieldSpecs(_this.opt('eventOrder'));
  7385. _this.nextDayThreshold = createDuration(_this.opt('nextDayThreshold'));
  7386. parentEl.appendChild(_this.el);
  7387. _this.initialize();
  7388. return _this;
  7389. }
  7390. View.prototype.initialize = function () {
  7391. };
  7392. Object.defineProperty(View.prototype, "activeStart", {
  7393. // Date Setting/Unsetting
  7394. // -----------------------------------------------------------------------------------------------------------------
  7395. get: function () {
  7396. return this.dateEnv.toDate(this.props.dateProfile.activeRange.start);
  7397. },
  7398. enumerable: true,
  7399. configurable: true
  7400. });
  7401. Object.defineProperty(View.prototype, "activeEnd", {
  7402. get: function () {
  7403. return this.dateEnv.toDate(this.props.dateProfile.activeRange.end);
  7404. },
  7405. enumerable: true,
  7406. configurable: true
  7407. });
  7408. Object.defineProperty(View.prototype, "currentStart", {
  7409. get: function () {
  7410. return this.dateEnv.toDate(this.props.dateProfile.currentRange.start);
  7411. },
  7412. enumerable: true,
  7413. configurable: true
  7414. });
  7415. Object.defineProperty(View.prototype, "currentEnd", {
  7416. get: function () {
  7417. return this.dateEnv.toDate(this.props.dateProfile.currentRange.end);
  7418. },
  7419. enumerable: true,
  7420. configurable: true
  7421. });
  7422. // General Rendering
  7423. // -----------------------------------------------------------------------------------------------------------------
  7424. View.prototype.render = function (props) {
  7425. this.renderDatesMem(props.dateProfile);
  7426. this.renderBusinessHoursMem(props.businessHours);
  7427. this.renderDateSelectionMem(props.dateSelection);
  7428. this.renderEventsMem(props.eventStore);
  7429. this.renderEventSelectionMem(props.eventSelection);
  7430. this.renderEventDragMem(props.eventDrag);
  7431. this.renderEventResizeMem(props.eventResize);
  7432. };
  7433. View.prototype.destroy = function () {
  7434. _super.prototype.destroy.call(this);
  7435. this.renderDatesMem.unrender(); // should unrender everything else
  7436. };
  7437. // Sizing
  7438. // -----------------------------------------------------------------------------------------------------------------
  7439. View.prototype.updateSize = function (isResize, viewHeight, isAuto) {
  7440. var calendar = this.calendar;
  7441. if (isResize || // HACKS...
  7442. calendar.isViewUpdated ||
  7443. calendar.isDatesUpdated ||
  7444. calendar.isEventsUpdated) {
  7445. // sort of the catch-all sizing
  7446. // anything that might cause dimension changes
  7447. this.updateBaseSize(isResize, viewHeight, isAuto);
  7448. }
  7449. };
  7450. View.prototype.updateBaseSize = function (isResize, viewHeight, isAuto) {
  7451. };
  7452. // Date Rendering
  7453. // -----------------------------------------------------------------------------------------------------------------
  7454. View.prototype.renderDatesWrap = function (dateProfile) {
  7455. this.renderDates(dateProfile);
  7456. this.addScroll({
  7457. duration: createDuration(this.opt('scrollTime'))
  7458. });
  7459. this.startNowIndicator(dateProfile); // shouldn't render yet because updateSize will be called soon
  7460. };
  7461. View.prototype.unrenderDatesWrap = function () {
  7462. this.stopNowIndicator();
  7463. this.unrenderDates();
  7464. };
  7465. View.prototype.renderDates = function (dateProfile) { };
  7466. View.prototype.unrenderDates = function () { };
  7467. // Business Hours
  7468. // -----------------------------------------------------------------------------------------------------------------
  7469. View.prototype.renderBusinessHours = function (businessHours) { };
  7470. View.prototype.unrenderBusinessHours = function () { };
  7471. // Date Selection
  7472. // -----------------------------------------------------------------------------------------------------------------
  7473. View.prototype.renderDateSelectionWrap = function (selection) {
  7474. if (selection) {
  7475. this.renderDateSelection(selection);
  7476. }
  7477. };
  7478. View.prototype.unrenderDateSelectionWrap = function (selection) {
  7479. if (selection) {
  7480. this.unrenderDateSelection(selection);
  7481. }
  7482. };
  7483. View.prototype.renderDateSelection = function (selection) { };
  7484. View.prototype.unrenderDateSelection = function (selection) { };
  7485. // Event Rendering
  7486. // -----------------------------------------------------------------------------------------------------------------
  7487. View.prototype.renderEvents = function (eventStore) { };
  7488. View.prototype.unrenderEvents = function () { };
  7489. // util for subclasses
  7490. View.prototype.sliceEvents = function (eventStore, allDay) {
  7491. var props = this.props;
  7492. return sliceEventStore(eventStore, props.eventUiBases, props.dateProfile.activeRange, allDay ? this.nextDayThreshold : null).fg;
  7493. };
  7494. View.prototype.computeEventDraggable = function (eventDef, eventUi) {
  7495. var transformers = this.calendar.pluginSystem.hooks.isDraggableTransformers;
  7496. var val = eventUi.startEditable;
  7497. for (var _i = 0, transformers_1 = transformers; _i < transformers_1.length; _i++) {
  7498. var transformer = transformers_1[_i];
  7499. val = transformer(val, eventDef, eventUi, this);
  7500. }
  7501. return val;
  7502. };
  7503. View.prototype.computeEventStartResizable = function (eventDef, eventUi) {
  7504. return eventUi.durationEditable && this.opt('eventResizableFromStart');
  7505. };
  7506. View.prototype.computeEventEndResizable = function (eventDef, eventUi) {
  7507. return eventUi.durationEditable;
  7508. };
  7509. // Event Selection
  7510. // -----------------------------------------------------------------------------------------------------------------
  7511. View.prototype.renderEventSelectionWrap = function (instanceId) {
  7512. if (instanceId) {
  7513. this.renderEventSelection(instanceId);
  7514. }
  7515. };
  7516. View.prototype.unrenderEventSelectionWrap = function (instanceId) {
  7517. if (instanceId) {
  7518. this.unrenderEventSelection(instanceId);
  7519. }
  7520. };
  7521. View.prototype.renderEventSelection = function (instanceId) { };
  7522. View.prototype.unrenderEventSelection = function (instanceId) { };
  7523. // Event Drag
  7524. // -----------------------------------------------------------------------------------------------------------------
  7525. View.prototype.renderEventDragWrap = function (state) {
  7526. if (state) {
  7527. this.renderEventDrag(state);
  7528. }
  7529. };
  7530. View.prototype.unrenderEventDragWrap = function (state) {
  7531. if (state) {
  7532. this.unrenderEventDrag(state);
  7533. }
  7534. };
  7535. View.prototype.renderEventDrag = function (state) { };
  7536. View.prototype.unrenderEventDrag = function (state) { };
  7537. // Event Resize
  7538. // -----------------------------------------------------------------------------------------------------------------
  7539. View.prototype.renderEventResizeWrap = function (state) {
  7540. if (state) {
  7541. this.renderEventResize(state);
  7542. }
  7543. };
  7544. View.prototype.unrenderEventResizeWrap = function (state) {
  7545. if (state) {
  7546. this.unrenderEventResize(state);
  7547. }
  7548. };
  7549. View.prototype.renderEventResize = function (state) { };
  7550. View.prototype.unrenderEventResize = function (state) { };
  7551. /* Now Indicator
  7552. ------------------------------------------------------------------------------------------------------------------*/
  7553. // Immediately render the current time indicator and begins re-rendering it at an interval,
  7554. // which is defined by this.getNowIndicatorUnit().
  7555. // TODO: somehow do this for the current whole day's background too
  7556. View.prototype.startNowIndicator = function (dateProfile) {
  7557. var _this = this;
  7558. var dateEnv = this.dateEnv;
  7559. var unit;
  7560. var update;
  7561. var delay; // ms wait value
  7562. if (this.opt('nowIndicator')) {
  7563. unit = this.getNowIndicatorUnit(dateProfile);
  7564. if (unit) {
  7565. update = this.updateNowIndicator.bind(this);
  7566. this.initialNowDate = this.calendar.getNow();
  7567. this.initialNowQueriedMs = new Date().valueOf();
  7568. // wait until the beginning of the next interval
  7569. delay = dateEnv.add(dateEnv.startOf(this.initialNowDate, unit), createDuration(1, unit)).valueOf() - this.initialNowDate.valueOf();
  7570. // TODO: maybe always use setTimeout, waiting until start of next unit
  7571. this.nowIndicatorTimeoutID = setTimeout(function () {
  7572. _this.nowIndicatorTimeoutID = null;
  7573. update();
  7574. if (unit === 'second') {
  7575. delay = 1000; // every second
  7576. }
  7577. else {
  7578. delay = 1000 * 60; // otherwise, every minute
  7579. }
  7580. _this.nowIndicatorIntervalID = setInterval(update, delay); // update every interval
  7581. }, delay);
  7582. }
  7583. // rendering will be initiated in updateSize
  7584. }
  7585. };
  7586. // rerenders the now indicator, computing the new current time from the amount of time that has passed
  7587. // since the initial getNow call.
  7588. View.prototype.updateNowIndicator = function () {
  7589. if (this.props.dateProfile && // a way to determine if dates were rendered yet
  7590. this.initialNowDate // activated before?
  7591. ) {
  7592. this.unrenderNowIndicator(); // won't unrender if unnecessary
  7593. this.renderNowIndicator(addMs(this.initialNowDate, new Date().valueOf() - this.initialNowQueriedMs));
  7594. this.isNowIndicatorRendered = true;
  7595. }
  7596. };
  7597. // Immediately unrenders the view's current time indicator and stops any re-rendering timers.
  7598. // Won't cause side effects if indicator isn't rendered.
  7599. View.prototype.stopNowIndicator = function () {
  7600. if (this.isNowIndicatorRendered) {
  7601. if (this.nowIndicatorTimeoutID) {
  7602. clearTimeout(this.nowIndicatorTimeoutID);
  7603. this.nowIndicatorTimeoutID = null;
  7604. }
  7605. if (this.nowIndicatorIntervalID) {
  7606. clearInterval(this.nowIndicatorIntervalID);
  7607. this.nowIndicatorIntervalID = null;
  7608. }
  7609. this.unrenderNowIndicator();
  7610. this.isNowIndicatorRendered = false;
  7611. }
  7612. };
  7613. View.prototype.getNowIndicatorUnit = function (dateProfile) {
  7614. // subclasses should implement
  7615. };
  7616. // Renders a current time indicator at the given datetime
  7617. View.prototype.renderNowIndicator = function (date) {
  7618. // SUBCLASSES MUST PASS TO CHILDREN!
  7619. };
  7620. // Undoes the rendering actions from renderNowIndicator
  7621. View.prototype.unrenderNowIndicator = function () {
  7622. // SUBCLASSES MUST PASS TO CHILDREN!
  7623. };
  7624. /* Scroller
  7625. ------------------------------------------------------------------------------------------------------------------*/
  7626. View.prototype.addScroll = function (scroll) {
  7627. var queuedScroll = this.queuedScroll || (this.queuedScroll = {});
  7628. __assign(queuedScroll, scroll);
  7629. };
  7630. View.prototype.popScroll = function (isResize) {
  7631. this.applyQueuedScroll(isResize);
  7632. this.queuedScroll = null;
  7633. };
  7634. View.prototype.applyQueuedScroll = function (isResize) {
  7635. this.applyScroll(this.queuedScroll || {}, isResize);
  7636. };
  7637. View.prototype.queryScroll = function () {
  7638. var scroll = {};
  7639. if (this.props.dateProfile) { // dates rendered yet?
  7640. __assign(scroll, this.queryDateScroll());
  7641. }
  7642. return scroll;
  7643. };
  7644. View.prototype.applyScroll = function (scroll, isResize) {
  7645. var duration = scroll.duration;
  7646. if (duration != null) {
  7647. delete scroll.duration;
  7648. if (this.props.dateProfile) { // dates rendered yet?
  7649. __assign(scroll, this.computeDateScroll(duration));
  7650. }
  7651. }
  7652. if (this.props.dateProfile) { // dates rendered yet?
  7653. this.applyDateScroll(scroll);
  7654. }
  7655. };
  7656. View.prototype.computeDateScroll = function (duration) {
  7657. return {}; // subclasses must implement
  7658. };
  7659. View.prototype.queryDateScroll = function () {
  7660. return {}; // subclasses must implement
  7661. };
  7662. View.prototype.applyDateScroll = function (scroll) {
  7663. // subclasses must implement
  7664. };
  7665. // for API
  7666. View.prototype.scrollToDuration = function (duration) {
  7667. this.applyScroll({ duration: duration }, false);
  7668. };
  7669. return View;
  7670. }(DateComponent));
  7671. EmitterMixin.mixInto(View);
  7672. View.prototype.usesMinMaxTime = false;
  7673. View.prototype.dateProfileGeneratorClass = DateProfileGenerator;
  7674. var FgEventRenderer = /** @class */ (function () {
  7675. function FgEventRenderer(context) {
  7676. this.segs = [];
  7677. this.isSizeDirty = false;
  7678. this.context = context;
  7679. }
  7680. FgEventRenderer.prototype.renderSegs = function (segs, mirrorInfo) {
  7681. this.rangeUpdated(); // called too frequently :(
  7682. // render an `.el` on each seg
  7683. // returns a subset of the segs. segs that were actually rendered
  7684. segs = this.renderSegEls(segs, mirrorInfo);
  7685. this.segs = segs;
  7686. this.attachSegs(segs, mirrorInfo);
  7687. this.isSizeDirty = true;
  7688. this.context.view.triggerRenderedSegs(this.segs, Boolean(mirrorInfo));
  7689. };
  7690. FgEventRenderer.prototype.unrender = function (_segs, mirrorInfo) {
  7691. this.context.view.triggerWillRemoveSegs(this.segs, Boolean(mirrorInfo));
  7692. this.detachSegs(this.segs);
  7693. this.segs = [];
  7694. };
  7695. // Updates values that rely on options and also relate to range
  7696. FgEventRenderer.prototype.rangeUpdated = function () {
  7697. var options = this.context.options;
  7698. var displayEventTime;
  7699. var displayEventEnd;
  7700. this.eventTimeFormat = createFormatter(options.eventTimeFormat || this.computeEventTimeFormat(), options.defaultRangeSeparator);
  7701. displayEventTime = options.displayEventTime;
  7702. if (displayEventTime == null) {
  7703. displayEventTime = this.computeDisplayEventTime(); // might be based off of range
  7704. }
  7705. displayEventEnd = options.displayEventEnd;
  7706. if (displayEventEnd == null) {
  7707. displayEventEnd = this.computeDisplayEventEnd(); // might be based off of range
  7708. }
  7709. this.displayEventTime = displayEventTime;
  7710. this.displayEventEnd = displayEventEnd;
  7711. };
  7712. // Renders and assigns an `el` property for each foreground event segment.
  7713. // Only returns segments that successfully rendered.
  7714. FgEventRenderer.prototype.renderSegEls = function (segs, mirrorInfo) {
  7715. var html = '';
  7716. var i;
  7717. if (segs.length) { // don't build an empty html string
  7718. // build a large concatenation of event segment HTML
  7719. for (i = 0; i < segs.length; i++) {
  7720. html += this.renderSegHtml(segs[i], mirrorInfo);
  7721. }
  7722. // Grab individual elements from the combined HTML string. Use each as the default rendering.
  7723. // Then, compute the 'el' for each segment. An el might be null if the eventRender callback returned false.
  7724. htmlToElements(html).forEach(function (el, i) {
  7725. var seg = segs[i];
  7726. if (el) {
  7727. seg.el = el;
  7728. }
  7729. });
  7730. segs = filterSegsViaEls(this.context.view, segs, Boolean(mirrorInfo));
  7731. }
  7732. return segs;
  7733. };
  7734. // Generic utility for generating the HTML classNames for an event segment's element
  7735. FgEventRenderer.prototype.getSegClasses = function (seg, isDraggable, isResizable, mirrorInfo) {
  7736. var classes = [
  7737. 'fc-event',
  7738. seg.isStart ? 'fc-start' : 'fc-not-start',
  7739. seg.isEnd ? 'fc-end' : 'fc-not-end'
  7740. ].concat(seg.eventRange.ui.classNames);
  7741. if (isDraggable) {
  7742. classes.push('fc-draggable');
  7743. }
  7744. if (isResizable) {
  7745. classes.push('fc-resizable');
  7746. }
  7747. if (mirrorInfo) {
  7748. classes.push('fc-mirror');
  7749. if (mirrorInfo.isDragging) {
  7750. classes.push('fc-dragging');
  7751. }
  7752. if (mirrorInfo.isResizing) {
  7753. classes.push('fc-resizing');
  7754. }
  7755. }
  7756. return classes;
  7757. };
  7758. // Compute the text that should be displayed on an event's element.
  7759. // `range` can be the Event object itself, or something range-like, with at least a `start`.
  7760. // If event times are disabled, or the event has no time, will return a blank string.
  7761. // If not specified, formatter will default to the eventTimeFormat setting,
  7762. // and displayEnd will default to the displayEventEnd setting.
  7763. FgEventRenderer.prototype.getTimeText = function (eventRange, formatter, displayEnd) {
  7764. var def = eventRange.def, instance = eventRange.instance;
  7765. return this._getTimeText(instance.range.start, def.hasEnd ? instance.range.end : null, def.allDay, formatter, displayEnd, instance.forcedStartTzo, instance.forcedEndTzo);
  7766. };
  7767. FgEventRenderer.prototype._getTimeText = function (start, end, allDay, formatter, displayEnd, forcedStartTzo, forcedEndTzo) {
  7768. var dateEnv = this.context.dateEnv;
  7769. if (formatter == null) {
  7770. formatter = this.eventTimeFormat;
  7771. }
  7772. if (displayEnd == null) {
  7773. displayEnd = this.displayEventEnd;
  7774. }
  7775. if (this.displayEventTime && !allDay) {
  7776. if (displayEnd && end) {
  7777. return dateEnv.formatRange(start, end, formatter, {
  7778. forcedStartTzo: forcedStartTzo,
  7779. forcedEndTzo: forcedEndTzo
  7780. });
  7781. }
  7782. else {
  7783. return dateEnv.format(start, formatter, {
  7784. forcedTzo: forcedStartTzo
  7785. });
  7786. }
  7787. }
  7788. return '';
  7789. };
  7790. FgEventRenderer.prototype.computeEventTimeFormat = function () {
  7791. return {
  7792. hour: 'numeric',
  7793. minute: '2-digit',
  7794. omitZeroMinute: true
  7795. };
  7796. };
  7797. FgEventRenderer.prototype.computeDisplayEventTime = function () {
  7798. return true;
  7799. };
  7800. FgEventRenderer.prototype.computeDisplayEventEnd = function () {
  7801. return true;
  7802. };
  7803. // Utility for generating event skin-related CSS properties
  7804. FgEventRenderer.prototype.getSkinCss = function (ui) {
  7805. return {
  7806. 'background-color': ui.backgroundColor,
  7807. 'border-color': ui.borderColor,
  7808. color: ui.textColor
  7809. };
  7810. };
  7811. FgEventRenderer.prototype.sortEventSegs = function (segs) {
  7812. var specs = this.context.view.eventOrderSpecs;
  7813. var objs = segs.map(buildSegCompareObj);
  7814. objs.sort(function (obj0, obj1) {
  7815. return compareByFieldSpecs(obj0, obj1, specs);
  7816. });
  7817. return objs.map(function (c) {
  7818. return c._seg;
  7819. });
  7820. };
  7821. FgEventRenderer.prototype.computeSizes = function (force) {
  7822. if (force || this.isSizeDirty) {
  7823. this.computeSegSizes(this.segs);
  7824. }
  7825. };
  7826. FgEventRenderer.prototype.assignSizes = function (force) {
  7827. if (force || this.isSizeDirty) {
  7828. this.assignSegSizes(this.segs);
  7829. this.isSizeDirty = false;
  7830. }
  7831. };
  7832. FgEventRenderer.prototype.computeSegSizes = function (segs) {
  7833. };
  7834. FgEventRenderer.prototype.assignSegSizes = function (segs) {
  7835. };
  7836. // Manipulation on rendered segs
  7837. FgEventRenderer.prototype.hideByHash = function (hash) {
  7838. if (hash) {
  7839. for (var _i = 0, _a = this.segs; _i < _a.length; _i++) {
  7840. var seg = _a[_i];
  7841. if (hash[seg.eventRange.instance.instanceId]) {
  7842. seg.el.style.visibility = 'hidden';
  7843. }
  7844. }
  7845. }
  7846. };
  7847. FgEventRenderer.prototype.showByHash = function (hash) {
  7848. if (hash) {
  7849. for (var _i = 0, _a = this.segs; _i < _a.length; _i++) {
  7850. var seg = _a[_i];
  7851. if (hash[seg.eventRange.instance.instanceId]) {
  7852. seg.el.style.visibility = '';
  7853. }
  7854. }
  7855. }
  7856. };
  7857. FgEventRenderer.prototype.selectByInstanceId = function (instanceId) {
  7858. if (instanceId) {
  7859. for (var _i = 0, _a = this.segs; _i < _a.length; _i++) {
  7860. var seg = _a[_i];
  7861. var eventInstance = seg.eventRange.instance;
  7862. if (eventInstance && eventInstance.instanceId === instanceId &&
  7863. seg.el // necessary?
  7864. ) {
  7865. seg.el.classList.add('fc-selected');
  7866. }
  7867. }
  7868. }
  7869. };
  7870. FgEventRenderer.prototype.unselectByInstanceId = function (instanceId) {
  7871. if (instanceId) {
  7872. for (var _i = 0, _a = this.segs; _i < _a.length; _i++) {
  7873. var seg = _a[_i];
  7874. if (seg.el) { // necessary?
  7875. seg.el.classList.remove('fc-selected');
  7876. }
  7877. }
  7878. }
  7879. };
  7880. return FgEventRenderer;
  7881. }());
  7882. // returns a object with all primitive props that can be compared
  7883. function buildSegCompareObj(seg) {
  7884. var eventDef = seg.eventRange.def;
  7885. var range = seg.eventRange.instance.range;
  7886. var start = range.start ? range.start.valueOf() : 0; // TODO: better support for open-range events
  7887. var end = range.end ? range.end.valueOf() : 0; // "
  7888. return __assign({}, eventDef.extendedProps, eventDef, { id: eventDef.publicId, start: start,
  7889. end: end, duration: end - start, allDay: Number(eventDef.allDay), _seg: seg // for later retrieval
  7890. });
  7891. }
  7892. var FillRenderer = /** @class */ (function () {
  7893. function FillRenderer(context) {
  7894. this.fillSegTag = 'div';
  7895. this.dirtySizeFlags = {};
  7896. this.context = context;
  7897. this.containerElsByType = {};
  7898. this.segsByType = {};
  7899. }
  7900. FillRenderer.prototype.getSegsByType = function (type) {
  7901. return this.segsByType[type] || [];
  7902. };
  7903. FillRenderer.prototype.renderSegs = function (type, segs) {
  7904. var _a;
  7905. var renderedSegs = this.renderSegEls(type, segs); // assignes `.el` to each seg. returns successfully rendered segs
  7906. var containerEls = this.attachSegs(type, renderedSegs);
  7907. if (containerEls) {
  7908. (_a = (this.containerElsByType[type] || (this.containerElsByType[type] = []))).push.apply(_a, containerEls);
  7909. }
  7910. this.segsByType[type] = renderedSegs;
  7911. if (type === 'bgEvent') {
  7912. this.context.view.triggerRenderedSegs(renderedSegs, false); // isMirror=false
  7913. }
  7914. this.dirtySizeFlags[type] = true;
  7915. };
  7916. // Unrenders a specific type of fill that is currently rendered on the grid
  7917. FillRenderer.prototype.unrender = function (type) {
  7918. var segs = this.segsByType[type];
  7919. if (segs) {
  7920. if (type === 'bgEvent') {
  7921. this.context.view.triggerWillRemoveSegs(segs, false); // isMirror=false
  7922. }
  7923. this.detachSegs(type, segs);
  7924. }
  7925. };
  7926. // Renders and assigns an `el` property for each fill segment. Generic enough to work with different types.
  7927. // Only returns segments that successfully rendered.
  7928. FillRenderer.prototype.renderSegEls = function (type, segs) {
  7929. var _this = this;
  7930. var html = '';
  7931. var i;
  7932. if (segs.length) {
  7933. // build a large concatenation of segment HTML
  7934. for (i = 0; i < segs.length; i++) {
  7935. html += this.renderSegHtml(type, segs[i]);
  7936. }
  7937. // Grab individual elements from the combined HTML string. Use each as the default rendering.
  7938. // Then, compute the 'el' for each segment.
  7939. htmlToElements(html).forEach(function (el, i) {
  7940. var seg = segs[i];
  7941. if (el) {
  7942. seg.el = el;
  7943. }
  7944. });
  7945. if (type === 'bgEvent') {
  7946. segs = filterSegsViaEls(this.context.view, segs, false // isMirror. background events can never be mirror elements
  7947. );
  7948. }
  7949. // correct element type? (would be bad if a non-TD were inserted into a table for example)
  7950. segs = segs.filter(function (seg) {
  7951. return elementMatches(seg.el, _this.fillSegTag);
  7952. });
  7953. }
  7954. return segs;
  7955. };
  7956. // Builds the HTML needed for one fill segment. Generic enough to work with different types.
  7957. FillRenderer.prototype.renderSegHtml = function (type, seg) {
  7958. var css = null;
  7959. var classNames = [];
  7960. if (type !== 'highlight' && type !== 'businessHours') {
  7961. css = {
  7962. 'background-color': seg.eventRange.ui.backgroundColor
  7963. };
  7964. }
  7965. if (type !== 'highlight') {
  7966. classNames = classNames.concat(seg.eventRange.ui.classNames);
  7967. }
  7968. if (type === 'businessHours') {
  7969. classNames.push('fc-bgevent');
  7970. }
  7971. else {
  7972. classNames.push('fc-' + type.toLowerCase());
  7973. }
  7974. return '<' + this.fillSegTag +
  7975. (classNames.length ? ' class="' + classNames.join(' ') + '"' : '') +
  7976. (css ? ' style="' + cssToStr(css) + '"' : '') +
  7977. '></' + this.fillSegTag + '>';
  7978. };
  7979. FillRenderer.prototype.detachSegs = function (type, segs) {
  7980. var containerEls = this.containerElsByType[type];
  7981. if (containerEls) {
  7982. containerEls.forEach(removeElement);
  7983. delete this.containerElsByType[type];
  7984. }
  7985. };
  7986. FillRenderer.prototype.computeSizes = function (force) {
  7987. for (var type in this.segsByType) {
  7988. if (force || this.dirtySizeFlags[type]) {
  7989. this.computeSegSizes(this.segsByType[type]);
  7990. }
  7991. }
  7992. };
  7993. FillRenderer.prototype.assignSizes = function (force) {
  7994. for (var type in this.segsByType) {
  7995. if (force || this.dirtySizeFlags[type]) {
  7996. this.assignSegSizes(this.segsByType[type]);
  7997. }
  7998. }
  7999. this.dirtySizeFlags = {};
  8000. };
  8001. FillRenderer.prototype.computeSegSizes = function (segs) {
  8002. };
  8003. FillRenderer.prototype.assignSegSizes = function (segs) {
  8004. };
  8005. return FillRenderer;
  8006. }());
  8007. var NamedTimeZoneImpl = /** @class */ (function () {
  8008. function NamedTimeZoneImpl(timeZoneName) {
  8009. this.timeZoneName = timeZoneName;
  8010. }
  8011. return NamedTimeZoneImpl;
  8012. }());
  8013. /*
  8014. An abstraction for a dragging interaction originating on an event.
  8015. Does higher-level things than PointerDragger, such as possibly:
  8016. - a "mirror" that moves with the pointer
  8017. - a minimum number of pixels or other criteria for a true drag to begin
  8018. subclasses must emit:
  8019. - pointerdown
  8020. - dragstart
  8021. - dragmove
  8022. - pointerup
  8023. - dragend
  8024. */
  8025. var ElementDragging = /** @class */ (function () {
  8026. function ElementDragging(el) {
  8027. this.emitter = new EmitterMixin();
  8028. }
  8029. ElementDragging.prototype.destroy = function () {
  8030. };
  8031. ElementDragging.prototype.setMirrorIsVisible = function (bool) {
  8032. // optional if subclass doesn't want to support a mirror
  8033. };
  8034. ElementDragging.prototype.setMirrorNeedsRevert = function (bool) {
  8035. // optional if subclass doesn't want to support a mirror
  8036. };
  8037. ElementDragging.prototype.setAutoScrollEnabled = function (bool) {
  8038. // optional
  8039. };
  8040. return ElementDragging;
  8041. }());
  8042. function formatDate(dateInput, settings) {
  8043. if (settings === void 0) { settings = {}; }
  8044. var dateEnv = buildDateEnv$1(settings);
  8045. var formatter = createFormatter(settings);
  8046. var dateMeta = dateEnv.createMarkerMeta(dateInput);
  8047. if (!dateMeta) { // TODO: warning?
  8048. return '';
  8049. }
  8050. return dateEnv.format(dateMeta.marker, formatter, {
  8051. forcedTzo: dateMeta.forcedTzo
  8052. });
  8053. }
  8054. function formatRange(startInput, endInput, settings // mixture of env and formatter settings
  8055. ) {
  8056. var dateEnv = buildDateEnv$1(typeof settings === 'object' && settings ? settings : {}); // pass in if non-null object
  8057. var formatter = createFormatter(settings, globalDefaults.defaultRangeSeparator);
  8058. var startMeta = dateEnv.createMarkerMeta(startInput);
  8059. var endMeta = dateEnv.createMarkerMeta(endInput);
  8060. if (!startMeta || !endMeta) { // TODO: warning?
  8061. return '';
  8062. }
  8063. return dateEnv.formatRange(startMeta.marker, endMeta.marker, formatter, {
  8064. forcedStartTzo: startMeta.forcedTzo,
  8065. forcedEndTzo: endMeta.forcedTzo,
  8066. isEndExclusive: settings.isEndExclusive
  8067. });
  8068. }
  8069. // TODO: more DRY and optimized
  8070. function buildDateEnv$1(settings) {
  8071. var locale = buildLocale(settings.locale || 'en', parseRawLocales([]).map); // TODO: don't hardcode 'en' everywhere
  8072. // ensure required settings
  8073. settings = __assign({ timeZone: globalDefaults.timeZone, calendarSystem: 'gregory' }, settings, { locale: locale });
  8074. return new DateEnv(settings);
  8075. }
  8076. var DRAG_META_PROPS = {
  8077. startTime: createDuration,
  8078. duration: createDuration,
  8079. create: Boolean,
  8080. sourceId: String
  8081. };
  8082. var DRAG_META_DEFAULTS = {
  8083. create: true
  8084. };
  8085. function parseDragMeta(raw) {
  8086. var leftoverProps = {};
  8087. var refined = refineProps(raw, DRAG_META_PROPS, DRAG_META_DEFAULTS, leftoverProps);
  8088. refined.leftoverProps = leftoverProps;
  8089. return refined;
  8090. }
  8091. // Computes a default column header formatting string if `colFormat` is not explicitly defined
  8092. function computeFallbackHeaderFormat(datesRepDistinctDays, dayCnt) {
  8093. // if more than one week row, or if there are a lot of columns with not much space,
  8094. // put just the day numbers will be in each cell
  8095. if (!datesRepDistinctDays || dayCnt > 10) {
  8096. return { weekday: 'short' }; // "Sat"
  8097. }
  8098. else if (dayCnt > 1) {
  8099. return { weekday: 'short', month: 'numeric', day: 'numeric', omitCommas: true }; // "Sat 11/12"
  8100. }
  8101. else {
  8102. return { weekday: 'long' }; // "Saturday"
  8103. }
  8104. }
  8105. function renderDateCell(dateMarker, dateProfile, datesRepDistinctDays, colCnt, colHeadFormat, context, colspan, otherAttrs) {
  8106. var view = context.view, dateEnv = context.dateEnv, theme = context.theme, options = context.options;
  8107. var isDateValid = rangeContainsMarker(dateProfile.activeRange, dateMarker); // TODO: called too frequently. cache somehow.
  8108. var classNames = [
  8109. 'fc-day-header',
  8110. theme.getClass('widgetHeader')
  8111. ];
  8112. var innerHtml;
  8113. if (typeof options.columnHeaderHtml === 'function') {
  8114. innerHtml = options.columnHeaderHtml(dateEnv.toDate(dateMarker));
  8115. }
  8116. else if (typeof options.columnHeaderText === 'function') {
  8117. innerHtml = htmlEscape(options.columnHeaderText(dateEnv.toDate(dateMarker)));
  8118. }
  8119. else {
  8120. innerHtml = htmlEscape(dateEnv.format(dateMarker, colHeadFormat));
  8121. }
  8122. // if only one row of days, the classNames on the header can represent the specific days beneath
  8123. if (datesRepDistinctDays) {
  8124. classNames = classNames.concat(
  8125. // includes the day-of-week class
  8126. // noThemeHighlight=true (don't highlight the header)
  8127. getDayClasses(dateMarker, dateProfile, context, true));
  8128. }
  8129. else {
  8130. classNames.push('fc-' + DAY_IDS[dateMarker.getUTCDay()]); // only add the day-of-week class
  8131. }
  8132. return '' +
  8133. '<th class="' + classNames.join(' ') + '"' +
  8134. ((isDateValid && datesRepDistinctDays) ?
  8135. ' data-date="' + dateEnv.formatIso(dateMarker, { omitTime: true }) + '"' :
  8136. '') +
  8137. (colspan > 1 ?
  8138. ' colspan="' + colspan + '"' :
  8139. '') +
  8140. (otherAttrs ?
  8141. ' ' + otherAttrs :
  8142. '') +
  8143. '>' +
  8144. (isDateValid ?
  8145. // don't make a link if the heading could represent multiple days, or if there's only one day (forceOff)
  8146. buildGotoAnchorHtml(view, { date: dateMarker, forceOff: !datesRepDistinctDays || colCnt === 1 }, innerHtml) :
  8147. // if not valid, display text, but no link
  8148. innerHtml) +
  8149. '</th>';
  8150. }
  8151. var DayHeader = /** @class */ (function (_super) {
  8152. __extends(DayHeader, _super);
  8153. function DayHeader(context, parentEl) {
  8154. var _this = _super.call(this, context) || this;
  8155. parentEl.innerHTML = ''; // because might be nbsp
  8156. parentEl.appendChild(_this.el = htmlToElement('<div class="fc-row ' + _this.theme.getClass('headerRow') + '">' +
  8157. '<table class="' + _this.theme.getClass('tableGrid') + '">' +
  8158. '<thead></thead>' +
  8159. '</table>' +
  8160. '</div>'));
  8161. _this.thead = _this.el.querySelector('thead');
  8162. return _this;
  8163. }
  8164. DayHeader.prototype.destroy = function () {
  8165. removeElement(this.el);
  8166. };
  8167. DayHeader.prototype.render = function (props) {
  8168. var dates = props.dates, datesRepDistinctDays = props.datesRepDistinctDays;
  8169. var parts = [];
  8170. if (props.renderIntroHtml) {
  8171. parts.push(props.renderIntroHtml());
  8172. }
  8173. var colHeadFormat = createFormatter(this.opt('columnHeaderFormat') ||
  8174. computeFallbackHeaderFormat(datesRepDistinctDays, dates.length));
  8175. for (var _i = 0, dates_1 = dates; _i < dates_1.length; _i++) {
  8176. var date = dates_1[_i];
  8177. parts.push(renderDateCell(date, props.dateProfile, datesRepDistinctDays, dates.length, colHeadFormat, this.context));
  8178. }
  8179. if (this.isRtl) {
  8180. parts.reverse();
  8181. }
  8182. this.thead.innerHTML = '<tr>' + parts.join('') + '</tr>';
  8183. };
  8184. return DayHeader;
  8185. }(Component));
  8186. var DaySeries = /** @class */ (function () {
  8187. function DaySeries(range, dateProfileGenerator) {
  8188. var date = range.start;
  8189. var end = range.end;
  8190. var indices = [];
  8191. var dates = [];
  8192. var dayIndex = -1;
  8193. while (date < end) { // loop each day from start to end
  8194. if (dateProfileGenerator.isHiddenDay(date)) {
  8195. indices.push(dayIndex + 0.5); // mark that it's between indices
  8196. }
  8197. else {
  8198. dayIndex++;
  8199. indices.push(dayIndex);
  8200. dates.push(date);
  8201. }
  8202. date = addDays(date, 1);
  8203. }
  8204. this.dates = dates;
  8205. this.indices = indices;
  8206. this.cnt = dates.length;
  8207. }
  8208. DaySeries.prototype.sliceRange = function (range) {
  8209. var firstIndex = this.getDateDayIndex(range.start); // inclusive first index
  8210. var lastIndex = this.getDateDayIndex(addDays(range.end, -1)); // inclusive last index
  8211. var clippedFirstIndex = Math.max(0, firstIndex);
  8212. var clippedLastIndex = Math.min(this.cnt - 1, lastIndex);
  8213. // deal with in-between indices
  8214. clippedFirstIndex = Math.ceil(clippedFirstIndex); // in-between starts round to next cell
  8215. clippedLastIndex = Math.floor(clippedLastIndex); // in-between ends round to prev cell
  8216. if (clippedFirstIndex <= clippedLastIndex) {
  8217. return {
  8218. firstIndex: clippedFirstIndex,
  8219. lastIndex: clippedLastIndex,
  8220. isStart: firstIndex === clippedFirstIndex,
  8221. isEnd: lastIndex === clippedLastIndex
  8222. };
  8223. }
  8224. else {
  8225. return null;
  8226. }
  8227. };
  8228. // Given a date, returns its chronolocial cell-index from the first cell of the grid.
  8229. // If the date lies between cells (because of hiddenDays), returns a floating-point value between offsets.
  8230. // If before the first offset, returns a negative number.
  8231. // If after the last offset, returns an offset past the last cell offset.
  8232. // Only works for *start* dates of cells. Will not work for exclusive end dates for cells.
  8233. DaySeries.prototype.getDateDayIndex = function (date) {
  8234. var indices = this.indices;
  8235. var dayOffset = Math.floor(diffDays(this.dates[0], date));
  8236. if (dayOffset < 0) {
  8237. return indices[0] - 1;
  8238. }
  8239. else if (dayOffset >= indices.length) {
  8240. return indices[indices.length - 1] + 1;
  8241. }
  8242. else {
  8243. return indices[dayOffset];
  8244. }
  8245. };
  8246. return DaySeries;
  8247. }());
  8248. var DayTable = /** @class */ (function () {
  8249. function DayTable(daySeries, breakOnWeeks) {
  8250. var dates = daySeries.dates;
  8251. var daysPerRow;
  8252. var firstDay;
  8253. var rowCnt;
  8254. if (breakOnWeeks) {
  8255. // count columns until the day-of-week repeats
  8256. firstDay = dates[0].getUTCDay();
  8257. for (daysPerRow = 1; daysPerRow < dates.length; daysPerRow++) {
  8258. if (dates[daysPerRow].getUTCDay() === firstDay) {
  8259. break;
  8260. }
  8261. }
  8262. rowCnt = Math.ceil(dates.length / daysPerRow);
  8263. }
  8264. else {
  8265. rowCnt = 1;
  8266. daysPerRow = dates.length;
  8267. }
  8268. this.rowCnt = rowCnt;
  8269. this.colCnt = daysPerRow;
  8270. this.daySeries = daySeries;
  8271. this.cells = this.buildCells();
  8272. this.headerDates = this.buildHeaderDates();
  8273. }
  8274. DayTable.prototype.buildCells = function () {
  8275. var rows = [];
  8276. for (var row = 0; row < this.rowCnt; row++) {
  8277. var cells = [];
  8278. for (var col = 0; col < this.colCnt; col++) {
  8279. cells.push(this.buildCell(row, col));
  8280. }
  8281. rows.push(cells);
  8282. }
  8283. return rows;
  8284. };
  8285. DayTable.prototype.buildCell = function (row, col) {
  8286. return {
  8287. date: this.daySeries.dates[row * this.colCnt + col]
  8288. };
  8289. };
  8290. DayTable.prototype.buildHeaderDates = function () {
  8291. var dates = [];
  8292. for (var col = 0; col < this.colCnt; col++) {
  8293. dates.push(this.cells[0][col].date);
  8294. }
  8295. return dates;
  8296. };
  8297. DayTable.prototype.sliceRange = function (range) {
  8298. var colCnt = this.colCnt;
  8299. var seriesSeg = this.daySeries.sliceRange(range);
  8300. var segs = [];
  8301. if (seriesSeg) {
  8302. var firstIndex = seriesSeg.firstIndex, lastIndex = seriesSeg.lastIndex;
  8303. var index = firstIndex;
  8304. while (index <= lastIndex) {
  8305. var row = Math.floor(index / colCnt);
  8306. var nextIndex = Math.min((row + 1) * colCnt, lastIndex + 1);
  8307. segs.push({
  8308. row: row,
  8309. firstCol: index % colCnt,
  8310. lastCol: (nextIndex - 1) % colCnt,
  8311. isStart: seriesSeg.isStart && index === firstIndex,
  8312. isEnd: seriesSeg.isEnd && (nextIndex - 1) === lastIndex
  8313. });
  8314. index = nextIndex;
  8315. }
  8316. }
  8317. return segs;
  8318. };
  8319. return DayTable;
  8320. }());
  8321. var Slicer = /** @class */ (function () {
  8322. function Slicer() {
  8323. this.sliceBusinessHours = memoize(this._sliceBusinessHours);
  8324. this.sliceDateSelection = memoize(this._sliceDateSpan);
  8325. this.sliceEventStore = memoize(this._sliceEventStore);
  8326. this.sliceEventDrag = memoize(this._sliceInteraction);
  8327. this.sliceEventResize = memoize(this._sliceInteraction);
  8328. }
  8329. Slicer.prototype.sliceProps = function (props, dateProfile, nextDayThreshold, component) {
  8330. var extraArgs = [];
  8331. for (var _i = 4; _i < arguments.length; _i++) {
  8332. extraArgs[_i - 4] = arguments[_i];
  8333. }
  8334. var eventUiBases = props.eventUiBases;
  8335. var eventSegs = this.sliceEventStore.apply(this, [props.eventStore, eventUiBases, dateProfile, nextDayThreshold, component].concat(extraArgs));
  8336. return {
  8337. dateSelectionSegs: this.sliceDateSelection.apply(this, [props.dateSelection, eventUiBases, component].concat(extraArgs)),
  8338. businessHourSegs: this.sliceBusinessHours.apply(this, [props.businessHours, dateProfile, nextDayThreshold, component].concat(extraArgs)),
  8339. fgEventSegs: eventSegs.fg,
  8340. bgEventSegs: eventSegs.bg,
  8341. eventDrag: this.sliceEventDrag.apply(this, [props.eventDrag, eventUiBases, dateProfile, nextDayThreshold, component].concat(extraArgs)),
  8342. eventResize: this.sliceEventResize.apply(this, [props.eventResize, eventUiBases, dateProfile, nextDayThreshold, component].concat(extraArgs)),
  8343. eventSelection: props.eventSelection
  8344. }; // TODO: give interactionSegs?
  8345. };
  8346. Slicer.prototype.sliceNowDate = function (// does not memoize
  8347. date, component) {
  8348. var extraArgs = [];
  8349. for (var _i = 2; _i < arguments.length; _i++) {
  8350. extraArgs[_i - 2] = arguments[_i];
  8351. }
  8352. return this._sliceDateSpan.apply(this, [{ range: { start: date, end: addMs(date, 1) }, allDay: false },
  8353. {},
  8354. component].concat(extraArgs));
  8355. };
  8356. Slicer.prototype._sliceBusinessHours = function (businessHours, dateProfile, nextDayThreshold, component) {
  8357. var extraArgs = [];
  8358. for (var _i = 4; _i < arguments.length; _i++) {
  8359. extraArgs[_i - 4] = arguments[_i];
  8360. }
  8361. if (!businessHours) {
  8362. return [];
  8363. }
  8364. return this._sliceEventStore.apply(this, [expandRecurring(businessHours, computeActiveRange(dateProfile, Boolean(nextDayThreshold)), component.calendar),
  8365. {},
  8366. dateProfile,
  8367. nextDayThreshold,
  8368. component].concat(extraArgs)).bg;
  8369. };
  8370. Slicer.prototype._sliceEventStore = function (eventStore, eventUiBases, dateProfile, nextDayThreshold, component) {
  8371. var extraArgs = [];
  8372. for (var _i = 5; _i < arguments.length; _i++) {
  8373. extraArgs[_i - 5] = arguments[_i];
  8374. }
  8375. if (eventStore) {
  8376. var rangeRes = sliceEventStore(eventStore, eventUiBases, computeActiveRange(dateProfile, Boolean(nextDayThreshold)), nextDayThreshold);
  8377. return {
  8378. bg: this.sliceEventRanges(rangeRes.bg, component, extraArgs),
  8379. fg: this.sliceEventRanges(rangeRes.fg, component, extraArgs)
  8380. };
  8381. }
  8382. else {
  8383. return { bg: [], fg: [] };
  8384. }
  8385. };
  8386. Slicer.prototype._sliceInteraction = function (interaction, eventUiBases, dateProfile, nextDayThreshold, component) {
  8387. var extraArgs = [];
  8388. for (var _i = 5; _i < arguments.length; _i++) {
  8389. extraArgs[_i - 5] = arguments[_i];
  8390. }
  8391. if (!interaction) {
  8392. return null;
  8393. }
  8394. var rangeRes = sliceEventStore(interaction.mutatedEvents, eventUiBases, computeActiveRange(dateProfile, Boolean(nextDayThreshold)), nextDayThreshold);
  8395. return {
  8396. segs: this.sliceEventRanges(rangeRes.fg, component, extraArgs),
  8397. affectedInstances: interaction.affectedEvents.instances,
  8398. isEvent: interaction.isEvent,
  8399. sourceSeg: interaction.origSeg
  8400. };
  8401. };
  8402. Slicer.prototype._sliceDateSpan = function (dateSpan, eventUiBases, component) {
  8403. var extraArgs = [];
  8404. for (var _i = 3; _i < arguments.length; _i++) {
  8405. extraArgs[_i - 3] = arguments[_i];
  8406. }
  8407. if (!dateSpan) {
  8408. return [];
  8409. }
  8410. var eventRange = fabricateEventRange(dateSpan, eventUiBases, component.calendar);
  8411. var segs = this.sliceRange.apply(this, [dateSpan.range].concat(extraArgs));
  8412. for (var _a = 0, segs_1 = segs; _a < segs_1.length; _a++) {
  8413. var seg = segs_1[_a];
  8414. seg.component = component;
  8415. seg.eventRange = eventRange;
  8416. }
  8417. return segs;
  8418. };
  8419. /*
  8420. "complete" seg means it has component and eventRange
  8421. */
  8422. Slicer.prototype.sliceEventRanges = function (eventRanges, component, // TODO: kill
  8423. extraArgs) {
  8424. var segs = [];
  8425. for (var _i = 0, eventRanges_1 = eventRanges; _i < eventRanges_1.length; _i++) {
  8426. var eventRange = eventRanges_1[_i];
  8427. segs.push.apply(segs, this.sliceEventRange(eventRange, component, extraArgs));
  8428. }
  8429. return segs;
  8430. };
  8431. /*
  8432. "complete" seg means it has component and eventRange
  8433. */
  8434. Slicer.prototype.sliceEventRange = function (eventRange, component, // TODO: kill
  8435. extraArgs) {
  8436. var segs = this.sliceRange.apply(this, [eventRange.range].concat(extraArgs));
  8437. for (var _i = 0, segs_2 = segs; _i < segs_2.length; _i++) {
  8438. var seg = segs_2[_i];
  8439. seg.component = component;
  8440. seg.eventRange = eventRange;
  8441. seg.isStart = eventRange.isStart && seg.isStart;
  8442. seg.isEnd = eventRange.isEnd && seg.isEnd;
  8443. }
  8444. return segs;
  8445. };
  8446. return Slicer;
  8447. }());
  8448. /*
  8449. for incorporating minTime/maxTime if appropriate
  8450. TODO: should be part of DateProfile!
  8451. TimelineDateProfile already does this btw
  8452. */
  8453. function computeActiveRange(dateProfile, isComponentAllDay) {
  8454. var range = dateProfile.activeRange;
  8455. if (isComponentAllDay) {
  8456. return range;
  8457. }
  8458. return {
  8459. start: addMs(range.start, dateProfile.minTime.milliseconds),
  8460. end: addMs(range.end, dateProfile.maxTime.milliseconds - 864e5) // 864e5 = ms in a day
  8461. };
  8462. }
  8463. // exports
  8464. // --------------------------------------------------------------------------------------------------
  8465. var version = '4.3.1';
  8466. export { Calendar, Component, 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, 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 };