UNPKG

ngx-bootstrap

Version:
1,370 lines (1,350 loc) 210 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('ngx-bootstrap/mini-ngrx'), require('rxjs'), require('ngx-bootstrap/positioning'), require('ngx-bootstrap/component-loader'), require('rxjs/operators'), require('ngx-bootstrap/chronos'), require('@angular/common'), require('@angular/forms'), require('@angular/core'), require('ngx-bootstrap/utils')) : typeof define === 'function' && define.amd ? define('ngx-bootstrap/datepicker', ['exports', 'ngx-bootstrap/mini-ngrx', 'rxjs', 'ngx-bootstrap/positioning', 'ngx-bootstrap/component-loader', 'rxjs/operators', 'ngx-bootstrap/chronos', '@angular/common', '@angular/forms', '@angular/core', 'ngx-bootstrap/utils'], factory) : (factory((global['ngx-bootstrap'] = global['ngx-bootstrap'] || {}, global['ngx-bootstrap'].datepicker = {}),global.miniNgrx,global.rxjs,global.positioning,global.componentLoader,global.rxjs.operators,global.chronos,global.ng.common,global.ng.forms,global.ng.core,global.utils)); }(this, (function (exports,miniNgrx,rxjs,positioning,componentLoader,operators,chronos,common,forms,core,utils) { 'use strict'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,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; /** * 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: core.Injectable } ]; return BsDatepickerConfig; }()); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @abstract */ var /** * @abstract */ BsDatepickerAbstractComponent = /** @class */ (function () { function BsDatepickerAbstractComponent() { this._customRangesFish = []; } 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, "isDisabled", { set: /** * @param {?} value * @return {?} */ function (value) { this._effects.setDisabled(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) { }; /* 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; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,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 {?} value * @return {?} */ BsDatepickerActions.prototype.isDisabled = /** * @param {?} value * @return {?} */ function (value) { return { type: BsDatepickerActions.SET_IS_DISABLED, 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_IS_DISABLED = '[datepicker] set is disabled'; BsDatepickerActions.SET_LOCALE = '[datepicker] set datepicker locale'; BsDatepickerActions.SELECT_RANGE = '[daterangepicker] select dates range'; BsDatepickerActions.decorators = [ { type: core.Injectable } ]; return BsDatepickerActions; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var BsLocaleService = /** @class */ (function () { function BsLocaleService() { this._defaultLocale = 'en'; this._locale = new rxjs.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: core.Injectable } ]; return BsLocaleService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,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; }; /** * @template THIS * @this {THIS} * @param {?} value * @return {THIS} */ BsDatepickerEffects.prototype.setDaysDisabled = /** * @template THIS * @this {THIS} * @param {?} value * @return {THIS} */ function (value) { ( /** @type {?} */(this))._store.dispatch(( /** @type {?} */(this))._actions.daysDisabled(value)); return ( /** @type {?} */(this)); }; /** * @template THIS * @this {THIS} * @param {?} value * @return {THIS} */ BsDatepickerEffects.prototype.setDatesDisabled = /** * @template THIS * @this {THIS} * @param {?} value * @return {THIS} */ function (value) { ( /** @type {?} */(this))._store.dispatch(( /** @type {?} */(this))._actions.datesDisabled(value)); return ( /** @type {?} */(this)); }; /** * @param {?} value * @return {?} */ BsDatepickerEffects.prototype.setDisabled = /** * @param {?} value * @return {?} */ function (value) { this._store.dispatch(this._actions.isDisabled(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(function (state) { return state.flaggedMonths; }) .pipe(operators.filter(function (months) { return !!months; })); // month calendar container.monthsCalendar = this._store .select(function (state) { return state.flaggedMonthsCalendar; }) .pipe(operators.filter(function (months) { return !!months; })); // year calendar container.yearsCalendar = this._store .select(function (state) { return state.yearsCalendarFlagged; }) .pipe(operators.filter(function (years) { return !!years; })); container.viewMode = this._store.select(function (state) { return state.view.mode; }); container.options = this._store .select(function (state) { return state.showWeekNumbers; }) .pipe(operators.map(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 = function (event) { _this._store.dispatch(_this._actions.changeViewMode(event)); }; container.navigateTo = function (event) { _this._store.dispatch(_this._actions.navigateStep(event.step)); }; container.dayHoverHandler = 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 = function (event) { event.cell.isHovered = event.isHovered; }; container.yearHoverHandler = function (event) { event.cell.isHovered = event.isHovered; }; container.monthSelectHandler = function (event) { if (event.isDisabled) { return; } _this._store.dispatch(_this._actions.navigateTo({ unit: { month: chronos.getMonth(event.date), year: chronos.getFullYear(event.date) }, viewMode: 'day' })); }; container.yearSelectHandler = function (event) { if (event.isDisabled) { return; } _this._store.dispatch(_this._actions.navigateTo({ unit: { year: chronos.getFullYear(event.date) }, viewMode: 'month' })); }; return this; }; /** * @return {?} */ BsDatepickerEffects.prototype.registerDatepickerSideEffects = /** * @return {?} */ function () { var _this = this; this._subs.push(this._store.select(function (state) { return state.view; }).subscribe(function (view) { _this._store.dispatch(_this._actions.calculate()); })); // format calendar values on month model change this._subs.push(this._store .select(function (state) { return state.monthsModel; }) .pipe(operators.filter(function (monthModel) { return !!monthModel; })) .subscribe(function (month) { return _this._store.dispatch(_this._actions.format()); })); // flag day values this._subs.push(this._store .select(function (state) { return state.formattedMonths; }) .pipe(operators.filter(function (month) { return !!month; })) .subscribe(function (month) { return _this._store.dispatch(_this._actions.flag()); })); // flag day values this._subs.push(this._store .select(function (state) { return state.selectedDate; }) .pipe(operators.filter(function (selectedDate) { return !!selectedDate; })) .subscribe(function (selectedDate) { return _this._store.dispatch(_this._actions.flag()); })); // flag for date range picker this._subs.push(this._store .select(function (state) { return state.selectedRange; }) .pipe(operators.filter(function (selectedRange) { return !!selectedRange; })) .subscribe(function (selectedRange) { return _this._store.dispatch(_this._actions.flag()); })); // monthsCalendar this._subs.push(this._store .select(function (state) { return state.monthsCalendar; }) .subscribe(function () { return _this._store.dispatch(_this._actions.flag()); })); // years calendar this._subs.push(this._store .select(function (state) { return state.yearsCalendarModel; }) .pipe(operators.filter(function (state) { return !!state; })) .subscribe(function () { return _this._store.dispatch(_this._actions.flag()); })); // on hover this._subs.push(this._store .select(function (state) { return state.hoveredDate; }) .pipe(operators.filter(function (hoveredDate) { return !!hoveredDate; })) .subscribe(function (hoveredDate) { return _this._store.dispatch(_this._actions.flag()); })); // on locale change this._subs.push(this._localeService.localeChange .subscribe(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: core.Injectable } ]; /** @nocollapse */ BsDatepickerEffects.ctorParameters = function () { return [ { type: BsDatepickerActions }, { type: BsLocaleService } ]; }; return BsDatepickerEffects; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var defaultMonthOptions = { width: 7, height: 6 }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @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,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} date * @param {?} options * @return {?} */ function getStartingDayOfCalendar(date, options) { if (chronos.isFirstDayOfWeek(date, options.firstDayOfWeek)) { return date; } /** @type {?} */ var weekDay = chronos.getDay(date); /** @type {?} */ var offset = calculateDateOffset(weekDay, options.firstDayOfWeek); return chronos.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 && chronos.isBefore(chronos.endOf(date, 'month'), min, 'day'); /** @type {?} */ var maxBound = max && chronos.isAfter(chronos.startOf(date, 'month'), max, 'day'); return minBound || maxBound; } /** * @param {?} date * @param {?} min * @param {?} max * @return {?} */ function isYearDisabled(date, min, max) { /** @type {?} */ var minBound = min && chronos.isBefore(chronos.endOf(date, 'year'), min, 'day'); /** @type {?} */ var maxBound = max && chronos.isAfter(chronos.startOf(date, 'year'), max, 'day'); return minBound || maxBound; } /** * @param {?} date * @param {?} datesDisabled * @return {?} */ function isDisabledDate(date, datesDisabled) { if (datesDisabled === undefined || !datesDisabled || !datesDisabled.length) { return false; } return datesDisabled.some(function (dateDisabled) { return chronos.isSame(date, dateDisabled, 'date'); }); } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @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 = chronos.shiftDate(prevValue, options.shift); } } return matrix; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} startingDate * @param {?} options * @return {?} */ function calcDaysCalendar(startingDate, options) { /** @type {?} */ var firstDay = chronos.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, function (date) { return date; }); return { daysMatrix: daysMatrix, month: firstDay }; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} daysCalendar * @param {?} formatOptions * @param {?} monthIndex * @return {?} */ function formatDaysCalendar(daysCalendar, formatOptions, monthIndex) { return { month: daysCalendar.month, monthTitle: chronos.formatDate(daysCalendar.month, formatOptions.monthTitle, formatOptions.locale), yearTitle: chronos.formatDate(daysCalendar.month, formatOptions.yearTitle, formatOptions.locale), weekNumbers: getWeekNumbers(daysCalendar.daysMatrix, formatOptions.weekNumbers, formatOptions.locale), weekdays: getShiftedWeekdays(formatOptions.locale), weeks: daysCalendar.daysMatrix.map(function (week, weekIndex) { return ({ days: week.map(function (date, dayIndex) { return ({ date: date, label: chronos.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(function (days) { return (days[0] ? chronos.formatDate(days[0], format, locale) : ''); }); } /** * @param {?} locale * @return {?} */ function getShiftedWeekdays(locale) { /** @type {?} */ var _locale = chronos.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,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} formattedMonth * @param {?} options * @return {?} */ function flagDaysCalendar(formattedMonth, options) { formattedMonth.weeks.forEach(function (week) { /* tslint:disable-next-line: cyclomatic-complexity */ week.days.forEach(function (day, dayIndex) { // datepicker /** @type {?} */ var isOtherMonth = !chronos.isSameMonth(day.date, formattedMonth.month); /** @type {?} */ var isHovered = !isOtherMonth && chronos.isSameDay(day.date, options.hoveredDate); // date range picker /** @type {?} */ var isSelectionStart = !isOtherMonth && options.selectedRange && chronos.isSameDay(day.date, options.selectedRange[0]); /** @type {?} */ var isSelectionEnd = !isOtherMonth && options.selectedRange && chronos.isSameDay(day.date, options.selectedRange[1]); /** @type {?} */ var isSelected = (!isOtherMonth && chronos.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 || chronos.isBefore(day.date, options.minDate, 'day') || chronos.isAfter(day.date, options.maxDate, 'day') || chronos.isDisabledDay(day.date, options.daysDisabled) || isDisabledDate(day.date, options.datesDisabled); /** @type {?} */ var currentDate = new Date(); /** @type {?} */ var isToday = !isOtherMonth && chronos.isSameDay(day.date, currentDate); // decide update or not /** @type {?} */ var newDay = Object.assign({}, day, { isOtherMonth: isOtherMonth, isHovered: isHovered, isSelected: isSelected, isSelectionStart: isSelectionStart, isSelectionEnd: isSelectionEnd, isInRange: isInRange, isDisabled: isDisabled, isToday: isToday }); 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) { 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(chronos.shiftDate(formattedMonth.month, { month: -1 }), options.minDate, options.maxDate); formattedMonth.disableRightArrow = isMonthDisabled(chronos.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,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,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var height = 4; /** @type {?} */ var width = 3; /** @type {?} */ var shift = { month: 1 }; /** * @param {?} viewDate * @param {?} formatOptions * @return {?} */ function formatMonthsCalendar(viewDate, formatOptions) { /** @type {?} */ var initialDate = chronos.startOf(viewDate, 'year'); /** @type {?} */ var matrixOptions = { width: width, height: height, initialDate: initialDate, shift: shift }; /** @type {?} */ var monthMatrix = createMatrix(matrixOptions, function (date) { return ({ date: date, label: chronos.formatDate(date, formatOptions.monthLabel, formatOptions.locale) }); }); return { months: monthMatrix, monthTitle: '', yearTitle: chronos.formatDate(viewDate, formatOptions.yearTitle, formatOptions.locale) }; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} monthCalendar * @param {?} options * @return {?} */ function flagMonthsCalendar(monthCalendar, options) { monthCalendar.months.forEach(function (months, rowIndex) { months.forEach(function (month, monthIndex) { /** @type {?} */ var isHovered = chronos.isSameMonth(month.date, options.hoveredMonth); /** @type {?} */ var isDisabled = options.isDisabled || isMonthDisabled(month.date, options.minDate, options.maxDate); /** @type {?} */ var newMonth = Object.assign(/*{},*/ month, { isHovered: isHovered, isDisabled: isDisabled }); if (month.isHovered !== newMonth.isHovered || month.isDisabled !== newMonth.isDisabled) { monthCalendar.months[rowIndex][monthIndex] = newMonth; } }); }); // todo: add check for linked calendars monthCalendar.hideLeftArrow = options.monthIndex > 0 && options.monthIndex !== options.displayMonths; monthCalendar.hideRightArrow = options.monthIndex < options.displayMonths && options.monthIndex + 1 !== options.displayMonths; monthCalendar.disableLeftArrow = isYearDisabled(chronos.shiftDate(monthCalendar.months[0][0].date, { year: -1 }), options.minDate, options.maxDate); monthCalendar.disableRightArrow = isYearDisabled(chronos.shiftDate(monthCalendar.months[0][0].date, { year: 1 }), options.minDate, options.maxDate); return monthCalendar; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ var height$1 = 4; /** @type {?} */ var width$1 = 4; /** @type {?} */ var yearsPerCalendar = height$1 * width$1; /** @type {?} */ var initialShift = (Math.floor(yearsPerCalendar / 2) - 1) * -1; /** @type {?} */ var shift$1 = { year: 1 }; /** * @param {?} viewDate * @param {?} formatOptions * @return {?} */ function formatYearsCalendar(viewDate, formatOptions) { /** @type {?} */ var initialDate = chronos.shiftDate(viewDate, { year: initialShift }); /** @type {?} */ var matrixOptions = { width: width$1, height: height$1, initialDate: initialDate, shift: shift$1 }; /** @type {?} */ var yearsMatrix = createMatrix(matrixOptions, function (date) { return ({ date: date, label: chronos.formatDate(date, formatOptions.yearLabel, formatOptions.locale) }); }); /** @type {?} */ var yearTitle = formatYearRangeTitle(yearsMatrix, formatOptions); return { years: yearsMatrix, monthTitle: '', yearTitle: yearTitle }; } /** * @param {?} yearsMatrix * @param {?} formatOptions * @return {?} */ function formatYearRangeTitle(yearsMatrix, formatOptions) { /** @type {?} */ var from = chronos.formatDate(yearsMatrix[0][0].date, formatOptions.yearTitle, formatOptions.locale); /** @type {?} */ var to = chronos.formatDate(yearsMatrix[height$1 - 1][width$1 - 1].date, formatOptions.yearTitle, formatOptions.locale); return from + " - " + to; } /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @param {?} yearsCalendar * @param {?} options * @return {?} */ function flagYearsCalendar(yearsCalendar, options) { yearsCalendar.years.forEach(function (years, rowIndex) { years.forEach(function (year, yearIndex) { /** @type {?} */ var isHovered = chronos.isSameYear(year.date, options.hoveredYear); /** @type {?} */ var isDisabled = options.isDisabled || isYearDisabled(year.date, options.minDate, options.maxDate); /** @type {?} */ var newMonth = Object.assign(/*{},*/ year, { isHovered: isHovered, isDisabled: isDisabled }); if (year.isHovered !== newMonth.isHovered || year.isDisabled !== newMonth.isDisabled) { yearsCalendar.years[rowIndex][yearIndex] = newMonth; } }); }); // todo: add check for linked calendars yearsCalendar.hideLeftArrow = options.yearIndex > 0 && options.yearIndex !== options.displayMonths; yearsCalendar.hideRightArrow = options.yearIndex < options.displayMonths && options.yearIndex + 1 !== options.displayMonths; yearsCalendar.disableLeftArrow = isYearDisabled(chronos.shiftDate(yearsCalendar.years[0][0].date, { year: -1 }), options.minDate, options.maxDate); /** @type {?} */ var i = yearsCalendar.years.length - 1; /** @type {?} */ var j = yearsCalendar.years[i].length - 1; yearsCalendar.disableRightArrow = isYearDisabled(chronos.shiftDate(yearsCalendar.years[i][j].date, { year: 1 }), o