@duoduo-oba/ng-devui
Version:
DevUI components based on Angular
1,169 lines (1,142 loc) • 272 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/forms'), require('ng-devui/utils'), require('ng-devui/i18n'), require('@angular/animations'), require('rxjs'), require('rxjs/operators'), require('@angular/common'), require('@angular/cdk/overlay'), require('ng-devui/button')) :
typeof define === 'function' && define.amd ? define('ng-devui/datepicker', ['exports', '@angular/core', '@angular/forms', 'ng-devui/utils', 'ng-devui/i18n', '@angular/animations', 'rxjs', 'rxjs/operators', '@angular/common', '@angular/cdk/overlay', 'ng-devui/button'], factory) :
(global = global || self, factory((global['ng-devui'] = global['ng-devui'] || {}, global['ng-devui'].datepicker = {}), global.ng.core, global.ng.forms, global['ng-devui'].utils, global['ng-devui'].i18n, global.ng.animations, global.rxjs, global.rxjs.operators, global.ng.common, global.ng.cdk.overlay, global['ng-devui'].button));
}(this, (function (exports, core, forms, utils, i18n, animations, rxjs, operators, common, overlay, button) { 'use strict';
/*! *****************************************************************************
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 __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
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;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
/**
* @fileoverview added by tsickle
* Generated from: date-picker.config.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DatePickerConfigService = /** @class */ (function () {
function DatePickerConfigService() {
this.dateConfig = {
timePicker: false,
dateConverter: null,
min: 1900,
max: 2099,
format: {
date: 'y/MM/dd',
time: 'y/MM/dd HH:mm:ss'
}
};
}
DatePickerConfigService.decorators = [
{ type: core.Injectable }
];
return DatePickerConfigService;
}());
if (false) {
/** @type {?} */
DatePickerConfigService.prototype.dateConfig;
}
/**
* @fileoverview added by tsickle
* Generated from: date-change-event-args.model.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @enum {number} */
var SelectDateChangeReason = {
date: 0,
time: 1,
button: 2,
format: 3,
};
SelectDateChangeReason[SelectDateChangeReason.date] = 'date';
SelectDateChangeReason[SelectDateChangeReason.time] = 'time';
SelectDateChangeReason[SelectDateChangeReason.button] = 'button';
SelectDateChangeReason[SelectDateChangeReason.format] = 'format';
/**
* @record
*/
function SelectDateChangeEventArgs() { }
if (false) {
/** @type {?} */
SelectDateChangeEventArgs.prototype.reason;
/** @type {?} */
SelectDateChangeEventArgs.prototype.selectedDate;
}
/**
* @fileoverview added by tsickle
* Generated from: datepicker.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DatepickerComponent = /** @class */ (function () {
function DatepickerComponent(elementRef, renderer2, datePickerConfig, changeDetectorRef, i18n) {
var _this = this;
this.elementRef = elementRef;
this.renderer2 = renderer2;
this.datePickerConfig = datePickerConfig;
this.changeDetectorRef = changeDetectorRef;
this.i18n = i18n;
this.selectedDateChange = new core.EventEmitter();
this.disabled = false;
this.yearNumber = 12;
this.onChange = (/**
* @param {?} _
* @return {?}
*/
function (_) { return null; });
this.onTouched = (/**
* @return {?}
*/
function () { return null; });
this.clearAll = (/**
* @return {?}
*/
function () {
_this.writeValue(null);
_this.onChange(null);
_this.selectedDateChange.emit({
reason: SelectDateChangeReason.button,
selectedDate: null
});
});
this.chooseDate = (/**
* @param {?} date
* @param {?=} event
* @return {?}
*/
function (date, event) {
if (event === void 0) { event = {}; }
/** @type {?} */
var parseDate = _this.dateConverter.parse(date, _this.dateFormat, _this.locale || _this.i18nLocale);
_this.selectedDate = parseDate || new Date();
_this.onSelectDateChanged();
_this.onSelectDate(event, parseDate);
});
this._dateConfig = datePickerConfig['dateConfig'];
this.dateConverter = datePickerConfig['dateConfig'].dateConverter || new utils.DefaultDateConverter();
this.renderer2.setStyle(this.elementRef.nativeElement, 'display', 'inline-block');
}
/**
* @return {?}
*/
DatepickerComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
var _this = this;
this.showTime = this.showTime || this.dateConfig.timePicker;
this._minDate = this.minDate ? new Date(this.minDate) : new Date(this.dateConfig.min, 0, 1, 0, 0, 0);
this._maxDate = this.maxDate ? new Date(this.maxDate) : new Date(this.dateConfig.max, 11, 31, 23, 59, 59);
this.hourOptions = new Array(24).fill(0).map((/**
* @param {?} value
* @param {?} index
* @return {?}
*/
function (value, index) { return _this.fillLeft(index); }));
this.minuteOptions = new Array(60).fill(0).map((/**
* @param {?} value
* @param {?} index
* @return {?}
*/
function (value, index) { return _this.fillLeft(index); }));
this.nowMinYear = (new Date()).getFullYear() - Math.floor(this.yearNumber / 2) < this.minDate.getFullYear() ?
this.minDate.getFullYear() : (new Date()).getFullYear() - Math.floor(this.yearNumber / 2);
this.nowMaxYear = this.nowMinYear + this.yearNumber > this.maxDate.getFullYear() ?
this.maxDate.getFullYear() : this.nowMinYear + this.yearNumber;
this.setI18nText();
this.onSelectDateChanged();
this.onDisplayWeeksChange();
this.onYearRangeChange();
this.initDatePicker();
};
/**
* @param {?} changes
* @return {?}
*/
DatepickerComponent.prototype.ngOnChanges = /**
* @param {?} changes
* @return {?}
*/
function (changes) {
if (changes && changes['selectedDate'] && changes['selectedDate'].currentValue) {
this.writeValue(this.selectedDate);
}
};
/**
* @param {?} $event
* @return {?}
*/
DatepickerComponent.prototype.onDocumentClick = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
if (!this.elementRef.nativeElement.contains($event.target)) {
this.openChooseYearAndMonth = false;
this.resetYearOptions();
}
};
/**
* @param {?} $event
* @return {?}
*/
DatepickerComponent.prototype.onClick = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
$event.stopPropagation();
};
Object.defineProperty(DatepickerComponent.prototype, "dateConfig", {
get: /**
* @return {?}
*/
function () {
return this._dateConfig;
},
set: /**
* @param {?} dateConfig
* @return {?}
*/
function (dateConfig) {
if (this.checkDateConfig(dateConfig)) {
this._dateConfig = dateConfig;
this._dateFormat = this.showTime ? dateConfig.format.time : dateConfig.format.date;
}
else {
this._dateConfig = this.datePickerConfig.dateConfig;
}
},
enumerable: true,
configurable: true
});
/**
* @param {?} dateConfig
* @return {?}
*/
DatepickerComponent.prototype.checkDateConfig = /**
* @param {?} dateConfig
* @return {?}
*/
function (dateConfig) {
if (!dateConfig) {
return false;
}
if (typeof (dateConfig.timePicker) !== 'boolean' || !dateConfig.max || !dateConfig.min || !dateConfig.format) {
return false;
}
return true;
};
Object.defineProperty(DatepickerComponent.prototype, "minDate", {
get: /**
* @return {?}
*/
function () {
return this._minDate;
},
set: /**
* @param {?} date
* @return {?}
*/
function (date) {
/** @type {?} */
var parseDate = this.dateConverter.parse(date, this.dateFormat, this.locale || this.i18nLocale);
if (parseDate) {
this._minDate = parseDate;
this.onYearRangeChange();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(DatepickerComponent.prototype, "maxDate", {
get: /**
* @return {?}
*/
function () {
return this._maxDate;
},
set: /**
* @param {?} date
* @return {?}
*/
function (date) {
/** @type {?} */
var parseDate = this.dateConverter.parse(date, this.dateFormat, this.locale || this.i18nLocale);
if (parseDate) {
this._maxDate = parseDate;
this.onYearRangeChange();
}
},
enumerable: true,
configurable: true
});
Object.defineProperty(DatepickerComponent.prototype, "dateFormat", {
get: /**
* @return {?}
*/
function () {
return this._dateFormat;
},
set: /**
* @param {?} dateFormat
* @return {?}
*/
function (dateFormat) {
if (this._dateFormat !== dateFormat) {
this._dateFormat = dateFormat;
}
},
enumerable: true,
configurable: true
});
/**
* @protected
* @return {?}
*/
DatepickerComponent.prototype.resetYearOptions = /**
* @protected
* @return {?}
*/
function () {
/** @type {?} */
var baseYear = this.selectedDate ? this.selectedDate.getFullYear() : (new Date()).getFullYear();
this.currentYear = baseYear;
this.nowMinYear = baseYear - Math.floor(this.yearNumber / 2) < this.minDate.getFullYear() ?
this.minDate.getFullYear() : baseYear - Math.floor(this.yearNumber / 2);
this.nowMaxYear = this.nowMinYear + this.yearNumber > this.maxDate.getFullYear() ?
this.maxDate.getFullYear() : this.nowMinYear + this.yearNumber;
this.onYearRangeChange();
};
/**
* @return {?}
*/
DatepickerComponent.prototype.onYearRangeChange = /**
* @return {?}
*/
function () {
var _this = this;
if (!this.nowMinYear || !this.nowMaxYear) {
return;
}
/** @type {?} */
var yearNumber = this.yearNumber > this.nowMaxYear - this.nowMinYear + 1 ? this.nowMaxYear - this.nowMinYear + 1 : this.yearNumber;
this.yearOptions = new Array(yearNumber).fill(0).map((/**
* @param {?} value
* @param {?} index
* @return {?}
*/
function (value, index) {
return _this.nowMinYear + index;
}));
};
/**
* @param {?} obj
* @return {?}
*/
DatepickerComponent.prototype.writeValue = /**
* @param {?} obj
* @return {?}
*/
function (obj) {
if (!obj) {
return;
}
this.selectedDate = obj ?
this.dateConverter.parse(obj, this.dateFormat, this.locale || this.i18nLocale) : null;
this.onSelectDateChanged();
this.onDisplayWeeksChange();
this.availableMonths = this.onDisplayMonthsChange();
this.changeDetectorRef.markForCheck();
};
/**
* @param {?} fn
* @return {?}
*/
DatepickerComponent.prototype.registerOnChange = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this.onChange = fn;
};
/**
* @param {?} fn
* @return {?}
*/
DatepickerComponent.prototype.registerOnTouched = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this.onTouched = fn;
};
/**
* @return {?}
*/
DatepickerComponent.prototype.hasPreMonth = /**
* @return {?}
*/
function () {
if (this.currentYear > this.minDate.getFullYear()) {
return true;
}
else if (this.currentYear === this.minDate.getFullYear() && this.currentMonth > this.minDate.getMonth()) {
return true;
}
else {
return false;
}
};
/**
* @return {?}
*/
DatepickerComponent.prototype.onPreMonth = /**
* @return {?}
*/
function () {
if (!this.hasPreMonth()) {
return;
}
/** @type {?} */
var date = new Date(this.currentYear, this.currentMonth);
date.setMonth(date.getMonth() - 1);
this.currentMonth = date.getMonth();
this.currentYear = date.getFullYear();
this.onDisplayWeeksChange();
};
/**
* @return {?}
*/
DatepickerComponent.prototype.hasNextMonth = /**
* @return {?}
*/
function () {
if (this.currentYear < this.maxDate.getFullYear()) {
return true;
}
else if (this.currentYear === this.maxDate.getFullYear() && this.currentMonth < this.maxDate.getMonth()) {
return true;
}
else {
return false;
}
};
/**
* @param {?=} currentDate
* @param {?=} invocation
* @return {?}
*/
DatepickerComponent.prototype.onNextMonth = /**
* @param {?=} currentDate
* @param {?=} invocation
* @return {?}
*/
function (currentDate, invocation) {
if (!this.hasNextMonth() && invocation !== 'init') {
return;
}
/** @type {?} */
var date;
if (currentDate) {
date = new Date(currentDate.getTime());
}
else {
date = new Date(this.currentYear, this.currentMonth);
}
date.setMonth(date.getMonth() + 1);
this.currentMonth = date.getMonth();
this.currentYear = date.getFullYear();
this.onDisplayWeeksChange();
};
/**
* @return {?}
*/
DatepickerComponent.prototype.hasPreYearOption = /**
* @return {?}
*/
function () {
return this.nowMinYear > this.minDate.getFullYear();
};
/**
* @return {?}
*/
DatepickerComponent.prototype.onPreYearOption = /**
* @return {?}
*/
function () {
if (!this.hasPreYearOption()) {
return;
}
if (this.nowMinYear - this.yearNumber >= this.minDate.getFullYear()) {
this.nowMaxYear = this.nowMinYear - 1;
this.nowMinYear = this.nowMinYear - this.yearNumber;
}
else {
this.nowMaxYear = this.nowMinYear - 1;
this.nowMinYear = this.minDate.getFullYear();
}
this.onYearRangeChange();
};
/**
* @return {?}
*/
DatepickerComponent.prototype.hasNextYearOption = /**
* @return {?}
*/
function () {
return this.nowMaxYear < this.maxDate.getFullYear();
};
/**
* @return {?}
*/
DatepickerComponent.prototype.onNextYearOption = /**
* @return {?}
*/
function () {
if (!this.hasNextYearOption()) {
return;
}
if (this.nowMaxYear + this.yearNumber <= this.maxDate.getFullYear()) {
this.nowMinYear = this.nowMaxYear + 1;
this.nowMaxYear = this.nowMaxYear + this.yearNumber;
}
else {
this.nowMinYear = this.nowMaxYear + 1;
this.nowMaxYear = this.maxDate.getFullYear();
}
this.onYearRangeChange();
};
/**
* @param {?} year
* @param {?=} $event
* @return {?}
*/
DatepickerComponent.prototype.onSelectYear = /**
* @param {?} year
* @param {?=} $event
* @return {?}
*/
function (year, $event) {
if ($event) {
$event.stopPropagation();
}
this.currentYear = year;
this.onDisplayWeeksChange();
this.availableMonths = this.onDisplayMonthsChange();
};
/**
* @protected
* @return {?}
*/
DatepickerComponent.prototype.onSelectDateChanged = /**
* @protected
* @return {?}
*/
function () {
/** @type {?} */
var date = this.selectedDate || new Date();
if (date.getTime() < this.minDate.getTime()) {
date = this.minDate;
}
if (date.getTime() > this.maxDate.getTime()) {
date = this.maxDate;
}
this.currentYear = date.getFullYear();
this.currentMonth = date.getMonth();
this.currentHour = this.showTime ? date.getHours() : 0;
this.currentMinute = this.showTime ? date.getMinutes() : 0;
this.currentSecond = this.showTime ? date.getSeconds() : 0;
};
/**
* @return {?}
*/
DatepickerComponent.prototype.onDisplayWeeksChange = /**
* @return {?}
*/
function () {
var _this = this;
/** @type {?} */
var firstDayOfMonth = new Date(this.currentYear, this.currentMonth, 1);
/** @type {?} */
var weekOfDay = firstDayOfMonth.getDay();
/** @type {?} */
var startDate = new Date(firstDayOfMonth.getTime() - weekOfDay * DatepickerComponent.DAY_DURATION);
/** @type {?} */
var displayWeeks = [];
var _loop_1 = function (i) {
/** @type {?} */
var startWeekDate = startDate.getTime() + i * 7 * DatepickerComponent.DAY_DURATION;
/** @type {?} */
var weekDays = new Array(7).fill(0).map((/**
* @param {?} value
* @param {?} index
* @return {?}
*/
function (value, index) {
/** @type {?} */
var currentDate = new Date(startWeekDate + index * DatepickerComponent.DAY_DURATION);
return {
day: _this.fillLeft(currentDate.getDate()),
date: currentDate,
inMonth: currentDate.getMonth().toString() === _this.currentMonth.toString()
};
}));
displayWeeks.push(weekDays);
};
for (var i = 0; i < 6; i++) {
_loop_1(i);
}
this.displayWeeks = displayWeeks;
};
/**
* @return {?}
*/
DatepickerComponent.prototype.onDisplayMonthsChange = /**
* @return {?}
*/
function () {
var e_1, _a, e_2, _b;
/** @type {?} */
var all = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
if (this.currentYear > this.minDate.getFullYear() && this.currentYear < this.maxDate.getFullYear()) {
return all;
}
if (this.currentYear < this.minDate.getFullYear() || this.currentYear > this.maxDate.getFullYear()) {
return [];
}
/** @type {?} */
var returnValue = [];
if (this.currentYear === this.minDate.getFullYear()) {
try {
for (var all_1 = __values(all), all_1_1 = all_1.next(); !all_1_1.done; all_1_1 = all_1.next()) {
var month = all_1_1.value;
if (month >= this.minDate.getMonth()) {
returnValue.push(month);
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (all_1_1 && !all_1_1.done && (_a = all_1.return)) _a.call(all_1);
}
finally { if (e_1) throw e_1.error; }
}
return returnValue;
}
if (this.currentYear === this.maxDate.getFullYear()) {
try {
for (var all_2 = __values(all), all_2_1 = all_2.next(); !all_2_1.done; all_2_1 = all_2.next()) {
var month = all_2_1.value;
if (month <= this.maxDate.getMonth()) {
returnValue.push(month);
}
}
}
catch (e_2_1) { e_2 = { error: e_2_1 }; }
finally {
try {
if (all_2_1 && !all_2_1.done && (_b = all_2.return)) _b.call(all_2);
}
finally { if (e_2) throw e_2.error; }
}
return returnValue;
}
};
/**
* @protected
* @param {?} num
* @return {?}
*/
DatepickerComponent.prototype.fillLeft = /**
* @protected
* @param {?} num
* @return {?}
*/
function (num) {
return num < 10 ? "0" + num : "" + num;
};
/**
* @param {?} date
* @return {?}
*/
DatepickerComponent.prototype.isDisabledDay = /**
* @param {?} date
* @return {?}
*/
function (date) {
/** @type {?} */
var minDate = new Date(this.minDate.getFullYear(), this.minDate.getMonth(), this.minDate.getDate());
/** @type {?} */
var maxDate = new Date(this.maxDate.getFullYear(), this.maxDate.getMonth(), this.maxDate.getDate(), 23, 59, 59);
/** @type {?} */
var dis = date.getTime() < minDate.getTime();
return this.disabled || (date.getTime() < minDate.getTime() ||
date.getTime() > maxDate.getTime());
};
/**
* @param {?} date
* @return {?}
*/
DatepickerComponent.prototype.isSelectDay = /**
* @param {?} date
* @return {?}
*/
function (date) {
if (!this.selectedDate || !date) {
return false;
}
return (date.getFullYear() === this.selectedDate.getFullYear() &&
date.getMonth() === this.selectedDate.getMonth() &&
date.getDate() === this.selectedDate.getDate());
};
/*
** @param invocation:调用时机
*/
/*
** @param invocation:调用时机
*/
/**
* @param {?} $event
* @param {?} date
* @param {?=} invocation
* @return {?}
*/
DatepickerComponent.prototype.onSelectDate = /*
** @param invocation:调用时机
*/
/**
* @param {?} $event
* @param {?} date
* @param {?=} invocation
* @return {?}
*/
function ($event, date, invocation) {
if ($event.stopPropagation) {
$event.stopPropagation();
}
if (this.isDisabledDay(date)) {
return;
}
this.selectedDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), this.currentHour, this.currentMinute, this.currentSecond);
this.onTouched();
this.writeValue(this.selectedDate);
// 初始化的时候不触发emit和ngModelChange
if (invocation !== 'init') {
this.onChange(this.selectedDate);
this.selectedDateChange.emit({
reason: SelectDateChangeReason.date,
selectedDate: this.selectedDate
});
}
if (this.currentMonth !== this.selectedDate.getMonth() ||
this.currentYear !== this.selectedDate.getFullYear()) {
this.currentYear = this.selectedDate.getFullYear();
this.currentMonth = this.selectedDate.getMonth();
this.onDisplayWeeksChange();
}
};
/**
* @return {?}
*/
DatepickerComponent.prototype.onTimeChange = /**
* @return {?}
*/
function () {
/** @type {?} */
var date = this.selectedDate || new Date();
this.selectedDate = new Date(date.getFullYear(), date.getMonth(), date.getDate(), this.currentHour, this.currentMinute, this.currentSecond);
this.onTouched();
this.writeValue(this.selectedDate);
this.onChange(this.selectedDate);
this.selectedDateChange.emit({
reason: SelectDateChangeReason.time,
selectedDate: this.selectedDate
});
};
/**
* @param {?} type
* @return {?}
*/
DatepickerComponent.prototype.timeUp = /**
* @param {?} type
* @return {?}
*/
function (type) {
switch (type) {
case 'h': {
this.currentHour < 23 ? this.currentHour += 1 : this.currentHour = 0;
break;
}
case 'm': {
this.currentMinute < 59 ? this.currentMinute += 1 : this.currentMinute = 0;
break;
}
case 's': {
this.currentSecond < 59 ? this.currentSecond += 1 : this.currentSecond = 0;
break;
}
}
this.onTimeChange();
};
/**
* @param {?} type
* @return {?}
*/
DatepickerComponent.prototype.timeDown = /**
* @param {?} type
* @return {?}
*/
function (type) {
switch (type) {
case 'h': {
this.currentHour > 0 ? this.currentHour -= 1 : this.currentHour = 23;
break;
}
case 'm': {
this.currentMinute > 0 ? this.currentMinute -= 1 : this.currentMinute = 59;
break;
}
case 's': {
this.currentSecond > 0 ? this.currentSecond -= 1 : this.currentSecond = 59;
break;
}
}
this.onTimeChange();
};
/**
* @param {?} $event
* @return {?}
*/
DatepickerComponent.prototype.toggle = /**
* @param {?} $event
* @return {?}
*/
function ($event) {
$event.stopPropagation();
this.openChooseYearAndMonth = !this.openChooseYearAndMonth;
};
/**
* @return {?}
*/
DatepickerComponent.prototype.isTodayDisable = /**
* @return {?}
*/
function () {
return this.isDisabledDay(new Date());
};
/**
* @return {?}
*/
DatepickerComponent.prototype.isDisabledTime = /**
* @return {?}
*/
function () {
return this.isDisabledDay(this.selectedDate);
};
/**
* @return {?}
*/
DatepickerComponent.prototype.initDatePicker = /**
* @return {?}
*/
function () {
this.selectedDate = this.selectedDate ? this.selectedDate : new Date();
if (this.isDisabledDay(this.selectedDate)) {
return;
}
this.selectedDate = this.selectedDate ? this.selectedDate : new Date();
this.onSelectDateChanged();
this.onSelectDate({}, this.selectedDate, 'init');
};
/**
* @param {?} event
* @return {?}
*/
DatepickerComponent.prototype.confirmTime = /**
* @param {?} event
* @return {?}
*/
function (event) {
event.stopPropagation();
this.writeValue(this.selectedDate);
this.onChange(this.selectedDate);
this.selectedDateChange.emit({
reason: SelectDateChangeReason.button,
selectedDate: this.selectedDate
});
};
/**
* @return {?}
*/
DatepickerComponent.prototype.chooseToday = /**
* @return {?}
*/
function () {
/** @type {?} */
var today = new Date();
if (this.isDisabledDay(today)) {
return;
}
this.selectedDate = today;
this.onSelectDateChanged();
this.onSelectDate({}, today);
};
/**
* @param {?} $index
* @return {?}
*/
DatepickerComponent.prototype.onSelectMonth = /**
* @param {?} $index
* @return {?}
*/
function ($index) {
this.currentMonth = $index;
this.onDisplayWeeksChange();
};
/**
* @param {?} item
* @return {?}
*/
DatepickerComponent.prototype.changeHoverYear = /**
* @param {?} item
* @return {?}
*/
function (item) {
this.hoverYear = item;
};
/**
* @param {?} item
* @return {?}
*/
DatepickerComponent.prototype.changeHoverMonth = /**
* @param {?} item
* @return {?}
*/
function (item) {
this.hoverMonth = item;
};
Object.defineProperty(DatepickerComponent.prototype, "minDateDefined", {
get: /**
* @return {?}
*/
function () {
return this.minDate.getTime() !== new Date(this.dateConfig.min, 0, 1, 0, 0, 0).getTime();
},
enumerable: true,
configurable: true
});
Object.defineProperty(DatepickerComponent.prototype, "maxDateDefined", {
get: /**
* @return {?}
*/
function () {
return this.maxDate.getTime() !== new Date(this.dateConfig.max, 11, 31, 23, 59, 59).getTime();
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
DatepickerComponent.prototype.setI18nText = /**
* @return {?}
*/
function () {
var _this = this;
this.i18nText = this.i18n.getI18nText().datePicker;
this.i18nLocale = this.i18n.getI18nText().locale;
this.i18nCommonText = this.i18n.getI18nText().common;
this.i18nSubscription = this.i18n.langChange().subscribe((/**
* @param {?} data
* @return {?}
*/
function (data) {
_this.i18nText = data.datePicker;
_this.i18nLocale = data.locale;
_this.i18nCommonText = data.common;
}));
};
/**
* @return {?}
*/
DatepickerComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
if (this.i18nSubscription) {
this.i18nSubscription.unsubscribe();
}
};
DatepickerComponent.DAY_DURATION = 24 * 60 * 60 * 1000;
DatepickerComponent.decorators = [
{ type: core.Component, args: [{
selector: 'd-datepicker',
template: "<div class=\"devui-month-view {{ cssClass }}\">\r\n <table class=\"devui-table devui-month-view-table\">\r\n <thead class=\"devui-noSelect\">\r\n <tr>\r\n <td>\r\n <a\r\n *ngIf=\"openChooseYearAndMonth\"\r\n class=\"devui-btn-link\"\r\n aria-hidden=\"true\"\r\n (click)=\"onPreYearOption()\"\r\n [ngClass]=\"{\r\n 'devui-year-month-disabled': !hasPreYearOption() || !openChooseYearAndMonth\r\n }\"\r\n >\r\n <span class=\"left-triangle\"></span>\r\n <span class=\"left-triangle second\"></span>\r\n </a>\r\n </td>\r\n <td>\r\n <a\r\n class=\"devui-btn-link devui-btn-left\"\r\n aria-hidden=\"true\"\r\n (click)=\"onPreMonth()\"\r\n [ngClass]=\"{ 'devui-year-month-disabled': !hasPreMonth() }\"\r\n >\r\n <svg\r\n width=\"16px\"\r\n height=\"16px\"\r\n viewBox=\"0 0 16 16\"\r\n version=\"1.1\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\r\n >\r\n <g id=\"collapse-left\" stroke=\"none\" stroke-width=\"1\" fill-rule=\"evenodd\">\r\n <g>\r\n <polygon\r\n id=\"left-path\"\r\n fill-rule=\"nonzero\"\r\n points=\"10.7071068 12.2928932 9.29289322 13.7071068 3.58578644 8 9.29289322 2.29289322 10.7071068 3.70710678 6.41421356 8\"\r\n ></polygon>\r\n </g>\r\n </g>\r\n </svg>\r\n </a>\r\n </td>\r\n <td colspan=\"3\" class=\"devui-dropdown\" [ngClass]=\"{ open: openChooseYearAndMonth }\" (click)=\"toggle($event)\">\r\n <span class=\"devui-date-title\">{{ (i18nText?.monthsOfYear)[currentMonth] }}</span>\r\n <span class=\"devui-date-title\">{{ currentYear }}</span>\r\n <ul class=\"devui-dropdown-menu devui-monthOption text-center\">\r\n <li\r\n *ngFor=\"let month of availableMonths\"\r\n class=\"devui-dropdown-item\"\r\n (mouseover)=\"changeHoverMonth(month)\"\r\n (mouseleave)=\"changeHoverMonth(null)\"\r\n [ngClass]=\"{ active: currentMonth == month }\"\r\n (click)=\"onSelectMonth(month)\"\r\n >\r\n {{ month + 1 }}\r\n </li>\r\n </ul>\r\n <ul class=\"devui-dropdown-menu devui-yearOption text-center\">\r\n <li\r\n *ngFor=\"let item of yearOptions\"\r\n class=\"devui-dropdown-item\"\r\n (mouseover)=\"changeHoverYear(item)\"\r\n (mouseleave)=\"changeHoverYear(null)\"\r\n [ngClass]=\"{ active: currentYear == item }\"\r\n (click)=\"onSelectYear(item, $event)\"\r\n >\r\n {{ item }}\r\n </li>\r\n </ul>\r\n </td>\r\n <td>\r\n <a\r\n class=\"devui-btn-link devui-btn-right\"\r\n aria-hidden=\"true\"\r\n (click)=\"onNextMonth()\"\r\n [ngClass]=\"{ 'devui-year-month-disabled': !hasNextMonth() }\"\r\n >\r\n <svg\r\n width=\"16px\"\r\n height=\"16px\"\r\n viewBox=\"0 0 16 16\"\r\n version=\"1.1\"\r\n xmlns=\"http://www.w3.org/2000/svg\"\r\n xmlns:xlink=\"http://www.w3.org/1999/xlink\"\r\n >\r\n <g id=\"collapse-right\" stroke=\"none\" stroke-width=\"1\" fill-rule=\"evenodd\">\r\n <g>\r\n <polygon\r\n id=\"right-path\"\r\n fill-rule=\"nonzero\"\r\n points=\"10.7071068 12.2928932 9.29289322 13.7071068 3.58578644 8 9.29289322 2.29289322 10.7071068 3.70710678 6.41421356 8\"\r\n ></polygon>\r\n </g>\r\n </g>\r\n </svg>\r\n </a>\r\n </td>\r\n <td>\r\n <a\r\n *ngIf=\"openChooseYearAndMonth\"\r\n class=\"devui-btn-link\"\r\n aria-hidden=\"true\"\r\n (click)=\"onNextYearOption()\"\r\n [ngClass]=\"{\r\n 'devui-year-month-disabled': !hasNextYearOption() || !openChooseYearAndMonth\r\n }\"\r\n >\r\n <span class=\"right-triangle\"></span>\r\n <span class=\"right-triangle second\"></span>\r\n </a>\r\n </td>\r\n </tr>\r\n <tr class=\"small text-center devui-week-header\">\r\n <td *ngFor=\"let item of i18nText?.daysOfWeek\">{{ item }}</td>\r\n </tr>\r\n </thead>\r\n <tbody class=\"devui-noSelect\">\r\n <tr *ngFor=\"let week of displayWeeks\">\r\n <td\r\n