ngx-bootstrap-fix-datepicker
Version:
Native Angular Bootstrap Components
1,761 lines (1,748 loc) • 262 kB
JavaScript
import { Injectable, EventEmitter, Component, Renderer2, ElementRef, Directive, ViewContainerRef, Input, Output, forwardRef, Host, ChangeDetectorRef, ChangeDetectionStrategy, NgModule, ViewChild } from '@angular/core';
import { __values, __spread, __extends } from 'tslib';
import { filter, map, take, takeUntil } from 'rxjs/operators';
import { getMonth, getFullYear, isFirstDayOfWeek, getDay, shiftDate, isBefore, endOf, isAfter, startOf, isArray, isSame, getFirstDayOfMonth, formatDate, getLocale, isSameMonth, isSameDay, isDisabledDay, isSameYear, isDateValid, setFullDate, isDate, parseDate, utcAsLocal } from 'ngx-bootstrap/chronos';
import { BehaviorSubject, Subject, Subscription } from 'rxjs';
import { MiniState, MiniStore } from 'ngx-bootstrap/mini-ngrx';
import { PositioningService } from 'ngx-bootstrap/positioning';
import { trigger, state, style, transition, animate } from '@angular/animations';
import { ComponentLoaderFactory } from 'ngx-bootstrap/component-loader';
import { NG_VALUE_ACCESSOR, NG_VALIDATORS, FormsModule } from '@angular/forms';
import { CommonModule } from '@angular/common';
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`
*/
var BsDatepickerConfig = /** @class */ (function () {
function BsDatepickerConfig() {
/**
* 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';
}
BsDatepickerConfig.decorators = [
{ type: Injectable }
];
return BsDatepickerConfig;
}());
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;
/**
* 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;
/** @type {?} */
BsDatepickerConfig.prototype.monthTitle;
/** @type {?} */
BsDatepickerConfig.prototype.yearTitle;
/** @type {?} */
BsDatepickerConfig.prototype.dayLabel;
/** @type {?} */
BsDatepickerConfig.prototype.monthLabel;
/** @type {?} */
BsDatepickerConfig.prototype.yearLabel;
/** @type {?} */
BsDatepickerConfig.prototype.weekNumbers;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @abstract
*/
var /**
* @abstract
*/
BsDatepickerAbstractComponent = /** @class */ (function () {
function BsDatepickerAbstractComponent() {
this.customRanges = [];
this.chosenRange = [];
}
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "minDate", {
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._effects.setMinDate(value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "maxDate", {
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._effects.setMaxDate(value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "daysDisabled", {
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._effects.setDaysDisabled(value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "datesDisabled", {
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._effects.setDatesDisabled(value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "datesEnabled", {
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._effects.setDatesEnabled(value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "isDisabled", {
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._effects.setDisabled(value);
},
enumerable: true,
configurable: true
});
Object.defineProperty(BsDatepickerAbstractComponent.prototype, "dateCustomClasses", {
set: /**
* @param {?} value
* @return {?}
*/
function (value) {
this._effects.setDateCustomClasses(value);
},
enumerable: true,
configurable: true
});
/**
* @param {?} event
* @return {?}
*/
BsDatepickerAbstractComponent.prototype.setViewMode = /**
* @param {?} event
* @return {?}
*/
function (event) { };
/**
* @param {?} event
* @return {?}
*/
BsDatepickerAbstractComponent.prototype.navigateTo = /**
* @param {?} event
* @return {?}
*/
function (event) { };
/**
* @param {?} event
* @return {?}
*/
BsDatepickerAbstractComponent.prototype.dayHoverHandler = /**
* @param {?} event
* @return {?}
*/
function (event) { };
/**
* @param {?} event
* @return {?}
*/
BsDatepickerAbstractComponent.prototype.weekHoverHandler = /**
* @param {?} event
* @return {?}
*/
function (event) { };
/**
* @param {?} event
* @return {?}
*/
BsDatepickerAbstractComponent.prototype.monthHoverHandler = /**
* @param {?} event
* @return {?}
*/
function (event) { };
/**
* @param {?} event
* @return {?}
*/
BsDatepickerAbstractComponent.prototype.yearHoverHandler = /**
* @param {?} event
* @return {?}
*/
function (event) { };
/**
* @param {?} day
* @return {?}
*/
BsDatepickerAbstractComponent.prototype.daySelectHandler = /**
* @param {?} day
* @return {?}
*/
function (day) { };
/**
* @param {?} event
* @return {?}
*/
BsDatepickerAbstractComponent.prototype.monthSelectHandler = /**
* @param {?} event
* @return {?}
*/
function (event) { };
/**
* @param {?} event
* @return {?}
*/
BsDatepickerAbstractComponent.prototype.yearSelectHandler = /**
* @param {?} event
* @return {?}
*/
function (event) { };
/**
* @param {?} dates
* @return {?}
*/
BsDatepickerAbstractComponent.prototype.setRangeOnCalendar = /**
* @param {?} dates
* @return {?}
*/
function (dates) { };
/* tslint:disable-next-line: no-any */
/* tslint:disable-next-line: no-any */
/**
* @param {?} event
* @return {?}
*/
BsDatepickerAbstractComponent.prototype._stopPropagation = /* tslint:disable-next-line: no-any */
/**
* @param {?} event
* @return {?}
*/
function (event) {
event.stopPropagation();
};
return BsDatepickerAbstractComponent;
}());
if (false) {
/** @type {?} */
BsDatepickerAbstractComponent.prototype.containerClass;
/** @type {?} */
BsDatepickerAbstractComponent.prototype.isOtherMonthsActive;
/** @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
*/
var BsDatepickerActions = /** @class */ (function () {
function BsDatepickerActions() {
}
/**
* @return {?}
*/
BsDatepickerActions.prototype.calculate = /**
* @return {?}
*/
function () {
return { type: BsDatepickerActions.CALCULATE };
};
/**
* @return {?}
*/
BsDatepickerActions.prototype.format = /**
* @return {?}
*/
function () {
return { type: BsDatepickerActions.FORMAT };
};
/**
* @return {?}
*/
BsDatepickerActions.prototype.flag = /**
* @return {?}
*/
function () {
return { type: BsDatepickerActions.FLAG };
};
/**
* @param {?} date
* @return {?}
*/
BsDatepickerActions.prototype.select = /**
* @param {?} date
* @return {?}
*/
function (date) {
return {
type: BsDatepickerActions.SELECT,
payload: date
};
};
/**
* @param {?} event
* @return {?}
*/
BsDatepickerActions.prototype.changeViewMode = /**
* @param {?} event
* @return {?}
*/
function (event) {
return {
type: BsDatepickerActions.CHANGE_VIEWMODE,
payload: event
};
};
/**
* @param {?} event
* @return {?}
*/
BsDatepickerActions.prototype.navigateTo = /**
* @param {?} event
* @return {?}
*/
function (event) {
return {
type: BsDatepickerActions.NAVIGATE_TO,
payload: event
};
};
/**
* @param {?} step
* @return {?}
*/
BsDatepickerActions.prototype.navigateStep = /**
* @param {?} step
* @return {?}
*/
function (step) {
return {
type: BsDatepickerActions.NAVIGATE_OFFSET,
payload: step
};
};
/**
* @param {?} options
* @return {?}
*/
BsDatepickerActions.prototype.setOptions = /**
* @param {?} options
* @return {?}
*/
function (options) {
return {
type: BsDatepickerActions.SET_OPTIONS,
payload: options
};
};
// date range picker
// date range picker
/**
* @param {?} value
* @return {?}
*/
BsDatepickerActions.prototype.selectRange =
// date range picker
/**
* @param {?} value
* @return {?}
*/
function (value) {
return {
type: BsDatepickerActions.SELECT_RANGE,
payload: value
};
};
/**
* @param {?} event
* @return {?}
*/
BsDatepickerActions.prototype.hoverDay = /**
* @param {?} event
* @return {?}
*/
function (event) {
return {
type: BsDatepickerActions.HOVER,
payload: event.isHovered ? event.cell.date : null
};
};
/**
* @param {?} date
* @return {?}
*/
BsDatepickerActions.prototype.minDate = /**
* @param {?} date
* @return {?}
*/
function (date) {
return {
type: BsDatepickerActions.SET_MIN_DATE,
payload: date
};
};
/**
* @param {?} date
* @return {?}
*/
BsDatepickerActions.prototype.maxDate = /**
* @param {?} date
* @return {?}
*/
function (date) {
return {
type: BsDatepickerActions.SET_MAX_DATE,
payload: date
};
};
/**
* @param {?} days
* @return {?}
*/
BsDatepickerActions.prototype.daysDisabled = /**
* @param {?} days
* @return {?}
*/
function (days) {
return {
type: BsDatepickerActions.SET_DAYSDISABLED,
payload: days
};
};
/**
* @param {?} dates
* @return {?}
*/
BsDatepickerActions.prototype.datesDisabled = /**
* @param {?} dates
* @return {?}
*/
function (dates) {
return {
type: BsDatepickerActions.SET_DATESDISABLED,
payload: dates
};
};
/**
* @param {?} dates
* @return {?}
*/
BsDatepickerActions.prototype.datesEnabled = /**
* @param {?} dates
* @return {?}
*/
function (dates) {
return {
type: BsDatepickerActions.SET_DATESENABLED,
payload: dates
};
};
/**
* @param {?} value
* @return {?}
*/
BsDatepickerActions.prototype.isDisabled = /**
* @param {?} value
* @return {?}
*/
function (value) {
return {
type: BsDatepickerActions.SET_IS_DISABLED,
payload: value
};
};
/**
* @param {?} value
* @return {?}
*/
BsDatepickerActions.prototype.setDateCustomClasses = /**
* @param {?} value
* @return {?}
*/
function (value) {
return {
type: BsDatepickerActions.SET_DATE_CUSTOM_CLASSES,
payload: value
};
};
/**
* @param {?} locale
* @return {?}
*/
BsDatepickerActions.prototype.setLocale = /**
* @param {?} locale
* @return {?}
*/
function (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_LOCALE = '[datepicker] set datepicker locale';
BsDatepickerActions.SELECT_RANGE = '[daterangepicker] select dates range';
BsDatepickerActions.decorators = [
{ type: Injectable }
];
return BsDatepickerActions;
}());
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_LOCALE;
/** @type {?} */
BsDatepickerActions.SELECT_RANGE;
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var BsLocaleService = /** @class */ (function () {
function BsLocaleService() {
this._defaultLocale = 'en';
this._locale = new BehaviorSubject(this._defaultLocale);
this._localeChange = this._locale.asObservable();
}
Object.defineProperty(BsLocaleService.prototype, "locale", {
get: /**
* @return {?}
*/
function () {
return this._locale;
},
enumerable: true,
configurable: true
});
Object.defineProperty(BsLocaleService.prototype, "localeChange", {
get: /**
* @return {?}
*/
function () {
return this._localeChange;
},
enumerable: true,
configurable: true
});
Object.defineProperty(BsLocaleService.prototype, "currentLocale", {
get: /**
* @return {?}
*/
function () {
return this._locale.getValue();
},
enumerable: true,
configurable: true
});
/**
* @param {?} locale
* @return {?}
*/
BsLocaleService.prototype.use = /**
* @param {?} locale
* @return {?}
*/
function (locale) {
if (locale === this.currentLocale) {
return;
}
this._locale.next(locale);
};
BsLocaleService.decorators = [
{ type: Injectable }
];
return BsLocaleService;
}());
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
*/
var BsDatepickerEffects = /** @class */ (function () {
function BsDatepickerEffects(_actions, _localeService) {
this._actions = _actions;
this._localeService = _localeService;
this._subs = [];
}
/**
* @param {?} _bsDatepickerStore
* @return {?}
*/
BsDatepickerEffects.prototype.init = /**
* @param {?} _bsDatepickerStore
* @return {?}
*/
function (_bsDatepickerStore) {
this._store = _bsDatepickerStore;
return this;
};
/** setters */
/**
* setters
* @param {?} value
* @return {?}
*/
BsDatepickerEffects.prototype.setValue = /**
* setters
* @param {?} value
* @return {?}
*/
function (value) {
this._store.dispatch(this._actions.select(value));
};
/**
* @param {?} value
* @return {?}
*/
BsDatepickerEffects.prototype.setRangeValue = /**
* @param {?} value
* @return {?}
*/
function (value) {
this._store.dispatch(this._actions.selectRange(value));
};
/**
* @param {?} value
* @return {?}
*/
BsDatepickerEffects.prototype.setMinDate = /**
* @param {?} value
* @return {?}
*/
function (value) {
this._store.dispatch(this._actions.minDate(value));
return this;
};
/**
* @param {?} value
* @return {?}
*/
BsDatepickerEffects.prototype.setMaxDate = /**
* @param {?} value
* @return {?}
*/
function (value) {
this._store.dispatch(this._actions.maxDate(value));
return this;
};
/**
* @param {?} value
* @return {?}
*/
BsDatepickerEffects.prototype.setDaysDisabled = /**
* @param {?} value
* @return {?}
*/
function (value) {
this._store.dispatch(this._actions.daysDisabled(value));
return this;
};
/**
* @param {?} value
* @return {?}
*/
BsDatepickerEffects.prototype.setDatesDisabled = /**
* @param {?} value
* @return {?}
*/
function (value) {
this._store.dispatch(this._actions.datesDisabled(value));
return this;
};
/**
* @param {?} value
* @return {?}
*/
BsDatepickerEffects.prototype.setDatesEnabled = /**
* @param {?} value
* @return {?}
*/
function (value) {
this._store.dispatch(this._actions.datesEnabled(value));
return this;
};
/**
* @param {?} value
* @return {?}
*/
BsDatepickerEffects.prototype.setDisabled = /**
* @param {?} value
* @return {?}
*/
function (value) {
this._store.dispatch(this._actions.isDisabled(value));
return this;
};
/**
* @param {?} value
* @return {?}
*/
BsDatepickerEffects.prototype.setDateCustomClasses = /**
* @param {?} value
* @return {?}
*/
function (value) {
this._store.dispatch(this._actions.setDateCustomClasses(value));
return this;
};
/* Set rendering options */
/* Set rendering options */
/**
* @param {?} _config
* @return {?}
*/
BsDatepickerEffects.prototype.setOptions = /* Set rendering options */
/**
* @param {?} _config
* @return {?}
*/
function (_config) {
/** @type {?} */
var _options = Object.assign({ locale: this._localeService.currentLocale }, _config);
this._store.dispatch(this._actions.setOptions(_options));
return this;
};
/** view to mode bindings */
/**
* view to mode bindings
* @param {?} container
* @return {?}
*/
BsDatepickerEffects.prototype.setBindings = /**
* view to mode bindings
* @param {?} container
* @return {?}
*/
function (container) {
container.daysCalendar = this._store
.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.flaggedMonths; }))
.pipe(filter((/**
* @param {?} months
* @return {?}
*/
function (months) { return !!months; })));
// month calendar
container.monthsCalendar = this._store
.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.flaggedMonthsCalendar; }))
.pipe(filter((/**
* @param {?} months
* @return {?}
*/
function (months) { return !!months; })));
// year calendar
container.yearsCalendar = this._store
.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.yearsCalendarFlagged; }))
.pipe(filter((/**
* @param {?} years
* @return {?}
*/
function (years) { return !!years; })));
container.viewMode = this._store.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.view.mode; }));
container.options = this._store
.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.showWeekNumbers; }))
.pipe(map((/**
* @param {?} showWeekNumbers
* @return {?}
*/
function (showWeekNumbers) { return ({ showWeekNumbers: showWeekNumbers }); })));
return this;
};
/** event handlers */
/**
* event handlers
* @param {?} container
* @return {?}
*/
BsDatepickerEffects.prototype.setEventHandlers = /**
* event handlers
* @param {?} container
* @return {?}
*/
function (container) {
var _this = this;
container.setViewMode = (/**
* @param {?} event
* @return {?}
*/
function (event) {
_this._store.dispatch(_this._actions.changeViewMode(event));
});
container.navigateTo = (/**
* @param {?} event
* @return {?}
*/
function (event) {
_this._store.dispatch(_this._actions.navigateStep(event.step));
});
container.dayHoverHandler = (/**
* @param {?} event
* @return {?}
*/
function (event) {
/** @type {?} */
var _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 {?}
*/
function (event) {
event.cell.isHovered = event.isHovered;
});
container.yearHoverHandler = (/**
* @param {?} event
* @return {?}
*/
function (event) {
event.cell.isHovered = event.isHovered;
});
container.monthSelectHandler = (/**
* @param {?} event
* @return {?}
*/
function (event) {
if (event.isDisabled) {
return;
}
_this._store.dispatch(_this._actions.navigateTo({
unit: {
month: getMonth(event.date),
year: getFullYear(event.date)
},
viewMode: 'day'
}));
});
container.yearSelectHandler = (/**
* @param {?} event
* @return {?}
*/
function (event) {
if (event.isDisabled) {
return;
}
_this._store.dispatch(_this._actions.navigateTo({
unit: {
year: getFullYear(event.date)
},
viewMode: 'month'
}));
});
return this;
};
/**
* @return {?}
*/
BsDatepickerEffects.prototype.registerDatepickerSideEffects = /**
* @return {?}
*/
function () {
var _this = this;
this._subs.push(this._store.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.view; })).subscribe((/**
* @param {?} view
* @return {?}
*/
function (view) {
_this._store.dispatch(_this._actions.calculate());
})));
// format calendar values on month model change
this._subs.push(this._store
.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.monthsModel; }))
.pipe(filter((/**
* @param {?} monthModel
* @return {?}
*/
function (monthModel) { return !!monthModel; })))
.subscribe((/**
* @param {?} month
* @return {?}
*/
function (month) { return _this._store.dispatch(_this._actions.format()); })));
// flag day values
this._subs.push(this._store
.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.formattedMonths; }))
.pipe(filter((/**
* @param {?} month
* @return {?}
*/
function (month) { return !!month; })))
.subscribe((/**
* @param {?} month
* @return {?}
*/
function (month) { return _this._store.dispatch(_this._actions.flag()); })));
// flag day values
this._subs.push(this._store
.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.selectedDate; }))
.pipe(filter((/**
* @param {?} selectedDate
* @return {?}
*/
function (selectedDate) { return !!selectedDate; })))
.subscribe((/**
* @param {?} selectedDate
* @return {?}
*/
function (selectedDate) { return _this._store.dispatch(_this._actions.flag()); })));
// flag for date range picker
this._subs.push(this._store
.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.selectedRange; }))
.pipe(filter((/**
* @param {?} selectedRange
* @return {?}
*/
function (selectedRange) { return !!selectedRange; })))
.subscribe((/**
* @param {?} selectedRange
* @return {?}
*/
function (selectedRange) { return _this._store.dispatch(_this._actions.flag()); })));
// monthsCalendar
this._subs.push(this._store
.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.monthsCalendar; }))
.subscribe((/**
* @return {?}
*/
function () { return _this._store.dispatch(_this._actions.flag()); })));
// years calendar
this._subs.push(this._store
.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.yearsCalendarModel; }))
.pipe(filter((/**
* @param {?} state
* @return {?}
*/
function (state) { return !!state; })))
.subscribe((/**
* @return {?}
*/
function () { return _this._store.dispatch(_this._actions.flag()); })));
// on hover
this._subs.push(this._store
.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.hoveredDate; }))
.pipe(filter((/**
* @param {?} hoveredDate
* @return {?}
*/
function (hoveredDate) { return !!hoveredDate; })))
.subscribe((/**
* @param {?} hoveredDate
* @return {?}
*/
function (hoveredDate) { return _this._store.dispatch(_this._actions.flag()); })));
// date custom classes
this._subs.push(this._store
.select((/**
* @param {?} state
* @return {?}
*/
function (state) { return state.dateCustomClasses; }))
.pipe(filter((/**
* @param {?} dateCustomClasses
* @return {?}
*/
function (dateCustomClasses) { return !!dateCustomClasses; })))
.subscribe((/**
* @param {?} dateCustomClasses
* @return {?}
*/
function (dateCustomClasses) { return _this._store.dispatch(_this._actions.flag()); })));
// on locale change
this._subs.push(this._localeService.localeChange
.subscribe((/**
* @param {?} locale
* @return {?}
*/
function (locale) { return _this._store.dispatch(_this._actions.setLocale(locale)); })));
return this;
};
/**
* @return {?}
*/
BsDatepickerEffects.prototype.destroy = /**
* @return {?}
*/
function () {
var e_1, _a;
try {
for (var _b = __values(this._subs), _c = _b.next(); !_c.done; _c = _b.next()) {
var sub = _c.value;
sub.unsubscribe();
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
};
BsDatepickerEffects.decorators = [
{ type: Injectable }
];
/** @nocollapse */
BsDatepickerEffects.ctorParameters = function () { return [
{ type: BsDatepickerActions },
{ type: BsLocaleService }
]; };
return BsDatepickerEffects;
}());
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 {?} */
var 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;
}
var BsDatepickerState = /** @class */ (function () {
function BsDatepickerState() {
}
return 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.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 {?} */
var _initialView = { date: new Date(), mode: 'day' };
/** @type {?} */
var 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 {?} */
var weekDay = getDay(date);
/** @type {?} */
var 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 {?} */
var offset = weekday - startingDayOffset % 7;
return offset < 0 ? offset + 7 : offset;
}
/**
* @param {?} date
* @param {?} min
* @param {?} max
* @return {?}
*/
function isMonthDisabled(date, min, max) {
/** @type {?} */
var minBound = min && isBefore(endOf(date, 'month'), min, 'day');
/** @type {?} */
var maxBound = max && isAfter(startOf(date, 'month'), max, 'day');
return minBound || maxBound;
}
/**
* @param {?} date
* @param {?} min
* @param {?} max
* @return {?}
*/
function isYearDisabled(date, min, max) {
/** @type {?} */
var minBound = min && isBefore(endOf(date, 'year'), min, 'day');
/** @type {?} */
var 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 {?}
*/
function (dateDisabled) { return 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 {?}
*/
function (enabledDate) { return isSame(date, enabledDate, 'date'); }));
}
/**
* @param {?} state
* @param {?=} calendarIndex
* @return {?}
*/
function getYearsCalendarInitialDate(state, calendarIndex) {
if (calendarIndex === void 0) { calendarIndex = 0; }
/** @type {?} */
var 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 {?} */
var prevValue = options.initialDate;
/** @type {?} */
var matrix = new Array(options.height);
for (var i = 0; i < options.height; i++) {
matrix[i] = new Array(options.width);
for (var 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 {?} */
var firstDay = getFirstDayOfMonth(startingDate);
/** @type {?} */
var initialDate = getStartingDayOfCalendar(firstDay, options);
/** @type {?} */
var matrixOptions = {
width: options.width,
height: options.height,
initialDate: initialDate,
shift: { day: 1 }
};
/** @type {?} */
var daysMatrix = createMatrix(matrixOptions, (/**
* @param {?} date
* @return {?}
*/
function (date) { return date; }));
return {
daysMatrix: 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 {?}
*/
function (week, weekIndex) { return ({
days: week.map((/**
* @param {?} date
* @param {?} dayIndex
* @return {?}
*/
function (date, dayIndex) { return ({
date: date,
label: formatDate(date, formatOptions.dayLabel, formatOptions.locale),
monthIndex: monthIndex,
weekIndex: weekIndex,
dayIndex: dayIndex
}); }))
}); }))
};
}
/**
* @param {?} daysMatrix
* @param {?} format
* @param {?} locale
* @return {?}
*/
function getWeekNumbers(daysMatrix, format, locale) {
return daysMatrix.map((/**
* @param {?} days
* @return {?}
*/
function (days) { return (days[0] ? formatDate(days[0], format, locale) : ''); }));
}
/**
* @param {?} locale
* @return {?}
*/
function getShiftedWeekdays(locale) {
/** @type {?} */
var _locale = getLocale(locale);
/** @type {?} */
var weekdays = (/** @type {?} */ (_locale.weekdaysShort()));
/** @type {?} */
var firstDayOfWeek = _locale.firstDayOfWeek();
return __spread(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;
}
/**
* @param {?} formattedMonth
* @param {?} options
* @return {?}
*/
function flagDaysCalendar(formattedMonth, options) {
formattedMonth.weeks.forEach((/**
* @param {?} week
* @return {?}
*/
function (week) {
/* tslint:disable-next-line: cyclomatic-complexity */
week.days.forEach((/**
* @param {?} day
* @param {?} dayIndex
* @return {?}
*/
function (day, dayIndex) {
// datepicker
/** @type {?} */
var isOtherMonth = !isSameMonth(day.date, formattedMonth.month);
/** @type {?} */
var isHovered = !isOtherMonth && isSameDay(day.date, options.hoveredDate);
// date range picker
/** @type {?} */
var isSelectionStart = !isOtherMonth &&
options.selectedRange &&
isSameDay(day.date, options.selectedRange[0]);
/** @type {?} */
var isSelectionEnd = !isOtherMonth &&
options.selectedRange &&
isSameDay(day.date, options.selectedRange[1]);
/** @type {?} */
var isSelected = (!isOtherMonth && isSameDay(day.date, options.selectedDate)) ||
isSelectionStart ||
isSelectionEnd;
/** @type {?} */
var isInRange = !isOtherMonth &&
options.selectedRange &&
isDateInRange(day.date, options.selectedRange, options.hoveredDate);
/** @type {?} */
var 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);