ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
2,331 lines • 67.2 kB
JavaScript
import { Directionality } from "@angular/cdk/bidi";
import * as i1 from "@angular/cdk/overlay";
import { CdkScrollable, OverlayRef, createBlockScrollStrategy, createGlobalPositionStrategy, createOverlayRef } from "@angular/cdk/overlay";
import * as i4 from "@angular/cdk/portal";
import { BasePortalOutlet, CdkPortalOutlet, ComponentPortal, PortalModule, TemplatePortal } from "@angular/cdk/portal";
import * as i0 from "@angular/core";
import { ANIMATION_MODULE_TYPE, ChangeDetectorRef, Component, ContentChild, DOCUMENT, DestroyRef, Directive, ElementRef, EventEmitter, Injectable, InjectionToken, Injector, Input, NgModule, NgZone, Output, Renderer2, TemplateRef, ViewChild, ViewContainerRef, booleanAttribute, inject, input, numberAttribute, output } from "@angular/core";
import { ReplaySubject, Subject, defer } from "rxjs";
import { filter, startWith, take, takeUntil } from "rxjs/operators";
import { NzConfigService, onConfigChangeEventForComponent } from "ng-zorro-antd/core/config";
import { warn } from "ng-zorro-antd/core/logger";
import { overlayZIndexSetter } from "ng-zorro-antd/core/overlay";
import { fromEventOutsideAngular, getElementOffset, isNotNil, isPromise, isTemplateRef } from "ng-zorro-antd/core/util";
import * as i5 from "ng-zorro-antd/button";
import { NzButtonModule } from "ng-zorro-antd/button";
import * as i2 from "ng-zorro-antd/core/outlet";
import { NzOutletModule } from "ng-zorro-antd/core/outlet";
import { NzI18nPipe } from "ng-zorro-antd/i18n";
import * as i1$1 from "ng-zorro-antd/icon";
import { NzIconModule } from "ng-zorro-antd/icon";
import * as i8 from "ng-zorro-antd/pipes";
import { NzPipesModule } from "ng-zorro-antd/pipes";
import { FocusTrapFactory } from "@angular/cdk/a11y";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { requestAnimationFrame } from "ng-zorro-antd/core/polyfill";
import * as i6 from "ng-zorro-antd/core/transition-patch";
import * as i7 from "ng-zorro-antd/core/wave";
import { coerceCssPixelValue } from "@angular/cdk/coercion";
import { CdkDrag, CdkDragHandle } from "@angular/cdk/drag-drop";
import { ESCAPE, hasModifierKey } from "@angular/cdk/keycodes";
const noopFun = () => void 0;
var ModalOptions = class {
nzCentered = false;
nzClosable = true;
nzOkLoading = false;
nzOkDisabled = false;
nzCancelDisabled = false;
nzCancelLoading = false;
nzDraggable = false;
nzNoAnimation = false;
nzAutofocus = "auto";
nzMask;
nzMaskClosable;
nzKeyboard = true;
nzZIndex = 1e3;
nzWidth = 520;
nzCloseIcon = "close";
nzOkType = "primary";
nzOkDanger = false;
nzModalType = "default";
nzOnCancel = noopFun;
nzOnOk = noopFun;
nzData;
nzMaskStyle;
nzBodyStyle;
nzWrapClassName;
nzClassName;
nzStyle;
nzTitle;
nzFooter;
nzCancelText;
nzOkText;
nzContent;
nzCloseOnNavigation;
nzViewContainerRef;
nzAfterOpen;
nzAfterClose;
nzIconType = "question-circle";
nzDirection;
};
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";
const NZ_MODAL_DATA = new InjectionToken(typeof ngDevMode !== "undefined" && ngDevMode ? "nz-modal-data" : "");
var NzModalCloseComponent = class NzModalCloseComponent {
config = inject(ModalOptions);
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalCloseComponent,
deps: [],
target: i0.ɵɵFactoryTarget.Component
});
static ɵcmp = i0.ɵɵngDeclareComponent({
minVersion: "14.0.0",
version: "22.2.2",
type: NzModalCloseComponent,
isStandalone: true,
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">
<nz-icon [nzType]="closeIcon" class="ant-modal-close-icon" />
</ng-container>
</span>
`,
isInline: true,
dependencies: [
{
kind: "ngmodule",
type: NzIconModule
},
{
kind: "directive",
type: i1$1.NzIconDirective,
selector: "nz-icon,[nz-icon]",
inputs: [
"nzType",
"nzTheme",
"nzTwotoneColor",
"nzSpin",
"nzRotate",
"nzIconfont",
"aria-label"
],
exportAs: ["nzIcon"]
},
{
kind: "ngmodule",
type: NzOutletModule
},
{
kind: "directive",
type: i2.NzStringTemplateOutletDirective,
selector: "[nzStringTemplateOutlet]",
inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"],
exportAs: ["nzStringTemplateOutlet"]
}
]
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
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">
<nz-icon [nzType]="closeIcon" class="ant-modal-close-icon" />
</ng-container>
</span>
`,
host: {
class: "ant-modal-close",
"aria-label": "Close"
},
imports: [NzIconModule, NzOutletModule]
}]
}]
});
function applyConfigDefaults(config, defaultOptions) {
return {
...defaultOptions,
...config
};
}
function getValueWithConfig(userValue, configValue, defaultValue) {
return typeof userValue === "undefined" ? typeof configValue === "undefined" ? defaultValue : configValue : userValue;
}
function getConfigFromComponent(component) {
const { nzCentered, nzMask, nzMaskClosable, nzClosable, nzOkLoading, nzOkDisabled, nzCancelDisabled, nzCancelLoading, nzKeyboard, nzNoAnimation, nzDraggable, nzContent, 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,
nzDraggable,
nzClosable,
nzOkLoading,
nzOkDisabled,
nzCancelDisabled,
nzCancelLoading,
nzKeyboard,
nzNoAnimation,
nzContent,
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");
}
var BaseModalContainerComponent = class BaseModalContainerComponent extends BasePortalOutlet {
document = inject(DOCUMENT);
cdr = inject(ChangeDetectorRef);
config = inject(ModalOptions);
ngZone = inject(NgZone);
host = inject(ElementRef);
focusTrapFactory = inject(FocusTrapFactory);
renderer = inject(Renderer2);
overlayRef = inject(OverlayRef);
nzConfigService = inject(NzConfigService);
animationType = inject(ANIMATION_MODULE_TYPE, { optional: true });
destroyRef = inject(DestroyRef);
portalOutlet;
modalElementRef;
animationStateChanged = new EventEmitter();
containerClick = new EventEmitter();
cancelTriggered = new EventEmitter();
okTriggered = new EventEmitter();
modalRef;
isStringContent = false;
dir = "ltr";
elementFocusedBeforeModalWasOpened = null;
focusTrap;
mouseDown = false;
oldMaskStyle = null;
get showMask() {
const defaultConfig = this.nzConfigService.getConfigForComponent("modal") || {};
return !!getValueWithConfig(this.config.nzMask, defaultConfig.nzMask, true);
}
get maskClosable() {
const defaultConfig = this.nzConfigService.getConfigForComponent("modal") || {};
return !!getValueWithConfig(this.config.nzMaskClosable, defaultConfig.nzMaskClosable, true);
}
constructor() {
super();
this.dir = this.overlayRef.getDirection();
this.isStringContent = typeof this.config.nzContent === "string";
onConfigChangeEventForComponent(NZ_CONFIG_MODULE_NAME, () => this.updateMaskClassname());
this.destroyRef.onDestroy(() => {
this.setMaskExitAnimationClass(this.overlayRef.backdropElement, 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();
}
markForCheck() {
this.cdr.markForCheck();
}
attachComponentPortal(portal) {
if (this.portalOutlet.hasAttached()) throwNzModalContentAlreadyAttachedError();
this.savePreviouslyFocusedElement();
this.setZIndexForBackdrop();
const result = this.portalOutlet.attachComponentPortal(portal);
this._startEnterAnimation();
return result;
}
attachTemplatePortal(portal) {
if (this.portalOutlet.hasAttached()) throwNzModalContentAlreadyAttachedError();
this.savePreviouslyFocusedElement();
this.setZIndexForBackdrop();
const result = this.portalOutlet.attachTemplatePortal(portal);
this._startEnterAnimation();
return result;
}
attachStringContent() {
this.savePreviouslyFocusedElement();
this.setZIndexForBackdrop();
this._startEnterAnimation();
}
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.renderer.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(() => requestAnimationFrame(() => 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() {
this.elementFocusedBeforeModalWasOpened?.focus();
this.focusTrap?.destroy();
}
isAnimating(element, animationName) {
return !!element.getAnimations?.().some((animation) => animation.animationName === animationName);
}
setEnterInitialClass() {
if (this.animationDisabled()) return;
const modalElement = this.modalElementRef.nativeElement;
const backdropElement = this.overlayRef.backdropElement;
modalElement.classList.add(ZOOM_CLASS_NAME_MAP.enter);
if (backdropElement) backdropElement.classList.add(FADE_CLASS_NAME_MAP.enter);
}
setEnterActiveClass() {
if (this.animationDisabled()) return;
this.setModalTransformOrigin();
const modalElement = this.modalElementRef.nativeElement;
const backdropElement = this.overlayRef.backdropElement;
modalElement.classList.add(ZOOM_CLASS_NAME_MAP.enterActive);
if (backdropElement) backdropElement.classList.add(FADE_CLASS_NAME_MAP.enterActive);
}
setExitAnimationClass(backdropElement) {
const modalElement = this.modalElementRef.nativeElement;
modalElement.classList.add(ZOOM_CLASS_NAME_MAP.leave);
modalElement.classList.add(ZOOM_CLASS_NAME_MAP.leaveActive);
this.setMaskExitAnimationClass(backdropElement);
}
setMaskExitAnimationClass(backdropElement, force = false) {
if (backdropElement) {
if (this.animationDisabled() || force) {
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.renderer.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.renderer.removeStyle(backdropElement, key);
});
this.oldMaskStyle = null;
}
this.setZIndexForBackdrop();
if (typeof this.config.nzMaskStyle === "object" && Object.keys(this.config.nzMaskStyle).length) {
const styles = { ...this.config.nzMaskStyle };
Object.keys(styles).forEach((key) => {
this.renderer.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);
}
}
_startEnterAnimation() {
this.bindBackdropStyle();
this.animationStateChanged.emit("enter-start");
if (this.animationDisabled()) {
this.trapFocus();
this.animationStateChanged.emit("enter-active");
} else {
this.setEnterInitialClass();
const element = this.modalElementRef.nativeElement;
const finish = () => {
element.removeEventListener("animationend", onAnimationEnd);
this.trapFocus();
this.cleanAnimationClass();
this.animationStateChanged.emit("enter-active");
};
const onAnimationEnd = (event) => {
if (event.target === element && event.animationName === "antZoomIn" && !element.classList.contains(ZOOM_CLASS_NAME_MAP.leave)) finish();
};
element.addEventListener("animationend", onAnimationEnd);
requestAnimationFrame(() => {
if (!element.isConnected || element.classList.contains(ZOOM_CLASS_NAME_MAP.leave)) return;
this.setEnterActiveClass();
if (!this.isAnimating(element, "antZoomIn")) finish();
});
}
}
_startLeaveAnimation(backdropElement) {
this.animationStateChanged.emit("leave-start");
if (this.animationDisabled()) {
this.restoreFocus();
this.animationStateChanged.emit("leave-active");
} else {
this.setExitAnimationClass(backdropElement);
const element = this.modalElementRef.nativeElement;
let pendingAnimations = backdropElement ? 2 : 1;
const finish = () => {
if (--pendingAnimations > 0) return;
this.restoreFocus();
this.cleanAnimationClass();
this.animationStateChanged.emit("leave-active");
};
const onModalAnimationEnd = (event) => {
if (event.target !== element || event.animationName !== "antZoomOut") return;
element.removeEventListener("animationend", onModalAnimationEnd);
finish();
};
if (this.isAnimating(element, "antZoomOut")) element.addEventListener("animationend", onModalAnimationEnd);
else finish();
if (backdropElement) {
const backdropParent = backdropElement.parentNode;
const observer = new MutationObserver(() => {
if (!backdropElement.isConnected) finishBackdrop();
});
const finishBackdrop = () => {
backdropElement.removeEventListener("animationend", onBackdropAnimationEnd);
observer.disconnect();
finish();
};
const onBackdropAnimationEnd = (event) => {
if (event.target !== backdropElement || event.animationName !== "antFadeOut") return;
finishBackdrop();
};
backdropElement.addEventListener("animationend", onBackdropAnimationEnd);
if (backdropParent) observer.observe(backdropParent, { childList: true });
}
}
}
setupMouseListeners(modalContainer) {
fromEventOutsideAngular(this.host.nativeElement, "mouseup").pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
if (this.mouseDown) setTimeout(() => {
this.mouseDown = false;
});
});
fromEventOutsideAngular(modalContainer.nativeElement, "mousedown").pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
this.mouseDown = true;
});
}
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: BaseModalContainerComponent,
deps: [],
target: i0.ɵɵFactoryTarget.Directive
});
static ɵdir = i0.ɵɵngDeclareDirective({
minVersion: "14.0.0",
version: "22.2.2",
type: BaseModalContainerComponent,
isStandalone: true,
usesInheritance: true,
ngImport: i0
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: BaseModalContainerComponent,
decorators: [{ type: Directive }],
ctorParameters: () => []
});
var NzModalConfirmContainerComponent = class NzModalConfirmContainerComponent extends BaseModalContainerComponent {
set _portalOutlet(portalOutlet) {
this.portalOutlet = portalOutlet;
}
set _modalElementRef(elementRef) {
this.modalElementRef = elementRef;
}
cancelTriggered = new EventEmitter();
okTriggered = new EventEmitter();
ngOnInit() {
this.setupMouseListeners(this.modalElementRef);
}
onCancel() {
this.cancelTriggered.emit();
}
onOk() {
this.okTriggered.emit();
}
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalConfirmContainerComponent,
deps: null,
target: i0.ɵɵFactoryTarget.Component
});
static ɵcmp = i0.ɵɵngDeclareComponent({
minVersion: "17.0.0",
version: "22.2.2",
type: NzModalConfirmContainerComponent,
isStandalone: true,
selector: "nz-modal-confirm-container",
outputs: {
cancelTriggered: "cancelTriggered",
okTriggered: "okTriggered"
},
host: {
attributes: {
"tabindex": "-1",
"role": "dialog"
},
listeners: { "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"
}
},
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,
hostDirectives: [{ directive: i1.CdkScrollable }],
ngImport: i0,
template: `
<div
#modalElement
role="document"
class="ant-modal"
[class]="config.nzClassName!"
[style]="config.nzStyle!"
[style.width]="config?.nzWidth! | nzToCssUnit"
>
<div class="ant-modal-content">
@if (config.nzClosable) {
<button nz-modal-close (click)="onCloseClick()"></button>
}
<div class="ant-modal-body" [style]="config.nzBodyStyle!">
<div class="ant-modal-confirm-body-wrapper">
<div class="ant-modal-confirm-body">
<nz-icon [nzType]="config.nzIconType!" />
<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 />
@if (isStringContent) {
<div [innerHTML]="config.nzContent"></div>
}
</div>
</div>
<div class="ant-modal-confirm-btns">
@if (config.nzCancelText !== null) {
<button
[attr.cdkFocusInitial]="config.nzAutofocus === 'cancel' || null"
nz-button
(click)="onCancel()"
[nzLoading]="config.nzCancelLoading"
[disabled]="config.nzCancelDisabled"
>
{{ config.nzCancelText || ('Modal.cancelText' | nzI18n) }}
</button>
}
@if (config.nzOkText !== null) {
<button
[attr.cdkFocusInitial]="config.nzAutofocus === 'ok' || null"
nz-button
[nzType]="config.nzOkType!"
(click)="onOk()"
[nzLoading]="config.nzOkLoading"
[disabled]="config.nzOkDisabled"
[nzDanger]="config.nzOkDanger"
>
{{ config.nzOkText || ('Modal.okText' | nzI18n) }}
</button>
}
</div>
</div>
</div>
</div>
</div>
`,
isInline: true,
dependencies: [
{
kind: "ngmodule",
type: NzPipesModule
},
{
kind: "ngmodule",
type: NzIconModule
},
{
kind: "directive",
type: i1$1.NzIconDirective,
selector: "nz-icon,[nz-icon]",
inputs: [
"nzType",
"nzTheme",
"nzTwotoneColor",
"nzSpin",
"nzRotate",
"nzIconfont",
"aria-label"
],
exportAs: ["nzIcon"]
},
{
kind: "component",
type: NzModalCloseComponent,
selector: "button[nz-modal-close]",
exportAs: ["nzModalCloseBuiltin"]
},
{
kind: "ngmodule",
type: NzOutletModule
},
{
kind: "directive",
type: i2.NzStringTemplateOutletDirective,
selector: "[nzStringTemplateOutlet]",
inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"],
exportAs: ["nzStringTemplateOutlet"]
},
{
kind: "ngmodule",
type: PortalModule
},
{
kind: "directive",
type: i4.CdkPortalOutlet,
selector: "[cdkPortalOutlet]",
inputs: ["cdkPortalOutlet"],
outputs: ["attached"],
exportAs: ["cdkPortalOutlet"]
},
{
kind: "ngmodule",
type: NzButtonModule
},
{
kind: "component",
type: i5.NzButtonComponent,
selector: "button[nz-button], a[nz-button]",
inputs: [
"nzBlock",
"nzGhost",
"nzLoading",
"nzDanger",
"disabled",
"tabIndex",
"nzType",
"nzShape",
"nzSize"
],
exportAs: ["nzButton"]
},
{
kind: "directive",
type: i6.ɵNzTransitionPatchDirective,
selector: "[nz-button], [nz-icon], nz-icon, [nz-menu-item], [nz-submenu], nz-select-top-control, nz-select-placeholder, nz-input-group",
inputs: ["hidden"]
},
{
kind: "directive",
type: i7.NzWaveDirective,
selector: "[nz-wave],button[nz-button]:not([nzType=\"link\"]):not([nzType=\"text\"])",
inputs: ["nzWaveExtraNode"],
exportAs: ["nzWave"]
},
{
kind: "pipe",
type: i8.NzToCssUnitPipe,
name: "nzToCssUnit"
},
{
kind: "pipe",
type: NzI18nPipe,
name: "nzI18n"
}
]
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalConfirmContainerComponent,
decorators: [{
type: Component,
args: [{
selector: "nz-modal-confirm-container",
exportAs: "nzModalConfirmContainer",
imports: [
NzPipesModule,
NzI18nPipe,
NzIconModule,
NzModalCloseComponent,
NzOutletModule,
PortalModule,
NzButtonModule
],
template: `
<div
#modalElement
role="document"
class="ant-modal"
[class]="config.nzClassName!"
[style]="config.nzStyle!"
[style.width]="config?.nzWidth! | nzToCssUnit"
>
<div class="ant-modal-content">
@if (config.nzClosable) {
<button nz-modal-close (click)="onCloseClick()"></button>
}
<div class="ant-modal-body" [style]="config.nzBodyStyle!">
<div class="ant-modal-confirm-body-wrapper">
<div class="ant-modal-confirm-body">
<nz-icon [nzType]="config.nzIconType!" />
<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 />
@if (isStringContent) {
<div [innerHTML]="config.nzContent"></div>
}
</div>
</div>
<div class="ant-modal-confirm-btns">
@if (config.nzCancelText !== null) {
<button
[attr.cdkFocusInitial]="config.nzAutofocus === 'cancel' || null"
nz-button
(click)="onCancel()"
[nzLoading]="config.nzCancelLoading"
[disabled]="config.nzCancelDisabled"
>
{{ config.nzCancelText || ('Modal.cancelText' | nzI18n) }}
</button>
}
@if (config.nzOkText !== null) {
<button
[attr.cdkFocusInitial]="config.nzAutofocus === 'ok' || null"
nz-button
[nzType]="config.nzOkType!"
(click)="onOk()"
[nzLoading]="config.nzOkLoading"
[disabled]="config.nzOkDisabled"
[nzDanger]="config.nzOkDanger"
>
{{ config.nzOkText || ('Modal.okText' | nzI18n) }}
</button>
}
</div>
</div>
</div>
</div>
</div>
`,
hostDirectives: [CdkScrollable],
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",
"(click)": "onContainerClick($event)"
}
}]
}],
propDecorators: {
_portalOutlet: [{
type: ViewChild,
args: [CdkPortalOutlet, { static: true }]
}],
_modalElementRef: [{
type: ViewChild,
args: ["modalElement", { static: true }]
}],
cancelTriggered: [{ type: Output }],
okTriggered: [{ type: Output }]
}
});
var NzModalFooterComponent = class NzModalFooterComponent {
cdr = inject(ChangeDetectorRef);
config = inject(ModalOptions);
modalRef = input.required(...ngDevMode ? [{ debugName: "modalRef" }] : /* istanbul ignore next */ []);
cancelTriggered = output();
okTriggered = output();
buttons = Array.isArray(this.config.nzFooter) ? this.config.nzFooter.map(mergeDefaultOption) : null;
onCancel() {
this.cancelTriggered.emit();
}
onOk() {
this.okTriggered.emit();
}
markForCheck() {
this.cdr.markForCheck();
}
getButtonCallableProp(options, prop) {
const value = options[prop];
const componentInstance = this.modalRef().getContentComponent();
return typeof value === "function" ? value.apply(options, componentInstance && [componentInstance]) : value;
}
onButtonClick(options) {
if (!this.getButtonCallableProp(options, "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;
});
}
}
}
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalFooterComponent,
deps: [],
target: i0.ɵɵFactoryTarget.Component
});
static ɵcmp = i0.ɵɵngDeclareComponent({
minVersion: "17.0.0",
version: "22.2.2",
type: NzModalFooterComponent,
isStandalone: true,
selector: "div[nz-modal-footer]",
inputs: { modalRef: {
classPropertyName: "modalRef",
publicName: "modalRef",
isSignal: true,
isRequired: true,
transformFunction: null
} },
outputs: {
cancelTriggered: "cancelTriggered",
okTriggered: "okTriggered"
},
host: { classAttribute: "ant-modal-footer" },
exportAs: ["nzModalFooterBuiltin"],
ngImport: i0,
template: `
@if (config.nzFooter) {
<ng-container
*nzStringTemplateOutlet="config.nzFooter; context: { $implicit: config.nzData, modalRef: modalRef() }"
>
@if (buttons) {
@for (button of buttons; track button) {
<button
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>
}
} @else {
<div [innerHTML]="config.nzFooter"></div>
}
</ng-container>
} @else {
@if (config.nzCancelText !== null) {
<button
[attr.cdkFocusInitial]="config.nzAutofocus === 'cancel' || null"
nz-button
(click)="onCancel()"
[nzLoading]="config.nzCancelLoading"
[disabled]="config.nzCancelDisabled"
>
{{ config.nzCancelText || ('Modal.cancelText' | nzI18n) }}
</button>
}
@if (config.nzOkText !== null) {
<button
[attr.cdkFocusInitial]="config.nzAutofocus === 'ok' || null"
nz-button
[nzType]="config.nzOkType!"
[nzDanger]="config.nzOkDanger"
(click)="onOk()"
[nzLoading]="config.nzOkLoading"
[disabled]="config.nzOkDisabled"
>
{{ config.nzOkText || ('Modal.okText' | nzI18n) }}
</button>
}
}
`,
isInline: true,
dependencies: [
{
kind: "ngmodule",
type: NzOutletModule
},
{
kind: "directive",
type: i2.NzStringTemplateOutletDirective,
selector: "[nzStringTemplateOutlet]",
inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"],
exportAs: ["nzStringTemplateOutlet"]
},
{
kind: "ngmodule",
type: NzButtonModule
},
{
kind: "component",
type: i5.NzButtonComponent,
selector: "button[nz-button], a[nz-button]",
inputs: [
"nzBlock",
"nzGhost",
"nzLoading",
"nzDanger",
"disabled",
"tabIndex",
"nzType",
"nzShape",
"nzSize"
],
exportAs: ["nzButton"]
},
{
kind: "directive",
type: i6.ɵNzTransitionPatchDirective,
selector: "[nz-button], [nz-icon], nz-icon, [nz-menu-item], [nz-submenu], nz-select-top-control, nz-select-placeholder, nz-input-group",
inputs: ["hidden"]
},
{
kind: "directive",
type: i7.NzWaveDirective,
selector: "[nz-wave],button[nz-button]:not([nzType=\"link\"]):not([nzType=\"text\"])",
inputs: ["nzWaveExtraNode"],
exportAs: ["nzWave"]
},
{
kind: "pipe",
type: NzI18nPipe,
name: "nzI18n"
}
]
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalFooterComponent,
decorators: [{
type: Component,
args: [{
selector: "div[nz-modal-footer]",
exportAs: "nzModalFooterBuiltin",
imports: [
NzOutletModule,
NzButtonModule,
NzI18nPipe
],
template: `
@if (config.nzFooter) {
<ng-container
*nzStringTemplateOutlet="config.nzFooter; context: { $implicit: config.nzData, modalRef: modalRef() }"
>
@if (buttons) {
@for (button of buttons; track button) {
<button
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>
}
} @else {
<div [innerHTML]="config.nzFooter"></div>
}
</ng-container>
} @else {
@if (config.nzCancelText !== null) {
<button
[attr.cdkFocusInitial]="config.nzAutofocus === 'cancel' || null"
nz-button
(click)="onCancel()"
[nzLoading]="config.nzCancelLoading"
[disabled]="config.nzCancelDisabled"
>
{{ config.nzCancelText || ('Modal.cancelText' | nzI18n) }}
</button>
}
@if (config.nzOkText !== null) {
<button
[attr.cdkFocusInitial]="config.nzAutofocus === 'ok' || null"
nz-button
[nzType]="config.nzOkType!"
[nzDanger]="config.nzOkDanger"
(click)="onOk()"
[nzLoading]="config.nzOkLoading"
[disabled]="config.nzOkDisabled"
>
{{ config.nzOkText || ('Modal.okText' | nzI18n) }}
</button>
}
}
`,
host: { class: "ant-modal-footer" }
}]
}],
propDecorators: {
modalRef: [{
type: i0.Input,
args: [{
isSignal: true,
alias: "modalRef",
required: true
}]
}],
cancelTriggered: [{
type: i0.Output,
args: ["cancelTriggered"]
}],
okTriggered: [{
type: i0.Output,
args: ["okTriggered"]
}]
}
});
function mergeDefaultOption(options) {
return {
type: null,
size: "default",
autoLoading: true,
show: true,
loading: false,
disabled: false,
...options
};
}
var NzModalTitleComponent = class NzModalTitleComponent {
config = inject(ModalOptions);
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalTitleComponent,
deps: [],
target: i0.ɵɵFactoryTarget.Component
});
static ɵcmp = i0.ɵɵngDeclareComponent({
minVersion: "14.0.0",
version: "22.2.2",
type: NzModalTitleComponent,
isStandalone: true,
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,
dependencies: [{
kind: "ngmodule",
type: NzOutletModule
}, {
kind: "directive",
type: i2.NzStringTemplateOutletDirective,
selector: "[nzStringTemplateOutlet]",
inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"],
exportAs: ["nzStringTemplateOutlet"]
}]
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
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" },
imports: [NzOutletModule]
}]
}]
});
var NzModalContainerComponent = class NzModalContainerComponent extends BaseModalContainerComponent {
set _portalOutlet(portalOutlet) {
this.portalOutlet = portalOutlet;
}
set _modalElementRef(elementRef) {
this.modalElementRef = elementRef;
}
modalFooter;
markForCheck() {
super.markForCheck();
this.modalFooter?.markForCheck();
}
ngOnInit() {
this.setupMouseListeners(this.modalElementRef);
}
onDragEnded(event) {
const element = this.modalElementRef.nativeElement;
const dragPosition = event.source.getFreeDragPosition();
const { top, left } = getComputedStyle(element);
this.renderer.setStyle(element, "top", coerceCssPixelValue((parseFloat(top) || 0) + dragPosition.y));
this.renderer.setStyle(element, "left", coerceCssPixelValue((parseFloat(left) || 0) + dragPosition.x));
event.source.reset();
}
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalContainerComponent,
deps: null,
target: i0.ɵɵFactoryTarget.Component
});
static ɵcmp = i0.ɵɵngDeclareComponent({
minVersion: "17.0.0",
version: "22.2.2",
type: NzModalContainerComponent,
isStandalone: true,
selector: "nz-modal-container",
host: {
attributes: {
"tabindex": "-1",
"role": "dialog"
},
listeners: { "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"
}
},
viewQueries: [
{
propertyName: "_portalOutlet",
first: true,
predicate: CdkPortalOutlet,
descendants: true,
static: true
},
{
propertyName: "_modalElementRef",
first: true,
predicate: ["modalElement"],
descendants: true,
static: true
},
{
propertyName: "modalFooter",
first: true,
predicate: NzModalFooterComponent,
descendants: true
}
],
exportAs: ["nzModalContainer"],
usesInheritance: true,
hostDirectives: [{ directive: i1.CdkScrollable }],
ngImport: i0,
template: `
<div
#modalElement
cdkDrag
cdkDragBoundary=".cdk-overlay-container"
[cdkDragDisabled]="!config.nzDraggable"
(cdkDragEnded)="onDragEnded($event)"
role="document"
class="ant-modal"
[class]="config.nzClassName!"
[style]="config.nzStyle!"
[style.width]="config?.nzWidth! | nzToCssUnit"
>
<div class="ant-modal-content">
@if (config.nzClosable) {
<button nz-modal-close (click)="onCloseClick()"></button>
}
@if (config.nzTitle) {
<div nz-modal-title cdkDragHandle [style.cursor]="config.nzDraggable ? 'move' : 'auto'"></div>
}
<div class="ant-modal-body" [style]="config.nzBodyStyle!">
<ng-template cdkPortalOutlet />
@if (isStringContent) {
<div [innerHTML]="config.nzContent"></div>
}
</div>
@if (config.nzFooter !== null) {
<div
nz-modal-footer
[modalRef]="modalRef"
(cancelTriggered)="onCloseClick()"
(okTriggered)="onOkClick()"
></div>
}
</div>
</div>
`,
isInline: true,
dependencies: [
{
kind: "component",
type: NzModalCloseComponent,
selector: "button[nz-modal-close]",
exportAs: ["nzModalCloseBuiltin"]
},
{
kind: "component",
type: NzModalTitleComponent,
selector: "div[nz-modal-title]",
exportAs: ["nzModalTitleBuiltin"]
},
{
kind: "ngmodule",
type: PortalModule
},
{
kind: "directive",
type: i4.CdkPortalOutlet,
selector: "[cdkPortalOutlet]",
inputs: ["cdkPortalOutlet"],
outputs: ["attached"],
exportAs: ["cdkPortalOutlet"]
},
{
kind: "component",
type: NzModalFooterComponent,
selector: "div[nz-modal-footer]",
inputs: ["modalRef"],
outputs: ["cancelTriggered", "okTriggered"],
exportAs: ["nzModalFooterBuiltin"]
},
{
kind: "ngmodule",
type: NzPipesModule
},
{
kind: "directive",
type: CdkDrag,
selector: "[cdkDrag]",
inputs: [
"cdkDragData",
"cdkDragLockAxis",
"cdkDragRootElement",
"cdkDragBoundary",
"cdkDragStartDelay",
"cdkDragFreeDragPosition",
"cdkDragDisabled",
"cdkDragConstrainPosition",
"cdkDragPreviewClass",
"cdkDragPreviewContainer",
"cdkDragScale"
],
outputs: [
"cdkDragStarted",
"cdkDragReleased",
"cdkDragEnded",
"cdkDragEntered",
"cdkDragExited",
"cdkDragDropped",
"cdkDragMoved"
],
exportAs: ["cdkDrag"]
},
{
kind: "directive",
type: CdkDragHandle,
selector: "[cdkDragHandle]",
inputs: ["cdkDragHandleDisabled"]
},
{
kind: "pipe",
type: i8.NzToCssUnitPipe,
name: "nzToCssUnit"
}
]
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalContainerComponent,
decorators: [{
type: Component,
args: [{
selector: "nz-modal-container",
exportAs: "nzModalContainer",
imports: [
NzModalCloseComponent,
NzModalTitleComponent,
PortalModule,
NzModalFooterComponent,
NzPipesModule,
CdkDrag,
CdkDragHandle
],
hostDirectives: [CdkScrollable],
template: `
<div
#modalElement
cdkDrag
cdkDragBoundary=".cdk-overlay-container"
[cdkDragDisabled]="!config.nzDraggable"
(cdkDragEnded)="onDragEnded($event)"
role="document"
class="ant-modal"
[class]="config.nzClassName!"
[style]="config.nzStyle!"
[style.width]="config?.nzWidth! | nzToCssUnit"
>
<div class="ant-modal-content">
@if (config.nzClosable) {
<button nz-modal-close (click)="onCloseClick()"></button>
}
@if (config.nzTitle) {
<div nz-modal-title cdkDragHandle [style.cursor]="config.nzDraggable ? 'move' : 'auto'"></div>
}
<div class="ant-modal-body" [style]="config.nzBodyStyle!">
<ng-template cdkPortalOutlet />
@if (isStringContent) {
<div [innerHTML]="config.nzContent"></div>
}
</div>
@if (config.nzFooter !== null) {
<div
nz-modal-footer
[modalRef]="modalRef"
(cancelTriggered)="onCloseClick()"
(okTriggered)="onOkClick()"
></div>
}
</div>
</div>
`,
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",
"(click)": "onContainerClick($event)"
}
}]
}],
propDecorators: {
_portalOutlet: [{
type: ViewChild,
args: [CdkPortalOutlet, { static: true }]
}],
_modalElementRef: [{
type: ViewChild,
args: ["modalElement", { static: true }]
}],
modalFooter: [{
type: ViewChild,
args: [NzModalFooterComponent]
}]
}
});
const NzModalState = {
OPEN: 0,
CLOSING: 1,
CLOSED: 2
};
const NzTriggerAction = {
CANCEL: "cancel",
OK: "ok"
};
var NzModalRef = class {
overlayRef;
config;
containerInstance;
componentInstance = null;
componentRef = null;
result;
state = NzModalState.OPEN;
afterClose = new Subject();
afterOpen = new ReplaySubject(1);
destroy$ = new Subject();
constructor(overlayRef, config, containerInstance) {
this.overlayRef = overlayRef;
this.config = config;
this.containerInstance = containerInstance;
containerInstance.animationStateChanged.pipe(filter((event) => event === "enter-active"), take(1)).subscribe(() => {
this.afterOpen.next();
this.afterOpen.complete();
if (config.nzAfterOpen instanceof EventEmitter) config.nzAfterOpen.emit();
});
containerInstance.animationStateChanged.pipe(filter((event) => event === "leave-active"), take(1)).subscribe(() => this._finishDialogClose());
containerInstance.containerClick.pipe(takeUntil(this.destroy$)).subscribe(() => {
if (!this.config.nzCancelLoading && !this.config.nzOkLoading) this.trigger(NzTriggerAction.CANCEL);
});
overlayRef.keydownEvents().pipe(filter(() => this.config.nzKeyboard && !this.config.nzCancelLoading && !this.config.nzOkLoading), filter((event) => event.keyCode === ESCAPE && !hasModifierKey(event))).subscribe((event) => {
event.preventDefault();
this.trigger(NzTriggerAction.CANCEL);
});
containerInstance.cancelTriggered.pipe(takeUntil(this.destroy$)).subscribe(() => this.trigger(NzTriggerAction.CANCEL));
containerInstance.okTriggered.pipe(takeUntil(this.destroy$)).subscribe(() => this.trigger(NzTriggerAction.OK));
overlayRef.detachments().subscribe(() => {
this.afterOpen.complete();
this.afterClose.next(this.result);
this.afterClose.complete();
if (config.nzAfterClose instanceof EventEmitter) config.nzAfterClose.emit(this.result);
this.componentInstance = null;
this.componentRef = null;
this.overlayRef.dispose();
});
}
getContentComponent() {
return this.componentInstance;
}
getContentComponentRef() {
return this.componentRef;
}
getElement() {
return this.containerInstance.getNativeElement();
}
destroy(result) {
this.close(result);
}
triggerOk() {
return this.trigger(NzTriggerAction.OK);
}
triggerCancel() {
return this.trigger(NzTriggerAction.CANCEL);
}
close(result) {
if (this.state !== NzModalState.OPEN) return;
this.result = result;
this.state = NzModalState.CLOSING;
const backdropElement = this.overlayRef.backdropElement;
this.overlayRef.detachBackdrop();
this.containerInstance._startLeaveAnimation(backdropElement);
}
updateConfig(config) {
Object.assign(this.config, config);
this.containerInstance.bindBackdropStyle();
this.containerInstance.markForCheck();
}
getState() {
return this.state;
}
getConfig() {
return this.config;
}
getBackdropElement() {
return this.overlayRef.backdropElement;
}
async trigger(action) {
if (this.state === NzModalState.CLOSING) return;
const { trigger, loadingKey } = {
[NzTriggerAction.OK]: {
trigger: this.config.nzOnOk,
loadingKey: "nzOkLoading"
},
[NzTriggerAction.CANCEL]: {
trigger: this.config.nzOnCancel,
loadingKey: "nzCancelLoading"
}
}[action];
if (this.config[loadingKey]) return;
if (trigger instanceof EventEmitter) trigger.emit(this.getContentComponent());
else if (typeof trigger === "function") {
const result = trigger(this.getContentComponent());
if (isPromise(result)) {
this.config[loadingKey] = true;
this.updateConfig(this.config);
let doClose = false;
try {
doClose = await result;
} finally {
this.config[loadingKey] = false;
this.updateConfig(this.config);
this.closeWhitResult(doClose);
}
} else this.closeWhitResult(result);
}
}
closeWhitResult(result) {
if (result !== false) this.close(result);
}
_finishDialogClose() {
this.state = NzModalState.CLOSED;
this.overlayRef.dispose();
this.destroy$.next();
}
};
var NzModalService = class NzModalService {
injector = inject(Injector);
nzConfigService = inject(NzConfigService);
directionality = inject(Directionality);
parentModal = inject(NzModalService, {
skipSelf: true,
optional: true
});
openModalsAtThisLevel = [];
afterAllClosedAtThisLevel = new Subject();
get openModals() {
return this.parentModal ? this.parentModal.openModals : this.openModalsAtThisLevel;
}
get _afterAllClosed() {
const parent = this.parentModal;
return parent ? parent._afterAllClosed : this.afterAllClosedAtThisLevel;
}
afterAllClose = defer(() => this.openModals.length ? this._afterAllClosed : this._afterAllClosed.pipe(startWith(void 0)));
create(config) {
return this.open(config.nzContent, config);
}
closeAll() {
this.closeModals(this.openModals);
}
confirm(options = {}, confirmType = "confirm") {
if ("nzFooter" in options) warn(`The Confirm-Modal doesn't support "nzFooter", this property will be ignored.`);
if (!("nzWidth" in options)) options.nzWidth = 416;
if (!("nzMaskClosable" in options)) options.nzMaskClosable = false;
options.nzModalType = "confirm";
options.nzClassName = `ant-modal-confirm ant-modal-confirm-${confirmType} ${options.nzClassName || ""}`;
return this.create(options);
}
info(options = {}) {
return this.confirmFactory(options, "info");
}
success(options = {}) {
return this.confirmFactory(options, "success");
}
error(options = {}) {
return this.confirmFactory(options, "error");
}
warning(options = {}) {
return this.confirmFactory(options, "warning");
}
open(componentOrTemplateRef, config) {
const configMerged = applyConfigDefaults(config || {}, new ModalOptions());
const overlayRef = this.createOverlay(configMerged);
const modalContainer = this.attachModalContainer(overlayRef, configMerged);
const modalRef = this.attachModalContent(componentOrTemplateRef, modalContainer, overlayRef, configMerged);
modalContainer.modalRef = modalRef;
overlayZIndexSetter(overlayRef, config?.nzZIndex);
this.openModals.push(modalRef);
modalRef.afterClose.subscribe(() => this.removeOpenModal(modalRef));
return modalRef;
}
removeOpenModal(modalRef) {
const index = this.openModals.indexOf(modalRef);
if (index > -1) {
this.openModals.splice(index, 1);
if (!this.openModals.length) this._afterAllClosed.next();
}
}
closeModals(dialogs) {
let i = dialogs.length;
while (i--) {
dialogs[i].close();
if (!this.openModals.length) this._afterAllClosed.next();
}
}
createOverlay(config) {
const globalConfig = this.nzConfigService.getConfigForComponent("modal") || {};
return createOverlayRef(this.injector, {
hasBackdrop: true,
scrollStrategy: createBlockScrollStrategy(this.injector),
backdropClass: getValueWithConfig(config.nzMask, globalConfig.nzMask, true) ? MODAL_MASK_CLASS_NAME : "",
positionStrategy: createGlobalPositionStrategy(this.injector),
disposeOnNavigation: getValueWithConfig(config.nzCloseOnNavigation, globalConfig.nzCloseOnNavigation, true),
direction: getValueWithConfig(config.nzDirection, globalConfig.nzDirection, this.directionality.valueSignal())
});
}
attachModalContainer(overlayRef, config) {
const userInjector = config && config.nzViewContainerRef && config.nzViewContainerRef.injector;
const injector = Injector.create({
parent: userInjector || this.injector,
providers: [{
provide: OverlayRef,
useValue: overlayRef
}, {
provide: ModalOptions,
useValue: config
}]
});
const ContainerComponent = config.nzModalType === "confirm" ? NzModalConfirmContainerComponent : NzModalContainerComponent;
const containerPortal = new ComponentPortal(ContainerComponent, config.nzViewContainerRef, injector);
return overlayRef.attach(containerPortal).instance;
}
attachModalContent(componentOrTemplateRef, modalContainer, overlayRef, config) {
const modalRef = new NzModalRef(overlayRef, config, modalContainer);
if (isTemplateRef(componentOrTemplateRef)) modalContainer.attachTemplatePortal(new TemplatePortal(componentOrTemplateRef, null, {
$implicit: config.nzData,
modalRef
}));
else if (isNotNil(componentOrTemplateRef) && typeof componentOrTemplateRef !== "string") {
const injector = this.createInjector(modalRef, config);
const contentRef = modalContainer.attachComponentPortal(new ComponentPortal(componentOrTemplateRef, config.nzViewContainerRef, injector));
modalRef.componentRef = contentRef;
modalRef.componentInstance = contentRef.instance;
} else modalContainer.attachStringContent();
return modalRef;
}
createInjector(modalRef, config) {
const userInjector = config && config.nzViewContainerRef && config.nzViewContainerRef.injector;
return Injector.create({
parent: userInjector || this.injector,
providers: [{
provide: NzModalRef,
useValue: modalRef
}, {
provide: NZ_MODAL_DATA,
useValue: config.nzData
}]
});
}
confirmFactory(options = {}, confirmType) {
const iconMap = {
info: "info-circle",
success: "check-circle",
error: "close-circle",
warning: "exclamation-circle"
};
if (!("nzIconType" in options)) options.nzIconType = iconMap[confirmType];
if (!("nzCancelText" in options)) options.nzCancelText = null;
return this.confirm(options, confirmType);
}
ngOnDestroy() {
this.closeModals(this.openModalsAtThisLevel);
this.afterAllClosedAtThisLevel.complete();
}
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalService,
deps: [],
target: i0.ɵɵFactoryTarget.Injectable
});
static ɵprov = i0.ɵɵngDeclareInjectable({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalService
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalService,
decorators: [{ type: Injectable }]
});
var NzModalContentDirective = class NzModalContentDirective {
templateRef = inject(TemplateRef);
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalContentDirective,
deps: [],
target: i0.ɵɵFactoryTarget.Directive
});
static ɵdir = i0.ɵɵngDeclareDirective({
minVersion: "14.0.0",
version: "22.2.2",
type: NzModalContentDirective,
isStandalone: true,
selector: "[nzModalContent]",
exportAs: ["nzModalContent"],
ngImport: i0
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalContentDirective,
decorators: [{
type: Directive,
args: [{
selector: "[nzModalContent]",
exportAs: "nzModalContent"
}]
}]
});
var NzModalFooterDirective = class NzModalFooterDirective {
templateRef = inject(TemplateRef);
nzModalRef = inject(NzModalRef, { optional: true });
constructor() {
this.nzModalRef?.updateConfig({ nzFooter: this.templateRef });
}
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalFooterDirective,
deps: [],
target: i0.ɵɵFactoryTarget.Directive
});
static ɵdir = i0.ɵɵngDeclareDirective({
minVersion: "14.0.0",
version: "22.2.2",
type: NzModalFooterDirective,
isStandalone: true,
selector: "[nzModalFooter]",
exportAs: ["nzModalFooter"],
ngImport: i0
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalFooterDirective,
decorators: [{
type: Directive,
args: [{
selector: "[nzModalFooter]",
exportAs: "nzModalFooter"
}]
}],
ctorParameters: () => []
});
var NzModalTitleDirective = class NzModalTitleDirective {
templateRef = inject(TemplateRef);
nzModalRef = inject(NzModalRef, { optional: true });
constructor() {
this.nzModalRef?.updateConfig({ nzTitle: this.templateRef });
}
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalTitleDirective,
deps: [],
target: i0.ɵɵFactoryTarget.Directive
});
static ɵdir = i0.ɵɵngDeclareDirective({
minVersion: "14.0.0",
version: "22.2.2",
type: NzModalTitleDirective,
isStandalone: true,
selector: "[nzModalTitle]",
exportAs: ["nzModalTitle"],
ngImport: i0
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalTitleDirective,
decorators: [{
type: Directive,
args: [{
selector: "[nzModalTitle]",
exportAs: "nzModalTitle"
}]
}],
ctorParameters: () => []
});
var NzModalComponent = class NzModalComponent {
cdr = inject(ChangeDetectorRef);
modal = inject(NzModalService);
viewContainerRef = inject(ViewContainerRef);
destroyRef = inject(DestroyRef);
nzMask;
nzMaskClosable;
nzCloseOnNavigation;
nzVisible = false;
nzClosable = true;
nzOkLoading = false;
nzOkDisabled = false;
nzCancelDisabled = false;
nzCancelLoading = false;
nzKeyboard = true;
nzNoAnimation = false;
nzCentered = false;
nzDraggable = false;
nzContent;
nzFooter;
nzZIndex = 1e3;
nzWidth = 520;
nzWrapClassName;
nzClassName;
nzStyle;
nzTitle;
nzCloseIcon = "close";
nzMaskStyle;
nzBodyStyle;
nzOkText;
nzCancelText;
nzOkType = "primary";
nzOkDanger = false;
nzIconType = "question-circle";
nzModalType = "default";
nzAutofocus = "auto";
nzOnOk = new EventEmitter();
nzOnCancel = new EventEmitter();
nzAfterOpen = new EventEmitter();
nzAfterClose = new EventEmitter();
nzVisibleChange = new EventEmitter();
set modalTitle(value) {
if (value) this.setTitleWithTemplate(value);
}
contentFromContentChild;
set modalFooter(value) {
if (value) this.setFooterWithTemplate(value);
}
modalRef = null;
get afterOpen() {
return this.nzAfterOpen.asObservable();
}
get afterClose() {
return this.nzAfterClose.asObservable();
}
constructor() {
this.destroyRef.onDestroy(() => {
this.modalRef?._finishDialogClose();
});
}
open() {
if (!this.nzVisible) {
this.nzVisible = true;
this.nzVisibleChange.emit(true);
}
if (!this.modalRef) {
const config = this.getConfig();
this.modalRef = this.modal.create(config);
this.modalRef.afterClose.asObservable().pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => {
this.close();
});
}
}
close(result) {
if (this.nzVisible) {
this.nzVisible = false;
this.nzVisibleChange.emit(false);
}
if (this.modalRef) {
this.modalRef.close(result);
this.modalRef = null;
}
}
destroy(result) {
this.close(result);
}
triggerOk() {
this.modalRef?.triggerOk();
}
triggerCancel() {
this.modalRef?.triggerCancel();
}
getContentComponent() {
return this.modalRef?.getContentComponent();
}
getElement() {
return this.modalRef?.getElement();
}
getModalRef() {
return this.modalRef;
}
setTitleWithTemplate(templateRef) {
this.nzTitle = templateRef;
if (this.modalRef) Promise.resolve().then(() => {
this.modalRef.updateConfig({ nzTitle: this.nzTitle });
});
}
setFooterWithTemplate(templateRef) {
this.nzFooter = templateRef;
if (this.modalRef) Promise.resolve().then(() => {
this.modalRef.updateConfig({ nzFooter: this.nzFooter });
});
this.cdr.markForCheck();
}
getConfig() {
const componentConfig = getConfigFromComponent(this);
componentConfig.nzViewContainerRef = this.viewContainerRef;
componentConfig.nzContent = this.nzContent || this.contentFromContentChild;
return componentConfig;
}
ngOnChanges(changes) {
const { nzVisible, ...otherChanges } = changes;
if (Object.keys(otherChanges).length && this.modalRef) this.modalRef.updateConfig(getConfigFromComponent(this));
if (nzVisible) {
if (this.nzVisible) this.open();
else this.close();
}
}
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalComponent,
deps: [],
target: i0.ɵɵFactoryTarget.Component
});
static ɵcmp = i0.ɵɵngDeclareComponent({
minVersion: "16.1.0",
version: "22.2.2",
type: NzModalComponent,
isStandalone: true,
selector: "nz-modal",
inputs: {
nzMask: [
"nzMask",
"nzMask",
booleanAttribute
],
nzMaskClosable: [
"nzMaskClosable",
"nzMaskClosable",
booleanAttribute
],
nzCloseOnNavigation: [
"nzCloseOnNavigation",
"nzCloseOnNavigation",
booleanAttribute
],
nzVisible: [
"nzVisible",
"nzVisible",
booleanAttribute
],
nzClosable: [
"nzClosable",
"nzClosable",
booleanAttribute
],
nzOkLoading: [
"nzOkLoading",
"nzOkLoading",
booleanAttribute
],
nzOkDisabled: [
"nzOkDisabled",
"nzOkDisabled",
booleanAttribute
],
nzCancelDisabled: [
"nzCancelDisabled",
"nzCancelDisabled",
booleanAttribute
],
nzCancelLoading: [
"nzCancelLoading",
"nzCancelLoading",
booleanAttribute
],
nzKeyboard: [
"nzKeyboard",
"nzKeyboard",
booleanAttribute
],
nzNoAnimation: [
"nzNoAnimation",
"nzNoAnimation",
booleanAttribute
],
nzCentered: [
"nzCentered",
"nzCentered",
booleanAttribute
],
nzDraggable: [
"nzDraggable",
"nzDraggable",
booleanAttribute
],
nzContent: "nzContent",
nzFooter: "nzFooter",
nzZIndex: [
"nzZIndex",
"nzZIndex",
numberAttribute
],
nzWidth: "nzWidth",
nzWrapClassName: "nzWrapClassName",
nzClassName: "nzClassName",
nzStyle: "nzStyle",
nzTitle: "nzTitle",
nzCloseIcon: "nzCloseIcon",
nzMaskStyle: "nzMaskStyle",
nzBodyStyle: "nzBodyStyle",
nzOkText: "nzOkText",
nzCancelText: "nzCancelText",
nzOkType: "nzOkType",
nzOkDanger: [
"nzOkDanger",
"nzOkDanger",
booleanAttribute
],
nzIconType: "nzIconType",
nzModalType: "nzModalType",
nzAutofocus: "nzAutofocus"
},
outputs: {
nzOnOk: "nzOnOk",
nzOnCancel: "nzOnCancel",
nzAfterOpen: "nzAfterOpen",
nzAfterClose: "nzAfterClose",
nzVisibleChange: "nzVisibleChange"
},
queries: [
{
propertyName: "modalTitle",
first: true,
predicate: NzModalTitleDirective,
descendants: true,
read: TemplateRef,
static: true
},
{
propertyName: "contentFromContentChild",
first: true,
predicate: NzModalContentDirective,
descendants: true,
read: TemplateRef,
static: true
},
{
propertyName: "modalFooter",
first: true,
predicate: NzModalFooterDirective,
descendants: true,
read: TemplateRef,
static: true
}
],
exportAs: ["nzModal"],
usesOnChanges: true,
ngImport: i0,
template: ``,
isInline: true
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalComponent,
decorators: [{
type: Component,
args: [{
selector: "nz-modal",
exportAs: "nzModal",
template: ``
}]
}],
ctorParameters: () => [],
propDecorators: {
nzMask: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzMaskClosable: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzCloseOnNavigation: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzVisible: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzClosable: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzOkLoading: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzOkDisabled: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzCancelDisabled: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzCancelLoading: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzKeyboard: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzNoAnimation: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzCentered: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzDraggable: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzContent: [{ type: Input }],
nzFooter: [{ type: Input }],
nzZIndex: [{
type: Input,
args: [{ transform: numberAttribute }]
}],
nzWidth: [{ type: Input }],
nzWrapClassName: [{ type: Input }],
nzClassName: [{ type: Input }],
nzStyle: [{ type: Input }],
nzTitle: [{ type: Input }],
nzCloseIcon: [{ type: Input }],
nzMaskStyle: [{ type: Input }],
nzBodyStyle: [{ type: Input }],
nzOkText: [{ type: Input }],
nzCancelText: [{ type: Input }],
nzOkType: [{ type: Input }],
nzOkDanger: [{
type: Input,
args: [{ transform: booleanAttribute }]
}],
nzIconType: [{ type: Input }],
nzModalType: [{ type: Input }],
nzAutofocus: [{ type: Input }],
nzOnOk: [{ type: Output }],
nzOnCancel: [{ type: Output }],
nzAfterOpen: [{ type: Output }],
nzAfterClose: [{ type: Output }],
nzVisibleChange: [{ type: Output }],
modalTitle: [{
type: ContentChild,
args: [NzModalTitleDirective, {
static: true,
read: TemplateRef
}]
}],
contentFromContentChild: [{
type: ContentChild,
args: [NzModalContentDirective, {
static: true,
read: TemplateRef
}]
}],
modalFooter: [{
type: ContentChild,
args: [NzModalFooterDirective, {
static: true,
read: TemplateRef
}]
}]
}
});
var NzModalModule = class NzModalModule {
static ɵfac = i0.ɵɵngDeclareFactory({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalModule,
deps: [],
target: i0.ɵɵFactoryTarget.NgModule
});
static ɵmod = i0.ɵɵngDeclareNgModule({
minVersion: "14.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalModule,
imports: [
NzModalComponent,
NzModalFooterDirective,
NzModalContentDirective,
NzModalCloseComponent,
NzModalFooterComponent,
NzModalTitleComponent,
NzModalTitleDirective,
NzModalContainerComponent,
NzModalConfirmContainerComponent
],
exports: [
NzModalComponent,
NzModalFooterDirective,
NzModalContentDirective,
NzModalTitleDirective
]
});
static ɵinj = i0.ɵɵngDeclareInjector({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalModule,
providers: [NzModalService],
imports: [
NzModalCloseComponent,
NzModalFooterComponent,
NzModalTitleComponent,
NzModalContainerComponent,
NzModalConfirmContainerComponent
]
});
};
i0.ɵɵngDeclareClassMetadata({
minVersion: "12.0.0",
version: "22.2.2",
ngImport: i0,
type: NzModalModule,
decorators: [{
type: NgModule,
args: [{
imports: [
NzModalComponent,
NzModalFooterDirective,
NzModalContentDirective,
NzModalCloseComponent,
NzModalFooterComponent,
NzModalTitleComponent,
NzModalTitleDirective,
NzModalContainerComponent,
NzModalConfirmContainerComponent
],
exports: [
NzModalComponent,
NzModalFooterDirective,
NzModalContentDirective,
NzModalTitleDirective
],
providers: [NzModalService]
}]
}]
});
var NzModalLegacyAPI = class {};
export { BaseModalContainerComponent, FADE_CLASS_NAME_MAP, MODAL_MASK_CLASS_NAME, ModalOptions, NZ_CONFIG_MODULE_NAME, NZ_MODAL_DATA, NzModalCloseComponent, NzModalComponent, NzModalConfirmContainerComponent, NzModalContainerComponent, NzModalContentDirective, NzModalFooterComponent, NzModalFooterDirective, NzModalLegacyAPI, NzModalModule, NzModalRef, NzModalService, NzModalState, NzModalTitleComponent, NzModalTitleDirective, NzTriggerAction, ZOOM_CLASS_NAME_MAP, applyConfigDefaults, getConfigFromComponent, getValueWithConfig, throwNzModalContentAlreadyAttachedError };
//# sourceMappingURL=ng-zorro-antd-modal.mjs.map