UNPKG

ngx-bootstrap

Version:
1,778 lines (1,762 loc) 241 kB
import { Injectable, ɵɵdefineInjectable, EventEmitter, Component, Renderer2, ElementRef, Directive, ViewContainerRef, Input, Output, forwardRef, Host, ChangeDetectorRef, ChangeDetectionStrategy, NgModule, ViewChild } from '@angular/core'; import { filter, map, take, takeUntil, distinctUntilChanged } from 'rxjs/operators'; import { isFirstDayOfWeek, getDay, shiftDate, isBefore, endOf, isAfter, startOf, isArray, isSame, getFirstDayOfMonth, formatDate, getLocale, isSameMonth, isSameDay, isDisabledDay, isSameYear, isDateValid, setFullDate, getMonth, getFullYear, isDate, parseDate, utcAsLocal } from 'ngx-bootstrap/chronos'; import { PositioningService } from 'ngx-bootstrap/positioning'; import { trigger, state, style, transition, animate } from '@angular/animations'; import { BehaviorSubject, Subject } from 'rxjs'; import { MiniStore, MiniState } from 'ngx-bootstrap/mini-ngrx'; import { ComponentLoaderFactory } from 'ngx-bootstrap/component-loader'; import { NG_VALUE_ACCESSOR, NG_VALIDATORS, FormsModule } from '@angular/forms'; import { CommonModule } from '@angular/common'; import { TooltipModule } from 'ngx-bootstrap/tooltip'; import { isBs3 } from 'ngx-bootstrap/utils'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * For date range picker there are `BsDaterangepickerConfig` which inherits all properties, * except `displayMonths`, for range picker it default to `2` */ class BsDatepickerConfig { constructor() { /** * sets use adaptive position */ this.adaptivePosition = false; /** * sets use UTC date time format */ this.useUtc = false; /** * turn on/off animation */ this.isAnimated = false; /** * If true, returns focus to the datepicker / daterangepicker input after date selection */ this.returnFocusToInput = false; /** * CSS class which will be applied to datepicker container, * usually used to set color theme */ this.containerClass = 'theme-green'; // DatepickerRenderOptions this.displayMonths = 1; /** * Allows to hide week numbers in datepicker */ this.showWeekNumbers = true; this.dateInputFormat = 'L'; // range picker this.rangeSeparator = ' - '; /** * Date format for date range input field */ this.rangeInputFormat = 'L'; // DatepickerFormatOptions this.monthTitle = 'MMMM'; this.yearTitle = 'YYYY'; this.dayLabel = 'D'; this.monthLabel = 'MMMM'; this.yearLabel = 'YYYY'; this.weekNumbers = 'w'; /** * Shows 'today' button */ this.showTodayButton = false; /** * Shows clear button */ this.showClearButton = false; /** * Positioning of 'today' button */ this.todayPosition = 'center'; /** * Positioning of 'clear' button */ this.clearPosition = 'right'; } } BsDatepickerConfig.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ BsDatepickerConfig.ɵprov = ɵɵdefineInjectable({ factory: function BsDatepickerConfig_Factory() { return new BsDatepickerConfig(); }, token: BsDatepickerConfig, providedIn: "root" }); if (false) { /** * sets use adaptive position * @type {?} */ BsDatepickerConfig.prototype.adaptivePosition; /** * sets use UTC date time format * @type {?} */ BsDatepickerConfig.prototype.useUtc; /** * turn on/off animation * @type {?} */ BsDatepickerConfig.prototype.isAnimated; /** @type {?} */ BsDatepickerConfig.prototype.value; /** @type {?} */ BsDatepickerConfig.prototype.isDisabled; /** * Default min date for all date/range pickers * @type {?} */ BsDatepickerConfig.prototype.minDate; /** * Default max date for all date/range pickers * @type {?} */ BsDatepickerConfig.prototype.maxDate; /** * Default date custom classes for all date/range pickers * @type {?} */ BsDatepickerConfig.prototype.dateCustomClasses; /** * Default tooltip text for all date/range pickers * @type {?} */ BsDatepickerConfig.prototype.dateTooltipTexts; /** * Disable specific days, e.g. [0,6] will disable all Saturdays and Sundays * @type {?} */ BsDatepickerConfig.prototype.daysDisabled; /** * Disable specific dates * @type {?} */ BsDatepickerConfig.prototype.datesDisabled; /** * Show one months for special cases (only for dateRangePicker) * 1. maxDate is equal to today's date * 2. minDate's month is equal to maxDate's month * @type {?} */ BsDatepickerConfig.prototype.displayOneMonthRange; /** * Enable specific dates * @type {?} */ BsDatepickerConfig.prototype.datesEnabled; /** * Makes dates from other months active * @type {?} */ BsDatepickerConfig.prototype.selectFromOtherMonth; /** * Allows select first date of the week by click on week number * @type {?} */ BsDatepickerConfig.prototype.selectWeek; /** * Allows select daterange as first and last day of week by click on week number (dateRangePicker only) * @type {?} */ BsDatepickerConfig.prototype.selectWeekDateRange; /** * Shows previous and current month, instead of current and next (dateRangePicker only) * @type {?} */ BsDatepickerConfig.prototype.showPreviousMonth; /** * Add class to current day * @type {?} */ BsDatepickerConfig.prototype.customTodayClass; /** * Default mode for all date pickers * @type {?} */ BsDatepickerConfig.prototype.minMode; /** * If true, returns focus to the datepicker / daterangepicker input after date selection * @type {?} */ BsDatepickerConfig.prototype.returnFocusToInput; /** * CSS class which will be applied to datepicker container, * usually used to set color theme * @type {?} */ BsDatepickerConfig.prototype.containerClass; /** @type {?} */ BsDatepickerConfig.prototype.displayMonths; /** * Allows to hide week numbers in datepicker * @type {?} */ BsDatepickerConfig.prototype.showWeekNumbers; /** @type {?} */ BsDatepickerConfig.prototype.dateInputFormat; /** @type {?} */ BsDatepickerConfig.prototype.rangeSeparator; /** * Date format for date range input field * @type {?} */ BsDatepickerConfig.prototype.rangeInputFormat; /** * Predefined ranges * @type {?} */ BsDatepickerConfig.prototype.ranges; /** * Max Date Range in days * @type {?} */ BsDatepickerConfig.prototype.maxDateRange; /** @type {?} */ BsDatepickerConfig.prototype.monthTitle; /** @type {?} */ BsDatepickerConfig.prototype.yearTitle; /** @type {?} */ BsDatepickerConfig.prototype.dayLabel; /** @type {?} */ BsDatepickerConfig.prototype.monthLabel; /** @type {?} */ BsDatepickerConfig.prototype.yearLabel; /** @type {?} */ BsDatepickerConfig.prototype.weekNumbers; /** * Shows 'today' button * @type {?} */ BsDatepickerConfig.prototype.showTodayButton; /** * Shows clear button * @type {?} */ BsDatepickerConfig.prototype.showClearButton; /** * Positioning of 'today' button * @type {?} */ BsDatepickerConfig.prototype.todayPosition; /** * Positioning of 'clear' button * @type {?} */ BsDatepickerConfig.prototype.clearPosition; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const DATEPICKER_ANIMATION_TIMING = '220ms cubic-bezier(0, 0, 0.2, 1)'; /** @type {?} */ const datepickerAnimation = trigger('datepickerAnimation', [ state('animated-down', style({ height: '*', overflow: 'hidden' })), transition('* => animated-down', [ style({ height: 0, overflow: 'hidden' }), animate(DATEPICKER_ANIMATION_TIMING) ]), state('animated-up', style({ height: '*', overflow: 'hidden' })), transition('* => animated-up', [ style({ height: '*', overflow: 'hidden' }), animate(DATEPICKER_ANIMATION_TIMING) ]), transition('* => unanimated', animate('0s')) ]); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @abstract */ class BsDatepickerAbstractComponent { constructor() { this.customRanges = []; this.chosenRange = []; } /** * @param {?} value * @return {?} */ set minDate(value) { this._effects.setMinDate(value); } /** * @param {?} value * @return {?} */ set maxDate(value) { this._effects.setMaxDate(value); } /** * @param {?} value * @return {?} */ set daysDisabled(value) { this._effects.setDaysDisabled(value); } /** * @param {?} value * @return {?} */ set datesDisabled(value) { this._effects.setDatesDisabled(value); } /** * @param {?} value * @return {?} */ set datesEnabled(value) { this._effects.setDatesEnabled(value); } /** * @param {?} value * @return {?} */ set isDisabled(value) { this._effects.setDisabled(value); } /** * @param {?} value * @return {?} */ set dateCustomClasses(value) { this._effects.setDateCustomClasses(value); } /** * @param {?} value * @return {?} */ set dateTooltipTexts(value) { this._effects.setDateTooltipTexts(value); } /** * @param {?} event * @return {?} */ setViewMode(event) { } /** * @param {?} event * @return {?} */ navigateTo(event) { } /** * @param {?} event * @return {?} */ dayHoverHandler(event) { } /** * @param {?} event * @return {?} */ weekHoverHandler(event) { } /** * @param {?} event * @return {?} */ monthHoverHandler(event) { } /** * @param {?} event * @return {?} */ yearHoverHandler(event) { } /** * @param {?} day * @return {?} */ daySelectHandler(day) { } /** * @param {?} event * @return {?} */ monthSelectHandler(event) { } /** * @param {?} event * @return {?} */ yearSelectHandler(event) { } /** * @param {?} dates * @return {?} */ setRangeOnCalendar(dates) { } /** * @return {?} */ setToday() { } /** * @return {?} */ clearDate() { } /* tslint:disable-next-line: no-any */ /** * @param {?} event * @return {?} */ _stopPropagation(event) { event.stopPropagation(); } } if (false) { /** @type {?} */ BsDatepickerAbstractComponent.prototype.containerClass; /** @type {?} */ BsDatepickerAbstractComponent.prototype.isOtherMonthsActive; /** @type {?} */ BsDatepickerAbstractComponent.prototype.showTodayBtn; /** @type {?} */ BsDatepickerAbstractComponent.prototype.todayPos; /** @type {?} */ BsDatepickerAbstractComponent.prototype.clearPos; /** @type {?} */ BsDatepickerAbstractComponent.prototype.showClearBtn; /** @type {?} */ BsDatepickerAbstractComponent.prototype._effects; /** @type {?} */ BsDatepickerAbstractComponent.prototype.customRanges; /** @type {?} */ BsDatepickerAbstractComponent.prototype.chosenRange; /** @type {?} */ BsDatepickerAbstractComponent.prototype.viewMode; /** @type {?} */ BsDatepickerAbstractComponent.prototype.daysCalendar; /** @type {?} */ BsDatepickerAbstractComponent.prototype.monthsCalendar; /** @type {?} */ BsDatepickerAbstractComponent.prototype.yearsCalendar; /** @type {?} */ BsDatepickerAbstractComponent.prototype.options; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class BsDatepickerActions { /** * @return {?} */ calculate() { return { type: BsDatepickerActions.CALCULATE }; } /** * @return {?} */ format() { return { type: BsDatepickerActions.FORMAT }; } /** * @return {?} */ flag() { return { type: BsDatepickerActions.FLAG }; } /** * @param {?} date * @return {?} */ select(date) { return { type: BsDatepickerActions.SELECT, payload: date }; } /** * @param {?} event * @return {?} */ changeViewMode(event) { return { type: BsDatepickerActions.CHANGE_VIEWMODE, payload: event }; } /** * @param {?} event * @return {?} */ navigateTo(event) { return { type: BsDatepickerActions.NAVIGATE_TO, payload: event }; } /** * @param {?} step * @return {?} */ navigateStep(step) { return { type: BsDatepickerActions.NAVIGATE_OFFSET, payload: step }; } /** * @param {?} options * @return {?} */ setOptions(options) { return { type: BsDatepickerActions.SET_OPTIONS, payload: options }; } // date range picker /** * @param {?} value * @return {?} */ selectRange(value) { return { type: BsDatepickerActions.SELECT_RANGE, payload: value }; } /** * @param {?} event * @return {?} */ hoverDay(event) { return { type: BsDatepickerActions.HOVER, payload: event.isHovered ? event.cell.date : null }; } /** * @param {?} date * @return {?} */ minDate(date) { return { type: BsDatepickerActions.SET_MIN_DATE, payload: date }; } /** * @param {?} date * @return {?} */ maxDate(date) { return { type: BsDatepickerActions.SET_MAX_DATE, payload: date }; } /** * @param {?} days * @return {?} */ daysDisabled(days) { return { type: BsDatepickerActions.SET_DAYSDISABLED, payload: days }; } /** * @param {?} dates * @return {?} */ datesDisabled(dates) { return { type: BsDatepickerActions.SET_DATESDISABLED, payload: dates }; } /** * @param {?} dates * @return {?} */ datesEnabled(dates) { return { type: BsDatepickerActions.SET_DATESENABLED, payload: dates }; } /** * @param {?} value * @return {?} */ isDisabled(value) { return { type: BsDatepickerActions.SET_IS_DISABLED, payload: value }; } /** * @param {?} value * @return {?} */ setDateCustomClasses(value) { return { type: BsDatepickerActions.SET_DATE_CUSTOM_CLASSES, payload: value }; } /** * @param {?} value * @return {?} */ setDateTooltipTexts(value) { return { type: BsDatepickerActions.SET_DATE_TOOLTIP_TEXTS, payload: value }; } /** * @param {?} locale * @return {?} */ setLocale(locale) { return { type: BsDatepickerActions.SET_LOCALE, payload: locale }; } } BsDatepickerActions.CALCULATE = '[datepicker] calculate dates matrix'; BsDatepickerActions.FORMAT = '[datepicker] format datepicker values'; BsDatepickerActions.FLAG = '[datepicker] set flags'; BsDatepickerActions.SELECT = '[datepicker] select date'; BsDatepickerActions.NAVIGATE_OFFSET = '[datepicker] shift view date'; BsDatepickerActions.NAVIGATE_TO = '[datepicker] change view date'; BsDatepickerActions.SET_OPTIONS = '[datepicker] update render options'; BsDatepickerActions.HOVER = '[datepicker] hover date'; BsDatepickerActions.CHANGE_VIEWMODE = '[datepicker] switch view mode'; BsDatepickerActions.SET_MIN_DATE = '[datepicker] set min date'; BsDatepickerActions.SET_MAX_DATE = '[datepicker] set max date'; BsDatepickerActions.SET_DAYSDISABLED = '[datepicker] set days disabled'; BsDatepickerActions.SET_DATESDISABLED = '[datepicker] set dates disabled'; BsDatepickerActions.SET_DATESENABLED = '[datepicker] set dates enabled'; BsDatepickerActions.SET_IS_DISABLED = '[datepicker] set is disabled'; BsDatepickerActions.SET_DATE_CUSTOM_CLASSES = '[datepicker] set date custom classes'; BsDatepickerActions.SET_DATE_TOOLTIP_TEXTS = '[datepicker] set date tooltip texts'; BsDatepickerActions.SET_LOCALE = '[datepicker] set datepicker locale'; BsDatepickerActions.SELECT_RANGE = '[daterangepicker] select dates range'; BsDatepickerActions.decorators = [ { type: Injectable } ]; if (false) { /** @type {?} */ BsDatepickerActions.CALCULATE; /** @type {?} */ BsDatepickerActions.FORMAT; /** @type {?} */ BsDatepickerActions.FLAG; /** @type {?} */ BsDatepickerActions.SELECT; /** @type {?} */ BsDatepickerActions.NAVIGATE_OFFSET; /** @type {?} */ BsDatepickerActions.NAVIGATE_TO; /** @type {?} */ BsDatepickerActions.SET_OPTIONS; /** @type {?} */ BsDatepickerActions.HOVER; /** @type {?} */ BsDatepickerActions.CHANGE_VIEWMODE; /** @type {?} */ BsDatepickerActions.SET_MIN_DATE; /** @type {?} */ BsDatepickerActions.SET_MAX_DATE; /** @type {?} */ BsDatepickerActions.SET_DAYSDISABLED; /** @type {?} */ BsDatepickerActions.SET_DATESDISABLED; /** @type {?} */ BsDatepickerActions.SET_DATESENABLED; /** @type {?} */ BsDatepickerActions.SET_IS_DISABLED; /** @type {?} */ BsDatepickerActions.SET_DATE_CUSTOM_CLASSES; /** @type {?} */ BsDatepickerActions.SET_DATE_TOOLTIP_TEXTS; /** @type {?} */ BsDatepickerActions.SET_LOCALE; /** @type {?} */ BsDatepickerActions.SELECT_RANGE; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class BsLocaleService { constructor() { this._defaultLocale = 'en'; this._locale = new BehaviorSubject(this._defaultLocale); this._localeChange = this._locale.asObservable(); } /** * @return {?} */ get locale() { return this._locale; } /** * @return {?} */ get localeChange() { return this._localeChange; } /** * @return {?} */ get currentLocale() { return this._locale.getValue(); } /** * @param {?} locale * @return {?} */ use(locale) { if (locale === this.currentLocale) { return; } this._locale.next(locale); } } BsLocaleService.decorators = [ { type: Injectable } ]; if (false) { /** * @type {?} * @private */ BsLocaleService.prototype._defaultLocale; /** * @type {?} * @private */ BsLocaleService.prototype._locale; /** * @type {?} * @private */ BsLocaleService.prototype._localeChange; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class BsDatepickerEffects { /** * @param {?} _actions * @param {?} _localeService */ constructor(_actions, _localeService) { this._actions = _actions; this._localeService = _localeService; this._subs = []; } /** * @param {?} _bsDatepickerStore * @return {?} */ init(_bsDatepickerStore) { this._store = _bsDatepickerStore; return this; } /** * setters * @param {?} value * @return {?} */ setValue(value) { this._store.dispatch(this._actions.select(value)); } /** * @param {?} value * @return {?} */ setRangeValue(value) { this._store.dispatch(this._actions.selectRange(value)); } /** * @param {?} value * @return {?} */ setMinDate(value) { this._store.dispatch(this._actions.minDate(value)); return this; } /** * @param {?} value * @return {?} */ setMaxDate(value) { this._store.dispatch(this._actions.maxDate(value)); return this; } /** * @param {?} value * @return {?} */ setDaysDisabled(value) { this._store.dispatch(this._actions.daysDisabled(value)); return this; } /** * @param {?} value * @return {?} */ setDatesDisabled(value) { this._store.dispatch(this._actions.datesDisabled(value)); return this; } /** * @param {?} value * @return {?} */ setDatesEnabled(value) { this._store.dispatch(this._actions.datesEnabled(value)); return this; } /** * @param {?} value * @return {?} */ setDisabled(value) { this._store.dispatch(this._actions.isDisabled(value)); return this; } /** * @param {?} value * @return {?} */ setDateCustomClasses(value) { this._store.dispatch(this._actions.setDateCustomClasses(value)); return this; } /** * @param {?} value * @return {?} */ setDateTooltipTexts(value) { this._store.dispatch(this._actions.setDateTooltipTexts(value)); return this; } /* Set rendering options */ /** * @param {?} _config * @return {?} */ setOptions(_config) { /** @type {?} */ const _options = Object.assign({ locale: this._localeService.currentLocale }, _config); this._store.dispatch(this._actions.setOptions(_options)); return this; } /** * view to mode bindings * @param {?} container * @return {?} */ setBindings(container) { container.daysCalendar = this._store .select((/** * @param {?} state * @return {?} */ state => state.flaggedMonths)) .pipe(filter((/** * @param {?} months * @return {?} */ months => !!months))); // month calendar container.monthsCalendar = this._store .select((/** * @param {?} state * @return {?} */ state => state.flaggedMonthsCalendar)) .pipe(filter((/** * @param {?} months * @return {?} */ months => !!months))); // year calendar container.yearsCalendar = this._store .select((/** * @param {?} state * @return {?} */ state => state.yearsCalendarFlagged)) .pipe(filter((/** * @param {?} years * @return {?} */ years => !!years))); container.viewMode = this._store.select((/** * @param {?} state * @return {?} */ state => state.view.mode)); container.options = this._store .select((/** * @param {?} state * @return {?} */ state => state.showWeekNumbers)) .pipe(map((/** * @param {?} showWeekNumbers * @return {?} */ showWeekNumbers => ({ showWeekNumbers })))); return this; } /** * event handlers * @param {?} container * @return {?} */ setEventHandlers(container) { container.setViewMode = (/** * @param {?} event * @return {?} */ (event) => { this._store.dispatch(this._actions.changeViewMode(event)); }); container.navigateTo = (/** * @param {?} event * @return {?} */ (event) => { this._store.dispatch(this._actions.navigateStep(event.step)); }); container.dayHoverHandler = (/** * @param {?} event * @return {?} */ (event) => { /** @type {?} */ const _cell = (/** @type {?} */ (event.cell)); if (_cell.isOtherMonth || _cell.isDisabled) { return; } this._store.dispatch(this._actions.hoverDay(event)); _cell.isHovered = event.isHovered; }); container.monthHoverHandler = (/** * @param {?} event * @return {?} */ (event) => { event.cell.isHovered = event.isHovered; }); container.yearHoverHandler = (/** * @param {?} event * @return {?} */ (event) => { event.cell.isHovered = event.isHovered; }); return this; } /** * @return {?} */ registerDatepickerSideEffects() { this._subs.push(this._store.select((/** * @param {?} state * @return {?} */ state => state.view)).subscribe((/** * @param {?} view * @return {?} */ view => { this._store.dispatch(this._actions.calculate()); }))); // format calendar values on month model change this._subs.push(this._store .select((/** * @param {?} state * @return {?} */ state => state.monthsModel)) .pipe(filter((/** * @param {?} monthModel * @return {?} */ monthModel => !!monthModel))) .subscribe((/** * @param {?} month * @return {?} */ month => this._store.dispatch(this._actions.format())))); // flag day values this._subs.push(this._store .select((/** * @param {?} state * @return {?} */ state => state.formattedMonths)) .pipe(filter((/** * @param {?} month * @return {?} */ month => !!month))) .subscribe((/** * @param {?} month * @return {?} */ month => this._store.dispatch(this._actions.flag())))); // flag day values this._subs.push(this._store .select((/** * @param {?} state * @return {?} */ state => state.selectedDate)) .pipe(filter((/** * @param {?} selectedDate * @return {?} */ selectedDate => !!selectedDate))) .subscribe((/** * @param {?} selectedDate * @return {?} */ selectedDate => this._store.dispatch(this._actions.flag())))); // flag for date range picker this._subs.push(this._store .select((/** * @param {?} state * @return {?} */ state => state.selectedRange)) .pipe(filter((/** * @param {?} selectedRange * @return {?} */ selectedRange => !!selectedRange))) .subscribe((/** * @param {?} selectedRange * @return {?} */ selectedRange => this._store.dispatch(this._actions.flag())))); // monthsCalendar this._subs.push(this._store .select((/** * @param {?} state * @return {?} */ state => state.monthsCalendar)) .subscribe((/** * @return {?} */ () => this._store.dispatch(this._actions.flag())))); // years calendar this._subs.push(this._store .select((/** * @param {?} state * @return {?} */ state => state.yearsCalendarModel)) .pipe(filter((/** * @param {?} state * @return {?} */ state => !!state))) .subscribe((/** * @return {?} */ () => this._store.dispatch(this._actions.flag())))); // on hover this._subs.push(this._store .select((/** * @param {?} state * @return {?} */ state => state.hoveredDate)) .pipe(filter((/** * @param {?} hoveredDate * @return {?} */ hoveredDate => !!hoveredDate))) .subscribe((/** * @param {?} hoveredDate * @return {?} */ hoveredDate => this._store.dispatch(this._actions.flag())))); // date custom classes this._subs.push(this._store .select((/** * @param {?} state * @return {?} */ state => state.dateCustomClasses)) .pipe(filter((/** * @param {?} dateCustomClasses * @return {?} */ dateCustomClasses => !!dateCustomClasses))) .subscribe((/** * @param {?} dateCustomClasses * @return {?} */ dateCustomClasses => this._store.dispatch(this._actions.flag())))); // date tooltip texts this._subs.push(this._store .select((/** * @param {?} state * @return {?} */ state => state.dateTooltipTexts)) .pipe(filter((/** * @param {?} dateTooltipTexts * @return {?} */ dateTooltipTexts => !!dateTooltipTexts))) .subscribe((/** * @param {?} dateTooltipTexts * @return {?} */ dateTooltipTexts => this._store.dispatch(this._actions.flag())))); // on locale change this._subs.push(this._localeService.localeChange .subscribe((/** * @param {?} locale * @return {?} */ locale => this._store.dispatch(this._actions.setLocale(locale))))); return this; } /** * @return {?} */ destroy() { for (const sub of this._subs) { sub.unsubscribe(); } } } BsDatepickerEffects.decorators = [ { type: Injectable } ]; /** @nocollapse */ BsDatepickerEffects.ctorParameters = () => [ { type: BsDatepickerActions }, { type: BsLocaleService } ]; if (false) { /** @type {?} */ BsDatepickerEffects.prototype.viewMode; /** @type {?} */ BsDatepickerEffects.prototype.daysCalendar; /** @type {?} */ BsDatepickerEffects.prototype.monthsCalendar; /** @type {?} */ BsDatepickerEffects.prototype.yearsCalendar; /** @type {?} */ BsDatepickerEffects.prototype.options; /** * @type {?} * @private */ BsDatepickerEffects.prototype._store; /** * @type {?} * @private */ BsDatepickerEffects.prototype._subs; /** * @type {?} * @private */ BsDatepickerEffects.prototype._actions; /** * @type {?} * @private */ BsDatepickerEffects.prototype._localeService; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const defaultMonthOptions = { width: 7, height: 6 }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function BsDatepickerViewState() { } if (false) { /** @type {?} */ BsDatepickerViewState.prototype.date; /** @type {?} */ BsDatepickerViewState.prototype.mode; } class BsDatepickerState { } if (false) { /** @type {?} */ BsDatepickerState.prototype.selectedDate; /** @type {?} */ BsDatepickerState.prototype.selectedRange; /** @type {?} */ BsDatepickerState.prototype.view; /** @type {?} */ BsDatepickerState.prototype.isDisabled; /** @type {?} */ BsDatepickerState.prototype.minDate; /** @type {?} */ BsDatepickerState.prototype.maxDate; /** @type {?} */ BsDatepickerState.prototype.daysDisabled; /** @type {?} */ BsDatepickerState.prototype.datesDisabled; /** @type {?} */ BsDatepickerState.prototype.datesEnabled; /** @type {?} */ BsDatepickerState.prototype.minMode; /** @type {?} */ BsDatepickerState.prototype.dateCustomClasses; /** @type {?} */ BsDatepickerState.prototype.dateTooltipTexts; /** @type {?} */ BsDatepickerState.prototype.hoveredDate; /** @type {?} */ BsDatepickerState.prototype.hoveredMonth; /** @type {?} */ BsDatepickerState.prototype.hoveredYear; /** @type {?} */ BsDatepickerState.prototype.monthsModel; /** @type {?} */ BsDatepickerState.prototype.formattedMonths; /** @type {?} */ BsDatepickerState.prototype.flaggedMonths; /** @type {?} */ BsDatepickerState.prototype.selectFromOtherMonth; /** @type {?} */ BsDatepickerState.prototype.showPreviousMonth; /** @type {?} */ BsDatepickerState.prototype.displayOneMonthRange; /** @type {?} */ BsDatepickerState.prototype.monthsCalendar; /** @type {?} */ BsDatepickerState.prototype.flaggedMonthsCalendar; /** @type {?} */ BsDatepickerState.prototype.yearsCalendarModel; /** @type {?} */ BsDatepickerState.prototype.yearsCalendarFlagged; /** @type {?} */ BsDatepickerState.prototype.monthViewOptions; /** @type {?} */ BsDatepickerState.prototype.showWeekNumbers; /** @type {?} */ BsDatepickerState.prototype.displayMonths; /** @type {?} */ BsDatepickerState.prototype.locale; /** @type {?} */ BsDatepickerState.prototype.monthTitle; /** @type {?} */ BsDatepickerState.prototype.yearTitle; /** @type {?} */ BsDatepickerState.prototype.dayLabel; /** @type {?} */ BsDatepickerState.prototype.monthLabel; /** @type {?} */ BsDatepickerState.prototype.yearLabel; /** @type {?} */ BsDatepickerState.prototype.weekNumbers; } /** @type {?} */ const _initialView = { date: new Date(), mode: 'day' }; /** @type {?} */ const initialDatepickerState = Object.assign(new BsDatepickerConfig(), { locale: 'en', view: _initialView, selectedRange: [], monthViewOptions: defaultMonthOptions }); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} date * @param {?} options * @return {?} */ function getStartingDayOfCalendar(date, options) { if (isFirstDayOfWeek(date, options.firstDayOfWeek)) { return date; } /** @type {?} */ const weekDay = getDay(date); /** @type {?} */ const offset = calculateDateOffset(weekDay, options.firstDayOfWeek); return shiftDate(date, { day: -offset }); } /** * @param {?} weekday * @param {?} startingDayOffset * @return {?} */ function calculateDateOffset(weekday, startingDayOffset) { if (startingDayOffset === 0) { return weekday; } /** @type {?} */ const offset = weekday - startingDayOffset % 7; return offset < 0 ? offset + 7 : offset; } /** * @param {?} date * @param {?} min * @param {?} max * @return {?} */ function isMonthDisabled(date, min, max) { /** @type {?} */ const minBound = min && isBefore(endOf(date, 'month'), min, 'day'); /** @type {?} */ const maxBound = max && isAfter(startOf(date, 'month'), max, 'day'); return minBound || maxBound; } /** * @param {?} date * @param {?} min * @param {?} max * @return {?} */ function isYearDisabled(date, min, max) { /** @type {?} */ const minBound = min && isBefore(endOf(date, 'year'), min, 'day'); /** @type {?} */ const maxBound = max && isAfter(startOf(date, 'year'), max, 'day'); return minBound || maxBound; } /** * @param {?} date * @param {?} datesDisabled * @return {?} */ function isDisabledDate(date, datesDisabled) { if (!datesDisabled || !isArray(datesDisabled) || !datesDisabled.length) { return false; } return datesDisabled.some((/** * @param {?} dateDisabled * @return {?} */ (dateDisabled) => isSame(date, dateDisabled, 'date'))); } /** * @param {?} date * @param {?} datesEnabled * @return {?} */ function isEnabledDate(date, datesEnabled) { if (!datesEnabled || !isArray(datesEnabled) || !datesEnabled.length) { return false; } return !datesEnabled.some((/** * @param {?} enabledDate * @return {?} */ (enabledDate) => isSame(date, enabledDate, 'date'))); } /** * @param {?} state * @param {?=} calendarIndex * @return {?} */ function getYearsCalendarInitialDate(state, calendarIndex = 0) { /** @type {?} */ const model = state && state.yearsCalendarModel && state.yearsCalendarModel[calendarIndex]; return model && model.years && model.years[0] && model.years[0][0] && model.years[0][0].date; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function MatrixOptions() { } if (false) { /** @type {?} */ MatrixOptions.prototype.height; /** @type {?} */ MatrixOptions.prototype.width; /** @type {?} */ MatrixOptions.prototype.initialDate; /** @type {?} */ MatrixOptions.prototype.shift; } /** * @template T * @param {?} options * @param {?} fn * @return {?} */ function createMatrix(options, fn) { /** @type {?} */ let prevValue = options.initialDate; /** @type {?} */ const matrix = new Array(options.height); for (let i = 0; i < options.height; i++) { matrix[i] = new Array(options.width); for (let j = 0; j < options.width; j++) { matrix[i][j] = fn(prevValue); prevValue = shiftDate(prevValue, options.shift); } } return matrix; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} startingDate * @param {?} options * @return {?} */ function calcDaysCalendar(startingDate, options) { /** @type {?} */ const firstDay = getFirstDayOfMonth(startingDate); /** @type {?} */ const initialDate = getStartingDayOfCalendar(firstDay, options); /** @type {?} */ const matrixOptions = { width: options.width, height: options.height, initialDate, shift: { day: 1 } }; /** @type {?} */ const daysMatrix = createMatrix(matrixOptions, (/** * @param {?} date * @return {?} */ date => date)); return { daysMatrix, month: firstDay }; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} daysCalendar * @param {?} formatOptions * @param {?} monthIndex * @return {?} */ function formatDaysCalendar(daysCalendar, formatOptions, monthIndex) { return { month: daysCalendar.month, monthTitle: formatDate(daysCalendar.month, formatOptions.monthTitle, formatOptions.locale), yearTitle: formatDate(daysCalendar.month, formatOptions.yearTitle, formatOptions.locale), weekNumbers: getWeekNumbers(daysCalendar.daysMatrix, formatOptions.weekNumbers, formatOptions.locale), weekdays: getShiftedWeekdays(formatOptions.locale), weeks: daysCalendar.daysMatrix.map((/** * @param {?} week * @param {?} weekIndex * @return {?} */ (week, weekIndex) => ({ days: week.map((/** * @param {?} date * @param {?} dayIndex * @return {?} */ (date, dayIndex) => ({ date, label: formatDate(date, formatOptions.dayLabel, formatOptions.locale), monthIndex, weekIndex, dayIndex }))) }))) }; } /** * @param {?} daysMatrix * @param {?} format * @param {?} locale * @return {?} */ function getWeekNumbers(daysMatrix, format, locale) { return daysMatrix.map((/** * @param {?} days * @return {?} */ (days) => (days[0] ? formatDate(days[0], format, locale) : ''))); } /** * @param {?} locale * @return {?} */ function getShiftedWeekdays(locale) { /** @type {?} */ const _locale = getLocale(locale); /** @type {?} */ const weekdays = (/** @type {?} */ (_locale.weekdaysShort())); /** @type {?} */ const firstDayOfWeek = _locale.firstDayOfWeek(); return [...weekdays.slice(firstDayOfWeek), ...weekdays.slice(0, firstDayOfWeek)]; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function FlagDaysCalendarOptions() { } if (false) { /** @type {?} */ FlagDaysCalendarOptions.prototype.isDisabled; /** @type {?} */ FlagDaysCalendarOptions.prototype.minDate; /** @type {?} */ FlagDaysCalendarOptions.prototype.maxDate; /** @type {?} */ FlagDaysCalendarOptions.prototype.daysDisabled; /** @type {?} */ FlagDaysCalendarOptions.prototype.datesDisabled; /** @type {?} */ FlagDaysCalendarOptions.prototype.datesEnabled; /** @type {?} */ FlagDaysCalendarOptions.prototype.hoveredDate; /** @type {?} */ FlagDaysCalendarOptions.prototype.selectedDate; /** @type {?} */ FlagDaysCalendarOptions.prototype.selectedRange; /** @type {?} */ FlagDaysCalendarOptions.prototype.displayMonths; /** @type {?} */ FlagDaysCalendarOptions.prototype.monthIndex; /** @type {?} */ FlagDaysCalendarOptions.prototype.dateCustomClasses; /** @type {?} */ FlagDaysCalendarOptions.prototype.dateTooltipTexts; } /** * @param {?} formattedMonth * @param {?} options * @return {?} */ function flagDaysCalendar(formattedMonth, options) { formattedMonth.weeks.forEach((/** * @param {?} week * @return {?} */ (week) => { /* tslint:disable-next-line: cyclomatic-complexity */ week.days.forEach((/** * @param {?} day * @param {?} dayIndex * @return {?} */ (day, dayIndex) => { // datepicker /** @type {?} */ const isOtherMonth = !isSameMonth(day.date, formattedMonth.month); /** @type {?} */ const isHovered = !isOtherMonth && isSameDay(day.date, options.hoveredDate); // date range picker /** @type {?} */ const isSelectionStart = !isOtherMonth && options.selectedRange && isSameDay(day.date, options.selectedRange[0]); /** @type {?} */ const isSelectionEnd = !isOtherMonth && options.selectedRange && isSameDay(day.date, options.selectedRange[1]); /** @type {?} */ const isSelected = (!isOtherMonth && isSameDay(day.date, options.selectedDate)) || isSelectionStart || isSelectionEnd; /** @type {?} */ const isInRange = !isOtherMonth && options.selectedRange && isDateInRange(day.date, options.selectedRange, options.hoveredDate); /** @type {?} */ const isDisabled = options.isDisabled || isBefore(day.date, options.minDate, 'day') || isAfter(day.date, options.maxDate, 'day') || isDisabledDay(day.date, options.daysDisabled) || isDisabledDate(day.date, options.datesDisabled) || isEnabledDate(day.date, options.datesEnabled); /** @type {?} */ const currentDate = new Date(); /** @type {?} */ const isToday = !isOtherMonth && isSameDay(day.date, currentDate); /** @type {?} */ const customClasses = options.dateCustomClasses && options.dateCustomClasses .map((/** * @param {?} dcc * @return {?} */ dcc => isSameDay(day.date, dcc.date) ? dcc.classes : [])) .reduce((/** * @param {?} previousValue * @param {?} currentValue * @return {?} */ (previousValue, currentValue) => previousValue.concat(currentValue)), []) .join(' ') || ''; /** @type {?} */ const tooltipText = options.dateTooltipTexts && options.dateTooltipTexts .map((/** * @param {?} tt * @return {?} */ tt => isSameDay(day.date, tt.date) ? tt.tooltipText : '')) .reduce((/** * @param {?} previousValue * @param {?} currentValue * @return {?} */ (previousValue, currentValue) => previousValue.concat(currentValue)), []) .join(' ') || ''; // decide update or not /** @type {?} */ const newDay = Object.assign({}, day, { isOtherMonth, isHovered, isSelected, isSelectionStart, isSelectionEnd, isInRange, isDisabled, isToday, customClasses, tooltipText }); if (day.isOtherMonth !== newDay.isOtherMonth || day.isHovered !== newDay.isHovered || day.isSelected !== newDay.isSelected || day.isSelectionStart !== newDay.isSelectionStart || day.isSelectionEnd !== newDay.isSelectionEnd || day.isDisabled !== newDay.isDisabled || day.isInRange !== newDay.isInRange || day.customClasses !== newDay.customClasses || day.tooltipText !== newDay.tooltipText) { week.days[dayIndex] = newDay; } })); })); // todo: add check for linked calendars formattedMonth.hideLeftArrow = options.isDisabled || (options.monthIndex > 0 && options.monthIndex !== options.displayMonths); formattedMonth.hideRightArrow = options.isDisabled || (options.monthIndex < options.displayMonths && options.monthIndex + 1 !== options.displayMonths); formattedMonth.disableLeftArrow = isMonthDisabled(shiftDate(formattedMonth.month, { month: -1 }), options.minDate, options.maxDate); formattedMonth.disableRightArrow = isMonthDisabled(shiftDate(formattedMonth.month, { month: 1 }), options.minDate, options.maxDate); return formattedMonth; } /** * @param {?} date * @param {?} selectedRange * @param {?} hoveredDate * @return {?} */ function isDateInRange(date, selectedRange, hoveredDate) { if (!date || !selectedRange[0]) { return false; } if (selectedRange[1]) { return date > selectedRange[0] && date <= selectedRange[1]; } if (hoveredDate) { return date > selectedRange[0] && date <= hoveredDate; } return false; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} mode * @param {?=} minMode * @return {?} */ function canSwitchMode(mode, minMode) { return minMode ? mode >= minMode : true; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const height = 4; /** @type {?} */ const width = 3; /** @type {?} */ const shift = { month: 1 }; /** * @param {?} viewDate * @param {?} formatOptions * @return {?} */ function formatMonthsCalendar(viewDate, formatOptions) { /** @type {?} */ const initialDate = startOf(viewDate, 'year'); /** @type {?} */ const matrixOptions = { width, height, initialDate, shift }; /** @type {?} */ const monthMatrix = createMatrix(matrixOptions, (/** * @param {?} date * @return {?} */ date => ({ date, label: formatDate(date, formatOptions.monthLabel, formatOptions.locale) }))); return { months: monthMatrix, monthTitle: '', yearTitle: formatDate(viewDate, formatOptions.yearTitle, formatOptions.locale) }; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @record */ function FlagMonthCalendarOptions() { } if (false) { /** @type {?} */ FlagMonthCalendarOptions.prototype.isDisabled; /** @type {?} */ FlagMonthCalendarOptions.prototype.minDate; /** @type {?} */ FlagMonthCalendarOptions.prototype.maxDate; /** @type {?} */ FlagMonthCalendarOptions.prototype.hoveredMonth; /** @type {?} */ FlagMonthCalendarOptions.prototype.selectedDate; /** @type {?} */ FlagMonthCalendarOptions.prototype.selectedRange; /** @type {?} */ FlagMonthCalendarOptions.prototype.displayMonths; /** @type {?} *