ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
1,010 lines (998 loc) • 80.6 kB
JavaScript
import * as i2 from '@angular/cdk/overlay';
import { OverlayConfig, OverlayRef, OverlayModule } from '@angular/cdk/overlay';
import * as i12 from '@angular/cdk/portal';
import { BasePortalOutlet, CdkPortalOutlet, ComponentPortal, TemplatePortal, PortalModule } from '@angular/cdk/portal';
import * as i0 from '@angular/core';
import { EventEmitter, Directive, Component, ChangeDetectionStrategy, Optional, Inject, ViewChild, Output, Input, Injector, TemplateRef, Injectable, SkipSelf, ContentChild, NgModule } from '@angular/core';
import { Subject, fromEvent, defer } from 'rxjs';
import { takeUntil, filter, take, startWith } from 'rxjs/operators';
import { warn } from 'ng-zorro-antd/core/logger';
import { getElementOffset, isNotNil, isPromise, InputBoolean } from 'ng-zorro-antd/core/util';
import * as i8 from '@angular/common';
import { DOCUMENT, CommonModule } from '@angular/common';
import { ANIMATION_MODULE_TYPE } from '@angular/platform-browser/animations';
import { trigger, state, style, transition, animate } from '@angular/animations';
import * as i1 from '@angular/cdk/a11y';
import * as i3 from 'ng-zorro-antd/core/config';
import * as i1$1 from 'ng-zorro-antd/i18n';
import { NzI18nModule } from 'ng-zorro-antd/i18n';
import * as i2$1 from 'ng-zorro-antd/core/outlet';
import { NzOutletModule } from 'ng-zorro-antd/core/outlet';
import * as i3$1 from 'ng-zorro-antd/core/transition-patch';
import * as i4 from 'ng-zorro-antd/icon';
import { NzIconModule } from 'ng-zorro-antd/icon';
import * as i7 from 'ng-zorro-antd/button';
import { NzButtonModule } from 'ng-zorro-antd/button';
import * as i13 from 'ng-zorro-antd/core/wave';
import * as i14 from 'ng-zorro-antd/pipes';
import { NzPipesModule } from 'ng-zorro-antd/pipes';
import { __awaiter, __rest, __decorate } from 'tslib';
import { ESCAPE, hasModifierKey } from '@angular/cdk/keycodes';
import * as i3$2 from '@angular/cdk/bidi';
import { BidiModule } from '@angular/cdk/bidi';
import { NzNoAnimationModule } from 'ng-zorro-antd/core/no-animation';
/**
* 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 noopFun = () => void 0;
class ModalOptions {
constructor() {
this.nzCentered = false;
this.nzClosable = true;
this.nzOkLoading = false;
this.nzOkDisabled = false;
this.nzCancelDisabled = false;
this.nzCancelLoading = false;
this.nzNoAnimation = false;
this.nzAutofocus = 'auto';
this.nzKeyboard = true;
this.nzZIndex = 1000;
this.nzWidth = 520;
this.nzCloseIcon = 'close';
this.nzOkType = 'primary';
this.nzOkDanger = false;
this.nzModalType = 'default';
this.nzOnCancel = noopFun;
this.nzOnOk = noopFun;
// Confirm
this.nzIconType = 'question-circle';
}
}
/**
* 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 ZOOM_CLASS_NAME_MAP = {
enter: 'ant-zoom-enter',
enterActive: 'ant-zoom-enter-active',
leave: 'ant-zoom-leave',
leaveActive: 'ant-zoom-leave-active'
};
const FADE_CLASS_NAME_MAP = {
enter: 'ant-fade-enter',
enterActive: 'ant-fade-enter-active',
leave: 'ant-fade-leave',
leaveActive: 'ant-fade-leave-active'
};
const MODAL_MASK_CLASS_NAME = 'ant-modal-mask';
const NZ_CONFIG_MODULE_NAME = 'modal';
/**
* 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 nzModalAnimations = {
modalContainer: trigger('modalContainer', [
state('void, exit', style({})),
state('enter', style({})),
transition('* => enter', animate('.24s', style({}))),
transition('* => void, * => exit', animate('.2s', style({})))
])
};
/**
* 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
*/
function applyConfigDefaults(config, defaultOptions) {
return Object.assign(Object.assign({}, defaultOptions), config);
}
function getValueWithConfig(userValue, configValue, defaultValue) {
return typeof userValue === 'undefined'
? typeof configValue === 'undefined'
? defaultValue
: configValue
: userValue;
}
/**
* Assign the params into the content component instance.
*
* @deprecated Should use dependency injection to get the params for user
* @breaking-change 14.0.0
*/
function setContentInstanceParams(instance, params) {
Object.assign(instance, params);
}
function getConfigFromComponent(component) {
const { nzCentered, nzMask, nzMaskClosable, nzClosable, nzOkLoading, nzOkDisabled, nzCancelDisabled, nzCancelLoading, nzKeyboard, nzNoAnimation, nzContent, nzComponentParams, nzFooter, nzZIndex, nzWidth, nzWrapClassName, nzClassName, nzStyle, nzTitle, nzCloseIcon, nzMaskStyle, nzBodyStyle, nzOkText, nzCancelText, nzOkType, nzOkDanger, nzIconType, nzModalType, nzOnOk, nzOnCancel, nzAfterOpen, nzAfterClose, nzCloseOnNavigation, nzAutofocus } = component;
return {
nzCentered,
nzMask,
nzMaskClosable,
nzClosable,
nzOkLoading,
nzOkDisabled,
nzCancelDisabled,
nzCancelLoading,
nzKeyboard,
nzNoAnimation,
nzContent,
nzComponentParams,
nzFooter,
nzZIndex,
nzWidth,
nzWrapClassName,
nzClassName,
nzStyle,
nzTitle,
nzCloseIcon,
nzMaskStyle,
nzBodyStyle,
nzOkText,
nzCancelText,
nzOkType,
nzOkDanger,
nzIconType,
nzModalType,
nzOnOk,
nzOnCancel,
nzAfterOpen,
nzAfterClose,
nzCloseOnNavigation,
nzAutofocus
};
}
function throwNzModalContentAlreadyAttachedError() {
throw Error('Attempting to attach modal content after content is already attached');
}
class BaseModalContainerComponent extends BasePortalOutlet {
constructor(ngZone, host, focusTrapFactory, cdr, render, overlayRef, nzConfigService, config, document, animationType) {
super();
this.ngZone = ngZone;
this.host = host;
this.focusTrapFactory = focusTrapFactory;
this.cdr = cdr;
this.render = render;
this.overlayRef = overlayRef;
this.nzConfigService = nzConfigService;
this.config = config;
this.animationType = animationType;
this.animationStateChanged = new EventEmitter();
this.containerClick = new EventEmitter();
this.cancelTriggered = new EventEmitter();
this.okTriggered = new EventEmitter();
this.state = 'enter';
this.isStringContent = false;
this.dir = 'ltr';
this.elementFocusedBeforeModalWasOpened = null;
this.mouseDown = false;
this.oldMaskStyle = null;
this.destroy$ = new Subject();
this.document = document;
this.dir = overlayRef.getDirection();
this.isStringContent = typeof config.nzContent === 'string';
this.nzConfigService
.getConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME)
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.updateMaskClassname();
});
}
get showMask() {
const defaultConfig = this.nzConfigService.getConfigForComponent(NZ_CONFIG_MODULE_NAME) || {};
return !!getValueWithConfig(this.config.nzMask, defaultConfig.nzMask, true);
}
get maskClosable() {
const defaultConfig = this.nzConfigService.getConfigForComponent(NZ_CONFIG_MODULE_NAME) || {};
return !!getValueWithConfig(this.config.nzMaskClosable, defaultConfig.nzMaskClosable, true);
}
onContainerClick(e) {
if (e.target === e.currentTarget && !this.mouseDown && this.showMask && this.maskClosable) {
this.containerClick.emit();
}
}
onCloseClick() {
this.cancelTriggered.emit();
}
onOkClick() {
this.okTriggered.emit();
}
attachComponentPortal(portal) {
if (this.portalOutlet.hasAttached()) {
throwNzModalContentAlreadyAttachedError();
}
this.savePreviouslyFocusedElement();
this.setZIndexForBackdrop();
return this.portalOutlet.attachComponentPortal(portal);
}
attachTemplatePortal(portal) {
if (this.portalOutlet.hasAttached()) {
throwNzModalContentAlreadyAttachedError();
}
this.savePreviouslyFocusedElement();
this.setZIndexForBackdrop();
return this.portalOutlet.attachTemplatePortal(portal);
}
attachStringContent() {
this.savePreviouslyFocusedElement();
this.setZIndexForBackdrop();
}
getNativeElement() {
return this.host.nativeElement;
}
animationDisabled() {
return this.config.nzNoAnimation || this.animationType === 'NoopAnimations';
}
setModalTransformOrigin() {
const modalElement = this.modalElementRef.nativeElement;
if (this.elementFocusedBeforeModalWasOpened) {
const previouslyDOMRect = this.elementFocusedBeforeModalWasOpened.getBoundingClientRect();
const lastPosition = getElementOffset(this.elementFocusedBeforeModalWasOpened);
const x = lastPosition.left + previouslyDOMRect.width / 2;
const y = lastPosition.top + previouslyDOMRect.height / 2;
const transformOrigin = `${x - modalElement.offsetLeft}px ${y - modalElement.offsetTop}px 0px`;
this.render.setStyle(modalElement, 'transform-origin', transformOrigin);
}
}
savePreviouslyFocusedElement() {
if (!this.focusTrap) {
this.focusTrap = this.focusTrapFactory.create(this.host.nativeElement);
}
if (this.document) {
this.elementFocusedBeforeModalWasOpened = this.document.activeElement;
if (this.host.nativeElement.focus) {
this.ngZone.runOutsideAngular(() => Promise.resolve().then(() => this.host.nativeElement.focus()));
}
}
}
trapFocus() {
const element = this.host.nativeElement;
if (this.config.nzAutofocus) {
this.focusTrap.focusInitialElementWhenReady();
}
else {
const activeElement = this.document.activeElement;
if (activeElement !== element && !element.contains(activeElement)) {
element.focus();
}
}
}
restoreFocus() {
const toFocus = this.elementFocusedBeforeModalWasOpened;
// We need the extra check, because IE can set the `activeElement` to null in some cases.
if (toFocus && typeof toFocus.focus === 'function') {
const activeElement = this.document.activeElement;
const element = this.host.nativeElement;
if (!activeElement ||
activeElement === this.document.body ||
activeElement === element ||
element.contains(activeElement)) {
toFocus.focus();
}
}
if (this.focusTrap) {
this.focusTrap.destroy();
}
}
setEnterAnimationClass() {
if (this.animationDisabled()) {
return;
}
// Make sure to set the `TransformOrigin` style before set the modelElement's class names
this.setModalTransformOrigin();
const modalElement = this.modalElementRef.nativeElement;
const backdropElement = this.overlayRef.backdropElement;
modalElement.classList.add(ZOOM_CLASS_NAME_MAP.enter);
modalElement.classList.add(ZOOM_CLASS_NAME_MAP.enterActive);
if (backdropElement) {
backdropElement.classList.add(FADE_CLASS_NAME_MAP.enter);
backdropElement.classList.add(FADE_CLASS_NAME_MAP.enterActive);
}
}
setExitAnimationClass() {
const modalElement = this.modalElementRef.nativeElement;
modalElement.classList.add(ZOOM_CLASS_NAME_MAP.leave);
modalElement.classList.add(ZOOM_CLASS_NAME_MAP.leaveActive);
this.setMaskExitAnimationClass();
}
setMaskExitAnimationClass(force = false) {
const backdropElement = this.overlayRef.backdropElement;
if (backdropElement) {
if (this.animationDisabled() || force) {
// https://github.com/angular/components/issues/18645
backdropElement.classList.remove(MODAL_MASK_CLASS_NAME);
return;
}
backdropElement.classList.add(FADE_CLASS_NAME_MAP.leave);
backdropElement.classList.add(FADE_CLASS_NAME_MAP.leaveActive);
}
}
cleanAnimationClass() {
if (this.animationDisabled()) {
return;
}
const backdropElement = this.overlayRef.backdropElement;
const modalElement = this.modalElementRef.nativeElement;
if (backdropElement) {
backdropElement.classList.remove(FADE_CLASS_NAME_MAP.enter);
backdropElement.classList.remove(FADE_CLASS_NAME_MAP.enterActive);
}
modalElement.classList.remove(ZOOM_CLASS_NAME_MAP.enter);
modalElement.classList.remove(ZOOM_CLASS_NAME_MAP.enterActive);
modalElement.classList.remove(ZOOM_CLASS_NAME_MAP.leave);
modalElement.classList.remove(ZOOM_CLASS_NAME_MAP.leaveActive);
}
setZIndexForBackdrop() {
const backdropElement = this.overlayRef.backdropElement;
if (backdropElement) {
if (isNotNil(this.config.nzZIndex)) {
this.render.setStyle(backdropElement, 'z-index', this.config.nzZIndex);
}
}
}
bindBackdropStyle() {
const backdropElement = this.overlayRef.backdropElement;
if (backdropElement) {
if (this.oldMaskStyle) {
const styles = this.oldMaskStyle;
Object.keys(styles).forEach(key => {
this.render.removeStyle(backdropElement, key);
});
this.oldMaskStyle = null;
}
this.setZIndexForBackdrop();
if (typeof this.config.nzMaskStyle === 'object' && Object.keys(this.config.nzMaskStyle).length) {
const styles = Object.assign({}, this.config.nzMaskStyle);
Object.keys(styles).forEach(key => {
this.render.setStyle(backdropElement, key, styles[key]);
});
this.oldMaskStyle = styles;
}
}
}
updateMaskClassname() {
const backdropElement = this.overlayRef.backdropElement;
if (backdropElement) {
if (this.showMask) {
backdropElement.classList.add(MODAL_MASK_CLASS_NAME);
}
else {
backdropElement.classList.remove(MODAL_MASK_CLASS_NAME);
}
}
}
onAnimationDone(event) {
if (event.toState === 'enter') {
this.trapFocus();
}
else if (event.toState === 'exit') {
this.restoreFocus();
}
this.cleanAnimationClass();
this.animationStateChanged.emit(event);
}
onAnimationStart(event) {
if (event.toState === 'enter') {
this.setEnterAnimationClass();
this.bindBackdropStyle();
}
else if (event.toState === 'exit') {
this.setExitAnimationClass();
}
this.animationStateChanged.emit(event);
}
startExitAnimation() {
this.state = 'exit';
this.cdr.markForCheck();
}
ngOnDestroy() {
this.setMaskExitAnimationClass(true);
this.destroy$.next();
this.destroy$.complete();
}
setupMouseListeners(modalContainer) {
this.ngZone.runOutsideAngular(() => {
fromEvent(this.host.nativeElement, 'mouseup')
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
if (this.mouseDown) {
setTimeout(() => {
this.mouseDown = false;
});
}
});
fromEvent(modalContainer.nativeElement, 'mousedown')
.pipe(takeUntil(this.destroy$))
.subscribe(() => {
this.mouseDown = true;
});
});
}
}
BaseModalContainerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: BaseModalContainerComponent, deps: "invalid", target: i0.ɵɵFactoryTarget.Directive });
BaseModalContainerComponent.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.2.5", type: BaseModalContainerComponent, usesInheritance: true, ngImport: i0 });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: BaseModalContainerComponent, decorators: [{
type: Directive
}], ctorParameters: function () { return [{ type: i0.NgZone }, { type: i0.ElementRef }, { type: i1.FocusTrapFactory }, { type: i0.ChangeDetectorRef }, { type: i0.Renderer2 }, { type: i2.OverlayRef }, { type: i3.NzConfigService }, { type: ModalOptions }, { type: undefined }, { type: undefined }]; } });
/**
* 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 NzModalCloseComponent {
constructor(config) {
this.config = config;
}
}
NzModalCloseComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzModalCloseComponent, deps: [{ token: ModalOptions }], target: i0.ɵɵFactoryTarget.Component });
NzModalCloseComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.5", type: NzModalCloseComponent, selector: "button[nz-modal-close]", host: { attributes: { "aria-label": "Close" }, classAttribute: "ant-modal-close" }, exportAs: ["NzModalCloseBuiltin"], ngImport: i0, template: `
<span class="ant-modal-close-x">
<ng-container *nzStringTemplateOutlet="config.nzCloseIcon; let closeIcon">
<i nz-icon [nzType]="closeIcon" class="ant-modal-close-icon"></i>
</ng-container>
</span>
`, isInline: true, directives: [{ type: i2$1.NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }, { type: i3$1.ɵ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"] }, { type: i4.NzIconDirective, selector: "[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzModalCloseComponent, decorators: [{
type: Component,
args: [{
selector: 'button[nz-modal-close]',
exportAs: 'NzModalCloseBuiltin',
template: `
<span class="ant-modal-close-x">
<ng-container *nzStringTemplateOutlet="config.nzCloseIcon; let closeIcon">
<i nz-icon [nzType]="closeIcon" class="ant-modal-close-icon"></i>
</ng-container>
</span>
`,
host: {
class: 'ant-modal-close',
'aria-label': 'Close'
},
changeDetection: ChangeDetectionStrategy.OnPush
}]
}], ctorParameters: function () { return [{ type: ModalOptions }]; } });
class NzModalConfirmContainerComponent extends BaseModalContainerComponent {
constructor(ngZone, i18n, host, focusTrapFactory, cdr, render, overlayRef, nzConfigService, config, document, animationType) {
super(ngZone, host, focusTrapFactory, cdr, render, overlayRef, nzConfigService, config, document, animationType);
this.i18n = i18n;
this.config = config;
this.cancelTriggered = new EventEmitter();
this.okTriggered = new EventEmitter();
this.i18n.localeChange.pipe(takeUntil(this.destroy$)).subscribe(() => {
this.locale = this.i18n.getLocaleData('Modal');
});
}
ngOnInit() {
this.setupMouseListeners(this.modalElementRef);
}
onCancel() {
this.cancelTriggered.emit();
}
onOk() {
this.okTriggered.emit();
}
}
NzModalConfirmContainerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzModalConfirmContainerComponent, deps: [{ token: i0.NgZone }, { token: i1$1.NzI18nService }, { token: i0.ElementRef }, { token: i1.FocusTrapFactory }, { token: i0.ChangeDetectorRef }, { token: i0.Renderer2 }, { token: i2.OverlayRef }, { token: i3.NzConfigService }, { token: ModalOptions }, { token: DOCUMENT, optional: true }, { token: ANIMATION_MODULE_TYPE, optional: true }], target: i0.ɵɵFactoryTarget.Component });
NzModalConfirmContainerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.5", type: NzModalConfirmContainerComponent, selector: "nz-modal-confirm-container", outputs: { cancelTriggered: "cancelTriggered", okTriggered: "okTriggered" }, host: { attributes: { "tabindex": "-1", "role": "dialog" }, listeners: { "@modalContainer.start": "onAnimationStart($event)", "@modalContainer.done": "onAnimationDone($event)", "click": "onContainerClick($event)" }, properties: { "class": "config.nzWrapClassName ? \"ant-modal-wrap \" + config.nzWrapClassName : \"ant-modal-wrap\"", "class.ant-modal-wrap-rtl": "dir === 'rtl'", "class.ant-modal-centered": "config.nzCentered", "style.zIndex": "config.nzZIndex", "@.disabled": "config.nzNoAnimation", "@modalContainer": "state" } }, viewQueries: [{ propertyName: "portalOutlet", first: true, predicate: CdkPortalOutlet, descendants: true, static: true }, { propertyName: "modalElementRef", first: true, predicate: ["modalElement"], descendants: true, static: true }], exportAs: ["nzModalConfirmContainer"], usesInheritance: true, ngImport: i0, template: `
<div
#modalElement
role="document"
class="ant-modal"
[ngClass]="config.nzClassName!"
[ngStyle]="config.nzStyle!"
[style.width]="config?.nzWidth! | nzToCssUnit"
>
<div class="ant-modal-content">
<button *ngIf="config.nzClosable" nz-modal-close (click)="onCloseClick()"></button>
<div class="ant-modal-body" [ngStyle]="config.nzBodyStyle!">
<div class="ant-modal-confirm-body-wrapper">
<div class="ant-modal-confirm-body">
<i nz-icon [nzType]="config.nzIconType!"></i>
<span class="ant-modal-confirm-title">
<ng-container *nzStringTemplateOutlet="config.nzTitle">
<span [innerHTML]="config.nzTitle"></span>
</ng-container>
</span>
<div class="ant-modal-confirm-content">
<ng-template cdkPortalOutlet></ng-template>
<div *ngIf="isStringContent" [innerHTML]="config.nzContent"></div>
</div>
</div>
<div class="ant-modal-confirm-btns">
<button
*ngIf="config.nzCancelText !== null"
[attr.cdkFocusInitial]="config.nzAutofocus === 'cancel' || null"
nz-button
(click)="onCancel()"
[nzLoading]="!!config.nzCancelLoading"
[disabled]="config.nzCancelDisabled"
>
{{ config.nzCancelText || locale.cancelText }}
</button>
<button
*ngIf="config.nzOkText !== null"
[attr.cdkFocusInitial]="config.nzAutofocus === 'ok' || null"
nz-button
[nzType]="config.nzOkType!"
(click)="onOk()"
[nzLoading]="!!config.nzOkLoading"
[disabled]="config.nzOkDisabled"
[nzDanger]="config.nzOkDanger"
>
{{ config.nzOkText || locale.okText }}
</button>
</div>
</div>
</div>
</div>
</div>
`, isInline: true, components: [{ type: NzModalCloseComponent, selector: "button[nz-modal-close]", exportAs: ["NzModalCloseBuiltin"] }, { type: i7.NzButtonComponent, selector: "button[nz-button], a[nz-button]", inputs: ["nzBlock", "nzGhost", "nzSearch", "nzLoading", "nzDanger", "disabled", "tabIndex", "nzType", "nzShape", "nzSize"], exportAs: ["nzButton"] }], directives: [{ type: i8.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i8.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i8.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i3$1.ɵ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"] }, { type: i4.NzIconDirective, selector: "[nz-icon]", inputs: ["nzSpin", "nzRotate", "nzType", "nzTheme", "nzTwotoneColor", "nzIconfont"], exportAs: ["nzIcon"] }, { type: i2$1.NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }, { type: i12.CdkPortalOutlet, selector: "[cdkPortalOutlet]", inputs: ["cdkPortalOutlet"], outputs: ["attached"], exportAs: ["cdkPortalOutlet"] }, { type: i13.NzWaveDirective, selector: "[nz-wave],button[nz-button]:not([nzType=\"link\"]):not([nzType=\"text\"])", inputs: ["nzWaveExtraNode"], exportAs: ["nzWave"] }], pipes: { "nzToCssUnit": i14.NzToCssUnitPipe }, animations: [nzModalAnimations.modalContainer], changeDetection: i0.ChangeDetectionStrategy.Default });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzModalConfirmContainerComponent, decorators: [{
type: Component,
args: [{
selector: 'nz-modal-confirm-container',
exportAs: 'nzModalConfirmContainer',
template: `
<div
#modalElement
role="document"
class="ant-modal"
[ngClass]="config.nzClassName!"
[ngStyle]="config.nzStyle!"
[style.width]="config?.nzWidth! | nzToCssUnit"
>
<div class="ant-modal-content">
<button *ngIf="config.nzClosable" nz-modal-close (click)="onCloseClick()"></button>
<div class="ant-modal-body" [ngStyle]="config.nzBodyStyle!">
<div class="ant-modal-confirm-body-wrapper">
<div class="ant-modal-confirm-body">
<i nz-icon [nzType]="config.nzIconType!"></i>
<span class="ant-modal-confirm-title">
<ng-container *nzStringTemplateOutlet="config.nzTitle">
<span [innerHTML]="config.nzTitle"></span>
</ng-container>
</span>
<div class="ant-modal-confirm-content">
<ng-template cdkPortalOutlet></ng-template>
<div *ngIf="isStringContent" [innerHTML]="config.nzContent"></div>
</div>
</div>
<div class="ant-modal-confirm-btns">
<button
*ngIf="config.nzCancelText !== null"
[attr.cdkFocusInitial]="config.nzAutofocus === 'cancel' || null"
nz-button
(click)="onCancel()"
[nzLoading]="!!config.nzCancelLoading"
[disabled]="config.nzCancelDisabled"
>
{{ config.nzCancelText || locale.cancelText }}
</button>
<button
*ngIf="config.nzOkText !== null"
[attr.cdkFocusInitial]="config.nzAutofocus === 'ok' || null"
nz-button
[nzType]="config.nzOkType!"
(click)="onOk()"
[nzLoading]="!!config.nzOkLoading"
[disabled]="config.nzOkDisabled"
[nzDanger]="config.nzOkDanger"
>
{{ config.nzOkText || locale.okText }}
</button>
</div>
</div>
</div>
</div>
</div>
`,
animations: [nzModalAnimations.modalContainer],
// Using OnPush for modal caused footer can not to detect changes. we can fix it when 8.x.
changeDetection: ChangeDetectionStrategy.Default,
host: {
tabindex: '-1',
role: 'dialog',
'[class]': 'config.nzWrapClassName ? "ant-modal-wrap " + config.nzWrapClassName : "ant-modal-wrap"',
'[class.ant-modal-wrap-rtl]': `dir === 'rtl'`,
'[class.ant-modal-centered]': 'config.nzCentered',
'[style.zIndex]': 'config.nzZIndex',
'[@.disabled]': 'config.nzNoAnimation',
'[@modalContainer]': 'state',
'(@modalContainer.start)': 'onAnimationStart($event)',
'(@modalContainer.done)': 'onAnimationDone($event)',
'(click)': 'onContainerClick($event)'
}
}]
}], ctorParameters: function () {
return [{ type: i0.NgZone }, { type: i1$1.NzI18nService }, { type: i0.ElementRef }, { type: i1.FocusTrapFactory }, { type: i0.ChangeDetectorRef }, { type: i0.Renderer2 }, { type: i2.OverlayRef }, { type: i3.NzConfigService }, { type: ModalOptions }, { type: undefined, decorators: [{
type: Optional
}, {
type: Inject,
args: [DOCUMENT]
}] }, { type: undefined, decorators: [{
type: Optional
}, {
type: Inject,
args: [ANIMATION_MODULE_TYPE]
}] }];
}, propDecorators: { portalOutlet: [{
type: ViewChild,
args: [CdkPortalOutlet, { static: true }]
}], modalElementRef: [{
type: ViewChild,
args: ['modalElement', { static: true }]
}], cancelTriggered: [{
type: Output
}], okTriggered: [{
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 NzModalTitleComponent {
constructor(config) {
this.config = config;
}
}
NzModalTitleComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzModalTitleComponent, deps: [{ token: ModalOptions }], target: i0.ɵɵFactoryTarget.Component });
NzModalTitleComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.5", type: NzModalTitleComponent, selector: "div[nz-modal-title]", host: { classAttribute: "ant-modal-header" }, exportAs: ["NzModalTitleBuiltin"], ngImport: i0, template: `
<div class="ant-modal-title">
<ng-container *nzStringTemplateOutlet="config.nzTitle">
<div [innerHTML]="config.nzTitle"></div>
</ng-container>
</div>
`, isInline: true, directives: [{ type: i2$1.NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzModalTitleComponent, decorators: [{
type: Component,
args: [{
selector: 'div[nz-modal-title]',
exportAs: 'NzModalTitleBuiltin',
template: `
<div class="ant-modal-title">
<ng-container *nzStringTemplateOutlet="config.nzTitle">
<div [innerHTML]="config.nzTitle"></div>
</ng-container>
</div>
`,
host: {
class: 'ant-modal-header'
},
changeDetection: ChangeDetectionStrategy.OnPush
}]
}], ctorParameters: function () { return [{ type: ModalOptions }]; } });
/**
* 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 NzModalFooterComponent {
constructor(i18n, config) {
this.i18n = i18n;
this.config = config;
this.buttonsFooter = false;
this.buttons = [];
this.cancelTriggered = new EventEmitter();
this.okTriggered = new EventEmitter();
this.destroy$ = new Subject();
if (Array.isArray(config.nzFooter)) {
this.buttonsFooter = true;
this.buttons = config.nzFooter.map(mergeDefaultOption);
}
this.i18n.localeChange.pipe(takeUntil(this.destroy$)).subscribe(() => {
this.locale = this.i18n.getLocaleData('Modal');
});
}
onCancel() {
this.cancelTriggered.emit();
}
onOk() {
this.okTriggered.emit();
}
/**
* Returns the value of the specified key.
* If it is a function, run and return the return value of the function.
*/
getButtonCallableProp(options, prop) {
const value = options[prop];
const componentInstance = this.modalRef.getContentComponent();
return typeof value === 'function' ? value.apply(options, componentInstance && [componentInstance]) : value;
}
/**
* Run function based on the type and set its `loading` prop if needed.
*/
onButtonClick(options) {
const loading = this.getButtonCallableProp(options, 'loading');
if (!loading) {
const result = this.getButtonCallableProp(options, 'onClick');
if (options.autoLoading && isPromise(result)) {
options.loading = true;
result
.then(() => (options.loading = false))
.catch(e => {
options.loading = false;
throw e;
});
}
}
}
ngOnDestroy() {
this.destroy$.next();
this.destroy$.complete();
}
}
NzModalFooterComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzModalFooterComponent, deps: [{ token: i1$1.NzI18nService }, { token: ModalOptions }], target: i0.ɵɵFactoryTarget.Component });
NzModalFooterComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.5", type: NzModalFooterComponent, selector: "div[nz-modal-footer]", inputs: { modalRef: "modalRef" }, outputs: { cancelTriggered: "cancelTriggered", okTriggered: "okTriggered" }, host: { classAttribute: "ant-modal-footer" }, exportAs: ["NzModalFooterBuiltin"], ngImport: i0, template: `
<ng-container *ngIf="config.nzFooter; else defaultFooterButtons">
<ng-container
*nzStringTemplateOutlet="config.nzFooter; context: { $implicit: config.nzComponentParams, modalRef: modalRef }"
>
<div *ngIf="!buttonsFooter" [innerHTML]="config.nzFooter"></div>
<ng-container *ngIf="buttonsFooter">
<button
*ngFor="let button of buttons"
nz-button
(click)="onButtonClick(button)"
[hidden]="!getButtonCallableProp(button, 'show')"
[nzLoading]="getButtonCallableProp(button, 'loading')"
[disabled]="getButtonCallableProp(button, 'disabled')"
[nzType]="button.type!"
[nzDanger]="button.danger"
[nzShape]="button.shape!"
[nzSize]="button.size!"
[nzGhost]="button.ghost!"
>
{{ button.label }}
</button>
</ng-container>
</ng-container>
</ng-container>
<ng-template #defaultFooterButtons>
<button
*ngIf="config.nzCancelText !== null"
[attr.cdkFocusInitial]="config.nzAutofocus === 'cancel' || null"
nz-button
(click)="onCancel()"
[nzLoading]="!!config.nzCancelLoading"
[disabled]="config.nzCancelDisabled"
>
{{ config.nzCancelText || locale.cancelText }}
</button>
<button
*ngIf="config.nzOkText !== null"
[attr.cdkFocusInitial]="config.nzAutofocus === 'ok' || null"
nz-button
[nzType]="config.nzOkType!"
[nzDanger]="config.nzOkDanger"
(click)="onOk()"
[nzLoading]="!!config.nzOkLoading"
[disabled]="config.nzOkDisabled"
>
{{ config.nzOkText || locale.okText }}
</button>
</ng-template>
`, isInline: true, components: [{ type: i7.NzButtonComponent, selector: "button[nz-button], a[nz-button]", inputs: ["nzBlock", "nzGhost", "nzSearch", "nzLoading", "nzDanger", "disabled", "tabIndex", "nzType", "nzShape", "nzSize"], exportAs: ["nzButton"] }], directives: [{ type: i8.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2$1.NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }, { type: i8.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i13.NzWaveDirective, selector: "[nz-wave],button[nz-button]:not([nzType=\"link\"]):not([nzType=\"text\"])", inputs: ["nzWaveExtraNode"], exportAs: ["nzWave"] }, { type: i3$1.ɵ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"] }], changeDetection: i0.ChangeDetectionStrategy.Default });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzModalFooterComponent, decorators: [{
type: Component,
args: [{
selector: 'div[nz-modal-footer]',
exportAs: 'NzModalFooterBuiltin',
template: `
<ng-container *ngIf="config.nzFooter; else defaultFooterButtons">
<ng-container
*nzStringTemplateOutlet="config.nzFooter; context: { $implicit: config.nzComponentParams, modalRef: modalRef }"
>
<div *ngIf="!buttonsFooter" [innerHTML]="config.nzFooter"></div>
<ng-container *ngIf="buttonsFooter">
<button
*ngFor="let button of buttons"
nz-button
(click)="onButtonClick(button)"
[hidden]="!getButtonCallableProp(button, 'show')"
[nzLoading]="getButtonCallableProp(button, 'loading')"
[disabled]="getButtonCallableProp(button, 'disabled')"
[nzType]="button.type!"
[nzDanger]="button.danger"
[nzShape]="button.shape!"
[nzSize]="button.size!"
[nzGhost]="button.ghost!"
>
{{ button.label }}
</button>
</ng-container>
</ng-container>
</ng-container>
<ng-template #defaultFooterButtons>
<button
*ngIf="config.nzCancelText !== null"
[attr.cdkFocusInitial]="config.nzAutofocus === 'cancel' || null"
nz-button
(click)="onCancel()"
[nzLoading]="!!config.nzCancelLoading"
[disabled]="config.nzCancelDisabled"
>
{{ config.nzCancelText || locale.cancelText }}
</button>
<button
*ngIf="config.nzOkText !== null"
[attr.cdkFocusInitial]="config.nzAutofocus === 'ok' || null"
nz-button
[nzType]="config.nzOkType!"
[nzDanger]="config.nzOkDanger"
(click)="onOk()"
[nzLoading]="!!config.nzOkLoading"
[disabled]="config.nzOkDisabled"
>
{{ config.nzOkText || locale.okText }}
</button>
</ng-template>
`,
host: {
class: 'ant-modal-footer'
},
changeDetection: ChangeDetectionStrategy.Default
}]
}], ctorParameters: function () { return [{ type: i1$1.NzI18nService }, { type: ModalOptions }]; }, propDecorators: { cancelTriggered: [{
type: Output
}], okTriggered: [{
type: Output
}], modalRef: [{
type: Input
}] } });
function mergeDefaultOption(options) {
return Object.assign({ type: null, size: 'default', autoLoading: true, show: true, loading: false, disabled: false }, options);
}
class NzModalContainerComponent extends BaseModalContainerComponent {
constructor(ngZone, host, focusTrapFactory, cdr, render, overlayRef, nzConfigService, config, document, animationType) {
super(ngZone, host, focusTrapFactory, cdr, render, overlayRef, nzConfigService, config, document, animationType);
this.config = config;
}
ngOnInit() {
this.setupMouseListeners(this.modalElementRef);
}
}
NzModalContainerComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzModalContainerComponent, deps: [{ token: i0.NgZone }, { token: i0.ElementRef }, { token: i1.FocusTrapFactory }, { token: i0.ChangeDetectorRef }, { token: i0.Renderer2 }, { token: i2.OverlayRef }, { token: i3.NzConfigService }, { token: ModalOptions }, { token: DOCUMENT, optional: true }, { token: ANIMATION_MODULE_TYPE, optional: true }], target: i0.ɵɵFactoryTarget.Component });
NzModalContainerComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.2.5", type: NzModalContainerComponent, selector: "nz-modal-container", host: { attributes: { "tabindex": "-1", "role": "dialog" }, listeners: { "@modalContainer.start": "onAnimationStart($event)", "@modalContainer.done": "onAnimationDone($event)", "click": "onContainerClick($event)" }, properties: { "class": "config.nzWrapClassName ? \"ant-modal-wrap \" + config.nzWrapClassName : \"ant-modal-wrap\"", "class.ant-modal-wrap-rtl": "dir === 'rtl'", "class.ant-modal-centered": "config.nzCentered", "style.zIndex": "config.nzZIndex", "@.disabled": "config.nzNoAnimation", "@modalContainer": "state" } }, viewQueries: [{ propertyName: "portalOutlet", first: true, predicate: CdkPortalOutlet, descendants: true, static: true }, { propertyName: "modalElementRef", first: true, predicate: ["modalElement"], descendants: true, static: true }], exportAs: ["nzModalContainer"], usesInheritance: true, ngImport: i0, template: `
<div
#modalElement
role="document"
class="ant-modal"
[ngClass]="config.nzClassName!"
[ngStyle]="config.nzStyle!"
[style.width]="config?.nzWidth! | nzToCssUnit"
>
<div class="ant-modal-content">
<button *ngIf="config.nzClosable" nz-modal-close (click)="onCloseClick()"></button>
<div *ngIf="config.nzTitle" nz-modal-title></div>
<div class="ant-modal-body" [ngStyle]="config.nzBodyStyle!">
<ng-template cdkPortalOutlet></ng-template>
<div *ngIf="isStringContent" [innerHTML]="config.nzContent"></div>
</div>
<div
*ngIf="config.nzFooter !== null"
nz-modal-footer
[modalRef]="modalRef"
(cancelTriggered)="onCloseClick()"
(okTriggered)="onOkClick()"
></div>
</div>
</div>
`, isInline: true, components: [{ type: NzModalCloseComponent, selector: "button[nz-modal-close]", exportAs: ["NzModalCloseBuiltin"] }, { type: NzModalTitleComponent, selector: "div[nz-modal-title]", exportAs: ["NzModalTitleBuiltin"] }, { type: NzModalFooterComponent, selector: "div[nz-modal-footer]", inputs: ["modalRef"], outputs: ["cancelTriggered", "okTriggered"], exportAs: ["NzModalFooterBuiltin"] }], directives: [{ type: i8.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i8.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i8.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i12.CdkPortalOutlet, selector: "[cdkPortalOutlet]", inputs: ["cdkPortalOutlet"], outputs: ["attached"], exportAs: ["cdkPortalOutlet"] }], pipes: { "nzToCssUnit": i14.NzToCssUnitPipe }, animations: [nzModalAnimations.modalContainer], changeDetection: i0.ChangeDetectionStrategy.Default });
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.2.5", ngImport: i0, type: NzModalContainerComponent, decorators: [{
type: Component,
args: [{
selector: 'nz-modal-container',
exportAs: 'nzModalContainer',
template: `
<div
#modalElement
role="document"
class="ant-modal"
[ngClass]="config.nzClassName!"
[ngStyle]="config.nzStyle!"
[style.width]="config?.nzWidth! | nzToCssUnit"
>
<div class="ant-modal-content">
<button *ngIf="config.nzClosable" nz-modal-close (click)="onCloseClick()"></button>
<div *ngIf="config.nzTitle" nz-modal-title></div>
<div class="ant-modal-body" [ngStyle]="config.nzBodyStyle!">
<ng-template cdkPortalOutlet></ng-template>
<div *ngIf="isStringContent" [innerHTML]="config.nzContent"></div>
</div>
<div
*ngIf="config.nzFooter !== null"
nz-modal-footer
[modalRef]="modalRef"
(cancelTriggered)="onCloseClick()"
(okTriggered)="onOkClick()"
></div>
</div>
</div>
`,
animations: [nzModalAnimations.modalContainer],
// Using OnPush for modal caused footer can not to detect changes. we can fix it when 8.x.
changeDetection: ChangeDetectionStrategy.Default,
host: {
tabindex: '-1',
role: 'dialog',
'[class]': 'config.nzWrapClassName ? "ant-modal-wrap " + config.nzWrapClassName : "ant-modal-wrap"',
'[class.ant-modal-wrap-rtl]': `dir === 'rtl'`,
'[class.ant-modal-centered]': 'config.nzCentered',
'[style.zIndex]': 'config.nzZIndex',
'[@.disabled]': 'config.nzNoAnimation',
'[@modalContainer]': 'state',
'(@modalContainer.start)': 'onAnimationStart($event)',
'(@modalContainer.done)': 'onAnimationDone($event)',
'(click)': 'onContainerClick($event)'
}
}]
}], ctorParameters: function () {
return [{ type: i0.NgZone }, { type: i0.ElementRef }, { type: i1.FocusTrapFactory }, { type: i0.ChangeDetectorRef }, { type: i0.Renderer2 }, { type: i2.OverlayRef }, { type: i3.NzConfigService }, { type: ModalOptions }, { type: undefined, decorators: [{
type: Optional
}, {
type: Inject,
args: [DOCUMENT]
}] }, { type: undefined, decorators: [{
type: Optional
}, {
type: Inject,
args: [ANIMATION_MODULE_TYPE]
}] }];
}, propDecorators: { portalOutlet: [{
type: ViewChild,
args: [CdkPortalOutlet, { static: true }]
}], modalElementRef: [{
type: ViewChild,
args: ['modalElement', { static: true }]
}] } });
class NzModalRef {
constructor(overlayRef, config, containerInstance) {
this.overlayRef = overlayRef;
this.config = config;
this.containerInstance = containerInstance;
this.componentInstance = null;
this.state = 0 /* OPEN */;
this.afterClose = new Subject();
this.afterOpen = new Subject();
this.destroy$ = new Subject();
containerInstance.animationStateChanged
.pipe(filter(event => event.phaseName === 'done' && event.toState === 'enter'), take(1))
.subscribe(() => {
this.afterOpen.next();
this.afterOpen.complete();
if (config.nzAfterOpen instanceof EventEmitter) {
config.nzAfterOpen.emit();
}
});
containerInstance.animationStateChanged
.pipe(filter(event => event.phaseName === 'done' && event.toState === 'exit'), take(1))
.subscribe(() => {
clearTimeout(this.closeTimeout);
this._finishDialogClose();
});
containerInstance.containerClick.pipe(take(1), takeUntil(this.destroy$)).subscribe(() => {
const cancelable = !this.config.nzCancelLoading && !this.config.nzOkLoading;
if (cancelable) {
this.trigger("cancel" /* CANCEL */);
}
});
overlayRef
.keydownEvents()
.pipe(filter(event => this.config.nzKeyboard &&
!this.config.nzCancelLoading &&
!this.config.nzOkLoading &&
event.keyCode === ESCAPE &&
!hasModifierKey(event)))
.subscribe(event => {
event.preventDefault();
this.trigger("cancel" /* CANCEL */);
});
containerInstance.cancelTriggered
.pipe(takeUntil(this.destroy$))