internal-common.js 290 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487
  1. import * as preact from 'preact';
  2. import { Component, createElement, isValidElement, Fragment } from 'preact';
  3. import { createPortal } from 'preact/compat';
  4. const styleTexts = [];
  5. const styleEls = new Map();
  6. function injectStyles(styleText) {
  7. styleTexts.push(styleText);
  8. styleEls.forEach((styleEl) => {
  9. appendStylesTo(styleEl, styleText);
  10. });
  11. }
  12. function ensureElHasStyles(el) {
  13. if (el.isConnected && // sometimes true if SSR system simulates DOM
  14. el.getRootNode // sometimes undefined if SSR system simulates DOM
  15. ) {
  16. registerStylesRoot(el.getRootNode());
  17. }
  18. }
  19. function registerStylesRoot(rootNode) {
  20. let styleEl = styleEls.get(rootNode);
  21. if (!styleEl || !styleEl.isConnected) {
  22. styleEl = rootNode.querySelector('style[data-fullcalendar]');
  23. if (!styleEl) {
  24. styleEl = document.createElement('style');
  25. styleEl.setAttribute('data-fullcalendar', '');
  26. const nonce = getNonceValue();
  27. if (nonce) {
  28. styleEl.nonce = nonce;
  29. }
  30. const parentEl = rootNode === document ? document.head : rootNode;
  31. const insertBefore = rootNode === document
  32. ? parentEl.querySelector('script,link[rel=stylesheet],link[as=style],style')
  33. : parentEl.firstChild;
  34. parentEl.insertBefore(styleEl, insertBefore);
  35. }
  36. styleEls.set(rootNode, styleEl);
  37. hydrateStylesRoot(styleEl);
  38. }
  39. }
  40. function hydrateStylesRoot(styleEl) {
  41. for (const styleText of styleTexts) {
  42. appendStylesTo(styleEl, styleText);
  43. }
  44. }
  45. function appendStylesTo(styleEl, styleText) {
  46. const { sheet } = styleEl;
  47. const ruleCnt = sheet.cssRules.length;
  48. styleText.split('}').forEach((styleStr, i) => {
  49. styleStr = styleStr.trim();
  50. if (styleStr) {
  51. sheet.insertRule(styleStr + '}', ruleCnt + i);
  52. }
  53. });
  54. }
  55. // nonce
  56. // -------------------------------------------------------------------------------------------------
  57. let queriedNonceValue;
  58. function getNonceValue() {
  59. if (queriedNonceValue === undefined) {
  60. queriedNonceValue = queryNonceValue();
  61. }
  62. return queriedNonceValue;
  63. }
  64. /*
  65. TODO: discourage meta tag and instead put nonce attribute on placeholder <style> tag
  66. */
  67. function queryNonceValue() {
  68. const metaWithNonce = document.querySelector('meta[name="csp-nonce"]');
  69. if (metaWithNonce && metaWithNonce.hasAttribute('content')) {
  70. return metaWithNonce.getAttribute('content');
  71. }
  72. const elWithNonce = document.querySelector('script[nonce]');
  73. if (elWithNonce) {
  74. return elWithNonce.nonce || '';
  75. }
  76. return '';
  77. }
  78. // main
  79. // -------------------------------------------------------------------------------------------------
  80. if (typeof document !== 'undefined') {
  81. registerStylesRoot(document);
  82. }
  83. var css_248z = ":root{--fc-small-font-size:.85em;--fc-page-bg-color:#fff;--fc-neutral-bg-color:hsla(0,0%,82%,.3);--fc-neutral-text-color:grey;--fc-border-color:#ddd;--fc-button-text-color:#fff;--fc-button-bg-color:#2c3e50;--fc-button-border-color:#2c3e50;--fc-button-hover-bg-color:#1e2b37;--fc-button-hover-border-color:#1a252f;--fc-button-active-bg-color:#1a252f;--fc-button-active-border-color:#151e27;--fc-event-bg-color:#3788d8;--fc-event-border-color:#3788d8;--fc-event-text-color:#fff;--fc-event-selected-overlay-color:rgba(0,0,0,.25);--fc-more-link-bg-color:#d0d0d0;--fc-more-link-text-color:inherit;--fc-event-resizer-thickness:8px;--fc-event-resizer-dot-total-width:8px;--fc-event-resizer-dot-border-width:1px;--fc-non-business-color:hsla(0,0%,84%,.3);--fc-bg-event-color:#8fdf82;--fc-bg-event-opacity:0.3;--fc-highlight-color:rgba(188,232,241,.3);--fc-today-bg-color:rgba(255,220,40,.15);--fc-now-indicator-color:red}.fc-not-allowed,.fc-not-allowed .fc-event{cursor:not-allowed}.fc{display:flex;flex-direction:column;font-size:1em}.fc,.fc *,.fc :after,.fc :before{box-sizing:border-box}.fc table{border-collapse:collapse;border-spacing:0;font-size:1em}.fc th{text-align:center}.fc td,.fc th{padding:0;vertical-align:top}.fc a[data-navlink]{cursor:pointer}.fc a[data-navlink]:hover{text-decoration:underline}.fc-direction-ltr{direction:ltr;text-align:left}.fc-direction-rtl{direction:rtl;text-align:right}.fc-theme-standard td,.fc-theme-standard th{border:1px solid var(--fc-border-color)}.fc-liquid-hack td,.fc-liquid-hack th{position:relative}@font-face{font-family:fcicons;font-style:normal;font-weight:400;src:url(\"data:application/x-font-ttf;charset=utf-8;base64,AAEAAAALAIAAAwAwT1MvMg8SBfAAAAC8AAAAYGNtYXAXVtKNAAABHAAAAFRnYXNwAAAAEAAAAXAAAAAIZ2x5ZgYydxIAAAF4AAAFNGhlYWQUJ7cIAAAGrAAAADZoaGVhB20DzAAABuQAAAAkaG10eCIABhQAAAcIAAAALGxvY2ED4AU6AAAHNAAAABhtYXhwAA8AjAAAB0wAAAAgbmFtZXsr690AAAdsAAABhnBvc3QAAwAAAAAI9AAAACAAAwPAAZAABQAAApkCzAAAAI8CmQLMAAAB6wAzAQkAAAAAAAAAAAAAAAAAAAABEAAAAAAAAAAAAAAAAAAAAABAAADpBgPA/8AAQAPAAEAAAAABAAAAAAAAAAAAAAAgAAAAAAADAAAAAwAAABwAAQADAAAAHAADAAEAAAAcAAQAOAAAAAoACAACAAIAAQAg6Qb//f//AAAAAAAg6QD//f//AAH/4xcEAAMAAQAAAAAAAAAAAAAAAQAB//8ADwABAAAAAAAAAAAAAgAANzkBAAAAAAEAAAAAAAAAAAACAAA3OQEAAAAAAQAAAAAAAAAAAAIAADc5AQAAAAABAWIAjQKeAskAEwAAJSc3NjQnJiIHAQYUFwEWMjc2NCcCnuLiDQ0MJAz/AA0NAQAMJAwNDcni4gwjDQwM/wANIwz/AA0NDCMNAAAAAQFiAI0CngLJABMAACUBNjQnASYiBwYUHwEHBhQXFjI3AZ4BAA0N/wAMJAwNDeLiDQ0MJAyNAQAMIw0BAAwMDSMM4uINIwwNDQAAAAIA4gC3Ax4CngATACcAACUnNzY0JyYiDwEGFB8BFjI3NjQnISc3NjQnJiIPAQYUHwEWMjc2NCcB87e3DQ0MIw3VDQ3VDSMMDQ0BK7e3DQ0MJAzVDQ3VDCQMDQ3zuLcMJAwNDdUNIwzWDAwNIwy4twwkDA0N1Q0jDNYMDA0jDAAAAgDiALcDHgKeABMAJwAAJTc2NC8BJiIHBhQfAQcGFBcWMjchNzY0LwEmIgcGFB8BBwYUFxYyNwJJ1Q0N1Q0jDA0Nt7cNDQwjDf7V1Q0N1QwkDA0Nt7cNDQwkDLfWDCMN1Q0NDCQMt7gMIw0MDNYMIw3VDQ0MJAy3uAwjDQwMAAADAFUAAAOrA1UAMwBoAHcAABMiBgcOAQcOAQcOARURFBYXHgEXHgEXHgEzITI2Nz4BNz4BNz4BNRE0JicuAScuAScuASMFITIWFx4BFx4BFx4BFREUBgcOAQcOAQcOASMhIiYnLgEnLgEnLgE1ETQ2Nz4BNz4BNz4BMxMhMjY1NCYjISIGFRQWM9UNGAwLFQkJDgUFBQUFBQ4JCRULDBgNAlYNGAwLFQkJDgUFBQUFBQ4JCRULDBgN/aoCVgQIBAQHAwMFAQIBAQIBBQMDBwQECAT9qgQIBAQHAwMFAQIBAQIBBQMDBwQECASAAVYRGRkR/qoRGRkRA1UFBAUOCQkVDAsZDf2rDRkLDBUJCA4FBQUFBQUOCQgVDAsZDQJVDRkLDBUJCQ4FBAVVAgECBQMCBwQECAX9qwQJAwQHAwMFAQICAgIBBQMDBwQDCQQCVQUIBAQHAgMFAgEC/oAZEhEZGRESGQAAAAADAFUAAAOrA1UAMwBoAIkAABMiBgcOAQcOAQcOARURFBYXHgEXHgEXHgEzITI2Nz4BNz4BNz4BNRE0JicuAScuAScuASMFITIWFx4BFx4BFx4BFREUBgcOAQcOAQcOASMhIiYnLgEnLgEnLgE1ETQ2Nz4BNz4BNz4BMxMzFRQWMzI2PQEzMjY1NCYrATU0JiMiBh0BIyIGFRQWM9UNGAwLFQkJDgUFBQUFBQ4JCRULDBgNAlYNGAwLFQkJDgUFBQUFBQ4JCRULDBgN/aoCVgQIBAQHAwMFAQIBAQIBBQMDBwQECAT9qgQIBAQHAwMFAQIBAQIBBQMDBwQECASAgBkSEhmAERkZEYAZEhIZgBEZGREDVQUEBQ4JCRUMCxkN/asNGQsMFQkIDgUFBQUFBQ4JCBUMCxkNAlUNGQsMFQkJDgUEBVUCAQIFAwIHBAQIBf2rBAkDBAcDAwUBAgICAgEFAwMHBAMJBAJVBQgEBAcCAwUCAQL+gIASGRkSgBkSERmAEhkZEoAZERIZAAABAOIAjQMeAskAIAAAExcHBhQXFjI/ARcWMjc2NC8BNzY0JyYiDwEnJiIHBhQX4uLiDQ0MJAzi4gwkDA0N4uINDQwkDOLiDCQMDQ0CjeLiDSMMDQ3h4Q0NDCMN4uIMIw0MDOLiDAwNIwwAAAABAAAAAQAAa5n0y18PPPUACwQAAAAAANivOVsAAAAA2K85WwAAAAADqwNVAAAACAACAAAAAAAAAAEAAAPA/8AAAAQAAAAAAAOrAAEAAAAAAAAAAAAAAAAAAAALBAAAAAAAAAAAAAAAAgAAAAQAAWIEAAFiBAAA4gQAAOIEAABVBAAAVQQAAOIAAAAAAAoAFAAeAEQAagCqAOoBngJkApoAAQAAAAsAigADAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAA4ArgABAAAAAAABAAcAAAABAAAAAAACAAcAYAABAAAAAAADAAcANgABAAAAAAAEAAcAdQABAAAAAAAFAAsAFQABAAAAAAAGAAcASwABAAAAAAAKABoAigADAAEECQABAA4ABwADAAEECQACAA4AZwADAAEECQADAA4APQADAAEECQAEAA4AfAADAAEECQAFABYAIAADAAEECQAGAA4AUgADAAEECQAKADQApGZjaWNvbnMAZgBjAGkAYwBvAG4Ac1ZlcnNpb24gMS4wAFYAZQByAHMAaQBvAG4AIAAxAC4AMGZjaWNvbnMAZgBjAGkAYwBvAG4Ac2ZjaWNvbnMAZgBjAGkAYwBvAG4Ac1JlZ3VsYXIAUgBlAGcAdQBsAGEAcmZjaWNvbnMAZgBjAGkAYwBvAG4Ac0ZvbnQgZ2VuZXJhdGVkIGJ5IEljb01vb24uAEYAbwBuAHQAIABnAGUAbgBlAHIAYQB0AGUAZAAgAGIAeQAgAEkAYwBvAE0AbwBvAG4ALgAAAAMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\") format(\"truetype\")}.fc-icon{speak:none;-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;display:inline-block;font-family:fcicons!important;font-style:normal;font-variant:normal;font-weight:400;height:1em;line-height:1;text-align:center;text-transform:none;-moz-user-select:none;user-select:none;width:1em}.fc-icon-chevron-left:before{content:\"\\e900\"}.fc-icon-chevron-right:before{content:\"\\e901\"}.fc-icon-chevrons-left:before{content:\"\\e902\"}.fc-icon-chevrons-right:before{content:\"\\e903\"}.fc-icon-minus-square:before{content:\"\\e904\"}.fc-icon-plus-square:before{content:\"\\e905\"}.fc-icon-x:before{content:\"\\e906\"}.fc .fc-button{border-radius:0;font-family:inherit;font-size:inherit;line-height:inherit;margin:0;overflow:visible;text-transform:none}.fc .fc-button:focus{outline:1px dotted;outline:5px auto -webkit-focus-ring-color}.fc .fc-button{-webkit-appearance:button}.fc .fc-button:not(:disabled){cursor:pointer}.fc .fc-button{background-color:transparent;border:1px solid transparent;border-radius:.25em;display:inline-block;font-size:1em;font-weight:400;line-height:1.5;padding:.4em .65em;text-align:center;-moz-user-select:none;user-select:none;vertical-align:middle}.fc .fc-button:hover{text-decoration:none}.fc .fc-button:focus{box-shadow:0 0 0 .2rem rgba(44,62,80,.25);outline:0}.fc .fc-button:disabled{opacity:.65}.fc .fc-button-primary{background-color:var(--fc-button-bg-color);border-color:var(--fc-button-border-color);color:var(--fc-button-text-color)}.fc .fc-button-primary:hover{background-color:var(--fc-button-hover-bg-color);border-color:var(--fc-button-hover-border-color);color:var(--fc-button-text-color)}.fc .fc-button-primary:disabled{background-color:var(--fc-button-bg-color);border-color:var(--fc-button-border-color);color:var(--fc-button-text-color)}.fc .fc-button-primary:focus{box-shadow:0 0 0 .2rem rgba(76,91,106,.5)}.fc .fc-button-primary:not(:disabled).fc-button-active,.fc .fc-button-primary:not(:disabled):active{background-color:var(--fc-button-active-bg-color);border-color:var(--fc-button-active-border-color);color:var(--fc-button-text-color)}.fc .fc-button-primary:not(:disabled).fc-button-active:focus,.fc .fc-button-primary:not(:disabled):active:focus{box-shadow:0 0 0 .2rem rgba(76,91,106,.5)}.fc .fc-button .fc-icon{font-size:1.5em;vertical-align:middle}.fc .fc-button-group{display:inline-flex;position:relative;vertical-align:middle}.fc .fc-button-group>.fc-button{flex:1 1 auto;position:relative}.fc .fc-button-group>.fc-button.fc-button-active,.fc .fc-button-group>.fc-button:active,.fc .fc-button-group>.fc-button:focus,.fc .fc-button-group>.fc-button:hover{z-index:1}.fc-direction-ltr .fc-button-group>.fc-button:not(:first-child){border-bottom-left-radius:0;border-top-left-radius:0;margin-left:-1px}.fc-direction-ltr .fc-button-group>.fc-button:not(:last-child){border-bottom-right-radius:0;border-top-right-radius:0}.fc-direction-rtl .fc-button-group>.fc-button:not(:first-child){border-bottom-right-radius:0;border-top-right-radius:0;margin-right:-1px}.fc-direction-rtl .fc-button-group>.fc-button:not(:last-child){border-bottom-left-radius:0;border-top-left-radius:0}.fc .fc-toolbar{align-items:center;display:flex;justify-content:space-between}.fc .fc-toolbar.fc-header-toolbar{margin-bottom:1.5em}.fc .fc-toolbar.fc-footer-toolbar{margin-top:1.5em}.fc .fc-toolbar-title{font-size:1.75em;margin:0}.fc-direction-ltr .fc-toolbar>*>:not(:first-child){margin-left:.75em}.fc-direction-rtl .fc-toolbar>*>:not(:first-child){margin-right:.75em}.fc-direction-rtl .fc-toolbar-ltr{flex-direction:row-reverse}.fc .fc-scroller{-webkit-overflow-scrolling:touch;position:relative}.fc .fc-scroller-liquid{height:100%}.fc .fc-scroller-liquid-absolute{bottom:0;left:0;position:absolute;right:0;top:0}.fc .fc-scroller-harness{direction:ltr;overflow:hidden;position:relative}.fc .fc-scroller-harness-liquid{height:100%}.fc-direction-rtl .fc-scroller-harness>.fc-scroller{direction:rtl}.fc-theme-standard .fc-scrollgrid{border:1px solid var(--fc-border-color)}.fc .fc-scrollgrid,.fc .fc-scrollgrid table{table-layout:fixed;width:100%}.fc .fc-scrollgrid table{border-left-style:hidden;border-right-style:hidden;border-top-style:hidden}.fc .fc-scrollgrid{border-bottom-width:0;border-collapse:separate;border-right-width:0}.fc .fc-scrollgrid-liquid{height:100%}.fc .fc-scrollgrid-section,.fc .fc-scrollgrid-section table,.fc .fc-scrollgrid-section>td{height:1px}.fc .fc-scrollgrid-section-liquid>td{height:100%}.fc .fc-scrollgrid-section>*{border-left-width:0;border-top-width:0}.fc .fc-scrollgrid-section-footer>*,.fc .fc-scrollgrid-section-header>*{border-bottom-width:0}.fc .fc-scrollgrid-section-body table,.fc .fc-scrollgrid-section-footer table{border-bottom-style:hidden}.fc .fc-scrollgrid-section-sticky>*{background:var(--fc-page-bg-color);position:sticky;z-index:3}.fc .fc-scrollgrid-section-header.fc-scrollgrid-section-sticky>*{top:0}.fc .fc-scrollgrid-section-footer.fc-scrollgrid-section-sticky>*{bottom:0}.fc .fc-scrollgrid-sticky-shim{height:1px;margin-bottom:-1px}.fc-sticky{position:sticky}.fc .fc-view-harness{flex-grow:1;position:relative}.fc .fc-view-harness-active>.fc-view{bottom:0;left:0;position:absolute;right:0;top:0}.fc .fc-col-header-cell-cushion{display:inline-block;padding:2px 4px}.fc .fc-bg-event,.fc .fc-highlight,.fc .fc-non-business{bottom:0;left:0;position:absolute;right:0;top:0}.fc .fc-non-business{background:var(--fc-non-business-color)}.fc .fc-bg-event{background:var(--fc-bg-event-color);opacity:var(--fc-bg-event-opacity)}.fc .fc-bg-event .fc-event-title{font-size:var(--fc-small-font-size);font-style:italic;margin:.5em}.fc .fc-highlight{background:var(--fc-highlight-color)}.fc .fc-cell-shaded,.fc .fc-day-disabled{background:var(--fc-neutral-bg-color)}a.fc-event,a.fc-event:hover{text-decoration:none}.fc-event.fc-event-draggable,.fc-event[href]{cursor:pointer}.fc-event .fc-event-main{position:relative;z-index:2}.fc-event-dragging:not(.fc-event-selected){opacity:.75}.fc-event-dragging.fc-event-selected{box-shadow:0 2px 7px rgba(0,0,0,.3)}.fc-event .fc-event-resizer{display:none;position:absolute;z-index:4}.fc-event-selected .fc-event-resizer,.fc-event:hover .fc-event-resizer{display:block}.fc-event-selected .fc-event-resizer{background:var(--fc-page-bg-color);border-color:inherit;border-radius:calc(var(--fc-event-resizer-dot-total-width)/2);border-style:solid;border-width:var(--fc-event-resizer-dot-border-width);height:var(--fc-event-resizer-dot-total-width);width:var(--fc-event-resizer-dot-total-width)}.fc-event-selected .fc-event-resizer:before{bottom:-20px;content:\"\";left:-20px;position:absolute;right:-20px;top:-20px}.fc-event-selected,.fc-event:focus{box-shadow:0 2px 5px rgba(0,0,0,.2)}.fc-event-selected:before,.fc-event:focus:before{bottom:0;content:\"\";left:0;position:absolute;right:0;top:0;z-index:3}.fc-event-selected:after,.fc-event:focus:after{background:var(--fc-event-selected-overlay-color);bottom:-1px;content:\"\";left:-1px;position:absolute;right:-1px;top:-1px;z-index:1}.fc-h-event{background-color:var(--fc-event-bg-color);border:1px solid var(--fc-event-border-color);display:block}.fc-h-event .fc-event-main{color:var(--fc-event-text-color)}.fc-h-event .fc-event-main-frame{display:flex}.fc-h-event .fc-event-time{max-width:100%;overflow:hidden}.fc-h-event .fc-event-title-container{flex-grow:1;flex-shrink:1;min-width:0}.fc-h-event .fc-event-title{display:inline-block;left:0;max-width:100%;overflow:hidden;right:0;vertical-align:top}.fc-h-event.fc-event-selected:before{bottom:-10px;top:-10px}.fc-direction-ltr .fc-daygrid-block-event:not(.fc-event-start),.fc-direction-rtl .fc-daygrid-block-event:not(.fc-event-end){border-bottom-left-radius:0;border-left-width:0;border-top-left-radius:0}.fc-direction-ltr .fc-daygrid-block-event:not(.fc-event-end),.fc-direction-rtl .fc-daygrid-block-event:not(.fc-event-start){border-bottom-right-radius:0;border-right-width:0;border-top-right-radius:0}.fc-h-event:not(.fc-event-selected) .fc-event-resizer{bottom:0;top:0;width:var(--fc-event-resizer-thickness)}.fc-direction-ltr .fc-h-event:not(.fc-event-selected) .fc-event-resizer-start,.fc-direction-rtl .fc-h-event:not(.fc-event-selected) .fc-event-resizer-end{cursor:w-resize;left:calc(var(--fc-event-resizer-thickness)*-.5)}.fc-direction-ltr .fc-h-event:not(.fc-event-selected) .fc-event-resizer-end,.fc-direction-rtl .fc-h-event:not(.fc-event-selected) .fc-event-resizer-start{cursor:e-resize;right:calc(var(--fc-event-resizer-thickness)*-.5)}.fc-h-event.fc-event-selected .fc-event-resizer{margin-top:calc(var(--fc-event-resizer-dot-total-width)*-.5);top:50%}.fc-direction-ltr .fc-h-event.fc-event-selected .fc-event-resizer-start,.fc-direction-rtl .fc-h-event.fc-event-selected .fc-event-resizer-end{left:calc(var(--fc-event-resizer-dot-total-width)*-.5)}.fc-direction-ltr .fc-h-event.fc-event-selected .fc-event-resizer-end,.fc-direction-rtl .fc-h-event.fc-event-selected .fc-event-resizer-start{right:calc(var(--fc-event-resizer-dot-total-width)*-.5)}.fc .fc-popover{box-shadow:0 2px 6px rgba(0,0,0,.15);position:absolute;z-index:9999}.fc .fc-popover-header{align-items:center;display:flex;flex-direction:row;justify-content:space-between;padding:3px 4px}.fc .fc-popover-title{margin:0 2px}.fc .fc-popover-close{cursor:pointer;font-size:1.1em;opacity:.65}.fc-theme-standard .fc-popover{background:var(--fc-page-bg-color);border:1px solid var(--fc-border-color)}.fc-theme-standard .fc-popover-header{background:var(--fc-neutral-bg-color)}";
  84. injectStyles(css_248z);
  85. class DelayedRunner {
  86. constructor(drainedOption) {
  87. this.drainedOption = drainedOption;
  88. this.isRunning = false;
  89. this.isDirty = false;
  90. this.pauseDepths = {};
  91. this.timeoutId = 0;
  92. }
  93. request(delay) {
  94. this.isDirty = true;
  95. if (!this.isPaused()) {
  96. this.clearTimeout();
  97. if (delay == null) {
  98. this.tryDrain();
  99. }
  100. else {
  101. this.timeoutId = setTimeout(// NOT OPTIMAL! TODO: look at debounce
  102. this.tryDrain.bind(this), delay);
  103. }
  104. }
  105. }
  106. pause(scope = '') {
  107. let { pauseDepths } = this;
  108. pauseDepths[scope] = (pauseDepths[scope] || 0) + 1;
  109. this.clearTimeout();
  110. }
  111. resume(scope = '', force) {
  112. let { pauseDepths } = this;
  113. if (scope in pauseDepths) {
  114. if (force) {
  115. delete pauseDepths[scope];
  116. }
  117. else {
  118. pauseDepths[scope] -= 1;
  119. let depth = pauseDepths[scope];
  120. if (depth <= 0) {
  121. delete pauseDepths[scope];
  122. }
  123. }
  124. this.tryDrain();
  125. }
  126. }
  127. isPaused() {
  128. return Object.keys(this.pauseDepths).length;
  129. }
  130. tryDrain() {
  131. if (!this.isRunning && !this.isPaused()) {
  132. this.isRunning = true;
  133. while (this.isDirty) {
  134. this.isDirty = false;
  135. this.drained(); // might set isDirty to true again
  136. }
  137. this.isRunning = false;
  138. }
  139. }
  140. clear() {
  141. this.clearTimeout();
  142. this.isDirty = false;
  143. this.pauseDepths = {};
  144. }
  145. clearTimeout() {
  146. if (this.timeoutId) {
  147. clearTimeout(this.timeoutId);
  148. this.timeoutId = 0;
  149. }
  150. }
  151. drained() {
  152. if (this.drainedOption) {
  153. this.drainedOption();
  154. }
  155. }
  156. }
  157. function removeElement(el) {
  158. if (el.parentNode) {
  159. el.parentNode.removeChild(el);
  160. }
  161. }
  162. // Querying
  163. // ----------------------------------------------------------------------------------------------------------------
  164. function elementClosest(el, selector) {
  165. if (el.closest) {
  166. return el.closest(selector);
  167. // really bad fallback for IE
  168. // from https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
  169. }
  170. if (!document.documentElement.contains(el)) {
  171. return null;
  172. }
  173. do {
  174. if (elementMatches(el, selector)) {
  175. return el;
  176. }
  177. el = (el.parentElement || el.parentNode);
  178. } while (el !== null && el.nodeType === 1);
  179. return null;
  180. }
  181. function elementMatches(el, selector) {
  182. let method = el.matches || el.matchesSelector || el.msMatchesSelector;
  183. return method.call(el, selector);
  184. }
  185. // accepts multiple subject els
  186. // returns a real array. good for methods like forEach
  187. // TODO: accept the document
  188. function findElements(container, selector) {
  189. let containers = container instanceof HTMLElement ? [container] : container;
  190. let allMatches = [];
  191. for (let i = 0; i < containers.length; i += 1) {
  192. let matches = containers[i].querySelectorAll(selector);
  193. for (let j = 0; j < matches.length; j += 1) {
  194. allMatches.push(matches[j]);
  195. }
  196. }
  197. return allMatches;
  198. }
  199. // accepts multiple subject els
  200. // only queries direct child elements // TODO: rename to findDirectChildren!
  201. function findDirectChildren(parent, selector) {
  202. let parents = parent instanceof HTMLElement ? [parent] : parent;
  203. let allMatches = [];
  204. for (let i = 0; i < parents.length; i += 1) {
  205. let childNodes = parents[i].children; // only ever elements
  206. for (let j = 0; j < childNodes.length; j += 1) {
  207. let childNode = childNodes[j];
  208. if (!selector || elementMatches(childNode, selector)) {
  209. allMatches.push(childNode);
  210. }
  211. }
  212. }
  213. return allMatches;
  214. }
  215. // Style
  216. // ----------------------------------------------------------------------------------------------------------------
  217. const PIXEL_PROP_RE = /(top|left|right|bottom|width|height)$/i;
  218. function applyStyle(el, props) {
  219. for (let propName in props) {
  220. applyStyleProp(el, propName, props[propName]);
  221. }
  222. }
  223. function applyStyleProp(el, name, val) {
  224. if (val == null) {
  225. el.style[name] = '';
  226. }
  227. else if (typeof val === 'number' && PIXEL_PROP_RE.test(name)) {
  228. el.style[name] = `${val}px`;
  229. }
  230. else {
  231. el.style[name] = val;
  232. }
  233. }
  234. // Event Handling
  235. // ----------------------------------------------------------------------------------------------------------------
  236. // if intercepting bubbled events at the document/window/body level,
  237. // and want to see originating element (the 'target'), use this util instead
  238. // of `ev.target` because it goes within web-component boundaries.
  239. function getEventTargetViaRoot(ev) {
  240. var _a, _b;
  241. return (_b = (_a = ev.composedPath) === null || _a === void 0 ? void 0 : _a.call(ev)[0]) !== null && _b !== void 0 ? _b : ev.target;
  242. }
  243. // Unique ID for DOM attribute
  244. let guid$1 = 0;
  245. function getUniqueDomId() {
  246. guid$1 += 1;
  247. return 'fc-dom-' + guid$1;
  248. }
  249. // Stops a mouse/touch event from doing it's native browser action
  250. function preventDefault(ev) {
  251. ev.preventDefault();
  252. }
  253. // Event Delegation
  254. // ----------------------------------------------------------------------------------------------------------------
  255. function buildDelegationHandler(selector, handler) {
  256. return (ev) => {
  257. let matchedChild = elementClosest(ev.target, selector);
  258. if (matchedChild) {
  259. handler.call(matchedChild, ev, matchedChild);
  260. }
  261. };
  262. }
  263. function listenBySelector(container, eventType, selector, handler) {
  264. let attachedHandler = buildDelegationHandler(selector, handler);
  265. container.addEventListener(eventType, attachedHandler);
  266. return () => {
  267. container.removeEventListener(eventType, attachedHandler);
  268. };
  269. }
  270. function listenToHoverBySelector(container, selector, onMouseEnter, onMouseLeave) {
  271. let currentMatchedChild;
  272. return listenBySelector(container, 'mouseover', selector, (mouseOverEv, matchedChild) => {
  273. if (matchedChild !== currentMatchedChild) {
  274. currentMatchedChild = matchedChild;
  275. onMouseEnter(mouseOverEv, matchedChild);
  276. let realOnMouseLeave = (mouseLeaveEv) => {
  277. currentMatchedChild = null;
  278. onMouseLeave(mouseLeaveEv, matchedChild);
  279. matchedChild.removeEventListener('mouseleave', realOnMouseLeave);
  280. };
  281. // listen to the next mouseleave, and then unattach
  282. matchedChild.addEventListener('mouseleave', realOnMouseLeave);
  283. }
  284. });
  285. }
  286. // Animation
  287. // ----------------------------------------------------------------------------------------------------------------
  288. const transitionEventNames = [
  289. 'webkitTransitionEnd',
  290. 'otransitionend',
  291. 'oTransitionEnd',
  292. 'msTransitionEnd',
  293. 'transitionend',
  294. ];
  295. // triggered only when the next single subsequent transition finishes
  296. function whenTransitionDone(el, callback) {
  297. let realCallback = (ev) => {
  298. callback(ev);
  299. transitionEventNames.forEach((eventName) => {
  300. el.removeEventListener(eventName, realCallback);
  301. });
  302. };
  303. transitionEventNames.forEach((eventName) => {
  304. el.addEventListener(eventName, realCallback); // cross-browser way to determine when the transition finishes
  305. });
  306. }
  307. // ARIA workarounds
  308. // ----------------------------------------------------------------------------------------------------------------
  309. function createAriaClickAttrs(handler) {
  310. return Object.assign({ onClick: handler }, createAriaKeyboardAttrs(handler));
  311. }
  312. function createAriaKeyboardAttrs(handler) {
  313. return {
  314. tabIndex: 0,
  315. onKeyDown(ev) {
  316. if (ev.key === 'Enter' || ev.key === ' ') {
  317. handler(ev);
  318. ev.preventDefault(); // if space, don't scroll down page
  319. }
  320. },
  321. };
  322. }
  323. let guidNumber = 0;
  324. function guid() {
  325. guidNumber += 1;
  326. return String(guidNumber);
  327. }
  328. /* FullCalendar-specific DOM Utilities
  329. ----------------------------------------------------------------------------------------------------------------------*/
  330. // Make the mouse cursor express that an event is not allowed in the current area
  331. function disableCursor() {
  332. document.body.classList.add('fc-not-allowed');
  333. }
  334. // Returns the mouse cursor to its original look
  335. function enableCursor() {
  336. document.body.classList.remove('fc-not-allowed');
  337. }
  338. /* Selection
  339. ----------------------------------------------------------------------------------------------------------------------*/
  340. function preventSelection(el) {
  341. el.style.userSelect = 'none';
  342. el.style.webkitUserSelect = 'none';
  343. el.addEventListener('selectstart', preventDefault);
  344. }
  345. function allowSelection(el) {
  346. el.style.userSelect = '';
  347. el.style.webkitUserSelect = '';
  348. el.removeEventListener('selectstart', preventDefault);
  349. }
  350. /* Context Menu
  351. ----------------------------------------------------------------------------------------------------------------------*/
  352. function preventContextMenu(el) {
  353. el.addEventListener('contextmenu', preventDefault);
  354. }
  355. function allowContextMenu(el) {
  356. el.removeEventListener('contextmenu', preventDefault);
  357. }
  358. function parseFieldSpecs(input) {
  359. let specs = [];
  360. let tokens = [];
  361. let i;
  362. let token;
  363. if (typeof input === 'string') {
  364. tokens = input.split(/\s*,\s*/);
  365. }
  366. else if (typeof input === 'function') {
  367. tokens = [input];
  368. }
  369. else if (Array.isArray(input)) {
  370. tokens = input;
  371. }
  372. for (i = 0; i < tokens.length; i += 1) {
  373. token = tokens[i];
  374. if (typeof token === 'string') {
  375. specs.push(token.charAt(0) === '-' ?
  376. { field: token.substring(1), order: -1 } :
  377. { field: token, order: 1 });
  378. }
  379. else if (typeof token === 'function') {
  380. specs.push({ func: token });
  381. }
  382. }
  383. return specs;
  384. }
  385. function compareByFieldSpecs(obj0, obj1, fieldSpecs) {
  386. let i;
  387. let cmp;
  388. for (i = 0; i < fieldSpecs.length; i += 1) {
  389. cmp = compareByFieldSpec(obj0, obj1, fieldSpecs[i]);
  390. if (cmp) {
  391. return cmp;
  392. }
  393. }
  394. return 0;
  395. }
  396. function compareByFieldSpec(obj0, obj1, fieldSpec) {
  397. if (fieldSpec.func) {
  398. return fieldSpec.func(obj0, obj1);
  399. }
  400. return flexibleCompare(obj0[fieldSpec.field], obj1[fieldSpec.field])
  401. * (fieldSpec.order || 1);
  402. }
  403. function flexibleCompare(a, b) {
  404. if (!a && !b) {
  405. return 0;
  406. }
  407. if (b == null) {
  408. return -1;
  409. }
  410. if (a == null) {
  411. return 1;
  412. }
  413. if (typeof a === 'string' || typeof b === 'string') {
  414. return String(a).localeCompare(String(b));
  415. }
  416. return a - b;
  417. }
  418. /* String Utilities
  419. ----------------------------------------------------------------------------------------------------------------------*/
  420. function padStart(val, len) {
  421. let s = String(val);
  422. return '000'.substr(0, len - s.length) + s;
  423. }
  424. function formatWithOrdinals(formatter, args, fallbackText) {
  425. if (typeof formatter === 'function') {
  426. return formatter(...args);
  427. }
  428. if (typeof formatter === 'string') { // non-blank string
  429. return args.reduce((str, arg, index) => (str.replace('$' + index, arg || '')), formatter);
  430. }
  431. return fallbackText;
  432. }
  433. /* Number Utilities
  434. ----------------------------------------------------------------------------------------------------------------------*/
  435. function compareNumbers(a, b) {
  436. return a - b;
  437. }
  438. function isInt(n) {
  439. return n % 1 === 0;
  440. }
  441. /* FC-specific DOM dimension stuff
  442. ----------------------------------------------------------------------------------------------------------------------*/
  443. function computeSmallestCellWidth(cellEl) {
  444. let allWidthEl = cellEl.querySelector('.fc-scrollgrid-shrink-frame');
  445. let contentWidthEl = cellEl.querySelector('.fc-scrollgrid-shrink-cushion');
  446. if (!allWidthEl) {
  447. throw new Error('needs fc-scrollgrid-shrink-frame className'); // TODO: use const
  448. }
  449. if (!contentWidthEl) {
  450. throw new Error('needs fc-scrollgrid-shrink-cushion className');
  451. }
  452. return cellEl.getBoundingClientRect().width - allWidthEl.getBoundingClientRect().width + // the cell padding+border
  453. contentWidthEl.getBoundingClientRect().width;
  454. }
  455. const INTERNAL_UNITS = ['years', 'months', 'days', 'milliseconds'];
  456. const PARSE_RE = /^(-?)(?:(\d+)\.)?(\d+):(\d\d)(?::(\d\d)(?:\.(\d\d\d))?)?/;
  457. // Parsing and Creation
  458. function createDuration(input, unit) {
  459. if (typeof input === 'string') {
  460. return parseString(input);
  461. }
  462. if (typeof input === 'object' && input) { // non-null object
  463. return parseObject(input);
  464. }
  465. if (typeof input === 'number') {
  466. return parseObject({ [unit || 'milliseconds']: input });
  467. }
  468. return null;
  469. }
  470. function parseString(s) {
  471. let m = PARSE_RE.exec(s);
  472. if (m) {
  473. let sign = m[1] ? -1 : 1;
  474. return {
  475. years: 0,
  476. months: 0,
  477. days: sign * (m[2] ? parseInt(m[2], 10) : 0),
  478. milliseconds: sign * ((m[3] ? parseInt(m[3], 10) : 0) * 60 * 60 * 1000 + // hours
  479. (m[4] ? parseInt(m[4], 10) : 0) * 60 * 1000 + // minutes
  480. (m[5] ? parseInt(m[5], 10) : 0) * 1000 + // seconds
  481. (m[6] ? parseInt(m[6], 10) : 0) // ms
  482. ),
  483. };
  484. }
  485. return null;
  486. }
  487. function parseObject(obj) {
  488. let duration = {
  489. years: obj.years || obj.year || 0,
  490. months: obj.months || obj.month || 0,
  491. days: obj.days || obj.day || 0,
  492. milliseconds: (obj.hours || obj.hour || 0) * 60 * 60 * 1000 + // hours
  493. (obj.minutes || obj.minute || 0) * 60 * 1000 + // minutes
  494. (obj.seconds || obj.second || 0) * 1000 + // seconds
  495. (obj.milliseconds || obj.millisecond || obj.ms || 0), // ms
  496. };
  497. let weeks = obj.weeks || obj.week;
  498. if (weeks) {
  499. duration.days += weeks * 7;
  500. duration.specifiedWeeks = true;
  501. }
  502. return duration;
  503. }
  504. // Equality
  505. function durationsEqual(d0, d1) {
  506. return d0.years === d1.years &&
  507. d0.months === d1.months &&
  508. d0.days === d1.days &&
  509. d0.milliseconds === d1.milliseconds;
  510. }
  511. function asCleanDays(dur) {
  512. if (!dur.years && !dur.months && !dur.milliseconds) {
  513. return dur.days;
  514. }
  515. return 0;
  516. }
  517. // Simple Math
  518. function addDurations(d0, d1) {
  519. return {
  520. years: d0.years + d1.years,
  521. months: d0.months + d1.months,
  522. days: d0.days + d1.days,
  523. milliseconds: d0.milliseconds + d1.milliseconds,
  524. };
  525. }
  526. function subtractDurations(d1, d0) {
  527. return {
  528. years: d1.years - d0.years,
  529. months: d1.months - d0.months,
  530. days: d1.days - d0.days,
  531. milliseconds: d1.milliseconds - d0.milliseconds,
  532. };
  533. }
  534. function multiplyDuration(d, n) {
  535. return {
  536. years: d.years * n,
  537. months: d.months * n,
  538. days: d.days * n,
  539. milliseconds: d.milliseconds * n,
  540. };
  541. }
  542. // Conversions
  543. // "Rough" because they are based on average-case Gregorian months/years
  544. function asRoughYears(dur) {
  545. return asRoughDays(dur) / 365;
  546. }
  547. function asRoughMonths(dur) {
  548. return asRoughDays(dur) / 30;
  549. }
  550. function asRoughDays(dur) {
  551. return asRoughMs(dur) / 864e5;
  552. }
  553. function asRoughMinutes(dur) {
  554. return asRoughMs(dur) / (1000 * 60);
  555. }
  556. function asRoughSeconds(dur) {
  557. return asRoughMs(dur) / 1000;
  558. }
  559. function asRoughMs(dur) {
  560. return dur.years * (365 * 864e5) +
  561. dur.months * (30 * 864e5) +
  562. dur.days * 864e5 +
  563. dur.milliseconds;
  564. }
  565. // Advanced Math
  566. function wholeDivideDurations(numerator, denominator) {
  567. let res = null;
  568. for (let i = 0; i < INTERNAL_UNITS.length; i += 1) {
  569. let unit = INTERNAL_UNITS[i];
  570. if (denominator[unit]) {
  571. let localRes = numerator[unit] / denominator[unit];
  572. if (!isInt(localRes) || (res !== null && res !== localRes)) {
  573. return null;
  574. }
  575. res = localRes;
  576. }
  577. else if (numerator[unit]) {
  578. // needs to divide by something but can't!
  579. return null;
  580. }
  581. }
  582. return res;
  583. }
  584. function greatestDurationDenominator(dur) {
  585. let ms = dur.milliseconds;
  586. if (ms) {
  587. if (ms % 1000 !== 0) {
  588. return { unit: 'millisecond', value: ms };
  589. }
  590. if (ms % (1000 * 60) !== 0) {
  591. return { unit: 'second', value: ms / 1000 };
  592. }
  593. if (ms % (1000 * 60 * 60) !== 0) {
  594. return { unit: 'minute', value: ms / (1000 * 60) };
  595. }
  596. if (ms) {
  597. return { unit: 'hour', value: ms / (1000 * 60 * 60) };
  598. }
  599. }
  600. if (dur.days) {
  601. if (dur.specifiedWeeks && dur.days % 7 === 0) {
  602. return { unit: 'week', value: dur.days / 7 };
  603. }
  604. return { unit: 'day', value: dur.days };
  605. }
  606. if (dur.months) {
  607. return { unit: 'month', value: dur.months };
  608. }
  609. if (dur.years) {
  610. return { unit: 'year', value: dur.years };
  611. }
  612. return { unit: 'millisecond', value: 0 };
  613. }
  614. // TODO: new util arrayify?
  615. function removeExact(array, exactVal) {
  616. let removeCnt = 0;
  617. let i = 0;
  618. while (i < array.length) {
  619. if (array[i] === exactVal) {
  620. array.splice(i, 1);
  621. removeCnt += 1;
  622. }
  623. else {
  624. i += 1;
  625. }
  626. }
  627. return removeCnt;
  628. }
  629. function isArraysEqual(a0, a1, equalityFunc) {
  630. if (a0 === a1) {
  631. return true;
  632. }
  633. let len = a0.length;
  634. let i;
  635. if (len !== a1.length) { // not array? or not same length?
  636. return false;
  637. }
  638. for (i = 0; i < len; i += 1) {
  639. if (!(equalityFunc ? equalityFunc(a0[i], a1[i]) : a0[i] === a1[i])) {
  640. return false;
  641. }
  642. }
  643. return true;
  644. }
  645. const DAY_IDS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
  646. // Adding
  647. function addWeeks(m, n) {
  648. let a = dateToUtcArray(m);
  649. a[2] += n * 7;
  650. return arrayToUtcDate(a);
  651. }
  652. function addDays(m, n) {
  653. let a = dateToUtcArray(m);
  654. a[2] += n;
  655. return arrayToUtcDate(a);
  656. }
  657. function addMs(m, n) {
  658. let a = dateToUtcArray(m);
  659. a[6] += n;
  660. return arrayToUtcDate(a);
  661. }
  662. // Diffing (all return floats)
  663. // TODO: why not use ranges?
  664. function diffWeeks(m0, m1) {
  665. return diffDays(m0, m1) / 7;
  666. }
  667. function diffDays(m0, m1) {
  668. return (m1.valueOf() - m0.valueOf()) / (1000 * 60 * 60 * 24);
  669. }
  670. function diffHours(m0, m1) {
  671. return (m1.valueOf() - m0.valueOf()) / (1000 * 60 * 60);
  672. }
  673. function diffMinutes(m0, m1) {
  674. return (m1.valueOf() - m0.valueOf()) / (1000 * 60);
  675. }
  676. function diffSeconds(m0, m1) {
  677. return (m1.valueOf() - m0.valueOf()) / 1000;
  678. }
  679. function diffDayAndTime(m0, m1) {
  680. let m0day = startOfDay(m0);
  681. let m1day = startOfDay(m1);
  682. return {
  683. years: 0,
  684. months: 0,
  685. days: Math.round(diffDays(m0day, m1day)),
  686. milliseconds: (m1.valueOf() - m1day.valueOf()) - (m0.valueOf() - m0day.valueOf()),
  687. };
  688. }
  689. // Diffing Whole Units
  690. function diffWholeWeeks(m0, m1) {
  691. let d = diffWholeDays(m0, m1);
  692. if (d !== null && d % 7 === 0) {
  693. return d / 7;
  694. }
  695. return null;
  696. }
  697. function diffWholeDays(m0, m1) {
  698. if (timeAsMs(m0) === timeAsMs(m1)) {
  699. return Math.round(diffDays(m0, m1));
  700. }
  701. return null;
  702. }
  703. // Start-Of
  704. function startOfDay(m) {
  705. return arrayToUtcDate([
  706. m.getUTCFullYear(),
  707. m.getUTCMonth(),
  708. m.getUTCDate(),
  709. ]);
  710. }
  711. function startOfHour(m) {
  712. return arrayToUtcDate([
  713. m.getUTCFullYear(),
  714. m.getUTCMonth(),
  715. m.getUTCDate(),
  716. m.getUTCHours(),
  717. ]);
  718. }
  719. function startOfMinute(m) {
  720. return arrayToUtcDate([
  721. m.getUTCFullYear(),
  722. m.getUTCMonth(),
  723. m.getUTCDate(),
  724. m.getUTCHours(),
  725. m.getUTCMinutes(),
  726. ]);
  727. }
  728. function startOfSecond(m) {
  729. return arrayToUtcDate([
  730. m.getUTCFullYear(),
  731. m.getUTCMonth(),
  732. m.getUTCDate(),
  733. m.getUTCHours(),
  734. m.getUTCMinutes(),
  735. m.getUTCSeconds(),
  736. ]);
  737. }
  738. // Week Computation
  739. function weekOfYear(marker, dow, doy) {
  740. let y = marker.getUTCFullYear();
  741. let w = weekOfGivenYear(marker, y, dow, doy);
  742. if (w < 1) {
  743. return weekOfGivenYear(marker, y - 1, dow, doy);
  744. }
  745. let nextW = weekOfGivenYear(marker, y + 1, dow, doy);
  746. if (nextW >= 1) {
  747. return Math.min(w, nextW);
  748. }
  749. return w;
  750. }
  751. function weekOfGivenYear(marker, year, dow, doy) {
  752. let firstWeekStart = arrayToUtcDate([year, 0, 1 + firstWeekOffset(year, dow, doy)]);
  753. let dayStart = startOfDay(marker);
  754. let days = Math.round(diffDays(firstWeekStart, dayStart));
  755. return Math.floor(days / 7) + 1; // zero-indexed
  756. }
  757. // start-of-first-week - start-of-year
  758. function firstWeekOffset(year, dow, doy) {
  759. // first-week day -- which january is always in the first week (4 for iso, 1 for other)
  760. let fwd = 7 + dow - doy;
  761. // first-week day local weekday -- which local weekday is fwd
  762. let fwdlw = (7 + arrayToUtcDate([year, 0, fwd]).getUTCDay() - dow) % 7;
  763. return -fwdlw + fwd - 1;
  764. }
  765. // Array Conversion
  766. function dateToLocalArray(date) {
  767. return [
  768. date.getFullYear(),
  769. date.getMonth(),
  770. date.getDate(),
  771. date.getHours(),
  772. date.getMinutes(),
  773. date.getSeconds(),
  774. date.getMilliseconds(),
  775. ];
  776. }
  777. function arrayToLocalDate(a) {
  778. return new Date(a[0], a[1] || 0, a[2] == null ? 1 : a[2], // day of month
  779. a[3] || 0, a[4] || 0, a[5] || 0);
  780. }
  781. function dateToUtcArray(date) {
  782. return [
  783. date.getUTCFullYear(),
  784. date.getUTCMonth(),
  785. date.getUTCDate(),
  786. date.getUTCHours(),
  787. date.getUTCMinutes(),
  788. date.getUTCSeconds(),
  789. date.getUTCMilliseconds(),
  790. ];
  791. }
  792. function arrayToUtcDate(a) {
  793. // according to web standards (and Safari), a month index is required.
  794. // massage if only given a year.
  795. if (a.length === 1) {
  796. a = a.concat([0]);
  797. }
  798. return new Date(Date.UTC(...a));
  799. }
  800. // Other Utils
  801. function isValidDate(m) {
  802. return !isNaN(m.valueOf());
  803. }
  804. function timeAsMs(m) {
  805. return m.getUTCHours() * 1000 * 60 * 60 +
  806. m.getUTCMinutes() * 1000 * 60 +
  807. m.getUTCSeconds() * 1000 +
  808. m.getUTCMilliseconds();
  809. }
  810. // timeZoneOffset is in minutes
  811. function buildIsoString(marker, timeZoneOffset, stripZeroTime = false) {
  812. let s = marker.toISOString();
  813. s = s.replace('.000', '');
  814. if (stripZeroTime) {
  815. s = s.replace('T00:00:00Z', '');
  816. }
  817. if (s.length > 10) { // time part wasn't stripped, can add timezone info
  818. if (timeZoneOffset == null) {
  819. s = s.replace('Z', '');
  820. }
  821. else if (timeZoneOffset !== 0) {
  822. s = s.replace('Z', formatTimeZoneOffset(timeZoneOffset, true));
  823. }
  824. // otherwise, its UTC-0 and we want to keep the Z
  825. }
  826. return s;
  827. }
  828. // formats the date, but with no time part
  829. // TODO: somehow merge with buildIsoString and stripZeroTime
  830. // TODO: rename. omit "string"
  831. function formatDayString(marker) {
  832. return marker.toISOString().replace(/T.*$/, '');
  833. }
  834. function formatIsoMonthStr(marker) {
  835. return marker.toISOString().match(/^\d{4}-\d{2}/)[0];
  836. }
  837. // TODO: use Date::toISOString and use everything after the T?
  838. function formatIsoTimeString(marker) {
  839. return padStart(marker.getUTCHours(), 2) + ':' +
  840. padStart(marker.getUTCMinutes(), 2) + ':' +
  841. padStart(marker.getUTCSeconds(), 2);
  842. }
  843. function formatTimeZoneOffset(minutes, doIso = false) {
  844. let sign = minutes < 0 ? '-' : '+';
  845. let abs = Math.abs(minutes);
  846. let hours = Math.floor(abs / 60);
  847. let mins = Math.round(abs % 60);
  848. if (doIso) {
  849. return `${sign + padStart(hours, 2)}:${padStart(mins, 2)}`;
  850. }
  851. return `GMT${sign}${hours}${mins ? `:${padStart(mins, 2)}` : ''}`;
  852. }
  853. function memoize(workerFunc, resEquality, teardownFunc) {
  854. let currentArgs;
  855. let currentRes;
  856. return function (...newArgs) {
  857. if (!currentArgs) {
  858. currentRes = workerFunc.apply(this, newArgs);
  859. }
  860. else if (!isArraysEqual(currentArgs, newArgs)) {
  861. if (teardownFunc) {
  862. teardownFunc(currentRes);
  863. }
  864. let res = workerFunc.apply(this, newArgs);
  865. if (!resEquality || !resEquality(res, currentRes)) {
  866. currentRes = res;
  867. }
  868. }
  869. currentArgs = newArgs;
  870. return currentRes;
  871. };
  872. }
  873. function memoizeObjArg(workerFunc, resEquality, teardownFunc) {
  874. let currentArg;
  875. let currentRes;
  876. return (newArg) => {
  877. if (!currentArg) {
  878. currentRes = workerFunc.call(this, newArg);
  879. }
  880. else if (!isPropsEqual(currentArg, newArg)) {
  881. if (teardownFunc) {
  882. teardownFunc(currentRes);
  883. }
  884. let res = workerFunc.call(this, newArg);
  885. if (!resEquality || !resEquality(res, currentRes)) {
  886. currentRes = res;
  887. }
  888. }
  889. currentArg = newArg;
  890. return currentRes;
  891. };
  892. }
  893. function memoizeArraylike(// used at all?
  894. workerFunc, resEquality, teardownFunc) {
  895. let currentArgSets = [];
  896. let currentResults = [];
  897. return (newArgSets) => {
  898. let currentLen = currentArgSets.length;
  899. let newLen = newArgSets.length;
  900. let i = 0;
  901. for (; i < currentLen; i += 1) {
  902. if (!newArgSets[i]) { // one of the old sets no longer exists
  903. if (teardownFunc) {
  904. teardownFunc(currentResults[i]);
  905. }
  906. }
  907. else if (!isArraysEqual(currentArgSets[i], newArgSets[i])) {
  908. if (teardownFunc) {
  909. teardownFunc(currentResults[i]);
  910. }
  911. let res = workerFunc.apply(this, newArgSets[i]);
  912. if (!resEquality || !resEquality(res, currentResults[i])) {
  913. currentResults[i] = res;
  914. }
  915. }
  916. }
  917. for (; i < newLen; i += 1) {
  918. currentResults[i] = workerFunc.apply(this, newArgSets[i]);
  919. }
  920. currentArgSets = newArgSets;
  921. currentResults.splice(newLen); // remove excess
  922. return currentResults;
  923. };
  924. }
  925. function memoizeHashlike(workerFunc, resEquality, teardownFunc) {
  926. let currentArgHash = {};
  927. let currentResHash = {};
  928. return (newArgHash) => {
  929. let newResHash = {};
  930. for (let key in newArgHash) {
  931. if (!currentResHash[key]) {
  932. newResHash[key] = workerFunc.apply(this, newArgHash[key]);
  933. }
  934. else if (!isArraysEqual(currentArgHash[key], newArgHash[key])) {
  935. if (teardownFunc) {
  936. teardownFunc(currentResHash[key]);
  937. }
  938. let res = workerFunc.apply(this, newArgHash[key]);
  939. newResHash[key] = (resEquality && resEquality(res, currentResHash[key]))
  940. ? currentResHash[key]
  941. : res;
  942. }
  943. else {
  944. newResHash[key] = currentResHash[key];
  945. }
  946. }
  947. currentArgHash = newArgHash;
  948. currentResHash = newResHash;
  949. return newResHash;
  950. };
  951. }
  952. const EXTENDED_SETTINGS_AND_SEVERITIES = {
  953. week: 3,
  954. separator: 0,
  955. omitZeroMinute: 0,
  956. meridiem: 0,
  957. omitCommas: 0,
  958. };
  959. const STANDARD_DATE_PROP_SEVERITIES = {
  960. timeZoneName: 7,
  961. era: 6,
  962. year: 5,
  963. month: 4,
  964. day: 2,
  965. weekday: 2,
  966. hour: 1,
  967. minute: 1,
  968. second: 1,
  969. };
  970. const MERIDIEM_RE = /\s*([ap])\.?m\.?/i; // eats up leading spaces too
  971. const COMMA_RE = /,/g; // we need re for globalness
  972. const MULTI_SPACE_RE = /\s+/g;
  973. const LTR_RE = /\u200e/g; // control character
  974. const UTC_RE = /UTC|GMT/;
  975. class NativeFormatter {
  976. constructor(formatSettings) {
  977. let standardDateProps = {};
  978. let extendedSettings = {};
  979. let severity = 0;
  980. for (let name in formatSettings) {
  981. if (name in EXTENDED_SETTINGS_AND_SEVERITIES) {
  982. extendedSettings[name] = formatSettings[name];
  983. severity = Math.max(EXTENDED_SETTINGS_AND_SEVERITIES[name], severity);
  984. }
  985. else {
  986. standardDateProps[name] = formatSettings[name];
  987. if (name in STANDARD_DATE_PROP_SEVERITIES) { // TODO: what about hour12? no severity
  988. severity = Math.max(STANDARD_DATE_PROP_SEVERITIES[name], severity);
  989. }
  990. }
  991. }
  992. this.standardDateProps = standardDateProps;
  993. this.extendedSettings = extendedSettings;
  994. this.severity = severity;
  995. this.buildFormattingFunc = memoize(buildFormattingFunc);
  996. }
  997. format(date, context) {
  998. return this.buildFormattingFunc(this.standardDateProps, this.extendedSettings, context)(date);
  999. }
  1000. formatRange(start, end, context, betterDefaultSeparator) {
  1001. let { standardDateProps, extendedSettings } = this;
  1002. let diffSeverity = computeMarkerDiffSeverity(start.marker, end.marker, context.calendarSystem);
  1003. if (!diffSeverity) {
  1004. return this.format(start, context);
  1005. }
  1006. let biggestUnitForPartial = diffSeverity;
  1007. if (biggestUnitForPartial > 1 && // the two dates are different in a way that's larger scale than time
  1008. (standardDateProps.year === 'numeric' || standardDateProps.year === '2-digit') &&
  1009. (standardDateProps.month === 'numeric' || standardDateProps.month === '2-digit') &&
  1010. (standardDateProps.day === 'numeric' || standardDateProps.day === '2-digit')) {
  1011. biggestUnitForPartial = 1; // make it look like the dates are only different in terms of time
  1012. }
  1013. let full0 = this.format(start, context);
  1014. let full1 = this.format(end, context);
  1015. if (full0 === full1) {
  1016. return full0;
  1017. }
  1018. let partialDateProps = computePartialFormattingOptions(standardDateProps, biggestUnitForPartial);
  1019. let partialFormattingFunc = buildFormattingFunc(partialDateProps, extendedSettings, context);
  1020. let partial0 = partialFormattingFunc(start);
  1021. let partial1 = partialFormattingFunc(end);
  1022. let insertion = findCommonInsertion(full0, partial0, full1, partial1);
  1023. let separator = extendedSettings.separator || betterDefaultSeparator || context.defaultSeparator || '';
  1024. if (insertion) {
  1025. return insertion.before + partial0 + separator + partial1 + insertion.after;
  1026. }
  1027. return full0 + separator + full1;
  1028. }
  1029. getLargestUnit() {
  1030. switch (this.severity) {
  1031. case 7:
  1032. case 6:
  1033. case 5:
  1034. return 'year';
  1035. case 4:
  1036. return 'month';
  1037. case 3:
  1038. return 'week';
  1039. case 2:
  1040. return 'day';
  1041. default:
  1042. return 'time'; // really?
  1043. }
  1044. }
  1045. }
  1046. function buildFormattingFunc(standardDateProps, extendedSettings, context) {
  1047. let standardDatePropCnt = Object.keys(standardDateProps).length;
  1048. if (standardDatePropCnt === 1 && standardDateProps.timeZoneName === 'short') {
  1049. return (date) => (formatTimeZoneOffset(date.timeZoneOffset));
  1050. }
  1051. if (standardDatePropCnt === 0 && extendedSettings.week) {
  1052. return (date) => (formatWeekNumber(context.computeWeekNumber(date.marker), context.weekText, context.weekTextLong, context.locale, extendedSettings.week));
  1053. }
  1054. return buildNativeFormattingFunc(standardDateProps, extendedSettings, context);
  1055. }
  1056. function buildNativeFormattingFunc(standardDateProps, extendedSettings, context) {
  1057. standardDateProps = Object.assign({}, standardDateProps); // copy
  1058. extendedSettings = Object.assign({}, extendedSettings); // copy
  1059. sanitizeSettings(standardDateProps, extendedSettings);
  1060. standardDateProps.timeZone = 'UTC'; // we leverage the only guaranteed timeZone for our UTC markers
  1061. let normalFormat = new Intl.DateTimeFormat(context.locale.codes, standardDateProps);
  1062. let zeroFormat; // needed?
  1063. if (extendedSettings.omitZeroMinute) {
  1064. let zeroProps = Object.assign({}, standardDateProps);
  1065. delete zeroProps.minute; // seconds and ms were already considered in sanitizeSettings
  1066. zeroFormat = new Intl.DateTimeFormat(context.locale.codes, zeroProps);
  1067. }
  1068. return (date) => {
  1069. let { marker } = date;
  1070. let format;
  1071. if (zeroFormat && !marker.getUTCMinutes()) {
  1072. format = zeroFormat;
  1073. }
  1074. else {
  1075. format = normalFormat;
  1076. }
  1077. let s = format.format(marker);
  1078. return postProcess(s, date, standardDateProps, extendedSettings, context);
  1079. };
  1080. }
  1081. function sanitizeSettings(standardDateProps, extendedSettings) {
  1082. // deal with a browser inconsistency where formatting the timezone
  1083. // requires that the hour/minute be present.
  1084. if (standardDateProps.timeZoneName) {
  1085. if (!standardDateProps.hour) {
  1086. standardDateProps.hour = '2-digit';
  1087. }
  1088. if (!standardDateProps.minute) {
  1089. standardDateProps.minute = '2-digit';
  1090. }
  1091. }
  1092. // only support short timezone names
  1093. if (standardDateProps.timeZoneName === 'long') {
  1094. standardDateProps.timeZoneName = 'short';
  1095. }
  1096. // if requesting to display seconds, MUST display minutes
  1097. if (extendedSettings.omitZeroMinute && (standardDateProps.second || standardDateProps.millisecond)) {
  1098. delete extendedSettings.omitZeroMinute;
  1099. }
  1100. }
  1101. function postProcess(s, date, standardDateProps, extendedSettings, context) {
  1102. s = s.replace(LTR_RE, ''); // remove left-to-right control chars. do first. good for other regexes
  1103. if (standardDateProps.timeZoneName === 'short') {
  1104. s = injectTzoStr(s, (context.timeZone === 'UTC' || date.timeZoneOffset == null) ?
  1105. 'UTC' : // important to normalize for IE, which does "GMT"
  1106. formatTimeZoneOffset(date.timeZoneOffset));
  1107. }
  1108. if (extendedSettings.omitCommas) {
  1109. s = s.replace(COMMA_RE, '').trim();
  1110. }
  1111. if (extendedSettings.omitZeroMinute) {
  1112. s = s.replace(':00', ''); // zeroFormat doesn't always achieve this
  1113. }
  1114. // ^ do anything that might create adjacent spaces before this point,
  1115. // because MERIDIEM_RE likes to eat up loading spaces
  1116. if (extendedSettings.meridiem === false) {
  1117. s = s.replace(MERIDIEM_RE, '').trim();
  1118. }
  1119. else if (extendedSettings.meridiem === 'narrow') { // a/p
  1120. s = s.replace(MERIDIEM_RE, (m0, m1) => m1.toLocaleLowerCase());
  1121. }
  1122. else if (extendedSettings.meridiem === 'short') { // am/pm
  1123. s = s.replace(MERIDIEM_RE, (m0, m1) => `${m1.toLocaleLowerCase()}m`);
  1124. }
  1125. else if (extendedSettings.meridiem === 'lowercase') { // other meridiem transformers already converted to lowercase
  1126. s = s.replace(MERIDIEM_RE, (m0) => m0.toLocaleLowerCase());
  1127. }
  1128. s = s.replace(MULTI_SPACE_RE, ' ');
  1129. s = s.trim();
  1130. return s;
  1131. }
  1132. function injectTzoStr(s, tzoStr) {
  1133. let replaced = false;
  1134. s = s.replace(UTC_RE, () => {
  1135. replaced = true;
  1136. return tzoStr;
  1137. });
  1138. // IE11 doesn't include UTC/GMT in the original string, so append to end
  1139. if (!replaced) {
  1140. s += ` ${tzoStr}`;
  1141. }
  1142. return s;
  1143. }
  1144. function formatWeekNumber(num, weekText, weekTextLong, locale, display) {
  1145. let parts = [];
  1146. if (display === 'long') {
  1147. parts.push(weekTextLong);
  1148. }
  1149. else if (display === 'short' || display === 'narrow') {
  1150. parts.push(weekText);
  1151. }
  1152. if (display === 'long' || display === 'short') {
  1153. parts.push(' ');
  1154. }
  1155. parts.push(locale.simpleNumberFormat.format(num));
  1156. if (locale.options.direction === 'rtl') { // TODO: use control characters instead?
  1157. parts.reverse();
  1158. }
  1159. return parts.join('');
  1160. }
  1161. // Range Formatting Utils
  1162. // 0 = exactly the same
  1163. // 1 = different by time
  1164. // and bigger
  1165. function computeMarkerDiffSeverity(d0, d1, ca) {
  1166. if (ca.getMarkerYear(d0) !== ca.getMarkerYear(d1)) {
  1167. return 5;
  1168. }
  1169. if (ca.getMarkerMonth(d0) !== ca.getMarkerMonth(d1)) {
  1170. return 4;
  1171. }
  1172. if (ca.getMarkerDay(d0) !== ca.getMarkerDay(d1)) {
  1173. return 2;
  1174. }
  1175. if (timeAsMs(d0) !== timeAsMs(d1)) {
  1176. return 1;
  1177. }
  1178. return 0;
  1179. }
  1180. function computePartialFormattingOptions(options, biggestUnit) {
  1181. let partialOptions = {};
  1182. for (let name in options) {
  1183. if (!(name in STANDARD_DATE_PROP_SEVERITIES) || // not a date part prop (like timeZone)
  1184. STANDARD_DATE_PROP_SEVERITIES[name] <= biggestUnit) {
  1185. partialOptions[name] = options[name];
  1186. }
  1187. }
  1188. return partialOptions;
  1189. }
  1190. function findCommonInsertion(full0, partial0, full1, partial1) {
  1191. let i0 = 0;
  1192. while (i0 < full0.length) {
  1193. let found0 = full0.indexOf(partial0, i0);
  1194. if (found0 === -1) {
  1195. break;
  1196. }
  1197. let before0 = full0.substr(0, found0);
  1198. i0 = found0 + partial0.length;
  1199. let after0 = full0.substr(i0);
  1200. let i1 = 0;
  1201. while (i1 < full1.length) {
  1202. let found1 = full1.indexOf(partial1, i1);
  1203. if (found1 === -1) {
  1204. break;
  1205. }
  1206. let before1 = full1.substr(0, found1);
  1207. i1 = found1 + partial1.length;
  1208. let after1 = full1.substr(i1);
  1209. if (before0 === before1 && after0 === after1) {
  1210. return {
  1211. before: before0,
  1212. after: after0,
  1213. };
  1214. }
  1215. }
  1216. }
  1217. return null;
  1218. }
  1219. function expandZonedMarker(dateInfo, calendarSystem) {
  1220. let a = calendarSystem.markerToArray(dateInfo.marker);
  1221. return {
  1222. marker: dateInfo.marker,
  1223. timeZoneOffset: dateInfo.timeZoneOffset,
  1224. array: a,
  1225. year: a[0],
  1226. month: a[1],
  1227. day: a[2],
  1228. hour: a[3],
  1229. minute: a[4],
  1230. second: a[5],
  1231. millisecond: a[6],
  1232. };
  1233. }
  1234. function createVerboseFormattingArg(start, end, context, betterDefaultSeparator) {
  1235. let startInfo = expandZonedMarker(start, context.calendarSystem);
  1236. let endInfo = end ? expandZonedMarker(end, context.calendarSystem) : null;
  1237. return {
  1238. date: startInfo,
  1239. start: startInfo,
  1240. end: endInfo,
  1241. timeZone: context.timeZone,
  1242. localeCodes: context.locale.codes,
  1243. defaultSeparator: betterDefaultSeparator || context.defaultSeparator,
  1244. };
  1245. }
  1246. /*
  1247. TODO: fix the terminology of "formatter" vs "formatting func"
  1248. */
  1249. /*
  1250. At the time of instantiation, this object does not know which cmd-formatting system it will use.
  1251. It receives this at the time of formatting, as a setting.
  1252. */
  1253. class CmdFormatter {
  1254. constructor(cmdStr) {
  1255. this.cmdStr = cmdStr;
  1256. }
  1257. format(date, context, betterDefaultSeparator) {
  1258. return context.cmdFormatter(this.cmdStr, createVerboseFormattingArg(date, null, context, betterDefaultSeparator));
  1259. }
  1260. formatRange(start, end, context, betterDefaultSeparator) {
  1261. return context.cmdFormatter(this.cmdStr, createVerboseFormattingArg(start, end, context, betterDefaultSeparator));
  1262. }
  1263. }
  1264. class FuncFormatter {
  1265. constructor(func) {
  1266. this.func = func;
  1267. }
  1268. format(date, context, betterDefaultSeparator) {
  1269. return this.func(createVerboseFormattingArg(date, null, context, betterDefaultSeparator));
  1270. }
  1271. formatRange(start, end, context, betterDefaultSeparator) {
  1272. return this.func(createVerboseFormattingArg(start, end, context, betterDefaultSeparator));
  1273. }
  1274. }
  1275. function createFormatter(input) {
  1276. if (typeof input === 'object' && input) { // non-null object
  1277. return new NativeFormatter(input);
  1278. }
  1279. if (typeof input === 'string') {
  1280. return new CmdFormatter(input);
  1281. }
  1282. if (typeof input === 'function') {
  1283. return new FuncFormatter(input);
  1284. }
  1285. return null;
  1286. }
  1287. // base options
  1288. // ------------
  1289. const BASE_OPTION_REFINERS = {
  1290. navLinkDayClick: identity,
  1291. navLinkWeekClick: identity,
  1292. duration: createDuration,
  1293. bootstrapFontAwesome: identity,
  1294. buttonIcons: identity,
  1295. customButtons: identity,
  1296. defaultAllDayEventDuration: createDuration,
  1297. defaultTimedEventDuration: createDuration,
  1298. nextDayThreshold: createDuration,
  1299. scrollTime: createDuration,
  1300. scrollTimeReset: Boolean,
  1301. slotMinTime: createDuration,
  1302. slotMaxTime: createDuration,
  1303. dayPopoverFormat: createFormatter,
  1304. slotDuration: createDuration,
  1305. snapDuration: createDuration,
  1306. headerToolbar: identity,
  1307. footerToolbar: identity,
  1308. defaultRangeSeparator: String,
  1309. titleRangeSeparator: String,
  1310. forceEventDuration: Boolean,
  1311. dayHeaders: Boolean,
  1312. dayHeaderFormat: createFormatter,
  1313. dayHeaderClassNames: identity,
  1314. dayHeaderContent: identity,
  1315. dayHeaderDidMount: identity,
  1316. dayHeaderWillUnmount: identity,
  1317. dayCellClassNames: identity,
  1318. dayCellContent: identity,
  1319. dayCellDidMount: identity,
  1320. dayCellWillUnmount: identity,
  1321. initialView: String,
  1322. aspectRatio: Number,
  1323. weekends: Boolean,
  1324. weekNumberCalculation: identity,
  1325. weekNumbers: Boolean,
  1326. weekNumberClassNames: identity,
  1327. weekNumberContent: identity,
  1328. weekNumberDidMount: identity,
  1329. weekNumberWillUnmount: identity,
  1330. editable: Boolean,
  1331. viewClassNames: identity,
  1332. viewDidMount: identity,
  1333. viewWillUnmount: identity,
  1334. nowIndicator: Boolean,
  1335. nowIndicatorClassNames: identity,
  1336. nowIndicatorContent: identity,
  1337. nowIndicatorDidMount: identity,
  1338. nowIndicatorWillUnmount: identity,
  1339. showNonCurrentDates: Boolean,
  1340. lazyFetching: Boolean,
  1341. startParam: String,
  1342. endParam: String,
  1343. timeZoneParam: String,
  1344. timeZone: String,
  1345. locales: identity,
  1346. locale: identity,
  1347. themeSystem: String,
  1348. dragRevertDuration: Number,
  1349. dragScroll: Boolean,
  1350. allDayMaintainDuration: Boolean,
  1351. unselectAuto: Boolean,
  1352. dropAccept: identity,
  1353. eventOrder: parseFieldSpecs,
  1354. eventOrderStrict: Boolean,
  1355. handleWindowResize: Boolean,
  1356. windowResizeDelay: Number,
  1357. longPressDelay: Number,
  1358. eventDragMinDistance: Number,
  1359. expandRows: Boolean,
  1360. height: identity,
  1361. contentHeight: identity,
  1362. direction: String,
  1363. weekNumberFormat: createFormatter,
  1364. eventResizableFromStart: Boolean,
  1365. displayEventTime: Boolean,
  1366. displayEventEnd: Boolean,
  1367. weekText: String,
  1368. weekTextLong: String,
  1369. progressiveEventRendering: Boolean,
  1370. businessHours: identity,
  1371. initialDate: identity,
  1372. now: identity,
  1373. eventDataTransform: identity,
  1374. stickyHeaderDates: identity,
  1375. stickyFooterScrollbar: identity,
  1376. viewHeight: identity,
  1377. defaultAllDay: Boolean,
  1378. eventSourceFailure: identity,
  1379. eventSourceSuccess: identity,
  1380. eventDisplay: String,
  1381. eventStartEditable: Boolean,
  1382. eventDurationEditable: Boolean,
  1383. eventOverlap: identity,
  1384. eventConstraint: identity,
  1385. eventAllow: identity,
  1386. eventBackgroundColor: String,
  1387. eventBorderColor: String,
  1388. eventTextColor: String,
  1389. eventColor: String,
  1390. eventClassNames: identity,
  1391. eventContent: identity,
  1392. eventDidMount: identity,
  1393. eventWillUnmount: identity,
  1394. selectConstraint: identity,
  1395. selectOverlap: identity,
  1396. selectAllow: identity,
  1397. droppable: Boolean,
  1398. unselectCancel: String,
  1399. slotLabelFormat: identity,
  1400. slotLaneClassNames: identity,
  1401. slotLaneContent: identity,
  1402. slotLaneDidMount: identity,
  1403. slotLaneWillUnmount: identity,
  1404. slotLabelClassNames: identity,
  1405. slotLabelContent: identity,
  1406. slotLabelDidMount: identity,
  1407. slotLabelWillUnmount: identity,
  1408. dayMaxEvents: identity,
  1409. dayMaxEventRows: identity,
  1410. dayMinWidth: Number,
  1411. slotLabelInterval: createDuration,
  1412. allDayText: String,
  1413. allDayClassNames: identity,
  1414. allDayContent: identity,
  1415. allDayDidMount: identity,
  1416. allDayWillUnmount: identity,
  1417. slotMinWidth: Number,
  1418. navLinks: Boolean,
  1419. eventTimeFormat: createFormatter,
  1420. rerenderDelay: Number,
  1421. moreLinkText: identity,
  1422. moreLinkHint: identity,
  1423. selectMinDistance: Number,
  1424. selectable: Boolean,
  1425. selectLongPressDelay: Number,
  1426. eventLongPressDelay: Number,
  1427. selectMirror: Boolean,
  1428. eventMaxStack: Number,
  1429. eventMinHeight: Number,
  1430. eventMinWidth: Number,
  1431. eventShortHeight: Number,
  1432. slotEventOverlap: Boolean,
  1433. plugins: identity,
  1434. firstDay: Number,
  1435. dayCount: Number,
  1436. dateAlignment: String,
  1437. dateIncrement: createDuration,
  1438. hiddenDays: identity,
  1439. fixedWeekCount: Boolean,
  1440. validRange: identity,
  1441. visibleRange: identity,
  1442. titleFormat: identity,
  1443. eventInteractive: Boolean,
  1444. // only used by list-view, but languages define the value, so we need it in base options
  1445. noEventsText: String,
  1446. viewHint: identity,
  1447. navLinkHint: identity,
  1448. closeHint: String,
  1449. timeHint: String,
  1450. eventHint: String,
  1451. moreLinkClick: identity,
  1452. moreLinkClassNames: identity,
  1453. moreLinkContent: identity,
  1454. moreLinkDidMount: identity,
  1455. moreLinkWillUnmount: identity,
  1456. monthStartFormat: createFormatter,
  1457. // for connectors
  1458. // (can't be part of plugin system b/c must be provided at runtime)
  1459. handleCustomRendering: identity,
  1460. customRenderingMetaMap: identity,
  1461. customRenderingReplaces: Boolean,
  1462. };
  1463. // do NOT give a type here. need `typeof BASE_OPTION_DEFAULTS` to give real results.
  1464. // raw values.
  1465. const BASE_OPTION_DEFAULTS = {
  1466. eventDisplay: 'auto',
  1467. defaultRangeSeparator: ' - ',
  1468. titleRangeSeparator: ' \u2013 ',
  1469. defaultTimedEventDuration: '01:00:00',
  1470. defaultAllDayEventDuration: { day: 1 },
  1471. forceEventDuration: false,
  1472. nextDayThreshold: '00:00:00',
  1473. dayHeaders: true,
  1474. initialView: '',
  1475. aspectRatio: 1.35,
  1476. headerToolbar: {
  1477. start: 'title',
  1478. center: '',
  1479. end: 'today prev,next',
  1480. },
  1481. weekends: true,
  1482. weekNumbers: false,
  1483. weekNumberCalculation: 'local',
  1484. editable: false,
  1485. nowIndicator: false,
  1486. scrollTime: '06:00:00',
  1487. scrollTimeReset: true,
  1488. slotMinTime: '00:00:00',
  1489. slotMaxTime: '24:00:00',
  1490. showNonCurrentDates: true,
  1491. lazyFetching: true,
  1492. startParam: 'start',
  1493. endParam: 'end',
  1494. timeZoneParam: 'timeZone',
  1495. timeZone: 'local',
  1496. locales: [],
  1497. locale: '',
  1498. themeSystem: 'standard',
  1499. dragRevertDuration: 500,
  1500. dragScroll: true,
  1501. allDayMaintainDuration: false,
  1502. unselectAuto: true,
  1503. dropAccept: '*',
  1504. eventOrder: 'start,-duration,allDay,title',
  1505. dayPopoverFormat: { month: 'long', day: 'numeric', year: 'numeric' },
  1506. handleWindowResize: true,
  1507. windowResizeDelay: 100,
  1508. longPressDelay: 1000,
  1509. eventDragMinDistance: 5,
  1510. expandRows: false,
  1511. navLinks: false,
  1512. selectable: false,
  1513. eventMinHeight: 15,
  1514. eventMinWidth: 30,
  1515. eventShortHeight: 30,
  1516. monthStartFormat: { month: 'long', day: 'numeric' },
  1517. };
  1518. // calendar listeners
  1519. // ------------------
  1520. const CALENDAR_LISTENER_REFINERS = {
  1521. datesSet: identity,
  1522. eventsSet: identity,
  1523. eventAdd: identity,
  1524. eventChange: identity,
  1525. eventRemove: identity,
  1526. windowResize: identity,
  1527. eventClick: identity,
  1528. eventMouseEnter: identity,
  1529. eventMouseLeave: identity,
  1530. select: identity,
  1531. unselect: identity,
  1532. loading: identity,
  1533. // internal
  1534. _unmount: identity,
  1535. _beforeprint: identity,
  1536. _afterprint: identity,
  1537. _noEventDrop: identity,
  1538. _noEventResize: identity,
  1539. _resize: identity,
  1540. _scrollRequest: identity,
  1541. };
  1542. // calendar-specific options
  1543. // -------------------------
  1544. const CALENDAR_OPTION_REFINERS = {
  1545. buttonText: identity,
  1546. buttonHints: identity,
  1547. views: identity,
  1548. plugins: identity,
  1549. initialEvents: identity,
  1550. events: identity,
  1551. eventSources: identity,
  1552. };
  1553. const COMPLEX_OPTION_COMPARATORS = {
  1554. headerToolbar: isMaybeObjectsEqual,
  1555. footerToolbar: isMaybeObjectsEqual,
  1556. buttonText: isMaybeObjectsEqual,
  1557. buttonHints: isMaybeObjectsEqual,
  1558. buttonIcons: isMaybeObjectsEqual,
  1559. dateIncrement: isMaybeObjectsEqual,
  1560. plugins: isMaybeArraysEqual,
  1561. events: isMaybeArraysEqual,
  1562. eventSources: isMaybeArraysEqual,
  1563. ['resources']: isMaybeArraysEqual,
  1564. };
  1565. function isMaybeObjectsEqual(a, b) {
  1566. if (typeof a === 'object' && typeof b === 'object' && a && b) { // both non-null objects
  1567. return isPropsEqual(a, b);
  1568. }
  1569. return a === b;
  1570. }
  1571. function isMaybeArraysEqual(a, b) {
  1572. if (Array.isArray(a) && Array.isArray(b)) {
  1573. return isArraysEqual(a, b);
  1574. }
  1575. return a === b;
  1576. }
  1577. // view-specific options
  1578. // ---------------------
  1579. const VIEW_OPTION_REFINERS = {
  1580. type: String,
  1581. component: identity,
  1582. buttonText: String,
  1583. buttonTextKey: String,
  1584. dateProfileGeneratorClass: identity,
  1585. usesMinMaxTime: Boolean,
  1586. classNames: identity,
  1587. content: identity,
  1588. didMount: identity,
  1589. willUnmount: identity,
  1590. };
  1591. // util funcs
  1592. // ----------------------------------------------------------------------------------------------------
  1593. function mergeRawOptions(optionSets) {
  1594. return mergeProps(optionSets, COMPLEX_OPTION_COMPARATORS);
  1595. }
  1596. function refineProps(input, refiners) {
  1597. let refined = {};
  1598. let extra = {};
  1599. for (let propName in refiners) {
  1600. if (propName in input) {
  1601. refined[propName] = refiners[propName](input[propName]);
  1602. }
  1603. }
  1604. for (let propName in input) {
  1605. if (!(propName in refiners)) {
  1606. extra[propName] = input[propName];
  1607. }
  1608. }
  1609. return { refined, extra };
  1610. }
  1611. function identity(raw) {
  1612. return raw;
  1613. }
  1614. const { hasOwnProperty } = Object.prototype;
  1615. // Merges an array of objects into a single object.
  1616. // The second argument allows for an array of property names who's object values will be merged together.
  1617. function mergeProps(propObjs, complexPropsMap) {
  1618. let dest = {};
  1619. if (complexPropsMap) {
  1620. for (let name in complexPropsMap) {
  1621. if (complexPropsMap[name] === isMaybeObjectsEqual) { // implies that it's object-mergeable
  1622. let complexObjs = [];
  1623. // collect the trailing object values, stopping when a non-object is discovered
  1624. for (let i = propObjs.length - 1; i >= 0; i -= 1) {
  1625. let val = propObjs[i][name];
  1626. if (typeof val === 'object' && val) { // non-null object
  1627. complexObjs.unshift(val);
  1628. }
  1629. else if (val !== undefined) {
  1630. dest[name] = val; // if there were no objects, this value will be used
  1631. break;
  1632. }
  1633. }
  1634. // if the trailing values were objects, use the merged value
  1635. if (complexObjs.length) {
  1636. dest[name] = mergeProps(complexObjs);
  1637. }
  1638. }
  1639. }
  1640. }
  1641. // copy values into the destination, going from last to first
  1642. for (let i = propObjs.length - 1; i >= 0; i -= 1) {
  1643. let props = propObjs[i];
  1644. for (let name in props) {
  1645. if (!(name in dest)) { // if already assigned by previous props or complex props, don't reassign
  1646. dest[name] = props[name];
  1647. }
  1648. }
  1649. }
  1650. return dest;
  1651. }
  1652. function filterHash(hash, func) {
  1653. let filtered = {};
  1654. for (let key in hash) {
  1655. if (func(hash[key], key)) {
  1656. filtered[key] = hash[key];
  1657. }
  1658. }
  1659. return filtered;
  1660. }
  1661. function mapHash(hash, func) {
  1662. let newHash = {};
  1663. for (let key in hash) {
  1664. newHash[key] = func(hash[key], key);
  1665. }
  1666. return newHash;
  1667. }
  1668. function arrayToHash(a) {
  1669. let hash = {};
  1670. for (let item of a) {
  1671. hash[item] = true;
  1672. }
  1673. return hash;
  1674. }
  1675. // TODO: reassess browser support
  1676. // https://caniuse.com/?search=object.values
  1677. function hashValuesToArray(obj) {
  1678. let a = [];
  1679. for (let key in obj) {
  1680. a.push(obj[key]);
  1681. }
  1682. return a;
  1683. }
  1684. function isPropsEqual(obj0, obj1) {
  1685. if (obj0 === obj1) {
  1686. return true;
  1687. }
  1688. for (let key in obj0) {
  1689. if (hasOwnProperty.call(obj0, key)) {
  1690. if (!(key in obj1)) {
  1691. return false;
  1692. }
  1693. }
  1694. }
  1695. for (let key in obj1) {
  1696. if (hasOwnProperty.call(obj1, key)) {
  1697. if (obj0[key] !== obj1[key]) {
  1698. return false;
  1699. }
  1700. }
  1701. }
  1702. return true;
  1703. }
  1704. const HANDLER_RE = /^on[A-Z]/;
  1705. function isNonHandlerPropsEqual(obj0, obj1) {
  1706. const keys = getUnequalProps(obj0, obj1);
  1707. for (let key of keys) {
  1708. if (!HANDLER_RE.test(key)) {
  1709. return false;
  1710. }
  1711. }
  1712. return true;
  1713. }
  1714. function getUnequalProps(obj0, obj1) {
  1715. let keys = [];
  1716. for (let key in obj0) {
  1717. if (hasOwnProperty.call(obj0, key)) {
  1718. if (!(key in obj1)) {
  1719. keys.push(key);
  1720. }
  1721. }
  1722. }
  1723. for (let key in obj1) {
  1724. if (hasOwnProperty.call(obj1, key)) {
  1725. if (obj0[key] !== obj1[key]) {
  1726. keys.push(key);
  1727. }
  1728. }
  1729. }
  1730. return keys;
  1731. }
  1732. function compareObjs(oldProps, newProps, equalityFuncs = {}) {
  1733. if (oldProps === newProps) {
  1734. return true;
  1735. }
  1736. for (let key in newProps) {
  1737. if (key in oldProps && isObjValsEqual(oldProps[key], newProps[key], equalityFuncs[key])) ;
  1738. else {
  1739. return false;
  1740. }
  1741. }
  1742. // check for props that were omitted in the new
  1743. for (let key in oldProps) {
  1744. if (!(key in newProps)) {
  1745. return false;
  1746. }
  1747. }
  1748. return true;
  1749. }
  1750. /*
  1751. assumed "true" equality for handler names like "onReceiveSomething"
  1752. */
  1753. function isObjValsEqual(val0, val1, comparator) {
  1754. if (val0 === val1 || comparator === true) {
  1755. return true;
  1756. }
  1757. if (comparator) {
  1758. return comparator(val0, val1);
  1759. }
  1760. return false;
  1761. }
  1762. function collectFromHash(hash, startIndex = 0, endIndex, step = 1) {
  1763. let res = [];
  1764. if (endIndex == null) {
  1765. endIndex = Object.keys(hash).length;
  1766. }
  1767. for (let i = startIndex; i < endIndex; i += step) {
  1768. let val = hash[i];
  1769. if (val !== undefined) { // will disregard undefined for sparse arrays
  1770. res.push(val);
  1771. }
  1772. }
  1773. return res;
  1774. }
  1775. let calendarSystemClassMap = {};
  1776. function registerCalendarSystem(name, theClass) {
  1777. calendarSystemClassMap[name] = theClass;
  1778. }
  1779. function createCalendarSystem(name) {
  1780. return new calendarSystemClassMap[name]();
  1781. }
  1782. class GregorianCalendarSystem {
  1783. getMarkerYear(d) {
  1784. return d.getUTCFullYear();
  1785. }
  1786. getMarkerMonth(d) {
  1787. return d.getUTCMonth();
  1788. }
  1789. getMarkerDay(d) {
  1790. return d.getUTCDate();
  1791. }
  1792. arrayToMarker(arr) {
  1793. return arrayToUtcDate(arr);
  1794. }
  1795. markerToArray(marker) {
  1796. return dateToUtcArray(marker);
  1797. }
  1798. }
  1799. registerCalendarSystem('gregory', GregorianCalendarSystem);
  1800. const ISO_RE = /^\s*(\d{4})(-?(\d{2})(-?(\d{2})([T ](\d{2}):?(\d{2})(:?(\d{2})(\.(\d+))?)?(Z|(([-+])(\d{2})(:?(\d{2}))?))?)?)?)?$/;
  1801. function parse(str) {
  1802. let m = ISO_RE.exec(str);
  1803. if (m) {
  1804. let 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));
  1805. if (isValidDate(marker)) {
  1806. let timeZoneOffset = null;
  1807. if (m[13]) {
  1808. timeZoneOffset = (m[15] === '-' ? -1 : 1) * (Number(m[16] || 0) * 60 +
  1809. Number(m[18] || 0));
  1810. }
  1811. return {
  1812. marker,
  1813. isTimeUnspecified: !m[6],
  1814. timeZoneOffset,
  1815. };
  1816. }
  1817. }
  1818. return null;
  1819. }
  1820. class DateEnv {
  1821. constructor(settings) {
  1822. let timeZone = this.timeZone = settings.timeZone;
  1823. let isNamedTimeZone = timeZone !== 'local' && timeZone !== 'UTC';
  1824. if (settings.namedTimeZoneImpl && isNamedTimeZone) {
  1825. this.namedTimeZoneImpl = new settings.namedTimeZoneImpl(timeZone);
  1826. }
  1827. this.canComputeOffset = Boolean(!isNamedTimeZone || this.namedTimeZoneImpl);
  1828. this.calendarSystem = createCalendarSystem(settings.calendarSystem);
  1829. this.locale = settings.locale;
  1830. this.weekDow = settings.locale.week.dow;
  1831. this.weekDoy = settings.locale.week.doy;
  1832. if (settings.weekNumberCalculation === 'ISO') {
  1833. this.weekDow = 1;
  1834. this.weekDoy = 4;
  1835. }
  1836. if (typeof settings.firstDay === 'number') {
  1837. this.weekDow = settings.firstDay;
  1838. }
  1839. if (typeof settings.weekNumberCalculation === 'function') {
  1840. this.weekNumberFunc = settings.weekNumberCalculation;
  1841. }
  1842. this.weekText = settings.weekText != null ? settings.weekText : settings.locale.options.weekText;
  1843. this.weekTextLong = (settings.weekTextLong != null ? settings.weekTextLong : settings.locale.options.weekTextLong) || this.weekText;
  1844. this.cmdFormatter = settings.cmdFormatter;
  1845. this.defaultSeparator = settings.defaultSeparator;
  1846. }
  1847. // Creating / Parsing
  1848. createMarker(input) {
  1849. let meta = this.createMarkerMeta(input);
  1850. if (meta === null) {
  1851. return null;
  1852. }
  1853. return meta.marker;
  1854. }
  1855. createNowMarker() {
  1856. if (this.canComputeOffset) {
  1857. return this.timestampToMarker(new Date().valueOf());
  1858. }
  1859. // if we can't compute the current date val for a timezone,
  1860. // better to give the current local date vals than UTC
  1861. return arrayToUtcDate(dateToLocalArray(new Date()));
  1862. }
  1863. createMarkerMeta(input) {
  1864. if (typeof input === 'string') {
  1865. return this.parse(input);
  1866. }
  1867. let marker = null;
  1868. if (typeof input === 'number') {
  1869. marker = this.timestampToMarker(input);
  1870. }
  1871. else if (input instanceof Date) {
  1872. input = input.valueOf();
  1873. if (!isNaN(input)) {
  1874. marker = this.timestampToMarker(input);
  1875. }
  1876. }
  1877. else if (Array.isArray(input)) {
  1878. marker = arrayToUtcDate(input);
  1879. }
  1880. if (marker === null || !isValidDate(marker)) {
  1881. return null;
  1882. }
  1883. return { marker, isTimeUnspecified: false, forcedTzo: null };
  1884. }
  1885. parse(s) {
  1886. let parts = parse(s);
  1887. if (parts === null) {
  1888. return null;
  1889. }
  1890. let { marker } = parts;
  1891. let forcedTzo = null;
  1892. if (parts.timeZoneOffset !== null) {
  1893. if (this.canComputeOffset) {
  1894. marker = this.timestampToMarker(marker.valueOf() - parts.timeZoneOffset * 60 * 1000);
  1895. }
  1896. else {
  1897. forcedTzo = parts.timeZoneOffset;
  1898. }
  1899. }
  1900. return { marker, isTimeUnspecified: parts.isTimeUnspecified, forcedTzo };
  1901. }
  1902. // Accessors
  1903. getYear(marker) {
  1904. return this.calendarSystem.getMarkerYear(marker);
  1905. }
  1906. getMonth(marker) {
  1907. return this.calendarSystem.getMarkerMonth(marker);
  1908. }
  1909. getDay(marker) {
  1910. return this.calendarSystem.getMarkerDay(marker);
  1911. }
  1912. // Adding / Subtracting
  1913. add(marker, dur) {
  1914. let a = this.calendarSystem.markerToArray(marker);
  1915. a[0] += dur.years;
  1916. a[1] += dur.months;
  1917. a[2] += dur.days;
  1918. a[6] += dur.milliseconds;
  1919. return this.calendarSystem.arrayToMarker(a);
  1920. }
  1921. subtract(marker, dur) {
  1922. let a = this.calendarSystem.markerToArray(marker);
  1923. a[0] -= dur.years;
  1924. a[1] -= dur.months;
  1925. a[2] -= dur.days;
  1926. a[6] -= dur.milliseconds;
  1927. return this.calendarSystem.arrayToMarker(a);
  1928. }
  1929. addYears(marker, n) {
  1930. let a = this.calendarSystem.markerToArray(marker);
  1931. a[0] += n;
  1932. return this.calendarSystem.arrayToMarker(a);
  1933. }
  1934. addMonths(marker, n) {
  1935. let a = this.calendarSystem.markerToArray(marker);
  1936. a[1] += n;
  1937. return this.calendarSystem.arrayToMarker(a);
  1938. }
  1939. // Diffing Whole Units
  1940. diffWholeYears(m0, m1) {
  1941. let { calendarSystem } = this;
  1942. if (timeAsMs(m0) === timeAsMs(m1) &&
  1943. calendarSystem.getMarkerDay(m0) === calendarSystem.getMarkerDay(m1) &&
  1944. calendarSystem.getMarkerMonth(m0) === calendarSystem.getMarkerMonth(m1)) {
  1945. return calendarSystem.getMarkerYear(m1) - calendarSystem.getMarkerYear(m0);
  1946. }
  1947. return null;
  1948. }
  1949. diffWholeMonths(m0, m1) {
  1950. let { calendarSystem } = this;
  1951. if (timeAsMs(m0) === timeAsMs(m1) &&
  1952. calendarSystem.getMarkerDay(m0) === calendarSystem.getMarkerDay(m1)) {
  1953. return (calendarSystem.getMarkerMonth(m1) - calendarSystem.getMarkerMonth(m0)) +
  1954. (calendarSystem.getMarkerYear(m1) - calendarSystem.getMarkerYear(m0)) * 12;
  1955. }
  1956. return null;
  1957. }
  1958. // Range / Duration
  1959. greatestWholeUnit(m0, m1) {
  1960. let n = this.diffWholeYears(m0, m1);
  1961. if (n !== null) {
  1962. return { unit: 'year', value: n };
  1963. }
  1964. n = this.diffWholeMonths(m0, m1);
  1965. if (n !== null) {
  1966. return { unit: 'month', value: n };
  1967. }
  1968. n = diffWholeWeeks(m0, m1);
  1969. if (n !== null) {
  1970. return { unit: 'week', value: n };
  1971. }
  1972. n = diffWholeDays(m0, m1);
  1973. if (n !== null) {
  1974. return { unit: 'day', value: n };
  1975. }
  1976. n = diffHours(m0, m1);
  1977. if (isInt(n)) {
  1978. return { unit: 'hour', value: n };
  1979. }
  1980. n = diffMinutes(m0, m1);
  1981. if (isInt(n)) {
  1982. return { unit: 'minute', value: n };
  1983. }
  1984. n = diffSeconds(m0, m1);
  1985. if (isInt(n)) {
  1986. return { unit: 'second', value: n };
  1987. }
  1988. return { unit: 'millisecond', value: m1.valueOf() - m0.valueOf() };
  1989. }
  1990. countDurationsBetween(m0, m1, d) {
  1991. // TODO: can use greatestWholeUnit
  1992. let diff;
  1993. if (d.years) {
  1994. diff = this.diffWholeYears(m0, m1);
  1995. if (diff !== null) {
  1996. return diff / asRoughYears(d);
  1997. }
  1998. }
  1999. if (d.months) {
  2000. diff = this.diffWholeMonths(m0, m1);
  2001. if (diff !== null) {
  2002. return diff / asRoughMonths(d);
  2003. }
  2004. }
  2005. if (d.days) {
  2006. diff = diffWholeDays(m0, m1);
  2007. if (diff !== null) {
  2008. return diff / asRoughDays(d);
  2009. }
  2010. }
  2011. return (m1.valueOf() - m0.valueOf()) / asRoughMs(d);
  2012. }
  2013. // Start-Of
  2014. // these DON'T return zoned-dates. only UTC start-of dates
  2015. startOf(m, unit) {
  2016. if (unit === 'year') {
  2017. return this.startOfYear(m);
  2018. }
  2019. if (unit === 'month') {
  2020. return this.startOfMonth(m);
  2021. }
  2022. if (unit === 'week') {
  2023. return this.startOfWeek(m);
  2024. }
  2025. if (unit === 'day') {
  2026. return startOfDay(m);
  2027. }
  2028. if (unit === 'hour') {
  2029. return startOfHour(m);
  2030. }
  2031. if (unit === 'minute') {
  2032. return startOfMinute(m);
  2033. }
  2034. if (unit === 'second') {
  2035. return startOfSecond(m);
  2036. }
  2037. return null;
  2038. }
  2039. startOfYear(m) {
  2040. return this.calendarSystem.arrayToMarker([
  2041. this.calendarSystem.getMarkerYear(m),
  2042. ]);
  2043. }
  2044. startOfMonth(m) {
  2045. return this.calendarSystem.arrayToMarker([
  2046. this.calendarSystem.getMarkerYear(m),
  2047. this.calendarSystem.getMarkerMonth(m),
  2048. ]);
  2049. }
  2050. startOfWeek(m) {
  2051. return this.calendarSystem.arrayToMarker([
  2052. this.calendarSystem.getMarkerYear(m),
  2053. this.calendarSystem.getMarkerMonth(m),
  2054. m.getUTCDate() - ((m.getUTCDay() - this.weekDow + 7) % 7),
  2055. ]);
  2056. }
  2057. // Week Number
  2058. computeWeekNumber(marker) {
  2059. if (this.weekNumberFunc) {
  2060. return this.weekNumberFunc(this.toDate(marker));
  2061. }
  2062. return weekOfYear(marker, this.weekDow, this.weekDoy);
  2063. }
  2064. // TODO: choke on timeZoneName: long
  2065. format(marker, formatter, dateOptions = {}) {
  2066. return formatter.format({
  2067. marker,
  2068. timeZoneOffset: dateOptions.forcedTzo != null ?
  2069. dateOptions.forcedTzo :
  2070. this.offsetForMarker(marker),
  2071. }, this);
  2072. }
  2073. formatRange(start, end, formatter, dateOptions = {}) {
  2074. if (dateOptions.isEndExclusive) {
  2075. end = addMs(end, -1);
  2076. }
  2077. return formatter.formatRange({
  2078. marker: start,
  2079. timeZoneOffset: dateOptions.forcedStartTzo != null ?
  2080. dateOptions.forcedStartTzo :
  2081. this.offsetForMarker(start),
  2082. }, {
  2083. marker: end,
  2084. timeZoneOffset: dateOptions.forcedEndTzo != null ?
  2085. dateOptions.forcedEndTzo :
  2086. this.offsetForMarker(end),
  2087. }, this, dateOptions.defaultSeparator);
  2088. }
  2089. /*
  2090. DUMB: the omitTime arg is dumb. if we omit the time, we want to omit the timezone offset. and if we do that,
  2091. might as well use buildIsoString or some other util directly
  2092. */
  2093. formatIso(marker, extraOptions = {}) {
  2094. let timeZoneOffset = null;
  2095. if (!extraOptions.omitTimeZoneOffset) {
  2096. if (extraOptions.forcedTzo != null) {
  2097. timeZoneOffset = extraOptions.forcedTzo;
  2098. }
  2099. else {
  2100. timeZoneOffset = this.offsetForMarker(marker);
  2101. }
  2102. }
  2103. return buildIsoString(marker, timeZoneOffset, extraOptions.omitTime);
  2104. }
  2105. // TimeZone
  2106. timestampToMarker(ms) {
  2107. if (this.timeZone === 'local') {
  2108. return arrayToUtcDate(dateToLocalArray(new Date(ms)));
  2109. }
  2110. if (this.timeZone === 'UTC' || !this.namedTimeZoneImpl) {
  2111. return new Date(ms);
  2112. }
  2113. return arrayToUtcDate(this.namedTimeZoneImpl.timestampToArray(ms));
  2114. }
  2115. offsetForMarker(m) {
  2116. if (this.timeZone === 'local') {
  2117. return -arrayToLocalDate(dateToUtcArray(m)).getTimezoneOffset(); // convert "inverse" offset to "normal" offset
  2118. }
  2119. if (this.timeZone === 'UTC') {
  2120. return 0;
  2121. }
  2122. if (this.namedTimeZoneImpl) {
  2123. return this.namedTimeZoneImpl.offsetForArray(dateToUtcArray(m));
  2124. }
  2125. return null;
  2126. }
  2127. // Conversion
  2128. toDate(m, forcedTzo) {
  2129. if (this.timeZone === 'local') {
  2130. return arrayToLocalDate(dateToUtcArray(m));
  2131. }
  2132. if (this.timeZone === 'UTC') {
  2133. return new Date(m.valueOf()); // make sure it's a copy
  2134. }
  2135. if (!this.namedTimeZoneImpl) {
  2136. return new Date(m.valueOf() - (forcedTzo || 0));
  2137. }
  2138. return new Date(m.valueOf() -
  2139. this.namedTimeZoneImpl.offsetForArray(dateToUtcArray(m)) * 1000 * 60);
  2140. }
  2141. }
  2142. class Theme {
  2143. constructor(calendarOptions) {
  2144. if (this.iconOverrideOption) {
  2145. this.setIconOverride(calendarOptions[this.iconOverrideOption]);
  2146. }
  2147. }
  2148. setIconOverride(iconOverrideHash) {
  2149. let iconClassesCopy;
  2150. let buttonName;
  2151. if (typeof iconOverrideHash === 'object' && iconOverrideHash) { // non-null object
  2152. iconClassesCopy = Object.assign({}, this.iconClasses);
  2153. for (buttonName in iconOverrideHash) {
  2154. iconClassesCopy[buttonName] = this.applyIconOverridePrefix(iconOverrideHash[buttonName]);
  2155. }
  2156. this.iconClasses = iconClassesCopy;
  2157. }
  2158. else if (iconOverrideHash === false) {
  2159. this.iconClasses = {};
  2160. }
  2161. }
  2162. applyIconOverridePrefix(className) {
  2163. let prefix = this.iconOverridePrefix;
  2164. if (prefix && className.indexOf(prefix) !== 0) { // if not already present
  2165. className = prefix + className;
  2166. }
  2167. return className;
  2168. }
  2169. getClass(key) {
  2170. return this.classes[key] || '';
  2171. }
  2172. getIconClass(buttonName, isRtl) {
  2173. let className;
  2174. if (isRtl && this.rtlIconClasses) {
  2175. className = this.rtlIconClasses[buttonName] || this.iconClasses[buttonName];
  2176. }
  2177. else {
  2178. className = this.iconClasses[buttonName];
  2179. }
  2180. if (className) {
  2181. return `${this.baseIconClass} ${className}`;
  2182. }
  2183. return '';
  2184. }
  2185. getCustomButtonIconClass(customButtonProps) {
  2186. let className;
  2187. if (this.iconOverrideCustomButtonOption) {
  2188. className = customButtonProps[this.iconOverrideCustomButtonOption];
  2189. if (className) {
  2190. return `${this.baseIconClass} ${this.applyIconOverridePrefix(className)}`;
  2191. }
  2192. }
  2193. return '';
  2194. }
  2195. }
  2196. Theme.prototype.classes = {};
  2197. Theme.prototype.iconClasses = {};
  2198. Theme.prototype.baseIconClass = '';
  2199. Theme.prototype.iconOverridePrefix = '';
  2200. /*
  2201. NOTE: this can be a public API, especially createElement for hooks.
  2202. See examples/typescript-scheduler/src/index.ts
  2203. */
  2204. function flushSync(runBeforeFlush) {
  2205. runBeforeFlush();
  2206. let oldDebounceRendering = preact.options.debounceRendering; // orig
  2207. let callbackQ = [];
  2208. function execCallbackSync(callback) {
  2209. callbackQ.push(callback);
  2210. }
  2211. preact.options.debounceRendering = execCallbackSync;
  2212. preact.render(preact.createElement(FakeComponent, {}), document.createElement('div'));
  2213. while (callbackQ.length) {
  2214. callbackQ.shift()();
  2215. }
  2216. preact.options.debounceRendering = oldDebounceRendering;
  2217. }
  2218. class FakeComponent extends preact.Component {
  2219. render() { return preact.createElement('div', {}); }
  2220. componentDidMount() { this.setState({}); }
  2221. }
  2222. // TODO: use preact/compat instead?
  2223. function createContext(defaultValue) {
  2224. let ContextType = preact.createContext(defaultValue);
  2225. let origProvider = ContextType.Provider;
  2226. ContextType.Provider = function () {
  2227. let isNew = !this.getChildContext;
  2228. let children = origProvider.apply(this, arguments); // eslint-disable-line prefer-rest-params
  2229. if (isNew) {
  2230. let subs = [];
  2231. this.shouldComponentUpdate = (_props) => {
  2232. if (this.props.value !== _props.value) {
  2233. subs.forEach((c) => {
  2234. c.context = _props.value;
  2235. c.forceUpdate();
  2236. });
  2237. }
  2238. };
  2239. this.sub = (c) => {
  2240. subs.push(c);
  2241. let old = c.componentWillUnmount;
  2242. c.componentWillUnmount = () => {
  2243. subs.splice(subs.indexOf(c), 1);
  2244. old && old.call(c);
  2245. };
  2246. };
  2247. }
  2248. return children;
  2249. };
  2250. return ContextType;
  2251. }
  2252. class ScrollResponder {
  2253. constructor(execFunc, emitter, scrollTime, scrollTimeReset) {
  2254. this.execFunc = execFunc;
  2255. this.emitter = emitter;
  2256. this.scrollTime = scrollTime;
  2257. this.scrollTimeReset = scrollTimeReset;
  2258. this.handleScrollRequest = (request) => {
  2259. this.queuedRequest = Object.assign({}, this.queuedRequest || {}, request);
  2260. this.drain();
  2261. };
  2262. emitter.on('_scrollRequest', this.handleScrollRequest);
  2263. this.fireInitialScroll();
  2264. }
  2265. detach() {
  2266. this.emitter.off('_scrollRequest', this.handleScrollRequest);
  2267. }
  2268. update(isDatesNew) {
  2269. if (isDatesNew && this.scrollTimeReset) {
  2270. this.fireInitialScroll(); // will drain
  2271. }
  2272. else {
  2273. this.drain();
  2274. }
  2275. }
  2276. fireInitialScroll() {
  2277. this.handleScrollRequest({
  2278. time: this.scrollTime,
  2279. });
  2280. }
  2281. drain() {
  2282. if (this.queuedRequest && this.execFunc(this.queuedRequest)) {
  2283. this.queuedRequest = null;
  2284. }
  2285. }
  2286. }
  2287. const ViewContextType = createContext({}); // for Components
  2288. function buildViewContext(viewSpec, viewApi, viewOptions, dateProfileGenerator, dateEnv, theme, pluginHooks, dispatch, getCurrentData, emitter, calendarApi, registerInteractiveComponent, unregisterInteractiveComponent) {
  2289. return {
  2290. dateEnv,
  2291. options: viewOptions,
  2292. pluginHooks,
  2293. emitter,
  2294. dispatch,
  2295. getCurrentData,
  2296. calendarApi,
  2297. viewSpec,
  2298. viewApi,
  2299. dateProfileGenerator,
  2300. theme,
  2301. isRtl: viewOptions.direction === 'rtl',
  2302. addResizeHandler(handler) {
  2303. emitter.on('_resize', handler);
  2304. },
  2305. removeResizeHandler(handler) {
  2306. emitter.off('_resize', handler);
  2307. },
  2308. createScrollResponder(execFunc) {
  2309. return new ScrollResponder(execFunc, emitter, createDuration(viewOptions.scrollTime), viewOptions.scrollTimeReset);
  2310. },
  2311. registerInteractiveComponent,
  2312. unregisterInteractiveComponent,
  2313. };
  2314. }
  2315. /* eslint max-classes-per-file: off */
  2316. class PureComponent extends Component {
  2317. shouldComponentUpdate(nextProps, nextState) {
  2318. if (this.debug) {
  2319. // eslint-disable-next-line no-console
  2320. console.log(getUnequalProps(nextProps, this.props), getUnequalProps(nextState, this.state));
  2321. }
  2322. return !compareObjs(this.props, nextProps, this.propEquality) ||
  2323. !compareObjs(this.state, nextState, this.stateEquality);
  2324. }
  2325. // HACK for freakin' React StrictMode
  2326. safeSetState(newState) {
  2327. if (!compareObjs(this.state, Object.assign(Object.assign({}, this.state), newState), this.stateEquality)) {
  2328. this.setState(newState);
  2329. }
  2330. }
  2331. }
  2332. PureComponent.addPropsEquality = addPropsEquality;
  2333. PureComponent.addStateEquality = addStateEquality;
  2334. PureComponent.contextType = ViewContextType;
  2335. PureComponent.prototype.propEquality = {};
  2336. PureComponent.prototype.stateEquality = {};
  2337. class BaseComponent extends PureComponent {
  2338. }
  2339. BaseComponent.contextType = ViewContextType;
  2340. function addPropsEquality(propEquality) {
  2341. let hash = Object.create(this.prototype.propEquality);
  2342. Object.assign(hash, propEquality);
  2343. this.prototype.propEquality = hash;
  2344. }
  2345. function addStateEquality(stateEquality) {
  2346. let hash = Object.create(this.prototype.stateEquality);
  2347. Object.assign(hash, stateEquality);
  2348. this.prototype.stateEquality = hash;
  2349. }
  2350. // use other one
  2351. function setRef(ref, current) {
  2352. if (typeof ref === 'function') {
  2353. ref(current);
  2354. }
  2355. else if (ref) {
  2356. // see https://github.com/facebook/react/issues/13029
  2357. ref.current = current;
  2358. }
  2359. }
  2360. class ContentInjector extends BaseComponent {
  2361. constructor() {
  2362. super(...arguments);
  2363. this.id = guid();
  2364. this.queuedDomNodes = [];
  2365. this.currentDomNodes = [];
  2366. this.handleEl = (el) => {
  2367. const { options } = this.context;
  2368. const { generatorName } = this.props;
  2369. if (!options.customRenderingReplaces || !hasCustomRenderingHandler(generatorName, options)) {
  2370. this.updateElRef(el);
  2371. }
  2372. };
  2373. this.updateElRef = (el) => {
  2374. if (this.props.elRef) {
  2375. setRef(this.props.elRef, el);
  2376. }
  2377. };
  2378. }
  2379. render() {
  2380. const { props, context } = this;
  2381. const { options } = context;
  2382. const { customGenerator, defaultGenerator, renderProps } = props;
  2383. const attrs = buildElAttrs(props, [], this.handleEl);
  2384. let useDefault = false;
  2385. let innerContent;
  2386. let queuedDomNodes = [];
  2387. let currentGeneratorMeta;
  2388. if (customGenerator != null) {
  2389. const customGeneratorRes = typeof customGenerator === 'function' ?
  2390. customGenerator(renderProps, createElement) :
  2391. customGenerator;
  2392. if (customGeneratorRes === true) {
  2393. useDefault = true;
  2394. }
  2395. else {
  2396. const isObject = customGeneratorRes && typeof customGeneratorRes === 'object'; // non-null
  2397. if (isObject && ('html' in customGeneratorRes)) {
  2398. attrs.dangerouslySetInnerHTML = { __html: customGeneratorRes.html };
  2399. }
  2400. else if (isObject && ('domNodes' in customGeneratorRes)) {
  2401. queuedDomNodes = Array.prototype.slice.call(customGeneratorRes.domNodes);
  2402. }
  2403. else if (isObject
  2404. ? isValidElement(customGeneratorRes) // vdom node
  2405. : typeof customGeneratorRes !== 'function' // primitive value (like string or number)
  2406. ) {
  2407. // use in vdom
  2408. innerContent = customGeneratorRes;
  2409. }
  2410. else {
  2411. // an exotic object for handleCustomRendering
  2412. currentGeneratorMeta = customGeneratorRes;
  2413. }
  2414. }
  2415. }
  2416. else {
  2417. useDefault = !hasCustomRenderingHandler(props.generatorName, options);
  2418. }
  2419. if (useDefault && defaultGenerator) {
  2420. innerContent = defaultGenerator(renderProps);
  2421. }
  2422. this.queuedDomNodes = queuedDomNodes;
  2423. this.currentGeneratorMeta = currentGeneratorMeta;
  2424. return createElement(props.elTag, attrs, innerContent);
  2425. }
  2426. componentDidMount() {
  2427. this.applyQueueudDomNodes();
  2428. this.triggerCustomRendering(true);
  2429. }
  2430. componentDidUpdate() {
  2431. this.applyQueueudDomNodes();
  2432. this.triggerCustomRendering(true);
  2433. }
  2434. componentWillUnmount() {
  2435. this.triggerCustomRendering(false); // TODO: different API for removal?
  2436. }
  2437. triggerCustomRendering(isActive) {
  2438. var _a;
  2439. const { props, context } = this;
  2440. const { handleCustomRendering, customRenderingMetaMap } = context.options;
  2441. if (handleCustomRendering) {
  2442. const generatorMeta = (_a = this.currentGeneratorMeta) !== null && _a !== void 0 ? _a : customRenderingMetaMap === null || customRenderingMetaMap === void 0 ? void 0 : customRenderingMetaMap[props.generatorName];
  2443. if (generatorMeta) {
  2444. handleCustomRendering(Object.assign(Object.assign({ id: this.id, isActive, containerEl: this.base, reportNewContainerEl: this.updateElRef, // front-end framework tells us about new container els
  2445. generatorMeta }, props), { elClasses: (props.elClasses || []).filter(isTruthy) }));
  2446. }
  2447. }
  2448. }
  2449. applyQueueudDomNodes() {
  2450. const { queuedDomNodes, currentDomNodes } = this;
  2451. const el = this.base;
  2452. if (!isArraysEqual(queuedDomNodes, currentDomNodes)) {
  2453. currentDomNodes.forEach(removeElement);
  2454. for (let newNode of queuedDomNodes) {
  2455. el.appendChild(newNode);
  2456. }
  2457. this.currentDomNodes = queuedDomNodes;
  2458. }
  2459. }
  2460. }
  2461. ContentInjector.addPropsEquality({
  2462. elClasses: isArraysEqual,
  2463. elStyle: isPropsEqual,
  2464. elAttrs: isNonHandlerPropsEqual,
  2465. renderProps: isPropsEqual,
  2466. });
  2467. // Util
  2468. /*
  2469. Does UI-framework provide custom way of rendering that does not use Preact VDOM
  2470. AND does the calendar's options define custom rendering?
  2471. AKA. Should we NOT render the default content?
  2472. */
  2473. function hasCustomRenderingHandler(generatorName, options) {
  2474. var _a;
  2475. return Boolean(options.handleCustomRendering &&
  2476. generatorName &&
  2477. ((_a = options.customRenderingMetaMap) === null || _a === void 0 ? void 0 : _a[generatorName]));
  2478. }
  2479. function buildElAttrs(props, extraClassNames, elRef) {
  2480. const attrs = Object.assign(Object.assign({}, props.elAttrs), { ref: elRef });
  2481. if (props.elClasses || extraClassNames) {
  2482. attrs.className = (props.elClasses || [])
  2483. .concat(extraClassNames || [])
  2484. .concat(attrs.className || [])
  2485. .filter(Boolean)
  2486. .join(' ');
  2487. }
  2488. if (props.elStyle) {
  2489. attrs.style = props.elStyle;
  2490. }
  2491. return attrs;
  2492. }
  2493. function isTruthy(val) {
  2494. return Boolean(val);
  2495. }
  2496. const RenderId = createContext(0);
  2497. class ContentContainer extends Component {
  2498. constructor() {
  2499. super(...arguments);
  2500. this.InnerContent = InnerContentInjector.bind(undefined, this);
  2501. this.handleEl = (el) => {
  2502. this.el = el;
  2503. if (this.props.elRef) {
  2504. setRef(this.props.elRef, el);
  2505. if (el && this.didMountMisfire) {
  2506. this.componentDidMount();
  2507. }
  2508. }
  2509. };
  2510. }
  2511. render() {
  2512. const { props } = this;
  2513. const generatedClassNames = generateClassNames(props.classNameGenerator, props.renderProps);
  2514. if (props.children) {
  2515. const elAttrs = buildElAttrs(props, generatedClassNames, this.handleEl);
  2516. const children = props.children(this.InnerContent, props.renderProps, elAttrs);
  2517. if (props.elTag) {
  2518. return createElement(props.elTag, elAttrs, children);
  2519. }
  2520. else {
  2521. return children;
  2522. }
  2523. }
  2524. else {
  2525. return createElement((ContentInjector), Object.assign(Object.assign({}, props), { elRef: this.handleEl, elTag: props.elTag || 'div', elClasses: (props.elClasses || []).concat(generatedClassNames), renderId: this.context }));
  2526. }
  2527. }
  2528. componentDidMount() {
  2529. var _a, _b;
  2530. if (this.el) {
  2531. (_b = (_a = this.props).didMount) === null || _b === void 0 ? void 0 : _b.call(_a, Object.assign(Object.assign({}, this.props.renderProps), { el: this.el }));
  2532. }
  2533. else {
  2534. this.didMountMisfire = true;
  2535. }
  2536. }
  2537. componentWillUnmount() {
  2538. var _a, _b;
  2539. (_b = (_a = this.props).willUnmount) === null || _b === void 0 ? void 0 : _b.call(_a, Object.assign(Object.assign({}, this.props.renderProps), { el: this.el }));
  2540. }
  2541. }
  2542. ContentContainer.contextType = RenderId;
  2543. function InnerContentInjector(containerComponent, props) {
  2544. const parentProps = containerComponent.props;
  2545. return createElement((ContentInjector), Object.assign({ renderProps: parentProps.renderProps, generatorName: parentProps.generatorName, customGenerator: parentProps.customGenerator, defaultGenerator: parentProps.defaultGenerator, renderId: containerComponent.context }, props));
  2546. }
  2547. // Utils
  2548. function generateClassNames(classNameGenerator, renderProps) {
  2549. const classNames = typeof classNameGenerator === 'function' ?
  2550. classNameGenerator(renderProps) :
  2551. classNameGenerator || [];
  2552. return typeof classNames === 'string' ? [classNames] : classNames;
  2553. }
  2554. class ViewContainer extends BaseComponent {
  2555. render() {
  2556. let { props, context } = this;
  2557. let { options } = context;
  2558. let renderProps = { view: context.viewApi };
  2559. return (createElement(ContentContainer, Object.assign({}, props, { elTag: props.elTag || 'div', elClasses: [
  2560. ...buildViewClassNames(props.viewSpec),
  2561. ...(props.elClasses || []),
  2562. ], renderProps: renderProps, classNameGenerator: options.viewClassNames, generatorName: undefined, didMount: options.viewDidMount, willUnmount: options.viewWillUnmount }), () => props.children));
  2563. }
  2564. }
  2565. function buildViewClassNames(viewSpec) {
  2566. return [
  2567. `fc-${viewSpec.type}-view`,
  2568. 'fc-view',
  2569. ];
  2570. }
  2571. function parseRange(input, dateEnv) {
  2572. let start = null;
  2573. let end = null;
  2574. if (input.start) {
  2575. start = dateEnv.createMarker(input.start);
  2576. }
  2577. if (input.end) {
  2578. end = dateEnv.createMarker(input.end);
  2579. }
  2580. if (!start && !end) {
  2581. return null;
  2582. }
  2583. if (start && end && end < start) {
  2584. return null;
  2585. }
  2586. return { start, end };
  2587. }
  2588. // SIDE-EFFECT: will mutate ranges.
  2589. // Will return a new array result.
  2590. function invertRanges(ranges, constraintRange) {
  2591. let invertedRanges = [];
  2592. let { start } = constraintRange; // the end of the previous range. the start of the new range
  2593. let i;
  2594. let dateRange;
  2595. // ranges need to be in order. required for our date-walking algorithm
  2596. ranges.sort(compareRanges);
  2597. for (i = 0; i < ranges.length; i += 1) {
  2598. dateRange = ranges[i];
  2599. // add the span of time before the event (if there is any)
  2600. if (dateRange.start > start) { // compare millisecond time (skip any ambig logic)
  2601. invertedRanges.push({ start, end: dateRange.start });
  2602. }
  2603. if (dateRange.end > start) {
  2604. start = dateRange.end;
  2605. }
  2606. }
  2607. // add the span of time after the last event (if there is any)
  2608. if (start < constraintRange.end) { // compare millisecond time (skip any ambig logic)
  2609. invertedRanges.push({ start, end: constraintRange.end });
  2610. }
  2611. return invertedRanges;
  2612. }
  2613. function compareRanges(range0, range1) {
  2614. return range0.start.valueOf() - range1.start.valueOf(); // earlier ranges go first
  2615. }
  2616. function intersectRanges(range0, range1) {
  2617. let { start, end } = range0;
  2618. let newRange = null;
  2619. if (range1.start !== null) {
  2620. if (start === null) {
  2621. start = range1.start;
  2622. }
  2623. else {
  2624. start = new Date(Math.max(start.valueOf(), range1.start.valueOf()));
  2625. }
  2626. }
  2627. if (range1.end != null) {
  2628. if (end === null) {
  2629. end = range1.end;
  2630. }
  2631. else {
  2632. end = new Date(Math.min(end.valueOf(), range1.end.valueOf()));
  2633. }
  2634. }
  2635. if (start === null || end === null || start < end) {
  2636. newRange = { start, end };
  2637. }
  2638. return newRange;
  2639. }
  2640. function rangesEqual(range0, range1) {
  2641. return (range0.start === null ? null : range0.start.valueOf()) === (range1.start === null ? null : range1.start.valueOf()) &&
  2642. (range0.end === null ? null : range0.end.valueOf()) === (range1.end === null ? null : range1.end.valueOf());
  2643. }
  2644. function rangesIntersect(range0, range1) {
  2645. return (range0.end === null || range1.start === null || range0.end > range1.start) &&
  2646. (range0.start === null || range1.end === null || range0.start < range1.end);
  2647. }
  2648. function rangeContainsRange(outerRange, innerRange) {
  2649. return (outerRange.start === null || (innerRange.start !== null && innerRange.start >= outerRange.start)) &&
  2650. (outerRange.end === null || (innerRange.end !== null && innerRange.end <= outerRange.end));
  2651. }
  2652. function rangeContainsMarker(range, date) {
  2653. return (range.start === null || date >= range.start) &&
  2654. (range.end === null || date < range.end);
  2655. }
  2656. // If the given date is not within the given range, move it inside.
  2657. // (If it's past the end, make it one millisecond before the end).
  2658. function constrainMarkerToRange(date, range) {
  2659. if (range.start != null && date < range.start) {
  2660. return range.start;
  2661. }
  2662. if (range.end != null && date >= range.end) {
  2663. return new Date(range.end.valueOf() - 1);
  2664. }
  2665. return date;
  2666. }
  2667. /* Date stuff that doesn't belong in datelib core
  2668. ----------------------------------------------------------------------------------------------------------------------*/
  2669. // given a timed range, computes an all-day range that has the same exact duration,
  2670. // but whose start time is aligned with the start of the day.
  2671. function computeAlignedDayRange(timedRange) {
  2672. let dayCnt = Math.floor(diffDays(timedRange.start, timedRange.end)) || 1;
  2673. let start = startOfDay(timedRange.start);
  2674. let end = addDays(start, dayCnt);
  2675. return { start, end };
  2676. }
  2677. // given a timed range, computes an all-day range based on how for the end date bleeds into the next day
  2678. // TODO: give nextDayThreshold a default arg
  2679. function computeVisibleDayRange(timedRange, nextDayThreshold = createDuration(0)) {
  2680. let startDay = null;
  2681. let endDay = null;
  2682. if (timedRange.end) {
  2683. endDay = startOfDay(timedRange.end);
  2684. let endTimeMS = timedRange.end.valueOf() - endDay.valueOf(); // # of milliseconds into `endDay`
  2685. // If the end time is actually inclusively part of the next day and is equal to or
  2686. // beyond the next day threshold, adjust the end to be the exclusive end of `endDay`.
  2687. // Otherwise, leaving it as inclusive will cause it to exclude `endDay`.
  2688. if (endTimeMS && endTimeMS >= asRoughMs(nextDayThreshold)) {
  2689. endDay = addDays(endDay, 1);
  2690. }
  2691. }
  2692. if (timedRange.start) {
  2693. startDay = startOfDay(timedRange.start); // the beginning of the day the range starts
  2694. // If end is within `startDay` but not past nextDayThreshold, assign the default duration of one day.
  2695. if (endDay && endDay <= startDay) {
  2696. endDay = addDays(startDay, 1);
  2697. }
  2698. }
  2699. return { start: startDay, end: endDay };
  2700. }
  2701. // spans from one day into another?
  2702. function isMultiDayRange(range) {
  2703. let visibleRange = computeVisibleDayRange(range);
  2704. return diffDays(visibleRange.start, visibleRange.end) > 1;
  2705. }
  2706. function diffDates(date0, date1, dateEnv, largeUnit) {
  2707. if (largeUnit === 'year') {
  2708. return createDuration(dateEnv.diffWholeYears(date0, date1), 'year');
  2709. }
  2710. if (largeUnit === 'month') {
  2711. return createDuration(dateEnv.diffWholeMonths(date0, date1), 'month');
  2712. }
  2713. return diffDayAndTime(date0, date1); // returns a duration
  2714. }
  2715. function reduceCurrentDate(currentDate, action) {
  2716. switch (action.type) {
  2717. case 'CHANGE_DATE':
  2718. return action.dateMarker;
  2719. default:
  2720. return currentDate;
  2721. }
  2722. }
  2723. function getInitialDate(options, dateEnv) {
  2724. let initialDateInput = options.initialDate;
  2725. // compute the initial ambig-timezone date
  2726. if (initialDateInput != null) {
  2727. return dateEnv.createMarker(initialDateInput);
  2728. }
  2729. return getNow(options.now, dateEnv); // getNow already returns unzoned
  2730. }
  2731. function getNow(nowInput, dateEnv) {
  2732. if (typeof nowInput === 'function') {
  2733. nowInput = nowInput();
  2734. }
  2735. if (nowInput == null) {
  2736. return dateEnv.createNowMarker();
  2737. }
  2738. return dateEnv.createMarker(nowInput);
  2739. }
  2740. class DateProfileGenerator {
  2741. constructor(props) {
  2742. this.props = props;
  2743. this.nowDate = getNow(props.nowInput, props.dateEnv);
  2744. this.initHiddenDays();
  2745. }
  2746. /* Date Range Computation
  2747. ------------------------------------------------------------------------------------------------------------------*/
  2748. // Builds a structure with info about what the dates/ranges will be for the "prev" view.
  2749. buildPrev(currentDateProfile, currentDate, forceToValid) {
  2750. let { dateEnv } = this.props;
  2751. let prevDate = dateEnv.subtract(dateEnv.startOf(currentDate, currentDateProfile.currentRangeUnit), // important for start-of-month
  2752. currentDateProfile.dateIncrement);
  2753. return this.build(prevDate, -1, forceToValid);
  2754. }
  2755. // Builds a structure with info about what the dates/ranges will be for the "next" view.
  2756. buildNext(currentDateProfile, currentDate, forceToValid) {
  2757. let { dateEnv } = this.props;
  2758. let nextDate = dateEnv.add(dateEnv.startOf(currentDate, currentDateProfile.currentRangeUnit), // important for start-of-month
  2759. currentDateProfile.dateIncrement);
  2760. return this.build(nextDate, 1, forceToValid);
  2761. }
  2762. // Builds a structure holding dates/ranges for rendering around the given date.
  2763. // Optional direction param indicates whether the date is being incremented/decremented
  2764. // from its previous value. decremented = -1, incremented = 1 (default).
  2765. build(currentDate, direction, forceToValid = true) {
  2766. let { props } = this;
  2767. let validRange;
  2768. let currentInfo;
  2769. let isRangeAllDay;
  2770. let renderRange;
  2771. let activeRange;
  2772. let isValid;
  2773. validRange = this.buildValidRange();
  2774. validRange = this.trimHiddenDays(validRange);
  2775. if (forceToValid) {
  2776. currentDate = constrainMarkerToRange(currentDate, validRange);
  2777. }
  2778. currentInfo = this.buildCurrentRangeInfo(currentDate, direction);
  2779. isRangeAllDay = /^(year|month|week|day)$/.test(currentInfo.unit);
  2780. renderRange = this.buildRenderRange(this.trimHiddenDays(currentInfo.range), currentInfo.unit, isRangeAllDay);
  2781. renderRange = this.trimHiddenDays(renderRange);
  2782. activeRange = renderRange;
  2783. if (!props.showNonCurrentDates) {
  2784. activeRange = intersectRanges(activeRange, currentInfo.range);
  2785. }
  2786. activeRange = this.adjustActiveRange(activeRange);
  2787. activeRange = intersectRanges(activeRange, validRange); // might return null
  2788. // it's invalid if the originally requested date is not contained,
  2789. // or if the range is completely outside of the valid range.
  2790. isValid = rangesIntersect(currentInfo.range, validRange);
  2791. // HACK: constrain to render-range so `currentDate` is more useful to view rendering
  2792. if (!rangeContainsMarker(renderRange, currentDate)) {
  2793. currentDate = renderRange.start;
  2794. }
  2795. return {
  2796. currentDate,
  2797. // constraint for where prev/next operations can go and where events can be dragged/resized to.
  2798. // an object with optional start and end properties.
  2799. validRange,
  2800. // range the view is formally responsible for.
  2801. // for example, a month view might have 1st-31st, excluding padded dates
  2802. currentRange: currentInfo.range,
  2803. // name of largest unit being displayed, like "month" or "week"
  2804. currentRangeUnit: currentInfo.unit,
  2805. isRangeAllDay,
  2806. // dates that display events and accept drag-n-drop
  2807. // will be `null` if no dates accept events
  2808. activeRange,
  2809. // date range with a rendered skeleton
  2810. // includes not-active days that need some sort of DOM
  2811. renderRange,
  2812. // Duration object that denotes the first visible time of any given day
  2813. slotMinTime: props.slotMinTime,
  2814. // Duration object that denotes the exclusive visible end time of any given day
  2815. slotMaxTime: props.slotMaxTime,
  2816. isValid,
  2817. // how far the current date will move for a prev/next operation
  2818. dateIncrement: this.buildDateIncrement(currentInfo.duration),
  2819. // pass a fallback (might be null) ^
  2820. };
  2821. }
  2822. // Builds an object with optional start/end properties.
  2823. // Indicates the minimum/maximum dates to display.
  2824. // not responsible for trimming hidden days.
  2825. buildValidRange() {
  2826. let input = this.props.validRangeInput;
  2827. let simpleInput = typeof input === 'function'
  2828. ? input.call(this.props.calendarApi, this.nowDate)
  2829. : input;
  2830. return this.refineRange(simpleInput) ||
  2831. { start: null, end: null }; // completely open-ended
  2832. }
  2833. // Builds a structure with info about the "current" range, the range that is
  2834. // highlighted as being the current month for example.
  2835. // See build() for a description of `direction`.
  2836. // Guaranteed to have `range` and `unit` properties. `duration` is optional.
  2837. buildCurrentRangeInfo(date, direction) {
  2838. let { props } = this;
  2839. let duration = null;
  2840. let unit = null;
  2841. let range = null;
  2842. let dayCount;
  2843. if (props.duration) {
  2844. duration = props.duration;
  2845. unit = props.durationUnit;
  2846. range = this.buildRangeFromDuration(date, direction, duration, unit);
  2847. }
  2848. else if ((dayCount = this.props.dayCount)) {
  2849. unit = 'day';
  2850. range = this.buildRangeFromDayCount(date, direction, dayCount);
  2851. }
  2852. else if ((range = this.buildCustomVisibleRange(date))) {
  2853. unit = props.dateEnv.greatestWholeUnit(range.start, range.end).unit;
  2854. }
  2855. else {
  2856. duration = this.getFallbackDuration();
  2857. unit = greatestDurationDenominator(duration).unit;
  2858. range = this.buildRangeFromDuration(date, direction, duration, unit);
  2859. }
  2860. return { duration, unit, range };
  2861. }
  2862. getFallbackDuration() {
  2863. return createDuration({ day: 1 });
  2864. }
  2865. // Returns a new activeRange to have time values (un-ambiguate)
  2866. // slotMinTime or slotMaxTime causes the range to expand.
  2867. adjustActiveRange(range) {
  2868. let { dateEnv, usesMinMaxTime, slotMinTime, slotMaxTime } = this.props;
  2869. let { start, end } = range;
  2870. if (usesMinMaxTime) {
  2871. // expand active range if slotMinTime is negative (why not when positive?)
  2872. if (asRoughDays(slotMinTime) < 0) {
  2873. start = startOfDay(start); // necessary?
  2874. start = dateEnv.add(start, slotMinTime);
  2875. }
  2876. // expand active range if slotMaxTime is beyond one day (why not when negative?)
  2877. if (asRoughDays(slotMaxTime) > 1) {
  2878. end = startOfDay(end); // necessary?
  2879. end = addDays(end, -1);
  2880. end = dateEnv.add(end, slotMaxTime);
  2881. }
  2882. }
  2883. return { start, end };
  2884. }
  2885. // Builds the "current" range when it is specified as an explicit duration.
  2886. // `unit` is the already-computed greatestDurationDenominator unit of duration.
  2887. buildRangeFromDuration(date, direction, duration, unit) {
  2888. let { dateEnv, dateAlignment } = this.props;
  2889. let start;
  2890. let end;
  2891. let res;
  2892. // compute what the alignment should be
  2893. if (!dateAlignment) {
  2894. let { dateIncrement } = this.props;
  2895. if (dateIncrement) {
  2896. // use the smaller of the two units
  2897. if (asRoughMs(dateIncrement) < asRoughMs(duration)) {
  2898. dateAlignment = greatestDurationDenominator(dateIncrement).unit;
  2899. }
  2900. else {
  2901. dateAlignment = unit;
  2902. }
  2903. }
  2904. else {
  2905. dateAlignment = unit;
  2906. }
  2907. }
  2908. // if the view displays a single day or smaller
  2909. if (asRoughDays(duration) <= 1) {
  2910. if (this.isHiddenDay(start)) {
  2911. start = this.skipHiddenDays(start, direction);
  2912. start = startOfDay(start);
  2913. }
  2914. }
  2915. function computeRes() {
  2916. start = dateEnv.startOf(date, dateAlignment);
  2917. end = dateEnv.add(start, duration);
  2918. res = { start, end };
  2919. }
  2920. computeRes();
  2921. // if range is completely enveloped by hidden days, go past the hidden days
  2922. if (!this.trimHiddenDays(res)) {
  2923. date = this.skipHiddenDays(date, direction);
  2924. computeRes();
  2925. }
  2926. return res;
  2927. }
  2928. // Builds the "current" range when a dayCount is specified.
  2929. buildRangeFromDayCount(date, direction, dayCount) {
  2930. let { dateEnv, dateAlignment } = this.props;
  2931. let runningCount = 0;
  2932. let start = date;
  2933. let end;
  2934. if (dateAlignment) {
  2935. start = dateEnv.startOf(start, dateAlignment);
  2936. }
  2937. start = startOfDay(start);
  2938. start = this.skipHiddenDays(start, direction);
  2939. end = start;
  2940. do {
  2941. end = addDays(end, 1);
  2942. if (!this.isHiddenDay(end)) {
  2943. runningCount += 1;
  2944. }
  2945. } while (runningCount < dayCount);
  2946. return { start, end };
  2947. }
  2948. // Builds a normalized range object for the "visible" range,
  2949. // which is a way to define the currentRange and activeRange at the same time.
  2950. buildCustomVisibleRange(date) {
  2951. let { props } = this;
  2952. let input = props.visibleRangeInput;
  2953. let simpleInput = typeof input === 'function'
  2954. ? input.call(props.calendarApi, props.dateEnv.toDate(date))
  2955. : input;
  2956. let range = this.refineRange(simpleInput);
  2957. if (range && (range.start == null || range.end == null)) {
  2958. return null;
  2959. }
  2960. return range;
  2961. }
  2962. // Computes the range that will represent the element/cells for *rendering*,
  2963. // but which may have voided days/times.
  2964. // not responsible for trimming hidden days.
  2965. buildRenderRange(currentRange, currentRangeUnit, isRangeAllDay) {
  2966. return currentRange;
  2967. }
  2968. // Compute the duration value that should be added/substracted to the current date
  2969. // when a prev/next operation happens.
  2970. buildDateIncrement(fallback) {
  2971. let { dateIncrement } = this.props;
  2972. let customAlignment;
  2973. if (dateIncrement) {
  2974. return dateIncrement;
  2975. }
  2976. if ((customAlignment = this.props.dateAlignment)) {
  2977. return createDuration(1, customAlignment);
  2978. }
  2979. if (fallback) {
  2980. return fallback;
  2981. }
  2982. return createDuration({ days: 1 });
  2983. }
  2984. refineRange(rangeInput) {
  2985. if (rangeInput) {
  2986. let range = parseRange(rangeInput, this.props.dateEnv);
  2987. if (range) {
  2988. range = computeVisibleDayRange(range);
  2989. }
  2990. return range;
  2991. }
  2992. return null;
  2993. }
  2994. /* Hidden Days
  2995. ------------------------------------------------------------------------------------------------------------------*/
  2996. // Initializes internal variables related to calculating hidden days-of-week
  2997. initHiddenDays() {
  2998. let hiddenDays = this.props.hiddenDays || []; // array of day-of-week indices that are hidden
  2999. let isHiddenDayHash = []; // is the day-of-week hidden? (hash with day-of-week-index -> bool)
  3000. let dayCnt = 0;
  3001. let i;
  3002. if (this.props.weekends === false) {
  3003. hiddenDays.push(0, 6); // 0=sunday, 6=saturday
  3004. }
  3005. for (i = 0; i < 7; i += 1) {
  3006. if (!(isHiddenDayHash[i] = hiddenDays.indexOf(i) !== -1)) {
  3007. dayCnt += 1;
  3008. }
  3009. }
  3010. if (!dayCnt) {
  3011. throw new Error('invalid hiddenDays'); // all days were hidden? bad.
  3012. }
  3013. this.isHiddenDayHash = isHiddenDayHash;
  3014. }
  3015. // Remove days from the beginning and end of the range that are computed as hidden.
  3016. // If the whole range is trimmed off, returns null
  3017. trimHiddenDays(range) {
  3018. let { start, end } = range;
  3019. if (start) {
  3020. start = this.skipHiddenDays(start);
  3021. }
  3022. if (end) {
  3023. end = this.skipHiddenDays(end, -1, true);
  3024. }
  3025. if (start == null || end == null || start < end) {
  3026. return { start, end };
  3027. }
  3028. return null;
  3029. }
  3030. // Is the current day hidden?
  3031. // `day` is a day-of-week index (0-6), or a Date (used for UTC)
  3032. isHiddenDay(day) {
  3033. if (day instanceof Date) {
  3034. day = day.getUTCDay();
  3035. }
  3036. return this.isHiddenDayHash[day];
  3037. }
  3038. // Incrementing the current day until it is no longer a hidden day, returning a copy.
  3039. // DOES NOT CONSIDER validRange!
  3040. // If the initial value of `date` is not a hidden day, don't do anything.
  3041. // Pass `isExclusive` as `true` if you are dealing with an end date.
  3042. // `inc` defaults to `1` (increment one day forward each time)
  3043. skipHiddenDays(date, inc = 1, isExclusive = false) {
  3044. while (this.isHiddenDayHash[(date.getUTCDay() + (isExclusive ? inc : 0) + 7) % 7]) {
  3045. date = addDays(date, inc);
  3046. }
  3047. return date;
  3048. }
  3049. }
  3050. function createEventInstance(defId, range, forcedStartTzo, forcedEndTzo) {
  3051. return {
  3052. instanceId: guid(),
  3053. defId,
  3054. range,
  3055. forcedStartTzo: forcedStartTzo == null ? null : forcedStartTzo,
  3056. forcedEndTzo: forcedEndTzo == null ? null : forcedEndTzo,
  3057. };
  3058. }
  3059. function parseRecurring(refined, defaultAllDay, dateEnv, recurringTypes) {
  3060. for (let i = 0; i < recurringTypes.length; i += 1) {
  3061. let parsed = recurringTypes[i].parse(refined, dateEnv);
  3062. if (parsed) {
  3063. let { allDay } = refined;
  3064. if (allDay == null) {
  3065. allDay = defaultAllDay;
  3066. if (allDay == null) {
  3067. allDay = parsed.allDayGuess;
  3068. if (allDay == null) {
  3069. allDay = false;
  3070. }
  3071. }
  3072. }
  3073. return {
  3074. allDay,
  3075. duration: parsed.duration,
  3076. typeData: parsed.typeData,
  3077. typeId: i,
  3078. };
  3079. }
  3080. }
  3081. return null;
  3082. }
  3083. function expandRecurring(eventStore, framingRange, context) {
  3084. let { dateEnv, pluginHooks, options } = context;
  3085. let { defs, instances } = eventStore;
  3086. // remove existing recurring instances
  3087. // TODO: bad. always expand events as a second step
  3088. instances = filterHash(instances, (instance) => !defs[instance.defId].recurringDef);
  3089. for (let defId in defs) {
  3090. let def = defs[defId];
  3091. if (def.recurringDef) {
  3092. let { duration } = def.recurringDef;
  3093. if (!duration) {
  3094. duration = def.allDay ?
  3095. options.defaultAllDayEventDuration :
  3096. options.defaultTimedEventDuration;
  3097. }
  3098. let starts = expandRecurringRanges(def, duration, framingRange, dateEnv, pluginHooks.recurringTypes);
  3099. for (let start of starts) {
  3100. let instance = createEventInstance(defId, {
  3101. start,
  3102. end: dateEnv.add(start, duration),
  3103. });
  3104. instances[instance.instanceId] = instance;
  3105. }
  3106. }
  3107. }
  3108. return { defs, instances };
  3109. }
  3110. /*
  3111. Event MUST have a recurringDef
  3112. */
  3113. function expandRecurringRanges(eventDef, duration, framingRange, dateEnv, recurringTypes) {
  3114. let typeDef = recurringTypes[eventDef.recurringDef.typeId];
  3115. let markers = typeDef.expand(eventDef.recurringDef.typeData, {
  3116. start: dateEnv.subtract(framingRange.start, duration),
  3117. end: framingRange.end,
  3118. }, dateEnv);
  3119. // the recurrence plugins don't guarantee that all-day events are start-of-day, so we have to
  3120. if (eventDef.allDay) {
  3121. markers = markers.map(startOfDay);
  3122. }
  3123. return markers;
  3124. }
  3125. const EVENT_NON_DATE_REFINERS = {
  3126. id: String,
  3127. groupId: String,
  3128. title: String,
  3129. url: String,
  3130. interactive: Boolean,
  3131. };
  3132. const EVENT_DATE_REFINERS = {
  3133. start: identity,
  3134. end: identity,
  3135. date: identity,
  3136. allDay: Boolean,
  3137. };
  3138. const EVENT_REFINERS = Object.assign(Object.assign(Object.assign({}, EVENT_NON_DATE_REFINERS), EVENT_DATE_REFINERS), { extendedProps: identity });
  3139. function parseEvent(raw, eventSource, context, allowOpenRange, refiners = buildEventRefiners(context), defIdMap, instanceIdMap) {
  3140. let { refined, extra } = refineEventDef(raw, context, refiners);
  3141. let defaultAllDay = computeIsDefaultAllDay(eventSource, context);
  3142. let recurringRes = parseRecurring(refined, defaultAllDay, context.dateEnv, context.pluginHooks.recurringTypes);
  3143. if (recurringRes) {
  3144. let def = parseEventDef(refined, extra, eventSource ? eventSource.sourceId : '', recurringRes.allDay, Boolean(recurringRes.duration), context, defIdMap);
  3145. def.recurringDef = {
  3146. typeId: recurringRes.typeId,
  3147. typeData: recurringRes.typeData,
  3148. duration: recurringRes.duration,
  3149. };
  3150. return { def, instance: null };
  3151. }
  3152. let singleRes = parseSingle(refined, defaultAllDay, context, allowOpenRange);
  3153. if (singleRes) {
  3154. let def = parseEventDef(refined, extra, eventSource ? eventSource.sourceId : '', singleRes.allDay, singleRes.hasEnd, context, defIdMap);
  3155. let instance = createEventInstance(def.defId, singleRes.range, singleRes.forcedStartTzo, singleRes.forcedEndTzo);
  3156. if (instanceIdMap && def.publicId && instanceIdMap[def.publicId]) {
  3157. instance.instanceId = instanceIdMap[def.publicId];
  3158. }
  3159. return { def, instance };
  3160. }
  3161. return null;
  3162. }
  3163. function refineEventDef(raw, context, refiners = buildEventRefiners(context)) {
  3164. return refineProps(raw, refiners);
  3165. }
  3166. function buildEventRefiners(context) {
  3167. return Object.assign(Object.assign(Object.assign({}, EVENT_UI_REFINERS), EVENT_REFINERS), context.pluginHooks.eventRefiners);
  3168. }
  3169. /*
  3170. Will NOT populate extendedProps with the leftover properties.
  3171. Will NOT populate date-related props.
  3172. */
  3173. function parseEventDef(refined, extra, sourceId, allDay, hasEnd, context, defIdMap) {
  3174. let def = {
  3175. title: refined.title || '',
  3176. groupId: refined.groupId || '',
  3177. publicId: refined.id || '',
  3178. url: refined.url || '',
  3179. recurringDef: null,
  3180. defId: ((defIdMap && refined.id) ? defIdMap[refined.id] : '') || guid(),
  3181. sourceId,
  3182. allDay,
  3183. hasEnd,
  3184. interactive: refined.interactive,
  3185. ui: createEventUi(refined, context),
  3186. extendedProps: Object.assign(Object.assign({}, (refined.extendedProps || {})), extra),
  3187. };
  3188. for (let memberAdder of context.pluginHooks.eventDefMemberAdders) {
  3189. Object.assign(def, memberAdder(refined));
  3190. }
  3191. // help out EventImpl from having user modify props
  3192. Object.freeze(def.ui.classNames);
  3193. Object.freeze(def.extendedProps);
  3194. return def;
  3195. }
  3196. function parseSingle(refined, defaultAllDay, context, allowOpenRange) {
  3197. let { allDay } = refined;
  3198. let startMeta;
  3199. let startMarker = null;
  3200. let hasEnd = false;
  3201. let endMeta;
  3202. let endMarker = null;
  3203. let startInput = refined.start != null ? refined.start : refined.date;
  3204. startMeta = context.dateEnv.createMarkerMeta(startInput);
  3205. if (startMeta) {
  3206. startMarker = startMeta.marker;
  3207. }
  3208. else if (!allowOpenRange) {
  3209. return null;
  3210. }
  3211. if (refined.end != null) {
  3212. endMeta = context.dateEnv.createMarkerMeta(refined.end);
  3213. }
  3214. if (allDay == null) {
  3215. if (defaultAllDay != null) {
  3216. allDay = defaultAllDay;
  3217. }
  3218. else {
  3219. // fall back to the date props LAST
  3220. allDay = (!startMeta || startMeta.isTimeUnspecified) &&
  3221. (!endMeta || endMeta.isTimeUnspecified);
  3222. }
  3223. }
  3224. if (allDay && startMarker) {
  3225. startMarker = startOfDay(startMarker);
  3226. }
  3227. if (endMeta) {
  3228. endMarker = endMeta.marker;
  3229. if (allDay) {
  3230. endMarker = startOfDay(endMarker);
  3231. }
  3232. if (startMarker && endMarker <= startMarker) {
  3233. endMarker = null;
  3234. }
  3235. }
  3236. if (endMarker) {
  3237. hasEnd = true;
  3238. }
  3239. else if (!allowOpenRange) {
  3240. hasEnd = context.options.forceEventDuration || false;
  3241. endMarker = context.dateEnv.add(startMarker, allDay ?
  3242. context.options.defaultAllDayEventDuration :
  3243. context.options.defaultTimedEventDuration);
  3244. }
  3245. return {
  3246. allDay,
  3247. hasEnd,
  3248. range: { start: startMarker, end: endMarker },
  3249. forcedStartTzo: startMeta ? startMeta.forcedTzo : null,
  3250. forcedEndTzo: endMeta ? endMeta.forcedTzo : null,
  3251. };
  3252. }
  3253. function computeIsDefaultAllDay(eventSource, context) {
  3254. let res = null;
  3255. if (eventSource) {
  3256. res = eventSource.defaultAllDay;
  3257. }
  3258. if (res == null) {
  3259. res = context.options.defaultAllDay;
  3260. }
  3261. return res;
  3262. }
  3263. function parseEvents(rawEvents, eventSource, context, allowOpenRange, defIdMap, instanceIdMap) {
  3264. let eventStore = createEmptyEventStore();
  3265. let eventRefiners = buildEventRefiners(context);
  3266. for (let rawEvent of rawEvents) {
  3267. let tuple = parseEvent(rawEvent, eventSource, context, allowOpenRange, eventRefiners, defIdMap, instanceIdMap);
  3268. if (tuple) {
  3269. eventTupleToStore(tuple, eventStore);
  3270. }
  3271. }
  3272. return eventStore;
  3273. }
  3274. function eventTupleToStore(tuple, eventStore = createEmptyEventStore()) {
  3275. eventStore.defs[tuple.def.defId] = tuple.def;
  3276. if (tuple.instance) {
  3277. eventStore.instances[tuple.instance.instanceId] = tuple.instance;
  3278. }
  3279. return eventStore;
  3280. }
  3281. // retrieves events that have the same groupId as the instance specified by `instanceId`
  3282. // or they are the same as the instance.
  3283. // why might instanceId not be in the store? an event from another calendar?
  3284. function getRelevantEvents(eventStore, instanceId) {
  3285. let instance = eventStore.instances[instanceId];
  3286. if (instance) {
  3287. let def = eventStore.defs[instance.defId];
  3288. // get events/instances with same group
  3289. let newStore = filterEventStoreDefs(eventStore, (lookDef) => isEventDefsGrouped(def, lookDef));
  3290. // add the original
  3291. // TODO: wish we could use eventTupleToStore or something like it
  3292. newStore.defs[def.defId] = def;
  3293. newStore.instances[instance.instanceId] = instance;
  3294. return newStore;
  3295. }
  3296. return createEmptyEventStore();
  3297. }
  3298. function isEventDefsGrouped(def0, def1) {
  3299. return Boolean(def0.groupId && def0.groupId === def1.groupId);
  3300. }
  3301. function createEmptyEventStore() {
  3302. return { defs: {}, instances: {} };
  3303. }
  3304. function mergeEventStores(store0, store1) {
  3305. return {
  3306. defs: Object.assign(Object.assign({}, store0.defs), store1.defs),
  3307. instances: Object.assign(Object.assign({}, store0.instances), store1.instances),
  3308. };
  3309. }
  3310. function filterEventStoreDefs(eventStore, filterFunc) {
  3311. let defs = filterHash(eventStore.defs, filterFunc);
  3312. let instances = filterHash(eventStore.instances, (instance) => (defs[instance.defId] // still exists?
  3313. ));
  3314. return { defs, instances };
  3315. }
  3316. function excludeSubEventStore(master, sub) {
  3317. let { defs, instances } = master;
  3318. let filteredDefs = {};
  3319. let filteredInstances = {};
  3320. for (let defId in defs) {
  3321. if (!sub.defs[defId]) { // not explicitly excluded
  3322. filteredDefs[defId] = defs[defId];
  3323. }
  3324. }
  3325. for (let instanceId in instances) {
  3326. if (!sub.instances[instanceId] && // not explicitly excluded
  3327. filteredDefs[instances[instanceId].defId] // def wasn't filtered away
  3328. ) {
  3329. filteredInstances[instanceId] = instances[instanceId];
  3330. }
  3331. }
  3332. return {
  3333. defs: filteredDefs,
  3334. instances: filteredInstances,
  3335. };
  3336. }
  3337. function normalizeConstraint(input, context) {
  3338. if (Array.isArray(input)) {
  3339. return parseEvents(input, null, context, true); // allowOpenRange=true
  3340. }
  3341. if (typeof input === 'object' && input) { // non-null object
  3342. return parseEvents([input], null, context, true); // allowOpenRange=true
  3343. }
  3344. if (input != null) {
  3345. return String(input);
  3346. }
  3347. return null;
  3348. }
  3349. function parseClassNames(raw) {
  3350. if (Array.isArray(raw)) {
  3351. return raw;
  3352. }
  3353. if (typeof raw === 'string') {
  3354. return raw.split(/\s+/);
  3355. }
  3356. return [];
  3357. }
  3358. // TODO: better called "EventSettings" or "EventConfig"
  3359. // TODO: move this file into structs
  3360. // TODO: separate constraint/overlap/allow, because selection uses only that, not other props
  3361. const EVENT_UI_REFINERS = {
  3362. display: String,
  3363. editable: Boolean,
  3364. startEditable: Boolean,
  3365. durationEditable: Boolean,
  3366. constraint: identity,
  3367. overlap: identity,
  3368. allow: identity,
  3369. className: parseClassNames,
  3370. classNames: parseClassNames,
  3371. color: String,
  3372. backgroundColor: String,
  3373. borderColor: String,
  3374. textColor: String,
  3375. };
  3376. const EMPTY_EVENT_UI = {
  3377. display: null,
  3378. startEditable: null,
  3379. durationEditable: null,
  3380. constraints: [],
  3381. overlap: null,
  3382. allows: [],
  3383. backgroundColor: '',
  3384. borderColor: '',
  3385. textColor: '',
  3386. classNames: [],
  3387. };
  3388. function createEventUi(refined, context) {
  3389. let constraint = normalizeConstraint(refined.constraint, context);
  3390. return {
  3391. display: refined.display || null,
  3392. startEditable: refined.startEditable != null ? refined.startEditable : refined.editable,
  3393. durationEditable: refined.durationEditable != null ? refined.durationEditable : refined.editable,
  3394. constraints: constraint != null ? [constraint] : [],
  3395. overlap: refined.overlap != null ? refined.overlap : null,
  3396. allows: refined.allow != null ? [refined.allow] : [],
  3397. backgroundColor: refined.backgroundColor || refined.color || '',
  3398. borderColor: refined.borderColor || refined.color || '',
  3399. textColor: refined.textColor || '',
  3400. classNames: (refined.className || []).concat(refined.classNames || []), // join singular and plural
  3401. };
  3402. }
  3403. // TODO: prevent against problems with <2 args!
  3404. function combineEventUis(uis) {
  3405. return uis.reduce(combineTwoEventUis, EMPTY_EVENT_UI);
  3406. }
  3407. function combineTwoEventUis(item0, item1) {
  3408. return {
  3409. display: item1.display != null ? item1.display : item0.display,
  3410. startEditable: item1.startEditable != null ? item1.startEditable : item0.startEditable,
  3411. durationEditable: item1.durationEditable != null ? item1.durationEditable : item0.durationEditable,
  3412. constraints: item0.constraints.concat(item1.constraints),
  3413. overlap: typeof item1.overlap === 'boolean' ? item1.overlap : item0.overlap,
  3414. allows: item0.allows.concat(item1.allows),
  3415. backgroundColor: item1.backgroundColor || item0.backgroundColor,
  3416. borderColor: item1.borderColor || item0.borderColor,
  3417. textColor: item1.textColor || item0.textColor,
  3418. classNames: item0.classNames.concat(item1.classNames),
  3419. };
  3420. }
  3421. const EVENT_SOURCE_REFINERS = {
  3422. id: String,
  3423. defaultAllDay: Boolean,
  3424. url: String,
  3425. format: String,
  3426. events: identity,
  3427. eventDataTransform: identity,
  3428. // for any network-related sources
  3429. success: identity,
  3430. failure: identity,
  3431. };
  3432. function parseEventSource(raw, context, refiners = buildEventSourceRefiners(context)) {
  3433. let rawObj;
  3434. if (typeof raw === 'string') {
  3435. rawObj = { url: raw };
  3436. }
  3437. else if (typeof raw === 'function' || Array.isArray(raw)) {
  3438. rawObj = { events: raw };
  3439. }
  3440. else if (typeof raw === 'object' && raw) { // not null
  3441. rawObj = raw;
  3442. }
  3443. if (rawObj) {
  3444. let { refined, extra } = refineProps(rawObj, refiners);
  3445. let metaRes = buildEventSourceMeta(refined, context);
  3446. if (metaRes) {
  3447. return {
  3448. _raw: raw,
  3449. isFetching: false,
  3450. latestFetchId: '',
  3451. fetchRange: null,
  3452. defaultAllDay: refined.defaultAllDay,
  3453. eventDataTransform: refined.eventDataTransform,
  3454. success: refined.success,
  3455. failure: refined.failure,
  3456. publicId: refined.id || '',
  3457. sourceId: guid(),
  3458. sourceDefId: metaRes.sourceDefId,
  3459. meta: metaRes.meta,
  3460. ui: createEventUi(refined, context),
  3461. extendedProps: extra,
  3462. };
  3463. }
  3464. }
  3465. return null;
  3466. }
  3467. function buildEventSourceRefiners(context) {
  3468. return Object.assign(Object.assign(Object.assign({}, EVENT_UI_REFINERS), EVENT_SOURCE_REFINERS), context.pluginHooks.eventSourceRefiners);
  3469. }
  3470. function buildEventSourceMeta(raw, context) {
  3471. let defs = context.pluginHooks.eventSourceDefs;
  3472. for (let i = defs.length - 1; i >= 0; i -= 1) { // later-added plugins take precedence
  3473. let def = defs[i];
  3474. let meta = def.parseMeta(raw);
  3475. if (meta) {
  3476. return { sourceDefId: i, meta };
  3477. }
  3478. }
  3479. return null;
  3480. }
  3481. function reduceEventStore(eventStore, action, eventSources, dateProfile, context) {
  3482. switch (action.type) {
  3483. case 'RECEIVE_EVENTS': // raw
  3484. return receiveRawEvents(eventStore, eventSources[action.sourceId], action.fetchId, action.fetchRange, action.rawEvents, context);
  3485. case 'RESET_RAW_EVENTS':
  3486. return resetRawEvents(eventStore, eventSources[action.sourceId], action.rawEvents, dateProfile.activeRange, context);
  3487. case 'ADD_EVENTS': // already parsed, but not expanded
  3488. return addEvent(eventStore, action.eventStore, // new ones
  3489. dateProfile ? dateProfile.activeRange : null, context);
  3490. case 'RESET_EVENTS':
  3491. return action.eventStore;
  3492. case 'MERGE_EVENTS': // already parsed and expanded
  3493. return mergeEventStores(eventStore, action.eventStore);
  3494. case 'PREV': // TODO: how do we track all actions that affect dateProfile :(
  3495. case 'NEXT':
  3496. case 'CHANGE_DATE':
  3497. case 'CHANGE_VIEW_TYPE':
  3498. if (dateProfile) {
  3499. return expandRecurring(eventStore, dateProfile.activeRange, context);
  3500. }
  3501. return eventStore;
  3502. case 'REMOVE_EVENTS':
  3503. return excludeSubEventStore(eventStore, action.eventStore);
  3504. case 'REMOVE_EVENT_SOURCE':
  3505. return excludeEventsBySourceId(eventStore, action.sourceId);
  3506. case 'REMOVE_ALL_EVENT_SOURCES':
  3507. return filterEventStoreDefs(eventStore, (eventDef) => (!eventDef.sourceId // only keep events with no source id
  3508. ));
  3509. case 'REMOVE_ALL_EVENTS':
  3510. return createEmptyEventStore();
  3511. default:
  3512. return eventStore;
  3513. }
  3514. }
  3515. function receiveRawEvents(eventStore, eventSource, fetchId, fetchRange, rawEvents, context) {
  3516. if (eventSource && // not already removed
  3517. fetchId === eventSource.latestFetchId // TODO: wish this logic was always in event-sources
  3518. ) {
  3519. let subset = parseEvents(transformRawEvents(rawEvents, eventSource, context), eventSource, context);
  3520. if (fetchRange) {
  3521. subset = expandRecurring(subset, fetchRange, context);
  3522. }
  3523. return mergeEventStores(excludeEventsBySourceId(eventStore, eventSource.sourceId), subset);
  3524. }
  3525. return eventStore;
  3526. }
  3527. function resetRawEvents(existingEventStore, eventSource, rawEvents, activeRange, context) {
  3528. const { defIdMap, instanceIdMap } = buildPublicIdMaps(existingEventStore);
  3529. let newEventStore = parseEvents(transformRawEvents(rawEvents, eventSource, context), eventSource, context, false, defIdMap, instanceIdMap);
  3530. return expandRecurring(newEventStore, activeRange, context);
  3531. }
  3532. function transformRawEvents(rawEvents, eventSource, context) {
  3533. let calEachTransform = context.options.eventDataTransform;
  3534. let sourceEachTransform = eventSource ? eventSource.eventDataTransform : null;
  3535. if (sourceEachTransform) {
  3536. rawEvents = transformEachRawEvent(rawEvents, sourceEachTransform);
  3537. }
  3538. if (calEachTransform) {
  3539. rawEvents = transformEachRawEvent(rawEvents, calEachTransform);
  3540. }
  3541. return rawEvents;
  3542. }
  3543. function transformEachRawEvent(rawEvents, func) {
  3544. let refinedEvents;
  3545. if (!func) {
  3546. refinedEvents = rawEvents;
  3547. }
  3548. else {
  3549. refinedEvents = [];
  3550. for (let rawEvent of rawEvents) {
  3551. let refinedEvent = func(rawEvent);
  3552. if (refinedEvent) {
  3553. refinedEvents.push(refinedEvent);
  3554. }
  3555. else if (refinedEvent == null) {
  3556. refinedEvents.push(rawEvent);
  3557. } // if a different falsy value, do nothing
  3558. }
  3559. }
  3560. return refinedEvents;
  3561. }
  3562. function addEvent(eventStore, subset, expandRange, context) {
  3563. if (expandRange) {
  3564. subset = expandRecurring(subset, expandRange, context);
  3565. }
  3566. return mergeEventStores(eventStore, subset);
  3567. }
  3568. function rezoneEventStoreDates(eventStore, oldDateEnv, newDateEnv) {
  3569. let { defs } = eventStore;
  3570. let instances = mapHash(eventStore.instances, (instance) => {
  3571. let def = defs[instance.defId];
  3572. if (def.allDay) {
  3573. return instance; // isn't dependent on timezone
  3574. }
  3575. return Object.assign(Object.assign({}, instance), { range: {
  3576. start: newDateEnv.createMarker(oldDateEnv.toDate(instance.range.start, instance.forcedStartTzo)),
  3577. end: newDateEnv.createMarker(oldDateEnv.toDate(instance.range.end, instance.forcedEndTzo)),
  3578. }, forcedStartTzo: newDateEnv.canComputeOffset ? null : instance.forcedStartTzo, forcedEndTzo: newDateEnv.canComputeOffset ? null : instance.forcedEndTzo });
  3579. });
  3580. return { defs, instances };
  3581. }
  3582. function excludeEventsBySourceId(eventStore, sourceId) {
  3583. return filterEventStoreDefs(eventStore, (eventDef) => eventDef.sourceId !== sourceId);
  3584. }
  3585. // QUESTION: why not just return instances? do a general object-property-exclusion util
  3586. function excludeInstances(eventStore, removals) {
  3587. return {
  3588. defs: eventStore.defs,
  3589. instances: filterHash(eventStore.instances, (instance) => !removals[instance.instanceId]),
  3590. };
  3591. }
  3592. function buildPublicIdMaps(eventStore) {
  3593. const { defs, instances } = eventStore;
  3594. const defIdMap = {};
  3595. const instanceIdMap = {};
  3596. for (let defId in defs) {
  3597. const def = defs[defId];
  3598. const { publicId } = def;
  3599. if (publicId) {
  3600. defIdMap[publicId] = defId;
  3601. }
  3602. }
  3603. for (let instanceId in instances) {
  3604. const instance = instances[instanceId];
  3605. const def = defs[instance.defId];
  3606. const { publicId } = def;
  3607. if (publicId) {
  3608. instanceIdMap[publicId] = instanceId;
  3609. }
  3610. }
  3611. return { defIdMap, instanceIdMap };
  3612. }
  3613. class Emitter {
  3614. constructor() {
  3615. this.handlers = {};
  3616. this.thisContext = null;
  3617. }
  3618. setThisContext(thisContext) {
  3619. this.thisContext = thisContext;
  3620. }
  3621. setOptions(options) {
  3622. this.options = options;
  3623. }
  3624. on(type, handler) {
  3625. addToHash(this.handlers, type, handler);
  3626. }
  3627. off(type, handler) {
  3628. removeFromHash(this.handlers, type, handler);
  3629. }
  3630. trigger(type, ...args) {
  3631. let attachedHandlers = this.handlers[type] || [];
  3632. let optionHandler = this.options && this.options[type];
  3633. let handlers = [].concat(optionHandler || [], attachedHandlers);
  3634. for (let handler of handlers) {
  3635. handler.apply(this.thisContext, args);
  3636. }
  3637. }
  3638. hasHandlers(type) {
  3639. return Boolean((this.handlers[type] && this.handlers[type].length) ||
  3640. (this.options && this.options[type]));
  3641. }
  3642. }
  3643. function addToHash(hash, type, handler) {
  3644. (hash[type] || (hash[type] = []))
  3645. .push(handler);
  3646. }
  3647. function removeFromHash(hash, type, handler) {
  3648. if (handler) {
  3649. if (hash[type]) {
  3650. hash[type] = hash[type].filter((func) => func !== handler);
  3651. }
  3652. }
  3653. else {
  3654. delete hash[type]; // remove all handler funcs for this type
  3655. }
  3656. }
  3657. const DEF_DEFAULTS = {
  3658. startTime: '09:00',
  3659. endTime: '17:00',
  3660. daysOfWeek: [1, 2, 3, 4, 5],
  3661. display: 'inverse-background',
  3662. classNames: 'fc-non-business',
  3663. groupId: '_businessHours', // so multiple defs get grouped
  3664. };
  3665. /*
  3666. TODO: pass around as EventDefHash!!!
  3667. */
  3668. function parseBusinessHours(input, context) {
  3669. return parseEvents(refineInputs(input), null, context);
  3670. }
  3671. function refineInputs(input) {
  3672. let rawDefs;
  3673. if (input === true) {
  3674. rawDefs = [{}]; // will get DEF_DEFAULTS verbatim
  3675. }
  3676. else if (Array.isArray(input)) {
  3677. // if specifying an array, every sub-definition NEEDS a day-of-week
  3678. rawDefs = input.filter((rawDef) => rawDef.daysOfWeek);
  3679. }
  3680. else if (typeof input === 'object' && input) { // non-null object
  3681. rawDefs = [input];
  3682. }
  3683. else { // is probably false
  3684. rawDefs = [];
  3685. }
  3686. rawDefs = rawDefs.map((rawDef) => (Object.assign(Object.assign({}, DEF_DEFAULTS), rawDef)));
  3687. return rawDefs;
  3688. }
  3689. function triggerDateSelect(selection, pev, context) {
  3690. context.emitter.trigger('select', Object.assign(Object.assign({}, buildDateSpanApiWithContext(selection, context)), { jsEvent: pev ? pev.origEvent : null, view: context.viewApi || context.calendarApi.view }));
  3691. }
  3692. function triggerDateUnselect(pev, context) {
  3693. context.emitter.trigger('unselect', {
  3694. jsEvent: pev ? pev.origEvent : null,
  3695. view: context.viewApi || context.calendarApi.view,
  3696. });
  3697. }
  3698. function buildDateSpanApiWithContext(dateSpan, context) {
  3699. let props = {};
  3700. for (let transform of context.pluginHooks.dateSpanTransforms) {
  3701. Object.assign(props, transform(dateSpan, context));
  3702. }
  3703. Object.assign(props, buildDateSpanApi(dateSpan, context.dateEnv));
  3704. return props;
  3705. }
  3706. // Given an event's allDay status and start date, return what its fallback end date should be.
  3707. // TODO: rename to computeDefaultEventEnd
  3708. function getDefaultEventEnd(allDay, marker, context) {
  3709. let { dateEnv, options } = context;
  3710. let end = marker;
  3711. if (allDay) {
  3712. end = startOfDay(end);
  3713. end = dateEnv.add(end, options.defaultAllDayEventDuration);
  3714. }
  3715. else {
  3716. end = dateEnv.add(end, options.defaultTimedEventDuration);
  3717. }
  3718. return end;
  3719. }
  3720. // applies the mutation to ALL defs/instances within the event store
  3721. function applyMutationToEventStore(eventStore, eventConfigBase, mutation, context) {
  3722. let eventConfigs = compileEventUis(eventStore.defs, eventConfigBase);
  3723. let dest = createEmptyEventStore();
  3724. for (let defId in eventStore.defs) {
  3725. let def = eventStore.defs[defId];
  3726. dest.defs[defId] = applyMutationToEventDef(def, eventConfigs[defId], mutation, context);
  3727. }
  3728. for (let instanceId in eventStore.instances) {
  3729. let instance = eventStore.instances[instanceId];
  3730. let def = dest.defs[instance.defId]; // important to grab the newly modified def
  3731. dest.instances[instanceId] = applyMutationToEventInstance(instance, def, eventConfigs[instance.defId], mutation, context);
  3732. }
  3733. return dest;
  3734. }
  3735. function applyMutationToEventDef(eventDef, eventConfig, mutation, context) {
  3736. let standardProps = mutation.standardProps || {};
  3737. // if hasEnd has not been specified, guess a good value based on deltas.
  3738. // if duration will change, there's no way the default duration will persist,
  3739. // and thus, we need to mark the event as having a real end
  3740. if (standardProps.hasEnd == null &&
  3741. eventConfig.durationEditable &&
  3742. (mutation.startDelta || mutation.endDelta)) {
  3743. standardProps.hasEnd = true; // TODO: is this mutation okay?
  3744. }
  3745. let copy = Object.assign(Object.assign(Object.assign({}, eventDef), standardProps), { ui: Object.assign(Object.assign({}, eventDef.ui), standardProps.ui) });
  3746. if (mutation.extendedProps) {
  3747. copy.extendedProps = Object.assign(Object.assign({}, copy.extendedProps), mutation.extendedProps);
  3748. }
  3749. for (let applier of context.pluginHooks.eventDefMutationAppliers) {
  3750. applier(copy, mutation, context);
  3751. }
  3752. if (!copy.hasEnd && context.options.forceEventDuration) {
  3753. copy.hasEnd = true;
  3754. }
  3755. return copy;
  3756. }
  3757. function applyMutationToEventInstance(eventInstance, eventDef, // must first be modified by applyMutationToEventDef
  3758. eventConfig, mutation, context) {
  3759. let { dateEnv } = context;
  3760. let forceAllDay = mutation.standardProps && mutation.standardProps.allDay === true;
  3761. let clearEnd = mutation.standardProps && mutation.standardProps.hasEnd === false;
  3762. let copy = Object.assign({}, eventInstance);
  3763. if (forceAllDay) {
  3764. copy.range = computeAlignedDayRange(copy.range);
  3765. }
  3766. if (mutation.datesDelta && eventConfig.startEditable) {
  3767. copy.range = {
  3768. start: dateEnv.add(copy.range.start, mutation.datesDelta),
  3769. end: dateEnv.add(copy.range.end, mutation.datesDelta),
  3770. };
  3771. }
  3772. if (mutation.startDelta && eventConfig.durationEditable) {
  3773. copy.range = {
  3774. start: dateEnv.add(copy.range.start, mutation.startDelta),
  3775. end: copy.range.end,
  3776. };
  3777. }
  3778. if (mutation.endDelta && eventConfig.durationEditable) {
  3779. copy.range = {
  3780. start: copy.range.start,
  3781. end: dateEnv.add(copy.range.end, mutation.endDelta),
  3782. };
  3783. }
  3784. if (clearEnd) {
  3785. copy.range = {
  3786. start: copy.range.start,
  3787. end: getDefaultEventEnd(eventDef.allDay, copy.range.start, context),
  3788. };
  3789. }
  3790. // in case event was all-day but the supplied deltas were not
  3791. // better util for this?
  3792. if (eventDef.allDay) {
  3793. copy.range = {
  3794. start: startOfDay(copy.range.start),
  3795. end: startOfDay(copy.range.end),
  3796. };
  3797. }
  3798. // handle invalid durations
  3799. if (copy.range.end < copy.range.start) {
  3800. copy.range.end = getDefaultEventEnd(eventDef.allDay, copy.range.start, context);
  3801. }
  3802. return copy;
  3803. }
  3804. class EventSourceImpl {
  3805. constructor(context, internalEventSource) {
  3806. this.context = context;
  3807. this.internalEventSource = internalEventSource;
  3808. }
  3809. remove() {
  3810. this.context.dispatch({
  3811. type: 'REMOVE_EVENT_SOURCE',
  3812. sourceId: this.internalEventSource.sourceId,
  3813. });
  3814. }
  3815. refetch() {
  3816. this.context.dispatch({
  3817. type: 'FETCH_EVENT_SOURCES',
  3818. sourceIds: [this.internalEventSource.sourceId],
  3819. isRefetch: true,
  3820. });
  3821. }
  3822. get id() {
  3823. return this.internalEventSource.publicId;
  3824. }
  3825. get url() {
  3826. return this.internalEventSource.meta.url;
  3827. }
  3828. get format() {
  3829. return this.internalEventSource.meta.format; // TODO: bad. not guaranteed
  3830. }
  3831. }
  3832. class EventImpl {
  3833. // instance will be null if expressing a recurring event that has no current instances,
  3834. // OR if trying to validate an incoming external event that has no dates assigned
  3835. constructor(context, def, instance) {
  3836. this._context = context;
  3837. this._def = def;
  3838. this._instance = instance || null;
  3839. }
  3840. /*
  3841. TODO: make event struct more responsible for this
  3842. */
  3843. setProp(name, val) {
  3844. if (name in EVENT_DATE_REFINERS) {
  3845. console.warn('Could not set date-related prop \'name\'. Use one of the date-related methods instead.');
  3846. // TODO: make proper aliasing system?
  3847. }
  3848. else if (name === 'id') {
  3849. val = EVENT_NON_DATE_REFINERS[name](val);
  3850. this.mutate({
  3851. standardProps: { publicId: val }, // hardcoded internal name
  3852. });
  3853. }
  3854. else if (name in EVENT_NON_DATE_REFINERS) {
  3855. val = EVENT_NON_DATE_REFINERS[name](val);
  3856. this.mutate({
  3857. standardProps: { [name]: val },
  3858. });
  3859. }
  3860. else if (name in EVENT_UI_REFINERS) {
  3861. let ui = EVENT_UI_REFINERS[name](val);
  3862. if (name === 'color') {
  3863. ui = { backgroundColor: val, borderColor: val };
  3864. }
  3865. else if (name === 'editable') {
  3866. ui = { startEditable: val, durationEditable: val };
  3867. }
  3868. else {
  3869. ui = { [name]: val };
  3870. }
  3871. this.mutate({
  3872. standardProps: { ui },
  3873. });
  3874. }
  3875. else {
  3876. console.warn(`Could not set prop '${name}'. Use setExtendedProp instead.`);
  3877. }
  3878. }
  3879. setExtendedProp(name, val) {
  3880. this.mutate({
  3881. extendedProps: { [name]: val },
  3882. });
  3883. }
  3884. setStart(startInput, options = {}) {
  3885. let { dateEnv } = this._context;
  3886. let start = dateEnv.createMarker(startInput);
  3887. if (start && this._instance) { // TODO: warning if parsed bad
  3888. let instanceRange = this._instance.range;
  3889. let startDelta = diffDates(instanceRange.start, start, dateEnv, options.granularity); // what if parsed bad!?
  3890. if (options.maintainDuration) {
  3891. this.mutate({ datesDelta: startDelta });
  3892. }
  3893. else {
  3894. this.mutate({ startDelta });
  3895. }
  3896. }
  3897. }
  3898. setEnd(endInput, options = {}) {
  3899. let { dateEnv } = this._context;
  3900. let end;
  3901. if (endInput != null) {
  3902. end = dateEnv.createMarker(endInput);
  3903. if (!end) {
  3904. return; // TODO: warning if parsed bad
  3905. }
  3906. }
  3907. if (this._instance) {
  3908. if (end) {
  3909. let endDelta = diffDates(this._instance.range.end, end, dateEnv, options.granularity);
  3910. this.mutate({ endDelta });
  3911. }
  3912. else {
  3913. this.mutate({ standardProps: { hasEnd: false } });
  3914. }
  3915. }
  3916. }
  3917. setDates(startInput, endInput, options = {}) {
  3918. let { dateEnv } = this._context;
  3919. let standardProps = { allDay: options.allDay };
  3920. let start = dateEnv.createMarker(startInput);
  3921. let end;
  3922. if (!start) {
  3923. return; // TODO: warning if parsed bad
  3924. }
  3925. if (endInput != null) {
  3926. end = dateEnv.createMarker(endInput);
  3927. if (!end) { // TODO: warning if parsed bad
  3928. return;
  3929. }
  3930. }
  3931. if (this._instance) {
  3932. let instanceRange = this._instance.range;
  3933. // when computing the diff for an event being converted to all-day,
  3934. // compute diff off of the all-day values the way event-mutation does.
  3935. if (options.allDay === true) {
  3936. instanceRange = computeAlignedDayRange(instanceRange);
  3937. }
  3938. let startDelta = diffDates(instanceRange.start, start, dateEnv, options.granularity);
  3939. if (end) {
  3940. let endDelta = diffDates(instanceRange.end, end, dateEnv, options.granularity);
  3941. if (durationsEqual(startDelta, endDelta)) {
  3942. this.mutate({ datesDelta: startDelta, standardProps });
  3943. }
  3944. else {
  3945. this.mutate({ startDelta, endDelta, standardProps });
  3946. }
  3947. }
  3948. else { // means "clear the end"
  3949. standardProps.hasEnd = false;
  3950. this.mutate({ datesDelta: startDelta, standardProps });
  3951. }
  3952. }
  3953. }
  3954. moveStart(deltaInput) {
  3955. let delta = createDuration(deltaInput);
  3956. if (delta) { // TODO: warning if parsed bad
  3957. this.mutate({ startDelta: delta });
  3958. }
  3959. }
  3960. moveEnd(deltaInput) {
  3961. let delta = createDuration(deltaInput);
  3962. if (delta) { // TODO: warning if parsed bad
  3963. this.mutate({ endDelta: delta });
  3964. }
  3965. }
  3966. moveDates(deltaInput) {
  3967. let delta = createDuration(deltaInput);
  3968. if (delta) { // TODO: warning if parsed bad
  3969. this.mutate({ datesDelta: delta });
  3970. }
  3971. }
  3972. setAllDay(allDay, options = {}) {
  3973. let standardProps = { allDay };
  3974. let { maintainDuration } = options;
  3975. if (maintainDuration == null) {
  3976. maintainDuration = this._context.options.allDayMaintainDuration;
  3977. }
  3978. if (this._def.allDay !== allDay) {
  3979. standardProps.hasEnd = maintainDuration;
  3980. }
  3981. this.mutate({ standardProps });
  3982. }
  3983. formatRange(formatInput) {
  3984. let { dateEnv } = this._context;
  3985. let instance = this._instance;
  3986. let formatter = createFormatter(formatInput);
  3987. if (this._def.hasEnd) {
  3988. return dateEnv.formatRange(instance.range.start, instance.range.end, formatter, {
  3989. forcedStartTzo: instance.forcedStartTzo,
  3990. forcedEndTzo: instance.forcedEndTzo,
  3991. });
  3992. }
  3993. return dateEnv.format(instance.range.start, formatter, {
  3994. forcedTzo: instance.forcedStartTzo,
  3995. });
  3996. }
  3997. mutate(mutation) {
  3998. let instance = this._instance;
  3999. if (instance) {
  4000. let def = this._def;
  4001. let context = this._context;
  4002. let { eventStore } = context.getCurrentData();
  4003. let relevantEvents = getRelevantEvents(eventStore, instance.instanceId);
  4004. let eventConfigBase = {
  4005. '': {
  4006. display: '',
  4007. startEditable: true,
  4008. durationEditable: true,
  4009. constraints: [],
  4010. overlap: null,
  4011. allows: [],
  4012. backgroundColor: '',
  4013. borderColor: '',
  4014. textColor: '',
  4015. classNames: [],
  4016. },
  4017. };
  4018. relevantEvents = applyMutationToEventStore(relevantEvents, eventConfigBase, mutation, context);
  4019. let oldEvent = new EventImpl(context, def, instance); // snapshot
  4020. this._def = relevantEvents.defs[def.defId];
  4021. this._instance = relevantEvents.instances[instance.instanceId];
  4022. context.dispatch({
  4023. type: 'MERGE_EVENTS',
  4024. eventStore: relevantEvents,
  4025. });
  4026. context.emitter.trigger('eventChange', {
  4027. oldEvent,
  4028. event: this,
  4029. relatedEvents: buildEventApis(relevantEvents, context, instance),
  4030. revert() {
  4031. context.dispatch({
  4032. type: 'RESET_EVENTS',
  4033. eventStore, // the ORIGINAL store
  4034. });
  4035. },
  4036. });
  4037. }
  4038. }
  4039. remove() {
  4040. let context = this._context;
  4041. let asStore = eventApiToStore(this);
  4042. context.dispatch({
  4043. type: 'REMOVE_EVENTS',
  4044. eventStore: asStore,
  4045. });
  4046. context.emitter.trigger('eventRemove', {
  4047. event: this,
  4048. relatedEvents: [],
  4049. revert() {
  4050. context.dispatch({
  4051. type: 'MERGE_EVENTS',
  4052. eventStore: asStore,
  4053. });
  4054. },
  4055. });
  4056. }
  4057. get source() {
  4058. let { sourceId } = this._def;
  4059. if (sourceId) {
  4060. return new EventSourceImpl(this._context, this._context.getCurrentData().eventSources[sourceId]);
  4061. }
  4062. return null;
  4063. }
  4064. get start() {
  4065. return this._instance ?
  4066. this._context.dateEnv.toDate(this._instance.range.start) :
  4067. null;
  4068. }
  4069. get end() {
  4070. return (this._instance && this._def.hasEnd) ?
  4071. this._context.dateEnv.toDate(this._instance.range.end) :
  4072. null;
  4073. }
  4074. get startStr() {
  4075. let instance = this._instance;
  4076. if (instance) {
  4077. return this._context.dateEnv.formatIso(instance.range.start, {
  4078. omitTime: this._def.allDay,
  4079. forcedTzo: instance.forcedStartTzo,
  4080. });
  4081. }
  4082. return '';
  4083. }
  4084. get endStr() {
  4085. let instance = this._instance;
  4086. if (instance && this._def.hasEnd) {
  4087. return this._context.dateEnv.formatIso(instance.range.end, {
  4088. omitTime: this._def.allDay,
  4089. forcedTzo: instance.forcedEndTzo,
  4090. });
  4091. }
  4092. return '';
  4093. }
  4094. // computable props that all access the def
  4095. // TODO: find a TypeScript-compatible way to do this at scale
  4096. get id() { return this._def.publicId; }
  4097. get groupId() { return this._def.groupId; }
  4098. get allDay() { return this._def.allDay; }
  4099. get title() { return this._def.title; }
  4100. get url() { return this._def.url; }
  4101. get display() { return this._def.ui.display || 'auto'; } // bad. just normalize the type earlier
  4102. get startEditable() { return this._def.ui.startEditable; }
  4103. get durationEditable() { return this._def.ui.durationEditable; }
  4104. get constraint() { return this._def.ui.constraints[0] || null; }
  4105. get overlap() { return this._def.ui.overlap; }
  4106. get allow() { return this._def.ui.allows[0] || null; }
  4107. get backgroundColor() { return this._def.ui.backgroundColor; }
  4108. get borderColor() { return this._def.ui.borderColor; }
  4109. get textColor() { return this._def.ui.textColor; }
  4110. // NOTE: user can't modify these because Object.freeze was called in event-def parsing
  4111. get classNames() { return this._def.ui.classNames; }
  4112. get extendedProps() { return this._def.extendedProps; }
  4113. toPlainObject(settings = {}) {
  4114. let def = this._def;
  4115. let { ui } = def;
  4116. let { startStr, endStr } = this;
  4117. let res = {
  4118. allDay: def.allDay,
  4119. };
  4120. if (def.title) {
  4121. res.title = def.title;
  4122. }
  4123. if (startStr) {
  4124. res.start = startStr;
  4125. }
  4126. if (endStr) {
  4127. res.end = endStr;
  4128. }
  4129. if (def.publicId) {
  4130. res.id = def.publicId;
  4131. }
  4132. if (def.groupId) {
  4133. res.groupId = def.groupId;
  4134. }
  4135. if (def.url) {
  4136. res.url = def.url;
  4137. }
  4138. if (ui.display && ui.display !== 'auto') {
  4139. res.display = ui.display;
  4140. }
  4141. // TODO: what about recurring-event properties???
  4142. // TODO: include startEditable/durationEditable/constraint/overlap/allow
  4143. if (settings.collapseColor && ui.backgroundColor && ui.backgroundColor === ui.borderColor) {
  4144. res.color = ui.backgroundColor;
  4145. }
  4146. else {
  4147. if (ui.backgroundColor) {
  4148. res.backgroundColor = ui.backgroundColor;
  4149. }
  4150. if (ui.borderColor) {
  4151. res.borderColor = ui.borderColor;
  4152. }
  4153. }
  4154. if (ui.textColor) {
  4155. res.textColor = ui.textColor;
  4156. }
  4157. if (ui.classNames.length) {
  4158. res.classNames = ui.classNames;
  4159. }
  4160. if (Object.keys(def.extendedProps).length) {
  4161. if (settings.collapseExtendedProps) {
  4162. Object.assign(res, def.extendedProps);
  4163. }
  4164. else {
  4165. res.extendedProps = def.extendedProps;
  4166. }
  4167. }
  4168. return res;
  4169. }
  4170. toJSON() {
  4171. return this.toPlainObject();
  4172. }
  4173. }
  4174. function eventApiToStore(eventApi) {
  4175. let def = eventApi._def;
  4176. let instance = eventApi._instance;
  4177. return {
  4178. defs: { [def.defId]: def },
  4179. instances: instance
  4180. ? { [instance.instanceId]: instance }
  4181. : {},
  4182. };
  4183. }
  4184. function buildEventApis(eventStore, context, excludeInstance) {
  4185. let { defs, instances } = eventStore;
  4186. let eventApis = [];
  4187. let excludeInstanceId = excludeInstance ? excludeInstance.instanceId : '';
  4188. for (let id in instances) {
  4189. let instance = instances[id];
  4190. let def = defs[instance.defId];
  4191. if (instance.instanceId !== excludeInstanceId) {
  4192. eventApis.push(new EventImpl(context, def, instance));
  4193. }
  4194. }
  4195. return eventApis;
  4196. }
  4197. /*
  4198. Specifying nextDayThreshold signals that all-day ranges should be sliced.
  4199. */
  4200. function sliceEventStore(eventStore, eventUiBases, framingRange, nextDayThreshold) {
  4201. let inverseBgByGroupId = {};
  4202. let inverseBgByDefId = {};
  4203. let defByGroupId = {};
  4204. let bgRanges = [];
  4205. let fgRanges = [];
  4206. let eventUis = compileEventUis(eventStore.defs, eventUiBases);
  4207. for (let defId in eventStore.defs) {
  4208. let def = eventStore.defs[defId];
  4209. let ui = eventUis[def.defId];
  4210. if (ui.display === 'inverse-background') {
  4211. if (def.groupId) {
  4212. inverseBgByGroupId[def.groupId] = [];
  4213. if (!defByGroupId[def.groupId]) {
  4214. defByGroupId[def.groupId] = def;
  4215. }
  4216. }
  4217. else {
  4218. inverseBgByDefId[defId] = [];
  4219. }
  4220. }
  4221. }
  4222. for (let instanceId in eventStore.instances) {
  4223. let instance = eventStore.instances[instanceId];
  4224. let def = eventStore.defs[instance.defId];
  4225. let ui = eventUis[def.defId];
  4226. let origRange = instance.range;
  4227. let normalRange = (!def.allDay && nextDayThreshold) ?
  4228. computeVisibleDayRange(origRange, nextDayThreshold) :
  4229. origRange;
  4230. let slicedRange = intersectRanges(normalRange, framingRange);
  4231. if (slicedRange) {
  4232. if (ui.display === 'inverse-background') {
  4233. if (def.groupId) {
  4234. inverseBgByGroupId[def.groupId].push(slicedRange);
  4235. }
  4236. else {
  4237. inverseBgByDefId[instance.defId].push(slicedRange);
  4238. }
  4239. }
  4240. else if (ui.display !== 'none') {
  4241. (ui.display === 'background' ? bgRanges : fgRanges).push({
  4242. def,
  4243. ui,
  4244. instance,
  4245. range: slicedRange,
  4246. isStart: normalRange.start && normalRange.start.valueOf() === slicedRange.start.valueOf(),
  4247. isEnd: normalRange.end && normalRange.end.valueOf() === slicedRange.end.valueOf(),
  4248. });
  4249. }
  4250. }
  4251. }
  4252. for (let groupId in inverseBgByGroupId) { // BY GROUP
  4253. let ranges = inverseBgByGroupId[groupId];
  4254. let invertedRanges = invertRanges(ranges, framingRange);
  4255. for (let invertedRange of invertedRanges) {
  4256. let def = defByGroupId[groupId];
  4257. let ui = eventUis[def.defId];
  4258. bgRanges.push({
  4259. def,
  4260. ui,
  4261. instance: null,
  4262. range: invertedRange,
  4263. isStart: false,
  4264. isEnd: false,
  4265. });
  4266. }
  4267. }
  4268. for (let defId in inverseBgByDefId) {
  4269. let ranges = inverseBgByDefId[defId];
  4270. let invertedRanges = invertRanges(ranges, framingRange);
  4271. for (let invertedRange of invertedRanges) {
  4272. bgRanges.push({
  4273. def: eventStore.defs[defId],
  4274. ui: eventUis[defId],
  4275. instance: null,
  4276. range: invertedRange,
  4277. isStart: false,
  4278. isEnd: false,
  4279. });
  4280. }
  4281. }
  4282. return { bg: bgRanges, fg: fgRanges };
  4283. }
  4284. function hasBgRendering(def) {
  4285. return def.ui.display === 'background' || def.ui.display === 'inverse-background';
  4286. }
  4287. function setElSeg(el, seg) {
  4288. el.fcSeg = seg;
  4289. }
  4290. function getElSeg(el) {
  4291. return el.fcSeg ||
  4292. el.parentNode.fcSeg || // for the harness
  4293. null;
  4294. }
  4295. // event ui computation
  4296. function compileEventUis(eventDefs, eventUiBases) {
  4297. return mapHash(eventDefs, (eventDef) => compileEventUi(eventDef, eventUiBases));
  4298. }
  4299. function compileEventUi(eventDef, eventUiBases) {
  4300. let uis = [];
  4301. if (eventUiBases['']) {
  4302. uis.push(eventUiBases['']);
  4303. }
  4304. if (eventUiBases[eventDef.defId]) {
  4305. uis.push(eventUiBases[eventDef.defId]);
  4306. }
  4307. uis.push(eventDef.ui);
  4308. return combineEventUis(uis);
  4309. }
  4310. function sortEventSegs(segs, eventOrderSpecs) {
  4311. let objs = segs.map(buildSegCompareObj);
  4312. objs.sort((obj0, obj1) => compareByFieldSpecs(obj0, obj1, eventOrderSpecs));
  4313. return objs.map((c) => c._seg);
  4314. }
  4315. // returns a object with all primitive props that can be compared
  4316. function buildSegCompareObj(seg) {
  4317. let { eventRange } = seg;
  4318. let eventDef = eventRange.def;
  4319. let range = eventRange.instance ? eventRange.instance.range : eventRange.range;
  4320. let start = range.start ? range.start.valueOf() : 0; // TODO: better support for open-range events
  4321. let end = range.end ? range.end.valueOf() : 0; // "
  4322. return Object.assign(Object.assign(Object.assign({}, eventDef.extendedProps), eventDef), { id: eventDef.publicId, start,
  4323. end, duration: end - start, allDay: Number(eventDef.allDay), _seg: seg });
  4324. }
  4325. function computeSegDraggable(seg, context) {
  4326. let { pluginHooks } = context;
  4327. let transformers = pluginHooks.isDraggableTransformers;
  4328. let { def, ui } = seg.eventRange;
  4329. let val = ui.startEditable;
  4330. for (let transformer of transformers) {
  4331. val = transformer(val, def, ui, context);
  4332. }
  4333. return val;
  4334. }
  4335. function computeSegStartResizable(seg, context) {
  4336. return seg.isStart && seg.eventRange.ui.durationEditable && context.options.eventResizableFromStart;
  4337. }
  4338. function computeSegEndResizable(seg, context) {
  4339. return seg.isEnd && seg.eventRange.ui.durationEditable;
  4340. }
  4341. function buildSegTimeText(seg, timeFormat, context, defaultDisplayEventTime, // defaults to true
  4342. defaultDisplayEventEnd, // defaults to true
  4343. startOverride, endOverride) {
  4344. let { dateEnv, options } = context;
  4345. let { displayEventTime, displayEventEnd } = options;
  4346. let eventDef = seg.eventRange.def;
  4347. let eventInstance = seg.eventRange.instance;
  4348. if (displayEventTime == null) {
  4349. displayEventTime = defaultDisplayEventTime !== false;
  4350. }
  4351. if (displayEventEnd == null) {
  4352. displayEventEnd = defaultDisplayEventEnd !== false;
  4353. }
  4354. let wholeEventStart = eventInstance.range.start;
  4355. let wholeEventEnd = eventInstance.range.end;
  4356. let segStart = startOverride || seg.start || seg.eventRange.range.start;
  4357. let segEnd = endOverride || seg.end || seg.eventRange.range.end;
  4358. let isStartDay = startOfDay(wholeEventStart).valueOf() === startOfDay(segStart).valueOf();
  4359. let isEndDay = startOfDay(addMs(wholeEventEnd, -1)).valueOf() === startOfDay(addMs(segEnd, -1)).valueOf();
  4360. if (displayEventTime && !eventDef.allDay && (isStartDay || isEndDay)) {
  4361. segStart = isStartDay ? wholeEventStart : segStart;
  4362. segEnd = isEndDay ? wholeEventEnd : segEnd;
  4363. if (displayEventEnd && eventDef.hasEnd) {
  4364. return dateEnv.formatRange(segStart, segEnd, timeFormat, {
  4365. forcedStartTzo: startOverride ? null : eventInstance.forcedStartTzo,
  4366. forcedEndTzo: endOverride ? null : eventInstance.forcedEndTzo,
  4367. });
  4368. }
  4369. return dateEnv.format(segStart, timeFormat, {
  4370. forcedTzo: startOverride ? null : eventInstance.forcedStartTzo, // nooooo, same
  4371. });
  4372. }
  4373. return '';
  4374. }
  4375. function getSegMeta(seg, todayRange, nowDate) {
  4376. let segRange = seg.eventRange.range;
  4377. return {
  4378. isPast: segRange.end <= (nowDate || todayRange.start),
  4379. isFuture: segRange.start >= (nowDate || todayRange.end),
  4380. isToday: todayRange && rangeContainsMarker(todayRange, segRange.start),
  4381. };
  4382. }
  4383. function getEventClassNames(props) {
  4384. let classNames = ['fc-event'];
  4385. if (props.isMirror) {
  4386. classNames.push('fc-event-mirror');
  4387. }
  4388. if (props.isDraggable) {
  4389. classNames.push('fc-event-draggable');
  4390. }
  4391. if (props.isStartResizable || props.isEndResizable) {
  4392. classNames.push('fc-event-resizable');
  4393. }
  4394. if (props.isDragging) {
  4395. classNames.push('fc-event-dragging');
  4396. }
  4397. if (props.isResizing) {
  4398. classNames.push('fc-event-resizing');
  4399. }
  4400. if (props.isSelected) {
  4401. classNames.push('fc-event-selected');
  4402. }
  4403. if (props.isStart) {
  4404. classNames.push('fc-event-start');
  4405. }
  4406. if (props.isEnd) {
  4407. classNames.push('fc-event-end');
  4408. }
  4409. if (props.isPast) {
  4410. classNames.push('fc-event-past');
  4411. }
  4412. if (props.isToday) {
  4413. classNames.push('fc-event-today');
  4414. }
  4415. if (props.isFuture) {
  4416. classNames.push('fc-event-future');
  4417. }
  4418. return classNames;
  4419. }
  4420. function buildEventRangeKey(eventRange) {
  4421. return eventRange.instance
  4422. ? eventRange.instance.instanceId
  4423. : `${eventRange.def.defId}:${eventRange.range.start.toISOString()}`;
  4424. // inverse-background events don't have specific instances. TODO: better solution
  4425. }
  4426. function getSegAnchorAttrs(seg, context) {
  4427. let { def, instance } = seg.eventRange;
  4428. let { url } = def;
  4429. if (url) {
  4430. return { href: url };
  4431. }
  4432. let { emitter, options } = context;
  4433. let { eventInteractive } = options;
  4434. if (eventInteractive == null) {
  4435. eventInteractive = def.interactive;
  4436. if (eventInteractive == null) {
  4437. eventInteractive = Boolean(emitter.hasHandlers('eventClick'));
  4438. }
  4439. }
  4440. // mock what happens in EventClicking
  4441. if (eventInteractive) {
  4442. // only attach keyboard-related handlers because click handler is already done in EventClicking
  4443. return createAriaKeyboardAttrs((ev) => {
  4444. emitter.trigger('eventClick', {
  4445. el: ev.target,
  4446. event: new EventImpl(context, def, instance),
  4447. jsEvent: ev,
  4448. view: context.viewApi,
  4449. });
  4450. });
  4451. }
  4452. return {};
  4453. }
  4454. const STANDARD_PROPS = {
  4455. start: identity,
  4456. end: identity,
  4457. allDay: Boolean,
  4458. };
  4459. function parseDateSpan(raw, dateEnv, defaultDuration) {
  4460. let span = parseOpenDateSpan(raw, dateEnv);
  4461. let { range } = span;
  4462. if (!range.start) {
  4463. return null;
  4464. }
  4465. if (!range.end) {
  4466. if (defaultDuration == null) {
  4467. return null;
  4468. }
  4469. range.end = dateEnv.add(range.start, defaultDuration);
  4470. }
  4471. return span;
  4472. }
  4473. /*
  4474. TODO: somehow combine with parseRange?
  4475. Will return null if the start/end props were present but parsed invalidly.
  4476. */
  4477. function parseOpenDateSpan(raw, dateEnv) {
  4478. let { refined: standardProps, extra } = refineProps(raw, STANDARD_PROPS);
  4479. let startMeta = standardProps.start ? dateEnv.createMarkerMeta(standardProps.start) : null;
  4480. let endMeta = standardProps.end ? dateEnv.createMarkerMeta(standardProps.end) : null;
  4481. let { allDay } = standardProps;
  4482. if (allDay == null) {
  4483. allDay = (startMeta && startMeta.isTimeUnspecified) &&
  4484. (!endMeta || endMeta.isTimeUnspecified);
  4485. }
  4486. return Object.assign({ range: {
  4487. start: startMeta ? startMeta.marker : null,
  4488. end: endMeta ? endMeta.marker : null,
  4489. }, allDay }, extra);
  4490. }
  4491. function isDateSpansEqual(span0, span1) {
  4492. return rangesEqual(span0.range, span1.range) &&
  4493. span0.allDay === span1.allDay &&
  4494. isSpanPropsEqual(span0, span1);
  4495. }
  4496. // the NON-DATE-RELATED props
  4497. function isSpanPropsEqual(span0, span1) {
  4498. for (let propName in span1) {
  4499. if (propName !== 'range' && propName !== 'allDay') {
  4500. if (span0[propName] !== span1[propName]) {
  4501. return false;
  4502. }
  4503. }
  4504. }
  4505. // are there any props that span0 has that span1 DOESN'T have?
  4506. // both have range/allDay, so no need to special-case.
  4507. for (let propName in span0) {
  4508. if (!(propName in span1)) {
  4509. return false;
  4510. }
  4511. }
  4512. return true;
  4513. }
  4514. function buildDateSpanApi(span, dateEnv) {
  4515. return Object.assign(Object.assign({}, buildRangeApi(span.range, dateEnv, span.allDay)), { allDay: span.allDay });
  4516. }
  4517. function buildRangeApiWithTimeZone(range, dateEnv, omitTime) {
  4518. return Object.assign(Object.assign({}, buildRangeApi(range, dateEnv, omitTime)), { timeZone: dateEnv.timeZone });
  4519. }
  4520. function buildRangeApi(range, dateEnv, omitTime) {
  4521. return {
  4522. start: dateEnv.toDate(range.start),
  4523. end: dateEnv.toDate(range.end),
  4524. startStr: dateEnv.formatIso(range.start, { omitTime }),
  4525. endStr: dateEnv.formatIso(range.end, { omitTime }),
  4526. };
  4527. }
  4528. function fabricateEventRange(dateSpan, eventUiBases, context) {
  4529. let res = refineEventDef({ editable: false }, context);
  4530. let def = parseEventDef(res.refined, res.extra, '', // sourceId
  4531. dateSpan.allDay, true, // hasEnd
  4532. context);
  4533. return {
  4534. def,
  4535. ui: compileEventUi(def, eventUiBases),
  4536. instance: createEventInstance(def.defId, dateSpan.range),
  4537. range: dateSpan.range,
  4538. isStart: true,
  4539. isEnd: true,
  4540. };
  4541. }
  4542. /*
  4543. given a function that resolves a result asynchronously.
  4544. the function can either call passed-in success and failure callbacks,
  4545. or it can return a promise.
  4546. if you need to pass additional params to func, bind them first.
  4547. */
  4548. function unpromisify(func, normalizedSuccessCallback, normalizedFailureCallback) {
  4549. // guard against success/failure callbacks being called more than once
  4550. // and guard against a promise AND callback being used together.
  4551. let isResolved = false;
  4552. let wrappedSuccess = function (res) {
  4553. if (!isResolved) {
  4554. isResolved = true;
  4555. normalizedSuccessCallback(res);
  4556. }
  4557. };
  4558. let wrappedFailure = function (error) {
  4559. if (!isResolved) {
  4560. isResolved = true;
  4561. normalizedFailureCallback(error);
  4562. }
  4563. };
  4564. let res = func(wrappedSuccess, wrappedFailure);
  4565. if (res && typeof res.then === 'function') {
  4566. res.then(wrappedSuccess, wrappedFailure);
  4567. }
  4568. }
  4569. class JsonRequestError extends Error {
  4570. constructor(message, response) {
  4571. super(message);
  4572. this.response = response;
  4573. }
  4574. }
  4575. function requestJson(method, url, params) {
  4576. method = method.toUpperCase();
  4577. const fetchOptions = {
  4578. method,
  4579. };
  4580. if (method === 'GET') {
  4581. url += (url.indexOf('?') === -1 ? '?' : '&') +
  4582. new URLSearchParams(params);
  4583. }
  4584. else {
  4585. fetchOptions.body = new URLSearchParams(params);
  4586. fetchOptions.headers = {
  4587. 'Content-Type': 'application/x-www-form-urlencoded',
  4588. };
  4589. }
  4590. return fetch(url, fetchOptions).then((fetchRes) => {
  4591. if (fetchRes.ok) {
  4592. return fetchRes.json().then((parsedResponse) => {
  4593. return [parsedResponse, fetchRes];
  4594. }, () => {
  4595. throw new JsonRequestError('Failure parsing JSON', fetchRes);
  4596. });
  4597. }
  4598. else {
  4599. throw new JsonRequestError('Request failed', fetchRes);
  4600. }
  4601. });
  4602. }
  4603. let canVGrowWithinCell;
  4604. function getCanVGrowWithinCell() {
  4605. if (canVGrowWithinCell == null) {
  4606. canVGrowWithinCell = computeCanVGrowWithinCell();
  4607. }
  4608. return canVGrowWithinCell;
  4609. }
  4610. function computeCanVGrowWithinCell() {
  4611. // for SSR, because this function is call immediately at top-level
  4612. // TODO: just make this logic execute top-level, immediately, instead of doing lazily
  4613. if (typeof document === 'undefined') {
  4614. return true;
  4615. }
  4616. let el = document.createElement('div');
  4617. el.style.position = 'absolute';
  4618. el.style.top = '0px';
  4619. el.style.left = '0px';
  4620. el.innerHTML = '<table><tr><td><div></div></td></tr></table>';
  4621. el.querySelector('table').style.height = '100px';
  4622. el.querySelector('div').style.height = '100%';
  4623. document.body.appendChild(el);
  4624. let div = el.querySelector('div');
  4625. let possible = div.offsetHeight > 0;
  4626. document.body.removeChild(el);
  4627. return possible;
  4628. }
  4629. class CalendarRoot extends BaseComponent {
  4630. constructor() {
  4631. super(...arguments);
  4632. this.state = {
  4633. forPrint: false,
  4634. };
  4635. this.handleBeforePrint = () => {
  4636. flushSync(() => {
  4637. this.setState({ forPrint: true });
  4638. });
  4639. };
  4640. this.handleAfterPrint = () => {
  4641. flushSync(() => {
  4642. this.setState({ forPrint: false });
  4643. });
  4644. };
  4645. }
  4646. render() {
  4647. let { props } = this;
  4648. let { options } = props;
  4649. let { forPrint } = this.state;
  4650. let isHeightAuto = forPrint || options.height === 'auto' || options.contentHeight === 'auto';
  4651. let height = (!isHeightAuto && options.height != null) ? options.height : '';
  4652. let classNames = [
  4653. 'fc',
  4654. forPrint ? 'fc-media-print' : 'fc-media-screen',
  4655. `fc-direction-${options.direction}`,
  4656. props.theme.getClass('root'),
  4657. ];
  4658. if (!getCanVGrowWithinCell()) {
  4659. classNames.push('fc-liquid-hack');
  4660. }
  4661. return props.children(classNames, height, isHeightAuto, forPrint);
  4662. }
  4663. componentDidMount() {
  4664. let { emitter } = this.props;
  4665. emitter.on('_beforeprint', this.handleBeforePrint);
  4666. emitter.on('_afterprint', this.handleAfterPrint);
  4667. }
  4668. componentWillUnmount() {
  4669. let { emitter } = this.props;
  4670. emitter.off('_beforeprint', this.handleBeforePrint);
  4671. emitter.off('_afterprint', this.handleAfterPrint);
  4672. }
  4673. }
  4674. class Interaction {
  4675. constructor(settings) {
  4676. this.component = settings.component;
  4677. this.isHitComboAllowed = settings.isHitComboAllowed || null;
  4678. }
  4679. destroy() {
  4680. }
  4681. }
  4682. function parseInteractionSettings(component, input) {
  4683. return {
  4684. component,
  4685. el: input.el,
  4686. useEventCenter: input.useEventCenter != null ? input.useEventCenter : true,
  4687. isHitComboAllowed: input.isHitComboAllowed || null,
  4688. };
  4689. }
  4690. function interactionSettingsToStore(settings) {
  4691. return {
  4692. [settings.component.uid]: settings,
  4693. };
  4694. }
  4695. // global state
  4696. const interactionSettingsStore = {};
  4697. class CalendarImpl {
  4698. getCurrentData() {
  4699. return this.currentDataManager.getCurrentData();
  4700. }
  4701. dispatch(action) {
  4702. this.currentDataManager.dispatch(action);
  4703. }
  4704. get view() { return this.getCurrentData().viewApi; }
  4705. batchRendering(callback) {
  4706. callback();
  4707. }
  4708. updateSize() {
  4709. this.trigger('_resize', true);
  4710. }
  4711. // Options
  4712. // -----------------------------------------------------------------------------------------------------------------
  4713. setOption(name, val) {
  4714. this.dispatch({
  4715. type: 'SET_OPTION',
  4716. optionName: name,
  4717. rawOptionValue: val,
  4718. });
  4719. }
  4720. getOption(name) {
  4721. return this.currentDataManager.currentCalendarOptionsInput[name];
  4722. }
  4723. getAvailableLocaleCodes() {
  4724. return Object.keys(this.getCurrentData().availableRawLocales);
  4725. }
  4726. // Trigger
  4727. // -----------------------------------------------------------------------------------------------------------------
  4728. on(handlerName, handler) {
  4729. let { currentDataManager } = this;
  4730. if (currentDataManager.currentCalendarOptionsRefiners[handlerName]) {
  4731. currentDataManager.emitter.on(handlerName, handler);
  4732. }
  4733. else {
  4734. console.warn(`Unknown listener name '${handlerName}'`);
  4735. }
  4736. }
  4737. off(handlerName, handler) {
  4738. this.currentDataManager.emitter.off(handlerName, handler);
  4739. }
  4740. // not meant for public use
  4741. trigger(handlerName, ...args) {
  4742. this.currentDataManager.emitter.trigger(handlerName, ...args);
  4743. }
  4744. // View
  4745. // -----------------------------------------------------------------------------------------------------------------
  4746. changeView(viewType, dateOrRange) {
  4747. this.batchRendering(() => {
  4748. this.unselect();
  4749. if (dateOrRange) {
  4750. if (dateOrRange.start && dateOrRange.end) { // a range
  4751. this.dispatch({
  4752. type: 'CHANGE_VIEW_TYPE',
  4753. viewType,
  4754. });
  4755. this.dispatch({
  4756. type: 'SET_OPTION',
  4757. optionName: 'visibleRange',
  4758. rawOptionValue: dateOrRange,
  4759. });
  4760. }
  4761. else {
  4762. let { dateEnv } = this.getCurrentData();
  4763. this.dispatch({
  4764. type: 'CHANGE_VIEW_TYPE',
  4765. viewType,
  4766. dateMarker: dateEnv.createMarker(dateOrRange),
  4767. });
  4768. }
  4769. }
  4770. else {
  4771. this.dispatch({
  4772. type: 'CHANGE_VIEW_TYPE',
  4773. viewType,
  4774. });
  4775. }
  4776. });
  4777. }
  4778. // Forces navigation to a view for the given date.
  4779. // `viewType` can be a specific view name or a generic one like "week" or "day".
  4780. // needs to change
  4781. zoomTo(dateMarker, viewType) {
  4782. let state = this.getCurrentData();
  4783. let spec;
  4784. viewType = viewType || 'day'; // day is default zoom
  4785. spec = state.viewSpecs[viewType] || this.getUnitViewSpec(viewType);
  4786. this.unselect();
  4787. if (spec) {
  4788. this.dispatch({
  4789. type: 'CHANGE_VIEW_TYPE',
  4790. viewType: spec.type,
  4791. dateMarker,
  4792. });
  4793. }
  4794. else {
  4795. this.dispatch({
  4796. type: 'CHANGE_DATE',
  4797. dateMarker,
  4798. });
  4799. }
  4800. }
  4801. // Given a duration singular unit, like "week" or "day", finds a matching view spec.
  4802. // Preference is given to views that have corresponding buttons.
  4803. getUnitViewSpec(unit) {
  4804. let { viewSpecs, toolbarConfig } = this.getCurrentData();
  4805. let viewTypes = [].concat(toolbarConfig.header ? toolbarConfig.header.viewsWithButtons : [], toolbarConfig.footer ? toolbarConfig.footer.viewsWithButtons : []);
  4806. let i;
  4807. let spec;
  4808. for (let viewType in viewSpecs) {
  4809. viewTypes.push(viewType);
  4810. }
  4811. for (i = 0; i < viewTypes.length; i += 1) {
  4812. spec = viewSpecs[viewTypes[i]];
  4813. if (spec) {
  4814. if (spec.singleUnit === unit) {
  4815. return spec;
  4816. }
  4817. }
  4818. }
  4819. return null;
  4820. }
  4821. // Current Date
  4822. // -----------------------------------------------------------------------------------------------------------------
  4823. prev() {
  4824. this.unselect();
  4825. this.dispatch({ type: 'PREV' });
  4826. }
  4827. next() {
  4828. this.unselect();
  4829. this.dispatch({ type: 'NEXT' });
  4830. }
  4831. prevYear() {
  4832. let state = this.getCurrentData();
  4833. this.unselect();
  4834. this.dispatch({
  4835. type: 'CHANGE_DATE',
  4836. dateMarker: state.dateEnv.addYears(state.currentDate, -1),
  4837. });
  4838. }
  4839. nextYear() {
  4840. let state = this.getCurrentData();
  4841. this.unselect();
  4842. this.dispatch({
  4843. type: 'CHANGE_DATE',
  4844. dateMarker: state.dateEnv.addYears(state.currentDate, 1),
  4845. });
  4846. }
  4847. today() {
  4848. let state = this.getCurrentData();
  4849. this.unselect();
  4850. this.dispatch({
  4851. type: 'CHANGE_DATE',
  4852. dateMarker: getNow(state.calendarOptions.now, state.dateEnv),
  4853. });
  4854. }
  4855. gotoDate(zonedDateInput) {
  4856. let state = this.getCurrentData();
  4857. this.unselect();
  4858. this.dispatch({
  4859. type: 'CHANGE_DATE',
  4860. dateMarker: state.dateEnv.createMarker(zonedDateInput),
  4861. });
  4862. }
  4863. incrementDate(deltaInput) {
  4864. let state = this.getCurrentData();
  4865. let delta = createDuration(deltaInput);
  4866. if (delta) { // else, warn about invalid input?
  4867. this.unselect();
  4868. this.dispatch({
  4869. type: 'CHANGE_DATE',
  4870. dateMarker: state.dateEnv.add(state.currentDate, delta),
  4871. });
  4872. }
  4873. }
  4874. getDate() {
  4875. let state = this.getCurrentData();
  4876. return state.dateEnv.toDate(state.currentDate);
  4877. }
  4878. // Date Formatting Utils
  4879. // -----------------------------------------------------------------------------------------------------------------
  4880. formatDate(d, formatter) {
  4881. let { dateEnv } = this.getCurrentData();
  4882. return dateEnv.format(dateEnv.createMarker(d), createFormatter(formatter));
  4883. }
  4884. // `settings` is for formatter AND isEndExclusive
  4885. formatRange(d0, d1, settings) {
  4886. let { dateEnv } = this.getCurrentData();
  4887. return dateEnv.formatRange(dateEnv.createMarker(d0), dateEnv.createMarker(d1), createFormatter(settings), settings);
  4888. }
  4889. formatIso(d, omitTime) {
  4890. let { dateEnv } = this.getCurrentData();
  4891. return dateEnv.formatIso(dateEnv.createMarker(d), { omitTime });
  4892. }
  4893. // Date Selection / Event Selection / DayClick
  4894. // -----------------------------------------------------------------------------------------------------------------
  4895. select(dateOrObj, endDate) {
  4896. let selectionInput;
  4897. if (endDate == null) {
  4898. if (dateOrObj.start != null) {
  4899. selectionInput = dateOrObj;
  4900. }
  4901. else {
  4902. selectionInput = {
  4903. start: dateOrObj,
  4904. end: null,
  4905. };
  4906. }
  4907. }
  4908. else {
  4909. selectionInput = {
  4910. start: dateOrObj,
  4911. end: endDate,
  4912. };
  4913. }
  4914. let state = this.getCurrentData();
  4915. let selection = parseDateSpan(selectionInput, state.dateEnv, createDuration({ days: 1 }));
  4916. if (selection) { // throw parse error otherwise?
  4917. this.dispatch({ type: 'SELECT_DATES', selection });
  4918. triggerDateSelect(selection, null, state);
  4919. }
  4920. }
  4921. unselect(pev) {
  4922. let state = this.getCurrentData();
  4923. if (state.dateSelection) {
  4924. this.dispatch({ type: 'UNSELECT_DATES' });
  4925. triggerDateUnselect(pev, state);
  4926. }
  4927. }
  4928. // Public Events API
  4929. // -----------------------------------------------------------------------------------------------------------------
  4930. addEvent(eventInput, sourceInput) {
  4931. if (eventInput instanceof EventImpl) {
  4932. let def = eventInput._def;
  4933. let instance = eventInput._instance;
  4934. let currentData = this.getCurrentData();
  4935. // not already present? don't want to add an old snapshot
  4936. if (!currentData.eventStore.defs[def.defId]) {
  4937. this.dispatch({
  4938. type: 'ADD_EVENTS',
  4939. eventStore: eventTupleToStore({ def, instance }), // TODO: better util for two args?
  4940. });
  4941. this.triggerEventAdd(eventInput);
  4942. }
  4943. return eventInput;
  4944. }
  4945. let state = this.getCurrentData();
  4946. let eventSource;
  4947. if (sourceInput instanceof EventSourceImpl) {
  4948. eventSource = sourceInput.internalEventSource;
  4949. }
  4950. else if (typeof sourceInput === 'boolean') {
  4951. if (sourceInput) { // true. part of the first event source
  4952. [eventSource] = hashValuesToArray(state.eventSources);
  4953. }
  4954. }
  4955. else if (sourceInput != null) { // an ID. accepts a number too
  4956. let sourceApi = this.getEventSourceById(sourceInput); // TODO: use an internal function
  4957. if (!sourceApi) {
  4958. console.warn(`Could not find an event source with ID "${sourceInput}"`); // TODO: test
  4959. return null;
  4960. }
  4961. eventSource = sourceApi.internalEventSource;
  4962. }
  4963. let tuple = parseEvent(eventInput, eventSource, state, false);
  4964. if (tuple) {
  4965. let newEventApi = new EventImpl(state, tuple.def, tuple.def.recurringDef ? null : tuple.instance);
  4966. this.dispatch({
  4967. type: 'ADD_EVENTS',
  4968. eventStore: eventTupleToStore(tuple),
  4969. });
  4970. this.triggerEventAdd(newEventApi);
  4971. return newEventApi;
  4972. }
  4973. return null;
  4974. }
  4975. triggerEventAdd(eventApi) {
  4976. let { emitter } = this.getCurrentData();
  4977. emitter.trigger('eventAdd', {
  4978. event: eventApi,
  4979. relatedEvents: [],
  4980. revert: () => {
  4981. this.dispatch({
  4982. type: 'REMOVE_EVENTS',
  4983. eventStore: eventApiToStore(eventApi),
  4984. });
  4985. },
  4986. });
  4987. }
  4988. // TODO: optimize
  4989. getEventById(id) {
  4990. let state = this.getCurrentData();
  4991. let { defs, instances } = state.eventStore;
  4992. id = String(id);
  4993. for (let defId in defs) {
  4994. let def = defs[defId];
  4995. if (def.publicId === id) {
  4996. if (def.recurringDef) {
  4997. return new EventImpl(state, def, null);
  4998. }
  4999. for (let instanceId in instances) {
  5000. let instance = instances[instanceId];
  5001. if (instance.defId === def.defId) {
  5002. return new EventImpl(state, def, instance);
  5003. }
  5004. }
  5005. }
  5006. }
  5007. return null;
  5008. }
  5009. getEvents() {
  5010. let currentData = this.getCurrentData();
  5011. return buildEventApis(currentData.eventStore, currentData);
  5012. }
  5013. removeAllEvents() {
  5014. this.dispatch({ type: 'REMOVE_ALL_EVENTS' });
  5015. }
  5016. // Public Event Sources API
  5017. // -----------------------------------------------------------------------------------------------------------------
  5018. getEventSources() {
  5019. let state = this.getCurrentData();
  5020. let sourceHash = state.eventSources;
  5021. let sourceApis = [];
  5022. for (let internalId in sourceHash) {
  5023. sourceApis.push(new EventSourceImpl(state, sourceHash[internalId]));
  5024. }
  5025. return sourceApis;
  5026. }
  5027. getEventSourceById(id) {
  5028. let state = this.getCurrentData();
  5029. let sourceHash = state.eventSources;
  5030. id = String(id);
  5031. for (let sourceId in sourceHash) {
  5032. if (sourceHash[sourceId].publicId === id) {
  5033. return new EventSourceImpl(state, sourceHash[sourceId]);
  5034. }
  5035. }
  5036. return null;
  5037. }
  5038. addEventSource(sourceInput) {
  5039. let state = this.getCurrentData();
  5040. if (sourceInput instanceof EventSourceImpl) {
  5041. // not already present? don't want to add an old snapshot
  5042. if (!state.eventSources[sourceInput.internalEventSource.sourceId]) {
  5043. this.dispatch({
  5044. type: 'ADD_EVENT_SOURCES',
  5045. sources: [sourceInput.internalEventSource],
  5046. });
  5047. }
  5048. return sourceInput;
  5049. }
  5050. let eventSource = parseEventSource(sourceInput, state);
  5051. if (eventSource) { // TODO: error otherwise?
  5052. this.dispatch({ type: 'ADD_EVENT_SOURCES', sources: [eventSource] });
  5053. return new EventSourceImpl(state, eventSource);
  5054. }
  5055. return null;
  5056. }
  5057. removeAllEventSources() {
  5058. this.dispatch({ type: 'REMOVE_ALL_EVENT_SOURCES' });
  5059. }
  5060. refetchEvents() {
  5061. this.dispatch({ type: 'FETCH_EVENT_SOURCES', isRefetch: true });
  5062. }
  5063. // Scroll
  5064. // -----------------------------------------------------------------------------------------------------------------
  5065. scrollToTime(timeInput) {
  5066. let time = createDuration(timeInput);
  5067. if (time) {
  5068. this.trigger('_scrollRequest', { time });
  5069. }
  5070. }
  5071. }
  5072. function pointInsideRect(point, rect) {
  5073. return point.left >= rect.left &&
  5074. point.left < rect.right &&
  5075. point.top >= rect.top &&
  5076. point.top < rect.bottom;
  5077. }
  5078. // Returns a new rectangle that is the intersection of the two rectangles. If they don't intersect, returns false
  5079. function intersectRects(rect1, rect2) {
  5080. let res = {
  5081. left: Math.max(rect1.left, rect2.left),
  5082. right: Math.min(rect1.right, rect2.right),
  5083. top: Math.max(rect1.top, rect2.top),
  5084. bottom: Math.min(rect1.bottom, rect2.bottom),
  5085. };
  5086. if (res.left < res.right && res.top < res.bottom) {
  5087. return res;
  5088. }
  5089. return false;
  5090. }
  5091. function translateRect(rect, deltaX, deltaY) {
  5092. return {
  5093. left: rect.left + deltaX,
  5094. right: rect.right + deltaX,
  5095. top: rect.top + deltaY,
  5096. bottom: rect.bottom + deltaY,
  5097. };
  5098. }
  5099. // Returns a new point that will have been moved to reside within the given rectangle
  5100. function constrainPoint(point, rect) {
  5101. return {
  5102. left: Math.min(Math.max(point.left, rect.left), rect.right),
  5103. top: Math.min(Math.max(point.top, rect.top), rect.bottom),
  5104. };
  5105. }
  5106. // Returns a point that is the center of the given rectangle
  5107. function getRectCenter(rect) {
  5108. return {
  5109. left: (rect.left + rect.right) / 2,
  5110. top: (rect.top + rect.bottom) / 2,
  5111. };
  5112. }
  5113. // Subtracts point2's coordinates from point1's coordinates, returning a delta
  5114. function diffPoints(point1, point2) {
  5115. return {
  5116. left: point1.left - point2.left,
  5117. top: point1.top - point2.top,
  5118. };
  5119. }
  5120. const EMPTY_EVENT_STORE = createEmptyEventStore(); // for purecomponents. TODO: keep elsewhere
  5121. class Splitter {
  5122. constructor() {
  5123. this.getKeysForEventDefs = memoize(this._getKeysForEventDefs);
  5124. this.splitDateSelection = memoize(this._splitDateSpan);
  5125. this.splitEventStore = memoize(this._splitEventStore);
  5126. this.splitIndividualUi = memoize(this._splitIndividualUi);
  5127. this.splitEventDrag = memoize(this._splitInteraction);
  5128. this.splitEventResize = memoize(this._splitInteraction);
  5129. this.eventUiBuilders = {}; // TODO: typescript protection
  5130. }
  5131. splitProps(props) {
  5132. let keyInfos = this.getKeyInfo(props);
  5133. let defKeys = this.getKeysForEventDefs(props.eventStore);
  5134. let dateSelections = this.splitDateSelection(props.dateSelection);
  5135. let individualUi = this.splitIndividualUi(props.eventUiBases, defKeys); // the individual *bases*
  5136. let eventStores = this.splitEventStore(props.eventStore, defKeys);
  5137. let eventDrags = this.splitEventDrag(props.eventDrag);
  5138. let eventResizes = this.splitEventResize(props.eventResize);
  5139. let splitProps = {};
  5140. this.eventUiBuilders = mapHash(keyInfos, (info, key) => this.eventUiBuilders[key] || memoize(buildEventUiForKey));
  5141. for (let key in keyInfos) {
  5142. let keyInfo = keyInfos[key];
  5143. let eventStore = eventStores[key] || EMPTY_EVENT_STORE;
  5144. let buildEventUi = this.eventUiBuilders[key];
  5145. splitProps[key] = {
  5146. businessHours: keyInfo.businessHours || props.businessHours,
  5147. dateSelection: dateSelections[key] || null,
  5148. eventStore,
  5149. eventUiBases: buildEventUi(props.eventUiBases[''], keyInfo.ui, individualUi[key]),
  5150. eventSelection: eventStore.instances[props.eventSelection] ? props.eventSelection : '',
  5151. eventDrag: eventDrags[key] || null,
  5152. eventResize: eventResizes[key] || null,
  5153. };
  5154. }
  5155. return splitProps;
  5156. }
  5157. _splitDateSpan(dateSpan) {
  5158. let dateSpans = {};
  5159. if (dateSpan) {
  5160. let keys = this.getKeysForDateSpan(dateSpan);
  5161. for (let key of keys) {
  5162. dateSpans[key] = dateSpan;
  5163. }
  5164. }
  5165. return dateSpans;
  5166. }
  5167. _getKeysForEventDefs(eventStore) {
  5168. return mapHash(eventStore.defs, (eventDef) => this.getKeysForEventDef(eventDef));
  5169. }
  5170. _splitEventStore(eventStore, defKeys) {
  5171. let { defs, instances } = eventStore;
  5172. let splitStores = {};
  5173. for (let defId in defs) {
  5174. for (let key of defKeys[defId]) {
  5175. if (!splitStores[key]) {
  5176. splitStores[key] = createEmptyEventStore();
  5177. }
  5178. splitStores[key].defs[defId] = defs[defId];
  5179. }
  5180. }
  5181. for (let instanceId in instances) {
  5182. let instance = instances[instanceId];
  5183. for (let key of defKeys[instance.defId]) {
  5184. if (splitStores[key]) { // must have already been created
  5185. splitStores[key].instances[instanceId] = instance;
  5186. }
  5187. }
  5188. }
  5189. return splitStores;
  5190. }
  5191. _splitIndividualUi(eventUiBases, defKeys) {
  5192. let splitHashes = {};
  5193. for (let defId in eventUiBases) {
  5194. if (defId) { // not the '' key
  5195. for (let key of defKeys[defId]) {
  5196. if (!splitHashes[key]) {
  5197. splitHashes[key] = {};
  5198. }
  5199. splitHashes[key][defId] = eventUiBases[defId];
  5200. }
  5201. }
  5202. }
  5203. return splitHashes;
  5204. }
  5205. _splitInteraction(interaction) {
  5206. let splitStates = {};
  5207. if (interaction) {
  5208. let affectedStores = this._splitEventStore(interaction.affectedEvents, this._getKeysForEventDefs(interaction.affectedEvents));
  5209. // can't rely on defKeys because event data is mutated
  5210. let mutatedKeysByDefId = this._getKeysForEventDefs(interaction.mutatedEvents);
  5211. let mutatedStores = this._splitEventStore(interaction.mutatedEvents, mutatedKeysByDefId);
  5212. let populate = (key) => {
  5213. if (!splitStates[key]) {
  5214. splitStates[key] = {
  5215. affectedEvents: affectedStores[key] || EMPTY_EVENT_STORE,
  5216. mutatedEvents: mutatedStores[key] || EMPTY_EVENT_STORE,
  5217. isEvent: interaction.isEvent,
  5218. };
  5219. }
  5220. };
  5221. for (let key in affectedStores) {
  5222. populate(key);
  5223. }
  5224. for (let key in mutatedStores) {
  5225. populate(key);
  5226. }
  5227. }
  5228. return splitStates;
  5229. }
  5230. }
  5231. function buildEventUiForKey(allUi, eventUiForKey, individualUi) {
  5232. let baseParts = [];
  5233. if (allUi) {
  5234. baseParts.push(allUi);
  5235. }
  5236. if (eventUiForKey) {
  5237. baseParts.push(eventUiForKey);
  5238. }
  5239. let stuff = {
  5240. '': combineEventUis(baseParts),
  5241. };
  5242. if (individualUi) {
  5243. Object.assign(stuff, individualUi);
  5244. }
  5245. return stuff;
  5246. }
  5247. function getDateMeta(date, todayRange, nowDate, dateProfile) {
  5248. return {
  5249. dow: date.getUTCDay(),
  5250. isDisabled: Boolean(dateProfile && !rangeContainsMarker(dateProfile.activeRange, date)),
  5251. isOther: Boolean(dateProfile && !rangeContainsMarker(dateProfile.currentRange, date)),
  5252. isToday: Boolean(todayRange && rangeContainsMarker(todayRange, date)),
  5253. isPast: Boolean(nowDate ? (date < nowDate) : todayRange ? (date < todayRange.start) : false),
  5254. isFuture: Boolean(nowDate ? (date > nowDate) : todayRange ? (date >= todayRange.end) : false),
  5255. };
  5256. }
  5257. function getDayClassNames(meta, theme) {
  5258. let classNames = [
  5259. 'fc-day',
  5260. `fc-day-${DAY_IDS[meta.dow]}`,
  5261. ];
  5262. if (meta.isDisabled) {
  5263. classNames.push('fc-day-disabled');
  5264. }
  5265. else {
  5266. if (meta.isToday) {
  5267. classNames.push('fc-day-today');
  5268. classNames.push(theme.getClass('today'));
  5269. }
  5270. if (meta.isPast) {
  5271. classNames.push('fc-day-past');
  5272. }
  5273. if (meta.isFuture) {
  5274. classNames.push('fc-day-future');
  5275. }
  5276. if (meta.isOther) {
  5277. classNames.push('fc-day-other');
  5278. }
  5279. }
  5280. return classNames;
  5281. }
  5282. function getSlotClassNames(meta, theme) {
  5283. let classNames = [
  5284. 'fc-slot',
  5285. `fc-slot-${DAY_IDS[meta.dow]}`,
  5286. ];
  5287. if (meta.isDisabled) {
  5288. classNames.push('fc-slot-disabled');
  5289. }
  5290. else {
  5291. if (meta.isToday) {
  5292. classNames.push('fc-slot-today');
  5293. classNames.push(theme.getClass('today'));
  5294. }
  5295. if (meta.isPast) {
  5296. classNames.push('fc-slot-past');
  5297. }
  5298. if (meta.isFuture) {
  5299. classNames.push('fc-slot-future');
  5300. }
  5301. }
  5302. return classNames;
  5303. }
  5304. const DAY_FORMAT = createFormatter({ year: 'numeric', month: 'long', day: 'numeric' });
  5305. const WEEK_FORMAT = createFormatter({ week: 'long' });
  5306. function buildNavLinkAttrs(context, dateMarker, viewType = 'day', isTabbable = true) {
  5307. const { dateEnv, options, calendarApi } = context;
  5308. let dateStr = dateEnv.format(dateMarker, viewType === 'week' ? WEEK_FORMAT : DAY_FORMAT);
  5309. if (options.navLinks) {
  5310. let zonedDate = dateEnv.toDate(dateMarker);
  5311. const handleInteraction = (ev) => {
  5312. let customAction = viewType === 'day' ? options.navLinkDayClick :
  5313. viewType === 'week' ? options.navLinkWeekClick : null;
  5314. if (typeof customAction === 'function') {
  5315. customAction.call(calendarApi, dateEnv.toDate(dateMarker), ev);
  5316. }
  5317. else {
  5318. if (typeof customAction === 'string') {
  5319. viewType = customAction;
  5320. }
  5321. calendarApi.zoomTo(dateMarker, viewType);
  5322. }
  5323. };
  5324. return Object.assign({ title: formatWithOrdinals(options.navLinkHint, [dateStr, zonedDate], dateStr), 'data-navlink': '' }, (isTabbable
  5325. ? createAriaClickAttrs(handleInteraction)
  5326. : { onClick: handleInteraction }));
  5327. }
  5328. return { 'aria-label': dateStr };
  5329. }
  5330. let _isRtlScrollbarOnLeft = null;
  5331. function getIsRtlScrollbarOnLeft() {
  5332. if (_isRtlScrollbarOnLeft === null) {
  5333. _isRtlScrollbarOnLeft = computeIsRtlScrollbarOnLeft();
  5334. }
  5335. return _isRtlScrollbarOnLeft;
  5336. }
  5337. function computeIsRtlScrollbarOnLeft() {
  5338. let outerEl = document.createElement('div');
  5339. applyStyle(outerEl, {
  5340. position: 'absolute',
  5341. top: -1000,
  5342. left: 0,
  5343. border: 0,
  5344. padding: 0,
  5345. overflow: 'scroll',
  5346. direction: 'rtl',
  5347. });
  5348. outerEl.innerHTML = '<div></div>';
  5349. document.body.appendChild(outerEl);
  5350. let innerEl = outerEl.firstChild;
  5351. let res = innerEl.getBoundingClientRect().left > outerEl.getBoundingClientRect().left;
  5352. removeElement(outerEl);
  5353. return res;
  5354. }
  5355. let _scrollbarWidths;
  5356. function getScrollbarWidths() {
  5357. if (!_scrollbarWidths) {
  5358. _scrollbarWidths = computeScrollbarWidths();
  5359. }
  5360. return _scrollbarWidths;
  5361. }
  5362. function computeScrollbarWidths() {
  5363. let el = document.createElement('div');
  5364. el.style.overflow = 'scroll';
  5365. el.style.position = 'absolute';
  5366. el.style.top = '-9999px';
  5367. el.style.left = '-9999px';
  5368. document.body.appendChild(el);
  5369. let res = computeScrollbarWidthsForEl(el);
  5370. document.body.removeChild(el);
  5371. return res;
  5372. }
  5373. // WARNING: will include border
  5374. function computeScrollbarWidthsForEl(el) {
  5375. return {
  5376. x: el.offsetHeight - el.clientHeight,
  5377. y: el.offsetWidth - el.clientWidth,
  5378. };
  5379. }
  5380. function computeEdges(el, getPadding = false) {
  5381. let computedStyle = window.getComputedStyle(el);
  5382. let borderLeft = parseInt(computedStyle.borderLeftWidth, 10) || 0;
  5383. let borderRight = parseInt(computedStyle.borderRightWidth, 10) || 0;
  5384. let borderTop = parseInt(computedStyle.borderTopWidth, 10) || 0;
  5385. let borderBottom = parseInt(computedStyle.borderBottomWidth, 10) || 0;
  5386. let badScrollbarWidths = computeScrollbarWidthsForEl(el); // includes border!
  5387. let scrollbarLeftRight = badScrollbarWidths.y - borderLeft - borderRight;
  5388. let scrollbarBottom = badScrollbarWidths.x - borderTop - borderBottom;
  5389. let res = {
  5390. borderLeft,
  5391. borderRight,
  5392. borderTop,
  5393. borderBottom,
  5394. scrollbarBottom,
  5395. scrollbarLeft: 0,
  5396. scrollbarRight: 0,
  5397. };
  5398. if (getIsRtlScrollbarOnLeft() && computedStyle.direction === 'rtl') { // is the scrollbar on the left side?
  5399. res.scrollbarLeft = scrollbarLeftRight;
  5400. }
  5401. else {
  5402. res.scrollbarRight = scrollbarLeftRight;
  5403. }
  5404. if (getPadding) {
  5405. res.paddingLeft = parseInt(computedStyle.paddingLeft, 10) || 0;
  5406. res.paddingRight = parseInt(computedStyle.paddingRight, 10) || 0;
  5407. res.paddingTop = parseInt(computedStyle.paddingTop, 10) || 0;
  5408. res.paddingBottom = parseInt(computedStyle.paddingBottom, 10) || 0;
  5409. }
  5410. return res;
  5411. }
  5412. function computeInnerRect(el, goWithinPadding = false, doFromWindowViewport) {
  5413. let outerRect = doFromWindowViewport ? el.getBoundingClientRect() : computeRect(el);
  5414. let edges = computeEdges(el, goWithinPadding);
  5415. let res = {
  5416. left: outerRect.left + edges.borderLeft + edges.scrollbarLeft,
  5417. right: outerRect.right - edges.borderRight - edges.scrollbarRight,
  5418. top: outerRect.top + edges.borderTop,
  5419. bottom: outerRect.bottom - edges.borderBottom - edges.scrollbarBottom,
  5420. };
  5421. if (goWithinPadding) {
  5422. res.left += edges.paddingLeft;
  5423. res.right -= edges.paddingRight;
  5424. res.top += edges.paddingTop;
  5425. res.bottom -= edges.paddingBottom;
  5426. }
  5427. return res;
  5428. }
  5429. function computeRect(el) {
  5430. let rect = el.getBoundingClientRect();
  5431. return {
  5432. left: rect.left + window.scrollX,
  5433. top: rect.top + window.scrollY,
  5434. right: rect.right + window.scrollX,
  5435. bottom: rect.bottom + window.scrollY,
  5436. };
  5437. }
  5438. function computeClippedClientRect(el) {
  5439. let clippingParents = getClippingParents(el);
  5440. let rect = el.getBoundingClientRect();
  5441. for (let clippingParent of clippingParents) {
  5442. let intersection = intersectRects(rect, clippingParent.getBoundingClientRect());
  5443. if (intersection) {
  5444. rect = intersection;
  5445. }
  5446. else {
  5447. return null;
  5448. }
  5449. }
  5450. return rect;
  5451. }
  5452. // does not return window
  5453. function getClippingParents(el) {
  5454. let parents = [];
  5455. while (el instanceof HTMLElement) { // will stop when gets to document or null
  5456. let computedStyle = window.getComputedStyle(el);
  5457. if (computedStyle.position === 'fixed') {
  5458. break;
  5459. }
  5460. if ((/(auto|scroll)/).test(computedStyle.overflow + computedStyle.overflowY + computedStyle.overflowX)) {
  5461. parents.push(el);
  5462. }
  5463. el = el.parentNode;
  5464. }
  5465. return parents;
  5466. }
  5467. /*
  5468. Records offset information for a set of elements, relative to an origin element.
  5469. Can record the left/right OR the top/bottom OR both.
  5470. Provides methods for querying the cache by position.
  5471. */
  5472. class PositionCache {
  5473. constructor(originEl, els, isHorizontal, isVertical) {
  5474. this.els = els;
  5475. let originClientRect = this.originClientRect = originEl.getBoundingClientRect(); // relative to viewport top-left
  5476. if (isHorizontal) {
  5477. this.buildElHorizontals(originClientRect.left);
  5478. }
  5479. if (isVertical) {
  5480. this.buildElVerticals(originClientRect.top);
  5481. }
  5482. }
  5483. // Populates the left/right internal coordinate arrays
  5484. buildElHorizontals(originClientLeft) {
  5485. let lefts = [];
  5486. let rights = [];
  5487. for (let el of this.els) {
  5488. let rect = el.getBoundingClientRect();
  5489. lefts.push(rect.left - originClientLeft);
  5490. rights.push(rect.right - originClientLeft);
  5491. }
  5492. this.lefts = lefts;
  5493. this.rights = rights;
  5494. }
  5495. // Populates the top/bottom internal coordinate arrays
  5496. buildElVerticals(originClientTop) {
  5497. let tops = [];
  5498. let bottoms = [];
  5499. for (let el of this.els) {
  5500. let rect = el.getBoundingClientRect();
  5501. tops.push(rect.top - originClientTop);
  5502. bottoms.push(rect.bottom - originClientTop);
  5503. }
  5504. this.tops = tops;
  5505. this.bottoms = bottoms;
  5506. }
  5507. // Given a left offset (from document left), returns the index of the el that it horizontally intersects.
  5508. // If no intersection is made, returns undefined.
  5509. leftToIndex(leftPosition) {
  5510. let { lefts, rights } = this;
  5511. let len = lefts.length;
  5512. let i;
  5513. for (i = 0; i < len; i += 1) {
  5514. if (leftPosition >= lefts[i] && leftPosition < rights[i]) {
  5515. return i;
  5516. }
  5517. }
  5518. return undefined; // TODO: better
  5519. }
  5520. // Given a top offset (from document top), returns the index of the el that it vertically intersects.
  5521. // If no intersection is made, returns undefined.
  5522. topToIndex(topPosition) {
  5523. let { tops, bottoms } = this;
  5524. let len = tops.length;
  5525. let i;
  5526. for (i = 0; i < len; i += 1) {
  5527. if (topPosition >= tops[i] && topPosition < bottoms[i]) {
  5528. return i;
  5529. }
  5530. }
  5531. return undefined; // TODO: better
  5532. }
  5533. // Gets the width of the element at the given index
  5534. getWidth(leftIndex) {
  5535. return this.rights[leftIndex] - this.lefts[leftIndex];
  5536. }
  5537. // Gets the height of the element at the given index
  5538. getHeight(topIndex) {
  5539. return this.bottoms[topIndex] - this.tops[topIndex];
  5540. }
  5541. similarTo(otherCache) {
  5542. return similarNumArrays(this.tops || [], otherCache.tops || []) &&
  5543. similarNumArrays(this.bottoms || [], otherCache.bottoms || []) &&
  5544. similarNumArrays(this.lefts || [], otherCache.lefts || []) &&
  5545. similarNumArrays(this.rights || [], otherCache.rights || []);
  5546. }
  5547. }
  5548. function similarNumArrays(a, b) {
  5549. const len = a.length;
  5550. if (len !== b.length) {
  5551. return false;
  5552. }
  5553. for (let i = 0; i < len; i++) {
  5554. if (Math.round(a[i]) !== Math.round(b[i])) {
  5555. return false;
  5556. }
  5557. }
  5558. return true;
  5559. }
  5560. /* eslint max-classes-per-file: "off" */
  5561. /*
  5562. An object for getting/setting scroll-related information for an element.
  5563. Internally, this is done very differently for window versus DOM element,
  5564. so this object serves as a common interface.
  5565. */
  5566. class ScrollController {
  5567. getMaxScrollTop() {
  5568. return this.getScrollHeight() - this.getClientHeight();
  5569. }
  5570. getMaxScrollLeft() {
  5571. return this.getScrollWidth() - this.getClientWidth();
  5572. }
  5573. canScrollVertically() {
  5574. return this.getMaxScrollTop() > 0;
  5575. }
  5576. canScrollHorizontally() {
  5577. return this.getMaxScrollLeft() > 0;
  5578. }
  5579. canScrollUp() {
  5580. return this.getScrollTop() > 0;
  5581. }
  5582. canScrollDown() {
  5583. return this.getScrollTop() < this.getMaxScrollTop();
  5584. }
  5585. canScrollLeft() {
  5586. return this.getScrollLeft() > 0;
  5587. }
  5588. canScrollRight() {
  5589. return this.getScrollLeft() < this.getMaxScrollLeft();
  5590. }
  5591. }
  5592. class ElementScrollController extends ScrollController {
  5593. constructor(el) {
  5594. super();
  5595. this.el = el;
  5596. }
  5597. getScrollTop() {
  5598. return this.el.scrollTop;
  5599. }
  5600. getScrollLeft() {
  5601. return this.el.scrollLeft;
  5602. }
  5603. setScrollTop(top) {
  5604. this.el.scrollTop = top;
  5605. }
  5606. setScrollLeft(left) {
  5607. this.el.scrollLeft = left;
  5608. }
  5609. getScrollWidth() {
  5610. return this.el.scrollWidth;
  5611. }
  5612. getScrollHeight() {
  5613. return this.el.scrollHeight;
  5614. }
  5615. getClientHeight() {
  5616. return this.el.clientHeight;
  5617. }
  5618. getClientWidth() {
  5619. return this.el.clientWidth;
  5620. }
  5621. }
  5622. class WindowScrollController extends ScrollController {
  5623. getScrollTop() {
  5624. return window.scrollY;
  5625. }
  5626. getScrollLeft() {
  5627. return window.scrollX;
  5628. }
  5629. setScrollTop(n) {
  5630. window.scroll(window.scrollX, n);
  5631. }
  5632. setScrollLeft(n) {
  5633. window.scroll(n, window.scrollY);
  5634. }
  5635. getScrollWidth() {
  5636. return document.documentElement.scrollWidth;
  5637. }
  5638. getScrollHeight() {
  5639. return document.documentElement.scrollHeight;
  5640. }
  5641. getClientHeight() {
  5642. return document.documentElement.clientHeight;
  5643. }
  5644. getClientWidth() {
  5645. return document.documentElement.clientWidth;
  5646. }
  5647. }
  5648. /*
  5649. an INTERACTABLE date component
  5650. PURPOSES:
  5651. - hook up to fg, fill, and mirror renderers
  5652. - interface for dragging and hits
  5653. */
  5654. class DateComponent extends BaseComponent {
  5655. constructor() {
  5656. super(...arguments);
  5657. this.uid = guid();
  5658. }
  5659. // Hit System
  5660. // -----------------------------------------------------------------------------------------------------------------
  5661. prepareHits() {
  5662. }
  5663. queryHit(positionLeft, positionTop, elWidth, elHeight) {
  5664. return null; // this should be abstract
  5665. }
  5666. // Pointer Interaction Utils
  5667. // -----------------------------------------------------------------------------------------------------------------
  5668. isValidSegDownEl(el) {
  5669. return !this.props.eventDrag && // HACK
  5670. !this.props.eventResize && // HACK
  5671. !elementClosest(el, '.fc-event-mirror');
  5672. }
  5673. isValidDateDownEl(el) {
  5674. return !elementClosest(el, '.fc-event:not(.fc-bg-event)') &&
  5675. !elementClosest(el, '.fc-more-link') && // a "more.." link
  5676. !elementClosest(el, 'a[data-navlink]') && // a clickable nav link
  5677. !elementClosest(el, '.fc-popover'); // hack
  5678. }
  5679. }
  5680. class NamedTimeZoneImpl {
  5681. constructor(timeZoneName) {
  5682. this.timeZoneName = timeZoneName;
  5683. }
  5684. }
  5685. class SegHierarchy {
  5686. constructor(getEntryThickness = (entry) => {
  5687. // if no thickness known, assume 1 (if 0, so small it always fits)
  5688. return entry.thickness || 1;
  5689. }) {
  5690. this.getEntryThickness = getEntryThickness;
  5691. // settings
  5692. this.strictOrder = false;
  5693. this.allowReslicing = false;
  5694. this.maxCoord = -1; // -1 means no max
  5695. this.maxStackCnt = -1; // -1 means no max
  5696. this.levelCoords = []; // ordered
  5697. this.entriesByLevel = []; // parallel with levelCoords
  5698. this.stackCnts = {}; // TODO: use better technique!?
  5699. }
  5700. addSegs(inputs) {
  5701. let hiddenEntries = [];
  5702. for (let input of inputs) {
  5703. this.insertEntry(input, hiddenEntries);
  5704. }
  5705. return hiddenEntries;
  5706. }
  5707. insertEntry(entry, hiddenEntries) {
  5708. let insertion = this.findInsertion(entry);
  5709. if (this.isInsertionValid(insertion, entry)) {
  5710. this.insertEntryAt(entry, insertion);
  5711. }
  5712. else {
  5713. this.handleInvalidInsertion(insertion, entry, hiddenEntries);
  5714. }
  5715. }
  5716. isInsertionValid(insertion, entry) {
  5717. return (this.maxCoord === -1 || insertion.levelCoord + this.getEntryThickness(entry) <= this.maxCoord) &&
  5718. (this.maxStackCnt === -1 || insertion.stackCnt < this.maxStackCnt);
  5719. }
  5720. handleInvalidInsertion(insertion, entry, hiddenEntries) {
  5721. if (this.allowReslicing && insertion.touchingEntry) {
  5722. const hiddenEntry = Object.assign(Object.assign({}, entry), { span: intersectSpans(entry.span, insertion.touchingEntry.span) });
  5723. hiddenEntries.push(hiddenEntry);
  5724. this.splitEntry(entry, insertion.touchingEntry, hiddenEntries);
  5725. }
  5726. else {
  5727. hiddenEntries.push(entry);
  5728. }
  5729. }
  5730. /*
  5731. Does NOT add what hit the `barrier` into hiddenEntries. Should already be done.
  5732. */
  5733. splitEntry(entry, barrier, hiddenEntries) {
  5734. let entrySpan = entry.span;
  5735. let barrierSpan = barrier.span;
  5736. if (entrySpan.start < barrierSpan.start) {
  5737. this.insertEntry({
  5738. index: entry.index,
  5739. thickness: entry.thickness,
  5740. span: { start: entrySpan.start, end: barrierSpan.start },
  5741. }, hiddenEntries);
  5742. }
  5743. if (entrySpan.end > barrierSpan.end) {
  5744. this.insertEntry({
  5745. index: entry.index,
  5746. thickness: entry.thickness,
  5747. span: { start: barrierSpan.end, end: entrySpan.end },
  5748. }, hiddenEntries);
  5749. }
  5750. }
  5751. insertEntryAt(entry, insertion) {
  5752. let { entriesByLevel, levelCoords } = this;
  5753. if (insertion.lateral === -1) {
  5754. // create a new level
  5755. insertAt(levelCoords, insertion.level, insertion.levelCoord);
  5756. insertAt(entriesByLevel, insertion.level, [entry]);
  5757. }
  5758. else {
  5759. // insert into existing level
  5760. insertAt(entriesByLevel[insertion.level], insertion.lateral, entry);
  5761. }
  5762. this.stackCnts[buildEntryKey(entry)] = insertion.stackCnt;
  5763. }
  5764. /*
  5765. does not care about limits
  5766. */
  5767. findInsertion(newEntry) {
  5768. let { levelCoords, entriesByLevel, strictOrder, stackCnts } = this;
  5769. let levelCnt = levelCoords.length;
  5770. let candidateCoord = 0;
  5771. let touchingLevel = -1;
  5772. let touchingLateral = -1;
  5773. let touchingEntry = null;
  5774. let stackCnt = 0;
  5775. for (let trackingLevel = 0; trackingLevel < levelCnt; trackingLevel += 1) {
  5776. const trackingCoord = levelCoords[trackingLevel];
  5777. // if the current level is past the placed entry, we have found a good empty space and can stop.
  5778. // if strictOrder, keep finding more lateral intersections.
  5779. if (!strictOrder && trackingCoord >= candidateCoord + this.getEntryThickness(newEntry)) {
  5780. break;
  5781. }
  5782. let trackingEntries = entriesByLevel[trackingLevel];
  5783. let trackingEntry;
  5784. let searchRes = binarySearch(trackingEntries, newEntry.span.start, getEntrySpanEnd); // find first entry after newEntry's end
  5785. let lateralIndex = searchRes[0] + searchRes[1]; // if exact match (which doesn't collide), go to next one
  5786. while ( // loop through entries that horizontally intersect
  5787. (trackingEntry = trackingEntries[lateralIndex]) && // but not past the whole entry list
  5788. trackingEntry.span.start < newEntry.span.end // and not entirely past newEntry
  5789. ) {
  5790. let trackingEntryBottom = trackingCoord + this.getEntryThickness(trackingEntry);
  5791. // intersects into the top of the candidate?
  5792. if (trackingEntryBottom > candidateCoord) {
  5793. candidateCoord = trackingEntryBottom;
  5794. touchingEntry = trackingEntry;
  5795. touchingLevel = trackingLevel;
  5796. touchingLateral = lateralIndex;
  5797. }
  5798. // butts up against top of candidate? (will happen if just intersected as well)
  5799. if (trackingEntryBottom === candidateCoord) {
  5800. // accumulate the highest possible stackCnt of the trackingEntries that butt up
  5801. stackCnt = Math.max(stackCnt, stackCnts[buildEntryKey(trackingEntry)] + 1);
  5802. }
  5803. lateralIndex += 1;
  5804. }
  5805. }
  5806. // the destination level will be after touchingEntry's level. find it
  5807. let destLevel = 0;
  5808. if (touchingEntry) {
  5809. destLevel = touchingLevel + 1;
  5810. while (destLevel < levelCnt && levelCoords[destLevel] < candidateCoord) {
  5811. destLevel += 1;
  5812. }
  5813. }
  5814. // if adding to an existing level, find where to insert
  5815. let destLateral = -1;
  5816. if (destLevel < levelCnt && levelCoords[destLevel] === candidateCoord) {
  5817. destLateral = binarySearch(entriesByLevel[destLevel], newEntry.span.end, getEntrySpanEnd)[0];
  5818. }
  5819. return {
  5820. touchingLevel,
  5821. touchingLateral,
  5822. touchingEntry,
  5823. stackCnt,
  5824. levelCoord: candidateCoord,
  5825. level: destLevel,
  5826. lateral: destLateral,
  5827. };
  5828. }
  5829. // sorted by levelCoord (lowest to highest)
  5830. toRects() {
  5831. let { entriesByLevel, levelCoords } = this;
  5832. let levelCnt = entriesByLevel.length;
  5833. let rects = [];
  5834. for (let level = 0; level < levelCnt; level += 1) {
  5835. let entries = entriesByLevel[level];
  5836. let levelCoord = levelCoords[level];
  5837. for (let entry of entries) {
  5838. rects.push(Object.assign(Object.assign({}, entry), { thickness: this.getEntryThickness(entry), levelCoord }));
  5839. }
  5840. }
  5841. return rects;
  5842. }
  5843. }
  5844. function getEntrySpanEnd(entry) {
  5845. return entry.span.end;
  5846. }
  5847. function buildEntryKey(entry) {
  5848. return entry.index + ':' + entry.span.start;
  5849. }
  5850. // returns groups with entries sorted by input order
  5851. function groupIntersectingEntries(entries) {
  5852. let merges = [];
  5853. for (let entry of entries) {
  5854. let filteredMerges = [];
  5855. let hungryMerge = {
  5856. span: entry.span,
  5857. entries: [entry],
  5858. };
  5859. for (let merge of merges) {
  5860. if (intersectSpans(merge.span, hungryMerge.span)) {
  5861. hungryMerge = {
  5862. entries: merge.entries.concat(hungryMerge.entries),
  5863. span: joinSpans(merge.span, hungryMerge.span),
  5864. };
  5865. }
  5866. else {
  5867. filteredMerges.push(merge);
  5868. }
  5869. }
  5870. filteredMerges.push(hungryMerge);
  5871. merges = filteredMerges;
  5872. }
  5873. return merges;
  5874. }
  5875. function joinSpans(span0, span1) {
  5876. return {
  5877. start: Math.min(span0.start, span1.start),
  5878. end: Math.max(span0.end, span1.end),
  5879. };
  5880. }
  5881. function intersectSpans(span0, span1) {
  5882. let start = Math.max(span0.start, span1.start);
  5883. let end = Math.min(span0.end, span1.end);
  5884. if (start < end) {
  5885. return { start, end };
  5886. }
  5887. return null;
  5888. }
  5889. // general util
  5890. // ---------------------------------------------------------------------------------------------------------------------
  5891. function insertAt(arr, index, item) {
  5892. arr.splice(index, 0, item);
  5893. }
  5894. function binarySearch(a, searchVal, getItemVal) {
  5895. let startIndex = 0;
  5896. let endIndex = a.length; // exclusive
  5897. if (!endIndex || searchVal < getItemVal(a[startIndex])) { // no items OR before first item
  5898. return [0, 0];
  5899. }
  5900. if (searchVal > getItemVal(a[endIndex - 1])) { // after last item
  5901. return [endIndex, 0];
  5902. }
  5903. while (startIndex < endIndex) {
  5904. let middleIndex = Math.floor(startIndex + (endIndex - startIndex) / 2);
  5905. let middleVal = getItemVal(a[middleIndex]);
  5906. if (searchVal < middleVal) {
  5907. endIndex = middleIndex;
  5908. }
  5909. else if (searchVal > middleVal) {
  5910. startIndex = middleIndex + 1;
  5911. }
  5912. else { // equal!
  5913. return [middleIndex, 1];
  5914. }
  5915. }
  5916. return [startIndex, 0];
  5917. }
  5918. /*
  5919. An abstraction for a dragging interaction originating on an event.
  5920. Does higher-level things than PointerDragger, such as possibly:
  5921. - a "mirror" that moves with the pointer
  5922. - a minimum number of pixels or other criteria for a true drag to begin
  5923. subclasses must emit:
  5924. - pointerdown
  5925. - dragstart
  5926. - dragmove
  5927. - pointerup
  5928. - dragend
  5929. */
  5930. class ElementDragging {
  5931. constructor(el, selector) {
  5932. this.emitter = new Emitter();
  5933. }
  5934. destroy() {
  5935. }
  5936. setMirrorIsVisible(bool) {
  5937. // optional if subclass doesn't want to support a mirror
  5938. }
  5939. setMirrorNeedsRevert(bool) {
  5940. // optional if subclass doesn't want to support a mirror
  5941. }
  5942. setAutoScrollEnabled(bool) {
  5943. // optional
  5944. }
  5945. }
  5946. // TODO: get rid of this in favor of options system,
  5947. // tho it's really easy to access this globally rather than pass thru options.
  5948. const config = {};
  5949. /*
  5950. Information about what will happen when an external element is dragged-and-dropped
  5951. onto a calendar. Contains information for creating an event.
  5952. */
  5953. const DRAG_META_REFINERS = {
  5954. startTime: createDuration,
  5955. duration: createDuration,
  5956. create: Boolean,
  5957. sourceId: String,
  5958. };
  5959. function parseDragMeta(raw) {
  5960. let { refined, extra } = refineProps(raw, DRAG_META_REFINERS);
  5961. return {
  5962. startTime: refined.startTime || null,
  5963. duration: refined.duration || null,
  5964. create: refined.create != null ? refined.create : true,
  5965. sourceId: refined.sourceId,
  5966. leftoverProps: extra,
  5967. };
  5968. }
  5969. // Computes a default column header formatting string if `colFormat` is not explicitly defined
  5970. function computeFallbackHeaderFormat(datesRepDistinctDays, dayCnt) {
  5971. // if more than one week row, or if there are a lot of columns with not much space,
  5972. // put just the day numbers will be in each cell
  5973. if (!datesRepDistinctDays || dayCnt > 10) {
  5974. return createFormatter({ weekday: 'short' }); // "Sat"
  5975. }
  5976. if (dayCnt > 1) {
  5977. return createFormatter({ weekday: 'short', month: 'numeric', day: 'numeric', omitCommas: true }); // "Sat 11/12"
  5978. }
  5979. return createFormatter({ weekday: 'long' }); // "Saturday"
  5980. }
  5981. const CLASS_NAME = 'fc-col-header-cell'; // do the cushion too? no
  5982. function renderInner$1(renderProps) {
  5983. return renderProps.text;
  5984. }
  5985. // BAD name for this class now. used in the Header
  5986. class TableDateCell extends BaseComponent {
  5987. render() {
  5988. let { dateEnv, options, theme, viewApi } = this.context;
  5989. let { props } = this;
  5990. let { date, dateProfile } = props;
  5991. let dayMeta = getDateMeta(date, props.todayRange, null, dateProfile);
  5992. let classNames = [CLASS_NAME].concat(getDayClassNames(dayMeta, theme));
  5993. let text = dateEnv.format(date, props.dayHeaderFormat);
  5994. // if colCnt is 1, we are already in a day-view and don't need a navlink
  5995. let navLinkAttrs = (!dayMeta.isDisabled && props.colCnt > 1)
  5996. ? buildNavLinkAttrs(this.context, date)
  5997. : {};
  5998. let renderProps = Object.assign(Object.assign(Object.assign({ date: dateEnv.toDate(date), view: viewApi }, props.extraRenderProps), { text }), dayMeta);
  5999. return (createElement(ContentContainer, { elTag: "th", elClasses: classNames, elAttrs: Object.assign({ role: 'columnheader', colSpan: props.colSpan, 'data-date': !dayMeta.isDisabled ? formatDayString(date) : undefined }, props.extraDataAttrs), renderProps: renderProps, generatorName: "dayHeaderContent", customGenerator: options.dayHeaderContent, defaultGenerator: renderInner$1, classNameGenerator: options.dayHeaderClassNames, didMount: options.dayHeaderDidMount, willUnmount: options.dayHeaderWillUnmount }, (InnerContainer) => (createElement("div", { className: "fc-scrollgrid-sync-inner" }, !dayMeta.isDisabled && (createElement(InnerContainer, { elTag: "a", elAttrs: navLinkAttrs, elClasses: [
  6000. 'fc-col-header-cell-cushion',
  6001. props.isSticky && 'fc-sticky',
  6002. ] }))))));
  6003. }
  6004. }
  6005. const WEEKDAY_FORMAT = createFormatter({ weekday: 'long' });
  6006. class TableDowCell extends BaseComponent {
  6007. render() {
  6008. let { props } = this;
  6009. let { dateEnv, theme, viewApi, options } = this.context;
  6010. let date = addDays(new Date(259200000), props.dow); // start with Sun, 04 Jan 1970 00:00:00 GMT
  6011. let dateMeta = {
  6012. dow: props.dow,
  6013. isDisabled: false,
  6014. isFuture: false,
  6015. isPast: false,
  6016. isToday: false,
  6017. isOther: false,
  6018. };
  6019. let text = dateEnv.format(date, props.dayHeaderFormat);
  6020. let renderProps = Object.assign(Object.assign(Object.assign(Object.assign({ // TODO: make this public?
  6021. date }, dateMeta), { view: viewApi }), props.extraRenderProps), { text });
  6022. return (createElement(ContentContainer, { elTag: "th", elClasses: [
  6023. CLASS_NAME,
  6024. ...getDayClassNames(dateMeta, theme),
  6025. ...(props.extraClassNames || []),
  6026. ], elAttrs: Object.assign({ role: 'columnheader', colSpan: props.colSpan }, props.extraDataAttrs), renderProps: renderProps, generatorName: "dayHeaderContent", customGenerator: options.dayHeaderContent, defaultGenerator: renderInner$1, classNameGenerator: options.dayHeaderClassNames, didMount: options.dayHeaderDidMount, willUnmount: options.dayHeaderWillUnmount }, (InnerContent) => (createElement("div", { className: "fc-scrollgrid-sync-inner" },
  6027. createElement(InnerContent, { elTag: "a", elClasses: [
  6028. 'fc-col-header-cell-cushion',
  6029. props.isSticky && 'fc-sticky',
  6030. ], elAttrs: {
  6031. 'aria-label': dateEnv.format(date, WEEKDAY_FORMAT),
  6032. } })))));
  6033. }
  6034. }
  6035. class NowTimer extends Component {
  6036. constructor(props, context) {
  6037. super(props, context);
  6038. this.initialNowDate = getNow(context.options.now, context.dateEnv);
  6039. this.initialNowQueriedMs = new Date().valueOf();
  6040. this.state = this.computeTiming().currentState;
  6041. }
  6042. render() {
  6043. let { props, state } = this;
  6044. return props.children(state.nowDate, state.todayRange);
  6045. }
  6046. componentDidMount() {
  6047. this.setTimeout();
  6048. }
  6049. componentDidUpdate(prevProps) {
  6050. if (prevProps.unit !== this.props.unit) {
  6051. this.clearTimeout();
  6052. this.setTimeout();
  6053. }
  6054. }
  6055. componentWillUnmount() {
  6056. this.clearTimeout();
  6057. }
  6058. computeTiming() {
  6059. let { props, context } = this;
  6060. let unroundedNow = addMs(this.initialNowDate, new Date().valueOf() - this.initialNowQueriedMs);
  6061. let currentUnitStart = context.dateEnv.startOf(unroundedNow, props.unit);
  6062. let nextUnitStart = context.dateEnv.add(currentUnitStart, createDuration(1, props.unit));
  6063. let waitMs = nextUnitStart.valueOf() - unroundedNow.valueOf();
  6064. // there is a max setTimeout ms value (https://stackoverflow.com/a/3468650/96342)
  6065. // ensure no longer than a day
  6066. waitMs = Math.min(1000 * 60 * 60 * 24, waitMs);
  6067. return {
  6068. currentState: { nowDate: currentUnitStart, todayRange: buildDayRange(currentUnitStart) },
  6069. nextState: { nowDate: nextUnitStart, todayRange: buildDayRange(nextUnitStart) },
  6070. waitMs,
  6071. };
  6072. }
  6073. setTimeout() {
  6074. let { nextState, waitMs } = this.computeTiming();
  6075. this.timeoutId = setTimeout(() => {
  6076. this.setState(nextState, () => {
  6077. this.setTimeout();
  6078. });
  6079. }, waitMs);
  6080. }
  6081. clearTimeout() {
  6082. if (this.timeoutId) {
  6083. clearTimeout(this.timeoutId);
  6084. }
  6085. }
  6086. }
  6087. NowTimer.contextType = ViewContextType;
  6088. function buildDayRange(date) {
  6089. let start = startOfDay(date);
  6090. let end = addDays(start, 1);
  6091. return { start, end };
  6092. }
  6093. class DayHeader extends BaseComponent {
  6094. constructor() {
  6095. super(...arguments);
  6096. this.createDayHeaderFormatter = memoize(createDayHeaderFormatter);
  6097. }
  6098. render() {
  6099. let { context } = this;
  6100. let { dates, dateProfile, datesRepDistinctDays, renderIntro } = this.props;
  6101. let dayHeaderFormat = this.createDayHeaderFormatter(context.options.dayHeaderFormat, datesRepDistinctDays, dates.length);
  6102. return (createElement(NowTimer, { unit: "day" }, (nowDate, todayRange) => (createElement("tr", { role: "row" },
  6103. renderIntro && renderIntro('day'),
  6104. dates.map((date) => (datesRepDistinctDays ? (createElement(TableDateCell, { key: date.toISOString(), date: date, dateProfile: dateProfile, todayRange: todayRange, colCnt: dates.length, dayHeaderFormat: dayHeaderFormat })) : (createElement(TableDowCell, { key: date.getUTCDay(), dow: date.getUTCDay(), dayHeaderFormat: dayHeaderFormat }))))))));
  6105. }
  6106. }
  6107. function createDayHeaderFormatter(explicitFormat, datesRepDistinctDays, dateCnt) {
  6108. return explicitFormat || computeFallbackHeaderFormat(datesRepDistinctDays, dateCnt);
  6109. }
  6110. class DaySeriesModel {
  6111. constructor(range, dateProfileGenerator) {
  6112. let date = range.start;
  6113. let { end } = range;
  6114. let indices = [];
  6115. let dates = [];
  6116. let dayIndex = -1;
  6117. while (date < end) { // loop each day from start to end
  6118. if (dateProfileGenerator.isHiddenDay(date)) {
  6119. indices.push(dayIndex + 0.5); // mark that it's between indices
  6120. }
  6121. else {
  6122. dayIndex += 1;
  6123. indices.push(dayIndex);
  6124. dates.push(date);
  6125. }
  6126. date = addDays(date, 1);
  6127. }
  6128. this.dates = dates;
  6129. this.indices = indices;
  6130. this.cnt = dates.length;
  6131. }
  6132. sliceRange(range) {
  6133. let firstIndex = this.getDateDayIndex(range.start); // inclusive first index
  6134. let lastIndex = this.getDateDayIndex(addDays(range.end, -1)); // inclusive last index
  6135. let clippedFirstIndex = Math.max(0, firstIndex);
  6136. let clippedLastIndex = Math.min(this.cnt - 1, lastIndex);
  6137. // deal with in-between indices
  6138. clippedFirstIndex = Math.ceil(clippedFirstIndex); // in-between starts round to next cell
  6139. clippedLastIndex = Math.floor(clippedLastIndex); // in-between ends round to prev cell
  6140. if (clippedFirstIndex <= clippedLastIndex) {
  6141. return {
  6142. firstIndex: clippedFirstIndex,
  6143. lastIndex: clippedLastIndex,
  6144. isStart: firstIndex === clippedFirstIndex,
  6145. isEnd: lastIndex === clippedLastIndex,
  6146. };
  6147. }
  6148. return null;
  6149. }
  6150. // Given a date, returns its chronolocial cell-index from the first cell of the grid.
  6151. // If the date lies between cells (because of hiddenDays), returns a floating-point value between offsets.
  6152. // If before the first offset, returns a negative number.
  6153. // If after the last offset, returns an offset past the last cell offset.
  6154. // Only works for *start* dates of cells. Will not work for exclusive end dates for cells.
  6155. getDateDayIndex(date) {
  6156. let { indices } = this;
  6157. let dayOffset = Math.floor(diffDays(this.dates[0], date));
  6158. if (dayOffset < 0) {
  6159. return indices[0] - 1;
  6160. }
  6161. if (dayOffset >= indices.length) {
  6162. return indices[indices.length - 1] + 1;
  6163. }
  6164. return indices[dayOffset];
  6165. }
  6166. }
  6167. class DayTableModel {
  6168. constructor(daySeries, breakOnWeeks) {
  6169. let { dates } = daySeries;
  6170. let daysPerRow;
  6171. let firstDay;
  6172. let rowCnt;
  6173. if (breakOnWeeks) {
  6174. // count columns until the day-of-week repeats
  6175. firstDay = dates[0].getUTCDay();
  6176. for (daysPerRow = 1; daysPerRow < dates.length; daysPerRow += 1) {
  6177. if (dates[daysPerRow].getUTCDay() === firstDay) {
  6178. break;
  6179. }
  6180. }
  6181. rowCnt = Math.ceil(dates.length / daysPerRow);
  6182. }
  6183. else {
  6184. rowCnt = 1;
  6185. daysPerRow = dates.length;
  6186. }
  6187. this.rowCnt = rowCnt;
  6188. this.colCnt = daysPerRow;
  6189. this.daySeries = daySeries;
  6190. this.cells = this.buildCells();
  6191. this.headerDates = this.buildHeaderDates();
  6192. }
  6193. buildCells() {
  6194. let rows = [];
  6195. for (let row = 0; row < this.rowCnt; row += 1) {
  6196. let cells = [];
  6197. for (let col = 0; col < this.colCnt; col += 1) {
  6198. cells.push(this.buildCell(row, col));
  6199. }
  6200. rows.push(cells);
  6201. }
  6202. return rows;
  6203. }
  6204. buildCell(row, col) {
  6205. let date = this.daySeries.dates[row * this.colCnt + col];
  6206. return {
  6207. key: date.toISOString(),
  6208. date,
  6209. };
  6210. }
  6211. buildHeaderDates() {
  6212. let dates = [];
  6213. for (let col = 0; col < this.colCnt; col += 1) {
  6214. dates.push(this.cells[0][col].date);
  6215. }
  6216. return dates;
  6217. }
  6218. sliceRange(range) {
  6219. let { colCnt } = this;
  6220. let seriesSeg = this.daySeries.sliceRange(range);
  6221. let segs = [];
  6222. if (seriesSeg) {
  6223. let { firstIndex, lastIndex } = seriesSeg;
  6224. let index = firstIndex;
  6225. while (index <= lastIndex) {
  6226. let row = Math.floor(index / colCnt);
  6227. let nextIndex = Math.min((row + 1) * colCnt, lastIndex + 1);
  6228. segs.push({
  6229. row,
  6230. firstCol: index % colCnt,
  6231. lastCol: (nextIndex - 1) % colCnt,
  6232. isStart: seriesSeg.isStart && index === firstIndex,
  6233. isEnd: seriesSeg.isEnd && (nextIndex - 1) === lastIndex,
  6234. });
  6235. index = nextIndex;
  6236. }
  6237. }
  6238. return segs;
  6239. }
  6240. }
  6241. class Slicer {
  6242. constructor() {
  6243. this.sliceBusinessHours = memoize(this._sliceBusinessHours);
  6244. this.sliceDateSelection = memoize(this._sliceDateSpan);
  6245. this.sliceEventStore = memoize(this._sliceEventStore);
  6246. this.sliceEventDrag = memoize(this._sliceInteraction);
  6247. this.sliceEventResize = memoize(this._sliceInteraction);
  6248. this.forceDayIfListItem = false; // hack
  6249. }
  6250. sliceProps(props, dateProfile, nextDayThreshold, context, ...extraArgs) {
  6251. let { eventUiBases } = props;
  6252. let eventSegs = this.sliceEventStore(props.eventStore, eventUiBases, dateProfile, nextDayThreshold, ...extraArgs);
  6253. return {
  6254. dateSelectionSegs: this.sliceDateSelection(props.dateSelection, dateProfile, nextDayThreshold, eventUiBases, context, ...extraArgs),
  6255. businessHourSegs: this.sliceBusinessHours(props.businessHours, dateProfile, nextDayThreshold, context, ...extraArgs),
  6256. fgEventSegs: eventSegs.fg,
  6257. bgEventSegs: eventSegs.bg,
  6258. eventDrag: this.sliceEventDrag(props.eventDrag, eventUiBases, dateProfile, nextDayThreshold, ...extraArgs),
  6259. eventResize: this.sliceEventResize(props.eventResize, eventUiBases, dateProfile, nextDayThreshold, ...extraArgs),
  6260. eventSelection: props.eventSelection,
  6261. }; // TODO: give interactionSegs?
  6262. }
  6263. sliceNowDate(// does not memoize
  6264. date, dateProfile, nextDayThreshold, context, ...extraArgs) {
  6265. return this._sliceDateSpan({ range: { start: date, end: addMs(date, 1) }, allDay: false }, // add 1 ms, protect against null range
  6266. dateProfile, nextDayThreshold, {}, context, ...extraArgs);
  6267. }
  6268. _sliceBusinessHours(businessHours, dateProfile, nextDayThreshold, context, ...extraArgs) {
  6269. if (!businessHours) {
  6270. return [];
  6271. }
  6272. return this._sliceEventStore(expandRecurring(businessHours, computeActiveRange(dateProfile, Boolean(nextDayThreshold)), context), {}, dateProfile, nextDayThreshold, ...extraArgs).bg;
  6273. }
  6274. _sliceEventStore(eventStore, eventUiBases, dateProfile, nextDayThreshold, ...extraArgs) {
  6275. if (eventStore) {
  6276. let rangeRes = sliceEventStore(eventStore, eventUiBases, computeActiveRange(dateProfile, Boolean(nextDayThreshold)), nextDayThreshold);
  6277. return {
  6278. bg: this.sliceEventRanges(rangeRes.bg, extraArgs),
  6279. fg: this.sliceEventRanges(rangeRes.fg, extraArgs),
  6280. };
  6281. }
  6282. return { bg: [], fg: [] };
  6283. }
  6284. _sliceInteraction(interaction, eventUiBases, dateProfile, nextDayThreshold, ...extraArgs) {
  6285. if (!interaction) {
  6286. return null;
  6287. }
  6288. let rangeRes = sliceEventStore(interaction.mutatedEvents, eventUiBases, computeActiveRange(dateProfile, Boolean(nextDayThreshold)), nextDayThreshold);
  6289. return {
  6290. segs: this.sliceEventRanges(rangeRes.fg, extraArgs),
  6291. affectedInstances: interaction.affectedEvents.instances,
  6292. isEvent: interaction.isEvent,
  6293. };
  6294. }
  6295. _sliceDateSpan(dateSpan, dateProfile, nextDayThreshold, eventUiBases, context, ...extraArgs) {
  6296. if (!dateSpan) {
  6297. return [];
  6298. }
  6299. let activeRange = computeActiveRange(dateProfile, Boolean(nextDayThreshold));
  6300. let activeDateSpanRange = intersectRanges(dateSpan.range, activeRange);
  6301. if (activeDateSpanRange) {
  6302. dateSpan = Object.assign(Object.assign({}, dateSpan), { range: activeDateSpanRange });
  6303. let eventRange = fabricateEventRange(dateSpan, eventUiBases, context);
  6304. let segs = this.sliceRange(dateSpan.range, ...extraArgs);
  6305. for (let seg of segs) {
  6306. seg.eventRange = eventRange;
  6307. }
  6308. return segs;
  6309. }
  6310. return [];
  6311. }
  6312. /*
  6313. "complete" seg means it has component and eventRange
  6314. */
  6315. sliceEventRanges(eventRanges, extraArgs) {
  6316. let segs = [];
  6317. for (let eventRange of eventRanges) {
  6318. segs.push(...this.sliceEventRange(eventRange, extraArgs));
  6319. }
  6320. return segs;
  6321. }
  6322. /*
  6323. "complete" seg means it has component and eventRange
  6324. */
  6325. sliceEventRange(eventRange, extraArgs) {
  6326. let dateRange = eventRange.range;
  6327. // hack to make multi-day events that are being force-displayed as list-items to take up only one day
  6328. if (this.forceDayIfListItem && eventRange.ui.display === 'list-item') {
  6329. dateRange = {
  6330. start: dateRange.start,
  6331. end: addDays(dateRange.start, 1),
  6332. };
  6333. }
  6334. let segs = this.sliceRange(dateRange, ...extraArgs);
  6335. for (let seg of segs) {
  6336. seg.eventRange = eventRange;
  6337. seg.isStart = eventRange.isStart && seg.isStart;
  6338. seg.isEnd = eventRange.isEnd && seg.isEnd;
  6339. }
  6340. return segs;
  6341. }
  6342. }
  6343. /*
  6344. for incorporating slotMinTime/slotMaxTime if appropriate
  6345. TODO: should be part of DateProfile!
  6346. TimelineDateProfile already does this btw
  6347. */
  6348. function computeActiveRange(dateProfile, isComponentAllDay) {
  6349. let range = dateProfile.activeRange;
  6350. if (isComponentAllDay) {
  6351. return range;
  6352. }
  6353. return {
  6354. start: addMs(range.start, dateProfile.slotMinTime.milliseconds),
  6355. end: addMs(range.end, dateProfile.slotMaxTime.milliseconds - 864e5), // 864e5 = ms in a day
  6356. };
  6357. }
  6358. // high-level segmenting-aware tester functions
  6359. // ------------------------------------------------------------------------------------------------------------------------
  6360. function isInteractionValid(interaction, dateProfile, context) {
  6361. let { instances } = interaction.mutatedEvents;
  6362. for (let instanceId in instances) {
  6363. if (!rangeContainsRange(dateProfile.validRange, instances[instanceId].range)) {
  6364. return false;
  6365. }
  6366. }
  6367. return isNewPropsValid({ eventDrag: interaction }, context); // HACK: the eventDrag props is used for ALL interactions
  6368. }
  6369. function isDateSelectionValid(dateSelection, dateProfile, context) {
  6370. if (!rangeContainsRange(dateProfile.validRange, dateSelection.range)) {
  6371. return false;
  6372. }
  6373. return isNewPropsValid({ dateSelection }, context);
  6374. }
  6375. function isNewPropsValid(newProps, context) {
  6376. let calendarState = context.getCurrentData();
  6377. let props = Object.assign({ businessHours: calendarState.businessHours, dateSelection: '', eventStore: calendarState.eventStore, eventUiBases: calendarState.eventUiBases, eventSelection: '', eventDrag: null, eventResize: null }, newProps);
  6378. return (context.pluginHooks.isPropsValid || isPropsValid)(props, context);
  6379. }
  6380. function isPropsValid(state, context, dateSpanMeta = {}, filterConfig) {
  6381. if (state.eventDrag && !isInteractionPropsValid(state, context, dateSpanMeta, filterConfig)) {
  6382. return false;
  6383. }
  6384. if (state.dateSelection && !isDateSelectionPropsValid(state, context, dateSpanMeta, filterConfig)) {
  6385. return false;
  6386. }
  6387. return true;
  6388. }
  6389. // Moving Event Validation
  6390. // ------------------------------------------------------------------------------------------------------------------------
  6391. function isInteractionPropsValid(state, context, dateSpanMeta, filterConfig) {
  6392. let currentState = context.getCurrentData();
  6393. let interaction = state.eventDrag; // HACK: the eventDrag props is used for ALL interactions
  6394. let subjectEventStore = interaction.mutatedEvents;
  6395. let subjectDefs = subjectEventStore.defs;
  6396. let subjectInstances = subjectEventStore.instances;
  6397. let subjectConfigs = compileEventUis(subjectDefs, interaction.isEvent ?
  6398. state.eventUiBases :
  6399. { '': currentState.selectionConfig });
  6400. if (filterConfig) {
  6401. subjectConfigs = mapHash(subjectConfigs, filterConfig);
  6402. }
  6403. // exclude the subject events. TODO: exclude defs too?
  6404. let otherEventStore = excludeInstances(state.eventStore, interaction.affectedEvents.instances);
  6405. let otherDefs = otherEventStore.defs;
  6406. let otherInstances = otherEventStore.instances;
  6407. let otherConfigs = compileEventUis(otherDefs, state.eventUiBases);
  6408. for (let subjectInstanceId in subjectInstances) {
  6409. let subjectInstance = subjectInstances[subjectInstanceId];
  6410. let subjectRange = subjectInstance.range;
  6411. let subjectConfig = subjectConfigs[subjectInstance.defId];
  6412. let subjectDef = subjectDefs[subjectInstance.defId];
  6413. // constraint
  6414. if (!allConstraintsPass(subjectConfig.constraints, subjectRange, otherEventStore, state.businessHours, context)) {
  6415. return false;
  6416. }
  6417. // overlap
  6418. let { eventOverlap } = context.options;
  6419. let eventOverlapFunc = typeof eventOverlap === 'function' ? eventOverlap : null;
  6420. for (let otherInstanceId in otherInstances) {
  6421. let otherInstance = otherInstances[otherInstanceId];
  6422. // intersect! evaluate
  6423. if (rangesIntersect(subjectRange, otherInstance.range)) {
  6424. let otherOverlap = otherConfigs[otherInstance.defId].overlap;
  6425. // consider the other event's overlap. only do this if the subject event is a "real" event
  6426. if (otherOverlap === false && interaction.isEvent) {
  6427. return false;
  6428. }
  6429. if (subjectConfig.overlap === false) {
  6430. return false;
  6431. }
  6432. if (eventOverlapFunc && !eventOverlapFunc(new EventImpl(context, otherDefs[otherInstance.defId], otherInstance), // still event
  6433. new EventImpl(context, subjectDef, subjectInstance))) {
  6434. return false;
  6435. }
  6436. }
  6437. }
  6438. // allow (a function)
  6439. let calendarEventStore = currentState.eventStore; // need global-to-calendar, not local to component (splittable)state
  6440. for (let subjectAllow of subjectConfig.allows) {
  6441. let subjectDateSpan = Object.assign(Object.assign({}, dateSpanMeta), { range: subjectInstance.range, allDay: subjectDef.allDay });
  6442. let origDef = calendarEventStore.defs[subjectDef.defId];
  6443. let origInstance = calendarEventStore.instances[subjectInstanceId];
  6444. let eventApi;
  6445. if (origDef) { // was previously in the calendar
  6446. eventApi = new EventImpl(context, origDef, origInstance);
  6447. }
  6448. else { // was an external event
  6449. eventApi = new EventImpl(context, subjectDef); // no instance, because had no dates
  6450. }
  6451. if (!subjectAllow(buildDateSpanApiWithContext(subjectDateSpan, context), eventApi)) {
  6452. return false;
  6453. }
  6454. }
  6455. }
  6456. return true;
  6457. }
  6458. // Date Selection Validation
  6459. // ------------------------------------------------------------------------------------------------------------------------
  6460. function isDateSelectionPropsValid(state, context, dateSpanMeta, filterConfig) {
  6461. let relevantEventStore = state.eventStore;
  6462. let relevantDefs = relevantEventStore.defs;
  6463. let relevantInstances = relevantEventStore.instances;
  6464. let selection = state.dateSelection;
  6465. let selectionRange = selection.range;
  6466. let { selectionConfig } = context.getCurrentData();
  6467. if (filterConfig) {
  6468. selectionConfig = filterConfig(selectionConfig);
  6469. }
  6470. // constraint
  6471. if (!allConstraintsPass(selectionConfig.constraints, selectionRange, relevantEventStore, state.businessHours, context)) {
  6472. return false;
  6473. }
  6474. // overlap
  6475. let { selectOverlap } = context.options;
  6476. let selectOverlapFunc = typeof selectOverlap === 'function' ? selectOverlap : null;
  6477. for (let relevantInstanceId in relevantInstances) {
  6478. let relevantInstance = relevantInstances[relevantInstanceId];
  6479. // intersect! evaluate
  6480. if (rangesIntersect(selectionRange, relevantInstance.range)) {
  6481. if (selectionConfig.overlap === false) {
  6482. return false;
  6483. }
  6484. if (selectOverlapFunc && !selectOverlapFunc(new EventImpl(context, relevantDefs[relevantInstance.defId], relevantInstance), null)) {
  6485. return false;
  6486. }
  6487. }
  6488. }
  6489. // allow (a function)
  6490. for (let selectionAllow of selectionConfig.allows) {
  6491. let fullDateSpan = Object.assign(Object.assign({}, dateSpanMeta), selection);
  6492. if (!selectionAllow(buildDateSpanApiWithContext(fullDateSpan, context), null)) {
  6493. return false;
  6494. }
  6495. }
  6496. return true;
  6497. }
  6498. // Constraint Utils
  6499. // ------------------------------------------------------------------------------------------------------------------------
  6500. function allConstraintsPass(constraints, subjectRange, otherEventStore, businessHoursUnexpanded, context) {
  6501. for (let constraint of constraints) {
  6502. if (!anyRangesContainRange(constraintToRanges(constraint, subjectRange, otherEventStore, businessHoursUnexpanded, context), subjectRange)) {
  6503. return false;
  6504. }
  6505. }
  6506. return true;
  6507. }
  6508. function constraintToRanges(constraint, subjectRange, // for expanding a recurring constraint, or expanding business hours
  6509. otherEventStore, // for if constraint is an even group ID
  6510. businessHoursUnexpanded, // for if constraint is 'businessHours'
  6511. context) {
  6512. if (constraint === 'businessHours') {
  6513. return eventStoreToRanges(expandRecurring(businessHoursUnexpanded, subjectRange, context));
  6514. }
  6515. if (typeof constraint === 'string') { // an group ID
  6516. return eventStoreToRanges(filterEventStoreDefs(otherEventStore, (eventDef) => eventDef.groupId === constraint));
  6517. }
  6518. if (typeof constraint === 'object' && constraint) { // non-null object
  6519. return eventStoreToRanges(expandRecurring(constraint, subjectRange, context));
  6520. }
  6521. return []; // if it's false
  6522. }
  6523. // TODO: move to event-store file?
  6524. function eventStoreToRanges(eventStore) {
  6525. let { instances } = eventStore;
  6526. let ranges = [];
  6527. for (let instanceId in instances) {
  6528. ranges.push(instances[instanceId].range);
  6529. }
  6530. return ranges;
  6531. }
  6532. // TODO: move to geom file?
  6533. function anyRangesContainRange(outerRanges, innerRange) {
  6534. for (let outerRange of outerRanges) {
  6535. if (rangeContainsRange(outerRange, innerRange)) {
  6536. return true;
  6537. }
  6538. }
  6539. return false;
  6540. }
  6541. const VISIBLE_HIDDEN_RE = /^(visible|hidden)$/;
  6542. class Scroller extends BaseComponent {
  6543. constructor() {
  6544. super(...arguments);
  6545. this.handleEl = (el) => {
  6546. this.el = el;
  6547. setRef(this.props.elRef, el);
  6548. };
  6549. }
  6550. render() {
  6551. let { props } = this;
  6552. let { liquid, liquidIsAbsolute } = props;
  6553. let isAbsolute = liquid && liquidIsAbsolute;
  6554. let className = ['fc-scroller'];
  6555. if (liquid) {
  6556. if (liquidIsAbsolute) {
  6557. className.push('fc-scroller-liquid-absolute');
  6558. }
  6559. else {
  6560. className.push('fc-scroller-liquid');
  6561. }
  6562. }
  6563. return (createElement("div", { ref: this.handleEl, className: className.join(' '), style: {
  6564. overflowX: props.overflowX,
  6565. overflowY: props.overflowY,
  6566. left: (isAbsolute && -(props.overcomeLeft || 0)) || '',
  6567. right: (isAbsolute && -(props.overcomeRight || 0)) || '',
  6568. bottom: (isAbsolute && -(props.overcomeBottom || 0)) || '',
  6569. marginLeft: (!isAbsolute && -(props.overcomeLeft || 0)) || '',
  6570. marginRight: (!isAbsolute && -(props.overcomeRight || 0)) || '',
  6571. marginBottom: (!isAbsolute && -(props.overcomeBottom || 0)) || '',
  6572. maxHeight: props.maxHeight || '',
  6573. } }, props.children));
  6574. }
  6575. needsXScrolling() {
  6576. if (VISIBLE_HIDDEN_RE.test(this.props.overflowX)) {
  6577. return false;
  6578. }
  6579. // testing scrollWidth>clientWidth is unreliable cross-browser when pixel heights aren't integers.
  6580. // much more reliable to see if children are taller than the scroller, even tho doesn't account for
  6581. // inner-child margins and absolute positioning
  6582. let { el } = this;
  6583. let realClientWidth = this.el.getBoundingClientRect().width - this.getYScrollbarWidth();
  6584. let { children } = el;
  6585. for (let i = 0; i < children.length; i += 1) {
  6586. let childEl = children[i];
  6587. if (childEl.getBoundingClientRect().width > realClientWidth) {
  6588. return true;
  6589. }
  6590. }
  6591. return false;
  6592. }
  6593. needsYScrolling() {
  6594. if (VISIBLE_HIDDEN_RE.test(this.props.overflowY)) {
  6595. return false;
  6596. }
  6597. // testing scrollHeight>clientHeight is unreliable cross-browser when pixel heights aren't integers.
  6598. // much more reliable to see if children are taller than the scroller, even tho doesn't account for
  6599. // inner-child margins and absolute positioning
  6600. let { el } = this;
  6601. let realClientHeight = this.el.getBoundingClientRect().height - this.getXScrollbarWidth();
  6602. let { children } = el;
  6603. for (let i = 0; i < children.length; i += 1) {
  6604. let childEl = children[i];
  6605. if (childEl.getBoundingClientRect().height > realClientHeight) {
  6606. return true;
  6607. }
  6608. }
  6609. return false;
  6610. }
  6611. getXScrollbarWidth() {
  6612. if (VISIBLE_HIDDEN_RE.test(this.props.overflowX)) {
  6613. return 0;
  6614. }
  6615. return this.el.offsetHeight - this.el.clientHeight; // only works because we guarantee no borders. TODO: add to CSS with important?
  6616. }
  6617. getYScrollbarWidth() {
  6618. if (VISIBLE_HIDDEN_RE.test(this.props.overflowY)) {
  6619. return 0;
  6620. }
  6621. return this.el.offsetWidth - this.el.clientWidth; // only works because we guarantee no borders. TODO: add to CSS with important?
  6622. }
  6623. }
  6624. /*
  6625. TODO: somehow infer OtherArgs from masterCallback?
  6626. TODO: infer RefType from masterCallback if provided
  6627. */
  6628. class RefMap {
  6629. constructor(masterCallback) {
  6630. this.masterCallback = masterCallback;
  6631. this.currentMap = {};
  6632. this.depths = {};
  6633. this.callbackMap = {};
  6634. this.handleValue = (val, key) => {
  6635. let { depths, currentMap } = this;
  6636. let removed = false;
  6637. let added = false;
  6638. if (val !== null) {
  6639. // for bug... ACTUALLY: can probably do away with this now that callers don't share numeric indices anymore
  6640. removed = (key in currentMap);
  6641. currentMap[key] = val;
  6642. depths[key] = (depths[key] || 0) + 1;
  6643. added = true;
  6644. }
  6645. else {
  6646. depths[key] -= 1;
  6647. if (!depths[key]) {
  6648. delete currentMap[key];
  6649. delete this.callbackMap[key];
  6650. removed = true;
  6651. }
  6652. }
  6653. if (this.masterCallback) {
  6654. if (removed) {
  6655. this.masterCallback(null, String(key));
  6656. }
  6657. if (added) {
  6658. this.masterCallback(val, String(key));
  6659. }
  6660. }
  6661. };
  6662. }
  6663. createRef(key) {
  6664. let refCallback = this.callbackMap[key];
  6665. if (!refCallback) {
  6666. refCallback = this.callbackMap[key] = (val) => {
  6667. this.handleValue(val, String(key));
  6668. };
  6669. }
  6670. return refCallback;
  6671. }
  6672. // TODO: check callers that don't care about order. should use getAll instead
  6673. // NOTE: this method has become less valuable now that we are encouraged to map order by some other index
  6674. // TODO: provide ONE array-export function, buildArray, which fails on non-numeric indexes. caller can manipulate and "collect"
  6675. collect(startIndex, endIndex, step) {
  6676. return collectFromHash(this.currentMap, startIndex, endIndex, step);
  6677. }
  6678. getAll() {
  6679. return hashValuesToArray(this.currentMap);
  6680. }
  6681. }
  6682. function computeShrinkWidth(chunkEls) {
  6683. let shrinkCells = findElements(chunkEls, '.fc-scrollgrid-shrink');
  6684. let largestWidth = 0;
  6685. for (let shrinkCell of shrinkCells) {
  6686. largestWidth = Math.max(largestWidth, computeSmallestCellWidth(shrinkCell));
  6687. }
  6688. return Math.ceil(largestWidth); // <table> elements work best with integers. round up to ensure contents fits
  6689. }
  6690. function getSectionHasLiquidHeight(props, sectionConfig) {
  6691. return props.liquid && sectionConfig.liquid; // does the section do liquid-height? (need to have whole scrollgrid liquid-height as well)
  6692. }
  6693. function getAllowYScrolling(props, sectionConfig) {
  6694. return sectionConfig.maxHeight != null || // if its possible for the height to max out, we might need scrollbars
  6695. getSectionHasLiquidHeight(props, sectionConfig); // if the section is liquid height, it might condense enough to require scrollbars
  6696. }
  6697. // TODO: ONLY use `arg`. force out internal function to use same API
  6698. function renderChunkContent(sectionConfig, chunkConfig, arg, isHeader) {
  6699. let { expandRows } = arg;
  6700. let content = typeof chunkConfig.content === 'function' ?
  6701. chunkConfig.content(arg) :
  6702. createElement('table', {
  6703. role: 'presentation',
  6704. className: [
  6705. chunkConfig.tableClassName,
  6706. sectionConfig.syncRowHeights ? 'fc-scrollgrid-sync-table' : '',
  6707. ].join(' '),
  6708. style: {
  6709. minWidth: arg.tableMinWidth,
  6710. width: arg.clientWidth,
  6711. height: expandRows ? arg.clientHeight : '', // css `height` on a <table> serves as a min-height
  6712. },
  6713. }, arg.tableColGroupNode, createElement(isHeader ? 'thead' : 'tbody', {
  6714. role: 'presentation',
  6715. }, typeof chunkConfig.rowContent === 'function'
  6716. ? chunkConfig.rowContent(arg)
  6717. : chunkConfig.rowContent));
  6718. return content;
  6719. }
  6720. function isColPropsEqual(cols0, cols1) {
  6721. return isArraysEqual(cols0, cols1, isPropsEqual);
  6722. }
  6723. function renderMicroColGroup(cols, shrinkWidth) {
  6724. let colNodes = [];
  6725. /*
  6726. for ColProps with spans, it would have been great to make a single <col span="">
  6727. HOWEVER, Chrome was getting messing up distributing the width to <td>/<th> elements with colspans.
  6728. SOLUTION: making individual <col> elements makes Chrome behave.
  6729. */
  6730. for (let colProps of cols) {
  6731. let span = colProps.span || 1;
  6732. for (let i = 0; i < span; i += 1) {
  6733. colNodes.push(createElement("col", { style: {
  6734. width: colProps.width === 'shrink' ? sanitizeShrinkWidth(shrinkWidth) : (colProps.width || ''),
  6735. minWidth: colProps.minWidth || '',
  6736. } }));
  6737. }
  6738. }
  6739. return createElement('colgroup', {}, ...colNodes);
  6740. }
  6741. function sanitizeShrinkWidth(shrinkWidth) {
  6742. /* why 4? if we do 0, it will kill any border, which are needed for computeSmallestCellWidth
  6743. 4 accounts for 2 2-pixel borders. TODO: better solution? */
  6744. return shrinkWidth == null ? 4 : shrinkWidth;
  6745. }
  6746. function hasShrinkWidth(cols) {
  6747. for (let col of cols) {
  6748. if (col.width === 'shrink') {
  6749. return true;
  6750. }
  6751. }
  6752. return false;
  6753. }
  6754. function getScrollGridClassNames(liquid, context) {
  6755. let classNames = [
  6756. 'fc-scrollgrid',
  6757. context.theme.getClass('table'),
  6758. ];
  6759. if (liquid) {
  6760. classNames.push('fc-scrollgrid-liquid');
  6761. }
  6762. return classNames;
  6763. }
  6764. function getSectionClassNames(sectionConfig, wholeTableVGrow) {
  6765. let classNames = [
  6766. 'fc-scrollgrid-section',
  6767. `fc-scrollgrid-section-${sectionConfig.type}`,
  6768. sectionConfig.className, // used?
  6769. ];
  6770. if (wholeTableVGrow && sectionConfig.liquid && sectionConfig.maxHeight == null) {
  6771. classNames.push('fc-scrollgrid-section-liquid');
  6772. }
  6773. if (sectionConfig.isSticky) {
  6774. classNames.push('fc-scrollgrid-section-sticky');
  6775. }
  6776. return classNames;
  6777. }
  6778. function renderScrollShim(arg) {
  6779. return (createElement("div", { className: "fc-scrollgrid-sticky-shim", style: {
  6780. width: arg.clientWidth,
  6781. minWidth: arg.tableMinWidth,
  6782. } }));
  6783. }
  6784. function getStickyHeaderDates(options) {
  6785. let { stickyHeaderDates } = options;
  6786. if (stickyHeaderDates == null || stickyHeaderDates === 'auto') {
  6787. stickyHeaderDates = options.height === 'auto' || options.viewHeight === 'auto';
  6788. }
  6789. return stickyHeaderDates;
  6790. }
  6791. function getStickyFooterScrollbar(options) {
  6792. let { stickyFooterScrollbar } = options;
  6793. if (stickyFooterScrollbar == null || stickyFooterScrollbar === 'auto') {
  6794. stickyFooterScrollbar = options.height === 'auto' || options.viewHeight === 'auto';
  6795. }
  6796. return stickyFooterScrollbar;
  6797. }
  6798. class SimpleScrollGrid extends BaseComponent {
  6799. constructor() {
  6800. super(...arguments);
  6801. this.processCols = memoize((a) => a, isColPropsEqual); // so we get same `cols` props every time
  6802. // yucky to memoize VNodes, but much more efficient for consumers
  6803. this.renderMicroColGroup = memoize(renderMicroColGroup);
  6804. this.scrollerRefs = new RefMap();
  6805. this.scrollerElRefs = new RefMap(this._handleScrollerEl.bind(this));
  6806. this.state = {
  6807. shrinkWidth: null,
  6808. forceYScrollbars: false,
  6809. scrollerClientWidths: {},
  6810. scrollerClientHeights: {},
  6811. };
  6812. // TODO: can do a really simple print-view. dont need to join rows
  6813. this.handleSizing = () => {
  6814. this.safeSetState(Object.assign({ shrinkWidth: this.computeShrinkWidth() }, this.computeScrollerDims()));
  6815. };
  6816. }
  6817. render() {
  6818. let { props, state, context } = this;
  6819. let sectionConfigs = props.sections || [];
  6820. let cols = this.processCols(props.cols);
  6821. let microColGroupNode = this.renderMicroColGroup(cols, state.shrinkWidth);
  6822. let classNames = getScrollGridClassNames(props.liquid, context);
  6823. if (props.collapsibleWidth) {
  6824. classNames.push('fc-scrollgrid-collapsible');
  6825. }
  6826. // TODO: make DRY
  6827. let configCnt = sectionConfigs.length;
  6828. let configI = 0;
  6829. let currentConfig;
  6830. let headSectionNodes = [];
  6831. let bodySectionNodes = [];
  6832. let footSectionNodes = [];
  6833. while (configI < configCnt && (currentConfig = sectionConfigs[configI]).type === 'header') {
  6834. headSectionNodes.push(this.renderSection(currentConfig, microColGroupNode, true));
  6835. configI += 1;
  6836. }
  6837. while (configI < configCnt && (currentConfig = sectionConfigs[configI]).type === 'body') {
  6838. bodySectionNodes.push(this.renderSection(currentConfig, microColGroupNode, false));
  6839. configI += 1;
  6840. }
  6841. while (configI < configCnt && (currentConfig = sectionConfigs[configI]).type === 'footer') {
  6842. footSectionNodes.push(this.renderSection(currentConfig, microColGroupNode, true));
  6843. configI += 1;
  6844. }
  6845. // firefox bug: when setting height on table and there is a thead or tfoot,
  6846. // the necessary height:100% on the liquid-height body section forces the *whole* table to be taller. (bug #5524)
  6847. // use getCanVGrowWithinCell as a way to detect table-stupid firefox.
  6848. // if so, use a simpler dom structure, jam everything into a lone tbody.
  6849. let isBuggy = !getCanVGrowWithinCell();
  6850. const roleAttrs = { role: 'rowgroup' };
  6851. return createElement('table', {
  6852. role: 'grid',
  6853. className: classNames.join(' '),
  6854. style: { height: props.height },
  6855. }, Boolean(!isBuggy && headSectionNodes.length) && createElement('thead', roleAttrs, ...headSectionNodes), Boolean(!isBuggy && bodySectionNodes.length) && createElement('tbody', roleAttrs, ...bodySectionNodes), Boolean(!isBuggy && footSectionNodes.length) && createElement('tfoot', roleAttrs, ...footSectionNodes), isBuggy && createElement('tbody', roleAttrs, ...headSectionNodes, ...bodySectionNodes, ...footSectionNodes));
  6856. }
  6857. renderSection(sectionConfig, microColGroupNode, isHeader) {
  6858. if ('outerContent' in sectionConfig) {
  6859. return (createElement(Fragment, { key: sectionConfig.key }, sectionConfig.outerContent));
  6860. }
  6861. return (createElement("tr", { key: sectionConfig.key, role: "presentation", className: getSectionClassNames(sectionConfig, this.props.liquid).join(' ') }, this.renderChunkTd(sectionConfig, microColGroupNode, sectionConfig.chunk, isHeader)));
  6862. }
  6863. renderChunkTd(sectionConfig, microColGroupNode, chunkConfig, isHeader) {
  6864. if ('outerContent' in chunkConfig) {
  6865. return chunkConfig.outerContent;
  6866. }
  6867. let { props } = this;
  6868. let { forceYScrollbars, scrollerClientWidths, scrollerClientHeights } = this.state;
  6869. let needsYScrolling = getAllowYScrolling(props, sectionConfig); // TODO: do lazily. do in section config?
  6870. let isLiquid = getSectionHasLiquidHeight(props, sectionConfig);
  6871. // for `!props.liquid` - is WHOLE scrollgrid natural height?
  6872. // TODO: do same thing in advanced scrollgrid? prolly not b/c always has horizontal scrollbars
  6873. let overflowY = !props.liquid ? 'visible' :
  6874. forceYScrollbars ? 'scroll' :
  6875. !needsYScrolling ? 'hidden' :
  6876. 'auto';
  6877. let sectionKey = sectionConfig.key;
  6878. let content = renderChunkContent(sectionConfig, chunkConfig, {
  6879. tableColGroupNode: microColGroupNode,
  6880. tableMinWidth: '',
  6881. clientWidth: (!props.collapsibleWidth && scrollerClientWidths[sectionKey] !== undefined) ? scrollerClientWidths[sectionKey] : null,
  6882. clientHeight: scrollerClientHeights[sectionKey] !== undefined ? scrollerClientHeights[sectionKey] : null,
  6883. expandRows: sectionConfig.expandRows,
  6884. syncRowHeights: false,
  6885. rowSyncHeights: [],
  6886. reportRowHeightChange: () => { },
  6887. }, isHeader);
  6888. return createElement(isHeader ? 'th' : 'td', {
  6889. ref: chunkConfig.elRef,
  6890. role: 'presentation',
  6891. }, createElement("div", { className: `fc-scroller-harness${isLiquid ? ' fc-scroller-harness-liquid' : ''}` },
  6892. createElement(Scroller, { ref: this.scrollerRefs.createRef(sectionKey), elRef: this.scrollerElRefs.createRef(sectionKey), overflowY: overflowY, overflowX: !props.liquid ? 'visible' : 'hidden' /* natural height? */, maxHeight: sectionConfig.maxHeight, liquid: isLiquid, liquidIsAbsolute // because its within a harness
  6893. : true }, content)));
  6894. }
  6895. _handleScrollerEl(scrollerEl, key) {
  6896. let section = getSectionByKey(this.props.sections, key);
  6897. if (section) {
  6898. setRef(section.chunk.scrollerElRef, scrollerEl);
  6899. }
  6900. }
  6901. componentDidMount() {
  6902. this.handleSizing();
  6903. this.context.addResizeHandler(this.handleSizing);
  6904. }
  6905. componentDidUpdate() {
  6906. // TODO: need better solution when state contains non-sizing things
  6907. this.handleSizing();
  6908. }
  6909. componentWillUnmount() {
  6910. this.context.removeResizeHandler(this.handleSizing);
  6911. }
  6912. computeShrinkWidth() {
  6913. return hasShrinkWidth(this.props.cols)
  6914. ? computeShrinkWidth(this.scrollerElRefs.getAll())
  6915. : 0;
  6916. }
  6917. computeScrollerDims() {
  6918. let scrollbarWidth = getScrollbarWidths();
  6919. let { scrollerRefs, scrollerElRefs } = this;
  6920. let forceYScrollbars = false;
  6921. let scrollerClientWidths = {};
  6922. let scrollerClientHeights = {};
  6923. for (let sectionKey in scrollerRefs.currentMap) {
  6924. let scroller = scrollerRefs.currentMap[sectionKey];
  6925. if (scroller && scroller.needsYScrolling()) {
  6926. forceYScrollbars = true;
  6927. break;
  6928. }
  6929. }
  6930. for (let section of this.props.sections) {
  6931. let sectionKey = section.key;
  6932. let scrollerEl = scrollerElRefs.currentMap[sectionKey];
  6933. if (scrollerEl) {
  6934. let harnessEl = scrollerEl.parentNode; // TODO: weird way to get this. need harness b/c doesn't include table borders
  6935. scrollerClientWidths[sectionKey] = Math.floor(harnessEl.getBoundingClientRect().width - (forceYScrollbars
  6936. ? scrollbarWidth.y // use global because scroller might not have scrollbars yet but will need them in future
  6937. : 0));
  6938. scrollerClientHeights[sectionKey] = Math.floor(harnessEl.getBoundingClientRect().height);
  6939. }
  6940. }
  6941. return { forceYScrollbars, scrollerClientWidths, scrollerClientHeights };
  6942. }
  6943. }
  6944. SimpleScrollGrid.addStateEquality({
  6945. scrollerClientWidths: isPropsEqual,
  6946. scrollerClientHeights: isPropsEqual,
  6947. });
  6948. function getSectionByKey(sections, key) {
  6949. for (let section of sections) {
  6950. if (section.key === key) {
  6951. return section;
  6952. }
  6953. }
  6954. return null;
  6955. }
  6956. class EventContainer extends BaseComponent {
  6957. constructor() {
  6958. super(...arguments);
  6959. this.handleEl = (el) => {
  6960. this.el = el;
  6961. if (el) {
  6962. setElSeg(el, this.props.seg);
  6963. }
  6964. };
  6965. }
  6966. render() {
  6967. const { props, context } = this;
  6968. const { options } = context;
  6969. const { seg } = props;
  6970. const { eventRange } = seg;
  6971. const { ui } = eventRange;
  6972. const renderProps = {
  6973. event: new EventImpl(context, eventRange.def, eventRange.instance),
  6974. view: context.viewApi,
  6975. timeText: props.timeText,
  6976. textColor: ui.textColor,
  6977. backgroundColor: ui.backgroundColor,
  6978. borderColor: ui.borderColor,
  6979. isDraggable: !props.disableDragging && computeSegDraggable(seg, context),
  6980. isStartResizable: !props.disableResizing && computeSegStartResizable(seg, context),
  6981. isEndResizable: !props.disableResizing && computeSegEndResizable(seg),
  6982. isMirror: Boolean(props.isDragging || props.isResizing || props.isDateSelecting),
  6983. isStart: Boolean(seg.isStart),
  6984. isEnd: Boolean(seg.isEnd),
  6985. isPast: Boolean(props.isPast),
  6986. isFuture: Boolean(props.isFuture),
  6987. isToday: Boolean(props.isToday),
  6988. isSelected: Boolean(props.isSelected),
  6989. isDragging: Boolean(props.isDragging),
  6990. isResizing: Boolean(props.isResizing),
  6991. };
  6992. return (createElement(ContentContainer, Object.assign({}, props /* contains children */, { elRef: this.handleEl, elClasses: [
  6993. ...getEventClassNames(renderProps),
  6994. ...seg.eventRange.ui.classNames,
  6995. ...(props.elClasses || []),
  6996. ], renderProps: renderProps, generatorName: "eventContent", customGenerator: options.eventContent, defaultGenerator: props.defaultGenerator, classNameGenerator: options.eventClassNames, didMount: options.eventDidMount, willUnmount: options.eventWillUnmount })));
  6997. }
  6998. componentDidUpdate(prevProps) {
  6999. if (this.el && this.props.seg !== prevProps.seg) {
  7000. setElSeg(this.el, this.props.seg);
  7001. }
  7002. }
  7003. }
  7004. // should not be a purecomponent
  7005. class StandardEvent extends BaseComponent {
  7006. render() {
  7007. let { props, context } = this;
  7008. let { options } = context;
  7009. let { seg } = props;
  7010. let { ui } = seg.eventRange;
  7011. let timeFormat = options.eventTimeFormat || props.defaultTimeFormat;
  7012. let timeText = buildSegTimeText(seg, timeFormat, context, props.defaultDisplayEventTime, props.defaultDisplayEventEnd);
  7013. return (createElement(EventContainer, Object.assign({}, props /* includes elRef */, { elTag: "a", elStyle: {
  7014. borderColor: ui.borderColor,
  7015. backgroundColor: ui.backgroundColor,
  7016. }, elAttrs: getSegAnchorAttrs(seg, context), defaultGenerator: renderInnerContent$1, timeText: timeText }), (InnerContent, eventContentArg) => (createElement(Fragment, null,
  7017. createElement(InnerContent, { elTag: "div", elClasses: ['fc-event-main'], elStyle: { color: eventContentArg.textColor } }),
  7018. Boolean(eventContentArg.isStartResizable) && (createElement("div", { className: "fc-event-resizer fc-event-resizer-start" })),
  7019. Boolean(eventContentArg.isEndResizable) && (createElement("div", { className: "fc-event-resizer fc-event-resizer-end" }))))));
  7020. }
  7021. }
  7022. function renderInnerContent$1(innerProps) {
  7023. return (createElement("div", { className: "fc-event-main-frame" },
  7024. innerProps.timeText && (createElement("div", { className: "fc-event-time" }, innerProps.timeText)),
  7025. createElement("div", { className: "fc-event-title-container" },
  7026. createElement("div", { className: "fc-event-title fc-sticky" }, innerProps.event.title || createElement(Fragment, null, "\u00A0")))));
  7027. }
  7028. const NowIndicatorContainer = (props) => (createElement(ViewContextType.Consumer, null, (context) => {
  7029. let { options } = context;
  7030. let renderProps = {
  7031. isAxis: props.isAxis,
  7032. date: context.dateEnv.toDate(props.date),
  7033. view: context.viewApi,
  7034. };
  7035. return (createElement(ContentContainer, Object.assign({}, props /* includes children */, { elTag: props.elTag || 'div', renderProps: renderProps, generatorName: "nowIndicatorContent", customGenerator: options.nowIndicatorContent, classNameGenerator: options.nowIndicatorClassNames, didMount: options.nowIndicatorDidMount, willUnmount: options.nowIndicatorWillUnmount })));
  7036. }));
  7037. const DAY_NUM_FORMAT = createFormatter({ day: 'numeric' });
  7038. class DayCellContainer extends BaseComponent {
  7039. constructor() {
  7040. super(...arguments);
  7041. this.refineRenderProps = memoizeObjArg(refineRenderProps);
  7042. }
  7043. render() {
  7044. let { props, context } = this;
  7045. let { options } = context;
  7046. let renderProps = this.refineRenderProps({
  7047. date: props.date,
  7048. dateProfile: props.dateProfile,
  7049. todayRange: props.todayRange,
  7050. isMonthStart: props.isMonthStart || false,
  7051. showDayNumber: props.showDayNumber,
  7052. extraRenderProps: props.extraRenderProps,
  7053. viewApi: context.viewApi,
  7054. dateEnv: context.dateEnv,
  7055. monthStartFormat: options.monthStartFormat,
  7056. });
  7057. return (createElement(ContentContainer, Object.assign({}, props /* includes children */, { elClasses: [
  7058. ...getDayClassNames(renderProps, context.theme),
  7059. ...(props.elClasses || []),
  7060. ], elAttrs: Object.assign(Object.assign({}, props.elAttrs), (renderProps.isDisabled ? {} : { 'data-date': formatDayString(props.date) })), renderProps: renderProps, generatorName: "dayCellContent", customGenerator: options.dayCellContent, defaultGenerator: props.defaultGenerator, classNameGenerator:
  7061. // don't use custom classNames if disabled
  7062. renderProps.isDisabled ? undefined : options.dayCellClassNames, didMount: options.dayCellDidMount, willUnmount: options.dayCellWillUnmount })));
  7063. }
  7064. }
  7065. function hasCustomDayCellContent(options) {
  7066. return Boolean(options.dayCellContent || hasCustomRenderingHandler('dayCellContent', options));
  7067. }
  7068. function refineRenderProps(raw) {
  7069. let { date, dateEnv, dateProfile, isMonthStart } = raw;
  7070. let dayMeta = getDateMeta(date, raw.todayRange, null, dateProfile);
  7071. let dayNumberText = raw.showDayNumber ? (dateEnv.format(date, isMonthStart ? raw.monthStartFormat : DAY_NUM_FORMAT)) : '';
  7072. return Object.assign(Object.assign(Object.assign({ date: dateEnv.toDate(date), view: raw.viewApi }, dayMeta), { isMonthStart,
  7073. dayNumberText }), raw.extraRenderProps);
  7074. }
  7075. class BgEvent extends BaseComponent {
  7076. render() {
  7077. let { props } = this;
  7078. let { seg } = props;
  7079. return (createElement(EventContainer, { elTag: "div", elClasses: ['fc-bg-event'], elStyle: { backgroundColor: seg.eventRange.ui.backgroundColor }, defaultGenerator: renderInnerContent, seg: seg, timeText: "", isDragging: false, isResizing: false, isDateSelecting: false, isSelected: false, isPast: props.isPast, isFuture: props.isFuture, isToday: props.isToday, disableDragging: true, disableResizing: true }));
  7080. }
  7081. }
  7082. function renderInnerContent(props) {
  7083. let { title } = props.event;
  7084. return title && (createElement("div", { className: "fc-event-title" }, props.event.title));
  7085. }
  7086. function renderFill(fillType) {
  7087. return (createElement("div", { className: `fc-${fillType}` }));
  7088. }
  7089. const WeekNumberContainer = (props) => (createElement(ViewContextType.Consumer, null, (context) => {
  7090. let { dateEnv, options } = context;
  7091. let { date } = props;
  7092. let format = options.weekNumberFormat || props.defaultFormat;
  7093. let num = dateEnv.computeWeekNumber(date); // TODO: somehow use for formatting as well?
  7094. let text = dateEnv.format(date, format);
  7095. let renderProps = { num, text, date };
  7096. return (createElement(ContentContainer // why isn't WeekNumberContentArg being auto-detected?
  7097. , Object.assign({}, props /* includes children */, { renderProps: renderProps, generatorName: "weekNumberContent", customGenerator: options.weekNumberContent, defaultGenerator: renderInner, classNameGenerator: options.weekNumberClassNames, didMount: options.weekNumberDidMount, willUnmount: options.weekNumberWillUnmount })));
  7098. }));
  7099. function renderInner(innerProps) {
  7100. return innerProps.text;
  7101. }
  7102. const PADDING_FROM_VIEWPORT = 10;
  7103. class Popover extends BaseComponent {
  7104. constructor() {
  7105. super(...arguments);
  7106. this.state = {
  7107. titleId: getUniqueDomId(),
  7108. };
  7109. this.handleRootEl = (el) => {
  7110. this.rootEl = el;
  7111. if (this.props.elRef) {
  7112. setRef(this.props.elRef, el);
  7113. }
  7114. };
  7115. // Triggered when the user clicks *anywhere* in the document, for the autoHide feature
  7116. this.handleDocumentMouseDown = (ev) => {
  7117. // only hide the popover if the click happened outside the popover
  7118. const target = getEventTargetViaRoot(ev);
  7119. if (!this.rootEl.contains(target)) {
  7120. this.handleCloseClick();
  7121. }
  7122. };
  7123. this.handleDocumentKeyDown = (ev) => {
  7124. if (ev.key === 'Escape') {
  7125. this.handleCloseClick();
  7126. }
  7127. };
  7128. this.handleCloseClick = () => {
  7129. let { onClose } = this.props;
  7130. if (onClose) {
  7131. onClose();
  7132. }
  7133. };
  7134. }
  7135. render() {
  7136. let { theme, options } = this.context;
  7137. let { props, state } = this;
  7138. let classNames = [
  7139. 'fc-popover',
  7140. theme.getClass('popover'),
  7141. ].concat(props.extraClassNames || []);
  7142. return createPortal(createElement("div", Object.assign({}, props.extraAttrs, { id: props.id, className: classNames.join(' '), "aria-labelledby": state.titleId, ref: this.handleRootEl }),
  7143. createElement("div", { className: 'fc-popover-header ' + theme.getClass('popoverHeader') },
  7144. createElement("span", { className: "fc-popover-title", id: state.titleId }, props.title),
  7145. createElement("span", { className: 'fc-popover-close ' + theme.getIconClass('close'), title: options.closeHint, onClick: this.handleCloseClick })),
  7146. createElement("div", { className: 'fc-popover-body ' + theme.getClass('popoverContent') }, props.children)), props.parentEl);
  7147. }
  7148. componentDidMount() {
  7149. document.addEventListener('mousedown', this.handleDocumentMouseDown);
  7150. document.addEventListener('keydown', this.handleDocumentKeyDown);
  7151. this.updateSize();
  7152. }
  7153. componentWillUnmount() {
  7154. document.removeEventListener('mousedown', this.handleDocumentMouseDown);
  7155. document.removeEventListener('keydown', this.handleDocumentKeyDown);
  7156. }
  7157. updateSize() {
  7158. let { isRtl } = this.context;
  7159. let { alignmentEl, alignGridTop } = this.props;
  7160. let { rootEl } = this;
  7161. let alignmentRect = computeClippedClientRect(alignmentEl);
  7162. if (alignmentRect) {
  7163. let popoverDims = rootEl.getBoundingClientRect();
  7164. // position relative to viewport
  7165. let popoverTop = alignGridTop
  7166. ? elementClosest(alignmentEl, '.fc-scrollgrid').getBoundingClientRect().top
  7167. : alignmentRect.top;
  7168. let popoverLeft = isRtl ? alignmentRect.right - popoverDims.width : alignmentRect.left;
  7169. // constrain
  7170. popoverTop = Math.max(popoverTop, PADDING_FROM_VIEWPORT);
  7171. popoverLeft = Math.min(popoverLeft, document.documentElement.clientWidth - PADDING_FROM_VIEWPORT - popoverDims.width);
  7172. popoverLeft = Math.max(popoverLeft, PADDING_FROM_VIEWPORT);
  7173. let origin = rootEl.offsetParent.getBoundingClientRect();
  7174. applyStyle(rootEl, {
  7175. top: popoverTop - origin.top,
  7176. left: popoverLeft - origin.left,
  7177. });
  7178. }
  7179. }
  7180. }
  7181. class MorePopover extends DateComponent {
  7182. constructor() {
  7183. super(...arguments);
  7184. this.handleRootEl = (rootEl) => {
  7185. this.rootEl = rootEl;
  7186. if (rootEl) {
  7187. this.context.registerInteractiveComponent(this, {
  7188. el: rootEl,
  7189. useEventCenter: false,
  7190. });
  7191. }
  7192. else {
  7193. this.context.unregisterInteractiveComponent(this);
  7194. }
  7195. };
  7196. }
  7197. render() {
  7198. let { options, dateEnv } = this.context;
  7199. let { props } = this;
  7200. let { startDate, todayRange, dateProfile } = props;
  7201. let title = dateEnv.format(startDate, options.dayPopoverFormat);
  7202. return (createElement(DayCellContainer, { elRef: this.handleRootEl, date: startDate, dateProfile: dateProfile, todayRange: todayRange }, (InnerContent, renderProps, elAttrs) => (createElement(Popover, { elRef: elAttrs.ref, id: props.id, title: title, extraClassNames: ['fc-more-popover'].concat(elAttrs.className || []), extraAttrs: elAttrs /* TODO: make these time-based when not whole-day? */, parentEl: props.parentEl, alignmentEl: props.alignmentEl, alignGridTop: props.alignGridTop, onClose: props.onClose },
  7203. hasCustomDayCellContent(options) && (createElement(InnerContent, { elTag: "div", elClasses: ['fc-more-popover-misc'] })),
  7204. props.children))));
  7205. }
  7206. queryHit(positionLeft, positionTop, elWidth, elHeight) {
  7207. let { rootEl, props } = this;
  7208. if (positionLeft >= 0 && positionLeft < elWidth &&
  7209. positionTop >= 0 && positionTop < elHeight) {
  7210. return {
  7211. dateProfile: props.dateProfile,
  7212. dateSpan: Object.assign({ allDay: !props.forceTimed, range: {
  7213. start: props.startDate,
  7214. end: props.endDate,
  7215. } }, props.extraDateSpan),
  7216. dayEl: rootEl,
  7217. rect: {
  7218. left: 0,
  7219. top: 0,
  7220. right: elWidth,
  7221. bottom: elHeight,
  7222. },
  7223. layer: 1, // important when comparing with hits from other components
  7224. };
  7225. }
  7226. return null;
  7227. }
  7228. }
  7229. class MoreLinkContainer extends BaseComponent {
  7230. constructor() {
  7231. super(...arguments);
  7232. this.state = {
  7233. isPopoverOpen: false,
  7234. popoverId: getUniqueDomId(),
  7235. };
  7236. this.handleLinkEl = (linkEl) => {
  7237. this.linkEl = linkEl;
  7238. if (this.props.elRef) {
  7239. setRef(this.props.elRef, linkEl);
  7240. }
  7241. };
  7242. this.handleClick = (ev) => {
  7243. let { props, context } = this;
  7244. let { moreLinkClick } = context.options;
  7245. let date = computeRange(props).start;
  7246. function buildPublicSeg(seg) {
  7247. let { def, instance, range } = seg.eventRange;
  7248. return {
  7249. event: new EventImpl(context, def, instance),
  7250. start: context.dateEnv.toDate(range.start),
  7251. end: context.dateEnv.toDate(range.end),
  7252. isStart: seg.isStart,
  7253. isEnd: seg.isEnd,
  7254. };
  7255. }
  7256. if (typeof moreLinkClick === 'function') {
  7257. moreLinkClick = moreLinkClick({
  7258. date,
  7259. allDay: Boolean(props.allDayDate),
  7260. allSegs: props.allSegs.map(buildPublicSeg),
  7261. hiddenSegs: props.hiddenSegs.map(buildPublicSeg),
  7262. jsEvent: ev,
  7263. view: context.viewApi,
  7264. });
  7265. }
  7266. if (!moreLinkClick || moreLinkClick === 'popover') {
  7267. this.setState({ isPopoverOpen: true });
  7268. }
  7269. else if (typeof moreLinkClick === 'string') { // a view name
  7270. context.calendarApi.zoomTo(date, moreLinkClick);
  7271. }
  7272. };
  7273. this.handlePopoverClose = () => {
  7274. this.setState({ isPopoverOpen: false });
  7275. };
  7276. }
  7277. render() {
  7278. let { props, state } = this;
  7279. return (createElement(ViewContextType.Consumer, null, (context) => {
  7280. let { viewApi, options, calendarApi } = context;
  7281. let { moreLinkText } = options;
  7282. let { moreCnt } = props;
  7283. let range = computeRange(props);
  7284. let text = typeof moreLinkText === 'function' // TODO: eventually use formatWithOrdinals
  7285. ? moreLinkText.call(calendarApi, moreCnt)
  7286. : `+${moreCnt} ${moreLinkText}`;
  7287. let hint = formatWithOrdinals(options.moreLinkHint, [moreCnt], text);
  7288. let renderProps = {
  7289. num: moreCnt,
  7290. shortText: `+${moreCnt}`,
  7291. text,
  7292. view: viewApi,
  7293. };
  7294. return (createElement(Fragment, null,
  7295. Boolean(props.moreCnt) && (createElement(ContentContainer, { elTag: props.elTag || 'a', elRef: this.handleLinkEl, elClasses: [
  7296. ...(props.elClasses || []),
  7297. 'fc-more-link',
  7298. ], elStyle: props.elStyle, elAttrs: Object.assign(Object.assign(Object.assign({}, props.elAttrs), createAriaClickAttrs(this.handleClick)), { title: hint, 'aria-expanded': state.isPopoverOpen, 'aria-controls': state.isPopoverOpen ? state.popoverId : '' }), renderProps: renderProps, generatorName: "moreLinkContent", customGenerator: options.moreLinkContent, defaultGenerator: props.defaultGenerator || renderMoreLinkInner, classNameGenerator: options.moreLinkClassNames, didMount: options.moreLinkDidMount, willUnmount: options.moreLinkWillUnmount }, props.children)),
  7299. state.isPopoverOpen && (createElement(MorePopover, { id: state.popoverId, startDate: range.start, endDate: range.end, dateProfile: props.dateProfile, todayRange: props.todayRange, extraDateSpan: props.extraDateSpan, parentEl: this.parentEl, alignmentEl: props.alignmentElRef ?
  7300. props.alignmentElRef.current :
  7301. this.linkEl, alignGridTop: props.alignGridTop, forceTimed: props.forceTimed, onClose: this.handlePopoverClose }, props.popoverContent()))));
  7302. }));
  7303. }
  7304. componentDidMount() {
  7305. this.updateParentEl();
  7306. }
  7307. componentDidUpdate() {
  7308. this.updateParentEl();
  7309. }
  7310. updateParentEl() {
  7311. if (this.linkEl) {
  7312. this.parentEl = elementClosest(this.linkEl, '.fc-view-harness');
  7313. }
  7314. }
  7315. }
  7316. function renderMoreLinkInner(props) {
  7317. return props.text;
  7318. }
  7319. function computeRange(props) {
  7320. if (props.allDayDate) {
  7321. return {
  7322. start: props.allDayDate,
  7323. end: addDays(props.allDayDate, 1),
  7324. };
  7325. }
  7326. let { hiddenSegs } = props;
  7327. return {
  7328. start: computeEarliestSegStart(hiddenSegs),
  7329. end: computeLatestSegEnd(hiddenSegs),
  7330. };
  7331. }
  7332. function computeEarliestSegStart(segs) {
  7333. return segs.reduce(pickEarliestStart).eventRange.range.start;
  7334. }
  7335. function pickEarliestStart(seg0, seg1) {
  7336. return seg0.eventRange.range.start < seg1.eventRange.range.start ? seg0 : seg1;
  7337. }
  7338. function computeLatestSegEnd(segs) {
  7339. return segs.reduce(pickLatestEnd).eventRange.range.end;
  7340. }
  7341. function pickLatestEnd(seg0, seg1) {
  7342. return seg0.eventRange.range.end > seg1.eventRange.range.end ? seg0 : seg1;
  7343. }
  7344. class Store {
  7345. constructor() {
  7346. this.handlers = [];
  7347. }
  7348. set(value) {
  7349. this.currentValue = value;
  7350. for (let handler of this.handlers) {
  7351. handler(value);
  7352. }
  7353. }
  7354. subscribe(handler) {
  7355. this.handlers.push(handler);
  7356. if (this.currentValue !== undefined) {
  7357. handler(this.currentValue);
  7358. }
  7359. }
  7360. }
  7361. /*
  7362. Subscribers will get a LIST of CustomRenderings
  7363. */
  7364. class CustomRenderingStore extends Store {
  7365. constructor() {
  7366. super(...arguments);
  7367. this.map = new Map();
  7368. }
  7369. // for consistent order
  7370. handle(customRendering) {
  7371. const { map } = this;
  7372. let updated = false;
  7373. if (customRendering.isActive) {
  7374. map.set(customRendering.id, customRendering);
  7375. updated = true;
  7376. }
  7377. else if (map.has(customRendering.id)) {
  7378. map.delete(customRendering.id);
  7379. updated = true;
  7380. }
  7381. if (updated) {
  7382. this.set(map);
  7383. }
  7384. }
  7385. }
  7386. export { elementClosest as $, memoizeObjArg as A, BaseComponent as B, ContentContainer as C, DelayedRunner as D, isPropsEqual as E, Emitter as F, getInitialDate as G, rangeContainsMarker as H, createEmptyEventStore as I, reduceCurrentDate as J, reduceEventStore as K, rezoneEventStoreDates as L, mergeRawOptions as M, BASE_OPTION_REFINERS as N, CALENDAR_LISTENER_REFINERS as O, CALENDAR_OPTION_REFINERS as P, COMPLEX_OPTION_COMPARATORS as Q, VIEW_OPTION_REFINERS as R, DateEnv as S, Theme as T, DateProfileGenerator as U, ViewContextType as V, createEventUi as W, parseBusinessHours as X, setRef as Y, Interaction as Z, getElSeg as _, mapHash as a, getSlotClassNames as a$, EventImpl as a0, listenBySelector as a1, listenToHoverBySelector as a2, PureComponent as a3, buildViewContext as a4, getUniqueDomId as a5, parseInteractionSettings as a6, interactionSettingsStore as a7, getNow as a8, CalendarImpl as a9, diffDates as aA, removeExact as aB, memoizeArraylike as aC, memoizeHashlike as aD, intersectRects as aE, pointInsideRect as aF, constrainPoint as aG, getRectCenter as aH, diffPoints as aI, translateRect as aJ, compareObjs as aK, collectFromHash as aL, findElements as aM, findDirectChildren as aN, removeElement as aO, applyStyle as aP, elementMatches as aQ, getEventTargetViaRoot as aR, parseClassNames as aS, getCanVGrowWithinCell as aT, mergeEventStores as aU, getRelevantEvents as aV, eventTupleToStore as aW, combineEventUis as aX, Splitter as aY, getDayClassNames as aZ, getDateMeta as a_, flushSync as aa, CalendarRoot as ab, RenderId as ac, ensureElHasStyles as ad, applyStyleProp as ae, sliceEventStore as af, JsonRequestError as ag, createContext as ah, refineProps as ai, createEventInstance as aj, parseEventDef as ak, refineEventDef as al, padStart as am, isInt as an, parseFieldSpecs as ao, compareByFieldSpecs as ap, flexibleCompare as aq, preventSelection as ar, allowSelection as as, preventContextMenu as at, allowContextMenu as au, compareNumbers as av, enableCursor as aw, disableCursor as ax, computeVisibleDayRange as ay, isMultiDayRange as az, buildViewClassNames as b, SimpleScrollGrid as b$, buildNavLinkAttrs as b0, preventDefault as b1, whenTransitionDone as b2, computeInnerRect as b3, computeEdges as b4, getClippingParents as b5, computeRect as b6, rangesEqual as b7, rangesIntersect as b8, rangeContainsRange as b9, SegHierarchy as bA, buildEntryKey as bB, getEntrySpanEnd as bC, binarySearch as bD, groupIntersectingEntries as bE, intersectSpans as bF, interactionSettingsToStore as bG, ElementDragging as bH, config as bI, parseDragMeta as bJ, DayHeader as bK, computeFallbackHeaderFormat as bL, TableDateCell as bM, TableDowCell as bN, DaySeriesModel as bO, hasBgRendering as bP, buildSegTimeText as bQ, sortEventSegs as bR, getSegMeta as bS, buildEventRangeKey as bT, getSegAnchorAttrs as bU, DayTableModel as bV, Slicer as bW, applyMutationToEventStore as bX, isPropsValid as bY, isInteractionValid as bZ, isDateSelectionValid as b_, PositionCache as ba, ScrollController as bb, ElementScrollController as bc, WindowScrollController as bd, DateComponent as be, isDateSpansEqual as bf, addMs as bg, addWeeks as bh, diffWeeks as bi, diffWholeWeeks as bj, diffDayAndTime as bk, diffDays as bl, isValidDate as bm, asCleanDays as bn, multiplyDuration as bo, addDurations as bp, asRoughMinutes as bq, asRoughSeconds as br, asRoughMs as bs, wholeDivideDurations as bt, formatIsoTimeString as bu, formatDayString as bv, buildIsoString as bw, formatIsoMonthStr as bx, NamedTimeZoneImpl as by, parse as bz, greatestDurationDenominator as c, hasShrinkWidth as c0, renderMicroColGroup as c1, getScrollGridClassNames as c2, getSectionClassNames as c3, getSectionHasLiquidHeight as c4, getAllowYScrolling as c5, renderChunkContent as c6, computeShrinkWidth as c7, sanitizeShrinkWidth as c8, isColPropsEqual as c9, renderScrollShim as ca, getStickyFooterScrollbar as cb, getStickyHeaderDates as cc, Scroller as cd, getScrollbarWidths as ce, RefMap as cf, getIsRtlScrollbarOnLeft as cg, NowTimer as ch, ScrollResponder as ci, StandardEvent as cj, NowIndicatorContainer as ck, DayCellContainer as cl, hasCustomDayCellContent as cm, EventContainer as cn, renderFill as co, BgEvent as cp, WeekNumberContainer as cq, MoreLinkContainer as cr, computeEarliestSegStart as cs, ViewContainer as ct, triggerDateSelect as cu, getDefaultEventEnd as cv, injectStyles as cw, buildElAttrs as cx, CustomRenderingStore as cy, createDuration as d, BASE_OPTION_DEFAULTS as e, arrayToHash as f, guid as g, filterHash as h, isArraysEqual as i, buildEventSourceRefiners as j, formatWithOrdinals as k, buildRangeApiWithTimeZone as l, mergeProps as m, identity as n, intersectRanges as o, parseEventSource as p, startOfDay as q, requestJson as r, subtractDurations as s, addDays as t, unpromisify as u, hashValuesToArray as v, buildEventApis as w, createFormatter as x, diffWholeDays as y, memoize as z };