ngx-bootstrap-datepicker.js 169 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140
  1. import { Injectable, EventEmitter, Component, Renderer2, ElementRef, Directive, ViewContainerRef, Input, Output, forwardRef, Host, ChangeDetectorRef, ChangeDetectionStrategy, NgModule, ViewChild } from '@angular/core';
  2. import { filter, map, take } from 'rxjs/operators';
  3. import { getMonth, getFullYear, isFirstDayOfWeek, getDay, shiftDate, isBefore, endOf, isAfter, startOf, isSame, getFirstDayOfMonth, formatDate, getLocale, isSameMonth, isSameDay, isDisabledDay, isSameYear, setFullDate, isDateValid, isArray, isDate, parseDate, utcAsLocal } from 'ngx-bootstrap/chronos';
  4. import { BehaviorSubject } from 'rxjs';
  5. import { MiniStore, MiniState } from 'ngx-bootstrap/mini-ngrx';
  6. import { PositioningService } from 'ngx-bootstrap/positioning';
  7. import { trigger, state, style, transition, animate } from '@angular/animations';
  8. import { ComponentLoaderFactory } from 'ngx-bootstrap/component-loader';
  9. import { NG_VALUE_ACCESSOR, NG_VALIDATORS, FormsModule } from '@angular/forms';
  10. import { CommonModule } from '@angular/common';
  11. import { isBs3 } from 'ngx-bootstrap/utils';
  12. /**
  13. * @fileoverview added by tsickle
  14. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  15. */
  16. /**
  17. * For date range picker there are `BsDaterangepickerConfig` which inherits all properties,
  18. * except `displayMonths`, for range picker it default to `2`
  19. */
  20. class BsDatepickerConfig {
  21. constructor() {
  22. /**
  23. * sets use adaptive position
  24. */
  25. this.adaptivePosition = false;
  26. /**
  27. * sets use UTC date time format
  28. */
  29. this.useUtc = false;
  30. /**
  31. * turn on/off animation
  32. */
  33. this.isAnimated = false;
  34. /**
  35. * CSS class which will be applied to datepicker container,
  36. * usually used to set color theme
  37. */
  38. this.containerClass = 'theme-green';
  39. // DatepickerRenderOptions
  40. this.displayMonths = 1;
  41. /**
  42. * Allows to hide week numbers in datepicker
  43. */
  44. this.showWeekNumbers = true;
  45. this.dateInputFormat = 'L';
  46. // range picker
  47. this.rangeSeparator = ' - ';
  48. /**
  49. * Date format for date range input field
  50. */
  51. this.rangeInputFormat = 'L';
  52. // DatepickerFormatOptions
  53. this.monthTitle = 'MMMM';
  54. this.yearTitle = 'YYYY';
  55. this.dayLabel = 'D';
  56. this.monthLabel = 'MMMM';
  57. this.yearLabel = 'YYYY';
  58. this.weekNumbers = 'w';
  59. }
  60. }
  61. BsDatepickerConfig.decorators = [
  62. { type: Injectable }
  63. ];
  64. /**
  65. * @fileoverview added by tsickle
  66. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  67. */
  68. /**
  69. * @abstract
  70. */
  71. class BsDatepickerAbstractComponent {
  72. constructor() {
  73. this._customRangesFish = [];
  74. }
  75. /**
  76. * @param {?} value
  77. * @return {?}
  78. */
  79. set minDate(value) {
  80. this._effects.setMinDate(value);
  81. }
  82. /**
  83. * @param {?} value
  84. * @return {?}
  85. */
  86. set maxDate(value) {
  87. this._effects.setMaxDate(value);
  88. }
  89. /**
  90. * @param {?} value
  91. * @return {?}
  92. */
  93. set daysDisabled(value) {
  94. this._effects.setDaysDisabled(value);
  95. }
  96. /**
  97. * @param {?} value
  98. * @return {?}
  99. */
  100. set datesDisabled(value) {
  101. this._effects.setDatesDisabled(value);
  102. }
  103. /**
  104. * @param {?} value
  105. * @return {?}
  106. */
  107. set isDisabled(value) {
  108. this._effects.setDisabled(value);
  109. }
  110. /**
  111. * @param {?} value
  112. * @return {?}
  113. */
  114. set dateCustomClasses(value) {
  115. this._effects.setDateCustomClasses(value);
  116. }
  117. /**
  118. * @param {?} event
  119. * @return {?}
  120. */
  121. setViewMode(event) { }
  122. /**
  123. * @param {?} event
  124. * @return {?}
  125. */
  126. navigateTo(event) { }
  127. /**
  128. * @param {?} event
  129. * @return {?}
  130. */
  131. dayHoverHandler(event) { }
  132. /**
  133. * @param {?} event
  134. * @return {?}
  135. */
  136. weekHoverHandler(event) { }
  137. /**
  138. * @param {?} event
  139. * @return {?}
  140. */
  141. monthHoverHandler(event) { }
  142. /**
  143. * @param {?} event
  144. * @return {?}
  145. */
  146. yearHoverHandler(event) { }
  147. /**
  148. * @param {?} day
  149. * @return {?}
  150. */
  151. daySelectHandler(day) { }
  152. /**
  153. * @param {?} event
  154. * @return {?}
  155. */
  156. monthSelectHandler(event) { }
  157. /**
  158. * @param {?} event
  159. * @return {?}
  160. */
  161. yearSelectHandler(event) { }
  162. /* tslint:disable-next-line: no-any */
  163. /**
  164. * @param {?} event
  165. * @return {?}
  166. */
  167. _stopPropagation(event) {
  168. event.stopPropagation();
  169. }
  170. }
  171. /**
  172. * @fileoverview added by tsickle
  173. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  174. */
  175. class BsDatepickerActions {
  176. /**
  177. * @return {?}
  178. */
  179. calculate() {
  180. return { type: BsDatepickerActions.CALCULATE };
  181. }
  182. /**
  183. * @return {?}
  184. */
  185. format() {
  186. return { type: BsDatepickerActions.FORMAT };
  187. }
  188. /**
  189. * @return {?}
  190. */
  191. flag() {
  192. return { type: BsDatepickerActions.FLAG };
  193. }
  194. /**
  195. * @param {?} date
  196. * @return {?}
  197. */
  198. select(date) {
  199. return {
  200. type: BsDatepickerActions.SELECT,
  201. payload: date
  202. };
  203. }
  204. /**
  205. * @param {?} event
  206. * @return {?}
  207. */
  208. changeViewMode(event) {
  209. return {
  210. type: BsDatepickerActions.CHANGE_VIEWMODE,
  211. payload: event
  212. };
  213. }
  214. /**
  215. * @param {?} event
  216. * @return {?}
  217. */
  218. navigateTo(event) {
  219. return {
  220. type: BsDatepickerActions.NAVIGATE_TO,
  221. payload: event
  222. };
  223. }
  224. /**
  225. * @param {?} step
  226. * @return {?}
  227. */
  228. navigateStep(step) {
  229. return {
  230. type: BsDatepickerActions.NAVIGATE_OFFSET,
  231. payload: step
  232. };
  233. }
  234. /**
  235. * @param {?} options
  236. * @return {?}
  237. */
  238. setOptions(options) {
  239. return {
  240. type: BsDatepickerActions.SET_OPTIONS,
  241. payload: options
  242. };
  243. }
  244. // date range picker
  245. /**
  246. * @param {?} value
  247. * @return {?}
  248. */
  249. selectRange(value) {
  250. return {
  251. type: BsDatepickerActions.SELECT_RANGE,
  252. payload: value
  253. };
  254. }
  255. /**
  256. * @param {?} event
  257. * @return {?}
  258. */
  259. hoverDay(event) {
  260. return {
  261. type: BsDatepickerActions.HOVER,
  262. payload: event.isHovered ? event.cell.date : null
  263. };
  264. }
  265. /**
  266. * @param {?} date
  267. * @return {?}
  268. */
  269. minDate(date) {
  270. return {
  271. type: BsDatepickerActions.SET_MIN_DATE,
  272. payload: date
  273. };
  274. }
  275. /**
  276. * @param {?} date
  277. * @return {?}
  278. */
  279. maxDate(date) {
  280. return {
  281. type: BsDatepickerActions.SET_MAX_DATE,
  282. payload: date
  283. };
  284. }
  285. /**
  286. * @param {?} days
  287. * @return {?}
  288. */
  289. daysDisabled(days) {
  290. return {
  291. type: BsDatepickerActions.SET_DAYSDISABLED,
  292. payload: days
  293. };
  294. }
  295. /**
  296. * @param {?} dates
  297. * @return {?}
  298. */
  299. datesDisabled(dates) {
  300. return {
  301. type: BsDatepickerActions.SET_DATESDISABLED,
  302. payload: dates
  303. };
  304. }
  305. /**
  306. * @param {?} value
  307. * @return {?}
  308. */
  309. isDisabled(value) {
  310. return {
  311. type: BsDatepickerActions.SET_IS_DISABLED,
  312. payload: value
  313. };
  314. }
  315. /**
  316. * @param {?} value
  317. * @return {?}
  318. */
  319. setDateCustomClasses(value) {
  320. return {
  321. type: BsDatepickerActions.SET_DATE_CUSTOM_CLASSES,
  322. payload: value
  323. };
  324. }
  325. /**
  326. * @param {?} locale
  327. * @return {?}
  328. */
  329. setLocale(locale) {
  330. return {
  331. type: BsDatepickerActions.SET_LOCALE,
  332. payload: locale
  333. };
  334. }
  335. }
  336. BsDatepickerActions.CALCULATE = '[datepicker] calculate dates matrix';
  337. BsDatepickerActions.FORMAT = '[datepicker] format datepicker values';
  338. BsDatepickerActions.FLAG = '[datepicker] set flags';
  339. BsDatepickerActions.SELECT = '[datepicker] select date';
  340. BsDatepickerActions.NAVIGATE_OFFSET = '[datepicker] shift view date';
  341. BsDatepickerActions.NAVIGATE_TO = '[datepicker] change view date';
  342. BsDatepickerActions.SET_OPTIONS = '[datepicker] update render options';
  343. BsDatepickerActions.HOVER = '[datepicker] hover date';
  344. BsDatepickerActions.CHANGE_VIEWMODE = '[datepicker] switch view mode';
  345. BsDatepickerActions.SET_MIN_DATE = '[datepicker] set min date';
  346. BsDatepickerActions.SET_MAX_DATE = '[datepicker] set max date';
  347. BsDatepickerActions.SET_DAYSDISABLED = '[datepicker] set days disabled';
  348. BsDatepickerActions.SET_DATESDISABLED = '[datepicker] set dates disabled';
  349. BsDatepickerActions.SET_IS_DISABLED = '[datepicker] set is disabled';
  350. BsDatepickerActions.SET_DATE_CUSTOM_CLASSES = '[datepicker] set date custom classes';
  351. BsDatepickerActions.SET_LOCALE = '[datepicker] set datepicker locale';
  352. BsDatepickerActions.SELECT_RANGE = '[daterangepicker] select dates range';
  353. BsDatepickerActions.decorators = [
  354. { type: Injectable }
  355. ];
  356. /**
  357. * @fileoverview added by tsickle
  358. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  359. */
  360. class BsLocaleService {
  361. constructor() {
  362. this._defaultLocale = 'en';
  363. this._locale = new BehaviorSubject(this._defaultLocale);
  364. this._localeChange = this._locale.asObservable();
  365. }
  366. /**
  367. * @return {?}
  368. */
  369. get locale() {
  370. return this._locale;
  371. }
  372. /**
  373. * @return {?}
  374. */
  375. get localeChange() {
  376. return this._localeChange;
  377. }
  378. /**
  379. * @return {?}
  380. */
  381. get currentLocale() {
  382. return this._locale.getValue();
  383. }
  384. /**
  385. * @param {?} locale
  386. * @return {?}
  387. */
  388. use(locale) {
  389. if (locale === this.currentLocale) {
  390. return;
  391. }
  392. this._locale.next(locale);
  393. }
  394. }
  395. BsLocaleService.decorators = [
  396. { type: Injectable }
  397. ];
  398. /**
  399. * @fileoverview added by tsickle
  400. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  401. */
  402. class BsDatepickerEffects {
  403. /**
  404. * @param {?} _actions
  405. * @param {?} _localeService
  406. */
  407. constructor(_actions, _localeService) {
  408. this._actions = _actions;
  409. this._localeService = _localeService;
  410. this._subs = [];
  411. }
  412. /**
  413. * @param {?} _bsDatepickerStore
  414. * @return {?}
  415. */
  416. init(_bsDatepickerStore) {
  417. this._store = _bsDatepickerStore;
  418. return this;
  419. }
  420. /**
  421. * setters
  422. * @param {?} value
  423. * @return {?}
  424. */
  425. setValue(value) {
  426. this._store.dispatch(this._actions.select(value));
  427. }
  428. /**
  429. * @param {?} value
  430. * @return {?}
  431. */
  432. setRangeValue(value) {
  433. this._store.dispatch(this._actions.selectRange(value));
  434. }
  435. /**
  436. * @param {?} value
  437. * @return {?}
  438. */
  439. setMinDate(value) {
  440. this._store.dispatch(this._actions.minDate(value));
  441. return this;
  442. }
  443. /**
  444. * @param {?} value
  445. * @return {?}
  446. */
  447. setMaxDate(value) {
  448. this._store.dispatch(this._actions.maxDate(value));
  449. return this;
  450. }
  451. /**
  452. * @template THIS
  453. * @this {THIS}
  454. * @param {?} value
  455. * @return {THIS}
  456. */
  457. setDaysDisabled(value) {
  458. (/** @type {?} */ (this))._store.dispatch((/** @type {?} */ (this))._actions.daysDisabled(value));
  459. return (/** @type {?} */ (this));
  460. }
  461. /**
  462. * @template THIS
  463. * @this {THIS}
  464. * @param {?} value
  465. * @return {THIS}
  466. */
  467. setDatesDisabled(value) {
  468. (/** @type {?} */ (this))._store.dispatch((/** @type {?} */ (this))._actions.datesDisabled(value));
  469. return (/** @type {?} */ (this));
  470. }
  471. /**
  472. * @param {?} value
  473. * @return {?}
  474. */
  475. setDisabled(value) {
  476. this._store.dispatch(this._actions.isDisabled(value));
  477. return this;
  478. }
  479. /**
  480. * @param {?} value
  481. * @return {?}
  482. */
  483. setDateCustomClasses(value) {
  484. this._store.dispatch(this._actions.setDateCustomClasses(value));
  485. return this;
  486. }
  487. /* Set rendering options */
  488. /**
  489. * @param {?} _config
  490. * @return {?}
  491. */
  492. setOptions(_config) {
  493. /** @type {?} */
  494. const _options = Object.assign({ locale: this._localeService.currentLocale }, _config);
  495. this._store.dispatch(this._actions.setOptions(_options));
  496. return this;
  497. }
  498. /**
  499. * view to mode bindings
  500. * @param {?} container
  501. * @return {?}
  502. */
  503. setBindings(container) {
  504. container.daysCalendar = this._store
  505. .select((/**
  506. * @param {?} state
  507. * @return {?}
  508. */
  509. state => state.flaggedMonths))
  510. .pipe(filter((/**
  511. * @param {?} months
  512. * @return {?}
  513. */
  514. months => !!months)));
  515. // month calendar
  516. container.monthsCalendar = this._store
  517. .select((/**
  518. * @param {?} state
  519. * @return {?}
  520. */
  521. state => state.flaggedMonthsCalendar))
  522. .pipe(filter((/**
  523. * @param {?} months
  524. * @return {?}
  525. */
  526. months => !!months)));
  527. // year calendar
  528. container.yearsCalendar = this._store
  529. .select((/**
  530. * @param {?} state
  531. * @return {?}
  532. */
  533. state => state.yearsCalendarFlagged))
  534. .pipe(filter((/**
  535. * @param {?} years
  536. * @return {?}
  537. */
  538. years => !!years)));
  539. container.viewMode = this._store.select((/**
  540. * @param {?} state
  541. * @return {?}
  542. */
  543. state => state.view.mode));
  544. container.options = this._store
  545. .select((/**
  546. * @param {?} state
  547. * @return {?}
  548. */
  549. state => state.showWeekNumbers))
  550. .pipe(map((/**
  551. * @param {?} showWeekNumbers
  552. * @return {?}
  553. */
  554. showWeekNumbers => ({ showWeekNumbers }))));
  555. return this;
  556. }
  557. /**
  558. * event handlers
  559. * @param {?} container
  560. * @return {?}
  561. */
  562. setEventHandlers(container) {
  563. container.setViewMode = (/**
  564. * @param {?} event
  565. * @return {?}
  566. */
  567. (event) => {
  568. this._store.dispatch(this._actions.changeViewMode(event));
  569. });
  570. container.navigateTo = (/**
  571. * @param {?} event
  572. * @return {?}
  573. */
  574. (event) => {
  575. this._store.dispatch(this._actions.navigateStep(event.step));
  576. });
  577. container.dayHoverHandler = (/**
  578. * @param {?} event
  579. * @return {?}
  580. */
  581. (event) => {
  582. /** @type {?} */
  583. const _cell = (/** @type {?} */ (event.cell));
  584. if (_cell.isOtherMonth || _cell.isDisabled) {
  585. return;
  586. }
  587. this._store.dispatch(this._actions.hoverDay(event));
  588. _cell.isHovered = event.isHovered;
  589. });
  590. container.monthHoverHandler = (/**
  591. * @param {?} event
  592. * @return {?}
  593. */
  594. (event) => {
  595. event.cell.isHovered = event.isHovered;
  596. });
  597. container.yearHoverHandler = (/**
  598. * @param {?} event
  599. * @return {?}
  600. */
  601. (event) => {
  602. event.cell.isHovered = event.isHovered;
  603. });
  604. container.monthSelectHandler = (/**
  605. * @param {?} event
  606. * @return {?}
  607. */
  608. (event) => {
  609. if (event.isDisabled) {
  610. return;
  611. }
  612. this._store.dispatch(this._actions.navigateTo({
  613. unit: {
  614. month: getMonth(event.date),
  615. year: getFullYear(event.date)
  616. },
  617. viewMode: 'day'
  618. }));
  619. });
  620. container.yearSelectHandler = (/**
  621. * @param {?} event
  622. * @return {?}
  623. */
  624. (event) => {
  625. if (event.isDisabled) {
  626. return;
  627. }
  628. this._store.dispatch(this._actions.navigateTo({
  629. unit: {
  630. year: getFullYear(event.date)
  631. },
  632. viewMode: 'month'
  633. }));
  634. });
  635. return this;
  636. }
  637. /**
  638. * @return {?}
  639. */
  640. registerDatepickerSideEffects() {
  641. this._subs.push(this._store.select((/**
  642. * @param {?} state
  643. * @return {?}
  644. */
  645. state => state.view)).subscribe((/**
  646. * @param {?} view
  647. * @return {?}
  648. */
  649. view => {
  650. this._store.dispatch(this._actions.calculate());
  651. })));
  652. // format calendar values on month model change
  653. this._subs.push(this._store
  654. .select((/**
  655. * @param {?} state
  656. * @return {?}
  657. */
  658. state => state.monthsModel))
  659. .pipe(filter((/**
  660. * @param {?} monthModel
  661. * @return {?}
  662. */
  663. monthModel => !!monthModel)))
  664. .subscribe((/**
  665. * @param {?} month
  666. * @return {?}
  667. */
  668. month => this._store.dispatch(this._actions.format()))));
  669. // flag day values
  670. this._subs.push(this._store
  671. .select((/**
  672. * @param {?} state
  673. * @return {?}
  674. */
  675. state => state.formattedMonths))
  676. .pipe(filter((/**
  677. * @param {?} month
  678. * @return {?}
  679. */
  680. month => !!month)))
  681. .subscribe((/**
  682. * @param {?} month
  683. * @return {?}
  684. */
  685. month => this._store.dispatch(this._actions.flag()))));
  686. // flag day values
  687. this._subs.push(this._store
  688. .select((/**
  689. * @param {?} state
  690. * @return {?}
  691. */
  692. state => state.selectedDate))
  693. .pipe(filter((/**
  694. * @param {?} selectedDate
  695. * @return {?}
  696. */
  697. selectedDate => !!selectedDate)))
  698. .subscribe((/**
  699. * @param {?} selectedDate
  700. * @return {?}
  701. */
  702. selectedDate => this._store.dispatch(this._actions.flag()))));
  703. // flag for date range picker
  704. this._subs.push(this._store
  705. .select((/**
  706. * @param {?} state
  707. * @return {?}
  708. */
  709. state => state.selectedRange))
  710. .pipe(filter((/**
  711. * @param {?} selectedRange
  712. * @return {?}
  713. */
  714. selectedRange => !!selectedRange)))
  715. .subscribe((/**
  716. * @param {?} selectedRange
  717. * @return {?}
  718. */
  719. selectedRange => this._store.dispatch(this._actions.flag()))));
  720. // monthsCalendar
  721. this._subs.push(this._store
  722. .select((/**
  723. * @param {?} state
  724. * @return {?}
  725. */
  726. state => state.monthsCalendar))
  727. .subscribe((/**
  728. * @return {?}
  729. */
  730. () => this._store.dispatch(this._actions.flag()))));
  731. // years calendar
  732. this._subs.push(this._store
  733. .select((/**
  734. * @param {?} state
  735. * @return {?}
  736. */
  737. state => state.yearsCalendarModel))
  738. .pipe(filter((/**
  739. * @param {?} state
  740. * @return {?}
  741. */
  742. state => !!state)))
  743. .subscribe((/**
  744. * @return {?}
  745. */
  746. () => this._store.dispatch(this._actions.flag()))));
  747. // on hover
  748. this._subs.push(this._store
  749. .select((/**
  750. * @param {?} state
  751. * @return {?}
  752. */
  753. state => state.hoveredDate))
  754. .pipe(filter((/**
  755. * @param {?} hoveredDate
  756. * @return {?}
  757. */
  758. hoveredDate => !!hoveredDate)))
  759. .subscribe((/**
  760. * @param {?} hoveredDate
  761. * @return {?}
  762. */
  763. hoveredDate => this._store.dispatch(this._actions.flag()))));
  764. // date custom classes
  765. this._subs.push(this._store
  766. .select((/**
  767. * @param {?} state
  768. * @return {?}
  769. */
  770. state => state.dateCustomClasses))
  771. .pipe(filter((/**
  772. * @param {?} dateCustomClasses
  773. * @return {?}
  774. */
  775. dateCustomClasses => !!dateCustomClasses)))
  776. .subscribe((/**
  777. * @param {?} dateCustomClasses
  778. * @return {?}
  779. */
  780. dateCustomClasses => this._store.dispatch(this._actions.flag()))));
  781. // on locale change
  782. this._subs.push(this._localeService.localeChange
  783. .subscribe((/**
  784. * @param {?} locale
  785. * @return {?}
  786. */
  787. locale => this._store.dispatch(this._actions.setLocale(locale)))));
  788. return this;
  789. }
  790. /**
  791. * @return {?}
  792. */
  793. destroy() {
  794. for (const sub of this._subs) {
  795. sub.unsubscribe();
  796. }
  797. }
  798. }
  799. BsDatepickerEffects.decorators = [
  800. { type: Injectable }
  801. ];
  802. /** @nocollapse */
  803. BsDatepickerEffects.ctorParameters = () => [
  804. { type: BsDatepickerActions },
  805. { type: BsLocaleService }
  806. ];
  807. /**
  808. * @fileoverview added by tsickle
  809. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  810. */
  811. /** @type {?} */
  812. const defaultMonthOptions = {
  813. width: 7,
  814. height: 6
  815. };
  816. /**
  817. * @fileoverview added by tsickle
  818. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  819. */
  820. /** @type {?} */
  821. const _initialView = { date: new Date(), mode: 'day' };
  822. /** @type {?} */
  823. const initialDatepickerState = Object.assign(new BsDatepickerConfig(), {
  824. locale: 'en',
  825. view: _initialView,
  826. selectedRange: [],
  827. monthViewOptions: defaultMonthOptions
  828. });
  829. /**
  830. * @fileoverview added by tsickle
  831. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  832. */
  833. /**
  834. * @param {?} date
  835. * @param {?} options
  836. * @return {?}
  837. */
  838. function getStartingDayOfCalendar(date, options) {
  839. if (isFirstDayOfWeek(date, options.firstDayOfWeek)) {
  840. return date;
  841. }
  842. /** @type {?} */
  843. const weekDay = getDay(date);
  844. /** @type {?} */
  845. const offset = calculateDateOffset(weekDay, options.firstDayOfWeek);
  846. return shiftDate(date, { day: -offset });
  847. }
  848. /**
  849. * @param {?} weekday
  850. * @param {?} startingDayOffset
  851. * @return {?}
  852. */
  853. function calculateDateOffset(weekday, startingDayOffset) {
  854. if (startingDayOffset === 0) {
  855. return weekday;
  856. }
  857. /** @type {?} */
  858. const offset = weekday - startingDayOffset % 7;
  859. return offset < 0 ? offset + 7 : offset;
  860. }
  861. /**
  862. * @param {?} date
  863. * @param {?} min
  864. * @param {?} max
  865. * @return {?}
  866. */
  867. function isMonthDisabled(date, min, max) {
  868. /** @type {?} */
  869. const minBound = min && isBefore(endOf(date, 'month'), min, 'day');
  870. /** @type {?} */
  871. const maxBound = max && isAfter(startOf(date, 'month'), max, 'day');
  872. return minBound || maxBound;
  873. }
  874. /**
  875. * @param {?} date
  876. * @param {?} min
  877. * @param {?} max
  878. * @return {?}
  879. */
  880. function isYearDisabled(date, min, max) {
  881. /** @type {?} */
  882. const minBound = min && isBefore(endOf(date, 'year'), min, 'day');
  883. /** @type {?} */
  884. const maxBound = max && isAfter(startOf(date, 'year'), max, 'day');
  885. return minBound || maxBound;
  886. }
  887. /**
  888. * @param {?} date
  889. * @param {?} datesDisabled
  890. * @return {?}
  891. */
  892. function isDisabledDate(date, datesDisabled) {
  893. if (datesDisabled === undefined || !datesDisabled || !datesDisabled.length) {
  894. return false;
  895. }
  896. return datesDisabled.some((/**
  897. * @param {?} dateDisabled
  898. * @return {?}
  899. */
  900. (dateDisabled) => isSame(date, dateDisabled, 'date')));
  901. }
  902. /**
  903. * @param {?} state
  904. * @param {?=} calendarIndex
  905. * @return {?}
  906. */
  907. function getYearsCalendarInitialDate(state, calendarIndex = 0) {
  908. /** @type {?} */
  909. const model = state && state.yearsCalendarModel && state.yearsCalendarModel[calendarIndex];
  910. return model && model.years && model.years[0] && model.years[0][0] && model.years[0][0].date;
  911. }
  912. /**
  913. * @fileoverview added by tsickle
  914. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  915. */
  916. /**
  917. * @template T
  918. * @param {?} options
  919. * @param {?} fn
  920. * @return {?}
  921. */
  922. function createMatrix(options, fn) {
  923. /** @type {?} */
  924. let prevValue = options.initialDate;
  925. /** @type {?} */
  926. const matrix = new Array(options.height);
  927. for (let i = 0; i < options.height; i++) {
  928. matrix[i] = new Array(options.width);
  929. for (let j = 0; j < options.width; j++) {
  930. matrix[i][j] = fn(prevValue);
  931. prevValue = shiftDate(prevValue, options.shift);
  932. }
  933. }
  934. return matrix;
  935. }
  936. /**
  937. * @fileoverview added by tsickle
  938. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  939. */
  940. /**
  941. * @param {?} startingDate
  942. * @param {?} options
  943. * @return {?}
  944. */
  945. function calcDaysCalendar(startingDate, options) {
  946. /** @type {?} */
  947. const firstDay = getFirstDayOfMonth(startingDate);
  948. /** @type {?} */
  949. const initialDate = getStartingDayOfCalendar(firstDay, options);
  950. /** @type {?} */
  951. const matrixOptions = {
  952. width: options.width,
  953. height: options.height,
  954. initialDate,
  955. shift: { day: 1 }
  956. };
  957. /** @type {?} */
  958. const daysMatrix = createMatrix(matrixOptions, (/**
  959. * @param {?} date
  960. * @return {?}
  961. */
  962. date => date));
  963. return {
  964. daysMatrix,
  965. month: firstDay
  966. };
  967. }
  968. /**
  969. * @fileoverview added by tsickle
  970. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  971. */
  972. /**
  973. * @param {?} daysCalendar
  974. * @param {?} formatOptions
  975. * @param {?} monthIndex
  976. * @return {?}
  977. */
  978. function formatDaysCalendar(daysCalendar, formatOptions, monthIndex) {
  979. return {
  980. month: daysCalendar.month,
  981. monthTitle: formatDate(daysCalendar.month, formatOptions.monthTitle, formatOptions.locale),
  982. yearTitle: formatDate(daysCalendar.month, formatOptions.yearTitle, formatOptions.locale),
  983. weekNumbers: getWeekNumbers(daysCalendar.daysMatrix, formatOptions.weekNumbers, formatOptions.locale),
  984. weekdays: getShiftedWeekdays(formatOptions.locale),
  985. weeks: daysCalendar.daysMatrix.map((/**
  986. * @param {?} week
  987. * @param {?} weekIndex
  988. * @return {?}
  989. */
  990. (week, weekIndex) => ({
  991. days: week.map((/**
  992. * @param {?} date
  993. * @param {?} dayIndex
  994. * @return {?}
  995. */
  996. (date, dayIndex) => ({
  997. date,
  998. label: formatDate(date, formatOptions.dayLabel, formatOptions.locale),
  999. monthIndex,
  1000. weekIndex,
  1001. dayIndex
  1002. })))
  1003. })))
  1004. };
  1005. }
  1006. /**
  1007. * @param {?} daysMatrix
  1008. * @param {?} format
  1009. * @param {?} locale
  1010. * @return {?}
  1011. */
  1012. function getWeekNumbers(daysMatrix, format, locale) {
  1013. return daysMatrix.map((/**
  1014. * @param {?} days
  1015. * @return {?}
  1016. */
  1017. (days) => (days[0] ? formatDate(days[0], format, locale) : '')));
  1018. }
  1019. /**
  1020. * @param {?} locale
  1021. * @return {?}
  1022. */
  1023. function getShiftedWeekdays(locale) {
  1024. /** @type {?} */
  1025. const _locale = getLocale(locale);
  1026. /** @type {?} */
  1027. const weekdays = (/** @type {?} */ (_locale.weekdaysShort()));
  1028. /** @type {?} */
  1029. const firstDayOfWeek = _locale.firstDayOfWeek();
  1030. return [...weekdays.slice(firstDayOfWeek), ...weekdays.slice(0, firstDayOfWeek)];
  1031. }
  1032. /**
  1033. * @fileoverview added by tsickle
  1034. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1035. */
  1036. /**
  1037. * @param {?} formattedMonth
  1038. * @param {?} options
  1039. * @return {?}
  1040. */
  1041. function flagDaysCalendar(formattedMonth, options) {
  1042. formattedMonth.weeks.forEach((/**
  1043. * @param {?} week
  1044. * @return {?}
  1045. */
  1046. (week) => {
  1047. /* tslint:disable-next-line: cyclomatic-complexity */
  1048. week.days.forEach((/**
  1049. * @param {?} day
  1050. * @param {?} dayIndex
  1051. * @return {?}
  1052. */
  1053. (day, dayIndex) => {
  1054. // datepicker
  1055. /** @type {?} */
  1056. const isOtherMonth = !isSameMonth(day.date, formattedMonth.month);
  1057. /** @type {?} */
  1058. const isHovered = !isOtherMonth && isSameDay(day.date, options.hoveredDate);
  1059. // date range picker
  1060. /** @type {?} */
  1061. const isSelectionStart = !isOtherMonth &&
  1062. options.selectedRange &&
  1063. isSameDay(day.date, options.selectedRange[0]);
  1064. /** @type {?} */
  1065. const isSelectionEnd = !isOtherMonth &&
  1066. options.selectedRange &&
  1067. isSameDay(day.date, options.selectedRange[1]);
  1068. /** @type {?} */
  1069. const isSelected = (!isOtherMonth && isSameDay(day.date, options.selectedDate)) ||
  1070. isSelectionStart ||
  1071. isSelectionEnd;
  1072. /** @type {?} */
  1073. const isInRange = !isOtherMonth &&
  1074. options.selectedRange &&
  1075. isDateInRange(day.date, options.selectedRange, options.hoveredDate);
  1076. /** @type {?} */
  1077. const isDisabled = options.isDisabled ||
  1078. isBefore(day.date, options.minDate, 'day') ||
  1079. isAfter(day.date, options.maxDate, 'day') ||
  1080. isDisabledDay(day.date, options.daysDisabled) ||
  1081. isDisabledDate(day.date, options.datesDisabled);
  1082. /** @type {?} */
  1083. const currentDate = new Date();
  1084. /** @type {?} */
  1085. const isToday = !isOtherMonth && isSameDay(day.date, currentDate);
  1086. /** @type {?} */
  1087. const customClasses = options.dateCustomClasses && options.dateCustomClasses
  1088. .map((/**
  1089. * @param {?} dcc
  1090. * @return {?}
  1091. */
  1092. dcc => isSameDay(day.date, dcc.date) ? dcc.classes : []))
  1093. .reduce((/**
  1094. * @param {?} previousValue
  1095. * @param {?} currentValue
  1096. * @return {?}
  1097. */
  1098. (previousValue, currentValue) => previousValue.concat(currentValue)), [])
  1099. .join(' ')
  1100. || '';
  1101. // decide update or not
  1102. /** @type {?} */
  1103. const newDay = Object.assign({}, day, {
  1104. isOtherMonth,
  1105. isHovered,
  1106. isSelected,
  1107. isSelectionStart,
  1108. isSelectionEnd,
  1109. isInRange,
  1110. isDisabled,
  1111. isToday,
  1112. customClasses
  1113. });
  1114. if (day.isOtherMonth !== newDay.isOtherMonth ||
  1115. day.isHovered !== newDay.isHovered ||
  1116. day.isSelected !== newDay.isSelected ||
  1117. day.isSelectionStart !== newDay.isSelectionStart ||
  1118. day.isSelectionEnd !== newDay.isSelectionEnd ||
  1119. day.isDisabled !== newDay.isDisabled ||
  1120. day.isInRange !== newDay.isInRange ||
  1121. day.customClasses !== newDay.customClasses) {
  1122. week.days[dayIndex] = newDay;
  1123. }
  1124. }));
  1125. }));
  1126. // todo: add check for linked calendars
  1127. formattedMonth.hideLeftArrow =
  1128. options.isDisabled ||
  1129. (options.monthIndex > 0 && options.monthIndex !== options.displayMonths);
  1130. formattedMonth.hideRightArrow =
  1131. options.isDisabled ||
  1132. (options.monthIndex < options.displayMonths &&
  1133. options.monthIndex + 1 !== options.displayMonths);
  1134. formattedMonth.disableLeftArrow = isMonthDisabled(shiftDate(formattedMonth.month, { month: -1 }), options.minDate, options.maxDate);
  1135. formattedMonth.disableRightArrow = isMonthDisabled(shiftDate(formattedMonth.month, { month: 1 }), options.minDate, options.maxDate);
  1136. return formattedMonth;
  1137. }
  1138. /**
  1139. * @param {?} date
  1140. * @param {?} selectedRange
  1141. * @param {?} hoveredDate
  1142. * @return {?}
  1143. */
  1144. function isDateInRange(date, selectedRange, hoveredDate) {
  1145. if (!date || !selectedRange[0]) {
  1146. return false;
  1147. }
  1148. if (selectedRange[1]) {
  1149. return date > selectedRange[0] && date <= selectedRange[1];
  1150. }
  1151. if (hoveredDate) {
  1152. return date > selectedRange[0] && date <= hoveredDate;
  1153. }
  1154. return false;
  1155. }
  1156. /**
  1157. * @fileoverview added by tsickle
  1158. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1159. */
  1160. /**
  1161. * @param {?} mode
  1162. * @param {?=} minMode
  1163. * @return {?}
  1164. */
  1165. function canSwitchMode(mode, minMode) {
  1166. return minMode ? mode >= minMode : true;
  1167. }
  1168. /**
  1169. * @fileoverview added by tsickle
  1170. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1171. */
  1172. /** @type {?} */
  1173. const height = 4;
  1174. /** @type {?} */
  1175. const width = 3;
  1176. /** @type {?} */
  1177. const shift = { month: 1 };
  1178. /**
  1179. * @param {?} viewDate
  1180. * @param {?} formatOptions
  1181. * @return {?}
  1182. */
  1183. function formatMonthsCalendar(viewDate, formatOptions) {
  1184. /** @type {?} */
  1185. const initialDate = startOf(viewDate, 'year');
  1186. /** @type {?} */
  1187. const matrixOptions = { width, height, initialDate, shift };
  1188. /** @type {?} */
  1189. const monthMatrix = createMatrix(matrixOptions, (/**
  1190. * @param {?} date
  1191. * @return {?}
  1192. */
  1193. date => ({
  1194. date,
  1195. label: formatDate(date, formatOptions.monthLabel, formatOptions.locale)
  1196. })));
  1197. return {
  1198. months: monthMatrix,
  1199. monthTitle: '',
  1200. yearTitle: formatDate(viewDate, formatOptions.yearTitle, formatOptions.locale)
  1201. };
  1202. }
  1203. /**
  1204. * @fileoverview added by tsickle
  1205. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1206. */
  1207. /**
  1208. * @param {?} monthCalendar
  1209. * @param {?} options
  1210. * @return {?}
  1211. */
  1212. function flagMonthsCalendar(monthCalendar, options) {
  1213. monthCalendar.months.forEach((/**
  1214. * @param {?} months
  1215. * @param {?} rowIndex
  1216. * @return {?}
  1217. */
  1218. (months, rowIndex) => {
  1219. months.forEach((/**
  1220. * @param {?} month
  1221. * @param {?} monthIndex
  1222. * @return {?}
  1223. */
  1224. (month, monthIndex) => {
  1225. /** @type {?} */
  1226. const isHovered = isSameMonth(month.date, options.hoveredMonth);
  1227. /** @type {?} */
  1228. const isDisabled = options.isDisabled ||
  1229. isMonthDisabled(month.date, options.minDate, options.maxDate);
  1230. /** @type {?} */
  1231. const isSelected = isSameMonth(month.date, options.selectedDate);
  1232. /** @type {?} */
  1233. const newMonth = Object.assign(/*{},*/ month, {
  1234. isHovered,
  1235. isDisabled,
  1236. isSelected
  1237. });
  1238. if (month.isHovered !== newMonth.isHovered ||
  1239. month.isDisabled !== newMonth.isDisabled ||
  1240. month.isSelected !== newMonth.isSelected) {
  1241. monthCalendar.months[rowIndex][monthIndex] = newMonth;
  1242. }
  1243. }));
  1244. }));
  1245. // todo: add check for linked calendars
  1246. monthCalendar.hideLeftArrow =
  1247. options.monthIndex > 0 && options.monthIndex !== options.displayMonths;
  1248. monthCalendar.hideRightArrow =
  1249. options.monthIndex < options.displayMonths &&
  1250. options.monthIndex + 1 !== options.displayMonths;
  1251. monthCalendar.disableLeftArrow = isYearDisabled(shiftDate(monthCalendar.months[0][0].date, { year: -1 }), options.minDate, options.maxDate);
  1252. monthCalendar.disableRightArrow = isYearDisabled(shiftDate(monthCalendar.months[0][0].date, { year: 1 }), options.minDate, options.maxDate);
  1253. return monthCalendar;
  1254. }
  1255. /**
  1256. * @fileoverview added by tsickle
  1257. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1258. */
  1259. /** @type {?} */
  1260. const height$1 = 4;
  1261. /** @type {?} */
  1262. const width$1 = 4;
  1263. /** @type {?} */
  1264. const yearsPerCalendar = height$1 * width$1;
  1265. /** @type {?} */
  1266. const initialYearShift = (Math.floor(yearsPerCalendar / 2) - 1) * -1;
  1267. /** @type {?} */
  1268. const shift$1 = { year: 1 };
  1269. /**
  1270. * @param {?} viewDate
  1271. * @param {?} formatOptions
  1272. * @param {?=} previousInitialDate
  1273. * @return {?}
  1274. */
  1275. function formatYearsCalendar(viewDate, formatOptions, previousInitialDate) {
  1276. /** @type {?} */
  1277. const initialDate = calculateInitialDate(viewDate, previousInitialDate);
  1278. /** @type {?} */
  1279. const matrixOptions = { width: width$1, height: height$1, initialDate, shift: shift$1 };
  1280. /** @type {?} */
  1281. const yearsMatrix = createMatrix(matrixOptions, (/**
  1282. * @param {?} date
  1283. * @return {?}
  1284. */
  1285. date => ({
  1286. date,
  1287. label: formatDate(date, formatOptions.yearLabel, formatOptions.locale)
  1288. })));
  1289. /** @type {?} */
  1290. const yearTitle = formatYearRangeTitle(yearsMatrix, formatOptions);
  1291. return {
  1292. years: yearsMatrix,
  1293. monthTitle: '',
  1294. yearTitle
  1295. };
  1296. }
  1297. /**
  1298. * @param {?} viewDate
  1299. * @param {?=} previousInitialDate
  1300. * @return {?}
  1301. */
  1302. function calculateInitialDate(viewDate, previousInitialDate) {
  1303. if (previousInitialDate
  1304. && viewDate.getFullYear() >= previousInitialDate.getFullYear()
  1305. && viewDate.getFullYear() < previousInitialDate.getFullYear() + yearsPerCalendar) {
  1306. return previousInitialDate;
  1307. }
  1308. return shiftDate(viewDate, { year: initialYearShift });
  1309. }
  1310. /**
  1311. * @param {?} yearsMatrix
  1312. * @param {?} formatOptions
  1313. * @return {?}
  1314. */
  1315. function formatYearRangeTitle(yearsMatrix, formatOptions) {
  1316. /** @type {?} */
  1317. const from = formatDate(yearsMatrix[0][0].date, formatOptions.yearTitle, formatOptions.locale);
  1318. /** @type {?} */
  1319. const to = formatDate(yearsMatrix[height$1 - 1][width$1 - 1].date, formatOptions.yearTitle, formatOptions.locale);
  1320. return `${from} - ${to}`;
  1321. }
  1322. /**
  1323. * @fileoverview added by tsickle
  1324. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1325. */
  1326. /**
  1327. * @param {?} yearsCalendar
  1328. * @param {?} options
  1329. * @return {?}
  1330. */
  1331. function flagYearsCalendar(yearsCalendar, options) {
  1332. yearsCalendar.years.forEach((/**
  1333. * @param {?} years
  1334. * @param {?} rowIndex
  1335. * @return {?}
  1336. */
  1337. (years, rowIndex) => {
  1338. years.forEach((/**
  1339. * @param {?} year
  1340. * @param {?} yearIndex
  1341. * @return {?}
  1342. */
  1343. (year, yearIndex) => {
  1344. /** @type {?} */
  1345. const isHovered = isSameYear(year.date, options.hoveredYear);
  1346. /** @type {?} */
  1347. const isDisabled = options.isDisabled ||
  1348. isYearDisabled(year.date, options.minDate, options.maxDate);
  1349. /** @type {?} */
  1350. const isSelected = isSameYear(year.date, options.selectedDate);
  1351. /** @type {?} */
  1352. const newMonth = Object.assign(/*{},*/ year, { isHovered, isDisabled, isSelected });
  1353. if (year.isHovered !== newMonth.isHovered ||
  1354. year.isDisabled !== newMonth.isDisabled ||
  1355. year.isSelected !== newMonth.isSelected) {
  1356. yearsCalendar.years[rowIndex][yearIndex] = newMonth;
  1357. }
  1358. }));
  1359. }));
  1360. // todo: add check for linked calendars
  1361. yearsCalendar.hideLeftArrow =
  1362. options.yearIndex > 0 && options.yearIndex !== options.displayMonths;
  1363. yearsCalendar.hideRightArrow =
  1364. options.yearIndex < options.displayMonths &&
  1365. options.yearIndex + 1 !== options.displayMonths;
  1366. yearsCalendar.disableLeftArrow = isYearDisabled(shiftDate(yearsCalendar.years[0][0].date, { year: -1 }), options.minDate, options.maxDate);
  1367. /** @type {?} */
  1368. const i = yearsCalendar.years.length - 1;
  1369. /** @type {?} */
  1370. const j = yearsCalendar.years[i].length - 1;
  1371. yearsCalendar.disableRightArrow = isYearDisabled(shiftDate(yearsCalendar.years[i][j].date, { year: 1 }), options.minDate, options.maxDate);
  1372. return yearsCalendar;
  1373. }
  1374. /**
  1375. * @fileoverview added by tsickle
  1376. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1377. */
  1378. /* tslint:disable-next-line: cyclomatic-complexity */
  1379. /**
  1380. * @param {?=} state
  1381. * @param {?=} action
  1382. * @return {?}
  1383. */
  1384. function bsDatepickerReducer(state = initialDatepickerState, action) {
  1385. switch (action.type) {
  1386. case BsDatepickerActions.CALCULATE: {
  1387. return calculateReducer(state);
  1388. }
  1389. case BsDatepickerActions.FORMAT: {
  1390. return formatReducer(state);
  1391. }
  1392. case BsDatepickerActions.FLAG: {
  1393. return flagReducer(state);
  1394. }
  1395. case BsDatepickerActions.NAVIGATE_OFFSET: {
  1396. return navigateOffsetReducer(state, action);
  1397. }
  1398. case BsDatepickerActions.NAVIGATE_TO: {
  1399. /** @type {?} */
  1400. const payload = action.payload;
  1401. /** @type {?} */
  1402. const date = setFullDate(state.view.date, payload.unit);
  1403. /** @type {?} */
  1404. let newState;
  1405. /** @type {?} */
  1406. let mode;
  1407. if (canSwitchMode(payload.viewMode, state.minMode)) {
  1408. mode = payload.viewMode;
  1409. newState = { view: { date, mode } };
  1410. }
  1411. else {
  1412. mode = state.view.mode;
  1413. newState = { selectedDate: date, view: { date, mode } };
  1414. }
  1415. return Object.assign({}, state, newState);
  1416. }
  1417. case BsDatepickerActions.CHANGE_VIEWMODE: {
  1418. if (!canSwitchMode(action.payload, state.minMode)) {
  1419. return state;
  1420. }
  1421. /** @type {?} */
  1422. const date = state.view.date;
  1423. /** @type {?} */
  1424. const mode = action.payload;
  1425. /** @type {?} */
  1426. const newState = { view: { date, mode } };
  1427. return Object.assign({}, state, newState);
  1428. }
  1429. case BsDatepickerActions.HOVER: {
  1430. return Object.assign({}, state, { hoveredDate: action.payload });
  1431. }
  1432. case BsDatepickerActions.SELECT: {
  1433. /** @type {?} */
  1434. const newState = {
  1435. selectedDate: action.payload,
  1436. view: state.view
  1437. };
  1438. /** @type {?} */
  1439. const mode = state.view.mode;
  1440. /** @type {?} */
  1441. const _date = action.payload || state.view.date;
  1442. /** @type {?} */
  1443. const date = getViewDate(_date, state.minDate, state.maxDate);
  1444. newState.view = { mode, date };
  1445. return Object.assign({}, state, newState);
  1446. }
  1447. case BsDatepickerActions.SET_OPTIONS: {
  1448. /** @type {?} */
  1449. const newState = action.payload;
  1450. // preserve view mode
  1451. /** @type {?} */
  1452. const mode = newState.minMode ? newState.minMode : state.view.mode;
  1453. /** @type {?} */
  1454. const _viewDate = isDateValid(newState.value) && newState.value
  1455. || isArray(newState.value) && isDateValid(newState.value[0]) && newState.value[0]
  1456. || state.view.date;
  1457. /** @type {?} */
  1458. const date = getViewDate(_viewDate, newState.minDate, newState.maxDate);
  1459. newState.view = { mode, date };
  1460. // update selected value
  1461. if (newState.value) {
  1462. // if new value is array we work with date range
  1463. if (isArray(newState.value)) {
  1464. newState.selectedRange = newState.value;
  1465. }
  1466. // if new value is a date -> datepicker
  1467. if (newState.value instanceof Date) {
  1468. newState.selectedDate = newState.value;
  1469. }
  1470. // provided value is not supported :)
  1471. // need to report it somehow
  1472. }
  1473. return Object.assign({}, state, newState);
  1474. }
  1475. // date range picker
  1476. case BsDatepickerActions.SELECT_RANGE: {
  1477. /** @type {?} */
  1478. const newState = {
  1479. selectedRange: action.payload,
  1480. view: state.view
  1481. };
  1482. /** @type {?} */
  1483. const mode = state.view.mode;
  1484. /** @type {?} */
  1485. const _date = action.payload && action.payload[0] || state.view.date;
  1486. /** @type {?} */
  1487. const date = getViewDate(_date, state.minDate, state.maxDate);
  1488. newState.view = { mode, date };
  1489. return Object.assign({}, state, newState);
  1490. }
  1491. case BsDatepickerActions.SET_MIN_DATE: {
  1492. return Object.assign({}, state, {
  1493. minDate: action.payload
  1494. });
  1495. }
  1496. case BsDatepickerActions.SET_MAX_DATE: {
  1497. return Object.assign({}, state, {
  1498. maxDate: action.payload
  1499. });
  1500. }
  1501. case BsDatepickerActions.SET_IS_DISABLED: {
  1502. return Object.assign({}, state, {
  1503. isDisabled: action.payload
  1504. });
  1505. }
  1506. case BsDatepickerActions.SET_DATE_CUSTOM_CLASSES: {
  1507. return Object.assign({}, state, {
  1508. dateCustomClasses: action.payload
  1509. });
  1510. }
  1511. default:
  1512. return state;
  1513. }
  1514. }
  1515. /**
  1516. * @param {?} state
  1517. * @return {?}
  1518. */
  1519. function calculateReducer(state) {
  1520. // how many calendars
  1521. /** @type {?} */
  1522. const displayMonths = state.displayMonths;
  1523. // use selected date on initial rendering if set
  1524. /** @type {?} */
  1525. let viewDate = state.view.date;
  1526. if (state.view.mode === 'day') {
  1527. state.monthViewOptions.firstDayOfWeek = getLocale(state.locale).firstDayOfWeek();
  1528. /** @type {?} */
  1529. const monthsModel = new Array(displayMonths);
  1530. for (let monthIndex = 0; monthIndex < displayMonths; monthIndex++) {
  1531. // todo: for unlinked calendars it will be harder
  1532. monthsModel[monthIndex] = calcDaysCalendar(viewDate, state.monthViewOptions);
  1533. viewDate = shiftDate(viewDate, { month: 1 });
  1534. }
  1535. return Object.assign({}, state, { monthsModel });
  1536. }
  1537. if (state.view.mode === 'month') {
  1538. /** @type {?} */
  1539. const monthsCalendar = new Array(displayMonths);
  1540. for (let calendarIndex = 0; calendarIndex < displayMonths; calendarIndex++) {
  1541. // todo: for unlinked calendars it will be harder
  1542. monthsCalendar[calendarIndex] = formatMonthsCalendar(viewDate, getFormatOptions(state));
  1543. viewDate = shiftDate(viewDate, { year: 1 });
  1544. }
  1545. return Object.assign({}, state, { monthsCalendar });
  1546. }
  1547. if (state.view.mode === 'year') {
  1548. /** @type {?} */
  1549. const yearsCalendarModel = new Array(displayMonths);
  1550. for (let calendarIndex = 0; calendarIndex < displayMonths; calendarIndex++) {
  1551. // todo: for unlinked calendars it will be harder
  1552. yearsCalendarModel[calendarIndex] = formatYearsCalendar(viewDate, getFormatOptions(state), state.minMode === 'year' ? getYearsCalendarInitialDate(state, calendarIndex) : undefined);
  1553. viewDate = shiftDate(viewDate, { year: yearsPerCalendar });
  1554. }
  1555. return Object.assign({}, state, { yearsCalendarModel });
  1556. }
  1557. return state;
  1558. }
  1559. /**
  1560. * @param {?} state
  1561. * @param {?} action
  1562. * @return {?}
  1563. */
  1564. function formatReducer(state, action) {
  1565. if (state.view.mode === 'day') {
  1566. /** @type {?} */
  1567. const formattedMonths = state.monthsModel.map((/**
  1568. * @param {?} month
  1569. * @param {?} monthIndex
  1570. * @return {?}
  1571. */
  1572. (month, monthIndex) => formatDaysCalendar(month, getFormatOptions(state), monthIndex)));
  1573. return Object.assign({}, state, { formattedMonths });
  1574. }
  1575. // how many calendars
  1576. /** @type {?} */
  1577. const displayMonths = state.displayMonths;
  1578. // check initial rendering
  1579. // use selected date on initial rendering if set
  1580. /** @type {?} */
  1581. let viewDate = state.view.date;
  1582. if (state.view.mode === 'month') {
  1583. /** @type {?} */
  1584. const monthsCalendar = new Array(displayMonths);
  1585. for (let calendarIndex = 0; calendarIndex < displayMonths; calendarIndex++) {
  1586. // todo: for unlinked calendars it will be harder
  1587. monthsCalendar[calendarIndex] = formatMonthsCalendar(viewDate, getFormatOptions(state));
  1588. viewDate = shiftDate(viewDate, { year: 1 });
  1589. }
  1590. return Object.assign({}, state, { monthsCalendar });
  1591. }
  1592. if (state.view.mode === 'year') {
  1593. /** @type {?} */
  1594. const yearsCalendarModel = new Array(displayMonths);
  1595. for (let calendarIndex = 0; calendarIndex < displayMonths; calendarIndex++) {
  1596. // todo: for unlinked calendars it will be harder
  1597. yearsCalendarModel[calendarIndex] = formatYearsCalendar(viewDate, getFormatOptions(state));
  1598. viewDate = shiftDate(viewDate, { year: 16 });
  1599. }
  1600. return Object.assign({}, state, { yearsCalendarModel });
  1601. }
  1602. return state;
  1603. }
  1604. /**
  1605. * @param {?} state
  1606. * @param {?} action
  1607. * @return {?}
  1608. */
  1609. function flagReducer(state, action) {
  1610. if (state.view.mode === 'day') {
  1611. /** @type {?} */
  1612. const flaggedMonths = state.formattedMonths.map((/**
  1613. * @param {?} formattedMonth
  1614. * @param {?} monthIndex
  1615. * @return {?}
  1616. */
  1617. (formattedMonth, monthIndex) => flagDaysCalendar(formattedMonth, {
  1618. isDisabled: state.isDisabled,
  1619. minDate: state.minDate,
  1620. maxDate: state.maxDate,
  1621. daysDisabled: state.daysDisabled,
  1622. datesDisabled: state.datesDisabled,
  1623. hoveredDate: state.hoveredDate,
  1624. selectedDate: state.selectedDate,
  1625. selectedRange: state.selectedRange,
  1626. displayMonths: state.displayMonths,
  1627. dateCustomClasses: state.dateCustomClasses,
  1628. monthIndex
  1629. })));
  1630. return Object.assign({}, state, { flaggedMonths });
  1631. }
  1632. if (state.view.mode === 'month') {
  1633. /** @type {?} */
  1634. const flaggedMonthsCalendar = state.monthsCalendar.map((/**
  1635. * @param {?} formattedMonth
  1636. * @param {?} monthIndex
  1637. * @return {?}
  1638. */
  1639. (formattedMonth, monthIndex) => flagMonthsCalendar(formattedMonth, {
  1640. isDisabled: state.isDisabled,
  1641. minDate: state.minDate,
  1642. maxDate: state.maxDate,
  1643. hoveredMonth: state.hoveredMonth,
  1644. selectedDate: state.selectedDate,
  1645. displayMonths: state.displayMonths,
  1646. monthIndex
  1647. })));
  1648. return Object.assign({}, state, { flaggedMonthsCalendar });
  1649. }
  1650. if (state.view.mode === 'year') {
  1651. /** @type {?} */
  1652. const yearsCalendarFlagged = state.yearsCalendarModel.map((/**
  1653. * @param {?} formattedMonth
  1654. * @param {?} yearIndex
  1655. * @return {?}
  1656. */
  1657. (formattedMonth, yearIndex) => flagYearsCalendar(formattedMonth, {
  1658. isDisabled: state.isDisabled,
  1659. minDate: state.minDate,
  1660. maxDate: state.maxDate,
  1661. hoveredYear: state.hoveredYear,
  1662. selectedDate: state.selectedDate,
  1663. displayMonths: state.displayMonths,
  1664. yearIndex
  1665. })));
  1666. return Object.assign({}, state, { yearsCalendarFlagged });
  1667. }
  1668. return state;
  1669. }
  1670. /**
  1671. * @param {?} state
  1672. * @param {?} action
  1673. * @return {?}
  1674. */
  1675. function navigateOffsetReducer(state, action) {
  1676. /** @type {?} */
  1677. const newState = {
  1678. view: {
  1679. mode: state.view.mode,
  1680. date: shiftViewDate(state, action)
  1681. }
  1682. };
  1683. return Object.assign({}, state, newState);
  1684. }
  1685. /**
  1686. * @param {?} state
  1687. * @param {?} action
  1688. * @return {?}
  1689. */
  1690. function shiftViewDate(state, action) {
  1691. if (state.view.mode === 'year' && state.minMode === 'year') {
  1692. /** @type {?} */
  1693. const initialDate = getYearsCalendarInitialDate(state, 0);
  1694. /** @type {?} */
  1695. const middleDate = shiftDate(initialDate, { year: -initialYearShift });
  1696. return shiftDate(middleDate, action.payload);
  1697. }
  1698. return shiftDate(startOf(state.view.date, 'month'), action.payload);
  1699. }
  1700. /**
  1701. * @param {?} state
  1702. * @return {?}
  1703. */
  1704. function getFormatOptions(state) {
  1705. return {
  1706. locale: state.locale,
  1707. monthTitle: state.monthTitle,
  1708. yearTitle: state.yearTitle,
  1709. dayLabel: state.dayLabel,
  1710. monthLabel: state.monthLabel,
  1711. yearLabel: state.yearLabel,
  1712. weekNumbers: state.weekNumbers
  1713. };
  1714. }
  1715. /**
  1716. * if view date is provided (bsValue|ngModel) it should be shown
  1717. * if view date is not provider:
  1718. * if minDate>currentDate (default view value), show minDate
  1719. * if maxDate<currentDate(default view value) show maxDate
  1720. * @param {?} viewDate
  1721. * @param {?} minDate
  1722. * @param {?} maxDate
  1723. * @return {?}
  1724. */
  1725. function getViewDate(viewDate, minDate, maxDate) {
  1726. /** @type {?} */
  1727. const _date = Array.isArray(viewDate) ? viewDate[0] : viewDate;
  1728. if (minDate && isAfter(minDate, _date, 'day')) {
  1729. return minDate;
  1730. }
  1731. if (maxDate && isBefore(maxDate, _date, 'day')) {
  1732. return maxDate;
  1733. }
  1734. return _date;
  1735. }
  1736. /**
  1737. * @fileoverview added by tsickle
  1738. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1739. */
  1740. class BsDatepickerStore extends MiniStore {
  1741. constructor() {
  1742. /** @type {?} */
  1743. const _dispatcher = new BehaviorSubject({
  1744. type: '[datepicker] dispatcher init'
  1745. });
  1746. /** @type {?} */
  1747. const state = new MiniState(initialDatepickerState, _dispatcher, bsDatepickerReducer);
  1748. super(_dispatcher, bsDatepickerReducer, state);
  1749. }
  1750. }
  1751. BsDatepickerStore.decorators = [
  1752. { type: Injectable }
  1753. ];
  1754. /** @nocollapse */
  1755. BsDatepickerStore.ctorParameters = () => [];
  1756. /**
  1757. * @fileoverview added by tsickle
  1758. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1759. */
  1760. /** @type {?} */
  1761. const DATEPICKER_ANIMATION_TIMING = '220ms cubic-bezier(0, 0, 0.2, 1)';
  1762. /** @type {?} */
  1763. const datepickerAnimation = trigger('datepickerAnimation', [
  1764. state('animated-down', style({ height: '*', overflow: 'hidden' })),
  1765. transition('* => animated-down', [
  1766. style({ height: 0, overflow: 'hidden' }),
  1767. animate(DATEPICKER_ANIMATION_TIMING)
  1768. ]),
  1769. state('animated-up', style({ height: '*', overflow: 'hidden' })),
  1770. transition('* => animated-up', [
  1771. style({ height: '*', overflow: 'hidden' }),
  1772. animate(DATEPICKER_ANIMATION_TIMING)
  1773. ]),
  1774. transition('* => unanimated', animate('0s'))
  1775. ]);
  1776. /**
  1777. * @fileoverview added by tsickle
  1778. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1779. */
  1780. class BsDatepickerContainerComponent extends BsDatepickerAbstractComponent {
  1781. /**
  1782. * @param {?} _renderer
  1783. * @param {?} _config
  1784. * @param {?} _store
  1785. * @param {?} _element
  1786. * @param {?} _actions
  1787. * @param {?} _effects
  1788. * @param {?} _positionService
  1789. */
  1790. constructor(_renderer, _config, _store, _element, _actions, _effects, _positionService) {
  1791. super();
  1792. this._config = _config;
  1793. this._store = _store;
  1794. this._element = _element;
  1795. this._actions = _actions;
  1796. this._positionService = _positionService;
  1797. this.valueChange = new EventEmitter();
  1798. this.animationState = 'void';
  1799. this._subs = [];
  1800. this._effects = _effects;
  1801. _renderer.setStyle(_element.nativeElement, 'display', 'block');
  1802. _renderer.setStyle(_element.nativeElement, 'position', 'absolute');
  1803. }
  1804. /**
  1805. * @param {?} value
  1806. * @return {?}
  1807. */
  1808. set value(value) {
  1809. this._effects.setValue(value);
  1810. }
  1811. /**
  1812. * @return {?}
  1813. */
  1814. ngOnInit() {
  1815. this._positionService.setOptions({
  1816. modifiers: { flip: { enabled: this._config.adaptivePosition } },
  1817. allowedPositions: ['top', 'bottom']
  1818. });
  1819. this._positionService.event$
  1820. .pipe(take(1))
  1821. .subscribe((/**
  1822. * @return {?}
  1823. */
  1824. () => {
  1825. this._positionService.disable();
  1826. if (this._config.isAnimated) {
  1827. this.animationState = this.isTopPosition ? 'animated-up' : 'animated-down';
  1828. return;
  1829. }
  1830. this.animationState = 'unanimated';
  1831. }));
  1832. this.isOtherMonthsActive = this._config.selectFromOtherMonth;
  1833. this.containerClass = this._config.containerClass;
  1834. this._effects
  1835. .init(this._store)
  1836. // intial state options
  1837. .setOptions(this._config)
  1838. // data binding view --> model
  1839. .setBindings(this)
  1840. // set event handlers
  1841. .setEventHandlers(this)
  1842. .registerDatepickerSideEffects();
  1843. // todo: move it somewhere else
  1844. // on selected date change
  1845. this._subs.push(this._store
  1846. /* tslint:disable-next-line: no-any */
  1847. .select((/**
  1848. * @param {?} state
  1849. * @return {?}
  1850. */
  1851. (state) => state.selectedDate))
  1852. /* tslint:disable-next-line: no-any */
  1853. .subscribe((/**
  1854. * @param {?} date
  1855. * @return {?}
  1856. */
  1857. (date) => this.valueChange.emit(date))));
  1858. }
  1859. /**
  1860. * @return {?}
  1861. */
  1862. get isTopPosition() {
  1863. return this._element.nativeElement.classList.contains('top');
  1864. }
  1865. /**
  1866. * @return {?}
  1867. */
  1868. positionServiceEnable() {
  1869. this._positionService.enable();
  1870. }
  1871. /**
  1872. * @param {?} day
  1873. * @return {?}
  1874. */
  1875. daySelectHandler(day) {
  1876. /** @type {?} */
  1877. const isDisabled = this.isOtherMonthsActive ? day.isDisabled : (day.isOtherMonth || day.isDisabled);
  1878. if (isDisabled) {
  1879. return;
  1880. }
  1881. this._store.dispatch(this._actions.select(day.date));
  1882. }
  1883. /**
  1884. * @return {?}
  1885. */
  1886. ngOnDestroy() {
  1887. for (const sub of this._subs) {
  1888. sub.unsubscribe();
  1889. }
  1890. this._effects.destroy();
  1891. }
  1892. }
  1893. BsDatepickerContainerComponent.decorators = [
  1894. { type: Component, args: [{
  1895. selector: 'bs-datepicker-container',
  1896. providers: [BsDatepickerStore, BsDatepickerEffects],
  1897. template: "<!-- days calendar view mode -->\n<div class=\"bs-datepicker\" [ngClass]=\"containerClass\" *ngIf=\"viewMode | async\">\n <div class=\"bs-datepicker-container\"\n [@datepickerAnimation]=\"animationState\"\n (@datepickerAnimation.done)=\"positionServiceEnable()\">\n <!--calendars-->\n <div class=\"bs-calendar-container\" [ngSwitch]=\"viewMode | async\" role=\"application\">\n <!--days calendar-->\n <div *ngSwitchCase=\"'day'\" class=\"bs-media-container\">\n <bs-days-calendar-view\n *ngFor=\"let calendar of daysCalendar | async\"\n [class.bs-datepicker-multiple]=\"(daysCalendar | async)?.length > 1\"\n [calendar]=\"calendar\"\n [options]=\"options | async\"\n (onNavigate)=\"navigateTo($event)\"\n (onViewMode)=\"setViewMode($event)\"\n (onHover)=\"dayHoverHandler($event)\"\n (onHoverWeek)=\"weekHoverHandler($event)\"\n (onSelect)=\"daySelectHandler($event)\">\n </bs-days-calendar-view>\n </div>\n\n <!--months calendar-->\n <div *ngSwitchCase=\"'month'\" class=\"bs-media-container\">\n <bs-month-calendar-view\n *ngFor=\"let calendar of monthsCalendar | async\"\n [class.bs-datepicker-multiple]=\"(daysCalendar | async)?.length > 1\"\n [calendar]=\"calendar\"\n (onNavigate)=\"navigateTo($event)\"\n (onViewMode)=\"setViewMode($event)\"\n (onHover)=\"monthHoverHandler($event)\"\n (onSelect)=\"monthSelectHandler($event)\">\n </bs-month-calendar-view>\n </div>\n\n <!--years calendar-->\n <div *ngSwitchCase=\"'year'\" class=\"bs-media-container\">\n <bs-years-calendar-view\n *ngFor=\"let calendar of yearsCalendar | async\"\n [class.bs-datepicker-multiple]=\"(daysCalendar | async)?.length > 1\"\n [calendar]=\"calendar\"\n (onNavigate)=\"navigateTo($event)\"\n (onViewMode)=\"setViewMode($event)\"\n (onHover)=\"yearHoverHandler($event)\"\n (onSelect)=\"yearSelectHandler($event)\">\n </bs-years-calendar-view>\n </div>\n </div>\n\n <!--applycancel buttons-->\n <div class=\"bs-datepicker-buttons\" *ngIf=\"false\">\n <button class=\"btn btn-success\" type=\"button\">Apply</button>\n <button class=\"btn btn-default\" type=\"button\">Cancel</button>\n </div>\n </div>\n\n <!--custom dates or date ranges picker-->\n <div class=\"bs-datepicker-custom-range\" *ngIf=\"false\">\n <bs-custom-date-view [ranges]=\"_customRangesFish\"></bs-custom-date-view>\n </div>\n</div>\n",
  1898. host: {
  1899. class: 'bottom',
  1900. '(click)': '_stopPropagation($event)',
  1901. role: 'dialog',
  1902. 'aria-label': 'calendar'
  1903. },
  1904. animations: [datepickerAnimation]
  1905. }] }
  1906. ];
  1907. /** @nocollapse */
  1908. BsDatepickerContainerComponent.ctorParameters = () => [
  1909. { type: Renderer2 },
  1910. { type: BsDatepickerConfig },
  1911. { type: BsDatepickerStore },
  1912. { type: ElementRef },
  1913. { type: BsDatepickerActions },
  1914. { type: BsDatepickerEffects },
  1915. { type: PositioningService }
  1916. ];
  1917. /**
  1918. * @fileoverview added by tsickle
  1919. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  1920. */
  1921. class BsDatepickerDirective {
  1922. /**
  1923. * @param {?} _config
  1924. * @param {?} _elementRef
  1925. * @param {?} _renderer
  1926. * @param {?} _viewContainerRef
  1927. * @param {?} cis
  1928. */
  1929. constructor(_config, _elementRef, _renderer, _viewContainerRef, cis) {
  1930. this._config = _config;
  1931. /**
  1932. * Placement of a datepicker. Accepts: "top", "bottom", "left", "right"
  1933. */
  1934. this.placement = 'bottom';
  1935. /**
  1936. * Specifies events that should trigger. Supports a space separated list of
  1937. * event names.
  1938. */
  1939. this.triggers = 'click';
  1940. /**
  1941. * Close datepicker on outside click
  1942. */
  1943. this.outsideClick = true;
  1944. /**
  1945. * A selector specifying the element the datepicker should be appended to.
  1946. */
  1947. this.container = 'body';
  1948. this.outsideEsc = true;
  1949. /**
  1950. * Emits when datepicker value has been changed
  1951. */
  1952. this.bsValueChange = new EventEmitter();
  1953. this._subs = [];
  1954. // todo: assign only subset of fields
  1955. Object.assign(this, this._config);
  1956. this._datepicker = cis.createLoader(_elementRef, _viewContainerRef, _renderer);
  1957. this.onShown = this._datepicker.onShown;
  1958. this.onHidden = this._datepicker.onHidden;
  1959. }
  1960. /**
  1961. * Returns whether or not the datepicker is currently being shown
  1962. * @return {?}
  1963. */
  1964. get isOpen() {
  1965. return this._datepicker.isShown;
  1966. }
  1967. /**
  1968. * @param {?} value
  1969. * @return {?}
  1970. */
  1971. set isOpen(value) {
  1972. if (value) {
  1973. this.show();
  1974. }
  1975. else {
  1976. this.hide();
  1977. }
  1978. }
  1979. /**
  1980. * Initial value of datepicker
  1981. * @param {?} value
  1982. * @return {?}
  1983. */
  1984. set bsValue(value) {
  1985. if (this._bsValue === value) {
  1986. return;
  1987. }
  1988. this._bsValue = value;
  1989. this.bsValueChange.emit(value);
  1990. }
  1991. /**
  1992. * @return {?}
  1993. */
  1994. ngOnInit() {
  1995. this._datepicker.listen({
  1996. outsideClick: this.outsideClick,
  1997. outsideEsc: this.outsideEsc,
  1998. triggers: this.triggers,
  1999. show: (/**
  2000. * @return {?}
  2001. */
  2002. () => this.show())
  2003. });
  2004. this.setConfig();
  2005. }
  2006. /**
  2007. * @param {?} changes
  2008. * @return {?}
  2009. */
  2010. ngOnChanges(changes) {
  2011. if (!this._datepickerRef || !this._datepickerRef.instance) {
  2012. return;
  2013. }
  2014. if (changes.minDate) {
  2015. this._datepickerRef.instance.minDate = this.minDate;
  2016. }
  2017. if (changes.maxDate) {
  2018. this._datepickerRef.instance.maxDate = this.maxDate;
  2019. }
  2020. if (changes.daysDisabled) {
  2021. this._datepickerRef.instance.daysDisabled = this.daysDisabled;
  2022. }
  2023. if (changes.datesDisabled) {
  2024. this._datepickerRef.instance.datesDisabled = this.datesDisabled;
  2025. }
  2026. if (changes.isDisabled) {
  2027. this._datepickerRef.instance.isDisabled = this.isDisabled;
  2028. }
  2029. if (changes.dateCustomClasses) {
  2030. this._datepickerRef.instance.dateCustomClasses = this.dateCustomClasses;
  2031. }
  2032. }
  2033. /**
  2034. * Opens an element’s datepicker. This is considered a “manual” triggering of
  2035. * the datepicker.
  2036. * @return {?}
  2037. */
  2038. show() {
  2039. if (this._datepicker.isShown) {
  2040. return;
  2041. }
  2042. this.setConfig();
  2043. this._datepickerRef = this._datepicker
  2044. .provide({ provide: BsDatepickerConfig, useValue: this._config })
  2045. .attach(BsDatepickerContainerComponent)
  2046. .to(this.container)
  2047. .position({ attachment: this.placement })
  2048. .show({ placement: this.placement });
  2049. // if date changes from external source (model -> view)
  2050. this._subs.push(this.bsValueChange.subscribe((/**
  2051. * @param {?} value
  2052. * @return {?}
  2053. */
  2054. (value) => {
  2055. this._datepickerRef.instance.value = value;
  2056. })));
  2057. // if date changes from picker (view -> model)
  2058. this._subs.push(this._datepickerRef.instance.valueChange.subscribe((/**
  2059. * @param {?} value
  2060. * @return {?}
  2061. */
  2062. (value) => {
  2063. this.bsValue = value;
  2064. this.hide();
  2065. })));
  2066. }
  2067. /**
  2068. * Closes an element’s datepicker. This is considered a “manual” triggering of
  2069. * the datepicker.
  2070. * @return {?}
  2071. */
  2072. hide() {
  2073. if (this.isOpen) {
  2074. this._datepicker.hide();
  2075. }
  2076. for (const sub of this._subs) {
  2077. sub.unsubscribe();
  2078. }
  2079. }
  2080. /**
  2081. * Toggles an element’s datepicker. This is considered a “manual” triggering
  2082. * of the datepicker.
  2083. * @return {?}
  2084. */
  2085. toggle() {
  2086. if (this.isOpen) {
  2087. return this.hide();
  2088. }
  2089. this.show();
  2090. }
  2091. /**
  2092. * Set config for datepicker
  2093. * @return {?}
  2094. */
  2095. setConfig() {
  2096. this._config = Object.assign({}, this._config, this.bsConfig, {
  2097. value: this._bsValue,
  2098. isDisabled: this.isDisabled,
  2099. minDate: this.minDate || this.bsConfig && this.bsConfig.minDate,
  2100. maxDate: this.maxDate || this.bsConfig && this.bsConfig.maxDate,
  2101. daysDisabled: this.daysDisabled || this.bsConfig && this.bsConfig.daysDisabled,
  2102. dateCustomClasses: this.dateCustomClasses || this.bsConfig && this.bsConfig.dateCustomClasses,
  2103. datesDisabled: this.datesDisabled || this.bsConfig && this.bsConfig.datesDisabled,
  2104. minMode: this.minMode || this.bsConfig && this.bsConfig.minMode
  2105. });
  2106. }
  2107. /**
  2108. * @return {?}
  2109. */
  2110. ngOnDestroy() {
  2111. this._datepicker.dispose();
  2112. }
  2113. }
  2114. BsDatepickerDirective.decorators = [
  2115. { type: Directive, args: [{
  2116. selector: '[bsDatepicker]',
  2117. exportAs: 'bsDatepicker'
  2118. },] }
  2119. ];
  2120. /** @nocollapse */
  2121. BsDatepickerDirective.ctorParameters = () => [
  2122. { type: BsDatepickerConfig },
  2123. { type: ElementRef },
  2124. { type: Renderer2 },
  2125. { type: ViewContainerRef },
  2126. { type: ComponentLoaderFactory }
  2127. ];
  2128. BsDatepickerDirective.propDecorators = {
  2129. placement: [{ type: Input }],
  2130. triggers: [{ type: Input }],
  2131. outsideClick: [{ type: Input }],
  2132. container: [{ type: Input }],
  2133. outsideEsc: [{ type: Input }],
  2134. isOpen: [{ type: Input }],
  2135. onShown: [{ type: Output }],
  2136. onHidden: [{ type: Output }],
  2137. bsValue: [{ type: Input }],
  2138. bsConfig: [{ type: Input }],
  2139. isDisabled: [{ type: Input }],
  2140. minDate: [{ type: Input }],
  2141. maxDate: [{ type: Input }],
  2142. minMode: [{ type: Input }],
  2143. daysDisabled: [{ type: Input }],
  2144. datesDisabled: [{ type: Input }],
  2145. dateCustomClasses: [{ type: Input }],
  2146. bsValueChange: [{ type: Output }]
  2147. };
  2148. /**
  2149. * @fileoverview added by tsickle
  2150. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2151. */
  2152. class BsDatepickerInlineConfig extends BsDatepickerConfig {
  2153. }
  2154. BsDatepickerInlineConfig.decorators = [
  2155. { type: Injectable }
  2156. ];
  2157. /**
  2158. * @fileoverview added by tsickle
  2159. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2160. */
  2161. class BsDatepickerInlineContainerComponent extends BsDatepickerContainerComponent {
  2162. /**
  2163. * @param {?} _renderer
  2164. * @param {?} _config
  2165. * @param {?} _store
  2166. * @param {?} _element
  2167. * @param {?} _actions
  2168. * @param {?} _effects
  2169. * @param {?} _positioningService
  2170. */
  2171. constructor(_renderer, _config, _store, _element, _actions, _effects, _positioningService) {
  2172. super(_renderer, _config, _store, _element, _actions, _effects, _positioningService);
  2173. _renderer.setStyle(_element.nativeElement, 'display', 'inline-block');
  2174. _renderer.setStyle(_element.nativeElement, 'position', 'static');
  2175. }
  2176. }
  2177. BsDatepickerInlineContainerComponent.decorators = [
  2178. { type: Component, args: [{
  2179. selector: 'bs-datepicker-inline-container',
  2180. providers: [BsDatepickerStore, BsDatepickerEffects],
  2181. template: "<!-- days calendar view mode -->\n<div class=\"bs-datepicker\" [ngClass]=\"containerClass\" *ngIf=\"viewMode | async\">\n <div class=\"bs-datepicker-container\"\n [@datepickerAnimation]=\"animationState\"\n (@datepickerAnimation.done)=\"positionServiceEnable()\">\n <!--calendars-->\n <div class=\"bs-calendar-container\" [ngSwitch]=\"viewMode | async\" role=\"application\">\n <!--days calendar-->\n <div *ngSwitchCase=\"'day'\" class=\"bs-media-container\">\n <bs-days-calendar-view\n *ngFor=\"let calendar of daysCalendar | async\"\n [class.bs-datepicker-multiple]=\"(daysCalendar | async)?.length > 1\"\n [calendar]=\"calendar\"\n [options]=\"options | async\"\n (onNavigate)=\"navigateTo($event)\"\n (onViewMode)=\"setViewMode($event)\"\n (onHover)=\"dayHoverHandler($event)\"\n (onHoverWeek)=\"weekHoverHandler($event)\"\n (onSelect)=\"daySelectHandler($event)\">\n </bs-days-calendar-view>\n </div>\n\n <!--months calendar-->\n <div *ngSwitchCase=\"'month'\" class=\"bs-media-container\">\n <bs-month-calendar-view\n *ngFor=\"let calendar of monthsCalendar | async\"\n [class.bs-datepicker-multiple]=\"(daysCalendar | async)?.length > 1\"\n [calendar]=\"calendar\"\n (onNavigate)=\"navigateTo($event)\"\n (onViewMode)=\"setViewMode($event)\"\n (onHover)=\"monthHoverHandler($event)\"\n (onSelect)=\"monthSelectHandler($event)\">\n </bs-month-calendar-view>\n </div>\n\n <!--years calendar-->\n <div *ngSwitchCase=\"'year'\" class=\"bs-media-container\">\n <bs-years-calendar-view\n *ngFor=\"let calendar of yearsCalendar | async\"\n [class.bs-datepicker-multiple]=\"(daysCalendar | async)?.length > 1\"\n [calendar]=\"calendar\"\n (onNavigate)=\"navigateTo($event)\"\n (onViewMode)=\"setViewMode($event)\"\n (onHover)=\"yearHoverHandler($event)\"\n (onSelect)=\"yearSelectHandler($event)\">\n </bs-years-calendar-view>\n </div>\n </div>\n\n <!--applycancel buttons-->\n <div class=\"bs-datepicker-buttons\" *ngIf=\"false\">\n <button class=\"btn btn-success\" type=\"button\">Apply</button>\n <button class=\"btn btn-default\" type=\"button\">Cancel</button>\n </div>\n </div>\n\n <!--custom dates or date ranges picker-->\n <div class=\"bs-datepicker-custom-range\" *ngIf=\"false\">\n <bs-custom-date-view [ranges]=\"_customRangesFish\"></bs-custom-date-view>\n </div>\n</div>\n",
  2182. host: {
  2183. '(click)': '_stopPropagation($event)'
  2184. },
  2185. animations: [datepickerAnimation]
  2186. }] }
  2187. ];
  2188. /** @nocollapse */
  2189. BsDatepickerInlineContainerComponent.ctorParameters = () => [
  2190. { type: Renderer2 },
  2191. { type: BsDatepickerConfig },
  2192. { type: BsDatepickerStore },
  2193. { type: ElementRef },
  2194. { type: BsDatepickerActions },
  2195. { type: BsDatepickerEffects },
  2196. { type: PositioningService }
  2197. ];
  2198. /**
  2199. * @fileoverview added by tsickle
  2200. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2201. */
  2202. class BsDatepickerInlineDirective {
  2203. /**
  2204. * @param {?} _config
  2205. * @param {?} _elementRef
  2206. * @param {?} _renderer
  2207. * @param {?} _viewContainerRef
  2208. * @param {?} cis
  2209. */
  2210. constructor(_config, _elementRef, _renderer, _viewContainerRef, cis) {
  2211. this._config = _config;
  2212. this._elementRef = _elementRef;
  2213. /**
  2214. * Emits when datepicker value has been changed
  2215. */
  2216. this.bsValueChange = new EventEmitter();
  2217. this._subs = [];
  2218. // todo: assign only subset of fields
  2219. Object.assign(this, this._config);
  2220. this._datepicker = cis.createLoader(_elementRef, _viewContainerRef, _renderer);
  2221. }
  2222. /**
  2223. * Initial value of datepicker
  2224. * @param {?} value
  2225. * @return {?}
  2226. */
  2227. set bsValue(value) {
  2228. if (this._bsValue === value) {
  2229. return;
  2230. }
  2231. this._bsValue = value;
  2232. this.bsValueChange.emit(value);
  2233. }
  2234. /**
  2235. * @return {?}
  2236. */
  2237. ngOnInit() {
  2238. this.setConfig();
  2239. this._datepickerRef = this._datepicker
  2240. .provide({ provide: BsDatepickerConfig, useValue: this._config })
  2241. .attach(BsDatepickerInlineContainerComponent)
  2242. .to(this._elementRef)
  2243. .show();
  2244. // if date changes from external source (model -> view)
  2245. this._subs.push(this.bsValueChange.subscribe((/**
  2246. * @param {?} value
  2247. * @return {?}
  2248. */
  2249. (value) => {
  2250. this._datepickerRef.instance.value = value;
  2251. })));
  2252. // if date changes from picker (view -> model)
  2253. this._subs.push(this._datepickerRef.instance.valueChange.subscribe((/**
  2254. * @param {?} value
  2255. * @return {?}
  2256. */
  2257. (value) => {
  2258. this.bsValue = value;
  2259. })));
  2260. }
  2261. /**
  2262. * @param {?} changes
  2263. * @return {?}
  2264. */
  2265. ngOnChanges(changes) {
  2266. if (!this._datepickerRef || !this._datepickerRef.instance) {
  2267. return;
  2268. }
  2269. if (changes.minDate) {
  2270. this._datepickerRef.instance.minDate = this.minDate;
  2271. this._datepickerRef.instance.value = this._bsValue;
  2272. }
  2273. if (changes.maxDate) {
  2274. this._datepickerRef.instance.maxDate = this.maxDate;
  2275. this._datepickerRef.instance.value = this._bsValue;
  2276. }
  2277. if (changes.datesDisabled) {
  2278. this._datepickerRef.instance.datesDisabled = this.datesDisabled;
  2279. this._datepickerRef.instance.value = this._bsValue;
  2280. }
  2281. if (changes.isDisabled) {
  2282. this._datepickerRef.instance.isDisabled = this.isDisabled;
  2283. }
  2284. if (changes.dateCustomClasses) {
  2285. this._datepickerRef.instance.dateCustomClasses = this.dateCustomClasses;
  2286. }
  2287. }
  2288. /**
  2289. * Set config for datepicker
  2290. * @return {?}
  2291. */
  2292. setConfig() {
  2293. this._config = Object.assign({}, this._config, this.bsConfig, {
  2294. value: this._bsValue,
  2295. isDisabled: this.isDisabled,
  2296. minDate: this.minDate || this.bsConfig && this.bsConfig.minDate,
  2297. maxDate: this.maxDate || this.bsConfig && this.bsConfig.maxDate,
  2298. dateCustomClasses: this.dateCustomClasses || this.bsConfig && this.bsConfig.dateCustomClasses,
  2299. datesDisabled: this.datesDisabled || this.bsConfig && this.bsConfig.datesDisabled
  2300. });
  2301. }
  2302. /**
  2303. * @return {?}
  2304. */
  2305. ngOnDestroy() {
  2306. this._datepicker.dispose();
  2307. }
  2308. }
  2309. BsDatepickerInlineDirective.decorators = [
  2310. { type: Directive, args: [{
  2311. selector: 'bs-datepicker-inline',
  2312. exportAs: 'bsDatepickerInline'
  2313. },] }
  2314. ];
  2315. /** @nocollapse */
  2316. BsDatepickerInlineDirective.ctorParameters = () => [
  2317. { type: BsDatepickerInlineConfig },
  2318. { type: ElementRef },
  2319. { type: Renderer2 },
  2320. { type: ViewContainerRef },
  2321. { type: ComponentLoaderFactory }
  2322. ];
  2323. BsDatepickerInlineDirective.propDecorators = {
  2324. bsValue: [{ type: Input }],
  2325. bsConfig: [{ type: Input }],
  2326. isDisabled: [{ type: Input }],
  2327. minDate: [{ type: Input }],
  2328. maxDate: [{ type: Input }],
  2329. dateCustomClasses: [{ type: Input }],
  2330. datesDisabled: [{ type: Input }],
  2331. bsValueChange: [{ type: Output }]
  2332. };
  2333. /**
  2334. * @fileoverview added by tsickle
  2335. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2336. */
  2337. class BsDaterangepickerInlineConfig extends BsDatepickerConfig {
  2338. constructor() {
  2339. super(...arguments);
  2340. // DatepickerRenderOptions
  2341. this.displayMonths = 2;
  2342. /**
  2343. * turn on/off animation
  2344. */
  2345. this.isAnimated = false;
  2346. }
  2347. }
  2348. BsDaterangepickerInlineConfig.decorators = [
  2349. { type: Injectable }
  2350. ];
  2351. /**
  2352. * @fileoverview added by tsickle
  2353. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2354. */
  2355. class BsDaterangepickerContainerComponent extends BsDatepickerAbstractComponent {
  2356. /**
  2357. * @param {?} _renderer
  2358. * @param {?} _config
  2359. * @param {?} _store
  2360. * @param {?} _element
  2361. * @param {?} _actions
  2362. * @param {?} _effects
  2363. * @param {?} _positionService
  2364. */
  2365. constructor(_renderer, _config, _store, _element, _actions, _effects, _positionService) {
  2366. super();
  2367. this._config = _config;
  2368. this._store = _store;
  2369. this._element = _element;
  2370. this._actions = _actions;
  2371. this._positionService = _positionService;
  2372. this.valueChange = new EventEmitter();
  2373. this.animationState = 'void';
  2374. this._rangeStack = [];
  2375. this._subs = [];
  2376. this._effects = _effects;
  2377. _renderer.setStyle(_element.nativeElement, 'display', 'block');
  2378. _renderer.setStyle(_element.nativeElement, 'position', 'absolute');
  2379. }
  2380. /**
  2381. * @param {?} value
  2382. * @return {?}
  2383. */
  2384. set value(value) {
  2385. this._effects.setRangeValue(value);
  2386. }
  2387. /**
  2388. * @return {?}
  2389. */
  2390. ngOnInit() {
  2391. this._positionService.setOptions({
  2392. modifiers: { flip: { enabled: this._config.adaptivePosition } },
  2393. allowedPositions: ['top', 'bottom']
  2394. });
  2395. this._positionService.event$
  2396. .pipe(take(1))
  2397. .subscribe((/**
  2398. * @return {?}
  2399. */
  2400. () => {
  2401. this._positionService.disable();
  2402. if (this._config.isAnimated) {
  2403. this.animationState = this.isTopPosition ? 'animated-up' : 'animated-down';
  2404. return;
  2405. }
  2406. this.animationState = 'unanimated';
  2407. }));
  2408. this.containerClass = this._config.containerClass;
  2409. this.isOtherMonthsActive = this._config.selectFromOtherMonth;
  2410. this._effects
  2411. .init(this._store)
  2412. // intial state options
  2413. // todo: fix this, split configs
  2414. .setOptions(this._config)
  2415. // data binding view --> model
  2416. .setBindings(this)
  2417. // set event handlers
  2418. .setEventHandlers(this)
  2419. .registerDatepickerSideEffects();
  2420. // todo: move it somewhere else
  2421. // on selected date change
  2422. this._subs.push(this._store
  2423. .select((/**
  2424. * @param {?} state
  2425. * @return {?}
  2426. */
  2427. state => state.selectedRange))
  2428. .subscribe((/**
  2429. * @param {?} date
  2430. * @return {?}
  2431. */
  2432. date => this.valueChange.emit(date))));
  2433. }
  2434. /**
  2435. * @return {?}
  2436. */
  2437. get isTopPosition() {
  2438. return this._element.nativeElement.classList.contains('top');
  2439. }
  2440. /**
  2441. * @return {?}
  2442. */
  2443. positionServiceEnable() {
  2444. this._positionService.enable();
  2445. }
  2446. /**
  2447. * @param {?} day
  2448. * @return {?}
  2449. */
  2450. daySelectHandler(day) {
  2451. /** @type {?} */
  2452. const isDisabled = this.isOtherMonthsActive ? day.isDisabled : (day.isOtherMonth || day.isDisabled);
  2453. if (isDisabled) {
  2454. return;
  2455. }
  2456. // if only one date is already selected
  2457. // and user clicks on previous date
  2458. // start selection from new date
  2459. // but if new date is after initial one
  2460. // than finish selection
  2461. if (this._rangeStack.length === 1) {
  2462. this._rangeStack =
  2463. day.date >= this._rangeStack[0]
  2464. ? [this._rangeStack[0], day.date]
  2465. : [day.date];
  2466. }
  2467. if (this._rangeStack.length === 0) {
  2468. this._rangeStack = [day.date];
  2469. }
  2470. this._store.dispatch(this._actions.selectRange(this._rangeStack));
  2471. if (this._rangeStack.length === 2) {
  2472. this._rangeStack = [];
  2473. }
  2474. }
  2475. /**
  2476. * @return {?}
  2477. */
  2478. ngOnDestroy() {
  2479. for (const sub of this._subs) {
  2480. sub.unsubscribe();
  2481. }
  2482. this._effects.destroy();
  2483. }
  2484. }
  2485. BsDaterangepickerContainerComponent.decorators = [
  2486. { type: Component, args: [{
  2487. selector: 'bs-daterangepicker-container',
  2488. providers: [BsDatepickerStore, BsDatepickerEffects],
  2489. template: "<!-- days calendar view mode -->\n<div class=\"bs-datepicker\" [ngClass]=\"containerClass\" *ngIf=\"viewMode | async\">\n <div class=\"bs-datepicker-container\"\n [@datepickerAnimation]=\"animationState\"\n (@datepickerAnimation.done)=\"positionServiceEnable()\">\n <!--calendars-->\n <div class=\"bs-calendar-container\" [ngSwitch]=\"viewMode | async\" role=\"application\">\n <!--days calendar-->\n <div *ngSwitchCase=\"'day'\" class=\"bs-media-container\">\n <bs-days-calendar-view\n *ngFor=\"let calendar of daysCalendar | async\"\n [class.bs-datepicker-multiple]=\"(daysCalendar | async)?.length > 1\"\n [calendar]=\"calendar\"\n [options]=\"options | async\"\n (onNavigate)=\"navigateTo($event)\"\n (onViewMode)=\"setViewMode($event)\"\n (onHover)=\"dayHoverHandler($event)\"\n (onHoverWeek)=\"weekHoverHandler($event)\"\n (onSelect)=\"daySelectHandler($event)\">\n </bs-days-calendar-view>\n </div>\n\n <!--months calendar-->\n <div *ngSwitchCase=\"'month'\" class=\"bs-media-container\">\n <bs-month-calendar-view\n *ngFor=\"let calendar of monthsCalendar | async\"\n [class.bs-datepicker-multiple]=\"(daysCalendar | async)?.length > 1\"\n [calendar]=\"calendar\"\n (onNavigate)=\"navigateTo($event)\"\n (onViewMode)=\"setViewMode($event)\"\n (onHover)=\"monthHoverHandler($event)\"\n (onSelect)=\"monthSelectHandler($event)\">\n </bs-month-calendar-view>\n </div>\n\n <!--years calendar-->\n <div *ngSwitchCase=\"'year'\" class=\"bs-media-container\">\n <bs-years-calendar-view\n *ngFor=\"let calendar of yearsCalendar | async\"\n [class.bs-datepicker-multiple]=\"(daysCalendar | async)?.length > 1\"\n [calendar]=\"calendar\"\n (onNavigate)=\"navigateTo($event)\"\n (onViewMode)=\"setViewMode($event)\"\n (onHover)=\"yearHoverHandler($event)\"\n (onSelect)=\"yearSelectHandler($event)\">\n </bs-years-calendar-view>\n </div>\n </div>\n\n <!--applycancel buttons-->\n <div class=\"bs-datepicker-buttons\" *ngIf=\"false\">\n <button class=\"btn btn-success\" type=\"button\">Apply</button>\n <button class=\"btn btn-default\" type=\"button\">Cancel</button>\n </div>\n </div>\n\n <!--custom dates or date ranges picker-->\n <div class=\"bs-datepicker-custom-range\" *ngIf=\"false\">\n <bs-custom-date-view [ranges]=\"_customRangesFish\"></bs-custom-date-view>\n </div>\n</div>\n",
  2490. host: {
  2491. class: 'bottom',
  2492. '(click)': '_stopPropagation($event)',
  2493. role: 'dialog',
  2494. 'aria-label': 'calendar'
  2495. },
  2496. animations: [datepickerAnimation]
  2497. }] }
  2498. ];
  2499. /** @nocollapse */
  2500. BsDaterangepickerContainerComponent.ctorParameters = () => [
  2501. { type: Renderer2 },
  2502. { type: BsDatepickerConfig },
  2503. { type: BsDatepickerStore },
  2504. { type: ElementRef },
  2505. { type: BsDatepickerActions },
  2506. { type: BsDatepickerEffects },
  2507. { type: PositioningService }
  2508. ];
  2509. /**
  2510. * @fileoverview added by tsickle
  2511. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2512. */
  2513. class BsDaterangepickerInlineContainerComponent extends BsDaterangepickerContainerComponent {
  2514. /**
  2515. * @param {?} _renderer
  2516. * @param {?} _config
  2517. * @param {?} _store
  2518. * @param {?} _element
  2519. * @param {?} _actions
  2520. * @param {?} _effects
  2521. * @param {?} _positioningService
  2522. */
  2523. constructor(_renderer, _config, _store, _element, _actions, _effects, _positioningService) {
  2524. super(_renderer, _config, _store, _element, _actions, _effects, _positioningService);
  2525. _renderer.setStyle(_element.nativeElement, 'display', 'inline-block');
  2526. _renderer.setStyle(_element.nativeElement, 'position', 'static');
  2527. }
  2528. }
  2529. BsDaterangepickerInlineContainerComponent.decorators = [
  2530. { type: Component, args: [{
  2531. selector: 'bs-daterangepicker-inline-container',
  2532. providers: [BsDatepickerStore, BsDatepickerEffects],
  2533. template: "<!-- days calendar view mode -->\n<div class=\"bs-datepicker\" [ngClass]=\"containerClass\" *ngIf=\"viewMode | async\">\n <div class=\"bs-datepicker-container\"\n [@datepickerAnimation]=\"animationState\"\n (@datepickerAnimation.done)=\"positionServiceEnable()\">\n <!--calendars-->\n <div class=\"bs-calendar-container\" [ngSwitch]=\"viewMode | async\" role=\"application\">\n <!--days calendar-->\n <div *ngSwitchCase=\"'day'\" class=\"bs-media-container\">\n <bs-days-calendar-view\n *ngFor=\"let calendar of daysCalendar | async\"\n [class.bs-datepicker-multiple]=\"(daysCalendar | async)?.length > 1\"\n [calendar]=\"calendar\"\n [options]=\"options | async\"\n (onNavigate)=\"navigateTo($event)\"\n (onViewMode)=\"setViewMode($event)\"\n (onHover)=\"dayHoverHandler($event)\"\n (onHoverWeek)=\"weekHoverHandler($event)\"\n (onSelect)=\"daySelectHandler($event)\">\n </bs-days-calendar-view>\n </div>\n\n <!--months calendar-->\n <div *ngSwitchCase=\"'month'\" class=\"bs-media-container\">\n <bs-month-calendar-view\n *ngFor=\"let calendar of monthsCalendar | async\"\n [class.bs-datepicker-multiple]=\"(daysCalendar | async)?.length > 1\"\n [calendar]=\"calendar\"\n (onNavigate)=\"navigateTo($event)\"\n (onViewMode)=\"setViewMode($event)\"\n (onHover)=\"monthHoverHandler($event)\"\n (onSelect)=\"monthSelectHandler($event)\">\n </bs-month-calendar-view>\n </div>\n\n <!--years calendar-->\n <div *ngSwitchCase=\"'year'\" class=\"bs-media-container\">\n <bs-years-calendar-view\n *ngFor=\"let calendar of yearsCalendar | async\"\n [class.bs-datepicker-multiple]=\"(daysCalendar | async)?.length > 1\"\n [calendar]=\"calendar\"\n (onNavigate)=\"navigateTo($event)\"\n (onViewMode)=\"setViewMode($event)\"\n (onHover)=\"yearHoverHandler($event)\"\n (onSelect)=\"yearSelectHandler($event)\">\n </bs-years-calendar-view>\n </div>\n </div>\n\n <!--applycancel buttons-->\n <div class=\"bs-datepicker-buttons\" *ngIf=\"false\">\n <button class=\"btn btn-success\" type=\"button\">Apply</button>\n <button class=\"btn btn-default\" type=\"button\">Cancel</button>\n </div>\n </div>\n\n <!--custom dates or date ranges picker-->\n <div class=\"bs-datepicker-custom-range\" *ngIf=\"false\">\n <bs-custom-date-view [ranges]=\"_customRangesFish\"></bs-custom-date-view>\n </div>\n</div>\n",
  2534. host: {
  2535. '(click)': '_stopPropagation($event)'
  2536. },
  2537. animations: [datepickerAnimation]
  2538. }] }
  2539. ];
  2540. /** @nocollapse */
  2541. BsDaterangepickerInlineContainerComponent.ctorParameters = () => [
  2542. { type: Renderer2 },
  2543. { type: BsDatepickerConfig },
  2544. { type: BsDatepickerStore },
  2545. { type: ElementRef },
  2546. { type: BsDatepickerActions },
  2547. { type: BsDatepickerEffects },
  2548. { type: PositioningService }
  2549. ];
  2550. /**
  2551. * @fileoverview added by tsickle
  2552. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2553. */
  2554. class BsDaterangepickerInlineDirective {
  2555. /**
  2556. * @param {?} _config
  2557. * @param {?} _elementRef
  2558. * @param {?} _renderer
  2559. * @param {?} _viewContainerRef
  2560. * @param {?} cis
  2561. */
  2562. constructor(_config, _elementRef, _renderer, _viewContainerRef, cis) {
  2563. this._config = _config;
  2564. this._elementRef = _elementRef;
  2565. /**
  2566. * Emits when daterangepicker value has been changed
  2567. */
  2568. this.bsValueChange = new EventEmitter();
  2569. this._subs = [];
  2570. // todo: assign only subset of fields
  2571. Object.assign(this, this._config);
  2572. this._datepicker = cis.createLoader(_elementRef, _viewContainerRef, _renderer);
  2573. }
  2574. /**
  2575. * Initial value of datepicker
  2576. * @param {?} value
  2577. * @return {?}
  2578. */
  2579. set bsValue(value) {
  2580. if (this._bsValue === value) {
  2581. return;
  2582. }
  2583. this._bsValue = value;
  2584. this.bsValueChange.emit(value);
  2585. }
  2586. /**
  2587. * @return {?}
  2588. */
  2589. ngOnInit() {
  2590. this.setConfig();
  2591. this._datepickerRef = this._datepicker
  2592. .provide({ provide: BsDatepickerConfig, useValue: this._config })
  2593. .attach(BsDaterangepickerInlineContainerComponent)
  2594. .to(this._elementRef)
  2595. .show();
  2596. // if date changes from external source (model -> view)
  2597. this._subs.push(this.bsValueChange.subscribe((/**
  2598. * @param {?} value
  2599. * @return {?}
  2600. */
  2601. (value) => {
  2602. this._datepickerRef.instance.value = value;
  2603. })));
  2604. // if date changes from picker (view -> model)
  2605. this._subs.push(this._datepickerRef.instance.valueChange
  2606. .pipe(filter((/**
  2607. * @param {?} range
  2608. * @return {?}
  2609. */
  2610. (range) => range && range[0] && !!range[1])))
  2611. .subscribe((/**
  2612. * @param {?} value
  2613. * @return {?}
  2614. */
  2615. (value) => {
  2616. this.bsValue = value;
  2617. })));
  2618. }
  2619. /**
  2620. * @param {?} changes
  2621. * @return {?}
  2622. */
  2623. ngOnChanges(changes) {
  2624. if (!this._datepickerRef || !this._datepickerRef.instance) {
  2625. return;
  2626. }
  2627. if (changes.minDate) {
  2628. this._datepickerRef.instance.minDate = this.minDate;
  2629. }
  2630. if (changes.maxDate) {
  2631. this._datepickerRef.instance.maxDate = this.maxDate;
  2632. }
  2633. if (changes.datesDisabled) {
  2634. this._datepickerRef.instance.datesDisabled = this.datesDisabled;
  2635. }
  2636. if (changes.isDisabled) {
  2637. this._datepickerRef.instance.isDisabled = this.isDisabled;
  2638. }
  2639. if (changes.dateCustomClasses) {
  2640. this._datepickerRef.instance.dateCustomClasses = this.dateCustomClasses;
  2641. }
  2642. }
  2643. /**
  2644. * Set config for datepicker
  2645. * @return {?}
  2646. */
  2647. setConfig() {
  2648. this._config = Object.assign({}, this._config, this.bsConfig, {
  2649. value: this._bsValue,
  2650. isDisabled: this.isDisabled,
  2651. minDate: this.minDate || this.bsConfig && this.bsConfig.minDate,
  2652. maxDate: this.maxDate || this.bsConfig && this.bsConfig.maxDate,
  2653. dateCustomClasses: this.dateCustomClasses || this.bsConfig && this.bsConfig.dateCustomClasses,
  2654. datesDisabled: this.datesDisabled || this.bsConfig && this.bsConfig.datesDisabled
  2655. });
  2656. }
  2657. /**
  2658. * @return {?}
  2659. */
  2660. ngOnDestroy() {
  2661. this._datepicker.dispose();
  2662. }
  2663. }
  2664. BsDaterangepickerInlineDirective.decorators = [
  2665. { type: Directive, args: [{
  2666. selector: 'bs-daterangepicker-inline',
  2667. exportAs: 'bsDaterangepickerInline'
  2668. },] }
  2669. ];
  2670. /** @nocollapse */
  2671. BsDaterangepickerInlineDirective.ctorParameters = () => [
  2672. { type: BsDaterangepickerInlineConfig },
  2673. { type: ElementRef },
  2674. { type: Renderer2 },
  2675. { type: ViewContainerRef },
  2676. { type: ComponentLoaderFactory }
  2677. ];
  2678. BsDaterangepickerInlineDirective.propDecorators = {
  2679. bsValue: [{ type: Input }],
  2680. bsConfig: [{ type: Input }],
  2681. isDisabled: [{ type: Input }],
  2682. minDate: [{ type: Input }],
  2683. maxDate: [{ type: Input }],
  2684. dateCustomClasses: [{ type: Input }],
  2685. datesDisabled: [{ type: Input }],
  2686. bsValueChange: [{ type: Output }]
  2687. };
  2688. /**
  2689. * @fileoverview added by tsickle
  2690. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2691. */
  2692. /** @type {?} */
  2693. const BS_DATEPICKER_VALUE_ACCESSOR = {
  2694. provide: NG_VALUE_ACCESSOR,
  2695. /* tslint:disable-next-line: no-use-before-declare */
  2696. useExisting: forwardRef((/**
  2697. * @return {?}
  2698. */
  2699. () => BsDatepickerInputDirective)),
  2700. multi: true
  2701. };
  2702. /** @type {?} */
  2703. const BS_DATEPICKER_VALIDATOR = {
  2704. provide: NG_VALIDATORS,
  2705. /* tslint:disable-next-line: no-use-before-declare */
  2706. useExisting: forwardRef((/**
  2707. * @return {?}
  2708. */
  2709. () => BsDatepickerInputDirective)),
  2710. multi: true
  2711. };
  2712. class BsDatepickerInputDirective {
  2713. /**
  2714. * @param {?} _picker
  2715. * @param {?} _localeService
  2716. * @param {?} _renderer
  2717. * @param {?} _elRef
  2718. * @param {?} changeDetection
  2719. */
  2720. constructor(_picker, _localeService, _renderer, _elRef, changeDetection) {
  2721. this._picker = _picker;
  2722. this._localeService = _localeService;
  2723. this._renderer = _renderer;
  2724. this._elRef = _elRef;
  2725. this.changeDetection = changeDetection;
  2726. this._onChange = Function.prototype;
  2727. this._onTouched = Function.prototype;
  2728. /* tslint:disable-next-line: no-unused-variable */
  2729. this._validatorChange = Function.prototype;
  2730. // update input value on datepicker value update
  2731. this._picker.bsValueChange.subscribe((/**
  2732. * @param {?} value
  2733. * @return {?}
  2734. */
  2735. (value) => {
  2736. this._setInputValue(value);
  2737. if (this._value !== value) {
  2738. this._value = value;
  2739. this._onChange(value);
  2740. this._onTouched();
  2741. }
  2742. this.changeDetection.markForCheck();
  2743. }));
  2744. // update input value on locale change
  2745. this._localeService.localeChange.subscribe((/**
  2746. * @return {?}
  2747. */
  2748. () => {
  2749. this._setInputValue(this._value);
  2750. }));
  2751. }
  2752. /**
  2753. * @param {?} value
  2754. * @return {?}
  2755. */
  2756. _setInputValue(value) {
  2757. /** @type {?} */
  2758. const initialDate = !value ? ''
  2759. : formatDate(value, this._picker._config.dateInputFormat, this._localeService.currentLocale);
  2760. this._renderer.setProperty(this._elRef.nativeElement, 'value', initialDate);
  2761. }
  2762. /**
  2763. * @param {?} event
  2764. * @return {?}
  2765. */
  2766. onChange(event) {
  2767. /* tslint:disable-next-line: no-any*/
  2768. this.writeValue(((/** @type {?} */ (event.target))).value);
  2769. this._onChange(this._value);
  2770. this._onTouched();
  2771. }
  2772. /**
  2773. * @param {?} c
  2774. * @return {?}
  2775. */
  2776. validate(c) {
  2777. /** @type {?} */
  2778. const _value = c.value;
  2779. /* tslint:disable-next-line: prefer-switch */
  2780. if (_value === null || _value === undefined || _value === '') {
  2781. return null;
  2782. }
  2783. if (isDate(_value)) {
  2784. /** @type {?} */
  2785. const _isDateValid = isDateValid(_value);
  2786. if (!_isDateValid) {
  2787. return { bsDate: { invalid: _value } };
  2788. }
  2789. if (this._picker && this._picker.minDate && isBefore(_value, this._picker.minDate, 'date')) {
  2790. return { bsDate: { minDate: this._picker.minDate } };
  2791. }
  2792. if (this._picker && this._picker.maxDate && isAfter(_value, this._picker.maxDate, 'date')) {
  2793. return { bsDate: { maxDate: this._picker.maxDate } };
  2794. }
  2795. }
  2796. }
  2797. /**
  2798. * @param {?} fn
  2799. * @return {?}
  2800. */
  2801. registerOnValidatorChange(fn) {
  2802. this._validatorChange = fn;
  2803. }
  2804. /**
  2805. * @param {?} value
  2806. * @return {?}
  2807. */
  2808. writeValue(value) {
  2809. if (!value) {
  2810. this._value = null;
  2811. }
  2812. else {
  2813. /** @type {?} */
  2814. const _localeKey = this._localeService.currentLocale;
  2815. /** @type {?} */
  2816. const _locale = getLocale(_localeKey);
  2817. if (!_locale) {
  2818. throw new Error(`Locale "${_localeKey}" is not defined, please add it with "defineLocale(...)"`);
  2819. }
  2820. this._value = parseDate(value, this._picker._config.dateInputFormat, this._localeService.currentLocale);
  2821. if (this._picker._config.useUtc) {
  2822. this._value = utcAsLocal(this._value);
  2823. }
  2824. }
  2825. this._picker.bsValue = this._value;
  2826. }
  2827. /**
  2828. * @param {?} isDisabled
  2829. * @return {?}
  2830. */
  2831. setDisabledState(isDisabled) {
  2832. this._picker.isDisabled = isDisabled;
  2833. if (isDisabled) {
  2834. this._renderer.setAttribute(this._elRef.nativeElement, 'disabled', 'disabled');
  2835. return;
  2836. }
  2837. this._renderer.removeAttribute(this._elRef.nativeElement, 'disabled');
  2838. }
  2839. /**
  2840. * @param {?} fn
  2841. * @return {?}
  2842. */
  2843. registerOnChange(fn) {
  2844. this._onChange = fn;
  2845. }
  2846. /**
  2847. * @param {?} fn
  2848. * @return {?}
  2849. */
  2850. registerOnTouched(fn) {
  2851. this._onTouched = fn;
  2852. }
  2853. /**
  2854. * @return {?}
  2855. */
  2856. onBlur() {
  2857. this._onTouched();
  2858. }
  2859. /**
  2860. * @return {?}
  2861. */
  2862. hide() {
  2863. this._picker.hide();
  2864. this._renderer.selectRootElement(this._elRef.nativeElement).blur();
  2865. }
  2866. }
  2867. BsDatepickerInputDirective.decorators = [
  2868. { type: Directive, args: [{
  2869. selector: `input[bsDatepicker]`,
  2870. host: {
  2871. '(change)': 'onChange($event)',
  2872. '(keyup.esc)': 'hide()',
  2873. '(blur)': 'onBlur()'
  2874. },
  2875. providers: [BS_DATEPICKER_VALUE_ACCESSOR, BS_DATEPICKER_VALIDATOR]
  2876. },] }
  2877. ];
  2878. /** @nocollapse */
  2879. BsDatepickerInputDirective.ctorParameters = () => [
  2880. { type: BsDatepickerDirective, decorators: [{ type: Host }] },
  2881. { type: BsLocaleService },
  2882. { type: Renderer2 },
  2883. { type: ElementRef },
  2884. { type: ChangeDetectorRef }
  2885. ];
  2886. /**
  2887. * @fileoverview added by tsickle
  2888. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2889. */
  2890. class BsDaterangepickerConfig extends BsDatepickerConfig {
  2891. constructor() {
  2892. super(...arguments);
  2893. // DatepickerRenderOptions
  2894. this.displayMonths = 2;
  2895. }
  2896. }
  2897. BsDaterangepickerConfig.decorators = [
  2898. { type: Injectable }
  2899. ];
  2900. /**
  2901. * @fileoverview added by tsickle
  2902. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  2903. */
  2904. class BsDaterangepickerDirective {
  2905. /**
  2906. * @param {?} _config
  2907. * @param {?} _elementRef
  2908. * @param {?} _renderer
  2909. * @param {?} _viewContainerRef
  2910. * @param {?} cis
  2911. */
  2912. constructor(_config, _elementRef, _renderer, _viewContainerRef, cis) {
  2913. this._config = _config;
  2914. /**
  2915. * Placement of a daterangepicker. Accepts: "top", "bottom", "left", "right"
  2916. */
  2917. this.placement = 'bottom';
  2918. /**
  2919. * Specifies events that should trigger. Supports a space separated list of
  2920. * event names.
  2921. */
  2922. this.triggers = 'click';
  2923. /**
  2924. * Close daterangepicker on outside click
  2925. */
  2926. this.outsideClick = true;
  2927. /**
  2928. * A selector specifying the element the daterangepicker should be appended to.
  2929. */
  2930. this.container = 'body';
  2931. this.outsideEsc = true;
  2932. /**
  2933. * Emits when daterangepicker value has been changed
  2934. */
  2935. this.bsValueChange = new EventEmitter();
  2936. this._subs = [];
  2937. this._datepicker = cis.createLoader(_elementRef, _viewContainerRef, _renderer);
  2938. Object.assign(this, _config);
  2939. this.onShown = this._datepicker.onShown;
  2940. this.onHidden = this._datepicker.onHidden;
  2941. }
  2942. /**
  2943. * Returns whether or not the daterangepicker is currently being shown
  2944. * @return {?}
  2945. */
  2946. get isOpen() {
  2947. return this._datepicker.isShown;
  2948. }
  2949. /**
  2950. * @param {?} value
  2951. * @return {?}
  2952. */
  2953. set isOpen(value) {
  2954. if (value) {
  2955. this.show();
  2956. }
  2957. else {
  2958. this.hide();
  2959. }
  2960. }
  2961. /**
  2962. * Initial value of daterangepicker
  2963. * @param {?} value
  2964. * @return {?}
  2965. */
  2966. set bsValue(value) {
  2967. if (this._bsValue === value) {
  2968. return;
  2969. }
  2970. this._bsValue = value;
  2971. this.bsValueChange.emit(value);
  2972. }
  2973. /**
  2974. * @return {?}
  2975. */
  2976. ngOnInit() {
  2977. this._datepicker.listen({
  2978. outsideClick: this.outsideClick,
  2979. outsideEsc: this.outsideEsc,
  2980. triggers: this.triggers,
  2981. show: (/**
  2982. * @return {?}
  2983. */
  2984. () => this.show())
  2985. });
  2986. this.setConfig();
  2987. }
  2988. /**
  2989. * @param {?} changes
  2990. * @return {?}
  2991. */
  2992. ngOnChanges(changes) {
  2993. if (!this._datepickerRef || !this._datepickerRef.instance) {
  2994. return;
  2995. }
  2996. if (changes.minDate) {
  2997. this._datepickerRef.instance.minDate = this.minDate;
  2998. }
  2999. if (changes.maxDate) {
  3000. this._datepickerRef.instance.maxDate = this.maxDate;
  3001. }
  3002. if (changes.datesDisabled) {
  3003. this._datepickerRef.instance.datesDisabled = this.datesDisabled;
  3004. }
  3005. if (changes.isDisabled) {
  3006. this._datepickerRef.instance.isDisabled = this.isDisabled;
  3007. }
  3008. if (changes.dateCustomClasses) {
  3009. this._datepickerRef.instance.dateCustomClasses = this.dateCustomClasses;
  3010. }
  3011. }
  3012. /**
  3013. * Opens an element’s datepicker. This is considered a “manual” triggering of
  3014. * the datepicker.
  3015. * @return {?}
  3016. */
  3017. show() {
  3018. if (this._datepicker.isShown) {
  3019. return;
  3020. }
  3021. this.setConfig();
  3022. this._datepickerRef = this._datepicker
  3023. .provide({ provide: BsDatepickerConfig, useValue: this._config })
  3024. .attach(BsDaterangepickerContainerComponent)
  3025. .to(this.container)
  3026. .position({ attachment: this.placement })
  3027. .show({ placement: this.placement });
  3028. // if date changes from external source (model -> view)
  3029. this._subs.push(this.bsValueChange.subscribe((/**
  3030. * @param {?} value
  3031. * @return {?}
  3032. */
  3033. (value) => {
  3034. this._datepickerRef.instance.value = value;
  3035. })));
  3036. // if date changes from picker (view -> model)
  3037. this._subs.push(this._datepickerRef.instance.valueChange
  3038. .pipe(filter((/**
  3039. * @param {?} range
  3040. * @return {?}
  3041. */
  3042. (range) => range && range[0] && !!range[1])))
  3043. .subscribe((/**
  3044. * @param {?} value
  3045. * @return {?}
  3046. */
  3047. (value) => {
  3048. this.bsValue = value;
  3049. this.hide();
  3050. })));
  3051. }
  3052. /**
  3053. * Set config for daterangepicker
  3054. * @return {?}
  3055. */
  3056. setConfig() {
  3057. this._config = Object.assign({}, this._config, this.bsConfig, {
  3058. value: this._bsValue,
  3059. isDisabled: this.isDisabled,
  3060. minDate: this.minDate || this.bsConfig && this.bsConfig.minDate,
  3061. maxDate: this.maxDate || this.bsConfig && this.bsConfig.maxDate,
  3062. dateCustomClasses: this.dateCustomClasses || this.bsConfig && this.bsConfig.dateCustomClasses,
  3063. datesDisabled: this.datesDisabled || this.bsConfig && this.bsConfig.datesDisabled
  3064. });
  3065. }
  3066. /**
  3067. * Closes an element’s datepicker. This is considered a “manual” triggering of
  3068. * the datepicker.
  3069. * @return {?}
  3070. */
  3071. hide() {
  3072. if (this.isOpen) {
  3073. this._datepicker.hide();
  3074. }
  3075. for (const sub of this._subs) {
  3076. sub.unsubscribe();
  3077. }
  3078. }
  3079. /**
  3080. * Toggles an element’s datepicker. This is considered a “manual” triggering
  3081. * of the datepicker.
  3082. * @return {?}
  3083. */
  3084. toggle() {
  3085. if (this.isOpen) {
  3086. return this.hide();
  3087. }
  3088. this.show();
  3089. }
  3090. /**
  3091. * @return {?}
  3092. */
  3093. ngOnDestroy() {
  3094. this._datepicker.dispose();
  3095. }
  3096. }
  3097. BsDaterangepickerDirective.decorators = [
  3098. { type: Directive, args: [{
  3099. selector: '[bsDaterangepicker]',
  3100. exportAs: 'bsDaterangepicker'
  3101. },] }
  3102. ];
  3103. /** @nocollapse */
  3104. BsDaterangepickerDirective.ctorParameters = () => [
  3105. { type: BsDaterangepickerConfig },
  3106. { type: ElementRef },
  3107. { type: Renderer2 },
  3108. { type: ViewContainerRef },
  3109. { type: ComponentLoaderFactory }
  3110. ];
  3111. BsDaterangepickerDirective.propDecorators = {
  3112. placement: [{ type: Input }],
  3113. triggers: [{ type: Input }],
  3114. outsideClick: [{ type: Input }],
  3115. container: [{ type: Input }],
  3116. outsideEsc: [{ type: Input }],
  3117. isOpen: [{ type: Input }],
  3118. onShown: [{ type: Output }],
  3119. onHidden: [{ type: Output }],
  3120. bsValue: [{ type: Input }],
  3121. bsConfig: [{ type: Input }],
  3122. isDisabled: [{ type: Input }],
  3123. minDate: [{ type: Input }],
  3124. maxDate: [{ type: Input }],
  3125. dateCustomClasses: [{ type: Input }],
  3126. datesDisabled: [{ type: Input }],
  3127. bsValueChange: [{ type: Output }]
  3128. };
  3129. /**
  3130. * @fileoverview added by tsickle
  3131. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3132. */
  3133. /** @type {?} */
  3134. const BS_DATERANGEPICKER_VALUE_ACCESSOR = {
  3135. provide: NG_VALUE_ACCESSOR,
  3136. /* tslint:disable-next-line: no-use-before-declare */
  3137. useExisting: forwardRef((/**
  3138. * @return {?}
  3139. */
  3140. () => BsDaterangepickerInputDirective)),
  3141. multi: true
  3142. };
  3143. /** @type {?} */
  3144. const BS_DATERANGEPICKER_VALIDATOR = {
  3145. provide: NG_VALIDATORS,
  3146. /* tslint:disable-next-line: no-use-before-declare */
  3147. useExisting: forwardRef((/**
  3148. * @return {?}
  3149. */
  3150. () => BsDaterangepickerInputDirective)),
  3151. multi: true
  3152. };
  3153. class BsDaterangepickerInputDirective {
  3154. /**
  3155. * @param {?} _picker
  3156. * @param {?} _localeService
  3157. * @param {?} _renderer
  3158. * @param {?} _elRef
  3159. * @param {?} changeDetection
  3160. */
  3161. constructor(_picker, _localeService, _renderer, _elRef, changeDetection) {
  3162. this._picker = _picker;
  3163. this._localeService = _localeService;
  3164. this._renderer = _renderer;
  3165. this._elRef = _elRef;
  3166. this.changeDetection = changeDetection;
  3167. this._onChange = Function.prototype;
  3168. this._onTouched = Function.prototype;
  3169. /* tslint:disable-next-line: no-unused-variable */
  3170. this._validatorChange = Function.prototype;
  3171. // update input value on datepicker value update
  3172. this._picker.bsValueChange.subscribe((/**
  3173. * @param {?} value
  3174. * @return {?}
  3175. */
  3176. (value) => {
  3177. this._setInputValue(value);
  3178. if (this._value !== value) {
  3179. this._value = value;
  3180. this._onChange(value);
  3181. this._onTouched();
  3182. }
  3183. this.changeDetection.markForCheck();
  3184. }));
  3185. // update input value on locale change
  3186. this._localeService.localeChange.subscribe((/**
  3187. * @return {?}
  3188. */
  3189. () => {
  3190. this._setInputValue(this._value);
  3191. }));
  3192. }
  3193. /**
  3194. * @param {?} date
  3195. * @return {?}
  3196. */
  3197. _setInputValue(date) {
  3198. /** @type {?} */
  3199. let range = '';
  3200. if (date) {
  3201. /** @type {?} */
  3202. const start = !date[0] ? ''
  3203. : formatDate(date[0], this._picker._config.rangeInputFormat, this._localeService.currentLocale);
  3204. /** @type {?} */
  3205. const end = !date[1] ? ''
  3206. : formatDate(date[1], this._picker._config.rangeInputFormat, this._localeService.currentLocale);
  3207. range = (start && end) ? start + this._picker._config.rangeSeparator + end : '';
  3208. }
  3209. this._renderer.setProperty(this._elRef.nativeElement, 'value', range);
  3210. }
  3211. /**
  3212. * @param {?} event
  3213. * @return {?}
  3214. */
  3215. onChange(event) {
  3216. /* tslint:disable-next-line: no-any*/
  3217. this.writeValue(((/** @type {?} */ (event.target))).value);
  3218. this._onChange(this._value);
  3219. this._onTouched();
  3220. }
  3221. /**
  3222. * @param {?} c
  3223. * @return {?}
  3224. */
  3225. validate(c) {
  3226. /** @type {?} */
  3227. const _value = c.value;
  3228. if (_value === null || _value === undefined || !isArray(_value)) {
  3229. return null;
  3230. }
  3231. /** @type {?} */
  3232. const _isFirstDateValid = isDateValid(_value[0]);
  3233. /** @type {?} */
  3234. const _isSecondDateValid = isDateValid(_value[1]);
  3235. if (!_isFirstDateValid) {
  3236. return { bsDate: { invalid: _value[0] } };
  3237. }
  3238. if (!_isSecondDateValid) {
  3239. return { bsDate: { invalid: _value[1] } };
  3240. }
  3241. if (this._picker && this._picker.minDate && isBefore(_value[0], this._picker.minDate, 'date')) {
  3242. return { bsDate: { minDate: this._picker.minDate } };
  3243. }
  3244. if (this._picker && this._picker.maxDate && isAfter(_value[1], this._picker.maxDate, 'date')) {
  3245. return { bsDate: { maxDate: this._picker.maxDate } };
  3246. }
  3247. }
  3248. /**
  3249. * @param {?} fn
  3250. * @return {?}
  3251. */
  3252. registerOnValidatorChange(fn) {
  3253. this._validatorChange = fn;
  3254. }
  3255. /**
  3256. * @param {?} value
  3257. * @return {?}
  3258. */
  3259. writeValue(value) {
  3260. if (!value) {
  3261. this._value = null;
  3262. }
  3263. else {
  3264. /** @type {?} */
  3265. const _localeKey = this._localeService.currentLocale;
  3266. /** @type {?} */
  3267. const _locale = getLocale(_localeKey);
  3268. if (!_locale) {
  3269. throw new Error(`Locale "${_localeKey}" is not defined, please add it with "defineLocale(...)"`);
  3270. }
  3271. /** @type {?} */
  3272. let _input = [];
  3273. if (typeof value === 'string') {
  3274. _input = value.split(this._picker._config.rangeSeparator);
  3275. }
  3276. if (Array.isArray(value)) {
  3277. _input = value;
  3278. }
  3279. this._value = ((/** @type {?} */ (_input)))
  3280. .map((/**
  3281. * @param {?} _val
  3282. * @return {?}
  3283. */
  3284. (_val) => {
  3285. if (this._picker._config.useUtc) {
  3286. return utcAsLocal(parseDate(_val, this._picker._config.dateInputFormat, this._localeService.currentLocale));
  3287. }
  3288. return parseDate(_val, this._picker._config.dateInputFormat, this._localeService.currentLocale);
  3289. }))
  3290. .map((/**
  3291. * @param {?} date
  3292. * @return {?}
  3293. */
  3294. (date) => (isNaN(date.valueOf()) ? null : date)));
  3295. }
  3296. this._picker.bsValue = this._value;
  3297. }
  3298. /**
  3299. * @param {?} isDisabled
  3300. * @return {?}
  3301. */
  3302. setDisabledState(isDisabled) {
  3303. this._picker.isDisabled = isDisabled;
  3304. if (isDisabled) {
  3305. this._renderer.setAttribute(this._elRef.nativeElement, 'disabled', 'disabled');
  3306. return;
  3307. }
  3308. this._renderer.removeAttribute(this._elRef.nativeElement, 'disabled');
  3309. }
  3310. /* tslint:disable-next-line: no-any*/
  3311. /**
  3312. * @param {?} fn
  3313. * @return {?}
  3314. */
  3315. registerOnChange(fn) {
  3316. this._onChange = fn;
  3317. }
  3318. /* tslint:disable-next-line: no-any*/
  3319. /**
  3320. * @param {?} fn
  3321. * @return {?}
  3322. */
  3323. registerOnTouched(fn) {
  3324. this._onTouched = fn;
  3325. }
  3326. /**
  3327. * @return {?}
  3328. */
  3329. onBlur() {
  3330. this._onTouched();
  3331. }
  3332. /**
  3333. * @return {?}
  3334. */
  3335. hide() {
  3336. this._picker.hide();
  3337. this._renderer.selectRootElement(this._elRef.nativeElement).blur();
  3338. }
  3339. }
  3340. BsDaterangepickerInputDirective.decorators = [
  3341. { type: Directive, args: [{
  3342. selector: `input[bsDaterangepicker]`,
  3343. host: {
  3344. '(change)': 'onChange($event)',
  3345. '(keyup.esc)': 'hide()',
  3346. '(blur)': 'onBlur()'
  3347. },
  3348. providers: [BS_DATERANGEPICKER_VALUE_ACCESSOR, BS_DATERANGEPICKER_VALIDATOR]
  3349. },] }
  3350. ];
  3351. /** @nocollapse */
  3352. BsDaterangepickerInputDirective.ctorParameters = () => [
  3353. { type: BsDaterangepickerDirective, decorators: [{ type: Host }] },
  3354. { type: BsLocaleService },
  3355. { type: Renderer2 },
  3356. { type: ElementRef },
  3357. { type: ChangeDetectorRef }
  3358. ];
  3359. /**
  3360. * @fileoverview added by tsickle
  3361. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3362. */
  3363. class BsCalendarLayoutComponent {
  3364. }
  3365. BsCalendarLayoutComponent.decorators = [
  3366. { type: Component, args: [{
  3367. selector: 'bs-calendar-layout',
  3368. template: `
  3369. <!-- current date, will be added in nearest releases -->
  3370. <bs-current-date title="hey there" *ngIf="false"></bs-current-date>
  3371. <!--navigation-->
  3372. <div class="bs-datepicker-head">
  3373. <ng-content select="bs-datepicker-navigation-view"></ng-content>
  3374. </div>
  3375. <div class="bs-datepicker-body">
  3376. <ng-content></ng-content>
  3377. </div>
  3378. <!--timepicker-->
  3379. <bs-timepicker *ngIf="false"></bs-timepicker>
  3380. `
  3381. }] }
  3382. ];
  3383. /**
  3384. * @fileoverview added by tsickle
  3385. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3386. */
  3387. class BsCurrentDateViewComponent {
  3388. }
  3389. BsCurrentDateViewComponent.decorators = [
  3390. { type: Component, args: [{
  3391. selector: 'bs-current-date',
  3392. template: `<div class="current-timedate"><span>{{ title }}</span></div>`
  3393. }] }
  3394. ];
  3395. BsCurrentDateViewComponent.propDecorators = {
  3396. title: [{ type: Input }]
  3397. };
  3398. /**
  3399. * @fileoverview added by tsickle
  3400. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3401. */
  3402. class BsCustomDatesViewComponent {
  3403. }
  3404. BsCustomDatesViewComponent.decorators = [
  3405. { type: Component, args: [{
  3406. selector: 'bs-custom-date-view',
  3407. template: `
  3408. <div class="bs-datepicker-predefined-btns">
  3409. <button *ngFor="let range of ranges" type="button">{{ range.label }}</button>
  3410. <button *ngIf="isCustomRangeShown" type="button">Custom Range</button>
  3411. </div>
  3412. `,
  3413. changeDetection: ChangeDetectionStrategy.OnPush
  3414. }] }
  3415. ];
  3416. BsCustomDatesViewComponent.propDecorators = {
  3417. isCustomRangeShown: [{ type: Input }],
  3418. ranges: [{ type: Input }]
  3419. };
  3420. /**
  3421. * @fileoverview added by tsickle
  3422. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3423. */
  3424. class BsDatepickerDayDecoratorComponent {
  3425. /**
  3426. * @param {?} _config
  3427. * @param {?} _elRef
  3428. * @param {?} _renderer
  3429. */
  3430. constructor(_config, _elRef, _renderer) {
  3431. this._config = _config;
  3432. this._elRef = _elRef;
  3433. this._renderer = _renderer;
  3434. }
  3435. /**
  3436. * @return {?}
  3437. */
  3438. ngOnInit() {
  3439. if (this.day.isToday && this._config && this._config.customTodayClass) {
  3440. this._renderer.addClass(this._elRef.nativeElement, this._config.customTodayClass);
  3441. }
  3442. if (typeof this.day.customClasses === 'string') {
  3443. this.day.customClasses.split(' ')
  3444. .filter((/**
  3445. * @param {?} className
  3446. * @return {?}
  3447. */
  3448. (className) => className))
  3449. .forEach((/**
  3450. * @param {?} className
  3451. * @return {?}
  3452. */
  3453. (className) => {
  3454. this._renderer.addClass(this._elRef.nativeElement, className);
  3455. }));
  3456. }
  3457. }
  3458. }
  3459. BsDatepickerDayDecoratorComponent.decorators = [
  3460. { type: Component, args: [{
  3461. selector: '[bsDatepickerDayDecorator]',
  3462. changeDetection: ChangeDetectionStrategy.OnPush,
  3463. host: {
  3464. '[class.disabled]': 'day.isDisabled',
  3465. '[class.is-highlighted]': 'day.isHovered',
  3466. '[class.is-other-month]': 'day.isOtherMonth',
  3467. '[class.is-active-other-month]': 'day.isOtherMonthHovered',
  3468. '[class.in-range]': 'day.isInRange',
  3469. '[class.select-start]': 'day.isSelectionStart',
  3470. '[class.select-end]': 'day.isSelectionEnd',
  3471. '[class.selected]': 'day.isSelected'
  3472. },
  3473. template: `{{ day.label }}`
  3474. }] }
  3475. ];
  3476. /** @nocollapse */
  3477. BsDatepickerDayDecoratorComponent.ctorParameters = () => [
  3478. { type: BsDatepickerConfig },
  3479. { type: ElementRef },
  3480. { type: Renderer2 }
  3481. ];
  3482. BsDatepickerDayDecoratorComponent.propDecorators = {
  3483. day: [{ type: Input }]
  3484. };
  3485. /**
  3486. * @fileoverview added by tsickle
  3487. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3488. */
  3489. /** @enum {number} */
  3490. const BsNavigationDirection = {
  3491. UP: 0,
  3492. DOWN: 1,
  3493. };
  3494. BsNavigationDirection[BsNavigationDirection.UP] = 'UP';
  3495. BsNavigationDirection[BsNavigationDirection.DOWN] = 'DOWN';
  3496. /**
  3497. * @fileoverview added by tsickle
  3498. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3499. */
  3500. class BsDatepickerNavigationViewComponent {
  3501. constructor() {
  3502. this.onNavigate = new EventEmitter();
  3503. this.onViewMode = new EventEmitter();
  3504. }
  3505. /**
  3506. * @param {?} down
  3507. * @return {?}
  3508. */
  3509. navTo(down) {
  3510. this.onNavigate.emit(down ? BsNavigationDirection.DOWN : BsNavigationDirection.UP);
  3511. }
  3512. /**
  3513. * @param {?} viewMode
  3514. * @return {?}
  3515. */
  3516. view(viewMode) {
  3517. this.onViewMode.emit(viewMode);
  3518. }
  3519. }
  3520. BsDatepickerNavigationViewComponent.decorators = [
  3521. { type: Component, args: [{
  3522. selector: 'bs-datepicker-navigation-view',
  3523. changeDetection: ChangeDetectionStrategy.OnPush,
  3524. template: `
  3525. <button class="previous"
  3526. [disabled]="calendar.disableLeftArrow"
  3527. [style.visibility]="calendar.hideLeftArrow ? 'hidden' : 'visible'"
  3528. type="button"
  3529. (click)="navTo(true)">
  3530. <span>&lsaquo;</span>
  3531. </button>
  3532. &#8203; <!-- zero-width space needed for correct alignement
  3533. with preserveWhitespaces: false in Angular -->
  3534. <button class="current"
  3535. *ngIf="calendar.monthTitle"
  3536. type="button"
  3537. (click)="view('month')">
  3538. <span>{{ calendar.monthTitle }}</span>
  3539. </button>
  3540. &#8203; <!-- zero-width space needed for correct alignement
  3541. with preserveWhitespaces: false in Angular -->
  3542. <button class="current" (click)="view('year')" type="button">
  3543. <span>{{ calendar.yearTitle }}</span>
  3544. </button>
  3545. &#8203; <!-- zero-width space needed for correct alignement
  3546. with preserveWhitespaces: false in Angular -->
  3547. <button class="next"
  3548. [disabled]="calendar.disableRightArrow"
  3549. [style.visibility]="calendar.hideRightArrow ? 'hidden' : 'visible'"
  3550. type="button"
  3551. (click)="navTo(false)"><span>&rsaquo;</span>
  3552. </button>
  3553. `
  3554. }] }
  3555. ];
  3556. BsDatepickerNavigationViewComponent.propDecorators = {
  3557. calendar: [{ type: Input }],
  3558. onNavigate: [{ type: Output }],
  3559. onViewMode: [{ type: Output }]
  3560. };
  3561. /**
  3562. * @fileoverview added by tsickle
  3563. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3564. */
  3565. class BsDaysCalendarViewComponent {
  3566. /**
  3567. * @param {?} _config
  3568. */
  3569. constructor(_config) {
  3570. this._config = _config;
  3571. this.onNavigate = new EventEmitter();
  3572. this.onViewMode = new EventEmitter();
  3573. this.onSelect = new EventEmitter();
  3574. this.onHover = new EventEmitter();
  3575. this.onHoverWeek = new EventEmitter();
  3576. }
  3577. /**
  3578. * @param {?} event
  3579. * @return {?}
  3580. */
  3581. navigateTo(event) {
  3582. /** @type {?} */
  3583. const step = BsNavigationDirection.DOWN === event ? -1 : 1;
  3584. this.onNavigate.emit({ step: { month: step } });
  3585. }
  3586. /**
  3587. * @param {?} event
  3588. * @return {?}
  3589. */
  3590. changeViewMode(event) {
  3591. this.onViewMode.emit(event);
  3592. }
  3593. /**
  3594. * @param {?} event
  3595. * @return {?}
  3596. */
  3597. selectDay(event) {
  3598. this.onSelect.emit(event);
  3599. }
  3600. /**
  3601. * @param {?} week
  3602. * @return {?}
  3603. */
  3604. selectWeek(week) {
  3605. if (!this._config.selectWeek) {
  3606. return;
  3607. }
  3608. if (week.days
  3609. && week.days[0]
  3610. && !week.days[0].isDisabled
  3611. && this._config.selectFromOtherMonth) {
  3612. this.onSelect.emit(week.days[0]);
  3613. return;
  3614. }
  3615. if (week.days.length === 0) {
  3616. return;
  3617. }
  3618. /** @type {?} */
  3619. const selectedDay = week.days.find((/**
  3620. * @param {?} day
  3621. * @return {?}
  3622. */
  3623. (day) => {
  3624. return this._config.selectFromOtherMonth
  3625. ? !day.isDisabled
  3626. : !day.isOtherMonth && !day.isDisabled;
  3627. }));
  3628. this.onSelect.emit(selectedDay);
  3629. }
  3630. /**
  3631. * @param {?} cell
  3632. * @param {?} isHovered
  3633. * @return {?}
  3634. */
  3635. weekHoverHandler(cell, isHovered) {
  3636. if (!this._config.selectWeek) {
  3637. return;
  3638. }
  3639. /** @type {?} */
  3640. const hasActiveDays = cell.days.find((/**
  3641. * @param {?} day
  3642. * @return {?}
  3643. */
  3644. (day) => {
  3645. return this._config.selectFromOtherMonth
  3646. ? !day.isDisabled
  3647. : !day.isOtherMonth && !day.isDisabled;
  3648. }));
  3649. if (hasActiveDays) {
  3650. cell.isHovered = isHovered;
  3651. this.isWeekHovered = isHovered;
  3652. this.onHoverWeek.emit(cell);
  3653. }
  3654. }
  3655. /**
  3656. * @param {?} cell
  3657. * @param {?} isHovered
  3658. * @return {?}
  3659. */
  3660. hoverDay(cell, isHovered) {
  3661. if (this._config.selectFromOtherMonth && cell.isOtherMonth) {
  3662. cell.isOtherMonthHovered = isHovered;
  3663. }
  3664. this.onHover.emit({ cell, isHovered });
  3665. }
  3666. }
  3667. BsDaysCalendarViewComponent.decorators = [
  3668. { type: Component, args: [{
  3669. selector: 'bs-days-calendar-view',
  3670. // changeDetection: ChangeDetectionStrategy.OnPush,
  3671. template: `
  3672. <bs-calendar-layout>
  3673. <bs-datepicker-navigation-view
  3674. [calendar]="calendar"
  3675. (onNavigate)="navigateTo($event)"
  3676. (onViewMode)="changeViewMode($event)"
  3677. ></bs-datepicker-navigation-view>
  3678. <!--days matrix-->
  3679. <table role="grid" class="days weeks">
  3680. <thead>
  3681. <tr>
  3682. <!--if show weeks-->
  3683. <th *ngIf="options.showWeekNumbers"></th>
  3684. <th *ngFor="let weekday of calendar.weekdays; let i = index"
  3685. aria-label="weekday">{{ calendar.weekdays[i] }}
  3686. </th>
  3687. </tr>
  3688. </thead>
  3689. <tbody>
  3690. <tr *ngFor="let week of calendar.weeks; let i = index">
  3691. <td class="week" [class.active-week]="isWeekHovered" *ngIf="options.showWeekNumbers">
  3692. <span
  3693. (click)="selectWeek(week)"
  3694. (mouseenter)="weekHoverHandler(week, true)"
  3695. (mouseleave)="weekHoverHandler(week, false)">{{ calendar.weekNumbers[i] }}</span>
  3696. </td>
  3697. <td *ngFor="let day of week.days" role="gridcell">
  3698. <span bsDatepickerDayDecorator
  3699. [day]="day"
  3700. (click)="selectDay(day)"
  3701. (mouseenter)="hoverDay(day, true)"
  3702. (mouseleave)="hoverDay(day, false)">{{ day.label }}</span>
  3703. </td>
  3704. </tr>
  3705. </tbody>
  3706. </table>
  3707. </bs-calendar-layout>
  3708. `
  3709. }] }
  3710. ];
  3711. /** @nocollapse */
  3712. BsDaysCalendarViewComponent.ctorParameters = () => [
  3713. { type: BsDatepickerConfig }
  3714. ];
  3715. BsDaysCalendarViewComponent.propDecorators = {
  3716. calendar: [{ type: Input }],
  3717. options: [{ type: Input }],
  3718. onNavigate: [{ type: Output }],
  3719. onViewMode: [{ type: Output }],
  3720. onSelect: [{ type: Output }],
  3721. onHover: [{ type: Output }],
  3722. onHoverWeek: [{ type: Output }]
  3723. };
  3724. /**
  3725. * @fileoverview added by tsickle
  3726. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3727. */
  3728. class BsMonthCalendarViewComponent {
  3729. constructor() {
  3730. this.onNavigate = new EventEmitter();
  3731. this.onViewMode = new EventEmitter();
  3732. this.onSelect = new EventEmitter();
  3733. this.onHover = new EventEmitter();
  3734. }
  3735. /**
  3736. * @param {?} event
  3737. * @return {?}
  3738. */
  3739. navigateTo(event) {
  3740. /** @type {?} */
  3741. const step = BsNavigationDirection.DOWN === event ? -1 : 1;
  3742. this.onNavigate.emit({ step: { year: step } });
  3743. }
  3744. /**
  3745. * @param {?} month
  3746. * @return {?}
  3747. */
  3748. viewMonth(month) {
  3749. this.onSelect.emit(month);
  3750. }
  3751. /**
  3752. * @param {?} cell
  3753. * @param {?} isHovered
  3754. * @return {?}
  3755. */
  3756. hoverMonth(cell, isHovered) {
  3757. this.onHover.emit({ cell, isHovered });
  3758. }
  3759. /**
  3760. * @param {?} event
  3761. * @return {?}
  3762. */
  3763. changeViewMode(event) {
  3764. this.onViewMode.emit(event);
  3765. }
  3766. }
  3767. BsMonthCalendarViewComponent.decorators = [
  3768. { type: Component, args: [{
  3769. selector: 'bs-month-calendar-view',
  3770. template: `
  3771. <bs-calendar-layout>
  3772. <bs-datepicker-navigation-view
  3773. [calendar]="calendar"
  3774. (onNavigate)="navigateTo($event)"
  3775. (onViewMode)="changeViewMode($event)"
  3776. ></bs-datepicker-navigation-view>
  3777. <table role="grid" class="months">
  3778. <tbody>
  3779. <tr *ngFor="let row of calendar.months">
  3780. <td *ngFor="let month of row" role="gridcell"
  3781. (click)="viewMonth(month)"
  3782. (mouseenter)="hoverMonth(month, true)"
  3783. (mouseleave)="hoverMonth(month, false)"
  3784. [class.disabled]="month.isDisabled"
  3785. [class.is-highlighted]="month.isHovered">
  3786. <span [class.selected]="month.isSelected">{{ month.label }}</span>
  3787. </td>
  3788. </tr>
  3789. </tbody>
  3790. </table>
  3791. </bs-calendar-layout>
  3792. `
  3793. }] }
  3794. ];
  3795. BsMonthCalendarViewComponent.propDecorators = {
  3796. calendar: [{ type: Input }],
  3797. onNavigate: [{ type: Output }],
  3798. onViewMode: [{ type: Output }],
  3799. onSelect: [{ type: Output }],
  3800. onHover: [{ type: Output }]
  3801. };
  3802. /**
  3803. * @fileoverview added by tsickle
  3804. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3805. */
  3806. class BsTimepickerViewComponent {
  3807. constructor() {
  3808. this.ampm = 'ok';
  3809. this.hours = 0;
  3810. this.minutes = 0;
  3811. }
  3812. }
  3813. BsTimepickerViewComponent.decorators = [
  3814. { type: Component, args: [{
  3815. selector: 'bs-timepicker',
  3816. template: `
  3817. <div class="bs-timepicker-container">
  3818. <div class="bs-timepicker-controls">
  3819. <button class="bs-decrease" type="button">-</button>
  3820. <input type="text" [value]="hours" placeholder="00">
  3821. <button class="bs-increase" type="button">+</button>
  3822. </div>
  3823. <div class="bs-timepicker-controls">
  3824. <button class="bs-decrease" type="button">-</button>
  3825. <input type="text" [value]="minutes" placeholder="00">
  3826. <button class="bs-increase" type="button">+</button>
  3827. </div>
  3828. <button class="switch-time-format" type="button">{{ ampm }}
  3829. <img
  3830. src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAAKCAYAAABi8KSDAAABSElEQVQYV3XQPUvDUBQG4HNuagtVqc6KgouCv6GIuIntYBLB9hcIQpLStCAIV7DYmpTcRWcXqZio3Vwc/UCc/QEqfgyKGbr0I7nS1EiHeqYzPO/h5SD0jaxUZjmSLCB+OFb+UFINFwASAEAdpu9gaGXVyAHHFQBkHpKHc6a9dzECvADyY9sqlAMsK9W0jzxDXqeytr3mhQckxSji27TJJ5/rPmIpwJJq3HrtduriYOurv1a4i1p5HnhkG9OFymi0ReoO05cGwb+ayv4dysVygjeFmsP05f8wpZQ8fsdvfmuY9zjWSNqUtgYFVnOVReILYoBFzdQI5/GGFzNHhGbeZnopDGU29sZbscgldmC99w35VOATTycIMMcBXIfpSVGzZhA6C8hh00conln6VQ9TGgV32OEAKQC4DrBq7CJwd0ggR7Vq/rPrfgB+C3sGypY5DAAAAABJRU5ErkJggg=="
  3831. alt="">
  3832. </button>
  3833. </div>
  3834. `
  3835. }] }
  3836. ];
  3837. /**
  3838. * @fileoverview added by tsickle
  3839. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3840. */
  3841. class BsYearsCalendarViewComponent {
  3842. constructor() {
  3843. this.onNavigate = new EventEmitter();
  3844. this.onViewMode = new EventEmitter();
  3845. this.onSelect = new EventEmitter();
  3846. this.onHover = new EventEmitter();
  3847. }
  3848. /**
  3849. * @param {?} event
  3850. * @return {?}
  3851. */
  3852. navigateTo(event) {
  3853. /** @type {?} */
  3854. const step = BsNavigationDirection.DOWN === event ? -1 : 1;
  3855. this.onNavigate.emit({ step: { year: step * yearsPerCalendar } });
  3856. }
  3857. /**
  3858. * @param {?} year
  3859. * @return {?}
  3860. */
  3861. viewYear(year) {
  3862. this.onSelect.emit(year);
  3863. }
  3864. /**
  3865. * @param {?} cell
  3866. * @param {?} isHovered
  3867. * @return {?}
  3868. */
  3869. hoverYear(cell, isHovered) {
  3870. this.onHover.emit({ cell, isHovered });
  3871. }
  3872. /**
  3873. * @param {?} event
  3874. * @return {?}
  3875. */
  3876. changeViewMode(event) {
  3877. this.onViewMode.emit(event);
  3878. }
  3879. }
  3880. BsYearsCalendarViewComponent.decorators = [
  3881. { type: Component, args: [{
  3882. selector: 'bs-years-calendar-view',
  3883. template: `
  3884. <bs-calendar-layout>
  3885. <bs-datepicker-navigation-view
  3886. [calendar]="calendar"
  3887. (onNavigate)="navigateTo($event)"
  3888. (onViewMode)="changeViewMode($event)"
  3889. ></bs-datepicker-navigation-view>
  3890. <table role="grid" class="years">
  3891. <tbody>
  3892. <tr *ngFor="let row of calendar.years">
  3893. <td *ngFor="let year of row" role="gridcell"
  3894. (click)="viewYear(year)"
  3895. (mouseenter)="hoverYear(year, true)"
  3896. (mouseleave)="hoverYear(year, false)"
  3897. [class.disabled]="year.isDisabled"
  3898. [class.is-highlighted]="year.isHovered">
  3899. <span [class.selected]="year.isSelected">{{ year.label }}</span>
  3900. </td>
  3901. </tr>
  3902. </tbody>
  3903. </table>
  3904. </bs-calendar-layout>
  3905. `
  3906. }] }
  3907. ];
  3908. BsYearsCalendarViewComponent.propDecorators = {
  3909. calendar: [{ type: Input }],
  3910. onNavigate: [{ type: Output }],
  3911. onViewMode: [{ type: Output }],
  3912. onSelect: [{ type: Output }],
  3913. onHover: [{ type: Output }]
  3914. };
  3915. /**
  3916. * @fileoverview added by tsickle
  3917. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3918. */
  3919. /** @type {?} */
  3920. const _exports = [
  3921. BsDatepickerContainerComponent,
  3922. BsDatepickerDirective,
  3923. BsDatepickerInlineContainerComponent,
  3924. BsDatepickerInlineDirective,
  3925. BsDatepickerInputDirective,
  3926. BsDaterangepickerContainerComponent,
  3927. BsDaterangepickerDirective,
  3928. BsDaterangepickerInlineContainerComponent,
  3929. BsDaterangepickerInlineDirective,
  3930. BsDaterangepickerInputDirective
  3931. ];
  3932. class BsDatepickerModule {
  3933. /**
  3934. * @return {?}
  3935. */
  3936. static forRoot() {
  3937. return {
  3938. ngModule: BsDatepickerModule,
  3939. providers: [
  3940. ComponentLoaderFactory,
  3941. PositioningService,
  3942. BsDatepickerStore,
  3943. BsDatepickerActions,
  3944. BsDatepickerConfig,
  3945. BsDaterangepickerConfig,
  3946. BsDatepickerInlineConfig,
  3947. BsDaterangepickerInlineConfig,
  3948. BsDatepickerEffects,
  3949. BsLocaleService
  3950. ]
  3951. };
  3952. }
  3953. }
  3954. BsDatepickerModule.decorators = [
  3955. { type: NgModule, args: [{
  3956. imports: [CommonModule],
  3957. declarations: [
  3958. BsCalendarLayoutComponent,
  3959. BsCurrentDateViewComponent,
  3960. BsCustomDatesViewComponent,
  3961. BsDatepickerDayDecoratorComponent,
  3962. BsDatepickerNavigationViewComponent,
  3963. BsDaysCalendarViewComponent,
  3964. BsMonthCalendarViewComponent,
  3965. BsTimepickerViewComponent,
  3966. BsYearsCalendarViewComponent,
  3967. ..._exports
  3968. ],
  3969. entryComponents: [
  3970. BsDatepickerContainerComponent,
  3971. BsDaterangepickerContainerComponent,
  3972. BsDatepickerInlineContainerComponent,
  3973. BsDaterangepickerInlineContainerComponent
  3974. ],
  3975. exports: _exports
  3976. },] }
  3977. ];
  3978. /**
  3979. * @fileoverview added by tsickle
  3980. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3981. */
  3982. class DateFormatter {
  3983. /**
  3984. * @param {?} date
  3985. * @param {?} format
  3986. * @param {?} locale
  3987. * @return {?}
  3988. */
  3989. format(date, format, locale) {
  3990. return formatDate(date, format, locale);
  3991. }
  3992. }
  3993. /**
  3994. * @fileoverview added by tsickle
  3995. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  3996. */
  3997. class DatePickerInnerComponent {
  3998. constructor() {
  3999. this.selectionDone = new EventEmitter(undefined);
  4000. this.update = new EventEmitter(false);
  4001. this.activeDateChange = new EventEmitter(undefined);
  4002. /* tslint:disable-next-line: no-any*/
  4003. this.stepDay = {};
  4004. /* tslint:disable-next-line: no-any*/
  4005. this.stepMonth = {};
  4006. /* tslint:disable-next-line: no-any*/
  4007. this.stepYear = {};
  4008. this.modes = ['day', 'month', 'year'];
  4009. this.dateFormatter = new DateFormatter();
  4010. }
  4011. /**
  4012. * @return {?}
  4013. */
  4014. get activeDate() {
  4015. return this._activeDate;
  4016. }
  4017. /**
  4018. * @param {?} value
  4019. * @return {?}
  4020. */
  4021. set activeDate(value) {
  4022. this._activeDate = value;
  4023. }
  4024. // todo: add formatter value to Date object
  4025. /**
  4026. * @return {?}
  4027. */
  4028. ngOnInit() {
  4029. // todo: use date for unique value
  4030. this.uniqueId = `datepicker--${Math.floor(Math.random() * 10000)}`;
  4031. if (this.initDate) {
  4032. this.activeDate = this.initDate;
  4033. this.selectedDate = new Date(this.activeDate.valueOf());
  4034. this.update.emit(this.activeDate);
  4035. }
  4036. else if (this.activeDate === undefined) {
  4037. this.activeDate = new Date();
  4038. }
  4039. }
  4040. // this.refreshView should be called here to reflect the changes on the fly
  4041. // tslint:disable-next-line:no-unused-variable
  4042. /**
  4043. * @param {?} changes
  4044. * @return {?}
  4045. */
  4046. ngOnChanges(changes) {
  4047. this.refreshView();
  4048. this.checkIfActiveDateGotUpdated(changes.activeDate);
  4049. }
  4050. // Check if activeDate has been update and then emit the activeDateChange with the new date
  4051. /* tslint:disable-next-line: no-any */
  4052. /**
  4053. * @param {?} activeDate
  4054. * @return {?}
  4055. */
  4056. checkIfActiveDateGotUpdated(activeDate) {
  4057. if (activeDate && !activeDate.firstChange) {
  4058. /** @type {?} */
  4059. const previousValue = activeDate.previousValue;
  4060. if (previousValue &&
  4061. previousValue instanceof Date &&
  4062. previousValue.getTime() !== activeDate.currentValue.getTime()) {
  4063. this.activeDateChange.emit(this.activeDate);
  4064. }
  4065. }
  4066. }
  4067. /**
  4068. * @param {?} handler
  4069. * @param {?} type
  4070. * @return {?}
  4071. */
  4072. setCompareHandler(handler, type) {
  4073. if (type === 'day') {
  4074. this.compareHandlerDay = handler;
  4075. }
  4076. if (type === 'month') {
  4077. this.compareHandlerMonth = handler;
  4078. }
  4079. if (type === 'year') {
  4080. this.compareHandlerYear = handler;
  4081. }
  4082. }
  4083. /**
  4084. * @param {?} date1
  4085. * @param {?} date2
  4086. * @return {?}
  4087. */
  4088. compare(date1, date2) {
  4089. if (date1 === undefined || date2 === undefined) {
  4090. return undefined;
  4091. }
  4092. if (this.datepickerMode === 'day' && this.compareHandlerDay) {
  4093. return this.compareHandlerDay(date1, date2);
  4094. }
  4095. if (this.datepickerMode === 'month' && this.compareHandlerMonth) {
  4096. return this.compareHandlerMonth(date1, date2);
  4097. }
  4098. if (this.datepickerMode === 'year' && this.compareHandlerYear) {
  4099. return this.compareHandlerYear(date1, date2);
  4100. }
  4101. return void 0;
  4102. }
  4103. /**
  4104. * @param {?} handler
  4105. * @param {?} type
  4106. * @return {?}
  4107. */
  4108. setRefreshViewHandler(handler, type) {
  4109. if (type === 'day') {
  4110. this.refreshViewHandlerDay = handler;
  4111. }
  4112. if (type === 'month') {
  4113. this.refreshViewHandlerMonth = handler;
  4114. }
  4115. if (type === 'year') {
  4116. this.refreshViewHandlerYear = handler;
  4117. }
  4118. }
  4119. /**
  4120. * @return {?}
  4121. */
  4122. refreshView() {
  4123. if (this.datepickerMode === 'day' && this.refreshViewHandlerDay) {
  4124. this.refreshViewHandlerDay();
  4125. }
  4126. if (this.datepickerMode === 'month' && this.refreshViewHandlerMonth) {
  4127. this.refreshViewHandlerMonth();
  4128. }
  4129. if (this.datepickerMode === 'year' && this.refreshViewHandlerYear) {
  4130. this.refreshViewHandlerYear();
  4131. }
  4132. }
  4133. /**
  4134. * @param {?} date
  4135. * @param {?} format
  4136. * @return {?}
  4137. */
  4138. dateFilter(date, format) {
  4139. return this.dateFormatter.format(date, format, this.locale);
  4140. }
  4141. /* tslint:disable-next-line: no-any*/
  4142. /**
  4143. * @param {?} dateObject
  4144. * @return {?}
  4145. */
  4146. isActive(dateObject) {
  4147. if (this.compare(dateObject.date, this.activeDate) === 0) {
  4148. this.activeDateId = dateObject.uid;
  4149. return true;
  4150. }
  4151. return false;
  4152. }
  4153. /* tslint:disable-next-line: no-any*/
  4154. /**
  4155. * @param {?} date
  4156. * @param {?} format
  4157. * @return {?}
  4158. */
  4159. createDateObject(date, format) {
  4160. /* tslint:disable-next-line: no-any*/
  4161. /** @type {?} */
  4162. const dateObject = {};
  4163. dateObject.date = new Date(date.getFullYear(), date.getMonth(), date.getDate());
  4164. dateObject.date = this.fixTimeZone(dateObject.date);
  4165. dateObject.label = this.dateFilter(date, format);
  4166. dateObject.selected = this.compare(date, this.selectedDate) === 0;
  4167. dateObject.disabled = this.isDisabled(date);
  4168. dateObject.current = this.compare(date, new Date()) === 0;
  4169. dateObject.customClass = this.getCustomClassForDate(dateObject.date);
  4170. return dateObject;
  4171. }
  4172. /* tslint:disable-next-line: no-any*/
  4173. /**
  4174. * @param {?} arr
  4175. * @param {?} size
  4176. * @return {?}
  4177. */
  4178. split(arr, size) {
  4179. /* tslint:disable-next-line: no-any*/
  4180. /** @type {?} */
  4181. const arrays = [];
  4182. while (arr.length > 0) {
  4183. arrays.push(arr.splice(0, size));
  4184. }
  4185. return arrays;
  4186. }
  4187. // Fix a hard-reproducible bug with timezones
  4188. // The bug depends on OS, browser, current timezone and current date
  4189. // i.e.
  4190. // var date = new Date(2014, 0, 1);
  4191. // console.log(date.getFullYear(), date.getMonth(), date.getDate(),
  4192. // date.getHours()); can result in "2013 11 31 23" because of the bug.
  4193. /**
  4194. * @param {?} date
  4195. * @return {?}
  4196. */
  4197. fixTimeZone(date) {
  4198. /** @type {?} */
  4199. const hours = date.getHours();
  4200. return new Date(date.getFullYear(), date.getMonth(), date.getDate(), hours === 23 ? hours + 2 : 0);
  4201. }
  4202. /**
  4203. * @param {?} date
  4204. * @param {?=} isManual
  4205. * @return {?}
  4206. */
  4207. select(date, isManual = true) {
  4208. if (this.datepickerMode === this.minMode) {
  4209. if (!this.activeDate) {
  4210. this.activeDate = new Date(0, 0, 0, 0, 0, 0, 0);
  4211. }
  4212. this.activeDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
  4213. this.activeDate = this.fixTimeZone(this.activeDate);
  4214. if (isManual) {
  4215. this.selectionDone.emit(this.activeDate);
  4216. }
  4217. }
  4218. else {
  4219. this.activeDate = new Date(date.getFullYear(), date.getMonth(), date.getDate());
  4220. this.activeDate = this.fixTimeZone(this.activeDate);
  4221. if (isManual) {
  4222. this.datepickerMode = this.modes[this.modes.indexOf(this.datepickerMode) - 1];
  4223. }
  4224. }
  4225. this.selectedDate = new Date(this.activeDate.valueOf());
  4226. this.update.emit(this.activeDate);
  4227. this.refreshView();
  4228. }
  4229. /**
  4230. * @param {?} direction
  4231. * @return {?}
  4232. */
  4233. move(direction) {
  4234. /* tslint:disable-next-line: no-any*/
  4235. /** @type {?} */
  4236. let expectedStep;
  4237. if (this.datepickerMode === 'day') {
  4238. expectedStep = this.stepDay;
  4239. }
  4240. if (this.datepickerMode === 'month') {
  4241. expectedStep = this.stepMonth;
  4242. }
  4243. if (this.datepickerMode === 'year') {
  4244. expectedStep = this.stepYear;
  4245. }
  4246. if (expectedStep) {
  4247. /** @type {?} */
  4248. const year = this.activeDate.getFullYear() + direction * (expectedStep.years || 0);
  4249. /** @type {?} */
  4250. const month = this.activeDate.getMonth() + direction * (expectedStep.months || 0);
  4251. this.activeDate = new Date(year, month, 1);
  4252. this.refreshView();
  4253. this.activeDateChange.emit(this.activeDate);
  4254. }
  4255. }
  4256. /**
  4257. * @param {?} _direction
  4258. * @return {?}
  4259. */
  4260. toggleMode(_direction) {
  4261. /** @type {?} */
  4262. const direction = _direction || 1;
  4263. if ((this.datepickerMode === this.maxMode && direction === 1) ||
  4264. (this.datepickerMode === this.minMode && direction === -1)) {
  4265. return;
  4266. }
  4267. this.datepickerMode = this.modes[this.modes.indexOf(this.datepickerMode) + direction];
  4268. this.refreshView();
  4269. }
  4270. /**
  4271. * @protected
  4272. * @param {?} date
  4273. * @return {?}
  4274. */
  4275. getCustomClassForDate(date) {
  4276. if (!this.customClass) {
  4277. return '';
  4278. }
  4279. // todo: build a hash of custom classes, it will work faster
  4280. /** @type {?} */
  4281. const customClassObject = this.customClass.find((/**
  4282. * @param {?} customClass
  4283. * @return {?}
  4284. */
  4285. (customClass) => {
  4286. return (customClass.date.valueOf() === date.valueOf() &&
  4287. customClass.mode === this.datepickerMode);
  4288. }), this);
  4289. return customClassObject === undefined ? '' : customClassObject.clazz;
  4290. }
  4291. /**
  4292. * @protected
  4293. * @param {?} date1Disabled
  4294. * @param {?} date2
  4295. * @return {?}
  4296. */
  4297. compareDateDisabled(date1Disabled, date2) {
  4298. if (date1Disabled === undefined || date2 === undefined) {
  4299. return undefined;
  4300. }
  4301. if (date1Disabled.mode === 'day' && this.compareHandlerDay) {
  4302. return this.compareHandlerDay(date1Disabled.date, date2);
  4303. }
  4304. if (date1Disabled.mode === 'month' && this.compareHandlerMonth) {
  4305. return this.compareHandlerMonth(date1Disabled.date, date2);
  4306. }
  4307. if (date1Disabled.mode === 'year' && this.compareHandlerYear) {
  4308. return this.compareHandlerYear(date1Disabled.date, date2);
  4309. }
  4310. return undefined;
  4311. }
  4312. /**
  4313. * @protected
  4314. * @param {?} date
  4315. * @return {?}
  4316. */
  4317. isDisabled(date) {
  4318. /** @type {?} */
  4319. let isDateDisabled = false;
  4320. if (this.dateDisabled) {
  4321. this.dateDisabled.forEach((/**
  4322. * @param {?} disabledDate
  4323. * @return {?}
  4324. */
  4325. (disabledDate) => {
  4326. if (this.compareDateDisabled(disabledDate, date) === 0) {
  4327. isDateDisabled = true;
  4328. }
  4329. }));
  4330. }
  4331. if (this.dayDisabled) {
  4332. isDateDisabled =
  4333. isDateDisabled ||
  4334. this.dayDisabled.indexOf(date.getDay()) > -1;
  4335. }
  4336. return (isDateDisabled ||
  4337. (this.minDate && this.compare(date, this.minDate) < 0) ||
  4338. (this.maxDate && this.compare(date, this.maxDate) > 0));
  4339. }
  4340. }
  4341. DatePickerInnerComponent.decorators = [
  4342. { type: Component, args: [{
  4343. selector: 'datepicker-inner',
  4344. template: `
  4345. <!--&lt;!&ndash;ng-keydown="keydown($event)"&ndash;&gt;-->
  4346. <div *ngIf="datepickerMode" class="well well-sm bg-faded p-a card" role="application" >
  4347. <ng-content></ng-content>
  4348. </div>
  4349. `
  4350. }] }
  4351. ];
  4352. DatePickerInnerComponent.propDecorators = {
  4353. locale: [{ type: Input }],
  4354. datepickerMode: [{ type: Input }],
  4355. startingDay: [{ type: Input }],
  4356. yearRange: [{ type: Input }],
  4357. minDate: [{ type: Input }],
  4358. maxDate: [{ type: Input }],
  4359. minMode: [{ type: Input }],
  4360. maxMode: [{ type: Input }],
  4361. showWeeks: [{ type: Input }],
  4362. formatDay: [{ type: Input }],
  4363. formatMonth: [{ type: Input }],
  4364. formatYear: [{ type: Input }],
  4365. formatDayHeader: [{ type: Input }],
  4366. formatDayTitle: [{ type: Input }],
  4367. formatMonthTitle: [{ type: Input }],
  4368. onlyCurrentMonth: [{ type: Input }],
  4369. shortcutPropagation: [{ type: Input }],
  4370. customClass: [{ type: Input }],
  4371. monthColLimit: [{ type: Input }],
  4372. yearColLimit: [{ type: Input }],
  4373. dateDisabled: [{ type: Input }],
  4374. dayDisabled: [{ type: Input }],
  4375. initDate: [{ type: Input }],
  4376. selectionDone: [{ type: Output }],
  4377. update: [{ type: Output }],
  4378. activeDateChange: [{ type: Output }],
  4379. activeDate: [{ type: Input }]
  4380. };
  4381. /**
  4382. * @fileoverview added by tsickle
  4383. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  4384. */
  4385. class DatepickerConfig {
  4386. constructor() {
  4387. this.locale = 'en';
  4388. this.datepickerMode = 'day';
  4389. this.startingDay = 0;
  4390. this.yearRange = 20;
  4391. this.minMode = 'day';
  4392. this.maxMode = 'year';
  4393. this.showWeeks = true;
  4394. this.formatDay = 'DD';
  4395. this.formatMonth = 'MMMM';
  4396. this.formatYear = 'YYYY';
  4397. this.formatDayHeader = 'dd';
  4398. this.formatDayTitle = 'MMMM YYYY';
  4399. this.formatMonthTitle = 'YYYY';
  4400. this.onlyCurrentMonth = false;
  4401. this.monthColLimit = 3;
  4402. this.yearColLimit = 5;
  4403. this.shortcutPropagation = false;
  4404. }
  4405. }
  4406. DatepickerConfig.decorators = [
  4407. { type: Injectable }
  4408. ];
  4409. /**
  4410. * @fileoverview added by tsickle
  4411. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  4412. */
  4413. /** @type {?} */
  4414. const DATEPICKER_CONTROL_VALUE_ACCESSOR = {
  4415. provide: NG_VALUE_ACCESSOR,
  4416. /* tslint:disable-next-line: no-use-before-declare */
  4417. useExisting: forwardRef((/**
  4418. * @return {?}
  4419. */
  4420. () => DatePickerComponent)),
  4421. multi: true
  4422. };
  4423. /* tslint:disable:component-selector-name component-selector-type */
  4424. /* tslint:enable:component-selector-name component-selector-type */
  4425. class DatePickerComponent {
  4426. /**
  4427. * @param {?} config
  4428. */
  4429. constructor(config) {
  4430. /**
  4431. * sets datepicker mode, supports: `day`, `month`, `year`
  4432. */
  4433. this.datepickerMode = 'day';
  4434. /**
  4435. * if false week numbers will be hidden
  4436. */
  4437. this.showWeeks = true;
  4438. this.selectionDone = new EventEmitter(undefined);
  4439. /**
  4440. * callback to invoke when the activeDate is changed.
  4441. */
  4442. this.activeDateChange = new EventEmitter(undefined);
  4443. /* tslint:disable-next-line: no-any*/
  4444. this.onChange = Function.prototype;
  4445. /* tslint:disable-next-line: no-any*/
  4446. this.onTouched = Function.prototype;
  4447. this._now = new Date();
  4448. this.config = config;
  4449. this.configureOptions();
  4450. }
  4451. /**
  4452. * currently active date
  4453. * @return {?}
  4454. */
  4455. get activeDate() {
  4456. return this._activeDate || this._now;
  4457. }
  4458. /**
  4459. * @param {?} value
  4460. * @return {?}
  4461. */
  4462. set activeDate(value) {
  4463. this._activeDate = value;
  4464. }
  4465. /**
  4466. * @return {?}
  4467. */
  4468. configureOptions() {
  4469. Object.assign(this, this.config);
  4470. }
  4471. /**
  4472. * @param {?} event
  4473. * @return {?}
  4474. */
  4475. onUpdate(event) {
  4476. this.activeDate = event;
  4477. this.onChange(event);
  4478. }
  4479. /**
  4480. * @param {?} event
  4481. * @return {?}
  4482. */
  4483. onSelectionDone(event) {
  4484. this.selectionDone.emit(event);
  4485. }
  4486. /**
  4487. * @param {?} event
  4488. * @return {?}
  4489. */
  4490. onActiveDateChange(event) {
  4491. this.activeDateChange.emit(event);
  4492. }
  4493. // todo: support null value
  4494. /* tslint:disable-next-line: no-any*/
  4495. /**
  4496. * @param {?} value
  4497. * @return {?}
  4498. */
  4499. writeValue(value) {
  4500. if (this._datePicker.compare(value, this._activeDate) === 0) {
  4501. return;
  4502. }
  4503. if (value && value instanceof Date) {
  4504. this.activeDate = value;
  4505. this._datePicker.select(value, false);
  4506. return;
  4507. }
  4508. this.activeDate = value ? new Date(value) : void 0;
  4509. }
  4510. /**
  4511. * @param {?} fn
  4512. * @return {?}
  4513. */
  4514. registerOnChange(fn) {
  4515. this.onChange = fn;
  4516. }
  4517. /**
  4518. * @param {?} fn
  4519. * @return {?}
  4520. */
  4521. registerOnTouched(fn) {
  4522. this.onTouched = fn;
  4523. }
  4524. }
  4525. DatePickerComponent.decorators = [
  4526. { type: Component, args: [{
  4527. selector: 'datepicker',
  4528. template: `
  4529. <datepicker-inner [activeDate]="activeDate"
  4530. (update)="onUpdate($event)"
  4531. [locale]="config.locale"
  4532. [datepickerMode]="datepickerMode"
  4533. [initDate]="initDate"
  4534. [minDate]="minDate"
  4535. [maxDate]="maxDate"
  4536. [minMode]="minMode"
  4537. [maxMode]="maxMode"
  4538. [showWeeks]="showWeeks"
  4539. [formatDay]="formatDay"
  4540. [formatMonth]="formatMonth"
  4541. [formatYear]="formatYear"
  4542. [formatDayHeader]="formatDayHeader"
  4543. [formatDayTitle]="formatDayTitle"
  4544. [formatMonthTitle]="formatMonthTitle"
  4545. [startingDay]="startingDay"
  4546. [yearRange]="yearRange"
  4547. [customClass]="customClass"
  4548. [dateDisabled]="dateDisabled"
  4549. [dayDisabled]="dayDisabled"
  4550. [onlyCurrentMonth]="onlyCurrentMonth"
  4551. [shortcutPropagation]="shortcutPropagation"
  4552. [monthColLimit]="monthColLimit"
  4553. [yearColLimit]="yearColLimit"
  4554. (selectionDone)="onSelectionDone($event)"
  4555. (activeDateChange)="onActiveDateChange($event)">
  4556. <daypicker tabindex="0"></daypicker>
  4557. <monthpicker tabindex="0"></monthpicker>
  4558. <yearpicker tabindex="0"></yearpicker>
  4559. </datepicker-inner>
  4560. `,
  4561. providers: [DATEPICKER_CONTROL_VALUE_ACCESSOR]
  4562. }] }
  4563. ];
  4564. /** @nocollapse */
  4565. DatePickerComponent.ctorParameters = () => [
  4566. { type: DatepickerConfig }
  4567. ];
  4568. DatePickerComponent.propDecorators = {
  4569. datepickerMode: [{ type: Input }],
  4570. initDate: [{ type: Input }],
  4571. minDate: [{ type: Input }],
  4572. maxDate: [{ type: Input }],
  4573. minMode: [{ type: Input }],
  4574. maxMode: [{ type: Input }],
  4575. showWeeks: [{ type: Input }],
  4576. formatDay: [{ type: Input }],
  4577. formatMonth: [{ type: Input }],
  4578. formatYear: [{ type: Input }],
  4579. formatDayHeader: [{ type: Input }],
  4580. formatDayTitle: [{ type: Input }],
  4581. formatMonthTitle: [{ type: Input }],
  4582. startingDay: [{ type: Input }],
  4583. yearRange: [{ type: Input }],
  4584. onlyCurrentMonth: [{ type: Input }],
  4585. shortcutPropagation: [{ type: Input }],
  4586. monthColLimit: [{ type: Input }],
  4587. yearColLimit: [{ type: Input }],
  4588. customClass: [{ type: Input }],
  4589. dateDisabled: [{ type: Input }],
  4590. dayDisabled: [{ type: Input }],
  4591. activeDate: [{ type: Input }],
  4592. selectionDone: [{ type: Output }],
  4593. activeDateChange: [{ type: Output }],
  4594. _datePicker: [{ type: ViewChild, args: [DatePickerInnerComponent, { static: true },] }]
  4595. };
  4596. /**
  4597. * @fileoverview added by tsickle
  4598. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  4599. */
  4600. class DayPickerComponent {
  4601. /**
  4602. * @param {?} datePicker
  4603. */
  4604. constructor(datePicker) {
  4605. this.labels = [];
  4606. this.rows = [];
  4607. this.weekNumbers = [];
  4608. this.datePicker = datePicker;
  4609. }
  4610. /**
  4611. * @return {?}
  4612. */
  4613. get isBs4() {
  4614. return !isBs3();
  4615. }
  4616. /*protected getDaysInMonth(year:number, month:number) {
  4617. return ((month === 1) && (year % 4 === 0) &&
  4618. ((year % 100 !== 0) || (year % 400 === 0))) ? 29 : DAYS_IN_MONTH[month];
  4619. }*/
  4620. /**
  4621. * @return {?}
  4622. */
  4623. ngOnInit() {
  4624. /** @type {?} */
  4625. const self = this;
  4626. this.datePicker.stepDay = { months: 1 };
  4627. this.datePicker.setRefreshViewHandler((/**
  4628. * @return {?}
  4629. */
  4630. function () {
  4631. /** @type {?} */
  4632. const year = this.activeDate.getFullYear();
  4633. /** @type {?} */
  4634. const month = this.activeDate.getMonth();
  4635. /** @type {?} */
  4636. const firstDayOfMonth = new Date(year, month, 1);
  4637. /** @type {?} */
  4638. const difference = this.startingDay - firstDayOfMonth.getDay();
  4639. /** @type {?} */
  4640. const numDisplayedFromPreviousMonth = difference > 0 ? 7 - difference : -difference;
  4641. /** @type {?} */
  4642. const firstDate = new Date(firstDayOfMonth.getTime());
  4643. if (numDisplayedFromPreviousMonth > 0) {
  4644. firstDate.setDate(-numDisplayedFromPreviousMonth + 1);
  4645. }
  4646. // 42 is the number of days on a six-week calendar
  4647. /** @type {?} */
  4648. const _days = self.getDates(firstDate, 42);
  4649. /** @type {?} */
  4650. const days = [];
  4651. for (let i = 0; i < 42; i++) {
  4652. /** @type {?} */
  4653. const _dateObject = this.createDateObject(_days[i], this.formatDay);
  4654. _dateObject.secondary = _days[i].getMonth() !== month;
  4655. _dateObject.uid = this.uniqueId + '-' + i;
  4656. days[i] = _dateObject;
  4657. }
  4658. self.labels = [];
  4659. for (let j = 0; j < 7; j++) {
  4660. self.labels[j] = {};
  4661. self.labels[j].abbr = this.dateFilter(days[j].date, this.formatDayHeader);
  4662. self.labels[j].full = this.dateFilter(days[j].date, 'EEEE');
  4663. }
  4664. self.title = this.dateFilter(this.activeDate, this.formatDayTitle);
  4665. self.rows = this.split(days, 7);
  4666. if (this.showWeeks) {
  4667. self.weekNumbers = [];
  4668. /** @type {?} */
  4669. const thursdayIndex = (4 + 7 - this.startingDay) % 7;
  4670. /** @type {?} */
  4671. const numWeeks = self.rows.length;
  4672. for (let curWeek = 0; curWeek < numWeeks; curWeek++) {
  4673. self.weekNumbers.push(self.getISO8601WeekNumber(self.rows[curWeek][thursdayIndex].date));
  4674. }
  4675. }
  4676. }), 'day');
  4677. this.datePicker.setCompareHandler((/**
  4678. * @param {?} date1
  4679. * @param {?} date2
  4680. * @return {?}
  4681. */
  4682. function (date1, date2) {
  4683. /** @type {?} */
  4684. const d1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
  4685. /** @type {?} */
  4686. const d2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
  4687. return d1.getTime() - d2.getTime();
  4688. }), 'day');
  4689. this.datePicker.refreshView();
  4690. }
  4691. /**
  4692. * @protected
  4693. * @param {?} startDate
  4694. * @param {?} n
  4695. * @return {?}
  4696. */
  4697. getDates(startDate, n) {
  4698. /** @type {?} */
  4699. const dates = new Array(n);
  4700. /** @type {?} */
  4701. let current = new Date(startDate.getTime());
  4702. /** @type {?} */
  4703. let i = 0;
  4704. /** @type {?} */
  4705. let date;
  4706. while (i < n) {
  4707. date = new Date(current.getTime());
  4708. date = this.datePicker.fixTimeZone(date);
  4709. dates[i++] = date;
  4710. current = new Date(date.getFullYear(), date.getMonth(), date.getDate() + 1);
  4711. }
  4712. return dates;
  4713. }
  4714. /**
  4715. * @protected
  4716. * @param {?} date
  4717. * @return {?}
  4718. */
  4719. getISO8601WeekNumber(date) {
  4720. /** @type {?} */
  4721. const checkDate = new Date(date.getTime());
  4722. // Thursday
  4723. checkDate.setDate(checkDate.getDate() + 4 - (checkDate.getDay() || 7));
  4724. /** @type {?} */
  4725. const time = checkDate.getTime();
  4726. // Compare with Jan 1
  4727. checkDate.setMonth(0);
  4728. checkDate.setDate(1);
  4729. return (Math.floor(Math.round((time - checkDate.getTime()) / 86400000) / 7) + 1);
  4730. }
  4731. }
  4732. DayPickerComponent.decorators = [
  4733. { type: Component, args: [{
  4734. selector: 'daypicker',
  4735. template: `
  4736. <table *ngIf="datePicker.datepickerMode === 'day'" role="grid" [attr.aria-labelledby]="datePicker.uniqueId + '-title'" aria-activedescendant="activeDateId">
  4737. <thead>
  4738. <tr>
  4739. <th>
  4740. <button *ngIf="!isBs4"
  4741. type="button"
  4742. class="btn btn-default btn-secondary btn-sm pull-left float-left"
  4743. (click)="datePicker.move(-1)"
  4744. tabindex="-1">‹</button>
  4745. <button *ngIf="isBs4"
  4746. type="button"
  4747. class="btn btn-default btn-secondary btn-sm pull-left float-left"
  4748. (click)="datePicker.move(-1)"
  4749. tabindex="-1">&lt;</button>
  4750. </th>
  4751. <th [attr.colspan]="5 + (datePicker.showWeeks ? 1 : 0)">
  4752. <button [id]="datePicker.uniqueId + '-title'"
  4753. type="button" class="btn btn-default btn-secondary btn-sm"
  4754. (click)="datePicker.toggleMode(0)"
  4755. [disabled]="datePicker.datepickerMode === datePicker.maxMode"
  4756. [ngClass]="{disabled: datePicker.datepickerMode === datePicker.maxMode}" tabindex="-1" style="width:100%;">
  4757. <strong>{{ title }}</strong>
  4758. </button>
  4759. </th>
  4760. <th>
  4761. <button *ngIf="!isBs4"
  4762. type="button"
  4763. class="btn btn-default btn-secondary btn-sm pull-right float-right"
  4764. (click)="datePicker.move(1)"
  4765. tabindex="-1">›</button>
  4766. <button *ngIf="isBs4"
  4767. type="button"
  4768. class="btn btn-default btn-secondary btn-sm pull-right float-right"
  4769. (click)="datePicker.move(1)"
  4770. tabindex="-1">&gt;
  4771. </button>
  4772. </th>
  4773. </tr>
  4774. <tr>
  4775. <th *ngIf="datePicker.showWeeks"></th>
  4776. <th *ngFor="let labelz of labels" class="text-center">
  4777. <small aria-label="labelz.full"><b>{{ labelz.abbr }}</b></small>
  4778. </th>
  4779. </tr>
  4780. </thead>
  4781. <tbody>
  4782. <ng-template ngFor [ngForOf]="rows" let-rowz="$implicit" let-index="index">
  4783. <tr *ngIf="!(datePicker.onlyCurrentMonth && rowz[0].secondary && rowz[6].secondary)">
  4784. <td *ngIf="datePicker.showWeeks" class="h6" class="text-center">
  4785. <em>{{ weekNumbers[index] }}</em>
  4786. </td>
  4787. <td *ngFor="let dtz of rowz" class="text-center" role="gridcell" [id]="dtz.uid">
  4788. <button type="button" style="min-width:100%;" class="btn btn-sm {{dtz.customClass}}"
  4789. *ngIf="!(datePicker.onlyCurrentMonth && dtz.secondary)"
  4790. [ngClass]="{'btn-secondary': isBs4 && !dtz.selected && !datePicker.isActive(dtz), 'btn-info': dtz.selected, disabled: dtz.disabled, active: !isBs4 && datePicker.isActive(dtz), 'btn-default': !isBs4}"
  4791. [disabled]="dtz.disabled"
  4792. (click)="datePicker.select(dtz.date)" tabindex="-1">
  4793. <span [ngClass]="{'text-muted': dtz.secondary || dtz.current, 'text-info': !isBs4 && dtz.current}">{{ dtz.label }}</span>
  4794. </button>
  4795. </td>
  4796. </tr>
  4797. </ng-template>
  4798. </tbody>
  4799. </table>
  4800. `,
  4801. styles: [`
  4802. :host .btn-secondary {
  4803. color: #292b2c;
  4804. background-color: #fff;
  4805. border-color: #ccc;
  4806. }
  4807. :host .btn-info .text-muted {
  4808. color: #292b2c !important;
  4809. }
  4810. `]
  4811. }] }
  4812. ];
  4813. /** @nocollapse */
  4814. DayPickerComponent.ctorParameters = () => [
  4815. { type: DatePickerInnerComponent }
  4816. ];
  4817. /**
  4818. * @fileoverview added by tsickle
  4819. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  4820. */
  4821. class MonthPickerComponent {
  4822. /**
  4823. * @param {?} datePicker
  4824. */
  4825. constructor(datePicker) {
  4826. this.rows = [];
  4827. this.datePicker = datePicker;
  4828. }
  4829. /**
  4830. * @return {?}
  4831. */
  4832. get isBs4() {
  4833. return !isBs3();
  4834. }
  4835. /**
  4836. * @return {?}
  4837. */
  4838. ngOnInit() {
  4839. /** @type {?} */
  4840. const self = this;
  4841. this.datePicker.stepMonth = { years: 1 };
  4842. this.datePicker.setRefreshViewHandler((/**
  4843. * @return {?}
  4844. */
  4845. function () {
  4846. /** @type {?} */
  4847. const months = new Array(12);
  4848. /** @type {?} */
  4849. const year = this.activeDate.getFullYear();
  4850. /** @type {?} */
  4851. let date;
  4852. for (let i = 0; i < 12; i++) {
  4853. date = new Date(year, i, 1);
  4854. date = this.fixTimeZone(date);
  4855. months[i] = this.createDateObject(date, this.formatMonth);
  4856. months[i].uid = this.uniqueId + '-' + i;
  4857. }
  4858. self.title = this.dateFilter(this.activeDate, this.formatMonthTitle);
  4859. self.rows = this.split(months, self.datePicker.monthColLimit);
  4860. }), 'month');
  4861. this.datePicker.setCompareHandler((/**
  4862. * @param {?} date1
  4863. * @param {?} date2
  4864. * @return {?}
  4865. */
  4866. function (date1, date2) {
  4867. /** @type {?} */
  4868. const d1 = new Date(date1.getFullYear(), date1.getMonth());
  4869. /** @type {?} */
  4870. const d2 = new Date(date2.getFullYear(), date2.getMonth());
  4871. return d1.getTime() - d2.getTime();
  4872. }), 'month');
  4873. this.datePicker.refreshView();
  4874. }
  4875. }
  4876. MonthPickerComponent.decorators = [
  4877. { type: Component, args: [{
  4878. selector: 'monthpicker',
  4879. template: `
  4880. <table *ngIf="datePicker.datepickerMode==='month'" role="grid">
  4881. <thead>
  4882. <tr>
  4883. <th>
  4884. <button type="button" class="btn btn-default btn-sm pull-left float-left"
  4885. (click)="datePicker.move(-1)" tabindex="-1">‹</button></th>
  4886. <th [attr.colspan]="((datePicker.monthColLimit - 2) <= 0) ? 1 : datePicker.monthColLimit - 2">
  4887. <button [id]="datePicker.uniqueId + '-title'"
  4888. type="button" class="btn btn-default btn-sm"
  4889. (click)="datePicker.toggleMode(0)"
  4890. [disabled]="datePicker.datepickerMode === maxMode"
  4891. [ngClass]="{disabled: datePicker.datepickerMode === maxMode}" tabindex="-1" style="width:100%;">
  4892. <strong>{{ title }}</strong>
  4893. </button>
  4894. </th>
  4895. <th>
  4896. <button type="button" class="btn btn-default btn-sm pull-right float-right"
  4897. (click)="datePicker.move(1)" tabindex="-1">›</button>
  4898. </th>
  4899. </tr>
  4900. </thead>
  4901. <tbody>
  4902. <tr *ngFor="let rowz of rows">
  4903. <td *ngFor="let dtz of rowz" class="text-center" role="gridcell" [attr.id]="dtz.uid" [ngClass]="dtz.customClass">
  4904. <button type="button" style="min-width:100%;" class="btn btn-default"
  4905. [ngClass]="{'btn-link': isBs4 && !dtz.selected && !datePicker.isActive(dtz), 'btn-info': dtz.selected || (isBs4 && !dtz.selected && datePicker.isActive(dtz)), disabled: dtz.disabled, active: !isBs4 && datePicker.isActive(dtz)}"
  4906. [disabled]="dtz.disabled"
  4907. (click)="datePicker.select(dtz.date)" tabindex="-1">
  4908. <span [ngClass]="{'text-success': isBs4 && dtz.current, 'text-info': !isBs4 && dtz.current}">{{ dtz.label }}</span>
  4909. </button>
  4910. </td>
  4911. </tr>
  4912. </tbody>
  4913. </table>
  4914. `,
  4915. styles: [`
  4916. :host .btn-info .text-success {
  4917. color: #fff !important;
  4918. }
  4919. `]
  4920. }] }
  4921. ];
  4922. /** @nocollapse */
  4923. MonthPickerComponent.ctorParameters = () => [
  4924. { type: DatePickerInnerComponent }
  4925. ];
  4926. /**
  4927. * @fileoverview added by tsickle
  4928. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  4929. */
  4930. class YearPickerComponent {
  4931. /**
  4932. * @param {?} datePicker
  4933. */
  4934. constructor(datePicker) {
  4935. this.rows = [];
  4936. this.datePicker = datePicker;
  4937. }
  4938. /**
  4939. * @return {?}
  4940. */
  4941. get isBs4() {
  4942. return !isBs3();
  4943. }
  4944. /**
  4945. * @return {?}
  4946. */
  4947. ngOnInit() {
  4948. /** @type {?} */
  4949. const self = this;
  4950. this.datePicker.stepYear = { years: this.datePicker.yearRange };
  4951. this.datePicker.setRefreshViewHandler((/**
  4952. * @return {?}
  4953. */
  4954. function () {
  4955. /** @type {?} */
  4956. const years = new Array(this.yearRange);
  4957. /** @type {?} */
  4958. let date;
  4959. /** @type {?} */
  4960. const start = self.getStartingYear(this.activeDate.getFullYear());
  4961. for (let i = 0; i < this.yearRange; i++) {
  4962. date = new Date(start + i, 0, 1);
  4963. date = this.fixTimeZone(date);
  4964. years[i] = this.createDateObject(date, this.formatYear);
  4965. years[i].uid = this.uniqueId + '-' + i;
  4966. }
  4967. self.title = [years[0].label, years[this.yearRange - 1].label].join(' - ');
  4968. self.rows = this.split(years, self.datePicker.yearColLimit);
  4969. }), 'year');
  4970. this.datePicker.setCompareHandler((/**
  4971. * @param {?} date1
  4972. * @param {?} date2
  4973. * @return {?}
  4974. */
  4975. function (date1, date2) {
  4976. return date1.getFullYear() - date2.getFullYear();
  4977. }), 'year');
  4978. this.datePicker.refreshView();
  4979. }
  4980. /**
  4981. * @protected
  4982. * @param {?} year
  4983. * @return {?}
  4984. */
  4985. getStartingYear(year) {
  4986. // todo: parseInt
  4987. return ((year - 1) / this.datePicker.yearRange * this.datePicker.yearRange + 1);
  4988. }
  4989. }
  4990. YearPickerComponent.decorators = [
  4991. { type: Component, args: [{
  4992. selector: 'yearpicker',
  4993. template: `
  4994. <table *ngIf="datePicker.datepickerMode==='year'" role="grid">
  4995. <thead>
  4996. <tr>
  4997. <th>
  4998. <button type="button" class="btn btn-default btn-sm pull-left float-left"
  4999. (click)="datePicker.move(-1)" tabindex="-1">‹</button>
  5000. </th>
  5001. <th [attr.colspan]="((datePicker.yearColLimit - 2) <= 0) ? 1 : datePicker.yearColLimit - 2">
  5002. <button [id]="datePicker.uniqueId + '-title'" role="heading"
  5003. type="button" class="btn btn-default btn-sm"
  5004. (click)="datePicker.toggleMode(0)"
  5005. [disabled]="datePicker.datepickerMode === datePicker.maxMode"
  5006. [ngClass]="{disabled: datePicker.datepickerMode === datePicker.maxMode}" tabindex="-1" style="width:100%;">
  5007. <strong>{{ title }}</strong>
  5008. </button>
  5009. </th>
  5010. <th>
  5011. <button type="button" class="btn btn-default btn-sm pull-right float-right"
  5012. (click)="datePicker.move(1)" tabindex="-1">›</button>
  5013. </th>
  5014. </tr>
  5015. </thead>
  5016. <tbody>
  5017. <tr *ngFor="let rowz of rows">
  5018. <td *ngFor="let dtz of rowz" class="text-center" role="gridcell" [attr.id]="dtz.uid">
  5019. <button type="button" style="min-width:100%;" class="btn btn-default"
  5020. [ngClass]="{'btn-link': isBs4 && !dtz.selected && !datePicker.isActive(dtz), 'btn-info': dtz.selected || (isBs4 && !dtz.selected && datePicker.isActive(dtz)), disabled: dtz.disabled, active: !isBs4 && datePicker.isActive(dtz)}"
  5021. [disabled]="dtz.disabled"
  5022. (click)="datePicker.select(dtz.date)" tabindex="-1">
  5023. <span [ngClass]="{'text-success': isBs4 && dtz.current, 'text-info': !isBs4 && dtz.current}">{{ dtz.label }}</span>
  5024. </button>
  5025. </td>
  5026. </tr>
  5027. </tbody>
  5028. </table>
  5029. `,
  5030. styles: [`
  5031. :host .btn-info .text-success {
  5032. color: #fff !important;
  5033. }
  5034. `]
  5035. }] }
  5036. ];
  5037. /** @nocollapse */
  5038. YearPickerComponent.ctorParameters = () => [
  5039. { type: DatePickerInnerComponent }
  5040. ];
  5041. /**
  5042. * @fileoverview added by tsickle
  5043. * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
  5044. */
  5045. class DatepickerModule {
  5046. /**
  5047. * @return {?}
  5048. */
  5049. static forRoot() {
  5050. return { ngModule: DatepickerModule, providers: [DatepickerConfig] };
  5051. }
  5052. }
  5053. DatepickerModule.decorators = [
  5054. { type: NgModule, args: [{
  5055. imports: [CommonModule, FormsModule],
  5056. declarations: [
  5057. DatePickerComponent,
  5058. DatePickerInnerComponent,
  5059. DayPickerComponent,
  5060. MonthPickerComponent,
  5061. YearPickerComponent
  5062. ],
  5063. exports: [
  5064. DatePickerComponent,
  5065. DatePickerInnerComponent,
  5066. DayPickerComponent,
  5067. MonthPickerComponent,
  5068. YearPickerComponent
  5069. ],
  5070. entryComponents: [DatePickerComponent]
  5071. },] }
  5072. ];
  5073. export { BsDatepickerConfig, BsDatepickerContainerComponent, BsDatepickerDirective, BsDatepickerInlineConfig, BsDatepickerInlineContainerComponent, BsDatepickerInlineDirective, BsDatepickerInputDirective, BsDatepickerModule, BsDaterangepickerConfig, BsDaterangepickerContainerComponent, BsDaterangepickerDirective, BsDaterangepickerInlineConfig, BsDaterangepickerInlineContainerComponent, BsDaterangepickerInlineDirective, BsDaterangepickerInputDirective, BsLocaleService, DateFormatter, DatePickerComponent, DatePickerInnerComponent, DatepickerConfig, DatepickerModule, DayPickerComponent, MonthPickerComponent, YearPickerComponent, DATEPICKER_CONTROL_VALUE_ACCESSOR as ɵa, BsDatepickerAbstractComponent as ɵb, BsDatepickerStore as ɵc, BsDatepickerEffects as ɵd, BsDatepickerActions as ɵe, datepickerAnimation as ɵf, BsCalendarLayoutComponent as ɵg, BsCurrentDateViewComponent as ɵh, BsCustomDatesViewComponent as ɵi, BsDatepickerDayDecoratorComponent as ɵj, BsDatepickerNavigationViewComponent as ɵk, BsDaysCalendarViewComponent as ɵl, BsMonthCalendarViewComponent as ɵm, BsTimepickerViewComponent as ɵn, BsYearsCalendarViewComponent as ɵo };
  5074. //# sourceMappingURL=ngx-bootstrap-datepicker.js.map