Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

main.js 685KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705
  1. /*!
  2. FullCalendar v5.8.0
  3. Docs & License: https://fullcalendar.io/
  4. (c) 2021 Adam Shaw
  5. */
  6. var FullCalendar = (function (exports) {
  7. 'use strict';
  8. /*! *****************************************************************************
  9. Copyright (c) Microsoft Corporation.
  10. Permission to use, copy, modify, and/or distribute this software for any
  11. purpose with or without fee is hereby granted.
  12. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  13. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  14. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  15. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  16. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  17. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  18. PERFORMANCE OF THIS SOFTWARE.
  19. ***************************************************************************** */
  20. /* global Reflect, Promise */
  21. var extendStatics = function(d, b) {
  22. extendStatics = Object.setPrototypeOf ||
  23. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  24. function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  25. return extendStatics(d, b);
  26. };
  27. function __extends(d, b) {
  28. if (typeof b !== "function" && b !== null)
  29. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  30. extendStatics(d, b);
  31. function __() { this.constructor = d; }
  32. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  33. }
  34. var __assign = function() {
  35. __assign = Object.assign || function __assign(t) {
  36. for (var s, i = 1, n = arguments.length; i < n; i++) {
  37. s = arguments[i];
  38. for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
  39. }
  40. return t;
  41. };
  42. return __assign.apply(this, arguments);
  43. };
  44. function __spreadArray(to, from) {
  45. for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
  46. to[j] = from[i];
  47. return to;
  48. }
  49. var n,u,i$1,t,o,r$1={},f$1=[],e$1=/acit|ex(?:s|g|n|p|$)|rph|grid|ows|mnc|ntw|ine[ch]|zoo|^ord|itera/i;function c$1(n,l){for(var u in l)n[u]=l[u];return n}function s(n){var l=n.parentNode;l&&l.removeChild(n);}function a$1(n,l,u){var i,t,o,r=arguments,f={};for(o in l)"key"==o?i=l[o]:"ref"==o?t=l[o]:f[o]=l[o];if(arguments.length>3)for(u=[u],o=3;o<arguments.length;o++)u.push(r[o]);if(null!=u&&(f.children=u),"function"==typeof n&&null!=n.defaultProps)for(o in n.defaultProps)void 0===f[o]&&(f[o]=n.defaultProps[o]);return v$1(n,f,i,t,null)}function v$1(l,u,i,t,o){var r={type:l,props:u,key:i,ref:t,__k:null,__:null,__b:0,__e:null,__d:void 0,__c:null,__h:null,constructor:void 0,__v:null==o?++n.__v:o};return null!=n.vnode&&n.vnode(r),r}function h(){return {current:null}}function y(n){return n.children}function p(n,l){this.props=n,this.context=l;}function d(n,l){if(null==l)return n.__?d(n.__,n.__.__k.indexOf(n)+1):null;for(var u;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e)return u.__e;return "function"==typeof n.type?d(n):null}function _(n){var l,u;if(null!=(n=n.__)&&null!=n.__c){for(n.__e=n.__c.base=null,l=0;l<n.__k.length;l++)if(null!=(u=n.__k[l])&&null!=u.__e){n.__e=n.__c.base=u.__e;break}return _(n)}}function k(l){(!l.__d&&(l.__d=!0)&&u.push(l)&&!b$1.__r++||t!==n.debounceRendering)&&((t=n.debounceRendering)||i$1)(b$1);}function b$1(){for(var n;b$1.__r=u.length;)n=u.sort(function(n,l){return n.__v.__b-l.__v.__b}),u=[],n.some(function(n){var l,u,i,t,o,r;n.__d&&(o=(t=(l=n).__v).__e,(r=l.__P)&&(u=[],(i=c$1({},t)).__v=t.__v+1,I$1(r,t,i,l.__n,void 0!==r.ownerSVGElement,null!=t.__h?[o]:null,u,null==o?d(t):o,t.__h),T$1(u,t),t.__e!=o&&_(t)));});}function m(n,l,u,i,t,o,e,c,s,a){var h,p,_,k,b,m,w,A=i&&i.__k||f$1,P=A.length;for(u.__k=[],h=0;h<l.length;h++)if(null!=(k=u.__k[h]=null==(k=l[h])||"boolean"==typeof k?null:"string"==typeof k||"number"==typeof k||"bigint"==typeof k?v$1(null,k,null,null,k):Array.isArray(k)?v$1(y,{children:k},null,null,null):k.__b>0?v$1(k.type,k.props,k.key,null,k.__v):k)){if(k.__=u,k.__b=u.__b+1,null===(_=A[h])||_&&k.key==_.key&&k.type===_.type)A[h]=void 0;else for(p=0;p<P;p++){if((_=A[p])&&k.key==_.key&&k.type===_.type){A[p]=void 0;break}_=null;}I$1(n,k,_=_||r$1,t,o,e,c,s,a),b=k.__e,(p=k.ref)&&_.ref!=p&&(w||(w=[]),_.ref&&w.push(_.ref,null,k),w.push(p,k.__c||b,k)),null!=b?(null==m&&(m=b),"function"==typeof k.type&&null!=k.__k&&k.__k===_.__k?k.__d=s=g$1(k,s,n):s=x$1(n,k,_,A,b,s),a||"option"!==u.type?"function"==typeof u.type&&(u.__d=s):n.value=""):s&&_.__e==s&&s.parentNode!=n&&(s=d(_));}for(u.__e=m,h=P;h--;)null!=A[h]&&("function"==typeof u.type&&null!=A[h].__e&&A[h].__e==u.__d&&(u.__d=d(i,h+1)),L$1(A[h],A[h]));if(w)for(h=0;h<w.length;h++)z(w[h],w[++h],w[++h]);}function g$1(n,l,u){var i,t;for(i=0;i<n.__k.length;i++)(t=n.__k[i])&&(t.__=n,l="function"==typeof t.type?g$1(t,l,u):x$1(u,t,t,n.__k,t.__e,l));return l}function w$1(n,l){return l=l||[],null==n||"boolean"==typeof n||(Array.isArray(n)?n.some(function(n){w$1(n,l);}):l.push(n)),l}function x$1(n,l,u,i,t,o){var r,f,e;if(void 0!==l.__d)r=l.__d,l.__d=void 0;else if(null==u||t!=o||null==t.parentNode)n:if(null==o||o.parentNode!==n)n.appendChild(t),r=null;else {for(f=o,e=0;(f=f.nextSibling)&&e<i.length;e+=2)if(f==t)break n;n.insertBefore(t,o),r=o;}return void 0!==r?r:t.nextSibling}function A$1(n,l,u,i,t){var o;for(o in u)"children"===o||"key"===o||o in l||C$1(n,o,null,u[o],i);for(o in l)t&&"function"!=typeof l[o]||"children"===o||"key"===o||"value"===o||"checked"===o||u[o]===l[o]||C$1(n,o,l[o],u[o],i);}function P$1(n,l,u){"-"===l[0]?n.setProperty(l,u):n[l]=null==u?"":"number"!=typeof u||e$1.test(l)?u:u+"px";}function C$1(n,l,u,i,t){var o;n:if("style"===l)if("string"==typeof u)n.style.cssText=u;else {if("string"==typeof i&&(n.style.cssText=i=""),i)for(l in i)u&&l in u||P$1(n.style,l,"");if(u)for(l in u)i&&u[l]===i[l]||P$1(n.style,l,u[l]);}else if("o"===l[0]&&"n"===l[1])o=l!==(l=l.replace(/Capture$/,"")),l=l.toLowerCase()in n?l.toLowerCase().slice(2):l.slice(2),n.l||(n.l={}),n.l[l+o]=u,u?i||n.addEventListener(l,o?H$1:$$1,o):n.removeEventListener(l,o?H$1:$$1,o);else if("dangerouslySetInnerHTML"!==l){if(t)l=l.replace(/xlink[H:h]/,"h").replace(/sName$/,"s");else if("href"!==l&&"list"!==l&&"form"!==l&&"tabIndex"!==l&&"download"!==l&&l in n)try{n[l]=null==u?"":u;break n}catch(n){}"function"==typeof u||(null!=u&&(!1!==u||"a"===l[0]&&"r"===l[1])?n.setAttribute(l,u):n.removeAttribute(l));}}function $$1(l){this.l[l.type+!1](n.event?n.event(l):l);}function H$1(l){this.l[l.type+!0](n.event?n.event(l):l);}function I$1(l,u,i,t,o,r,f,e,s){var a,v,h,d,_,k,b,g,w,x,A,P=u.type;if(void 0!==u.constructor)return null;null!=i.__h&&(s=i.__h,e=u.__e=i.__e,u.__h=null,r=[e]),(a=n.__b)&&a(u);try{n:if("function"==typeof P){if(g=u.props,w=(a=P.contextType)&&t[a.__c],x=a?w?w.props.value:a.__:t,i.__c?b=(v=u.__c=i.__c).__=v.__E:("prototype"in P&&P.prototype.render?u.__c=v=new P(g,x):(u.__c=v=new p(g,x),v.constructor=P,v.render=M$1),w&&w.sub(v),v.props=g,v.state||(v.state={}),v.context=x,v.__n=t,h=v.__d=!0,v.__h=[]),null==v.__s&&(v.__s=v.state),null!=P.getDerivedStateFromProps&&(v.__s==v.state&&(v.__s=c$1({},v.__s)),c$1(v.__s,P.getDerivedStateFromProps(g,v.__s))),d=v.props,_=v.state,h)null==P.getDerivedStateFromProps&&null!=v.componentWillMount&&v.componentWillMount(),null!=v.componentDidMount&&v.__h.push(v.componentDidMount);else {if(null==P.getDerivedStateFromProps&&g!==d&&null!=v.componentWillReceiveProps&&v.componentWillReceiveProps(g,x),!v.__e&&null!=v.shouldComponentUpdate&&!1===v.shouldComponentUpdate(g,v.__s,x)||u.__v===i.__v){v.props=g,v.state=v.__s,u.__v!==i.__v&&(v.__d=!1),v.__v=u,u.__e=i.__e,u.__k=i.__k,u.__k.forEach(function(n){n&&(n.__=u);}),v.__h.length&&f.push(v);break n}null!=v.componentWillUpdate&&v.componentWillUpdate(g,v.__s,x),null!=v.componentDidUpdate&&v.__h.push(function(){v.componentDidUpdate(d,_,k);});}v.context=x,v.props=g,v.state=v.__s,(a=n.__r)&&a(u),v.__d=!1,v.__v=u,v.__P=l,a=v.render(v.props,v.state,v.context),v.state=v.__s,null!=v.getChildContext&&(t=c$1(c$1({},t),v.getChildContext())),h||null==v.getSnapshotBeforeUpdate||(k=v.getSnapshotBeforeUpdate(d,_)),A=null!=a&&a.type===y&&null==a.key?a.props.children:a,m(l,Array.isArray(A)?A:[A],u,i,t,o,r,f,e,s),v.base=u.__e,u.__h=null,v.__h.length&&f.push(v),b&&(v.__E=v.__=null),v.__e=!1;}else null==r&&u.__v===i.__v?(u.__k=i.__k,u.__e=i.__e):u.__e=j$2(i.__e,u,i,t,o,r,f,s);(a=n.diffed)&&a(u);}catch(l){u.__v=null,(s||null!=r)&&(u.__e=e,u.__h=!!s,r[r.indexOf(e)]=null),n.__e(l,u,i);}}function T$1(l,u){n.__c&&n.__c(u,l),l.some(function(u){try{l=u.__h,u.__h=[],l.some(function(n){n.call(u);});}catch(l){n.__e(l,u.__v);}});}function j$2(n,l,u,i,t,o,e,c){var a,v,h,y,p=u.props,d=l.props,_=l.type,k=0;if("svg"===_&&(t=!0),null!=o)for(;k<o.length;k++)if((a=o[k])&&(a===n||(_?a.localName==_:3==a.nodeType))){n=a,o[k]=null;break}if(null==n){if(null===_)return document.createTextNode(d);n=t?document.createElementNS("http://www.w3.org/2000/svg",_):document.createElement(_,d.is&&d),o=null,c=!1;}if(null===_)p===d||c&&n.data===d||(n.data=d);else {if(o=o&&f$1.slice.call(n.childNodes),v=(p=u.props||r$1).dangerouslySetInnerHTML,h=d.dangerouslySetInnerHTML,!c){if(null!=o)for(p={},y=0;y<n.attributes.length;y++)p[n.attributes[y].name]=n.attributes[y].value;(h||v)&&(h&&(v&&h.__html==v.__html||h.__html===n.innerHTML)||(n.innerHTML=h&&h.__html||""));}if(A$1(n,d,p,t,c),h)l.__k=[];else if(k=l.props.children,m(n,Array.isArray(k)?k:[k],l,u,i,t&&"foreignObject"!==_,o,e,n.firstChild,c),null!=o)for(k=o.length;k--;)null!=o[k]&&s(o[k]);c||("value"in d&&void 0!==(k=d.value)&&(k!==n.value||"progress"===_&&!k)&&C$1(n,"value",k,p.value,!1),"checked"in d&&void 0!==(k=d.checked)&&k!==n.checked&&C$1(n,"checked",k,p.checked,!1));}return n}function z(l,u,i){try{"function"==typeof l?l(u):l.current=u;}catch(l){n.__e(l,i);}}function L$1(l,u,i){var t,o,r;if(n.unmount&&n.unmount(l),(t=l.ref)&&(t.current&&t.current!==l.__e||z(t,null,u)),i||"function"==typeof l.type||(i=null!=(o=l.__e)),l.__e=l.__d=void 0,null!=(t=l.__c)){if(t.componentWillUnmount)try{t.componentWillUnmount();}catch(l){n.__e(l,u);}t.base=t.__P=null;}if(t=l.__k)for(r=0;r<t.length;r++)t[r]&&L$1(t[r],u,i);null!=o&&s(o);}function M$1(n,l,u){return this.constructor(n,u)}function N(l,u,i){var t,o,e;n.__&&n.__(l,u),o=(t="function"==typeof i)?null:i&&i.__k||u.__k,e=[],I$1(u,l=(!t&&i||u).__k=a$1(y,null,[l]),o||r$1,r$1,void 0!==u.ownerSVGElement,!t&&i?[i]:o?null:u.firstChild?f$1.slice.call(u.childNodes):null,e,!t&&i?i:o?o.__e:u.firstChild,t),T$1(e,l);}function q(n,l){var u={__c:l="__cC"+o++,__:n,Consumer:function(n,l){return n.children(l)},Provider:function(n){var u,i;return this.getChildContext||(u=[],(i={})[l]=this,this.getChildContext=function(){return i},this.shouldComponentUpdate=function(n){this.props.value!==n.value&&u.some(k);},this.sub=function(n){u.push(n);var l=n.componentWillUnmount;n.componentWillUnmount=function(){u.splice(u.indexOf(n),1),l&&l.call(n);};}),n.children}};return u.Provider.__=u.Consumer.contextType=u}n={__e:function(n,l){for(var u,i,t;l=l.__;)if((u=l.__c)&&!u.__)try{if((i=u.constructor)&&null!=i.getDerivedStateFromError&&(u.setState(i.getDerivedStateFromError(n)),t=u.__d),null!=u.componentDidCatch&&(u.componentDidCatch(n),t=u.__d),t)return u.__E=u}catch(l){n=l;}throw n},__v:0},p.prototype.setState=function(n,l){var u;u=null!=this.__s&&this.__s!==this.state?this.__s:this.__s=c$1({},this.state),"function"==typeof n&&(n=n(c$1({},u),this.props)),n&&c$1(u,n),null!=n&&this.__v&&(l&&this.__h.push(l),k(this));},p.prototype.forceUpdate=function(n){this.__v&&(this.__e=!0,n&&this.__h.push(n),k(this));},p.prototype.render=y,u=[],i$1="function"==typeof Promise?Promise.prototype.then.bind(Promise.resolve()):setTimeout,b$1.__r=0,o=0;
  50. var r,i=[],c=n.__b,f=n.__r,e=n.diffed,a=n.__c,v=n.unmount;function x(){i.forEach(function(t){if(t.__P)try{t.__H.__h.forEach(g),t.__H.__h.forEach(j$1),t.__H.__h=[];}catch(u){t.__H.__h=[],n.__e(u,t.__v);}}),i=[];}n.__b=function(n){c&&c(n);},n.__r=function(n){f&&f(n);var r=(n.__c).__H;r&&(r.__h.forEach(g),r.__h.forEach(j$1),r.__h=[]);},n.diffed=function(t){e&&e(t);var o=t.__c;o&&o.__H&&o.__H.__h.length&&(1!==i.push(o)&&r===n.requestAnimationFrame||((r=n.requestAnimationFrame)||function(n){var t,u=function(){clearTimeout(r),b&&cancelAnimationFrame(t),setTimeout(n);},r=setTimeout(u,100);b&&(t=requestAnimationFrame(u));})(x));},n.__c=function(t,u){u.some(function(t){try{t.__h.forEach(g),t.__h=t.__h.filter(function(n){return !n.__||j$1(n)});}catch(r){u.some(function(n){n.__h&&(n.__h=[]);}),u=[],n.__e(r,t.__v);}}),a&&a(t,u);},n.unmount=function(t){v&&v(t);var u=t.__c;if(u&&u.__H)try{u.__H.__.forEach(g);}catch(t){n.__e(t,u.__v);}};var b="function"==typeof requestAnimationFrame;function g(n){"function"==typeof n.__c&&n.__c();}function j$1(n){n.__c=n.__();}
  51. function C(n,t){for(var e in t)n[e]=t[e];return n}function S(n,t){for(var e in n)if("__source"!==e&&!(e in t))return !0;for(var r in t)if("__source"!==r&&n[r]!==t[r])return !0;return !1}function E(n){this.props=n;}(E.prototype=new p).isPureReactComponent=!0,E.prototype.shouldComponentUpdate=function(n,t){return S(this.props,n)||S(this.state,t)};var w=n.__b;n.__b=function(n){n.type&&n.type.__f&&n.ref&&(n.props.ref=n.ref,n.ref=null),w&&w(n);};var A=n.__e;n.__e=function(n,t,e){if(n.then)for(var r,u=t;u=u.__;)if((r=u.__c)&&r.__c)return null==t.__e&&(t.__e=e.__e,t.__k=e.__k),r.__c(n,t);A(n,t,e);};var O=n.unmount;function L(){this.__u=0,this.t=null,this.__b=null;}function U(n){var t=n.__.__c;return t&&t.__e&&t.__e(n)}function F(){this.u=null,this.o=null;}n.unmount=function(n){var t=n.__c;t&&t.__R&&t.__R(),t&&!0===n.__h&&(n.type=null),O&&O(n);},(L.prototype=new p).__c=function(n,t){var e=t.__c,r=this;null==r.t&&(r.t=[]),r.t.push(e);var u=U(r.__v),o=!1,i=function(){o||(o=!0,e.__R=null,u?u(l):l());};e.__R=i;var l=function(){if(!--r.__u){if(r.state.__e){var n=r.state.__e;r.__v.__k[0]=function n(t,e,r){return t&&(t.__v=null,t.__k=t.__k&&t.__k.map(function(t){return n(t,e,r)}),t.__c&&t.__c.__P===e&&(t.__e&&r.insertBefore(t.__e,t.__d),t.__c.__e=!0,t.__c.__P=r)),t}(n,n.__c.__P,n.__c.__O);}var t;for(r.setState({__e:r.__b=null});t=r.t.pop();)t.forceUpdate();}},f=!0===t.__h;r.__u++||f||r.setState({__e:r.__b=r.__v.__k[0]}),n.then(i,i);},L.prototype.componentWillUnmount=function(){this.t=[];},L.prototype.render=function(n,t){if(this.__b){if(this.__v.__k){var e=document.createElement("div"),r=this.__v.__k[0].__c;this.__v.__k[0]=function n(t,e,r){return t&&(t.__c&&t.__c.__H&&(t.__c.__H.__.forEach(function(n){"function"==typeof n.__c&&n.__c();}),t.__c.__H=null),null!=(t=C({},t)).__c&&(t.__c.__P===r&&(t.__c.__P=e),t.__c=null),t.__k=t.__k&&t.__k.map(function(t){return n(t,e,r)})),t}(this.__b,e,r.__O=r.__P);}this.__b=null;}var u=t.__e&&a$1(y,null,n.fallback);return u&&(u.__h=null),[a$1(y,null,t.__e?null:n.children),u]};var M=function(n,t,e){if(++e[1]===e[0]&&n.o.delete(t),n.props.revealOrder&&("t"!==n.props.revealOrder[0]||!n.o.size))for(e=n.u;e;){for(;e.length>3;)e.pop()();if(e[1]<e[0])break;n.u=e=e[2];}};function T(n){return this.getChildContext=function(){return n.context},n.children}function j(n){var t=this,e=n.i;t.componentWillUnmount=function(){N(null,t.l),t.l=null,t.i=null;},t.i&&t.i!==e&&t.componentWillUnmount(),n.__v?(t.l||(t.i=e,t.l={nodeType:1,parentNode:e,childNodes:[],appendChild:function(n){this.childNodes.push(n),t.i.appendChild(n);},insertBefore:function(n,e){this.childNodes.push(n),t.i.appendChild(n);},removeChild:function(n){this.childNodes.splice(this.childNodes.indexOf(n)>>>1,1),t.i.removeChild(n);}}),N(a$1(T,{context:t.context},n.__v),t.l)):t.l&&t.componentWillUnmount();}function I(n,t){return a$1(j,{__v:n,i:t})}(F.prototype=new p).__e=function(n){var t=this,e=U(t.__v),r=t.o.get(n);return r[0]++,function(u){var o=function(){t.props.revealOrder?(r.push(u),M(t,n,r)):u();};e?e(o):o();}},F.prototype.render=function(n){this.u=null,this.o=new Map;var t=w$1(n.children);n.revealOrder&&"b"===n.revealOrder[0]&&t.reverse();for(var e=t.length;e--;)this.o.set(t[e],this.u=[1,0,this.u]);return n.children},F.prototype.componentDidUpdate=F.prototype.componentDidMount=function(){var n=this;this.o.forEach(function(t,e){M(n,e,t);});};var W="undefined"!=typeof Symbol&&Symbol.for&&Symbol.for("react.element")||60103,P=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|fill|flood|font|glyph(?!R)|horiz|marker(?!H|W|U)|overline|paint|stop|strikethrough|stroke|text(?!L)|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,V=function(n){return ("undefined"!=typeof Symbol&&"symbol"==typeof Symbol()?/fil|che|rad/i:/fil|che|ra/i).test(n)};p.prototype.isReactComponent={},["componentWillMount","componentWillReceiveProps","componentWillUpdate"].forEach(function(n){Object.defineProperty(p.prototype,n,{configurable:!0,get:function(){return this["UNSAFE_"+n]},set:function(t){Object.defineProperty(this,n,{configurable:!0,writable:!0,value:t});}});});var H=n.event;function Z(){}function Y(){return this.cancelBubble}function $(){return this.defaultPrevented}n.event=function(n){return H&&(n=H(n)),n.persist=Z,n.isPropagationStopped=Y,n.isDefaultPrevented=$,n.nativeEvent=n};var G={configurable:!0,get:function(){return this.class}},J=n.vnode;n.vnode=function(n){var t=n.type,e=n.props,r=e;if("string"==typeof t){for(var u in r={},e){var o=e[u];"value"===u&&"defaultValue"in e&&null==o||("defaultValue"===u&&"value"in e&&null==e.value?u="value":"download"===u&&!0===o?o="":/ondoubleclick/i.test(u)?u="ondblclick":/^onchange(textarea|input)/i.test(u+t)&&!V(e.type)?u="oninput":/^on(Ani|Tra|Tou|BeforeInp)/.test(u)?u=u.toLowerCase():P.test(u)?u=u.replace(/[A-Z0-9]/,"-$&").toLowerCase():null===o&&(o=void 0),r[u]=o);}"select"==t&&r.multiple&&Array.isArray(r.value)&&(r.value=w$1(e.children).forEach(function(n){n.props.selected=-1!=r.value.indexOf(n.props.value);})),"select"==t&&null!=r.defaultValue&&(r.value=w$1(e.children).forEach(function(n){n.props.selected=r.multiple?-1!=r.defaultValue.indexOf(n.props.value):r.defaultValue==n.props.value;})),n.props=r;}t&&e.class!=e.className&&(G.enumerable="className"in e,null!=e.className&&(r.class=e.className),Object.defineProperty(r,"className",G)),n.$$typeof=W,J&&J(n);};var K=n.__r;n.__r=function(n){K&&K(n);};"object"==typeof performance&&"function"==typeof performance.now?performance.now.bind(performance):function(){return Date.now()};
  52. var globalObj = typeof globalThis !== 'undefined' ? globalThis : window; // // TODO: streamline when killing IE11 support
  53. if (globalObj.FullCalendarVDom) {
  54. console.warn('FullCalendar VDOM already loaded');
  55. }
  56. else {
  57. globalObj.FullCalendarVDom = {
  58. Component: p,
  59. createElement: a$1,
  60. render: N,
  61. createRef: h,
  62. Fragment: y,
  63. createContext: createContext$1,
  64. createPortal: I,
  65. flushToDom: flushToDom$1,
  66. unmountComponentAtNode: unmountComponentAtNode$1,
  67. };
  68. }
  69. // HACKS...
  70. // TODO: lock version
  71. // TODO: link gh issues
  72. function flushToDom$1() {
  73. var oldDebounceRendering = n.debounceRendering; // orig
  74. var callbackQ = [];
  75. function execCallbackSync(callback) {
  76. callbackQ.push(callback);
  77. }
  78. n.debounceRendering = execCallbackSync;
  79. N(a$1(FakeComponent, {}), document.createElement('div'));
  80. while (callbackQ.length) {
  81. callbackQ.shift()();
  82. }
  83. n.debounceRendering = oldDebounceRendering;
  84. }
  85. var FakeComponent = /** @class */ (function (_super) {
  86. __extends(FakeComponent, _super);
  87. function FakeComponent() {
  88. return _super !== null && _super.apply(this, arguments) || this;
  89. }
  90. FakeComponent.prototype.render = function () { return a$1('div', {}); };
  91. FakeComponent.prototype.componentDidMount = function () { this.setState({}); };
  92. return FakeComponent;
  93. }(p));
  94. function createContext$1(defaultValue) {
  95. var ContextType = q(defaultValue);
  96. var origProvider = ContextType.Provider;
  97. ContextType.Provider = function () {
  98. var _this = this;
  99. var isNew = !this.getChildContext;
  100. var children = origProvider.apply(this, arguments); // eslint-disable-line prefer-rest-params
  101. if (isNew) {
  102. var subs_1 = [];
  103. this.shouldComponentUpdate = function (_props) {
  104. if (_this.props.value !== _props.value) {
  105. subs_1.forEach(function (c) {
  106. c.context = _props.value;
  107. c.forceUpdate();
  108. });
  109. }
  110. };
  111. this.sub = function (c) {
  112. subs_1.push(c);
  113. var old = c.componentWillUnmount;
  114. c.componentWillUnmount = function () {
  115. subs_1.splice(subs_1.indexOf(c), 1);
  116. old && old.call(c);
  117. };
  118. };
  119. }
  120. return children;
  121. };
  122. return ContextType;
  123. }
  124. function unmountComponentAtNode$1(node) {
  125. N(null, node);
  126. }
  127. // no public types yet. when there are, export from:
  128. // import {} from './api-type-deps'
  129. var EventSourceApi = /** @class */ (function () {
  130. function EventSourceApi(context, internalEventSource) {
  131. this.context = context;
  132. this.internalEventSource = internalEventSource;
  133. }
  134. EventSourceApi.prototype.remove = function () {
  135. this.context.dispatch({
  136. type: 'REMOVE_EVENT_SOURCE',
  137. sourceId: this.internalEventSource.sourceId,
  138. });
  139. };
  140. EventSourceApi.prototype.refetch = function () {
  141. this.context.dispatch({
  142. type: 'FETCH_EVENT_SOURCES',
  143. sourceIds: [this.internalEventSource.sourceId],
  144. isRefetch: true,
  145. });
  146. };
  147. Object.defineProperty(EventSourceApi.prototype, "id", {
  148. get: function () {
  149. return this.internalEventSource.publicId;
  150. },
  151. enumerable: false,
  152. configurable: true
  153. });
  154. Object.defineProperty(EventSourceApi.prototype, "url", {
  155. get: function () {
  156. return this.internalEventSource.meta.url;
  157. },
  158. enumerable: false,
  159. configurable: true
  160. });
  161. Object.defineProperty(EventSourceApi.prototype, "format", {
  162. get: function () {
  163. return this.internalEventSource.meta.format; // TODO: bad. not guaranteed
  164. },
  165. enumerable: false,
  166. configurable: true
  167. });
  168. return EventSourceApi;
  169. }());
  170. function removeElement(el) {
  171. if (el.parentNode) {
  172. el.parentNode.removeChild(el);
  173. }
  174. }
  175. // Querying
  176. // ----------------------------------------------------------------------------------------------------------------
  177. function elementClosest(el, selector) {
  178. if (el.closest) {
  179. return el.closest(selector);
  180. // really bad fallback for IE
  181. // from https://developer.mozilla.org/en-US/docs/Web/API/Element/closest
  182. }
  183. if (!document.documentElement.contains(el)) {
  184. return null;
  185. }
  186. do {
  187. if (elementMatches(el, selector)) {
  188. return el;
  189. }
  190. el = (el.parentElement || el.parentNode);
  191. } while (el !== null && el.nodeType === 1);
  192. return null;
  193. }
  194. function elementMatches(el, selector) {
  195. var method = el.matches || el.matchesSelector || el.msMatchesSelector;
  196. return method.call(el, selector);
  197. }
  198. // accepts multiple subject els
  199. // returns a real array. good for methods like forEach
  200. // TODO: accept the document
  201. function findElements(container, selector) {
  202. var containers = container instanceof HTMLElement ? [container] : container;
  203. var allMatches = [];
  204. for (var i = 0; i < containers.length; i += 1) {
  205. var matches = containers[i].querySelectorAll(selector);
  206. for (var j = 0; j < matches.length; j += 1) {
  207. allMatches.push(matches[j]);
  208. }
  209. }
  210. return allMatches;
  211. }
  212. // accepts multiple subject els
  213. // only queries direct child elements // TODO: rename to findDirectChildren!
  214. function findDirectChildren(parent, selector) {
  215. var parents = parent instanceof HTMLElement ? [parent] : parent;
  216. var allMatches = [];
  217. for (var i = 0; i < parents.length; i += 1) {
  218. var childNodes = parents[i].children; // only ever elements
  219. for (var j = 0; j < childNodes.length; j += 1) {
  220. var childNode = childNodes[j];
  221. if (!selector || elementMatches(childNode, selector)) {
  222. allMatches.push(childNode);
  223. }
  224. }
  225. }
  226. return allMatches;
  227. }
  228. // Style
  229. // ----------------------------------------------------------------------------------------------------------------
  230. var PIXEL_PROP_RE = /(top|left|right|bottom|width|height)$/i;
  231. function applyStyle(el, props) {
  232. for (var propName in props) {
  233. applyStyleProp(el, propName, props[propName]);
  234. }
  235. }
  236. function applyStyleProp(el, name, val) {
  237. if (val == null) {
  238. el.style[name] = '';
  239. }
  240. else if (typeof val === 'number' && PIXEL_PROP_RE.test(name)) {
  241. el.style[name] = val + "px";
  242. }
  243. else {
  244. el.style[name] = val;
  245. }
  246. }
  247. // Event Handling
  248. // ----------------------------------------------------------------------------------------------------------------
  249. // if intercepting bubbled events at the document/window/body level,
  250. // and want to see originating element (the 'target'), use this util instead
  251. // of `ev.target` because it goes within web-component boundaries.
  252. function getEventTargetViaRoot(ev) {
  253. var _a, _b;
  254. return (_b = (_a = ev.composedPath) === null || _a === void 0 ? void 0 : _a.call(ev)[0]) !== null && _b !== void 0 ? _b : ev.target;
  255. }
  256. // Stops a mouse/touch event from doing it's native browser action
  257. function preventDefault(ev) {
  258. ev.preventDefault();
  259. }
  260. // Event Delegation
  261. // ----------------------------------------------------------------------------------------------------------------
  262. function buildDelegationHandler(selector, handler) {
  263. return function (ev) {
  264. var matchedChild = elementClosest(ev.target, selector);
  265. if (matchedChild) {
  266. handler.call(matchedChild, ev, matchedChild);
  267. }
  268. };
  269. }
  270. function listenBySelector(container, eventType, selector, handler) {
  271. var attachedHandler = buildDelegationHandler(selector, handler);
  272. container.addEventListener(eventType, attachedHandler);
  273. return function () {
  274. container.removeEventListener(eventType, attachedHandler);
  275. };
  276. }
  277. function listenToHoverBySelector(container, selector, onMouseEnter, onMouseLeave) {
  278. var currentMatchedChild;
  279. return listenBySelector(container, 'mouseover', selector, function (mouseOverEv, matchedChild) {
  280. if (matchedChild !== currentMatchedChild) {
  281. currentMatchedChild = matchedChild;
  282. onMouseEnter(mouseOverEv, matchedChild);
  283. var realOnMouseLeave_1 = function (mouseLeaveEv) {
  284. currentMatchedChild = null;
  285. onMouseLeave(mouseLeaveEv, matchedChild);
  286. matchedChild.removeEventListener('mouseleave', realOnMouseLeave_1);
  287. };
  288. // listen to the next mouseleave, and then unattach
  289. matchedChild.addEventListener('mouseleave', realOnMouseLeave_1);
  290. }
  291. });
  292. }
  293. // Animation
  294. // ----------------------------------------------------------------------------------------------------------------
  295. var transitionEventNames = [
  296. 'webkitTransitionEnd',
  297. 'otransitionend',
  298. 'oTransitionEnd',
  299. 'msTransitionEnd',
  300. 'transitionend',
  301. ];
  302. // triggered only when the next single subsequent transition finishes
  303. function whenTransitionDone(el, callback) {
  304. var realCallback = function (ev) {
  305. callback(ev);
  306. transitionEventNames.forEach(function (eventName) {
  307. el.removeEventListener(eventName, realCallback);
  308. });
  309. };
  310. transitionEventNames.forEach(function (eventName) {
  311. el.addEventListener(eventName, realCallback); // cross-browser way to determine when the transition finishes
  312. });
  313. }
  314. var guidNumber = 0;
  315. function guid() {
  316. guidNumber += 1;
  317. return String(guidNumber);
  318. }
  319. /* FullCalendar-specific DOM Utilities
  320. ----------------------------------------------------------------------------------------------------------------------*/
  321. // Make the mouse cursor express that an event is not allowed in the current area
  322. function disableCursor() {
  323. document.body.classList.add('fc-not-allowed');
  324. }
  325. // Returns the mouse cursor to its original look
  326. function enableCursor() {
  327. document.body.classList.remove('fc-not-allowed');
  328. }
  329. /* Selection
  330. ----------------------------------------------------------------------------------------------------------------------*/
  331. function preventSelection(el) {
  332. el.classList.add('fc-unselectable');
  333. el.addEventListener('selectstart', preventDefault);
  334. }
  335. function allowSelection(el) {
  336. el.classList.remove('fc-unselectable');
  337. el.removeEventListener('selectstart', preventDefault);
  338. }
  339. /* Context Menu
  340. ----------------------------------------------------------------------------------------------------------------------*/
  341. function preventContextMenu(el) {
  342. el.addEventListener('contextmenu', preventDefault);
  343. }
  344. function allowContextMenu(el) {
  345. el.removeEventListener('contextmenu', preventDefault);
  346. }
  347. function parseFieldSpecs(input) {
  348. var specs = [];
  349. var tokens = [];
  350. var i;
  351. var token;
  352. if (typeof input === 'string') {
  353. tokens = input.split(/\s*,\s*/);
  354. }
  355. else if (typeof input === 'function') {
  356. tokens = [input];
  357. }
  358. else if (Array.isArray(input)) {
  359. tokens = input;
  360. }
  361. for (i = 0; i < tokens.length; i += 1) {
  362. token = tokens[i];
  363. if (typeof token === 'string') {
  364. specs.push(token.charAt(0) === '-' ?
  365. { field: token.substring(1), order: -1 } :
  366. { field: token, order: 1 });
  367. }
  368. else if (typeof token === 'function') {
  369. specs.push({ func: token });
  370. }
  371. }
  372. return specs;
  373. }
  374. function compareByFieldSpecs(obj0, obj1, fieldSpecs) {
  375. var i;
  376. var cmp;
  377. for (i = 0; i < fieldSpecs.length; i += 1) {
  378. cmp = compareByFieldSpec(obj0, obj1, fieldSpecs[i]);
  379. if (cmp) {
  380. return cmp;
  381. }
  382. }
  383. return 0;
  384. }
  385. function compareByFieldSpec(obj0, obj1, fieldSpec) {
  386. if (fieldSpec.func) {
  387. return fieldSpec.func(obj0, obj1);
  388. }
  389. return flexibleCompare(obj0[fieldSpec.field], obj1[fieldSpec.field])
  390. * (fieldSpec.order || 1);
  391. }
  392. function flexibleCompare(a, b) {
  393. if (!a && !b) {
  394. return 0;
  395. }
  396. if (b == null) {
  397. return -1;
  398. }
  399. if (a == null) {
  400. return 1;
  401. }
  402. if (typeof a === 'string' || typeof b === 'string') {
  403. return String(a).localeCompare(String(b));
  404. }
  405. return a - b;
  406. }
  407. /* String Utilities
  408. ----------------------------------------------------------------------------------------------------------------------*/
  409. function padStart(val, len) {
  410. var s = String(val);
  411. return '000'.substr(0, len - s.length) + s;
  412. }
  413. /* Number Utilities
  414. ----------------------------------------------------------------------------------------------------------------------*/
  415. function compareNumbers(a, b) {
  416. return a - b;
  417. }
  418. function isInt(n) {
  419. return n % 1 === 0;
  420. }
  421. /* FC-specific DOM dimension stuff
  422. ----------------------------------------------------------------------------------------------------------------------*/
  423. function computeSmallestCellWidth(cellEl) {
  424. var allWidthEl = cellEl.querySelector('.fc-scrollgrid-shrink-frame');
  425. var contentWidthEl = cellEl.querySelector('.fc-scrollgrid-shrink-cushion');
  426. if (!allWidthEl) {
  427. throw new Error('needs fc-scrollgrid-shrink-frame className'); // TODO: use const
  428. }
  429. if (!contentWidthEl) {
  430. throw new Error('needs fc-scrollgrid-shrink-cushion className');
  431. }
  432. return cellEl.getBoundingClientRect().width - allWidthEl.getBoundingClientRect().width + // the cell padding+border
  433. contentWidthEl.getBoundingClientRect().width;
  434. }
  435. var DAY_IDS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
  436. // Adding
  437. function addWeeks(m, n) {
  438. var a = dateToUtcArray(m);
  439. a[2] += n * 7;
  440. return arrayToUtcDate(a);
  441. }
  442. function addDays(m, n) {
  443. var a = dateToUtcArray(m);
  444. a[2] += n;
  445. return arrayToUtcDate(a);
  446. }
  447. function addMs(m, n) {
  448. var a = dateToUtcArray(m);
  449. a[6] += n;
  450. return arrayToUtcDate(a);
  451. }
  452. // Diffing (all return floats)
  453. // TODO: why not use ranges?
  454. function diffWeeks(m0, m1) {
  455. return diffDays(m0, m1) / 7;
  456. }
  457. function diffDays(m0, m1) {
  458. return (m1.valueOf() - m0.valueOf()) / (1000 * 60 * 60 * 24);
  459. }
  460. function diffHours(m0, m1) {
  461. return (m1.valueOf() - m0.valueOf()) / (1000 * 60 * 60);
  462. }
  463. function diffMinutes(m0, m1) {
  464. return (m1.valueOf() - m0.valueOf()) / (1000 * 60);
  465. }
  466. function diffSeconds(m0, m1) {
  467. return (m1.valueOf() - m0.valueOf()) / 1000;
  468. }
  469. function diffDayAndTime(m0, m1) {
  470. var m0day = startOfDay(m0);
  471. var m1day = startOfDay(m1);
  472. return {
  473. years: 0,
  474. months: 0,
  475. days: Math.round(diffDays(m0day, m1day)),
  476. milliseconds: (m1.valueOf() - m1day.valueOf()) - (m0.valueOf() - m0day.valueOf()),
  477. };
  478. }
  479. // Diffing Whole Units
  480. function diffWholeWeeks(m0, m1) {
  481. var d = diffWholeDays(m0, m1);
  482. if (d !== null && d % 7 === 0) {
  483. return d / 7;
  484. }
  485. return null;
  486. }
  487. function diffWholeDays(m0, m1) {
  488. if (timeAsMs(m0) === timeAsMs(m1)) {
  489. return Math.round(diffDays(m0, m1));
  490. }
  491. return null;
  492. }
  493. // Start-Of
  494. function startOfDay(m) {
  495. return arrayToUtcDate([
  496. m.getUTCFullYear(),
  497. m.getUTCMonth(),
  498. m.getUTCDate(),
  499. ]);
  500. }
  501. function startOfHour(m) {
  502. return arrayToUtcDate([
  503. m.getUTCFullYear(),
  504. m.getUTCMonth(),
  505. m.getUTCDate(),
  506. m.getUTCHours(),
  507. ]);
  508. }
  509. function startOfMinute(m) {
  510. return arrayToUtcDate([
  511. m.getUTCFullYear(),
  512. m.getUTCMonth(),
  513. m.getUTCDate(),
  514. m.getUTCHours(),
  515. m.getUTCMinutes(),
  516. ]);
  517. }
  518. function startOfSecond(m) {
  519. return arrayToUtcDate([
  520. m.getUTCFullYear(),
  521. m.getUTCMonth(),
  522. m.getUTCDate(),
  523. m.getUTCHours(),
  524. m.getUTCMinutes(),
  525. m.getUTCSeconds(),
  526. ]);
  527. }
  528. // Week Computation
  529. function weekOfYear(marker, dow, doy) {
  530. var y = marker.getUTCFullYear();
  531. var w = weekOfGivenYear(marker, y, dow, doy);
  532. if (w < 1) {
  533. return weekOfGivenYear(marker, y - 1, dow, doy);
  534. }
  535. var nextW = weekOfGivenYear(marker, y + 1, dow, doy);
  536. if (nextW >= 1) {
  537. return Math.min(w, nextW);
  538. }
  539. return w;
  540. }
  541. function weekOfGivenYear(marker, year, dow, doy) {
  542. var firstWeekStart = arrayToUtcDate([year, 0, 1 + firstWeekOffset(year, dow, doy)]);
  543. var dayStart = startOfDay(marker);
  544. var days = Math.round(diffDays(firstWeekStart, dayStart));
  545. return Math.floor(days / 7) + 1; // zero-indexed
  546. }
  547. // start-of-first-week - start-of-year
  548. function firstWeekOffset(year, dow, doy) {
  549. // first-week day -- which january is always in the first week (4 for iso, 1 for other)
  550. var fwd = 7 + dow - doy;
  551. // first-week day local weekday -- which local weekday is fwd
  552. var fwdlw = (7 + arrayToUtcDate([year, 0, fwd]).getUTCDay() - dow) % 7;
  553. return -fwdlw + fwd - 1;
  554. }
  555. // Array Conversion
  556. function dateToLocalArray(date) {
  557. return [
  558. date.getFullYear(),
  559. date.getMonth(),
  560. date.getDate(),
  561. date.getHours(),
  562. date.getMinutes(),
  563. date.getSeconds(),
  564. date.getMilliseconds(),
  565. ];
  566. }
  567. function arrayToLocalDate(a) {
  568. return new Date(a[0], a[1] || 0, a[2] == null ? 1 : a[2], // day of month
  569. a[3] || 0, a[4] || 0, a[5] || 0);
  570. }
  571. function dateToUtcArray(date) {
  572. return [
  573. date.getUTCFullYear(),
  574. date.getUTCMonth(),
  575. date.getUTCDate(),
  576. date.getUTCHours(),
  577. date.getUTCMinutes(),
  578. date.getUTCSeconds(),
  579. date.getUTCMilliseconds(),
  580. ];
  581. }
  582. function arrayToUtcDate(a) {
  583. // according to web standards (and Safari), a month index is required.
  584. // massage if only given a year.
  585. if (a.length === 1) {
  586. a = a.concat([0]);
  587. }
  588. return new Date(Date.UTC.apply(Date, a));
  589. }
  590. // Other Utils
  591. function isValidDate(m) {
  592. return !isNaN(m.valueOf());
  593. }
  594. function timeAsMs(m) {
  595. return m.getUTCHours() * 1000 * 60 * 60 +
  596. m.getUTCMinutes() * 1000 * 60 +
  597. m.getUTCSeconds() * 1000 +
  598. m.getUTCMilliseconds();
  599. }
  600. function createEventInstance(defId, range, forcedStartTzo, forcedEndTzo) {
  601. return {
  602. instanceId: guid(),
  603. defId: defId,
  604. range: range,
  605. forcedStartTzo: forcedStartTzo == null ? null : forcedStartTzo,
  606. forcedEndTzo: forcedEndTzo == null ? null : forcedEndTzo,
  607. };
  608. }
  609. var hasOwnProperty = Object.prototype.hasOwnProperty;
  610. // Merges an array of objects into a single object.
  611. // The second argument allows for an array of property names who's object values will be merged together.
  612. function mergeProps(propObjs, complexPropsMap) {
  613. var dest = {};
  614. if (complexPropsMap) {
  615. for (var name_1 in complexPropsMap) {
  616. var complexObjs = [];
  617. // collect the trailing object values, stopping when a non-object is discovered
  618. for (var i = propObjs.length - 1; i >= 0; i -= 1) {
  619. var val = propObjs[i][name_1];
  620. if (typeof val === 'object' && val) { // non-null object
  621. complexObjs.unshift(val);
  622. }
  623. else if (val !== undefined) {
  624. dest[name_1] = val; // if there were no objects, this value will be used
  625. break;
  626. }
  627. }
  628. // if the trailing values were objects, use the merged value
  629. if (complexObjs.length) {
  630. dest[name_1] = mergeProps(complexObjs);
  631. }
  632. }
  633. }
  634. // copy values into the destination, going from last to first
  635. for (var i = propObjs.length - 1; i >= 0; i -= 1) {
  636. var props = propObjs[i];
  637. for (var name_2 in props) {
  638. if (!(name_2 in dest)) { // if already assigned by previous props or complex props, don't reassign
  639. dest[name_2] = props[name_2];
  640. }
  641. }
  642. }
  643. return dest;
  644. }
  645. function filterHash(hash, func) {
  646. var filtered = {};
  647. for (var key in hash) {
  648. if (func(hash[key], key)) {
  649. filtered[key] = hash[key];
  650. }
  651. }
  652. return filtered;
  653. }
  654. function mapHash(hash, func) {
  655. var newHash = {};
  656. for (var key in hash) {
  657. newHash[key] = func(hash[key], key);
  658. }
  659. return newHash;
  660. }
  661. function arrayToHash(a) {
  662. var hash = {};
  663. for (var _i = 0, a_1 = a; _i < a_1.length; _i++) {
  664. var item = a_1[_i];
  665. hash[item] = true;
  666. }
  667. return hash;
  668. }
  669. function buildHashFromArray(a, func) {
  670. var hash = {};
  671. for (var i = 0; i < a.length; i += 1) {
  672. var tuple = func(a[i], i);
  673. hash[tuple[0]] = tuple[1];
  674. }
  675. return hash;
  676. }
  677. function hashValuesToArray(obj) {
  678. var a = [];
  679. for (var key in obj) {
  680. a.push(obj[key]);
  681. }
  682. return a;
  683. }
  684. function isPropsEqual(obj0, obj1) {
  685. if (obj0 === obj1) {
  686. return true;
  687. }
  688. for (var key in obj0) {
  689. if (hasOwnProperty.call(obj0, key)) {
  690. if (!(key in obj1)) {
  691. return false;
  692. }
  693. }
  694. }
  695. for (var key in obj1) {
  696. if (hasOwnProperty.call(obj1, key)) {
  697. if (obj0[key] !== obj1[key]) {
  698. return false;
  699. }
  700. }
  701. }
  702. return true;
  703. }
  704. function getUnequalProps(obj0, obj1) {
  705. var keys = [];
  706. for (var key in obj0) {
  707. if (hasOwnProperty.call(obj0, key)) {
  708. if (!(key in obj1)) {
  709. keys.push(key);
  710. }
  711. }
  712. }
  713. for (var key in obj1) {
  714. if (hasOwnProperty.call(obj1, key)) {
  715. if (obj0[key] !== obj1[key]) {
  716. keys.push(key);
  717. }
  718. }
  719. }
  720. return keys;
  721. }
  722. function compareObjs(oldProps, newProps, equalityFuncs) {
  723. if (equalityFuncs === void 0) { equalityFuncs = {}; }
  724. if (oldProps === newProps) {
  725. return true;
  726. }
  727. for (var key in newProps) {
  728. if (key in oldProps && isObjValsEqual(oldProps[key], newProps[key], equalityFuncs[key])) ;
  729. else {
  730. return false;
  731. }
  732. }
  733. // check for props that were omitted in the new
  734. for (var key in oldProps) {
  735. if (!(key in newProps)) {
  736. return false;
  737. }
  738. }
  739. return true;
  740. }
  741. /*
  742. assumed "true" equality for handler names like "onReceiveSomething"
  743. */
  744. function isObjValsEqual(val0, val1, comparator) {
  745. if (val0 === val1 || comparator === true) {
  746. return true;
  747. }
  748. if (comparator) {
  749. return comparator(val0, val1);
  750. }
  751. return false;
  752. }
  753. function collectFromHash(hash, startIndex, endIndex, step) {
  754. if (startIndex === void 0) { startIndex = 0; }
  755. if (step === void 0) { step = 1; }
  756. var res = [];
  757. if (endIndex == null) {
  758. endIndex = Object.keys(hash).length;
  759. }
  760. for (var i = startIndex; i < endIndex; i += step) {
  761. var val = hash[i];
  762. if (val !== undefined) { // will disregard undefined for sparse arrays
  763. res.push(val);
  764. }
  765. }
  766. return res;
  767. }
  768. function parseRecurring(refined, defaultAllDay, dateEnv, recurringTypes) {
  769. for (var i = 0; i < recurringTypes.length; i += 1) {
  770. var parsed = recurringTypes[i].parse(refined, dateEnv);
  771. if (parsed) {
  772. var allDay = refined.allDay;
  773. if (allDay == null) {
  774. allDay = defaultAllDay;
  775. if (allDay == null) {
  776. allDay = parsed.allDayGuess;
  777. if (allDay == null) {
  778. allDay = false;
  779. }
  780. }
  781. }
  782. return {
  783. allDay: allDay,
  784. duration: parsed.duration,
  785. typeData: parsed.typeData,
  786. typeId: i,
  787. };
  788. }
  789. }
  790. return null;
  791. }
  792. function expandRecurring(eventStore, framingRange, context) {
  793. var dateEnv = context.dateEnv, pluginHooks = context.pluginHooks, options = context.options;
  794. var defs = eventStore.defs, instances = eventStore.instances;
  795. // remove existing recurring instances
  796. // TODO: bad. always expand events as a second step
  797. instances = filterHash(instances, function (instance) { return !defs[instance.defId].recurringDef; });
  798. for (var defId in defs) {
  799. var def = defs[defId];
  800. if (def.recurringDef) {
  801. var duration = def.recurringDef.duration;
  802. if (!duration) {
  803. duration = def.allDay ?
  804. options.defaultAllDayEventDuration :
  805. options.defaultTimedEventDuration;
  806. }
  807. var starts = expandRecurringRanges(def, duration, framingRange, dateEnv, pluginHooks.recurringTypes);
  808. for (var _i = 0, starts_1 = starts; _i < starts_1.length; _i++) {
  809. var start = starts_1[_i];
  810. var instance = createEventInstance(defId, {
  811. start: start,
  812. end: dateEnv.add(start, duration),
  813. });
  814. instances[instance.instanceId] = instance;
  815. }
  816. }
  817. }
  818. return { defs: defs, instances: instances };
  819. }
  820. /*
  821. Event MUST have a recurringDef
  822. */
  823. function expandRecurringRanges(eventDef, duration, framingRange, dateEnv, recurringTypes) {
  824. var typeDef = recurringTypes[eventDef.recurringDef.typeId];
  825. var markers = typeDef.expand(eventDef.recurringDef.typeData, {
  826. start: dateEnv.subtract(framingRange.start, duration),
  827. end: framingRange.end,
  828. }, dateEnv);
  829. // the recurrence plugins don't guarantee that all-day events are start-of-day, so we have to
  830. if (eventDef.allDay) {
  831. markers = markers.map(startOfDay);
  832. }
  833. return markers;
  834. }
  835. var INTERNAL_UNITS = ['years', 'months', 'days', 'milliseconds'];
  836. var PARSE_RE = /^(-?)(?:(\d+)\.)?(\d+):(\d\d)(?::(\d\d)(?:\.(\d\d\d))?)?/;
  837. // Parsing and Creation
  838. function createDuration(input, unit) {
  839. var _a;
  840. if (typeof input === 'string') {
  841. return parseString(input);
  842. }
  843. if (typeof input === 'object' && input) { // non-null object
  844. return parseObject(input);
  845. }
  846. if (typeof input === 'number') {
  847. return parseObject((_a = {}, _a[unit || 'milliseconds'] = input, _a));
  848. }
  849. return null;
  850. }
  851. function parseString(s) {
  852. var m = PARSE_RE.exec(s);
  853. if (m) {
  854. var sign = m[1] ? -1 : 1;
  855. return {
  856. years: 0,
  857. months: 0,
  858. days: sign * (m[2] ? parseInt(m[2], 10) : 0),
  859. milliseconds: sign * ((m[3] ? parseInt(m[3], 10) : 0) * 60 * 60 * 1000 + // hours
  860. (m[4] ? parseInt(m[4], 10) : 0) * 60 * 1000 + // minutes
  861. (m[5] ? parseInt(m[5], 10) : 0) * 1000 + // seconds
  862. (m[6] ? parseInt(m[6], 10) : 0) // ms
  863. ),
  864. };
  865. }
  866. return null;
  867. }
  868. function parseObject(obj) {
  869. var duration = {
  870. years: obj.years || obj.year || 0,
  871. months: obj.months || obj.month || 0,
  872. days: obj.days || obj.day || 0,
  873. milliseconds: (obj.hours || obj.hour || 0) * 60 * 60 * 1000 + // hours
  874. (obj.minutes || obj.minute || 0) * 60 * 1000 + // minutes
  875. (obj.seconds || obj.second || 0) * 1000 + // seconds
  876. (obj.milliseconds || obj.millisecond || obj.ms || 0), // ms
  877. };
  878. var weeks = obj.weeks || obj.week;
  879. if (weeks) {
  880. duration.days += weeks * 7;
  881. duration.specifiedWeeks = true;
  882. }
  883. return duration;
  884. }
  885. // Equality
  886. function durationsEqual(d0, d1) {
  887. return d0.years === d1.years &&
  888. d0.months === d1.months &&
  889. d0.days === d1.days &&
  890. d0.milliseconds === d1.milliseconds;
  891. }
  892. function asCleanDays(dur) {
  893. if (!dur.years && !dur.months && !dur.milliseconds) {
  894. return dur.days;
  895. }
  896. return 0;
  897. }
  898. // Simple Math
  899. function addDurations(d0, d1) {
  900. return {
  901. years: d0.years + d1.years,
  902. months: d0.months + d1.months,
  903. days: d0.days + d1.days,
  904. milliseconds: d0.milliseconds + d1.milliseconds,
  905. };
  906. }
  907. function subtractDurations(d1, d0) {
  908. return {
  909. years: d1.years - d0.years,
  910. months: d1.months - d0.months,
  911. days: d1.days - d0.days,
  912. milliseconds: d1.milliseconds - d0.milliseconds,
  913. };
  914. }
  915. function multiplyDuration(d, n) {
  916. return {
  917. years: d.years * n,
  918. months: d.months * n,
  919. days: d.days * n,
  920. milliseconds: d.milliseconds * n,
  921. };
  922. }
  923. // Conversions
  924. // "Rough" because they are based on average-case Gregorian months/years
  925. function asRoughYears(dur) {
  926. return asRoughDays(dur) / 365;
  927. }
  928. function asRoughMonths(dur) {
  929. return asRoughDays(dur) / 30;
  930. }
  931. function asRoughDays(dur) {
  932. return asRoughMs(dur) / 864e5;
  933. }
  934. function asRoughMinutes(dur) {
  935. return asRoughMs(dur) / (1000 * 60);
  936. }
  937. function asRoughSeconds(dur) {
  938. return asRoughMs(dur) / 1000;
  939. }
  940. function asRoughMs(dur) {
  941. return dur.years * (365 * 864e5) +
  942. dur.months * (30 * 864e5) +
  943. dur.days * 864e5 +
  944. dur.milliseconds;
  945. }
  946. // Advanced Math
  947. function wholeDivideDurations(numerator, denominator) {
  948. var res = null;
  949. for (var i = 0; i < INTERNAL_UNITS.length; i += 1) {
  950. var unit = INTERNAL_UNITS[i];
  951. if (denominator[unit]) {
  952. var localRes = numerator[unit] / denominator[unit];
  953. if (!isInt(localRes) || (res !== null && res !== localRes)) {
  954. return null;
  955. }
  956. res = localRes;
  957. }
  958. else if (numerator[unit]) {
  959. // needs to divide by something but can't!
  960. return null;
  961. }
  962. }
  963. return res;
  964. }
  965. function greatestDurationDenominator(dur) {
  966. var ms = dur.milliseconds;
  967. if (ms) {
  968. if (ms % 1000 !== 0) {
  969. return { unit: 'millisecond', value: ms };
  970. }
  971. if (ms % (1000 * 60) !== 0) {
  972. return { unit: 'second', value: ms / 1000 };
  973. }
  974. if (ms % (1000 * 60 * 60) !== 0) {
  975. return { unit: 'minute', value: ms / (1000 * 60) };
  976. }
  977. if (ms) {
  978. return { unit: 'hour', value: ms / (1000 * 60 * 60) };
  979. }
  980. }
  981. if (dur.days) {
  982. if (dur.specifiedWeeks && dur.days % 7 === 0) {
  983. return { unit: 'week', value: dur.days / 7 };
  984. }
  985. return { unit: 'day', value: dur.days };
  986. }
  987. if (dur.months) {
  988. return { unit: 'month', value: dur.months };
  989. }
  990. if (dur.years) {
  991. return { unit: 'year', value: dur.years };
  992. }
  993. return { unit: 'millisecond', value: 0 };
  994. }
  995. // timeZoneOffset is in minutes
  996. function buildIsoString(marker, timeZoneOffset, stripZeroTime) {
  997. if (stripZeroTime === void 0) { stripZeroTime = false; }
  998. var s = marker.toISOString();
  999. s = s.replace('.000', '');
  1000. if (stripZeroTime) {
  1001. s = s.replace('T00:00:00Z', '');
  1002. }
  1003. if (s.length > 10) { // time part wasn't stripped, can add timezone info
  1004. if (timeZoneOffset == null) {
  1005. s = s.replace('Z', '');
  1006. }
  1007. else if (timeZoneOffset !== 0) {
  1008. s = s.replace('Z', formatTimeZoneOffset(timeZoneOffset, true));
  1009. }
  1010. // otherwise, its UTC-0 and we want to keep the Z
  1011. }
  1012. return s;
  1013. }
  1014. // formats the date, but with no time part
  1015. // TODO: somehow merge with buildIsoString and stripZeroTime
  1016. // TODO: rename. omit "string"
  1017. function formatDayString(marker) {
  1018. return marker.toISOString().replace(/T.*$/, '');
  1019. }
  1020. // TODO: use Date::toISOString and use everything after the T?
  1021. function formatIsoTimeString(marker) {
  1022. return padStart(marker.getUTCHours(), 2) + ':' +
  1023. padStart(marker.getUTCMinutes(), 2) + ':' +
  1024. padStart(marker.getUTCSeconds(), 2);
  1025. }
  1026. function formatTimeZoneOffset(minutes, doIso) {
  1027. if (doIso === void 0) { doIso = false; }
  1028. var sign = minutes < 0 ? '-' : '+';
  1029. var abs = Math.abs(minutes);
  1030. var hours = Math.floor(abs / 60);
  1031. var mins = Math.round(abs % 60);
  1032. if (doIso) {
  1033. return sign + padStart(hours, 2) + ":" + padStart(mins, 2);
  1034. }
  1035. return "GMT" + sign + hours + (mins ? ":" + padStart(mins, 2) : '');
  1036. }
  1037. // TODO: new util arrayify?
  1038. function removeExact(array, exactVal) {
  1039. var removeCnt = 0;
  1040. var i = 0;
  1041. while (i < array.length) {
  1042. if (array[i] === exactVal) {
  1043. array.splice(i, 1);
  1044. removeCnt += 1;
  1045. }
  1046. else {
  1047. i += 1;
  1048. }
  1049. }
  1050. return removeCnt;
  1051. }
  1052. function isArraysEqual(a0, a1, equalityFunc) {
  1053. if (a0 === a1) {
  1054. return true;
  1055. }
  1056. var len = a0.length;
  1057. var i;
  1058. if (len !== a1.length) { // not array? or not same length?
  1059. return false;
  1060. }
  1061. for (i = 0; i < len; i += 1) {
  1062. if (!(equalityFunc ? equalityFunc(a0[i], a1[i]) : a0[i] === a1[i])) {
  1063. return false;
  1064. }
  1065. }
  1066. return true;
  1067. }
  1068. function memoize(workerFunc, resEquality, teardownFunc) {
  1069. var currentArgs;
  1070. var currentRes;
  1071. return function () {
  1072. var newArgs = [];
  1073. for (var _i = 0; _i < arguments.length; _i++) {
  1074. newArgs[_i] = arguments[_i];
  1075. }
  1076. if (!currentArgs) {
  1077. currentRes = workerFunc.apply(this, newArgs);
  1078. }
  1079. else if (!isArraysEqual(currentArgs, newArgs)) {
  1080. if (teardownFunc) {
  1081. teardownFunc(currentRes);
  1082. }
  1083. var res = workerFunc.apply(this, newArgs);
  1084. if (!resEquality || !resEquality(res, currentRes)) {
  1085. currentRes = res;
  1086. }
  1087. }
  1088. currentArgs = newArgs;
  1089. return currentRes;
  1090. };
  1091. }
  1092. function memoizeObjArg(workerFunc, resEquality, teardownFunc) {
  1093. var _this = this;
  1094. var currentArg;
  1095. var currentRes;
  1096. return function (newArg) {
  1097. if (!currentArg) {
  1098. currentRes = workerFunc.call(_this, newArg);
  1099. }
  1100. else if (!isPropsEqual(currentArg, newArg)) {
  1101. if (teardownFunc) {
  1102. teardownFunc(currentRes);
  1103. }
  1104. var res = workerFunc.call(_this, newArg);
  1105. if (!resEquality || !resEquality(res, currentRes)) {
  1106. currentRes = res;
  1107. }
  1108. }
  1109. currentArg = newArg;
  1110. return currentRes;
  1111. };
  1112. }
  1113. function memoizeArraylike(// used at all?
  1114. workerFunc, resEquality, teardownFunc) {
  1115. var _this = this;
  1116. var currentArgSets = [];
  1117. var currentResults = [];
  1118. return function (newArgSets) {
  1119. var currentLen = currentArgSets.length;
  1120. var newLen = newArgSets.length;
  1121. var i = 0;
  1122. for (; i < currentLen; i += 1) {
  1123. if (!newArgSets[i]) { // one of the old sets no longer exists
  1124. if (teardownFunc) {
  1125. teardownFunc(currentResults[i]);
  1126. }
  1127. }
  1128. else if (!isArraysEqual(currentArgSets[i], newArgSets[i])) {
  1129. if (teardownFunc) {
  1130. teardownFunc(currentResults[i]);
  1131. }
  1132. var res = workerFunc.apply(_this, newArgSets[i]);
  1133. if (!resEquality || !resEquality(res, currentResults[i])) {
  1134. currentResults[i] = res;
  1135. }
  1136. }
  1137. }
  1138. for (; i < newLen; i += 1) {
  1139. currentResults[i] = workerFunc.apply(_this, newArgSets[i]);
  1140. }
  1141. currentArgSets = newArgSets;
  1142. currentResults.splice(newLen); // remove excess
  1143. return currentResults;
  1144. };
  1145. }
  1146. function memoizeHashlike(// used?
  1147. workerFunc, resEquality, teardownFunc) {
  1148. var _this = this;
  1149. var currentArgHash = {};
  1150. var currentResHash = {};
  1151. return function (newArgHash) {
  1152. var newResHash = {};
  1153. for (var key in newArgHash) {
  1154. if (!currentResHash[key]) {
  1155. newResHash[key] = workerFunc.apply(_this, newArgHash[key]);
  1156. }
  1157. else if (!isArraysEqual(currentArgHash[key], newArgHash[key])) {
  1158. if (teardownFunc) {
  1159. teardownFunc(currentResHash[key]);
  1160. }
  1161. var res = workerFunc.apply(_this, newArgHash[key]);
  1162. newResHash[key] = (resEquality && resEquality(res, currentResHash[key]))
  1163. ? currentResHash[key]
  1164. : res;
  1165. }
  1166. else {
  1167. newResHash[key] = currentResHash[key];
  1168. }
  1169. }
  1170. currentArgHash = newArgHash;
  1171. currentResHash = newResHash;
  1172. return newResHash;
  1173. };
  1174. }
  1175. var EXTENDED_SETTINGS_AND_SEVERITIES = {
  1176. week: 3,
  1177. separator: 0,
  1178. omitZeroMinute: 0,
  1179. meridiem: 0,
  1180. omitCommas: 0,
  1181. };
  1182. var STANDARD_DATE_PROP_SEVERITIES = {
  1183. timeZoneName: 7,
  1184. era: 6,
  1185. year: 5,
  1186. month: 4,
  1187. day: 2,
  1188. weekday: 2,
  1189. hour: 1,
  1190. minute: 1,
  1191. second: 1,
  1192. };
  1193. var MERIDIEM_RE = /\s*([ap])\.?m\.?/i; // eats up leading spaces too
  1194. var COMMA_RE = /,/g; // we need re for globalness
  1195. var MULTI_SPACE_RE = /\s+/g;
  1196. var LTR_RE = /\u200e/g; // control character
  1197. var UTC_RE = /UTC|GMT/;
  1198. var NativeFormatter = /** @class */ (function () {
  1199. function NativeFormatter(formatSettings) {
  1200. var standardDateProps = {};
  1201. var extendedSettings = {};
  1202. var severity = 0;
  1203. for (var name_1 in formatSettings) {
  1204. if (name_1 in EXTENDED_SETTINGS_AND_SEVERITIES) {
  1205. extendedSettings[name_1] = formatSettings[name_1];
  1206. severity = Math.max(EXTENDED_SETTINGS_AND_SEVERITIES[name_1], severity);
  1207. }
  1208. else {
  1209. standardDateProps[name_1] = formatSettings[name_1];
  1210. if (name_1 in STANDARD_DATE_PROP_SEVERITIES) { // TODO: what about hour12? no severity
  1211. severity = Math.max(STANDARD_DATE_PROP_SEVERITIES[name_1], severity);
  1212. }
  1213. }
  1214. }
  1215. this.standardDateProps = standardDateProps;
  1216. this.extendedSettings = extendedSettings;
  1217. this.severity = severity;
  1218. this.buildFormattingFunc = memoize(buildFormattingFunc);
  1219. }
  1220. NativeFormatter.prototype.format = function (date, context) {
  1221. return this.buildFormattingFunc(this.standardDateProps, this.extendedSettings, context)(date);
  1222. };
  1223. NativeFormatter.prototype.formatRange = function (start, end, context, betterDefaultSeparator) {
  1224. var _a = this, standardDateProps = _a.standardDateProps, extendedSettings = _a.extendedSettings;
  1225. var diffSeverity = computeMarkerDiffSeverity(start.marker, end.marker, context.calendarSystem);
  1226. if (!diffSeverity) {
  1227. return this.format(start, context);
  1228. }
  1229. var biggestUnitForPartial = diffSeverity;
  1230. if (biggestUnitForPartial > 1 && // the two dates are different in a way that's larger scale than time
  1231. (standardDateProps.year === 'numeric' || standardDateProps.year === '2-digit') &&
  1232. (standardDateProps.month === 'numeric' || standardDateProps.month === '2-digit') &&
  1233. (standardDateProps.day === 'numeric' || standardDateProps.day === '2-digit')) {
  1234. biggestUnitForPartial = 1; // make it look like the dates are only different in terms of time
  1235. }
  1236. var full0 = this.format(start, context);
  1237. var full1 = this.format(end, context);
  1238. if (full0 === full1) {
  1239. return full0;
  1240. }
  1241. var partialDateProps = computePartialFormattingOptions(standardDateProps, biggestUnitForPartial);
  1242. var partialFormattingFunc = buildFormattingFunc(partialDateProps, extendedSettings, context);
  1243. var partial0 = partialFormattingFunc(start);
  1244. var partial1 = partialFormattingFunc(end);
  1245. var insertion = findCommonInsertion(full0, partial0, full1, partial1);
  1246. var separator = extendedSettings.separator || betterDefaultSeparator || context.defaultSeparator || '';
  1247. if (insertion) {
  1248. return insertion.before + partial0 + separator + partial1 + insertion.after;
  1249. }
  1250. return full0 + separator + full1;
  1251. };
  1252. NativeFormatter.prototype.getLargestUnit = function () {
  1253. switch (this.severity) {
  1254. case 7:
  1255. case 6:
  1256. case 5:
  1257. return 'year';
  1258. case 4:
  1259. return 'month';
  1260. case 3:
  1261. return 'week';
  1262. case 2:
  1263. return 'day';
  1264. default:
  1265. return 'time'; // really?
  1266. }
  1267. };
  1268. return NativeFormatter;
  1269. }());
  1270. function buildFormattingFunc(standardDateProps, extendedSettings, context) {
  1271. var standardDatePropCnt = Object.keys(standardDateProps).length;
  1272. if (standardDatePropCnt === 1 && standardDateProps.timeZoneName === 'short') {
  1273. return function (date) { return (formatTimeZoneOffset(date.timeZoneOffset)); };
  1274. }
  1275. if (standardDatePropCnt === 0 && extendedSettings.week) {
  1276. return function (date) { return (formatWeekNumber(context.computeWeekNumber(date.marker), context.weekText, context.locale, extendedSettings.week)); };
  1277. }
  1278. return buildNativeFormattingFunc(standardDateProps, extendedSettings, context);
  1279. }
  1280. function buildNativeFormattingFunc(standardDateProps, extendedSettings, context) {
  1281. standardDateProps = __assign({}, standardDateProps); // copy
  1282. extendedSettings = __assign({}, extendedSettings); // copy
  1283. sanitizeSettings(standardDateProps, extendedSettings);
  1284. standardDateProps.timeZone = 'UTC'; // we leverage the only guaranteed timeZone for our UTC markers
  1285. var normalFormat = new Intl.DateTimeFormat(context.locale.codes, standardDateProps);
  1286. var zeroFormat; // needed?
  1287. if (extendedSettings.omitZeroMinute) {
  1288. var zeroProps = __assign({}, standardDateProps);
  1289. delete zeroProps.minute; // seconds and ms were already considered in sanitizeSettings
  1290. zeroFormat = new Intl.DateTimeFormat(context.locale.codes, zeroProps);
  1291. }
  1292. return function (date) {
  1293. var marker = date.marker;
  1294. var format;
  1295. if (zeroFormat && !marker.getUTCMinutes()) {
  1296. format = zeroFormat;
  1297. }
  1298. else {
  1299. format = normalFormat;
  1300. }
  1301. var s = format.format(marker);
  1302. return postProcess(s, date, standardDateProps, extendedSettings, context);
  1303. };
  1304. }
  1305. function sanitizeSettings(standardDateProps, extendedSettings) {
  1306. // deal with a browser inconsistency where formatting the timezone
  1307. // requires that the hour/minute be present.
  1308. if (standardDateProps.timeZoneName) {
  1309. if (!standardDateProps.hour) {
  1310. standardDateProps.hour = '2-digit';
  1311. }
  1312. if (!standardDateProps.minute) {
  1313. standardDateProps.minute = '2-digit';
  1314. }
  1315. }
  1316. // only support short timezone names
  1317. if (standardDateProps.timeZoneName === 'long') {
  1318. standardDateProps.timeZoneName = 'short';
  1319. }
  1320. // if requesting to display seconds, MUST display minutes
  1321. if (extendedSettings.omitZeroMinute && (standardDateProps.second || standardDateProps.millisecond)) {
  1322. delete extendedSettings.omitZeroMinute;
  1323. }
  1324. }
  1325. function postProcess(s, date, standardDateProps, extendedSettings, context) {
  1326. s = s.replace(LTR_RE, ''); // remove left-to-right control chars. do first. good for other regexes
  1327. if (standardDateProps.timeZoneName === 'short') {
  1328. s = injectTzoStr(s, (context.timeZone === 'UTC' || date.timeZoneOffset == null) ?
  1329. 'UTC' : // important to normalize for IE, which does "GMT"
  1330. formatTimeZoneOffset(date.timeZoneOffset));
  1331. }
  1332. if (extendedSettings.omitCommas) {
  1333. s = s.replace(COMMA_RE, '').trim();
  1334. }
  1335. if (extendedSettings.omitZeroMinute) {
  1336. s = s.replace(':00', ''); // zeroFormat doesn't always achieve this
  1337. }
  1338. // ^ do anything that might create adjacent spaces before this point,
  1339. // because MERIDIEM_RE likes to eat up loading spaces
  1340. if (extendedSettings.meridiem === false) {
  1341. s = s.replace(MERIDIEM_RE, '').trim();
  1342. }
  1343. else if (extendedSettings.meridiem === 'narrow') { // a/p
  1344. s = s.replace(MERIDIEM_RE, function (m0, m1) { return m1.toLocaleLowerCase(); });
  1345. }
  1346. else if (extendedSettings.meridiem === 'short') { // am/pm
  1347. s = s.replace(MERIDIEM_RE, function (m0, m1) { return m1.toLocaleLowerCase() + "m"; });
  1348. }
  1349. else if (extendedSettings.meridiem === 'lowercase') { // other meridiem transformers already converted to lowercase
  1350. s = s.replace(MERIDIEM_RE, function (m0) { return m0.toLocaleLowerCase(); });
  1351. }
  1352. s = s.replace(MULTI_SPACE_RE, ' ');
  1353. s = s.trim();
  1354. return s;
  1355. }
  1356. function injectTzoStr(s, tzoStr) {
  1357. var replaced = false;
  1358. s = s.replace(UTC_RE, function () {
  1359. replaced = true;
  1360. return tzoStr;
  1361. });
  1362. // IE11 doesn't include UTC/GMT in the original string, so append to end
  1363. if (!replaced) {
  1364. s += " " + tzoStr;
  1365. }
  1366. return s;
  1367. }
  1368. function formatWeekNumber(num, weekText, locale, display) {
  1369. var parts = [];
  1370. if (display === 'narrow') {
  1371. parts.push(weekText);
  1372. }
  1373. else if (display === 'short') {
  1374. parts.push(weekText, ' ');
  1375. }
  1376. // otherwise, considered 'numeric'
  1377. parts.push(locale.simpleNumberFormat.format(num));
  1378. if (locale.options.direction === 'rtl') { // TODO: use control characters instead?
  1379. parts.reverse();
  1380. }
  1381. return parts.join('');
  1382. }
  1383. // Range Formatting Utils
  1384. // 0 = exactly the same
  1385. // 1 = different by time
  1386. // and bigger
  1387. function computeMarkerDiffSeverity(d0, d1, ca) {
  1388. if (ca.getMarkerYear(d0) !== ca.getMarkerYear(d1)) {
  1389. return 5;
  1390. }
  1391. if (ca.getMarkerMonth(d0) !== ca.getMarkerMonth(d1)) {
  1392. return 4;
  1393. }
  1394. if (ca.getMarkerDay(d0) !== ca.getMarkerDay(d1)) {
  1395. return 2;
  1396. }
  1397. if (timeAsMs(d0) !== timeAsMs(d1)) {
  1398. return 1;
  1399. }
  1400. return 0;
  1401. }
  1402. function computePartialFormattingOptions(options, biggestUnit) {
  1403. var partialOptions = {};
  1404. for (var name_2 in options) {
  1405. if (!(name_2 in STANDARD_DATE_PROP_SEVERITIES) || // not a date part prop (like timeZone)
  1406. STANDARD_DATE_PROP_SEVERITIES[name_2] <= biggestUnit) {
  1407. partialOptions[name_2] = options[name_2];
  1408. }
  1409. }
  1410. return partialOptions;
  1411. }
  1412. function findCommonInsertion(full0, partial0, full1, partial1) {
  1413. var i0 = 0;
  1414. while (i0 < full0.length) {
  1415. var found0 = full0.indexOf(partial0, i0);
  1416. if (found0 === -1) {
  1417. break;
  1418. }
  1419. var before0 = full0.substr(0, found0);
  1420. i0 = found0 + partial0.length;
  1421. var after0 = full0.substr(i0);
  1422. var i1 = 0;
  1423. while (i1 < full1.length) {
  1424. var found1 = full1.indexOf(partial1, i1);
  1425. if (found1 === -1) {
  1426. break;
  1427. }
  1428. var before1 = full1.substr(0, found1);
  1429. i1 = found1 + partial1.length;
  1430. var after1 = full1.substr(i1);
  1431. if (before0 === before1 && after0 === after1) {
  1432. return {
  1433. before: before0,
  1434. after: after0,
  1435. };
  1436. }
  1437. }
  1438. }
  1439. return null;
  1440. }
  1441. function expandZonedMarker(dateInfo, calendarSystem) {
  1442. var a = calendarSystem.markerToArray(dateInfo.marker);
  1443. return {
  1444. marker: dateInfo.marker,
  1445. timeZoneOffset: dateInfo.timeZoneOffset,
  1446. array: a,
  1447. year: a[0],
  1448. month: a[1],
  1449. day: a[2],
  1450. hour: a[3],
  1451. minute: a[4],
  1452. second: a[5],
  1453. millisecond: a[6],
  1454. };
  1455. }
  1456. function createVerboseFormattingArg(start, end, context, betterDefaultSeparator) {
  1457. var startInfo = expandZonedMarker(start, context.calendarSystem);
  1458. var endInfo = end ? expandZonedMarker(end, context.calendarSystem) : null;
  1459. return {
  1460. date: startInfo,
  1461. start: startInfo,
  1462. end: endInfo,
  1463. timeZone: context.timeZone,
  1464. localeCodes: context.locale.codes,
  1465. defaultSeparator: betterDefaultSeparator || context.defaultSeparator,
  1466. };
  1467. }
  1468. /*
  1469. TODO: fix the terminology of "formatter" vs "formatting func"
  1470. */
  1471. /*
  1472. At the time of instantiation, this object does not know which cmd-formatting system it will use.
  1473. It receives this at the time of formatting, as a setting.
  1474. */
  1475. var CmdFormatter = /** @class */ (function () {
  1476. function CmdFormatter(cmdStr) {
  1477. this.cmdStr = cmdStr;
  1478. }
  1479. CmdFormatter.prototype.format = function (date, context, betterDefaultSeparator) {
  1480. return context.cmdFormatter(this.cmdStr, createVerboseFormattingArg(date, null, context, betterDefaultSeparator));
  1481. };
  1482. CmdFormatter.prototype.formatRange = function (start, end, context, betterDefaultSeparator) {
  1483. return context.cmdFormatter(this.cmdStr, createVerboseFormattingArg(start, end, context, betterDefaultSeparator));
  1484. };
  1485. return CmdFormatter;
  1486. }());
  1487. var FuncFormatter = /** @class */ (function () {
  1488. function FuncFormatter(func) {
  1489. this.func = func;
  1490. }
  1491. FuncFormatter.prototype.format = function (date, context, betterDefaultSeparator) {
  1492. return this.func(createVerboseFormattingArg(date, null, context, betterDefaultSeparator));
  1493. };
  1494. FuncFormatter.prototype.formatRange = function (start, end, context, betterDefaultSeparator) {
  1495. return this.func(createVerboseFormattingArg(start, end, context, betterDefaultSeparator));
  1496. };
  1497. return FuncFormatter;
  1498. }());
  1499. function createFormatter(input) {
  1500. if (typeof input === 'object' && input) { // non-null object
  1501. return new NativeFormatter(input);
  1502. }
  1503. if (typeof input === 'string') {
  1504. return new CmdFormatter(input);
  1505. }
  1506. if (typeof input === 'function') {
  1507. return new FuncFormatter(input);
  1508. }
  1509. return null;
  1510. }
  1511. // base options
  1512. // ------------
  1513. var BASE_OPTION_REFINERS = {
  1514. navLinkDayClick: identity,
  1515. navLinkWeekClick: identity,
  1516. duration: createDuration,
  1517. bootstrapFontAwesome: identity,
  1518. buttonIcons: identity,
  1519. customButtons: identity,
  1520. defaultAllDayEventDuration: createDuration,
  1521. defaultTimedEventDuration: createDuration,
  1522. nextDayThreshold: createDuration,
  1523. scrollTime: createDuration,
  1524. scrollTimeReset: Boolean,
  1525. slotMinTime: createDuration,
  1526. slotMaxTime: createDuration,
  1527. dayPopoverFormat: createFormatter,
  1528. slotDuration: createDuration,
  1529. snapDuration: createDuration,
  1530. headerToolbar: identity,
  1531. footerToolbar: identity,
  1532. defaultRangeSeparator: String,
  1533. titleRangeSeparator: String,
  1534. forceEventDuration: Boolean,
  1535. dayHeaders: Boolean,
  1536. dayHeaderFormat: createFormatter,
  1537. dayHeaderClassNames: identity,
  1538. dayHeaderContent: identity,
  1539. dayHeaderDidMount: identity,
  1540. dayHeaderWillUnmount: identity,
  1541. dayCellClassNames: identity,
  1542. dayCellContent: identity,
  1543. dayCellDidMount: identity,
  1544. dayCellWillUnmount: identity,
  1545. initialView: String,
  1546. aspectRatio: Number,
  1547. weekends: Boolean,
  1548. weekNumberCalculation: identity,
  1549. weekNumbers: Boolean,
  1550. weekNumberClassNames: identity,
  1551. weekNumberContent: identity,
  1552. weekNumberDidMount: identity,
  1553. weekNumberWillUnmount: identity,
  1554. editable: Boolean,
  1555. viewClassNames: identity,
  1556. viewDidMount: identity,
  1557. viewWillUnmount: identity,
  1558. nowIndicator: Boolean,
  1559. nowIndicatorClassNames: identity,
  1560. nowIndicatorContent: identity,
  1561. nowIndicatorDidMount: identity,
  1562. nowIndicatorWillUnmount: identity,
  1563. showNonCurrentDates: Boolean,
  1564. lazyFetching: Boolean,
  1565. startParam: String,
  1566. endParam: String,
  1567. timeZoneParam: String,
  1568. timeZone: String,
  1569. locales: identity,
  1570. locale: identity,
  1571. themeSystem: String,
  1572. dragRevertDuration: Number,
  1573. dragScroll: Boolean,
  1574. allDayMaintainDuration: Boolean,
  1575. unselectAuto: Boolean,
  1576. dropAccept: identity,
  1577. eventOrder: parseFieldSpecs,
  1578. eventOrderStrict: Boolean,
  1579. handleWindowResize: Boolean,
  1580. windowResizeDelay: Number,
  1581. longPressDelay: Number,
  1582. eventDragMinDistance: Number,
  1583. expandRows: Boolean,
  1584. height: identity,
  1585. contentHeight: identity,
  1586. direction: String,
  1587. weekNumberFormat: createFormatter,
  1588. eventResizableFromStart: Boolean,
  1589. displayEventTime: Boolean,
  1590. displayEventEnd: Boolean,
  1591. weekText: String,
  1592. progressiveEventRendering: Boolean,
  1593. businessHours: identity,
  1594. initialDate: identity,
  1595. now: identity,
  1596. eventDataTransform: identity,
  1597. stickyHeaderDates: identity,
  1598. stickyFooterScrollbar: identity,
  1599. viewHeight: identity,
  1600. defaultAllDay: Boolean,
  1601. eventSourceFailure: identity,
  1602. eventSourceSuccess: identity,
  1603. eventDisplay: String,
  1604. eventStartEditable: Boolean,
  1605. eventDurationEditable: Boolean,
  1606. eventOverlap: identity,
  1607. eventConstraint: identity,
  1608. eventAllow: identity,
  1609. eventBackgroundColor: String,
  1610. eventBorderColor: String,
  1611. eventTextColor: String,
  1612. eventColor: String,
  1613. eventClassNames: identity,
  1614. eventContent: identity,
  1615. eventDidMount: identity,
  1616. eventWillUnmount: identity,
  1617. selectConstraint: identity,
  1618. selectOverlap: identity,
  1619. selectAllow: identity,
  1620. droppable: Boolean,
  1621. unselectCancel: String,
  1622. slotLabelFormat: identity,
  1623. slotLaneClassNames: identity,
  1624. slotLaneContent: identity,
  1625. slotLaneDidMount: identity,
  1626. slotLaneWillUnmount: identity,
  1627. slotLabelClassNames: identity,
  1628. slotLabelContent: identity,
  1629. slotLabelDidMount: identity,
  1630. slotLabelWillUnmount: identity,
  1631. dayMaxEvents: identity,
  1632. dayMaxEventRows: identity,
  1633. dayMinWidth: Number,
  1634. slotLabelInterval: createDuration,
  1635. allDayText: String,
  1636. allDayClassNames: identity,
  1637. allDayContent: identity,
  1638. allDayDidMount: identity,
  1639. allDayWillUnmount: identity,
  1640. slotMinWidth: Number,
  1641. navLinks: Boolean,
  1642. eventTimeFormat: createFormatter,
  1643. rerenderDelay: Number,
  1644. moreLinkText: identity,
  1645. selectMinDistance: Number,
  1646. selectable: Boolean,
  1647. selectLongPressDelay: Number,
  1648. eventLongPressDelay: Number,
  1649. selectMirror: Boolean,
  1650. eventMaxStack: Number,
  1651. eventMinHeight: Number,
  1652. eventMinWidth: Number,
  1653. eventShortHeight: Number,
  1654. slotEventOverlap: Boolean,
  1655. plugins: identity,
  1656. firstDay: Number,
  1657. dayCount: Number,
  1658. dateAlignment: String,
  1659. dateIncrement: createDuration,
  1660. hiddenDays: identity,
  1661. monthMode: Boolean,
  1662. fixedWeekCount: Boolean,
  1663. validRange: identity,
  1664. visibleRange: identity,
  1665. titleFormat: identity,
  1666. // only used by list-view, but languages define the value, so we need it in base options
  1667. noEventsText: String,
  1668. moreLinkClick: identity,
  1669. moreLinkClassNames: identity,
  1670. moreLinkContent: identity,
  1671. moreLinkDidMount: identity,
  1672. moreLinkWillUnmount: identity,
  1673. };
  1674. // do NOT give a type here. need `typeof BASE_OPTION_DEFAULTS` to give real results.
  1675. // raw values.
  1676. var BASE_OPTION_DEFAULTS = {
  1677. eventDisplay: 'auto',
  1678. defaultRangeSeparator: ' - ',
  1679. titleRangeSeparator: ' \u2013 ',
  1680. defaultTimedEventDuration: '01:00:00',
  1681. defaultAllDayEventDuration: { day: 1 },
  1682. forceEventDuration: false,
  1683. nextDayThreshold: '00:00:00',
  1684. dayHeaders: true,
  1685. initialView: '',
  1686. aspectRatio: 1.35,
  1687. headerToolbar: {
  1688. start: 'title',
  1689. center: '',
  1690. end: 'today prev,next',
  1691. },
  1692. weekends: true,
  1693. weekNumbers: false,
  1694. weekNumberCalculation: 'local',
  1695. editable: false,
  1696. nowIndicator: false,
  1697. scrollTime: '06:00:00',
  1698. scrollTimeReset: true,
  1699. slotMinTime: '00:00:00',
  1700. slotMaxTime: '24:00:00',
  1701. showNonCurrentDates: true,
  1702. lazyFetching: true,
  1703. startParam: 'start',
  1704. endParam: 'end',
  1705. timeZoneParam: 'timeZone',
  1706. timeZone: 'local',
  1707. locales: [],
  1708. locale: '',
  1709. themeSystem: 'standard',
  1710. dragRevertDuration: 500,
  1711. dragScroll: true,
  1712. allDayMaintainDuration: false,
  1713. unselectAuto: true,
  1714. dropAccept: '*',
  1715. eventOrder: 'start,-duration,allDay,title',
  1716. dayPopoverFormat: { month: 'long', day: 'numeric', year: 'numeric' },
  1717. handleWindowResize: true,
  1718. windowResizeDelay: 100,
  1719. longPressDelay: 1000,
  1720. eventDragMinDistance: 5,
  1721. expandRows: false,
  1722. navLinks: false,
  1723. selectable: false,
  1724. eventMinHeight: 15,
  1725. eventMinWidth: 30,
  1726. eventShortHeight: 30,
  1727. };
  1728. // calendar listeners
  1729. // ------------------
  1730. var CALENDAR_LISTENER_REFINERS = {
  1731. datesSet: identity,
  1732. eventsSet: identity,
  1733. eventAdd: identity,
  1734. eventChange: identity,
  1735. eventRemove: identity,
  1736. windowResize: identity,
  1737. eventClick: identity,
  1738. eventMouseEnter: identity,
  1739. eventMouseLeave: identity,
  1740. select: identity,
  1741. unselect: identity,
  1742. loading: identity,
  1743. // internal
  1744. _unmount: identity,
  1745. _beforeprint: identity,
  1746. _afterprint: identity,
  1747. _noEventDrop: identity,
  1748. _noEventResize: identity,
  1749. _resize: identity,
  1750. _scrollRequest: identity,
  1751. };
  1752. // calendar-specific options
  1753. // -------------------------
  1754. var CALENDAR_OPTION_REFINERS = {
  1755. buttonText: identity,
  1756. views: identity,
  1757. plugins: identity,
  1758. initialEvents: identity,
  1759. events: identity,
  1760. eventSources: identity,
  1761. };
  1762. var COMPLEX_OPTION_COMPARATORS = {
  1763. headerToolbar: isBoolComplexEqual,
  1764. footerToolbar: isBoolComplexEqual,
  1765. buttonText: isBoolComplexEqual,
  1766. buttonIcons: isBoolComplexEqual,
  1767. };
  1768. function isBoolComplexEqual(a, b) {
  1769. if (typeof a === 'object' && typeof b === 'object' && a && b) { // both non-null objects
  1770. return isPropsEqual(a, b);
  1771. }
  1772. return a === b;
  1773. }
  1774. // view-specific options
  1775. // ---------------------
  1776. var VIEW_OPTION_REFINERS = {
  1777. type: String,
  1778. component: identity,
  1779. buttonText: String,
  1780. buttonTextKey: String,
  1781. dateProfileGeneratorClass: identity,
  1782. usesMinMaxTime: Boolean,
  1783. classNames: identity,
  1784. content: identity,
  1785. didMount: identity,
  1786. willUnmount: identity,
  1787. };
  1788. // util funcs
  1789. // ----------------------------------------------------------------------------------------------------
  1790. function mergeRawOptions(optionSets) {
  1791. return mergeProps(optionSets, COMPLEX_OPTION_COMPARATORS);
  1792. }
  1793. function refineProps(input, refiners) {
  1794. var refined = {};
  1795. var extra = {};
  1796. for (var propName in refiners) {
  1797. if (propName in input) {
  1798. refined[propName] = refiners[propName](input[propName]);
  1799. }
  1800. }
  1801. for (var propName in input) {
  1802. if (!(propName in refiners)) {
  1803. extra[propName] = input[propName];
  1804. }
  1805. }
  1806. return { refined: refined, extra: extra };
  1807. }
  1808. function identity(raw) {
  1809. return raw;
  1810. }
  1811. function parseEvents(rawEvents, eventSource, context, allowOpenRange) {
  1812. var eventStore = createEmptyEventStore();
  1813. var eventRefiners = buildEventRefiners(context);
  1814. for (var _i = 0, rawEvents_1 = rawEvents; _i < rawEvents_1.length; _i++) {
  1815. var rawEvent = rawEvents_1[_i];
  1816. var tuple = parseEvent(rawEvent, eventSource, context, allowOpenRange, eventRefiners);
  1817. if (tuple) {
  1818. eventTupleToStore(tuple, eventStore);
  1819. }
  1820. }
  1821. return eventStore;
  1822. }
  1823. function eventTupleToStore(tuple, eventStore) {
  1824. if (eventStore === void 0) { eventStore = createEmptyEventStore(); }
  1825. eventStore.defs[tuple.def.defId] = tuple.def;
  1826. if (tuple.instance) {
  1827. eventStore.instances[tuple.instance.instanceId] = tuple.instance;
  1828. }
  1829. return eventStore;
  1830. }
  1831. // retrieves events that have the same groupId as the instance specified by `instanceId`
  1832. // or they are the same as the instance.
  1833. // why might instanceId not be in the store? an event from another calendar?
  1834. function getRelevantEvents(eventStore, instanceId) {
  1835. var instance = eventStore.instances[instanceId];
  1836. if (instance) {
  1837. var def_1 = eventStore.defs[instance.defId];
  1838. // get events/instances with same group
  1839. var newStore = filterEventStoreDefs(eventStore, function (lookDef) { return isEventDefsGrouped(def_1, lookDef); });
  1840. // add the original
  1841. // TODO: wish we could use eventTupleToStore or something like it
  1842. newStore.defs[def_1.defId] = def_1;
  1843. newStore.instances[instance.instanceId] = instance;
  1844. return newStore;
  1845. }
  1846. return createEmptyEventStore();
  1847. }
  1848. function isEventDefsGrouped(def0, def1) {
  1849. return Boolean(def0.groupId && def0.groupId === def1.groupId);
  1850. }
  1851. function createEmptyEventStore() {
  1852. return { defs: {}, instances: {} };
  1853. }
  1854. function mergeEventStores(store0, store1) {
  1855. return {
  1856. defs: __assign(__assign({}, store0.defs), store1.defs),
  1857. instances: __assign(__assign({}, store0.instances), store1.instances),
  1858. };
  1859. }
  1860. function filterEventStoreDefs(eventStore, filterFunc) {
  1861. var defs = filterHash(eventStore.defs, filterFunc);
  1862. var instances = filterHash(eventStore.instances, function (instance) { return (defs[instance.defId] // still exists?
  1863. ); });
  1864. return { defs: defs, instances: instances };
  1865. }
  1866. function excludeSubEventStore(master, sub) {
  1867. var defs = master.defs, instances = master.instances;
  1868. var filteredDefs = {};
  1869. var filteredInstances = {};
  1870. for (var defId in defs) {
  1871. if (!sub.defs[defId]) { // not explicitly excluded
  1872. filteredDefs[defId] = defs[defId];
  1873. }
  1874. }
  1875. for (var instanceId in instances) {
  1876. if (!sub.instances[instanceId] && // not explicitly excluded
  1877. filteredDefs[instances[instanceId].defId] // def wasn't filtered away
  1878. ) {
  1879. filteredInstances[instanceId] = instances[instanceId];
  1880. }
  1881. }
  1882. return {
  1883. defs: filteredDefs,
  1884. instances: filteredInstances,
  1885. };
  1886. }
  1887. function normalizeConstraint(input, context) {
  1888. if (Array.isArray(input)) {
  1889. return parseEvents(input, null, context, true); // allowOpenRange=true
  1890. }
  1891. if (typeof input === 'object' && input) { // non-null object
  1892. return parseEvents([input], null, context, true); // allowOpenRange=true
  1893. }
  1894. if (input != null) {
  1895. return String(input);
  1896. }
  1897. return null;
  1898. }
  1899. function parseClassNames(raw) {
  1900. if (Array.isArray(raw)) {
  1901. return raw;
  1902. }
  1903. if (typeof raw === 'string') {
  1904. return raw.split(/\s+/);
  1905. }
  1906. return [];
  1907. }
  1908. // TODO: better called "EventSettings" or "EventConfig"
  1909. // TODO: move this file into structs
  1910. // TODO: separate constraint/overlap/allow, because selection uses only that, not other props
  1911. var EVENT_UI_REFINERS = {
  1912. display: String,
  1913. editable: Boolean,
  1914. startEditable: Boolean,
  1915. durationEditable: Boolean,
  1916. constraint: identity,
  1917. overlap: identity,
  1918. allow: identity,
  1919. className: parseClassNames,
  1920. classNames: parseClassNames,
  1921. color: String,
  1922. backgroundColor: String,
  1923. borderColor: String,
  1924. textColor: String,
  1925. };
  1926. var EMPTY_EVENT_UI = {
  1927. display: null,
  1928. startEditable: null,
  1929. durationEditable: null,
  1930. constraints: [],
  1931. overlap: null,
  1932. allows: [],
  1933. backgroundColor: '',
  1934. borderColor: '',
  1935. textColor: '',
  1936. classNames: [],
  1937. };
  1938. function createEventUi(refined, context) {
  1939. var constraint = normalizeConstraint(refined.constraint, context);
  1940. return {
  1941. display: refined.display || null,
  1942. startEditable: refined.startEditable != null ? refined.startEditable : refined.editable,
  1943. durationEditable: refined.durationEditable != null ? refined.durationEditable : refined.editable,
  1944. constraints: constraint != null ? [constraint] : [],
  1945. overlap: refined.overlap != null ? refined.overlap : null,
  1946. allows: refined.allow != null ? [refined.allow] : [],
  1947. backgroundColor: refined.backgroundColor || refined.color || '',
  1948. borderColor: refined.borderColor || refined.color || '',
  1949. textColor: refined.textColor || '',
  1950. classNames: (refined.className || []).concat(refined.classNames || []), // join singular and plural
  1951. };
  1952. }
  1953. // TODO: prevent against problems with <2 args!
  1954. function combineEventUis(uis) {
  1955. return uis.reduce(combineTwoEventUis, EMPTY_EVENT_UI);
  1956. }
  1957. function combineTwoEventUis(item0, item1) {
  1958. return {
  1959. display: item1.display != null ? item1.display : item0.display,
  1960. startEditable: item1.startEditable != null ? item1.startEditable : item0.startEditable,
  1961. durationEditable: item1.durationEditable != null ? item1.durationEditable : item0.durationEditable,
  1962. constraints: item0.constraints.concat(item1.constraints),
  1963. overlap: typeof item1.overlap === 'boolean' ? item1.overlap : item0.overlap,
  1964. allows: item0.allows.concat(item1.allows),
  1965. backgroundColor: item1.backgroundColor || item0.backgroundColor,
  1966. borderColor: item1.borderColor || item0.borderColor,
  1967. textColor: item1.textColor || item0.textColor,
  1968. classNames: item0.classNames.concat(item1.classNames),
  1969. };
  1970. }
  1971. var EVENT_NON_DATE_REFINERS = {
  1972. id: String,
  1973. groupId: String,
  1974. title: String,
  1975. url: String,
  1976. };
  1977. var EVENT_DATE_REFINERS = {
  1978. start: identity,
  1979. end: identity,
  1980. date: identity,
  1981. allDay: Boolean,
  1982. };
  1983. var EVENT_REFINERS = __assign(__assign(__assign({}, EVENT_NON_DATE_REFINERS), EVENT_DATE_REFINERS), { extendedProps: identity });
  1984. function parseEvent(raw, eventSource, context, allowOpenRange, refiners) {
  1985. if (refiners === void 0) { refiners = buildEventRefiners(context); }
  1986. var _a = refineEventDef(raw, context, refiners), refined = _a.refined, extra = _a.extra;
  1987. var defaultAllDay = computeIsDefaultAllDay(eventSource, context);
  1988. var recurringRes = parseRecurring(refined, defaultAllDay, context.dateEnv, context.pluginHooks.recurringTypes);
  1989. if (recurringRes) {
  1990. var def = parseEventDef(refined, extra, eventSource ? eventSource.sourceId : '', recurringRes.allDay, Boolean(recurringRes.duration), context);
  1991. def.recurringDef = {
  1992. typeId: recurringRes.typeId,
  1993. typeData: recurringRes.typeData,
  1994. duration: recurringRes.duration,
  1995. };
  1996. return { def: def, instance: null };
  1997. }
  1998. var singleRes = parseSingle(refined, defaultAllDay, context, allowOpenRange);
  1999. if (singleRes) {
  2000. var def = parseEventDef(refined, extra, eventSource ? eventSource.sourceId : '', singleRes.allDay, singleRes.hasEnd, context);
  2001. var instance = createEventInstance(def.defId, singleRes.range, singleRes.forcedStartTzo, singleRes.forcedEndTzo);
  2002. return { def: def, instance: instance };
  2003. }
  2004. return null;
  2005. }
  2006. function refineEventDef(raw, context, refiners) {
  2007. if (refiners === void 0) { refiners = buildEventRefiners(context); }
  2008. return refineProps(raw, refiners);
  2009. }
  2010. function buildEventRefiners(context) {
  2011. return __assign(__assign(__assign({}, EVENT_UI_REFINERS), EVENT_REFINERS), context.pluginHooks.eventRefiners);
  2012. }
  2013. /*
  2014. Will NOT populate extendedProps with the leftover properties.
  2015. Will NOT populate date-related props.
  2016. */
  2017. function parseEventDef(refined, extra, sourceId, allDay, hasEnd, context) {
  2018. var def = {
  2019. title: refined.title || '',
  2020. groupId: refined.groupId || '',
  2021. publicId: refined.id || '',
  2022. url: refined.url || '',
  2023. recurringDef: null,
  2024. defId: guid(),
  2025. sourceId: sourceId,
  2026. allDay: allDay,
  2027. hasEnd: hasEnd,
  2028. ui: createEventUi(refined, context),
  2029. extendedProps: __assign(__assign({}, (refined.extendedProps || {})), extra),
  2030. };
  2031. for (var _i = 0, _a = context.pluginHooks.eventDefMemberAdders; _i < _a.length; _i++) {
  2032. var memberAdder = _a[_i];
  2033. __assign(def, memberAdder(refined));
  2034. }
  2035. // help out EventApi from having user modify props
  2036. Object.freeze(def.ui.classNames);
  2037. Object.freeze(def.extendedProps);
  2038. return def;
  2039. }
  2040. function parseSingle(refined, defaultAllDay, context, allowOpenRange) {
  2041. var allDay = refined.allDay;
  2042. var startMeta;
  2043. var startMarker = null;
  2044. var hasEnd = false;
  2045. var endMeta;
  2046. var endMarker = null;
  2047. var startInput = refined.start != null ? refined.start : refined.date;
  2048. startMeta = context.dateEnv.createMarkerMeta(startInput);
  2049. if (startMeta) {
  2050. startMarker = startMeta.marker;
  2051. }
  2052. else if (!allowOpenRange) {
  2053. return null;
  2054. }
  2055. if (refined.end != null) {
  2056. endMeta = context.dateEnv.createMarkerMeta(refined.end);
  2057. }
  2058. if (allDay == null) {
  2059. if (defaultAllDay != null) {
  2060. allDay = defaultAllDay;
  2061. }
  2062. else {
  2063. // fall back to the date props LAST
  2064. allDay = (!startMeta || startMeta.isTimeUnspecified) &&
  2065. (!endMeta || endMeta.isTimeUnspecified);
  2066. }
  2067. }
  2068. if (allDay && startMarker) {
  2069. startMarker = startOfDay(startMarker);
  2070. }
  2071. if (endMeta) {
  2072. endMarker = endMeta.marker;
  2073. if (allDay) {
  2074. endMarker = startOfDay(endMarker);
  2075. }
  2076. if (startMarker && endMarker <= startMarker) {
  2077. endMarker = null;
  2078. }
  2079. }
  2080. if (endMarker) {
  2081. hasEnd = true;
  2082. }
  2083. else if (!allowOpenRange) {
  2084. hasEnd = context.options.forceEventDuration || false;
  2085. endMarker = context.dateEnv.add(startMarker, allDay ?
  2086. context.options.defaultAllDayEventDuration :
  2087. context.options.defaultTimedEventDuration);
  2088. }
  2089. return {
  2090. allDay: allDay,
  2091. hasEnd: hasEnd,
  2092. range: { start: startMarker, end: endMarker },
  2093. forcedStartTzo: startMeta ? startMeta.forcedTzo : null,
  2094. forcedEndTzo: endMeta ? endMeta.forcedTzo : null,
  2095. };
  2096. }
  2097. function computeIsDefaultAllDay(eventSource, context) {
  2098. var res = null;
  2099. if (eventSource) {
  2100. res = eventSource.defaultAllDay;
  2101. }
  2102. if (res == null) {
  2103. res = context.options.defaultAllDay;
  2104. }
  2105. return res;
  2106. }
  2107. /* Date stuff that doesn't belong in datelib core
  2108. ----------------------------------------------------------------------------------------------------------------------*/
  2109. // given a timed range, computes an all-day range that has the same exact duration,
  2110. // but whose start time is aligned with the start of the day.
  2111. function computeAlignedDayRange(timedRange) {
  2112. var dayCnt = Math.floor(diffDays(timedRange.start, timedRange.end)) || 1;
  2113. var start = startOfDay(timedRange.start);
  2114. var end = addDays(start, dayCnt);
  2115. return { start: start, end: end };
  2116. }
  2117. // given a timed range, computes an all-day range based on how for the end date bleeds into the next day
  2118. // TODO: give nextDayThreshold a default arg
  2119. function computeVisibleDayRange(timedRange, nextDayThreshold) {
  2120. if (nextDayThreshold === void 0) { nextDayThreshold = createDuration(0); }
  2121. var startDay = null;
  2122. var endDay = null;
  2123. if (timedRange.end) {
  2124. endDay = startOfDay(timedRange.end);
  2125. var endTimeMS = timedRange.end.valueOf() - endDay.valueOf(); // # of milliseconds into `endDay`
  2126. // If the end time is actually inclusively part of the next day and is equal to or
  2127. // beyond the next day threshold, adjust the end to be the exclusive end of `endDay`.
  2128. // Otherwise, leaving it as inclusive will cause it to exclude `endDay`.
  2129. if (endTimeMS && endTimeMS >= asRoughMs(nextDayThreshold)) {
  2130. endDay = addDays(endDay, 1);
  2131. }
  2132. }
  2133. if (timedRange.start) {
  2134. startDay = startOfDay(timedRange.start); // the beginning of the day the range starts
  2135. // If end is within `startDay` but not past nextDayThreshold, assign the default duration of one day.
  2136. if (endDay && endDay <= startDay) {
  2137. endDay = addDays(startDay, 1);
  2138. }
  2139. }
  2140. return { start: startDay, end: endDay };
  2141. }
  2142. // spans from one day into another?
  2143. function isMultiDayRange(range) {
  2144. var visibleRange = computeVisibleDayRange(range);
  2145. return diffDays(visibleRange.start, visibleRange.end) > 1;
  2146. }
  2147. function diffDates(date0, date1, dateEnv, largeUnit) {
  2148. if (largeUnit === 'year') {
  2149. return createDuration(dateEnv.diffWholeYears(date0, date1), 'year');
  2150. }
  2151. if (largeUnit === 'month') {
  2152. return createDuration(dateEnv.diffWholeMonths(date0, date1), 'month');
  2153. }
  2154. return diffDayAndTime(date0, date1); // returns a duration
  2155. }
  2156. function parseRange(input, dateEnv) {
  2157. var start = null;
  2158. var end = null;
  2159. if (input.start) {
  2160. start = dateEnv.createMarker(input.start);
  2161. }
  2162. if (input.end) {
  2163. end = dateEnv.createMarker(input.end);
  2164. }
  2165. if (!start && !end) {
  2166. return null;
  2167. }
  2168. if (start && end && end < start) {
  2169. return null;
  2170. }
  2171. return { start: start, end: end };
  2172. }
  2173. // SIDE-EFFECT: will mutate ranges.
  2174. // Will return a new array result.
  2175. function invertRanges(ranges, constraintRange) {
  2176. var invertedRanges = [];
  2177. var start = constraintRange.start; // the end of the previous range. the start of the new range
  2178. var i;
  2179. var dateRange;
  2180. // ranges need to be in order. required for our date-walking algorithm
  2181. ranges.sort(compareRanges);
  2182. for (i = 0; i < ranges.length; i += 1) {
  2183. dateRange = ranges[i];
  2184. // add the span of time before the event (if there is any)
  2185. if (dateRange.start > start) { // compare millisecond time (skip any ambig logic)
  2186. invertedRanges.push({ start: start, end: dateRange.start });
  2187. }
  2188. if (dateRange.end > start) {
  2189. start = dateRange.end;
  2190. }
  2191. }
  2192. // add the span of time after the last event (if there is any)
  2193. if (start < constraintRange.end) { // compare millisecond time (skip any ambig logic)
  2194. invertedRanges.push({ start: start, end: constraintRange.end });
  2195. }
  2196. return invertedRanges;
  2197. }
  2198. function compareRanges(range0, range1) {
  2199. return range0.start.valueOf() - range1.start.valueOf(); // earlier ranges go first
  2200. }
  2201. function intersectRanges(range0, range1) {
  2202. var start = range0.start, end = range0.end;
  2203. var newRange = null;
  2204. if (range1.start !== null) {
  2205. if (start === null) {
  2206. start = range1.start;
  2207. }
  2208. else {
  2209. start = new Date(Math.max(start.valueOf(), range1.start.valueOf()));
  2210. }
  2211. }
  2212. if (range1.end != null) {
  2213. if (end === null) {
  2214. end = range1.end;
  2215. }
  2216. else {
  2217. end = new Date(Math.min(end.valueOf(), range1.end.valueOf()));
  2218. }
  2219. }
  2220. if (start === null || end === null || start < end) {
  2221. newRange = { start: start, end: end };
  2222. }
  2223. return newRange;
  2224. }
  2225. function rangesEqual(range0, range1) {
  2226. return (range0.start === null ? null : range0.start.valueOf()) === (range1.start === null ? null : range1.start.valueOf()) &&
  2227. (range0.end === null ? null : range0.end.valueOf()) === (range1.end === null ? null : range1.end.valueOf());
  2228. }
  2229. function rangesIntersect(range0, range1) {
  2230. return (range0.end === null || range1.start === null || range0.end > range1.start) &&
  2231. (range0.start === null || range1.end === null || range0.start < range1.end);
  2232. }
  2233. function rangeContainsRange(outerRange, innerRange) {
  2234. return (outerRange.start === null || (innerRange.start !== null && innerRange.start >= outerRange.start)) &&
  2235. (outerRange.end === null || (innerRange.end !== null && innerRange.end <= outerRange.end));
  2236. }
  2237. function rangeContainsMarker(range, date) {
  2238. return (range.start === null || date >= range.start) &&
  2239. (range.end === null || date < range.end);
  2240. }
  2241. // If the given date is not within the given range, move it inside.
  2242. // (If it's past the end, make it one millisecond before the end).
  2243. function constrainMarkerToRange(date, range) {
  2244. if (range.start != null && date < range.start) {
  2245. return range.start;
  2246. }
  2247. if (range.end != null && date >= range.end) {
  2248. return new Date(range.end.valueOf() - 1);
  2249. }
  2250. return date;
  2251. }
  2252. /*
  2253. Specifying nextDayThreshold signals that all-day ranges should be sliced.
  2254. */
  2255. function sliceEventStore(eventStore, eventUiBases, framingRange, nextDayThreshold) {
  2256. var inverseBgByGroupId = {};
  2257. var inverseBgByDefId = {};
  2258. var defByGroupId = {};
  2259. var bgRanges = [];
  2260. var fgRanges = [];
  2261. var eventUis = compileEventUis(eventStore.defs, eventUiBases);
  2262. for (var defId in eventStore.defs) {
  2263. var def = eventStore.defs[defId];
  2264. var ui = eventUis[def.defId];
  2265. if (ui.display === 'inverse-background') {
  2266. if (def.groupId) {
  2267. inverseBgByGroupId[def.groupId] = [];
  2268. if (!defByGroupId[def.groupId]) {
  2269. defByGroupId[def.groupId] = def;
  2270. }
  2271. }
  2272. else {
  2273. inverseBgByDefId[defId] = [];
  2274. }
  2275. }
  2276. }
  2277. for (var instanceId in eventStore.instances) {
  2278. var instance = eventStore.instances[instanceId];
  2279. var def = eventStore.defs[instance.defId];
  2280. var ui = eventUis[def.defId];
  2281. var origRange = instance.range;
  2282. var normalRange = (!def.allDay && nextDayThreshold) ?
  2283. computeVisibleDayRange(origRange, nextDayThreshold) :
  2284. origRange;
  2285. var slicedRange = intersectRanges(normalRange, framingRange);
  2286. if (slicedRange) {
  2287. if (ui.display === 'inverse-background') {
  2288. if (def.groupId) {
  2289. inverseBgByGroupId[def.groupId].push(slicedRange);
  2290. }
  2291. else {
  2292. inverseBgByDefId[instance.defId].push(slicedRange);
  2293. }
  2294. }
  2295. else if (ui.display !== 'none') {
  2296. (ui.display === 'background' ? bgRanges : fgRanges).push({
  2297. def: def,
  2298. ui: ui,
  2299. instance: instance,
  2300. range: slicedRange,
  2301. isStart: normalRange.start && normalRange.start.valueOf() === slicedRange.start.valueOf(),
  2302. isEnd: normalRange.end && normalRange.end.valueOf() === slicedRange.end.valueOf(),
  2303. });
  2304. }
  2305. }
  2306. }
  2307. for (var groupId in inverseBgByGroupId) { // BY GROUP
  2308. var ranges = inverseBgByGroupId[groupId];
  2309. var invertedRanges = invertRanges(ranges, framingRange);
  2310. for (var _i = 0, invertedRanges_1 = invertedRanges; _i < invertedRanges_1.length; _i++) {
  2311. var invertedRange = invertedRanges_1[_i];
  2312. var def = defByGroupId[groupId];
  2313. var ui = eventUis[def.defId];
  2314. bgRanges.push({
  2315. def: def,
  2316. ui: ui,
  2317. instance: null,
  2318. range: invertedRange,
  2319. isStart: false,
  2320. isEnd: false,
  2321. });
  2322. }
  2323. }
  2324. for (var defId in inverseBgByDefId) {
  2325. var ranges = inverseBgByDefId[defId];
  2326. var invertedRanges = invertRanges(ranges, framingRange);
  2327. for (var _a = 0, invertedRanges_2 = invertedRanges; _a < invertedRanges_2.length; _a++) {
  2328. var invertedRange = invertedRanges_2[_a];
  2329. bgRanges.push({
  2330. def: eventStore.defs[defId],
  2331. ui: eventUis[defId],
  2332. instance: null,
  2333. range: invertedRange,
  2334. isStart: false,
  2335. isEnd: false,
  2336. });
  2337. }
  2338. }
  2339. return { bg: bgRanges, fg: fgRanges };
  2340. }
  2341. function hasBgRendering(def) {
  2342. return def.ui.display === 'background' || def.ui.display === 'inverse-background';
  2343. }
  2344. function setElSeg(el, seg) {
  2345. el.fcSeg = seg;
  2346. }
  2347. function getElSeg(el) {
  2348. return el.fcSeg ||
  2349. el.parentNode.fcSeg || // for the harness
  2350. null;
  2351. }
  2352. // event ui computation
  2353. function compileEventUis(eventDefs, eventUiBases) {
  2354. return mapHash(eventDefs, function (eventDef) { return compileEventUi(eventDef, eventUiBases); });
  2355. }
  2356. function compileEventUi(eventDef, eventUiBases) {
  2357. var uis = [];
  2358. if (eventUiBases['']) {
  2359. uis.push(eventUiBases['']);
  2360. }
  2361. if (eventUiBases[eventDef.defId]) {
  2362. uis.push(eventUiBases[eventDef.defId]);
  2363. }
  2364. uis.push(eventDef.ui);
  2365. return combineEventUis(uis);
  2366. }
  2367. function sortEventSegs(segs, eventOrderSpecs) {
  2368. var objs = segs.map(buildSegCompareObj);
  2369. objs.sort(function (obj0, obj1) { return compareByFieldSpecs(obj0, obj1, eventOrderSpecs); });
  2370. return objs.map(function (c) { return c._seg; });
  2371. }
  2372. // returns a object with all primitive props that can be compared
  2373. function buildSegCompareObj(seg) {
  2374. var eventRange = seg.eventRange;
  2375. var eventDef = eventRange.def;
  2376. var range = eventRange.instance ? eventRange.instance.range : eventRange.range;
  2377. var start = range.start ? range.start.valueOf() : 0; // TODO: better support for open-range events
  2378. var end = range.end ? range.end.valueOf() : 0; // "
  2379. return __assign(__assign(__assign({}, eventDef.extendedProps), eventDef), { id: eventDef.publicId, start: start,
  2380. end: end, duration: end - start, allDay: Number(eventDef.allDay), _seg: seg });
  2381. }
  2382. function computeSegDraggable(seg, context) {
  2383. var pluginHooks = context.pluginHooks;
  2384. var transformers = pluginHooks.isDraggableTransformers;
  2385. var _a = seg.eventRange, def = _a.def, ui = _a.ui;
  2386. var val = ui.startEditable;
  2387. for (var _i = 0, transformers_1 = transformers; _i < transformers_1.length; _i++) {
  2388. var transformer = transformers_1[_i];
  2389. val = transformer(val, def, ui, context);
  2390. }
  2391. return val;
  2392. }
  2393. function computeSegStartResizable(seg, context) {
  2394. return seg.isStart && seg.eventRange.ui.durationEditable && context.options.eventResizableFromStart;
  2395. }
  2396. function computeSegEndResizable(seg, context) {
  2397. return seg.isEnd && seg.eventRange.ui.durationEditable;
  2398. }
  2399. function buildSegTimeText(seg, timeFormat, context, defaultDisplayEventTime, // defaults to true
  2400. defaultDisplayEventEnd, // defaults to true
  2401. startOverride, endOverride) {
  2402. var dateEnv = context.dateEnv, options = context.options;
  2403. var displayEventTime = options.displayEventTime, displayEventEnd = options.displayEventEnd;
  2404. var eventDef = seg.eventRange.def;
  2405. var eventInstance = seg.eventRange.instance;
  2406. if (displayEventTime == null) {
  2407. displayEventTime = defaultDisplayEventTime !== false;
  2408. }
  2409. if (displayEventEnd == null) {
  2410. displayEventEnd = defaultDisplayEventEnd !== false;
  2411. }
  2412. var wholeEventStart = eventInstance.range.start;
  2413. var wholeEventEnd = eventInstance.range.end;
  2414. var segStart = startOverride || seg.start || seg.eventRange.range.start;
  2415. var segEnd = endOverride || seg.end || seg.eventRange.range.end;
  2416. var isStartDay = startOfDay(wholeEventStart).valueOf() === startOfDay(segStart).valueOf();
  2417. var isEndDay = startOfDay(addMs(wholeEventEnd, -1)).valueOf() === startOfDay(addMs(segEnd, -1)).valueOf();
  2418. if (displayEventTime && !eventDef.allDay && (isStartDay || isEndDay)) {
  2419. segStart = isStartDay ? wholeEventStart : segStart;
  2420. segEnd = isEndDay ? wholeEventEnd : segEnd;
  2421. if (displayEventEnd && eventDef.hasEnd) {
  2422. return dateEnv.formatRange(segStart, segEnd, timeFormat, {
  2423. forcedStartTzo: startOverride ? null : eventInstance.forcedStartTzo,
  2424. forcedEndTzo: endOverride ? null : eventInstance.forcedEndTzo,
  2425. });
  2426. }
  2427. return dateEnv.format(segStart, timeFormat, {
  2428. forcedTzo: startOverride ? null : eventInstance.forcedStartTzo, // nooooo, same
  2429. });
  2430. }
  2431. return '';
  2432. }
  2433. function getSegMeta(seg, todayRange, nowDate) {
  2434. var segRange = seg.eventRange.range;
  2435. return {
  2436. isPast: segRange.end < (nowDate || todayRange.start),
  2437. isFuture: segRange.start >= (nowDate || todayRange.end),
  2438. isToday: todayRange && rangeContainsMarker(todayRange, segRange.start),
  2439. };
  2440. }
  2441. function getEventClassNames(props) {
  2442. var classNames = ['fc-event'];
  2443. if (props.isMirror) {
  2444. classNames.push('fc-event-mirror');
  2445. }
  2446. if (props.isDraggable) {
  2447. classNames.push('fc-event-draggable');
  2448. }
  2449. if (props.isStartResizable || props.isEndResizable) {
  2450. classNames.push('fc-event-resizable');
  2451. }
  2452. if (props.isDragging) {
  2453. classNames.push('fc-event-dragging');
  2454. }
  2455. if (props.isResizing) {
  2456. classNames.push('fc-event-resizing');
  2457. }
  2458. if (props.isSelected) {
  2459. classNames.push('fc-event-selected');
  2460. }
  2461. if (props.isStart) {
  2462. classNames.push('fc-event-start');
  2463. }
  2464. if (props.isEnd) {
  2465. classNames.push('fc-event-end');
  2466. }
  2467. if (props.isPast) {
  2468. classNames.push('fc-event-past');
  2469. }
  2470. if (props.isToday) {
  2471. classNames.push('fc-event-today');
  2472. }
  2473. if (props.isFuture) {
  2474. classNames.push('fc-event-future');
  2475. }
  2476. return classNames;
  2477. }
  2478. function buildEventRangeKey(eventRange) {
  2479. return eventRange.instance
  2480. ? eventRange.instance.instanceId
  2481. : eventRange.def.defId + ":" + eventRange.range.start.toISOString();
  2482. // inverse-background events don't have specific instances. TODO: better solution
  2483. }
  2484. var STANDARD_PROPS = {
  2485. start: identity,
  2486. end: identity,
  2487. allDay: Boolean,
  2488. };
  2489. function parseDateSpan(raw, dateEnv, defaultDuration) {
  2490. var span = parseOpenDateSpan(raw, dateEnv);
  2491. var range = span.range;
  2492. if (!range.start) {
  2493. return null;
  2494. }
  2495. if (!range.end) {
  2496. if (defaultDuration == null) {
  2497. return null;
  2498. }
  2499. range.end = dateEnv.add(range.start, defaultDuration);
  2500. }
  2501. return span;
  2502. }
  2503. /*
  2504. TODO: somehow combine with parseRange?
  2505. Will return null if the start/end props were present but parsed invalidly.
  2506. */
  2507. function parseOpenDateSpan(raw, dateEnv) {
  2508. var _a = refineProps(raw, STANDARD_PROPS), standardProps = _a.refined, extra = _a.extra;
  2509. var startMeta = standardProps.start ? dateEnv.createMarkerMeta(standardProps.start) : null;
  2510. var endMeta = standardProps.end ? dateEnv.createMarkerMeta(standardProps.end) : null;
  2511. var allDay = standardProps.allDay;
  2512. if (allDay == null) {
  2513. allDay = (startMeta && startMeta.isTimeUnspecified) &&
  2514. (!endMeta || endMeta.isTimeUnspecified);
  2515. }
  2516. return __assign({ range: {
  2517. start: startMeta ? startMeta.marker : null,
  2518. end: endMeta ? endMeta.marker : null,
  2519. }, allDay: allDay }, extra);
  2520. }
  2521. function isDateSpansEqual(span0, span1) {
  2522. return rangesEqual(span0.range, span1.range) &&
  2523. span0.allDay === span1.allDay &&
  2524. isSpanPropsEqual(span0, span1);
  2525. }
  2526. // the NON-DATE-RELATED props
  2527. function isSpanPropsEqual(span0, span1) {
  2528. for (var propName in span1) {
  2529. if (propName !== 'range' && propName !== 'allDay') {
  2530. if (span0[propName] !== span1[propName]) {
  2531. return false;
  2532. }
  2533. }
  2534. }
  2535. // are there any props that span0 has that span1 DOESN'T have?
  2536. // both have range/allDay, so no need to special-case.
  2537. for (var propName in span0) {
  2538. if (!(propName in span1)) {
  2539. return false;
  2540. }
  2541. }
  2542. return true;
  2543. }
  2544. function buildDateSpanApi(span, dateEnv) {
  2545. return __assign(__assign({}, buildRangeApi(span.range, dateEnv, span.allDay)), { allDay: span.allDay });
  2546. }
  2547. function buildRangeApiWithTimeZone(range, dateEnv, omitTime) {
  2548. return __assign(__assign({}, buildRangeApi(range, dateEnv, omitTime)), { timeZone: dateEnv.timeZone });
  2549. }
  2550. function buildRangeApi(range, dateEnv, omitTime) {
  2551. return {
  2552. start: dateEnv.toDate(range.start),
  2553. end: dateEnv.toDate(range.end),
  2554. startStr: dateEnv.formatIso(range.start, { omitTime: omitTime }),
  2555. endStr: dateEnv.formatIso(range.end, { omitTime: omitTime }),
  2556. };
  2557. }
  2558. function fabricateEventRange(dateSpan, eventUiBases, context) {
  2559. var res = refineEventDef({ editable: false }, context);
  2560. var def = parseEventDef(res.refined, res.extra, '', // sourceId
  2561. dateSpan.allDay, true, // hasEnd
  2562. context);
  2563. return {
  2564. def: def,
  2565. ui: compileEventUi(def, eventUiBases),
  2566. instance: createEventInstance(def.defId, dateSpan.range),
  2567. range: dateSpan.range,
  2568. isStart: true,
  2569. isEnd: true,
  2570. };
  2571. }
  2572. function triggerDateSelect(selection, pev, context) {
  2573. context.emitter.trigger('select', __assign(__assign({}, buildDateSpanApiWithContext(selection, context)), { jsEvent: pev ? pev.origEvent : null, view: context.viewApi || context.calendarApi.view }));
  2574. }
  2575. function triggerDateUnselect(pev, context) {
  2576. context.emitter.trigger('unselect', {
  2577. jsEvent: pev ? pev.origEvent : null,
  2578. view: context.viewApi || context.calendarApi.view,
  2579. });
  2580. }
  2581. function buildDateSpanApiWithContext(dateSpan, context) {
  2582. var props = {};
  2583. for (var _i = 0, _a = context.pluginHooks.dateSpanTransforms; _i < _a.length; _i++) {
  2584. var transform = _a[_i];
  2585. __assign(props, transform(dateSpan, context));
  2586. }
  2587. __assign(props, buildDateSpanApi(dateSpan, context.dateEnv));
  2588. return props;
  2589. }
  2590. // Given an event's allDay status and start date, return what its fallback end date should be.
  2591. // TODO: rename to computeDefaultEventEnd
  2592. function getDefaultEventEnd(allDay, marker, context) {
  2593. var dateEnv = context.dateEnv, options = context.options;
  2594. var end = marker;
  2595. if (allDay) {
  2596. end = startOfDay(end);
  2597. end = dateEnv.add(end, options.defaultAllDayEventDuration);
  2598. }
  2599. else {
  2600. end = dateEnv.add(end, options.defaultTimedEventDuration);
  2601. }
  2602. return end;
  2603. }
  2604. // applies the mutation to ALL defs/instances within the event store
  2605. function applyMutationToEventStore(eventStore, eventConfigBase, mutation, context) {
  2606. var eventConfigs = compileEventUis(eventStore.defs, eventConfigBase);
  2607. var dest = createEmptyEventStore();
  2608. for (var defId in eventStore.defs) {
  2609. var def = eventStore.defs[defId];
  2610. dest.defs[defId] = applyMutationToEventDef(def, eventConfigs[defId], mutation, context);
  2611. }
  2612. for (var instanceId in eventStore.instances) {
  2613. var instance = eventStore.instances[instanceId];
  2614. var def = dest.defs[instance.defId]; // important to grab the newly modified def
  2615. dest.instances[instanceId] = applyMutationToEventInstance(instance, def, eventConfigs[instance.defId], mutation, context);
  2616. }
  2617. return dest;
  2618. }
  2619. function applyMutationToEventDef(eventDef, eventConfig, mutation, context) {
  2620. var standardProps = mutation.standardProps || {};
  2621. // if hasEnd has not been specified, guess a good value based on deltas.
  2622. // if duration will change, there's no way the default duration will persist,
  2623. // and thus, we need to mark the event as having a real end
  2624. if (standardProps.hasEnd == null &&
  2625. eventConfig.durationEditable &&
  2626. (mutation.startDelta || mutation.endDelta)) {
  2627. standardProps.hasEnd = true; // TODO: is this mutation okay?
  2628. }
  2629. var copy = __assign(__assign(__assign({}, eventDef), standardProps), { ui: __assign(__assign({}, eventDef.ui), standardProps.ui) });
  2630. if (mutation.extendedProps) {
  2631. copy.extendedProps = __assign(__assign({}, copy.extendedProps), mutation.extendedProps);
  2632. }
  2633. for (var _i = 0, _a = context.pluginHooks.eventDefMutationAppliers; _i < _a.length; _i++) {
  2634. var applier = _a[_i];
  2635. applier(copy, mutation, context);
  2636. }
  2637. if (!copy.hasEnd && context.options.forceEventDuration) {
  2638. copy.hasEnd = true;
  2639. }
  2640. return copy;
  2641. }
  2642. function applyMutationToEventInstance(eventInstance, eventDef, // must first be modified by applyMutationToEventDef
  2643. eventConfig, mutation, context) {
  2644. var dateEnv = context.dateEnv;
  2645. var forceAllDay = mutation.standardProps && mutation.standardProps.allDay === true;
  2646. var clearEnd = mutation.standardProps && mutation.standardProps.hasEnd === false;
  2647. var copy = __assign({}, eventInstance);
  2648. if (forceAllDay) {
  2649. copy.range = computeAlignedDayRange(copy.range);
  2650. }
  2651. if (mutation.datesDelta && eventConfig.startEditable) {
  2652. copy.range = {
  2653. start: dateEnv.add(copy.range.start, mutation.datesDelta),
  2654. end: dateEnv.add(copy.range.end, mutation.datesDelta),
  2655. };
  2656. }
  2657. if (mutation.startDelta && eventConfig.durationEditable) {
  2658. copy.range = {
  2659. start: dateEnv.add(copy.range.start, mutation.startDelta),
  2660. end: copy.range.end,
  2661. };
  2662. }
  2663. if (mutation.endDelta && eventConfig.durationEditable) {
  2664. copy.range = {
  2665. start: copy.range.start,
  2666. end: dateEnv.add(copy.range.end, mutation.endDelta),
  2667. };
  2668. }
  2669. if (clearEnd) {
  2670. copy.range = {
  2671. start: copy.range.start,
  2672. end: getDefaultEventEnd(eventDef.allDay, copy.range.start, context),
  2673. };
  2674. }
  2675. // in case event was all-day but the supplied deltas were not
  2676. // better util for this?
  2677. if (eventDef.allDay) {
  2678. copy.range = {
  2679. start: startOfDay(copy.range.start),
  2680. end: startOfDay(copy.range.end),
  2681. };
  2682. }
  2683. // handle invalid durations
  2684. if (copy.range.end < copy.range.start) {
  2685. copy.range.end = getDefaultEventEnd(eventDef.allDay, copy.range.start, context);
  2686. }
  2687. return copy;
  2688. }
  2689. // no public types yet. when there are, export from:
  2690. // import {} from './api-type-deps'
  2691. var ViewApi = /** @class */ (function () {
  2692. function ViewApi(type, getCurrentData, dateEnv) {
  2693. this.type = type;
  2694. this.getCurrentData = getCurrentData;
  2695. this.dateEnv = dateEnv;
  2696. }
  2697. Object.defineProperty(ViewApi.prototype, "calendar", {
  2698. get: function () {
  2699. return this.getCurrentData().calendarApi;
  2700. },
  2701. enumerable: false,
  2702. configurable: true
  2703. });
  2704. Object.defineProperty(ViewApi.prototype, "title", {
  2705. get: function () {
  2706. return this.getCurrentData().viewTitle;
  2707. },
  2708. enumerable: false,
  2709. configurable: true
  2710. });
  2711. Object.defineProperty(ViewApi.prototype, "activeStart", {
  2712. get: function () {
  2713. return this.dateEnv.toDate(this.getCurrentData().dateProfile.activeRange.start);
  2714. },
  2715. enumerable: false,
  2716. configurable: true
  2717. });
  2718. Object.defineProperty(ViewApi.prototype, "activeEnd", {
  2719. get: function () {
  2720. return this.dateEnv.toDate(this.getCurrentData().dateProfile.activeRange.end);
  2721. },
  2722. enumerable: false,
  2723. configurable: true
  2724. });
  2725. Object.defineProperty(ViewApi.prototype, "currentStart", {
  2726. get: function () {
  2727. return this.dateEnv.toDate(this.getCurrentData().dateProfile.currentRange.start);
  2728. },
  2729. enumerable: false,
  2730. configurable: true
  2731. });
  2732. Object.defineProperty(ViewApi.prototype, "currentEnd", {
  2733. get: function () {
  2734. return this.dateEnv.toDate(this.getCurrentData().dateProfile.currentRange.end);
  2735. },
  2736. enumerable: false,
  2737. configurable: true
  2738. });
  2739. ViewApi.prototype.getOption = function (name) {
  2740. return this.getCurrentData().options[name]; // are the view-specific options
  2741. };
  2742. return ViewApi;
  2743. }());
  2744. var EVENT_SOURCE_REFINERS$1 = {
  2745. id: String,
  2746. defaultAllDay: Boolean,
  2747. url: String,
  2748. format: String,
  2749. events: identity,
  2750. eventDataTransform: identity,
  2751. // for any network-related sources
  2752. success: identity,
  2753. failure: identity,
  2754. };
  2755. function parseEventSource(raw, context, refiners) {
  2756. if (refiners === void 0) { refiners = buildEventSourceRefiners(context); }
  2757. var rawObj;
  2758. if (typeof raw === 'string') {
  2759. rawObj = { url: raw };
  2760. }
  2761. else if (typeof raw === 'function' || Array.isArray(raw)) {
  2762. rawObj = { events: raw };
  2763. }
  2764. else if (typeof raw === 'object' && raw) { // not null
  2765. rawObj = raw;
  2766. }
  2767. if (rawObj) {
  2768. var _a = refineProps(rawObj, refiners), refined = _a.refined, extra = _a.extra;
  2769. var metaRes = buildEventSourceMeta(refined, context);
  2770. if (metaRes) {
  2771. return {
  2772. _raw: raw,
  2773. isFetching: false,
  2774. latestFetchId: '',
  2775. fetchRange: null,
  2776. defaultAllDay: refined.defaultAllDay,
  2777. eventDataTransform: refined.eventDataTransform,
  2778. success: refined.success,
  2779. failure: refined.failure,
  2780. publicId: refined.id || '',
  2781. sourceId: guid(),
  2782. sourceDefId: metaRes.sourceDefId,
  2783. meta: metaRes.meta,
  2784. ui: createEventUi(refined, context),
  2785. extendedProps: extra,
  2786. };
  2787. }
  2788. }
  2789. return null;
  2790. }
  2791. function buildEventSourceRefiners(context) {
  2792. return __assign(__assign(__assign({}, EVENT_UI_REFINERS), EVENT_SOURCE_REFINERS$1), context.pluginHooks.eventSourceRefiners);
  2793. }
  2794. function buildEventSourceMeta(raw, context) {
  2795. var defs = context.pluginHooks.eventSourceDefs;
  2796. for (var i = defs.length - 1; i >= 0; i -= 1) { // later-added plugins take precedence
  2797. var def = defs[i];
  2798. var meta = def.parseMeta(raw);
  2799. if (meta) {
  2800. return { sourceDefId: i, meta: meta };
  2801. }
  2802. }
  2803. return null;
  2804. }
  2805. function reduceCurrentDate(currentDate, action) {
  2806. switch (action.type) {
  2807. case 'CHANGE_DATE':
  2808. return action.dateMarker;
  2809. default:
  2810. return currentDate;
  2811. }
  2812. }
  2813. function getInitialDate(options, dateEnv) {
  2814. var initialDateInput = options.initialDate;
  2815. // compute the initial ambig-timezone date
  2816. if (initialDateInput != null) {
  2817. return dateEnv.createMarker(initialDateInput);
  2818. }
  2819. return getNow(options.now, dateEnv); // getNow already returns unzoned
  2820. }
  2821. function getNow(nowInput, dateEnv) {
  2822. if (typeof nowInput === 'function') {
  2823. nowInput = nowInput();
  2824. }
  2825. if (nowInput == null) {
  2826. return dateEnv.createNowMarker();
  2827. }
  2828. return dateEnv.createMarker(nowInput);
  2829. }
  2830. var CalendarApi = /** @class */ (function () {
  2831. function CalendarApi() {
  2832. }
  2833. CalendarApi.prototype.getCurrentData = function () {
  2834. return this.currentDataManager.getCurrentData();
  2835. };
  2836. CalendarApi.prototype.dispatch = function (action) {
  2837. return this.currentDataManager.dispatch(action);
  2838. };
  2839. Object.defineProperty(CalendarApi.prototype, "view", {
  2840. get: function () { return this.getCurrentData().viewApi; } // for public API
  2841. ,
  2842. enumerable: false,
  2843. configurable: true
  2844. });
  2845. CalendarApi.prototype.batchRendering = function (callback) {
  2846. callback();
  2847. };
  2848. CalendarApi.prototype.updateSize = function () {
  2849. this.trigger('_resize', true);
  2850. };
  2851. // Options
  2852. // -----------------------------------------------------------------------------------------------------------------
  2853. CalendarApi.prototype.setOption = function (name, val) {
  2854. this.dispatch({
  2855. type: 'SET_OPTION',
  2856. optionName: name,
  2857. rawOptionValue: val,
  2858. });
  2859. };
  2860. CalendarApi.prototype.getOption = function (name) {
  2861. return this.currentDataManager.currentCalendarOptionsInput[name];
  2862. };
  2863. CalendarApi.prototype.getAvailableLocaleCodes = function () {
  2864. return Object.keys(this.getCurrentData().availableRawLocales);
  2865. };
  2866. // Trigger
  2867. // -----------------------------------------------------------------------------------------------------------------
  2868. CalendarApi.prototype.on = function (handlerName, handler) {
  2869. var currentDataManager = this.currentDataManager;
  2870. if (currentDataManager.currentCalendarOptionsRefiners[handlerName]) {
  2871. currentDataManager.emitter.on(handlerName, handler);
  2872. }
  2873. else {
  2874. console.warn("Unknown listener name '" + handlerName + "'");
  2875. }
  2876. };
  2877. CalendarApi.prototype.off = function (handlerName, handler) {
  2878. this.currentDataManager.emitter.off(handlerName, handler);
  2879. };
  2880. // not meant for public use
  2881. CalendarApi.prototype.trigger = function (handlerName) {
  2882. var _a;
  2883. var args = [];
  2884. for (var _i = 1; _i < arguments.length; _i++) {
  2885. args[_i - 1] = arguments[_i];
  2886. }
  2887. (_a = this.currentDataManager.emitter).trigger.apply(_a, __spreadArray([handlerName], args));
  2888. };
  2889. // View
  2890. // -----------------------------------------------------------------------------------------------------------------
  2891. CalendarApi.prototype.changeView = function (viewType, dateOrRange) {
  2892. var _this = this;
  2893. this.batchRendering(function () {
  2894. _this.unselect();
  2895. if (dateOrRange) {
  2896. if (dateOrRange.start && dateOrRange.end) { // a range
  2897. _this.dispatch({
  2898. type: 'CHANGE_VIEW_TYPE',
  2899. viewType: viewType,
  2900. });
  2901. _this.dispatch({
  2902. type: 'SET_OPTION',
  2903. optionName: 'visibleRange',
  2904. rawOptionValue: dateOrRange,
  2905. });
  2906. }
  2907. else {
  2908. var dateEnv = _this.getCurrentData().dateEnv;
  2909. _this.dispatch({
  2910. type: 'CHANGE_VIEW_TYPE',
  2911. viewType: viewType,
  2912. dateMarker: dateEnv.createMarker(dateOrRange),
  2913. });
  2914. }
  2915. }
  2916. else {
  2917. _this.dispatch({
  2918. type: 'CHANGE_VIEW_TYPE',
  2919. viewType: viewType,
  2920. });
  2921. }
  2922. });
  2923. };
  2924. // Forces navigation to a view for the given date.
  2925. // `viewType` can be a specific view name or a generic one like "week" or "day".
  2926. // needs to change
  2927. CalendarApi.prototype.zoomTo = function (dateMarker, viewType) {
  2928. var state = this.getCurrentData();
  2929. var spec;
  2930. viewType = viewType || 'day'; // day is default zoom
  2931. spec = state.viewSpecs[viewType] || this.getUnitViewSpec(viewType);
  2932. this.unselect();
  2933. if (spec) {
  2934. this.dispatch({
  2935. type: 'CHANGE_VIEW_TYPE',
  2936. viewType: spec.type,
  2937. dateMarker: dateMarker,
  2938. });
  2939. }
  2940. else {
  2941. this.dispatch({
  2942. type: 'CHANGE_DATE',
  2943. dateMarker: dateMarker,
  2944. });
  2945. }
  2946. };
  2947. // Given a duration singular unit, like "week" or "day", finds a matching view spec.
  2948. // Preference is given to views that have corresponding buttons.
  2949. CalendarApi.prototype.getUnitViewSpec = function (unit) {
  2950. var _a = this.getCurrentData(), viewSpecs = _a.viewSpecs, toolbarConfig = _a.toolbarConfig;
  2951. var viewTypes = [].concat(toolbarConfig.viewsWithButtons);
  2952. var i;
  2953. var spec;
  2954. for (var viewType in viewSpecs) {
  2955. viewTypes.push(viewType);
  2956. }
  2957. for (i = 0; i < viewTypes.length; i += 1) {
  2958. spec = viewSpecs[viewTypes[i]];
  2959. if (spec) {
  2960. if (spec.singleUnit === unit) {
  2961. return spec;
  2962. }
  2963. }
  2964. }
  2965. return null;
  2966. };
  2967. // Current Date
  2968. // -----------------------------------------------------------------------------------------------------------------
  2969. CalendarApi.prototype.prev = function () {
  2970. this.unselect();
  2971. this.dispatch({ type: 'PREV' });
  2972. };
  2973. CalendarApi.prototype.next = function () {
  2974. this.unselect();
  2975. this.dispatch({ type: 'NEXT' });
  2976. };
  2977. CalendarApi.prototype.prevYear = function () {
  2978. var state = this.getCurrentData();
  2979. this.unselect();
  2980. this.dispatch({
  2981. type: 'CHANGE_DATE',
  2982. dateMarker: state.dateEnv.addYears(state.currentDate, -1),
  2983. });
  2984. };
  2985. CalendarApi.prototype.nextYear = function () {
  2986. var state = this.getCurrentData();
  2987. this.unselect();
  2988. this.dispatch({
  2989. type: 'CHANGE_DATE',
  2990. dateMarker: state.dateEnv.addYears(state.currentDate, 1),
  2991. });
  2992. };
  2993. CalendarApi.prototype.today = function () {
  2994. var state = this.getCurrentData();
  2995. this.unselect();
  2996. this.dispatch({
  2997. type: 'CHANGE_DATE',
  2998. dateMarker: getNow(state.calendarOptions.now, state.dateEnv),
  2999. });
  3000. };
  3001. CalendarApi.prototype.gotoDate = function (zonedDateInput) {
  3002. var state = this.getCurrentData();
  3003. this.unselect();
  3004. this.dispatch({
  3005. type: 'CHANGE_DATE',
  3006. dateMarker: state.dateEnv.createMarker(zonedDateInput),
  3007. });
  3008. };
  3009. CalendarApi.prototype.incrementDate = function (deltaInput) {
  3010. var state = this.getCurrentData();
  3011. var delta = createDuration(deltaInput);
  3012. if (delta) { // else, warn about invalid input?
  3013. this.unselect();
  3014. this.dispatch({
  3015. type: 'CHANGE_DATE',
  3016. dateMarker: state.dateEnv.add(state.currentDate, delta),
  3017. });
  3018. }
  3019. };
  3020. // for external API
  3021. CalendarApi.prototype.getDate = function () {
  3022. var state = this.getCurrentData();
  3023. return state.dateEnv.toDate(state.currentDate);
  3024. };
  3025. // Date Formatting Utils
  3026. // -----------------------------------------------------------------------------------------------------------------
  3027. CalendarApi.prototype.formatDate = function (d, formatter) {
  3028. var dateEnv = this.getCurrentData().dateEnv;
  3029. return dateEnv.format(dateEnv.createMarker(d), createFormatter(formatter));
  3030. };
  3031. // `settings` is for formatter AND isEndExclusive
  3032. CalendarApi.prototype.formatRange = function (d0, d1, settings) {
  3033. var dateEnv = this.getCurrentData().dateEnv;
  3034. return dateEnv.formatRange(dateEnv.createMarker(d0), dateEnv.createMarker(d1), createFormatter(settings), settings);
  3035. };
  3036. CalendarApi.prototype.formatIso = function (d, omitTime) {
  3037. var dateEnv = this.getCurrentData().dateEnv;
  3038. return dateEnv.formatIso(dateEnv.createMarker(d), { omitTime: omitTime });
  3039. };
  3040. // Date Selection / Event Selection / DayClick
  3041. // -----------------------------------------------------------------------------------------------------------------
  3042. // this public method receives start/end dates in any format, with any timezone
  3043. // NOTE: args were changed from v3
  3044. CalendarApi.prototype.select = function (dateOrObj, endDate) {
  3045. var selectionInput;
  3046. if (endDate == null) {
  3047. if (dateOrObj.start != null) {
  3048. selectionInput = dateOrObj;
  3049. }
  3050. else {
  3051. selectionInput = {
  3052. start: dateOrObj,
  3053. end: null,
  3054. };
  3055. }
  3056. }
  3057. else {
  3058. selectionInput = {
  3059. start: dateOrObj,
  3060. end: endDate,
  3061. };
  3062. }
  3063. var state = this.getCurrentData();
  3064. var selection = parseDateSpan(selectionInput, state.dateEnv, createDuration({ days: 1 }));
  3065. if (selection) { // throw parse error otherwise?
  3066. this.dispatch({ type: 'SELECT_DATES', selection: selection });
  3067. triggerDateSelect(selection, null, state);
  3068. }
  3069. };
  3070. // public method
  3071. CalendarApi.prototype.unselect = function (pev) {
  3072. var state = this.getCurrentData();
  3073. if (state.dateSelection) {
  3074. this.dispatch({ type: 'UNSELECT_DATES' });
  3075. triggerDateUnselect(pev, state);
  3076. }
  3077. };
  3078. // Public Events API
  3079. // -----------------------------------------------------------------------------------------------------------------
  3080. CalendarApi.prototype.addEvent = function (eventInput, sourceInput) {
  3081. if (eventInput instanceof EventApi) {
  3082. var def = eventInput._def;
  3083. var instance = eventInput._instance;
  3084. var currentData = this.getCurrentData();
  3085. // not already present? don't want to add an old snapshot
  3086. if (!currentData.eventStore.defs[def.defId]) {
  3087. this.dispatch({
  3088. type: 'ADD_EVENTS',
  3089. eventStore: eventTupleToStore({ def: def, instance: instance }), // TODO: better util for two args?
  3090. });
  3091. this.triggerEventAdd(eventInput);
  3092. }
  3093. return eventInput;
  3094. }
  3095. var state = this.getCurrentData();
  3096. var eventSource;
  3097. if (sourceInput instanceof EventSourceApi) {
  3098. eventSource = sourceInput.internalEventSource;
  3099. }
  3100. else if (typeof sourceInput === 'boolean') {
  3101. if (sourceInput) { // true. part of the first event source
  3102. eventSource = hashValuesToArray(state.eventSources)[0];
  3103. }
  3104. }
  3105. else if (sourceInput != null) { // an ID. accepts a number too
  3106. var sourceApi = this.getEventSourceById(sourceInput); // TODO: use an internal function
  3107. if (!sourceApi) {
  3108. console.warn("Could not find an event source with ID \"" + sourceInput + "\""); // TODO: test
  3109. return null;
  3110. }
  3111. eventSource = sourceApi.internalEventSource;
  3112. }
  3113. var tuple = parseEvent(eventInput, eventSource, state, false);
  3114. if (tuple) {
  3115. var newEventApi = new EventApi(state, tuple.def, tuple.def.recurringDef ? null : tuple.instance);
  3116. this.dispatch({
  3117. type: 'ADD_EVENTS',
  3118. eventStore: eventTupleToStore(tuple),
  3119. });
  3120. this.triggerEventAdd(newEventApi);
  3121. return newEventApi;
  3122. }
  3123. return null;
  3124. };
  3125. CalendarApi.prototype.triggerEventAdd = function (eventApi) {
  3126. var _this = this;
  3127. var emitter = this.getCurrentData().emitter;
  3128. emitter.trigger('eventAdd', {
  3129. event: eventApi,
  3130. relatedEvents: [],
  3131. revert: function () {
  3132. _this.dispatch({
  3133. type: 'REMOVE_EVENTS',
  3134. eventStore: eventApiToStore(eventApi),
  3135. });
  3136. },
  3137. });
  3138. };
  3139. // TODO: optimize
  3140. CalendarApi.prototype.getEventById = function (id) {
  3141. var state = this.getCurrentData();
  3142. var _a = state.eventStore, defs = _a.defs, instances = _a.instances;
  3143. id = String(id);
  3144. for (var defId in defs) {
  3145. var def = defs[defId];
  3146. if (def.publicId === id) {
  3147. if (def.recurringDef) {
  3148. return new EventApi(state, def, null);
  3149. }
  3150. for (var instanceId in instances) {
  3151. var instance = instances[instanceId];
  3152. if (instance.defId === def.defId) {
  3153. return new EventApi(state, def, instance);
  3154. }
  3155. }
  3156. }
  3157. }
  3158. return null;
  3159. };
  3160. CalendarApi.prototype.getEvents = function () {
  3161. var currentData = this.getCurrentData();
  3162. return buildEventApis(currentData.eventStore, currentData);
  3163. };
  3164. CalendarApi.prototype.removeAllEvents = function () {
  3165. this.dispatch({ type: 'REMOVE_ALL_EVENTS' });
  3166. };
  3167. // Public Event Sources API
  3168. // -----------------------------------------------------------------------------------------------------------------
  3169. CalendarApi.prototype.getEventSources = function () {
  3170. var state = this.getCurrentData();
  3171. var sourceHash = state.eventSources;
  3172. var sourceApis = [];
  3173. for (var internalId in sourceHash) {
  3174. sourceApis.push(new EventSourceApi(state, sourceHash[internalId]));
  3175. }
  3176. return sourceApis;
  3177. };
  3178. CalendarApi.prototype.getEventSourceById = function (id) {
  3179. var state = this.getCurrentData();
  3180. var sourceHash = state.eventSources;
  3181. id = String(id);
  3182. for (var sourceId in sourceHash) {
  3183. if (sourceHash[sourceId].publicId === id) {
  3184. return new EventSourceApi(state, sourceHash[sourceId]);
  3185. }
  3186. }
  3187. return null;
  3188. };
  3189. CalendarApi.prototype.addEventSource = function (sourceInput) {
  3190. var state = this.getCurrentData();
  3191. if (sourceInput instanceof EventSourceApi) {
  3192. // not already present? don't want to add an old snapshot
  3193. if (!state.eventSources[sourceInput.internalEventSource.sourceId]) {
  3194. this.dispatch({
  3195. type: 'ADD_EVENT_SOURCES',
  3196. sources: [sourceInput.internalEventSource],
  3197. });
  3198. }
  3199. return sourceInput;
  3200. }
  3201. var eventSource = parseEventSource(sourceInput, state);
  3202. if (eventSource) { // TODO: error otherwise?
  3203. this.dispatch({ type: 'ADD_EVENT_SOURCES', sources: [eventSource] });
  3204. return new EventSourceApi(state, eventSource);
  3205. }
  3206. return null;
  3207. };
  3208. CalendarApi.prototype.removeAllEventSources = function () {
  3209. this.dispatch({ type: 'REMOVE_ALL_EVENT_SOURCES' });
  3210. };
  3211. CalendarApi.prototype.refetchEvents = function () {
  3212. this.dispatch({ type: 'FETCH_EVENT_SOURCES', isRefetch: true });
  3213. };
  3214. // Scroll
  3215. // -----------------------------------------------------------------------------------------------------------------
  3216. CalendarApi.prototype.scrollToTime = function (timeInput) {
  3217. var time = createDuration(timeInput);
  3218. if (time) {
  3219. this.trigger('_scrollRequest', { time: time });
  3220. }
  3221. };
  3222. return CalendarApi;
  3223. }());
  3224. var EventApi = /** @class */ (function () {
  3225. // instance will be null if expressing a recurring event that has no current instances,
  3226. // OR if trying to validate an incoming external event that has no dates assigned
  3227. function EventApi(context, def, instance) {
  3228. this._context = context;
  3229. this._def = def;
  3230. this._instance = instance || null;
  3231. }
  3232. /*
  3233. TODO: make event struct more responsible for this
  3234. */
  3235. EventApi.prototype.setProp = function (name, val) {
  3236. var _a, _b;
  3237. if (name in EVENT_DATE_REFINERS) {
  3238. console.warn('Could not set date-related prop \'name\'. Use one of the date-related methods instead.');
  3239. // TODO: make proper aliasing system?
  3240. }
  3241. else if (name === 'id') {
  3242. val = EVENT_NON_DATE_REFINERS[name](val);
  3243. this.mutate({
  3244. standardProps: { publicId: val }, // hardcoded internal name
  3245. });
  3246. }
  3247. else if (name in EVENT_NON_DATE_REFINERS) {
  3248. val = EVENT_NON_DATE_REFINERS[name](val);
  3249. this.mutate({
  3250. standardProps: (_a = {}, _a[name] = val, _a),
  3251. });
  3252. }
  3253. else if (name in EVENT_UI_REFINERS) {
  3254. var ui = EVENT_UI_REFINERS[name](val);
  3255. if (name === 'color') {
  3256. ui = { backgroundColor: val, borderColor: val };
  3257. }
  3258. else if (name === 'editable') {
  3259. ui = { startEditable: val, durationEditable: val };
  3260. }
  3261. else {
  3262. ui = (_b = {}, _b[name] = val, _b);
  3263. }
  3264. this.mutate({
  3265. standardProps: { ui: ui },
  3266. });
  3267. }
  3268. else {
  3269. console.warn("Could not set prop '" + name + "'. Use setExtendedProp instead.");
  3270. }
  3271. };
  3272. EventApi.prototype.setExtendedProp = function (name, val) {
  3273. var _a;
  3274. this.mutate({
  3275. extendedProps: (_a = {}, _a[name] = val, _a),
  3276. });
  3277. };
  3278. EventApi.prototype.setStart = function (startInput, options) {
  3279. if (options === void 0) { options = {}; }
  3280. var dateEnv = this._context.dateEnv;
  3281. var start = dateEnv.createMarker(startInput);
  3282. if (start && this._instance) { // TODO: warning if parsed bad
  3283. var instanceRange = this._instance.range;
  3284. var startDelta = diffDates(instanceRange.start, start, dateEnv, options.granularity); // what if parsed bad!?
  3285. if (options.maintainDuration) {
  3286. this.mutate({ datesDelta: startDelta });
  3287. }
  3288. else {
  3289. this.mutate({ startDelta: startDelta });
  3290. }
  3291. }
  3292. };
  3293. EventApi.prototype.setEnd = function (endInput, options) {
  3294. if (options === void 0) { options = {}; }
  3295. var dateEnv = this._context.dateEnv;
  3296. var end;
  3297. if (endInput != null) {
  3298. end = dateEnv.createMarker(endInput);
  3299. if (!end) {
  3300. return; // TODO: warning if parsed bad
  3301. }
  3302. }
  3303. if (this._instance) {
  3304. if (end) {
  3305. var endDelta = diffDates(this._instance.range.end, end, dateEnv, options.granularity);
  3306. this.mutate({ endDelta: endDelta });
  3307. }
  3308. else {
  3309. this.mutate({ standardProps: { hasEnd: false } });
  3310. }
  3311. }
  3312. };
  3313. EventApi.prototype.setDates = function (startInput, endInput, options) {
  3314. if (options === void 0) { options = {}; }
  3315. var dateEnv = this._context.dateEnv;
  3316. var standardProps = { allDay: options.allDay };
  3317. var start = dateEnv.createMarker(startInput);
  3318. var end;
  3319. if (!start) {
  3320. return; // TODO: warning if parsed bad
  3321. }
  3322. if (endInput != null) {
  3323. end = dateEnv.createMarker(endInput);
  3324. if (!end) { // TODO: warning if parsed bad
  3325. return;
  3326. }
  3327. }
  3328. if (this._instance) {
  3329. var instanceRange = this._instance.range;
  3330. // when computing the diff for an event being converted to all-day,
  3331. // compute diff off of the all-day values the way event-mutation does.
  3332. if (options.allDay === true) {
  3333. instanceRange = computeAlignedDayRange(instanceRange);
  3334. }
  3335. var startDelta = diffDates(instanceRange.start, start, dateEnv, options.granularity);
  3336. if (end) {
  3337. var endDelta = diffDates(instanceRange.end, end, dateEnv, options.granularity);
  3338. if (durationsEqual(startDelta, endDelta)) {
  3339. this.mutate({ datesDelta: startDelta, standardProps: standardProps });
  3340. }
  3341. else {
  3342. this.mutate({ startDelta: startDelta, endDelta: endDelta, standardProps: standardProps });
  3343. }
  3344. }
  3345. else { // means "clear the end"
  3346. standardProps.hasEnd = false;
  3347. this.mutate({ datesDelta: startDelta, standardProps: standardProps });
  3348. }
  3349. }
  3350. };
  3351. EventApi.prototype.moveStart = function (deltaInput) {
  3352. var delta = createDuration(deltaInput);
  3353. if (delta) { // TODO: warning if parsed bad
  3354. this.mutate({ startDelta: delta });
  3355. }
  3356. };
  3357. EventApi.prototype.moveEnd = function (deltaInput) {
  3358. var delta = createDuration(deltaInput);
  3359. if (delta) { // TODO: warning if parsed bad
  3360. this.mutate({ endDelta: delta });
  3361. }
  3362. };
  3363. EventApi.prototype.moveDates = function (deltaInput) {
  3364. var delta = createDuration(deltaInput);
  3365. if (delta) { // TODO: warning if parsed bad
  3366. this.mutate({ datesDelta: delta });
  3367. }
  3368. };
  3369. EventApi.prototype.setAllDay = function (allDay, options) {
  3370. if (options === void 0) { options = {}; }
  3371. var standardProps = { allDay: allDay };
  3372. var maintainDuration = options.maintainDuration;
  3373. if (maintainDuration == null) {
  3374. maintainDuration = this._context.options.allDayMaintainDuration;
  3375. }
  3376. if (this._def.allDay !== allDay) {
  3377. standardProps.hasEnd = maintainDuration;
  3378. }
  3379. this.mutate({ standardProps: standardProps });
  3380. };
  3381. EventApi.prototype.formatRange = function (formatInput) {
  3382. var dateEnv = this._context.dateEnv;
  3383. var instance = this._instance;
  3384. var formatter = createFormatter(formatInput);
  3385. if (this._def.hasEnd) {
  3386. return dateEnv.formatRange(instance.range.start, instance.range.end, formatter, {
  3387. forcedStartTzo: instance.forcedStartTzo,
  3388. forcedEndTzo: instance.forcedEndTzo,
  3389. });
  3390. }
  3391. return dateEnv.format(instance.range.start, formatter, {
  3392. forcedTzo: instance.forcedStartTzo,
  3393. });
  3394. };
  3395. EventApi.prototype.mutate = function (mutation) {
  3396. var instance = this._instance;
  3397. if (instance) {
  3398. var def = this._def;
  3399. var context_1 = this._context;
  3400. var eventStore_1 = context_1.getCurrentData().eventStore;
  3401. var relevantEvents = getRelevantEvents(eventStore_1, instance.instanceId);
  3402. var eventConfigBase = {
  3403. '': {
  3404. display: '',
  3405. startEditable: true,
  3406. durationEditable: true,
  3407. constraints: [],
  3408. overlap: null,
  3409. allows: [],
  3410. backgroundColor: '',
  3411. borderColor: '',
  3412. textColor: '',
  3413. classNames: [],
  3414. },
  3415. };
  3416. relevantEvents = applyMutationToEventStore(relevantEvents, eventConfigBase, mutation, context_1);
  3417. var oldEvent = new EventApi(context_1, def, instance); // snapshot
  3418. this._def = relevantEvents.defs[def.defId];
  3419. this._instance = relevantEvents.instances[instance.instanceId];
  3420. context_1.dispatch({
  3421. type: 'MERGE_EVENTS',
  3422. eventStore: relevantEvents,
  3423. });
  3424. context_1.emitter.trigger('eventChange', {
  3425. oldEvent: oldEvent,
  3426. event: this,
  3427. relatedEvents: buildEventApis(relevantEvents, context_1, instance),
  3428. revert: function () {
  3429. context_1.dispatch({
  3430. type: 'RESET_EVENTS',
  3431. eventStore: eventStore_1,
  3432. });
  3433. },
  3434. });
  3435. }
  3436. };
  3437. EventApi.prototype.remove = function () {
  3438. var context = this._context;
  3439. var asStore = eventApiToStore(this);
  3440. context.dispatch({
  3441. type: 'REMOVE_EVENTS',
  3442. eventStore: asStore,
  3443. });
  3444. context.emitter.trigger('eventRemove', {
  3445. event: this,
  3446. relatedEvents: [],
  3447. revert: function () {
  3448. context.dispatch({
  3449. type: 'MERGE_EVENTS',
  3450. eventStore: asStore,
  3451. });
  3452. },
  3453. });
  3454. };
  3455. Object.defineProperty(EventApi.prototype, "source", {
  3456. get: function () {
  3457. var sourceId = this._def.sourceId;
  3458. if (sourceId) {
  3459. return new EventSourceApi(this._context, this._context.getCurrentData().eventSources[sourceId]);
  3460. }
  3461. return null;
  3462. },
  3463. enumerable: false,
  3464. configurable: true
  3465. });
  3466. Object.defineProperty(EventApi.prototype, "start", {
  3467. get: function () {
  3468. return this._instance ?
  3469. this._context.dateEnv.toDate(this._instance.range.start) :
  3470. null;
  3471. },
  3472. enumerable: false,
  3473. configurable: true
  3474. });
  3475. Object.defineProperty(EventApi.prototype, "end", {
  3476. get: function () {
  3477. return (this._instance && this._def.hasEnd) ?
  3478. this._context.dateEnv.toDate(this._instance.range.end) :
  3479. null;
  3480. },
  3481. enumerable: false,
  3482. configurable: true
  3483. });
  3484. Object.defineProperty(EventApi.prototype, "startStr", {
  3485. get: function () {
  3486. var instance = this._instance;
  3487. if (instance) {
  3488. return this._context.dateEnv.formatIso(instance.range.start, {
  3489. omitTime: this._def.allDay,
  3490. forcedTzo: instance.forcedStartTzo,
  3491. });
  3492. }
  3493. return '';
  3494. },
  3495. enumerable: false,
  3496. configurable: true
  3497. });
  3498. Object.defineProperty(EventApi.prototype, "endStr", {
  3499. get: function () {
  3500. var instance = this._instance;
  3501. if (instance && this._def.hasEnd) {
  3502. return this._context.dateEnv.formatIso(instance.range.end, {
  3503. omitTime: this._def.allDay,
  3504. forcedTzo: instance.forcedEndTzo,
  3505. });
  3506. }
  3507. return '';
  3508. },
  3509. enumerable: false,
  3510. configurable: true
  3511. });
  3512. Object.defineProperty(EventApi.prototype, "id", {
  3513. // computable props that all access the def
  3514. // TODO: find a TypeScript-compatible way to do this at scale
  3515. get: function () { return this._def.publicId; },
  3516. enumerable: false,
  3517. configurable: true
  3518. });
  3519. Object.defineProperty(EventApi.prototype, "groupId", {
  3520. get: function () { return this._def.groupId; },
  3521. enumerable: false,
  3522. configurable: true
  3523. });
  3524. Object.defineProperty(EventApi.prototype, "allDay", {
  3525. get: function () { return this._def.allDay; },
  3526. enumerable: false,
  3527. configurable: true
  3528. });
  3529. Object.defineProperty(EventApi.prototype, "title", {
  3530. get: function () { return this._def.title; },
  3531. enumerable: false,
  3532. configurable: true
  3533. });
  3534. Object.defineProperty(EventApi.prototype, "url", {
  3535. get: function () { return this._def.url; },
  3536. enumerable: false,
  3537. configurable: true
  3538. });
  3539. Object.defineProperty(EventApi.prototype, "display", {
  3540. get: function () { return this._def.ui.display || 'auto'; } // bad. just normalize the type earlier
  3541. ,
  3542. enumerable: false,
  3543. configurable: true
  3544. });
  3545. Object.defineProperty(EventApi.prototype, "startEditable", {
  3546. get: function () { return this._def.ui.startEditable; },
  3547. enumerable: false,
  3548. configurable: true
  3549. });
  3550. Object.defineProperty(EventApi.prototype, "durationEditable", {
  3551. get: function () { return this._def.ui.durationEditable; },
  3552. enumerable: false,
  3553. configurable: true
  3554. });
  3555. Object.defineProperty(EventApi.prototype, "constraint", {
  3556. get: function () { return this._def.ui.constraints[0] || null; },
  3557. enumerable: false,
  3558. configurable: true
  3559. });
  3560. Object.defineProperty(EventApi.prototype, "overlap", {
  3561. get: function () { return this._def.ui.overlap; },
  3562. enumerable: false,
  3563. configurable: true
  3564. });
  3565. Object.defineProperty(EventApi.prototype, "allow", {
  3566. get: function () { return this._def.ui.allows[0] || null; },
  3567. enumerable: false,
  3568. configurable: true
  3569. });
  3570. Object.defineProperty(EventApi.prototype, "backgroundColor", {
  3571. get: function () { return this._def.ui.backgroundColor; },
  3572. enumerable: false,
  3573. configurable: true
  3574. });
  3575. Object.defineProperty(EventApi.prototype, "borderColor", {
  3576. get: function () { return this._def.ui.borderColor; },
  3577. enumerable: false,
  3578. configurable: true
  3579. });
  3580. Object.defineProperty(EventApi.prototype, "textColor", {
  3581. get: function () { return this._def.ui.textColor; },
  3582. enumerable: false,
  3583. configurable: true
  3584. });
  3585. Object.defineProperty(EventApi.prototype, "classNames", {
  3586. // NOTE: user can't modify these because Object.freeze was called in event-def parsing
  3587. get: function () { return this._def.ui.classNames; },
  3588. enumerable: false,
  3589. configurable: true
  3590. });
  3591. Object.defineProperty(EventApi.prototype, "extendedProps", {
  3592. get: function () { return this._def.extendedProps; },
  3593. enumerable: false,
  3594. configurable: true
  3595. });
  3596. EventApi.prototype.toPlainObject = function (settings) {
  3597. if (settings === void 0) { settings = {}; }
  3598. var def = this._def;
  3599. var ui = def.ui;
  3600. var _a = this, startStr = _a.startStr, endStr = _a.endStr;
  3601. var res = {};
  3602. if (def.title) {
  3603. res.title = def.title;
  3604. }
  3605. if (startStr) {
  3606. res.start = startStr;
  3607. }
  3608. if (endStr) {
  3609. res.end = endStr;
  3610. }
  3611. if (def.publicId) {
  3612. res.id = def.publicId;
  3613. }
  3614. if (def.groupId) {
  3615. res.groupId = def.groupId;
  3616. }
  3617. if (def.url) {
  3618. res.url = def.url;
  3619. }
  3620. if (ui.display && ui.display !== 'auto') {
  3621. res.display = ui.display;
  3622. }
  3623. // TODO: what about recurring-event properties???
  3624. // TODO: include startEditable/durationEditable/constraint/overlap/allow
  3625. if (settings.collapseColor && ui.backgroundColor && ui.backgroundColor === ui.borderColor) {
  3626. res.color = ui.backgroundColor;
  3627. }
  3628. else {
  3629. if (ui.backgroundColor) {
  3630. res.backgroundColor = ui.backgroundColor;
  3631. }
  3632. if (ui.borderColor) {
  3633. res.borderColor = ui.borderColor;
  3634. }
  3635. }
  3636. if (ui.textColor) {
  3637. res.textColor = ui.textColor;
  3638. }
  3639. if (ui.classNames.length) {
  3640. res.classNames = ui.classNames;
  3641. }
  3642. if (Object.keys(def.extendedProps).length) {
  3643. if (settings.collapseExtendedProps) {
  3644. __assign(res, def.extendedProps);
  3645. }
  3646. else {
  3647. res.extendedProps = def.extendedProps;
  3648. }
  3649. }
  3650. return res;
  3651. };
  3652. EventApi.prototype.toJSON = function () {
  3653. return this.toPlainObject();
  3654. };
  3655. return EventApi;
  3656. }());
  3657. function eventApiToStore(eventApi) {
  3658. var _a, _b;
  3659. var def = eventApi._def;
  3660. var instance = eventApi._instance;
  3661. return {
  3662. defs: (_a = {}, _a[def.defId] = def, _a),
  3663. instances: instance
  3664. ? (_b = {}, _b[instance.instanceId] = instance, _b) : {},
  3665. };
  3666. }
  3667. function buildEventApis(eventStore, context, excludeInstance) {
  3668. var defs = eventStore.defs, instances = eventStore.instances;
  3669. var eventApis = [];
  3670. var excludeInstanceId = excludeInstance ? excludeInstance.instanceId : '';
  3671. for (var id in instances) {
  3672. var instance = instances[id];
  3673. var def = defs[instance.defId];
  3674. if (instance.instanceId !== excludeInstanceId) {
  3675. eventApis.push(new EventApi(context, def, instance));
  3676. }
  3677. }
  3678. return eventApis;
  3679. }
  3680. var calendarSystemClassMap = {};
  3681. function registerCalendarSystem(name, theClass) {
  3682. calendarSystemClassMap[name] = theClass;
  3683. }
  3684. function createCalendarSystem(name) {
  3685. return new calendarSystemClassMap[name]();
  3686. }
  3687. var GregorianCalendarSystem = /** @class */ (function () {
  3688. function GregorianCalendarSystem() {
  3689. }
  3690. GregorianCalendarSystem.prototype.getMarkerYear = function (d) {
  3691. return d.getUTCFullYear();
  3692. };
  3693. GregorianCalendarSystem.prototype.getMarkerMonth = function (d) {
  3694. return d.getUTCMonth();
  3695. };
  3696. GregorianCalendarSystem.prototype.getMarkerDay = function (d) {
  3697. return d.getUTCDate();
  3698. };
  3699. GregorianCalendarSystem.prototype.arrayToMarker = function (arr) {
  3700. return arrayToUtcDate(arr);
  3701. };
  3702. GregorianCalendarSystem.prototype.markerToArray = function (marker) {
  3703. return dateToUtcArray(marker);
  3704. };
  3705. return GregorianCalendarSystem;
  3706. }());
  3707. registerCalendarSystem('gregory', GregorianCalendarSystem);
  3708. var ISO_RE = /^\s*(\d{4})(-?(\d{2})(-?(\d{2})([T ](\d{2}):?(\d{2})(:?(\d{2})(\.(\d+))?)?(Z|(([-+])(\d{2})(:?(\d{2}))?))?)?)?)?$/;
  3709. function parse(str) {
  3710. var m = ISO_RE.exec(str);
  3711. if (m) {
  3712. var marker = new Date(Date.UTC(Number(m[1]), m[3] ? Number(m[3]) - 1 : 0, Number(m[5] || 1), Number(m[7] || 0), Number(m[8] || 0), Number(m[10] || 0), m[12] ? Number("0." + m[12]) * 1000 : 0));
  3713. if (isValidDate(marker)) {
  3714. var timeZoneOffset = null;
  3715. if (m[13]) {
  3716. timeZoneOffset = (m[15] === '-' ? -1 : 1) * (Number(m[16] || 0) * 60 +
  3717. Number(m[18] || 0));
  3718. }
  3719. return {
  3720. marker: marker,
  3721. isTimeUnspecified: !m[6],
  3722. timeZoneOffset: timeZoneOffset,
  3723. };
  3724. }
  3725. }
  3726. return null;
  3727. }
  3728. var DateEnv = /** @class */ (function () {
  3729. function DateEnv(settings) {
  3730. var timeZone = this.timeZone = settings.timeZone;
  3731. var isNamedTimeZone = timeZone !== 'local' && timeZone !== 'UTC';
  3732. if (settings.namedTimeZoneImpl && isNamedTimeZone) {
  3733. this.namedTimeZoneImpl = new settings.namedTimeZoneImpl(timeZone);
  3734. }
  3735. this.canComputeOffset = Boolean(!isNamedTimeZone || this.namedTimeZoneImpl);
  3736. this.calendarSystem = createCalendarSystem(settings.calendarSystem);
  3737. this.locale = settings.locale;
  3738. this.weekDow = settings.locale.week.dow;
  3739. this.weekDoy = settings.locale.week.doy;
  3740. if (settings.weekNumberCalculation === 'ISO') {
  3741. this.weekDow = 1;
  3742. this.weekDoy = 4;
  3743. }
  3744. if (typeof settings.firstDay === 'number') {
  3745. this.weekDow = settings.firstDay;
  3746. }
  3747. if (typeof settings.weekNumberCalculation === 'function') {
  3748. this.weekNumberFunc = settings.weekNumberCalculation;
  3749. }
  3750. this.weekText = settings.weekText != null ? settings.weekText : settings.locale.options.weekText;
  3751. this.cmdFormatter = settings.cmdFormatter;
  3752. this.defaultSeparator = settings.defaultSeparator;
  3753. }
  3754. // Creating / Parsing
  3755. DateEnv.prototype.createMarker = function (input) {
  3756. var meta = this.createMarkerMeta(input);
  3757. if (meta === null) {
  3758. return null;
  3759. }
  3760. return meta.marker;
  3761. };
  3762. DateEnv.prototype.createNowMarker = function () {
  3763. if (this.canComputeOffset) {
  3764. return this.timestampToMarker(new Date().valueOf());
  3765. }
  3766. // if we can't compute the current date val for a timezone,
  3767. // better to give the current local date vals than UTC
  3768. return arrayToUtcDate(dateToLocalArray(new Date()));
  3769. };
  3770. DateEnv.prototype.createMarkerMeta = function (input) {
  3771. if (typeof input === 'string') {
  3772. return this.parse(input);
  3773. }
  3774. var marker = null;
  3775. if (typeof input === 'number') {
  3776. marker = this.timestampToMarker(input);
  3777. }
  3778. else if (input instanceof Date) {
  3779. input = input.valueOf();
  3780. if (!isNaN(input)) {
  3781. marker = this.timestampToMarker(input);
  3782. }
  3783. }
  3784. else if (Array.isArray(input)) {
  3785. marker = arrayToUtcDate(input);
  3786. }
  3787. if (marker === null || !isValidDate(marker)) {
  3788. return null;
  3789. }
  3790. return { marker: marker, isTimeUnspecified: false, forcedTzo: null };
  3791. };
  3792. DateEnv.prototype.parse = function (s) {
  3793. var parts = parse(s);
  3794. if (parts === null) {
  3795. return null;
  3796. }
  3797. var marker = parts.marker;
  3798. var forcedTzo = null;
  3799. if (parts.timeZoneOffset !== null) {
  3800. if (this.canComputeOffset) {
  3801. marker = this.timestampToMarker(marker.valueOf() - parts.timeZoneOffset * 60 * 1000);
  3802. }
  3803. else {
  3804. forcedTzo = parts.timeZoneOffset;
  3805. }
  3806. }
  3807. return { marker: marker, isTimeUnspecified: parts.isTimeUnspecified, forcedTzo: forcedTzo };
  3808. };
  3809. // Accessors
  3810. DateEnv.prototype.getYear = function (marker) {
  3811. return this.calendarSystem.getMarkerYear(marker);
  3812. };
  3813. DateEnv.prototype.getMonth = function (marker) {
  3814. return this.calendarSystem.getMarkerMonth(marker);
  3815. };
  3816. // Adding / Subtracting
  3817. DateEnv.prototype.add = function (marker, dur) {
  3818. var a = this.calendarSystem.markerToArray(marker);
  3819. a[0] += dur.years;
  3820. a[1] += dur.months;
  3821. a[2] += dur.days;
  3822. a[6] += dur.milliseconds;
  3823. return this.calendarSystem.arrayToMarker(a);
  3824. };
  3825. DateEnv.prototype.subtract = function (marker, dur) {
  3826. var a = this.calendarSystem.markerToArray(marker);
  3827. a[0] -= dur.years;
  3828. a[1] -= dur.months;
  3829. a[2] -= dur.days;
  3830. a[6] -= dur.milliseconds;
  3831. return this.calendarSystem.arrayToMarker(a);
  3832. };
  3833. DateEnv.prototype.addYears = function (marker, n) {
  3834. var a = this.calendarSystem.markerToArray(marker);
  3835. a[0] += n;
  3836. return this.calendarSystem.arrayToMarker(a);
  3837. };
  3838. DateEnv.prototype.addMonths = function (marker, n) {
  3839. var a = this.calendarSystem.markerToArray(marker);
  3840. a[1] += n;
  3841. return this.calendarSystem.arrayToMarker(a);
  3842. };
  3843. // Diffing Whole Units
  3844. DateEnv.prototype.diffWholeYears = function (m0, m1) {
  3845. var calendarSystem = this.calendarSystem;
  3846. if (timeAsMs(m0) === timeAsMs(m1) &&
  3847. calendarSystem.getMarkerDay(m0) === calendarSystem.getMarkerDay(m1) &&
  3848. calendarSystem.getMarkerMonth(m0) === calendarSystem.getMarkerMonth(m1)) {
  3849. return calendarSystem.getMarkerYear(m1) - calendarSystem.getMarkerYear(m0);
  3850. }
  3851. return null;
  3852. };
  3853. DateEnv.prototype.diffWholeMonths = function (m0, m1) {
  3854. var calendarSystem = this.calendarSystem;
  3855. if (timeAsMs(m0) === timeAsMs(m1) &&
  3856. calendarSystem.getMarkerDay(m0) === calendarSystem.getMarkerDay(m1)) {
  3857. return (calendarSystem.getMarkerMonth(m1) - calendarSystem.getMarkerMonth(m0)) +
  3858. (calendarSystem.getMarkerYear(m1) - calendarSystem.getMarkerYear(m0)) * 12;
  3859. }
  3860. return null;
  3861. };
  3862. // Range / Duration
  3863. DateEnv.prototype.greatestWholeUnit = function (m0, m1) {
  3864. var n = this.diffWholeYears(m0, m1);
  3865. if (n !== null) {
  3866. return { unit: 'year', value: n };
  3867. }
  3868. n = this.diffWholeMonths(m0, m1);
  3869. if (n !== null) {
  3870. return { unit: 'month', value: n };
  3871. }
  3872. n = diffWholeWeeks(m0, m1);
  3873. if (n !== null) {
  3874. return { unit: 'week', value: n };
  3875. }
  3876. n = diffWholeDays(m0, m1);
  3877. if (n !== null) {
  3878. return { unit: 'day', value: n };
  3879. }
  3880. n = diffHours(m0, m1);
  3881. if (isInt(n)) {
  3882. return { unit: 'hour', value: n };
  3883. }
  3884. n = diffMinutes(m0, m1);
  3885. if (isInt(n)) {
  3886. return { unit: 'minute', value: n };
  3887. }
  3888. n = diffSeconds(m0, m1);
  3889. if (isInt(n)) {
  3890. return { unit: 'second', value: n };
  3891. }
  3892. return { unit: 'millisecond', value: m1.valueOf() - m0.valueOf() };
  3893. };
  3894. DateEnv.prototype.countDurationsBetween = function (m0, m1, d) {
  3895. // TODO: can use greatestWholeUnit
  3896. var diff;
  3897. if (d.years) {
  3898. diff = this.diffWholeYears(m0, m1);
  3899. if (diff !== null) {
  3900. return diff / asRoughYears(d);
  3901. }
  3902. }
  3903. if (d.months) {
  3904. diff = this.diffWholeMonths(m0, m1);
  3905. if (diff !== null) {
  3906. return diff / asRoughMonths(d);
  3907. }
  3908. }
  3909. if (d.days) {
  3910. diff = diffWholeDays(m0, m1);
  3911. if (diff !== null) {
  3912. return diff / asRoughDays(d);
  3913. }
  3914. }
  3915. return (m1.valueOf() - m0.valueOf()) / asRoughMs(d);
  3916. };
  3917. // Start-Of
  3918. // these DON'T return zoned-dates. only UTC start-of dates
  3919. DateEnv.prototype.startOf = function (m, unit) {
  3920. if (unit === 'year') {
  3921. return this.startOfYear(m);
  3922. }
  3923. if (unit === 'month') {
  3924. return this.startOfMonth(m);
  3925. }
  3926. if (unit === 'week') {
  3927. return this.startOfWeek(m);
  3928. }
  3929. if (unit === 'day') {
  3930. return startOfDay(m);
  3931. }
  3932. if (unit === 'hour') {
  3933. return startOfHour(m);
  3934. }
  3935. if (unit === 'minute') {
  3936. return startOfMinute(m);
  3937. }
  3938. if (unit === 'second') {
  3939. return startOfSecond(m);
  3940. }
  3941. return null;
  3942. };
  3943. DateEnv.prototype.startOfYear = function (m) {
  3944. return this.calendarSystem.arrayToMarker([
  3945. this.calendarSystem.getMarkerYear(m),
  3946. ]);
  3947. };
  3948. DateEnv.prototype.startOfMonth = function (m) {
  3949. return this.calendarSystem.arrayToMarker([
  3950. this.calendarSystem.getMarkerYear(m),
  3951. this.calendarSystem.getMarkerMonth(m),
  3952. ]);
  3953. };
  3954. DateEnv.prototype.startOfWeek = function (m) {
  3955. return this.calendarSystem.arrayToMarker([
  3956. this.calendarSystem.getMarkerYear(m),
  3957. this.calendarSystem.getMarkerMonth(m),
  3958. m.getUTCDate() - ((m.getUTCDay() - this.weekDow + 7) % 7),
  3959. ]);
  3960. };
  3961. // Week Number
  3962. DateEnv.prototype.computeWeekNumber = function (marker) {
  3963. if (this.weekNumberFunc) {
  3964. return this.weekNumberFunc(this.toDate(marker));
  3965. }
  3966. return weekOfYear(marker, this.weekDow, this.weekDoy);
  3967. };
  3968. // TODO: choke on timeZoneName: long
  3969. DateEnv.prototype.format = function (marker, formatter, dateOptions) {
  3970. if (dateOptions === void 0) { dateOptions = {}; }
  3971. return formatter.format({
  3972. marker: marker,
  3973. timeZoneOffset: dateOptions.forcedTzo != null ?
  3974. dateOptions.forcedTzo :
  3975. this.offsetForMarker(marker),
  3976. }, this);
  3977. };
  3978. DateEnv.prototype.formatRange = function (start, end, formatter, dateOptions) {
  3979. if (dateOptions === void 0) { dateOptions = {}; }
  3980. if (dateOptions.isEndExclusive) {
  3981. end = addMs(end, -1);
  3982. }
  3983. return formatter.formatRange({
  3984. marker: start,
  3985. timeZoneOffset: dateOptions.forcedStartTzo != null ?
  3986. dateOptions.forcedStartTzo :
  3987. this.offsetForMarker(start),
  3988. }, {
  3989. marker: end,
  3990. timeZoneOffset: dateOptions.forcedEndTzo != null ?
  3991. dateOptions.forcedEndTzo :
  3992. this.offsetForMarker(end),
  3993. }, this, dateOptions.defaultSeparator);
  3994. };
  3995. /*
  3996. DUMB: the omitTime arg is dumb. if we omit the time, we want to omit the timezone offset. and if we do that,
  3997. might as well use buildIsoString or some other util directly
  3998. */
  3999. DateEnv.prototype.formatIso = function (marker, extraOptions) {
  4000. if (extraOptions === void 0) { extraOptions = {}; }
  4001. var timeZoneOffset = null;
  4002. if (!extraOptions.omitTimeZoneOffset) {
  4003. if (extraOptions.forcedTzo != null) {
  4004. timeZoneOffset = extraOptions.forcedTzo;
  4005. }
  4006. else {
  4007. timeZoneOffset = this.offsetForMarker(marker);
  4008. }
  4009. }
  4010. return buildIsoString(marker, timeZoneOffset, extraOptions.omitTime);
  4011. };
  4012. // TimeZone
  4013. DateEnv.prototype.timestampToMarker = function (ms) {
  4014. if (this.timeZone === 'local') {
  4015. return arrayToUtcDate(dateToLocalArray(new Date(ms)));
  4016. }
  4017. if (this.timeZone === 'UTC' || !this.namedTimeZoneImpl) {
  4018. return new Date(ms);
  4019. }
  4020. return arrayToUtcDate(this.namedTimeZoneImpl.timestampToArray(ms));
  4021. };
  4022. DateEnv.prototype.offsetForMarker = function (m) {
  4023. if (this.timeZone === 'local') {
  4024. return -arrayToLocalDate(dateToUtcArray(m)).getTimezoneOffset(); // convert "inverse" offset to "normal" offset
  4025. }
  4026. if (this.timeZone === 'UTC') {
  4027. return 0;
  4028. }
  4029. if (this.namedTimeZoneImpl) {
  4030. return this.namedTimeZoneImpl.offsetForArray(dateToUtcArray(m));
  4031. }
  4032. return null;
  4033. };
  4034. // Conversion
  4035. DateEnv.prototype.toDate = function (m, forcedTzo) {
  4036. if (this.timeZone === 'local') {
  4037. return arrayToLocalDate(dateToUtcArray(m));
  4038. }
  4039. if (this.timeZone === 'UTC') {
  4040. return new Date(m.valueOf()); // make sure it's a copy
  4041. }
  4042. if (!this.namedTimeZoneImpl) {
  4043. return new Date(m.valueOf() - (forcedTzo || 0));
  4044. }
  4045. return new Date(m.valueOf() -
  4046. this.namedTimeZoneImpl.offsetForArray(dateToUtcArray(m)) * 1000 * 60);
  4047. };
  4048. return DateEnv;
  4049. }());
  4050. var globalLocales = [];
  4051. var RAW_EN_LOCALE = {
  4052. code: 'en',
  4053. week: {
  4054. dow: 0,
  4055. doy: 4, // 4 days need to be within the year to be considered the first week
  4056. },
  4057. direction: 'ltr',
  4058. buttonText: {
  4059. prev: 'prev',
  4060. next: 'next',
  4061. prevYear: 'prev year',
  4062. nextYear: 'next year',
  4063. year: 'year',
  4064. today: 'today',
  4065. month: 'month',
  4066. week: 'week',
  4067. day: 'day',
  4068. list: 'list',
  4069. },
  4070. weekText: 'W',
  4071. allDayText: 'all-day',
  4072. moreLinkText: 'more',
  4073. noEventsText: 'No events to display',
  4074. };
  4075. function organizeRawLocales(explicitRawLocales) {
  4076. var defaultCode = explicitRawLocales.length > 0 ? explicitRawLocales[0].code : 'en';
  4077. var allRawLocales = globalLocales.concat(explicitRawLocales);
  4078. var rawLocaleMap = {
  4079. en: RAW_EN_LOCALE, // necessary?
  4080. };
  4081. for (var _i = 0, allRawLocales_1 = allRawLocales; _i < allRawLocales_1.length; _i++) {
  4082. var rawLocale = allRawLocales_1[_i];
  4083. rawLocaleMap[rawLocale.code] = rawLocale;
  4084. }
  4085. return {
  4086. map: rawLocaleMap,
  4087. defaultCode: defaultCode,
  4088. };
  4089. }
  4090. function buildLocale(inputSingular, available) {
  4091. if (typeof inputSingular === 'object' && !Array.isArray(inputSingular)) {
  4092. return parseLocale(inputSingular.code, [inputSingular.code], inputSingular);
  4093. }
  4094. return queryLocale(inputSingular, available);
  4095. }
  4096. function queryLocale(codeArg, available) {
  4097. var codes = [].concat(codeArg || []); // will convert to array
  4098. var raw = queryRawLocale(codes, available) || RAW_EN_LOCALE;
  4099. return parseLocale(codeArg, codes, raw);
  4100. }
  4101. function queryRawLocale(codes, available) {
  4102. for (var i = 0; i < codes.length; i += 1) {
  4103. var parts = codes[i].toLocaleLowerCase().split('-');
  4104. for (var j = parts.length; j > 0; j -= 1) {
  4105. var simpleId = parts.slice(0, j).join('-');
  4106. if (available[simpleId]) {
  4107. return available[simpleId];
  4108. }
  4109. }
  4110. }
  4111. return null;
  4112. }
  4113. function parseLocale(codeArg, codes, raw) {
  4114. var merged = mergeProps([RAW_EN_LOCALE, raw], ['buttonText']);
  4115. delete merged.code; // don't want this part of the options
  4116. var week = merged.week;
  4117. delete merged.week;
  4118. return {
  4119. codeArg: codeArg,
  4120. codes: codes,
  4121. week: week,
  4122. simpleNumberFormat: new Intl.NumberFormat(codeArg),
  4123. options: merged,
  4124. };
  4125. }
  4126. function formatDate(dateInput, options) {
  4127. if (options === void 0) { options = {}; }
  4128. var dateEnv = buildDateEnv$1(options);
  4129. var formatter = createFormatter(options);
  4130. var dateMeta = dateEnv.createMarkerMeta(dateInput);
  4131. if (!dateMeta) { // TODO: warning?
  4132. return '';
  4133. }
  4134. return dateEnv.format(dateMeta.marker, formatter, {
  4135. forcedTzo: dateMeta.forcedTzo,
  4136. });
  4137. }
  4138. function formatRange(startInput, endInput, options) {
  4139. var dateEnv = buildDateEnv$1(typeof options === 'object' && options ? options : {}); // pass in if non-null object
  4140. var formatter = createFormatter(options);
  4141. var startMeta = dateEnv.createMarkerMeta(startInput);
  4142. var endMeta = dateEnv.createMarkerMeta(endInput);
  4143. if (!startMeta || !endMeta) { // TODO: warning?
  4144. return '';
  4145. }
  4146. return dateEnv.formatRange(startMeta.marker, endMeta.marker, formatter, {
  4147. forcedStartTzo: startMeta.forcedTzo,
  4148. forcedEndTzo: endMeta.forcedTzo,
  4149. isEndExclusive: options.isEndExclusive,
  4150. defaultSeparator: BASE_OPTION_DEFAULTS.defaultRangeSeparator,
  4151. });
  4152. }
  4153. // TODO: more DRY and optimized
  4154. function buildDateEnv$1(settings) {
  4155. var locale = buildLocale(settings.locale || 'en', organizeRawLocales([]).map); // TODO: don't hardcode 'en' everywhere
  4156. return new DateEnv(__assign(__assign({ timeZone: BASE_OPTION_DEFAULTS.timeZone, calendarSystem: 'gregory' }, settings), { locale: locale }));
  4157. }
  4158. var DEF_DEFAULTS = {
  4159. startTime: '09:00',
  4160. endTime: '17:00',
  4161. daysOfWeek: [1, 2, 3, 4, 5],
  4162. display: 'inverse-background',
  4163. classNames: 'fc-non-business',
  4164. groupId: '_businessHours', // so multiple defs get grouped
  4165. };
  4166. /*
  4167. TODO: pass around as EventDefHash!!!
  4168. */
  4169. function parseBusinessHours(input, context) {
  4170. return parseEvents(refineInputs(input), null, context);
  4171. }
  4172. function refineInputs(input) {
  4173. var rawDefs;
  4174. if (input === true) {
  4175. rawDefs = [{}]; // will get DEF_DEFAULTS verbatim
  4176. }
  4177. else if (Array.isArray(input)) {
  4178. // if specifying an array, every sub-definition NEEDS a day-of-week
  4179. rawDefs = input.filter(function (rawDef) { return rawDef.daysOfWeek; });
  4180. }
  4181. else if (typeof input === 'object' && input) { // non-null object
  4182. rawDefs = [input];
  4183. }
  4184. else { // is probably false
  4185. rawDefs = [];
  4186. }
  4187. rawDefs = rawDefs.map(function (rawDef) { return (__assign(__assign({}, DEF_DEFAULTS), rawDef)); });
  4188. return rawDefs;
  4189. }
  4190. function pointInsideRect(point, rect) {
  4191. return point.left >= rect.left &&
  4192. point.left < rect.right &&
  4193. point.top >= rect.top &&
  4194. point.top < rect.bottom;
  4195. }
  4196. // Returns a new rectangle that is the intersection of the two rectangles. If they don't intersect, returns false
  4197. function intersectRects(rect1, rect2) {
  4198. var res = {
  4199. left: Math.max(rect1.left, rect2.left),
  4200. right: Math.min(rect1.right, rect2.right),
  4201. top: Math.max(rect1.top, rect2.top),
  4202. bottom: Math.min(rect1.bottom, rect2.bottom),
  4203. };
  4204. if (res.left < res.right && res.top < res.bottom) {
  4205. return res;
  4206. }
  4207. return false;
  4208. }
  4209. function translateRect(rect, deltaX, deltaY) {
  4210. return {
  4211. left: rect.left + deltaX,
  4212. right: rect.right + deltaX,
  4213. top: rect.top + deltaY,
  4214. bottom: rect.bottom + deltaY,
  4215. };
  4216. }
  4217. // Returns a new point that will have been moved to reside within the given rectangle
  4218. function constrainPoint(point, rect) {
  4219. return {
  4220. left: Math.min(Math.max(point.left, rect.left), rect.right),
  4221. top: Math.min(Math.max(point.top, rect.top), rect.bottom),
  4222. };
  4223. }
  4224. // Returns a point that is the center of the given rectangle
  4225. function getRectCenter(rect) {
  4226. return {
  4227. left: (rect.left + rect.right) / 2,
  4228. top: (rect.top + rect.bottom) / 2,
  4229. };
  4230. }
  4231. // Subtracts point2's coordinates from point1's coordinates, returning a delta
  4232. function diffPoints(point1, point2) {
  4233. return {
  4234. left: point1.left - point2.left,
  4235. top: point1.top - point2.top,
  4236. };
  4237. }
  4238. var canVGrowWithinCell;
  4239. function getCanVGrowWithinCell() {
  4240. if (canVGrowWithinCell == null) {
  4241. canVGrowWithinCell = computeCanVGrowWithinCell();
  4242. }
  4243. return canVGrowWithinCell;
  4244. }
  4245. function computeCanVGrowWithinCell() {
  4246. // for SSR, because this function is call immediately at top-level
  4247. // TODO: just make this logic execute top-level, immediately, instead of doing lazily
  4248. if (typeof document === 'undefined') {
  4249. return true;
  4250. }
  4251. var el = document.createElement('div');
  4252. el.style.position = 'absolute';
  4253. el.style.top = '0px';
  4254. el.style.left = '0px';
  4255. el.innerHTML = '<table><tr><td><div></div></td></tr></table>';
  4256. el.querySelector('table').style.height = '100px';
  4257. el.querySelector('div').style.height = '100%';
  4258. document.body.appendChild(el);
  4259. var div = el.querySelector('div');
  4260. var possible = div.offsetHeight > 0;
  4261. document.body.removeChild(el);
  4262. return possible;
  4263. }
  4264. var EMPTY_EVENT_STORE = createEmptyEventStore(); // for purecomponents. TODO: keep elsewhere
  4265. var Splitter = /** @class */ (function () {
  4266. function Splitter() {
  4267. this.getKeysForEventDefs = memoize(this._getKeysForEventDefs);
  4268. this.splitDateSelection = memoize(this._splitDateSpan);
  4269. this.splitEventStore = memoize(this._splitEventStore);
  4270. this.splitIndividualUi = memoize(this._splitIndividualUi);
  4271. this.splitEventDrag = memoize(this._splitInteraction);
  4272. this.splitEventResize = memoize(this._splitInteraction);
  4273. this.eventUiBuilders = {}; // TODO: typescript protection
  4274. }
  4275. Splitter.prototype.splitProps = function (props) {
  4276. var _this = this;
  4277. var keyInfos = this.getKeyInfo(props);
  4278. var defKeys = this.getKeysForEventDefs(props.eventStore);
  4279. var dateSelections = this.splitDateSelection(props.dateSelection);
  4280. var individualUi = this.splitIndividualUi(props.eventUiBases, defKeys); // the individual *bases*
  4281. var eventStores = this.splitEventStore(props.eventStore, defKeys);
  4282. var eventDrags = this.splitEventDrag(props.eventDrag);
  4283. var eventResizes = this.splitEventResize(props.eventResize);
  4284. var splitProps = {};
  4285. this.eventUiBuilders = mapHash(keyInfos, function (info, key) { return _this.eventUiBuilders[key] || memoize(buildEventUiForKey); });
  4286. for (var key in keyInfos) {
  4287. var keyInfo = keyInfos[key];
  4288. var eventStore = eventStores[key] || EMPTY_EVENT_STORE;
  4289. var buildEventUi = this.eventUiBuilders[key];
  4290. splitProps[key] = {
  4291. businessHours: keyInfo.businessHours || props.businessHours,
  4292. dateSelection: dateSelections[key] || null,
  4293. eventStore: eventStore,
  4294. eventUiBases: buildEventUi(props.eventUiBases[''], keyInfo.ui, individualUi[key]),
  4295. eventSelection: eventStore.instances[props.eventSelection] ? props.eventSelection : '',
  4296. eventDrag: eventDrags[key] || null,
  4297. eventResize: eventResizes[key] || null,
  4298. };
  4299. }
  4300. return splitProps;
  4301. };
  4302. Splitter.prototype._splitDateSpan = function (dateSpan) {
  4303. var dateSpans = {};
  4304. if (dateSpan) {
  4305. var keys = this.getKeysForDateSpan(dateSpan);
  4306. for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) {
  4307. var key = keys_1[_i];
  4308. dateSpans[key] = dateSpan;
  4309. }
  4310. }
  4311. return dateSpans;
  4312. };
  4313. Splitter.prototype._getKeysForEventDefs = function (eventStore) {
  4314. var _this = this;
  4315. return mapHash(eventStore.defs, function (eventDef) { return _this.getKeysForEventDef(eventDef); });
  4316. };
  4317. Splitter.prototype._splitEventStore = function (eventStore, defKeys) {
  4318. var defs = eventStore.defs, instances = eventStore.instances;
  4319. var splitStores = {};
  4320. for (var defId in defs) {
  4321. for (var _i = 0, _a = defKeys[defId]; _i < _a.length; _i++) {
  4322. var key = _a[_i];
  4323. if (!splitStores[key]) {
  4324. splitStores[key] = createEmptyEventStore();
  4325. }
  4326. splitStores[key].defs[defId] = defs[defId];
  4327. }
  4328. }
  4329. for (var instanceId in instances) {
  4330. var instance = instances[instanceId];
  4331. for (var _b = 0, _c = defKeys[instance.defId]; _b < _c.length; _b++) {
  4332. var key = _c[_b];
  4333. if (splitStores[key]) { // must have already been created
  4334. splitStores[key].instances[instanceId] = instance;
  4335. }
  4336. }
  4337. }
  4338. return splitStores;
  4339. };
  4340. Splitter.prototype._splitIndividualUi = function (eventUiBases, defKeys) {
  4341. var splitHashes = {};
  4342. for (var defId in eventUiBases) {
  4343. if (defId) { // not the '' key
  4344. for (var _i = 0, _a = defKeys[defId]; _i < _a.length; _i++) {
  4345. var key = _a[_i];
  4346. if (!splitHashes[key]) {
  4347. splitHashes[key] = {};
  4348. }
  4349. splitHashes[key][defId] = eventUiBases[defId];
  4350. }
  4351. }
  4352. }
  4353. return splitHashes;
  4354. };
  4355. Splitter.prototype._splitInteraction = function (interaction) {
  4356. var splitStates = {};
  4357. if (interaction) {
  4358. var affectedStores_1 = this._splitEventStore(interaction.affectedEvents, this._getKeysForEventDefs(interaction.affectedEvents));
  4359. // can't rely on defKeys because event data is mutated
  4360. var mutatedKeysByDefId = this._getKeysForEventDefs(interaction.mutatedEvents);
  4361. var mutatedStores_1 = this._splitEventStore(interaction.mutatedEvents, mutatedKeysByDefId);
  4362. var populate = function (key) {
  4363. if (!splitStates[key]) {
  4364. splitStates[key] = {
  4365. affectedEvents: affectedStores_1[key] || EMPTY_EVENT_STORE,
  4366. mutatedEvents: mutatedStores_1[key] || EMPTY_EVENT_STORE,
  4367. isEvent: interaction.isEvent,
  4368. };
  4369. }
  4370. };
  4371. for (var key in affectedStores_1) {
  4372. populate(key);
  4373. }
  4374. for (var key in mutatedStores_1) {
  4375. populate(key);
  4376. }
  4377. }
  4378. return splitStates;
  4379. };
  4380. return Splitter;
  4381. }());
  4382. function buildEventUiForKey(allUi, eventUiForKey, individualUi) {
  4383. var baseParts = [];
  4384. if (allUi) {
  4385. baseParts.push(allUi);
  4386. }
  4387. if (eventUiForKey) {
  4388. baseParts.push(eventUiForKey);
  4389. }
  4390. var stuff = {
  4391. '': combineEventUis(baseParts),
  4392. };
  4393. if (individualUi) {
  4394. __assign(stuff, individualUi);
  4395. }
  4396. return stuff;
  4397. }
  4398. function getDateMeta(date, todayRange, nowDate, dateProfile) {
  4399. return {
  4400. dow: date.getUTCDay(),
  4401. isDisabled: Boolean(dateProfile && !rangeContainsMarker(dateProfile.activeRange, date)),
  4402. isOther: Boolean(dateProfile && !rangeContainsMarker(dateProfile.currentRange, date)),
  4403. isToday: Boolean(todayRange && rangeContainsMarker(todayRange, date)),
  4404. isPast: Boolean(nowDate ? (date < nowDate) : todayRange ? (date < todayRange.start) : false),
  4405. isFuture: Boolean(nowDate ? (date > nowDate) : todayRange ? (date >= todayRange.end) : false),
  4406. };
  4407. }
  4408. function getDayClassNames(meta, theme) {
  4409. var classNames = [
  4410. 'fc-day',
  4411. "fc-day-" + DAY_IDS[meta.dow],
  4412. ];
  4413. if (meta.isDisabled) {
  4414. classNames.push('fc-day-disabled');
  4415. }
  4416. else {
  4417. if (meta.isToday) {
  4418. classNames.push('fc-day-today');
  4419. classNames.push(theme.getClass('today'));
  4420. }
  4421. if (meta.isPast) {
  4422. classNames.push('fc-day-past');
  4423. }
  4424. if (meta.isFuture) {
  4425. classNames.push('fc-day-future');
  4426. }
  4427. if (meta.isOther) {
  4428. classNames.push('fc-day-other');
  4429. }
  4430. }
  4431. return classNames;
  4432. }
  4433. function getSlotClassNames(meta, theme) {
  4434. var classNames = [
  4435. 'fc-slot',
  4436. "fc-slot-" + DAY_IDS[meta.dow],
  4437. ];
  4438. if (meta.isDisabled) {
  4439. classNames.push('fc-slot-disabled');
  4440. }
  4441. else {
  4442. if (meta.isToday) {
  4443. classNames.push('fc-slot-today');
  4444. classNames.push(theme.getClass('today'));
  4445. }
  4446. if (meta.isPast) {
  4447. classNames.push('fc-slot-past');
  4448. }
  4449. if (meta.isFuture) {
  4450. classNames.push('fc-slot-future');
  4451. }
  4452. }
  4453. return classNames;
  4454. }
  4455. function buildNavLinkData(date, type) {
  4456. if (type === void 0) { type = 'day'; }
  4457. return JSON.stringify({
  4458. date: formatDayString(date),
  4459. type: type,
  4460. });
  4461. }
  4462. var _isRtlScrollbarOnLeft = null;
  4463. function getIsRtlScrollbarOnLeft() {
  4464. if (_isRtlScrollbarOnLeft === null) {
  4465. _isRtlScrollbarOnLeft = computeIsRtlScrollbarOnLeft();
  4466. }
  4467. return _isRtlScrollbarOnLeft;
  4468. }
  4469. function computeIsRtlScrollbarOnLeft() {
  4470. var outerEl = document.createElement('div');
  4471. applyStyle(outerEl, {
  4472. position: 'absolute',
  4473. top: -1000,
  4474. left: 0,
  4475. border: 0,
  4476. padding: 0,
  4477. overflow: 'scroll',
  4478. direction: 'rtl',
  4479. });
  4480. outerEl.innerHTML = '<div></div>';
  4481. document.body.appendChild(outerEl);
  4482. var innerEl = outerEl.firstChild;
  4483. var res = innerEl.getBoundingClientRect().left > outerEl.getBoundingClientRect().left;
  4484. removeElement(outerEl);
  4485. return res;
  4486. }
  4487. var _scrollbarWidths;
  4488. function getScrollbarWidths() {
  4489. if (!_scrollbarWidths) {
  4490. _scrollbarWidths = computeScrollbarWidths();
  4491. }
  4492. return _scrollbarWidths;
  4493. }
  4494. function computeScrollbarWidths() {
  4495. var el = document.createElement('div');
  4496. el.style.overflow = 'scroll';
  4497. el.style.position = 'absolute';
  4498. el.style.top = '-9999px';
  4499. el.style.left = '-9999px';
  4500. document.body.appendChild(el);
  4501. var res = computeScrollbarWidthsForEl(el);
  4502. document.body.removeChild(el);
  4503. return res;
  4504. }
  4505. // WARNING: will include border
  4506. function computeScrollbarWidthsForEl(el) {
  4507. return {
  4508. x: el.offsetHeight - el.clientHeight,
  4509. y: el.offsetWidth - el.clientWidth,
  4510. };
  4511. }
  4512. function computeEdges(el, getPadding) {
  4513. if (getPadding === void 0) { getPadding = false; }
  4514. var computedStyle = window.getComputedStyle(el);
  4515. var borderLeft = parseInt(computedStyle.borderLeftWidth, 10) || 0;
  4516. var borderRight = parseInt(computedStyle.borderRightWidth, 10) || 0;
  4517. var borderTop = parseInt(computedStyle.borderTopWidth, 10) || 0;
  4518. var borderBottom = parseInt(computedStyle.borderBottomWidth, 10) || 0;
  4519. var badScrollbarWidths = computeScrollbarWidthsForEl(el); // includes border!
  4520. var scrollbarLeftRight = badScrollbarWidths.y - borderLeft - borderRight;
  4521. var scrollbarBottom = badScrollbarWidths.x - borderTop - borderBottom;
  4522. var res = {
  4523. borderLeft: borderLeft,
  4524. borderRight: borderRight,
  4525. borderTop: borderTop,
  4526. borderBottom: borderBottom,
  4527. scrollbarBottom: scrollbarBottom,
  4528. scrollbarLeft: 0,
  4529. scrollbarRight: 0,
  4530. };
  4531. if (getIsRtlScrollbarOnLeft() && computedStyle.direction === 'rtl') { // is the scrollbar on the left side?
  4532. res.scrollbarLeft = scrollbarLeftRight;
  4533. }
  4534. else {
  4535. res.scrollbarRight = scrollbarLeftRight;
  4536. }
  4537. if (getPadding) {
  4538. res.paddingLeft = parseInt(computedStyle.paddingLeft, 10) || 0;
  4539. res.paddingRight = parseInt(computedStyle.paddingRight, 10) || 0;
  4540. res.paddingTop = parseInt(computedStyle.paddingTop, 10) || 0;
  4541. res.paddingBottom = parseInt(computedStyle.paddingBottom, 10) || 0;
  4542. }
  4543. return res;
  4544. }
  4545. function computeInnerRect(el, goWithinPadding, doFromWindowViewport) {
  4546. if (goWithinPadding === void 0) { goWithinPadding = false; }
  4547. var outerRect = doFromWindowViewport ? el.getBoundingClientRect() : computeRect(el);
  4548. var edges = computeEdges(el, goWithinPadding);
  4549. var res = {
  4550. left: outerRect.left + edges.borderLeft + edges.scrollbarLeft,
  4551. right: outerRect.right - edges.borderRight - edges.scrollbarRight,
  4552. top: outerRect.top + edges.borderTop,
  4553. bottom: outerRect.bottom - edges.borderBottom - edges.scrollbarBottom,
  4554. };
  4555. if (goWithinPadding) {
  4556. res.left += edges.paddingLeft;
  4557. res.right -= edges.paddingRight;
  4558. res.top += edges.paddingTop;
  4559. res.bottom -= edges.paddingBottom;
  4560. }
  4561. return res;
  4562. }
  4563. function computeRect(el) {
  4564. var rect = el.getBoundingClientRect();
  4565. return {
  4566. left: rect.left + window.pageXOffset,
  4567. top: rect.top + window.pageYOffset,
  4568. right: rect.right + window.pageXOffset,
  4569. bottom: rect.bottom + window.pageYOffset,
  4570. };
  4571. }
  4572. function computeClippedClientRect(el) {
  4573. var clippingParents = getClippingParents(el);
  4574. var rect = el.getBoundingClientRect();
  4575. for (var _i = 0, clippingParents_1 = clippingParents; _i < clippingParents_1.length; _i++) {
  4576. var clippingParent = clippingParents_1[_i];
  4577. var intersection = intersectRects(rect, clippingParent.getBoundingClientRect());
  4578. if (intersection) {
  4579. rect = intersection;
  4580. }
  4581. else {
  4582. return null;
  4583. }
  4584. }
  4585. return rect;
  4586. }
  4587. function computeHeightAndMargins(el) {
  4588. return el.getBoundingClientRect().height + computeVMargins(el);
  4589. }
  4590. function computeVMargins(el) {
  4591. var computed = window.getComputedStyle(el);
  4592. return parseInt(computed.marginTop, 10) +
  4593. parseInt(computed.marginBottom, 10);
  4594. }
  4595. // does not return window
  4596. function getClippingParents(el) {
  4597. var parents = [];
  4598. while (el instanceof HTMLElement) { // will stop when gets to document or null
  4599. var computedStyle = window.getComputedStyle(el);
  4600. if (computedStyle.position === 'fixed') {
  4601. break;
  4602. }
  4603. if ((/(auto|scroll)/).test(computedStyle.overflow + computedStyle.overflowY + computedStyle.overflowX)) {
  4604. parents.push(el);
  4605. }
  4606. el = el.parentNode;
  4607. }
  4608. return parents;
  4609. }
  4610. // given a function that resolves a result asynchronously.
  4611. // the function can either call passed-in success and failure callbacks,
  4612. // or it can return a promise.
  4613. // if you need to pass additional params to func, bind them first.
  4614. function unpromisify(func, success, failure) {
  4615. // guard against success/failure callbacks being called more than once
  4616. // and guard against a promise AND callback being used together.
  4617. var isResolved = false;
  4618. var wrappedSuccess = function () {
  4619. if (!isResolved) {
  4620. isResolved = true;
  4621. success.apply(this, arguments); // eslint-disable-line prefer-rest-params
  4622. }
  4623. };
  4624. var wrappedFailure = function () {
  4625. if (!isResolved) {
  4626. isResolved = true;
  4627. if (failure) {
  4628. failure.apply(this, arguments); // eslint-disable-line prefer-rest-params
  4629. }
  4630. }
  4631. };
  4632. var res = func(wrappedSuccess, wrappedFailure);
  4633. if (res && typeof res.then === 'function') {
  4634. res.then(wrappedSuccess, wrappedFailure);
  4635. }
  4636. }
  4637. var Emitter = /** @class */ (function () {
  4638. function Emitter() {
  4639. this.handlers = {};
  4640. this.thisContext = null;
  4641. }
  4642. Emitter.prototype.setThisContext = function (thisContext) {
  4643. this.thisContext = thisContext;
  4644. };
  4645. Emitter.prototype.setOptions = function (options) {
  4646. this.options = options;
  4647. };
  4648. Emitter.prototype.on = function (type, handler) {
  4649. addToHash(this.handlers, type, handler);
  4650. };
  4651. Emitter.prototype.off = function (type, handler) {
  4652. removeFromHash(this.handlers, type, handler);
  4653. };
  4654. Emitter.prototype.trigger = function (type) {
  4655. var args = [];
  4656. for (var _i = 1; _i < arguments.length; _i++) {
  4657. args[_i - 1] = arguments[_i];
  4658. }
  4659. var attachedHandlers = this.handlers[type] || [];
  4660. var optionHandler = this.options && this.options[type];
  4661. var handlers = [].concat(optionHandler || [], attachedHandlers);
  4662. for (var _a = 0, handlers_1 = handlers; _a < handlers_1.length; _a++) {
  4663. var handler = handlers_1[_a];
  4664. handler.apply(this.thisContext, args);
  4665. }
  4666. };
  4667. Emitter.prototype.hasHandlers = function (type) {
  4668. return (this.handlers[type] && this.handlers[type].length) ||
  4669. (this.options && this.options[type]);
  4670. };
  4671. return Emitter;
  4672. }());
  4673. function addToHash(hash, type, handler) {
  4674. (hash[type] || (hash[type] = []))
  4675. .push(handler);
  4676. }
  4677. function removeFromHash(hash, type, handler) {
  4678. if (handler) {
  4679. if (hash[type]) {
  4680. hash[type] = hash[type].filter(function (func) { return func !== handler; });
  4681. }
  4682. }
  4683. else {
  4684. delete hash[type]; // remove all handler funcs for this type
  4685. }
  4686. }
  4687. /*
  4688. Records offset information for a set of elements, relative to an origin element.
  4689. Can record the left/right OR the top/bottom OR both.
  4690. Provides methods for querying the cache by position.
  4691. */
  4692. var PositionCache = /** @class */ (function () {
  4693. function PositionCache(originEl, els, isHorizontal, isVertical) {
  4694. this.els = els;
  4695. var originClientRect = this.originClientRect = originEl.getBoundingClientRect(); // relative to viewport top-left
  4696. if (isHorizontal) {
  4697. this.buildElHorizontals(originClientRect.left);
  4698. }
  4699. if (isVertical) {
  4700. this.buildElVerticals(originClientRect.top);
  4701. }
  4702. }
  4703. // Populates the left/right internal coordinate arrays
  4704. PositionCache.prototype.buildElHorizontals = function (originClientLeft) {
  4705. var lefts = [];
  4706. var rights = [];
  4707. for (var _i = 0, _a = this.els; _i < _a.length; _i++) {
  4708. var el = _a[_i];
  4709. var rect = el.getBoundingClientRect();
  4710. lefts.push(rect.left - originClientLeft);
  4711. rights.push(rect.right - originClientLeft);
  4712. }
  4713. this.lefts = lefts;
  4714. this.rights = rights;
  4715. };
  4716. // Populates the top/bottom internal coordinate arrays
  4717. PositionCache.prototype.buildElVerticals = function (originClientTop) {
  4718. var tops = [];
  4719. var bottoms = [];
  4720. for (var _i = 0, _a = this.els; _i < _a.length; _i++) {
  4721. var el = _a[_i];
  4722. var rect = el.getBoundingClientRect();
  4723. tops.push(rect.top - originClientTop);
  4724. bottoms.push(rect.bottom - originClientTop);
  4725. }
  4726. this.tops = tops;
  4727. this.bottoms = bottoms;
  4728. };
  4729. // Given a left offset (from document left), returns the index of the el that it horizontally intersects.
  4730. // If no intersection is made, returns undefined.
  4731. PositionCache.prototype.leftToIndex = function (leftPosition) {
  4732. var _a = this, lefts = _a.lefts, rights = _a.rights;
  4733. var len = lefts.length;
  4734. var i;
  4735. for (i = 0; i < len; i += 1) {
  4736. if (leftPosition >= lefts[i] && leftPosition < rights[i]) {
  4737. return i;
  4738. }
  4739. }
  4740. return undefined; // TODO: better
  4741. };
  4742. // Given a top offset (from document top), returns the index of the el that it vertically intersects.
  4743. // If no intersection is made, returns undefined.
  4744. PositionCache.prototype.topToIndex = function (topPosition) {
  4745. var _a = this, tops = _a.tops, bottoms = _a.bottoms;
  4746. var len = tops.length;
  4747. var i;
  4748. for (i = 0; i < len; i += 1) {
  4749. if (topPosition >= tops[i] && topPosition < bottoms[i]) {
  4750. return i;
  4751. }
  4752. }
  4753. return undefined; // TODO: better
  4754. };
  4755. // Gets the width of the element at the given index
  4756. PositionCache.prototype.getWidth = function (leftIndex) {
  4757. return this.rights[leftIndex] - this.lefts[leftIndex];
  4758. };
  4759. // Gets the height of the element at the given index
  4760. PositionCache.prototype.getHeight = function (topIndex) {
  4761. return this.bottoms[topIndex] - this.tops[topIndex];
  4762. };
  4763. return PositionCache;
  4764. }());
  4765. /* eslint max-classes-per-file: "off" */
  4766. /*
  4767. An object for getting/setting scroll-related information for an element.
  4768. Internally, this is done very differently for window versus DOM element,
  4769. so this object serves as a common interface.
  4770. */
  4771. var ScrollController = /** @class */ (function () {
  4772. function ScrollController() {
  4773. }
  4774. ScrollController.prototype.getMaxScrollTop = function () {
  4775. return this.getScrollHeight() - this.getClientHeight();
  4776. };
  4777. ScrollController.prototype.getMaxScrollLeft = function () {
  4778. return this.getScrollWidth() - this.getClientWidth();
  4779. };
  4780. ScrollController.prototype.canScrollVertically = function () {
  4781. return this.getMaxScrollTop() > 0;
  4782. };
  4783. ScrollController.prototype.canScrollHorizontally = function () {
  4784. return this.getMaxScrollLeft() > 0;
  4785. };
  4786. ScrollController.prototype.canScrollUp = function () {
  4787. return this.getScrollTop() > 0;
  4788. };
  4789. ScrollController.prototype.canScrollDown = function () {
  4790. return this.getScrollTop() < this.getMaxScrollTop();
  4791. };
  4792. ScrollController.prototype.canScrollLeft = function () {
  4793. return this.getScrollLeft() > 0;
  4794. };
  4795. ScrollController.prototype.canScrollRight = function () {
  4796. return this.getScrollLeft() < this.getMaxScrollLeft();
  4797. };
  4798. return ScrollController;
  4799. }());
  4800. var ElementScrollController = /** @class */ (function (_super) {
  4801. __extends(ElementScrollController, _super);
  4802. function ElementScrollController(el) {
  4803. var _this = _super.call(this) || this;
  4804. _this.el = el;
  4805. return _this;
  4806. }
  4807. ElementScrollController.prototype.getScrollTop = function () {
  4808. return this.el.scrollTop;
  4809. };
  4810. ElementScrollController.prototype.getScrollLeft = function () {
  4811. return this.el.scrollLeft;
  4812. };
  4813. ElementScrollController.prototype.setScrollTop = function (top) {
  4814. this.el.scrollTop = top;
  4815. };
  4816. ElementScrollController.prototype.setScrollLeft = function (left) {
  4817. this.el.scrollLeft = left;
  4818. };
  4819. ElementScrollController.prototype.getScrollWidth = function () {
  4820. return this.el.scrollWidth;
  4821. };
  4822. ElementScrollController.prototype.getScrollHeight = function () {
  4823. return this.el.scrollHeight;
  4824. };
  4825. ElementScrollController.prototype.getClientHeight = function () {
  4826. return this.el.clientHeight;
  4827. };
  4828. ElementScrollController.prototype.getClientWidth = function () {
  4829. return this.el.clientWidth;
  4830. };
  4831. return ElementScrollController;
  4832. }(ScrollController));
  4833. var WindowScrollController = /** @class */ (function (_super) {
  4834. __extends(WindowScrollController, _super);
  4835. function WindowScrollController() {
  4836. return _super !== null && _super.apply(this, arguments) || this;
  4837. }
  4838. WindowScrollController.prototype.getScrollTop = function () {
  4839. return window.pageYOffset;
  4840. };
  4841. WindowScrollController.prototype.getScrollLeft = function () {
  4842. return window.pageXOffset;
  4843. };
  4844. WindowScrollController.prototype.setScrollTop = function (n) {
  4845. window.scroll(window.pageXOffset, n);
  4846. };
  4847. WindowScrollController.prototype.setScrollLeft = function (n) {
  4848. window.scroll(n, window.pageYOffset);
  4849. };
  4850. WindowScrollController.prototype.getScrollWidth = function () {
  4851. return document.documentElement.scrollWidth;
  4852. };
  4853. WindowScrollController.prototype.getScrollHeight = function () {
  4854. return document.documentElement.scrollHeight;
  4855. };
  4856. WindowScrollController.prototype.getClientHeight = function () {
  4857. return document.documentElement.clientHeight;
  4858. };
  4859. WindowScrollController.prototype.getClientWidth = function () {
  4860. return document.documentElement.clientWidth;
  4861. };
  4862. return WindowScrollController;
  4863. }(ScrollController));
  4864. var Theme = /** @class */ (function () {
  4865. function Theme(calendarOptions) {
  4866. if (this.iconOverrideOption) {
  4867. this.setIconOverride(calendarOptions[this.iconOverrideOption]);
  4868. }
  4869. }
  4870. Theme.prototype.setIconOverride = function (iconOverrideHash) {
  4871. var iconClassesCopy;
  4872. var buttonName;
  4873. if (typeof iconOverrideHash === 'object' && iconOverrideHash) { // non-null object
  4874. iconClassesCopy = __assign({}, this.iconClasses);
  4875. for (buttonName in iconOverrideHash) {
  4876. iconClassesCopy[buttonName] = this.applyIconOverridePrefix(iconOverrideHash[buttonName]);
  4877. }
  4878. this.iconClasses = iconClassesCopy;
  4879. }
  4880. else if (iconOverrideHash === false) {
  4881. this.iconClasses = {};
  4882. }
  4883. };
  4884. Theme.prototype.applyIconOverridePrefix = function (className) {
  4885. var prefix = this.iconOverridePrefix;
  4886. if (prefix && className.indexOf(prefix) !== 0) { // if not already present
  4887. className = prefix + className;
  4888. }
  4889. return className;
  4890. };
  4891. Theme.prototype.getClass = function (key) {
  4892. return this.classes[key] || '';
  4893. };
  4894. Theme.prototype.getIconClass = function (buttonName, isRtl) {
  4895. var className;
  4896. if (isRtl && this.rtlIconClasses) {
  4897. className = this.rtlIconClasses[buttonName] || this.iconClasses[buttonName];
  4898. }
  4899. else {
  4900. className = this.iconClasses[buttonName];
  4901. }
  4902. if (className) {
  4903. return this.baseIconClass + " " + className;
  4904. }
  4905. return '';
  4906. };
  4907. Theme.prototype.getCustomButtonIconClass = function (customButtonProps) {
  4908. var className;
  4909. if (this.iconOverrideCustomButtonOption) {
  4910. className = customButtonProps[this.iconOverrideCustomButtonOption];
  4911. if (className) {
  4912. return this.baseIconClass + " " + this.applyIconOverridePrefix(className);
  4913. }
  4914. }
  4915. return '';
  4916. };
  4917. return Theme;
  4918. }());
  4919. Theme.prototype.classes = {};
  4920. Theme.prototype.iconClasses = {};
  4921. Theme.prototype.baseIconClass = '';
  4922. Theme.prototype.iconOverridePrefix = '';
  4923. /// <reference types="@fullcalendar/core-preact" />
  4924. if (typeof FullCalendarVDom === 'undefined') {
  4925. throw new Error('Please import the top-level fullcalendar lib before attempting to import a plugin.');
  4926. }
  4927. var Component = FullCalendarVDom.Component;
  4928. var createElement = FullCalendarVDom.createElement;
  4929. var render = FullCalendarVDom.render;
  4930. var createRef = FullCalendarVDom.createRef;
  4931. var Fragment = FullCalendarVDom.Fragment;
  4932. var createContext = FullCalendarVDom.createContext;
  4933. var createPortal = FullCalendarVDom.createPortal;
  4934. var flushToDom = FullCalendarVDom.flushToDom;
  4935. var unmountComponentAtNode = FullCalendarVDom.unmountComponentAtNode;
  4936. /* eslint-enable */
  4937. var ScrollResponder = /** @class */ (function () {
  4938. function ScrollResponder(execFunc, emitter, scrollTime, scrollTimeReset) {
  4939. var _this = this;
  4940. this.execFunc = execFunc;
  4941. this.emitter = emitter;
  4942. this.scrollTime = scrollTime;
  4943. this.scrollTimeReset = scrollTimeReset;
  4944. this.handleScrollRequest = function (request) {
  4945. _this.queuedRequest = __assign({}, _this.queuedRequest || {}, request);
  4946. _this.drain();
  4947. };
  4948. emitter.on('_scrollRequest', this.handleScrollRequest);
  4949. this.fireInitialScroll();
  4950. }
  4951. ScrollResponder.prototype.detach = function () {
  4952. this.emitter.off('_scrollRequest', this.handleScrollRequest);
  4953. };
  4954. ScrollResponder.prototype.update = function (isDatesNew) {
  4955. if (isDatesNew && this.scrollTimeReset) {
  4956. this.fireInitialScroll(); // will drain
  4957. }
  4958. else {
  4959. this.drain();
  4960. }
  4961. };
  4962. ScrollResponder.prototype.fireInitialScroll = function () {
  4963. this.handleScrollRequest({
  4964. time: this.scrollTime,
  4965. });
  4966. };
  4967. ScrollResponder.prototype.drain = function () {
  4968. if (this.queuedRequest && this.execFunc(this.queuedRequest)) {
  4969. this.queuedRequest = null;
  4970. }
  4971. };
  4972. return ScrollResponder;
  4973. }());
  4974. var ViewContextType = createContext({}); // for Components
  4975. function buildViewContext(viewSpec, viewApi, viewOptions, dateProfileGenerator, dateEnv, theme, pluginHooks, dispatch, getCurrentData, emitter, calendarApi, registerInteractiveComponent, unregisterInteractiveComponent) {
  4976. return {
  4977. dateEnv: dateEnv,
  4978. options: viewOptions,
  4979. pluginHooks: pluginHooks,
  4980. emitter: emitter,
  4981. dispatch: dispatch,
  4982. getCurrentData: getCurrentData,
  4983. calendarApi: calendarApi,
  4984. viewSpec: viewSpec,
  4985. viewApi: viewApi,
  4986. dateProfileGenerator: dateProfileGenerator,
  4987. theme: theme,
  4988. isRtl: viewOptions.direction === 'rtl',
  4989. addResizeHandler: function (handler) {
  4990. emitter.on('_resize', handler);
  4991. },
  4992. removeResizeHandler: function (handler) {
  4993. emitter.off('_resize', handler);
  4994. },
  4995. createScrollResponder: function (execFunc) {
  4996. return new ScrollResponder(execFunc, emitter, createDuration(viewOptions.scrollTime), viewOptions.scrollTimeReset);
  4997. },
  4998. registerInteractiveComponent: registerInteractiveComponent,
  4999. unregisterInteractiveComponent: unregisterInteractiveComponent,
  5000. };
  5001. }
  5002. /* eslint max-classes-per-file: off */
  5003. var PureComponent = /** @class */ (function (_super) {
  5004. __extends(PureComponent, _super);
  5005. function PureComponent() {
  5006. return _super !== null && _super.apply(this, arguments) || this;
  5007. }
  5008. PureComponent.prototype.shouldComponentUpdate = function (nextProps, nextState) {
  5009. if (this.debug) {
  5010. // eslint-disable-next-line no-console
  5011. console.log(getUnequalProps(nextProps, this.props), getUnequalProps(nextState, this.state));
  5012. }
  5013. return !compareObjs(this.props, nextProps, this.propEquality) ||
  5014. !compareObjs(this.state, nextState, this.stateEquality);
  5015. };
  5016. PureComponent.addPropsEquality = addPropsEquality;
  5017. PureComponent.addStateEquality = addStateEquality;
  5018. PureComponent.contextType = ViewContextType;
  5019. return PureComponent;
  5020. }(Component));
  5021. PureComponent.prototype.propEquality = {};
  5022. PureComponent.prototype.stateEquality = {};
  5023. var BaseComponent = /** @class */ (function (_super) {
  5024. __extends(BaseComponent, _super);
  5025. function BaseComponent() {
  5026. return _super !== null && _super.apply(this, arguments) || this;
  5027. }
  5028. BaseComponent.contextType = ViewContextType;
  5029. return BaseComponent;
  5030. }(PureComponent));
  5031. function addPropsEquality(propEquality) {
  5032. var hash = Object.create(this.prototype.propEquality);
  5033. __assign(hash, propEquality);
  5034. this.prototype.propEquality = hash;
  5035. }
  5036. function addStateEquality(stateEquality) {
  5037. var hash = Object.create(this.prototype.stateEquality);
  5038. __assign(hash, stateEquality);
  5039. this.prototype.stateEquality = hash;
  5040. }
  5041. // use other one
  5042. function setRef(ref, current) {
  5043. if (typeof ref === 'function') {
  5044. ref(current);
  5045. }
  5046. else if (ref) {
  5047. // see https://github.com/facebook/react/issues/13029
  5048. ref.current = current;
  5049. }
  5050. }
  5051. /*
  5052. an INTERACTABLE date component
  5053. PURPOSES:
  5054. - hook up to fg, fill, and mirror renderers
  5055. - interface for dragging and hits
  5056. */
  5057. var DateComponent = /** @class */ (function (_super) {
  5058. __extends(DateComponent, _super);
  5059. function DateComponent() {
  5060. var _this = _super !== null && _super.apply(this, arguments) || this;
  5061. _this.uid = guid();
  5062. return _this;
  5063. }
  5064. // Hit System
  5065. // -----------------------------------------------------------------------------------------------------------------
  5066. DateComponent.prototype.prepareHits = function () {
  5067. };
  5068. DateComponent.prototype.queryHit = function (positionLeft, positionTop, elWidth, elHeight) {
  5069. return null; // this should be abstract
  5070. };
  5071. // Pointer Interaction Utils
  5072. // -----------------------------------------------------------------------------------------------------------------
  5073. DateComponent.prototype.isValidSegDownEl = function (el) {
  5074. return !this.props.eventDrag && // HACK
  5075. !this.props.eventResize && // HACK
  5076. !elementClosest(el, '.fc-event-mirror');
  5077. };
  5078. DateComponent.prototype.isValidDateDownEl = function (el) {
  5079. return !elementClosest(el, '.fc-event:not(.fc-bg-event)') &&
  5080. !elementClosest(el, '.fc-more-link') && // a "more.." link
  5081. !elementClosest(el, 'a[data-navlink]') && // a clickable nav link
  5082. !elementClosest(el, '.fc-popover'); // hack
  5083. };
  5084. return DateComponent;
  5085. }(BaseComponent));
  5086. // TODO: easier way to add new hooks? need to update a million things
  5087. function createPlugin(input) {
  5088. return {
  5089. id: guid(),
  5090. deps: input.deps || [],
  5091. reducers: input.reducers || [],
  5092. isLoadingFuncs: input.isLoadingFuncs || [],
  5093. contextInit: [].concat(input.contextInit || []),
  5094. eventRefiners: input.eventRefiners || {},
  5095. eventDefMemberAdders: input.eventDefMemberAdders || [],
  5096. eventSourceRefiners: input.eventSourceRefiners || {},
  5097. isDraggableTransformers: input.isDraggableTransformers || [],
  5098. eventDragMutationMassagers: input.eventDragMutationMassagers || [],
  5099. eventDefMutationAppliers: input.eventDefMutationAppliers || [],
  5100. dateSelectionTransformers: input.dateSelectionTransformers || [],
  5101. datePointTransforms: input.datePointTransforms || [],
  5102. dateSpanTransforms: input.dateSpanTransforms || [],
  5103. views: input.views || {},
  5104. viewPropsTransformers: input.viewPropsTransformers || [],
  5105. isPropsValid: input.isPropsValid || null,
  5106. externalDefTransforms: input.externalDefTransforms || [],
  5107. viewContainerAppends: input.viewContainerAppends || [],
  5108. eventDropTransformers: input.eventDropTransformers || [],
  5109. componentInteractions: input.componentInteractions || [],
  5110. calendarInteractions: input.calendarInteractions || [],
  5111. themeClasses: input.themeClasses || {},
  5112. eventSourceDefs: input.eventSourceDefs || [],
  5113. cmdFormatter: input.cmdFormatter,
  5114. recurringTypes: input.recurringTypes || [],
  5115. namedTimeZonedImpl: input.namedTimeZonedImpl,
  5116. initialView: input.initialView || '',
  5117. elementDraggingImpl: input.elementDraggingImpl,
  5118. optionChangeHandlers: input.optionChangeHandlers || {},
  5119. scrollGridImpl: input.scrollGridImpl || null,
  5120. contentTypeHandlers: input.contentTypeHandlers || {},
  5121. listenerRefiners: input.listenerRefiners || {},
  5122. optionRefiners: input.optionRefiners || {},
  5123. propSetHandlers: input.propSetHandlers || {},
  5124. };
  5125. }
  5126. function buildPluginHooks(pluginDefs, globalDefs) {
  5127. var isAdded = {};
  5128. var hooks = {
  5129. reducers: [],
  5130. isLoadingFuncs: [],
  5131. contextInit: [],
  5132. eventRefiners: {},
  5133. eventDefMemberAdders: [],
  5134. eventSourceRefiners: {},
  5135. isDraggableTransformers: [],
  5136. eventDragMutationMassagers: [],
  5137. eventDefMutationAppliers: [],
  5138. dateSelectionTransformers: [],
  5139. datePointTransforms: [],
  5140. dateSpanTransforms: [],
  5141. views: {},
  5142. viewPropsTransformers: [],
  5143. isPropsValid: null,
  5144. externalDefTransforms: [],
  5145. viewContainerAppends: [],
  5146. eventDropTransformers: [],
  5147. componentInteractions: [],
  5148. calendarInteractions: [],
  5149. themeClasses: {},
  5150. eventSourceDefs: [],
  5151. cmdFormatter: null,
  5152. recurringTypes: [],
  5153. namedTimeZonedImpl: null,
  5154. initialView: '',
  5155. elementDraggingImpl: null,
  5156. optionChangeHandlers: {},
  5157. scrollGridImpl: null,
  5158. contentTypeHandlers: {},
  5159. listenerRefiners: {},
  5160. optionRefiners: {},
  5161. propSetHandlers: {},
  5162. };
  5163. function addDefs(defs) {
  5164. for (var _i = 0, defs_1 = defs; _i < defs_1.length; _i++) {
  5165. var def = defs_1[_i];
  5166. if (!isAdded[def.id]) {
  5167. isAdded[def.id] = true;
  5168. addDefs(def.deps);
  5169. hooks = combineHooks(hooks, def);
  5170. }
  5171. }
  5172. }
  5173. if (pluginDefs) {
  5174. addDefs(pluginDefs);
  5175. }
  5176. addDefs(globalDefs);
  5177. return hooks;
  5178. }
  5179. function buildBuildPluginHooks() {
  5180. var currentOverrideDefs = [];
  5181. var currentGlobalDefs = [];
  5182. var currentHooks;
  5183. return function (overrideDefs, globalDefs) {
  5184. if (!currentHooks || !isArraysEqual(overrideDefs, currentOverrideDefs) || !isArraysEqual(globalDefs, currentGlobalDefs)) {
  5185. currentHooks = buildPluginHooks(overrideDefs, globalDefs);
  5186. }
  5187. currentOverrideDefs = overrideDefs;
  5188. currentGlobalDefs = globalDefs;
  5189. return currentHooks;
  5190. };
  5191. }
  5192. function combineHooks(hooks0, hooks1) {
  5193. return {
  5194. reducers: hooks0.reducers.concat(hooks1.reducers),
  5195. isLoadingFuncs: hooks0.isLoadingFuncs.concat(hooks1.isLoadingFuncs),
  5196. contextInit: hooks0.contextInit.concat(hooks1.contextInit),
  5197. eventRefiners: __assign(__assign({}, hooks0.eventRefiners), hooks1.eventRefiners),
  5198. eventDefMemberAdders: hooks0.eventDefMemberAdders.concat(hooks1.eventDefMemberAdders),
  5199. eventSourceRefiners: __assign(__assign({}, hooks0.eventSourceRefiners), hooks1.eventSourceRefiners),
  5200. isDraggableTransformers: hooks0.isDraggableTransformers.concat(hooks1.isDraggableTransformers),
  5201. eventDragMutationMassagers: hooks0.eventDragMutationMassagers.concat(hooks1.eventDragMutationMassagers),
  5202. eventDefMutationAppliers: hooks0.eventDefMutationAppliers.concat(hooks1.eventDefMutationAppliers),
  5203. dateSelectionTransformers: hooks0.dateSelectionTransformers.concat(hooks1.dateSelectionTransformers),
  5204. datePointTransforms: hooks0.datePointTransforms.concat(hooks1.datePointTransforms),
  5205. dateSpanTransforms: hooks0.dateSpanTransforms.concat(hooks1.dateSpanTransforms),
  5206. views: __assign(__assign({}, hooks0.views), hooks1.views),
  5207. viewPropsTransformers: hooks0.viewPropsTransformers.concat(hooks1.viewPropsTransformers),
  5208. isPropsValid: hooks1.isPropsValid || hooks0.isPropsValid,
  5209. externalDefTransforms: hooks0.externalDefTransforms.concat(hooks1.externalDefTransforms),
  5210. viewContainerAppends: hooks0.viewContainerAppends.concat(hooks1.viewContainerAppends),
  5211. eventDropTransformers: hooks0.eventDropTransformers.concat(hooks1.eventDropTransformers),
  5212. calendarInteractions: hooks0.calendarInteractions.concat(hooks1.calendarInteractions),
  5213. componentInteractions: hooks0.componentInteractions.concat(hooks1.componentInteractions),
  5214. themeClasses: __assign(__assign({}, hooks0.themeClasses), hooks1.themeClasses),
  5215. eventSourceDefs: hooks0.eventSourceDefs.concat(hooks1.eventSourceDefs),
  5216. cmdFormatter: hooks1.cmdFormatter || hooks0.cmdFormatter,
  5217. recurringTypes: hooks0.recurringTypes.concat(hooks1.recurringTypes),
  5218. namedTimeZonedImpl: hooks1.namedTimeZonedImpl || hooks0.namedTimeZonedImpl,
  5219. initialView: hooks0.initialView || hooks1.initialView,
  5220. elementDraggingImpl: hooks0.elementDraggingImpl || hooks1.elementDraggingImpl,
  5221. optionChangeHandlers: __assign(__assign({}, hooks0.optionChangeHandlers), hooks1.optionChangeHandlers),
  5222. scrollGridImpl: hooks1.scrollGridImpl || hooks0.scrollGridImpl,
  5223. contentTypeHandlers: __assign(__assign({}, hooks0.contentTypeHandlers), hooks1.contentTypeHandlers),
  5224. listenerRefiners: __assign(__assign({}, hooks0.listenerRefiners), hooks1.listenerRefiners),
  5225. optionRefiners: __assign(__assign({}, hooks0.optionRefiners), hooks1.optionRefiners),
  5226. propSetHandlers: __assign(__assign({}, hooks0.propSetHandlers), hooks1.propSetHandlers),
  5227. };
  5228. }
  5229. var StandardTheme = /** @class */ (function (_super) {
  5230. __extends(StandardTheme, _super);
  5231. function StandardTheme() {
  5232. return _super !== null && _super.apply(this, arguments) || this;
  5233. }
  5234. return StandardTheme;
  5235. }(Theme));
  5236. StandardTheme.prototype.classes = {
  5237. root: 'fc-theme-standard',
  5238. tableCellShaded: 'fc-cell-shaded',
  5239. buttonGroup: 'fc-button-group',
  5240. button: 'fc-button fc-button-primary',
  5241. buttonActive: 'fc-button-active',
  5242. };
  5243. StandardTheme.prototype.baseIconClass = 'fc-icon';
  5244. StandardTheme.prototype.iconClasses = {
  5245. close: 'fc-icon-x',
  5246. prev: 'fc-icon-chevron-left',
  5247. next: 'fc-icon-chevron-right',
  5248. prevYear: 'fc-icon-chevrons-left',
  5249. nextYear: 'fc-icon-chevrons-right',
  5250. };
  5251. StandardTheme.prototype.rtlIconClasses = {
  5252. prev: 'fc-icon-chevron-right',
  5253. next: 'fc-icon-chevron-left',
  5254. prevYear: 'fc-icon-chevrons-right',
  5255. nextYear: 'fc-icon-chevrons-left',
  5256. };
  5257. StandardTheme.prototype.iconOverrideOption = 'buttonIcons'; // TODO: make TS-friendly
  5258. StandardTheme.prototype.iconOverrideCustomButtonOption = 'icon';
  5259. StandardTheme.prototype.iconOverridePrefix = 'fc-icon-';
  5260. function compileViewDefs(defaultConfigs, overrideConfigs) {
  5261. var hash = {};
  5262. var viewType;
  5263. for (viewType in defaultConfigs) {
  5264. ensureViewDef(viewType, hash, defaultConfigs, overrideConfigs);
  5265. }
  5266. for (viewType in overrideConfigs) {
  5267. ensureViewDef(viewType, hash, defaultConfigs, overrideConfigs);
  5268. }
  5269. return hash;
  5270. }
  5271. function ensureViewDef(viewType, hash, defaultConfigs, overrideConfigs) {
  5272. if (hash[viewType]) {
  5273. return hash[viewType];
  5274. }
  5275. var viewDef = buildViewDef(viewType, hash, defaultConfigs, overrideConfigs);
  5276. if (viewDef) {
  5277. hash[viewType] = viewDef;
  5278. }
  5279. return viewDef;
  5280. }
  5281. function buildViewDef(viewType, hash, defaultConfigs, overrideConfigs) {
  5282. var defaultConfig = defaultConfigs[viewType];
  5283. var overrideConfig = overrideConfigs[viewType];
  5284. var queryProp = function (name) { return ((defaultConfig && defaultConfig[name] !== null) ? defaultConfig[name] :
  5285. ((overrideConfig && overrideConfig[name] !== null) ? overrideConfig[name] : null)); };
  5286. var theComponent = queryProp('component');
  5287. var superType = queryProp('superType');
  5288. var superDef = null;
  5289. if (superType) {
  5290. if (superType === viewType) {
  5291. throw new Error('Can\'t have a custom view type that references itself');
  5292. }
  5293. superDef = ensureViewDef(superType, hash, defaultConfigs, overrideConfigs);
  5294. }
  5295. if (!theComponent && superDef) {
  5296. theComponent = superDef.component;
  5297. }
  5298. if (!theComponent) {
  5299. return null; // don't throw a warning, might be settings for a single-unit view
  5300. }
  5301. return {
  5302. type: viewType,
  5303. component: theComponent,
  5304. defaults: __assign(__assign({}, (superDef ? superDef.defaults : {})), (defaultConfig ? defaultConfig.rawOptions : {})),
  5305. overrides: __assign(__assign({}, (superDef ? superDef.overrides : {})), (overrideConfig ? overrideConfig.rawOptions : {})),
  5306. };
  5307. }
  5308. /* eslint max-classes-per-file: off */
  5309. // NOTE: in JSX, you should always use this class with <HookProps> arg. otherwise, will default to any???
  5310. var RenderHook = /** @class */ (function (_super) {
  5311. __extends(RenderHook, _super);
  5312. function RenderHook() {
  5313. var _this = _super !== null && _super.apply(this, arguments) || this;
  5314. _this.rootElRef = createRef();
  5315. _this.handleRootEl = function (el) {
  5316. setRef(_this.rootElRef, el);
  5317. if (_this.props.elRef) {
  5318. setRef(_this.props.elRef, el);
  5319. }
  5320. };
  5321. return _this;
  5322. }
  5323. RenderHook.prototype.render = function () {
  5324. var _this = this;
  5325. var props = this.props;
  5326. var hookProps = props.hookProps;
  5327. return (createElement(MountHook, { hookProps: hookProps, didMount: props.didMount, willUnmount: props.willUnmount, elRef: this.handleRootEl }, function (rootElRef) { return (createElement(ContentHook, { hookProps: hookProps, content: props.content, defaultContent: props.defaultContent, backupElRef: _this.rootElRef }, function (innerElRef, innerContent) { return props.children(rootElRef, normalizeClassNames(props.classNames, hookProps), innerElRef, innerContent); })); }));
  5328. };
  5329. return RenderHook;
  5330. }(BaseComponent));
  5331. // TODO: rename to be about function, not default. use in above type
  5332. // for forcing rerender of components that use the ContentHook
  5333. var CustomContentRenderContext = createContext(0);
  5334. function ContentHook(props) {
  5335. return (createElement(CustomContentRenderContext.Consumer, null, function (renderId) { return (createElement(ContentHookInner, __assign({ renderId: renderId }, props))); }));
  5336. }
  5337. var ContentHookInner = /** @class */ (function (_super) {
  5338. __extends(ContentHookInner, _super);
  5339. function ContentHookInner() {
  5340. var _this = _super !== null && _super.apply(this, arguments) || this;
  5341. _this.innerElRef = createRef();
  5342. return _this;
  5343. }
  5344. ContentHookInner.prototype.render = function () {
  5345. return this.props.children(this.innerElRef, this.renderInnerContent());
  5346. };
  5347. ContentHookInner.prototype.componentDidMount = function () {
  5348. this.updateCustomContent();
  5349. };
  5350. ContentHookInner.prototype.componentDidUpdate = function () {
  5351. this.updateCustomContent();
  5352. };
  5353. ContentHookInner.prototype.componentWillUnmount = function () {
  5354. if (this.customContentInfo && this.customContentInfo.destroy) {
  5355. this.customContentInfo.destroy();
  5356. }
  5357. };
  5358. ContentHookInner.prototype.renderInnerContent = function () {
  5359. var contentTypeHandlers = this.context.pluginHooks.contentTypeHandlers;
  5360. var _a = this, props = _a.props, customContentInfo = _a.customContentInfo;
  5361. var rawVal = props.content;
  5362. var innerContent = normalizeContent(rawVal, props.hookProps);
  5363. var innerContentVDom = null;
  5364. if (innerContent === undefined) { // use the default
  5365. innerContent = normalizeContent(props.defaultContent, props.hookProps);
  5366. }
  5367. if (innerContent !== undefined) { // we allow custom content handlers to return nothing
  5368. if (customContentInfo) {
  5369. customContentInfo.contentVal = innerContent[customContentInfo.contentKey];
  5370. }
  5371. else if (typeof innerContent === 'object') {
  5372. // look for a prop that would indicate a custom content handler is needed
  5373. for (var contentKey in contentTypeHandlers) {
  5374. if (innerContent[contentKey] !== undefined) {
  5375. var stuff = contentTypeHandlers[contentKey]();
  5376. customContentInfo = this.customContentInfo = __assign({ contentKey: contentKey, contentVal: innerContent[contentKey] }, stuff);
  5377. break;
  5378. }
  5379. }
  5380. }
  5381. if (customContentInfo) {
  5382. innerContentVDom = []; // signal that something was specified
  5383. }
  5384. else {
  5385. innerContentVDom = innerContent; // assume a [p]react vdom node. use it
  5386. }
  5387. }
  5388. return innerContentVDom;
  5389. };
  5390. ContentHookInner.prototype.updateCustomContent = function () {
  5391. if (this.customContentInfo) {
  5392. this.customContentInfo.render(this.innerElRef.current || this.props.backupElRef.current, // the element to render into
  5393. this.customContentInfo.contentVal);
  5394. }
  5395. };
  5396. return ContentHookInner;
  5397. }(BaseComponent));
  5398. var MountHook = /** @class */ (function (_super) {
  5399. __extends(MountHook, _super);
  5400. function MountHook() {
  5401. var _this = _super !== null && _super.apply(this, arguments) || this;
  5402. _this.handleRootEl = function (rootEl) {
  5403. _this.rootEl = rootEl;
  5404. if (_this.props.elRef) {
  5405. setRef(_this.props.elRef, rootEl);
  5406. }
  5407. };
  5408. return _this;
  5409. }
  5410. MountHook.prototype.render = function () {
  5411. return this.props.children(this.handleRootEl);
  5412. };
  5413. MountHook.prototype.componentDidMount = function () {
  5414. var callback = this.props.didMount;
  5415. if (callback) {
  5416. callback(__assign(__assign({}, this.props.hookProps), { el: this.rootEl }));
  5417. }
  5418. };
  5419. MountHook.prototype.componentWillUnmount = function () {
  5420. var callback = this.props.willUnmount;
  5421. if (callback) {
  5422. callback(__assign(__assign({}, this.props.hookProps), { el: this.rootEl }));
  5423. }
  5424. };
  5425. return MountHook;
  5426. }(BaseComponent));
  5427. function buildClassNameNormalizer() {
  5428. var currentGenerator;
  5429. var currentHookProps;
  5430. var currentClassNames = [];
  5431. return function (generator, hookProps) {
  5432. if (!currentHookProps || !isPropsEqual(currentHookProps, hookProps) || generator !== currentGenerator) {
  5433. currentGenerator = generator;
  5434. currentHookProps = hookProps;
  5435. currentClassNames = normalizeClassNames(generator, hookProps);
  5436. }
  5437. return currentClassNames;
  5438. };
  5439. }
  5440. function normalizeClassNames(classNames, hookProps) {
  5441. if (typeof classNames === 'function') {
  5442. classNames = classNames(hookProps);
  5443. }
  5444. return parseClassNames(classNames);
  5445. }
  5446. function normalizeContent(input, hookProps) {
  5447. if (typeof input === 'function') {
  5448. return input(hookProps, createElement); // give the function the vdom-creation func
  5449. }
  5450. return input;
  5451. }
  5452. var ViewRoot = /** @class */ (function (_super) {
  5453. __extends(ViewRoot, _super);
  5454. function ViewRoot() {
  5455. var _this = _super !== null && _super.apply(this, arguments) || this;
  5456. _this.normalizeClassNames = buildClassNameNormalizer();
  5457. return _this;
  5458. }
  5459. ViewRoot.prototype.render = function () {
  5460. var _a = this, props = _a.props, context = _a.context;
  5461. var options = context.options;
  5462. var hookProps = { view: context.viewApi };
  5463. var customClassNames = this.normalizeClassNames(options.viewClassNames, hookProps);
  5464. return (createElement(MountHook, { hookProps: hookProps, didMount: options.viewDidMount, willUnmount: options.viewWillUnmount, elRef: props.elRef }, function (rootElRef) { return props.children(rootElRef, ["fc-" + props.viewSpec.type + "-view", 'fc-view'].concat(customClassNames)); }));
  5465. };
  5466. return ViewRoot;
  5467. }(BaseComponent));
  5468. function parseViewConfigs(inputs) {
  5469. return mapHash(inputs, parseViewConfig);
  5470. }
  5471. function parseViewConfig(input) {
  5472. var rawOptions = typeof input === 'function' ?
  5473. { component: input } :
  5474. input;
  5475. var component = rawOptions.component;
  5476. if (rawOptions.content) {
  5477. component = createViewHookComponent(rawOptions);
  5478. // TODO: remove content/classNames/didMount/etc from options?
  5479. }
  5480. return {
  5481. superType: rawOptions.type,
  5482. component: component,
  5483. rawOptions: rawOptions,
  5484. };
  5485. }
  5486. function createViewHookComponent(options) {
  5487. return function (viewProps) { return (createElement(ViewContextType.Consumer, null, function (context) { return (createElement(ViewRoot, { viewSpec: context.viewSpec }, function (viewElRef, viewClassNames) {
  5488. var hookProps = __assign(__assign({}, viewProps), { nextDayThreshold: context.options.nextDayThreshold });
  5489. return (createElement(RenderHook, { hookProps: hookProps, classNames: options.classNames, content: options.content, didMount: options.didMount, willUnmount: options.willUnmount, elRef: viewElRef }, function (rootElRef, customClassNames, innerElRef, innerContent) { return (createElement("div", { className: viewClassNames.concat(customClassNames).join(' '), ref: rootElRef }, innerContent)); }));
  5490. })); })); };
  5491. }
  5492. function buildViewSpecs(defaultInputs, optionOverrides, dynamicOptionOverrides, localeDefaults) {
  5493. var defaultConfigs = parseViewConfigs(defaultInputs);
  5494. var overrideConfigs = parseViewConfigs(optionOverrides.views);
  5495. var viewDefs = compileViewDefs(defaultConfigs, overrideConfigs);
  5496. return mapHash(viewDefs, function (viewDef) { return buildViewSpec(viewDef, overrideConfigs, optionOverrides, dynamicOptionOverrides, localeDefaults); });
  5497. }
  5498. function buildViewSpec(viewDef, overrideConfigs, optionOverrides, dynamicOptionOverrides, localeDefaults) {
  5499. var durationInput = viewDef.overrides.duration ||
  5500. viewDef.defaults.duration ||
  5501. dynamicOptionOverrides.duration ||
  5502. optionOverrides.duration;
  5503. var duration = null;
  5504. var durationUnit = '';
  5505. var singleUnit = '';
  5506. var singleUnitOverrides = {};
  5507. if (durationInput) {
  5508. duration = createDurationCached(durationInput);
  5509. if (duration) { // valid?
  5510. var denom = greatestDurationDenominator(duration);
  5511. durationUnit = denom.unit;
  5512. if (denom.value === 1) {
  5513. singleUnit = durationUnit;
  5514. singleUnitOverrides = overrideConfigs[durationUnit] ? overrideConfigs[durationUnit].rawOptions : {};
  5515. }
  5516. }
  5517. }
  5518. var queryButtonText = function (optionsSubset) {
  5519. var buttonTextMap = optionsSubset.buttonText || {};
  5520. var buttonTextKey = viewDef.defaults.buttonTextKey;
  5521. if (buttonTextKey != null && buttonTextMap[buttonTextKey] != null) {
  5522. return buttonTextMap[buttonTextKey];
  5523. }
  5524. if (buttonTextMap[viewDef.type] != null) {
  5525. return buttonTextMap[viewDef.type];
  5526. }
  5527. if (buttonTextMap[singleUnit] != null) {
  5528. return buttonTextMap[singleUnit];
  5529. }
  5530. return null;
  5531. };
  5532. return {
  5533. type: viewDef.type,
  5534. component: viewDef.component,
  5535. duration: duration,
  5536. durationUnit: durationUnit,
  5537. singleUnit: singleUnit,
  5538. optionDefaults: viewDef.defaults,
  5539. optionOverrides: __assign(__assign({}, singleUnitOverrides), viewDef.overrides),
  5540. buttonTextOverride: queryButtonText(dynamicOptionOverrides) ||
  5541. queryButtonText(optionOverrides) || // constructor-specified buttonText lookup hash takes precedence
  5542. viewDef.overrides.buttonText,
  5543. buttonTextDefault: queryButtonText(localeDefaults) ||
  5544. viewDef.defaults.buttonText ||
  5545. queryButtonText(BASE_OPTION_DEFAULTS) ||
  5546. viewDef.type, // fall back to given view name
  5547. };
  5548. }
  5549. // hack to get memoization working
  5550. var durationInputMap = {};
  5551. function createDurationCached(durationInput) {
  5552. var json = JSON.stringify(durationInput);
  5553. var res = durationInputMap[json];
  5554. if (res === undefined) {
  5555. res = createDuration(durationInput);
  5556. durationInputMap[json] = res;
  5557. }
  5558. return res;
  5559. }
  5560. var DateProfileGenerator = /** @class */ (function () {
  5561. function DateProfileGenerator(props) {
  5562. this.props = props;
  5563. this.nowDate = getNow(props.nowInput, props.dateEnv);
  5564. this.initHiddenDays();
  5565. }
  5566. /* Date Range Computation
  5567. ------------------------------------------------------------------------------------------------------------------*/
  5568. // Builds a structure with info about what the dates/ranges will be for the "prev" view.
  5569. DateProfileGenerator.prototype.buildPrev = function (currentDateProfile, currentDate, forceToValid) {
  5570. var dateEnv = this.props.dateEnv;
  5571. var prevDate = dateEnv.subtract(dateEnv.startOf(currentDate, currentDateProfile.currentRangeUnit), // important for start-of-month
  5572. currentDateProfile.dateIncrement);
  5573. return this.build(prevDate, -1, forceToValid);
  5574. };
  5575. // Builds a structure with info about what the dates/ranges will be for the "next" view.
  5576. DateProfileGenerator.prototype.buildNext = function (currentDateProfile, currentDate, forceToValid) {
  5577. var dateEnv = this.props.dateEnv;
  5578. var nextDate = dateEnv.add(dateEnv.startOf(currentDate, currentDateProfile.currentRangeUnit), // important for start-of-month
  5579. currentDateProfile.dateIncrement);
  5580. return this.build(nextDate, 1, forceToValid);
  5581. };
  5582. // Builds a structure holding dates/ranges for rendering around the given date.
  5583. // Optional direction param indicates whether the date is being incremented/decremented
  5584. // from its previous value. decremented = -1, incremented = 1 (default).
  5585. DateProfileGenerator.prototype.build = function (currentDate, direction, forceToValid) {
  5586. if (forceToValid === void 0) { forceToValid = true; }
  5587. var props = this.props;
  5588. var validRange;
  5589. var currentInfo;
  5590. var isRangeAllDay;
  5591. var renderRange;
  5592. var activeRange;
  5593. var isValid;
  5594. validRange = this.buildValidRange();
  5595. validRange = this.trimHiddenDays(validRange);
  5596. if (forceToValid) {
  5597. currentDate = constrainMarkerToRange(currentDate, validRange);
  5598. }
  5599. currentInfo = this.buildCurrentRangeInfo(currentDate, direction);
  5600. isRangeAllDay = /^(year|month|week|day)$/.test(currentInfo.unit);
  5601. renderRange = this.buildRenderRange(this.trimHiddenDays(currentInfo.range), currentInfo.unit, isRangeAllDay);
  5602. renderRange = this.trimHiddenDays(renderRange);
  5603. activeRange = renderRange;
  5604. if (!props.showNonCurrentDates) {
  5605. activeRange = intersectRanges(activeRange, currentInfo.range);
  5606. }
  5607. activeRange = this.adjustActiveRange(activeRange);
  5608. activeRange = intersectRanges(activeRange, validRange); // might return null
  5609. // it's invalid if the originally requested date is not contained,
  5610. // or if the range is completely outside of the valid range.
  5611. isValid = rangesIntersect(currentInfo.range, validRange);
  5612. return {
  5613. // constraint for where prev/next operations can go and where events can be dragged/resized to.
  5614. // an object with optional start and end properties.
  5615. validRange: validRange,
  5616. // range the view is formally responsible for.
  5617. // for example, a month view might have 1st-31st, excluding padded dates
  5618. currentRange: currentInfo.range,
  5619. // name of largest unit being displayed, like "month" or "week"
  5620. currentRangeUnit: currentInfo.unit,
  5621. isRangeAllDay: isRangeAllDay,
  5622. // dates that display events and accept drag-n-drop
  5623. // will be `null` if no dates accept events
  5624. activeRange: activeRange,
  5625. // date range with a rendered skeleton
  5626. // includes not-active days that need some sort of DOM
  5627. renderRange: renderRange,
  5628. // Duration object that denotes the first visible time of any given day
  5629. slotMinTime: props.slotMinTime,
  5630. // Duration object that denotes the exclusive visible end time of any given day
  5631. slotMaxTime: props.slotMaxTime,
  5632. isValid: isValid,
  5633. // how far the current date will move for a prev/next operation
  5634. dateIncrement: this.buildDateIncrement(currentInfo.duration),
  5635. // pass a fallback (might be null) ^
  5636. };
  5637. };
  5638. // Builds an object with optional start/end properties.
  5639. // Indicates the minimum/maximum dates to display.
  5640. // not responsible for trimming hidden days.
  5641. DateProfileGenerator.prototype.buildValidRange = function () {
  5642. var input = this.props.validRangeInput;
  5643. var simpleInput = typeof input === 'function'
  5644. ? input.call(this.props.calendarApi, this.nowDate)
  5645. : input;
  5646. return this.refineRange(simpleInput) ||
  5647. { start: null, end: null }; // completely open-ended
  5648. };
  5649. // Builds a structure with info about the "current" range, the range that is
  5650. // highlighted as being the current month for example.
  5651. // See build() for a description of `direction`.
  5652. // Guaranteed to have `range` and `unit` properties. `duration` is optional.
  5653. DateProfileGenerator.prototype.buildCurrentRangeInfo = function (date, direction) {
  5654. var props = this.props;
  5655. var duration = null;
  5656. var unit = null;
  5657. var range = null;
  5658. var dayCount;
  5659. if (props.duration) {
  5660. duration = props.duration;
  5661. unit = props.durationUnit;
  5662. range = this.buildRangeFromDuration(date, direction, duration, unit);
  5663. }
  5664. else if ((dayCount = this.props.dayCount)) {
  5665. unit = 'day';
  5666. range = this.buildRangeFromDayCount(date, direction, dayCount);
  5667. }
  5668. else if ((range = this.buildCustomVisibleRange(date))) {
  5669. unit = props.dateEnv.greatestWholeUnit(range.start, range.end).unit;
  5670. }
  5671. else {
  5672. duration = this.getFallbackDuration();
  5673. unit = greatestDurationDenominator(duration).unit;
  5674. range = this.buildRangeFromDuration(date, direction, duration, unit);
  5675. }
  5676. return { duration: duration, unit: unit, range: range };
  5677. };
  5678. DateProfileGenerator.prototype.getFallbackDuration = function () {
  5679. return createDuration({ day: 1 });
  5680. };
  5681. // Returns a new activeRange to have time values (un-ambiguate)
  5682. // slotMinTime or slotMaxTime causes the range to expand.
  5683. DateProfileGenerator.prototype.adjustActiveRange = function (range) {
  5684. var _a = this.props, dateEnv = _a.dateEnv, usesMinMaxTime = _a.usesMinMaxTime, slotMinTime = _a.slotMinTime, slotMaxTime = _a.slotMaxTime;
  5685. var start = range.start, end = range.end;
  5686. if (usesMinMaxTime) {
  5687. // expand active range if slotMinTime is negative (why not when positive?)
  5688. if (asRoughDays(slotMinTime) < 0) {
  5689. start = startOfDay(start); // necessary?
  5690. start = dateEnv.add(start, slotMinTime);
  5691. }
  5692. // expand active range if slotMaxTime is beyond one day (why not when negative?)
  5693. if (asRoughDays(slotMaxTime) > 1) {
  5694. end = startOfDay(end); // necessary?
  5695. end = addDays(end, -1);
  5696. end = dateEnv.add(end, slotMaxTime);
  5697. }
  5698. }
  5699. return { start: start, end: end };
  5700. };
  5701. // Builds the "current" range when it is specified as an explicit duration.
  5702. // `unit` is the already-computed greatestDurationDenominator unit of duration.
  5703. DateProfileGenerator.prototype.buildRangeFromDuration = function (date, direction, duration, unit) {
  5704. var _a = this.props, dateEnv = _a.dateEnv, dateAlignment = _a.dateAlignment;
  5705. var start;
  5706. var end;
  5707. var res;
  5708. // compute what the alignment should be
  5709. if (!dateAlignment) {
  5710. var dateIncrement = this.props.dateIncrement;
  5711. if (dateIncrement) {
  5712. // use the smaller of the two units
  5713. if (asRoughMs(dateIncrement) < asRoughMs(duration)) {
  5714. dateAlignment = greatestDurationDenominator(dateIncrement).unit;
  5715. }
  5716. else {
  5717. dateAlignment = unit;
  5718. }
  5719. }
  5720. else {
  5721. dateAlignment = unit;
  5722. }
  5723. }
  5724. // if the view displays a single day or smaller
  5725. if (asRoughDays(duration) <= 1) {
  5726. if (this.isHiddenDay(start)) {
  5727. start = this.skipHiddenDays(start, direction);
  5728. start = startOfDay(start);
  5729. }
  5730. }
  5731. function computeRes() {
  5732. start = dateEnv.startOf(date, dateAlignment);
  5733. end = dateEnv.add(start, duration);
  5734. res = { start: start, end: end };
  5735. }
  5736. computeRes();
  5737. // if range is completely enveloped by hidden days, go past the hidden days
  5738. if (!this.trimHiddenDays(res)) {
  5739. date = this.skipHiddenDays(date, direction);
  5740. computeRes();
  5741. }
  5742. return res;
  5743. };
  5744. // Builds the "current" range when a dayCount is specified.
  5745. DateProfileGenerator.prototype.buildRangeFromDayCount = function (date, direction, dayCount) {
  5746. var _a = this.props, dateEnv = _a.dateEnv, dateAlignment = _a.dateAlignment;
  5747. var runningCount = 0;
  5748. var start = date;
  5749. var end;
  5750. if (dateAlignment) {
  5751. start = dateEnv.startOf(start, dateAlignment);
  5752. }
  5753. start = startOfDay(start);
  5754. start = this.skipHiddenDays(start, direction);
  5755. end = start;
  5756. do {
  5757. end = addDays(end, 1);
  5758. if (!this.isHiddenDay(end)) {
  5759. runningCount += 1;
  5760. }
  5761. } while (runningCount < dayCount);
  5762. return { start: start, end: end };
  5763. };
  5764. // Builds a normalized range object for the "visible" range,
  5765. // which is a way to define the currentRange and activeRange at the same time.
  5766. DateProfileGenerator.prototype.buildCustomVisibleRange = function (date) {
  5767. var props = this.props;
  5768. var input = props.visibleRangeInput;
  5769. var simpleInput = typeof input === 'function'
  5770. ? input.call(props.calendarApi, props.dateEnv.toDate(date))
  5771. : input;
  5772. var range = this.refineRange(simpleInput);
  5773. if (range && (range.start == null || range.end == null)) {
  5774. return null;
  5775. }
  5776. return range;
  5777. };
  5778. // Computes the range that will represent the element/cells for *rendering*,
  5779. // but which may have voided days/times.
  5780. // not responsible for trimming hidden days.
  5781. DateProfileGenerator.prototype.buildRenderRange = function (currentRange, currentRangeUnit, isRangeAllDay) {
  5782. return currentRange;
  5783. };
  5784. // Compute the duration value that should be added/substracted to the current date
  5785. // when a prev/next operation happens.
  5786. DateProfileGenerator.prototype.buildDateIncrement = function (fallback) {
  5787. var dateIncrement = this.props.dateIncrement;
  5788. var customAlignment;
  5789. if (dateIncrement) {
  5790. return dateIncrement;
  5791. }
  5792. if ((customAlignment = this.props.dateAlignment)) {
  5793. return createDuration(1, customAlignment);
  5794. }
  5795. if (fallback) {
  5796. return fallback;
  5797. }
  5798. return createDuration({ days: 1 });
  5799. };
  5800. DateProfileGenerator.prototype.refineRange = function (rangeInput) {
  5801. if (rangeInput) {
  5802. var range = parseRange(rangeInput, this.props.dateEnv);
  5803. if (range) {
  5804. range = computeVisibleDayRange(range);
  5805. }
  5806. return range;
  5807. }
  5808. return null;
  5809. };
  5810. /* Hidden Days
  5811. ------------------------------------------------------------------------------------------------------------------*/
  5812. // Initializes internal variables related to calculating hidden days-of-week
  5813. DateProfileGenerator.prototype.initHiddenDays = function () {
  5814. var hiddenDays = this.props.hiddenDays || []; // array of day-of-week indices that are hidden
  5815. var isHiddenDayHash = []; // is the day-of-week hidden? (hash with day-of-week-index -> bool)
  5816. var dayCnt = 0;
  5817. var i;
  5818. if (this.props.weekends === false) {
  5819. hiddenDays.push(0, 6); // 0=sunday, 6=saturday
  5820. }
  5821. for (i = 0; i < 7; i += 1) {
  5822. if (!(isHiddenDayHash[i] = hiddenDays.indexOf(i) !== -1)) {
  5823. dayCnt += 1;
  5824. }
  5825. }
  5826. if (!dayCnt) {
  5827. throw new Error('invalid hiddenDays'); // all days were hidden? bad.
  5828. }
  5829. this.isHiddenDayHash = isHiddenDayHash;
  5830. };
  5831. // Remove days from the beginning and end of the range that are computed as hidden.
  5832. // If the whole range is trimmed off, returns null
  5833. DateProfileGenerator.prototype.trimHiddenDays = function (range) {
  5834. var start = range.start, end = range.end;
  5835. if (start) {
  5836. start = this.skipHiddenDays(start);
  5837. }
  5838. if (end) {
  5839. end = this.skipHiddenDays(end, -1, true);
  5840. }
  5841. if (start == null || end == null || start < end) {
  5842. return { start: start, end: end };
  5843. }
  5844. return null;
  5845. };
  5846. // Is the current day hidden?
  5847. // `day` is a day-of-week index (0-6), or a Date (used for UTC)
  5848. DateProfileGenerator.prototype.isHiddenDay = function (day) {
  5849. if (day instanceof Date) {
  5850. day = day.getUTCDay();
  5851. }
  5852. return this.isHiddenDayHash[day];
  5853. };
  5854. // Incrementing the current day until it is no longer a hidden day, returning a copy.
  5855. // DOES NOT CONSIDER validRange!
  5856. // If the initial value of `date` is not a hidden day, don't do anything.
  5857. // Pass `isExclusive` as `true` if you are dealing with an end date.
  5858. // `inc` defaults to `1` (increment one day forward each time)
  5859. DateProfileGenerator.prototype.skipHiddenDays = function (date, inc, isExclusive) {
  5860. if (inc === void 0) { inc = 1; }
  5861. if (isExclusive === void 0) { isExclusive = false; }
  5862. while (this.isHiddenDayHash[(date.getUTCDay() + (isExclusive ? inc : 0) + 7) % 7]) {
  5863. date = addDays(date, inc);
  5864. }
  5865. return date;
  5866. };
  5867. return DateProfileGenerator;
  5868. }());
  5869. function reduceViewType(viewType, action) {
  5870. switch (action.type) {
  5871. case 'CHANGE_VIEW_TYPE':
  5872. viewType = action.viewType;
  5873. }
  5874. return viewType;
  5875. }
  5876. function reduceDynamicOptionOverrides(dynamicOptionOverrides, action) {
  5877. var _a;
  5878. switch (action.type) {
  5879. case 'SET_OPTION':
  5880. return __assign(__assign({}, dynamicOptionOverrides), (_a = {}, _a[action.optionName] = action.rawOptionValue, _a));
  5881. default:
  5882. return dynamicOptionOverrides;
  5883. }
  5884. }
  5885. function reduceDateProfile(currentDateProfile, action, currentDate, dateProfileGenerator) {
  5886. var dp;
  5887. switch (action.type) {
  5888. case 'CHANGE_VIEW_TYPE':
  5889. return dateProfileGenerator.build(action.dateMarker || currentDate);
  5890. case 'CHANGE_DATE':
  5891. return dateProfileGenerator.build(action.dateMarker);
  5892. case 'PREV':
  5893. dp = dateProfileGenerator.buildPrev(currentDateProfile, currentDate);
  5894. if (dp.isValid) {
  5895. return dp;
  5896. }
  5897. break;
  5898. case 'NEXT':
  5899. dp = dateProfileGenerator.buildNext(currentDateProfile, currentDate);
  5900. if (dp.isValid) {
  5901. return dp;
  5902. }
  5903. break;
  5904. }
  5905. return currentDateProfile;
  5906. }
  5907. function initEventSources(calendarOptions, dateProfile, context) {
  5908. var activeRange = dateProfile ? dateProfile.activeRange : null;
  5909. return addSources({}, parseInitialSources(calendarOptions, context), activeRange, context);
  5910. }
  5911. function reduceEventSources(eventSources, action, dateProfile, context) {
  5912. var activeRange = dateProfile ? dateProfile.activeRange : null; // need this check?
  5913. switch (action.type) {
  5914. case 'ADD_EVENT_SOURCES': // already parsed
  5915. return addSources(eventSources, action.sources, activeRange, context);
  5916. case 'REMOVE_EVENT_SOURCE':
  5917. return removeSource(eventSources, action.sourceId);
  5918. case 'PREV': // TODO: how do we track all actions that affect dateProfile :(
  5919. case 'NEXT':
  5920. case 'CHANGE_DATE':
  5921. case 'CHANGE_VIEW_TYPE':
  5922. if (dateProfile) {
  5923. return fetchDirtySources(eventSources, activeRange, context);
  5924. }
  5925. return eventSources;
  5926. case 'FETCH_EVENT_SOURCES':
  5927. return fetchSourcesByIds(eventSources, action.sourceIds ? // why no type?
  5928. arrayToHash(action.sourceIds) :
  5929. excludeStaticSources(eventSources, context), activeRange, action.isRefetch || false, context);
  5930. case 'RECEIVE_EVENTS':
  5931. case 'RECEIVE_EVENT_ERROR':
  5932. return receiveResponse(eventSources, action.sourceId, action.fetchId, action.fetchRange);
  5933. case 'REMOVE_ALL_EVENT_SOURCES':
  5934. return {};
  5935. default:
  5936. return eventSources;
  5937. }
  5938. }
  5939. function reduceEventSourcesNewTimeZone(eventSources, dateProfile, context) {
  5940. var activeRange = dateProfile ? dateProfile.activeRange : null; // need this check?
  5941. return fetchSourcesByIds(eventSources, excludeStaticSources(eventSources, context), activeRange, true, context);
  5942. }
  5943. function computeEventSourcesLoading(eventSources) {
  5944. for (var sourceId in eventSources) {
  5945. if (eventSources[sourceId].isFetching) {
  5946. return true;
  5947. }
  5948. }
  5949. return false;
  5950. }
  5951. function addSources(eventSourceHash, sources, fetchRange, context) {
  5952. var hash = {};
  5953. for (var _i = 0, sources_1 = sources; _i < sources_1.length; _i++) {
  5954. var source = sources_1[_i];
  5955. hash[source.sourceId] = source;
  5956. }
  5957. if (fetchRange) {
  5958. hash = fetchDirtySources(hash, fetchRange, context);
  5959. }
  5960. return __assign(__assign({}, eventSourceHash), hash);
  5961. }
  5962. function removeSource(eventSourceHash, sourceId) {
  5963. return filterHash(eventSourceHash, function (eventSource) { return eventSource.sourceId !== sourceId; });
  5964. }
  5965. function fetchDirtySources(sourceHash, fetchRange, context) {
  5966. return fetchSourcesByIds(sourceHash, filterHash(sourceHash, function (eventSource) { return isSourceDirty(eventSource, fetchRange, context); }), fetchRange, false, context);
  5967. }
  5968. function isSourceDirty(eventSource, fetchRange, context) {
  5969. if (!doesSourceNeedRange(eventSource, context)) {
  5970. return !eventSource.latestFetchId;
  5971. }
  5972. return !context.options.lazyFetching ||
  5973. !eventSource.fetchRange ||
  5974. eventSource.isFetching || // always cancel outdated in-progress fetches
  5975. fetchRange.start < eventSource.fetchRange.start ||
  5976. fetchRange.end > eventSource.fetchRange.end;
  5977. }
  5978. function fetchSourcesByIds(prevSources, sourceIdHash, fetchRange, isRefetch, context) {
  5979. var nextSources = {};
  5980. for (var sourceId in prevSources) {
  5981. var source = prevSources[sourceId];
  5982. if (sourceIdHash[sourceId]) {
  5983. nextSources[sourceId] = fetchSource(source, fetchRange, isRefetch, context);
  5984. }
  5985. else {
  5986. nextSources[sourceId] = source;
  5987. }
  5988. }
  5989. return nextSources;
  5990. }
  5991. function fetchSource(eventSource, fetchRange, isRefetch, context) {
  5992. var options = context.options, calendarApi = context.calendarApi;
  5993. var sourceDef = context.pluginHooks.eventSourceDefs[eventSource.sourceDefId];
  5994. var fetchId = guid();
  5995. sourceDef.fetch({
  5996. eventSource: eventSource,
  5997. range: fetchRange,
  5998. isRefetch: isRefetch,
  5999. context: context,
  6000. }, function (res) {
  6001. var rawEvents = res.rawEvents;
  6002. if (options.eventSourceSuccess) {
  6003. rawEvents = options.eventSourceSuccess.call(calendarApi, rawEvents, res.xhr) || rawEvents;
  6004. }
  6005. if (eventSource.success) {
  6006. rawEvents = eventSource.success.call(calendarApi, rawEvents, res.xhr) || rawEvents;
  6007. }
  6008. context.dispatch({
  6009. type: 'RECEIVE_EVENTS',
  6010. sourceId: eventSource.sourceId,
  6011. fetchId: fetchId,
  6012. fetchRange: fetchRange,
  6013. rawEvents: rawEvents,
  6014. });
  6015. }, function (error) {
  6016. console.warn(error.message, error);
  6017. if (options.eventSourceFailure) {
  6018. options.eventSourceFailure.call(calendarApi, error);
  6019. }
  6020. if (eventSource.failure) {
  6021. eventSource.failure(error);
  6022. }
  6023. context.dispatch({
  6024. type: 'RECEIVE_EVENT_ERROR',
  6025. sourceId: eventSource.sourceId,
  6026. fetchId: fetchId,
  6027. fetchRange: fetchRange,
  6028. error: error,
  6029. });
  6030. });
  6031. return __assign(__assign({}, eventSource), { isFetching: true, latestFetchId: fetchId });
  6032. }
  6033. function receiveResponse(sourceHash, sourceId, fetchId, fetchRange) {
  6034. var _a;
  6035. var eventSource = sourceHash[sourceId];
  6036. if (eventSource && // not already removed
  6037. fetchId === eventSource.latestFetchId) {
  6038. return __assign(__assign({}, sourceHash), (_a = {}, _a[sourceId] = __assign(__assign({}, eventSource), { isFetching: false, fetchRange: fetchRange }), _a));
  6039. }
  6040. return sourceHash;
  6041. }
  6042. function excludeStaticSources(eventSources, context) {
  6043. return filterHash(eventSources, function (eventSource) { return doesSourceNeedRange(eventSource, context); });
  6044. }
  6045. function parseInitialSources(rawOptions, context) {
  6046. var refiners = buildEventSourceRefiners(context);
  6047. var rawSources = [].concat(rawOptions.eventSources || []);
  6048. var sources = []; // parsed
  6049. if (rawOptions.initialEvents) {
  6050. rawSources.unshift(rawOptions.initialEvents);
  6051. }
  6052. if (rawOptions.events) {
  6053. rawSources.unshift(rawOptions.events);
  6054. }
  6055. for (var _i = 0, rawSources_1 = rawSources; _i < rawSources_1.length; _i++) {
  6056. var rawSource = rawSources_1[_i];
  6057. var source = parseEventSource(rawSource, context, refiners);
  6058. if (source) {
  6059. sources.push(source);
  6060. }
  6061. }
  6062. return sources;
  6063. }
  6064. function doesSourceNeedRange(eventSource, context) {
  6065. var defs = context.pluginHooks.eventSourceDefs;
  6066. return !defs[eventSource.sourceDefId].ignoreRange;
  6067. }
  6068. function reduceEventStore(eventStore, action, eventSources, dateProfile, context) {
  6069. switch (action.type) {
  6070. case 'RECEIVE_EVENTS': // raw
  6071. return receiveRawEvents(eventStore, eventSources[action.sourceId], action.fetchId, action.fetchRange, action.rawEvents, context);
  6072. case 'ADD_EVENTS': // already parsed, but not expanded
  6073. return addEvent(eventStore, action.eventStore, // new ones
  6074. dateProfile ? dateProfile.activeRange : null, context);
  6075. case 'RESET_EVENTS':
  6076. return action.eventStore;
  6077. case 'MERGE_EVENTS': // already parsed and expanded
  6078. return mergeEventStores(eventStore, action.eventStore);
  6079. case 'PREV': // TODO: how do we track all actions that affect dateProfile :(
  6080. case 'NEXT':
  6081. case 'CHANGE_DATE':
  6082. case 'CHANGE_VIEW_TYPE':
  6083. if (dateProfile) {
  6084. return expandRecurring(eventStore, dateProfile.activeRange, context);
  6085. }
  6086. return eventStore;
  6087. case 'REMOVE_EVENTS':
  6088. return excludeSubEventStore(eventStore, action.eventStore);
  6089. case 'REMOVE_EVENT_SOURCE':
  6090. return excludeEventsBySourceId(eventStore, action.sourceId);
  6091. case 'REMOVE_ALL_EVENT_SOURCES':
  6092. return filterEventStoreDefs(eventStore, function (eventDef) { return (!eventDef.sourceId // only keep events with no source id
  6093. ); });
  6094. case 'REMOVE_ALL_EVENTS':
  6095. return createEmptyEventStore();
  6096. default:
  6097. return eventStore;
  6098. }
  6099. }
  6100. function receiveRawEvents(eventStore, eventSource, fetchId, fetchRange, rawEvents, context) {
  6101. if (eventSource && // not already removed
  6102. fetchId === eventSource.latestFetchId // TODO: wish this logic was always in event-sources
  6103. ) {
  6104. var subset = parseEvents(transformRawEvents(rawEvents, eventSource, context), eventSource, context);
  6105. if (fetchRange) {
  6106. subset = expandRecurring(subset, fetchRange, context);
  6107. }
  6108. return mergeEventStores(excludeEventsBySourceId(eventStore, eventSource.sourceId), subset);
  6109. }
  6110. return eventStore;
  6111. }
  6112. function transformRawEvents(rawEvents, eventSource, context) {
  6113. var calEachTransform = context.options.eventDataTransform;
  6114. var sourceEachTransform = eventSource ? eventSource.eventDataTransform : null;
  6115. if (sourceEachTransform) {
  6116. rawEvents = transformEachRawEvent(rawEvents, sourceEachTransform);
  6117. }
  6118. if (calEachTransform) {
  6119. rawEvents = transformEachRawEvent(rawEvents, calEachTransform);
  6120. }
  6121. return rawEvents;
  6122. }
  6123. function transformEachRawEvent(rawEvents, func) {
  6124. var refinedEvents;
  6125. if (!func) {
  6126. refinedEvents = rawEvents;
  6127. }
  6128. else {
  6129. refinedEvents = [];
  6130. for (var _i = 0, rawEvents_1 = rawEvents; _i < rawEvents_1.length; _i++) {
  6131. var rawEvent = rawEvents_1[_i];
  6132. var refinedEvent = func(rawEvent);
  6133. if (refinedEvent) {
  6134. refinedEvents.push(refinedEvent);
  6135. }
  6136. else if (refinedEvent == null) {
  6137. refinedEvents.push(rawEvent);
  6138. } // if a different falsy value, do nothing
  6139. }
  6140. }
  6141. return refinedEvents;
  6142. }
  6143. function addEvent(eventStore, subset, expandRange, context) {
  6144. if (expandRange) {
  6145. subset = expandRecurring(subset, expandRange, context);
  6146. }
  6147. return mergeEventStores(eventStore, subset);
  6148. }
  6149. function rezoneEventStoreDates(eventStore, oldDateEnv, newDateEnv) {
  6150. var defs = eventStore.defs;
  6151. var instances = mapHash(eventStore.instances, function (instance) {
  6152. var def = defs[instance.defId];
  6153. if (def.allDay || def.recurringDef) {
  6154. return instance; // isn't dependent on timezone
  6155. }
  6156. return __assign(__assign({}, instance), { range: {
  6157. start: newDateEnv.createMarker(oldDateEnv.toDate(instance.range.start, instance.forcedStartTzo)),
  6158. end: newDateEnv.createMarker(oldDateEnv.toDate(instance.range.end, instance.forcedEndTzo)),
  6159. }, forcedStartTzo: newDateEnv.canComputeOffset ? null : instance.forcedStartTzo, forcedEndTzo: newDateEnv.canComputeOffset ? null : instance.forcedEndTzo });
  6160. });
  6161. return { defs: defs, instances: instances };
  6162. }
  6163. function excludeEventsBySourceId(eventStore, sourceId) {
  6164. return filterEventStoreDefs(eventStore, function (eventDef) { return eventDef.sourceId !== sourceId; });
  6165. }
  6166. // QUESTION: why not just return instances? do a general object-property-exclusion util
  6167. function excludeInstances(eventStore, removals) {
  6168. return {
  6169. defs: eventStore.defs,
  6170. instances: filterHash(eventStore.instances, function (instance) { return !removals[instance.instanceId]; }),
  6171. };
  6172. }
  6173. function reduceDateSelection(currentSelection, action) {
  6174. switch (action.type) {
  6175. case 'UNSELECT_DATES':
  6176. return null;
  6177. case 'SELECT_DATES':
  6178. return action.selection;
  6179. default:
  6180. return currentSelection;
  6181. }
  6182. }
  6183. function reduceSelectedEvent(currentInstanceId, action) {
  6184. switch (action.type) {
  6185. case 'UNSELECT_EVENT':
  6186. return '';
  6187. case 'SELECT_EVENT':
  6188. return action.eventInstanceId;
  6189. default:
  6190. return currentInstanceId;
  6191. }
  6192. }
  6193. function reduceEventDrag(currentDrag, action) {
  6194. var newDrag;
  6195. switch (action.type) {
  6196. case 'UNSET_EVENT_DRAG':
  6197. return null;
  6198. case 'SET_EVENT_DRAG':
  6199. newDrag = action.state;
  6200. return {
  6201. affectedEvents: newDrag.affectedEvents,
  6202. mutatedEvents: newDrag.mutatedEvents,
  6203. isEvent: newDrag.isEvent,
  6204. };
  6205. default:
  6206. return currentDrag;
  6207. }
  6208. }
  6209. function reduceEventResize(currentResize, action) {
  6210. var newResize;
  6211. switch (action.type) {
  6212. case 'UNSET_EVENT_RESIZE':
  6213. return null;
  6214. case 'SET_EVENT_RESIZE':
  6215. newResize = action.state;
  6216. return {
  6217. affectedEvents: newResize.affectedEvents,
  6218. mutatedEvents: newResize.mutatedEvents,
  6219. isEvent: newResize.isEvent,
  6220. };
  6221. default:
  6222. return currentResize;
  6223. }
  6224. }
  6225. function parseToolbars(calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi) {
  6226. var viewsWithButtons = [];
  6227. var headerToolbar = calendarOptions.headerToolbar ? parseToolbar(calendarOptions.headerToolbar, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons) : null;
  6228. var footerToolbar = calendarOptions.footerToolbar ? parseToolbar(calendarOptions.footerToolbar, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons) : null;
  6229. return { headerToolbar: headerToolbar, footerToolbar: footerToolbar, viewsWithButtons: viewsWithButtons };
  6230. }
  6231. function parseToolbar(sectionStrHash, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons) {
  6232. return mapHash(sectionStrHash, function (sectionStr) { return parseSection(sectionStr, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons); });
  6233. }
  6234. /*
  6235. BAD: querying icons and text here. should be done at render time
  6236. */
  6237. function parseSection(sectionStr, calendarOptions, calendarOptionOverrides, theme, viewSpecs, calendarApi, viewsWithButtons) {
  6238. var isRtl = calendarOptions.direction === 'rtl';
  6239. var calendarCustomButtons = calendarOptions.customButtons || {};
  6240. var calendarButtonTextOverrides = calendarOptionOverrides.buttonText || {};
  6241. var calendarButtonText = calendarOptions.buttonText || {};
  6242. var sectionSubstrs = sectionStr ? sectionStr.split(' ') : [];
  6243. return sectionSubstrs.map(function (buttonGroupStr) { return (buttonGroupStr.split(',').map(function (buttonName) {
  6244. if (buttonName === 'title') {
  6245. return { buttonName: buttonName };
  6246. }
  6247. var customButtonProps;
  6248. var viewSpec;
  6249. var buttonClick;
  6250. var buttonIcon; // only one of these will be set
  6251. var buttonText; // "
  6252. if ((customButtonProps = calendarCustomButtons[buttonName])) {
  6253. buttonClick = function (ev) {
  6254. if (customButtonProps.click) {
  6255. customButtonProps.click.call(ev.target, ev, ev.target); // TODO: use Calendar this context?
  6256. }
  6257. };
  6258. (buttonIcon = theme.getCustomButtonIconClass(customButtonProps)) ||
  6259. (buttonIcon = theme.getIconClass(buttonName, isRtl)) ||
  6260. (buttonText = customButtonProps.text);
  6261. }
  6262. else if ((viewSpec = viewSpecs[buttonName])) {
  6263. viewsWithButtons.push(buttonName);
  6264. buttonClick = function () {
  6265. calendarApi.changeView(buttonName);
  6266. };
  6267. (buttonText = viewSpec.buttonTextOverride) ||
  6268. (buttonIcon = theme.getIconClass(buttonName, isRtl)) ||
  6269. (buttonText = viewSpec.buttonTextDefault);
  6270. }
  6271. else if (calendarApi[buttonName]) { // a calendarApi method
  6272. buttonClick = function () {
  6273. calendarApi[buttonName]();
  6274. };
  6275. (buttonText = calendarButtonTextOverrides[buttonName]) ||
  6276. (buttonIcon = theme.getIconClass(buttonName, isRtl)) ||
  6277. (buttonText = calendarButtonText[buttonName]);
  6278. // ^ everything else is considered default
  6279. }
  6280. return { buttonName: buttonName, buttonClick: buttonClick, buttonIcon: buttonIcon, buttonText: buttonText };
  6281. })); });
  6282. }
  6283. var eventSourceDef$3 = {
  6284. ignoreRange: true,
  6285. parseMeta: function (refined) {
  6286. if (Array.isArray(refined.events)) {
  6287. return refined.events;
  6288. }
  6289. return null;
  6290. },
  6291. fetch: function (arg, success) {
  6292. success({
  6293. rawEvents: arg.eventSource.meta,
  6294. });
  6295. },
  6296. };
  6297. var arrayEventSourcePlugin = createPlugin({
  6298. eventSourceDefs: [eventSourceDef$3],
  6299. });
  6300. var eventSourceDef$2 = {
  6301. parseMeta: function (refined) {
  6302. if (typeof refined.events === 'function') {
  6303. return refined.events;
  6304. }
  6305. return null;
  6306. },
  6307. fetch: function (arg, success, failure) {
  6308. var dateEnv = arg.context.dateEnv;
  6309. var func = arg.eventSource.meta;
  6310. unpromisify(func.bind(null, buildRangeApiWithTimeZone(arg.range, dateEnv)), function (rawEvents) {
  6311. success({ rawEvents: rawEvents }); // needs an object response
  6312. }, failure);
  6313. },
  6314. };
  6315. var funcEventSourcePlugin = createPlugin({
  6316. eventSourceDefs: [eventSourceDef$2],
  6317. });
  6318. function requestJson(method, url, params, successCallback, failureCallback) {
  6319. method = method.toUpperCase();
  6320. var body = null;
  6321. if (method === 'GET') {
  6322. url = injectQueryStringParams(url, params);
  6323. }
  6324. else {
  6325. body = encodeParams(params);
  6326. }
  6327. var xhr = new XMLHttpRequest();
  6328. xhr.open(method, url, true);
  6329. if (method !== 'GET') {
  6330. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  6331. }
  6332. xhr.onload = function () {
  6333. if (xhr.status >= 200 && xhr.status < 400) {
  6334. var parsed = false;
  6335. var res = void 0;
  6336. try {
  6337. res = JSON.parse(xhr.responseText);
  6338. parsed = true;
  6339. }
  6340. catch (err) {
  6341. // will handle parsed=false
  6342. }
  6343. if (parsed) {
  6344. successCallback(res, xhr);
  6345. }
  6346. else {
  6347. failureCallback('Failure parsing JSON', xhr);
  6348. }
  6349. }
  6350. else {
  6351. failureCallback('Request failed', xhr);
  6352. }
  6353. };
  6354. xhr.onerror = function () {
  6355. failureCallback('Request failed', xhr);
  6356. };
  6357. xhr.send(body);
  6358. }
  6359. function injectQueryStringParams(url, params) {
  6360. return url +
  6361. (url.indexOf('?') === -1 ? '?' : '&') +
  6362. encodeParams(params);
  6363. }
  6364. function encodeParams(params) {
  6365. var parts = [];
  6366. for (var key in params) {
  6367. parts.push(encodeURIComponent(key) + "=" + encodeURIComponent(params[key]));
  6368. }
  6369. return parts.join('&');
  6370. }
  6371. var JSON_FEED_EVENT_SOURCE_REFINERS = {
  6372. method: String,
  6373. extraParams: identity,
  6374. startParam: String,
  6375. endParam: String,
  6376. timeZoneParam: String,
  6377. };
  6378. var eventSourceDef$1 = {
  6379. parseMeta: function (refined) {
  6380. if (refined.url && (refined.format === 'json' || !refined.format)) {
  6381. return {
  6382. url: refined.url,
  6383. format: 'json',
  6384. method: (refined.method || 'GET').toUpperCase(),
  6385. extraParams: refined.extraParams,
  6386. startParam: refined.startParam,
  6387. endParam: refined.endParam,
  6388. timeZoneParam: refined.timeZoneParam,
  6389. };
  6390. }
  6391. return null;
  6392. },
  6393. fetch: function (arg, success, failure) {
  6394. var meta = arg.eventSource.meta;
  6395. var requestParams = buildRequestParams$1(meta, arg.range, arg.context);
  6396. requestJson(meta.method, meta.url, requestParams, function (rawEvents, xhr) {
  6397. success({ rawEvents: rawEvents, xhr: xhr });
  6398. }, function (errorMessage, xhr) {
  6399. failure({ message: errorMessage, xhr: xhr });
  6400. });
  6401. },
  6402. };
  6403. var jsonFeedEventSourcePlugin = createPlugin({
  6404. eventSourceRefiners: JSON_FEED_EVENT_SOURCE_REFINERS,
  6405. eventSourceDefs: [eventSourceDef$1],
  6406. });
  6407. function buildRequestParams$1(meta, range, context) {
  6408. var dateEnv = context.dateEnv, options = context.options;
  6409. var startParam;
  6410. var endParam;
  6411. var timeZoneParam;
  6412. var customRequestParams;
  6413. var params = {};
  6414. startParam = meta.startParam;
  6415. if (startParam == null) {
  6416. startParam = options.startParam;
  6417. }
  6418. endParam = meta.endParam;
  6419. if (endParam == null) {
  6420. endParam = options.endParam;
  6421. }
  6422. timeZoneParam = meta.timeZoneParam;
  6423. if (timeZoneParam == null) {
  6424. timeZoneParam = options.timeZoneParam;
  6425. }
  6426. // retrieve any outbound GET/POST data from the options
  6427. if (typeof meta.extraParams === 'function') {
  6428. // supplied as a function that returns a key/value object
  6429. customRequestParams = meta.extraParams();
  6430. }
  6431. else {
  6432. // probably supplied as a straight key/value object
  6433. customRequestParams = meta.extraParams || {};
  6434. }
  6435. __assign(params, customRequestParams);
  6436. params[startParam] = dateEnv.formatIso(range.start);
  6437. params[endParam] = dateEnv.formatIso(range.end);
  6438. if (dateEnv.timeZone !== 'local') {
  6439. params[timeZoneParam] = dateEnv.timeZone;
  6440. }
  6441. return params;
  6442. }
  6443. var SIMPLE_RECURRING_REFINERS = {
  6444. daysOfWeek: identity,
  6445. startTime: createDuration,
  6446. endTime: createDuration,
  6447. duration: createDuration,
  6448. startRecur: identity,
  6449. endRecur: identity,
  6450. };
  6451. var recurring = {
  6452. parse: function (refined, dateEnv) {
  6453. if (refined.daysOfWeek || refined.startTime || refined.endTime || refined.startRecur || refined.endRecur) {
  6454. var recurringData = {
  6455. daysOfWeek: refined.daysOfWeek || null,
  6456. startTime: refined.startTime || null,
  6457. endTime: refined.endTime || null,
  6458. startRecur: refined.startRecur ? dateEnv.createMarker(refined.startRecur) : null,
  6459. endRecur: refined.endRecur ? dateEnv.createMarker(refined.endRecur) : null,
  6460. };
  6461. var duration = void 0;
  6462. if (refined.duration) {
  6463. duration = refined.duration;
  6464. }
  6465. if (!duration && refined.startTime && refined.endTime) {
  6466. duration = subtractDurations(refined.endTime, refined.startTime);
  6467. }
  6468. return {
  6469. allDayGuess: Boolean(!refined.startTime && !refined.endTime),
  6470. duration: duration,
  6471. typeData: recurringData, // doesn't need endTime anymore but oh well
  6472. };
  6473. }
  6474. return null;
  6475. },
  6476. expand: function (typeData, framingRange, dateEnv) {
  6477. var clippedFramingRange = intersectRanges(framingRange, { start: typeData.startRecur, end: typeData.endRecur });
  6478. if (clippedFramingRange) {
  6479. return expandRanges(typeData.daysOfWeek, typeData.startTime, clippedFramingRange, dateEnv);
  6480. }
  6481. return [];
  6482. },
  6483. };
  6484. var simpleRecurringEventsPlugin = createPlugin({
  6485. recurringTypes: [recurring],
  6486. eventRefiners: SIMPLE_RECURRING_REFINERS,
  6487. });
  6488. function expandRanges(daysOfWeek, startTime, framingRange, dateEnv) {
  6489. var dowHash = daysOfWeek ? arrayToHash(daysOfWeek) : null;
  6490. var dayMarker = startOfDay(framingRange.start);
  6491. var endMarker = framingRange.end;
  6492. var instanceStarts = [];
  6493. while (dayMarker < endMarker) {
  6494. var instanceStart
  6495. // if everyday, or this particular day-of-week
  6496. = void 0;
  6497. // if everyday, or this particular day-of-week
  6498. if (!dowHash || dowHash[dayMarker.getUTCDay()]) {
  6499. if (startTime) {
  6500. instanceStart = dateEnv.add(dayMarker, startTime);
  6501. }
  6502. else {
  6503. instanceStart = dayMarker;
  6504. }
  6505. instanceStarts.push(instanceStart);
  6506. }
  6507. dayMarker = addDays(dayMarker, 1);
  6508. }
  6509. return instanceStarts;
  6510. }
  6511. var changeHandlerPlugin = createPlugin({
  6512. optionChangeHandlers: {
  6513. events: function (events, context) {
  6514. handleEventSources([events], context);
  6515. },
  6516. eventSources: handleEventSources,
  6517. },
  6518. });
  6519. /*
  6520. BUG: if `event` was supplied, all previously-given `eventSources` will be wiped out
  6521. */
  6522. function handleEventSources(inputs, context) {
  6523. var unfoundSources = hashValuesToArray(context.getCurrentData().eventSources);
  6524. var newInputs = [];
  6525. for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {
  6526. var input = inputs_1[_i];
  6527. var inputFound = false;
  6528. for (var i = 0; i < unfoundSources.length; i += 1) {
  6529. if (unfoundSources[i]._raw === input) {
  6530. unfoundSources.splice(i, 1); // delete
  6531. inputFound = true;
  6532. break;
  6533. }
  6534. }
  6535. if (!inputFound) {
  6536. newInputs.push(input);
  6537. }
  6538. }
  6539. for (var _a = 0, unfoundSources_1 = unfoundSources; _a < unfoundSources_1.length; _a++) {
  6540. var unfoundSource = unfoundSources_1[_a];
  6541. context.dispatch({
  6542. type: 'REMOVE_EVENT_SOURCE',
  6543. sourceId: unfoundSource.sourceId,
  6544. });
  6545. }
  6546. for (var _b = 0, newInputs_1 = newInputs; _b < newInputs_1.length; _b++) {
  6547. var newInput = newInputs_1[_b];
  6548. context.calendarApi.addEventSource(newInput);
  6549. }
  6550. }
  6551. function handleDateProfile(dateProfile, context) {
  6552. context.emitter.trigger('datesSet', __assign(__assign({}, buildRangeApiWithTimeZone(dateProfile.activeRange, context.dateEnv)), { view: context.viewApi }));
  6553. }
  6554. function handleEventStore(eventStore, context) {
  6555. var emitter = context.emitter;
  6556. if (emitter.hasHandlers('eventsSet')) {
  6557. emitter.trigger('eventsSet', buildEventApis(eventStore, context));
  6558. }
  6559. }
  6560. /*
  6561. this array is exposed on the root namespace so that UMD plugins can add to it.
  6562. see the rollup-bundles script.
  6563. */
  6564. var globalPlugins = [
  6565. arrayEventSourcePlugin,
  6566. funcEventSourcePlugin,
  6567. jsonFeedEventSourcePlugin,
  6568. simpleRecurringEventsPlugin,
  6569. changeHandlerPlugin,
  6570. createPlugin({
  6571. isLoadingFuncs: [
  6572. function (state) { return computeEventSourcesLoading(state.eventSources); },
  6573. ],
  6574. contentTypeHandlers: {
  6575. html: function () { return ({ render: injectHtml }); },
  6576. domNodes: function () { return ({ render: injectDomNodes }); },
  6577. },
  6578. propSetHandlers: {
  6579. dateProfile: handleDateProfile,
  6580. eventStore: handleEventStore,
  6581. },
  6582. }),
  6583. ];
  6584. function injectHtml(el, html) {
  6585. el.innerHTML = html;
  6586. }
  6587. function injectDomNodes(el, domNodes) {
  6588. var oldNodes = Array.prototype.slice.call(el.childNodes); // TODO: use array util
  6589. var newNodes = Array.prototype.slice.call(domNodes); // TODO: use array util
  6590. if (!isArraysEqual(oldNodes, newNodes)) {
  6591. for (var _i = 0, newNodes_1 = newNodes; _i < newNodes_1.length; _i++) {
  6592. var newNode = newNodes_1[_i];
  6593. el.appendChild(newNode);
  6594. }
  6595. oldNodes.forEach(removeElement);
  6596. }
  6597. }
  6598. var DelayedRunner = /** @class */ (function () {
  6599. function DelayedRunner(drainedOption) {
  6600. this.drainedOption = drainedOption;
  6601. this.isRunning = false;
  6602. this.isDirty = false;
  6603. this.pauseDepths = {};
  6604. this.timeoutId = 0;
  6605. }
  6606. DelayedRunner.prototype.request = function (delay) {
  6607. this.isDirty = true;
  6608. if (!this.isPaused()) {
  6609. this.clearTimeout();
  6610. if (delay == null) {
  6611. this.tryDrain();
  6612. }
  6613. else {
  6614. this.timeoutId = setTimeout(// NOT OPTIMAL! TODO: look at debounce
  6615. this.tryDrain.bind(this), delay);
  6616. }
  6617. }
  6618. };
  6619. DelayedRunner.prototype.pause = function (scope) {
  6620. if (scope === void 0) { scope = ''; }
  6621. var pauseDepths = this.pauseDepths;
  6622. pauseDepths[scope] = (pauseDepths[scope] || 0) + 1;
  6623. this.clearTimeout();
  6624. };
  6625. DelayedRunner.prototype.resume = function (scope, force) {
  6626. if (scope === void 0) { scope = ''; }
  6627. var pauseDepths = this.pauseDepths;
  6628. if (scope in pauseDepths) {
  6629. if (force) {
  6630. delete pauseDepths[scope];
  6631. }
  6632. else {
  6633. pauseDepths[scope] -= 1;
  6634. var depth = pauseDepths[scope];
  6635. if (depth <= 0) {
  6636. delete pauseDepths[scope];
  6637. }
  6638. }
  6639. this.tryDrain();
  6640. }
  6641. };
  6642. DelayedRunner.prototype.isPaused = function () {
  6643. return Object.keys(this.pauseDepths).length;
  6644. };
  6645. DelayedRunner.prototype.tryDrain = function () {
  6646. if (!this.isRunning && !this.isPaused()) {
  6647. this.isRunning = true;
  6648. while (this.isDirty) {
  6649. this.isDirty = false;
  6650. this.drained(); // might set isDirty to true again
  6651. }
  6652. this.isRunning = false;
  6653. }
  6654. };
  6655. DelayedRunner.prototype.clear = function () {
  6656. this.clearTimeout();
  6657. this.isDirty = false;
  6658. this.pauseDepths = {};
  6659. };
  6660. DelayedRunner.prototype.clearTimeout = function () {
  6661. if (this.timeoutId) {
  6662. clearTimeout(this.timeoutId);
  6663. this.timeoutId = 0;
  6664. }
  6665. };
  6666. DelayedRunner.prototype.drained = function () {
  6667. if (this.drainedOption) {
  6668. this.drainedOption();
  6669. }
  6670. };
  6671. return DelayedRunner;
  6672. }());
  6673. var TaskRunner = /** @class */ (function () {
  6674. function TaskRunner(runTaskOption, drainedOption) {
  6675. this.runTaskOption = runTaskOption;
  6676. this.drainedOption = drainedOption;
  6677. this.queue = [];
  6678. this.delayedRunner = new DelayedRunner(this.drain.bind(this));
  6679. }
  6680. TaskRunner.prototype.request = function (task, delay) {
  6681. this.queue.push(task);
  6682. this.delayedRunner.request(delay);
  6683. };
  6684. TaskRunner.prototype.pause = function (scope) {
  6685. this.delayedRunner.pause(scope);
  6686. };
  6687. TaskRunner.prototype.resume = function (scope, force) {
  6688. this.delayedRunner.resume(scope, force);
  6689. };
  6690. TaskRunner.prototype.drain = function () {
  6691. var queue = this.queue;
  6692. while (queue.length) {
  6693. var completedTasks = [];
  6694. var task = void 0;
  6695. while ((task = queue.shift())) {
  6696. this.runTask(task);
  6697. completedTasks.push(task);
  6698. }
  6699. this.drained(completedTasks);
  6700. } // keep going, in case new tasks were added in the drained handler
  6701. };
  6702. TaskRunner.prototype.runTask = function (task) {
  6703. if (this.runTaskOption) {
  6704. this.runTaskOption(task);
  6705. }
  6706. };
  6707. TaskRunner.prototype.drained = function (completedTasks) {
  6708. if (this.drainedOption) {
  6709. this.drainedOption(completedTasks);
  6710. }
  6711. };
  6712. return TaskRunner;
  6713. }());
  6714. // Computes what the title at the top of the calendarApi should be for this view
  6715. function buildTitle(dateProfile, viewOptions, dateEnv) {
  6716. var range;
  6717. // for views that span a large unit of time, show the proper interval, ignoring stray days before and after
  6718. if (/^(year|month)$/.test(dateProfile.currentRangeUnit)) {
  6719. range = dateProfile.currentRange;
  6720. }
  6721. else { // for day units or smaller, use the actual day range
  6722. range = dateProfile.activeRange;
  6723. }
  6724. return dateEnv.formatRange(range.start, range.end, createFormatter(viewOptions.titleFormat || buildTitleFormat(dateProfile)), {
  6725. isEndExclusive: dateProfile.isRangeAllDay,
  6726. defaultSeparator: viewOptions.titleRangeSeparator,
  6727. });
  6728. }
  6729. // Generates the format string that should be used to generate the title for the current date range.
  6730. // Attempts to compute the most appropriate format if not explicitly specified with `titleFormat`.
  6731. function buildTitleFormat(dateProfile) {
  6732. var currentRangeUnit = dateProfile.currentRangeUnit;
  6733. if (currentRangeUnit === 'year') {
  6734. return { year: 'numeric' };
  6735. }
  6736. if (currentRangeUnit === 'month') {
  6737. return { year: 'numeric', month: 'long' }; // like "September 2014"
  6738. }
  6739. var days = diffWholeDays(dateProfile.currentRange.start, dateProfile.currentRange.end);
  6740. if (days !== null && days > 1) {
  6741. // multi-day range. shorter, like "Sep 9 - 10 2014"
  6742. return { year: 'numeric', month: 'short', day: 'numeric' };
  6743. }
  6744. // one day. longer, like "September 9 2014"
  6745. return { year: 'numeric', month: 'long', day: 'numeric' };
  6746. }
  6747. // in future refactor, do the redux-style function(state=initial) for initial-state
  6748. // also, whatever is happening in constructor, have it happen in action queue too
  6749. var CalendarDataManager = /** @class */ (function () {
  6750. function CalendarDataManager(props) {
  6751. var _this = this;
  6752. this.computeOptionsData = memoize(this._computeOptionsData);
  6753. this.computeCurrentViewData = memoize(this._computeCurrentViewData);
  6754. this.organizeRawLocales = memoize(organizeRawLocales);
  6755. this.buildLocale = memoize(buildLocale);
  6756. this.buildPluginHooks = buildBuildPluginHooks();
  6757. this.buildDateEnv = memoize(buildDateEnv);
  6758. this.buildTheme = memoize(buildTheme);
  6759. this.parseToolbars = memoize(parseToolbars);
  6760. this.buildViewSpecs = memoize(buildViewSpecs);
  6761. this.buildDateProfileGenerator = memoizeObjArg(buildDateProfileGenerator);
  6762. this.buildViewApi = memoize(buildViewApi);
  6763. this.buildViewUiProps = memoizeObjArg(buildViewUiProps);
  6764. this.buildEventUiBySource = memoize(buildEventUiBySource, isPropsEqual);
  6765. this.buildEventUiBases = memoize(buildEventUiBases);
  6766. this.parseContextBusinessHours = memoizeObjArg(parseContextBusinessHours);
  6767. this.buildTitle = memoize(buildTitle);
  6768. this.emitter = new Emitter();
  6769. this.actionRunner = new TaskRunner(this._handleAction.bind(this), this.updateData.bind(this));
  6770. this.currentCalendarOptionsInput = {};
  6771. this.currentCalendarOptionsRefined = {};
  6772. this.currentViewOptionsInput = {};
  6773. this.currentViewOptionsRefined = {};
  6774. this.currentCalendarOptionsRefiners = {};
  6775. this.getCurrentData = function () { return _this.data; };
  6776. this.dispatch = function (action) {
  6777. _this.actionRunner.request(action); // protects against recursive calls to _handleAction
  6778. };
  6779. this.props = props;
  6780. this.actionRunner.pause();
  6781. var dynamicOptionOverrides = {};
  6782. var optionsData = this.computeOptionsData(props.optionOverrides, dynamicOptionOverrides, props.calendarApi);
  6783. var currentViewType = optionsData.calendarOptions.initialView || optionsData.pluginHooks.initialView;
  6784. var currentViewData = this.computeCurrentViewData(currentViewType, optionsData, props.optionOverrides, dynamicOptionOverrides);
  6785. // wire things up
  6786. // TODO: not DRY
  6787. props.calendarApi.currentDataManager = this;
  6788. this.emitter.setThisContext(props.calendarApi);
  6789. this.emitter.setOptions(currentViewData.options);
  6790. var currentDate = getInitialDate(optionsData.calendarOptions, optionsData.dateEnv);
  6791. var dateProfile = currentViewData.dateProfileGenerator.build(currentDate);
  6792. if (!rangeContainsMarker(dateProfile.activeRange, currentDate)) {
  6793. currentDate = dateProfile.currentRange.start;
  6794. }
  6795. var calendarContext = {
  6796. dateEnv: optionsData.dateEnv,
  6797. options: optionsData.calendarOptions,
  6798. pluginHooks: optionsData.pluginHooks,
  6799. calendarApi: props.calendarApi,
  6800. dispatch: this.dispatch,
  6801. emitter: this.emitter,
  6802. getCurrentData: this.getCurrentData,
  6803. };
  6804. // needs to be after setThisContext
  6805. for (var _i = 0, _a = optionsData.pluginHooks.contextInit; _i < _a.length; _i++) {
  6806. var callback = _a[_i];
  6807. callback(calendarContext);
  6808. }
  6809. // NOT DRY
  6810. var eventSources = initEventSources(optionsData.calendarOptions, dateProfile, calendarContext);
  6811. var initialState = {
  6812. dynamicOptionOverrides: dynamicOptionOverrides,
  6813. currentViewType: currentViewType,
  6814. currentDate: currentDate,
  6815. dateProfile: dateProfile,
  6816. businessHours: this.parseContextBusinessHours(calendarContext),
  6817. eventSources: eventSources,
  6818. eventUiBases: {},
  6819. eventStore: createEmptyEventStore(),
  6820. renderableEventStore: createEmptyEventStore(),
  6821. dateSelection: null,
  6822. eventSelection: '',
  6823. eventDrag: null,
  6824. eventResize: null,
  6825. selectionConfig: this.buildViewUiProps(calendarContext).selectionConfig,
  6826. };
  6827. var contextAndState = __assign(__assign({}, calendarContext), initialState);
  6828. for (var _b = 0, _c = optionsData.pluginHooks.reducers; _b < _c.length; _b++) {
  6829. var reducer = _c[_b];
  6830. __assign(initialState, reducer(null, null, contextAndState));
  6831. }
  6832. if (computeIsLoading(initialState, calendarContext)) {
  6833. this.emitter.trigger('loading', true); // NOT DRY
  6834. }
  6835. this.state = initialState;
  6836. this.updateData();
  6837. this.actionRunner.resume();
  6838. }
  6839. CalendarDataManager.prototype.resetOptions = function (optionOverrides, append) {
  6840. var props = this.props;
  6841. props.optionOverrides = append
  6842. ? __assign(__assign({}, props.optionOverrides), optionOverrides) : optionOverrides;
  6843. this.actionRunner.request({
  6844. type: 'NOTHING',
  6845. });
  6846. };
  6847. CalendarDataManager.prototype._handleAction = function (action) {
  6848. var _a = this, props = _a.props, state = _a.state, emitter = _a.emitter;
  6849. var dynamicOptionOverrides = reduceDynamicOptionOverrides(state.dynamicOptionOverrides, action);
  6850. var optionsData = this.computeOptionsData(props.optionOverrides, dynamicOptionOverrides, props.calendarApi);
  6851. var currentViewType = reduceViewType(state.currentViewType, action);
  6852. var currentViewData = this.computeCurrentViewData(currentViewType, optionsData, props.optionOverrides, dynamicOptionOverrides);
  6853. // wire things up
  6854. // TODO: not DRY
  6855. props.calendarApi.currentDataManager = this;
  6856. emitter.setThisContext(props.calendarApi);
  6857. emitter.setOptions(currentViewData.options);
  6858. var calendarContext = {
  6859. dateEnv: optionsData.dateEnv,
  6860. options: optionsData.calendarOptions,
  6861. pluginHooks: optionsData.pluginHooks,
  6862. calendarApi: props.calendarApi,
  6863. dispatch: this.dispatch,
  6864. emitter: emitter,
  6865. getCurrentData: this.getCurrentData,
  6866. };
  6867. var currentDate = state.currentDate, dateProfile = state.dateProfile;
  6868. if (this.data && this.data.dateProfileGenerator !== currentViewData.dateProfileGenerator) { // hack
  6869. dateProfile = currentViewData.dateProfileGenerator.build(currentDate);
  6870. }
  6871. currentDate = reduceCurrentDate(currentDate, action);
  6872. dateProfile = reduceDateProfile(dateProfile, action, currentDate, currentViewData.dateProfileGenerator);
  6873. if (action.type === 'PREV' || // TODO: move this logic into DateProfileGenerator
  6874. action.type === 'NEXT' || // "
  6875. !rangeContainsMarker(dateProfile.currentRange, currentDate)) {
  6876. currentDate = dateProfile.currentRange.start;
  6877. }
  6878. var eventSources = reduceEventSources(state.eventSources, action, dateProfile, calendarContext);
  6879. var eventStore = reduceEventStore(state.eventStore, action, eventSources, dateProfile, calendarContext);
  6880. var isEventsLoading = computeEventSourcesLoading(eventSources); // BAD. also called in this func in computeIsLoading
  6881. var renderableEventStore = (isEventsLoading && !currentViewData.options.progressiveEventRendering) ?
  6882. (state.renderableEventStore || eventStore) : // try from previous state
  6883. eventStore;
  6884. var _b = this.buildViewUiProps(calendarContext), eventUiSingleBase = _b.eventUiSingleBase, selectionConfig = _b.selectionConfig; // will memoize obj
  6885. var eventUiBySource = this.buildEventUiBySource(eventSources);
  6886. var eventUiBases = this.buildEventUiBases(renderableEventStore.defs, eventUiSingleBase, eventUiBySource);
  6887. var newState = {
  6888. dynamicOptionOverrides: dynamicOptionOverrides,
  6889. currentViewType: currentViewType,
  6890. currentDate: currentDate,
  6891. dateProfile: dateProfile,
  6892. eventSources: eventSources,
  6893. eventStore: eventStore,
  6894. renderableEventStore: renderableEventStore,
  6895. selectionConfig: selectionConfig,
  6896. eventUiBases: eventUiBases,
  6897. businessHours: this.parseContextBusinessHours(calendarContext),
  6898. dateSelection: reduceDateSelection(state.dateSelection, action),
  6899. eventSelection: reduceSelectedEvent(state.eventSelection, action),
  6900. eventDrag: reduceEventDrag(state.eventDrag, action),
  6901. eventResize: reduceEventResize(state.eventResize, action),
  6902. };
  6903. var contextAndState = __assign(__assign({}, calendarContext), newState);
  6904. for (var _i = 0, _c = optionsData.pluginHooks.reducers; _i < _c.length; _i++) {
  6905. var reducer = _c[_i];
  6906. __assign(newState, reducer(state, action, contextAndState)); // give the OLD state, for old value
  6907. }
  6908. var wasLoading = computeIsLoading(state, calendarContext);
  6909. var isLoading = computeIsLoading(newState, calendarContext);
  6910. // TODO: use propSetHandlers in plugin system
  6911. if (!wasLoading && isLoading) {
  6912. emitter.trigger('loading', true);
  6913. }
  6914. else if (wasLoading && !isLoading) {
  6915. emitter.trigger('loading', false);
  6916. }
  6917. this.state = newState;
  6918. if (props.onAction) {
  6919. props.onAction(action);
  6920. }
  6921. };
  6922. CalendarDataManager.prototype.updateData = function () {
  6923. var _a = this, props = _a.props, state = _a.state;
  6924. var oldData = this.data;
  6925. var optionsData = this.computeOptionsData(props.optionOverrides, state.dynamicOptionOverrides, props.calendarApi);
  6926. var currentViewData = this.computeCurrentViewData(state.currentViewType, optionsData, props.optionOverrides, state.dynamicOptionOverrides);
  6927. var data = this.data = __assign(__assign(__assign({ viewTitle: this.buildTitle(state.dateProfile, currentViewData.options, optionsData.dateEnv), calendarApi: props.calendarApi, dispatch: this.dispatch, emitter: this.emitter, getCurrentData: this.getCurrentData }, optionsData), currentViewData), state);
  6928. var changeHandlers = optionsData.pluginHooks.optionChangeHandlers;
  6929. var oldCalendarOptions = oldData && oldData.calendarOptions;
  6930. var newCalendarOptions = optionsData.calendarOptions;
  6931. if (oldCalendarOptions && oldCalendarOptions !== newCalendarOptions) {
  6932. if (oldCalendarOptions.timeZone !== newCalendarOptions.timeZone) {
  6933. // hack
  6934. state.eventSources = data.eventSources = reduceEventSourcesNewTimeZone(data.eventSources, state.dateProfile, data);
  6935. state.eventStore = data.eventStore = rezoneEventStoreDates(data.eventStore, oldData.dateEnv, data.dateEnv);
  6936. }
  6937. for (var optionName in changeHandlers) {
  6938. if (oldCalendarOptions[optionName] !== newCalendarOptions[optionName]) {
  6939. changeHandlers[optionName](newCalendarOptions[optionName], data);
  6940. }
  6941. }
  6942. }
  6943. if (props.onData) {
  6944. props.onData(data);
  6945. }
  6946. };
  6947. CalendarDataManager.prototype._computeOptionsData = function (optionOverrides, dynamicOptionOverrides, calendarApi) {
  6948. // TODO: blacklist options that are handled by optionChangeHandlers
  6949. var _a = this.processRawCalendarOptions(optionOverrides, dynamicOptionOverrides), refinedOptions = _a.refinedOptions, pluginHooks = _a.pluginHooks, localeDefaults = _a.localeDefaults, availableLocaleData = _a.availableLocaleData, extra = _a.extra;
  6950. warnUnknownOptions(extra);
  6951. var dateEnv = this.buildDateEnv(refinedOptions.timeZone, refinedOptions.locale, refinedOptions.weekNumberCalculation, refinedOptions.firstDay, refinedOptions.weekText, pluginHooks, availableLocaleData, refinedOptions.defaultRangeSeparator);
  6952. var viewSpecs = this.buildViewSpecs(pluginHooks.views, optionOverrides, dynamicOptionOverrides, localeDefaults);
  6953. var theme = this.buildTheme(refinedOptions, pluginHooks);
  6954. var toolbarConfig = this.parseToolbars(refinedOptions, optionOverrides, theme, viewSpecs, calendarApi);
  6955. return {
  6956. calendarOptions: refinedOptions,
  6957. pluginHooks: pluginHooks,
  6958. dateEnv: dateEnv,
  6959. viewSpecs: viewSpecs,
  6960. theme: theme,
  6961. toolbarConfig: toolbarConfig,
  6962. localeDefaults: localeDefaults,
  6963. availableRawLocales: availableLocaleData.map,
  6964. };
  6965. };
  6966. // always called from behind a memoizer
  6967. CalendarDataManager.prototype.processRawCalendarOptions = function (optionOverrides, dynamicOptionOverrides) {
  6968. var _a = mergeRawOptions([
  6969. BASE_OPTION_DEFAULTS,
  6970. optionOverrides,
  6971. dynamicOptionOverrides,
  6972. ]), locales = _a.locales, locale = _a.locale;
  6973. var availableLocaleData = this.organizeRawLocales(locales);
  6974. var availableRawLocales = availableLocaleData.map;
  6975. var localeDefaults = this.buildLocale(locale || availableLocaleData.defaultCode, availableRawLocales).options;
  6976. var pluginHooks = this.buildPluginHooks(optionOverrides.plugins || [], globalPlugins);
  6977. var refiners = this.currentCalendarOptionsRefiners = __assign(__assign(__assign(__assign(__assign({}, BASE_OPTION_REFINERS), CALENDAR_LISTENER_REFINERS), CALENDAR_OPTION_REFINERS), pluginHooks.listenerRefiners), pluginHooks.optionRefiners);
  6978. var extra = {};
  6979. var raw = mergeRawOptions([
  6980. BASE_OPTION_DEFAULTS,
  6981. localeDefaults,
  6982. optionOverrides,
  6983. dynamicOptionOverrides,
  6984. ]);
  6985. var refined = {};
  6986. var currentRaw = this.currentCalendarOptionsInput;
  6987. var currentRefined = this.currentCalendarOptionsRefined;
  6988. var anyChanges = false;
  6989. for (var optionName in raw) {
  6990. if (optionName !== 'plugins') { // because plugins is special-cased
  6991. if (raw[optionName] === currentRaw[optionName] ||
  6992. (COMPLEX_OPTION_COMPARATORS[optionName] &&
  6993. (optionName in currentRaw) &&
  6994. COMPLEX_OPTION_COMPARATORS[optionName](currentRaw[optionName], raw[optionName]))) {
  6995. refined[optionName] = currentRefined[optionName];
  6996. }
  6997. else if (refiners[optionName]) {
  6998. refined[optionName] = refiners[optionName](raw[optionName]);
  6999. anyChanges = true;
  7000. }
  7001. else {
  7002. extra[optionName] = currentRaw[optionName];
  7003. }
  7004. }
  7005. }
  7006. if (anyChanges) {
  7007. this.currentCalendarOptionsInput = raw;
  7008. this.currentCalendarOptionsRefined = refined;
  7009. }
  7010. return {
  7011. rawOptions: this.currentCalendarOptionsInput,
  7012. refinedOptions: this.currentCalendarOptionsRefined,
  7013. pluginHooks: pluginHooks,
  7014. availableLocaleData: availableLocaleData,
  7015. localeDefaults: localeDefaults,
  7016. extra: extra,
  7017. };
  7018. };
  7019. CalendarDataManager.prototype._computeCurrentViewData = function (viewType, optionsData, optionOverrides, dynamicOptionOverrides) {
  7020. var viewSpec = optionsData.viewSpecs[viewType];
  7021. if (!viewSpec) {
  7022. throw new Error("viewType \"" + viewType + "\" is not available. Please make sure you've loaded all neccessary plugins");
  7023. }
  7024. var _a = this.processRawViewOptions(viewSpec, optionsData.pluginHooks, optionsData.localeDefaults, optionOverrides, dynamicOptionOverrides), refinedOptions = _a.refinedOptions, extra = _a.extra;
  7025. warnUnknownOptions(extra);
  7026. var dateProfileGenerator = this.buildDateProfileGenerator({
  7027. dateProfileGeneratorClass: viewSpec.optionDefaults.dateProfileGeneratorClass,
  7028. duration: viewSpec.duration,
  7029. durationUnit: viewSpec.durationUnit,
  7030. usesMinMaxTime: viewSpec.optionDefaults.usesMinMaxTime,
  7031. dateEnv: optionsData.dateEnv,
  7032. calendarApi: this.props.calendarApi,
  7033. slotMinTime: refinedOptions.slotMinTime,
  7034. slotMaxTime: refinedOptions.slotMaxTime,
  7035. showNonCurrentDates: refinedOptions.showNonCurrentDates,
  7036. dayCount: refinedOptions.dayCount,
  7037. dateAlignment: refinedOptions.dateAlignment,
  7038. dateIncrement: refinedOptions.dateIncrement,
  7039. hiddenDays: refinedOptions.hiddenDays,
  7040. weekends: refinedOptions.weekends,
  7041. nowInput: refinedOptions.now,
  7042. validRangeInput: refinedOptions.validRange,
  7043. visibleRangeInput: refinedOptions.visibleRange,
  7044. monthMode: refinedOptions.monthMode,
  7045. fixedWeekCount: refinedOptions.fixedWeekCount,
  7046. });
  7047. var viewApi = this.buildViewApi(viewType, this.getCurrentData, optionsData.dateEnv);
  7048. return { viewSpec: viewSpec, options: refinedOptions, dateProfileGenerator: dateProfileGenerator, viewApi: viewApi };
  7049. };
  7050. CalendarDataManager.prototype.processRawViewOptions = function (viewSpec, pluginHooks, localeDefaults, optionOverrides, dynamicOptionOverrides) {
  7051. var raw = mergeRawOptions([
  7052. BASE_OPTION_DEFAULTS,
  7053. viewSpec.optionDefaults,
  7054. localeDefaults,
  7055. optionOverrides,
  7056. viewSpec.optionOverrides,
  7057. dynamicOptionOverrides,
  7058. ]);
  7059. var refiners = __assign(__assign(__assign(__assign(__assign(__assign({}, BASE_OPTION_REFINERS), CALENDAR_LISTENER_REFINERS), CALENDAR_OPTION_REFINERS), VIEW_OPTION_REFINERS), pluginHooks.listenerRefiners), pluginHooks.optionRefiners);
  7060. var refined = {};
  7061. var currentRaw = this.currentViewOptionsInput;
  7062. var currentRefined = this.currentViewOptionsRefined;
  7063. var anyChanges = false;
  7064. var extra = {};
  7065. for (var optionName in raw) {
  7066. if (raw[optionName] === currentRaw[optionName]) {
  7067. refined[optionName] = currentRefined[optionName];
  7068. }
  7069. else {
  7070. if (raw[optionName] === this.currentCalendarOptionsInput[optionName]) {
  7071. if (optionName in this.currentCalendarOptionsRefined) { // might be an "extra" prop
  7072. refined[optionName] = this.currentCalendarOptionsRefined[optionName];
  7073. }
  7074. }
  7075. else if (refiners[optionName]) {
  7076. refined[optionName] = refiners[optionName](raw[optionName]);
  7077. }
  7078. else {
  7079. extra[optionName] = raw[optionName];
  7080. }
  7081. anyChanges = true;
  7082. }
  7083. }
  7084. if (anyChanges) {
  7085. this.currentViewOptionsInput = raw;
  7086. this.currentViewOptionsRefined = refined;
  7087. }
  7088. return {
  7089. rawOptions: this.currentViewOptionsInput,
  7090. refinedOptions: this.currentViewOptionsRefined,
  7091. extra: extra,
  7092. };
  7093. };
  7094. return CalendarDataManager;
  7095. }());
  7096. function buildDateEnv(timeZone, explicitLocale, weekNumberCalculation, firstDay, weekText, pluginHooks, availableLocaleData, defaultSeparator) {
  7097. var locale = buildLocale(explicitLocale || availableLocaleData.defaultCode, availableLocaleData.map);
  7098. return new DateEnv({
  7099. calendarSystem: 'gregory',
  7100. timeZone: timeZone,
  7101. namedTimeZoneImpl: pluginHooks.namedTimeZonedImpl,
  7102. locale: locale,
  7103. weekNumberCalculation: weekNumberCalculation,
  7104. firstDay: firstDay,
  7105. weekText: weekText,
  7106. cmdFormatter: pluginHooks.cmdFormatter,
  7107. defaultSeparator: defaultSeparator,
  7108. });
  7109. }
  7110. function buildTheme(options, pluginHooks) {
  7111. var ThemeClass = pluginHooks.themeClasses[options.themeSystem] || StandardTheme;
  7112. return new ThemeClass(options);
  7113. }
  7114. function buildDateProfileGenerator(props) {
  7115. var DateProfileGeneratorClass = props.dateProfileGeneratorClass || DateProfileGenerator;
  7116. return new DateProfileGeneratorClass(props);
  7117. }
  7118. function buildViewApi(type, getCurrentData, dateEnv) {
  7119. return new ViewApi(type, getCurrentData, dateEnv);
  7120. }
  7121. function buildEventUiBySource(eventSources) {
  7122. return mapHash(eventSources, function (eventSource) { return eventSource.ui; });
  7123. }
  7124. function buildEventUiBases(eventDefs, eventUiSingleBase, eventUiBySource) {
  7125. var eventUiBases = { '': eventUiSingleBase };
  7126. for (var defId in eventDefs) {
  7127. var def = eventDefs[defId];
  7128. if (def.sourceId && eventUiBySource[def.sourceId]) {
  7129. eventUiBases[defId] = eventUiBySource[def.sourceId];
  7130. }
  7131. }
  7132. return eventUiBases;
  7133. }
  7134. function buildViewUiProps(calendarContext) {
  7135. var options = calendarContext.options;
  7136. return {
  7137. eventUiSingleBase: createEventUi({
  7138. display: options.eventDisplay,
  7139. editable: options.editable,
  7140. startEditable: options.eventStartEditable,
  7141. durationEditable: options.eventDurationEditable,
  7142. constraint: options.eventConstraint,
  7143. overlap: typeof options.eventOverlap === 'boolean' ? options.eventOverlap : undefined,
  7144. allow: options.eventAllow,
  7145. backgroundColor: options.eventBackgroundColor,
  7146. borderColor: options.eventBorderColor,
  7147. textColor: options.eventTextColor,
  7148. color: options.eventColor,
  7149. // classNames: options.eventClassNames // render hook will handle this
  7150. }, calendarContext),
  7151. selectionConfig: createEventUi({
  7152. constraint: options.selectConstraint,
  7153. overlap: typeof options.selectOverlap === 'boolean' ? options.selectOverlap : undefined,
  7154. allow: options.selectAllow,
  7155. }, calendarContext),
  7156. };
  7157. }
  7158. function computeIsLoading(state, context) {
  7159. for (var _i = 0, _a = context.pluginHooks.isLoadingFuncs; _i < _a.length; _i++) {
  7160. var isLoadingFunc = _a[_i];
  7161. if (isLoadingFunc(state)) {
  7162. return true;
  7163. }
  7164. }
  7165. return false;
  7166. }
  7167. function parseContextBusinessHours(calendarContext) {
  7168. return parseBusinessHours(calendarContext.options.businessHours, calendarContext);
  7169. }
  7170. function warnUnknownOptions(options, viewName) {
  7171. for (var optionName in options) {
  7172. console.warn("Unknown option '" + optionName + "'" +
  7173. (viewName ? " for view '" + viewName + "'" : ''));
  7174. }
  7175. }
  7176. // TODO: move this to react plugin?
  7177. var CalendarDataProvider = /** @class */ (function (_super) {
  7178. __extends(CalendarDataProvider, _super);
  7179. function CalendarDataProvider(props) {
  7180. var _this = _super.call(this, props) || this;
  7181. _this.handleData = function (data) {
  7182. if (!_this.dataManager) { // still within initial run, before assignment in constructor
  7183. // eslint-disable-next-line react/no-direct-mutation-state
  7184. _this.state = data; // can't use setState yet
  7185. }
  7186. else {
  7187. _this.setState(data);
  7188. }
  7189. };
  7190. _this.dataManager = new CalendarDataManager({
  7191. optionOverrides: props.optionOverrides,
  7192. calendarApi: props.calendarApi,
  7193. onData: _this.handleData,
  7194. });
  7195. return _this;
  7196. }
  7197. CalendarDataProvider.prototype.render = function () {
  7198. return this.props.children(this.state);
  7199. };
  7200. CalendarDataProvider.prototype.componentDidUpdate = function (prevProps) {
  7201. var newOptionOverrides = this.props.optionOverrides;
  7202. if (newOptionOverrides !== prevProps.optionOverrides) { // prevent recursive handleData
  7203. this.dataManager.resetOptions(newOptionOverrides);
  7204. }
  7205. };
  7206. return CalendarDataProvider;
  7207. }(Component));
  7208. // HELPERS
  7209. /*
  7210. if nextDayThreshold is specified, slicing is done in an all-day fashion.
  7211. you can get nextDayThreshold from context.nextDayThreshold
  7212. */
  7213. function sliceEvents(props, allDay) {
  7214. return sliceEventStore(props.eventStore, props.eventUiBases, props.dateProfile.activeRange, allDay ? props.nextDayThreshold : null).fg;
  7215. }
  7216. var NamedTimeZoneImpl = /** @class */ (function () {
  7217. function NamedTimeZoneImpl(timeZoneName) {
  7218. this.timeZoneName = timeZoneName;
  7219. }
  7220. return NamedTimeZoneImpl;
  7221. }());
  7222. var SegHierarchy = /** @class */ (function () {
  7223. function SegHierarchy() {
  7224. // settings
  7225. this.strictOrder = false;
  7226. this.allowReslicing = false;
  7227. this.maxCoord = -1; // -1 means no max
  7228. this.maxStackCnt = -1; // -1 means no max
  7229. this.levelCoords = []; // ordered
  7230. this.entriesByLevel = []; // parallel with levelCoords
  7231. this.stackCnts = {}; // TODO: use better technique!?
  7232. }
  7233. SegHierarchy.prototype.addSegs = function (inputs) {
  7234. var hiddenEntries = [];
  7235. for (var _i = 0, inputs_1 = inputs; _i < inputs_1.length; _i++) {
  7236. var input = inputs_1[_i];
  7237. this.insertEntry(input, hiddenEntries);
  7238. }
  7239. return hiddenEntries;
  7240. };
  7241. SegHierarchy.prototype.insertEntry = function (entry, hiddenEntries) {
  7242. var insertion = this.findInsertion(entry);
  7243. if (this.isInsertionValid(insertion, entry)) {
  7244. this.insertEntryAt(entry, insertion);
  7245. return 1;
  7246. }
  7247. return this.handleInvalidInsertion(insertion, entry, hiddenEntries);
  7248. };
  7249. SegHierarchy.prototype.isInsertionValid = function (insertion, entry) {
  7250. return (this.maxCoord === -1 || insertion.levelCoord + entry.thickness <= this.maxCoord) &&
  7251. (this.maxStackCnt === -1 || insertion.stackCnt < this.maxStackCnt);
  7252. };
  7253. // returns number of new entries inserted
  7254. SegHierarchy.prototype.handleInvalidInsertion = function (insertion, entry, hiddenEntries) {
  7255. if (this.allowReslicing && insertion.touchingEntry) {
  7256. return this.splitEntry(entry, insertion.touchingEntry, hiddenEntries);
  7257. }
  7258. hiddenEntries.push(entry);
  7259. return 0;
  7260. };
  7261. SegHierarchy.prototype.splitEntry = function (entry, barrier, hiddenEntries) {
  7262. var partCnt = 0;
  7263. var splitHiddenEntries = [];
  7264. var entrySpan = entry.span;
  7265. var barrierSpan = barrier.span;
  7266. if (entrySpan.start < barrierSpan.start) {
  7267. partCnt += this.insertEntry({
  7268. index: entry.index,
  7269. thickness: entry.thickness,
  7270. span: { start: entrySpan.start, end: barrierSpan.start },
  7271. }, splitHiddenEntries);
  7272. }
  7273. if (entrySpan.end > barrierSpan.end) {
  7274. partCnt += this.insertEntry({
  7275. index: entry.index,
  7276. thickness: entry.thickness,
  7277. span: { start: barrierSpan.end, end: entrySpan.end },
  7278. }, splitHiddenEntries);
  7279. }
  7280. if (partCnt) {
  7281. hiddenEntries.push.apply(hiddenEntries, __spreadArray([{
  7282. index: entry.index,
  7283. thickness: entry.thickness,
  7284. span: intersectSpans(barrierSpan, entrySpan), // guaranteed to intersect
  7285. }], splitHiddenEntries));
  7286. return partCnt;
  7287. }
  7288. hiddenEntries.push(entry);
  7289. return 0;
  7290. };
  7291. SegHierarchy.prototype.insertEntryAt = function (entry, insertion) {
  7292. var _a = this, entriesByLevel = _a.entriesByLevel, levelCoords = _a.levelCoords;
  7293. var destLevel = insertion.level;
  7294. if (destLevel >= levelCoords.length || // level doesn't exist yet
  7295. levelCoords[destLevel] > insertion.levelCoord // destLevel needs to be pushed forward to make way
  7296. ) {
  7297. // create a new level
  7298. insertAt(levelCoords, destLevel, insertion.levelCoord);
  7299. insertAt(entriesByLevel, destLevel, [entry]);
  7300. }
  7301. else {
  7302. // insert into existing level
  7303. insertAt(entriesByLevel[destLevel], insertion.lateralEnd, entry);
  7304. }
  7305. this.stackCnts[buildEntryKey(entry)] = insertion.stackCnt;
  7306. };
  7307. SegHierarchy.prototype.findInsertion = function (newEntry) {
  7308. var _a = this, levelCoords = _a.levelCoords, entriesByLevel = _a.entriesByLevel, stackCnts = _a.stackCnts, strictOrder = _a.strictOrder;
  7309. var levelCnt = levelCoords.length;
  7310. var resLevelCoord = 0;
  7311. var resLevel = 0;
  7312. var lateralStart = 0;
  7313. var lateralEnd = 0;
  7314. var touchingLevel = -1;
  7315. var touchingEntry = null; // last touch entry
  7316. for (var level = 0; level < levelCnt; level += 1) {
  7317. var levelCoord = levelCoords[level];
  7318. // if the current level is past the placed entry, we have found a good empty space and can stop.
  7319. // if strictOrder, keep finding more lateral intersections.
  7320. if (!strictOrder && levelCoord >= resLevelCoord + newEntry.thickness) {
  7321. break;
  7322. }
  7323. var entries = entriesByLevel[level];
  7324. var entry = void 0;
  7325. var searchRes = binarySearch(entries, newEntry.span.start, getEntrySpanEnd);
  7326. lateralStart = searchRes[0] + searchRes[1]; // if exact match (which doesn't collide), go to next one
  7327. lateralEnd = lateralStart; // also functions as a moving index
  7328. while ( // loop through entries that horizontally intersect
  7329. (entry = entries[lateralEnd]) && // but not past the whole entry list
  7330. entry.span.start < newEntry.span.end // and not entirely past newEntry
  7331. ) {
  7332. if (strictOrder || // strict-mode doesn't care about vert intersection. record touch and keep pushing down
  7333. ( // vertically intersects?
  7334. resLevelCoord < levelCoord + entry.thickness &&
  7335. resLevelCoord + newEntry.thickness > levelCoord)) {
  7336. // push down the potential destination
  7337. resLevelCoord = levelCoord + entry.thickness; // move to bottom of colliding entry
  7338. touchingLevel = level;
  7339. touchingEntry = entry;
  7340. }
  7341. lateralEnd += 1;
  7342. }
  7343. // regardless of whether there were collisions in the current level,
  7344. // keep updating the final-destination level until it goes past the final-destination coord.
  7345. if (levelCoord < resLevelCoord) {
  7346. resLevel = level + 1;
  7347. }
  7348. }
  7349. return {
  7350. level: resLevel,
  7351. levelCoord: resLevelCoord,
  7352. lateralStart: lateralStart,
  7353. lateralEnd: lateralEnd,
  7354. touchingLevel: touchingLevel,
  7355. touchingEntry: touchingEntry,
  7356. stackCnt: touchingEntry ? stackCnts[buildEntryKey(touchingEntry)] + 1 : 0,
  7357. };
  7358. };
  7359. // sorted by levelCoord (lowest to highest)
  7360. SegHierarchy.prototype.toRects = function () {
  7361. var _a = this, entriesByLevel = _a.entriesByLevel, levelCoords = _a.levelCoords;
  7362. var levelCnt = entriesByLevel.length;
  7363. var rects = [];
  7364. for (var level = 0; level < levelCnt; level += 1) {
  7365. var entries = entriesByLevel[level];
  7366. var levelCoord = levelCoords[level];
  7367. for (var _i = 0, entries_1 = entries; _i < entries_1.length; _i++) {
  7368. var entry = entries_1[_i];
  7369. rects.push(__assign(__assign({}, entry), { levelCoord: levelCoord }));
  7370. }
  7371. }
  7372. return rects;
  7373. };
  7374. return SegHierarchy;
  7375. }());
  7376. function getEntrySpanEnd(entry) {
  7377. return entry.span.end;
  7378. }
  7379. function buildEntryKey(entry) {
  7380. return entry.index + ':' + entry.span.start;
  7381. }
  7382. // returns groups with entries sorted by input order
  7383. function groupIntersectingEntries(entries) {
  7384. var merges = [];
  7385. for (var _i = 0, entries_2 = entries; _i < entries_2.length; _i++) {
  7386. var entry = entries_2[_i];
  7387. var filteredMerges = [];
  7388. var hungryMerge = {
  7389. span: entry.span,
  7390. entries: [entry],
  7391. };
  7392. for (var _a = 0, merges_1 = merges; _a < merges_1.length; _a++) {
  7393. var merge = merges_1[_a];
  7394. if (intersectSpans(merge.span, hungryMerge.span)) {
  7395. hungryMerge = {
  7396. entries: merge.entries.concat(hungryMerge.entries),
  7397. span: joinSpans(merge.span, hungryMerge.span),
  7398. };
  7399. }
  7400. else {
  7401. filteredMerges.push(merge);
  7402. }
  7403. }
  7404. filteredMerges.push(hungryMerge);
  7405. merges = filteredMerges;
  7406. }
  7407. return merges;
  7408. }
  7409. function joinSpans(span0, span1) {
  7410. return {
  7411. start: Math.min(span0.start, span1.start),
  7412. end: Math.max(span0.end, span1.end),
  7413. };
  7414. }
  7415. function intersectSpans(span0, span1) {
  7416. var start = Math.max(span0.start, span1.start);
  7417. var end = Math.min(span0.end, span1.end);
  7418. if (start < end) {
  7419. return { start: start, end: end };
  7420. }
  7421. return null;
  7422. }
  7423. // general util
  7424. // ---------------------------------------------------------------------------------------------------------------------
  7425. function insertAt(arr, index, item) {
  7426. arr.splice(index, 0, item);
  7427. }
  7428. function binarySearch(a, searchVal, getItemVal) {
  7429. var startIndex = 0;
  7430. var endIndex = a.length; // exclusive
  7431. if (!endIndex || searchVal < getItemVal(a[startIndex])) { // no items OR before first item
  7432. return [0, 0];
  7433. }
  7434. if (searchVal > getItemVal(a[endIndex - 1])) { // after last item
  7435. return [endIndex, 0];
  7436. }
  7437. while (startIndex < endIndex) {
  7438. var middleIndex = Math.floor(startIndex + (endIndex - startIndex) / 2);
  7439. var middleVal = getItemVal(a[middleIndex]);
  7440. if (searchVal < middleVal) {
  7441. endIndex = middleIndex;
  7442. }
  7443. else if (searchVal > middleVal) {
  7444. startIndex = middleIndex + 1;
  7445. }
  7446. else { // equal!
  7447. return [middleIndex, 1];
  7448. }
  7449. }
  7450. return [startIndex, 0];
  7451. }
  7452. var Interaction = /** @class */ (function () {
  7453. function Interaction(settings) {
  7454. this.component = settings.component;
  7455. this.isHitComboAllowed = settings.isHitComboAllowed || null;
  7456. }
  7457. Interaction.prototype.destroy = function () {
  7458. };
  7459. return Interaction;
  7460. }());
  7461. function parseInteractionSettings(component, input) {
  7462. return {
  7463. component: component,
  7464. el: input.el,
  7465. useEventCenter: input.useEventCenter != null ? input.useEventCenter : true,
  7466. isHitComboAllowed: input.isHitComboAllowed || null,
  7467. };
  7468. }
  7469. function interactionSettingsToStore(settings) {
  7470. var _a;
  7471. return _a = {},
  7472. _a[settings.component.uid] = settings,
  7473. _a;
  7474. }
  7475. // global state
  7476. var interactionSettingsStore = {};
  7477. /*
  7478. An abstraction for a dragging interaction originating on an event.
  7479. Does higher-level things than PointerDragger, such as possibly:
  7480. - a "mirror" that moves with the pointer
  7481. - a minimum number of pixels or other criteria for a true drag to begin
  7482. subclasses must emit:
  7483. - pointerdown
  7484. - dragstart
  7485. - dragmove
  7486. - pointerup
  7487. - dragend
  7488. */
  7489. var ElementDragging = /** @class */ (function () {
  7490. function ElementDragging(el, selector) {
  7491. this.emitter = new Emitter();
  7492. }
  7493. ElementDragging.prototype.destroy = function () {
  7494. };
  7495. ElementDragging.prototype.setMirrorIsVisible = function (bool) {
  7496. // optional if subclass doesn't want to support a mirror
  7497. };
  7498. ElementDragging.prototype.setMirrorNeedsRevert = function (bool) {
  7499. // optional if subclass doesn't want to support a mirror
  7500. };
  7501. ElementDragging.prototype.setAutoScrollEnabled = function (bool) {
  7502. // optional
  7503. };
  7504. return ElementDragging;
  7505. }());
  7506. // TODO: get rid of this in favor of options system,
  7507. // tho it's really easy to access this globally rather than pass thru options.
  7508. var config = {};
  7509. /*
  7510. Information about what will happen when an external element is dragged-and-dropped
  7511. onto a calendar. Contains information for creating an event.
  7512. */
  7513. var DRAG_META_REFINERS = {
  7514. startTime: createDuration,
  7515. duration: createDuration,
  7516. create: Boolean,
  7517. sourceId: String,
  7518. };
  7519. function parseDragMeta(raw) {
  7520. var _a = refineProps(raw, DRAG_META_REFINERS), refined = _a.refined, extra = _a.extra;
  7521. return {
  7522. startTime: refined.startTime || null,
  7523. duration: refined.duration || null,
  7524. create: refined.create != null ? refined.create : true,
  7525. sourceId: refined.sourceId,
  7526. leftoverProps: extra,
  7527. };
  7528. }
  7529. var ToolbarSection = /** @class */ (function (_super) {
  7530. __extends(ToolbarSection, _super);
  7531. function ToolbarSection() {
  7532. return _super !== null && _super.apply(this, arguments) || this;
  7533. }
  7534. ToolbarSection.prototype.render = function () {
  7535. var _this = this;
  7536. var children = this.props.widgetGroups.map(function (widgetGroup) { return _this.renderWidgetGroup(widgetGroup); });
  7537. return createElement.apply(void 0, __spreadArray(['div', { className: 'fc-toolbar-chunk' }], children));
  7538. };
  7539. ToolbarSection.prototype.renderWidgetGroup = function (widgetGroup) {
  7540. var props = this.props;
  7541. var theme = this.context.theme;
  7542. var children = [];
  7543. var isOnlyButtons = true;
  7544. for (var _i = 0, widgetGroup_1 = widgetGroup; _i < widgetGroup_1.length; _i++) {
  7545. var widget = widgetGroup_1[_i];
  7546. var buttonName = widget.buttonName, buttonClick = widget.buttonClick, buttonText = widget.buttonText, buttonIcon = widget.buttonIcon;
  7547. if (buttonName === 'title') {
  7548. isOnlyButtons = false;
  7549. children.push(createElement("h2", { className: "fc-toolbar-title" }, props.title));
  7550. }
  7551. else {
  7552. var ariaAttrs = buttonIcon ? { 'aria-label': buttonName } : {};
  7553. var buttonClasses = ["fc-" + buttonName + "-button", theme.getClass('button')];
  7554. if (buttonName === props.activeButton) {
  7555. buttonClasses.push(theme.getClass('buttonActive'));
  7556. }
  7557. var isDisabled = (!props.isTodayEnabled && buttonName === 'today') ||
  7558. (!props.isPrevEnabled && buttonName === 'prev') ||
  7559. (!props.isNextEnabled && buttonName === 'next');
  7560. children.push(createElement("button", __assign({ disabled: isDisabled, className: buttonClasses.join(' '), onClick: buttonClick, type: "button" }, ariaAttrs), buttonText || (buttonIcon ? createElement("span", { className: buttonIcon }) : '')));
  7561. }
  7562. }
  7563. if (children.length > 1) {
  7564. var groupClassName = (isOnlyButtons && theme.getClass('buttonGroup')) || '';
  7565. return createElement.apply(void 0, __spreadArray(['div', { className: groupClassName }], children));
  7566. }
  7567. return children[0];
  7568. };
  7569. return ToolbarSection;
  7570. }(BaseComponent));
  7571. var Toolbar = /** @class */ (function (_super) {
  7572. __extends(Toolbar, _super);
  7573. function Toolbar() {
  7574. return _super !== null && _super.apply(this, arguments) || this;
  7575. }
  7576. Toolbar.prototype.render = function () {
  7577. var _a = this.props, model = _a.model, extraClassName = _a.extraClassName;
  7578. var forceLtr = false;
  7579. var startContent;
  7580. var endContent;
  7581. var centerContent = model.center;
  7582. if (model.left) {
  7583. forceLtr = true;
  7584. startContent = model.left;
  7585. }
  7586. else {
  7587. startContent = model.start;
  7588. }
  7589. if (model.right) {
  7590. forceLtr = true;
  7591. endContent = model.right;
  7592. }
  7593. else {
  7594. endContent = model.end;
  7595. }
  7596. var classNames = [
  7597. extraClassName || '',
  7598. 'fc-toolbar',
  7599. forceLtr ? 'fc-toolbar-ltr' : '',
  7600. ];
  7601. return (createElement("div", { className: classNames.join(' ') },
  7602. this.renderSection('start', startContent || []),
  7603. this.renderSection('center', centerContent || []),
  7604. this.renderSection('end', endContent || [])));
  7605. };
  7606. Toolbar.prototype.renderSection = function (key, widgetGroups) {
  7607. var props = this.props;
  7608. return (createElement(ToolbarSection, { key: key, widgetGroups: widgetGroups, title: props.title, activeButton: props.activeButton, isTodayEnabled: props.isTodayEnabled, isPrevEnabled: props.isPrevEnabled, isNextEnabled: props.isNextEnabled }));
  7609. };
  7610. return Toolbar;
  7611. }(BaseComponent));
  7612. // TODO: do function component?
  7613. var ViewContainer = /** @class */ (function (_super) {
  7614. __extends(ViewContainer, _super);
  7615. function ViewContainer() {
  7616. var _this = _super !== null && _super.apply(this, arguments) || this;
  7617. _this.state = {
  7618. availableWidth: null,
  7619. };
  7620. _this.handleEl = function (el) {
  7621. _this.el = el;
  7622. setRef(_this.props.elRef, el);
  7623. _this.updateAvailableWidth();
  7624. };
  7625. _this.handleResize = function () {
  7626. _this.updateAvailableWidth();
  7627. };
  7628. return _this;
  7629. }
  7630. ViewContainer.prototype.render = function () {
  7631. var _a = this, props = _a.props, state = _a.state;
  7632. var aspectRatio = props.aspectRatio;
  7633. var classNames = [
  7634. 'fc-view-harness',
  7635. (aspectRatio || props.liquid || props.height)
  7636. ? 'fc-view-harness-active' // harness controls the height
  7637. : 'fc-view-harness-passive', // let the view do the height
  7638. ];
  7639. var height = '';
  7640. var paddingBottom = '';
  7641. if (aspectRatio) {
  7642. if (state.availableWidth !== null) {
  7643. height = state.availableWidth / aspectRatio;
  7644. }
  7645. else {
  7646. // while waiting to know availableWidth, we can't set height to *zero*
  7647. // because will cause lots of unnecessary scrollbars within scrollgrid.
  7648. // BETTER: don't start rendering ANYTHING yet until we know container width
  7649. // NOTE: why not always use paddingBottom? Causes height oscillation (issue 5606)
  7650. paddingBottom = (1 / aspectRatio) * 100 + "%";
  7651. }
  7652. }
  7653. else {
  7654. height = props.height || '';
  7655. }
  7656. return (createElement("div", { ref: this.handleEl, onClick: props.onClick, className: classNames.join(' '), style: { height: height, paddingBottom: paddingBottom } }, props.children));
  7657. };
  7658. ViewContainer.prototype.componentDidMount = function () {
  7659. this.context.addResizeHandler(this.handleResize);
  7660. };
  7661. ViewContainer.prototype.componentWillUnmount = function () {
  7662. this.context.removeResizeHandler(this.handleResize);
  7663. };
  7664. ViewContainer.prototype.updateAvailableWidth = function () {
  7665. if (this.el && // needed. but why?
  7666. this.props.aspectRatio // aspectRatio is the only height setting that needs availableWidth
  7667. ) {
  7668. this.setState({ availableWidth: this.el.offsetWidth });
  7669. }
  7670. };
  7671. return ViewContainer;
  7672. }(BaseComponent));
  7673. /*
  7674. Detects when the user clicks on an event within a DateComponent
  7675. */
  7676. var EventClicking = /** @class */ (function (_super) {
  7677. __extends(EventClicking, _super);
  7678. function EventClicking(settings) {
  7679. var _this = _super.call(this, settings) || this;
  7680. _this.handleSegClick = function (ev, segEl) {
  7681. var component = _this.component;
  7682. var context = component.context;
  7683. var seg = getElSeg(segEl);
  7684. if (seg && // might be the <div> surrounding the more link
  7685. component.isValidSegDownEl(ev.target)) {
  7686. // our way to simulate a link click for elements that can't be <a> tags
  7687. // grab before trigger fired in case trigger trashes DOM thru rerendering
  7688. var hasUrlContainer = elementClosest(ev.target, '.fc-event-forced-url');
  7689. var url = hasUrlContainer ? hasUrlContainer.querySelector('a[href]').href : '';
  7690. context.emitter.trigger('eventClick', {
  7691. el: segEl,
  7692. event: new EventApi(component.context, seg.eventRange.def, seg.eventRange.instance),
  7693. jsEvent: ev,
  7694. view: context.viewApi,
  7695. });
  7696. if (url && !ev.defaultPrevented) {
  7697. window.location.href = url;
  7698. }
  7699. }
  7700. };
  7701. _this.destroy = listenBySelector(settings.el, 'click', '.fc-event', // on both fg and bg events
  7702. _this.handleSegClick);
  7703. return _this;
  7704. }
  7705. return EventClicking;
  7706. }(Interaction));
  7707. /*
  7708. Triggers events and adds/removes core classNames when the user's pointer
  7709. enters/leaves event-elements of a component.
  7710. */
  7711. var EventHovering = /** @class */ (function (_super) {
  7712. __extends(EventHovering, _super);
  7713. function EventHovering(settings) {
  7714. var _this = _super.call(this, settings) || this;
  7715. // for simulating an eventMouseLeave when the event el is destroyed while mouse is over it
  7716. _this.handleEventElRemove = function (el) {
  7717. if (el === _this.currentSegEl) {
  7718. _this.handleSegLeave(null, _this.currentSegEl);
  7719. }
  7720. };
  7721. _this.handleSegEnter = function (ev, segEl) {
  7722. if (getElSeg(segEl)) { // TODO: better way to make sure not hovering over more+ link or its wrapper
  7723. _this.currentSegEl = segEl;
  7724. _this.triggerEvent('eventMouseEnter', ev, segEl);
  7725. }
  7726. };
  7727. _this.handleSegLeave = function (ev, segEl) {
  7728. if (_this.currentSegEl) {
  7729. _this.currentSegEl = null;
  7730. _this.triggerEvent('eventMouseLeave', ev, segEl);
  7731. }
  7732. };
  7733. _this.removeHoverListeners = listenToHoverBySelector(settings.el, '.fc-event', // on both fg and bg events
  7734. _this.handleSegEnter, _this.handleSegLeave);
  7735. return _this;
  7736. }
  7737. EventHovering.prototype.destroy = function () {
  7738. this.removeHoverListeners();
  7739. };
  7740. EventHovering.prototype.triggerEvent = function (publicEvName, ev, segEl) {
  7741. var component = this.component;
  7742. var context = component.context;
  7743. var seg = getElSeg(segEl);
  7744. if (!ev || component.isValidSegDownEl(ev.target)) {
  7745. context.emitter.trigger(publicEvName, {
  7746. el: segEl,
  7747. event: new EventApi(context, seg.eventRange.def, seg.eventRange.instance),
  7748. jsEvent: ev,
  7749. view: context.viewApi,
  7750. });
  7751. }
  7752. };
  7753. return EventHovering;
  7754. }(Interaction));
  7755. var CalendarContent = /** @class */ (function (_super) {
  7756. __extends(CalendarContent, _super);
  7757. function CalendarContent() {
  7758. var _this = _super !== null && _super.apply(this, arguments) || this;
  7759. _this.buildViewContext = memoize(buildViewContext);
  7760. _this.buildViewPropTransformers = memoize(buildViewPropTransformers);
  7761. _this.buildToolbarProps = memoize(buildToolbarProps);
  7762. _this.handleNavLinkClick = buildDelegationHandler('a[data-navlink]', _this._handleNavLinkClick.bind(_this));
  7763. _this.headerRef = createRef();
  7764. _this.footerRef = createRef();
  7765. _this.interactionsStore = {};
  7766. // Component Registration
  7767. // -----------------------------------------------------------------------------------------------------------------
  7768. _this.registerInteractiveComponent = function (component, settingsInput) {
  7769. var settings = parseInteractionSettings(component, settingsInput);
  7770. var DEFAULT_INTERACTIONS = [
  7771. EventClicking,
  7772. EventHovering,
  7773. ];
  7774. var interactionClasses = DEFAULT_INTERACTIONS.concat(_this.props.pluginHooks.componentInteractions);
  7775. var interactions = interactionClasses.map(function (TheInteractionClass) { return new TheInteractionClass(settings); });
  7776. _this.interactionsStore[component.uid] = interactions;
  7777. interactionSettingsStore[component.uid] = settings;
  7778. };
  7779. _this.unregisterInteractiveComponent = function (component) {
  7780. for (var _i = 0, _a = _this.interactionsStore[component.uid]; _i < _a.length; _i++) {
  7781. var listener = _a[_i];
  7782. listener.destroy();
  7783. }
  7784. delete _this.interactionsStore[component.uid];
  7785. delete interactionSettingsStore[component.uid];
  7786. };
  7787. // Resizing
  7788. // -----------------------------------------------------------------------------------------------------------------
  7789. _this.resizeRunner = new DelayedRunner(function () {
  7790. _this.props.emitter.trigger('_resize', true); // should window resizes be considered "forced" ?
  7791. _this.props.emitter.trigger('windowResize', { view: _this.props.viewApi });
  7792. });
  7793. _this.handleWindowResize = function (ev) {
  7794. var options = _this.props.options;
  7795. if (options.handleWindowResize &&
  7796. ev.target === window // avoid jqui events
  7797. ) {
  7798. _this.resizeRunner.request(options.windowResizeDelay);
  7799. }
  7800. };
  7801. return _this;
  7802. }
  7803. /*
  7804. renders INSIDE of an outer div
  7805. */
  7806. CalendarContent.prototype.render = function () {
  7807. var props = this.props;
  7808. var toolbarConfig = props.toolbarConfig, options = props.options;
  7809. var toolbarProps = this.buildToolbarProps(props.viewSpec, props.dateProfile, props.dateProfileGenerator, props.currentDate, getNow(props.options.now, props.dateEnv), // TODO: use NowTimer????
  7810. props.viewTitle);
  7811. var viewVGrow = false;
  7812. var viewHeight = '';
  7813. var viewAspectRatio;
  7814. if (props.isHeightAuto || props.forPrint) {
  7815. viewHeight = '';
  7816. }
  7817. else if (options.height != null) {
  7818. viewVGrow = true;
  7819. }
  7820. else if (options.contentHeight != null) {
  7821. viewHeight = options.contentHeight;
  7822. }
  7823. else {
  7824. viewAspectRatio = Math.max(options.aspectRatio, 0.5); // prevent from getting too tall
  7825. }
  7826. var viewContext = this.buildViewContext(props.viewSpec, props.viewApi, props.options, props.dateProfileGenerator, props.dateEnv, props.theme, props.pluginHooks, props.dispatch, props.getCurrentData, props.emitter, props.calendarApi, this.registerInteractiveComponent, this.unregisterInteractiveComponent);
  7827. return (createElement(ViewContextType.Provider, { value: viewContext },
  7828. toolbarConfig.headerToolbar && (createElement(Toolbar, __assign({ ref: this.headerRef, extraClassName: "fc-header-toolbar", model: toolbarConfig.headerToolbar }, toolbarProps))),
  7829. createElement(ViewContainer, { liquid: viewVGrow, height: viewHeight, aspectRatio: viewAspectRatio, onClick: this.handleNavLinkClick },
  7830. this.renderView(props),
  7831. this.buildAppendContent()),
  7832. toolbarConfig.footerToolbar && (createElement(Toolbar, __assign({ ref: this.footerRef, extraClassName: "fc-footer-toolbar", model: toolbarConfig.footerToolbar }, toolbarProps)))));
  7833. };
  7834. CalendarContent.prototype.componentDidMount = function () {
  7835. var props = this.props;
  7836. this.calendarInteractions = props.pluginHooks.calendarInteractions
  7837. .map(function (CalendarInteractionClass) { return new CalendarInteractionClass(props); });
  7838. window.addEventListener('resize', this.handleWindowResize);
  7839. var propSetHandlers = props.pluginHooks.propSetHandlers;
  7840. for (var propName in propSetHandlers) {
  7841. propSetHandlers[propName](props[propName], props);
  7842. }
  7843. };
  7844. CalendarContent.prototype.componentDidUpdate = function (prevProps) {
  7845. var props = this.props;
  7846. var propSetHandlers = props.pluginHooks.propSetHandlers;
  7847. for (var propName in propSetHandlers) {
  7848. if (props[propName] !== prevProps[propName]) {
  7849. propSetHandlers[propName](props[propName], props);
  7850. }
  7851. }
  7852. };
  7853. CalendarContent.prototype.componentWillUnmount = function () {
  7854. window.removeEventListener('resize', this.handleWindowResize);
  7855. this.resizeRunner.clear();
  7856. for (var _i = 0, _a = this.calendarInteractions; _i < _a.length; _i++) {
  7857. var interaction = _a[_i];
  7858. interaction.destroy();
  7859. }
  7860. this.props.emitter.trigger('_unmount');
  7861. };
  7862. CalendarContent.prototype._handleNavLinkClick = function (ev, anchorEl) {
  7863. var _a = this.props, dateEnv = _a.dateEnv, options = _a.options, calendarApi = _a.calendarApi;
  7864. var navLinkOptions = anchorEl.getAttribute('data-navlink');
  7865. navLinkOptions = navLinkOptions ? JSON.parse(navLinkOptions) : {};
  7866. var dateMarker = dateEnv.createMarker(navLinkOptions.date);
  7867. var viewType = navLinkOptions.type;
  7868. var customAction = viewType === 'day' ? options.navLinkDayClick :
  7869. viewType === 'week' ? options.navLinkWeekClick : null;
  7870. if (typeof customAction === 'function') {
  7871. customAction.call(calendarApi, dateEnv.toDate(dateMarker), ev);
  7872. }
  7873. else {
  7874. if (typeof customAction === 'string') {
  7875. viewType = customAction;
  7876. }
  7877. calendarApi.zoomTo(dateMarker, viewType);
  7878. }
  7879. };
  7880. CalendarContent.prototype.buildAppendContent = function () {
  7881. var props = this.props;
  7882. var children = props.pluginHooks.viewContainerAppends.map(function (buildAppendContent) { return buildAppendContent(props); });
  7883. return createElement.apply(void 0, __spreadArray([Fragment, {}], children));
  7884. };
  7885. CalendarContent.prototype.renderView = function (props) {
  7886. var pluginHooks = props.pluginHooks;
  7887. var viewSpec = props.viewSpec;
  7888. var viewProps = {
  7889. dateProfile: props.dateProfile,
  7890. businessHours: props.businessHours,
  7891. eventStore: props.renderableEventStore,
  7892. eventUiBases: props.eventUiBases,
  7893. dateSelection: props.dateSelection,
  7894. eventSelection: props.eventSelection,
  7895. eventDrag: props.eventDrag,
  7896. eventResize: props.eventResize,
  7897. isHeightAuto: props.isHeightAuto,
  7898. forPrint: props.forPrint,
  7899. };
  7900. var transformers = this.buildViewPropTransformers(pluginHooks.viewPropsTransformers);
  7901. for (var _i = 0, transformers_1 = transformers; _i < transformers_1.length; _i++) {
  7902. var transformer = transformers_1[_i];
  7903. __assign(viewProps, transformer.transform(viewProps, props));
  7904. }
  7905. var ViewComponent = viewSpec.component;
  7906. return (createElement(ViewComponent, __assign({}, viewProps)));
  7907. };
  7908. return CalendarContent;
  7909. }(PureComponent));
  7910. function buildToolbarProps(viewSpec, dateProfile, dateProfileGenerator, currentDate, now, title) {
  7911. // don't force any date-profiles to valid date profiles (the `false`) so that we can tell if it's invalid
  7912. var todayInfo = dateProfileGenerator.build(now, undefined, false); // TODO: need `undefined` or else INFINITE LOOP for some reason
  7913. var prevInfo = dateProfileGenerator.buildPrev(dateProfile, currentDate, false);
  7914. var nextInfo = dateProfileGenerator.buildNext(dateProfile, currentDate, false);
  7915. return {
  7916. title: title,
  7917. activeButton: viewSpec.type,
  7918. isTodayEnabled: todayInfo.isValid && !rangeContainsMarker(dateProfile.currentRange, now),
  7919. isPrevEnabled: prevInfo.isValid,
  7920. isNextEnabled: nextInfo.isValid,
  7921. };
  7922. }
  7923. // Plugin
  7924. // -----------------------------------------------------------------------------------------------------------------
  7925. function buildViewPropTransformers(theClasses) {
  7926. return theClasses.map(function (TheClass) { return new TheClass(); });
  7927. }
  7928. var CalendarRoot = /** @class */ (function (_super) {
  7929. __extends(CalendarRoot, _super);
  7930. function CalendarRoot() {
  7931. var _this = _super !== null && _super.apply(this, arguments) || this;
  7932. _this.state = {
  7933. forPrint: false,
  7934. };
  7935. _this.handleBeforePrint = function () {
  7936. _this.setState({ forPrint: true });
  7937. };
  7938. _this.handleAfterPrint = function () {
  7939. _this.setState({ forPrint: false });
  7940. };
  7941. return _this;
  7942. }
  7943. CalendarRoot.prototype.render = function () {
  7944. var props = this.props;
  7945. var options = props.options;
  7946. var forPrint = this.state.forPrint;
  7947. var isHeightAuto = forPrint || options.height === 'auto' || options.contentHeight === 'auto';
  7948. var height = (!isHeightAuto && options.height != null) ? options.height : '';
  7949. var classNames = [
  7950. 'fc',
  7951. forPrint ? 'fc-media-print' : 'fc-media-screen',
  7952. "fc-direction-" + options.direction,
  7953. props.theme.getClass('root'),
  7954. ];
  7955. if (!getCanVGrowWithinCell()) {
  7956. classNames.push('fc-liquid-hack');
  7957. }
  7958. return props.children(classNames, height, isHeightAuto, forPrint);
  7959. };
  7960. CalendarRoot.prototype.componentDidMount = function () {
  7961. var emitter = this.props.emitter;
  7962. emitter.on('_beforeprint', this.handleBeforePrint);
  7963. emitter.on('_afterprint', this.handleAfterPrint);
  7964. };
  7965. CalendarRoot.prototype.componentWillUnmount = function () {
  7966. var emitter = this.props.emitter;
  7967. emitter.off('_beforeprint', this.handleBeforePrint);
  7968. emitter.off('_afterprint', this.handleAfterPrint);
  7969. };
  7970. return CalendarRoot;
  7971. }(BaseComponent));
  7972. // Computes a default column header formatting string if `colFormat` is not explicitly defined
  7973. function computeFallbackHeaderFormat(datesRepDistinctDays, dayCnt) {
  7974. // if more than one week row, or if there are a lot of columns with not much space,
  7975. // put just the day numbers will be in each cell
  7976. if (!datesRepDistinctDays || dayCnt > 10) {
  7977. return createFormatter({ weekday: 'short' }); // "Sat"
  7978. }
  7979. if (dayCnt > 1) {
  7980. return createFormatter({ weekday: 'short', month: 'numeric', day: 'numeric', omitCommas: true }); // "Sat 11/12"
  7981. }
  7982. return createFormatter({ weekday: 'long' }); // "Saturday"
  7983. }
  7984. var CLASS_NAME = 'fc-col-header-cell'; // do the cushion too? no
  7985. function renderInner$1(hookProps) {
  7986. return hookProps.text;
  7987. }
  7988. var TableDateCell = /** @class */ (function (_super) {
  7989. __extends(TableDateCell, _super);
  7990. function TableDateCell() {
  7991. return _super !== null && _super.apply(this, arguments) || this;
  7992. }
  7993. TableDateCell.prototype.render = function () {
  7994. var _a = this.context, dateEnv = _a.dateEnv, options = _a.options, theme = _a.theme, viewApi = _a.viewApi;
  7995. var props = this.props;
  7996. var date = props.date, dateProfile = props.dateProfile;
  7997. var dayMeta = getDateMeta(date, props.todayRange, null, dateProfile);
  7998. var classNames = [CLASS_NAME].concat(getDayClassNames(dayMeta, theme));
  7999. var text = dateEnv.format(date, props.dayHeaderFormat);
  8000. // if colCnt is 1, we are already in a day-view and don't need a navlink
  8001. var navLinkAttrs = (options.navLinks && !dayMeta.isDisabled && props.colCnt > 1)
  8002. ? { 'data-navlink': buildNavLinkData(date), tabIndex: 0 }
  8003. : {};
  8004. var hookProps = __assign(__assign(__assign({ date: dateEnv.toDate(date), view: viewApi }, props.extraHookProps), { text: text }), dayMeta);
  8005. return (createElement(RenderHook, { hookProps: hookProps, classNames: options.dayHeaderClassNames, content: options.dayHeaderContent, defaultContent: renderInner$1, didMount: options.dayHeaderDidMount, willUnmount: options.dayHeaderWillUnmount }, function (rootElRef, customClassNames, innerElRef, innerContent) { return (createElement("th", __assign({ ref: rootElRef, className: classNames.concat(customClassNames).join(' '), "data-date": !dayMeta.isDisabled ? formatDayString(date) : undefined, colSpan: props.colSpan }, props.extraDataAttrs),
  8006. createElement("div", { className: "fc-scrollgrid-sync-inner" }, !dayMeta.isDisabled && (createElement("a", __assign({ ref: innerElRef, className: [
  8007. 'fc-col-header-cell-cushion',
  8008. props.isSticky ? 'fc-sticky' : '',
  8009. ].join(' ') }, navLinkAttrs), innerContent))))); }));
  8010. };
  8011. return TableDateCell;
  8012. }(BaseComponent));
  8013. var TableDowCell = /** @class */ (function (_super) {
  8014. __extends(TableDowCell, _super);
  8015. function TableDowCell() {
  8016. return _super !== null && _super.apply(this, arguments) || this;
  8017. }
  8018. TableDowCell.prototype.render = function () {
  8019. var props = this.props;
  8020. var _a = this.context, dateEnv = _a.dateEnv, theme = _a.theme, viewApi = _a.viewApi, options = _a.options;
  8021. var date = addDays(new Date(259200000), props.dow); // start with Sun, 04 Jan 1970 00:00:00 GMT
  8022. var dateMeta = {
  8023. dow: props.dow,
  8024. isDisabled: false,
  8025. isFuture: false,
  8026. isPast: false,
  8027. isToday: false,
  8028. isOther: false,
  8029. };
  8030. var classNames = [CLASS_NAME].concat(getDayClassNames(dateMeta, theme), props.extraClassNames || []);
  8031. var text = dateEnv.format(date, props.dayHeaderFormat);
  8032. var hookProps = __assign(__assign(__assign(__assign({ // TODO: make this public?
  8033. date: date }, dateMeta), { view: viewApi }), props.extraHookProps), { text: text });
  8034. return (createElement(RenderHook, { hookProps: hookProps, classNames: options.dayHeaderClassNames, content: options.dayHeaderContent, defaultContent: renderInner$1, didMount: options.dayHeaderDidMount, willUnmount: options.dayHeaderWillUnmount }, function (rootElRef, customClassNames, innerElRef, innerContent) { return (createElement("th", __assign({ ref: rootElRef, className: classNames.concat(customClassNames).join(' '), colSpan: props.colSpan }, props.extraDataAttrs),
  8035. createElement("div", { className: "fc-scrollgrid-sync-inner" },
  8036. createElement("a", { className: [
  8037. 'fc-col-header-cell-cushion',
  8038. props.isSticky ? 'fc-sticky' : '',
  8039. ].join(' '), ref: innerElRef }, innerContent)))); }));
  8040. };
  8041. return TableDowCell;
  8042. }(BaseComponent));
  8043. var NowTimer = /** @class */ (function (_super) {
  8044. __extends(NowTimer, _super);
  8045. function NowTimer(props, context) {
  8046. var _this = _super.call(this, props, context) || this;
  8047. _this.initialNowDate = getNow(context.options.now, context.dateEnv);
  8048. _this.initialNowQueriedMs = new Date().valueOf();
  8049. _this.state = _this.computeTiming().currentState;
  8050. return _this;
  8051. }
  8052. NowTimer.prototype.render = function () {
  8053. var _a = this, props = _a.props, state = _a.state;
  8054. return props.children(state.nowDate, state.todayRange);
  8055. };
  8056. NowTimer.prototype.componentDidMount = function () {
  8057. this.setTimeout();
  8058. };
  8059. NowTimer.prototype.componentDidUpdate = function (prevProps) {
  8060. if (prevProps.unit !== this.props.unit) {
  8061. this.clearTimeout();
  8062. this.setTimeout();
  8063. }
  8064. };
  8065. NowTimer.prototype.componentWillUnmount = function () {
  8066. this.clearTimeout();
  8067. };
  8068. NowTimer.prototype.computeTiming = function () {
  8069. var _a = this, props = _a.props, context = _a.context;
  8070. var unroundedNow = addMs(this.initialNowDate, new Date().valueOf() - this.initialNowQueriedMs);
  8071. var currentUnitStart = context.dateEnv.startOf(unroundedNow, props.unit);
  8072. var nextUnitStart = context.dateEnv.add(currentUnitStart, createDuration(1, props.unit));
  8073. var waitMs = nextUnitStart.valueOf() - unroundedNow.valueOf();
  8074. // there is a max setTimeout ms value (https://stackoverflow.com/a/3468650/96342)
  8075. // ensure no longer than a day
  8076. waitMs = Math.min(1000 * 60 * 60 * 24, waitMs);
  8077. return {
  8078. currentState: { nowDate: currentUnitStart, todayRange: buildDayRange(currentUnitStart) },
  8079. nextState: { nowDate: nextUnitStart, todayRange: buildDayRange(nextUnitStart) },
  8080. waitMs: waitMs,
  8081. };
  8082. };
  8083. NowTimer.prototype.setTimeout = function () {
  8084. var _this = this;
  8085. var _a = this.computeTiming(), nextState = _a.nextState, waitMs = _a.waitMs;
  8086. this.timeoutId = setTimeout(function () {
  8087. _this.setState(nextState, function () {
  8088. _this.setTimeout();
  8089. });
  8090. }, waitMs);
  8091. };
  8092. NowTimer.prototype.clearTimeout = function () {
  8093. if (this.timeoutId) {
  8094. clearTimeout(this.timeoutId);
  8095. }
  8096. };
  8097. NowTimer.contextType = ViewContextType;
  8098. return NowTimer;
  8099. }(Component));
  8100. function buildDayRange(date) {
  8101. var start = startOfDay(date);
  8102. var end = addDays(start, 1);
  8103. return { start: start, end: end };
  8104. }
  8105. var DayHeader = /** @class */ (function (_super) {
  8106. __extends(DayHeader, _super);
  8107. function DayHeader() {
  8108. var _this = _super !== null && _super.apply(this, arguments) || this;
  8109. _this.createDayHeaderFormatter = memoize(createDayHeaderFormatter);
  8110. return _this;
  8111. }
  8112. DayHeader.prototype.render = function () {
  8113. var context = this.context;
  8114. var _a = this.props, dates = _a.dates, dateProfile = _a.dateProfile, datesRepDistinctDays = _a.datesRepDistinctDays, renderIntro = _a.renderIntro;
  8115. var dayHeaderFormat = this.createDayHeaderFormatter(context.options.dayHeaderFormat, datesRepDistinctDays, dates.length);
  8116. return (createElement(NowTimer, { unit: "day" }, function (nowDate, todayRange) { return (createElement("tr", null,
  8117. renderIntro && renderIntro('day'),
  8118. dates.map(function (date) { return (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 }))); }))); }));
  8119. };
  8120. return DayHeader;
  8121. }(BaseComponent));
  8122. function createDayHeaderFormatter(explicitFormat, datesRepDistinctDays, dateCnt) {
  8123. return explicitFormat || computeFallbackHeaderFormat(datesRepDistinctDays, dateCnt);
  8124. }
  8125. var DaySeriesModel = /** @class */ (function () {
  8126. function DaySeriesModel(range, dateProfileGenerator) {
  8127. var date = range.start;
  8128. var end = range.end;
  8129. var indices = [];
  8130. var dates = [];
  8131. var dayIndex = -1;
  8132. while (date < end) { // loop each day from start to end
  8133. if (dateProfileGenerator.isHiddenDay(date)) {
  8134. indices.push(dayIndex + 0.5); // mark that it's between indices
  8135. }
  8136. else {
  8137. dayIndex += 1;
  8138. indices.push(dayIndex);
  8139. dates.push(date);
  8140. }
  8141. date = addDays(date, 1);
  8142. }
  8143. this.dates = dates;
  8144. this.indices = indices;
  8145. this.cnt = dates.length;
  8146. }
  8147. DaySeriesModel.prototype.sliceRange = function (range) {
  8148. var firstIndex = this.getDateDayIndex(range.start); // inclusive first index
  8149. var lastIndex = this.getDateDayIndex(addDays(range.end, -1)); // inclusive last index
  8150. var clippedFirstIndex = Math.max(0, firstIndex);
  8151. var clippedLastIndex = Math.min(this.cnt - 1, lastIndex);
  8152. // deal with in-between indices
  8153. clippedFirstIndex = Math.ceil(clippedFirstIndex); // in-between starts round to next cell
  8154. clippedLastIndex = Math.floor(clippedLastIndex); // in-between ends round to prev cell
  8155. if (clippedFirstIndex <= clippedLastIndex) {
  8156. return {
  8157. firstIndex: clippedFirstIndex,
  8158. lastIndex: clippedLastIndex,
  8159. isStart: firstIndex === clippedFirstIndex,
  8160. isEnd: lastIndex === clippedLastIndex,
  8161. };
  8162. }
  8163. return null;
  8164. };
  8165. // Given a date, returns its chronolocial cell-index from the first cell of the grid.
  8166. // If the date lies between cells (because of hiddenDays), returns a floating-point value between offsets.
  8167. // If before the first offset, returns a negative number.
  8168. // If after the last offset, returns an offset past the last cell offset.
  8169. // Only works for *start* dates of cells. Will not work for exclusive end dates for cells.
  8170. DaySeriesModel.prototype.getDateDayIndex = function (date) {
  8171. var indices = this.indices;
  8172. var dayOffset = Math.floor(diffDays(this.dates[0], date));
  8173. if (dayOffset < 0) {
  8174. return indices[0] - 1;
  8175. }
  8176. if (dayOffset >= indices.length) {
  8177. return indices[indices.length - 1] + 1;
  8178. }
  8179. return indices[dayOffset];
  8180. };
  8181. return DaySeriesModel;
  8182. }());
  8183. var DayTableModel = /** @class */ (function () {
  8184. function DayTableModel(daySeries, breakOnWeeks) {
  8185. var dates = daySeries.dates;
  8186. var daysPerRow;
  8187. var firstDay;
  8188. var rowCnt;
  8189. if (breakOnWeeks) {
  8190. // count columns until the day-of-week repeats
  8191. firstDay = dates[0].getUTCDay();
  8192. for (daysPerRow = 1; daysPerRow < dates.length; daysPerRow += 1) {
  8193. if (dates[daysPerRow].getUTCDay() === firstDay) {
  8194. break;
  8195. }
  8196. }
  8197. rowCnt = Math.ceil(dates.length / daysPerRow);
  8198. }
  8199. else {
  8200. rowCnt = 1;
  8201. daysPerRow = dates.length;
  8202. }
  8203. this.rowCnt = rowCnt;
  8204. this.colCnt = daysPerRow;
  8205. this.daySeries = daySeries;
  8206. this.cells = this.buildCells();
  8207. this.headerDates = this.buildHeaderDates();
  8208. }
  8209. DayTableModel.prototype.buildCells = function () {
  8210. var rows = [];
  8211. for (var row = 0; row < this.rowCnt; row += 1) {
  8212. var cells = [];
  8213. for (var col = 0; col < this.colCnt; col += 1) {
  8214. cells.push(this.buildCell(row, col));
  8215. }
  8216. rows.push(cells);
  8217. }
  8218. return rows;
  8219. };
  8220. DayTableModel.prototype.buildCell = function (row, col) {
  8221. var date = this.daySeries.dates[row * this.colCnt + col];
  8222. return {
  8223. key: date.toISOString(),
  8224. date: date,
  8225. };
  8226. };
  8227. DayTableModel.prototype.buildHeaderDates = function () {
  8228. var dates = [];
  8229. for (var col = 0; col < this.colCnt; col += 1) {
  8230. dates.push(this.cells[0][col].date);
  8231. }
  8232. return dates;
  8233. };
  8234. DayTableModel.prototype.sliceRange = function (range) {
  8235. var colCnt = this.colCnt;
  8236. var seriesSeg = this.daySeries.sliceRange(range);
  8237. var segs = [];
  8238. if (seriesSeg) {
  8239. var firstIndex = seriesSeg.firstIndex, lastIndex = seriesSeg.lastIndex;
  8240. var index = firstIndex;
  8241. while (index <= lastIndex) {
  8242. var row = Math.floor(index / colCnt);
  8243. var nextIndex = Math.min((row + 1) * colCnt, lastIndex + 1);
  8244. segs.push({
  8245. row: row,
  8246. firstCol: index % colCnt,
  8247. lastCol: (nextIndex - 1) % colCnt,
  8248. isStart: seriesSeg.isStart && index === firstIndex,
  8249. isEnd: seriesSeg.isEnd && (nextIndex - 1) === lastIndex,
  8250. });
  8251. index = nextIndex;
  8252. }
  8253. }
  8254. return segs;
  8255. };
  8256. return DayTableModel;
  8257. }());
  8258. var Slicer = /** @class */ (function () {
  8259. function Slicer() {
  8260. this.sliceBusinessHours = memoize(this._sliceBusinessHours);
  8261. this.sliceDateSelection = memoize(this._sliceDateSpan);
  8262. this.sliceEventStore = memoize(this._sliceEventStore);
  8263. this.sliceEventDrag = memoize(this._sliceInteraction);
  8264. this.sliceEventResize = memoize(this._sliceInteraction);
  8265. this.forceDayIfListItem = false; // hack
  8266. }
  8267. Slicer.prototype.sliceProps = function (props, dateProfile, nextDayThreshold, context) {
  8268. var extraArgs = [];
  8269. for (var _i = 4; _i < arguments.length; _i++) {
  8270. extraArgs[_i - 4] = arguments[_i];
  8271. }
  8272. var eventUiBases = props.eventUiBases;
  8273. var eventSegs = this.sliceEventStore.apply(this, __spreadArray([props.eventStore, eventUiBases, dateProfile, nextDayThreshold], extraArgs));
  8274. return {
  8275. dateSelectionSegs: this.sliceDateSelection.apply(this, __spreadArray([props.dateSelection, eventUiBases, context], extraArgs)),
  8276. businessHourSegs: this.sliceBusinessHours.apply(this, __spreadArray([props.businessHours, dateProfile, nextDayThreshold, context], extraArgs)),
  8277. fgEventSegs: eventSegs.fg,
  8278. bgEventSegs: eventSegs.bg,
  8279. eventDrag: this.sliceEventDrag.apply(this, __spreadArray([props.eventDrag, eventUiBases, dateProfile, nextDayThreshold], extraArgs)),
  8280. eventResize: this.sliceEventResize.apply(this, __spreadArray([props.eventResize, eventUiBases, dateProfile, nextDayThreshold], extraArgs)),
  8281. eventSelection: props.eventSelection,
  8282. }; // TODO: give interactionSegs?
  8283. };
  8284. Slicer.prototype.sliceNowDate = function (// does not memoize
  8285. date, context) {
  8286. var extraArgs = [];
  8287. for (var _i = 2; _i < arguments.length; _i++) {
  8288. extraArgs[_i - 2] = arguments[_i];
  8289. }
  8290. return this._sliceDateSpan.apply(this, __spreadArray([{ range: { start: date, end: addMs(date, 1) }, allDay: false },
  8291. {},
  8292. context], extraArgs));
  8293. };
  8294. Slicer.prototype._sliceBusinessHours = function (businessHours, dateProfile, nextDayThreshold, context) {
  8295. var extraArgs = [];
  8296. for (var _i = 4; _i < arguments.length; _i++) {
  8297. extraArgs[_i - 4] = arguments[_i];
  8298. }
  8299. if (!businessHours) {
  8300. return [];
  8301. }
  8302. return this._sliceEventStore.apply(this, __spreadArray([expandRecurring(businessHours, computeActiveRange(dateProfile, Boolean(nextDayThreshold)), context),
  8303. {},
  8304. dateProfile,
  8305. nextDayThreshold], extraArgs)).bg;
  8306. };
  8307. Slicer.prototype._sliceEventStore = function (eventStore, eventUiBases, dateProfile, nextDayThreshold) {
  8308. var extraArgs = [];
  8309. for (var _i = 4; _i < arguments.length; _i++) {
  8310. extraArgs[_i - 4] = arguments[_i];
  8311. }
  8312. if (eventStore) {
  8313. var rangeRes = sliceEventStore(eventStore, eventUiBases, computeActiveRange(dateProfile, Boolean(nextDayThreshold)), nextDayThreshold);
  8314. return {
  8315. bg: this.sliceEventRanges(rangeRes.bg, extraArgs),
  8316. fg: this.sliceEventRanges(rangeRes.fg, extraArgs),
  8317. };
  8318. }
  8319. return { bg: [], fg: [] };
  8320. };
  8321. Slicer.prototype._sliceInteraction = function (interaction, eventUiBases, dateProfile, nextDayThreshold) {
  8322. var extraArgs = [];
  8323. for (var _i = 4; _i < arguments.length; _i++) {
  8324. extraArgs[_i - 4] = arguments[_i];
  8325. }
  8326. if (!interaction) {
  8327. return null;
  8328. }
  8329. var rangeRes = sliceEventStore(interaction.mutatedEvents, eventUiBases, computeActiveRange(dateProfile, Boolean(nextDayThreshold)), nextDayThreshold);
  8330. return {
  8331. segs: this.sliceEventRanges(rangeRes.fg, extraArgs),
  8332. affectedInstances: interaction.affectedEvents.instances,
  8333. isEvent: interaction.isEvent,
  8334. };
  8335. };
  8336. Slicer.prototype._sliceDateSpan = function (dateSpan, eventUiBases, context) {
  8337. var extraArgs = [];
  8338. for (var _i = 3; _i < arguments.length; _i++) {
  8339. extraArgs[_i - 3] = arguments[_i];
  8340. }
  8341. if (!dateSpan) {
  8342. return [];
  8343. }
  8344. var eventRange = fabricateEventRange(dateSpan, eventUiBases, context);
  8345. var segs = this.sliceRange.apply(this, __spreadArray([dateSpan.range], extraArgs));
  8346. for (var _a = 0, segs_1 = segs; _a < segs_1.length; _a++) {
  8347. var seg = segs_1[_a];
  8348. seg.eventRange = eventRange;
  8349. }
  8350. return segs;
  8351. };
  8352. /*
  8353. "complete" seg means it has component and eventRange
  8354. */
  8355. Slicer.prototype.sliceEventRanges = function (eventRanges, extraArgs) {
  8356. var segs = [];
  8357. for (var _i = 0, eventRanges_1 = eventRanges; _i < eventRanges_1.length; _i++) {
  8358. var eventRange = eventRanges_1[_i];
  8359. segs.push.apply(segs, this.sliceEventRange(eventRange, extraArgs));
  8360. }
  8361. return segs;
  8362. };
  8363. /*
  8364. "complete" seg means it has component and eventRange
  8365. */
  8366. Slicer.prototype.sliceEventRange = function (eventRange, extraArgs) {
  8367. var dateRange = eventRange.range;
  8368. // hack to make multi-day events that are being force-displayed as list-items to take up only one day
  8369. if (this.forceDayIfListItem && eventRange.ui.display === 'list-item') {
  8370. dateRange = {
  8371. start: dateRange.start,
  8372. end: addDays(dateRange.start, 1),
  8373. };
  8374. }
  8375. var segs = this.sliceRange.apply(this, __spreadArray([dateRange], extraArgs));
  8376. for (var _i = 0, segs_2 = segs; _i < segs_2.length; _i++) {
  8377. var seg = segs_2[_i];
  8378. seg.eventRange = eventRange;
  8379. seg.isStart = eventRange.isStart && seg.isStart;
  8380. seg.isEnd = eventRange.isEnd && seg.isEnd;
  8381. }
  8382. return segs;
  8383. };
  8384. return Slicer;
  8385. }());
  8386. /*
  8387. for incorporating slotMinTime/slotMaxTime if appropriate
  8388. TODO: should be part of DateProfile!
  8389. TimelineDateProfile already does this btw
  8390. */
  8391. function computeActiveRange(dateProfile, isComponentAllDay) {
  8392. var range = dateProfile.activeRange;
  8393. if (isComponentAllDay) {
  8394. return range;
  8395. }
  8396. return {
  8397. start: addMs(range.start, dateProfile.slotMinTime.milliseconds),
  8398. end: addMs(range.end, dateProfile.slotMaxTime.milliseconds - 864e5), // 864e5 = ms in a day
  8399. };
  8400. }
  8401. // high-level segmenting-aware tester functions
  8402. // ------------------------------------------------------------------------------------------------------------------------
  8403. function isInteractionValid(interaction, dateProfile, context) {
  8404. var instances = interaction.mutatedEvents.instances;
  8405. for (var instanceId in instances) {
  8406. if (!rangeContainsRange(dateProfile.validRange, instances[instanceId].range)) {
  8407. return false;
  8408. }
  8409. }
  8410. return isNewPropsValid({ eventDrag: interaction }, context); // HACK: the eventDrag props is used for ALL interactions
  8411. }
  8412. function isDateSelectionValid(dateSelection, dateProfile, context) {
  8413. if (!rangeContainsRange(dateProfile.validRange, dateSelection.range)) {
  8414. return false;
  8415. }
  8416. return isNewPropsValid({ dateSelection: dateSelection }, context);
  8417. }
  8418. function isNewPropsValid(newProps, context) {
  8419. var calendarState = context.getCurrentData();
  8420. var props = __assign({ businessHours: calendarState.businessHours, dateSelection: '', eventStore: calendarState.eventStore, eventUiBases: calendarState.eventUiBases, eventSelection: '', eventDrag: null, eventResize: null }, newProps);
  8421. return (context.pluginHooks.isPropsValid || isPropsValid)(props, context);
  8422. }
  8423. function isPropsValid(state, context, dateSpanMeta, filterConfig) {
  8424. if (dateSpanMeta === void 0) { dateSpanMeta = {}; }
  8425. if (state.eventDrag && !isInteractionPropsValid(state, context, dateSpanMeta, filterConfig)) {
  8426. return false;
  8427. }
  8428. if (state.dateSelection && !isDateSelectionPropsValid(state, context, dateSpanMeta, filterConfig)) {
  8429. return false;
  8430. }
  8431. return true;
  8432. }
  8433. // Moving Event Validation
  8434. // ------------------------------------------------------------------------------------------------------------------------
  8435. function isInteractionPropsValid(state, context, dateSpanMeta, filterConfig) {
  8436. var currentState = context.getCurrentData();
  8437. var interaction = state.eventDrag; // HACK: the eventDrag props is used for ALL interactions
  8438. var subjectEventStore = interaction.mutatedEvents;
  8439. var subjectDefs = subjectEventStore.defs;
  8440. var subjectInstances = subjectEventStore.instances;
  8441. var subjectConfigs = compileEventUis(subjectDefs, interaction.isEvent ?
  8442. state.eventUiBases :
  8443. { '': currentState.selectionConfig });
  8444. if (filterConfig) {
  8445. subjectConfigs = mapHash(subjectConfigs, filterConfig);
  8446. }
  8447. // exclude the subject events. TODO: exclude defs too?
  8448. var otherEventStore = excludeInstances(state.eventStore, interaction.affectedEvents.instances);
  8449. var otherDefs = otherEventStore.defs;
  8450. var otherInstances = otherEventStore.instances;
  8451. var otherConfigs = compileEventUis(otherDefs, state.eventUiBases);
  8452. for (var subjectInstanceId in subjectInstances) {
  8453. var subjectInstance = subjectInstances[subjectInstanceId];
  8454. var subjectRange = subjectInstance.range;
  8455. var subjectConfig = subjectConfigs[subjectInstance.defId];
  8456. var subjectDef = subjectDefs[subjectInstance.defId];
  8457. // constraint
  8458. if (!allConstraintsPass(subjectConfig.constraints, subjectRange, otherEventStore, state.businessHours, context)) {
  8459. return false;
  8460. }
  8461. // overlap
  8462. var eventOverlap = context.options.eventOverlap;
  8463. var eventOverlapFunc = typeof eventOverlap === 'function' ? eventOverlap : null;
  8464. for (var otherInstanceId in otherInstances) {
  8465. var otherInstance = otherInstances[otherInstanceId];
  8466. // intersect! evaluate
  8467. if (rangesIntersect(subjectRange, otherInstance.range)) {
  8468. var otherOverlap = otherConfigs[otherInstance.defId].overlap;
  8469. // consider the other event's overlap. only do this if the subject event is a "real" event
  8470. if (otherOverlap === false && interaction.isEvent) {
  8471. return false;
  8472. }
  8473. if (subjectConfig.overlap === false) {
  8474. return false;
  8475. }
  8476. if (eventOverlapFunc && !eventOverlapFunc(new EventApi(context, otherDefs[otherInstance.defId], otherInstance), // still event
  8477. new EventApi(context, subjectDef, subjectInstance))) {
  8478. return false;
  8479. }
  8480. }
  8481. }
  8482. // allow (a function)
  8483. var calendarEventStore = currentState.eventStore; // need global-to-calendar, not local to component (splittable)state
  8484. for (var _i = 0, _a = subjectConfig.allows; _i < _a.length; _i++) {
  8485. var subjectAllow = _a[_i];
  8486. var subjectDateSpan = __assign(__assign({}, dateSpanMeta), { range: subjectInstance.range, allDay: subjectDef.allDay });
  8487. var origDef = calendarEventStore.defs[subjectDef.defId];
  8488. var origInstance = calendarEventStore.instances[subjectInstanceId];
  8489. var eventApi = void 0;
  8490. if (origDef) { // was previously in the calendar
  8491. eventApi = new EventApi(context, origDef, origInstance);
  8492. }
  8493. else { // was an external event
  8494. eventApi = new EventApi(context, subjectDef); // no instance, because had no dates
  8495. }
  8496. if (!subjectAllow(buildDateSpanApiWithContext(subjectDateSpan, context), eventApi)) {
  8497. return false;
  8498. }
  8499. }
  8500. }
  8501. return true;
  8502. }
  8503. // Date Selection Validation
  8504. // ------------------------------------------------------------------------------------------------------------------------
  8505. function isDateSelectionPropsValid(state, context, dateSpanMeta, filterConfig) {
  8506. var relevantEventStore = state.eventStore;
  8507. var relevantDefs = relevantEventStore.defs;
  8508. var relevantInstances = relevantEventStore.instances;
  8509. var selection = state.dateSelection;
  8510. var selectionRange = selection.range;
  8511. var selectionConfig = context.getCurrentData().selectionConfig;
  8512. if (filterConfig) {
  8513. selectionConfig = filterConfig(selectionConfig);
  8514. }
  8515. // constraint
  8516. if (!allConstraintsPass(selectionConfig.constraints, selectionRange, relevantEventStore, state.businessHours, context)) {
  8517. return false;
  8518. }
  8519. // overlap
  8520. var selectOverlap = context.options.selectOverlap;
  8521. var selectOverlapFunc = typeof selectOverlap === 'function' ? selectOverlap : null;
  8522. for (var relevantInstanceId in relevantInstances) {
  8523. var relevantInstance = relevantInstances[relevantInstanceId];
  8524. // intersect! evaluate
  8525. if (rangesIntersect(selectionRange, relevantInstance.range)) {
  8526. if (selectionConfig.overlap === false) {
  8527. return false;
  8528. }
  8529. if (selectOverlapFunc && !selectOverlapFunc(new EventApi(context, relevantDefs[relevantInstance.defId], relevantInstance), null)) {
  8530. return false;
  8531. }
  8532. }
  8533. }
  8534. // allow (a function)
  8535. for (var _i = 0, _a = selectionConfig.allows; _i < _a.length; _i++) {
  8536. var selectionAllow = _a[_i];
  8537. var fullDateSpan = __assign(__assign({}, dateSpanMeta), selection);
  8538. if (!selectionAllow(buildDateSpanApiWithContext(fullDateSpan, context), null)) {
  8539. return false;
  8540. }
  8541. }
  8542. return true;
  8543. }
  8544. // Constraint Utils
  8545. // ------------------------------------------------------------------------------------------------------------------------
  8546. function allConstraintsPass(constraints, subjectRange, otherEventStore, businessHoursUnexpanded, context) {
  8547. for (var _i = 0, constraints_1 = constraints; _i < constraints_1.length; _i++) {
  8548. var constraint = constraints_1[_i];
  8549. if (!anyRangesContainRange(constraintToRanges(constraint, subjectRange, otherEventStore, businessHoursUnexpanded, context), subjectRange)) {
  8550. return false;
  8551. }
  8552. }
  8553. return true;
  8554. }
  8555. function constraintToRanges(constraint, subjectRange, // for expanding a recurring constraint, or expanding business hours
  8556. otherEventStore, // for if constraint is an even group ID
  8557. businessHoursUnexpanded, // for if constraint is 'businessHours'
  8558. context) {
  8559. if (constraint === 'businessHours') {
  8560. return eventStoreToRanges(expandRecurring(businessHoursUnexpanded, subjectRange, context));
  8561. }
  8562. if (typeof constraint === 'string') { // an group ID
  8563. return eventStoreToRanges(filterEventStoreDefs(otherEventStore, function (eventDef) { return eventDef.groupId === constraint; }));
  8564. }
  8565. if (typeof constraint === 'object' && constraint) { // non-null object
  8566. return eventStoreToRanges(expandRecurring(constraint, subjectRange, context));
  8567. }
  8568. return []; // if it's false
  8569. }
  8570. // TODO: move to event-store file?
  8571. function eventStoreToRanges(eventStore) {
  8572. var instances = eventStore.instances;
  8573. var ranges = [];
  8574. for (var instanceId in instances) {
  8575. ranges.push(instances[instanceId].range);
  8576. }
  8577. return ranges;
  8578. }
  8579. // TODO: move to geom file?
  8580. function anyRangesContainRange(outerRanges, innerRange) {
  8581. for (var _i = 0, outerRanges_1 = outerRanges; _i < outerRanges_1.length; _i++) {
  8582. var outerRange = outerRanges_1[_i];
  8583. if (rangeContainsRange(outerRange, innerRange)) {
  8584. return true;
  8585. }
  8586. }
  8587. return false;
  8588. }
  8589. var VISIBLE_HIDDEN_RE = /^(visible|hidden)$/;
  8590. var Scroller = /** @class */ (function (_super) {
  8591. __extends(Scroller, _super);
  8592. function Scroller() {
  8593. var _this = _super !== null && _super.apply(this, arguments) || this;
  8594. _this.handleEl = function (el) {
  8595. _this.el = el;
  8596. setRef(_this.props.elRef, el);
  8597. };
  8598. return _this;
  8599. }
  8600. Scroller.prototype.render = function () {
  8601. var props = this.props;
  8602. var liquid = props.liquid, liquidIsAbsolute = props.liquidIsAbsolute;
  8603. var isAbsolute = liquid && liquidIsAbsolute;
  8604. var className = ['fc-scroller'];
  8605. if (liquid) {
  8606. if (liquidIsAbsolute) {
  8607. className.push('fc-scroller-liquid-absolute');
  8608. }
  8609. else {
  8610. className.push('fc-scroller-liquid');
  8611. }
  8612. }
  8613. return (createElement("div", { ref: this.handleEl, className: className.join(' '), style: {
  8614. overflowX: props.overflowX,
  8615. overflowY: props.overflowY,
  8616. left: (isAbsolute && -(props.overcomeLeft || 0)) || '',
  8617. right: (isAbsolute && -(props.overcomeRight || 0)) || '',
  8618. bottom: (isAbsolute && -(props.overcomeBottom || 0)) || '',
  8619. marginLeft: (!isAbsolute && -(props.overcomeLeft || 0)) || '',
  8620. marginRight: (!isAbsolute && -(props.overcomeRight || 0)) || '',
  8621. marginBottom: (!isAbsolute && -(props.overcomeBottom || 0)) || '',
  8622. maxHeight: props.maxHeight || '',
  8623. } }, props.children));
  8624. };
  8625. Scroller.prototype.needsXScrolling = function () {
  8626. if (VISIBLE_HIDDEN_RE.test(this.props.overflowX)) {
  8627. return false;
  8628. }
  8629. // testing scrollWidth>clientWidth is unreliable cross-browser when pixel heights aren't integers.
  8630. // much more reliable to see if children are taller than the scroller, even tho doesn't account for
  8631. // inner-child margins and absolute positioning
  8632. var el = this.el;
  8633. var realClientWidth = this.el.getBoundingClientRect().width - this.getYScrollbarWidth();
  8634. var children = el.children;
  8635. for (var i = 0; i < children.length; i += 1) {
  8636. var childEl = children[i];
  8637. if (childEl.getBoundingClientRect().width > realClientWidth) {
  8638. return true;
  8639. }
  8640. }
  8641. return false;
  8642. };
  8643. Scroller.prototype.needsYScrolling = function () {
  8644. if (VISIBLE_HIDDEN_RE.test(this.props.overflowY)) {
  8645. return false;
  8646. }
  8647. // testing scrollHeight>clientHeight is unreliable cross-browser when pixel heights aren't integers.
  8648. // much more reliable to see if children are taller than the scroller, even tho doesn't account for
  8649. // inner-child margins and absolute positioning
  8650. var el = this.el;
  8651. var realClientHeight = this.el.getBoundingClientRect().height - this.getXScrollbarWidth();
  8652. var children = el.children;
  8653. for (var i = 0; i < children.length; i += 1) {
  8654. var childEl = children[i];
  8655. if (childEl.getBoundingClientRect().height > realClientHeight) {
  8656. return true;
  8657. }
  8658. }
  8659. return false;
  8660. };
  8661. Scroller.prototype.getXScrollbarWidth = function () {
  8662. if (VISIBLE_HIDDEN_RE.test(this.props.overflowX)) {
  8663. return 0;
  8664. }
  8665. return this.el.offsetHeight - this.el.clientHeight; // only works because we guarantee no borders. TODO: add to CSS with important?
  8666. };
  8667. Scroller.prototype.getYScrollbarWidth = function () {
  8668. if (VISIBLE_HIDDEN_RE.test(this.props.overflowY)) {
  8669. return 0;
  8670. }
  8671. return this.el.offsetWidth - this.el.clientWidth; // only works because we guarantee no borders. TODO: add to CSS with important?
  8672. };
  8673. return Scroller;
  8674. }(BaseComponent));
  8675. /*
  8676. TODO: somehow infer OtherArgs from masterCallback?
  8677. TODO: infer RefType from masterCallback if provided
  8678. */
  8679. var RefMap = /** @class */ (function () {
  8680. function RefMap(masterCallback) {
  8681. var _this = this;
  8682. this.masterCallback = masterCallback;
  8683. this.currentMap = {};
  8684. this.depths = {};
  8685. this.callbackMap = {};
  8686. this.handleValue = function (val, key) {
  8687. var _a = _this, depths = _a.depths, currentMap = _a.currentMap;
  8688. var removed = false;
  8689. var added = false;
  8690. if (val !== null) {
  8691. // for bug... ACTUALLY: can probably do away with this now that callers don't share numeric indices anymore
  8692. removed = (key in currentMap);
  8693. currentMap[key] = val;
  8694. depths[key] = (depths[key] || 0) + 1;
  8695. added = true;
  8696. }
  8697. else {
  8698. depths[key] -= 1;
  8699. if (!depths[key]) {
  8700. delete currentMap[key];
  8701. delete _this.callbackMap[key];
  8702. removed = true;
  8703. }
  8704. }
  8705. if (_this.masterCallback) {
  8706. if (removed) {
  8707. _this.masterCallback(null, String(key));
  8708. }
  8709. if (added) {
  8710. _this.masterCallback(val, String(key));
  8711. }
  8712. }
  8713. };
  8714. }
  8715. RefMap.prototype.createRef = function (key) {
  8716. var _this = this;
  8717. var refCallback = this.callbackMap[key];
  8718. if (!refCallback) {
  8719. refCallback = this.callbackMap[key] = function (val) {
  8720. _this.handleValue(val, String(key));
  8721. };
  8722. }
  8723. return refCallback;
  8724. };
  8725. // TODO: check callers that don't care about order. should use getAll instead
  8726. // NOTE: this method has become less valuable now that we are encouraged to map order by some other index
  8727. // TODO: provide ONE array-export function, buildArray, which fails on non-numeric indexes. caller can manipulate and "collect"
  8728. RefMap.prototype.collect = function (startIndex, endIndex, step) {
  8729. return collectFromHash(this.currentMap, startIndex, endIndex, step);
  8730. };
  8731. RefMap.prototype.getAll = function () {
  8732. return hashValuesToArray(this.currentMap);
  8733. };
  8734. return RefMap;
  8735. }());
  8736. function computeShrinkWidth(chunkEls) {
  8737. var shrinkCells = findElements(chunkEls, '.fc-scrollgrid-shrink');
  8738. var largestWidth = 0;
  8739. for (var _i = 0, shrinkCells_1 = shrinkCells; _i < shrinkCells_1.length; _i++) {
  8740. var shrinkCell = shrinkCells_1[_i];
  8741. largestWidth = Math.max(largestWidth, computeSmallestCellWidth(shrinkCell));
  8742. }
  8743. return Math.ceil(largestWidth); // <table> elements work best with integers. round up to ensure contents fits
  8744. }
  8745. function getSectionHasLiquidHeight(props, sectionConfig) {
  8746. return props.liquid && sectionConfig.liquid; // does the section do liquid-height? (need to have whole scrollgrid liquid-height as well)
  8747. }
  8748. function getAllowYScrolling(props, sectionConfig) {
  8749. return sectionConfig.maxHeight != null || // if its possible for the height to max out, we might need scrollbars
  8750. getSectionHasLiquidHeight(props, sectionConfig); // if the section is liquid height, it might condense enough to require scrollbars
  8751. }
  8752. // TODO: ONLY use `arg`. force out internal function to use same API
  8753. function renderChunkContent(sectionConfig, chunkConfig, arg) {
  8754. var expandRows = arg.expandRows;
  8755. var content = typeof chunkConfig.content === 'function' ?
  8756. chunkConfig.content(arg) :
  8757. createElement('table', {
  8758. className: [
  8759. chunkConfig.tableClassName,
  8760. sectionConfig.syncRowHeights ? 'fc-scrollgrid-sync-table' : '',
  8761. ].join(' '),
  8762. style: {
  8763. minWidth: arg.tableMinWidth,
  8764. width: arg.clientWidth,
  8765. height: expandRows ? arg.clientHeight : '', // css `height` on a <table> serves as a min-height
  8766. },
  8767. }, arg.tableColGroupNode, createElement('tbody', {}, typeof chunkConfig.rowContent === 'function' ? chunkConfig.rowContent(arg) : chunkConfig.rowContent));
  8768. return content;
  8769. }
  8770. function isColPropsEqual(cols0, cols1) {
  8771. return isArraysEqual(cols0, cols1, isPropsEqual);
  8772. }
  8773. function renderMicroColGroup(cols, shrinkWidth) {
  8774. var colNodes = [];
  8775. /*
  8776. for ColProps with spans, it would have been great to make a single <col span="">
  8777. HOWEVER, Chrome was getting messing up distributing the width to <td>/<th> elements with colspans.
  8778. SOLUTION: making individual <col> elements makes Chrome behave.
  8779. */
  8780. for (var _i = 0, cols_1 = cols; _i < cols_1.length; _i++) {
  8781. var colProps = cols_1[_i];
  8782. var span = colProps.span || 1;
  8783. for (var i = 0; i < span; i += 1) {
  8784. colNodes.push(createElement("col", { style: {
  8785. width: colProps.width === 'shrink' ? sanitizeShrinkWidth(shrinkWidth) : (colProps.width || ''),
  8786. minWidth: colProps.minWidth || '',
  8787. } }));
  8788. }
  8789. }
  8790. return createElement.apply(void 0, __spreadArray(['colgroup', {}], colNodes));
  8791. }
  8792. function sanitizeShrinkWidth(shrinkWidth) {
  8793. /* why 4? if we do 0, it will kill any border, which are needed for computeSmallestCellWidth
  8794. 4 accounts for 2 2-pixel borders. TODO: better solution? */
  8795. return shrinkWidth == null ? 4 : shrinkWidth;
  8796. }
  8797. function hasShrinkWidth(cols) {
  8798. for (var _i = 0, cols_2 = cols; _i < cols_2.length; _i++) {
  8799. var col = cols_2[_i];
  8800. if (col.width === 'shrink') {
  8801. return true;
  8802. }
  8803. }
  8804. return false;
  8805. }
  8806. function getScrollGridClassNames(liquid, context) {
  8807. var classNames = [
  8808. 'fc-scrollgrid',
  8809. context.theme.getClass('table'),
  8810. ];
  8811. if (liquid) {
  8812. classNames.push('fc-scrollgrid-liquid');
  8813. }
  8814. return classNames;
  8815. }
  8816. function getSectionClassNames(sectionConfig, wholeTableVGrow) {
  8817. var classNames = [
  8818. 'fc-scrollgrid-section',
  8819. "fc-scrollgrid-section-" + sectionConfig.type,
  8820. sectionConfig.className, // used?
  8821. ];
  8822. if (wholeTableVGrow && sectionConfig.liquid && sectionConfig.maxHeight == null) {
  8823. classNames.push('fc-scrollgrid-section-liquid');
  8824. }
  8825. if (sectionConfig.isSticky) {
  8826. classNames.push('fc-scrollgrid-section-sticky');
  8827. }
  8828. return classNames;
  8829. }
  8830. function renderScrollShim(arg) {
  8831. return (createElement("div", { className: "fc-scrollgrid-sticky-shim", style: {
  8832. width: arg.clientWidth,
  8833. minWidth: arg.tableMinWidth,
  8834. } }));
  8835. }
  8836. function getStickyHeaderDates(options) {
  8837. var stickyHeaderDates = options.stickyHeaderDates;
  8838. if (stickyHeaderDates == null || stickyHeaderDates === 'auto') {
  8839. stickyHeaderDates = options.height === 'auto' || options.viewHeight === 'auto';
  8840. }
  8841. return stickyHeaderDates;
  8842. }
  8843. function getStickyFooterScrollbar(options) {
  8844. var stickyFooterScrollbar = options.stickyFooterScrollbar;
  8845. if (stickyFooterScrollbar == null || stickyFooterScrollbar === 'auto') {
  8846. stickyFooterScrollbar = options.height === 'auto' || options.viewHeight === 'auto';
  8847. }
  8848. return stickyFooterScrollbar;
  8849. }
  8850. var SimpleScrollGrid = /** @class */ (function (_super) {
  8851. __extends(SimpleScrollGrid, _super);
  8852. function SimpleScrollGrid() {
  8853. var _this = _super !== null && _super.apply(this, arguments) || this;
  8854. _this.processCols = memoize(function (a) { return a; }, isColPropsEqual); // so we get same `cols` props every time
  8855. // yucky to memoize VNodes, but much more efficient for consumers
  8856. _this.renderMicroColGroup = memoize(renderMicroColGroup);
  8857. _this.scrollerRefs = new RefMap();
  8858. _this.scrollerElRefs = new RefMap(_this._handleScrollerEl.bind(_this));
  8859. _this.state = {
  8860. shrinkWidth: null,
  8861. forceYScrollbars: false,
  8862. scrollerClientWidths: {},
  8863. scrollerClientHeights: {},
  8864. };
  8865. // TODO: can do a really simple print-view. dont need to join rows
  8866. _this.handleSizing = function () {
  8867. _this.setState(__assign({ shrinkWidth: _this.computeShrinkWidth() }, _this.computeScrollerDims()));
  8868. };
  8869. return _this;
  8870. }
  8871. SimpleScrollGrid.prototype.render = function () {
  8872. var _a = this, props = _a.props, state = _a.state, context = _a.context;
  8873. var sectionConfigs = props.sections || [];
  8874. var cols = this.processCols(props.cols);
  8875. var microColGroupNode = this.renderMicroColGroup(cols, state.shrinkWidth);
  8876. var classNames = getScrollGridClassNames(props.liquid, context);
  8877. if (props.collapsibleWidth) {
  8878. classNames.push('fc-scrollgrid-collapsible');
  8879. }
  8880. // TODO: make DRY
  8881. var configCnt = sectionConfigs.length;
  8882. var configI = 0;
  8883. var currentConfig;
  8884. var headSectionNodes = [];
  8885. var bodySectionNodes = [];
  8886. var footSectionNodes = [];
  8887. while (configI < configCnt && (currentConfig = sectionConfigs[configI]).type === 'header') {
  8888. headSectionNodes.push(this.renderSection(currentConfig, microColGroupNode));
  8889. configI += 1;
  8890. }
  8891. while (configI < configCnt && (currentConfig = sectionConfigs[configI]).type === 'body') {
  8892. bodySectionNodes.push(this.renderSection(currentConfig, microColGroupNode));
  8893. configI += 1;
  8894. }
  8895. while (configI < configCnt && (currentConfig = sectionConfigs[configI]).type === 'footer') {
  8896. footSectionNodes.push(this.renderSection(currentConfig, microColGroupNode));
  8897. configI += 1;
  8898. }
  8899. // firefox bug: when setting height on table and there is a thead or tfoot,
  8900. // the necessary height:100% on the liquid-height body section forces the *whole* table to be taller. (bug #5524)
  8901. // use getCanVGrowWithinCell as a way to detect table-stupid firefox.
  8902. // if so, use a simpler dom structure, jam everything into a lone tbody.
  8903. var isBuggy = !getCanVGrowWithinCell();
  8904. return createElement('table', {
  8905. className: classNames.join(' '),
  8906. style: { height: props.height },
  8907. }, Boolean(!isBuggy && headSectionNodes.length) && createElement.apply(void 0, __spreadArray(['thead', {}], headSectionNodes)), Boolean(!isBuggy && bodySectionNodes.length) && createElement.apply(void 0, __spreadArray(['tbody', {}], bodySectionNodes)), Boolean(!isBuggy && footSectionNodes.length) && createElement.apply(void 0, __spreadArray(['tfoot', {}], footSectionNodes)), isBuggy && createElement.apply(void 0, __spreadArray(__spreadArray(__spreadArray(['tbody', {}], headSectionNodes), bodySectionNodes), footSectionNodes)));
  8908. };
  8909. SimpleScrollGrid.prototype.renderSection = function (sectionConfig, microColGroupNode) {
  8910. if ('outerContent' in sectionConfig) {
  8911. return (createElement(Fragment, { key: sectionConfig.key }, sectionConfig.outerContent));
  8912. }
  8913. return (createElement("tr", { key: sectionConfig.key, className: getSectionClassNames(sectionConfig, this.props.liquid).join(' ') }, this.renderChunkTd(sectionConfig, microColGroupNode, sectionConfig.chunk)));
  8914. };
  8915. SimpleScrollGrid.prototype.renderChunkTd = function (sectionConfig, microColGroupNode, chunkConfig) {
  8916. if ('outerContent' in chunkConfig) {
  8917. return chunkConfig.outerContent;
  8918. }
  8919. var props = this.props;
  8920. var _a = this.state, forceYScrollbars = _a.forceYScrollbars, scrollerClientWidths = _a.scrollerClientWidths, scrollerClientHeights = _a.scrollerClientHeights;
  8921. var needsYScrolling = getAllowYScrolling(props, sectionConfig); // TODO: do lazily. do in section config?
  8922. var isLiquid = getSectionHasLiquidHeight(props, sectionConfig);
  8923. // for `!props.liquid` - is WHOLE scrollgrid natural height?
  8924. // TODO: do same thing in advanced scrollgrid? prolly not b/c always has horizontal scrollbars
  8925. var overflowY = !props.liquid ? 'visible' :
  8926. forceYScrollbars ? 'scroll' :
  8927. !needsYScrolling ? 'hidden' :
  8928. 'auto';
  8929. var sectionKey = sectionConfig.key;
  8930. var content = renderChunkContent(sectionConfig, chunkConfig, {
  8931. tableColGroupNode: microColGroupNode,
  8932. tableMinWidth: '',
  8933. clientWidth: (!props.collapsibleWidth && scrollerClientWidths[sectionKey] !== undefined) ? scrollerClientWidths[sectionKey] : null,
  8934. clientHeight: scrollerClientHeights[sectionKey] !== undefined ? scrollerClientHeights[sectionKey] : null,
  8935. expandRows: sectionConfig.expandRows,
  8936. syncRowHeights: false,
  8937. rowSyncHeights: [],
  8938. reportRowHeightChange: function () { },
  8939. });
  8940. return (createElement("td", { ref: chunkConfig.elRef },
  8941. createElement("div", { className: "fc-scroller-harness" + (isLiquid ? ' fc-scroller-harness-liquid' : '') },
  8942. 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
  8943. : true }, content))));
  8944. };
  8945. SimpleScrollGrid.prototype._handleScrollerEl = function (scrollerEl, key) {
  8946. var section = getSectionByKey(this.props.sections, key);
  8947. if (section) {
  8948. setRef(section.chunk.scrollerElRef, scrollerEl);
  8949. }
  8950. };
  8951. SimpleScrollGrid.prototype.componentDidMount = function () {
  8952. this.handleSizing();
  8953. this.context.addResizeHandler(this.handleSizing);
  8954. };
  8955. SimpleScrollGrid.prototype.componentDidUpdate = function () {
  8956. // TODO: need better solution when state contains non-sizing things
  8957. this.handleSizing();
  8958. };
  8959. SimpleScrollGrid.prototype.componentWillUnmount = function () {
  8960. this.context.removeResizeHandler(this.handleSizing);
  8961. };
  8962. SimpleScrollGrid.prototype.computeShrinkWidth = function () {
  8963. return hasShrinkWidth(this.props.cols)
  8964. ? computeShrinkWidth(this.scrollerElRefs.getAll())
  8965. : 0;
  8966. };
  8967. SimpleScrollGrid.prototype.computeScrollerDims = function () {
  8968. var scrollbarWidth = getScrollbarWidths();
  8969. var _a = this, scrollerRefs = _a.scrollerRefs, scrollerElRefs = _a.scrollerElRefs;
  8970. var forceYScrollbars = false;
  8971. var scrollerClientWidths = {};
  8972. var scrollerClientHeights = {};
  8973. for (var sectionKey in scrollerRefs.currentMap) {
  8974. var scroller = scrollerRefs.currentMap[sectionKey];
  8975. if (scroller && scroller.needsYScrolling()) {
  8976. forceYScrollbars = true;
  8977. break;
  8978. }
  8979. }
  8980. for (var _i = 0, _b = this.props.sections; _i < _b.length; _i++) {
  8981. var section = _b[_i];
  8982. var sectionKey = section.key;
  8983. var scrollerEl = scrollerElRefs.currentMap[sectionKey];
  8984. if (scrollerEl) {
  8985. var harnessEl = scrollerEl.parentNode; // TODO: weird way to get this. need harness b/c doesn't include table borders
  8986. scrollerClientWidths[sectionKey] = Math.floor(harnessEl.getBoundingClientRect().width - (forceYScrollbars
  8987. ? scrollbarWidth.y // use global because scroller might not have scrollbars yet but will need them in future
  8988. : 0));
  8989. scrollerClientHeights[sectionKey] = Math.floor(harnessEl.getBoundingClientRect().height);
  8990. }
  8991. }
  8992. return { forceYScrollbars: forceYScrollbars, scrollerClientWidths: scrollerClientWidths, scrollerClientHeights: scrollerClientHeights };
  8993. };
  8994. return SimpleScrollGrid;
  8995. }(BaseComponent));
  8996. SimpleScrollGrid.addStateEquality({
  8997. scrollerClientWidths: isPropsEqual,
  8998. scrollerClientHeights: isPropsEqual,
  8999. });
  9000. function getSectionByKey(sections, key) {
  9001. for (var _i = 0, sections_1 = sections; _i < sections_1.length; _i++) {
  9002. var section = sections_1[_i];
  9003. if (section.key === key) {
  9004. return section;
  9005. }
  9006. }
  9007. return null;
  9008. }
  9009. var EventRoot = /** @class */ (function (_super) {
  9010. __extends(EventRoot, _super);
  9011. function EventRoot() {
  9012. var _this = _super !== null && _super.apply(this, arguments) || this;
  9013. _this.elRef = createRef();
  9014. return _this;
  9015. }
  9016. EventRoot.prototype.render = function () {
  9017. var _a = this, props = _a.props, context = _a.context;
  9018. var options = context.options;
  9019. var seg = props.seg;
  9020. var eventRange = seg.eventRange;
  9021. var ui = eventRange.ui;
  9022. var hookProps = {
  9023. event: new EventApi(context, eventRange.def, eventRange.instance),
  9024. view: context.viewApi,
  9025. timeText: props.timeText,
  9026. textColor: ui.textColor,
  9027. backgroundColor: ui.backgroundColor,
  9028. borderColor: ui.borderColor,
  9029. isDraggable: !props.disableDragging && computeSegDraggable(seg, context),
  9030. isStartResizable: !props.disableResizing && computeSegStartResizable(seg, context),
  9031. isEndResizable: !props.disableResizing && computeSegEndResizable(seg),
  9032. isMirror: Boolean(props.isDragging || props.isResizing || props.isDateSelecting),
  9033. isStart: Boolean(seg.isStart),
  9034. isEnd: Boolean(seg.isEnd),
  9035. isPast: Boolean(props.isPast),
  9036. isFuture: Boolean(props.isFuture),
  9037. isToday: Boolean(props.isToday),
  9038. isSelected: Boolean(props.isSelected),
  9039. isDragging: Boolean(props.isDragging),
  9040. isResizing: Boolean(props.isResizing),
  9041. };
  9042. var standardClassNames = getEventClassNames(hookProps).concat(ui.classNames);
  9043. return (createElement(RenderHook, { hookProps: hookProps, classNames: options.eventClassNames, content: options.eventContent, defaultContent: props.defaultContent, didMount: options.eventDidMount, willUnmount: options.eventWillUnmount, elRef: this.elRef }, function (rootElRef, customClassNames, innerElRef, innerContent) { return props.children(rootElRef, standardClassNames.concat(customClassNames), innerElRef, innerContent, hookProps); }));
  9044. };
  9045. EventRoot.prototype.componentDidMount = function () {
  9046. setElSeg(this.elRef.current, this.props.seg);
  9047. };
  9048. /*
  9049. need to re-assign seg to the element if seg changes, even if the element is the same
  9050. */
  9051. EventRoot.prototype.componentDidUpdate = function (prevProps) {
  9052. var seg = this.props.seg;
  9053. if (seg !== prevProps.seg) {
  9054. setElSeg(this.elRef.current, seg);
  9055. }
  9056. };
  9057. return EventRoot;
  9058. }(BaseComponent));
  9059. // should not be a purecomponent
  9060. var StandardEvent = /** @class */ (function (_super) {
  9061. __extends(StandardEvent, _super);
  9062. function StandardEvent() {
  9063. return _super !== null && _super.apply(this, arguments) || this;
  9064. }
  9065. StandardEvent.prototype.render = function () {
  9066. var _a = this, props = _a.props, context = _a.context;
  9067. var seg = props.seg;
  9068. var timeFormat = context.options.eventTimeFormat || props.defaultTimeFormat;
  9069. var timeText = buildSegTimeText(seg, timeFormat, context, props.defaultDisplayEventTime, props.defaultDisplayEventEnd);
  9070. return (createElement(EventRoot, { seg: seg, timeText: timeText, disableDragging: props.disableDragging, disableResizing: props.disableResizing, defaultContent: props.defaultContent || renderInnerContent$4, isDragging: props.isDragging, isResizing: props.isResizing, isDateSelecting: props.isDateSelecting, isSelected: props.isSelected, isPast: props.isPast, isFuture: props.isFuture, isToday: props.isToday }, function (rootElRef, classNames, innerElRef, innerContent, hookProps) { return (createElement("a", __assign({ className: props.extraClassNames.concat(classNames).join(' '), style: {
  9071. borderColor: hookProps.borderColor,
  9072. backgroundColor: hookProps.backgroundColor,
  9073. }, ref: rootElRef }, getSegAnchorAttrs$1(seg)),
  9074. createElement("div", { className: "fc-event-main", ref: innerElRef, style: { color: hookProps.textColor } }, innerContent),
  9075. hookProps.isStartResizable &&
  9076. createElement("div", { className: "fc-event-resizer fc-event-resizer-start" }),
  9077. hookProps.isEndResizable &&
  9078. createElement("div", { className: "fc-event-resizer fc-event-resizer-end" }))); }));
  9079. };
  9080. return StandardEvent;
  9081. }(BaseComponent));
  9082. function renderInnerContent$4(innerProps) {
  9083. return (createElement("div", { className: "fc-event-main-frame" },
  9084. innerProps.timeText && (createElement("div", { className: "fc-event-time" }, innerProps.timeText)),
  9085. createElement("div", { className: "fc-event-title-container" },
  9086. createElement("div", { className: "fc-event-title fc-sticky" }, innerProps.event.title || createElement(Fragment, null, "\u00A0")))));
  9087. }
  9088. function getSegAnchorAttrs$1(seg) {
  9089. var url = seg.eventRange.def.url;
  9090. return url ? { href: url } : {};
  9091. }
  9092. var NowIndicatorRoot = function (props) { return (createElement(ViewContextType.Consumer, null, function (context) {
  9093. var options = context.options;
  9094. var hookProps = {
  9095. isAxis: props.isAxis,
  9096. date: context.dateEnv.toDate(props.date),
  9097. view: context.viewApi,
  9098. };
  9099. return (createElement(RenderHook, { hookProps: hookProps, classNames: options.nowIndicatorClassNames, content: options.nowIndicatorContent, didMount: options.nowIndicatorDidMount, willUnmount: options.nowIndicatorWillUnmount }, props.children));
  9100. })); };
  9101. var DAY_NUM_FORMAT = createFormatter({ day: 'numeric' });
  9102. var DayCellContent = /** @class */ (function (_super) {
  9103. __extends(DayCellContent, _super);
  9104. function DayCellContent() {
  9105. return _super !== null && _super.apply(this, arguments) || this;
  9106. }
  9107. DayCellContent.prototype.render = function () {
  9108. var _a = this, props = _a.props, context = _a.context;
  9109. var options = context.options;
  9110. var hookProps = refineDayCellHookProps({
  9111. date: props.date,
  9112. dateProfile: props.dateProfile,
  9113. todayRange: props.todayRange,
  9114. showDayNumber: props.showDayNumber,
  9115. extraProps: props.extraHookProps,
  9116. viewApi: context.viewApi,
  9117. dateEnv: context.dateEnv,
  9118. });
  9119. return (createElement(ContentHook, { hookProps: hookProps, content: options.dayCellContent, defaultContent: props.defaultContent }, props.children));
  9120. };
  9121. return DayCellContent;
  9122. }(BaseComponent));
  9123. function refineDayCellHookProps(raw) {
  9124. var date = raw.date, dateEnv = raw.dateEnv;
  9125. var dayMeta = getDateMeta(date, raw.todayRange, null, raw.dateProfile);
  9126. return __assign(__assign(__assign({ date: dateEnv.toDate(date), view: raw.viewApi }, dayMeta), { dayNumberText: raw.showDayNumber ? dateEnv.format(date, DAY_NUM_FORMAT) : '' }), raw.extraProps);
  9127. }
  9128. var DayCellRoot = /** @class */ (function (_super) {
  9129. __extends(DayCellRoot, _super);
  9130. function DayCellRoot() {
  9131. var _this = _super !== null && _super.apply(this, arguments) || this;
  9132. _this.refineHookProps = memoizeObjArg(refineDayCellHookProps);
  9133. _this.normalizeClassNames = buildClassNameNormalizer();
  9134. return _this;
  9135. }
  9136. DayCellRoot.prototype.render = function () {
  9137. var _a = this, props = _a.props, context = _a.context;
  9138. var options = context.options;
  9139. var hookProps = this.refineHookProps({
  9140. date: props.date,
  9141. dateProfile: props.dateProfile,
  9142. todayRange: props.todayRange,
  9143. showDayNumber: props.showDayNumber,
  9144. extraProps: props.extraHookProps,
  9145. viewApi: context.viewApi,
  9146. dateEnv: context.dateEnv,
  9147. });
  9148. var classNames = getDayClassNames(hookProps, context.theme).concat(hookProps.isDisabled
  9149. ? [] // don't use custom classNames if disabled
  9150. : this.normalizeClassNames(options.dayCellClassNames, hookProps));
  9151. var dataAttrs = hookProps.isDisabled ? {} : {
  9152. 'data-date': formatDayString(props.date),
  9153. };
  9154. return (createElement(MountHook, { hookProps: hookProps, didMount: options.dayCellDidMount, willUnmount: options.dayCellWillUnmount, elRef: props.elRef }, function (rootElRef) { return props.children(rootElRef, classNames, dataAttrs, hookProps.isDisabled); }));
  9155. };
  9156. return DayCellRoot;
  9157. }(BaseComponent));
  9158. function renderFill(fillType) {
  9159. return (createElement("div", { className: "fc-" + fillType }));
  9160. }
  9161. var BgEvent = function (props) { return (createElement(EventRoot, { defaultContent: renderInnerContent$3, seg: props.seg /* uselesss i think */, timeText: "", disableDragging: true, disableResizing: true, isDragging: false, isResizing: false, isDateSelecting: false, isSelected: false, isPast: props.isPast, isFuture: props.isFuture, isToday: props.isToday }, function (rootElRef, classNames, innerElRef, innerContent, hookProps) { return (createElement("div", { ref: rootElRef, className: ['fc-bg-event'].concat(classNames).join(' '), style: {
  9162. backgroundColor: hookProps.backgroundColor,
  9163. } }, innerContent)); })); };
  9164. function renderInnerContent$3(props) {
  9165. var title = props.event.title;
  9166. return title && (createElement("div", { className: "fc-event-title" }, props.event.title));
  9167. }
  9168. var WeekNumberRoot = function (props) { return (createElement(ViewContextType.Consumer, null, function (context) {
  9169. var dateEnv = context.dateEnv, options = context.options;
  9170. var date = props.date;
  9171. var format = options.weekNumberFormat || props.defaultFormat;
  9172. var num = dateEnv.computeWeekNumber(date); // TODO: somehow use for formatting as well?
  9173. var text = dateEnv.format(date, format);
  9174. var hookProps = { num: num, text: text, date: date };
  9175. return (createElement(RenderHook, { hookProps: hookProps, classNames: options.weekNumberClassNames, content: options.weekNumberContent, defaultContent: renderInner, didMount: options.weekNumberDidMount, willUnmount: options.weekNumberWillUnmount }, props.children));
  9176. })); };
  9177. function renderInner(innerProps) {
  9178. return innerProps.text;
  9179. }
  9180. var PADDING_FROM_VIEWPORT = 10;
  9181. var Popover = /** @class */ (function (_super) {
  9182. __extends(Popover, _super);
  9183. function Popover() {
  9184. var _this = _super !== null && _super.apply(this, arguments) || this;
  9185. _this.handleRootEl = function (el) {
  9186. _this.rootEl = el;
  9187. if (_this.props.elRef) {
  9188. setRef(_this.props.elRef, el);
  9189. }
  9190. };
  9191. // Triggered when the user clicks *anywhere* in the document, for the autoHide feature
  9192. _this.handleDocumentMousedown = function (ev) {
  9193. // only hide the popover if the click happened outside the popover
  9194. var target = getEventTargetViaRoot(ev);
  9195. if (!_this.rootEl.contains(target)) {
  9196. _this.handleCloseClick();
  9197. }
  9198. };
  9199. _this.handleCloseClick = function () {
  9200. var onClose = _this.props.onClose;
  9201. if (onClose) {
  9202. onClose();
  9203. }
  9204. };
  9205. return _this;
  9206. }
  9207. Popover.prototype.render = function () {
  9208. var theme = this.context.theme;
  9209. var props = this.props;
  9210. var classNames = [
  9211. 'fc-popover',
  9212. theme.getClass('popover'),
  9213. ].concat(props.extraClassNames || []);
  9214. return createPortal(createElement("div", __assign({ className: classNames.join(' ') }, props.extraAttrs, { ref: this.handleRootEl }),
  9215. createElement("div", { className: 'fc-popover-header ' + theme.getClass('popoverHeader') },
  9216. createElement("span", { className: "fc-popover-title" }, props.title),
  9217. createElement("span", { className: 'fc-popover-close ' + theme.getIconClass('close'), onClick: this.handleCloseClick })),
  9218. createElement("div", { className: 'fc-popover-body ' + theme.getClass('popoverContent') }, props.children)), props.parentEl);
  9219. };
  9220. Popover.prototype.componentDidMount = function () {
  9221. document.addEventListener('mousedown', this.handleDocumentMousedown);
  9222. this.updateSize();
  9223. };
  9224. Popover.prototype.componentWillUnmount = function () {
  9225. document.removeEventListener('mousedown', this.handleDocumentMousedown);
  9226. };
  9227. Popover.prototype.updateSize = function () {
  9228. var isRtl = this.context.isRtl;
  9229. var _a = this.props, alignmentEl = _a.alignmentEl, alignGridTop = _a.alignGridTop;
  9230. var rootEl = this.rootEl;
  9231. var alignmentRect = computeClippedClientRect(alignmentEl);
  9232. if (alignmentRect) {
  9233. var popoverDims = rootEl.getBoundingClientRect();
  9234. // position relative to viewport
  9235. var popoverTop = alignGridTop
  9236. ? elementClosest(alignmentEl, '.fc-scrollgrid').getBoundingClientRect().top
  9237. : alignmentRect.top;
  9238. var popoverLeft = isRtl ? alignmentRect.right - popoverDims.width : alignmentRect.left;
  9239. // constrain
  9240. popoverTop = Math.max(popoverTop, PADDING_FROM_VIEWPORT);
  9241. popoverLeft = Math.min(popoverLeft, document.documentElement.clientWidth - PADDING_FROM_VIEWPORT - popoverDims.width);
  9242. popoverLeft = Math.max(popoverLeft, PADDING_FROM_VIEWPORT);
  9243. var origin_1 = rootEl.offsetParent.getBoundingClientRect();
  9244. applyStyle(rootEl, {
  9245. top: popoverTop - origin_1.top,
  9246. left: popoverLeft - origin_1.left,
  9247. });
  9248. }
  9249. };
  9250. return Popover;
  9251. }(BaseComponent));
  9252. var MorePopover = /** @class */ (function (_super) {
  9253. __extends(MorePopover, _super);
  9254. function MorePopover() {
  9255. var _this = _super !== null && _super.apply(this, arguments) || this;
  9256. _this.handleRootEl = function (rootEl) {
  9257. _this.rootEl = rootEl;
  9258. if (rootEl) {
  9259. _this.context.registerInteractiveComponent(_this, {
  9260. el: rootEl,
  9261. useEventCenter: false,
  9262. });
  9263. }
  9264. else {
  9265. _this.context.unregisterInteractiveComponent(_this);
  9266. }
  9267. };
  9268. return _this;
  9269. }
  9270. MorePopover.prototype.render = function () {
  9271. var _a = this.context, options = _a.options, dateEnv = _a.dateEnv;
  9272. var props = this.props;
  9273. var startDate = props.startDate, todayRange = props.todayRange, dateProfile = props.dateProfile;
  9274. var title = dateEnv.format(startDate, options.dayPopoverFormat);
  9275. return (createElement(DayCellRoot, { date: startDate, dateProfile: dateProfile, todayRange: todayRange, elRef: this.handleRootEl }, function (rootElRef, dayClassNames, dataAttrs) { return (createElement(Popover, { elRef: rootElRef, title: title, extraClassNames: ['fc-more-popover'].concat(dayClassNames), extraAttrs: dataAttrs /* TODO: make these time-based when not whole-day? */, parentEl: props.parentEl, alignmentEl: props.alignmentEl, alignGridTop: props.alignGridTop, onClose: props.onClose },
  9276. createElement(DayCellContent, { date: startDate, dateProfile: dateProfile, todayRange: todayRange }, function (innerElRef, innerContent) { return (innerContent &&
  9277. createElement("div", { className: "fc-more-popover-misc", ref: innerElRef }, innerContent)); }),
  9278. props.children)); }));
  9279. };
  9280. MorePopover.prototype.queryHit = function (positionLeft, positionTop, elWidth, elHeight) {
  9281. var _a = this, rootEl = _a.rootEl, props = _a.props;
  9282. if (positionLeft >= 0 && positionLeft < elWidth &&
  9283. positionTop >= 0 && positionTop < elHeight) {
  9284. return {
  9285. dateProfile: props.dateProfile,
  9286. dateSpan: __assign({ allDay: true, range: {
  9287. start: props.startDate,
  9288. end: props.endDate,
  9289. } }, props.extraDateSpan),
  9290. dayEl: rootEl,
  9291. rect: {
  9292. left: 0,
  9293. top: 0,
  9294. right: elWidth,
  9295. bottom: elHeight,
  9296. },
  9297. layer: 1, // important when comparing with hits from other components
  9298. };
  9299. }
  9300. return null;
  9301. };
  9302. return MorePopover;
  9303. }(DateComponent));
  9304. var MoreLinkRoot = /** @class */ (function (_super) {
  9305. __extends(MoreLinkRoot, _super);
  9306. function MoreLinkRoot() {
  9307. var _this = _super !== null && _super.apply(this, arguments) || this;
  9308. _this.linkElRef = createRef();
  9309. _this.state = {
  9310. isPopoverOpen: false,
  9311. };
  9312. _this.handleClick = function (ev) {
  9313. var _a = _this, props = _a.props, context = _a.context;
  9314. var moreLinkClick = context.options.moreLinkClick;
  9315. var date = computeRange(props).start;
  9316. function buildPublicSeg(seg) {
  9317. var _a = seg.eventRange, def = _a.def, instance = _a.instance, range = _a.range;
  9318. return {
  9319. event: new EventApi(context, def, instance),
  9320. start: context.dateEnv.toDate(range.start),
  9321. end: context.dateEnv.toDate(range.end),
  9322. isStart: seg.isStart,
  9323. isEnd: seg.isEnd,
  9324. };
  9325. }
  9326. if (typeof moreLinkClick === 'function') {
  9327. moreLinkClick = moreLinkClick({
  9328. date: date,
  9329. allDay: Boolean(props.allDayDate),
  9330. allSegs: props.allSegs.map(buildPublicSeg),
  9331. hiddenSegs: props.hiddenSegs.map(buildPublicSeg),
  9332. jsEvent: ev,
  9333. view: context.viewApi,
  9334. });
  9335. }
  9336. if (!moreLinkClick || moreLinkClick === 'popover') {
  9337. _this.setState({ isPopoverOpen: true });
  9338. }
  9339. else if (typeof moreLinkClick === 'string') { // a view name
  9340. context.calendarApi.zoomTo(date, moreLinkClick);
  9341. }
  9342. };
  9343. _this.handlePopoverClose = function () {
  9344. _this.setState({ isPopoverOpen: false });
  9345. };
  9346. return _this;
  9347. }
  9348. MoreLinkRoot.prototype.render = function () {
  9349. var _this = this;
  9350. var props = this.props;
  9351. return (createElement(ViewContextType.Consumer, null, function (context) {
  9352. var viewApi = context.viewApi, options = context.options, calendarApi = context.calendarApi;
  9353. var moreLinkText = options.moreLinkText;
  9354. var moreCnt = props.moreCnt;
  9355. var range = computeRange(props);
  9356. var hookProps = {
  9357. num: moreCnt,
  9358. shortText: "+" + moreCnt,
  9359. text: typeof moreLinkText === 'function'
  9360. ? moreLinkText.call(calendarApi, moreCnt)
  9361. : "+" + moreCnt + " " + moreLinkText,
  9362. view: viewApi,
  9363. };
  9364. return (createElement(Fragment, null,
  9365. Boolean(props.moreCnt) && (createElement(RenderHook, { elRef: _this.linkElRef, hookProps: hookProps, classNames: options.moreLinkClassNames, content: options.moreLinkContent, defaultContent: props.defaultContent || renderMoreLinkInner$1, didMount: options.moreLinkDidMount, willUnmount: options.moreLinkWillUnmount }, function (rootElRef, customClassNames, innerElRef, innerContent) { return props.children(rootElRef, ['fc-more-link'].concat(customClassNames), innerElRef, innerContent, _this.handleClick); })),
  9366. _this.state.isPopoverOpen && (createElement(MorePopover, { startDate: range.start, endDate: range.end, dateProfile: props.dateProfile, todayRange: props.todayRange, extraDateSpan: props.extraDateSpan, parentEl: _this.parentEl, alignmentEl: props.alignmentElRef.current, alignGridTop: props.alignGridTop, onClose: _this.handlePopoverClose }, props.popoverContent()))));
  9367. }));
  9368. };
  9369. MoreLinkRoot.prototype.componentDidMount = function () {
  9370. this.updateParentEl();
  9371. };
  9372. MoreLinkRoot.prototype.componentDidUpdate = function () {
  9373. this.updateParentEl();
  9374. };
  9375. MoreLinkRoot.prototype.updateParentEl = function () {
  9376. if (this.linkElRef.current) {
  9377. this.parentEl = elementClosest(this.linkElRef.current, '.fc-view-harness');
  9378. }
  9379. };
  9380. return MoreLinkRoot;
  9381. }(BaseComponent));
  9382. function renderMoreLinkInner$1(props) {
  9383. return props.text;
  9384. }
  9385. function computeRange(props) {
  9386. if (props.allDayDate) {
  9387. return {
  9388. start: props.allDayDate,
  9389. end: addDays(props.allDayDate, 1),
  9390. };
  9391. }
  9392. var hiddenSegs = props.hiddenSegs;
  9393. return {
  9394. start: computeEarliestSegStart(hiddenSegs),
  9395. end: computeLatestSegEnd(hiddenSegs),
  9396. };
  9397. }
  9398. function computeEarliestSegStart(segs) {
  9399. return segs.reduce(pickEarliestStart).eventRange.range.start;
  9400. }
  9401. function pickEarliestStart(seg0, seg1) {
  9402. return seg0.eventRange.range.start < seg1.eventRange.range.start ? seg0 : seg1;
  9403. }
  9404. function computeLatestSegEnd(segs) {
  9405. return segs.reduce(pickLatestEnd).eventRange.range.end;
  9406. }
  9407. function pickLatestEnd(seg0, seg1) {
  9408. return seg0.eventRange.range.end > seg1.eventRange.range.end ? seg0 : seg1;
  9409. }
  9410. // exports
  9411. // --------------------------------------------------------------------------------------------------
  9412. var version = '5.8.0'; // important to type it, so .d.ts has generic string
  9413. var Calendar = /** @class */ (function (_super) {
  9414. __extends(Calendar, _super);
  9415. function Calendar(el, optionOverrides) {
  9416. if (optionOverrides === void 0) { optionOverrides = {}; }
  9417. var _this = _super.call(this) || this;
  9418. _this.isRendering = false;
  9419. _this.isRendered = false;
  9420. _this.currentClassNames = [];
  9421. _this.customContentRenderId = 0; // will affect custom generated classNames?
  9422. _this.handleAction = function (action) {
  9423. // actions we know we want to render immediately
  9424. switch (action.type) {
  9425. case 'SET_EVENT_DRAG':
  9426. case 'SET_EVENT_RESIZE':
  9427. _this.renderRunner.tryDrain();
  9428. }
  9429. };
  9430. _this.handleData = function (data) {
  9431. _this.currentData = data;
  9432. _this.renderRunner.request(data.calendarOptions.rerenderDelay);
  9433. };
  9434. _this.handleRenderRequest = function () {
  9435. if (_this.isRendering) {
  9436. _this.isRendered = true;
  9437. var currentData_1 = _this.currentData;
  9438. render(createElement(CalendarRoot, { options: currentData_1.calendarOptions, theme: currentData_1.theme, emitter: currentData_1.emitter }, function (classNames, height, isHeightAuto, forPrint) {
  9439. _this.setClassNames(classNames);
  9440. _this.setHeight(height);
  9441. return (createElement(CustomContentRenderContext.Provider, { value: _this.customContentRenderId },
  9442. createElement(CalendarContent, __assign({ isHeightAuto: isHeightAuto, forPrint: forPrint }, currentData_1))));
  9443. }), _this.el);
  9444. }
  9445. else if (_this.isRendered) {
  9446. _this.isRendered = false;
  9447. unmountComponentAtNode(_this.el);
  9448. _this.setClassNames([]);
  9449. _this.setHeight('');
  9450. }
  9451. flushToDom();
  9452. };
  9453. _this.el = el;
  9454. _this.renderRunner = new DelayedRunner(_this.handleRenderRequest);
  9455. new CalendarDataManager({
  9456. optionOverrides: optionOverrides,
  9457. calendarApi: _this,
  9458. onAction: _this.handleAction,
  9459. onData: _this.handleData,
  9460. });
  9461. return _this;
  9462. }
  9463. Object.defineProperty(Calendar.prototype, "view", {
  9464. get: function () { return this.currentData.viewApi; } // for public API
  9465. ,
  9466. enumerable: false,
  9467. configurable: true
  9468. });
  9469. Calendar.prototype.render = function () {
  9470. var wasRendering = this.isRendering;
  9471. if (!wasRendering) {
  9472. this.isRendering = true;
  9473. }
  9474. else {
  9475. this.customContentRenderId += 1;
  9476. }
  9477. this.renderRunner.request();
  9478. if (wasRendering) {
  9479. this.updateSize();
  9480. }
  9481. };
  9482. Calendar.prototype.destroy = function () {
  9483. if (this.isRendering) {
  9484. this.isRendering = false;
  9485. this.renderRunner.request();
  9486. }
  9487. };
  9488. Calendar.prototype.updateSize = function () {
  9489. _super.prototype.updateSize.call(this);
  9490. flushToDom();
  9491. };
  9492. Calendar.prototype.batchRendering = function (func) {
  9493. this.renderRunner.pause('batchRendering');
  9494. func();
  9495. this.renderRunner.resume('batchRendering');
  9496. };
  9497. Calendar.prototype.pauseRendering = function () {
  9498. this.renderRunner.pause('pauseRendering');
  9499. };
  9500. Calendar.prototype.resumeRendering = function () {
  9501. this.renderRunner.resume('pauseRendering', true);
  9502. };
  9503. Calendar.prototype.resetOptions = function (optionOverrides, append) {
  9504. this.currentDataManager.resetOptions(optionOverrides, append);
  9505. };
  9506. Calendar.prototype.setClassNames = function (classNames) {
  9507. if (!isArraysEqual(classNames, this.currentClassNames)) {
  9508. var classList = this.el.classList;
  9509. for (var _i = 0, _a = this.currentClassNames; _i < _a.length; _i++) {
  9510. var className = _a[_i];
  9511. classList.remove(className);
  9512. }
  9513. for (var _b = 0, classNames_1 = classNames; _b < classNames_1.length; _b++) {
  9514. var className = classNames_1[_b];
  9515. classList.add(className);
  9516. }
  9517. this.currentClassNames = classNames;
  9518. }
  9519. };
  9520. Calendar.prototype.setHeight = function (height) {
  9521. applyStyleProp(this.el, 'height', height);
  9522. };
  9523. return Calendar;
  9524. }(CalendarApi));
  9525. config.touchMouseIgnoreWait = 500;
  9526. var ignoreMouseDepth = 0;
  9527. var listenerCnt = 0;
  9528. var isWindowTouchMoveCancelled = false;
  9529. /*
  9530. Uses a "pointer" abstraction, which monitors UI events for both mouse and touch.
  9531. Tracks when the pointer "drags" on a certain element, meaning down+move+up.
  9532. Also, tracks if there was touch-scrolling.
  9533. Also, can prevent touch-scrolling from happening.
  9534. Also, can fire pointermove events when scrolling happens underneath, even when no real pointer movement.
  9535. emits:
  9536. - pointerdown
  9537. - pointermove
  9538. - pointerup
  9539. */
  9540. var PointerDragging = /** @class */ (function () {
  9541. function PointerDragging(containerEl) {
  9542. var _this = this;
  9543. this.subjectEl = null;
  9544. // options that can be directly assigned by caller
  9545. this.selector = ''; // will cause subjectEl in all emitted events to be this element
  9546. this.handleSelector = '';
  9547. this.shouldIgnoreMove = false;
  9548. this.shouldWatchScroll = true; // for simulating pointermove on scroll
  9549. // internal states
  9550. this.isDragging = false;
  9551. this.isTouchDragging = false;
  9552. this.wasTouchScroll = false;
  9553. // Mouse
  9554. // ----------------------------------------------------------------------------------------------------
  9555. this.handleMouseDown = function (ev) {
  9556. if (!_this.shouldIgnoreMouse() &&
  9557. isPrimaryMouseButton(ev) &&
  9558. _this.tryStart(ev)) {
  9559. var pev = _this.createEventFromMouse(ev, true);
  9560. _this.emitter.trigger('pointerdown', pev);
  9561. _this.initScrollWatch(pev);
  9562. if (!_this.shouldIgnoreMove) {
  9563. document.addEventListener('mousemove', _this.handleMouseMove);
  9564. }
  9565. document.addEventListener('mouseup', _this.handleMouseUp);
  9566. }
  9567. };
  9568. this.handleMouseMove = function (ev) {
  9569. var pev = _this.createEventFromMouse(ev);
  9570. _this.recordCoords(pev);
  9571. _this.emitter.trigger('pointermove', pev);
  9572. };
  9573. this.handleMouseUp = function (ev) {
  9574. document.removeEventListener('mousemove', _this.handleMouseMove);
  9575. document.removeEventListener('mouseup', _this.handleMouseUp);
  9576. _this.emitter.trigger('pointerup', _this.createEventFromMouse(ev));
  9577. _this.cleanup(); // call last so that pointerup has access to props
  9578. };
  9579. // Touch
  9580. // ----------------------------------------------------------------------------------------------------
  9581. this.handleTouchStart = function (ev) {
  9582. if (_this.tryStart(ev)) {
  9583. _this.isTouchDragging = true;
  9584. var pev = _this.createEventFromTouch(ev, true);
  9585. _this.emitter.trigger('pointerdown', pev);
  9586. _this.initScrollWatch(pev);
  9587. // unlike mouse, need to attach to target, not document
  9588. // https://stackoverflow.com/a/45760014
  9589. var targetEl = ev.target;
  9590. if (!_this.shouldIgnoreMove) {
  9591. targetEl.addEventListener('touchmove', _this.handleTouchMove);
  9592. }
  9593. targetEl.addEventListener('touchend', _this.handleTouchEnd);
  9594. targetEl.addEventListener('touchcancel', _this.handleTouchEnd); // treat it as a touch end
  9595. // attach a handler to get called when ANY scroll action happens on the page.
  9596. // this was impossible to do with normal on/off because 'scroll' doesn't bubble.
  9597. // http://stackoverflow.com/a/32954565/96342
  9598. window.addEventListener('scroll', _this.handleTouchScroll, true);
  9599. }
  9600. };
  9601. this.handleTouchMove = function (ev) {
  9602. var pev = _this.createEventFromTouch(ev);
  9603. _this.recordCoords(pev);
  9604. _this.emitter.trigger('pointermove', pev);
  9605. };
  9606. this.handleTouchEnd = function (ev) {
  9607. if (_this.isDragging) { // done to guard against touchend followed by touchcancel
  9608. var targetEl = ev.target;
  9609. targetEl.removeEventListener('touchmove', _this.handleTouchMove);
  9610. targetEl.removeEventListener('touchend', _this.handleTouchEnd);
  9611. targetEl.removeEventListener('touchcancel', _this.handleTouchEnd);
  9612. window.removeEventListener('scroll', _this.handleTouchScroll, true); // useCaptured=true
  9613. _this.emitter.trigger('pointerup', _this.createEventFromTouch(ev));
  9614. _this.cleanup(); // call last so that pointerup has access to props
  9615. _this.isTouchDragging = false;
  9616. startIgnoringMouse();
  9617. }
  9618. };
  9619. this.handleTouchScroll = function () {
  9620. _this.wasTouchScroll = true;
  9621. };
  9622. this.handleScroll = function (ev) {
  9623. if (!_this.shouldIgnoreMove) {
  9624. var pageX = (window.pageXOffset - _this.prevScrollX) + _this.prevPageX;
  9625. var pageY = (window.pageYOffset - _this.prevScrollY) + _this.prevPageY;
  9626. _this.emitter.trigger('pointermove', {
  9627. origEvent: ev,
  9628. isTouch: _this.isTouchDragging,
  9629. subjectEl: _this.subjectEl,
  9630. pageX: pageX,
  9631. pageY: pageY,
  9632. deltaX: pageX - _this.origPageX,
  9633. deltaY: pageY - _this.origPageY,
  9634. });
  9635. }
  9636. };
  9637. this.containerEl = containerEl;
  9638. this.emitter = new Emitter();
  9639. containerEl.addEventListener('mousedown', this.handleMouseDown);
  9640. containerEl.addEventListener('touchstart', this.handleTouchStart, { passive: true });
  9641. listenerCreated();
  9642. }
  9643. PointerDragging.prototype.destroy = function () {
  9644. this.containerEl.removeEventListener('mousedown', this.handleMouseDown);
  9645. this.containerEl.removeEventListener('touchstart', this.handleTouchStart, { passive: true });
  9646. listenerDestroyed();
  9647. };
  9648. PointerDragging.prototype.tryStart = function (ev) {
  9649. var subjectEl = this.querySubjectEl(ev);
  9650. var downEl = ev.target;
  9651. if (subjectEl &&
  9652. (!this.handleSelector || elementClosest(downEl, this.handleSelector))) {
  9653. this.subjectEl = subjectEl;
  9654. this.isDragging = true; // do this first so cancelTouchScroll will work
  9655. this.wasTouchScroll = false;
  9656. return true;
  9657. }
  9658. return false;
  9659. };
  9660. PointerDragging.prototype.cleanup = function () {
  9661. isWindowTouchMoveCancelled = false;
  9662. this.isDragging = false;
  9663. this.subjectEl = null;
  9664. // keep wasTouchScroll around for later access
  9665. this.destroyScrollWatch();
  9666. };
  9667. PointerDragging.prototype.querySubjectEl = function (ev) {
  9668. if (this.selector) {
  9669. return elementClosest(ev.target, this.selector);
  9670. }
  9671. return this.containerEl;
  9672. };
  9673. PointerDragging.prototype.shouldIgnoreMouse = function () {
  9674. return ignoreMouseDepth || this.isTouchDragging;
  9675. };
  9676. // can be called by user of this class, to cancel touch-based scrolling for the current drag
  9677. PointerDragging.prototype.cancelTouchScroll = function () {
  9678. if (this.isDragging) {
  9679. isWindowTouchMoveCancelled = true;
  9680. }
  9681. };
  9682. // Scrolling that simulates pointermoves
  9683. // ----------------------------------------------------------------------------------------------------
  9684. PointerDragging.prototype.initScrollWatch = function (ev) {
  9685. if (this.shouldWatchScroll) {
  9686. this.recordCoords(ev);
  9687. window.addEventListener('scroll', this.handleScroll, true); // useCapture=true
  9688. }
  9689. };
  9690. PointerDragging.prototype.recordCoords = function (ev) {
  9691. if (this.shouldWatchScroll) {
  9692. this.prevPageX = ev.pageX;
  9693. this.prevPageY = ev.pageY;
  9694. this.prevScrollX = window.pageXOffset;
  9695. this.prevScrollY = window.pageYOffset;
  9696. }
  9697. };
  9698. PointerDragging.prototype.destroyScrollWatch = function () {
  9699. if (this.shouldWatchScroll) {
  9700. window.removeEventListener('scroll', this.handleScroll, true); // useCaptured=true
  9701. }
  9702. };
  9703. // Event Normalization
  9704. // ----------------------------------------------------------------------------------------------------
  9705. PointerDragging.prototype.createEventFromMouse = function (ev, isFirst) {
  9706. var deltaX = 0;
  9707. var deltaY = 0;
  9708. // TODO: repeat code
  9709. if (isFirst) {
  9710. this.origPageX = ev.pageX;
  9711. this.origPageY = ev.pageY;
  9712. }
  9713. else {
  9714. deltaX = ev.pageX - this.origPageX;
  9715. deltaY = ev.pageY - this.origPageY;
  9716. }
  9717. return {
  9718. origEvent: ev,
  9719. isTouch: false,
  9720. subjectEl: this.subjectEl,
  9721. pageX: ev.pageX,
  9722. pageY: ev.pageY,
  9723. deltaX: deltaX,
  9724. deltaY: deltaY,
  9725. };
  9726. };
  9727. PointerDragging.prototype.createEventFromTouch = function (ev, isFirst) {
  9728. var touches = ev.touches;
  9729. var pageX;
  9730. var pageY;
  9731. var deltaX = 0;
  9732. var deltaY = 0;
  9733. // if touch coords available, prefer,
  9734. // because FF would give bad ev.pageX ev.pageY
  9735. if (touches && touches.length) {
  9736. pageX = touches[0].pageX;
  9737. pageY = touches[0].pageY;
  9738. }
  9739. else {
  9740. pageX = ev.pageX;
  9741. pageY = ev.pageY;
  9742. }
  9743. // TODO: repeat code
  9744. if (isFirst) {
  9745. this.origPageX = pageX;
  9746. this.origPageY = pageY;
  9747. }
  9748. else {
  9749. deltaX = pageX - this.origPageX;
  9750. deltaY = pageY - this.origPageY;
  9751. }
  9752. return {
  9753. origEvent: ev,
  9754. isTouch: true,
  9755. subjectEl: this.subjectEl,
  9756. pageX: pageX,
  9757. pageY: pageY,
  9758. deltaX: deltaX,
  9759. deltaY: deltaY,
  9760. };
  9761. };
  9762. return PointerDragging;
  9763. }());
  9764. // Returns a boolean whether this was a left mouse click and no ctrl key (which means right click on Mac)
  9765. function isPrimaryMouseButton(ev) {
  9766. return ev.button === 0 && !ev.ctrlKey;
  9767. }
  9768. // Ignoring fake mouse events generated by touch
  9769. // ----------------------------------------------------------------------------------------------------
  9770. function startIgnoringMouse() {
  9771. ignoreMouseDepth += 1;
  9772. setTimeout(function () {
  9773. ignoreMouseDepth -= 1;
  9774. }, config.touchMouseIgnoreWait);
  9775. }
  9776. // We want to attach touchmove as early as possible for Safari
  9777. // ----------------------------------------------------------------------------------------------------
  9778. function listenerCreated() {
  9779. listenerCnt += 1;
  9780. if (listenerCnt === 1) {
  9781. window.addEventListener('touchmove', onWindowTouchMove, { passive: false });
  9782. }
  9783. }
  9784. function listenerDestroyed() {
  9785. listenerCnt -= 1;
  9786. if (!listenerCnt) {
  9787. window.removeEventListener('touchmove', onWindowTouchMove, { passive: false });
  9788. }
  9789. }
  9790. function onWindowTouchMove(ev) {
  9791. if (isWindowTouchMoveCancelled) {
  9792. ev.preventDefault();
  9793. }
  9794. }
  9795. /*
  9796. An effect in which an element follows the movement of a pointer across the screen.
  9797. The moving element is a clone of some other element.
  9798. Must call start + handleMove + stop.
  9799. */
  9800. var ElementMirror = /** @class */ (function () {
  9801. function ElementMirror() {
  9802. this.isVisible = false; // must be explicitly enabled
  9803. this.sourceEl = null;
  9804. this.mirrorEl = null;
  9805. this.sourceElRect = null; // screen coords relative to viewport
  9806. // options that can be set directly by caller
  9807. this.parentNode = document.body;
  9808. this.zIndex = 9999;
  9809. this.revertDuration = 0;
  9810. }
  9811. ElementMirror.prototype.start = function (sourceEl, pageX, pageY) {
  9812. this.sourceEl = sourceEl;
  9813. this.sourceElRect = this.sourceEl.getBoundingClientRect();
  9814. this.origScreenX = pageX - window.pageXOffset;
  9815. this.origScreenY = pageY - window.pageYOffset;
  9816. this.deltaX = 0;
  9817. this.deltaY = 0;
  9818. this.updateElPosition();
  9819. };
  9820. ElementMirror.prototype.handleMove = function (pageX, pageY) {
  9821. this.deltaX = (pageX - window.pageXOffset) - this.origScreenX;
  9822. this.deltaY = (pageY - window.pageYOffset) - this.origScreenY;
  9823. this.updateElPosition();
  9824. };
  9825. // can be called before start
  9826. ElementMirror.prototype.setIsVisible = function (bool) {
  9827. if (bool) {
  9828. if (!this.isVisible) {
  9829. if (this.mirrorEl) {
  9830. this.mirrorEl.style.display = '';
  9831. }
  9832. this.isVisible = bool; // needs to happen before updateElPosition
  9833. this.updateElPosition(); // because was not updating the position while invisible
  9834. }
  9835. }
  9836. else if (this.isVisible) {
  9837. if (this.mirrorEl) {
  9838. this.mirrorEl.style.display = 'none';
  9839. }
  9840. this.isVisible = bool;
  9841. }
  9842. };
  9843. // always async
  9844. ElementMirror.prototype.stop = function (needsRevertAnimation, callback) {
  9845. var _this = this;
  9846. var done = function () {
  9847. _this.cleanup();
  9848. callback();
  9849. };
  9850. if (needsRevertAnimation &&
  9851. this.mirrorEl &&
  9852. this.isVisible &&
  9853. this.revertDuration && // if 0, transition won't work
  9854. (this.deltaX || this.deltaY) // if same coords, transition won't work
  9855. ) {
  9856. this.doRevertAnimation(done, this.revertDuration);
  9857. }
  9858. else {
  9859. setTimeout(done, 0);
  9860. }
  9861. };
  9862. ElementMirror.prototype.doRevertAnimation = function (callback, revertDuration) {
  9863. var mirrorEl = this.mirrorEl;
  9864. var finalSourceElRect = this.sourceEl.getBoundingClientRect(); // because autoscrolling might have happened
  9865. mirrorEl.style.transition =
  9866. 'top ' + revertDuration + 'ms,' +
  9867. 'left ' + revertDuration + 'ms';
  9868. applyStyle(mirrorEl, {
  9869. left: finalSourceElRect.left,
  9870. top: finalSourceElRect.top,
  9871. });
  9872. whenTransitionDone(mirrorEl, function () {
  9873. mirrorEl.style.transition = '';
  9874. callback();
  9875. });
  9876. };
  9877. ElementMirror.prototype.cleanup = function () {
  9878. if (this.mirrorEl) {
  9879. removeElement(this.mirrorEl);
  9880. this.mirrorEl = null;
  9881. }
  9882. this.sourceEl = null;
  9883. };
  9884. ElementMirror.prototype.updateElPosition = function () {
  9885. if (this.sourceEl && this.isVisible) {
  9886. applyStyle(this.getMirrorEl(), {
  9887. left: this.sourceElRect.left + this.deltaX,
  9888. top: this.sourceElRect.top + this.deltaY,
  9889. });
  9890. }
  9891. };
  9892. ElementMirror.prototype.getMirrorEl = function () {
  9893. var sourceElRect = this.sourceElRect;
  9894. var mirrorEl = this.mirrorEl;
  9895. if (!mirrorEl) {
  9896. mirrorEl = this.mirrorEl = this.sourceEl.cloneNode(true); // cloneChildren=true
  9897. // we don't want long taps or any mouse interaction causing selection/menus.
  9898. // would use preventSelection(), but that prevents selectstart, causing problems.
  9899. mirrorEl.classList.add('fc-unselectable');
  9900. mirrorEl.classList.add('fc-event-dragging');
  9901. applyStyle(mirrorEl, {
  9902. position: 'fixed',
  9903. zIndex: this.zIndex,
  9904. visibility: '',
  9905. boxSizing: 'border-box',
  9906. width: sourceElRect.right - sourceElRect.left,
  9907. height: sourceElRect.bottom - sourceElRect.top,
  9908. right: 'auto',
  9909. bottom: 'auto',
  9910. margin: 0,
  9911. });
  9912. this.parentNode.appendChild(mirrorEl);
  9913. }
  9914. return mirrorEl;
  9915. };
  9916. return ElementMirror;
  9917. }());
  9918. /*
  9919. Is a cache for a given element's scroll information (all the info that ScrollController stores)
  9920. in addition the "client rectangle" of the element.. the area within the scrollbars.
  9921. The cache can be in one of two modes:
  9922. - doesListening:false - ignores when the container is scrolled by someone else
  9923. - doesListening:true - watch for scrolling and update the cache
  9924. */
  9925. var ScrollGeomCache = /** @class */ (function (_super) {
  9926. __extends(ScrollGeomCache, _super);
  9927. function ScrollGeomCache(scrollController, doesListening) {
  9928. var _this = _super.call(this) || this;
  9929. _this.handleScroll = function () {
  9930. _this.scrollTop = _this.scrollController.getScrollTop();
  9931. _this.scrollLeft = _this.scrollController.getScrollLeft();
  9932. _this.handleScrollChange();
  9933. };
  9934. _this.scrollController = scrollController;
  9935. _this.doesListening = doesListening;
  9936. _this.scrollTop = _this.origScrollTop = scrollController.getScrollTop();
  9937. _this.scrollLeft = _this.origScrollLeft = scrollController.getScrollLeft();
  9938. _this.scrollWidth = scrollController.getScrollWidth();
  9939. _this.scrollHeight = scrollController.getScrollHeight();
  9940. _this.clientWidth = scrollController.getClientWidth();
  9941. _this.clientHeight = scrollController.getClientHeight();
  9942. _this.clientRect = _this.computeClientRect(); // do last in case it needs cached values
  9943. if (_this.doesListening) {
  9944. _this.getEventTarget().addEventListener('scroll', _this.handleScroll);
  9945. }
  9946. return _this;
  9947. }
  9948. ScrollGeomCache.prototype.destroy = function () {
  9949. if (this.doesListening) {
  9950. this.getEventTarget().removeEventListener('scroll', this.handleScroll);
  9951. }
  9952. };
  9953. ScrollGeomCache.prototype.getScrollTop = function () {
  9954. return this.scrollTop;
  9955. };
  9956. ScrollGeomCache.prototype.getScrollLeft = function () {
  9957. return this.scrollLeft;
  9958. };
  9959. ScrollGeomCache.prototype.setScrollTop = function (top) {
  9960. this.scrollController.setScrollTop(top);
  9961. if (!this.doesListening) {
  9962. // we are not relying on the element to normalize out-of-bounds scroll values
  9963. // so we need to sanitize ourselves
  9964. this.scrollTop = Math.max(Math.min(top, this.getMaxScrollTop()), 0);
  9965. this.handleScrollChange();
  9966. }
  9967. };
  9968. ScrollGeomCache.prototype.setScrollLeft = function (top) {
  9969. this.scrollController.setScrollLeft(top);
  9970. if (!this.doesListening) {
  9971. // we are not relying on the element to normalize out-of-bounds scroll values
  9972. // so we need to sanitize ourselves
  9973. this.scrollLeft = Math.max(Math.min(top, this.getMaxScrollLeft()), 0);
  9974. this.handleScrollChange();
  9975. }
  9976. };
  9977. ScrollGeomCache.prototype.getClientWidth = function () {
  9978. return this.clientWidth;
  9979. };
  9980. ScrollGeomCache.prototype.getClientHeight = function () {
  9981. return this.clientHeight;
  9982. };
  9983. ScrollGeomCache.prototype.getScrollWidth = function () {
  9984. return this.scrollWidth;
  9985. };
  9986. ScrollGeomCache.prototype.getScrollHeight = function () {
  9987. return this.scrollHeight;
  9988. };
  9989. ScrollGeomCache.prototype.handleScrollChange = function () {
  9990. };
  9991. return ScrollGeomCache;
  9992. }(ScrollController));
  9993. var ElementScrollGeomCache = /** @class */ (function (_super) {
  9994. __extends(ElementScrollGeomCache, _super);
  9995. function ElementScrollGeomCache(el, doesListening) {
  9996. return _super.call(this, new ElementScrollController(el), doesListening) || this;
  9997. }
  9998. ElementScrollGeomCache.prototype.getEventTarget = function () {
  9999. return this.scrollController.el;
  10000. };
  10001. ElementScrollGeomCache.prototype.computeClientRect = function () {
  10002. return computeInnerRect(this.scrollController.el);
  10003. };
  10004. return ElementScrollGeomCache;
  10005. }(ScrollGeomCache));
  10006. var WindowScrollGeomCache = /** @class */ (function (_super) {
  10007. __extends(WindowScrollGeomCache, _super);
  10008. function WindowScrollGeomCache(doesListening) {
  10009. return _super.call(this, new WindowScrollController(), doesListening) || this;
  10010. }
  10011. WindowScrollGeomCache.prototype.getEventTarget = function () {
  10012. return window;
  10013. };
  10014. WindowScrollGeomCache.prototype.computeClientRect = function () {
  10015. return {
  10016. left: this.scrollLeft,
  10017. right: this.scrollLeft + this.clientWidth,
  10018. top: this.scrollTop,
  10019. bottom: this.scrollTop + this.clientHeight,
  10020. };
  10021. };
  10022. // the window is the only scroll object that changes it's rectangle relative
  10023. // to the document's topleft as it scrolls
  10024. WindowScrollGeomCache.prototype.handleScrollChange = function () {
  10025. this.clientRect = this.computeClientRect();
  10026. };
  10027. return WindowScrollGeomCache;
  10028. }(ScrollGeomCache));
  10029. // If available we are using native "performance" API instead of "Date"
  10030. // Read more about it on MDN:
  10031. // https://developer.mozilla.org/en-US/docs/Web/API/Performance
  10032. var getTime = typeof performance === 'function' ? performance.now : Date.now;
  10033. /*
  10034. For a pointer interaction, automatically scrolls certain scroll containers when the pointer
  10035. approaches the edge.
  10036. The caller must call start + handleMove + stop.
  10037. */
  10038. var AutoScroller = /** @class */ (function () {
  10039. function AutoScroller() {
  10040. var _this = this;
  10041. // options that can be set by caller
  10042. this.isEnabled = true;
  10043. this.scrollQuery = [window, '.fc-scroller'];
  10044. this.edgeThreshold = 50; // pixels
  10045. this.maxVelocity = 300; // pixels per second
  10046. // internal state
  10047. this.pointerScreenX = null;
  10048. this.pointerScreenY = null;
  10049. this.isAnimating = false;
  10050. this.scrollCaches = null;
  10051. // protect against the initial pointerdown being too close to an edge and starting the scroll
  10052. this.everMovedUp = false;
  10053. this.everMovedDown = false;
  10054. this.everMovedLeft = false;
  10055. this.everMovedRight = false;
  10056. this.animate = function () {
  10057. if (_this.isAnimating) { // wasn't cancelled between animation calls
  10058. var edge = _this.computeBestEdge(_this.pointerScreenX + window.pageXOffset, _this.pointerScreenY + window.pageYOffset);
  10059. if (edge) {
  10060. var now = getTime();
  10061. _this.handleSide(edge, (now - _this.msSinceRequest) / 1000);
  10062. _this.requestAnimation(now);
  10063. }
  10064. else {
  10065. _this.isAnimating = false; // will stop animation
  10066. }
  10067. }
  10068. };
  10069. }
  10070. AutoScroller.prototype.start = function (pageX, pageY) {
  10071. if (this.isEnabled) {
  10072. this.scrollCaches = this.buildCaches();
  10073. this.pointerScreenX = null;
  10074. this.pointerScreenY = null;
  10075. this.everMovedUp = false;
  10076. this.everMovedDown = false;
  10077. this.everMovedLeft = false;
  10078. this.everMovedRight = false;
  10079. this.handleMove(pageX, pageY);
  10080. }
  10081. };
  10082. AutoScroller.prototype.handleMove = function (pageX, pageY) {
  10083. if (this.isEnabled) {
  10084. var pointerScreenX = pageX - window.pageXOffset;
  10085. var pointerScreenY = pageY - window.pageYOffset;
  10086. var yDelta = this.pointerScreenY === null ? 0 : pointerScreenY - this.pointerScreenY;
  10087. var xDelta = this.pointerScreenX === null ? 0 : pointerScreenX - this.pointerScreenX;
  10088. if (yDelta < 0) {
  10089. this.everMovedUp = true;
  10090. }
  10091. else if (yDelta > 0) {
  10092. this.everMovedDown = true;
  10093. }
  10094. if (xDelta < 0) {
  10095. this.everMovedLeft = true;
  10096. }
  10097. else if (xDelta > 0) {
  10098. this.everMovedRight = true;
  10099. }
  10100. this.pointerScreenX = pointerScreenX;
  10101. this.pointerScreenY = pointerScreenY;
  10102. if (!this.isAnimating) {
  10103. this.isAnimating = true;
  10104. this.requestAnimation(getTime());
  10105. }
  10106. }
  10107. };
  10108. AutoScroller.prototype.stop = function () {
  10109. if (this.isEnabled) {
  10110. this.isAnimating = false; // will stop animation
  10111. for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
  10112. var scrollCache = _a[_i];
  10113. scrollCache.destroy();
  10114. }
  10115. this.scrollCaches = null;
  10116. }
  10117. };
  10118. AutoScroller.prototype.requestAnimation = function (now) {
  10119. this.msSinceRequest = now;
  10120. requestAnimationFrame(this.animate);
  10121. };
  10122. AutoScroller.prototype.handleSide = function (edge, seconds) {
  10123. var scrollCache = edge.scrollCache;
  10124. var edgeThreshold = this.edgeThreshold;
  10125. var invDistance = edgeThreshold - edge.distance;
  10126. var velocity = // the closer to the edge, the faster we scroll
  10127. ((invDistance * invDistance) / (edgeThreshold * edgeThreshold)) * // quadratic
  10128. this.maxVelocity * seconds;
  10129. var sign = 1;
  10130. switch (edge.name) {
  10131. case 'left':
  10132. sign = -1;
  10133. // falls through
  10134. case 'right':
  10135. scrollCache.setScrollLeft(scrollCache.getScrollLeft() + velocity * sign);
  10136. break;
  10137. case 'top':
  10138. sign = -1;
  10139. // falls through
  10140. case 'bottom':
  10141. scrollCache.setScrollTop(scrollCache.getScrollTop() + velocity * sign);
  10142. break;
  10143. }
  10144. };
  10145. // left/top are relative to document topleft
  10146. AutoScroller.prototype.computeBestEdge = function (left, top) {
  10147. var edgeThreshold = this.edgeThreshold;
  10148. var bestSide = null;
  10149. for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
  10150. var scrollCache = _a[_i];
  10151. var rect = scrollCache.clientRect;
  10152. var leftDist = left - rect.left;
  10153. var rightDist = rect.right - left;
  10154. var topDist = top - rect.top;
  10155. var bottomDist = rect.bottom - top;
  10156. // completely within the rect?
  10157. if (leftDist >= 0 && rightDist >= 0 && topDist >= 0 && bottomDist >= 0) {
  10158. if (topDist <= edgeThreshold && this.everMovedUp && scrollCache.canScrollUp() &&
  10159. (!bestSide || bestSide.distance > topDist)) {
  10160. bestSide = { scrollCache: scrollCache, name: 'top', distance: topDist };
  10161. }
  10162. if (bottomDist <= edgeThreshold && this.everMovedDown && scrollCache.canScrollDown() &&
  10163. (!bestSide || bestSide.distance > bottomDist)) {
  10164. bestSide = { scrollCache: scrollCache, name: 'bottom', distance: bottomDist };
  10165. }
  10166. if (leftDist <= edgeThreshold && this.everMovedLeft && scrollCache.canScrollLeft() &&
  10167. (!bestSide || bestSide.distance > leftDist)) {
  10168. bestSide = { scrollCache: scrollCache, name: 'left', distance: leftDist };
  10169. }
  10170. if (rightDist <= edgeThreshold && this.everMovedRight && scrollCache.canScrollRight() &&
  10171. (!bestSide || bestSide.distance > rightDist)) {
  10172. bestSide = { scrollCache: scrollCache, name: 'right', distance: rightDist };
  10173. }
  10174. }
  10175. }
  10176. return bestSide;
  10177. };
  10178. AutoScroller.prototype.buildCaches = function () {
  10179. return this.queryScrollEls().map(function (el) {
  10180. if (el === window) {
  10181. return new WindowScrollGeomCache(false); // false = don't listen to user-generated scrolls
  10182. }
  10183. return new ElementScrollGeomCache(el, false); // false = don't listen to user-generated scrolls
  10184. });
  10185. };
  10186. AutoScroller.prototype.queryScrollEls = function () {
  10187. var els = [];
  10188. for (var _i = 0, _a = this.scrollQuery; _i < _a.length; _i++) {
  10189. var query = _a[_i];
  10190. if (typeof query === 'object') {
  10191. els.push(query);
  10192. }
  10193. else {
  10194. els.push.apply(els, Array.prototype.slice.call(document.querySelectorAll(query)));
  10195. }
  10196. }
  10197. return els;
  10198. };
  10199. return AutoScroller;
  10200. }());
  10201. /*
  10202. Monitors dragging on an element. Has a number of high-level features:
  10203. - minimum distance required before dragging
  10204. - minimum wait time ("delay") before dragging
  10205. - a mirror element that follows the pointer
  10206. */
  10207. var FeaturefulElementDragging = /** @class */ (function (_super) {
  10208. __extends(FeaturefulElementDragging, _super);
  10209. function FeaturefulElementDragging(containerEl, selector) {
  10210. var _this = _super.call(this, containerEl) || this;
  10211. // options that can be directly set by caller
  10212. // the caller can also set the PointerDragging's options as well
  10213. _this.delay = null;
  10214. _this.minDistance = 0;
  10215. _this.touchScrollAllowed = true; // prevents drag from starting and blocks scrolling during drag
  10216. _this.mirrorNeedsRevert = false;
  10217. _this.isInteracting = false; // is the user validly moving the pointer? lasts until pointerup
  10218. _this.isDragging = false; // is it INTENTFULLY dragging? lasts until after revert animation
  10219. _this.isDelayEnded = false;
  10220. _this.isDistanceSurpassed = false;
  10221. _this.delayTimeoutId = null;
  10222. _this.onPointerDown = function (ev) {
  10223. if (!_this.isDragging) { // so new drag doesn't happen while revert animation is going
  10224. _this.isInteracting = true;
  10225. _this.isDelayEnded = false;
  10226. _this.isDistanceSurpassed = false;
  10227. preventSelection(document.body);
  10228. preventContextMenu(document.body);
  10229. // prevent links from being visited if there's an eventual drag.
  10230. // also prevents selection in older browsers (maybe?).
  10231. // not necessary for touch, besides, browser would complain about passiveness.
  10232. if (!ev.isTouch) {
  10233. ev.origEvent.preventDefault();
  10234. }
  10235. _this.emitter.trigger('pointerdown', ev);
  10236. if (_this.isInteracting && // not destroyed via pointerdown handler
  10237. !_this.pointer.shouldIgnoreMove) {
  10238. // actions related to initiating dragstart+dragmove+dragend...
  10239. _this.mirror.setIsVisible(false); // reset. caller must set-visible
  10240. _this.mirror.start(ev.subjectEl, ev.pageX, ev.pageY); // must happen on first pointer down
  10241. _this.startDelay(ev);
  10242. if (!_this.minDistance) {
  10243. _this.handleDistanceSurpassed(ev);
  10244. }
  10245. }
  10246. }
  10247. };
  10248. _this.onPointerMove = function (ev) {
  10249. if (_this.isInteracting) {
  10250. _this.emitter.trigger('pointermove', ev);
  10251. if (!_this.isDistanceSurpassed) {
  10252. var minDistance = _this.minDistance;
  10253. var distanceSq = void 0; // current distance from the origin, squared
  10254. var deltaX = ev.deltaX, deltaY = ev.deltaY;
  10255. distanceSq = deltaX * deltaX + deltaY * deltaY;
  10256. if (distanceSq >= minDistance * minDistance) { // use pythagorean theorem
  10257. _this.handleDistanceSurpassed(ev);
  10258. }
  10259. }
  10260. if (_this.isDragging) {
  10261. // a real pointer move? (not one simulated by scrolling)
  10262. if (ev.origEvent.type !== 'scroll') {
  10263. _this.mirror.handleMove(ev.pageX, ev.pageY);
  10264. _this.autoScroller.handleMove(ev.pageX, ev.pageY);
  10265. }
  10266. _this.emitter.trigger('dragmove', ev);
  10267. }
  10268. }
  10269. };
  10270. _this.onPointerUp = function (ev) {
  10271. if (_this.isInteracting) {
  10272. _this.isInteracting = false;
  10273. allowSelection(document.body);
  10274. allowContextMenu(document.body);
  10275. _this.emitter.trigger('pointerup', ev); // can potentially set mirrorNeedsRevert
  10276. if (_this.isDragging) {
  10277. _this.autoScroller.stop();
  10278. _this.tryStopDrag(ev); // which will stop the mirror
  10279. }
  10280. if (_this.delayTimeoutId) {
  10281. clearTimeout(_this.delayTimeoutId);
  10282. _this.delayTimeoutId = null;
  10283. }
  10284. }
  10285. };
  10286. var pointer = _this.pointer = new PointerDragging(containerEl);
  10287. pointer.emitter.on('pointerdown', _this.onPointerDown);
  10288. pointer.emitter.on('pointermove', _this.onPointerMove);
  10289. pointer.emitter.on('pointerup', _this.onPointerUp);
  10290. if (selector) {
  10291. pointer.selector = selector;
  10292. }
  10293. _this.mirror = new ElementMirror();
  10294. _this.autoScroller = new AutoScroller();
  10295. return _this;
  10296. }
  10297. FeaturefulElementDragging.prototype.destroy = function () {
  10298. this.pointer.destroy();
  10299. // HACK: simulate a pointer-up to end the current drag
  10300. // TODO: fire 'dragend' directly and stop interaction. discourage use of pointerup event (b/c might not fire)
  10301. this.onPointerUp({});
  10302. };
  10303. FeaturefulElementDragging.prototype.startDelay = function (ev) {
  10304. var _this = this;
  10305. if (typeof this.delay === 'number') {
  10306. this.delayTimeoutId = setTimeout(function () {
  10307. _this.delayTimeoutId = null;
  10308. _this.handleDelayEnd(ev);
  10309. }, this.delay); // not assignable to number!
  10310. }
  10311. else {
  10312. this.handleDelayEnd(ev);
  10313. }
  10314. };
  10315. FeaturefulElementDragging.prototype.handleDelayEnd = function (ev) {
  10316. this.isDelayEnded = true;
  10317. this.tryStartDrag(ev);
  10318. };
  10319. FeaturefulElementDragging.prototype.handleDistanceSurpassed = function (ev) {
  10320. this.isDistanceSurpassed = true;
  10321. this.tryStartDrag(ev);
  10322. };
  10323. FeaturefulElementDragging.prototype.tryStartDrag = function (ev) {
  10324. if (this.isDelayEnded && this.isDistanceSurpassed) {
  10325. if (!this.pointer.wasTouchScroll || this.touchScrollAllowed) {
  10326. this.isDragging = true;
  10327. this.mirrorNeedsRevert = false;
  10328. this.autoScroller.start(ev.pageX, ev.pageY);
  10329. this.emitter.trigger('dragstart', ev);
  10330. if (this.touchScrollAllowed === false) {
  10331. this.pointer.cancelTouchScroll();
  10332. }
  10333. }
  10334. }
  10335. };
  10336. FeaturefulElementDragging.prototype.tryStopDrag = function (ev) {
  10337. // .stop() is ALWAYS asynchronous, which we NEED because we want all pointerup events
  10338. // that come from the document to fire beforehand. much more convenient this way.
  10339. this.mirror.stop(this.mirrorNeedsRevert, this.stopDrag.bind(this, ev));
  10340. };
  10341. FeaturefulElementDragging.prototype.stopDrag = function (ev) {
  10342. this.isDragging = false;
  10343. this.emitter.trigger('dragend', ev);
  10344. };
  10345. // fill in the implementations...
  10346. FeaturefulElementDragging.prototype.setIgnoreMove = function (bool) {
  10347. this.pointer.shouldIgnoreMove = bool;
  10348. };
  10349. FeaturefulElementDragging.prototype.setMirrorIsVisible = function (bool) {
  10350. this.mirror.setIsVisible(bool);
  10351. };
  10352. FeaturefulElementDragging.prototype.setMirrorNeedsRevert = function (bool) {
  10353. this.mirrorNeedsRevert = bool;
  10354. };
  10355. FeaturefulElementDragging.prototype.setAutoScrollEnabled = function (bool) {
  10356. this.autoScroller.isEnabled = bool;
  10357. };
  10358. return FeaturefulElementDragging;
  10359. }(ElementDragging));
  10360. /*
  10361. When this class is instantiated, it records the offset of an element (relative to the document topleft),
  10362. and continues to monitor scrolling, updating the cached coordinates if it needs to.
  10363. Does not access the DOM after instantiation, so highly performant.
  10364. Also keeps track of all scrolling/overflow:hidden containers that are parents of the given element
  10365. and an determine if a given point is inside the combined clipping rectangle.
  10366. */
  10367. var OffsetTracker = /** @class */ (function () {
  10368. function OffsetTracker(el) {
  10369. this.origRect = computeRect(el);
  10370. // will work fine for divs that have overflow:hidden
  10371. this.scrollCaches = getClippingParents(el).map(function (scrollEl) { return new ElementScrollGeomCache(scrollEl, true); });
  10372. }
  10373. OffsetTracker.prototype.destroy = function () {
  10374. for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
  10375. var scrollCache = _a[_i];
  10376. scrollCache.destroy();
  10377. }
  10378. };
  10379. OffsetTracker.prototype.computeLeft = function () {
  10380. var left = this.origRect.left;
  10381. for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
  10382. var scrollCache = _a[_i];
  10383. left += scrollCache.origScrollLeft - scrollCache.getScrollLeft();
  10384. }
  10385. return left;
  10386. };
  10387. OffsetTracker.prototype.computeTop = function () {
  10388. var top = this.origRect.top;
  10389. for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
  10390. var scrollCache = _a[_i];
  10391. top += scrollCache.origScrollTop - scrollCache.getScrollTop();
  10392. }
  10393. return top;
  10394. };
  10395. OffsetTracker.prototype.isWithinClipping = function (pageX, pageY) {
  10396. var point = { left: pageX, top: pageY };
  10397. for (var _i = 0, _a = this.scrollCaches; _i < _a.length; _i++) {
  10398. var scrollCache = _a[_i];
  10399. if (!isIgnoredClipping(scrollCache.getEventTarget()) &&
  10400. !pointInsideRect(point, scrollCache.clientRect)) {
  10401. return false;
  10402. }
  10403. }
  10404. return true;
  10405. };
  10406. return OffsetTracker;
  10407. }());
  10408. // certain clipping containers should never constrain interactions, like <html> and <body>
  10409. // https://github.com/fullcalendar/fullcalendar/issues/3615
  10410. function isIgnoredClipping(node) {
  10411. var tagName = node.tagName;
  10412. return tagName === 'HTML' || tagName === 'BODY';
  10413. }
  10414. /*
  10415. Tracks movement over multiple droppable areas (aka "hits")
  10416. that exist in one or more DateComponents.
  10417. Relies on an existing draggable.
  10418. emits:
  10419. - pointerdown
  10420. - dragstart
  10421. - hitchange - fires initially, even if not over a hit
  10422. - pointerup
  10423. - (hitchange - again, to null, if ended over a hit)
  10424. - dragend
  10425. */
  10426. var HitDragging = /** @class */ (function () {
  10427. function HitDragging(dragging, droppableStore) {
  10428. var _this = this;
  10429. // options that can be set by caller
  10430. this.useSubjectCenter = false;
  10431. this.requireInitial = true; // if doesn't start out on a hit, won't emit any events
  10432. this.initialHit = null;
  10433. this.movingHit = null;
  10434. this.finalHit = null; // won't ever be populated if shouldIgnoreMove
  10435. this.handlePointerDown = function (ev) {
  10436. var dragging = _this.dragging;
  10437. _this.initialHit = null;
  10438. _this.movingHit = null;
  10439. _this.finalHit = null;
  10440. _this.prepareHits();
  10441. _this.processFirstCoord(ev);
  10442. if (_this.initialHit || !_this.requireInitial) {
  10443. dragging.setIgnoreMove(false);
  10444. // TODO: fire this before computing processFirstCoord, so listeners can cancel. this gets fired by almost every handler :(
  10445. _this.emitter.trigger('pointerdown', ev);
  10446. }
  10447. else {
  10448. dragging.setIgnoreMove(true);
  10449. }
  10450. };
  10451. this.handleDragStart = function (ev) {
  10452. _this.emitter.trigger('dragstart', ev);
  10453. _this.handleMove(ev, true); // force = fire even if initially null
  10454. };
  10455. this.handleDragMove = function (ev) {
  10456. _this.emitter.trigger('dragmove', ev);
  10457. _this.handleMove(ev);
  10458. };
  10459. this.handlePointerUp = function (ev) {
  10460. _this.releaseHits();
  10461. _this.emitter.trigger('pointerup', ev);
  10462. };
  10463. this.handleDragEnd = function (ev) {
  10464. if (_this.movingHit) {
  10465. _this.emitter.trigger('hitupdate', null, true, ev);
  10466. }
  10467. _this.finalHit = _this.movingHit;
  10468. _this.movingHit = null;
  10469. _this.emitter.trigger('dragend', ev);
  10470. };
  10471. this.droppableStore = droppableStore;
  10472. dragging.emitter.on('pointerdown', this.handlePointerDown);
  10473. dragging.emitter.on('dragstart', this.handleDragStart);
  10474. dragging.emitter.on('dragmove', this.handleDragMove);
  10475. dragging.emitter.on('pointerup', this.handlePointerUp);
  10476. dragging.emitter.on('dragend', this.handleDragEnd);
  10477. this.dragging = dragging;
  10478. this.emitter = new Emitter();
  10479. }
  10480. // sets initialHit
  10481. // sets coordAdjust
  10482. HitDragging.prototype.processFirstCoord = function (ev) {
  10483. var origPoint = { left: ev.pageX, top: ev.pageY };
  10484. var adjustedPoint = origPoint;
  10485. var subjectEl = ev.subjectEl;
  10486. var subjectRect;
  10487. if (subjectEl !== document) {
  10488. subjectRect = computeRect(subjectEl);
  10489. adjustedPoint = constrainPoint(adjustedPoint, subjectRect);
  10490. }
  10491. var initialHit = this.initialHit = this.queryHitForOffset(adjustedPoint.left, adjustedPoint.top);
  10492. if (initialHit) {
  10493. if (this.useSubjectCenter && subjectRect) {
  10494. var slicedSubjectRect = intersectRects(subjectRect, initialHit.rect);
  10495. if (slicedSubjectRect) {
  10496. adjustedPoint = getRectCenter(slicedSubjectRect);
  10497. }
  10498. }
  10499. this.coordAdjust = diffPoints(adjustedPoint, origPoint);
  10500. }
  10501. else {
  10502. this.coordAdjust = { left: 0, top: 0 };
  10503. }
  10504. };
  10505. HitDragging.prototype.handleMove = function (ev, forceHandle) {
  10506. var hit = this.queryHitForOffset(ev.pageX + this.coordAdjust.left, ev.pageY + this.coordAdjust.top);
  10507. if (forceHandle || !isHitsEqual(this.movingHit, hit)) {
  10508. this.movingHit = hit;
  10509. this.emitter.trigger('hitupdate', hit, false, ev);
  10510. }
  10511. };
  10512. HitDragging.prototype.prepareHits = function () {
  10513. this.offsetTrackers = mapHash(this.droppableStore, function (interactionSettings) {
  10514. interactionSettings.component.prepareHits();
  10515. return new OffsetTracker(interactionSettings.el);
  10516. });
  10517. };
  10518. HitDragging.prototype.releaseHits = function () {
  10519. var offsetTrackers = this.offsetTrackers;
  10520. for (var id in offsetTrackers) {
  10521. offsetTrackers[id].destroy();
  10522. }
  10523. this.offsetTrackers = {};
  10524. };
  10525. HitDragging.prototype.queryHitForOffset = function (offsetLeft, offsetTop) {
  10526. var _a = this, droppableStore = _a.droppableStore, offsetTrackers = _a.offsetTrackers;
  10527. var bestHit = null;
  10528. for (var id in droppableStore) {
  10529. var component = droppableStore[id].component;
  10530. var offsetTracker = offsetTrackers[id];
  10531. if (offsetTracker && // wasn't destroyed mid-drag
  10532. offsetTracker.isWithinClipping(offsetLeft, offsetTop)) {
  10533. var originLeft = offsetTracker.computeLeft();
  10534. var originTop = offsetTracker.computeTop();
  10535. var positionLeft = offsetLeft - originLeft;
  10536. var positionTop = offsetTop - originTop;
  10537. var origRect = offsetTracker.origRect;
  10538. var width = origRect.right - origRect.left;
  10539. var height = origRect.bottom - origRect.top;
  10540. if (
  10541. // must be within the element's bounds
  10542. positionLeft >= 0 && positionLeft < width &&
  10543. positionTop >= 0 && positionTop < height) {
  10544. var hit = component.queryHit(positionLeft, positionTop, width, height);
  10545. if (hit && (
  10546. // make sure the hit is within activeRange, meaning it's not a dead cell
  10547. rangeContainsRange(hit.dateProfile.activeRange, hit.dateSpan.range)) &&
  10548. (!bestHit || hit.layer > bestHit.layer)) {
  10549. hit.componentId = id;
  10550. hit.context = component.context;
  10551. // TODO: better way to re-orient rectangle
  10552. hit.rect.left += originLeft;
  10553. hit.rect.right += originLeft;
  10554. hit.rect.top += originTop;
  10555. hit.rect.bottom += originTop;
  10556. bestHit = hit;
  10557. }
  10558. }
  10559. }
  10560. }
  10561. return bestHit;
  10562. };
  10563. return HitDragging;
  10564. }());
  10565. function isHitsEqual(hit0, hit1) {
  10566. if (!hit0 && !hit1) {
  10567. return true;
  10568. }
  10569. if (Boolean(hit0) !== Boolean(hit1)) {
  10570. return false;
  10571. }
  10572. return isDateSpansEqual(hit0.dateSpan, hit1.dateSpan);
  10573. }
  10574. function buildDatePointApiWithContext(dateSpan, context) {
  10575. var props = {};
  10576. for (var _i = 0, _a = context.pluginHooks.datePointTransforms; _i < _a.length; _i++) {
  10577. var transform = _a[_i];
  10578. __assign(props, transform(dateSpan, context));
  10579. }
  10580. __assign(props, buildDatePointApi(dateSpan, context.dateEnv));
  10581. return props;
  10582. }
  10583. function buildDatePointApi(span, dateEnv) {
  10584. return {
  10585. date: dateEnv.toDate(span.range.start),
  10586. dateStr: dateEnv.formatIso(span.range.start, { omitTime: span.allDay }),
  10587. allDay: span.allDay,
  10588. };
  10589. }
  10590. /*
  10591. Monitors when the user clicks on a specific date/time of a component.
  10592. A pointerdown+pointerup on the same "hit" constitutes a click.
  10593. */
  10594. var DateClicking = /** @class */ (function (_super) {
  10595. __extends(DateClicking, _super);
  10596. function DateClicking(settings) {
  10597. var _this = _super.call(this, settings) || this;
  10598. _this.handlePointerDown = function (pev) {
  10599. var dragging = _this.dragging;
  10600. var downEl = pev.origEvent.target;
  10601. // do this in pointerdown (not dragend) because DOM might be mutated by the time dragend is fired
  10602. dragging.setIgnoreMove(!_this.component.isValidDateDownEl(downEl));
  10603. };
  10604. // won't even fire if moving was ignored
  10605. _this.handleDragEnd = function (ev) {
  10606. var component = _this.component;
  10607. var pointer = _this.dragging.pointer;
  10608. if (!pointer.wasTouchScroll) {
  10609. var _a = _this.hitDragging, initialHit = _a.initialHit, finalHit = _a.finalHit;
  10610. if (initialHit && finalHit && isHitsEqual(initialHit, finalHit)) {
  10611. var context = component.context;
  10612. var arg = __assign(__assign({}, buildDatePointApiWithContext(initialHit.dateSpan, context)), { dayEl: initialHit.dayEl, jsEvent: ev.origEvent, view: context.viewApi || context.calendarApi.view });
  10613. context.emitter.trigger('dateClick', arg);
  10614. }
  10615. }
  10616. };
  10617. // we DO want to watch pointer moves because otherwise finalHit won't get populated
  10618. _this.dragging = new FeaturefulElementDragging(settings.el);
  10619. _this.dragging.autoScroller.isEnabled = false;
  10620. var hitDragging = _this.hitDragging = new HitDragging(_this.dragging, interactionSettingsToStore(settings));
  10621. hitDragging.emitter.on('pointerdown', _this.handlePointerDown);
  10622. hitDragging.emitter.on('dragend', _this.handleDragEnd);
  10623. return _this;
  10624. }
  10625. DateClicking.prototype.destroy = function () {
  10626. this.dragging.destroy();
  10627. };
  10628. return DateClicking;
  10629. }(Interaction));
  10630. /*
  10631. Tracks when the user selects a portion of time of a component,
  10632. constituted by a drag over date cells, with a possible delay at the beginning of the drag.
  10633. */
  10634. var DateSelecting = /** @class */ (function (_super) {
  10635. __extends(DateSelecting, _super);
  10636. function DateSelecting(settings) {
  10637. var _this = _super.call(this, settings) || this;
  10638. _this.dragSelection = null;
  10639. _this.handlePointerDown = function (ev) {
  10640. var _a = _this, component = _a.component, dragging = _a.dragging;
  10641. var options = component.context.options;
  10642. var canSelect = options.selectable &&
  10643. component.isValidDateDownEl(ev.origEvent.target);
  10644. // don't bother to watch expensive moves if component won't do selection
  10645. dragging.setIgnoreMove(!canSelect);
  10646. // if touch, require user to hold down
  10647. dragging.delay = ev.isTouch ? getComponentTouchDelay$1(component) : null;
  10648. };
  10649. _this.handleDragStart = function (ev) {
  10650. _this.component.context.calendarApi.unselect(ev); // unselect previous selections
  10651. };
  10652. _this.handleHitUpdate = function (hit, isFinal) {
  10653. var context = _this.component.context;
  10654. var dragSelection = null;
  10655. var isInvalid = false;
  10656. if (hit) {
  10657. var initialHit = _this.hitDragging.initialHit;
  10658. var disallowed = hit.componentId === initialHit.componentId
  10659. && _this.isHitComboAllowed
  10660. && !_this.isHitComboAllowed(initialHit, hit);
  10661. if (!disallowed) {
  10662. dragSelection = joinHitsIntoSelection(initialHit, hit, context.pluginHooks.dateSelectionTransformers);
  10663. }
  10664. if (!dragSelection || !isDateSelectionValid(dragSelection, hit.dateProfile, context)) {
  10665. isInvalid = true;
  10666. dragSelection = null;
  10667. }
  10668. }
  10669. if (dragSelection) {
  10670. context.dispatch({ type: 'SELECT_DATES', selection: dragSelection });
  10671. }
  10672. else if (!isFinal) { // only unselect if moved away while dragging
  10673. context.dispatch({ type: 'UNSELECT_DATES' });
  10674. }
  10675. if (!isInvalid) {
  10676. enableCursor();
  10677. }
  10678. else {
  10679. disableCursor();
  10680. }
  10681. if (!isFinal) {
  10682. _this.dragSelection = dragSelection; // only clear if moved away from all hits while dragging
  10683. }
  10684. };
  10685. _this.handlePointerUp = function (pev) {
  10686. if (_this.dragSelection) {
  10687. // selection is already rendered, so just need to report selection
  10688. triggerDateSelect(_this.dragSelection, pev, _this.component.context);
  10689. _this.dragSelection = null;
  10690. }
  10691. };
  10692. var component = settings.component;
  10693. var options = component.context.options;
  10694. var dragging = _this.dragging = new FeaturefulElementDragging(settings.el);
  10695. dragging.touchScrollAllowed = false;
  10696. dragging.minDistance = options.selectMinDistance || 0;
  10697. dragging.autoScroller.isEnabled = options.dragScroll;
  10698. var hitDragging = _this.hitDragging = new HitDragging(_this.dragging, interactionSettingsToStore(settings));
  10699. hitDragging.emitter.on('pointerdown', _this.handlePointerDown);
  10700. hitDragging.emitter.on('dragstart', _this.handleDragStart);
  10701. hitDragging.emitter.on('hitupdate', _this.handleHitUpdate);
  10702. hitDragging.emitter.on('pointerup', _this.handlePointerUp);
  10703. return _this;
  10704. }
  10705. DateSelecting.prototype.destroy = function () {
  10706. this.dragging.destroy();
  10707. };
  10708. return DateSelecting;
  10709. }(Interaction));
  10710. function getComponentTouchDelay$1(component) {
  10711. var options = component.context.options;
  10712. var delay = options.selectLongPressDelay;
  10713. if (delay == null) {
  10714. delay = options.longPressDelay;
  10715. }
  10716. return delay;
  10717. }
  10718. function joinHitsIntoSelection(hit0, hit1, dateSelectionTransformers) {
  10719. var dateSpan0 = hit0.dateSpan;
  10720. var dateSpan1 = hit1.dateSpan;
  10721. var ms = [
  10722. dateSpan0.range.start,
  10723. dateSpan0.range.end,
  10724. dateSpan1.range.start,
  10725. dateSpan1.range.end,
  10726. ];
  10727. ms.sort(compareNumbers);
  10728. var props = {};
  10729. for (var _i = 0, dateSelectionTransformers_1 = dateSelectionTransformers; _i < dateSelectionTransformers_1.length; _i++) {
  10730. var transformer = dateSelectionTransformers_1[_i];
  10731. var res = transformer(hit0, hit1);
  10732. if (res === false) {
  10733. return null;
  10734. }
  10735. if (res) {
  10736. __assign(props, res);
  10737. }
  10738. }
  10739. props.range = { start: ms[0], end: ms[3] };
  10740. props.allDay = dateSpan0.allDay;
  10741. return props;
  10742. }
  10743. var EventDragging = /** @class */ (function (_super) {
  10744. __extends(EventDragging, _super);
  10745. function EventDragging(settings) {
  10746. var _this = _super.call(this, settings) || this;
  10747. // internal state
  10748. _this.subjectEl = null;
  10749. _this.subjectSeg = null; // the seg being selected/dragged
  10750. _this.isDragging = false;
  10751. _this.eventRange = null;
  10752. _this.relevantEvents = null; // the events being dragged
  10753. _this.receivingContext = null;
  10754. _this.validMutation = null;
  10755. _this.mutatedRelevantEvents = null;
  10756. _this.handlePointerDown = function (ev) {
  10757. var origTarget = ev.origEvent.target;
  10758. var _a = _this, component = _a.component, dragging = _a.dragging;
  10759. var mirror = dragging.mirror;
  10760. var options = component.context.options;
  10761. var initialContext = component.context;
  10762. _this.subjectEl = ev.subjectEl;
  10763. var subjectSeg = _this.subjectSeg = getElSeg(ev.subjectEl);
  10764. var eventRange = _this.eventRange = subjectSeg.eventRange;
  10765. var eventInstanceId = eventRange.instance.instanceId;
  10766. _this.relevantEvents = getRelevantEvents(initialContext.getCurrentData().eventStore, eventInstanceId);
  10767. dragging.minDistance = ev.isTouch ? 0 : options.eventDragMinDistance;
  10768. dragging.delay =
  10769. // only do a touch delay if touch and this event hasn't been selected yet
  10770. (ev.isTouch && eventInstanceId !== component.props.eventSelection) ?
  10771. getComponentTouchDelay(component) :
  10772. null;
  10773. if (options.fixedMirrorParent) {
  10774. mirror.parentNode = options.fixedMirrorParent;
  10775. }
  10776. else {
  10777. mirror.parentNode = elementClosest(origTarget, '.fc');
  10778. }
  10779. mirror.revertDuration = options.dragRevertDuration;
  10780. var isValid = component.isValidSegDownEl(origTarget) &&
  10781. !elementClosest(origTarget, '.fc-event-resizer'); // NOT on a resizer
  10782. dragging.setIgnoreMove(!isValid);
  10783. // disable dragging for elements that are resizable (ie, selectable)
  10784. // but are not draggable
  10785. _this.isDragging = isValid &&
  10786. ev.subjectEl.classList.contains('fc-event-draggable');
  10787. };
  10788. _this.handleDragStart = function (ev) {
  10789. var initialContext = _this.component.context;
  10790. var eventRange = _this.eventRange;
  10791. var eventInstanceId = eventRange.instance.instanceId;
  10792. if (ev.isTouch) {
  10793. // need to select a different event?
  10794. if (eventInstanceId !== _this.component.props.eventSelection) {
  10795. initialContext.dispatch({ type: 'SELECT_EVENT', eventInstanceId: eventInstanceId });
  10796. }
  10797. }
  10798. else {
  10799. // if now using mouse, but was previous touch interaction, clear selected event
  10800. initialContext.dispatch({ type: 'UNSELECT_EVENT' });
  10801. }
  10802. if (_this.isDragging) {
  10803. initialContext.calendarApi.unselect(ev); // unselect *date* selection
  10804. initialContext.emitter.trigger('eventDragStart', {
  10805. el: _this.subjectEl,
  10806. event: new EventApi(initialContext, eventRange.def, eventRange.instance),
  10807. jsEvent: ev.origEvent,
  10808. view: initialContext.viewApi,
  10809. });
  10810. }
  10811. };
  10812. _this.handleHitUpdate = function (hit, isFinal) {
  10813. if (!_this.isDragging) {
  10814. return;
  10815. }
  10816. var relevantEvents = _this.relevantEvents;
  10817. var initialHit = _this.hitDragging.initialHit;
  10818. var initialContext = _this.component.context;
  10819. // states based on new hit
  10820. var receivingContext = null;
  10821. var mutation = null;
  10822. var mutatedRelevantEvents = null;
  10823. var isInvalid = false;
  10824. var interaction = {
  10825. affectedEvents: relevantEvents,
  10826. mutatedEvents: createEmptyEventStore(),
  10827. isEvent: true,
  10828. };
  10829. if (hit) {
  10830. receivingContext = hit.context;
  10831. var receivingOptions = receivingContext.options;
  10832. if (initialContext === receivingContext ||
  10833. (receivingOptions.editable && receivingOptions.droppable)) {
  10834. mutation = computeEventMutation(initialHit, hit, receivingContext.getCurrentData().pluginHooks.eventDragMutationMassagers);
  10835. if (mutation) {
  10836. mutatedRelevantEvents = applyMutationToEventStore(relevantEvents, receivingContext.getCurrentData().eventUiBases, mutation, receivingContext);
  10837. interaction.mutatedEvents = mutatedRelevantEvents;
  10838. if (!isInteractionValid(interaction, hit.dateProfile, receivingContext)) {
  10839. isInvalid = true;
  10840. mutation = null;
  10841. mutatedRelevantEvents = null;
  10842. interaction.mutatedEvents = createEmptyEventStore();
  10843. }
  10844. }
  10845. }
  10846. else {
  10847. receivingContext = null;
  10848. }
  10849. }
  10850. _this.displayDrag(receivingContext, interaction);
  10851. if (!isInvalid) {
  10852. enableCursor();
  10853. }
  10854. else {
  10855. disableCursor();
  10856. }
  10857. if (!isFinal) {
  10858. if (initialContext === receivingContext && // TODO: write test for this
  10859. isHitsEqual(initialHit, hit)) {
  10860. mutation = null;
  10861. }
  10862. _this.dragging.setMirrorNeedsRevert(!mutation);
  10863. // render the mirror if no already-rendered mirror
  10864. // TODO: wish we could somehow wait for dispatch to guarantee render
  10865. _this.dragging.setMirrorIsVisible(!hit || !document.querySelector('.fc-event-mirror'));
  10866. // assign states based on new hit
  10867. _this.receivingContext = receivingContext;
  10868. _this.validMutation = mutation;
  10869. _this.mutatedRelevantEvents = mutatedRelevantEvents;
  10870. }
  10871. };
  10872. _this.handlePointerUp = function () {
  10873. if (!_this.isDragging) {
  10874. _this.cleanup(); // because handleDragEnd won't fire
  10875. }
  10876. };
  10877. _this.handleDragEnd = function (ev) {
  10878. if (_this.isDragging) {
  10879. var initialContext_1 = _this.component.context;
  10880. var initialView = initialContext_1.viewApi;
  10881. var _a = _this, receivingContext_1 = _a.receivingContext, validMutation = _a.validMutation;
  10882. var eventDef = _this.eventRange.def;
  10883. var eventInstance = _this.eventRange.instance;
  10884. var eventApi = new EventApi(initialContext_1, eventDef, eventInstance);
  10885. var relevantEvents_1 = _this.relevantEvents;
  10886. var mutatedRelevantEvents_1 = _this.mutatedRelevantEvents;
  10887. var finalHit = _this.hitDragging.finalHit;
  10888. _this.clearDrag(); // must happen after revert animation
  10889. initialContext_1.emitter.trigger('eventDragStop', {
  10890. el: _this.subjectEl,
  10891. event: eventApi,
  10892. jsEvent: ev.origEvent,
  10893. view: initialView,
  10894. });
  10895. if (validMutation) {
  10896. // dropped within same calendar
  10897. if (receivingContext_1 === initialContext_1) {
  10898. var updatedEventApi = new EventApi(initialContext_1, mutatedRelevantEvents_1.defs[eventDef.defId], eventInstance ? mutatedRelevantEvents_1.instances[eventInstance.instanceId] : null);
  10899. initialContext_1.dispatch({
  10900. type: 'MERGE_EVENTS',
  10901. eventStore: mutatedRelevantEvents_1,
  10902. });
  10903. var eventChangeArg = {
  10904. oldEvent: eventApi,
  10905. event: updatedEventApi,
  10906. relatedEvents: buildEventApis(mutatedRelevantEvents_1, initialContext_1, eventInstance),
  10907. revert: function () {
  10908. initialContext_1.dispatch({
  10909. type: 'MERGE_EVENTS',
  10910. eventStore: relevantEvents_1, // the pre-change data
  10911. });
  10912. },
  10913. };
  10914. var transformed = {};
  10915. for (var _i = 0, _b = initialContext_1.getCurrentData().pluginHooks.eventDropTransformers; _i < _b.length; _i++) {
  10916. var transformer = _b[_i];
  10917. __assign(transformed, transformer(validMutation, initialContext_1));
  10918. }
  10919. initialContext_1.emitter.trigger('eventDrop', __assign(__assign(__assign({}, eventChangeArg), transformed), { el: ev.subjectEl, delta: validMutation.datesDelta, jsEvent: ev.origEvent, view: initialView }));
  10920. initialContext_1.emitter.trigger('eventChange', eventChangeArg);
  10921. // dropped in different calendar
  10922. }
  10923. else if (receivingContext_1) {
  10924. var eventRemoveArg = {
  10925. event: eventApi,
  10926. relatedEvents: buildEventApis(relevantEvents_1, initialContext_1, eventInstance),
  10927. revert: function () {
  10928. initialContext_1.dispatch({
  10929. type: 'MERGE_EVENTS',
  10930. eventStore: relevantEvents_1,
  10931. });
  10932. },
  10933. };
  10934. initialContext_1.emitter.trigger('eventLeave', __assign(__assign({}, eventRemoveArg), { draggedEl: ev.subjectEl, view: initialView }));
  10935. initialContext_1.dispatch({
  10936. type: 'REMOVE_EVENTS',
  10937. eventStore: relevantEvents_1,
  10938. });
  10939. initialContext_1.emitter.trigger('eventRemove', eventRemoveArg);
  10940. var addedEventDef = mutatedRelevantEvents_1.defs[eventDef.defId];
  10941. var addedEventInstance = mutatedRelevantEvents_1.instances[eventInstance.instanceId];
  10942. var addedEventApi = new EventApi(receivingContext_1, addedEventDef, addedEventInstance);
  10943. receivingContext_1.dispatch({
  10944. type: 'MERGE_EVENTS',
  10945. eventStore: mutatedRelevantEvents_1,
  10946. });
  10947. var eventAddArg = {
  10948. event: addedEventApi,
  10949. relatedEvents: buildEventApis(mutatedRelevantEvents_1, receivingContext_1, addedEventInstance),
  10950. revert: function () {
  10951. receivingContext_1.dispatch({
  10952. type: 'REMOVE_EVENTS',
  10953. eventStore: mutatedRelevantEvents_1,
  10954. });
  10955. },
  10956. };
  10957. receivingContext_1.emitter.trigger('eventAdd', eventAddArg);
  10958. if (ev.isTouch) {
  10959. receivingContext_1.dispatch({
  10960. type: 'SELECT_EVENT',
  10961. eventInstanceId: eventInstance.instanceId,
  10962. });
  10963. }
  10964. receivingContext_1.emitter.trigger('drop', __assign(__assign({}, buildDatePointApiWithContext(finalHit.dateSpan, receivingContext_1)), { draggedEl: ev.subjectEl, jsEvent: ev.origEvent, view: finalHit.context.viewApi }));
  10965. receivingContext_1.emitter.trigger('eventReceive', __assign(__assign({}, eventAddArg), { draggedEl: ev.subjectEl, view: finalHit.context.viewApi }));
  10966. }
  10967. }
  10968. else {
  10969. initialContext_1.emitter.trigger('_noEventDrop');
  10970. }
  10971. }
  10972. _this.cleanup();
  10973. };
  10974. var component = _this.component;
  10975. var options = component.context.options;
  10976. var dragging = _this.dragging = new FeaturefulElementDragging(settings.el);
  10977. dragging.pointer.selector = EventDragging.SELECTOR;
  10978. dragging.touchScrollAllowed = false;
  10979. dragging.autoScroller.isEnabled = options.dragScroll;
  10980. var hitDragging = _this.hitDragging = new HitDragging(_this.dragging, interactionSettingsStore);
  10981. hitDragging.useSubjectCenter = settings.useEventCenter;
  10982. hitDragging.emitter.on('pointerdown', _this.handlePointerDown);
  10983. hitDragging.emitter.on('dragstart', _this.handleDragStart);
  10984. hitDragging.emitter.on('hitupdate', _this.handleHitUpdate);
  10985. hitDragging.emitter.on('pointerup', _this.handlePointerUp);
  10986. hitDragging.emitter.on('dragend', _this.handleDragEnd);
  10987. return _this;
  10988. }
  10989. EventDragging.prototype.destroy = function () {
  10990. this.dragging.destroy();
  10991. };
  10992. // render a drag state on the next receivingCalendar
  10993. EventDragging.prototype.displayDrag = function (nextContext, state) {
  10994. var initialContext = this.component.context;
  10995. var prevContext = this.receivingContext;
  10996. // does the previous calendar need to be cleared?
  10997. if (prevContext && prevContext !== nextContext) {
  10998. // does the initial calendar need to be cleared?
  10999. // if so, don't clear all the way. we still need to to hide the affectedEvents
  11000. if (prevContext === initialContext) {
  11001. prevContext.dispatch({
  11002. type: 'SET_EVENT_DRAG',
  11003. state: {
  11004. affectedEvents: state.affectedEvents,
  11005. mutatedEvents: createEmptyEventStore(),
  11006. isEvent: true,
  11007. },
  11008. });
  11009. // completely clear the old calendar if it wasn't the initial
  11010. }
  11011. else {
  11012. prevContext.dispatch({ type: 'UNSET_EVENT_DRAG' });
  11013. }
  11014. }
  11015. if (nextContext) {
  11016. nextContext.dispatch({ type: 'SET_EVENT_DRAG', state: state });
  11017. }
  11018. };
  11019. EventDragging.prototype.clearDrag = function () {
  11020. var initialCalendar = this.component.context;
  11021. var receivingContext = this.receivingContext;
  11022. if (receivingContext) {
  11023. receivingContext.dispatch({ type: 'UNSET_EVENT_DRAG' });
  11024. }
  11025. // the initial calendar might have an dummy drag state from displayDrag
  11026. if (initialCalendar !== receivingContext) {
  11027. initialCalendar.dispatch({ type: 'UNSET_EVENT_DRAG' });
  11028. }
  11029. };
  11030. EventDragging.prototype.cleanup = function () {
  11031. this.subjectSeg = null;
  11032. this.isDragging = false;
  11033. this.eventRange = null;
  11034. this.relevantEvents = null;
  11035. this.receivingContext = null;
  11036. this.validMutation = null;
  11037. this.mutatedRelevantEvents = null;
  11038. };
  11039. // TODO: test this in IE11
  11040. // QUESTION: why do we need it on the resizable???
  11041. EventDragging.SELECTOR = '.fc-event-draggable, .fc-event-resizable';
  11042. return EventDragging;
  11043. }(Interaction));
  11044. function computeEventMutation(hit0, hit1, massagers) {
  11045. var dateSpan0 = hit0.dateSpan;
  11046. var dateSpan1 = hit1.dateSpan;
  11047. var date0 = dateSpan0.range.start;
  11048. var date1 = dateSpan1.range.start;
  11049. var standardProps = {};
  11050. if (dateSpan0.allDay !== dateSpan1.allDay) {
  11051. standardProps.allDay = dateSpan1.allDay;
  11052. standardProps.hasEnd = hit1.context.options.allDayMaintainDuration;
  11053. if (dateSpan1.allDay) {
  11054. // means date1 is already start-of-day,
  11055. // but date0 needs to be converted
  11056. date0 = startOfDay(date0);
  11057. }
  11058. }
  11059. var delta = diffDates(date0, date1, hit0.context.dateEnv, hit0.componentId === hit1.componentId ?
  11060. hit0.largeUnit :
  11061. null);
  11062. if (delta.milliseconds) { // has hours/minutes/seconds
  11063. standardProps.allDay = false;
  11064. }
  11065. var mutation = {
  11066. datesDelta: delta,
  11067. standardProps: standardProps,
  11068. };
  11069. for (var _i = 0, massagers_1 = massagers; _i < massagers_1.length; _i++) {
  11070. var massager = massagers_1[_i];
  11071. massager(mutation, hit0, hit1);
  11072. }
  11073. return mutation;
  11074. }
  11075. function getComponentTouchDelay(component) {
  11076. var options = component.context.options;
  11077. var delay = options.eventLongPressDelay;
  11078. if (delay == null) {
  11079. delay = options.longPressDelay;
  11080. }
  11081. return delay;
  11082. }
  11083. var EventResizing = /** @class */ (function (_super) {
  11084. __extends(EventResizing, _super);
  11085. function EventResizing(settings) {
  11086. var _this = _super.call(this, settings) || this;
  11087. // internal state
  11088. _this.draggingSegEl = null;
  11089. _this.draggingSeg = null; // TODO: rename to resizingSeg? subjectSeg?
  11090. _this.eventRange = null;
  11091. _this.relevantEvents = null;
  11092. _this.validMutation = null;
  11093. _this.mutatedRelevantEvents = null;
  11094. _this.handlePointerDown = function (ev) {
  11095. var component = _this.component;
  11096. var segEl = _this.querySegEl(ev);
  11097. var seg = getElSeg(segEl);
  11098. var eventRange = _this.eventRange = seg.eventRange;
  11099. _this.dragging.minDistance = component.context.options.eventDragMinDistance;
  11100. // if touch, need to be working with a selected event
  11101. _this.dragging.setIgnoreMove(!_this.component.isValidSegDownEl(ev.origEvent.target) ||
  11102. (ev.isTouch && _this.component.props.eventSelection !== eventRange.instance.instanceId));
  11103. };
  11104. _this.handleDragStart = function (ev) {
  11105. var context = _this.component.context;
  11106. var eventRange = _this.eventRange;
  11107. _this.relevantEvents = getRelevantEvents(context.getCurrentData().eventStore, _this.eventRange.instance.instanceId);
  11108. var segEl = _this.querySegEl(ev);
  11109. _this.draggingSegEl = segEl;
  11110. _this.draggingSeg = getElSeg(segEl);
  11111. context.calendarApi.unselect();
  11112. context.emitter.trigger('eventResizeStart', {
  11113. el: segEl,
  11114. event: new EventApi(context, eventRange.def, eventRange.instance),
  11115. jsEvent: ev.origEvent,
  11116. view: context.viewApi,
  11117. });
  11118. };
  11119. _this.handleHitUpdate = function (hit, isFinal, ev) {
  11120. var context = _this.component.context;
  11121. var relevantEvents = _this.relevantEvents;
  11122. var initialHit = _this.hitDragging.initialHit;
  11123. var eventInstance = _this.eventRange.instance;
  11124. var mutation = null;
  11125. var mutatedRelevantEvents = null;
  11126. var isInvalid = false;
  11127. var interaction = {
  11128. affectedEvents: relevantEvents,
  11129. mutatedEvents: createEmptyEventStore(),
  11130. isEvent: true,
  11131. };
  11132. if (hit) {
  11133. var disallowed = hit.componentId === initialHit.componentId
  11134. && _this.isHitComboAllowed
  11135. && !_this.isHitComboAllowed(initialHit, hit);
  11136. if (!disallowed) {
  11137. mutation = computeMutation(initialHit, hit, ev.subjectEl.classList.contains('fc-event-resizer-start'), eventInstance.range);
  11138. }
  11139. }
  11140. if (mutation) {
  11141. mutatedRelevantEvents = applyMutationToEventStore(relevantEvents, context.getCurrentData().eventUiBases, mutation, context);
  11142. interaction.mutatedEvents = mutatedRelevantEvents;
  11143. if (!isInteractionValid(interaction, hit.dateProfile, context)) {
  11144. isInvalid = true;
  11145. mutation = null;
  11146. mutatedRelevantEvents = null;
  11147. interaction.mutatedEvents = null;
  11148. }
  11149. }
  11150. if (mutatedRelevantEvents) {
  11151. context.dispatch({
  11152. type: 'SET_EVENT_RESIZE',
  11153. state: interaction,
  11154. });
  11155. }
  11156. else {
  11157. context.dispatch({ type: 'UNSET_EVENT_RESIZE' });
  11158. }
  11159. if (!isInvalid) {
  11160. enableCursor();
  11161. }
  11162. else {
  11163. disableCursor();
  11164. }
  11165. if (!isFinal) {
  11166. if (mutation && isHitsEqual(initialHit, hit)) {
  11167. mutation = null;
  11168. }
  11169. _this.validMutation = mutation;
  11170. _this.mutatedRelevantEvents = mutatedRelevantEvents;
  11171. }
  11172. };
  11173. _this.handleDragEnd = function (ev) {
  11174. var context = _this.component.context;
  11175. var eventDef = _this.eventRange.def;
  11176. var eventInstance = _this.eventRange.instance;
  11177. var eventApi = new EventApi(context, eventDef, eventInstance);
  11178. var relevantEvents = _this.relevantEvents;
  11179. var mutatedRelevantEvents = _this.mutatedRelevantEvents;
  11180. context.emitter.trigger('eventResizeStop', {
  11181. el: _this.draggingSegEl,
  11182. event: eventApi,
  11183. jsEvent: ev.origEvent,
  11184. view: context.viewApi,
  11185. });
  11186. if (_this.validMutation) {
  11187. var updatedEventApi = new EventApi(context, mutatedRelevantEvents.defs[eventDef.defId], eventInstance ? mutatedRelevantEvents.instances[eventInstance.instanceId] : null);
  11188. context.dispatch({
  11189. type: 'MERGE_EVENTS',
  11190. eventStore: mutatedRelevantEvents,
  11191. });
  11192. var eventChangeArg = {
  11193. oldEvent: eventApi,
  11194. event: updatedEventApi,
  11195. relatedEvents: buildEventApis(mutatedRelevantEvents, context, eventInstance),
  11196. revert: function () {
  11197. context.dispatch({
  11198. type: 'MERGE_EVENTS',
  11199. eventStore: relevantEvents, // the pre-change events
  11200. });
  11201. },
  11202. };
  11203. context.emitter.trigger('eventResize', __assign(__assign({}, eventChangeArg), { el: _this.draggingSegEl, startDelta: _this.validMutation.startDelta || createDuration(0), endDelta: _this.validMutation.endDelta || createDuration(0), jsEvent: ev.origEvent, view: context.viewApi }));
  11204. context.emitter.trigger('eventChange', eventChangeArg);
  11205. }
  11206. else {
  11207. context.emitter.trigger('_noEventResize');
  11208. }
  11209. // reset all internal state
  11210. _this.draggingSeg = null;
  11211. _this.relevantEvents = null;
  11212. _this.validMutation = null;
  11213. // okay to keep eventInstance around. useful to set it in handlePointerDown
  11214. };
  11215. var component = settings.component;
  11216. var dragging = _this.dragging = new FeaturefulElementDragging(settings.el);
  11217. dragging.pointer.selector = '.fc-event-resizer';
  11218. dragging.touchScrollAllowed = false;
  11219. dragging.autoScroller.isEnabled = component.context.options.dragScroll;
  11220. var hitDragging = _this.hitDragging = new HitDragging(_this.dragging, interactionSettingsToStore(settings));
  11221. hitDragging.emitter.on('pointerdown', _this.handlePointerDown);
  11222. hitDragging.emitter.on('dragstart', _this.handleDragStart);
  11223. hitDragging.emitter.on('hitupdate', _this.handleHitUpdate);
  11224. hitDragging.emitter.on('dragend', _this.handleDragEnd);
  11225. return _this;
  11226. }
  11227. EventResizing.prototype.destroy = function () {
  11228. this.dragging.destroy();
  11229. };
  11230. EventResizing.prototype.querySegEl = function (ev) {
  11231. return elementClosest(ev.subjectEl, '.fc-event');
  11232. };
  11233. return EventResizing;
  11234. }(Interaction));
  11235. function computeMutation(hit0, hit1, isFromStart, instanceRange) {
  11236. var dateEnv = hit0.context.dateEnv;
  11237. var date0 = hit0.dateSpan.range.start;
  11238. var date1 = hit1.dateSpan.range.start;
  11239. var delta = diffDates(date0, date1, dateEnv, hit0.largeUnit);
  11240. if (isFromStart) {
  11241. if (dateEnv.add(instanceRange.start, delta) < instanceRange.end) {
  11242. return { startDelta: delta };
  11243. }
  11244. }
  11245. else if (dateEnv.add(instanceRange.end, delta) > instanceRange.start) {
  11246. return { endDelta: delta };
  11247. }
  11248. return null;
  11249. }
  11250. var UnselectAuto = /** @class */ (function () {
  11251. function UnselectAuto(context) {
  11252. var _this = this;
  11253. this.context = context;
  11254. this.isRecentPointerDateSelect = false; // wish we could use a selector to detect date selection, but uses hit system
  11255. this.matchesCancel = false;
  11256. this.matchesEvent = false;
  11257. this.onSelect = function (selectInfo) {
  11258. if (selectInfo.jsEvent) {
  11259. _this.isRecentPointerDateSelect = true;
  11260. }
  11261. };
  11262. this.onDocumentPointerDown = function (pev) {
  11263. var unselectCancel = _this.context.options.unselectCancel;
  11264. var downEl = pev.origEvent.target;
  11265. _this.matchesCancel = !!elementClosest(downEl, unselectCancel);
  11266. _this.matchesEvent = !!elementClosest(downEl, EventDragging.SELECTOR); // interaction started on an event?
  11267. };
  11268. this.onDocumentPointerUp = function (pev) {
  11269. var context = _this.context;
  11270. var documentPointer = _this.documentPointer;
  11271. var calendarState = context.getCurrentData();
  11272. // touch-scrolling should never unfocus any type of selection
  11273. if (!documentPointer.wasTouchScroll) {
  11274. if (calendarState.dateSelection && // an existing date selection?
  11275. !_this.isRecentPointerDateSelect // a new pointer-initiated date selection since last onDocumentPointerUp?
  11276. ) {
  11277. var unselectAuto = context.options.unselectAuto;
  11278. if (unselectAuto && (!unselectAuto || !_this.matchesCancel)) {
  11279. context.calendarApi.unselect(pev);
  11280. }
  11281. }
  11282. if (calendarState.eventSelection && // an existing event selected?
  11283. !_this.matchesEvent // interaction DIDN'T start on an event
  11284. ) {
  11285. context.dispatch({ type: 'UNSELECT_EVENT' });
  11286. }
  11287. }
  11288. _this.isRecentPointerDateSelect = false;
  11289. };
  11290. var documentPointer = this.documentPointer = new PointerDragging(document);
  11291. documentPointer.shouldIgnoreMove = true;
  11292. documentPointer.shouldWatchScroll = false;
  11293. documentPointer.emitter.on('pointerdown', this.onDocumentPointerDown);
  11294. documentPointer.emitter.on('pointerup', this.onDocumentPointerUp);
  11295. /*
  11296. TODO: better way to know about whether there was a selection with the pointer
  11297. */
  11298. context.emitter.on('select', this.onSelect);
  11299. }
  11300. UnselectAuto.prototype.destroy = function () {
  11301. this.context.emitter.off('select', this.onSelect);
  11302. this.documentPointer.destroy();
  11303. };
  11304. return UnselectAuto;
  11305. }());
  11306. var OPTION_REFINERS$3 = {
  11307. fixedMirrorParent: identity,
  11308. };
  11309. var LISTENER_REFINERS = {
  11310. dateClick: identity,
  11311. eventDragStart: identity,
  11312. eventDragStop: identity,
  11313. eventDrop: identity,
  11314. eventResizeStart: identity,
  11315. eventResizeStop: identity,
  11316. eventResize: identity,
  11317. drop: identity,
  11318. eventReceive: identity,
  11319. eventLeave: identity,
  11320. };
  11321. /*
  11322. Given an already instantiated draggable object for one-or-more elements,
  11323. Interprets any dragging as an attempt to drag an events that lives outside
  11324. of a calendar onto a calendar.
  11325. */
  11326. var ExternalElementDragging = /** @class */ (function () {
  11327. function ExternalElementDragging(dragging, suppliedDragMeta) {
  11328. var _this = this;
  11329. this.receivingContext = null;
  11330. this.droppableEvent = null; // will exist for all drags, even if create:false
  11331. this.suppliedDragMeta = null;
  11332. this.dragMeta = null;
  11333. this.handleDragStart = function (ev) {
  11334. _this.dragMeta = _this.buildDragMeta(ev.subjectEl);
  11335. };
  11336. this.handleHitUpdate = function (hit, isFinal, ev) {
  11337. var dragging = _this.hitDragging.dragging;
  11338. var receivingContext = null;
  11339. var droppableEvent = null;
  11340. var isInvalid = false;
  11341. var interaction = {
  11342. affectedEvents: createEmptyEventStore(),
  11343. mutatedEvents: createEmptyEventStore(),
  11344. isEvent: _this.dragMeta.create,
  11345. };
  11346. if (hit) {
  11347. receivingContext = hit.context;
  11348. if (_this.canDropElOnCalendar(ev.subjectEl, receivingContext)) {
  11349. droppableEvent = computeEventForDateSpan(hit.dateSpan, _this.dragMeta, receivingContext);
  11350. interaction.mutatedEvents = eventTupleToStore(droppableEvent);
  11351. isInvalid = !isInteractionValid(interaction, hit.dateProfile, receivingContext);
  11352. if (isInvalid) {
  11353. interaction.mutatedEvents = createEmptyEventStore();
  11354. droppableEvent = null;
  11355. }
  11356. }
  11357. }
  11358. _this.displayDrag(receivingContext, interaction);
  11359. // show mirror if no already-rendered mirror element OR if we are shutting down the mirror (?)
  11360. // TODO: wish we could somehow wait for dispatch to guarantee render
  11361. dragging.setMirrorIsVisible(isFinal || !droppableEvent || !document.querySelector('.fc-event-mirror'));
  11362. if (!isInvalid) {
  11363. enableCursor();
  11364. }
  11365. else {
  11366. disableCursor();
  11367. }
  11368. if (!isFinal) {
  11369. dragging.setMirrorNeedsRevert(!droppableEvent);
  11370. _this.receivingContext = receivingContext;
  11371. _this.droppableEvent = droppableEvent;
  11372. }
  11373. };
  11374. this.handleDragEnd = function (pev) {
  11375. var _a = _this, receivingContext = _a.receivingContext, droppableEvent = _a.droppableEvent;
  11376. _this.clearDrag();
  11377. if (receivingContext && droppableEvent) {
  11378. var finalHit = _this.hitDragging.finalHit;
  11379. var finalView = finalHit.context.viewApi;
  11380. var dragMeta = _this.dragMeta;
  11381. receivingContext.emitter.trigger('drop', __assign(__assign({}, buildDatePointApiWithContext(finalHit.dateSpan, receivingContext)), { draggedEl: pev.subjectEl, jsEvent: pev.origEvent, view: finalView }));
  11382. if (dragMeta.create) {
  11383. var addingEvents_1 = eventTupleToStore(droppableEvent);
  11384. receivingContext.dispatch({
  11385. type: 'MERGE_EVENTS',
  11386. eventStore: addingEvents_1,
  11387. });
  11388. if (pev.isTouch) {
  11389. receivingContext.dispatch({
  11390. type: 'SELECT_EVENT',
  11391. eventInstanceId: droppableEvent.instance.instanceId,
  11392. });
  11393. }
  11394. // signal that an external event landed
  11395. receivingContext.emitter.trigger('eventReceive', {
  11396. event: new EventApi(receivingContext, droppableEvent.def, droppableEvent.instance),
  11397. relatedEvents: [],
  11398. revert: function () {
  11399. receivingContext.dispatch({
  11400. type: 'REMOVE_EVENTS',
  11401. eventStore: addingEvents_1,
  11402. });
  11403. },
  11404. draggedEl: pev.subjectEl,
  11405. view: finalView,
  11406. });
  11407. }
  11408. }
  11409. _this.receivingContext = null;
  11410. _this.droppableEvent = null;
  11411. };
  11412. var hitDragging = this.hitDragging = new HitDragging(dragging, interactionSettingsStore);
  11413. hitDragging.requireInitial = false; // will start outside of a component
  11414. hitDragging.emitter.on('dragstart', this.handleDragStart);
  11415. hitDragging.emitter.on('hitupdate', this.handleHitUpdate);
  11416. hitDragging.emitter.on('dragend', this.handleDragEnd);
  11417. this.suppliedDragMeta = suppliedDragMeta;
  11418. }
  11419. ExternalElementDragging.prototype.buildDragMeta = function (subjectEl) {
  11420. if (typeof this.suppliedDragMeta === 'object') {
  11421. return parseDragMeta(this.suppliedDragMeta);
  11422. }
  11423. if (typeof this.suppliedDragMeta === 'function') {
  11424. return parseDragMeta(this.suppliedDragMeta(subjectEl));
  11425. }
  11426. return getDragMetaFromEl(subjectEl);
  11427. };
  11428. ExternalElementDragging.prototype.displayDrag = function (nextContext, state) {
  11429. var prevContext = this.receivingContext;
  11430. if (prevContext && prevContext !== nextContext) {
  11431. prevContext.dispatch({ type: 'UNSET_EVENT_DRAG' });
  11432. }
  11433. if (nextContext) {
  11434. nextContext.dispatch({ type: 'SET_EVENT_DRAG', state: state });
  11435. }
  11436. };
  11437. ExternalElementDragging.prototype.clearDrag = function () {
  11438. if (this.receivingContext) {
  11439. this.receivingContext.dispatch({ type: 'UNSET_EVENT_DRAG' });
  11440. }
  11441. };
  11442. ExternalElementDragging.prototype.canDropElOnCalendar = function (el, receivingContext) {
  11443. var dropAccept = receivingContext.options.dropAccept;
  11444. if (typeof dropAccept === 'function') {
  11445. return dropAccept.call(receivingContext.calendarApi, el);
  11446. }
  11447. if (typeof dropAccept === 'string' && dropAccept) {
  11448. return Boolean(elementMatches(el, dropAccept));
  11449. }
  11450. return true;
  11451. };
  11452. return ExternalElementDragging;
  11453. }());
  11454. // Utils for computing event store from the DragMeta
  11455. // ----------------------------------------------------------------------------------------------------
  11456. function computeEventForDateSpan(dateSpan, dragMeta, context) {
  11457. var defProps = __assign({}, dragMeta.leftoverProps);
  11458. for (var _i = 0, _a = context.pluginHooks.externalDefTransforms; _i < _a.length; _i++) {
  11459. var transform = _a[_i];
  11460. __assign(defProps, transform(dateSpan, dragMeta));
  11461. }
  11462. var _b = refineEventDef(defProps, context), refined = _b.refined, extra = _b.extra;
  11463. var def = parseEventDef(refined, extra, dragMeta.sourceId, dateSpan.allDay, context.options.forceEventDuration || Boolean(dragMeta.duration), // hasEnd
  11464. context);
  11465. var start = dateSpan.range.start;
  11466. // only rely on time info if drop zone is all-day,
  11467. // otherwise, we already know the time
  11468. if (dateSpan.allDay && dragMeta.startTime) {
  11469. start = context.dateEnv.add(start, dragMeta.startTime);
  11470. }
  11471. var end = dragMeta.duration ?
  11472. context.dateEnv.add(start, dragMeta.duration) :
  11473. getDefaultEventEnd(dateSpan.allDay, start, context);
  11474. var instance = createEventInstance(def.defId, { start: start, end: end });
  11475. return { def: def, instance: instance };
  11476. }
  11477. // Utils for extracting data from element
  11478. // ----------------------------------------------------------------------------------------------------
  11479. function getDragMetaFromEl(el) {
  11480. var str = getEmbeddedElData(el, 'event');
  11481. var obj = str ?
  11482. JSON.parse(str) :
  11483. { create: false }; // if no embedded data, assume no event creation
  11484. return parseDragMeta(obj);
  11485. }
  11486. config.dataAttrPrefix = '';
  11487. function getEmbeddedElData(el, name) {
  11488. var prefix = config.dataAttrPrefix;
  11489. var prefixedName = (prefix ? prefix + '-' : '') + name;
  11490. return el.getAttribute('data-' + prefixedName) || '';
  11491. }
  11492. /*
  11493. Makes an element (that is *external* to any calendar) draggable.
  11494. Can pass in data that determines how an event will be created when dropped onto a calendar.
  11495. Leverages FullCalendar's internal drag-n-drop functionality WITHOUT a third-party drag system.
  11496. */
  11497. var ExternalDraggable = /** @class */ (function () {
  11498. function ExternalDraggable(el, settings) {
  11499. var _this = this;
  11500. if (settings === void 0) { settings = {}; }
  11501. this.handlePointerDown = function (ev) {
  11502. var dragging = _this.dragging;
  11503. var _a = _this.settings, minDistance = _a.minDistance, longPressDelay = _a.longPressDelay;
  11504. dragging.minDistance =
  11505. minDistance != null ?
  11506. minDistance :
  11507. (ev.isTouch ? 0 : BASE_OPTION_DEFAULTS.eventDragMinDistance);
  11508. dragging.delay =
  11509. ev.isTouch ? // TODO: eventually read eventLongPressDelay instead vvv
  11510. (longPressDelay != null ? longPressDelay : BASE_OPTION_DEFAULTS.longPressDelay) :
  11511. 0;
  11512. };
  11513. this.handleDragStart = function (ev) {
  11514. if (ev.isTouch &&
  11515. _this.dragging.delay &&
  11516. ev.subjectEl.classList.contains('fc-event')) {
  11517. _this.dragging.mirror.getMirrorEl().classList.add('fc-event-selected');
  11518. }
  11519. };
  11520. this.settings = settings;
  11521. var dragging = this.dragging = new FeaturefulElementDragging(el);
  11522. dragging.touchScrollAllowed = false;
  11523. if (settings.itemSelector != null) {
  11524. dragging.pointer.selector = settings.itemSelector;
  11525. }
  11526. if (settings.appendTo != null) {
  11527. dragging.mirror.parentNode = settings.appendTo; // TODO: write tests
  11528. }
  11529. dragging.emitter.on('pointerdown', this.handlePointerDown);
  11530. dragging.emitter.on('dragstart', this.handleDragStart);
  11531. new ExternalElementDragging(dragging, settings.eventData); // eslint-disable-line no-new
  11532. }
  11533. ExternalDraggable.prototype.destroy = function () {
  11534. this.dragging.destroy();
  11535. };
  11536. return ExternalDraggable;
  11537. }());
  11538. /*
  11539. Detects when a *THIRD-PARTY* drag-n-drop system interacts with elements.
  11540. The third-party system is responsible for drawing the visuals effects of the drag.
  11541. This class simply monitors for pointer movements and fires events.
  11542. It also has the ability to hide the moving element (the "mirror") during the drag.
  11543. */
  11544. var InferredElementDragging = /** @class */ (function (_super) {
  11545. __extends(InferredElementDragging, _super);
  11546. function InferredElementDragging(containerEl) {
  11547. var _this = _super.call(this, containerEl) || this;
  11548. _this.shouldIgnoreMove = false;
  11549. _this.mirrorSelector = '';
  11550. _this.currentMirrorEl = null;
  11551. _this.handlePointerDown = function (ev) {
  11552. _this.emitter.trigger('pointerdown', ev);
  11553. if (!_this.shouldIgnoreMove) {
  11554. // fire dragstart right away. does not support delay or min-distance
  11555. _this.emitter.trigger('dragstart', ev);
  11556. }
  11557. };
  11558. _this.handlePointerMove = function (ev) {
  11559. if (!_this.shouldIgnoreMove) {
  11560. _this.emitter.trigger('dragmove', ev);
  11561. }
  11562. };
  11563. _this.handlePointerUp = function (ev) {
  11564. _this.emitter.trigger('pointerup', ev);
  11565. if (!_this.shouldIgnoreMove) {
  11566. // fire dragend right away. does not support a revert animation
  11567. _this.emitter.trigger('dragend', ev);
  11568. }
  11569. };
  11570. var pointer = _this.pointer = new PointerDragging(containerEl);
  11571. pointer.emitter.on('pointerdown', _this.handlePointerDown);
  11572. pointer.emitter.on('pointermove', _this.handlePointerMove);
  11573. pointer.emitter.on('pointerup', _this.handlePointerUp);
  11574. return _this;
  11575. }
  11576. InferredElementDragging.prototype.destroy = function () {
  11577. this.pointer.destroy();
  11578. };
  11579. InferredElementDragging.prototype.setIgnoreMove = function (bool) {
  11580. this.shouldIgnoreMove = bool;
  11581. };
  11582. InferredElementDragging.prototype.setMirrorIsVisible = function (bool) {
  11583. if (bool) {
  11584. // restore a previously hidden element.
  11585. // use the reference in case the selector class has already been removed.
  11586. if (this.currentMirrorEl) {
  11587. this.currentMirrorEl.style.visibility = '';
  11588. this.currentMirrorEl = null;
  11589. }
  11590. }
  11591. else {
  11592. var mirrorEl = this.mirrorSelector ?
  11593. document.querySelector(this.mirrorSelector) :
  11594. null;
  11595. if (mirrorEl) {
  11596. this.currentMirrorEl = mirrorEl;
  11597. mirrorEl.style.visibility = 'hidden';
  11598. }
  11599. }
  11600. };
  11601. return InferredElementDragging;
  11602. }(ElementDragging));
  11603. /*
  11604. Bridges third-party drag-n-drop systems with FullCalendar.
  11605. Must be instantiated and destroyed by caller.
  11606. */
  11607. var ThirdPartyDraggable = /** @class */ (function () {
  11608. function ThirdPartyDraggable(containerOrSettings, settings) {
  11609. var containerEl = document;
  11610. if (
  11611. // wish we could just test instanceof EventTarget, but doesn't work in IE11
  11612. containerOrSettings === document ||
  11613. containerOrSettings instanceof Element) {
  11614. containerEl = containerOrSettings;
  11615. settings = settings || {};
  11616. }
  11617. else {
  11618. settings = (containerOrSettings || {});
  11619. }
  11620. var dragging = this.dragging = new InferredElementDragging(containerEl);
  11621. if (typeof settings.itemSelector === 'string') {
  11622. dragging.pointer.selector = settings.itemSelector;
  11623. }
  11624. else if (containerEl === document) {
  11625. dragging.pointer.selector = '[data-event]';
  11626. }
  11627. if (typeof settings.mirrorSelector === 'string') {
  11628. dragging.mirrorSelector = settings.mirrorSelector;
  11629. }
  11630. new ExternalElementDragging(dragging, settings.eventData); // eslint-disable-line no-new
  11631. }
  11632. ThirdPartyDraggable.prototype.destroy = function () {
  11633. this.dragging.destroy();
  11634. };
  11635. return ThirdPartyDraggable;
  11636. }());
  11637. var interactionPlugin = createPlugin({
  11638. componentInteractions: [DateClicking, DateSelecting, EventDragging, EventResizing],
  11639. calendarInteractions: [UnselectAuto],
  11640. elementDraggingImpl: FeaturefulElementDragging,
  11641. optionRefiners: OPTION_REFINERS$3,
  11642. listenerRefiners: LISTENER_REFINERS,
  11643. });
  11644. /* An abstract class for the daygrid views, as well as month view. Renders one or more rows of day cells.
  11645. ----------------------------------------------------------------------------------------------------------------------*/
  11646. // It is a manager for a Table subcomponent, which does most of the heavy lifting.
  11647. // It is responsible for managing width/height.
  11648. var TableView = /** @class */ (function (_super) {
  11649. __extends(TableView, _super);
  11650. function TableView() {
  11651. var _this = _super !== null && _super.apply(this, arguments) || this;
  11652. _this.headerElRef = createRef();
  11653. return _this;
  11654. }
  11655. TableView.prototype.renderSimpleLayout = function (headerRowContent, bodyContent) {
  11656. var _a = this, props = _a.props, context = _a.context;
  11657. var sections = [];
  11658. var stickyHeaderDates = getStickyHeaderDates(context.options);
  11659. if (headerRowContent) {
  11660. sections.push({
  11661. type: 'header',
  11662. key: 'header',
  11663. isSticky: stickyHeaderDates,
  11664. chunk: {
  11665. elRef: this.headerElRef,
  11666. tableClassName: 'fc-col-header',
  11667. rowContent: headerRowContent,
  11668. },
  11669. });
  11670. }
  11671. sections.push({
  11672. type: 'body',
  11673. key: 'body',
  11674. liquid: true,
  11675. chunk: { content: bodyContent },
  11676. });
  11677. return (createElement(ViewRoot, { viewSpec: context.viewSpec }, function (rootElRef, classNames) { return (createElement("div", { ref: rootElRef, className: ['fc-daygrid'].concat(classNames).join(' ') },
  11678. createElement(SimpleScrollGrid, { liquid: !props.isHeightAuto && !props.forPrint, collapsibleWidth: props.forPrint, cols: [] /* TODO: make optional? */, sections: sections }))); }));
  11679. };
  11680. TableView.prototype.renderHScrollLayout = function (headerRowContent, bodyContent, colCnt, dayMinWidth) {
  11681. var ScrollGrid = this.context.pluginHooks.scrollGridImpl;
  11682. if (!ScrollGrid) {
  11683. throw new Error('No ScrollGrid implementation');
  11684. }
  11685. var _a = this, props = _a.props, context = _a.context;
  11686. var stickyHeaderDates = !props.forPrint && getStickyHeaderDates(context.options);
  11687. var stickyFooterScrollbar = !props.forPrint && getStickyFooterScrollbar(context.options);
  11688. var sections = [];
  11689. if (headerRowContent) {
  11690. sections.push({
  11691. type: 'header',
  11692. key: 'header',
  11693. isSticky: stickyHeaderDates,
  11694. chunks: [{
  11695. key: 'main',
  11696. elRef: this.headerElRef,
  11697. tableClassName: 'fc-col-header',
  11698. rowContent: headerRowContent,
  11699. }],
  11700. });
  11701. }
  11702. sections.push({
  11703. type: 'body',
  11704. key: 'body',
  11705. liquid: true,
  11706. chunks: [{
  11707. key: 'main',
  11708. content: bodyContent,
  11709. }],
  11710. });
  11711. if (stickyFooterScrollbar) {
  11712. sections.push({
  11713. type: 'footer',
  11714. key: 'footer',
  11715. isSticky: true,
  11716. chunks: [{
  11717. key: 'main',
  11718. content: renderScrollShim,
  11719. }],
  11720. });
  11721. }
  11722. return (createElement(ViewRoot, { viewSpec: context.viewSpec }, function (rootElRef, classNames) { return (createElement("div", { ref: rootElRef, className: ['fc-daygrid'].concat(classNames).join(' ') },
  11723. createElement(ScrollGrid, { liquid: !props.isHeightAuto && !props.forPrint, collapsibleWidth: props.forPrint, colGroups: [{ cols: [{ span: colCnt, minWidth: dayMinWidth }] }], sections: sections }))); }));
  11724. };
  11725. return TableView;
  11726. }(DateComponent));
  11727. function splitSegsByRow(segs, rowCnt) {
  11728. var byRow = [];
  11729. for (var i = 0; i < rowCnt; i += 1) {
  11730. byRow[i] = [];
  11731. }
  11732. for (var _i = 0, segs_1 = segs; _i < segs_1.length; _i++) {
  11733. var seg = segs_1[_i];
  11734. byRow[seg.row].push(seg);
  11735. }
  11736. return byRow;
  11737. }
  11738. function splitSegsByFirstCol(segs, colCnt) {
  11739. var byCol = [];
  11740. for (var i = 0; i < colCnt; i += 1) {
  11741. byCol[i] = [];
  11742. }
  11743. for (var _i = 0, segs_2 = segs; _i < segs_2.length; _i++) {
  11744. var seg = segs_2[_i];
  11745. byCol[seg.firstCol].push(seg);
  11746. }
  11747. return byCol;
  11748. }
  11749. function splitInteractionByRow(ui, rowCnt) {
  11750. var byRow = [];
  11751. if (!ui) {
  11752. for (var i = 0; i < rowCnt; i += 1) {
  11753. byRow[i] = null;
  11754. }
  11755. }
  11756. else {
  11757. for (var i = 0; i < rowCnt; i += 1) {
  11758. byRow[i] = {
  11759. affectedInstances: ui.affectedInstances,
  11760. isEvent: ui.isEvent,
  11761. segs: [],
  11762. };
  11763. }
  11764. for (var _i = 0, _a = ui.segs; _i < _a.length; _i++) {
  11765. var seg = _a[_i];
  11766. byRow[seg.row].segs.push(seg);
  11767. }
  11768. }
  11769. return byRow;
  11770. }
  11771. var TableCellTop = /** @class */ (function (_super) {
  11772. __extends(TableCellTop, _super);
  11773. function TableCellTop() {
  11774. return _super !== null && _super.apply(this, arguments) || this;
  11775. }
  11776. TableCellTop.prototype.render = function () {
  11777. var props = this.props;
  11778. var navLinkAttrs = this.context.options.navLinks
  11779. ? { 'data-navlink': buildNavLinkData(props.date), tabIndex: 0 }
  11780. : {};
  11781. return (createElement(DayCellContent, { date: props.date, dateProfile: props.dateProfile, todayRange: props.todayRange, showDayNumber: props.showDayNumber, extraHookProps: props.extraHookProps, defaultContent: renderTopInner }, function (innerElRef, innerContent) { return ((innerContent || props.forceDayTop) && (createElement("div", { className: "fc-daygrid-day-top", ref: innerElRef },
  11782. createElement("a", __assign({ className: "fc-daygrid-day-number" }, navLinkAttrs), innerContent || createElement(Fragment, null, "\u00A0"))))); }));
  11783. };
  11784. return TableCellTop;
  11785. }(BaseComponent));
  11786. function renderTopInner(props) {
  11787. return props.dayNumberText;
  11788. }
  11789. var DEFAULT_TABLE_EVENT_TIME_FORMAT = createFormatter({
  11790. hour: 'numeric',
  11791. minute: '2-digit',
  11792. omitZeroMinute: true,
  11793. meridiem: 'narrow',
  11794. });
  11795. function hasListItemDisplay(seg) {
  11796. var display = seg.eventRange.ui.display;
  11797. return display === 'list-item' || (display === 'auto' &&
  11798. !seg.eventRange.def.allDay &&
  11799. seg.firstCol === seg.lastCol && // can't be multi-day
  11800. seg.isStart && // "
  11801. seg.isEnd // "
  11802. );
  11803. }
  11804. var TableBlockEvent = /** @class */ (function (_super) {
  11805. __extends(TableBlockEvent, _super);
  11806. function TableBlockEvent() {
  11807. return _super !== null && _super.apply(this, arguments) || this;
  11808. }
  11809. TableBlockEvent.prototype.render = function () {
  11810. var props = this.props;
  11811. return (createElement(StandardEvent, __assign({}, props, { extraClassNames: ['fc-daygrid-event', 'fc-daygrid-block-event', 'fc-h-event'], defaultTimeFormat: DEFAULT_TABLE_EVENT_TIME_FORMAT, defaultDisplayEventEnd: props.defaultDisplayEventEnd, disableResizing: !props.seg.eventRange.def.allDay })));
  11812. };
  11813. return TableBlockEvent;
  11814. }(BaseComponent));
  11815. var TableListItemEvent = /** @class */ (function (_super) {
  11816. __extends(TableListItemEvent, _super);
  11817. function TableListItemEvent() {
  11818. return _super !== null && _super.apply(this, arguments) || this;
  11819. }
  11820. TableListItemEvent.prototype.render = function () {
  11821. var _a = this, props = _a.props, context = _a.context;
  11822. var timeFormat = context.options.eventTimeFormat || DEFAULT_TABLE_EVENT_TIME_FORMAT;
  11823. var timeText = buildSegTimeText(props.seg, timeFormat, context, true, props.defaultDisplayEventEnd);
  11824. return (createElement(EventRoot, { seg: props.seg, timeText: timeText, defaultContent: renderInnerContent$2, isDragging: props.isDragging, isResizing: false, isDateSelecting: false, isSelected: props.isSelected, isPast: props.isPast, isFuture: props.isFuture, isToday: props.isToday }, function (rootElRef, classNames, innerElRef, innerContent) { return ( // we don't use styles!
  11825. createElement("a", __assign({ className: ['fc-daygrid-event', 'fc-daygrid-dot-event'].concat(classNames).join(' '), ref: rootElRef }, getSegAnchorAttrs(props.seg)), innerContent)); }));
  11826. };
  11827. return TableListItemEvent;
  11828. }(BaseComponent));
  11829. function renderInnerContent$2(innerProps) {
  11830. return (createElement(Fragment, null,
  11831. createElement("div", { className: "fc-daygrid-event-dot", style: { borderColor: innerProps.borderColor || innerProps.backgroundColor } }),
  11832. innerProps.timeText && (createElement("div", { className: "fc-event-time" }, innerProps.timeText)),
  11833. createElement("div", { className: "fc-event-title" }, innerProps.event.title || createElement(Fragment, null, "\u00A0"))));
  11834. }
  11835. function getSegAnchorAttrs(seg) {
  11836. var url = seg.eventRange.def.url;
  11837. return url ? { href: url } : {};
  11838. }
  11839. var TableCellMoreLink = /** @class */ (function (_super) {
  11840. __extends(TableCellMoreLink, _super);
  11841. function TableCellMoreLink() {
  11842. var _this = _super !== null && _super.apply(this, arguments) || this;
  11843. _this.compileSegs = memoize(compileSegs);
  11844. return _this;
  11845. }
  11846. TableCellMoreLink.prototype.render = function () {
  11847. var props = this.props;
  11848. var _a = this.compileSegs(props.singlePlacements), allSegs = _a.allSegs, invisibleSegs = _a.invisibleSegs;
  11849. return (createElement(MoreLinkRoot, { dateProfile: props.dateProfile, todayRange: props.todayRange, allDayDate: props.allDayDate, moreCnt: props.moreCnt, allSegs: allSegs, hiddenSegs: invisibleSegs, alignmentElRef: props.alignmentElRef, alignGridTop: props.alignGridTop, extraDateSpan: props.extraDateSpan, popoverContent: function () {
  11850. var isForcedInvisible = (props.eventDrag ? props.eventDrag.affectedInstances : null) ||
  11851. (props.eventResize ? props.eventResize.affectedInstances : null) ||
  11852. {};
  11853. return (createElement(Fragment, null, allSegs.map(function (seg) {
  11854. var instanceId = seg.eventRange.instance.instanceId;
  11855. return (createElement("div", { className: "fc-daygrid-event-harness", key: instanceId, style: {
  11856. visibility: isForcedInvisible[instanceId] ? 'hidden' : '',
  11857. } }, hasListItemDisplay(seg) ? (createElement(TableListItemEvent, __assign({ seg: seg, isDragging: false, isSelected: instanceId === props.eventSelection, defaultDisplayEventEnd: false }, getSegMeta(seg, props.todayRange)))) : (createElement(TableBlockEvent, __assign({ seg: seg, isDragging: false, isResizing: false, isDateSelecting: false, isSelected: instanceId === props.eventSelection, defaultDisplayEventEnd: false }, getSegMeta(seg, props.todayRange))))));
  11858. })));
  11859. } }, function (rootElRef, classNames, innerElRef, innerContent, handleClick) { return (createElement("a", { ref: rootElRef, className: ['fc-daygrid-more-link'].concat(classNames).join(' '), onClick: handleClick }, innerContent)); }));
  11860. };
  11861. return TableCellMoreLink;
  11862. }(BaseComponent));
  11863. function compileSegs(singlePlacements) {
  11864. var allSegs = [];
  11865. var invisibleSegs = [];
  11866. for (var _i = 0, singlePlacements_1 = singlePlacements; _i < singlePlacements_1.length; _i++) {
  11867. var placement = singlePlacements_1[_i];
  11868. allSegs.push(placement.seg);
  11869. if (!placement.isVisible) {
  11870. invisibleSegs.push(placement.seg);
  11871. }
  11872. }
  11873. return { allSegs: allSegs, invisibleSegs: invisibleSegs };
  11874. }
  11875. var DEFAULT_WEEK_NUM_FORMAT$1 = createFormatter({ week: 'narrow' });
  11876. var TableCell = /** @class */ (function (_super) {
  11877. __extends(TableCell, _super);
  11878. function TableCell() {
  11879. var _this = _super !== null && _super.apply(this, arguments) || this;
  11880. _this.rootElRef = createRef();
  11881. _this.handleRootEl = function (el) {
  11882. setRef(_this.rootElRef, el);
  11883. setRef(_this.props.elRef, el);
  11884. };
  11885. return _this;
  11886. }
  11887. TableCell.prototype.render = function () {
  11888. var _a = this, props = _a.props, context = _a.context, rootElRef = _a.rootElRef;
  11889. var options = context.options;
  11890. var date = props.date, dateProfile = props.dateProfile;
  11891. var navLinkAttrs = options.navLinks
  11892. ? { 'data-navlink': buildNavLinkData(date, 'week'), tabIndex: 0 }
  11893. : {};
  11894. return (createElement(DayCellRoot, { date: date, dateProfile: dateProfile, todayRange: props.todayRange, showDayNumber: props.showDayNumber, extraHookProps: props.extraHookProps, elRef: this.handleRootEl }, function (dayElRef, dayClassNames, rootDataAttrs, isDisabled) { return (createElement("td", __assign({ ref: dayElRef, className: ['fc-daygrid-day'].concat(dayClassNames, props.extraClassNames || []).join(' ') }, rootDataAttrs, props.extraDataAttrs),
  11895. createElement("div", { className: "fc-daygrid-day-frame fc-scrollgrid-sync-inner", ref: props.innerElRef /* different from hook system! RENAME */ },
  11896. props.showWeekNumber && (createElement(WeekNumberRoot, { date: date, defaultFormat: DEFAULT_WEEK_NUM_FORMAT$1 }, function (weekElRef, weekClassNames, innerElRef, innerContent) { return (createElement("a", __assign({ ref: weekElRef, className: ['fc-daygrid-week-number'].concat(weekClassNames).join(' ') }, navLinkAttrs), innerContent)); })),
  11897. !isDisabled && (createElement(TableCellTop, { date: date, dateProfile: dateProfile, showDayNumber: props.showDayNumber, forceDayTop: props.forceDayTop, todayRange: props.todayRange, extraHookProps: props.extraHookProps })),
  11898. createElement("div", { className: "fc-daygrid-day-events", ref: props.fgContentElRef },
  11899. props.fgContent,
  11900. createElement("div", { className: "fc-daygrid-day-bottom", style: { marginTop: props.moreMarginTop } },
  11901. createElement(TableCellMoreLink, { allDayDate: date, singlePlacements: props.singlePlacements, moreCnt: props.moreCnt, alignmentElRef: rootElRef, alignGridTop: !props.showDayNumber, extraDateSpan: props.extraDateSpan, dateProfile: props.dateProfile, eventSelection: props.eventSelection, eventDrag: props.eventDrag, eventResize: props.eventResize, todayRange: props.todayRange }))),
  11902. createElement("div", { className: "fc-daygrid-day-bg" }, props.bgContent)))); }));
  11903. };
  11904. return TableCell;
  11905. }(DateComponent));
  11906. function computeFgSegPlacement(segs, // assumed already sorted
  11907. dayMaxEvents, dayMaxEventRows, strictOrder, eventInstanceHeights, maxContentHeight, cells) {
  11908. var hierarchy = new DayGridSegHierarchy();
  11909. hierarchy.allowReslicing = true;
  11910. hierarchy.strictOrder = strictOrder;
  11911. if (dayMaxEvents === true || dayMaxEventRows === true) {
  11912. hierarchy.maxCoord = maxContentHeight;
  11913. hierarchy.hiddenConsumes = true;
  11914. }
  11915. else if (typeof dayMaxEvents === 'number') {
  11916. hierarchy.maxStackCnt = dayMaxEvents;
  11917. }
  11918. else if (typeof dayMaxEventRows === 'number') {
  11919. hierarchy.maxStackCnt = dayMaxEventRows;
  11920. hierarchy.hiddenConsumes = true;
  11921. }
  11922. // create segInputs only for segs with known heights
  11923. var segInputs = [];
  11924. var unknownHeightSegs = [];
  11925. for (var i = 0; i < segs.length; i += 1) {
  11926. var seg = segs[i];
  11927. var instanceId = seg.eventRange.instance.instanceId;
  11928. var eventHeight = eventInstanceHeights[instanceId];
  11929. if (eventHeight != null) {
  11930. segInputs.push({
  11931. index: i,
  11932. thickness: eventHeight,
  11933. span: {
  11934. start: seg.firstCol,
  11935. end: seg.lastCol + 1,
  11936. },
  11937. });
  11938. }
  11939. else {
  11940. unknownHeightSegs.push(seg);
  11941. }
  11942. }
  11943. var hiddenEntries = hierarchy.addSegs(segInputs);
  11944. var segRects = hierarchy.toRects();
  11945. var _a = placeRects(segRects, segs, cells), singleColPlacements = _a.singleColPlacements, multiColPlacements = _a.multiColPlacements, leftoverMargins = _a.leftoverMargins;
  11946. var moreCnts = [];
  11947. var moreMarginTops = [];
  11948. // add segs with unknown heights
  11949. for (var _i = 0, unknownHeightSegs_1 = unknownHeightSegs; _i < unknownHeightSegs_1.length; _i++) {
  11950. var seg = unknownHeightSegs_1[_i];
  11951. multiColPlacements[seg.firstCol].push({
  11952. seg: seg,
  11953. isVisible: false,
  11954. isAbsolute: true,
  11955. absoluteTop: 0,
  11956. marginTop: 0,
  11957. });
  11958. for (var col = seg.firstCol; col <= seg.lastCol; col += 1) {
  11959. singleColPlacements[col].push({
  11960. seg: resliceSeg(seg, col, col + 1, cells),
  11961. isVisible: false,
  11962. isAbsolute: false,
  11963. absoluteTop: 0,
  11964. marginTop: 0,
  11965. });
  11966. }
  11967. }
  11968. // add the hidden entries
  11969. for (var col = 0; col < cells.length; col += 1) {
  11970. moreCnts.push(0);
  11971. }
  11972. for (var _b = 0, hiddenEntries_1 = hiddenEntries; _b < hiddenEntries_1.length; _b++) {
  11973. var hiddenEntry = hiddenEntries_1[_b];
  11974. var seg = segs[hiddenEntry.index];
  11975. var hiddenSpan = hiddenEntry.span;
  11976. multiColPlacements[hiddenSpan.start].push({
  11977. seg: resliceSeg(seg, hiddenSpan.start, hiddenSpan.end, cells),
  11978. isVisible: false,
  11979. isAbsolute: true,
  11980. absoluteTop: 0,
  11981. marginTop: 0,
  11982. });
  11983. for (var col = hiddenSpan.start; col < hiddenSpan.end; col += 1) {
  11984. moreCnts[col] += 1;
  11985. singleColPlacements[col].push({
  11986. seg: resliceSeg(seg, col, col + 1, cells),
  11987. isVisible: false,
  11988. isAbsolute: false,
  11989. absoluteTop: 0,
  11990. marginTop: 0,
  11991. });
  11992. }
  11993. }
  11994. // deal with leftover margins
  11995. for (var col = 0; col < cells.length; col += 1) {
  11996. moreMarginTops.push(leftoverMargins[col]);
  11997. }
  11998. return { singleColPlacements: singleColPlacements, multiColPlacements: multiColPlacements, moreCnts: moreCnts, moreMarginTops: moreMarginTops };
  11999. }
  12000. // rects ordered by top coord, then left
  12001. function placeRects(allRects, segs, cells) {
  12002. var rectsByEachCol = groupRectsByEachCol(allRects, cells.length);
  12003. var singleColPlacements = [];
  12004. var multiColPlacements = [];
  12005. var leftoverMargins = [];
  12006. for (var col = 0; col < cells.length; col += 1) {
  12007. var rects = rectsByEachCol[col];
  12008. // compute all static segs in singlePlacements
  12009. var singlePlacements = [];
  12010. var currentHeight = 0;
  12011. var currentMarginTop = 0;
  12012. for (var _i = 0, rects_1 = rects; _i < rects_1.length; _i++) {
  12013. var rect = rects_1[_i];
  12014. var seg = segs[rect.index];
  12015. singlePlacements.push({
  12016. seg: resliceSeg(seg, col, col + 1, cells),
  12017. isVisible: true,
  12018. isAbsolute: false,
  12019. absoluteTop: 0,
  12020. marginTop: rect.levelCoord - currentHeight,
  12021. });
  12022. currentHeight = rect.levelCoord + rect.thickness;
  12023. }
  12024. // compute mixed static/absolute segs in multiPlacements
  12025. var multiPlacements = [];
  12026. currentHeight = 0;
  12027. currentMarginTop = 0;
  12028. for (var _a = 0, rects_2 = rects; _a < rects_2.length; _a++) {
  12029. var rect = rects_2[_a];
  12030. var seg = segs[rect.index];
  12031. var isAbsolute = rect.span.end - rect.span.start > 1; // multi-column?
  12032. var isFirstCol = rect.span.start === col;
  12033. currentMarginTop += rect.levelCoord - currentHeight; // amount of space since bottom of previous seg
  12034. currentHeight = rect.levelCoord + rect.thickness; // height will now be bottom of current seg
  12035. if (isAbsolute) {
  12036. currentMarginTop += rect.thickness;
  12037. if (isFirstCol) {
  12038. multiPlacements.push({
  12039. seg: resliceSeg(seg, rect.span.start, rect.span.end, cells),
  12040. isVisible: true,
  12041. isAbsolute: true,
  12042. absoluteTop: rect.levelCoord,
  12043. marginTop: 0,
  12044. });
  12045. }
  12046. }
  12047. else if (isFirstCol) {
  12048. multiPlacements.push({
  12049. seg: resliceSeg(seg, rect.span.start, rect.span.end, cells),
  12050. isVisible: true,
  12051. isAbsolute: false,
  12052. absoluteTop: 0,
  12053. marginTop: currentMarginTop, // claim the margin
  12054. });
  12055. currentMarginTop = 0;
  12056. }
  12057. }
  12058. singleColPlacements.push(singlePlacements);
  12059. multiColPlacements.push(multiPlacements);
  12060. leftoverMargins.push(currentMarginTop);
  12061. }
  12062. return { singleColPlacements: singleColPlacements, multiColPlacements: multiColPlacements, leftoverMargins: leftoverMargins };
  12063. }
  12064. function groupRectsByEachCol(rects, colCnt) {
  12065. var rectsByEachCol = [];
  12066. for (var col = 0; col < colCnt; col += 1) {
  12067. rectsByEachCol.push([]);
  12068. }
  12069. for (var _i = 0, rects_3 = rects; _i < rects_3.length; _i++) {
  12070. var rect = rects_3[_i];
  12071. for (var col = rect.span.start; col < rect.span.end; col += 1) {
  12072. rectsByEachCol[col].push(rect);
  12073. }
  12074. }
  12075. return rectsByEachCol;
  12076. }
  12077. function resliceSeg(seg, spanStart, spanEnd, cells) {
  12078. if (seg.firstCol === spanStart && seg.lastCol === spanEnd - 1) {
  12079. return seg;
  12080. }
  12081. var eventRange = seg.eventRange;
  12082. var origRange = eventRange.range;
  12083. var slicedRange = intersectRanges(origRange, {
  12084. start: cells[spanStart].date,
  12085. end: addDays(cells[spanEnd - 1].date, 1),
  12086. });
  12087. return __assign(__assign({}, seg), { firstCol: spanStart, lastCol: spanEnd - 1, eventRange: {
  12088. def: eventRange.def,
  12089. ui: __assign(__assign({}, eventRange.ui), { durationEditable: false }),
  12090. instance: eventRange.instance,
  12091. range: slicedRange,
  12092. }, isStart: seg.isStart && slicedRange.start.valueOf() === origRange.start.valueOf(), isEnd: seg.isEnd && slicedRange.end.valueOf() === origRange.end.valueOf() });
  12093. }
  12094. var DayGridSegHierarchy = /** @class */ (function (_super) {
  12095. __extends(DayGridSegHierarchy, _super);
  12096. function DayGridSegHierarchy() {
  12097. var _this = _super !== null && _super.apply(this, arguments) || this;
  12098. // config
  12099. _this.hiddenConsumes = false;
  12100. // allows us to keep hidden entries in the hierarchy so they take up space
  12101. _this.forceHidden = {};
  12102. return _this;
  12103. }
  12104. DayGridSegHierarchy.prototype.addSegs = function (segInputs) {
  12105. var _this = this;
  12106. var hiddenSegs = _super.prototype.addSegs.call(this, segInputs);
  12107. var entriesByLevel = this.entriesByLevel;
  12108. var excludeHidden = function (entry) { return !_this.forceHidden[buildEntryKey(entry)]; };
  12109. // remove the forced-hidden segs
  12110. for (var level = 0; level < entriesByLevel.length; level += 1) {
  12111. entriesByLevel[level] = entriesByLevel[level].filter(excludeHidden);
  12112. }
  12113. return hiddenSegs;
  12114. };
  12115. DayGridSegHierarchy.prototype.handleInvalidInsertion = function (insertion, entry, hiddenEntries) {
  12116. var _a = this, entriesByLevel = _a.entriesByLevel, forceHidden = _a.forceHidden;
  12117. var touchingLevel = insertion.touchingLevel;
  12118. if (this.hiddenConsumes && touchingLevel >= 0) {
  12119. for (var lateral = insertion.lateralStart; lateral < insertion.lateralEnd; lateral += 1) {
  12120. var leadingEntry = entriesByLevel[touchingLevel][lateral];
  12121. if (this.allowReslicing) {
  12122. var placeholderEntry = __assign(__assign({}, leadingEntry), { span: intersectSpans(leadingEntry.span, entry.span) });
  12123. var placeholderEntryId = buildEntryKey(placeholderEntry);
  12124. if (!forceHidden[placeholderEntryId]) { // if not already hidden
  12125. forceHidden[placeholderEntryId] = true;
  12126. entriesByLevel[touchingLevel][lateral] = placeholderEntry; // replace leadingEntry with our placeholder
  12127. this.splitEntry(leadingEntry, entry, hiddenEntries); // split up the leadingEntry, reinsert it
  12128. }
  12129. }
  12130. else {
  12131. var placeholderEntryId = buildEntryKey(leadingEntry);
  12132. if (!forceHidden[placeholderEntryId]) {
  12133. forceHidden[placeholderEntryId] = true;
  12134. hiddenEntries.push(leadingEntry);
  12135. }
  12136. }
  12137. }
  12138. }
  12139. return _super.prototype.handleInvalidInsertion.call(this, insertion, entry, hiddenEntries);
  12140. };
  12141. return DayGridSegHierarchy;
  12142. }(SegHierarchy));
  12143. var TableRow = /** @class */ (function (_super) {
  12144. __extends(TableRow, _super);
  12145. function TableRow() {
  12146. var _this = _super !== null && _super.apply(this, arguments) || this;
  12147. _this.cellElRefs = new RefMap(); // the <td>
  12148. _this.frameElRefs = new RefMap(); // the fc-daygrid-day-frame
  12149. _this.fgElRefs = new RefMap(); // the fc-daygrid-day-events
  12150. _this.segHarnessRefs = new RefMap(); // indexed by "instanceId:firstCol"
  12151. _this.rootElRef = createRef();
  12152. _this.state = {
  12153. framePositions: null,
  12154. maxContentHeight: null,
  12155. eventInstanceHeights: {},
  12156. };
  12157. return _this;
  12158. }
  12159. TableRow.prototype.render = function () {
  12160. var _this = this;
  12161. var _a = this, props = _a.props, state = _a.state, context = _a.context;
  12162. var options = context.options;
  12163. var colCnt = props.cells.length;
  12164. var businessHoursByCol = splitSegsByFirstCol(props.businessHourSegs, colCnt);
  12165. var bgEventSegsByCol = splitSegsByFirstCol(props.bgEventSegs, colCnt);
  12166. var highlightSegsByCol = splitSegsByFirstCol(this.getHighlightSegs(), colCnt);
  12167. var mirrorSegsByCol = splitSegsByFirstCol(this.getMirrorSegs(), colCnt);
  12168. var _b = computeFgSegPlacement(sortEventSegs(props.fgEventSegs, options.eventOrder), props.dayMaxEvents, props.dayMaxEventRows, options.eventOrderStrict, state.eventInstanceHeights, state.maxContentHeight, props.cells), singleColPlacements = _b.singleColPlacements, multiColPlacements = _b.multiColPlacements, moreCnts = _b.moreCnts, moreMarginTops = _b.moreMarginTops;
  12169. var isForcedInvisible = // TODO: messy way to compute this
  12170. (props.eventDrag && props.eventDrag.affectedInstances) ||
  12171. (props.eventResize && props.eventResize.affectedInstances) ||
  12172. {};
  12173. return (createElement("tr", { ref: this.rootElRef },
  12174. props.renderIntro && props.renderIntro(),
  12175. props.cells.map(function (cell, col) {
  12176. var normalFgNodes = _this.renderFgSegs(col, props.forPrint ? singleColPlacements[col] : multiColPlacements[col], props.todayRange, isForcedInvisible);
  12177. var mirrorFgNodes = _this.renderFgSegs(col, buildMirrorPlacements(mirrorSegsByCol[col], multiColPlacements), props.todayRange, {}, Boolean(props.eventDrag), Boolean(props.eventResize), false);
  12178. return (createElement(TableCell, { key: cell.key, elRef: _this.cellElRefs.createRef(cell.key), innerElRef: _this.frameElRefs.createRef(cell.key) /* FF <td> problem, but okay to use for left/right. TODO: rename prop */, dateProfile: props.dateProfile, date: cell.date, showDayNumber: props.showDayNumbers, showWeekNumber: props.showWeekNumbers && col === 0, forceDayTop: props.showWeekNumbers /* even displaying weeknum for row, not necessarily day */, todayRange: props.todayRange, eventSelection: props.eventSelection, eventDrag: props.eventDrag, eventResize: props.eventResize, extraHookProps: cell.extraHookProps, extraDataAttrs: cell.extraDataAttrs, extraClassNames: cell.extraClassNames, extraDateSpan: cell.extraDateSpan, moreCnt: moreCnts[col], moreMarginTop: moreMarginTops[col], singlePlacements: singleColPlacements[col], fgContentElRef: _this.fgElRefs.createRef(cell.key), fgContent: ( // Fragment scopes the keys
  12179. createElement(Fragment, null,
  12180. createElement(Fragment, null, normalFgNodes),
  12181. createElement(Fragment, null, mirrorFgNodes))), bgContent: ( // Fragment scopes the keys
  12182. createElement(Fragment, null,
  12183. _this.renderFillSegs(highlightSegsByCol[col], 'highlight'),
  12184. _this.renderFillSegs(businessHoursByCol[col], 'non-business'),
  12185. _this.renderFillSegs(bgEventSegsByCol[col], 'bg-event'))) }));
  12186. })));
  12187. };
  12188. TableRow.prototype.componentDidMount = function () {
  12189. this.updateSizing(true);
  12190. };
  12191. TableRow.prototype.componentDidUpdate = function (prevProps, prevState) {
  12192. var currentProps = this.props;
  12193. this.updateSizing(!isPropsEqual(prevProps, currentProps));
  12194. };
  12195. TableRow.prototype.getHighlightSegs = function () {
  12196. var props = this.props;
  12197. if (props.eventDrag && props.eventDrag.segs.length) { // messy check
  12198. return props.eventDrag.segs;
  12199. }
  12200. if (props.eventResize && props.eventResize.segs.length) { // messy check
  12201. return props.eventResize.segs;
  12202. }
  12203. return props.dateSelectionSegs;
  12204. };
  12205. TableRow.prototype.getMirrorSegs = function () {
  12206. var props = this.props;
  12207. if (props.eventResize && props.eventResize.segs.length) { // messy check
  12208. return props.eventResize.segs;
  12209. }
  12210. return [];
  12211. };
  12212. TableRow.prototype.renderFgSegs = function (col, segPlacements, todayRange, isForcedInvisible, isDragging, isResizing, isDateSelecting) {
  12213. var context = this.context;
  12214. var eventSelection = this.props.eventSelection;
  12215. var framePositions = this.state.framePositions;
  12216. var defaultDisplayEventEnd = this.props.cells.length === 1; // colCnt === 1
  12217. var isMirror = isDragging || isResizing || isDateSelecting;
  12218. var nodes = [];
  12219. if (framePositions) {
  12220. for (var _i = 0, segPlacements_1 = segPlacements; _i < segPlacements_1.length; _i++) {
  12221. var placement = segPlacements_1[_i];
  12222. var seg = placement.seg;
  12223. var instanceId = seg.eventRange.instance.instanceId;
  12224. var key = instanceId + ':' + col;
  12225. var isVisible = placement.isVisible && !isForcedInvisible[instanceId];
  12226. var isAbsolute = placement.isAbsolute;
  12227. var left = '';
  12228. var right = '';
  12229. if (isAbsolute) {
  12230. if (context.isRtl) {
  12231. right = 0;
  12232. left = framePositions.lefts[seg.lastCol] - framePositions.lefts[seg.firstCol];
  12233. }
  12234. else {
  12235. left = 0;
  12236. right = framePositions.rights[seg.firstCol] - framePositions.rights[seg.lastCol];
  12237. }
  12238. }
  12239. /*
  12240. known bug: events that are force to be list-item but span multiple days still take up space in later columns
  12241. todo: in print view, for multi-day events, don't display title within non-start/end segs
  12242. */
  12243. nodes.push(createElement("div", { className: 'fc-daygrid-event-harness' + (isAbsolute ? ' fc-daygrid-event-harness-abs' : ''), key: key, ref: isMirror ? null : this.segHarnessRefs.createRef(key), style: {
  12244. visibility: isVisible ? '' : 'hidden',
  12245. marginTop: isAbsolute ? '' : placement.marginTop,
  12246. top: isAbsolute ? placement.absoluteTop : '',
  12247. left: left,
  12248. right: right,
  12249. } }, hasListItemDisplay(seg) ? (createElement(TableListItemEvent, __assign({ seg: seg, isDragging: isDragging, isSelected: instanceId === eventSelection, defaultDisplayEventEnd: defaultDisplayEventEnd }, getSegMeta(seg, todayRange)))) : (createElement(TableBlockEvent, __assign({ seg: seg, isDragging: isDragging, isResizing: isResizing, isDateSelecting: isDateSelecting, isSelected: instanceId === eventSelection, defaultDisplayEventEnd: defaultDisplayEventEnd }, getSegMeta(seg, todayRange))))));
  12250. }
  12251. }
  12252. return nodes;
  12253. };
  12254. TableRow.prototype.renderFillSegs = function (segs, fillType) {
  12255. var isRtl = this.context.isRtl;
  12256. var todayRange = this.props.todayRange;
  12257. var framePositions = this.state.framePositions;
  12258. var nodes = [];
  12259. if (framePositions) {
  12260. for (var _i = 0, segs_1 = segs; _i < segs_1.length; _i++) {
  12261. var seg = segs_1[_i];
  12262. var leftRightCss = isRtl ? {
  12263. right: 0,
  12264. left: framePositions.lefts[seg.lastCol] - framePositions.lefts[seg.firstCol],
  12265. } : {
  12266. left: 0,
  12267. right: framePositions.rights[seg.firstCol] - framePositions.rights[seg.lastCol],
  12268. };
  12269. nodes.push(createElement("div", { key: buildEventRangeKey(seg.eventRange), className: "fc-daygrid-bg-harness", style: leftRightCss }, fillType === 'bg-event' ?
  12270. createElement(BgEvent, __assign({ seg: seg }, getSegMeta(seg, todayRange))) :
  12271. renderFill(fillType)));
  12272. }
  12273. }
  12274. return createElement.apply(void 0, __spreadArray([Fragment, {}], nodes));
  12275. };
  12276. TableRow.prototype.updateSizing = function (isExternalSizingChange) {
  12277. var _a = this, props = _a.props, frameElRefs = _a.frameElRefs;
  12278. if (!props.forPrint &&
  12279. props.clientWidth !== null // positioning ready?
  12280. ) {
  12281. if (isExternalSizingChange) {
  12282. var frameEls = props.cells.map(function (cell) { return frameElRefs.currentMap[cell.key]; });
  12283. if (frameEls.length) {
  12284. var originEl = this.rootElRef.current;
  12285. this.setState({
  12286. framePositions: new PositionCache(originEl, frameEls, true, // isHorizontal
  12287. false),
  12288. });
  12289. }
  12290. }
  12291. var limitByContentHeight = props.dayMaxEvents === true || props.dayMaxEventRows === true;
  12292. this.setState({
  12293. eventInstanceHeights: this.queryEventInstanceHeights(),
  12294. maxContentHeight: limitByContentHeight ? this.computeMaxContentHeight() : null,
  12295. });
  12296. }
  12297. };
  12298. TableRow.prototype.queryEventInstanceHeights = function () {
  12299. var segElMap = this.segHarnessRefs.currentMap;
  12300. var eventInstanceHeights = {};
  12301. // get the max height amongst instance segs
  12302. for (var key in segElMap) {
  12303. var height = Math.round(segElMap[key].getBoundingClientRect().height);
  12304. var instanceId = key.split(':')[0]; // deconstruct how renderFgSegs makes the key
  12305. eventInstanceHeights[instanceId] = Math.max(eventInstanceHeights[instanceId] || 0, height);
  12306. }
  12307. return eventInstanceHeights;
  12308. };
  12309. TableRow.prototype.computeMaxContentHeight = function () {
  12310. var firstKey = this.props.cells[0].key;
  12311. var cellEl = this.cellElRefs.currentMap[firstKey];
  12312. var fcContainerEl = this.fgElRefs.currentMap[firstKey];
  12313. return cellEl.getBoundingClientRect().bottom - fcContainerEl.getBoundingClientRect().top;
  12314. };
  12315. TableRow.prototype.getCellEls = function () {
  12316. var elMap = this.cellElRefs.currentMap;
  12317. return this.props.cells.map(function (cell) { return elMap[cell.key]; });
  12318. };
  12319. return TableRow;
  12320. }(DateComponent));
  12321. TableRow.addStateEquality({
  12322. eventInstanceHeights: isPropsEqual,
  12323. });
  12324. function buildMirrorPlacements(mirrorSegs, colPlacements) {
  12325. if (!mirrorSegs.length) {
  12326. return [];
  12327. }
  12328. var topsByInstanceId = buildAbsoluteTopHash(colPlacements); // TODO: cache this at first render?
  12329. return mirrorSegs.map(function (seg) { return ({
  12330. seg: seg,
  12331. isVisible: true,
  12332. isAbsolute: true,
  12333. absoluteTop: topsByInstanceId[seg.eventRange.instance.instanceId],
  12334. marginTop: 0,
  12335. }); });
  12336. }
  12337. function buildAbsoluteTopHash(colPlacements) {
  12338. var topsByInstanceId = {};
  12339. for (var _i = 0, colPlacements_1 = colPlacements; _i < colPlacements_1.length; _i++) {
  12340. var placements = colPlacements_1[_i];
  12341. for (var _a = 0, placements_1 = placements; _a < placements_1.length; _a++) {
  12342. var placement = placements_1[_a];
  12343. topsByInstanceId[placement.seg.eventRange.instance.instanceId] = placement.absoluteTop;
  12344. }
  12345. }
  12346. return colPlacements;
  12347. }
  12348. var Table = /** @class */ (function (_super) {
  12349. __extends(Table, _super);
  12350. function Table() {
  12351. var _this = _super !== null && _super.apply(this, arguments) || this;
  12352. _this.splitBusinessHourSegs = memoize(splitSegsByRow);
  12353. _this.splitBgEventSegs = memoize(splitSegsByRow);
  12354. _this.splitFgEventSegs = memoize(splitSegsByRow);
  12355. _this.splitDateSelectionSegs = memoize(splitSegsByRow);
  12356. _this.splitEventDrag = memoize(splitInteractionByRow);
  12357. _this.splitEventResize = memoize(splitInteractionByRow);
  12358. _this.rowRefs = new RefMap();
  12359. _this.handleRootEl = function (rootEl) {
  12360. _this.rootEl = rootEl;
  12361. if (rootEl) {
  12362. _this.context.registerInteractiveComponent(_this, {
  12363. el: rootEl,
  12364. isHitComboAllowed: _this.props.isHitComboAllowed,
  12365. });
  12366. }
  12367. else {
  12368. _this.context.unregisterInteractiveComponent(_this);
  12369. }
  12370. };
  12371. return _this;
  12372. }
  12373. Table.prototype.render = function () {
  12374. var _this = this;
  12375. var props = this.props;
  12376. var dateProfile = props.dateProfile, dayMaxEventRows = props.dayMaxEventRows, dayMaxEvents = props.dayMaxEvents, expandRows = props.expandRows;
  12377. var rowCnt = props.cells.length;
  12378. var businessHourSegsByRow = this.splitBusinessHourSegs(props.businessHourSegs, rowCnt);
  12379. var bgEventSegsByRow = this.splitBgEventSegs(props.bgEventSegs, rowCnt);
  12380. var fgEventSegsByRow = this.splitFgEventSegs(props.fgEventSegs, rowCnt);
  12381. var dateSelectionSegsByRow = this.splitDateSelectionSegs(props.dateSelectionSegs, rowCnt);
  12382. var eventDragByRow = this.splitEventDrag(props.eventDrag, rowCnt);
  12383. var eventResizeByRow = this.splitEventResize(props.eventResize, rowCnt);
  12384. var limitViaBalanced = dayMaxEvents === true || dayMaxEventRows === true;
  12385. // if rows can't expand to fill fixed height, can't do balanced-height event limit
  12386. // TODO: best place to normalize these options?
  12387. if (limitViaBalanced && !expandRows) {
  12388. limitViaBalanced = false;
  12389. dayMaxEventRows = null;
  12390. dayMaxEvents = null;
  12391. }
  12392. var classNames = [
  12393. 'fc-daygrid-body',
  12394. limitViaBalanced ? 'fc-daygrid-body-balanced' : 'fc-daygrid-body-unbalanced',
  12395. expandRows ? '' : 'fc-daygrid-body-natural', // will height of one row depend on the others?
  12396. ];
  12397. return (createElement("div", { className: classNames.join(' '), ref: this.handleRootEl, style: {
  12398. // these props are important to give this wrapper correct dimensions for interactions
  12399. // TODO: if we set it here, can we avoid giving to inner tables?
  12400. width: props.clientWidth,
  12401. minWidth: props.tableMinWidth,
  12402. } },
  12403. createElement(NowTimer, { unit: "day" }, function (nowDate, todayRange) { return (createElement(Fragment, null,
  12404. createElement("table", { className: "fc-scrollgrid-sync-table", style: {
  12405. width: props.clientWidth,
  12406. minWidth: props.tableMinWidth,
  12407. height: expandRows ? props.clientHeight : '',
  12408. } },
  12409. props.colGroupNode,
  12410. createElement("tbody", null, props.cells.map(function (cells, row) { return (createElement(TableRow, { ref: _this.rowRefs.createRef(row), key: cells.length
  12411. ? cells[0].date.toISOString() /* best? or put key on cell? or use diff formatter? */
  12412. : row // in case there are no cells (like when resource view is loading)
  12413. , showDayNumbers: rowCnt > 1, showWeekNumbers: props.showWeekNumbers, todayRange: todayRange, dateProfile: dateProfile, cells: cells, renderIntro: props.renderRowIntro, businessHourSegs: businessHourSegsByRow[row], eventSelection: props.eventSelection, bgEventSegs: bgEventSegsByRow[row].filter(isSegAllDay) /* hack */, fgEventSegs: fgEventSegsByRow[row], dateSelectionSegs: dateSelectionSegsByRow[row], eventDrag: eventDragByRow[row], eventResize: eventResizeByRow[row], dayMaxEvents: dayMaxEvents, dayMaxEventRows: dayMaxEventRows, clientWidth: props.clientWidth, clientHeight: props.clientHeight, forPrint: props.forPrint })); }))))); })));
  12414. };
  12415. // Hit System
  12416. // ----------------------------------------------------------------------------------------------------
  12417. Table.prototype.prepareHits = function () {
  12418. this.rowPositions = new PositionCache(this.rootEl, this.rowRefs.collect().map(function (rowObj) { return rowObj.getCellEls()[0]; }), // first cell el in each row. TODO: not optimal
  12419. false, true);
  12420. this.colPositions = new PositionCache(this.rootEl, this.rowRefs.currentMap[0].getCellEls(), // cell els in first row
  12421. true, // horizontal
  12422. false);
  12423. };
  12424. Table.prototype.queryHit = function (positionLeft, positionTop) {
  12425. var _a = this, colPositions = _a.colPositions, rowPositions = _a.rowPositions;
  12426. var col = colPositions.leftToIndex(positionLeft);
  12427. var row = rowPositions.topToIndex(positionTop);
  12428. if (row != null && col != null) {
  12429. var cell = this.props.cells[row][col];
  12430. return {
  12431. dateProfile: this.props.dateProfile,
  12432. dateSpan: __assign({ range: this.getCellRange(row, col), allDay: true }, cell.extraDateSpan),
  12433. dayEl: this.getCellEl(row, col),
  12434. rect: {
  12435. left: colPositions.lefts[col],
  12436. right: colPositions.rights[col],
  12437. top: rowPositions.tops[row],
  12438. bottom: rowPositions.bottoms[row],
  12439. },
  12440. layer: 0,
  12441. };
  12442. }
  12443. return null;
  12444. };
  12445. Table.prototype.getCellEl = function (row, col) {
  12446. return this.rowRefs.currentMap[row].getCellEls()[col]; // TODO: not optimal
  12447. };
  12448. Table.prototype.getCellRange = function (row, col) {
  12449. var start = this.props.cells[row][col].date;
  12450. var end = addDays(start, 1);
  12451. return { start: start, end: end };
  12452. };
  12453. return Table;
  12454. }(DateComponent));
  12455. function isSegAllDay(seg) {
  12456. return seg.eventRange.def.allDay;
  12457. }
  12458. var DayTableSlicer = /** @class */ (function (_super) {
  12459. __extends(DayTableSlicer, _super);
  12460. function DayTableSlicer() {
  12461. var _this = _super !== null && _super.apply(this, arguments) || this;
  12462. _this.forceDayIfListItem = true;
  12463. return _this;
  12464. }
  12465. DayTableSlicer.prototype.sliceRange = function (dateRange, dayTableModel) {
  12466. return dayTableModel.sliceRange(dateRange);
  12467. };
  12468. return DayTableSlicer;
  12469. }(Slicer));
  12470. var DayTable = /** @class */ (function (_super) {
  12471. __extends(DayTable, _super);
  12472. function DayTable() {
  12473. var _this = _super !== null && _super.apply(this, arguments) || this;
  12474. _this.slicer = new DayTableSlicer();
  12475. _this.tableRef = createRef();
  12476. return _this;
  12477. }
  12478. DayTable.prototype.render = function () {
  12479. var _a = this, props = _a.props, context = _a.context;
  12480. return (createElement(Table, __assign({ ref: this.tableRef }, this.slicer.sliceProps(props, props.dateProfile, props.nextDayThreshold, context, props.dayTableModel), { dateProfile: props.dateProfile, cells: props.dayTableModel.cells, colGroupNode: props.colGroupNode, tableMinWidth: props.tableMinWidth, renderRowIntro: props.renderRowIntro, dayMaxEvents: props.dayMaxEvents, dayMaxEventRows: props.dayMaxEventRows, showWeekNumbers: props.showWeekNumbers, expandRows: props.expandRows, headerAlignElRef: props.headerAlignElRef, clientWidth: props.clientWidth, clientHeight: props.clientHeight, forPrint: props.forPrint })));
  12481. };
  12482. return DayTable;
  12483. }(DateComponent));
  12484. var DayTableView = /** @class */ (function (_super) {
  12485. __extends(DayTableView, _super);
  12486. function DayTableView() {
  12487. var _this = _super !== null && _super.apply(this, arguments) || this;
  12488. _this.buildDayTableModel = memoize(buildDayTableModel);
  12489. _this.headerRef = createRef();
  12490. _this.tableRef = createRef();
  12491. return _this;
  12492. }
  12493. DayTableView.prototype.render = function () {
  12494. var _this = this;
  12495. var _a = this.context, options = _a.options, dateProfileGenerator = _a.dateProfileGenerator;
  12496. var props = this.props;
  12497. var dayTableModel = this.buildDayTableModel(props.dateProfile, dateProfileGenerator);
  12498. var headerContent = options.dayHeaders && (createElement(DayHeader, { ref: this.headerRef, dateProfile: props.dateProfile, dates: dayTableModel.headerDates, datesRepDistinctDays: dayTableModel.rowCnt === 1 }));
  12499. var bodyContent = function (contentArg) { return (createElement(DayTable, { ref: _this.tableRef, dateProfile: props.dateProfile, dayTableModel: dayTableModel, businessHours: props.businessHours, dateSelection: props.dateSelection, eventStore: props.eventStore, eventUiBases: props.eventUiBases, eventSelection: props.eventSelection, eventDrag: props.eventDrag, eventResize: props.eventResize, nextDayThreshold: options.nextDayThreshold, colGroupNode: contentArg.tableColGroupNode, tableMinWidth: contentArg.tableMinWidth, dayMaxEvents: options.dayMaxEvents, dayMaxEventRows: options.dayMaxEventRows, showWeekNumbers: options.weekNumbers, expandRows: !props.isHeightAuto, headerAlignElRef: _this.headerElRef, clientWidth: contentArg.clientWidth, clientHeight: contentArg.clientHeight, forPrint: props.forPrint })); };
  12500. return options.dayMinWidth
  12501. ? this.renderHScrollLayout(headerContent, bodyContent, dayTableModel.colCnt, options.dayMinWidth)
  12502. : this.renderSimpleLayout(headerContent, bodyContent);
  12503. };
  12504. return DayTableView;
  12505. }(TableView));
  12506. function buildDayTableModel(dateProfile, dateProfileGenerator) {
  12507. var daySeries = new DaySeriesModel(dateProfile.renderRange, dateProfileGenerator);
  12508. return new DayTableModel(daySeries, /year|month|week/.test(dateProfile.currentRangeUnit));
  12509. }
  12510. var TableDateProfileGenerator = /** @class */ (function (_super) {
  12511. __extends(TableDateProfileGenerator, _super);
  12512. function TableDateProfileGenerator() {
  12513. return _super !== null && _super.apply(this, arguments) || this;
  12514. }
  12515. // Computes the date range that will be rendered.
  12516. TableDateProfileGenerator.prototype.buildRenderRange = function (currentRange, currentRangeUnit, isRangeAllDay) {
  12517. var dateEnv = this.props.dateEnv;
  12518. var renderRange = _super.prototype.buildRenderRange.call(this, currentRange, currentRangeUnit, isRangeAllDay);
  12519. var start = renderRange.start;
  12520. var end = renderRange.end;
  12521. var endOfWeek;
  12522. // year and month views should be aligned with weeks. this is already done for week
  12523. if (/^(year|month)$/.test(currentRangeUnit)) {
  12524. start = dateEnv.startOfWeek(start);
  12525. // make end-of-week if not already
  12526. endOfWeek = dateEnv.startOfWeek(end);
  12527. if (endOfWeek.valueOf() !== end.valueOf()) {
  12528. end = addWeeks(endOfWeek, 1);
  12529. }
  12530. }
  12531. // ensure 6 weeks
  12532. if (this.props.monthMode &&
  12533. this.props.fixedWeekCount) {
  12534. var rowCnt = Math.ceil(// could be partial weeks due to hiddenDays
  12535. diffWeeks(start, end));
  12536. end = addWeeks(end, 6 - rowCnt);
  12537. }
  12538. return { start: start, end: end };
  12539. };
  12540. return TableDateProfileGenerator;
  12541. }(DateProfileGenerator));
  12542. var dayGridPlugin = createPlugin({
  12543. initialView: 'dayGridMonth',
  12544. views: {
  12545. dayGrid: {
  12546. component: DayTableView,
  12547. dateProfileGeneratorClass: TableDateProfileGenerator,
  12548. },
  12549. dayGridDay: {
  12550. type: 'dayGrid',
  12551. duration: { days: 1 },
  12552. },
  12553. dayGridWeek: {
  12554. type: 'dayGrid',
  12555. duration: { weeks: 1 },
  12556. },
  12557. dayGridMonth: {
  12558. type: 'dayGrid',
  12559. duration: { months: 1 },
  12560. monthMode: true,
  12561. fixedWeekCount: true,
  12562. },
  12563. },
  12564. });
  12565. var AllDaySplitter = /** @class */ (function (_super) {
  12566. __extends(AllDaySplitter, _super);
  12567. function AllDaySplitter() {
  12568. return _super !== null && _super.apply(this, arguments) || this;
  12569. }
  12570. AllDaySplitter.prototype.getKeyInfo = function () {
  12571. return {
  12572. allDay: {},
  12573. timed: {},
  12574. };
  12575. };
  12576. AllDaySplitter.prototype.getKeysForDateSpan = function (dateSpan) {
  12577. if (dateSpan.allDay) {
  12578. return ['allDay'];
  12579. }
  12580. return ['timed'];
  12581. };
  12582. AllDaySplitter.prototype.getKeysForEventDef = function (eventDef) {
  12583. if (!eventDef.allDay) {
  12584. return ['timed'];
  12585. }
  12586. if (hasBgRendering(eventDef)) {
  12587. return ['timed', 'allDay'];
  12588. }
  12589. return ['allDay'];
  12590. };
  12591. return AllDaySplitter;
  12592. }(Splitter));
  12593. var DEFAULT_SLAT_LABEL_FORMAT = createFormatter({
  12594. hour: 'numeric',
  12595. minute: '2-digit',
  12596. omitZeroMinute: true,
  12597. meridiem: 'short',
  12598. });
  12599. function TimeColsAxisCell(props) {
  12600. var classNames = [
  12601. 'fc-timegrid-slot',
  12602. 'fc-timegrid-slot-label',
  12603. props.isLabeled ? 'fc-scrollgrid-shrink' : 'fc-timegrid-slot-minor',
  12604. ];
  12605. return (createElement(ViewContextType.Consumer, null, function (context) {
  12606. if (!props.isLabeled) {
  12607. return (createElement("td", { className: classNames.join(' '), "data-time": props.isoTimeStr }));
  12608. }
  12609. var dateEnv = context.dateEnv, options = context.options, viewApi = context.viewApi;
  12610. var labelFormat = // TODO: fully pre-parse
  12611. options.slotLabelFormat == null ? DEFAULT_SLAT_LABEL_FORMAT :
  12612. Array.isArray(options.slotLabelFormat) ? createFormatter(options.slotLabelFormat[0]) :
  12613. createFormatter(options.slotLabelFormat);
  12614. var hookProps = {
  12615. level: 0,
  12616. time: props.time,
  12617. date: dateEnv.toDate(props.date),
  12618. view: viewApi,
  12619. text: dateEnv.format(props.date, labelFormat),
  12620. };
  12621. return (createElement(RenderHook, { hookProps: hookProps, classNames: options.slotLabelClassNames, content: options.slotLabelContent, defaultContent: renderInnerContent$1, didMount: options.slotLabelDidMount, willUnmount: options.slotLabelWillUnmount }, function (rootElRef, customClassNames, innerElRef, innerContent) { return (createElement("td", { ref: rootElRef, className: classNames.concat(customClassNames).join(' '), "data-time": props.isoTimeStr },
  12622. createElement("div", { className: "fc-timegrid-slot-label-frame fc-scrollgrid-shrink-frame" },
  12623. createElement("div", { className: "fc-timegrid-slot-label-cushion fc-scrollgrid-shrink-cushion", ref: innerElRef }, innerContent)))); }));
  12624. }));
  12625. }
  12626. function renderInnerContent$1(props) {
  12627. return props.text;
  12628. }
  12629. var TimeBodyAxis = /** @class */ (function (_super) {
  12630. __extends(TimeBodyAxis, _super);
  12631. function TimeBodyAxis() {
  12632. return _super !== null && _super.apply(this, arguments) || this;
  12633. }
  12634. TimeBodyAxis.prototype.render = function () {
  12635. return this.props.slatMetas.map(function (slatMeta) { return (createElement("tr", { key: slatMeta.key },
  12636. createElement(TimeColsAxisCell, __assign({}, slatMeta)))); });
  12637. };
  12638. return TimeBodyAxis;
  12639. }(BaseComponent));
  12640. var DEFAULT_WEEK_NUM_FORMAT = createFormatter({ week: 'short' });
  12641. var AUTO_ALL_DAY_MAX_EVENT_ROWS = 5;
  12642. var TimeColsView = /** @class */ (function (_super) {
  12643. __extends(TimeColsView, _super);
  12644. function TimeColsView() {
  12645. var _this = _super !== null && _super.apply(this, arguments) || this;
  12646. _this.allDaySplitter = new AllDaySplitter(); // for use by subclasses
  12647. _this.headerElRef = createRef();
  12648. _this.rootElRef = createRef();
  12649. _this.scrollerElRef = createRef();
  12650. _this.state = {
  12651. slatCoords: null,
  12652. };
  12653. _this.handleScrollTopRequest = function (scrollTop) {
  12654. var scrollerEl = _this.scrollerElRef.current;
  12655. if (scrollerEl) { // TODO: not sure how this could ever be null. weirdness with the reducer
  12656. scrollerEl.scrollTop = scrollTop;
  12657. }
  12658. };
  12659. /* Header Render Methods
  12660. ------------------------------------------------------------------------------------------------------------------*/
  12661. _this.renderHeadAxis = function (rowKey, frameHeight) {
  12662. if (frameHeight === void 0) { frameHeight = ''; }
  12663. var options = _this.context.options;
  12664. var dateProfile = _this.props.dateProfile;
  12665. var range = dateProfile.renderRange;
  12666. var dayCnt = diffDays(range.start, range.end);
  12667. var navLinkAttrs = (options.navLinks && dayCnt === 1) // only do in day views (to avoid doing in week views that dont need it)
  12668. ? { 'data-navlink': buildNavLinkData(range.start, 'week'), tabIndex: 0 }
  12669. : {};
  12670. if (options.weekNumbers && rowKey === 'day') {
  12671. return (createElement(WeekNumberRoot, { date: range.start, defaultFormat: DEFAULT_WEEK_NUM_FORMAT }, function (rootElRef, classNames, innerElRef, innerContent) { return (createElement("th", { ref: rootElRef, className: [
  12672. 'fc-timegrid-axis',
  12673. 'fc-scrollgrid-shrink',
  12674. ].concat(classNames).join(' ') },
  12675. createElement("div", { className: "fc-timegrid-axis-frame fc-scrollgrid-shrink-frame fc-timegrid-axis-frame-liquid", style: { height: frameHeight } },
  12676. createElement("a", __assign({ ref: innerElRef, className: "fc-timegrid-axis-cushion fc-scrollgrid-shrink-cushion fc-scrollgrid-sync-inner" }, navLinkAttrs), innerContent)))); }));
  12677. }
  12678. return (createElement("th", { className: "fc-timegrid-axis" },
  12679. createElement("div", { className: "fc-timegrid-axis-frame", style: { height: frameHeight } })));
  12680. };
  12681. /* Table Component Render Methods
  12682. ------------------------------------------------------------------------------------------------------------------*/
  12683. // only a one-way height sync. we don't send the axis inner-content height to the DayGrid,
  12684. // but DayGrid still needs to have classNames on inner elements in order to measure.
  12685. _this.renderTableRowAxis = function (rowHeight) {
  12686. var _a = _this.context, options = _a.options, viewApi = _a.viewApi;
  12687. var hookProps = {
  12688. text: options.allDayText,
  12689. view: viewApi,
  12690. };
  12691. return (
  12692. // TODO: make reusable hook. used in list view too
  12693. createElement(RenderHook, { hookProps: hookProps, classNames: options.allDayClassNames, content: options.allDayContent, defaultContent: renderAllDayInner$1, didMount: options.allDayDidMount, willUnmount: options.allDayWillUnmount }, function (rootElRef, classNames, innerElRef, innerContent) { return (createElement("td", { ref: rootElRef, className: [
  12694. 'fc-timegrid-axis',
  12695. 'fc-scrollgrid-shrink',
  12696. ].concat(classNames).join(' ') },
  12697. createElement("div", { className: 'fc-timegrid-axis-frame fc-scrollgrid-shrink-frame' + (rowHeight == null ? ' fc-timegrid-axis-frame-liquid' : ''), style: { height: rowHeight } },
  12698. createElement("span", { className: "fc-timegrid-axis-cushion fc-scrollgrid-shrink-cushion fc-scrollgrid-sync-inner", ref: innerElRef }, innerContent)))); }));
  12699. };
  12700. _this.handleSlatCoords = function (slatCoords) {
  12701. _this.setState({ slatCoords: slatCoords });
  12702. };
  12703. return _this;
  12704. }
  12705. // rendering
  12706. // ----------------------------------------------------------------------------------------------------
  12707. TimeColsView.prototype.renderSimpleLayout = function (headerRowContent, allDayContent, timeContent) {
  12708. var _a = this, context = _a.context, props = _a.props;
  12709. var sections = [];
  12710. var stickyHeaderDates = getStickyHeaderDates(context.options);
  12711. if (headerRowContent) {
  12712. sections.push({
  12713. type: 'header',
  12714. key: 'header',
  12715. isSticky: stickyHeaderDates,
  12716. chunk: {
  12717. elRef: this.headerElRef,
  12718. tableClassName: 'fc-col-header',
  12719. rowContent: headerRowContent,
  12720. },
  12721. });
  12722. }
  12723. if (allDayContent) {
  12724. sections.push({
  12725. type: 'body',
  12726. key: 'all-day',
  12727. chunk: { content: allDayContent },
  12728. });
  12729. sections.push({
  12730. type: 'body',
  12731. key: 'all-day-divider',
  12732. outerContent: ( // TODO: rename to cellContent so don't need to define <tr>?
  12733. createElement("tr", { className: "fc-scrollgrid-section" },
  12734. createElement("td", { className: 'fc-timegrid-divider ' + context.theme.getClass('tableCellShaded') }))),
  12735. });
  12736. }
  12737. sections.push({
  12738. type: 'body',
  12739. key: 'body',
  12740. liquid: true,
  12741. expandRows: Boolean(context.options.expandRows),
  12742. chunk: {
  12743. scrollerElRef: this.scrollerElRef,
  12744. content: timeContent,
  12745. },
  12746. });
  12747. return (createElement(ViewRoot, { viewSpec: context.viewSpec, elRef: this.rootElRef }, function (rootElRef, classNames) { return (createElement("div", { className: ['fc-timegrid'].concat(classNames).join(' '), ref: rootElRef },
  12748. createElement(SimpleScrollGrid, { liquid: !props.isHeightAuto && !props.forPrint, collapsibleWidth: props.forPrint, cols: [{ width: 'shrink' }], sections: sections }))); }));
  12749. };
  12750. TimeColsView.prototype.renderHScrollLayout = function (headerRowContent, allDayContent, timeContent, colCnt, dayMinWidth, slatMetas, slatCoords) {
  12751. var _this = this;
  12752. var ScrollGrid = this.context.pluginHooks.scrollGridImpl;
  12753. if (!ScrollGrid) {
  12754. throw new Error('No ScrollGrid implementation');
  12755. }
  12756. var _a = this, context = _a.context, props = _a.props;
  12757. var stickyHeaderDates = !props.forPrint && getStickyHeaderDates(context.options);
  12758. var stickyFooterScrollbar = !props.forPrint && getStickyFooterScrollbar(context.options);
  12759. var sections = [];
  12760. if (headerRowContent) {
  12761. sections.push({
  12762. type: 'header',
  12763. key: 'header',
  12764. isSticky: stickyHeaderDates,
  12765. syncRowHeights: true,
  12766. chunks: [
  12767. {
  12768. key: 'axis',
  12769. rowContent: function (arg) { return (createElement("tr", null, _this.renderHeadAxis('day', arg.rowSyncHeights[0]))); },
  12770. },
  12771. {
  12772. key: 'cols',
  12773. elRef: this.headerElRef,
  12774. tableClassName: 'fc-col-header',
  12775. rowContent: headerRowContent,
  12776. },
  12777. ],
  12778. });
  12779. }
  12780. if (allDayContent) {
  12781. sections.push({
  12782. type: 'body',
  12783. key: 'all-day',
  12784. syncRowHeights: true,
  12785. chunks: [
  12786. {
  12787. key: 'axis',
  12788. rowContent: function (contentArg) { return (createElement("tr", null, _this.renderTableRowAxis(contentArg.rowSyncHeights[0]))); },
  12789. },
  12790. {
  12791. key: 'cols',
  12792. content: allDayContent,
  12793. },
  12794. ],
  12795. });
  12796. sections.push({
  12797. key: 'all-day-divider',
  12798. type: 'body',
  12799. outerContent: ( // TODO: rename to cellContent so don't need to define <tr>?
  12800. createElement("tr", { className: "fc-scrollgrid-section" },
  12801. createElement("td", { colSpan: 2, className: 'fc-timegrid-divider ' + context.theme.getClass('tableCellShaded') }))),
  12802. });
  12803. }
  12804. var isNowIndicator = context.options.nowIndicator;
  12805. sections.push({
  12806. type: 'body',
  12807. key: 'body',
  12808. liquid: true,
  12809. expandRows: Boolean(context.options.expandRows),
  12810. chunks: [
  12811. {
  12812. key: 'axis',
  12813. content: function (arg) { return (
  12814. // TODO: make this now-indicator arrow more DRY with TimeColsContent
  12815. createElement("div", { className: "fc-timegrid-axis-chunk" },
  12816. createElement("table", { style: { height: arg.expandRows ? arg.clientHeight : '' } },
  12817. arg.tableColGroupNode,
  12818. createElement("tbody", null,
  12819. createElement(TimeBodyAxis, { slatMetas: slatMetas }))),
  12820. createElement("div", { className: "fc-timegrid-now-indicator-container" },
  12821. createElement(NowTimer, { unit: isNowIndicator ? 'minute' : 'day' /* hacky */ }, function (nowDate) {
  12822. var nowIndicatorTop = isNowIndicator &&
  12823. slatCoords &&
  12824. slatCoords.safeComputeTop(nowDate); // might return void
  12825. if (typeof nowIndicatorTop === 'number') {
  12826. return (createElement(NowIndicatorRoot, { isAxis: true, date: nowDate }, function (rootElRef, classNames, innerElRef, innerContent) { return (createElement("div", { ref: rootElRef, className: ['fc-timegrid-now-indicator-arrow'].concat(classNames).join(' '), style: { top: nowIndicatorTop } }, innerContent)); }));
  12827. }
  12828. return null;
  12829. })))); },
  12830. },
  12831. {
  12832. key: 'cols',
  12833. scrollerElRef: this.scrollerElRef,
  12834. content: timeContent,
  12835. },
  12836. ],
  12837. });
  12838. if (stickyFooterScrollbar) {
  12839. sections.push({
  12840. key: 'footer',
  12841. type: 'footer',
  12842. isSticky: true,
  12843. chunks: [
  12844. {
  12845. key: 'axis',
  12846. content: renderScrollShim,
  12847. },
  12848. {
  12849. key: 'cols',
  12850. content: renderScrollShim,
  12851. },
  12852. ],
  12853. });
  12854. }
  12855. return (createElement(ViewRoot, { viewSpec: context.viewSpec, elRef: this.rootElRef }, function (rootElRef, classNames) { return (createElement("div", { className: ['fc-timegrid'].concat(classNames).join(' '), ref: rootElRef },
  12856. createElement(ScrollGrid, { liquid: !props.isHeightAuto && !props.forPrint, collapsibleWidth: false, colGroups: [
  12857. { width: 'shrink', cols: [{ width: 'shrink' }] },
  12858. { cols: [{ span: colCnt, minWidth: dayMinWidth }] },
  12859. ], sections: sections }))); }));
  12860. };
  12861. /* Dimensions
  12862. ------------------------------------------------------------------------------------------------------------------*/
  12863. TimeColsView.prototype.getAllDayMaxEventProps = function () {
  12864. var _a = this.context.options, dayMaxEvents = _a.dayMaxEvents, dayMaxEventRows = _a.dayMaxEventRows;
  12865. if (dayMaxEvents === true || dayMaxEventRows === true) { // is auto?
  12866. dayMaxEvents = undefined;
  12867. dayMaxEventRows = AUTO_ALL_DAY_MAX_EVENT_ROWS; // make sure "auto" goes to a real number
  12868. }
  12869. return { dayMaxEvents: dayMaxEvents, dayMaxEventRows: dayMaxEventRows };
  12870. };
  12871. return TimeColsView;
  12872. }(DateComponent));
  12873. function renderAllDayInner$1(hookProps) {
  12874. return hookProps.text;
  12875. }
  12876. var TimeColsSlatsCoords = /** @class */ (function () {
  12877. function TimeColsSlatsCoords(positions, dateProfile, slotDuration) {
  12878. this.positions = positions;
  12879. this.dateProfile = dateProfile;
  12880. this.slotDuration = slotDuration;
  12881. }
  12882. TimeColsSlatsCoords.prototype.safeComputeTop = function (date) {
  12883. var dateProfile = this.dateProfile;
  12884. if (rangeContainsMarker(dateProfile.currentRange, date)) {
  12885. var startOfDayDate = startOfDay(date);
  12886. var timeMs = date.valueOf() - startOfDayDate.valueOf();
  12887. if (timeMs >= asRoughMs(dateProfile.slotMinTime) &&
  12888. timeMs < asRoughMs(dateProfile.slotMaxTime)) {
  12889. return this.computeTimeTop(createDuration(timeMs));
  12890. }
  12891. }
  12892. return null;
  12893. };
  12894. // Computes the top coordinate, relative to the bounds of the grid, of the given date.
  12895. // A `startOfDayDate` must be given for avoiding ambiguity over how to treat midnight.
  12896. TimeColsSlatsCoords.prototype.computeDateTop = function (when, startOfDayDate) {
  12897. if (!startOfDayDate) {
  12898. startOfDayDate = startOfDay(when);
  12899. }
  12900. return this.computeTimeTop(createDuration(when.valueOf() - startOfDayDate.valueOf()));
  12901. };
  12902. // Computes the top coordinate, relative to the bounds of the grid, of the given time (a Duration).
  12903. // This is a makeshify way to compute the time-top. Assumes all slatMetas dates are uniform.
  12904. // Eventually allow computation with arbirary slat dates.
  12905. TimeColsSlatsCoords.prototype.computeTimeTop = function (duration) {
  12906. var _a = this, positions = _a.positions, dateProfile = _a.dateProfile;
  12907. var len = positions.els.length;
  12908. // floating-point value of # of slots covered
  12909. var slatCoverage = (duration.milliseconds - asRoughMs(dateProfile.slotMinTime)) / asRoughMs(this.slotDuration);
  12910. var slatIndex;
  12911. var slatRemainder;
  12912. // compute a floating-point number for how many slats should be progressed through.
  12913. // from 0 to number of slats (inclusive)
  12914. // constrained because slotMinTime/slotMaxTime might be customized.
  12915. slatCoverage = Math.max(0, slatCoverage);
  12916. slatCoverage = Math.min(len, slatCoverage);
  12917. // an integer index of the furthest whole slat
  12918. // from 0 to number slats (*exclusive*, so len-1)
  12919. slatIndex = Math.floor(slatCoverage);
  12920. slatIndex = Math.min(slatIndex, len - 1);
  12921. // how much further through the slatIndex slat (from 0.0-1.0) must be covered in addition.
  12922. // could be 1.0 if slatCoverage is covering *all* the slots
  12923. slatRemainder = slatCoverage - slatIndex;
  12924. return positions.tops[slatIndex] +
  12925. positions.getHeight(slatIndex) * slatRemainder;
  12926. };
  12927. return TimeColsSlatsCoords;
  12928. }());
  12929. var TimeColsSlatsBody = /** @class */ (function (_super) {
  12930. __extends(TimeColsSlatsBody, _super);
  12931. function TimeColsSlatsBody() {
  12932. return _super !== null && _super.apply(this, arguments) || this;
  12933. }
  12934. TimeColsSlatsBody.prototype.render = function () {
  12935. var _a = this, props = _a.props, context = _a.context;
  12936. var options = context.options;
  12937. var slatElRefs = props.slatElRefs;
  12938. return (createElement("tbody", null, props.slatMetas.map(function (slatMeta, i) {
  12939. var hookProps = {
  12940. time: slatMeta.time,
  12941. date: context.dateEnv.toDate(slatMeta.date),
  12942. view: context.viewApi,
  12943. };
  12944. var classNames = [
  12945. 'fc-timegrid-slot',
  12946. 'fc-timegrid-slot-lane',
  12947. slatMeta.isLabeled ? '' : 'fc-timegrid-slot-minor',
  12948. ];
  12949. return (createElement("tr", { key: slatMeta.key, ref: slatElRefs.createRef(slatMeta.key) },
  12950. props.axis && (createElement(TimeColsAxisCell, __assign({}, slatMeta))),
  12951. createElement(RenderHook, { hookProps: hookProps, classNames: options.slotLaneClassNames, content: options.slotLaneContent, didMount: options.slotLaneDidMount, willUnmount: options.slotLaneWillUnmount }, function (rootElRef, customClassNames, innerElRef, innerContent) { return (createElement("td", { ref: rootElRef, className: classNames.concat(customClassNames).join(' '), "data-time": slatMeta.isoTimeStr }, innerContent)); })));
  12952. })));
  12953. };
  12954. return TimeColsSlatsBody;
  12955. }(BaseComponent));
  12956. /*
  12957. for the horizontal "slats" that run width-wise. Has a time axis on a side. Depends on RTL.
  12958. */
  12959. var TimeColsSlats = /** @class */ (function (_super) {
  12960. __extends(TimeColsSlats, _super);
  12961. function TimeColsSlats() {
  12962. var _this = _super !== null && _super.apply(this, arguments) || this;
  12963. _this.rootElRef = createRef();
  12964. _this.slatElRefs = new RefMap();
  12965. return _this;
  12966. }
  12967. TimeColsSlats.prototype.render = function () {
  12968. var _a = this, props = _a.props, context = _a.context;
  12969. return (createElement("div", { className: "fc-timegrid-slots", ref: this.rootElRef },
  12970. createElement("table", { className: context.theme.getClass('table'), style: {
  12971. minWidth: props.tableMinWidth,
  12972. width: props.clientWidth,
  12973. height: props.minHeight,
  12974. } },
  12975. props.tableColGroupNode /* relies on there only being a single <col> for the axis */,
  12976. createElement(TimeColsSlatsBody, { slatElRefs: this.slatElRefs, axis: props.axis, slatMetas: props.slatMetas }))));
  12977. };
  12978. TimeColsSlats.prototype.componentDidMount = function () {
  12979. this.updateSizing();
  12980. };
  12981. TimeColsSlats.prototype.componentDidUpdate = function () {
  12982. this.updateSizing();
  12983. };
  12984. TimeColsSlats.prototype.componentWillUnmount = function () {
  12985. if (this.props.onCoords) {
  12986. this.props.onCoords(null);
  12987. }
  12988. };
  12989. TimeColsSlats.prototype.updateSizing = function () {
  12990. var _a = this, context = _a.context, props = _a.props;
  12991. if (props.onCoords &&
  12992. props.clientWidth !== null // means sizing has stabilized
  12993. ) {
  12994. var rootEl = this.rootElRef.current;
  12995. if (rootEl.offsetHeight) { // not hidden by css
  12996. props.onCoords(new TimeColsSlatsCoords(new PositionCache(this.rootElRef.current, collectSlatEls(this.slatElRefs.currentMap, props.slatMetas), false, true), this.props.dateProfile, context.options.slotDuration));
  12997. }
  12998. }
  12999. };
  13000. return TimeColsSlats;
  13001. }(BaseComponent));
  13002. function collectSlatEls(elMap, slatMetas) {
  13003. return slatMetas.map(function (slatMeta) { return elMap[slatMeta.key]; });
  13004. }
  13005. function splitSegsByCol(segs, colCnt) {
  13006. var segsByCol = [];
  13007. var i;
  13008. for (i = 0; i < colCnt; i += 1) {
  13009. segsByCol.push([]);
  13010. }
  13011. if (segs) {
  13012. for (i = 0; i < segs.length; i += 1) {
  13013. segsByCol[segs[i].col].push(segs[i]);
  13014. }
  13015. }
  13016. return segsByCol;
  13017. }
  13018. function splitInteractionByCol(ui, colCnt) {
  13019. var byRow = [];
  13020. if (!ui) {
  13021. for (var i = 0; i < colCnt; i += 1) {
  13022. byRow[i] = null;
  13023. }
  13024. }
  13025. else {
  13026. for (var i = 0; i < colCnt; i += 1) {
  13027. byRow[i] = {
  13028. affectedInstances: ui.affectedInstances,
  13029. isEvent: ui.isEvent,
  13030. segs: [],
  13031. };
  13032. }
  13033. for (var _i = 0, _a = ui.segs; _i < _a.length; _i++) {
  13034. var seg = _a[_i];
  13035. byRow[seg.col].segs.push(seg);
  13036. }
  13037. }
  13038. return byRow;
  13039. }
  13040. var TimeColMoreLink = /** @class */ (function (_super) {
  13041. __extends(TimeColMoreLink, _super);
  13042. function TimeColMoreLink() {
  13043. var _this = _super !== null && _super.apply(this, arguments) || this;
  13044. _this.rootElRef = createRef();
  13045. return _this;
  13046. }
  13047. TimeColMoreLink.prototype.render = function () {
  13048. var _this = this;
  13049. var props = this.props;
  13050. return (createElement(MoreLinkRoot, { allDayDate: null, moreCnt: props.hiddenSegs.length, allSegs: props.hiddenSegs, hiddenSegs: props.hiddenSegs, alignmentElRef: this.rootElRef, defaultContent: renderMoreLinkInner, extraDateSpan: props.extraDateSpan, dateProfile: props.dateProfile, todayRange: props.todayRange, popoverContent: function () { return renderPlainFgSegs(props.hiddenSegs, props); } }, function (rootElRef, classNames, innerElRef, innerContent, handleClick) { return (createElement("a", { ref: function (el) {
  13051. setRef(rootElRef, el);
  13052. setRef(_this.rootElRef, el);
  13053. }, className: ['fc-timegrid-more-link'].concat(classNames).join(' '), style: { top: props.top, bottom: props.bottom }, onClick: handleClick },
  13054. createElement("div", { ref: innerElRef, className: "fc-timegrid-more-link-inner fc-sticky" }, innerContent))); }));
  13055. };
  13056. return TimeColMoreLink;
  13057. }(BaseComponent));
  13058. function renderMoreLinkInner(props) {
  13059. return props.shortText;
  13060. }
  13061. // segInputs assumed sorted
  13062. function buildPositioning(segInputs, strictOrder, maxStackCnt) {
  13063. var hierarchy = new SegHierarchy();
  13064. if (strictOrder != null) {
  13065. hierarchy.strictOrder = strictOrder;
  13066. }
  13067. if (maxStackCnt != null) {
  13068. hierarchy.maxStackCnt = maxStackCnt;
  13069. }
  13070. var hiddenEntries = hierarchy.addSegs(segInputs);
  13071. var hiddenGroups = groupIntersectingEntries(hiddenEntries);
  13072. var web = buildWeb(hierarchy);
  13073. web = stretchWeb(web, 1); // all levelCoords/thickness will have 0.0-1.0
  13074. var segRects = webToRects(web);
  13075. return { segRects: segRects, hiddenGroups: hiddenGroups };
  13076. }
  13077. function buildWeb(hierarchy) {
  13078. var entriesByLevel = hierarchy.entriesByLevel;
  13079. var buildNode = cacheable(function (level, lateral) { return level + ':' + lateral; }, function (level, lateral) {
  13080. var siblingRange = findNextLevelSegs(hierarchy, level, lateral);
  13081. var nextLevelRes = buildNodes(siblingRange, buildNode);
  13082. var entry = entriesByLevel[level][lateral];
  13083. return [
  13084. __assign(__assign({}, entry), { nextLevelNodes: nextLevelRes[0] }),
  13085. entry.thickness + nextLevelRes[1], // the pressure builds
  13086. ];
  13087. });
  13088. return buildNodes(entriesByLevel.length
  13089. ? { level: 0, lateralStart: 0, lateralEnd: entriesByLevel[0].length }
  13090. : null, buildNode)[0];
  13091. }
  13092. function buildNodes(siblingRange, buildNode) {
  13093. if (!siblingRange) {
  13094. return [[], 0];
  13095. }
  13096. var level = siblingRange.level, lateralStart = siblingRange.lateralStart, lateralEnd = siblingRange.lateralEnd;
  13097. var lateral = lateralStart;
  13098. var pairs = [];
  13099. while (lateral < lateralEnd) {
  13100. pairs.push(buildNode(level, lateral));
  13101. lateral += 1;
  13102. }
  13103. pairs.sort(cmpDescPressures);
  13104. return [
  13105. pairs.map(extractNode),
  13106. pairs[0][1], // first item's pressure
  13107. ];
  13108. }
  13109. function cmpDescPressures(a, b) {
  13110. return b[1] - a[1];
  13111. }
  13112. function extractNode(a) {
  13113. return a[0];
  13114. }
  13115. function findNextLevelSegs(hierarchy, subjectLevel, subjectLateral) {
  13116. var levelCoords = hierarchy.levelCoords, entriesByLevel = hierarchy.entriesByLevel;
  13117. var subjectEntry = entriesByLevel[subjectLevel][subjectLateral];
  13118. var afterSubject = levelCoords[subjectLevel] + subjectEntry.thickness;
  13119. var levelCnt = levelCoords.length;
  13120. var level = subjectLevel;
  13121. // skip past levels that are too high up
  13122. for (; level < levelCnt && levelCoords[level] < afterSubject; level += 1)
  13123. ; // do nothing
  13124. for (; level < levelCnt; level += 1) {
  13125. var entries = entriesByLevel[level];
  13126. var entry = void 0;
  13127. var searchIndex = binarySearch(entries, subjectEntry.span.start, getEntrySpanEnd);
  13128. var lateralStart = searchIndex[0] + searchIndex[1]; // if exact match (which doesn't collide), go to next one
  13129. var lateralEnd = lateralStart;
  13130. while ( // loop through entries that horizontally intersect
  13131. (entry = entries[lateralEnd]) && // but not past the whole seg list
  13132. entry.span.start < subjectEntry.span.end) {
  13133. lateralEnd += 1;
  13134. }
  13135. if (lateralStart < lateralEnd) {
  13136. return { level: level, lateralStart: lateralStart, lateralEnd: lateralEnd };
  13137. }
  13138. }
  13139. return null;
  13140. }
  13141. function stretchWeb(topLevelNodes, totalThickness) {
  13142. var stretchNode = cacheable(function (node, startCoord, prevThickness) { return buildEntryKey(node); }, function (node, startCoord, prevThickness) {
  13143. var nextLevelNodes = node.nextLevelNodes, thickness = node.thickness;
  13144. var allThickness = thickness + prevThickness;
  13145. var thicknessFraction = thickness / allThickness;
  13146. var endCoord;
  13147. var newChildren = [];
  13148. if (!nextLevelNodes.length) {
  13149. endCoord = totalThickness;
  13150. }
  13151. else {
  13152. for (var _i = 0, nextLevelNodes_1 = nextLevelNodes; _i < nextLevelNodes_1.length; _i++) {
  13153. var childNode = nextLevelNodes_1[_i];
  13154. if (endCoord === undefined) {
  13155. var res = stretchNode(childNode, startCoord, allThickness);
  13156. endCoord = res[0];
  13157. newChildren.push(res[1]);
  13158. }
  13159. else {
  13160. var res = stretchNode(childNode, endCoord, 0);
  13161. newChildren.push(res[1]);
  13162. }
  13163. }
  13164. }
  13165. var newThickness = (endCoord - startCoord) * thicknessFraction;
  13166. return [endCoord - newThickness, __assign(__assign({}, node), { thickness: newThickness, nextLevelNodes: newChildren })];
  13167. });
  13168. return topLevelNodes.map(function (node) { return stretchNode(node, 0, 0)[1]; });
  13169. }
  13170. // not sorted in any particular order
  13171. function webToRects(topLevelNodes) {
  13172. var rects = [];
  13173. var processNode = cacheable(function (node, levelCoord, stackDepth) { return buildEntryKey(node); }, function (node, levelCoord, stackDepth) {
  13174. var rect = __assign(__assign({}, node), { levelCoord: levelCoord,
  13175. stackDepth: stackDepth, stackForward: 0 });
  13176. rects.push(rect);
  13177. return (rect.stackForward = processNodes(node.nextLevelNodes, levelCoord + node.thickness, stackDepth + 1) + 1);
  13178. });
  13179. function processNodes(nodes, levelCoord, stackDepth) {
  13180. var stackForward = 0;
  13181. for (var _i = 0, nodes_1 = nodes; _i < nodes_1.length; _i++) {
  13182. var node = nodes_1[_i];
  13183. stackForward = Math.max(processNode(node, levelCoord, stackDepth), stackForward);
  13184. }
  13185. return stackForward;
  13186. }
  13187. processNodes(topLevelNodes, 0, 0);
  13188. return rects; // TODO: sort rects by levelCoord to be consistent with toRects?
  13189. }
  13190. // TODO: move to general util
  13191. function cacheable(keyFunc, workFunc) {
  13192. var cache = {};
  13193. return function () {
  13194. var args = [];
  13195. for (var _i = 0; _i < arguments.length; _i++) {
  13196. args[_i] = arguments[_i];
  13197. }
  13198. var key = keyFunc.apply(void 0, args);
  13199. return (key in cache)
  13200. ? cache[key]
  13201. : (cache[key] = workFunc.apply(void 0, args));
  13202. };
  13203. }
  13204. function computeSegVCoords(segs, colDate, slatCoords, eventMinHeight) {
  13205. if (slatCoords === void 0) { slatCoords = null; }
  13206. if (eventMinHeight === void 0) { eventMinHeight = 0; }
  13207. var vcoords = [];
  13208. if (slatCoords) {
  13209. for (var i = 0; i < segs.length; i += 1) {
  13210. var seg = segs[i];
  13211. var spanStart = slatCoords.computeDateTop(seg.start, colDate);
  13212. var spanEnd = Math.max(spanStart + (eventMinHeight || 0), // :(
  13213. slatCoords.computeDateTop(seg.end, colDate));
  13214. vcoords.push({
  13215. start: Math.round(spanStart),
  13216. end: Math.round(spanEnd), //
  13217. });
  13218. }
  13219. }
  13220. return vcoords;
  13221. }
  13222. function computeFgSegPlacements(segs, segVCoords, // might not have for every seg
  13223. eventOrderStrict, eventMaxStack) {
  13224. var segInputs = [];
  13225. var dumbSegs = []; // segs without coords
  13226. for (var i = 0; i < segs.length; i += 1) {
  13227. var vcoords = segVCoords[i];
  13228. if (vcoords) {
  13229. segInputs.push({
  13230. index: i,
  13231. thickness: 1,
  13232. span: vcoords,
  13233. });
  13234. }
  13235. else {
  13236. dumbSegs.push(segs[i]);
  13237. }
  13238. }
  13239. var _a = buildPositioning(segInputs, eventOrderStrict, eventMaxStack), segRects = _a.segRects, hiddenGroups = _a.hiddenGroups;
  13240. var segPlacements = [];
  13241. for (var _i = 0, segRects_1 = segRects; _i < segRects_1.length; _i++) {
  13242. var segRect = segRects_1[_i];
  13243. segPlacements.push({
  13244. seg: segs[segRect.index],
  13245. rect: segRect,
  13246. });
  13247. }
  13248. for (var _b = 0, dumbSegs_1 = dumbSegs; _b < dumbSegs_1.length; _b++) {
  13249. var dumbSeg = dumbSegs_1[_b];
  13250. segPlacements.push({ seg: dumbSeg, rect: null });
  13251. }
  13252. return { segPlacements: segPlacements, hiddenGroups: hiddenGroups };
  13253. }
  13254. var DEFAULT_TIME_FORMAT$1 = createFormatter({
  13255. hour: 'numeric',
  13256. minute: '2-digit',
  13257. meridiem: false,
  13258. });
  13259. var TimeColEvent = /** @class */ (function (_super) {
  13260. __extends(TimeColEvent, _super);
  13261. function TimeColEvent() {
  13262. return _super !== null && _super.apply(this, arguments) || this;
  13263. }
  13264. TimeColEvent.prototype.render = function () {
  13265. var classNames = [
  13266. 'fc-timegrid-event',
  13267. 'fc-v-event',
  13268. ];
  13269. if (this.props.isShort) {
  13270. classNames.push('fc-timegrid-event-short');
  13271. }
  13272. return (createElement(StandardEvent, __assign({}, this.props, { defaultTimeFormat: DEFAULT_TIME_FORMAT$1, extraClassNames: classNames })));
  13273. };
  13274. return TimeColEvent;
  13275. }(BaseComponent));
  13276. var TimeColMisc = /** @class */ (function (_super) {
  13277. __extends(TimeColMisc, _super);
  13278. function TimeColMisc() {
  13279. return _super !== null && _super.apply(this, arguments) || this;
  13280. }
  13281. TimeColMisc.prototype.render = function () {
  13282. var props = this.props;
  13283. return (createElement(DayCellContent, { date: props.date, dateProfile: props.dateProfile, todayRange: props.todayRange, extraHookProps: props.extraHookProps }, function (innerElRef, innerContent) { return (innerContent &&
  13284. createElement("div", { className: "fc-timegrid-col-misc", ref: innerElRef }, innerContent)); }));
  13285. };
  13286. return TimeColMisc;
  13287. }(BaseComponent));
  13288. var TimeCol = /** @class */ (function (_super) {
  13289. __extends(TimeCol, _super);
  13290. function TimeCol() {
  13291. var _this = _super !== null && _super.apply(this, arguments) || this;
  13292. _this.sortEventSegs = memoize(sortEventSegs);
  13293. return _this;
  13294. }
  13295. // TODO: memoize event-placement?
  13296. TimeCol.prototype.render = function () {
  13297. var _this = this;
  13298. var _a = this, props = _a.props, context = _a.context;
  13299. var isSelectMirror = context.options.selectMirror;
  13300. var mirrorSegs = (props.eventDrag && props.eventDrag.segs) ||
  13301. (props.eventResize && props.eventResize.segs) ||
  13302. (isSelectMirror && props.dateSelectionSegs) ||
  13303. [];
  13304. var interactionAffectedInstances = // TODO: messy way to compute this
  13305. (props.eventDrag && props.eventDrag.affectedInstances) ||
  13306. (props.eventResize && props.eventResize.affectedInstances) ||
  13307. {};
  13308. var sortedFgSegs = this.sortEventSegs(props.fgEventSegs, context.options.eventOrder);
  13309. return (createElement(DayCellRoot, { elRef: props.elRef, date: props.date, dateProfile: props.dateProfile, todayRange: props.todayRange, extraHookProps: props.extraHookProps }, function (rootElRef, classNames, dataAttrs) { return (createElement("td", __assign({ ref: rootElRef, className: ['fc-timegrid-col'].concat(classNames, props.extraClassNames || []).join(' ') }, dataAttrs, props.extraDataAttrs),
  13310. createElement("div", { className: "fc-timegrid-col-frame" },
  13311. createElement("div", { className: "fc-timegrid-col-bg" },
  13312. _this.renderFillSegs(props.businessHourSegs, 'non-business'),
  13313. _this.renderFillSegs(props.bgEventSegs, 'bg-event'),
  13314. _this.renderFillSegs(props.dateSelectionSegs, 'highlight')),
  13315. createElement("div", { className: "fc-timegrid-col-events" }, _this.renderFgSegs(sortedFgSegs, interactionAffectedInstances, false, false, false)),
  13316. createElement("div", { className: "fc-timegrid-col-events" }, _this.renderFgSegs(mirrorSegs, {}, Boolean(props.eventDrag), Boolean(props.eventResize), Boolean(isSelectMirror))),
  13317. createElement("div", { className: "fc-timegrid-now-indicator-container" }, _this.renderNowIndicator(props.nowIndicatorSegs)),
  13318. createElement(TimeColMisc, { date: props.date, dateProfile: props.dateProfile, todayRange: props.todayRange, extraHookProps: props.extraHookProps })))); }));
  13319. };
  13320. TimeCol.prototype.renderFgSegs = function (sortedFgSegs, segIsInvisible, isDragging, isResizing, isDateSelecting) {
  13321. var props = this.props;
  13322. if (props.forPrint) {
  13323. return renderPlainFgSegs(sortedFgSegs, props);
  13324. }
  13325. return this.renderPositionedFgSegs(sortedFgSegs, segIsInvisible, isDragging, isResizing, isDateSelecting);
  13326. };
  13327. TimeCol.prototype.renderPositionedFgSegs = function (segs, // if not mirror, needs to be sorted
  13328. segIsInvisible, isDragging, isResizing, isDateSelecting) {
  13329. var _this = this;
  13330. var _a = this.context.options, eventMaxStack = _a.eventMaxStack, eventShortHeight = _a.eventShortHeight, eventOrderStrict = _a.eventOrderStrict, eventMinHeight = _a.eventMinHeight;
  13331. var _b = this.props, date = _b.date, slatCoords = _b.slatCoords, eventSelection = _b.eventSelection, todayRange = _b.todayRange, nowDate = _b.nowDate;
  13332. var isMirror = isDragging || isResizing || isDateSelecting;
  13333. var segVCoords = computeSegVCoords(segs, date, slatCoords, eventMinHeight);
  13334. var _c = computeFgSegPlacements(segs, segVCoords, eventOrderStrict, eventMaxStack), segPlacements = _c.segPlacements, hiddenGroups = _c.hiddenGroups;
  13335. return (createElement(Fragment, null,
  13336. this.renderHiddenGroups(hiddenGroups, segs),
  13337. segPlacements.map(function (segPlacement) {
  13338. var seg = segPlacement.seg, rect = segPlacement.rect;
  13339. var instanceId = seg.eventRange.instance.instanceId;
  13340. var isVisible = isMirror || Boolean(!segIsInvisible[instanceId] && rect);
  13341. var vStyle = computeSegVStyle(rect && rect.span);
  13342. var hStyle = (!isMirror && rect) ? _this.computeSegHStyle(rect) : { left: 0, right: 0 };
  13343. var isInset = Boolean(rect) && rect.stackForward > 0;
  13344. var isShort = Boolean(rect) && (rect.span.end - rect.span.start) < eventShortHeight; // look at other places for this problem
  13345. return (createElement("div", { className: 'fc-timegrid-event-harness' +
  13346. (isInset ? ' fc-timegrid-event-harness-inset' : ''), key: instanceId, style: __assign(__assign({ visibility: isVisible ? '' : 'hidden' }, vStyle), hStyle) },
  13347. createElement(TimeColEvent, __assign({ seg: seg, isDragging: isDragging, isResizing: isResizing, isDateSelecting: isDateSelecting, isSelected: instanceId === eventSelection, isShort: isShort }, getSegMeta(seg, todayRange, nowDate)))));
  13348. })));
  13349. };
  13350. // will already have eventMinHeight applied because segInputs already had it
  13351. TimeCol.prototype.renderHiddenGroups = function (hiddenGroups, segs) {
  13352. var _a = this.props, extraDateSpan = _a.extraDateSpan, dateProfile = _a.dateProfile, todayRange = _a.todayRange, nowDate = _a.nowDate, eventSelection = _a.eventSelection, eventDrag = _a.eventDrag, eventResize = _a.eventResize;
  13353. return (createElement(Fragment, null, hiddenGroups.map(function (hiddenGroup) {
  13354. var positionCss = computeSegVStyle(hiddenGroup.span);
  13355. var hiddenSegs = compileSegsFromEntries(hiddenGroup.entries, segs);
  13356. return (createElement(TimeColMoreLink, { key: buildIsoString(computeEarliestSegStart(hiddenSegs)), hiddenSegs: hiddenSegs, top: positionCss.top, bottom: positionCss.bottom, extraDateSpan: extraDateSpan, dateProfile: dateProfile, todayRange: todayRange, nowDate: nowDate, eventSelection: eventSelection, eventDrag: eventDrag, eventResize: eventResize }));
  13357. })));
  13358. };
  13359. TimeCol.prototype.renderFillSegs = function (segs, fillType) {
  13360. var _a = this, props = _a.props, context = _a.context;
  13361. var segVCoords = computeSegVCoords(segs, props.date, props.slatCoords, context.options.eventMinHeight); // don't assume all populated
  13362. var children = segVCoords.map(function (vcoords, i) {
  13363. var seg = segs[i];
  13364. return (createElement("div", { key: buildEventRangeKey(seg.eventRange), className: "fc-timegrid-bg-harness", style: computeSegVStyle(vcoords) }, fillType === 'bg-event' ?
  13365. createElement(BgEvent, __assign({ seg: seg }, getSegMeta(seg, props.todayRange, props.nowDate))) :
  13366. renderFill(fillType)));
  13367. });
  13368. return createElement(Fragment, null, children);
  13369. };
  13370. TimeCol.prototype.renderNowIndicator = function (segs) {
  13371. var _a = this.props, slatCoords = _a.slatCoords, date = _a.date;
  13372. if (!slatCoords) {
  13373. return null;
  13374. }
  13375. return segs.map(function (seg, i) { return (createElement(NowIndicatorRoot, { isAxis: false, date: date,
  13376. // key doesn't matter. will only ever be one
  13377. key: i }, function (rootElRef, classNames, innerElRef, innerContent) { return (createElement("div", { ref: rootElRef, className: ['fc-timegrid-now-indicator-line'].concat(classNames).join(' '), style: { top: slatCoords.computeDateTop(seg.start, date) } }, innerContent)); })); });
  13378. };
  13379. TimeCol.prototype.computeSegHStyle = function (segHCoords) {
  13380. var _a = this.context, isRtl = _a.isRtl, options = _a.options;
  13381. var shouldOverlap = options.slotEventOverlap;
  13382. var nearCoord = segHCoords.levelCoord; // the left side if LTR. the right side if RTL. floating-point
  13383. var farCoord = segHCoords.levelCoord + segHCoords.thickness; // the right side if LTR. the left side if RTL. floating-point
  13384. var left; // amount of space from left edge, a fraction of the total width
  13385. var right; // amount of space from right edge, a fraction of the total width
  13386. if (shouldOverlap) {
  13387. // double the width, but don't go beyond the maximum forward coordinate (1.0)
  13388. farCoord = Math.min(1, nearCoord + (farCoord - nearCoord) * 2);
  13389. }
  13390. if (isRtl) {
  13391. left = 1 - farCoord;
  13392. right = nearCoord;
  13393. }
  13394. else {
  13395. left = nearCoord;
  13396. right = 1 - farCoord;
  13397. }
  13398. var props = {
  13399. zIndex: segHCoords.stackDepth + 1,
  13400. left: left * 100 + '%',
  13401. right: right * 100 + '%',
  13402. };
  13403. if (shouldOverlap && !segHCoords.stackForward) {
  13404. // add padding to the edge so that forward stacked events don't cover the resizer's icon
  13405. props[isRtl ? 'marginLeft' : 'marginRight'] = 10 * 2; // 10 is a guesstimate of the icon's width
  13406. }
  13407. return props;
  13408. };
  13409. return TimeCol;
  13410. }(BaseComponent));
  13411. function renderPlainFgSegs(sortedFgSegs, _a) {
  13412. var todayRange = _a.todayRange, nowDate = _a.nowDate, eventSelection = _a.eventSelection, eventDrag = _a.eventDrag, eventResize = _a.eventResize;
  13413. var hiddenInstances = (eventDrag ? eventDrag.affectedInstances : null) ||
  13414. (eventResize ? eventResize.affectedInstances : null) ||
  13415. {};
  13416. return (createElement(Fragment, null, sortedFgSegs.map(function (seg) {
  13417. var instanceId = seg.eventRange.instance.instanceId;
  13418. return (createElement("div", { key: instanceId, style: { visibility: hiddenInstances[instanceId] ? 'hidden' : '' } },
  13419. createElement(TimeColEvent, __assign({ seg: seg, isDragging: false, isResizing: false, isDateSelecting: false, isSelected: instanceId === eventSelection, isShort: false }, getSegMeta(seg, todayRange, nowDate)))));
  13420. })));
  13421. }
  13422. function computeSegVStyle(segVCoords) {
  13423. if (!segVCoords) {
  13424. return { top: '', bottom: '' };
  13425. }
  13426. return {
  13427. top: segVCoords.start,
  13428. bottom: -segVCoords.end,
  13429. };
  13430. }
  13431. function compileSegsFromEntries(segEntries, allSegs) {
  13432. return segEntries.map(function (segEntry) { return allSegs[segEntry.index]; });
  13433. }
  13434. var TimeColsContent = /** @class */ (function (_super) {
  13435. __extends(TimeColsContent, _super);
  13436. function TimeColsContent() {
  13437. var _this = _super !== null && _super.apply(this, arguments) || this;
  13438. _this.splitFgEventSegs = memoize(splitSegsByCol);
  13439. _this.splitBgEventSegs = memoize(splitSegsByCol);
  13440. _this.splitBusinessHourSegs = memoize(splitSegsByCol);
  13441. _this.splitNowIndicatorSegs = memoize(splitSegsByCol);
  13442. _this.splitDateSelectionSegs = memoize(splitSegsByCol);
  13443. _this.splitEventDrag = memoize(splitInteractionByCol);
  13444. _this.splitEventResize = memoize(splitInteractionByCol);
  13445. _this.rootElRef = createRef();
  13446. _this.cellElRefs = new RefMap();
  13447. return _this;
  13448. }
  13449. TimeColsContent.prototype.render = function () {
  13450. var _this = this;
  13451. var _a = this, props = _a.props, context = _a.context;
  13452. var nowIndicatorTop = context.options.nowIndicator &&
  13453. props.slatCoords &&
  13454. props.slatCoords.safeComputeTop(props.nowDate); // might return void
  13455. var colCnt = props.cells.length;
  13456. var fgEventSegsByRow = this.splitFgEventSegs(props.fgEventSegs, colCnt);
  13457. var bgEventSegsByRow = this.splitBgEventSegs(props.bgEventSegs, colCnt);
  13458. var businessHourSegsByRow = this.splitBusinessHourSegs(props.businessHourSegs, colCnt);
  13459. var nowIndicatorSegsByRow = this.splitNowIndicatorSegs(props.nowIndicatorSegs, colCnt);
  13460. var dateSelectionSegsByRow = this.splitDateSelectionSegs(props.dateSelectionSegs, colCnt);
  13461. var eventDragByRow = this.splitEventDrag(props.eventDrag, colCnt);
  13462. var eventResizeByRow = this.splitEventResize(props.eventResize, colCnt);
  13463. return (createElement("div", { className: "fc-timegrid-cols", ref: this.rootElRef },
  13464. createElement("table", { style: {
  13465. minWidth: props.tableMinWidth,
  13466. width: props.clientWidth,
  13467. } },
  13468. props.tableColGroupNode,
  13469. createElement("tbody", null,
  13470. createElement("tr", null,
  13471. props.axis && (createElement("td", { className: "fc-timegrid-col fc-timegrid-axis" },
  13472. createElement("div", { className: "fc-timegrid-col-frame" },
  13473. createElement("div", { className: "fc-timegrid-now-indicator-container" }, typeof nowIndicatorTop === 'number' && (createElement(NowIndicatorRoot, { isAxis: true, date: props.nowDate }, function (rootElRef, classNames, innerElRef, innerContent) { return (createElement("div", { ref: rootElRef, className: ['fc-timegrid-now-indicator-arrow'].concat(classNames).join(' '), style: { top: nowIndicatorTop } }, innerContent)); })))))),
  13474. props.cells.map(function (cell, i) { return (createElement(TimeCol, { key: cell.key, elRef: _this.cellElRefs.createRef(cell.key), dateProfile: props.dateProfile, date: cell.date, nowDate: props.nowDate, todayRange: props.todayRange, extraHookProps: cell.extraHookProps, extraDataAttrs: cell.extraDataAttrs, extraClassNames: cell.extraClassNames, extraDateSpan: cell.extraDateSpan, fgEventSegs: fgEventSegsByRow[i], bgEventSegs: bgEventSegsByRow[i], businessHourSegs: businessHourSegsByRow[i], nowIndicatorSegs: nowIndicatorSegsByRow[i], dateSelectionSegs: dateSelectionSegsByRow[i], eventDrag: eventDragByRow[i], eventResize: eventResizeByRow[i], slatCoords: props.slatCoords, eventSelection: props.eventSelection, forPrint: props.forPrint })); }))))));
  13475. };
  13476. TimeColsContent.prototype.componentDidMount = function () {
  13477. this.updateCoords();
  13478. };
  13479. TimeColsContent.prototype.componentDidUpdate = function () {
  13480. this.updateCoords();
  13481. };
  13482. TimeColsContent.prototype.updateCoords = function () {
  13483. var props = this.props;
  13484. if (props.onColCoords &&
  13485. props.clientWidth !== null // means sizing has stabilized
  13486. ) {
  13487. props.onColCoords(new PositionCache(this.rootElRef.current, collectCellEls(this.cellElRefs.currentMap, props.cells), true, // horizontal
  13488. false));
  13489. }
  13490. };
  13491. return TimeColsContent;
  13492. }(BaseComponent));
  13493. function collectCellEls(elMap, cells) {
  13494. return cells.map(function (cell) { return elMap[cell.key]; });
  13495. }
  13496. /* A component that renders one or more columns of vertical time slots
  13497. ----------------------------------------------------------------------------------------------------------------------*/
  13498. var TimeCols = /** @class */ (function (_super) {
  13499. __extends(TimeCols, _super);
  13500. function TimeCols() {
  13501. var _this = _super !== null && _super.apply(this, arguments) || this;
  13502. _this.processSlotOptions = memoize(processSlotOptions);
  13503. _this.state = {
  13504. slatCoords: null,
  13505. };
  13506. _this.handleRootEl = function (el) {
  13507. if (el) {
  13508. _this.context.registerInteractiveComponent(_this, {
  13509. el: el,
  13510. isHitComboAllowed: _this.props.isHitComboAllowed,
  13511. });
  13512. }
  13513. else {
  13514. _this.context.unregisterInteractiveComponent(_this);
  13515. }
  13516. };
  13517. _this.handleScrollRequest = function (request) {
  13518. var onScrollTopRequest = _this.props.onScrollTopRequest;
  13519. var slatCoords = _this.state.slatCoords;
  13520. if (onScrollTopRequest && slatCoords) {
  13521. if (request.time) {
  13522. var top_1 = slatCoords.computeTimeTop(request.time);
  13523. top_1 = Math.ceil(top_1); // zoom can give weird floating-point values. rather scroll a little bit further
  13524. if (top_1) {
  13525. top_1 += 1; // to overcome top border that slots beyond the first have. looks better
  13526. }
  13527. onScrollTopRequest(top_1);
  13528. }
  13529. return true;
  13530. }
  13531. return false;
  13532. };
  13533. _this.handleColCoords = function (colCoords) {
  13534. _this.colCoords = colCoords;
  13535. };
  13536. _this.handleSlatCoords = function (slatCoords) {
  13537. _this.setState({ slatCoords: slatCoords });
  13538. if (_this.props.onSlatCoords) {
  13539. _this.props.onSlatCoords(slatCoords);
  13540. }
  13541. };
  13542. return _this;
  13543. }
  13544. TimeCols.prototype.render = function () {
  13545. var _a = this, props = _a.props, state = _a.state;
  13546. return (createElement("div", { className: "fc-timegrid-body", ref: this.handleRootEl, style: {
  13547. // these props are important to give this wrapper correct dimensions for interactions
  13548. // TODO: if we set it here, can we avoid giving to inner tables?
  13549. width: props.clientWidth,
  13550. minWidth: props.tableMinWidth,
  13551. } },
  13552. createElement(TimeColsSlats, { axis: props.axis, dateProfile: props.dateProfile, slatMetas: props.slatMetas, clientWidth: props.clientWidth, minHeight: props.expandRows ? props.clientHeight : '', tableMinWidth: props.tableMinWidth, tableColGroupNode: props.axis ? props.tableColGroupNode : null /* axis depends on the colgroup's shrinking */, onCoords: this.handleSlatCoords }),
  13553. createElement(TimeColsContent, { cells: props.cells, axis: props.axis, dateProfile: props.dateProfile, businessHourSegs: props.businessHourSegs, bgEventSegs: props.bgEventSegs, fgEventSegs: props.fgEventSegs, dateSelectionSegs: props.dateSelectionSegs, eventSelection: props.eventSelection, eventDrag: props.eventDrag, eventResize: props.eventResize, todayRange: props.todayRange, nowDate: props.nowDate, nowIndicatorSegs: props.nowIndicatorSegs, clientWidth: props.clientWidth, tableMinWidth: props.tableMinWidth, tableColGroupNode: props.tableColGroupNode, slatCoords: state.slatCoords, onColCoords: this.handleColCoords, forPrint: props.forPrint })));
  13554. };
  13555. TimeCols.prototype.componentDidMount = function () {
  13556. this.scrollResponder = this.context.createScrollResponder(this.handleScrollRequest);
  13557. };
  13558. TimeCols.prototype.componentDidUpdate = function (prevProps) {
  13559. this.scrollResponder.update(prevProps.dateProfile !== this.props.dateProfile);
  13560. };
  13561. TimeCols.prototype.componentWillUnmount = function () {
  13562. this.scrollResponder.detach();
  13563. };
  13564. TimeCols.prototype.queryHit = function (positionLeft, positionTop) {
  13565. var _a = this.context, dateEnv = _a.dateEnv, options = _a.options;
  13566. var colCoords = this.colCoords;
  13567. var dateProfile = this.props.dateProfile;
  13568. var slatCoords = this.state.slatCoords;
  13569. var _b = this.processSlotOptions(this.props.slotDuration, options.snapDuration), snapDuration = _b.snapDuration, snapsPerSlot = _b.snapsPerSlot;
  13570. var colIndex = colCoords.leftToIndex(positionLeft);
  13571. var slatIndex = slatCoords.positions.topToIndex(positionTop);
  13572. if (colIndex != null && slatIndex != null) {
  13573. var cell = this.props.cells[colIndex];
  13574. var slatTop = slatCoords.positions.tops[slatIndex];
  13575. var slatHeight = slatCoords.positions.getHeight(slatIndex);
  13576. var partial = (positionTop - slatTop) / slatHeight; // floating point number between 0 and 1
  13577. var localSnapIndex = Math.floor(partial * snapsPerSlot); // the snap # relative to start of slat
  13578. var snapIndex = slatIndex * snapsPerSlot + localSnapIndex;
  13579. var dayDate = this.props.cells[colIndex].date;
  13580. var time = addDurations(dateProfile.slotMinTime, multiplyDuration(snapDuration, snapIndex));
  13581. var start = dateEnv.add(dayDate, time);
  13582. var end = dateEnv.add(start, snapDuration);
  13583. return {
  13584. dateProfile: dateProfile,
  13585. dateSpan: __assign({ range: { start: start, end: end }, allDay: false }, cell.extraDateSpan),
  13586. dayEl: colCoords.els[colIndex],
  13587. rect: {
  13588. left: colCoords.lefts[colIndex],
  13589. right: colCoords.rights[colIndex],
  13590. top: slatTop,
  13591. bottom: slatTop + slatHeight,
  13592. },
  13593. layer: 0,
  13594. };
  13595. }
  13596. return null;
  13597. };
  13598. return TimeCols;
  13599. }(DateComponent));
  13600. function processSlotOptions(slotDuration, snapDurationOverride) {
  13601. var snapDuration = snapDurationOverride || slotDuration;
  13602. var snapsPerSlot = wholeDivideDurations(slotDuration, snapDuration);
  13603. if (snapsPerSlot === null) {
  13604. snapDuration = slotDuration;
  13605. snapsPerSlot = 1;
  13606. // TODO: say warning?
  13607. }
  13608. return { snapDuration: snapDuration, snapsPerSlot: snapsPerSlot };
  13609. }
  13610. var DayTimeColsSlicer = /** @class */ (function (_super) {
  13611. __extends(DayTimeColsSlicer, _super);
  13612. function DayTimeColsSlicer() {
  13613. return _super !== null && _super.apply(this, arguments) || this;
  13614. }
  13615. DayTimeColsSlicer.prototype.sliceRange = function (range, dayRanges) {
  13616. var segs = [];
  13617. for (var col = 0; col < dayRanges.length; col += 1) {
  13618. var segRange = intersectRanges(range, dayRanges[col]);
  13619. if (segRange) {
  13620. segs.push({
  13621. start: segRange.start,
  13622. end: segRange.end,
  13623. isStart: segRange.start.valueOf() === range.start.valueOf(),
  13624. isEnd: segRange.end.valueOf() === range.end.valueOf(),
  13625. col: col,
  13626. });
  13627. }
  13628. }
  13629. return segs;
  13630. };
  13631. return DayTimeColsSlicer;
  13632. }(Slicer));
  13633. var DayTimeCols = /** @class */ (function (_super) {
  13634. __extends(DayTimeCols, _super);
  13635. function DayTimeCols() {
  13636. var _this = _super !== null && _super.apply(this, arguments) || this;
  13637. _this.buildDayRanges = memoize(buildDayRanges);
  13638. _this.slicer = new DayTimeColsSlicer();
  13639. _this.timeColsRef = createRef();
  13640. return _this;
  13641. }
  13642. DayTimeCols.prototype.render = function () {
  13643. var _this = this;
  13644. var _a = this, props = _a.props, context = _a.context;
  13645. var dateProfile = props.dateProfile, dayTableModel = props.dayTableModel;
  13646. var isNowIndicator = context.options.nowIndicator;
  13647. var dayRanges = this.buildDayRanges(dayTableModel, dateProfile, context.dateEnv);
  13648. // give it the first row of cells
  13649. // TODO: would move this further down hierarchy, but sliceNowDate needs it
  13650. return (createElement(NowTimer, { unit: isNowIndicator ? 'minute' : 'day' }, function (nowDate, todayRange) { return (createElement(TimeCols, __assign({ ref: _this.timeColsRef }, _this.slicer.sliceProps(props, dateProfile, null, context, dayRanges), { forPrint: props.forPrint, axis: props.axis, dateProfile: dateProfile, slatMetas: props.slatMetas, slotDuration: props.slotDuration, cells: dayTableModel.cells[0], tableColGroupNode: props.tableColGroupNode, tableMinWidth: props.tableMinWidth, clientWidth: props.clientWidth, clientHeight: props.clientHeight, expandRows: props.expandRows, nowDate: nowDate, nowIndicatorSegs: isNowIndicator && _this.slicer.sliceNowDate(nowDate, context, dayRanges), todayRange: todayRange, onScrollTopRequest: props.onScrollTopRequest, onSlatCoords: props.onSlatCoords }))); }));
  13651. };
  13652. return DayTimeCols;
  13653. }(DateComponent));
  13654. function buildDayRanges(dayTableModel, dateProfile, dateEnv) {
  13655. var ranges = [];
  13656. for (var _i = 0, _a = dayTableModel.headerDates; _i < _a.length; _i++) {
  13657. var date = _a[_i];
  13658. ranges.push({
  13659. start: dateEnv.add(date, dateProfile.slotMinTime),
  13660. end: dateEnv.add(date, dateProfile.slotMaxTime),
  13661. });
  13662. }
  13663. return ranges;
  13664. }
  13665. // potential nice values for the slot-duration and interval-duration
  13666. // from largest to smallest
  13667. var STOCK_SUB_DURATIONS = [
  13668. { hours: 1 },
  13669. { minutes: 30 },
  13670. { minutes: 15 },
  13671. { seconds: 30 },
  13672. { seconds: 15 },
  13673. ];
  13674. function buildSlatMetas(slotMinTime, slotMaxTime, explicitLabelInterval, slotDuration, dateEnv) {
  13675. var dayStart = new Date(0);
  13676. var slatTime = slotMinTime;
  13677. var slatIterator = createDuration(0);
  13678. var labelInterval = explicitLabelInterval || computeLabelInterval(slotDuration);
  13679. var metas = [];
  13680. while (asRoughMs(slatTime) < asRoughMs(slotMaxTime)) {
  13681. var date = dateEnv.add(dayStart, slatTime);
  13682. var isLabeled = wholeDivideDurations(slatIterator, labelInterval) !== null;
  13683. metas.push({
  13684. date: date,
  13685. time: slatTime,
  13686. key: date.toISOString(),
  13687. isoTimeStr: formatIsoTimeString(date),
  13688. isLabeled: isLabeled,
  13689. });
  13690. slatTime = addDurations(slatTime, slotDuration);
  13691. slatIterator = addDurations(slatIterator, slotDuration);
  13692. }
  13693. return metas;
  13694. }
  13695. // Computes an automatic value for slotLabelInterval
  13696. function computeLabelInterval(slotDuration) {
  13697. var i;
  13698. var labelInterval;
  13699. var slotsPerLabel;
  13700. // find the smallest stock label interval that results in more than one slots-per-label
  13701. for (i = STOCK_SUB_DURATIONS.length - 1; i >= 0; i -= 1) {
  13702. labelInterval = createDuration(STOCK_SUB_DURATIONS[i]);
  13703. slotsPerLabel = wholeDivideDurations(labelInterval, slotDuration);
  13704. if (slotsPerLabel !== null && slotsPerLabel > 1) {
  13705. return labelInterval;
  13706. }
  13707. }
  13708. return slotDuration; // fall back
  13709. }
  13710. var DayTimeColsView = /** @class */ (function (_super) {
  13711. __extends(DayTimeColsView, _super);
  13712. function DayTimeColsView() {
  13713. var _this = _super !== null && _super.apply(this, arguments) || this;
  13714. _this.buildTimeColsModel = memoize(buildTimeColsModel);
  13715. _this.buildSlatMetas = memoize(buildSlatMetas);
  13716. return _this;
  13717. }
  13718. DayTimeColsView.prototype.render = function () {
  13719. var _this = this;
  13720. var _a = this.context, options = _a.options, dateEnv = _a.dateEnv, dateProfileGenerator = _a.dateProfileGenerator;
  13721. var props = this.props;
  13722. var dateProfile = props.dateProfile;
  13723. var dayTableModel = this.buildTimeColsModel(dateProfile, dateProfileGenerator);
  13724. var splitProps = this.allDaySplitter.splitProps(props);
  13725. var slatMetas = this.buildSlatMetas(dateProfile.slotMinTime, dateProfile.slotMaxTime, options.slotLabelInterval, options.slotDuration, dateEnv);
  13726. var dayMinWidth = options.dayMinWidth;
  13727. var hasAttachedAxis = !dayMinWidth;
  13728. var hasDetachedAxis = dayMinWidth;
  13729. var headerContent = options.dayHeaders && (createElement(DayHeader, { dates: dayTableModel.headerDates, dateProfile: dateProfile, datesRepDistinctDays: true, renderIntro: hasAttachedAxis ? this.renderHeadAxis : null }));
  13730. var allDayContent = (options.allDaySlot !== false) && (function (contentArg) { return (createElement(DayTable, __assign({}, splitProps.allDay, { dateProfile: dateProfile, dayTableModel: dayTableModel, nextDayThreshold: options.nextDayThreshold, tableMinWidth: contentArg.tableMinWidth, colGroupNode: contentArg.tableColGroupNode, renderRowIntro: hasAttachedAxis ? _this.renderTableRowAxis : null, showWeekNumbers: false, expandRows: false, headerAlignElRef: _this.headerElRef, clientWidth: contentArg.clientWidth, clientHeight: contentArg.clientHeight, forPrint: props.forPrint }, _this.getAllDayMaxEventProps()))); });
  13731. var timeGridContent = function (contentArg) { return (createElement(DayTimeCols, __assign({}, splitProps.timed, { dayTableModel: dayTableModel, dateProfile: dateProfile, axis: hasAttachedAxis, slotDuration: options.slotDuration, slatMetas: slatMetas, forPrint: props.forPrint, tableColGroupNode: contentArg.tableColGroupNode, tableMinWidth: contentArg.tableMinWidth, clientWidth: contentArg.clientWidth, clientHeight: contentArg.clientHeight, onSlatCoords: _this.handleSlatCoords, expandRows: contentArg.expandRows, onScrollTopRequest: _this.handleScrollTopRequest }))); };
  13732. return hasDetachedAxis
  13733. ? this.renderHScrollLayout(headerContent, allDayContent, timeGridContent, dayTableModel.colCnt, dayMinWidth, slatMetas, this.state.slatCoords)
  13734. : this.renderSimpleLayout(headerContent, allDayContent, timeGridContent);
  13735. };
  13736. return DayTimeColsView;
  13737. }(TimeColsView));
  13738. function buildTimeColsModel(dateProfile, dateProfileGenerator) {
  13739. var daySeries = new DaySeriesModel(dateProfile.renderRange, dateProfileGenerator);
  13740. return new DayTableModel(daySeries, false);
  13741. }
  13742. var OPTION_REFINERS$2 = {
  13743. allDaySlot: Boolean,
  13744. };
  13745. var timeGridPlugin = createPlugin({
  13746. initialView: 'timeGridWeek',
  13747. optionRefiners: OPTION_REFINERS$2,
  13748. views: {
  13749. timeGrid: {
  13750. component: DayTimeColsView,
  13751. usesMinMaxTime: true,
  13752. allDaySlot: true,
  13753. slotDuration: '00:30:00',
  13754. slotEventOverlap: true, // a bad name. confused with overlap/constraint system
  13755. },
  13756. timeGridDay: {
  13757. type: 'timeGrid',
  13758. duration: { days: 1 },
  13759. },
  13760. timeGridWeek: {
  13761. type: 'timeGrid',
  13762. duration: { weeks: 1 },
  13763. },
  13764. },
  13765. });
  13766. var ListViewHeaderRow = /** @class */ (function (_super) {
  13767. __extends(ListViewHeaderRow, _super);
  13768. function ListViewHeaderRow() {
  13769. return _super !== null && _super.apply(this, arguments) || this;
  13770. }
  13771. ListViewHeaderRow.prototype.render = function () {
  13772. var _a = this.props, dayDate = _a.dayDate, todayRange = _a.todayRange;
  13773. var _b = this.context, theme = _b.theme, dateEnv = _b.dateEnv, options = _b.options, viewApi = _b.viewApi;
  13774. var dayMeta = getDateMeta(dayDate, todayRange);
  13775. // will ever be falsy?
  13776. var text = options.listDayFormat ? dateEnv.format(dayDate, options.listDayFormat) : '';
  13777. // will ever be falsy? also, BAD NAME "alt"
  13778. var sideText = options.listDaySideFormat ? dateEnv.format(dayDate, options.listDaySideFormat) : '';
  13779. var navLinkData = options.navLinks
  13780. ? buildNavLinkData(dayDate)
  13781. : null;
  13782. var hookProps = __assign({ date: dateEnv.toDate(dayDate), view: viewApi, text: text,
  13783. sideText: sideText,
  13784. navLinkData: navLinkData }, dayMeta);
  13785. var classNames = ['fc-list-day'].concat(getDayClassNames(dayMeta, theme));
  13786. // TODO: make a reusable HOC for dayHeader (used in daygrid/timegrid too)
  13787. return (createElement(RenderHook, { hookProps: hookProps, classNames: options.dayHeaderClassNames, content: options.dayHeaderContent, defaultContent: renderInnerContent, didMount: options.dayHeaderDidMount, willUnmount: options.dayHeaderWillUnmount }, function (rootElRef, customClassNames, innerElRef, innerContent) { return (createElement("tr", { ref: rootElRef, className: classNames.concat(customClassNames).join(' '), "data-date": formatDayString(dayDate) },
  13788. createElement("th", { colSpan: 3 },
  13789. createElement("div", { className: 'fc-list-day-cushion ' + theme.getClass('tableCellShaded'), ref: innerElRef }, innerContent)))); }));
  13790. };
  13791. return ListViewHeaderRow;
  13792. }(BaseComponent));
  13793. function renderInnerContent(props) {
  13794. var navLinkAttrs = props.navLinkData // is there a type for this?
  13795. ? { 'data-navlink': props.navLinkData, tabIndex: 0 }
  13796. : {};
  13797. return (createElement(Fragment, null,
  13798. props.text && (createElement("a", __assign({ className: "fc-list-day-text" }, navLinkAttrs), props.text)),
  13799. props.sideText && (createElement("a", __assign({ className: "fc-list-day-side-text" }, navLinkAttrs), props.sideText))));
  13800. }
  13801. var DEFAULT_TIME_FORMAT = createFormatter({
  13802. hour: 'numeric',
  13803. minute: '2-digit',
  13804. meridiem: 'short',
  13805. });
  13806. var ListViewEventRow = /** @class */ (function (_super) {
  13807. __extends(ListViewEventRow, _super);
  13808. function ListViewEventRow() {
  13809. return _super !== null && _super.apply(this, arguments) || this;
  13810. }
  13811. ListViewEventRow.prototype.render = function () {
  13812. var _a = this, props = _a.props, context = _a.context;
  13813. var seg = props.seg;
  13814. var timeFormat = context.options.eventTimeFormat || DEFAULT_TIME_FORMAT;
  13815. return (createElement(EventRoot, { seg: seg, timeText: "" // BAD. because of all-day content
  13816. , disableDragging: true, disableResizing: true, defaultContent: renderEventInnerContent, isPast: props.isPast, isFuture: props.isFuture, isToday: props.isToday, isSelected: props.isSelected, isDragging: props.isDragging, isResizing: props.isResizing, isDateSelecting: props.isDateSelecting }, function (rootElRef, classNames, innerElRef, innerContent, hookProps) { return (createElement("tr", { className: ['fc-list-event', hookProps.event.url ? 'fc-event-forced-url' : ''].concat(classNames).join(' '), ref: rootElRef },
  13817. buildTimeContent(seg, timeFormat, context),
  13818. createElement("td", { className: "fc-list-event-graphic" },
  13819. createElement("span", { className: "fc-list-event-dot", style: { borderColor: hookProps.borderColor || hookProps.backgroundColor } })),
  13820. createElement("td", { className: "fc-list-event-title", ref: innerElRef }, innerContent))); }));
  13821. };
  13822. return ListViewEventRow;
  13823. }(BaseComponent));
  13824. function renderEventInnerContent(props) {
  13825. var event = props.event;
  13826. var url = event.url;
  13827. var anchorAttrs = url ? { href: url } : {};
  13828. return (createElement("a", __assign({}, anchorAttrs), event.title));
  13829. }
  13830. function buildTimeContent(seg, timeFormat, context) {
  13831. var options = context.options;
  13832. if (options.displayEventTime !== false) {
  13833. var eventDef = seg.eventRange.def;
  13834. var eventInstance = seg.eventRange.instance;
  13835. var doAllDay = false;
  13836. var timeText = void 0;
  13837. if (eventDef.allDay) {
  13838. doAllDay = true;
  13839. }
  13840. else if (isMultiDayRange(seg.eventRange.range)) { // TODO: use (!isStart || !isEnd) instead?
  13841. if (seg.isStart) {
  13842. timeText = buildSegTimeText(seg, timeFormat, context, null, null, eventInstance.range.start, seg.end);
  13843. }
  13844. else if (seg.isEnd) {
  13845. timeText = buildSegTimeText(seg, timeFormat, context, null, null, seg.start, eventInstance.range.end);
  13846. }
  13847. else {
  13848. doAllDay = true;
  13849. }
  13850. }
  13851. else {
  13852. timeText = buildSegTimeText(seg, timeFormat, context);
  13853. }
  13854. if (doAllDay) {
  13855. var hookProps = {
  13856. text: context.options.allDayText,
  13857. view: context.viewApi,
  13858. };
  13859. return (createElement(RenderHook, { hookProps: hookProps, classNames: options.allDayClassNames, content: options.allDayContent, defaultContent: renderAllDayInner, didMount: options.allDayDidMount, willUnmount: options.allDayWillUnmount }, function (rootElRef, classNames, innerElRef, innerContent) { return (createElement("td", { className: ['fc-list-event-time'].concat(classNames).join(' '), ref: rootElRef }, innerContent)); }));
  13860. }
  13861. return (createElement("td", { className: "fc-list-event-time" }, timeText));
  13862. }
  13863. return null;
  13864. }
  13865. function renderAllDayInner(hookProps) {
  13866. return hookProps.text;
  13867. }
  13868. /*
  13869. Responsible for the scroller, and forwarding event-related actions into the "grid".
  13870. */
  13871. var ListView = /** @class */ (function (_super) {
  13872. __extends(ListView, _super);
  13873. function ListView() {
  13874. var _this = _super !== null && _super.apply(this, arguments) || this;
  13875. _this.computeDateVars = memoize(computeDateVars);
  13876. _this.eventStoreToSegs = memoize(_this._eventStoreToSegs);
  13877. _this.setRootEl = function (rootEl) {
  13878. if (rootEl) {
  13879. _this.context.registerInteractiveComponent(_this, {
  13880. el: rootEl,
  13881. });
  13882. }
  13883. else {
  13884. _this.context.unregisterInteractiveComponent(_this);
  13885. }
  13886. };
  13887. return _this;
  13888. }
  13889. ListView.prototype.render = function () {
  13890. var _this = this;
  13891. var _a = this, props = _a.props, context = _a.context;
  13892. var extraClassNames = [
  13893. 'fc-list',
  13894. context.theme.getClass('table'),
  13895. context.options.stickyHeaderDates !== false ? 'fc-list-sticky' : '',
  13896. ];
  13897. var _b = this.computeDateVars(props.dateProfile), dayDates = _b.dayDates, dayRanges = _b.dayRanges;
  13898. var eventSegs = this.eventStoreToSegs(props.eventStore, props.eventUiBases, dayRanges);
  13899. return (createElement(ViewRoot, { viewSpec: context.viewSpec, elRef: this.setRootEl }, function (rootElRef, classNames) { return (createElement("div", { ref: rootElRef, className: extraClassNames.concat(classNames).join(' ') },
  13900. createElement(Scroller, { liquid: !props.isHeightAuto, overflowX: props.isHeightAuto ? 'visible' : 'hidden', overflowY: props.isHeightAuto ? 'visible' : 'auto' }, eventSegs.length > 0 ?
  13901. _this.renderSegList(eventSegs, dayDates) :
  13902. _this.renderEmptyMessage()))); }));
  13903. };
  13904. ListView.prototype.renderEmptyMessage = function () {
  13905. var _a = this.context, options = _a.options, viewApi = _a.viewApi;
  13906. var hookProps = {
  13907. text: options.noEventsText,
  13908. view: viewApi,
  13909. };
  13910. return (createElement(RenderHook, { hookProps: hookProps, classNames: options.noEventsClassNames, content: options.noEventsContent, defaultContent: renderNoEventsInner, didMount: options.noEventsDidMount, willUnmount: options.noEventsWillUnmount }, function (rootElRef, classNames, innerElRef, innerContent) { return (createElement("div", { className: ['fc-list-empty'].concat(classNames).join(' '), ref: rootElRef },
  13911. createElement("div", { className: "fc-list-empty-cushion", ref: innerElRef }, innerContent))); }));
  13912. };
  13913. ListView.prototype.renderSegList = function (allSegs, dayDates) {
  13914. var _a = this.context, theme = _a.theme, options = _a.options;
  13915. var segsByDay = groupSegsByDay(allSegs); // sparse array
  13916. return (createElement(NowTimer, { unit: "day" }, function (nowDate, todayRange) {
  13917. var innerNodes = [];
  13918. for (var dayIndex = 0; dayIndex < segsByDay.length; dayIndex += 1) {
  13919. var daySegs = segsByDay[dayIndex];
  13920. if (daySegs) { // sparse array, so might be undefined
  13921. var dayStr = dayDates[dayIndex].toISOString();
  13922. // append a day header
  13923. innerNodes.push(createElement(ListViewHeaderRow, { key: dayStr, dayDate: dayDates[dayIndex], todayRange: todayRange }));
  13924. daySegs = sortEventSegs(daySegs, options.eventOrder);
  13925. for (var _i = 0, daySegs_1 = daySegs; _i < daySegs_1.length; _i++) {
  13926. var seg = daySegs_1[_i];
  13927. innerNodes.push(createElement(ListViewEventRow, __assign({ key: dayStr + ':' + seg.eventRange.instance.instanceId /* are multiple segs for an instanceId */, seg: seg, isDragging: false, isResizing: false, isDateSelecting: false, isSelected: false }, getSegMeta(seg, todayRange, nowDate))));
  13928. }
  13929. }
  13930. }
  13931. return (createElement("table", { className: 'fc-list-table ' + theme.getClass('table') },
  13932. createElement("tbody", null, innerNodes)));
  13933. }));
  13934. };
  13935. ListView.prototype._eventStoreToSegs = function (eventStore, eventUiBases, dayRanges) {
  13936. return this.eventRangesToSegs(sliceEventStore(eventStore, eventUiBases, this.props.dateProfile.activeRange, this.context.options.nextDayThreshold).fg, dayRanges);
  13937. };
  13938. ListView.prototype.eventRangesToSegs = function (eventRanges, dayRanges) {
  13939. var segs = [];
  13940. for (var _i = 0, eventRanges_1 = eventRanges; _i < eventRanges_1.length; _i++) {
  13941. var eventRange = eventRanges_1[_i];
  13942. segs.push.apply(segs, this.eventRangeToSegs(eventRange, dayRanges));
  13943. }
  13944. return segs;
  13945. };
  13946. ListView.prototype.eventRangeToSegs = function (eventRange, dayRanges) {
  13947. var dateEnv = this.context.dateEnv;
  13948. var nextDayThreshold = this.context.options.nextDayThreshold;
  13949. var range = eventRange.range;
  13950. var allDay = eventRange.def.allDay;
  13951. var dayIndex;
  13952. var segRange;
  13953. var seg;
  13954. var segs = [];
  13955. for (dayIndex = 0; dayIndex < dayRanges.length; dayIndex += 1) {
  13956. segRange = intersectRanges(range, dayRanges[dayIndex]);
  13957. if (segRange) {
  13958. seg = {
  13959. component: this,
  13960. eventRange: eventRange,
  13961. start: segRange.start,
  13962. end: segRange.end,
  13963. isStart: eventRange.isStart && segRange.start.valueOf() === range.start.valueOf(),
  13964. isEnd: eventRange.isEnd && segRange.end.valueOf() === range.end.valueOf(),
  13965. dayIndex: dayIndex,
  13966. };
  13967. segs.push(seg);
  13968. // detect when range won't go fully into the next day,
  13969. // and mutate the latest seg to the be the end.
  13970. if (!seg.isEnd && !allDay &&
  13971. dayIndex + 1 < dayRanges.length &&
  13972. range.end <
  13973. dateEnv.add(dayRanges[dayIndex + 1].start, nextDayThreshold)) {
  13974. seg.end = range.end;
  13975. seg.isEnd = true;
  13976. break;
  13977. }
  13978. }
  13979. }
  13980. return segs;
  13981. };
  13982. return ListView;
  13983. }(DateComponent));
  13984. function renderNoEventsInner(hookProps) {
  13985. return hookProps.text;
  13986. }
  13987. function computeDateVars(dateProfile) {
  13988. var dayStart = startOfDay(dateProfile.renderRange.start);
  13989. var viewEnd = dateProfile.renderRange.end;
  13990. var dayDates = [];
  13991. var dayRanges = [];
  13992. while (dayStart < viewEnd) {
  13993. dayDates.push(dayStart);
  13994. dayRanges.push({
  13995. start: dayStart,
  13996. end: addDays(dayStart, 1),
  13997. });
  13998. dayStart = addDays(dayStart, 1);
  13999. }
  14000. return { dayDates: dayDates, dayRanges: dayRanges };
  14001. }
  14002. // Returns a sparse array of arrays, segs grouped by their dayIndex
  14003. function groupSegsByDay(segs) {
  14004. var segsByDay = []; // sparse array
  14005. var i;
  14006. var seg;
  14007. for (i = 0; i < segs.length; i += 1) {
  14008. seg = segs[i];
  14009. (segsByDay[seg.dayIndex] || (segsByDay[seg.dayIndex] = []))
  14010. .push(seg);
  14011. }
  14012. return segsByDay;
  14013. }
  14014. var OPTION_REFINERS$1 = {
  14015. listDayFormat: createFalsableFormatter,
  14016. listDaySideFormat: createFalsableFormatter,
  14017. noEventsClassNames: identity,
  14018. noEventsContent: identity,
  14019. noEventsDidMount: identity,
  14020. noEventsWillUnmount: identity,
  14021. // noEventsText is defined in base options
  14022. };
  14023. function createFalsableFormatter(input) {
  14024. return input === false ? null : createFormatter(input);
  14025. }
  14026. var listPlugin = createPlugin({
  14027. optionRefiners: OPTION_REFINERS$1,
  14028. views: {
  14029. list: {
  14030. component: ListView,
  14031. buttonTextKey: 'list',
  14032. listDayFormat: { month: 'long', day: 'numeric', year: 'numeric' }, // like "January 1, 2016"
  14033. },
  14034. listDay: {
  14035. type: 'list',
  14036. duration: { days: 1 },
  14037. listDayFormat: { weekday: 'long' }, // day-of-week is all we need. full date is probably in headerToolbar
  14038. },
  14039. listWeek: {
  14040. type: 'list',
  14041. duration: { weeks: 1 },
  14042. listDayFormat: { weekday: 'long' },
  14043. listDaySideFormat: { month: 'long', day: 'numeric', year: 'numeric' },
  14044. },
  14045. listMonth: {
  14046. type: 'list',
  14047. duration: { month: 1 },
  14048. listDaySideFormat: { weekday: 'long' }, // day-of-week is nice-to-have
  14049. },
  14050. listYear: {
  14051. type: 'list',
  14052. duration: { year: 1 },
  14053. listDaySideFormat: { weekday: 'long' }, // day-of-week is nice-to-have
  14054. },
  14055. },
  14056. });
  14057. var BootstrapTheme = /** @class */ (function (_super) {
  14058. __extends(BootstrapTheme, _super);
  14059. function BootstrapTheme() {
  14060. return _super !== null && _super.apply(this, arguments) || this;
  14061. }
  14062. return BootstrapTheme;
  14063. }(Theme));
  14064. BootstrapTheme.prototype.classes = {
  14065. root: 'fc-theme-bootstrap',
  14066. table: 'table-bordered',
  14067. tableCellShaded: 'table-active',
  14068. buttonGroup: 'btn-group',
  14069. button: 'btn btn-primary',
  14070. buttonActive: 'active',
  14071. popover: 'popover',
  14072. popoverHeader: 'popover-header',
  14073. popoverContent: 'popover-body',
  14074. };
  14075. BootstrapTheme.prototype.baseIconClass = 'fa';
  14076. BootstrapTheme.prototype.iconClasses = {
  14077. close: 'fa-times',
  14078. prev: 'fa-chevron-left',
  14079. next: 'fa-chevron-right',
  14080. prevYear: 'fa-angle-double-left',
  14081. nextYear: 'fa-angle-double-right',
  14082. };
  14083. BootstrapTheme.prototype.rtlIconClasses = {
  14084. prev: 'fa-chevron-right',
  14085. next: 'fa-chevron-left',
  14086. prevYear: 'fa-angle-double-right',
  14087. nextYear: 'fa-angle-double-left',
  14088. };
  14089. BootstrapTheme.prototype.iconOverrideOption = 'bootstrapFontAwesome'; // TODO: make TS-friendly. move the option-processing into this plugin
  14090. BootstrapTheme.prototype.iconOverrideCustomButtonOption = 'bootstrapFontAwesome';
  14091. BootstrapTheme.prototype.iconOverridePrefix = 'fa-';
  14092. var plugin = createPlugin({
  14093. themeClasses: {
  14094. bootstrap: BootstrapTheme,
  14095. },
  14096. });
  14097. // rename this file to options.ts like other packages?
  14098. var OPTION_REFINERS = {
  14099. googleCalendarApiKey: String,
  14100. };
  14101. var EVENT_SOURCE_REFINERS = {
  14102. googleCalendarApiKey: String,
  14103. googleCalendarId: String,
  14104. googleCalendarApiBase: String,
  14105. extraParams: identity,
  14106. };
  14107. // TODO: expose somehow
  14108. var API_BASE = 'https://www.googleapis.com/calendar/v3/calendars';
  14109. var eventSourceDef = {
  14110. parseMeta: function (refined) {
  14111. var googleCalendarId = refined.googleCalendarId;
  14112. if (!googleCalendarId && refined.url) {
  14113. googleCalendarId = parseGoogleCalendarId(refined.url);
  14114. }
  14115. if (googleCalendarId) {
  14116. return {
  14117. googleCalendarId: googleCalendarId,
  14118. googleCalendarApiKey: refined.googleCalendarApiKey,
  14119. googleCalendarApiBase: refined.googleCalendarApiBase,
  14120. extraParams: refined.extraParams,
  14121. };
  14122. }
  14123. return null;
  14124. },
  14125. fetch: function (arg, onSuccess, onFailure) {
  14126. var _a = arg.context, dateEnv = _a.dateEnv, options = _a.options;
  14127. var meta = arg.eventSource.meta;
  14128. var apiKey = meta.googleCalendarApiKey || options.googleCalendarApiKey;
  14129. if (!apiKey) {
  14130. onFailure({
  14131. message: 'Specify a googleCalendarApiKey. See http://fullcalendar.io/docs/google_calendar/',
  14132. });
  14133. }
  14134. else {
  14135. var url = buildUrl(meta);
  14136. // TODO: make DRY with json-feed-event-source
  14137. var extraParams = meta.extraParams;
  14138. var extraParamsObj = typeof extraParams === 'function' ? extraParams() : extraParams;
  14139. var requestParams_1 = buildRequestParams(arg.range, apiKey, extraParamsObj, dateEnv);
  14140. requestJson('GET', url, requestParams_1, function (body, xhr) {
  14141. if (body.error) {
  14142. onFailure({
  14143. message: 'Google Calendar API: ' + body.error.message,
  14144. errors: body.error.errors,
  14145. xhr: xhr,
  14146. });
  14147. }
  14148. else {
  14149. onSuccess({
  14150. rawEvents: gcalItemsToRawEventDefs(body.items, requestParams_1.timeZone),
  14151. xhr: xhr,
  14152. });
  14153. }
  14154. }, function (message, xhr) {
  14155. onFailure({ message: message, xhr: xhr });
  14156. });
  14157. }
  14158. },
  14159. };
  14160. function parseGoogleCalendarId(url) {
  14161. var match;
  14162. // detect if the ID was specified as a single string.
  14163. // will match calendars like "asdf1234@calendar.google.com" in addition to person email calendars.
  14164. if (/^[^/]+@([^/.]+\.)*(google|googlemail|gmail)\.com$/.test(url)) {
  14165. return url;
  14166. }
  14167. if ((match = /^https:\/\/www.googleapis.com\/calendar\/v3\/calendars\/([^/]*)/.exec(url)) ||
  14168. (match = /^https?:\/\/www.google.com\/calendar\/feeds\/([^/]*)/.exec(url))) {
  14169. return decodeURIComponent(match[1]);
  14170. }
  14171. return null;
  14172. }
  14173. function buildUrl(meta) {
  14174. var apiBase = meta.googleCalendarApiBase;
  14175. if (!apiBase) {
  14176. apiBase = API_BASE;
  14177. }
  14178. return apiBase + '/' + encodeURIComponent(meta.googleCalendarId) + '/events';
  14179. }
  14180. function buildRequestParams(range, apiKey, extraParams, dateEnv) {
  14181. var params;
  14182. var startStr;
  14183. var endStr;
  14184. if (dateEnv.canComputeOffset) {
  14185. // strings will naturally have offsets, which GCal needs
  14186. startStr = dateEnv.formatIso(range.start);
  14187. endStr = dateEnv.formatIso(range.end);
  14188. }
  14189. else {
  14190. // when timezone isn't known, we don't know what the UTC offset should be, so ask for +/- 1 day
  14191. // from the UTC day-start to guarantee we're getting all the events
  14192. // (start/end will be UTC-coerced dates, so toISOString is okay)
  14193. startStr = addDays(range.start, -1).toISOString();
  14194. endStr = addDays(range.end, 1).toISOString();
  14195. }
  14196. params = __assign(__assign({}, (extraParams || {})), { key: apiKey, timeMin: startStr, timeMax: endStr, singleEvents: true, maxResults: 9999 });
  14197. if (dateEnv.timeZone !== 'local') {
  14198. params.timeZone = dateEnv.timeZone;
  14199. }
  14200. return params;
  14201. }
  14202. function gcalItemsToRawEventDefs(items, gcalTimezone) {
  14203. return items.map(function (item) { return gcalItemToRawEventDef(item, gcalTimezone); });
  14204. }
  14205. function gcalItemToRawEventDef(item, gcalTimezone) {
  14206. var url = item.htmlLink || null;
  14207. // make the URLs for each event show times in the correct timezone
  14208. if (url && gcalTimezone) {
  14209. url = injectQsComponent(url, 'ctz=' + gcalTimezone);
  14210. }
  14211. return {
  14212. id: item.id,
  14213. title: item.summary,
  14214. start: item.start.dateTime || item.start.date,
  14215. end: item.end.dateTime || item.end.date,
  14216. url: url,
  14217. location: item.location,
  14218. description: item.description,
  14219. attachments: item.attachments || [],
  14220. extendedProps: (item.extendedProperties || {}).shared || {},
  14221. };
  14222. }
  14223. // Injects a string like "arg=value" into the querystring of a URL
  14224. // TODO: move to a general util file?
  14225. function injectQsComponent(url, component) {
  14226. // inject it after the querystring but before the fragment
  14227. return url.replace(/(\?.*?)?(#|$)/, function (whole, qs, hash) { return (qs ? qs + '&' : '?') + component + hash; });
  14228. }
  14229. var googleCalendarPlugin = createPlugin({
  14230. eventSourceDefs: [eventSourceDef],
  14231. optionRefiners: OPTION_REFINERS,
  14232. eventSourceRefiners: EVENT_SOURCE_REFINERS,
  14233. });
  14234. globalPlugins.push(interactionPlugin, dayGridPlugin, timeGridPlugin, listPlugin, plugin, googleCalendarPlugin);
  14235. exports.BASE_OPTION_DEFAULTS = BASE_OPTION_DEFAULTS;
  14236. exports.BASE_OPTION_REFINERS = BASE_OPTION_REFINERS;
  14237. exports.BaseComponent = BaseComponent;
  14238. exports.BgEvent = BgEvent;
  14239. exports.BootstrapTheme = BootstrapTheme;
  14240. exports.Calendar = Calendar;
  14241. exports.CalendarApi = CalendarApi;
  14242. exports.CalendarContent = CalendarContent;
  14243. exports.CalendarDataManager = CalendarDataManager;
  14244. exports.CalendarDataProvider = CalendarDataProvider;
  14245. exports.CalendarRoot = CalendarRoot;
  14246. exports.Component = Component;
  14247. exports.ContentHook = ContentHook;
  14248. exports.CustomContentRenderContext = CustomContentRenderContext;
  14249. exports.DateComponent = DateComponent;
  14250. exports.DateEnv = DateEnv;
  14251. exports.DateProfileGenerator = DateProfileGenerator;
  14252. exports.DayCellContent = DayCellContent;
  14253. exports.DayCellRoot = DayCellRoot;
  14254. exports.DayGridView = DayTableView;
  14255. exports.DayHeader = DayHeader;
  14256. exports.DaySeriesModel = DaySeriesModel;
  14257. exports.DayTable = DayTable;
  14258. exports.DayTableModel = DayTableModel;
  14259. exports.DayTableSlicer = DayTableSlicer;
  14260. exports.DayTimeCols = DayTimeCols;
  14261. exports.DayTimeColsSlicer = DayTimeColsSlicer;
  14262. exports.DayTimeColsView = DayTimeColsView;
  14263. exports.DelayedRunner = DelayedRunner;
  14264. exports.Draggable = ExternalDraggable;
  14265. exports.ElementDragging = ElementDragging;
  14266. exports.ElementScrollController = ElementScrollController;
  14267. exports.Emitter = Emitter;
  14268. exports.EventApi = EventApi;
  14269. exports.EventRoot = EventRoot;
  14270. exports.EventSourceApi = EventSourceApi;
  14271. exports.FeaturefulElementDragging = FeaturefulElementDragging;
  14272. exports.Fragment = Fragment;
  14273. exports.Interaction = Interaction;
  14274. exports.ListView = ListView;
  14275. exports.MoreLinkRoot = MoreLinkRoot;
  14276. exports.MountHook = MountHook;
  14277. exports.NamedTimeZoneImpl = NamedTimeZoneImpl;
  14278. exports.NowIndicatorRoot = NowIndicatorRoot;
  14279. exports.NowTimer = NowTimer;
  14280. exports.PointerDragging = PointerDragging;
  14281. exports.PositionCache = PositionCache;
  14282. exports.RefMap = RefMap;
  14283. exports.RenderHook = RenderHook;
  14284. exports.ScrollController = ScrollController;
  14285. exports.ScrollResponder = ScrollResponder;
  14286. exports.Scroller = Scroller;
  14287. exports.SegHierarchy = SegHierarchy;
  14288. exports.SimpleScrollGrid = SimpleScrollGrid;
  14289. exports.Slicer = Slicer;
  14290. exports.Splitter = Splitter;
  14291. exports.StandardEvent = StandardEvent;
  14292. exports.Table = Table;
  14293. exports.TableDateCell = TableDateCell;
  14294. exports.TableDowCell = TableDowCell;
  14295. exports.TableView = TableView;
  14296. exports.Theme = Theme;
  14297. exports.ThirdPartyDraggable = ThirdPartyDraggable;
  14298. exports.TimeCols = TimeCols;
  14299. exports.TimeColsSlatsCoords = TimeColsSlatsCoords;
  14300. exports.TimeColsView = TimeColsView;
  14301. exports.ViewApi = ViewApi;
  14302. exports.ViewContextType = ViewContextType;
  14303. exports.ViewRoot = ViewRoot;
  14304. exports.WeekNumberRoot = WeekNumberRoot;
  14305. exports.WindowScrollController = WindowScrollController;
  14306. exports.addDays = addDays;
  14307. exports.addDurations = addDurations;
  14308. exports.addMs = addMs;
  14309. exports.addWeeks = addWeeks;
  14310. exports.allowContextMenu = allowContextMenu;
  14311. exports.allowSelection = allowSelection;
  14312. exports.applyMutationToEventStore = applyMutationToEventStore;
  14313. exports.applyStyle = applyStyle;
  14314. exports.applyStyleProp = applyStyleProp;
  14315. exports.asCleanDays = asCleanDays;
  14316. exports.asRoughMinutes = asRoughMinutes;
  14317. exports.asRoughMs = asRoughMs;
  14318. exports.asRoughSeconds = asRoughSeconds;
  14319. exports.binarySearch = binarySearch;
  14320. exports.buildClassNameNormalizer = buildClassNameNormalizer;
  14321. exports.buildDayRanges = buildDayRanges;
  14322. exports.buildDayTableModel = buildDayTableModel;
  14323. exports.buildEntryKey = buildEntryKey;
  14324. exports.buildEventApis = buildEventApis;
  14325. exports.buildEventRangeKey = buildEventRangeKey;
  14326. exports.buildHashFromArray = buildHashFromArray;
  14327. exports.buildIsoString = buildIsoString;
  14328. exports.buildNavLinkData = buildNavLinkData;
  14329. exports.buildSegCompareObj = buildSegCompareObj;
  14330. exports.buildSegTimeText = buildSegTimeText;
  14331. exports.buildSlatMetas = buildSlatMetas;
  14332. exports.buildTimeColsModel = buildTimeColsModel;
  14333. exports.collectFromHash = collectFromHash;
  14334. exports.combineEventUis = combineEventUis;
  14335. exports.compareByFieldSpec = compareByFieldSpec;
  14336. exports.compareByFieldSpecs = compareByFieldSpecs;
  14337. exports.compareNumbers = compareNumbers;
  14338. exports.compareObjs = compareObjs;
  14339. exports.computeEarliestSegStart = computeEarliestSegStart;
  14340. exports.computeEdges = computeEdges;
  14341. exports.computeFallbackHeaderFormat = computeFallbackHeaderFormat;
  14342. exports.computeHeightAndMargins = computeHeightAndMargins;
  14343. exports.computeInnerRect = computeInnerRect;
  14344. exports.computeRect = computeRect;
  14345. exports.computeSegDraggable = computeSegDraggable;
  14346. exports.computeSegEndResizable = computeSegEndResizable;
  14347. exports.computeSegStartResizable = computeSegStartResizable;
  14348. exports.computeShrinkWidth = computeShrinkWidth;
  14349. exports.computeSmallestCellWidth = computeSmallestCellWidth;
  14350. exports.computeVisibleDayRange = computeVisibleDayRange;
  14351. exports.config = config;
  14352. exports.constrainPoint = constrainPoint;
  14353. exports.createContext = createContext;
  14354. exports.createDuration = createDuration;
  14355. exports.createElement = createElement;
  14356. exports.createEmptyEventStore = createEmptyEventStore;
  14357. exports.createEventInstance = createEventInstance;
  14358. exports.createEventUi = createEventUi;
  14359. exports.createFormatter = createFormatter;
  14360. exports.createPlugin = createPlugin;
  14361. exports.createPortal = createPortal;
  14362. exports.createRef = createRef;
  14363. exports.diffDates = diffDates;
  14364. exports.diffDayAndTime = diffDayAndTime;
  14365. exports.diffDays = diffDays;
  14366. exports.diffPoints = diffPoints;
  14367. exports.diffWeeks = diffWeeks;
  14368. exports.diffWholeDays = diffWholeDays;
  14369. exports.diffWholeWeeks = diffWholeWeeks;
  14370. exports.disableCursor = disableCursor;
  14371. exports.elementClosest = elementClosest;
  14372. exports.elementMatches = elementMatches;
  14373. exports.enableCursor = enableCursor;
  14374. exports.eventTupleToStore = eventTupleToStore;
  14375. exports.filterEventStoreDefs = filterEventStoreDefs;
  14376. exports.filterHash = filterHash;
  14377. exports.findDirectChildren = findDirectChildren;
  14378. exports.findElements = findElements;
  14379. exports.flexibleCompare = flexibleCompare;
  14380. exports.flushToDom = flushToDom;
  14381. exports.formatDate = formatDate;
  14382. exports.formatDayString = formatDayString;
  14383. exports.formatIsoTimeString = formatIsoTimeString;
  14384. exports.formatRange = formatRange;
  14385. exports.getAllowYScrolling = getAllowYScrolling;
  14386. exports.getCanVGrowWithinCell = getCanVGrowWithinCell;
  14387. exports.getClippingParents = getClippingParents;
  14388. exports.getDateMeta = getDateMeta;
  14389. exports.getDayClassNames = getDayClassNames;
  14390. exports.getDefaultEventEnd = getDefaultEventEnd;
  14391. exports.getElSeg = getElSeg;
  14392. exports.getEntrySpanEnd = getEntrySpanEnd;
  14393. exports.getEventClassNames = getEventClassNames;
  14394. exports.getIsRtlScrollbarOnLeft = getIsRtlScrollbarOnLeft;
  14395. exports.getRectCenter = getRectCenter;
  14396. exports.getRelevantEvents = getRelevantEvents;
  14397. exports.getScrollGridClassNames = getScrollGridClassNames;
  14398. exports.getScrollbarWidths = getScrollbarWidths;
  14399. exports.getSectionClassNames = getSectionClassNames;
  14400. exports.getSectionHasLiquidHeight = getSectionHasLiquidHeight;
  14401. exports.getSegMeta = getSegMeta;
  14402. exports.getSlotClassNames = getSlotClassNames;
  14403. exports.getStickyFooterScrollbar = getStickyFooterScrollbar;
  14404. exports.getStickyHeaderDates = getStickyHeaderDates;
  14405. exports.getUnequalProps = getUnequalProps;
  14406. exports.globalLocales = globalLocales;
  14407. exports.globalPlugins = globalPlugins;
  14408. exports.greatestDurationDenominator = greatestDurationDenominator;
  14409. exports.groupIntersectingEntries = groupIntersectingEntries;
  14410. exports.guid = guid;
  14411. exports.hasBgRendering = hasBgRendering;
  14412. exports.hasShrinkWidth = hasShrinkWidth;
  14413. exports.identity = identity;
  14414. exports.interactionSettingsStore = interactionSettingsStore;
  14415. exports.interactionSettingsToStore = interactionSettingsToStore;
  14416. exports.intersectRanges = intersectRanges;
  14417. exports.intersectRects = intersectRects;
  14418. exports.intersectSpans = intersectSpans;
  14419. exports.isArraysEqual = isArraysEqual;
  14420. exports.isColPropsEqual = isColPropsEqual;
  14421. exports.isDateSelectionValid = isDateSelectionValid;
  14422. exports.isDateSpansEqual = isDateSpansEqual;
  14423. exports.isInt = isInt;
  14424. exports.isInteractionValid = isInteractionValid;
  14425. exports.isMultiDayRange = isMultiDayRange;
  14426. exports.isPropsEqual = isPropsEqual;
  14427. exports.isPropsValid = isPropsValid;
  14428. exports.isValidDate = isValidDate;
  14429. exports.joinSpans = joinSpans;
  14430. exports.listenBySelector = listenBySelector;
  14431. exports.mapHash = mapHash;
  14432. exports.memoize = memoize;
  14433. exports.memoizeArraylike = memoizeArraylike;
  14434. exports.memoizeHashlike = memoizeHashlike;
  14435. exports.memoizeObjArg = memoizeObjArg;
  14436. exports.mergeEventStores = mergeEventStores;
  14437. exports.multiplyDuration = multiplyDuration;
  14438. exports.padStart = padStart;
  14439. exports.parseBusinessHours = parseBusinessHours;
  14440. exports.parseClassNames = parseClassNames;
  14441. exports.parseDragMeta = parseDragMeta;
  14442. exports.parseEventDef = parseEventDef;
  14443. exports.parseFieldSpecs = parseFieldSpecs;
  14444. exports.parseMarker = parse;
  14445. exports.pointInsideRect = pointInsideRect;
  14446. exports.preventContextMenu = preventContextMenu;
  14447. exports.preventDefault = preventDefault;
  14448. exports.preventSelection = preventSelection;
  14449. exports.rangeContainsMarker = rangeContainsMarker;
  14450. exports.rangeContainsRange = rangeContainsRange;
  14451. exports.rangesEqual = rangesEqual;
  14452. exports.rangesIntersect = rangesIntersect;
  14453. exports.refineEventDef = refineEventDef;
  14454. exports.refineProps = refineProps;
  14455. exports.removeElement = removeElement;
  14456. exports.removeExact = removeExact;
  14457. exports.render = render;
  14458. exports.renderChunkContent = renderChunkContent;
  14459. exports.renderFill = renderFill;
  14460. exports.renderMicroColGroup = renderMicroColGroup;
  14461. exports.renderScrollShim = renderScrollShim;
  14462. exports.requestJson = requestJson;
  14463. exports.sanitizeShrinkWidth = sanitizeShrinkWidth;
  14464. exports.setElSeg = setElSeg;
  14465. exports.setRef = setRef;
  14466. exports.sliceEventStore = sliceEventStore;
  14467. exports.sliceEvents = sliceEvents;
  14468. exports.sortEventSegs = sortEventSegs;
  14469. exports.startOfDay = startOfDay;
  14470. exports.translateRect = translateRect;
  14471. exports.triggerDateSelect = triggerDateSelect;
  14472. exports.unmountComponentAtNode = unmountComponentAtNode;
  14473. exports.unpromisify = unpromisify;
  14474. exports.version = version;
  14475. exports.whenTransitionDone = whenTransitionDone;
  14476. exports.wholeDivideDurations = wholeDivideDurations;
  14477. Object.defineProperty(exports, '__esModule', { value: true });
  14478. return exports;
  14479. }({}));