ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
1,269 lines (1,236 loc) • 205 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/overlay'), require('@angular/common'), require('@angular/core'), require('@angular/forms'), require('ng-zorro-antd/button'), require('ng-zorro-antd/core/no-animation'), require('ng-zorro-antd/core/outlet'), require('ng-zorro-antd/core/overlay'), require('ng-zorro-antd/icon'), require('ng-zorro-antd/time-picker'), require('ng-zorro-antd/core/time'), require('ng-zorro-antd/core/util'), require('ng-zorro-antd/i18n'), require('ng-zorro-antd/core/logger'), require('rxjs'), require('rxjs/operators'), require('ng-zorro-antd/core/config'), require('ng-zorro-antd/core/animation')) :
typeof define === 'function' && define.amd ? define('ng-zorro-antd/date-picker', ['exports', '@angular/cdk/overlay', '@angular/common', '@angular/core', '@angular/forms', 'ng-zorro-antd/button', 'ng-zorro-antd/core/no-animation', 'ng-zorro-antd/core/outlet', 'ng-zorro-antd/core/overlay', 'ng-zorro-antd/icon', 'ng-zorro-antd/time-picker', 'ng-zorro-antd/core/time', 'ng-zorro-antd/core/util', 'ng-zorro-antd/i18n', 'ng-zorro-antd/core/logger', 'rxjs', 'rxjs/operators', 'ng-zorro-antd/core/config', 'ng-zorro-antd/core/animation'], factory) :
(global = global || self, factory((global['ng-zorro-antd'] = global['ng-zorro-antd'] || {}, global['ng-zorro-antd']['date-picker'] = {}), global.ng.cdk.overlay, global.ng.common, global.ng.core, global.ng.forms, global['ng-zorro-antd'].button, global['ng-zorro-antd'].core['no-animation'], global['ng-zorro-antd'].core.outlet, global['ng-zorro-antd'].core.overlay, global['ng-zorro-antd'].icon, global['ng-zorro-antd']['time-picker'], global['ng-zorro-antd'].core.time, global['ng-zorro-antd'].core.util, global['ng-zorro-antd'].i18n, global['ng-zorro-antd'].core.logger, global.rxjs, global.rxjs.operators, global['ng-zorro-antd'].core.config, global['ng-zorro-antd'].core.animation));
}(this, (function (exports, overlay, common, core, forms, button, noAnimation, outlet, overlay$1, icon, timePicker, time, util, i18n, logger, rxjs, operators, config, animation) { '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) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
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) : adopt(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 s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
if (m) return m.call(o);
if (o && typeof o.length === "number") return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
}
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 };
}
function __classPrivateFieldGet(receiver, privateMap) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to get private field on non-instance");
}
return privateMap.get(receiver);
}
function __classPrivateFieldSet(receiver, privateMap, value) {
if (!privateMap.has(receiver)) {
throw new TypeError("attempted to set private field on non-instance");
}
privateMap.set(receiver, value);
return value;
}
/**
* @fileoverview added by tsickle
* Generated from: standard-types.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @license
* Copyright Alibaba.com All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
/**
* @record
*/
function PickerResultSingle() { }
if (false) {
/** @type {?} */
PickerResultSingle.prototype.date;
/** @type {?} */
PickerResultSingle.prototype.dateString;
}
/**
* @record
*/
function PickerResultRange() { }
if (false) {
/** @type {?} */
PickerResultRange.prototype.date;
/** @type {?} */
PickerResultRange.prototype.dateString;
}
/**
* @record
*/
function DisabledTimeConfig() { }
if (false) {
/**
* @return {?}
*/
DisabledTimeConfig.prototype.nzDisabledHours = function () { };
/**
* @param {?} hour
* @return {?}
*/
DisabledTimeConfig.prototype.nzDisabledMinutes = function (hour) { };
/**
* @param {?} hour
* @param {?} minute
* @return {?}
*/
DisabledTimeConfig.prototype.nzDisabledSeconds = function (hour, minute) { };
}
/**
* @record
*/
function SupportTimeOptions() { }
if (false) {
/** @type {?|undefined} */
SupportTimeOptions.prototype.nzFormat;
/** @type {?|undefined} */
SupportTimeOptions.prototype.nzHourStep;
/** @type {?|undefined} */
SupportTimeOptions.prototype.nzMinuteStep;
/** @type {?|undefined} */
SupportTimeOptions.prototype.nzSecondStep;
/** @type {?|undefined} */
SupportTimeOptions.prototype.nzHideDisabledOptions;
/** @type {?|undefined} */
SupportTimeOptions.prototype.nzDefaultOpenValue;
/** @type {?|undefined} */
SupportTimeOptions.prototype.nzAddOn;
/** @type {?|undefined} */
SupportTimeOptions.prototype.nzUse12Hours;
/**
* @return {?}
*/
SupportTimeOptions.prototype.nzDisabledHours = function () { };
/**
* @param {?} hour
* @return {?}
*/
SupportTimeOptions.prototype.nzDisabledMinutes = function (hour) { };
/**
* @param {?} hour
* @param {?} minute
* @return {?}
*/
SupportTimeOptions.prototype.nzDisabledSeconds = function (hour, minute) { };
}
/**
* @record
*/
function PresetRanges() { }
/**
* @fileoverview added by tsickle
* Generated from: util.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @license
* Copyright Alibaba.com All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
/** @type {?} */
var PREFIX_CLASS = 'ant-picker';
/** @type {?} */
var defaultDisabledTime = {
nzDisabledHours: /**
* @return {?}
*/
function () {
return [];
},
nzDisabledMinutes: /**
* @return {?}
*/
function () {
return [];
},
nzDisabledSeconds: /**
* @return {?}
*/
function () {
return [];
}
};
/**
* @param {?} value
* @param {?} disabledTime
* @return {?}
*/
function getTimeConfig(value, disabledTime) {
/** @type {?} */
var disabledTimeConfig = disabledTime ? disabledTime(value && value.nativeDate) : ((/** @type {?} */ ({})));
disabledTimeConfig = __assign(__assign({}, defaultDisabledTime), disabledTimeConfig);
return disabledTimeConfig;
}
/**
* @param {?} value
* @param {?} disabledTimeConfig
* @return {?}
*/
function isTimeValidByConfig(value, disabledTimeConfig) {
/** @type {?} */
var invalidTime = false;
if (value) {
/** @type {?} */
var hour = value.getHours();
/** @type {?} */
var minutes = value.getMinutes();
/** @type {?} */
var seconds = value.getSeconds();
/** @type {?} */
var disabledHours = disabledTimeConfig.nzDisabledHours();
if (disabledHours.indexOf(hour) === -1) {
/** @type {?} */
var disabledMinutes = disabledTimeConfig.nzDisabledMinutes(hour);
if (disabledMinutes.indexOf(minutes) === -1) {
/** @type {?} */
var disabledSeconds = disabledTimeConfig.nzDisabledSeconds(hour, minutes);
invalidTime = disabledSeconds.indexOf(seconds) !== -1;
}
else {
invalidTime = true;
}
}
else {
invalidTime = true;
}
}
return !invalidTime;
}
/**
* @param {?} value
* @param {?} disabledTime
* @return {?}
*/
function isTimeValid(value, disabledTime) {
/** @type {?} */
var disabledTimeConfig = getTimeConfig(value, disabledTime);
return isTimeValidByConfig(value, disabledTimeConfig);
}
/**
* @param {?} value
* @param {?=} disabledDate
* @param {?=} disabledTime
* @return {?}
*/
function isAllowedDate(value, disabledDate, disabledTime) {
if (!value) {
return false;
}
if (disabledDate) {
if (disabledDate(value.nativeDate)) {
return false;
}
}
if (disabledTime) {
if (!isTimeValid(value, disabledTime)) {
return false;
}
}
return true;
}
/**
* @fileoverview added by tsickle
* Generated from: lib/util.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @license
* Copyright Alibaba.com All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
*/
/**
* Compatible translate the moment-like format pattern to angular's pattern
* Why? For now, we need to support the existing language formats in AntD, and AntD uses the default temporal syntax.
*
* TODO: compare and complete all format patterns
* Each format docs as below:
* @link https://momentjs.com/docs/#/displaying/format/ / https://angular.io/api/common/DatePipe#description
* @param {?} format input format pattern
* @return {?}
*/
function transCompatFormat(format) {
return (format &&
format
.replace(/Y/g, 'y') // only support y, yy, yyy, yyyy
.replace(/D/g, 'd')); // d, dd represent of D, DD for momentjs, others are not support
}
/**
* @fileoverview added by tsickle
* Generated from: calendar-footer.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var CalendarFooterComponent = /** @class */ (function () {
function CalendarFooterComponent(dateHelper) {
this.dateHelper = dateHelper;
this.showToday = false;
this.hasTimePicker = false;
this.isRange = false;
this.okDisabled = false;
this.clickOk = new core.EventEmitter();
this.clickToday = new core.EventEmitter();
this.prefixCls = PREFIX_CLASS;
this.isTemplateRef = util.isTemplateRef;
this.isNonEmptyString = util.isNonEmptyString;
this.now = new time.CandyDate();
}
/**
* @param {?} changes
* @return {?}
*/
CalendarFooterComponent.prototype.ngOnChanges = /**
* @param {?} changes
* @return {?}
*/
function (changes) {
if (changes.disabledDate) {
this.isTodayDisabled = this.disabledDate && this.disabledDate(this.now.nativeDate);
}
if (changes.locale) {
// NOTE: Compat for DatePipe formatting rules
/** @type {?} */
var dateFormat = transCompatFormat(this.locale.dateFormat);
this.todayTitle = this.dateHelper.format(this.now.nativeDate, dateFormat);
}
};
/**
* @return {?}
*/
CalendarFooterComponent.prototype.onClickToday = /**
* @return {?}
*/
function () {
this.clickToday.emit(this.now.clone()); // To prevent the "now" being modified from outside, we use clone
};
CalendarFooterComponent.decorators = [
{ type: core.Component, args: [{
encapsulation: core.ViewEncapsulation.None,
changeDetection: core.ChangeDetectionStrategy.OnPush,
// tslint:disable-next-line:component-selector
selector: 'calendar-footer',
exportAs: 'calendarFooter',
template: "\n <div class=\"{{ prefixCls }}-footer\">\n <div *ngIf=\"extraFooter\" class=\"{{ prefixCls }}-footer-extra\">\n <ng-container [ngSwitch]=\"true\">\n <ng-container *ngSwitchCase=\"isTemplateRef(extraFooter)\">\n <ng-container *ngTemplateOutlet=\"extraFooter\"></ng-container>\n </ng-container>\n <ng-container *ngSwitchCase=\"isNonEmptyString(extraFooter)\">\n <span [innerHTML]=\"extraFooter\"></span>\n </ng-container>\n </ng-container>\n </div>\n <a\n *ngIf=\"showToday && !hasTimePicker\"\n class=\"{{ prefixCls }}-today-btn {{ isTodayDisabled ? prefixCls + '-today-btn-disabled' : '' }}\"\n role=\"button\"\n (click)=\"isTodayDisabled ? null : onClickToday()\"\n title=\"{{ todayTitle }}\"\n >\n {{ locale.today }}\n </a>\n <ul *ngIf=\"hasTimePicker || rangeQuickSelector\" class=\"{{ prefixCls }}-ranges\">\n <ng-container *ngTemplateOutlet=\"rangeQuickSelector\"></ng-container>\n <li *ngIf=\"hasTimePicker && !isRange\" class=\"{{ prefixCls }}-now\">\n <a class=\"{{ prefixCls }}-now-btn\" (click)=\"isTodayDisabled ? null : onClickToday()\">\n {{ locale.now }}\n </a>\n </li>\n <li *ngIf=\"hasTimePicker\" class=\"{{ prefixCls }}-ok\">\n <button\n nz-button\n type=\"button\"\n nzType=\"primary\"\n nzSize=\"small\"\n [disabled]=\"okDisabled\"\n (click)=\"okDisabled ? null : clickOk.emit()\"\n >\n {{ locale.ok }}\n </button>\n </li>\n </ul>\n </div>\n "
}] }
];
/** @nocollapse */
CalendarFooterComponent.ctorParameters = function () { return [
{ type: i18n.DateHelperService }
]; };
CalendarFooterComponent.propDecorators = {
locale: [{ type: core.Input }],
showToday: [{ type: core.Input }],
hasTimePicker: [{ type: core.Input }],
isRange: [{ type: core.Input }],
okDisabled: [{ type: core.Input }],
disabledDate: [{ type: core.Input }],
extraFooter: [{ type: core.Input }],
rangeQuickSelector: [{ type: core.Input }],
clickOk: [{ type: core.Output }],
clickToday: [{ type: core.Output }]
};
return CalendarFooterComponent;
}());
if (false) {
/** @type {?} */
CalendarFooterComponent.prototype.locale;
/** @type {?} */
CalendarFooterComponent.prototype.showToday;
/** @type {?} */
CalendarFooterComponent.prototype.hasTimePicker;
/** @type {?} */
CalendarFooterComponent.prototype.isRange;
/** @type {?} */
CalendarFooterComponent.prototype.okDisabled;
/** @type {?} */
CalendarFooterComponent.prototype.disabledDate;
/** @type {?} */
CalendarFooterComponent.prototype.extraFooter;
/** @type {?} */
CalendarFooterComponent.prototype.rangeQuickSelector;
/** @type {?} */
CalendarFooterComponent.prototype.clickOk;
/** @type {?} */
CalendarFooterComponent.prototype.clickToday;
/** @type {?} */
CalendarFooterComponent.prototype.prefixCls;
/** @type {?} */
CalendarFooterComponent.prototype.isTemplateRef;
/** @type {?} */
CalendarFooterComponent.prototype.isNonEmptyString;
/** @type {?} */
CalendarFooterComponent.prototype.isTodayDisabled;
/** @type {?} */
CalendarFooterComponent.prototype.todayTitle;
/**
* @type {?}
* @private
*/
CalendarFooterComponent.prototype.now;
/**
* @type {?}
* @private
*/
CalendarFooterComponent.prototype.dateHelper;
}
/**
* @fileoverview added by tsickle
* Generated from: date-picker.service.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DatePickerService = /** @class */ (function () {
function DatePickerService() {
this.activeInput = 'left';
this.arrowPositionStyle = {};
this.isRange = false;
this.valueChange$ = new rxjs.ReplaySubject(1);
this.emitValue$ = new rxjs.Subject();
this.inputPartChange$ = new rxjs.Subject();
}
/**
* @return {?}
*/
DatePickerService.prototype.initValue = /**
* @return {?}
*/
function () {
if (this.isRange) {
this.setActiveDate([]);
this.value = this.initialValue = [];
}
else {
this.value = this.initialValue = null;
}
};
/**
* @param {?=} value
* @return {?}
*/
DatePickerService.prototype.hasValue = /**
* @param {?=} value
* @return {?}
*/
function (value) {
if (value === void 0) { value = this.value; }
if (Array.isArray(value)) {
return !!value[0] && !!value[1];
}
else {
return !!value;
}
};
/**
* @param {?} value
* @return {?}
*/
DatePickerService.prototype.makeValue = /**
* @param {?} value
* @return {?}
*/
function (value) {
if (this.isRange) {
return value ? ((/** @type {?} */ (value))).map((/**
* @param {?} val
* @return {?}
*/
function (val) { return new time.CandyDate(val); })) : [];
}
else {
return value ? new time.CandyDate((/** @type {?} */ (value))) : null;
}
};
/**
* @param {?} value
* @param {?=} normalize
* @return {?}
*/
DatePickerService.prototype.setActiveDate = /**
* @param {?} value
* @param {?=} normalize
* @return {?}
*/
function (value, normalize) {
if (normalize === void 0) { normalize = false; }
if (this.isRange) {
this.activeDate = normalize ? time.normalizeRangeValue((/** @type {?} */ (value))) : value;
}
else {
this.activeDate = time.cloneDate(value);
}
};
/**
* @param {?} value
* @return {?}
*/
DatePickerService.prototype.setValue = /**
* @param {?} value
* @return {?}
*/
function (value) {
this.value = value;
this.valueChange$.next(this.value);
};
/**
* @param {?=} part
* @return {?}
*/
DatePickerService.prototype.getActiveIndex = /**
* @param {?=} part
* @return {?}
*/
function (part) {
if (part === void 0) { part = this.activeInput; }
return { left: 0, right: 1 }[part];
};
/**
* @return {?}
*/
DatePickerService.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.valueChange$.complete();
this.emitValue$.complete();
this.inputPartChange$.complete();
};
DatePickerService.decorators = [
{ type: core.Injectable }
];
return DatePickerService;
}());
if (false) {
/** @type {?} */
DatePickerService.prototype.initialValue;
/** @type {?} */
DatePickerService.prototype.value;
/** @type {?} */
DatePickerService.prototype.activeDate;
/** @type {?} */
DatePickerService.prototype.activeInput;
/** @type {?} */
DatePickerService.prototype.arrowPositionStyle;
/** @type {?} */
DatePickerService.prototype.isRange;
/** @type {?} */
DatePickerService.prototype.valueChange$;
/** @type {?} */
DatePickerService.prototype.emitValue$;
/** @type {?} */
DatePickerService.prototype.inputPartChange$;
}
/**
* @fileoverview added by tsickle
* Generated from: date-range-popup.component.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var DateRangePopupComponent = /** @class */ (function () {
function DateRangePopupComponent(datePickerService, cdr) {
var _this = this;
this.datePickerService = datePickerService;
this.cdr = cdr;
this.panelModeChange = new core.EventEmitter();
this.calendarChange = new core.EventEmitter();
this.resultOk = new core.EventEmitter(); // Emitted when done with date selecting
// Emitted when done with date selecting
this.prefixCls = PREFIX_CLASS;
this.endPanelMode = 'date';
this.hoverValue = []; // Range ONLY
// Range ONLY
this.destroy$ = new rxjs.Subject();
this.disabledStartTime = (/**
* @param {?} value
* @return {?}
*/
function (value) {
return _this.disabledTime && _this.disabledTime(value, 'start');
});
this.disabledEndTime = (/**
* @param {?} value
* @return {?}
*/
function (value) {
return _this.disabledTime && _this.disabledTime(value, 'end');
});
}
Object.defineProperty(DateRangePopupComponent.prototype, "hasTimePicker", {
get: /**
* @return {?}
*/
function () {
return !!this.showTime;
},
enumerable: true,
configurable: true
});
Object.defineProperty(DateRangePopupComponent.prototype, "hasFooter", {
get: /**
* @return {?}
*/
function () {
return this.showToday || this.hasTimePicker || !!this.extraFooter || !!this.ranges;
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
DateRangePopupComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
var _this = this;
this.datePickerService.valueChange$.pipe(operators.takeUntil(this.destroy$)).subscribe((/**
* @return {?}
*/
function () {
_this.initActiveDate();
_this.cdr.markForCheck();
}));
};
/**
* @param {?} changes
* @return {?}
*/
DateRangePopupComponent.prototype.ngOnChanges = /**
* @param {?} changes
* @return {?}
*/
function (changes) {
// Parse showTime options
if (changes.showTime || changes.disabledTime) {
if (this.showTime) {
this.buildTimeOptions();
}
}
if (changes.panelMode) {
this.endPanelMode = this.panelMode;
}
};
/**
* @return {?}
*/
DateRangePopupComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.destroy$.next();
this.destroy$.complete();
};
/**
* @return {?}
*/
DateRangePopupComponent.prototype.initActiveDate = /**
* @return {?}
*/
function () {
/** @type {?} */
var activeDate = this.datePickerService.hasValue()
? this.datePickerService.value
: this.datePickerService.makeValue(this.defaultPickerValue);
this.datePickerService.setActiveDate(activeDate, !this.showTime);
};
/**
* @return {?}
*/
DateRangePopupComponent.prototype.onClickOk = /**
* @return {?}
*/
function () {
/** @type {?} */
var otherPart = this.datePickerService.activeInput === 'left' ? 'right' : 'left';
/** @type {?} */
var selectedValue = this.datePickerService.value;
if (this.isAllowed(selectedValue, true)) {
this.resultOk.emit();
}
else {
if (this.isRange && this.isOneAllowed((/** @type {?} */ (selectedValue)))) {
this.datePickerService.inputPartChange$.next(otherPart);
}
else {
this.datePickerService.inputPartChange$.next();
}
}
};
/**
* @param {?} value
* @return {?}
*/
DateRangePopupComponent.prototype.onClickToday = /**
* @param {?} value
* @return {?}
*/
function (value) {
this.changeValueFromSelect(value, !this.showTime);
};
/**
* @param {?} value
* @return {?}
*/
DateRangePopupComponent.prototype.onDayHover = /**
* @param {?} value
* @return {?}
*/
function (value) {
if (!this.isRange) {
return;
}
/** @type {?} */
var otherInputIndex = { left: 1, right: 0 }[this.datePickerService.activeInput];
/** @type {?} */
var base = (/** @type {?} */ (((/** @type {?} */ (this.datePickerService.value)))[otherInputIndex]));
if (base) {
if (base.isBeforeDay(value)) {
this.hoverValue = [base, value];
}
else {
this.hoverValue = [value, base];
}
}
};
/**
* @param {?} mode
* @param {?=} partType
* @return {?}
*/
DateRangePopupComponent.prototype.onPanelModeChange = /**
* @param {?} mode
* @param {?=} partType
* @return {?}
*/
function (mode, partType) {
if (this.isRange) {
/** @type {?} */
var index = this.datePickerService.getActiveIndex(partType);
if (index === 0) {
this.panelMode = (/** @type {?} */ ([mode, this.panelMode[1]]));
}
else {
this.panelMode = (/** @type {?} */ ([this.panelMode[0], mode]));
}
}
else {
this.panelMode = mode;
}
// this.cdr.markForCheck();
this.panelModeChange.emit(this.panelMode);
};
/**
* @param {?} value
* @param {?} partType
* @return {?}
*/
DateRangePopupComponent.prototype.onActiveDateChange = /**
* @param {?} value
* @param {?} partType
* @return {?}
*/
function (value, partType) {
if (this.isRange) {
if (partType === 'left') {
this.datePickerService.activeDate = [value, value.addMonths(1)];
}
else {
this.datePickerService.activeDate = [value.addMonths(-1), value];
}
}
else {
this.datePickerService.activeDate = value;
}
};
/**
* @param {?} value
* @param {?=} partType
* @return {?}
*/
DateRangePopupComponent.prototype.onSelectTime = /**
* @param {?} value
* @param {?=} partType
* @return {?}
*/
function (value, partType) {
if (this.isRange) {
/** @type {?} */
var newValue = (/** @type {?} */ (time.cloneDate(this.datePickerService.value)));
/** @type {?} */
var index = this.datePickerService.getActiveIndex(partType);
newValue[index] = this.overrideHms(value, newValue[index]);
this.datePickerService.setValue(newValue);
}
else {
/** @type {?} */
var newValue = this.overrideHms(value, (/** @type {?} */ (this.datePickerService.value)));
this.datePickerService.setValue(newValue); // If not select a date currently, use today
}
this.datePickerService.inputPartChange$.next();
this.buildTimeOptions();
};
/**
* @param {?} value
* @param {?=} emitValue
* @return {?}
*/
DateRangePopupComponent.prototype.changeValueFromSelect = /**
* @param {?} value
* @param {?=} emitValue
* @return {?}
*/
function (value, emitValue) {
if (emitValue === void 0) { emitValue = true; }
if (this.isRange) {
/** @type {?} */
var selectedValue = (/** @type {?} */ (time.cloneDate(this.datePickerService.value)));
/** @type {?} */
var otherPart = void 0;
if (this.datePickerService.activeInput === 'left') {
otherPart = 'right';
selectedValue[0] = value;
}
else {
otherPart = 'left';
selectedValue[1] = value;
}
selectedValue = time.sortRangeValue(selectedValue);
this.hoverValue = selectedValue;
this.datePickerService.setValue(selectedValue);
this.datePickerService.setActiveDate(selectedValue, !this.showTime);
this.datePickerService.inputPartChange$.next();
if (!this.isAllowed(selectedValue)) {
return;
}
if (emitValue) {
// If the other input has value
if (this.isBothAllowed(selectedValue)) {
this.calendarChange.emit(selectedValue);
this.clearHoverValue();
this.datePickerService.emitValue$.next();
}
else {
this.calendarChange.emit([value.clone()]);
this.datePickerService.inputPartChange$.next((/** @type {?} */ (otherPart)));
}
}
}
else {
this.datePickerService.setValue(value);
this.datePickerService.setActiveDate(value, !this.showTime);
this.datePickerService.inputPartChange$.next();
if (!this.isAllowed(value)) {
return;
}
if (emitValue) {
this.datePickerService.emitValue$.next();
}
}
};
/**
* @param {?} panelMode
* @param {?=} partType
* @return {?}
*/
DateRangePopupComponent.prototype.getPanelMode = /**
* @param {?} panelMode
* @param {?=} partType
* @return {?}
*/
function (panelMode, partType) {
if (this.isRange) {
return (/** @type {?} */ (panelMode[this.datePickerService.getActiveIndex(partType)]));
}
else {
return (/** @type {?} */ (panelMode));
}
};
// Get single value or part value of a range
// Get single value or part value of a range
/**
* @param {?=} partType
* @return {?}
*/
DateRangePopupComponent.prototype.getValue =
// Get single value or part value of a range
/**
* @param {?=} partType
* @return {?}
*/
function (partType) {
if (this.isRange) {
return (((/** @type {?} */ (this.datePickerService.value))) || [])[this.datePickerService.getActiveIndex(partType)];
}
else {
return (/** @type {?} */ (this.datePickerService.value));
}
};
/**
* @param {?=} partType
* @return {?}
*/
DateRangePopupComponent.prototype.getActiveDate = /**
* @param {?=} partType
* @return {?}
*/
function (partType) {
if (this.isRange) {
return ((/** @type {?} */ (this.datePickerService.activeDate)))[this.datePickerService.getActiveIndex(partType)];
}
else {
return (/** @type {?} */ (this.datePickerService.activeDate));
}
};
/**
* @param {?} selectedValue
* @return {?}
*/
DateRangePopupComponent.prototype.isOneAllowed = /**
* @param {?} selectedValue
* @return {?}
*/
function (selectedValue) {
/** @type {?} */
var index = this.datePickerService.getActiveIndex();
/** @type {?} */
var disabledTimeArr = [this.disabledStartTime, this.disabledEndTime];
return isAllowedDate((/** @type {?} */ (selectedValue[index])), this.disabledDate, disabledTimeArr[index]);
};
/**
* @param {?} selectedValue
* @return {?}
*/
DateRangePopupComponent.prototype.isBothAllowed = /**
* @param {?} selectedValue
* @return {?}
*/
function (selectedValue) {
return (isAllowedDate((/** @type {?} */ (selectedValue[0])), this.disabledDate, this.disabledStartTime) &&
isAllowedDate((/** @type {?} */ (selectedValue[1])), this.disabledDate, this.disabledEndTime));
};
/**
* @param {?} value
* @param {?=} isBoth
* @return {?}
*/
DateRangePopupComponent.prototype.isAllowed = /**
* @param {?} value
* @param {?=} isBoth
* @return {?}
*/
function (value, isBoth) {
if (isBoth === void 0) { isBoth = false; }
if (this.isRange) {
return isBoth ? this.isBothAllowed((/** @type {?} */ (value))) : this.isOneAllowed((/** @type {?} */ (value)));
}
else {
return isAllowedDate((/** @type {?} */ (value)), this.disabledDate, this.disabledTime);
}
};
/**
* @param {?=} partType
* @return {?}
*/
DateRangePopupComponent.prototype.getTimeOptions = /**
* @param {?=} partType
* @return {?}
*/
function (partType) {
if (this.showTime && this.timeOptions) {
return this.timeOptions instanceof Array ? this.timeOptions[this.datePickerService.getActiveIndex(partType)] : this.timeOptions;
}
return null;
};
/**
* @param {?} val
* @return {?}
*/
DateRangePopupComponent.prototype.onClickPresetRange = /**
* @param {?} val
* @return {?}
*/
function (val) {
/** @type {?} */
var value = typeof val === 'function' ? val() : val;
if (value) {
this.datePickerService.setValue([new time.CandyDate(value[0]), new time.CandyDate(value[1])]);
this.resultOk.emit();
}
};
/**
* @return {?}
*/
DateRangePopupComponent.prototype.onPresetRangeMouseLeave = /**
* @return {?}
*/
function () {
this.clearHoverValue();
};
/**
* @param {?} val
* @return {?}
*/
DateRangePopupComponent.prototype.onHoverPresetRange = /**
* @param {?} val
* @return {?}
*/
function (val) {
if (typeof val !== 'function') {
this.hoverValue = [new time.CandyDate(val[0]), new time.CandyDate(val[1])];
}
};
/**
* @param {?} obj
* @return {?}
*/
DateRangePopupComponent.prototype.getObjectKeys = /**
* @param {?} obj
* @return {?}
*/
function (obj) {
return obj ? Object.keys(obj) : [];
};
/**
* @param {?} partType
* @return {?}
*/
DateRangePopupComponent.prototype.show = /**
* @param {?} partType
* @return {?}
*/
function (partType) {
/** @type {?} */
var hide = this.showTime && this.isRange && this.datePickerService.activeInput !== partType;
return !hide;
};
/**
* @private
* @return {?}
*/
DateRangePopupComponent.prototype.clearHoverValue = /**
* @private
* @return {?}
*/
function () {
this.hoverValue = [];
};
/**
* @private
* @return {?}
*/
DateRangePopupComponent.prototype.buildTimeOptions = /**
* @private
* @return {?}
*/
function () {
if (this.showTime) {
/** @type {?} */
var showTime = typeof this.showTime === 'object' ? this.showTime : {};
if (this.isRange) {
/** @type {?} */
var value = (/** @type {?} */ (this.datePickerService.value));
this.timeOptions = [this.overrideTimeOptions(showTime, value[0], 'start'), this.overrideTimeOptions(showTime, value[1], 'end')];
}
else {
this.timeOptions = this.overrideTimeOptions(showTime, (/** @type {?} */ (this.datePickerService.value)));
}
}
else {
this.timeOptions = null;
}
};
/**
* @private
* @param {?} origin
* @param {?} value
* @param {?=} partial
* @return {?}
*/
DateRangePopupComponent.prototype.overrideTimeOptions = /**
* @private
* @param {?} origin
* @param {?} value
* @param {?=} partial
* @return {?}
*/
function (origin, value, partial) {
/** @type {?} */
var disabledTimeFn;
if (partial) {
disabledTimeFn = partial === 'start' ? this.disabledStartTime : this.disabledEndTime;
}
else {
disabledTimeFn = this.disabledTime;
}
return __assign(__assign({}, origin), getTimeConfig(value, disabledTimeFn));
};
/**
* @private
* @param {?} newValue