UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

973 lines (963 loc) 164 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/cdk/bidi'), 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('rxjs'), require('rxjs/operators'), require('ng-zorro-antd/core/config'), require('@angular/cdk/keycodes'), require('@angular/cdk/platform'), require('ng-zorro-antd/core/animation'), require('ng-zorro-antd/core/resize-observers')) : typeof define === 'function' && define.amd ? define('ng-zorro-antd/date-picker', ['exports', '@angular/cdk/bidi', '@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', 'rxjs', 'rxjs/operators', 'ng-zorro-antd/core/config', '@angular/cdk/keycodes', '@angular/cdk/platform', 'ng-zorro-antd/core/animation', 'ng-zorro-antd/core/resize-observers'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global['ng-zorro-antd'] = global['ng-zorro-antd'] || {}, global['ng-zorro-antd']['date-picker'] = {}), global.ng.cdk.bidi, 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.rxjs, global.rxjs.operators, global['ng-zorro-antd'].core.config, global.ng.cdk.keycodes, global.ng.cdk.platform, global['ng-zorro-antd'].core.animation, global['ng-zorro-antd'].core['resize-observers'])); }(this, (function (exports, bidi, overlay, common, core, forms, button, noAnimation, outlet, overlay$1, icon, timePicker, time, util, i18n, rxjs, operators, config, keycodes, platform, animation, resizeObservers) { 'use strict'; /** * 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 */ var PREFIX_CLASS = 'ant-picker'; var defaultDisabledTime = { nzDisabledHours: function () { return []; }, nzDisabledMinutes: function () { return []; }, nzDisabledSeconds: function () { return []; } }; function getTimeConfig(value, disabledTime) { var disabledTimeConfig = disabledTime ? disabledTime(value && value.nativeDate) : {}; disabledTimeConfig = Object.assign(Object.assign({}, defaultDisabledTime), disabledTimeConfig); return disabledTimeConfig; } function isTimeValidByConfig(value, disabledTimeConfig) { var invalidTime = false; if (value) { var hour = value.getHours(); var minutes = value.getMinutes(); var seconds = value.getSeconds(); var disabledHours = disabledTimeConfig.nzDisabledHours(); if (disabledHours.indexOf(hour) === -1) { var disabledMinutes = disabledTimeConfig.nzDisabledMinutes(hour); if (disabledMinutes.indexOf(minutes) === -1) { var disabledSeconds = disabledTimeConfig.nzDisabledSeconds(hour, minutes); invalidTime = disabledSeconds.indexOf(seconds) !== -1; } else { invalidTime = true; } } else { invalidTime = true; } } return !invalidTime; } function isTimeValid(value, disabledTime) { var disabledTimeConfig = getTimeConfig(value, disabledTime); return isTimeValidByConfig(value, disabledTimeConfig); } 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; } /** * 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/ * @link https://angular.io/api/common/DatePipe#description * @param format input format pattern */ 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 } /** * 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 */ var CalendarFooterComponent = /** @class */ (function () { function CalendarFooterComponent(dateHelper) { this.dateHelper = dateHelper; this.showToday = false; this.showNow = false; this.hasTimePicker = false; this.isRange = false; this.okDisabled = false; this.rangeQuickSelector = null; this.clickOk = new core.EventEmitter(); this.clickToday = new core.EventEmitter(); this.prefixCls = PREFIX_CLASS; this.isTemplateRef = util.isTemplateRef; this.isNonEmptyString = util.isNonEmptyString; this.isTodayDisabled = false; this.todayTitle = ''; } CalendarFooterComponent.prototype.ngOnChanges = function (changes) { var now = new Date(); if (changes.disabledDate) { this.isTodayDisabled = !!(this.disabledDate && this.disabledDate(now)); } if (changes.locale) { // NOTE: Compat for DatePipe formatting rules var dateFormat = transCompatFormat(this.locale.dateFormat); this.todayTitle = this.dateHelper.format(now, dateFormat); } }; CalendarFooterComponent.prototype.onClickToday = function () { var now = new time.CandyDate(); this.clickToday.emit(now.clone()); // To prevent the "now" being modified from outside, we use clone }; return CalendarFooterComponent; }()); 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=\"$any(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\"\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=\"showNow\" 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 " },] } ]; CalendarFooterComponent.ctorParameters = function () { return [ { type: i18n.DateHelperService } ]; }; CalendarFooterComponent.propDecorators = { locale: [{ type: core.Input }], showToday: [{ type: core.Input }], showNow: [{ 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 }] }; /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* 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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); 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 }; } } var __createBinding = Object.create ? (function (o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } }); }) : (function (o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; }); function __exportStar(m, o) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(o, p)) __createBinding(o, 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; } /** @deprecated */ function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } /** @deprecated */ 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 __spreadArray(to, from) { for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i]; return to; } 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; } ; var __setModuleDefault = Object.create ? (function (o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function (o, v) { o["default"] = v; }; function __importStar(mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, 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; } /** * 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 */ var DatePickerService = /** @class */ (function () { function DatePickerService() { this.activeInput = 'left'; this.arrowLeft = 0; this.isRange = false; this.valueChange$ = new rxjs.ReplaySubject(1); this.emitValue$ = new rxjs.Subject(); this.inputPartChange$ = new rxjs.Subject(); } DatePickerService.prototype.initValue = function () { if (this.isRange) { this.initialValue = []; } else { this.initialValue = null; } this.setValue(this.initialValue); }; DatePickerService.prototype.hasValue = function (value) { if (value === void 0) { value = this.value; } if (Array.isArray(value)) { return !!value[0] || !!value[1]; } else { return !!value; } }; DatePickerService.prototype.makeValue = function (value) { if (this.isRange) { return value ? value.map(function (val) { return new time.CandyDate(val); }) : []; } else { return value ? new time.CandyDate(value) : null; } }; DatePickerService.prototype.setActiveDate = function (value, hasTimePicker, mode) { if (hasTimePicker === void 0) { hasTimePicker = false; } if (mode === void 0) { mode = 'month'; } var parentPanels = { date: 'month', month: 'year', year: 'decade' }; if (this.isRange) { this.activeDate = time.normalizeRangeValue(value, hasTimePicker, parentPanels[mode], this.activeInput); } else { this.activeDate = time.cloneDate(value); } }; DatePickerService.prototype.setValue = function (value) { this.value = value; this.valueChange$.next(this.value); }; DatePickerService.prototype.getActiveIndex = function (part) { if (part === void 0) { part = this.activeInput; } return { left: 0, right: 1 }[part]; }; DatePickerService.prototype.ngOnDestroy = function () { this.valueChange$.complete(); this.emitValue$.complete(); this.inputPartChange$.complete(); }; return DatePickerService; }()); DatePickerService.decorators = [ { type: core.Injectable } ]; /** * 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 */ var DateRangePopupComponent = /** @class */ (function () { function DateRangePopupComponent(datePickerService, cdr) { var _this = this; this.datePickerService = datePickerService; this.cdr = cdr; this.inline = false; this.panelModeChange = new core.EventEmitter(); this.calendarChange = new core.EventEmitter(); this.resultOk = new core.EventEmitter(); // Emitted when done with date selecting this.dir = 'ltr'; this.prefixCls = PREFIX_CLASS; this.endPanelMode = 'date'; this.timeOptions = null; this.hoverValue = []; // Range ONLY this.checkedPartArr = [false, false]; this.destroy$ = new rxjs.Subject(); this.disabledStartTime = function (value) { return _this.disabledTime && _this.disabledTime(value, 'start'); }; this.disabledEndTime = function (value) { return _this.disabledTime && _this.disabledTime(value, 'end'); }; } Object.defineProperty(DateRangePopupComponent.prototype, "hasTimePicker", { get: function () { return !!this.showTime; }, enumerable: false, configurable: true }); Object.defineProperty(DateRangePopupComponent.prototype, "hasFooter", { get: function () { return this.showToday || this.hasTimePicker || !!this.extraFooter || !!this.ranges; }, enumerable: false, configurable: true }); DateRangePopupComponent.prototype.ngOnInit = function () { var _this = this; this.datePickerService.valueChange$.pipe(operators.takeUntil(this.destroy$)).subscribe(function () { _this.updateActiveDate(); _this.cdr.markForCheck(); }); }; DateRangePopupComponent.prototype.ngOnChanges = function (changes) { // Parse showTime options if (changes.showTime || changes.disabledTime) { if (this.showTime) { this.buildTimeOptions(); } } if (changes.panelMode) { this.endPanelMode = this.panelMode; } if (changes.defaultPickerValue) { this.updateActiveDate(); } }; DateRangePopupComponent.prototype.ngOnDestroy = function () { this.destroy$.next(); this.destroy$.complete(); }; DateRangePopupComponent.prototype.updateActiveDate = function () { var activeDate = this.datePickerService.hasValue() ? this.datePickerService.value : this.datePickerService.makeValue(this.defaultPickerValue); this.datePickerService.setActiveDate(activeDate, this.hasTimePicker, this.getPanelMode(this.endPanelMode)); }; DateRangePopupComponent.prototype.init = function () { this.checkedPartArr = [false, false]; this.updateActiveDate(); }; /** * Prevent input losing focus when click panel * @param event */ DateRangePopupComponent.prototype.onMousedown = function (event) { event.preventDefault(); }; DateRangePopupComponent.prototype.onClickOk = function () { var inputIndex = { left: 0, right: 1 }[this.datePickerService.activeInput]; var value = this.isRange ? this.datePickerService.value[inputIndex] : this.datePickerService.value; this.changeValueFromSelect(value); this.resultOk.emit(); }; DateRangePopupComponent.prototype.onClickToday = function (value) { this.changeValueFromSelect(value, !this.showTime); }; DateRangePopupComponent.prototype.onCellHover = function (value) { if (!this.isRange) { return; } var otherInputIndex = { left: 1, right: 0 }[this.datePickerService.activeInput]; var base = this.datePickerService.value[otherInputIndex]; if (base) { if (base.isBeforeDay(value)) { this.hoverValue = [base, value]; } else { this.hoverValue = [value, base]; } } }; DateRangePopupComponent.prototype.onPanelModeChange = function (mode, partType) { if (this.isRange) { var index = this.datePickerService.getActiveIndex(partType); if (index === 0) { this.panelMode = [mode, this.panelMode[1]]; } else { this.panelMode = [this.panelMode[0], mode]; } } else { this.panelMode = mode; } this.panelModeChange.emit(this.panelMode); }; DateRangePopupComponent.prototype.onActiveDateChange = function (value, partType) { if (this.isRange) { var activeDate = []; activeDate[this.datePickerService.getActiveIndex(partType)] = value; this.datePickerService.setActiveDate(activeDate, this.hasTimePicker, this.getPanelMode(this.endPanelMode, partType)); } else { this.datePickerService.setActiveDate(value); } }; DateRangePopupComponent.prototype.onSelectTime = function (value, partType) { if (this.isRange) { var newValue = time.cloneDate(this.datePickerService.value); var index = this.datePickerService.getActiveIndex(partType); newValue[index] = this.overrideHms(value, newValue[index]); this.datePickerService.setValue(newValue); } else { var newValue = this.overrideHms(value, this.datePickerService.value); this.datePickerService.setValue(newValue); // If not select a date currently, use today } this.datePickerService.inputPartChange$.next(); this.buildTimeOptions(); }; DateRangePopupComponent.prototype.changeValueFromSelect = function (value, emitValue) { if (emitValue === void 0) { emitValue = true; } if (this.isRange) { var selectedValue = time.cloneDate(this.datePickerService.value); var checkedPart = this.datePickerService.activeInput; var nextPart = checkedPart; selectedValue[this.datePickerService.getActiveIndex(checkedPart)] = value; this.checkedPartArr[this.datePickerService.getActiveIndex(checkedPart)] = true; this.hoverValue = selectedValue; if (emitValue) { if (this.inline) { // For UE, Should always be reversed, and clear vaue when next part is right nextPart = this.reversedPart(checkedPart); if (nextPart === 'right') { selectedValue[this.datePickerService.getActiveIndex(nextPart)] = null; this.checkedPartArr[this.datePickerService.getActiveIndex(nextPart)] = false; } this.datePickerService.setValue(selectedValue); this.calendarChange.emit(selectedValue); if (this.isBothAllowed(selectedValue) && this.checkedPartArr[0] && this.checkedPartArr[1]) { this.clearHoverValue(); this.datePickerService.emitValue$.next(); } } else { /** * if sort order is wrong, clear the other part's value */ if (time.wrongSortOrder(selectedValue)) { nextPart = this.reversedPart(checkedPart); selectedValue[this.datePickerService.getActiveIndex(nextPart)] = null; this.checkedPartArr[this.datePickerService.getActiveIndex(nextPart)] = false; } this.datePickerService.setValue(selectedValue); /** * range date usually selected paired, * so we emit the date value only both date is allowed and both part are checked */ if (this.isBothAllowed(selectedValue) && this.checkedPartArr[0] && this.checkedPartArr[1]) { this.calendarChange.emit(selectedValue); this.clearHoverValue(); this.datePickerService.emitValue$.next(); } else if (this.isAllowed(selectedValue)) { nextPart = this.reversedPart(checkedPart); this.calendarChange.emit([value.clone()]); } } } else { this.datePickerService.setValue(selectedValue); } this.datePickerService.inputPartChange$.next(nextPart); } else { this.datePickerService.setValue(value); this.datePickerService.inputPartChange$.next(); if (emitValue && this.isAllowed(value)) { this.datePickerService.emitValue$.next(); } } }; DateRangePopupComponent.prototype.reversedPart = function (part) { return part === 'left' ? 'right' : 'left'; }; DateRangePopupComponent.prototype.getPanelMode = function (panelMode, partType) { if (this.isRange) { return panelMode[this.datePickerService.getActiveIndex(partType)]; } else { return panelMode; } }; // Get single value or part value of a range DateRangePopupComponent.prototype.getValue = function (partType) { if (this.isRange) { return (this.datePickerService.value || [])[this.datePickerService.getActiveIndex(partType)]; } else { return this.datePickerService.value; } }; DateRangePopupComponent.prototype.getActiveDate = function (partType) { if (this.isRange) { return this.datePickerService.activeDate[this.datePickerService.getActiveIndex(partType)]; } else { return this.datePickerService.activeDate; } }; DateRangePopupComponent.prototype.isOneAllowed = function (selectedValue) { var index = this.datePickerService.getActiveIndex(); var disabledTimeArr = [this.disabledStartTime, this.disabledEndTime]; return isAllowedDate(selectedValue[index], this.disabledDate, disabledTimeArr[index]); }; DateRangePopupComponent.prototype.isBothAllowed = function (selectedValue) { return (isAllowedDate(selectedValue[0], this.disabledDate, this.disabledStartTime) && isAllowedDate(selectedValue[1], this.disabledDate, this.disabledEndTime)); }; DateRangePopupComponent.prototype.isAllowed = function (value, isBoth) { if (isBoth === void 0) { isBoth = false; } if (this.isRange) { return isBoth ? this.isBothAllowed(value) : this.isOneAllowed(value); } else { return isAllowedDate(value, this.disabledDate, this.disabledTime); } }; DateRangePopupComponent.prototype.getTimeOptions = function (partType) { if (this.showTime && this.timeOptions) { return this.timeOptions instanceof Array ? this.timeOptions[this.datePickerService.getActiveIndex(partType)] : this.timeOptions; } return null; }; DateRangePopupComponent.prototype.onClickPresetRange = function (val) { var value = typeof val === 'function' ? val() : val; if (value) { this.datePickerService.setValue([new time.CandyDate(value[0]), new time.CandyDate(value[1])]); this.datePickerService.emitValue$.next(); } }; DateRangePopupComponent.prototype.onPresetRangeMouseLeave = function () { this.clearHoverValue(); }; DateRangePopupComponent.prototype.onHoverPresetRange = function (val) { if (typeof val !== 'function') { this.hoverValue = [new time.CandyDate(val[0]), new time.CandyDate(val[1])]; } }; DateRangePopupComponent.prototype.getObjectKeys = function (obj) { return obj ? Object.keys(obj) : []; }; DateRangePopupComponent.prototype.show = function (partType) { var hide = this.showTime && this.isRange && this.datePickerService.activeInput !== partType; return !hide; }; DateRangePopupComponent.prototype.clearHoverValue = function () { this.hoverValue = []; }; DateRangePopupComponent.prototype.buildTimeOptions = function () { if (this.showTime) { var showTime = typeof this.showTime === 'object' ? this.showTime : {}; if (this.isRange) { var value = this.datePickerService.value; this.timeOptions = [this.overrideTimeOptions(showTime, value[0], 'start'), this.overrideTimeOptions(showTime, value[1], 'end')]; } else { this.timeOptions = this.overrideTimeOptions(showTime, this.datePickerService.value); } } else { this.timeOptions = null; } }; DateRangePopupComponent.prototype.overrideTimeOptions = function (origin, value, partial) { var disabledTimeFn; if (partial) { disabledTimeFn = partial === 'start' ? this.disabledStartTime : this.disabledEndTime; } else { disabledTimeFn = this.disabledTime; } return Object.assign(Object.assign({}, origin), getTimeConfig(value, disabledTimeFn)); }; DateRangePopupComponent.prototype.overrideHms = function (newValue, oldValue) { // tslint:disable-next-line:no-parameter-reassignment newValue = newValue || new time.CandyDate(); // tslint:disable-next-line:no-parameter-reassignment oldValue = oldValue || new time.CandyDate(); return oldValue.setHms(newValue.getHours(), newValue.getMinutes(), newValue.getSeconds()); }; return DateRangePopupComponent; }()); DateRangePopupComponent.decorators = [ { type: core.Component, args: [{ encapsulation: core.ViewEncapsulation.None, changeDetection: core.ChangeDetectionStrategy.OnPush, // tslint:disable-next-line:component-selector selector: 'date-range-popup', exportAs: 'dateRangePopup', template: "\n <ng-container *ngIf=\"isRange; else singlePanel\">\n <div class=\"{{ prefixCls }}-range-wrapper {{ prefixCls }}-date-range-wrapper\">\n <div class=\"{{ prefixCls }}-range-arrow\" [style.left.px]=\"datePickerService?.arrowLeft\"></div>\n <div class=\"{{ prefixCls }}-panel-container\">\n <div class=\"{{ prefixCls }}-panels\">\n <ng-container *ngTemplateOutlet=\"tplInnerPopup; context: { partType: 'left' }\"></ng-container>\n <ng-container *ngTemplateOutlet=\"tplInnerPopup; context: { partType: 'right' }\"></ng-container>\n </div>\n <ng-container *ngTemplateOutlet=\"tplFooter\"></ng-container>\n </div>\n </div>\n </ng-container>\n <ng-template #singlePanel>\n <div\n class=\"{{ prefixCls }}-panel-container {{ showWeek ? prefixCls + '-week-number' : '' }} {{\n hasTimePicker ? prefixCls + '-time' : ''\n }} {{ isRange ? prefixCls + '-range' : '' }}\"\n >\n <div class=\"{{ prefixCls }}-panel\" [class.ant-picker-panel-rtl]=\"dir === 'rtl'\" tabindex=\"-1\">\n <!-- Single ONLY -->\n <ng-container *ngTemplateOutlet=\"tplInnerPopup\"></ng-container>\n <ng-container *ngTemplateOutlet=\"tplFooter\"></ng-container>\n </div>\n </div>\n </ng-template>\n\n <ng-template #tplInnerPopup let-partType=\"partType\">\n <div class=\"{{ prefixCls }}-panel\" [class.ant-picker-panel-rtl]=\"dir === 'rtl'\" [style.display]=\"show(partType) ? 'block' : 'none'\">\n <!-- TODO(@wenqi73) [selectedValue] [hoverValue] types-->\n <inner-popup\n [showWeek]=\"showWeek\"\n [endPanelMode]=\"getPanelMode(endPanelMode, partType)\"\n [partType]=\"partType\"\n [locale]=\"locale!\"\n [showTimePicker]=\"hasTimePicker\"\n [timeOptions]=\"getTimeOptions(partType)\"\n [panelMode]=\"getPanelMode(panelMode, partType)\"\n (panelModeChange)=\"onPanelModeChange($event, partType)\"\n [activeDate]=\"getActiveDate(partType)\"\n [value]=\"getValue(partType)\"\n [disabledDate]=\"disabledDate\"\n [dateRender]=\"dateRender\"\n [selectedValue]=\"$any(datePickerService?.value)\"\n [hoverValue]=\"$any(hoverValue)\"\n (cellHover)=\"onCellHover($event)\"\n (selectDate)=\"changeValueFromSelect($event, !showTime)\"\n (selectTime)=\"onSelectTime($event, partType)\"\n (headerChange)=\"onActiveDateChange($event, partType)\"\n ></inner-popup>\n </div>\n </ng-template>\n\n <ng-template #tplFooter>\n <calendar-footer\n *ngIf=\"hasFooter\"\n [locale]=\"locale!\"\n [isRange]=\"isRange\"\n [showToday]=\"showToday\"\n [showNow]=\"showNow\"\n [hasTimePicker]=\"hasTimePicker\"\n [okDisabled]=\"!isAllowed($any(datePickerService?.value))\"\n [extraFooter]=\"extraFooter\"\n [rangeQuickSelector]=\"ranges ? tplRangeQuickSelector : null\"\n (clickOk)=\"onClickOk()\"\n (clickToday)=\"onClickToday($event)\"\n ></calendar-footer>\n </ng-template>\n\n <!-- Range ONLY: Range Quick Selector -->\n <ng-template #tplRangeQuickSelector>\n <li\n *ngFor=\"let name of getObjectKeys(ranges)\"\n class=\"{{ prefixCls }}-preset\"\n (click)=\"onClickPresetRange(ranges![name])\"\n (mouseenter)=\"onHoverPresetRange(ranges![name])\"\n (mouseleave)=\"onPresetRangeMouseLeave()\"\n >\n <span class=\"ant-tag ant-tag-blue\">{{ name }}</span>\n </li>\n </ng-template>\n ", host: { '(mousedown)': 'onMousedown($event)' } },] } ]; DateRangePopupComponent.ctorParameters = function () { return [ { type: DatePickerService }, { type: core.ChangeDetectorRef } ]; }; DateRangePopupComponent.propDecorators = { isRange: [{ type: core.Input }], inline: [{ type: core.Input }], showWeek: [{ type: core.Input }], locale: [{ type: core.Input }], disabledDate: [{ type: core.Input }], disabledTime: [{ type: core.Input }], showToday: [{ type: core.Input }], showNow: [{ type: core.Input }], showTime: [{ type: core.Input }], extraFooter: [{ type: core.Input }], ranges: [{ type: core.Input }], dateRender: [{ type: core.Input }], panelMode: [{ type: core.Input }], defaultPickerValue: [{ type: core.Input }], panelModeChange: [{ type: core.Output }], calendarChange: [{ type: core.Output }], resultOk: [{ type: core.Output }], dir: [{ type: core.Input }] }; /** * 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 */ var NzPickerComponent = /** @class */ (function () { function NzPickerComponent(elementRef, dateHelper, cdr, platform, nzResizeObserver, datePickerService, doc) { this.elementRef = elementRef; this.dateHelper = dateHelper; this.cdr = cdr; this.platform = platform; this.nzResizeObserver = nzResizeObserver; this.datePickerService = datePickerService; this.noAnimation = false; this.isRange = false; this.open = undefined; this.disabled = false; this.inputReadOnly = false; this.inline = false; this.popupStyle = null; this.dir = 'ltr'; this.nzId = null; this.focusChange = new core.EventEmitter(); this.valueChange = new core.EventEmitter(); this.openChange = new core.EventEmitter(); // Emitted when overlay's open state change this.inputSize = 12; this.destroy$ = new rxjs.Subject(); this.prefixCls = PREFIX_CLASS; this.activeBarStyle = {}; this.overlayOpen = false; // Available when "open"=undefined this.overlayPositions = [ { offsetX: -12, offsetY: 8, originX: 'start', originY: 'bottom', overlayX: 'start', overlayY: 'top' }, { offsetX: -12, offsetY: -8, originX: 'start', originY: 'top', overlayX: 'start', overlayY: 'bottom' }, { offsetX: 12, offsetY: 8, originX: 'end', originY: 'bottom', overlayX: 'end', overlayY: 'top' }, { offsetX: 12, offsetY: -8, originX: 'end', originY: 'top', overlayX: 'end', overlayY: 'bottom' } ]; this.currentPositionX = 'start'; this.currentPositionY = 'bottom'; this.document = doc; this.origin = new overlay.CdkOverlayOrigin(this.elementRef); } Object.defineProperty(NzPickerComponent.prototype, "realOpenState", { get: function () { // The value that really decide the open state of overlay return this.isOpenHandledByUser() ? !!this.open : this.overlayOpen; }, enumerable: false,