UNPKG

ng-zorro-antd

Version:

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

804 lines (794 loc) 193 kB
import * as i6 from '@angular/cdk/bidi'; import { BidiModule } from '@angular/cdk/bidi'; import * as i11$1 from '@angular/cdk/overlay'; import { CdkOverlayOrigin, CdkConnectedOverlay, OverlayModule } from '@angular/cdk/overlay'; import * as i2 from '@angular/common'; import { DOCUMENT, CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { EventEmitter, Component, ViewEncapsulation, ChangeDetectionStrategy, Input, Output, Injectable, Directive, forwardRef, Inject, Optional, Host, ViewChild, ViewChildren, NgModule } from '@angular/core'; import * as i10 from '@angular/forms'; import { NG_VALUE_ACCESSOR, FormsModule } from '@angular/forms'; import * as i3 from 'ng-zorro-antd/button'; import { NzButtonModule } from 'ng-zorro-antd/button'; import * as i8 from 'ng-zorro-antd/core/form'; import { NzFormPatchModule } from 'ng-zorro-antd/core/form'; import * as i7 from 'ng-zorro-antd/core/no-animation'; import { NzNoAnimationModule } from 'ng-zorro-antd/core/no-animation'; import * as i14 from 'ng-zorro-antd/core/outlet'; import { NzOutletModule } from 'ng-zorro-antd/core/outlet'; import * as i13 from 'ng-zorro-antd/core/overlay'; import { DEFAULT_DATE_PICKER_POSITIONS, DATE_PICKER_POSITION_MAP, NzOverlayModule } from 'ng-zorro-antd/core/overlay'; import * as i12 from 'ng-zorro-antd/icon'; import { NzIconModule } from 'ng-zorro-antd/icon'; import * as i11 from 'ng-zorro-antd/time-picker'; import { NzTimePickerModule } from 'ng-zorro-antd/time-picker'; import { CandyDate, normalizeRangeValue, cloneDate, wrongSortOrder } from 'ng-zorro-antd/core/time'; import { isTemplateRef, isNonEmptyString, valueFunctionProp, toBoolean, getStatusClassNames, InputBoolean } from 'ng-zorro-antd/core/util'; import * as i1 from 'ng-zorro-antd/i18n'; import { NzI18nModule } from 'ng-zorro-antd/i18n'; import * as i4 from 'ng-zorro-antd/core/transition-patch'; import * as i5 from 'ng-zorro-antd/core/wave'; import { __decorate } from 'tslib'; import { ESCAPE } from '@angular/cdk/keycodes'; import { ReplaySubject, Subject, merge, fromEvent, of } from 'rxjs'; import { takeUntil, distinctUntilChanged, withLatestFrom, map } from 'rxjs/operators'; import { slideMotion } from 'ng-zorro-antd/core/animation'; import * as i1$1 from 'ng-zorro-antd/core/config'; import { WithConfig } from 'ng-zorro-antd/core/config'; import * as i4$1 from 'ng-zorro-antd/cdk/resize-observer'; import * as i5$1 from '@angular/cdk/platform'; /** * 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 */ const PREFIX_CLASS = 'ant-picker'; const defaultDisabledTime = { nzDisabledHours() { return []; }, nzDisabledMinutes() { return []; }, nzDisabledSeconds() { return []; } }; function getTimeConfig(value, disabledTime) { let disabledTimeConfig = disabledTime ? disabledTime(value && value.nativeDate) : {}; disabledTimeConfig = Object.assign(Object.assign({}, defaultDisabledTime), disabledTimeConfig); return disabledTimeConfig; } function isTimeValidByConfig(value, disabledTimeConfig) { let invalidTime = false; if (value) { const hour = value.getHours(); const minutes = value.getMinutes(); const seconds = value.getSeconds(); const disabledHours = disabledTimeConfig.nzDisabledHours(); if (disabledHours.indexOf(hour) === -1) { const disabledMinutes = disabledTimeConfig.nzDisabledMinutes(hour); if (disabledMinutes.indexOf(minutes) === -1) { const disabledSeconds = disabledTimeConfig.nzDisabledSeconds(hour, minutes); invalidTime = disabledSeconds.indexOf(seconds) !== -1; } else { invalidTime = true; } } else { invalidTime = true; } } return !invalidTime; } function isTimeValid(value, disabledTime) { const 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 */ class CalendarFooterComponent { constructor(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 EventEmitter(); this.clickToday = new EventEmitter(); this.prefixCls = PREFIX_CLASS; this.isTemplateRef = isTemplateRef; this.isNonEmptyString = isNonEmptyString; this.isTodayDisabled = false; this.todayTitle = ''; } ngOnChanges(changes) { const now = new Date(); if (changes.disabledDate) { this.isTodayDisabled = !!(this.disabledDate && this.disabledDate(now)); } if (changes.locale) { // NOTE: Compat for DatePipe formatting rules const dateFormat = transCompatFormat(this.locale.dateFormat); this.todayTitle = this.dateHelper.format(now, dateFormat); } } onClickToday() { const now = new CandyDate(); this.clickToday.emit(now.clone()); // To prevent the "now" being modified from outside, we use clone } } CalendarFooterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: CalendarFooterComponent, deps: [{ token: i1.DateHelperService }], target: i0.ɵɵFactoryTarget.Component }); CalendarFooterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.1.3", type: CalendarFooterComponent, selector: "calendar-footer", inputs: { locale: "locale", showToday: "showToday", showNow: "showNow", hasTimePicker: "hasTimePicker", isRange: "isRange", okDisabled: "okDisabled", disabledDate: "disabledDate", extraFooter: "extraFooter", rangeQuickSelector: "rangeQuickSelector" }, outputs: { clickOk: "clickOk", clickToday: "clickToday" }, exportAs: ["calendarFooter"], usesOnChanges: true, ngImport: i0, template: ` <div class="{{ prefixCls }}-footer"> <div *ngIf="extraFooter" class="{{ prefixCls }}-footer-extra"> <ng-container [ngSwitch]="true"> <ng-container *ngSwitchCase="isTemplateRef(extraFooter)"> <ng-container *ngTemplateOutlet="$any(extraFooter)"></ng-container> </ng-container> <ng-container *ngSwitchCase="isNonEmptyString(extraFooter)"> <span [innerHTML]="extraFooter"></span> </ng-container> </ng-container> </div> <a *ngIf="showToday" class="{{ prefixCls }}-today-btn {{ isTodayDisabled ? prefixCls + '-today-btn-disabled' : '' }}" role="button" (click)="isTodayDisabled ? null : onClickToday()" title="{{ todayTitle }}" > {{ locale.today }} </a> <ul *ngIf="hasTimePicker || rangeQuickSelector" class="{{ prefixCls }}-ranges"> <ng-container *ngTemplateOutlet="rangeQuickSelector"></ng-container> <li *ngIf="showNow" class="{{ prefixCls }}-now"> <a class="{{ prefixCls }}-now-btn" (click)="isTodayDisabled ? null : onClickToday()"> {{ locale.now }} </a> </li> <li *ngIf="hasTimePicker" class="{{ prefixCls }}-ok"> <button nz-button type="button" nzType="primary" nzSize="small" [disabled]="okDisabled" (click)="okDisabled ? null : clickOk.emit()" > {{ locale.ok }} </button> </li> </ul> </div> `, isInline: true, dependencies: [{ kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i2.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i2.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "component", type: i3.NzButtonComponent, selector: "button[nz-button], a[nz-button]", inputs: ["nzBlock", "nzGhost", "nzSearch", "nzLoading", "nzDanger", "disabled", "tabIndex", "nzType", "nzShape", "nzSize"], exportAs: ["nzButton"] }, { kind: "directive", type: i4.ɵNzTransitionPatchDirective, selector: "[nz-button], nz-button-group, [nz-icon], [nz-menu-item], [nz-submenu], nz-select-top-control, nz-select-placeholder, nz-input-group", inputs: ["hidden"] }, { kind: "directive", type: i5.NzWaveDirective, selector: "[nz-wave],button[nz-button]:not([nzType=\"link\"]):not([nzType=\"text\"])", inputs: ["nzWaveExtraNode"], exportAs: ["nzWave"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: CalendarFooterComponent, decorators: [{ type: Component, args: [{ encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, // eslint-disable-next-line @angular-eslint/component-selector selector: 'calendar-footer', exportAs: 'calendarFooter', template: ` <div class="{{ prefixCls }}-footer"> <div *ngIf="extraFooter" class="{{ prefixCls }}-footer-extra"> <ng-container [ngSwitch]="true"> <ng-container *ngSwitchCase="isTemplateRef(extraFooter)"> <ng-container *ngTemplateOutlet="$any(extraFooter)"></ng-container> </ng-container> <ng-container *ngSwitchCase="isNonEmptyString(extraFooter)"> <span [innerHTML]="extraFooter"></span> </ng-container> </ng-container> </div> <a *ngIf="showToday" class="{{ prefixCls }}-today-btn {{ isTodayDisabled ? prefixCls + '-today-btn-disabled' : '' }}" role="button" (click)="isTodayDisabled ? null : onClickToday()" title="{{ todayTitle }}" > {{ locale.today }} </a> <ul *ngIf="hasTimePicker || rangeQuickSelector" class="{{ prefixCls }}-ranges"> <ng-container *ngTemplateOutlet="rangeQuickSelector"></ng-container> <li *ngIf="showNow" class="{{ prefixCls }}-now"> <a class="{{ prefixCls }}-now-btn" (click)="isTodayDisabled ? null : onClickToday()"> {{ locale.now }} </a> </li> <li *ngIf="hasTimePicker" class="{{ prefixCls }}-ok"> <button nz-button type="button" nzType="primary" nzSize="small" [disabled]="okDisabled" (click)="okDisabled ? null : clickOk.emit()" > {{ locale.ok }} </button> </li> </ul> </div> ` }] }], ctorParameters: function () { return [{ type: i1.DateHelperService }]; }, propDecorators: { locale: [{ type: Input }], showToday: [{ type: Input }], showNow: [{ type: Input }], hasTimePicker: [{ type: Input }], isRange: [{ type: Input }], okDisabled: [{ type: Input }], disabledDate: [{ type: Input }], extraFooter: [{ type: Input }], rangeQuickSelector: [{ type: Input }], clickOk: [{ type: Output }], clickToday: [{ type: Output }] } }); /** * 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 */ class DatePickerService { constructor() { this.activeInput = 'left'; this.arrowLeft = 0; this.isRange = false; this.valueChange$ = new ReplaySubject(1); this.emitValue$ = new Subject(); this.inputPartChange$ = new Subject(); } initValue(reset = false) { if (reset) { this.initialValue = this.isRange ? [] : null; } this.setValue(this.initialValue); } hasValue(value = this.value) { if (Array.isArray(value)) { return !!value[0] || !!value[1]; } else { return !!value; } } makeValue(value) { if (this.isRange) { return value ? value.map(val => new CandyDate(val)) : []; } else { return value ? new CandyDate(value) : null; } } setActiveDate(value, hasTimePicker = false, mode = 'month') { const parentPanels = { date: 'month', month: 'year', year: 'decade' }; if (this.isRange) { this.activeDate = normalizeRangeValue(value, hasTimePicker, parentPanels[mode], this.activeInput); } else { this.activeDate = cloneDate(value); } } setValue(value) { this.value = value; this.valueChange$.next(this.value); } getActiveIndex(part = this.activeInput) { return { left: 0, right: 1 }[part]; } ngOnDestroy() { this.valueChange$.complete(); this.emitValue$.complete(); this.inputPartChange$.complete(); } } DatePickerService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: DatePickerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); DatePickerService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: DatePickerService }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: DatePickerService, decorators: [{ type: 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 */ // eslint-disable-next-line @angular-eslint/directive-class-suffix class AbstractPanelHeader { constructor() { this.prefixCls = `ant-picker-header`; this.selectors = []; this.showSuperPreBtn = true; this.showSuperNextBtn = true; this.showPreBtn = true; this.showNextBtn = true; this.panelModeChange = new EventEmitter(); this.valueChange = new EventEmitter(); } superPreviousTitle() { return this.locale.previousYear; } previousTitle() { return this.locale.previousMonth; } superNextTitle() { return this.locale.nextYear; } nextTitle() { return this.locale.nextMonth; } superPrevious() { this.changeValue(this.value.addYears(-1)); } superNext() { this.changeValue(this.value.addYears(1)); } previous() { this.changeValue(this.value.addMonths(-1)); } next() { this.changeValue(this.value.addMonths(1)); } changeValue(value) { if (this.value !== value) { this.value = value; this.valueChange.emit(this.value); this.render(); } } changeMode(mode) { this.panelModeChange.emit(mode); } render() { if (this.value) { this.selectors = this.getSelectors(); } } ngOnInit() { if (!this.value) { this.value = new CandyDate(); // Show today by default } this.selectors = this.getSelectors(); } ngOnChanges(changes) { if (changes.value || changes.locale) { this.render(); } } } AbstractPanelHeader.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: AbstractPanelHeader, deps: [], target: i0.ɵɵFactoryTarget.Directive }); AbstractPanelHeader.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.1.3", type: AbstractPanelHeader, inputs: { value: "value", locale: "locale", showSuperPreBtn: "showSuperPreBtn", showSuperNextBtn: "showSuperNextBtn", showPreBtn: "showPreBtn", showNextBtn: "showNextBtn" }, outputs: { panelModeChange: "panelModeChange", valueChange: "valueChange" }, usesOnChanges: true, ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: AbstractPanelHeader, decorators: [{ type: Directive }], propDecorators: { value: [{ type: Input }], locale: [{ type: Input }], showSuperPreBtn: [{ type: Input }], showSuperNextBtn: [{ type: Input }], showPreBtn: [{ type: Input }], showNextBtn: [{ type: Input }], panelModeChange: [{ type: Output }], valueChange: [{ type: Output }] } }); /** * 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 */ class DateHeaderComponent extends AbstractPanelHeader { constructor(dateHelper) { super(); this.dateHelper = dateHelper; } getSelectors() { return [ { className: `${this.prefixCls}-year-btn`, title: this.locale.yearSelect, onClick: () => this.changeMode('year'), label: this.dateHelper.format(this.value.nativeDate, transCompatFormat(this.locale.yearFormat)) }, { className: `${this.prefixCls}-month-btn`, title: this.locale.monthSelect, onClick: () => this.changeMode('month'), label: this.dateHelper.format(this.value.nativeDate, this.locale.monthFormat || 'MMM') } ]; } } DateHeaderComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: DateHeaderComponent, deps: [{ token: i1.DateHelperService }], target: i0.ɵɵFactoryTarget.Component }); DateHeaderComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.1.3", type: DateHeaderComponent, selector: "date-header", exportAs: ["dateHeader"], usesInheritance: true, ngImport: i0, template: "<div class=\"{{ prefixCls }}\">\n <button\n [style.visibility]=\"showSuperPreBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-super-prev-btn\"\n role=\"button\"\n type=\"button\"\n tabindex=\"-1\"\n title=\"{{ superPreviousTitle() }}\"\n (click)=\"superPrevious()\"\n >\n <span class=\"ant-picker-super-prev-icon\"></span>\n </button>\n <button\n [style.visibility]=\"showPreBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-prev-btn\"\n role=\"button\"\n type=\"button\"\n title=\"{{ previousTitle() }}\"\n tabindex=\"-1\"\n (click)=\"previous()\"\n >\n <span class=\"ant-picker-prev-icon\"></span>\n </button>\n\n <div class=\"{{ prefixCls }}-view\">\n <ng-container *ngFor=\"let selector of selectors\">\n <button\n class=\"{{ selector.className }}\"\n role=\"button\"\n type=\"button\"\n title=\"{{ selector.title || null }}\"\n (click)=\"selector.onClick()\"\n >\n {{ selector.label }}\n </button>\n </ng-container>\n </div>\n <button\n [style.visibility]=\"showNextBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-next-btn\"\n role=\"button\"\n type=\"button\"\n tabindex=\"-1\"\n title=\"{{ nextTitle() }}\"\n (click)=\"next()\"\n >\n <span class=\"ant-picker-next-icon\"></span>\n </button>\n <button\n [style.visibility]=\"showSuperNextBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-super-next-btn\"\n role=\"button\"\n type=\"button\"\n tabindex=\"-1\"\n title=\"{{ superNextTitle() }}\"\n (click)=\"superNext()\"\n >\n <span class=\"ant-picker-super-next-icon\"></span>\n </button>\n</div>\n", dependencies: [{ kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: DateHeaderComponent, decorators: [{ type: Component, args: [{ encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, selector: 'date-header', exportAs: 'dateHeader', template: "<div class=\"{{ prefixCls }}\">\n <button\n [style.visibility]=\"showSuperPreBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-super-prev-btn\"\n role=\"button\"\n type=\"button\"\n tabindex=\"-1\"\n title=\"{{ superPreviousTitle() }}\"\n (click)=\"superPrevious()\"\n >\n <span class=\"ant-picker-super-prev-icon\"></span>\n </button>\n <button\n [style.visibility]=\"showPreBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-prev-btn\"\n role=\"button\"\n type=\"button\"\n title=\"{{ previousTitle() }}\"\n tabindex=\"-1\"\n (click)=\"previous()\"\n >\n <span class=\"ant-picker-prev-icon\"></span>\n </button>\n\n <div class=\"{{ prefixCls }}-view\">\n <ng-container *ngFor=\"let selector of selectors\">\n <button\n class=\"{{ selector.className }}\"\n role=\"button\"\n type=\"button\"\n title=\"{{ selector.title || null }}\"\n (click)=\"selector.onClick()\"\n >\n {{ selector.label }}\n </button>\n </ng-container>\n </div>\n <button\n [style.visibility]=\"showNextBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-next-btn\"\n role=\"button\"\n type=\"button\"\n tabindex=\"-1\"\n title=\"{{ nextTitle() }}\"\n (click)=\"next()\"\n >\n <span class=\"ant-picker-next-icon\"></span>\n </button>\n <button\n [style.visibility]=\"showSuperNextBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-super-next-btn\"\n role=\"button\"\n type=\"button\"\n tabindex=\"-1\"\n title=\"{{ superNextTitle() }}\"\n (click)=\"superNext()\"\n >\n <span class=\"ant-picker-super-next-icon\"></span>\n </button>\n</div>\n" }] }], ctorParameters: function () { return [{ type: i1.DateHelperService }]; } }); /** * 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 */ // eslint-disable-next-line @angular-eslint/directive-class-suffix class AbstractTable { constructor() { this.isTemplateRef = isTemplateRef; this.isNonEmptyString = isNonEmptyString; this.headRow = []; this.bodyRows = []; this.MAX_ROW = 6; this.MAX_COL = 7; this.prefixCls = 'ant-picker'; this.activeDate = new CandyDate(); this.showWeek = false; this.selectedValue = []; // Range ONLY this.hoverValue = []; // Range ONLY this.valueChange = new EventEmitter(); this.cellHover = new EventEmitter(); // Emitted when hover on a day by mouse enter } render() { if (this.activeDate) { this.headRow = this.makeHeadRow(); this.bodyRows = this.makeBodyRows(); } } trackByBodyRow(_index, item) { return item.trackByIndex; } trackByBodyColumn(_index, item) { return item.trackByIndex; } hasRangeValue() { var _a, _b; return ((_a = this.selectedValue) === null || _a === void 0 ? void 0 : _a.length) > 0 || ((_b = this.hoverValue) === null || _b === void 0 ? void 0 : _b.length) > 0; } getClassMap(cell) { return { [`ant-picker-cell`]: true, [`ant-picker-cell-in-view`]: true, [`ant-picker-cell-selected`]: cell.isSelected, [`ant-picker-cell-disabled`]: cell.isDisabled, [`ant-picker-cell-in-range`]: !!cell.isInSelectedRange, [`ant-picker-cell-range-start`]: !!cell.isSelectedStart, [`ant-picker-cell-range-end`]: !!cell.isSelectedEnd, [`ant-picker-cell-range-start-single`]: !!cell.isStartSingle, [`ant-picker-cell-range-end-single`]: !!cell.isEndSingle, [`ant-picker-cell-range-hover`]: !!cell.isInHoverRange, [`ant-picker-cell-range-hover-start`]: !!cell.isHoverStart, [`ant-picker-cell-range-hover-end`]: !!cell.isHoverEnd, [`ant-picker-cell-range-hover-edge-start`]: !!cell.isFirstCellInPanel, [`ant-picker-cell-range-hover-edge-end`]: !!cell.isLastCellInPanel, [`ant-picker-cell-range-start-near-hover`]: !!cell.isRangeStartNearHover, [`ant-picker-cell-range-end-near-hover`]: !!cell.isRangeEndNearHover }; } ngOnInit() { this.render(); } ngOnChanges(changes) { if (changes.activeDate && !changes.activeDate.currentValue) { this.activeDate = new CandyDate(); } if (changes.disabledDate || changes.locale || changes.showWeek || this.isDateRealChange(changes.activeDate) || this.isDateRealChange(changes.value) || this.isDateRealChange(changes.selectedValue) || this.isDateRealChange(changes.hoverValue)) { this.render(); } } isDateRealChange(change) { if (change) { const previousValue = change.previousValue; const currentValue = change.currentValue; if (Array.isArray(currentValue)) { return (!Array.isArray(previousValue) || currentValue.length !== previousValue.length || currentValue.some((value, index) => { const previousCandyDate = previousValue[index]; return previousCandyDate instanceof CandyDate ? previousCandyDate.isSameDay(value) : previousCandyDate !== value; })); } else { return !this.isSameDate(previousValue, currentValue); } } return false; } isSameDate(left, right) { return (!left && !right) || (left && right && right.isSameDay(left)); } } AbstractTable.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: AbstractTable, deps: [], target: i0.ɵɵFactoryTarget.Directive }); AbstractTable.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "14.1.3", type: AbstractTable, inputs: { prefixCls: "prefixCls", value: "value", locale: "locale", activeDate: "activeDate", showWeek: "showWeek", selectedValue: "selectedValue", hoverValue: "hoverValue", disabledDate: "disabledDate", cellRender: "cellRender", fullCellRender: "fullCellRender" }, outputs: { valueChange: "valueChange", cellHover: "cellHover" }, usesOnChanges: true, ngImport: i0 }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: AbstractTable, decorators: [{ type: Directive }], propDecorators: { prefixCls: [{ type: Input }], value: [{ type: Input }], locale: [{ type: Input }], activeDate: [{ type: Input }], showWeek: [{ type: Input }], selectedValue: [{ type: Input }], hoverValue: [{ type: Input }], disabledDate: [{ type: Input }], cellRender: [{ type: Input }], fullCellRender: [{ type: Input }], valueChange: [{ type: Output }], cellHover: [{ type: Output }] } }); /** * 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 */ class DateTableComponent extends AbstractTable { constructor(i18n, dateHelper) { super(); this.i18n = i18n; this.dateHelper = dateHelper; } changeValueFromInside(value) { // Only change date not change time this.activeDate = this.activeDate.setYear(value.getYear()).setMonth(value.getMonth()).setDate(value.getDate()); this.valueChange.emit(this.activeDate); if (!this.activeDate.isSameMonth(this.value)) { this.render(); } } makeHeadRow() { const weekDays = []; const start = this.activeDate.calendarStart({ weekStartsOn: this.dateHelper.getFirstDayOfWeek() }); for (let colIndex = 0; colIndex < this.MAX_COL; colIndex++) { const day = start.addDays(colIndex); weekDays.push({ trackByIndex: null, value: day.nativeDate, title: this.dateHelper.format(day.nativeDate, 'E'), content: this.dateHelper.format(day.nativeDate, this.getVeryShortWeekFormat()), isSelected: false, isDisabled: false, onClick() { }, onMouseEnter() { } }); } return weekDays; } getVeryShortWeekFormat() { return this.i18n.getLocaleId().toLowerCase().indexOf('zh') === 0 ? 'EEEEE' : 'EEEEEE'; // Use extreme short for chinese } makeBodyRows() { const weekRows = []; const firstDayOfMonth = this.activeDate.calendarStart({ weekStartsOn: this.dateHelper.getFirstDayOfWeek() }); for (let week = 0; week < this.MAX_ROW; week++) { const weekStart = firstDayOfMonth.addDays(week * 7); const row = { isActive: false, dateCells: [], trackByIndex: week }; for (let day = 0; day < 7; day++) { const date = weekStart.addDays(day); const dateFormat = transCompatFormat(this.i18n.getLocaleData('DatePicker.lang.dateFormat', 'YYYY-MM-DD')); const title = this.dateHelper.format(date.nativeDate, dateFormat); const label = this.dateHelper.format(date.nativeDate, 'dd'); const cell = { trackByIndex: day, value: date.nativeDate, label, isSelected: false, isDisabled: false, isToday: false, title, cellRender: valueFunctionProp(this.cellRender, date), fullCellRender: valueFunctionProp(this.fullCellRender, date), content: `${date.getDate()}`, onClick: () => this.changeValueFromInside(date), onMouseEnter: () => this.cellHover.emit(date) }; this.addCellProperty(cell, date); if (this.showWeek && !row.weekNum) { row.weekNum = this.dateHelper.getISOWeek(date.nativeDate); } if (date.isSameDay(this.value)) { row.isActive = date.isSameDay(this.value); } row.dateCells.push(cell); } row.classMap = { [`ant-picker-week-panel-row`]: this.showWeek, [`ant-picker-week-panel-row-selected`]: this.showWeek && row.isActive }; weekRows.push(row); } return weekRows; } addCellProperty(cell, date) { var _a; if (this.hasRangeValue() && !this.showWeek) { const [startHover, endHover] = this.hoverValue; const [startSelected, endSelected] = this.selectedValue; // Selected if (startSelected === null || startSelected === void 0 ? void 0 : startSelected.isSameDay(date)) { cell.isSelectedStart = true; cell.isSelected = true; } if (endSelected === null || endSelected === void 0 ? void 0 : endSelected.isSameDay(date)) { cell.isSelectedEnd = true; cell.isSelected = true; } if (startHover && endHover) { cell.isHoverStart = startHover.isSameDay(date); cell.isHoverEnd = endHover.isSameDay(date); cell.isLastCellInPanel = date.isLastDayOfMonth(); cell.isFirstCellInPanel = date.isFirstDayOfMonth(); cell.isInHoverRange = startHover.isBeforeDay(date) && date.isBeforeDay(endHover); } cell.isStartSingle = startSelected && !endSelected; cell.isEndSingle = !startSelected && endSelected; cell.isInSelectedRange = (startSelected === null || startSelected === void 0 ? void 0 : startSelected.isBeforeDay(date)) && date.isBeforeDay(endSelected); cell.isRangeStartNearHover = startSelected && cell.isInHoverRange; cell.isRangeEndNearHover = endSelected && cell.isInHoverRange; } cell.isToday = date.isToday(); cell.isSelected = date.isSameDay(this.value); cell.isDisabled = !!((_a = this.disabledDate) === null || _a === void 0 ? void 0 : _a.call(this, date.nativeDate)); cell.classMap = this.getClassMap(cell); } getClassMap(cell) { const date = new CandyDate(cell.value); return Object.assign(Object.assign({}, super.getClassMap(cell)), { [`ant-picker-cell-today`]: !!cell.isToday, [`ant-picker-cell-in-view`]: date.isSameMonth(this.activeDate) }); } } DateTableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: DateTableComponent, deps: [{ token: i1.NzI18nService }, { token: i1.DateHelperService }], target: i0.ɵɵFactoryTarget.Component }); DateTableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.1.3", type: DateTableComponent, selector: "date-table", inputs: { locale: "locale" }, exportAs: ["dateTable"], usesInheritance: true, ngImport: i0, template: "<table class=\"ant-picker-content\" cellspacing=\"0\" role=\"grid\">\n <thead *ngIf=\"headRow && headRow.length > 0\">\n <tr role=\"row\">\n <th *ngIf=\"showWeek\" role=\"columnheader\"></th>\n <th *ngFor=\"let cell of headRow\" role=\"columnheader\" title=\"{{ cell.title }}\">\n {{ cell.content }}\n </th>\n </tr>\n </thead>\n <tbody>\n <tr *ngFor=\"let row of bodyRows; trackBy: trackByBodyRow\" [ngClass]=\"row.classMap!\" role=\"row\">\n <td *ngIf=\"row.weekNum\" role=\"gridcell\" class=\"{{ prefixCls }}-cell-week\">\n {{ row.weekNum }}\n </td>\n <td\n *ngFor=\"let cell of row.dateCells; trackBy: trackByBodyColumn\"\n title=\"{{ cell.title }}\"\n role=\"gridcell\"\n [ngClass]=\"cell.classMap!\"\n (click)=\"cell.isDisabled ? null : cell.onClick()\"\n (mouseenter)=\"cell.onMouseEnter()\"\n >\n <ng-container [ngSwitch]=\"prefixCls\">\n <ng-container *ngSwitchCase=\"'ant-picker'\">\n <ng-container [ngSwitch]=\"true\">\n <ng-container *ngSwitchCase=\"isTemplateRef(cell.cellRender)\">\n <!-- *ngSwitchCase not has type assertion support, the cellRender type here is TemplateRef -->\n <ng-container\n *ngTemplateOutlet=\"$any(cell.cellRender); context: { $implicit: cell.value }\"\n ></ng-container>\n </ng-container>\n <ng-container *ngSwitchCase=\"isNonEmptyString(cell.cellRender)\">\n <span [innerHTML]=\"cell.cellRender\"></span>\n </ng-container>\n <ng-container *ngSwitchDefault>\n <div\n class=\"{{ prefixCls }}-cell-inner\"\n [attr.aria-selected]=\"cell.isSelected\"\n [attr.aria-disabled]=\"cell.isDisabled\"\n >\n {{ cell.content }}\n </div>\n </ng-container>\n </ng-container>\n </ng-container>\n <ng-container *ngSwitchCase=\"'ant-picker-calendar'\">\n <div\n class=\"{{ prefixCls }}-date ant-picker-cell-inner\"\n [class.ant-picker-calendar-date-today]=\"cell.isToday\"\n >\n <ng-container *ngIf=\"cell.fullCellRender; else defaultCell\">\n <ng-container\n *ngTemplateOutlet=\"$any(cell.fullCellRender); context: { $implicit: cell.value }\"\n >\n </ng-container>\n </ng-container>\n <ng-template #defaultCell>\n <div class=\"{{ prefixCls }}-date-value\">{{ cell.content }}</div>\n <div class=\"{{ prefixCls }}-date-content\">\n <ng-container\n *ngTemplateOutlet=\"$any(cell.cellRender); context: { $implicit: cell.value }\"\n >\n </ng-container>\n </div>\n </ng-template>\n </div>\n </ng-container>\n </ng-container>\n </td>\n </tr>\n </tbody>\n</table>\n", dependencies: [{ kind: "directive", type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i2.NgSwitch, selector: "[ngSwitch]", inputs: ["ngSwitch"] }, { kind: "directive", type: i2.NgSwitchCase, selector: "[ngSwitchCase]", inputs: ["ngSwitchCase"] }, { kind: "directive", type: i2.NgSwitchDefault, selector: "[ngSwitchDefault]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: DateTableComponent, decorators: [{ type: Component, args: [{ encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, selector: 'date-table', exportAs: 'dateTable', template: "<table class=\"ant-picker-content\" cellspacing=\"0\" role=\"grid\">\n <thead *ngIf=\"headRow && headRow.length > 0\">\n <tr role=\"row\">\n <th *ngIf=\"showWeek\" role=\"columnheader\"></th>\n <th *ngFor=\"let cell of headRow\" role=\"columnheader\" title=\"{{ cell.title }}\">\n {{ cell.content }}\n </th>\n </tr>\n </thead>\n <tbody>\n <tr *ngFor=\"let row of bodyRows; trackBy: trackByBodyRow\" [ngClass]=\"row.classMap!\" role=\"row\">\n <td *ngIf=\"row.weekNum\" role=\"gridcell\" class=\"{{ prefixCls }}-cell-week\">\n {{ row.weekNum }}\n </td>\n <td\n *ngFor=\"let cell of row.dateCells; trackBy: trackByBodyColumn\"\n title=\"{{ cell.title }}\"\n role=\"gridcell\"\n [ngClass]=\"cell.classMap!\"\n (click)=\"cell.isDisabled ? null : cell.onClick()\"\n (mouseenter)=\"cell.onMouseEnter()\"\n >\n <ng-container [ngSwitch]=\"prefixCls\">\n <ng-container *ngSwitchCase=\"'ant-picker'\">\n <ng-container [ngSwitch]=\"true\">\n <ng-container *ngSwitchCase=\"isTemplateRef(cell.cellRender)\">\n <!-- *ngSwitchCase not has type assertion support, the cellRender type here is TemplateRef -->\n <ng-container\n *ngTemplateOutlet=\"$any(cell.cellRender); context: { $implicit: cell.value }\"\n ></ng-container>\n </ng-container>\n <ng-container *ngSwitchCase=\"isNonEmptyString(cell.cellRender)\">\n <span [innerHTML]=\"cell.cellRender\"></span>\n </ng-container>\n <ng-container *ngSwitchDefault>\n <div\n class=\"{{ prefixCls }}-cell-inner\"\n [attr.aria-selected]=\"cell.isSelected\"\n [attr.aria-disabled]=\"cell.isDisabled\"\n >\n {{ cell.content }}\n </div>\n </ng-container>\n </ng-container>\n </ng-container>\n <ng-container *ngSwitchCase=\"'ant-picker-calendar'\">\n <div\n class=\"{{ prefixCls }}-date ant-picker-cell-inner\"\n [class.ant-picker-calendar-date-today]=\"cell.isToday\"\n >\n <ng-container *ngIf=\"cell.fullCellRender; else defaultCell\">\n <ng-container\n *ngTemplateOutlet=\"$any(cell.fullCellRender); context: { $implicit: cell.value }\"\n >\n </ng-container>\n </ng-container>\n <ng-template #defaultCell>\n <div class=\"{{ prefixCls }}-date-value\">{{ cell.content }}</div>\n <div class=\"{{ prefixCls }}-date-content\">\n <ng-container\n *ngTemplateOutlet=\"$any(cell.cellRender); context: { $implicit: cell.value }\"\n >\n </ng-container>\n </div>\n </ng-template>\n </div>\n </ng-container>\n </ng-container>\n </td>\n </tr>\n </tbody>\n</table>\n" }] }], ctorParameters: function () { return [{ type: i1.NzI18nService }, { type: i1.DateHelperService }]; }, propDecorators: { locale: [{ type: 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 */ class DecadeHeaderComponent extends AbstractPanelHeader { previous() { } next() { } get startYear() { return parseInt(`${this.value.getYear() / 100}`, 10) * 100; } get endYear() { return this.startYear + 99; } superPrevious() { this.changeValue(this.value.addYears(-100)); } superNext() { this.changeValue(this.value.addYears(100)); } getSelectors() { return [ { className: `${this.prefixCls}-decade-btn`, title: '', onClick: () => { // noop }, label: `${this.startYear}-${this.endYear}` } ]; } } DecadeHeaderComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: DecadeHeaderComponent, deps: null, target: i0.ɵɵFactoryTarget.Component }); DecadeHeaderComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.1.3", type: DecadeHeaderComponent, selector: "decade-header", exportAs: ["decadeHeader"], usesInheritance: true, ngImport: i0, template: "<div class=\"{{ prefixCls }}\">\n <button\n [style.visibility]=\"showSuperPreBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-super-prev-btn\"\n role=\"button\"\n type=\"button\"\n tabindex=\"-1\"\n title=\"{{ superPreviousTitle() }}\"\n (click)=\"superPrevious()\"\n >\n <span class=\"ant-picker-super-prev-icon\"></span>\n </button>\n <button\n [style.visibility]=\"showPreBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-prev-btn\"\n role=\"button\"\n type=\"button\"\n title=\"{{ previousTitle() }}\"\n tabindex=\"-1\"\n (click)=\"previous()\"\n >\n <span class=\"ant-picker-prev-icon\"></span>\n </button>\n\n <div class=\"{{ prefixCls }}-view\">\n <ng-container *ngFor=\"let selector of selectors\">\n <button\n class=\"{{ selector.className }}\"\n role=\"button\"\n type=\"button\"\n title=\"{{ selector.title || null }}\"\n (click)=\"selector.onClick()\"\n >\n {{ selector.label }}\n </button>\n </ng-container>\n </div>\n <button\n [style.visibility]=\"showNextBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-next-btn\"\n role=\"button\"\n type=\"button\"\n tabindex=\"-1\"\n title=\"{{ nextTitle() }}\"\n (click)=\"next()\"\n >\n <span class=\"ant-picker-next-icon\"></span>\n </button>\n <button\n [style.visibility]=\"showSuperNextBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-super-next-btn\"\n role=\"button\"\n type=\"button\"\n tabindex=\"-1\"\n title=\"{{ superNextTitle() }}\"\n (click)=\"superNext()\"\n >\n <span class=\"ant-picker-super-next-icon\"></span>\n </button>\n</div>\n", dependencies: [{ kind: "directive", type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.1.3", ngImport: i0, type: DecadeHeaderComponent, decorators: [{ type: Component, args: [{ encapsulation: ViewEncapsulation.None, changeDetection: ChangeDetectionStrategy.OnPush, selector: 'decade-header', exportAs: 'decadeHeader', template: "<div class=\"{{ prefixCls }}\">\n <button\n [style.visibility]=\"showSuperPreBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-super-prev-btn\"\n role=\"button\"\n type=\"button\"\n tabindex=\"-1\"\n title=\"{{ superPreviousTitle() }}\"\n (click)=\"superPrevious()\"\n >\n <span class=\"ant-picker-super-prev-icon\"></span>\n </button>\n <button\n [style.visibility]=\"showPreBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-prev-btn\"\n role=\"button\"\n type=\"button\"\n title=\"{{ previousTitle() }}\"\n tabindex=\"-1\"\n (click)=\"previous()\"\n >\n <span class=\"ant-picker-prev-icon\"></span>\n </button>\n\n <div class=\"{{ prefixCls }}-view\">\n <ng-container *ngFor=\"let selector of selectors\">\n <button\n class=\"{{ selector.className }}\"\n role=\"button\"\n type=\"button\"\n title=\"{{ selector.title || null }}\"\n (click)=\"selector.onClick()\"\n >\n {{ selector.label }}\n </button>\n </ng-container>\n </div>\n <button\n [style.visibility]=\"showNextBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-next-btn\"\n role=\"button\"\n type=\"button\"\n tabindex=\"-1\"\n title=\"{{ nextTitle() }}\"\n (click)=\"next()\"\n >\n <span class=\"ant-picker-next-icon\"></span>\n </button>\n <button\n [style.visibility]=\"showSuperNextBtn ? 'visible' : 'hidden'\"\n class=\"{{ prefixCls }}-super-next-btn\"\n role=\"button\"\n type=\"button\"\n tabindex=\"-1\"\n title=\"{{ superNextTitle() }}\"\n (click)=\"superNext()\"\n >\n <span class=\"ant-picker-super-next-icon\"></span>\n </button>\n</div>\n" }] }] }); /** * 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 */ const MAX_ROW = 4; const MAX_COL = 3; class DecadeTableComponent extends AbstractTable { get startYear() { return parseInt(`${this.activeDate.getYear() / 100}`, 10) * 100; } get endYear() { return this.startYear + 99; } makeHeadRow() { return []; } makeBodyRows() { const decades = []; const currentYear = this.value && this.value.getYear(); const startYear = this.startYear; const endYear = this.endYear; const previousYear = startYear - 10; let index = 0; for (let rowIndex = 0; rowIndex < MAX_ROW; rowIndex++) { const row = { dateCells: [], trackByIndex: rowIndex }; for (let colIndex = 0; colIndex < MAX_COL; colIndex++) { const start = previousYear + index * 10; const end = previousYear + index * 10 + 9; const content = `${start}-${end}`; const cell = { trackByIndex: colIndex, value: t