UNPKG

angular-mydatepicker

Version:
1,570 lines (1,560 loc) 189 kB
import { CommonModule } from '@angular/common'; import { __read, __values } from 'tslib'; import { NG_VALIDATORS, NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms'; import { Injectable, Component, ElementRef, ViewEncapsulation, ViewChild, Renderer2, ChangeDetectorRef, HostBinding, EventEmitter, Input, Output, Directive, ViewContainerRef, ComponentFactoryResolver, forwardRef, HostListener, NgModule } from '@angular/core'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ var KeyCode = { enter: 13, esc: 27, space: 32, leftArrow: 37, upArrow: 38, rightArrow: 39, downArrow: 40, tab: 9, shift: 16, }; KeyCode[KeyCode.enter] = 'enter'; KeyCode[KeyCode.esc] = 'esc'; KeyCode[KeyCode.space] = 'space'; KeyCode[KeyCode.leftArrow] = 'leftArrow'; KeyCode[KeyCode.upArrow] = 'upArrow'; KeyCode[KeyCode.rightArrow] = 'rightArrow'; KeyCode[KeyCode.downArrow] = 'downArrow'; KeyCode[KeyCode.tab] = 'tab'; KeyCode[KeyCode.shift] = 'shift'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {string} */ var KeyName = { enter: "Enter", esc: "Escape|Esc", space: " |Spacebar", leftArrow: "ArrowLeft|Left", upArrow: "ArrowUp|Up", rightArrow: "ArrowRight|Right", downArrow: "ArrowDown|Down", tab: "Tab", shift: "Shift", }; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * Constants * @type {?} */ var D = "d"; /** @type {?} */ var DD = "dd"; /** @type {?} */ var M = "m"; /** @type {?} */ var MM = "mm"; /** @type {?} */ var MMM = "mmm"; /** @type {?} */ var Y = "y"; /** @type {?} */ var YYYY = "yyyy"; /** @type {?} */ var ORDINAL = "##"; /** @type {?} */ var ST = 'st'; /** @type {?} */ var ND = "nd"; /** @type {?} */ var RD = "rd"; /** @type {?} */ var DATE_ROW_COUNT = 5; /** @type {?} */ var DATE_COL_COUNT = 6; /** @type {?} */ var MONTH_ROW_COUNT = 3; /** @type {?} */ var MONTH_COL_COUNT = 2; /** @type {?} */ var YEAR_ROW_COUNT = 4; /** @type {?} */ var YEAR_COL_COUNT = 4; /** @type {?} */ var DOT = "."; /** @type {?} */ var UNDER_LINE = "_"; /** @type {?} */ var PIPE = "|"; /** @type {?} */ var YEAR_SEPARATOR = " - "; /** @type {?} */ var SU = "su"; /** @type {?} */ var MO = "mo"; /** @type {?} */ var TU = "tu"; /** @type {?} */ var WE = "we"; /** @type {?} */ var TH = "th"; /** @type {?} */ var FR = "fr"; /** @type {?} */ var SA = "sa"; /** @type {?} */ var DEFAULT_LOCALE = "en"; /** @type {?} */ var ZERO_STR = "0"; /** @type {?} */ var EMPTY_STR = ""; /** @type {?} */ var SPACE_STR = " "; /** @type {?} */ var CLICK = "click"; /** @type {?} */ var KEYUP = "keyup"; /** @type {?} */ var BLUR = "blur"; /** @type {?} */ var DISABLED = "disabled"; /** @type {?} */ var BODY = "body"; /** @type {?} */ var VALUE = "value"; /** @type {?} */ var OPTIONS = "options"; /** @type {?} */ var DEFAULT_MONTH = "defaultMonth"; /** @type {?} */ var LOCALE = "locale"; /** @type {?} */ var OBJECT = "object"; /** @type {?} */ var PX = "px"; /** @type {?} */ var STYLE = "style"; /** @type {?} */ var INNER_HTML = "innerHTML"; /** @type {?} */ var OPTS = "opts"; /** @type {?} */ var YEARS_DURATION = "yearsDuration"; /** @type {?} */ var YEARS = "years"; /** @type {?} */ var VISIBLE_MONTH = "visibleMonth"; /** @type {?} */ var SELECT_MONTH = "selectMonth"; /** @type {?} */ var SELECT_YEAR = "selectYear"; /** @type {?} */ var PREV_VIEW_DISABLED = "prevViewDisabled"; /** @type {?} */ var NEXT_VIEW_DISABLED = "nextViewDisabled"; /** @type {?} */ var DATES = "dates"; /** @type {?} */ var WEEK_DAYS = "weekDays"; /** @type {?} */ var SELECTED_DATE = "selectedDate"; /** @type {?} */ var SELECTED_DATE_RANGE = "selectedDateRange"; /** @type {?} */ var MONTHS = "months"; /** @type {?} */ var ANIMATION_END = "animationend"; /** @type {?} */ var ANIMATION_TIMEOUT = 550; /** @type {?} */ var MY_DP_ANIMATION = "myDpAnimation"; /** @type {?} */ var ANIMATION_NAMES = ["Fade", "ScaleTop", "ScaleCenter", "Rotate", "FlipDiagonal", "Own"]; /** @type {?} */ var IN = "In"; /** @type {?} */ var OUT = "Out"; /** @type {?} */ var TABINDEX = "tabindex"; /** @type {?} */ var TD_SELECTOR = "table tbody tr td:not(.myDpDaycellWeekNbr)"; /** @type {?} */ var PREVENT_CLOSE_TIMEOUT = 50; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var UtilService = /** @class */ (function () { function UtilService() { this.weekDays = [SU, MO, TU, WE, TH, FR, SA]; } /** * @param {?} dateStr * @param {?} options * @param {?} validateOpts * @return {?} */ UtilService.prototype.isDateValid = /** * @param {?} dateStr * @param {?} options * @param {?} validateOpts * @return {?} */ function (dateStr, options, validateOpts) { var e_1, _a; var dateFormat = options.dateFormat, minYear = options.minYear, maxYear = options.maxYear, monthLabels = options.monthLabels; /** @type {?} */ var returnDate = this.resetDate(); /** @type {?} */ var datesInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; /** @type {?} */ var isMonthStr = dateFormat.indexOf(MMM) !== -1; /** @type {?} */ var delimeters = dateFormat.match(/[^(d#my)]{1,}/g); if (!dateStr || dateStr === EMPTY_STR) { return returnDate; } /** @type {?} */ var dateValues = this.getDateValue(dateStr, dateFormat, delimeters); /** @type {?} */ var year = 0; /** @type {?} */ var month = 0; /** @type {?} */ var day = 0; try { for (var dateValues_1 = __values(dateValues), dateValues_1_1 = dateValues_1.next(); !dateValues_1_1.done; dateValues_1_1 = dateValues_1.next()) { var dv = dateValues_1_1.value; if (dv.format.indexOf(ORDINAL) != -1) { /** @type {?} */ var dayNumber = parseInt(dv.value.replace(/\D/g, '')); /** @type {?} */ var ordinalStr = dv.value.replace(/[0-9]/g, ''); /** @type {?} */ var ordinal = this.getOrdinal(dayNumber); if (ordinal !== ordinalStr) { return returnDate; } dv.value = dv.value.replace(ST, EMPTY_STR).replace(ND, EMPTY_STR).replace(RD, EMPTY_STR).replace(TH, EMPTY_STR); dv.format = dv.format.replace(ORDINAL, EMPTY_STR); } var value = dv.value, format = dv.format; if (value && /^\d+$/.test(value) && Number(value) === 0) { return returnDate; } if (format.indexOf(YYYY) !== -1) { year = this.getNumberByValue(dv); } else if (format.indexOf(M) !== -1) { month = isMonthStr ? this.getMonthNumberByMonthName(dv, monthLabels) : this.getNumberByValue(dv); } else if (format.indexOf(D) !== -1) { day = this.getNumberByValue(dv); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (dateValues_1_1 && !dateValues_1_1.done && (_a = dateValues_1.return)) _a.call(dateValues_1); } finally { if (e_1) throw e_1.error; } } var validateDisabledDates = validateOpts.validateDisabledDates, selectedValue = validateOpts.selectedValue; year = year === 0 && selectedValue ? selectedValue.year : year; month = month === 0 && selectedValue ? selectedValue.month : month; day = day === 0 && selectedValue ? selectedValue.day : day; /** @type {?} */ var today = this.getToday(); if (year === 0 && (month !== 0 || day !== 0)) { year = today.year; } if (month === 0 && (year !== 0 || day !== 0)) { month = today.month; } if (day === 0 && (year !== 0 || month !== 0)) { day = today.day; } if (month !== -1 && day !== -1 && year !== -1) { if (year < minYear || year > maxYear || month < 1 || month > 12) { return returnDate; } /** @type {?} */ var date = { year: year, month: month, day: day }; if (validateDisabledDates && this.isDisabledDate(date, options).disabled) { return returnDate; } if (year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0)) { datesInMonth[1] = 29; } if (day < 1 || day > datesInMonth[month - 1]) { return returnDate; } // Valid date return date; } return returnDate; }; /** * @param {?} dateRangeStr * @param {?} options * @param {?} validateOpts * @return {?} */ UtilService.prototype.isDateValidDateRange = /** * @param {?} dateRangeStr * @param {?} options * @param {?} validateOpts * @return {?} */ function (dateRangeStr, options, validateOpts) { /** @type {?} */ var dateRange = { begin: this.resetDate(), end: this.resetDate() }; if (dateRangeStr && dateRangeStr.length) { /** @type {?} */ var dates = dateRangeStr.split(options.dateRangeDatesDelimiter); if (dates && dates.length === 2) { var _a = __read(dates, 2), beginDate = _a[0], endDate = _a[1]; var selectedValue = validateOpts.selectedValue; if (selectedValue) { validateOpts.selectedValue = selectedValue.begin; } /** @type {?} */ var begin = this.isDateValid(beginDate, options, validateOpts); if (this.isInitializedDate(begin)) { if (selectedValue) { validateOpts.selectedValue = selectedValue.end; } /** @type {?} */ var end = this.isDateValid(endDate, options, validateOpts); if (this.isInitializedDate(end) && this.isDateSameOrEarlier(begin, end)) { dateRange = { begin: begin, end: end }; } } } } return dateRange; }; /** * @param {?} dateStr * @param {?} dateFormat * @param {?} delimeters * @return {?} */ UtilService.prototype.getDateValue = /** * @param {?} dateStr * @param {?} dateFormat * @param {?} delimeters * @return {?} */ function (dateStr, dateFormat, delimeters) { var e_2, _a; /** @type {?} */ var del = EMPTY_STR; if (delimeters) { try { for (var delimeters_1 = __values(delimeters), delimeters_1_1 = delimeters_1.next(); !delimeters_1_1.done; delimeters_1_1 = delimeters_1.next()) { var d = delimeters_1_1.value; if (del.indexOf(d) === -1) { del += d; } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (delimeters_1_1 && !delimeters_1_1.done && (_a = delimeters_1.return)) _a.call(delimeters_1); } finally { if (e_2) throw e_2.error; } } } /** @type {?} */ var re = new RegExp("[" + del + "]"); /** @type {?} */ var ds = dateStr.split(re); /** @type {?} */ var df = dateFormat.split(re); /** @type {?} */ var da = []; for (var i = 0; i < df.length; i++) { if (df[i].indexOf(YYYY) !== -1) { da.push({ value: ds[i], format: df[i] }); } if (df[i].indexOf(M) !== -1) { da.push({ value: ds[i], format: df[i] }); } if (df[i].indexOf(D) !== -1) { da.push({ value: ds[i], format: df[i] }); } } return da; }; /** * @param {?} df * @param {?} monthLabels * @return {?} */ UtilService.prototype.getMonthNumberByMonthName = /** * @param {?} df * @param {?} monthLabels * @return {?} */ function (df, monthLabels) { if (df.value) { for (var key = 1; key <= 12; key++) { if (df.value.toLowerCase() === monthLabels[key].toLowerCase()) { return key; } } } return -1; }; /** * @param {?} df * @return {?} */ UtilService.prototype.getNumberByValue = /** * @param {?} df * @return {?} */ function (df) { if (!/^\d+$/.test(df.value)) { return -1; } /** @type {?} */ var nbr = Number(df.value); if (df.format.length === 1 && df.value.length !== 1 && nbr < 10 || df.format.length === 1 && df.value.length !== 2 && nbr >= 10) { nbr = -1; } else if (df.format.length === 2 && df.value.length > 2) { nbr = -1; } return nbr; }; /** * @param {?} monthString * @return {?} */ UtilService.prototype.parseDefaultMonth = /** * @param {?} monthString * @return {?} */ function (monthString) { /** @type {?} */ var month = { monthTxt: EMPTY_STR, monthNbr: 0, year: 0 }; if (monthString !== EMPTY_STR) { /** @type {?} */ var split = monthString.split(monthString.match(/[^0-9]/)[0]); month.monthNbr = split[0].length === 2 ? Number(split[0]) : Number(split[1]); month.year = split[0].length === 2 ? Number(split[1]) : Number(split[0]); } return month; }; /** * @param {?} date * @param {?} options * @return {?} */ UtilService.prototype.isDisabledDate = /** * @param {?} date * @param {?} options * @return {?} */ function (date, options) { var e_3, _a, e_4, _b; var minYear = options.minYear, maxYear = options.maxYear, disableUntil = options.disableUntil, disableSince = options.disableSince, disableWeekends = options.disableWeekends, disableDates = options.disableDates, disableDateRanges = options.disableDateRanges, disableWeekdays = options.disableWeekdays, enableDates = options.enableDates; if (this.dateMatchToDates(date, enableDates)) { return this.getDisabledValue(false, EMPTY_STR); } if (date.year < minYear && date.month === 12 || date.year > maxYear && date.month === 1) { return this.getDisabledValue(true, EMPTY_STR); } /** @type {?} */ var inputDates = (/** @type {?} */ (disableDates)); /** @type {?} */ var result = inputDates.find((/** * @param {?} d * @return {?} */ function (d) { return d.dates; })); if (!result) { if (this.dateMatchToDates(date, inputDates)) { return this.getDisabledValue(true, EMPTY_STR); } } else { try { for (var inputDates_1 = __values(inputDates), inputDates_1_1 = inputDates_1.next(); !inputDates_1_1.done; inputDates_1_1 = inputDates_1.next()) { var dd = inputDates_1_1.value; if (this.dateMatchToDates(date, dd.dates)) { return this.getDisabledValue(true, dd.styleClass); } } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (inputDates_1_1 && !inputDates_1_1.done && (_a = inputDates_1.return)) _a.call(inputDates_1); } finally { if (e_3) throw e_3.error; } } } if (this.isDisabledByDisableUntil(date, disableUntil)) { return this.getDisabledValue(true, EMPTY_STR); } if (this.isDisabledByDisableSince(date, disableSince)) { return this.getDisabledValue(true, EMPTY_STR); } if (disableWeekends) { /** @type {?} */ var dayNbr = this.getDayNumber(date); if (dayNbr === 0 || dayNbr === 6) { return this.getDisabledValue(true, EMPTY_STR); } } /** @type {?} */ var dn = this.getDayNumber(date); if (disableWeekdays.length > 0) { try { for (var disableWeekdays_1 = __values(disableWeekdays), disableWeekdays_1_1 = disableWeekdays_1.next(); !disableWeekdays_1_1.done; disableWeekdays_1_1 = disableWeekdays_1.next()) { var wd = disableWeekdays_1_1.value; if (dn === this.getWeekdayIndex(wd)) { return this.getDisabledValue(true, EMPTY_STR); } } } catch (e_4_1) { e_4 = { error: e_4_1 }; } finally { try { if (disableWeekdays_1_1 && !disableWeekdays_1_1.done && (_b = disableWeekdays_1.return)) _b.call(disableWeekdays_1); } finally { if (e_4) throw e_4.error; } } } if (this.isDisabledByDisableDateRange(date, date, disableDateRanges)) { return this.getDisabledValue(true, EMPTY_STR); } return this.getDisabledValue(false, EMPTY_STR); }; /** * @param {?} disabled * @param {?} styleClass * @return {?} */ UtilService.prototype.getDisabledValue = /** * @param {?} disabled * @param {?} styleClass * @return {?} */ function (disabled, styleClass) { return { disabled: disabled, styleClass: styleClass }; }; /** * @param {?} date * @param {?} dates * @return {?} */ UtilService.prototype.dateMatchToDates = /** * @param {?} date * @param {?} dates * @return {?} */ function (date, dates) { var e_5, _a; try { for (var dates_1 = __values(dates), dates_1_1 = dates_1.next(); !dates_1_1.done; dates_1_1 = dates_1.next()) { var d = dates_1_1.value; if ((d.year === 0 || d.year === date.year) && (d.month === 0 || d.month === date.month) && d.day === date.day) { return true; } } } catch (e_5_1) { e_5 = { error: e_5_1 }; } finally { try { if (dates_1_1 && !dates_1_1.done && (_a = dates_1.return)) _a.call(dates_1); } finally { if (e_5) throw e_5.error; } } return false; }; /** * @param {?} year * @param {?} month * @param {?} options * @return {?} */ UtilService.prototype.isDisabledMonth = /** * @param {?} year * @param {?} month * @param {?} options * @return {?} */ function (year, month, options) { var disableUntil = options.disableUntil, disableSince = options.disableSince, disableDateRanges = options.disableDateRanges, enableDates = options.enableDates; /** @type {?} */ var dateEnd = { year: year, month: month, day: this.datesInMonth(month, year) }; /** @type {?} */ var dateBegin = { year: year, month: month, day: 1 }; if (this.isDatesEnabled(dateBegin, dateEnd, enableDates)) { return false; } if (this.isDisabledByDisableUntil(dateEnd, disableUntil)) { return true; } if (this.isDisabledByDisableSince(dateBegin, disableSince)) { return true; } if (this.isDisabledByDisableDateRange(dateBegin, dateEnd, disableDateRanges)) { return true; } return false; }; /** * @param {?} year * @param {?} options * @return {?} */ UtilService.prototype.isDisabledYear = /** * @param {?} year * @param {?} options * @return {?} */ function (year, options) { var disableUntil = options.disableUntil, disableSince = options.disableSince, disableDateRanges = options.disableDateRanges, enableDates = options.enableDates, minYear = options.minYear, maxYear = options.maxYear; /** @type {?} */ var dateEnd = { year: year, month: 12, day: 31 }; /** @type {?} */ var dateBegin = { year: year, month: 1, day: 1 }; if (this.isDatesEnabled(dateBegin, dateEnd, enableDates)) { return false; } if (this.isDisabledByDisableUntil(dateEnd, disableUntil)) { return true; } if (this.isDisabledByDisableSince(dateBegin, disableSince)) { return true; } if (this.isDisabledByDisableDateRange(dateBegin, dateEnd, disableDateRanges)) { return true; } if (year < minYear || year > maxYear) { return true; } return false; }; /** * @param {?} date * @param {?} disableUntil * @return {?} */ UtilService.prototype.isDisabledByDisableUntil = /** * @param {?} date * @param {?} disableUntil * @return {?} */ function (date, disableUntil) { return this.isInitializedDate(disableUntil) && this.getTimeInMilliseconds(date) <= this.getTimeInMilliseconds(disableUntil); }; /** * @param {?} date * @param {?} disableSince * @return {?} */ UtilService.prototype.isDisabledByDisableSince = /** * @param {?} date * @param {?} disableSince * @return {?} */ function (date, disableSince) { return this.isInitializedDate(disableSince) && this.getTimeInMilliseconds(date) >= this.getTimeInMilliseconds(disableSince); }; /** * @param {?} date * @param {?} enableDates * @return {?} */ UtilService.prototype.isPastDatesEnabled = /** * @param {?} date * @param {?} enableDates * @return {?} */ function (date, enableDates) { var e_6, _a; try { for (var enableDates_1 = __values(enableDates), enableDates_1_1 = enableDates_1.next(); !enableDates_1_1.done; enableDates_1_1 = enableDates_1.next()) { var d = enableDates_1_1.value; if (this.getTimeInMilliseconds(d) <= this.getTimeInMilliseconds(date)) { return true; } } } catch (e_6_1) { e_6 = { error: e_6_1 }; } finally { try { if (enableDates_1_1 && !enableDates_1_1.done && (_a = enableDates_1.return)) _a.call(enableDates_1); } finally { if (e_6) throw e_6.error; } } return false; }; /** * @param {?} date * @param {?} enableDates * @return {?} */ UtilService.prototype.isFutureDatesEnabled = /** * @param {?} date * @param {?} enableDates * @return {?} */ function (date, enableDates) { var e_7, _a; try { for (var enableDates_2 = __values(enableDates), enableDates_2_1 = enableDates_2.next(); !enableDates_2_1.done; enableDates_2_1 = enableDates_2.next()) { var d = enableDates_2_1.value; if (this.getTimeInMilliseconds(d) >= this.getTimeInMilliseconds(date)) { return true; } } } catch (e_7_1) { e_7 = { error: e_7_1 }; } finally { try { if (enableDates_2_1 && !enableDates_2_1.done && (_a = enableDates_2.return)) _a.call(enableDates_2); } finally { if (e_7) throw e_7.error; } } return false; }; /** * @param {?} dateBegin * @param {?} dateEnd * @param {?} enableDates * @return {?} */ UtilService.prototype.isDatesEnabled = /** * @param {?} dateBegin * @param {?} dateEnd * @param {?} enableDates * @return {?} */ function (dateBegin, dateEnd, enableDates) { var e_8, _a; try { for (var enableDates_3 = __values(enableDates), enableDates_3_1 = enableDates_3.next(); !enableDates_3_1.done; enableDates_3_1 = enableDates_3.next()) { var d = enableDates_3_1.value; if (this.getTimeInMilliseconds(d) >= this.getTimeInMilliseconds(dateBegin) && this.getTimeInMilliseconds(d) <= this.getTimeInMilliseconds(dateEnd)) { return true; } } } catch (e_8_1) { e_8 = { error: e_8_1 }; } finally { try { if (enableDates_3_1 && !enableDates_3_1.done && (_a = enableDates_3.return)) _a.call(enableDates_3); } finally { if (e_8) throw e_8.error; } } return false; }; /** * @param {?} dateBegin * @param {?} dateEnd * @param {?} disableDateRanges * @return {?} */ UtilService.prototype.isDisabledByDisableDateRange = /** * @param {?} dateBegin * @param {?} dateEnd * @param {?} disableDateRanges * @return {?} */ function (dateBegin, dateEnd, disableDateRanges) { var e_9, _a; /** @type {?} */ var dateMsBegin = this.getTimeInMilliseconds(dateBegin); /** @type {?} */ var dateMsEnd = this.getTimeInMilliseconds(dateEnd); try { for (var disableDateRanges_1 = __values(disableDateRanges), disableDateRanges_1_1 = disableDateRanges_1.next(); !disableDateRanges_1_1.done; disableDateRanges_1_1 = disableDateRanges_1.next()) { var d = disableDateRanges_1_1.value; if (this.isInitializedDate(d.begin) && this.isInitializedDate(d.end) && dateMsBegin >= this.getTimeInMilliseconds(d.begin) && dateMsEnd <= this.getTimeInMilliseconds(d.end)) { return true; } } } catch (e_9_1) { e_9 = { error: e_9_1 }; } finally { try { if (disableDateRanges_1_1 && !disableDateRanges_1_1.done && (_a = disableDateRanges_1.return)) _a.call(disableDateRanges_1); } finally { if (e_9) throw e_9.error; } } return false; }; /** * @param {?} date * @param {?} options * @return {?} */ UtilService.prototype.isMarkedDate = /** * @param {?} date * @param {?} options * @return {?} */ function (date, options) { var e_10, _a; var markDates = options.markDates, markWeekends = options.markWeekends; try { for (var markDates_1 = __values(markDates), markDates_1_1 = markDates_1.next(); !markDates_1_1.done; markDates_1_1 = markDates_1.next()) { var md = markDates_1_1.value; if (this.dateMatchToDates(date, md.dates)) { return this.getMarkedValue(true, md.color, md.styleClass); } } } catch (e_10_1) { e_10 = { error: e_10_1 }; } finally { try { if (markDates_1_1 && !markDates_1_1.done && (_a = markDates_1.return)) _a.call(markDates_1); } finally { if (e_10) throw e_10.error; } } if (markWeekends && markWeekends.marked) { /** @type {?} */ var dayNbr = this.getDayNumber(date); if (dayNbr === 0 || dayNbr === 6) { return this.getMarkedValue(true, markWeekends.color, EMPTY_STR); } } return this.getMarkedValue(false, EMPTY_STR, EMPTY_STR); }; /** * @param {?} marked * @param {?} color * @param {?} styleClass * @return {?} */ UtilService.prototype.getMarkedValue = /** * @param {?} marked * @param {?} color * @param {?} styleClass * @return {?} */ function (marked, color, styleClass) { return { marked: marked, color: color ? color : EMPTY_STR, styleClass: styleClass ? styleClass : EMPTY_STR }; }; /** * @param {?} date * @param {?} options * @return {?} */ UtilService.prototype.isHighlightedDate = /** * @param {?} date * @param {?} options * @return {?} */ function (date, options) { var sunHighlight = options.sunHighlight, satHighlight = options.satHighlight, highlightDates = options.highlightDates; /** @type {?} */ var dayNbr = this.getDayNumber(date); if (sunHighlight && dayNbr === 0 || satHighlight && dayNbr === 6) { return true; } if (this.dateMatchToDates(date, highlightDates)) { return true; } return false; }; /** * @param {?} date * @return {?} */ UtilService.prototype.getWeekNumber = /** * @param {?} date * @return {?} */ function (date) { /** @type {?} */ var d = new Date(date.year, date.month - 1, date.day, 0, 0, 0, 0); d.setDate(d.getDate() + (d.getDay() === 0 ? -3 : 4 - d.getDay())); return Math.round(((d.getTime() - new Date(d.getFullYear(), 0, 4).getTime()) / 86400000) / 7) + 1; }; /** * @param {?} date * @param {?} dateRange * @param {?} dateFormat * @param {?} monthLabels * @param {?} rangeDelimiter * @param {?=} dateStr * @return {?} */ UtilService.prototype.getDateModel = /** * @param {?} date * @param {?} dateRange * @param {?} dateFormat * @param {?} monthLabels * @param {?} rangeDelimiter * @param {?=} dateStr * @return {?} */ function (date, dateRange, dateFormat, monthLabels, rangeDelimiter, dateStr) { if (dateStr === void 0) { dateStr = EMPTY_STR; } /** @type {?} */ var singleDateModel = null; /** @type {?} */ var dateRangeModel = null; if (date) { singleDateModel = { date: date, jsDate: this.myDateToJsDate(date), formatted: dateStr.length ? dateStr : this.formatDate(date, dateFormat, monthLabels), epoc: this.getEpocTime(date) }; } else { dateRangeModel = { beginDate: dateRange.begin, beginJsDate: this.myDateToJsDate(dateRange.begin), beginEpoc: this.getEpocTime(dateRange.begin), endDate: dateRange.end, endJsDate: this.myDateToJsDate(dateRange.end), endEpoc: this.getEpocTime(dateRange.end), formatted: this.formatDate(dateRange.begin, dateFormat, monthLabels) + rangeDelimiter + this.formatDate(dateRange.end, dateFormat, monthLabels) }; } return { isRange: date === null, singleDate: singleDateModel, dateRange: dateRangeModel }; }; /** * @param {?} date * @param {?} dateFormat * @param {?} monthLabels * @return {?} */ UtilService.prototype.formatDate = /** * @param {?} date * @param {?} dateFormat * @param {?} monthLabels * @return {?} */ function (date, dateFormat, monthLabels) { /** @type {?} */ var formatted = dateFormat.replace(YYYY, String(date.year)); if (dateFormat.indexOf(MMM) !== -1) { formatted = formatted.replace(MMM, monthLabels[date.month]); } else if (dateFormat.indexOf(MM) !== -1) { formatted = formatted.replace(MM, this.preZero(date.month)); } else { formatted = formatted.replace(M, String(date.month)); } if (dateFormat.indexOf(DD) !== -1) { formatted = formatted.replace(DD, this.preZero(date.day)); } else { formatted = formatted.replace(D, String(date.day)); } if (dateFormat.indexOf(ORDINAL) !== -1) { formatted = formatted.replace(ORDINAL, this.getOrdinal(date.day)); } return formatted; }; /** * @param {?} date * @return {?} */ UtilService.prototype.getOrdinal = /** * @param {?} date * @return {?} */ function (date) { if (date > 3 && date < 21) { return TH; } switch (date % 10) { case 1: return ST; case 2: return ND; case 3: return RD; default: return TH; } }; /** * @param {?} model * @return {?} */ UtilService.prototype.getFormattedDate = /** * @param {?} model * @return {?} */ function (model) { return !model.isRange ? model.singleDate.formatted : model.dateRange.formatted; }; /** * @param {?} val * @return {?} */ UtilService.prototype.preZero = /** * @param {?} val * @return {?} */ function (val) { return val < 10 ? ZERO_STR + val : String(val); }; /** * @param {?} date * @return {?} */ UtilService.prototype.isInitializedDate = /** * @param {?} date * @return {?} */ function (date) { return date.year !== 0 && date.month !== 0 && date.day !== 0; }; /** * @param {?} firstDate * @param {?} secondDate * @return {?} */ UtilService.prototype.isDateEarlier = /** * @param {?} firstDate * @param {?} secondDate * @return {?} */ function (firstDate, secondDate) { return this.getTimeInMilliseconds(firstDate) < this.getTimeInMilliseconds(secondDate); }; /** * @param {?} firstDate * @param {?} secondDate * @return {?} */ UtilService.prototype.isDateSameOrEarlier = /** * @param {?} firstDate * @param {?} secondDate * @return {?} */ function (firstDate, secondDate) { return this.getTimeInMilliseconds(firstDate) <= this.getTimeInMilliseconds(secondDate); }; /** * @param {?} firstDate * @param {?} secondDate * @return {?} */ UtilService.prototype.isDateSame = /** * @param {?} firstDate * @param {?} secondDate * @return {?} */ function (firstDate, secondDate) { return this.getTimeInMilliseconds(firstDate) === this.getTimeInMilliseconds(secondDate); }; /** * @param {?} dateRange * @param {?} date * @return {?} */ UtilService.prototype.isDateRangeBeginOrEndSame = /** * @param {?} dateRange * @param {?} date * @return {?} */ function (dateRange, date) { /** @type {?} */ var dateMs = this.getTimeInMilliseconds(date); return this.getTimeInMilliseconds(dateRange.begin) === dateMs || this.getTimeInMilliseconds(dateRange.end) === dateMs; }; /** * @param {?} dateRange * @param {?} date * @return {?} */ UtilService.prototype.isDateRangeBegin = /** * @param {?} dateRange * @param {?} date * @return {?} */ function (dateRange, date) { /** @type {?} */ var dateMs = this.getTimeInMilliseconds(date); return this.getTimeInMilliseconds(dateRange.begin) === dateMs; }; /** * @param {?} dateRange * @param {?} date * @return {?} */ UtilService.prototype.isDateRangeEnd = /** * @param {?} dateRange * @param {?} date * @return {?} */ function (dateRange, date) { /** @type {?} */ var dateMs = this.getTimeInMilliseconds(date); return this.getTimeInMilliseconds(dateRange.end) === dateMs; }; /** * @param {?} date * @param {?} dateRange * @return {?} */ UtilService.prototype.isDateInRange = /** * @param {?} date * @param {?} dateRange * @return {?} */ function (date, dateRange) { if (!this.isInitializedDate(dateRange.begin) || !this.isInitializedDate(dateRange.end)) { return false; } return this.isDateSameOrEarlier(dateRange.begin, date) && this.isDateSameOrEarlier(date, dateRange.end); }; /** * @return {?} */ UtilService.prototype.resetDate = /** * @return {?} */ function () { return { year: 0, month: 0, day: 0 }; }; /** * @param {?} date * @return {?} */ UtilService.prototype.getTimeInMilliseconds = /** * @param {?} date * @return {?} */ function (date) { return this.myDateToJsDate(date).getTime(); }; /** * @return {?} */ UtilService.prototype.getToday = /** * @return {?} */ function () { /** @type {?} */ var date = new Date(); return { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() }; }; /** * @param {?} date * @return {?} */ UtilService.prototype.getDayNumber = /** * @param {?} date * @return {?} */ function (date) { return new Date(date.year, date.month - 1, date.day, 0, 0, 0, 0).getDay(); }; /** * @param {?} wd * @return {?} */ UtilService.prototype.getWeekdayIndex = /** * @param {?} wd * @return {?} */ function (wd) { return this.weekDays.indexOf(wd); }; /** * @param {?} date * @return {?} */ UtilService.prototype.getEpocTime = /** * @param {?} date * @return {?} */ function (date) { return Math.round(this.getTimeInMilliseconds(date) / 1000.0); }; /** * @param {?} date * @return {?} */ UtilService.prototype.jsDateToMyDate = /** * @param {?} date * @return {?} */ function (date) { return { year: date.getFullYear(), month: date.getMonth() + 1, day: date.getDate() }; }; /** * @param {?} date * @return {?} */ UtilService.prototype.myDateToJsDate = /** * @param {?} date * @return {?} */ function (date) { var year = date.year, month = date.month, day = date.day; return new Date(year, month - 1, day, 0, 0, 0, 0); }; /** * @param {?} m * @param {?} y * @return {?} */ UtilService.prototype.datesInMonth = /** * @param {?} m * @param {?} y * @return {?} */ function (m, y) { return new Date(y, m, 0).getDate(); }; /** * @param {?} m * @param {?} y * @return {?} */ UtilService.prototype.datesInPrevMonth = /** * @param {?} m * @param {?} y * @return {?} */ function (m, y) { /** @type {?} */ var d = this.getJsDate(y, m, 1); d.setMonth(d.getMonth() - 1); return this.datesInMonth(d.getMonth() + 1, d.getFullYear()); }; /** * @param {?} year * @param {?} month * @param {?} day * @return {?} */ UtilService.prototype.getJsDate = /** * @param {?} year * @param {?} month * @param {?} day * @return {?} */ function (year, month, day) { return new Date(year, month - 1, day, 0, 0, 0, 0); }; /** * @param {?} selectedValue * @param {?} dateRange * @return {?} */ UtilService.prototype.getSelectedValue = /** * @param {?} selectedValue * @param {?} dateRange * @return {?} */ function (selectedValue, dateRange) { if (!selectedValue) { return null; } if (!dateRange) { return selectedValue.date; } else { var beginDate = selectedValue.beginDate, endDate = selectedValue.endDate; return { begin: beginDate, end: endDate }; } }; /** * @param {?} event * @return {?} */ UtilService.prototype.getKeyCodeFromEvent = /** * @param {?} event * @return {?} */ function (event) { /** @type {?} */ var key = event.key || event.keyCode || event.which; if (this.checkKeyName(key, KeyName.enter) || key === KeyCode.enter) { return KeyCode.enter; } else if (this.checkKeyName(key, KeyName.esc) || key === KeyCode.esc) { return KeyCode.esc; } else if (this.checkKeyName(key, KeyName.space) || key === KeyCode.space) { return KeyCode.space; } else if (this.checkKeyName(key, KeyName.leftArrow) || key === KeyCode.leftArrow) { return KeyCode.leftArrow; } else if (this.checkKeyName(key, KeyName.upArrow) || key === KeyCode.upArrow) { return KeyCode.upArrow; } else if (this.checkKeyName(key, KeyName.rightArrow) || key === KeyCode.rightArrow) { return KeyCode.rightArrow; } else if (this.checkKeyName(key, KeyName.downArrow) || key === KeyCode.downArrow) { return KeyCode.downArrow; } else if (this.checkKeyName(key, KeyName.tab) || key === KeyCode.tab) { return KeyCode.tab; } else if (this.checkKeyName(key, KeyName.shift) || key === KeyCode.shift) { return KeyCode.shift; } else { return null; } }; /** * @param {?} key * @param {?} keyName * @return {?} */ UtilService.prototype.checkKeyName = /** * @param {?} key * @param {?} keyName * @return {?} */ function (key, keyName) { /** @type {?} */ var arr = keyName.split(PIPE); return arr.indexOf(key) !== -1; }; UtilService.decorators = [ { type: Injectable } ]; return UtilService; }()); /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ var MonthId = { prev: 1, curr: 2, next: 3, }; MonthId[MonthId.prev] = 'prev'; MonthId[MonthId.curr] = 'curr'; MonthId[MonthId.next] = 'next'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ var DefaultView = { Date: 1, Month: 2, Year: 3, }; DefaultView[DefaultView.Date] = 'Date'; DefaultView[DefaultView.Month] = 'Month'; DefaultView[DefaultView.Year] = 'Year'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ var CalAnimation = { None: 0, Fade: 1, ScaleTop: 2, ScaleCenter: 3, Rotate: 4, FlipDiagonal: 5, Own: 6, }; CalAnimation[CalAnimation.None] = 'None'; CalAnimation[CalAnimation.Fade] = 'Fade'; CalAnimation[CalAnimation.ScaleTop] = 'ScaleTop'; CalAnimation[CalAnimation.ScaleCenter] = 'ScaleCenter'; CalAnimation[CalAnimation.Rotate] = 'Rotate'; CalAnimation[CalAnimation.FlipDiagonal] = 'FlipDiagonal'; CalAnimation[CalAnimation.Own] = 'Own'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ var HeaderAction = { PrevBtnClick: 1, NextBtnClick: 2, MonthBtnClick: 3, YearBtnClick: 4, }; HeaderAction[HeaderAction.PrevBtnClick] = 'PrevBtnClick'; HeaderAction[HeaderAction.NextBtnClick] = 'NextBtnClick'; HeaderAction[HeaderAction.MonthBtnClick] = 'MonthBtnClick'; HeaderAction[HeaderAction.YearBtnClick] = 'YearBtnClick'; /** * @fileoverview added by tsickle * @suppress {checkTypes,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var CalendarComponent = /** @class */ (function () { function CalendarComponent(elem, renderer, cdr, utilService) { var _this = this; this.elem = elem; this.renderer = renderer; this.cdr = cdr; this.utilService = utilService; this.position = "static"; this.visibleMonth = { monthTxt: EMPTY_STR, monthNbr: 0, year: 0 }; this.selectedMonth = { monthNbr: 0, year: 0 }; this.selectedDate = { year: 0, month: 0, day: 0 }; this.selectedDateRange = { begin: { year: 0, month: 0, day: 0 }, end: { year: 0, month: 0, day: 0 } }; this.weekDays = []; this.dates = []; this.months = []; this.years = []; this.yearsDuration = ""; this.dayIdx = 0; this.weekDayOpts = [SU, MO, TU, WE, TH, FR, SA]; this.selectMonth = false; this.selectYear = false; this.viewChanged = false; this.selectorPos = null; this.prevViewDisabled = false; this.nextViewDisabled = false; this.clickListener = renderer.listen(elem.nativeElement, CLICK, (/** * @param {?} event * @return {?} */ function (event) { if ((_this.opts.monthSelector || _this.opts.yearSelector) && event.target) { _this.resetMonthYearSelect(); } })); } /** * @return {?} */ CalendarComponent.prototype.ngAfterViewInit = /** * @return {?} */ function () { var _a = this.opts, stylesData = _a.stylesData, calendarAnimation = _a.calendarAnimation, inline = _a.inline; if (stylesData.styles.length) { /** @type {?} */ var styleElTemp = this.renderer.createElement(STYLE); this.renderer.appendChild(styleElTemp, this.renderer.createText(stylesData.styles)); this.renderer.appendChild(this.styleEl.nativeElement, styleElTemp); } if (calendarAnimation.in !== CalAnimation.None) { this.setCalendarAnimation(calendarAnimation, true); } if (!inline) { this.focusToSelector(); } }; /** * @return {?} */ CalendarComponent.prototype.ngOnDestroy = /** * @return {?} */ function () { this.clickListener(); }; /** * @param {?} opts * @param {?} defaultMonth * @param {?} selectedValue * @param {?} inputValue * @param {?} selectorPos * @param {?} dc * @param {?} cvc * @param {?} rds * @param {?} va * @param {?} cbe * @return {?} */ CalendarComponent.prototype.initializeComponent = /** * @param {?} opts * @param {?} defaultMonth * @param {?} selectedValue * @param {?} inputValue * @param {?} selectorPos * @param {?} dc * @param {?} cvc * @param {?} rds * @param {?} va * @param {?} cbe * @return {?} */ function (opts, defaultMonth, selectedValue, inputValue, selectorPos, dc, cvc, rds, va, cbe) { this.opts = opts; this.selectorPos = selectorPos; this.dateChanged = dc; this.calendarViewChanged = cvc; this.rangeDateSelection = rds; this.viewActivated = va; this.closedByEsc = cbe; var defaultView = opts.defaultView, firstDayOfWeek = opts.firstDayOfWeek, dayLabels = opts.dayLabels; this.weekDays.length = 0; this.dayIdx = this.weekDayOpts.indexOf(firstDayOfWeek); if (this.dayIdx !== -1) { /** @type {?} */ var idx = this.dayIdx; for (var i = 0; i < this.weekDayOpts.length; i++) { this.weekDays.push(dayLabels[this.weekDayOpts[idx]]); idx = this.weekDayOpts[idx] === SA ? 0 : idx + 1; } } this.initializeView(defaultMonth, selectedValue, inputValue); this.setCalendarVisibleMonth(); this.setDefaultView(defaultView); }; /** * @param {?} defaultMonth * @param {?} selectedValue * @param {?} inputValue * @return {?} */ CalendarComponent.prototype.initializeView = /** * @param {?} defaultMonth * @param {?} selectedValue * @param {?} inputValue * @return {?} */ function (defaultMonth, selectedValue, inputValue) { var dateRange = this.opts.dateRange; // use today as a selected month /** @type {?} */ var today = this.utilService.getToday(); this.selectedMonth = { monthNbr: today.month, year: today.year }; // If default month attribute valur given use it as a selected month var defMonth = defaultMonth.defMonth, overrideSelection = defaultMonth.overrideSelection; if (defMonth && defMonth.length) { this.selectedMonth = this.utilService.parseDefaultMonth(defMonth); } /** @type {?} */ var validateOpts = null; if (!dateRange) { // Single date mode - If date selected use it as selected month validateOpts = { validateDisabledDates: false, selectedValue: this.utilService.getSelectedValue(selectedValue, dateRange) }; /** @type {?} */ var date = this.utilService.isDateValid(inputValue, this.opts, validateOpts); if (this.utilService.isInitializedDate(date)) { this.selectedDate = date; if (!overrideSelection) { this.selectedMonth = { monthNbr: date.month, year: date.year };