primeng
Version:
PrimeNG is a premium UI library for Angular featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock,
1,097 lines (1,085 loc) • 37.9 kB
JavaScript
import { NgComponentOutlet, DOCUMENT } from '@angular/common';
import * as i0 from '@angular/core';
import { Directive, Injectable, InjectionToken, inject, signal, viewChild, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule, createComponent, Inject } from '@angular/core';
import { uuid, appendChild } from '@primeuix/utils';
import { TranslationKeys, SharedModule } from 'primeng/api';
import { BaseComponent, PARENT_INSTANCE } from 'primeng/basecomponent';
import * as i1 from 'primeng/bind';
import { Bind, BindModule } from 'primeng/bind';
import { DialogStyle, Dialog } from 'primeng/dialog';
import { Subject } from 'rxjs';
/**
* Dialogs can be created dynamically with any component as the content using a DialogService.
* @group Components
*/
class DynamicDialogConfig {
/**
* An object to pass to the component loaded inside the Dialog.
* @group Props
*/
data;
/**
* An object to pass to the component loaded inside the Dialog.
* @group Props
*/
inputValues;
/**
* Header text of the dialog.
* @group Props
*/
header;
/**
* Identifies the element (or elements) that labels the element it is applied to.
* @group Props
*/
ariaLabelledBy;
/**
* Footer text of the dialog.
* @group Props
*/
footer;
/**
* Width of the dialog.
* @group Props
*/
width;
/**
* Height of the dialog.
* @group Props
*/
height;
/**
* Specifies if pressing escape key should hide the dialog.
* @group Props
*/
closeOnEscape = false;
/**
* Specifies if autofocus should happen on show.
* @group Props
*/
focusOnShow = true;
/**
* When enabled, can only focus on elements inside the dialog.
* @group Props
*/
focusTrap = true;
/**
* Base zIndex value to use in layering.
* @group Props
*/
baseZIndex;
/**
* Whether to re-enforce layering through applying zIndex.
* @group Props
*/
autoZIndex = false;
/**
* Specifies if clicking the modal background should hide the dialog.
* @group Props
*/
dismissableMask = false;
/**
* Inline style of the component.
* @group Props
*/
rtl = false;
/**
* Inline style of the component.
* @group Props
*/
style;
/**
* Inline style of the content.
* @group Props
*/
contentStyle;
/**
* Style class of the component.
* @group Props
*/
styleClass;
/**
* The motion options for the dialog.
* @group Props
*/
motionOptions;
/**
* The motion options for the mask.
* @group Props
*/
maskMotionOptions;
/**
* Adds a close icon to the header to hide the dialog.
* @group Props
*/
closable = false;
/**
* Whether to show the header or not.
* @group Props
*/
showHeader = false;
/**
* Defines if background should be blocked when dialog is displayed.
* @group Props
*/
modal = false;
/**
* Style class of the mask.
* @group Props
*/
maskStyleClass;
/**
* Enables resizing of the content.
* @group Props
*/
resizable = false;
/**
* Enables dragging to change the position using header.
* @group Props
*/
draggable = false;
/**
* Keeps dialog in the viewport.
* @group Props
*/
keepInViewport = false;
/**
* Minimum value for the left coordinate of dialog in dragging.
* @group Props
*/
minX;
/**
* Minimum value for the top coordinate of dialog in dragging.
* @group Props
*/
minY;
/**
* Whether the dialog can be displayed full screen.
* @group Props
*/
maximizable = false;
/**
* Name of the maximize icon.
* @group Props
*/
maximizeIcon;
/**
* Name of the minimize icon.
* @group Props
*/
minimizeIcon;
/**
* Position of the dialog.
* @group Props
*/
position;
/**
* Defines a string that labels the close button for accessibility.
* @group Props
*/
closeAriaLabel;
/**
* Target element to attach the overlay, valid values are "body" or a local ng-template variable of another element (note: use binding with brackets for template variables, e.g. [appendTo]="mydiv" for a div element having #mydiv as variable name).
* @group Props
*/
appendTo;
/**
* A boolean to determine if it can be duplicate.
* @group Props
*/
duplicate = false;
/**
* Object literal to define widths per screen size.
* @group Props
*/
breakpoints;
/**
* Dialog templates.
* @group Props
*/
templates;
/**
* Used to pass attributes to DOM elements inside the Dialog component.
* @group Props
*/
pt;
/**
* Indicates whether the component should be rendered without styles.
* @group Props
*/
unstyled;
}
/**
* Dynamic Dialog instance.
* @group Components
*/
class DynamicDialogRef {
constructor() { }
/**
* Closes dialog.
* @group Method
*/
close(result) {
this._onClose.next(result);
setTimeout(() => {
this._onClose.complete();
}, 1000);
}
/**
* Destroys the dialog instance.
* @group Method
*/
destroy() {
this._onDestroy.next(null);
}
/**
* Callback to invoke on drag start.
* @param {MouseEvent} event - Mouse event.
* @group Method
*/
dragStart(event) {
this._onDragStart.next(event);
}
/**
* Callback to invoke on drag end.
* @param {MouseEvent} event - Mouse event.
* @group Method
*/
dragEnd(event) {
this._onDragEnd.next(event);
}
/**
* Callback to invoke on resize start.
* @param {MouseEvent} event - Mouse event.
* @group Method
*/
resizeInit(event) {
this._onResizeInit.next(event);
}
/**
* Callback to invoke on resize start.
* @param {MouseEvent} event - Mouse event.
* @group Method
*/
resizeEnd(event) {
this._onResizeEnd.next(event);
}
/**
* Callback to invoke on dialog is maximized.
* @param {*} value - Size value.
* @group Method
*/
maximize(value) {
this._onMaximize.next(value);
}
_onClose = new Subject();
/**
* Event triggered on dialog is closed.
* @group Events
*/
onClose = this._onClose.asObservable();
_onDestroy = new Subject();
/**
* Event triggered on dialog instance is destroyed.
* @group Events
*/
onDestroy = this._onDestroy.asObservable();
_onDragStart = new Subject();
/**
* Event triggered on drag start.
* @param {MouseEvent} event - Mouse event.
* @group Events
*/
onDragStart = this._onDragStart.asObservable();
_onDragEnd = new Subject();
/**
* Event triggered on drag end.
* @param {MouseEvent} event - Mouse event.
* @group Events
*/
onDragEnd = this._onDragEnd.asObservable();
_onResizeInit = new Subject();
/**
* Event triggered on resize start.
* @param {MouseEvent} event - Mouse event.
* @group Events
*/
onResizeInit = this._onResizeInit.asObservable();
_onResizeEnd = new Subject();
/**
* Event triggered on resize end.
* @param {MouseEvent} event - Mouse event.
* @group Events
*/
onResizeEnd = this._onResizeEnd.asObservable();
_onMaximize = new Subject();
/**
* Event triggered on dialog is maximized.
* @param {*} value - Size value.
* @group Events
*/
onMaximize = this._onMaximize.asObservable();
/**
* Event triggered on child component load.
* @param {*} value - Chi.
* @group Events
*/
onChildComponentLoaded = new Subject();
}
class DynamicDialogContent {
viewContainerRef;
constructor(viewContainerRef) {
this.viewContainerRef = viewContainerRef;
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DynamicDialogContent, deps: [{ token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.0.6", type: DynamicDialogContent, isStandalone: true, selector: "[pDynamicDialogContent]", ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DynamicDialogContent, decorators: [{
type: Directive,
args: [{
selector: '[pDynamicDialogContent]',
standalone: true
}]
}], ctorParameters: () => [{ type: i0.ViewContainerRef }] });
class DynamicDialogStyle extends DialogStyle {
name = 'dialog';
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DynamicDialogStyle, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DynamicDialogStyle });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DynamicDialogStyle, decorators: [{
type: Injectable
}] });
/**
*
* DynamicDialog is a container to display content in an overlay window.
*
* [Live Demo](https://www.primeng.org/dynamicdialog)
*
* @module dynamicdialogstyle
*
*/
var DynamicDialogClasses;
(function (DynamicDialogClasses) {
/**
* Class name of the mask element
*/
DynamicDialogClasses["mask"] = "p-dialog-mask";
/**
* Class name of the root element
*/
DynamicDialogClasses["root"] = "p-dialog";
/**
* Class name of the header element
*/
DynamicDialogClasses["header"] = "p-dialog-header";
/**
* Class name of the title element
*/
DynamicDialogClasses["title"] = "p-dialog-title";
/**
* Class name of the header actions element
*/
DynamicDialogClasses["headerActions"] = "p-dialog-header-actions";
/**
* Class name of the maximize button element
*/
DynamicDialogClasses["pcMaximizeButton"] = "p-dialog-maximize-button";
/**
* Class name of the close button element
*/
DynamicDialogClasses["pcCloseButton"] = "p-dialog-close-button";
/**
* Class name of the content element
*/
DynamicDialogClasses["content"] = "p-dialog-content";
/**
* Class name of the footer element
*/
DynamicDialogClasses["footer"] = "p-dialog-footer";
})(DynamicDialogClasses || (DynamicDialogClasses = {}));
const DYNAMIC_DIALOG_INSTANCE = new InjectionToken('DYNAMIC_DIALOG_INSTANCE');
class DynamicDialog extends BaseComponent {
componentName = 'Dialog';
_componentStyle = inject(DynamicDialogStyle);
$pcDynamicDialog = inject(DYNAMIC_DIALOG_INSTANCE, { optional: true, skipSelf: true }) ?? undefined;
bindDirectiveInstance = inject(Bind, { self: true });
ddconfig = inject(DynamicDialogConfig);
dialogRef = inject(DynamicDialogRef);
onAfterViewChecked() {
this.bindDirectiveInstance.setAttrs(this.ptms(['host', 'root']));
}
visible = signal(true, /* @ts-ignore */
...(ngDevMode ? [{ debugName: "visible" }] : /* istanbul ignore next */ []));
componentRef;
id = uuid('pn_id_');
insertionPoint = viewChild(DynamicDialogContent, /* @ts-ignore */
...(ngDevMode ? [{ debugName: "insertionPoint" }] : /* istanbul ignore next */ []));
dialog = viewChild(Dialog, /* @ts-ignore */
...(ngDevMode ? [{ debugName: "dialog" }] : /* istanbul ignore next */ []));
childComponentType;
inputValues = {};
get draggable() {
return this.ddconfig.draggable !== false;
}
get resizable() {
return this.ddconfig.resizable !== false;
}
get modal() {
return this.ddconfig.modal !== false;
}
get closeOnEscape() {
return this.ddconfig.closeOnEscape !== false;
}
get showHeader() {
return this.ddconfig.showHeader !== false;
}
get autoZIndex() {
return this.ddconfig.autoZIndex !== false;
}
get baseZIndex() {
return this.ddconfig.baseZIndex ?? 0;
}
get focusOnShow() {
return this.ddconfig.focusOnShow !== false;
}
get focusTrap() {
return this.ddconfig.focusTrap !== false;
}
get closeAriaLabel() {
return this.ddconfig.closeAriaLabel ?? this.defaultCloseAriaLabel;
}
get rtl() {
return this.ddconfig.rtl;
}
get styleClass() {
return this.ddconfig.styleClass;
}
get maskStyleClass() {
return this.ddconfig.maskStyleClass;
}
get dismissableMask() {
return this.ddconfig.dismissableMask;
}
get contentStyle() {
return this.ddconfig.contentStyle;
}
get minX() {
return this.ddconfig.minX ?? 0;
}
get minY() {
return this.ddconfig.minY ?? 0;
}
get keepInViewport() {
return this.ddconfig.keepInViewport ?? false;
}
get maximizable() {
return this.ddconfig.maximizable ?? false;
}
get maximizeIcon() {
return this.ddconfig.maximizeIcon;
}
get minimizeIcon() {
return this.ddconfig.minimizeIcon;
}
get closable() {
return this.ddconfig.closable;
}
get position() {
return this.ddconfig.position;
}
get defaultCloseAriaLabel() {
return this.translate(TranslationKeys.ARIA, 'close');
}
get breakpoints() {
return this.ddconfig.breakpoints;
}
get footerTemplate() {
return this.ddconfig?.templates?.footer;
}
get headerTemplate() {
return this.ddconfig?.templates?.header;
}
get contentTemplate() {
return this.ddconfig?.templates?.content;
}
get minimizeIconTemplate() {
return this.ddconfig?.templates?.minimizeicon;
}
get maximizeIconTemplate() {
return this.ddconfig?.templates?.maximizeicon;
}
get closeIconTemplate() {
return this.ddconfig?.templates?.closeicon;
}
get dialogStyle() {
return {
...(this.ddconfig?.style || {}),
...(this.ddconfig?.width && { width: this.ddconfig.width }),
...(this.ddconfig?.height && { height: this.ddconfig.height })
};
}
get header() {
return this.ddconfig.header;
}
get data() {
return this.ddconfig.data;
}
get dialogId() {
return this.$attrSelector;
}
get isUnstyled() {
return this.ddconfig.unstyled || this.$unstyled();
}
get motionOptions() {
return this.ddconfig.motionOptions;
}
get maskMotionOptions() {
return this.ddconfig.maskMotionOptions;
}
get closeButtonProps() {
return { severity: 'secondary', variant: 'text', rounded: true };
}
get maximizeButtonProps() {
return { severity: 'secondary', variant: 'text', rounded: true };
}
maximized;
dragging;
resizing;
ariaLabelledBy;
lastPageX;
lastPageY;
contentViewChild = null;
footerViewChild = null;
headerViewChild = null;
maskViewChild = null;
maskClickListener = null;
documentDragListener = null;
documentDragEndListener = null;
documentResizeListener = null;
documentResizeEndListener = null;
documentEscapeListener = null;
constructor() {
super();
}
onVisibleChange(visible) {
if (!visible) {
this.dialogRef.close();
}
}
onAfterViewInit() {
this.loadChildComponent(this.childComponentType);
this.ariaLabelledBy = this.getAriaLabelledBy();
this.cd.detectChanges();
}
getAriaLabelledBy() {
const { header, showHeader } = this.ddconfig;
if (header === null || showHeader === false) {
return null;
}
return uuid('pn_id_') + '_header';
}
loadChildComponent(componentType) {
let viewContainerRef = this.insertionPoint()?.viewContainerRef;
viewContainerRef?.clear();
this.componentRef = viewContainerRef?.createComponent(componentType);
if (this.inputValues && this.componentRef) {
Object.entries(this.inputValues).forEach(([key, value]) => {
this.componentRef.setInput(key, value);
});
}
this.dialogRef.onChildComponentLoaded.next(this.componentRef.instance);
}
onDialogHide() {
this.dialogRef.destroy();
}
onDialogMaximize(event) {
this.maximized = event.maximized;
this.dialogRef.maximize(event);
}
onDialogResizeInit(event) {
this.resizing = true;
this.dialogRef.resizeInit(event);
}
onDialogResizeEnd(event) {
this.resizing = false;
this.dialogRef.resizeEnd(event);
}
onDialogDragStart(event) {
this.dragging = true;
this.dialogRef.dragStart(event);
}
onDialogDragEnd(event) {
this.dragging = false;
this.dialogRef.dragEnd(event);
}
close() {
this.visible.set(false);
}
hide() {
if (this.dialogRef) {
this.dialogRef.close();
}
}
container = null;
wrapper = null;
unbindGlobalListeners() {
this.unbindDocumentEscapeListener();
this.unbindDocumentResizeListeners();
this.unbindDocumentDragListener();
this.unbindDocumentDragEndListener();
}
onContainerDestroy() {
this.unbindGlobalListeners();
if (this.ddconfig.modal) {
this.disableModality();
}
this.container = null;
}
bindDocumentDragListener() {
if (!this.documentDragListener) {
this.documentDragListener = this.renderer.listen(this.document.defaultView, 'mousemove', (event) => {
this.onDrag(event);
});
}
}
bindDocumentDragEndListener() {
if (!this.documentDragEndListener) {
this.documentDragEndListener = this.renderer.listen(this.document.defaultView, 'mouseup', (event) => {
this.endDrag(event);
});
}
}
unbindDocumentDragEndListener() {
if (this.documentDragEndListener) {
this.documentDragEndListener();
this.documentDragEndListener = null;
}
}
unbindDocumentDragListener() {
if (this.documentDragListener) {
this.documentDragListener();
this.documentDragListener = null;
}
}
onDrag(event) {
if (this.dragging) {
this.lastPageX = event.pageX;
this.lastPageY = event.pageY;
if (this.ddconfig.keepInViewport && this.container) {
this.container.style.position = 'fixed';
}
}
}
endDrag(event) {
if (this.dragging) {
this.dragging = false;
this.dialogRef.dragEnd(event);
this.cd.detectChanges();
}
}
resetPosition() {
if (this.container) {
this.container.style.position = '';
this.container.style.left = '';
this.container.style.top = '';
this.container.style.margin = '';
}
}
bindDocumentResizeListeners() {
if (!this.documentResizeListener) {
this.documentResizeListener = this.renderer.listen(this.document.defaultView, 'mousemove', (event) => {
this.onResize(event);
});
}
if (!this.documentResizeEndListener) {
this.documentResizeEndListener = this.renderer.listen(this.document.defaultView, 'mouseup', (event) => {
this.resizeEnd(event);
});
}
}
unbindDocumentResizeListeners() {
if (this.documentResizeListener) {
this.documentResizeListener();
this.documentResizeListener = null;
}
if (this.documentResizeEndListener) {
this.documentResizeEndListener();
this.documentResizeEndListener = null;
}
}
initResize(event) {
this.resizing = true;
this.lastPageX = event.pageX;
this.lastPageY = event.pageY;
this.dialogRef.resizeInit(event);
}
onResize(event) {
if (this.resizing) {
this.lastPageX = event.pageX;
this.lastPageY = event.pageY;
}
}
resizeEnd(event) {
if (this.resizing) {
this.resizing = false;
this.dialogRef.resizeEnd(event);
}
}
maximize() {
this.maximized = !this.maximized;
this.dialogRef.maximize({ maximized: this.maximized });
}
enableModality() {
if (this.ddconfig.dismissableMask && this.wrapper) {
this.maskClickListener = this.renderer.listen(this.wrapper, 'mousedown', (event) => {
if (this.wrapper && this.wrapper.isSameNode(event.target)) {
this.hide();
}
});
}
}
disableModality() {
this.unbindMaskClickListener();
this.cd.detectChanges();
}
unbindMaskClickListener() {
if (this.maskClickListener) {
this.maskClickListener();
this.maskClickListener = null;
}
}
bindDocumentEscapeListener() {
if (this.ddconfig.closeOnEscape) {
this.documentEscapeListener = this.renderer.listen(this.document, 'keydown', (event) => {
if (event.key === 'Escape' && this.container) {
this.hide();
}
});
}
}
unbindDocumentEscapeListener() {
if (this.documentEscapeListener) {
this.documentEscapeListener();
this.documentEscapeListener = null;
}
}
onDestroy() {
this.onContainerDestroy();
if (this.componentRef && typeof this.componentRef.destroy === 'function') {
this.componentRef.destroy();
}
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DynamicDialog, deps: [], target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.0.6", type: DynamicDialog, isStandalone: true, selector: "p-dynamicdialog, p-dynamic-dialog", providers: [DynamicDialogStyle, { provide: DYNAMIC_DIALOG_INSTANCE, useExisting: DynamicDialog }, { provide: PARENT_INSTANCE, useExisting: DynamicDialog }], viewQueries: [{ propertyName: "insertionPoint", first: true, predicate: DynamicDialogContent, descendants: true, isSignal: true }, { propertyName: "dialog", first: true, predicate: Dialog, descendants: true, isSignal: true }], usesInheritance: true, hostDirectives: [{ directive: i1.Bind }], ngImport: i0, template: `
<p-dialog
[visible]="visible()"
[header]="header"
[draggable]="draggable"
[resizable]="resizable"
[contentStyle]="contentStyle"
[modal]="modal"
[closeOnEscape]="closeOnEscape"
[dismissableMask]="dismissableMask"
[rtl]="rtl"
[closable]="closable"
[breakpoints]="breakpoints"
[styleClass]="styleClass"
[maskStyleClass]="maskStyleClass"
[showHeader]="showHeader"
[autoZIndex]="autoZIndex"
[baseZIndex]="baseZIndex"
[minX]="minX"
[minY]="minY"
[focusOnShow]="focusOnShow"
[maximizable]="maximizable"
[keepInViewport]="keepInViewport"
[focusTrap]="focusTrap"
[motionOptions]="motionOptions"
[maskMotionOptions]="maskMotionOptions"
[closeAriaLabel]="closeAriaLabel"
[minimizeIcon]="minimizeIcon"
[maximizeIcon]="maximizeIcon"
[closeButtonProps]="closeButtonProps"
[maximizeButtonProps]="maximizeButtonProps"
[style]="dialogStyle"
[position]="position"
(onHide)="onDialogHide()"
(onMaximize)="onDialogMaximize($event)"
(onResizeInit)="onDialogResizeInit($event)"
(onResizeEnd)="onDialogResizeEnd($event)"
(onDragStart)="onDialogDragStart($event)"
(onDragEnd)="onDialogDragEnd($event)"
(visibleChange)="onVisibleChange($event)"
[pt]="ddconfig.pt"
appendTo="self"
hostName="DynamicDialog"
[unstyled]="isUnstyled"
>
(headerTemplate) {
<ng-template #header>
<ng-container *ngComponentOutlet="headerTemplate"></ng-container>
</ng-template>
}
(contentTemplate) {
<ng-template #content>
<ng-container *ngComponentOutlet="contentTemplate"></ng-container>
</ng-template>
}
(footerTemplate) {
<ng-template #footer>
<ng-container *ngComponentOutlet="footerTemplate"></ng-container>
</ng-template>
}
(closeIconTemplate) {
<ng-template #closeicon>
<ng-container *ngComponentOutlet="closeIconTemplate"></ng-container>
</ng-template>
}
(maximizeIconTemplate) {
<ng-template #maximizeicon>
<ng-container *ngComponentOutlet="maximizeIconTemplate"></ng-container>
</ng-template>
}
(minimizeIconTemplate) {
<ng-template #minimizeicon>
<ng-container *ngComponentOutlet="minimizeIconTemplate"></ng-container>
</ng-template>
}
(!contentTemplate) {
<ng-template pDynamicDialogContent></ng-template>
}
(ddconfig.footer && !footerTemplate) {
<div>{{ ddconfig.footer }}</div>
}
</p-dialog>
`, isInline: true, dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletEnvironmentInjector", "ngComponentOutletContent", "ngComponentOutletNgModule"], exportAs: ["ngComponentOutlet"] }, { kind: "ngmodule", type: SharedModule }, { kind: "directive", type: DynamicDialogContent, selector: "[pDynamicDialogContent]" }, { kind: "component", type: Dialog, selector: "p-dialog", inputs: ["hostName", "header", "draggable", "resizable", "contentStyle", "contentStyleClass", "modal", "closeOnEscape", "dismissableMask", "rtl", "closable", "breakpoints", "styleClass", "maskStyleClass", "maskStyle", "showHeader", "blockScroll", "autoZIndex", "baseZIndex", "minX", "minY", "focusOnShow", "maximizable", "keepInViewport", "focusTrap", "maskMotionOptions", "motionOptions", "closeIcon", "closeAriaLabel", "closeTabindex", "minimizeIcon", "maximizeIcon", "closeButtonProps", "maximizeButtonProps", "visible", "style", "position", "role", "appendTo"], outputs: ["visibleChange", "onShow", "onHide", "onResizeInit", "onResizeEnd", "onDragStart", "onDragEnd", "onMaximize"] }, { kind: "ngmodule", type: BindModule }], changeDetection: i0.ChangeDetectionStrategy.Eager, encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DynamicDialog, decorators: [{
type: Component,
args: [{
selector: 'p-dynamicdialog, p-dynamic-dialog',
standalone: true,
imports: [NgComponentOutlet, SharedModule, DynamicDialogContent, Dialog, BindModule],
template: `
<p-dialog
[visible]="visible()"
[header]="header"
[draggable]="draggable"
[resizable]="resizable"
[contentStyle]="contentStyle"
[modal]="modal"
[closeOnEscape]="closeOnEscape"
[dismissableMask]="dismissableMask"
[rtl]="rtl"
[closable]="closable"
[breakpoints]="breakpoints"
[styleClass]="styleClass"
[maskStyleClass]="maskStyleClass"
[showHeader]="showHeader"
[autoZIndex]="autoZIndex"
[baseZIndex]="baseZIndex"
[minX]="minX"
[minY]="minY"
[focusOnShow]="focusOnShow"
[maximizable]="maximizable"
[keepInViewport]="keepInViewport"
[focusTrap]="focusTrap"
[motionOptions]="motionOptions"
[maskMotionOptions]="maskMotionOptions"
[closeAriaLabel]="closeAriaLabel"
[minimizeIcon]="minimizeIcon"
[maximizeIcon]="maximizeIcon"
[closeButtonProps]="closeButtonProps"
[maximizeButtonProps]="maximizeButtonProps"
[style]="dialogStyle"
[position]="position"
(onHide)="onDialogHide()"
(onMaximize)="onDialogMaximize($event)"
(onResizeInit)="onDialogResizeInit($event)"
(onResizeEnd)="onDialogResizeEnd($event)"
(onDragStart)="onDialogDragStart($event)"
(onDragEnd)="onDialogDragEnd($event)"
(visibleChange)="onVisibleChange($event)"
[pt]="ddconfig.pt"
appendTo="self"
hostName="DynamicDialog"
[unstyled]="isUnstyled"
>
(headerTemplate) {
<ng-template #header>
<ng-container *ngComponentOutlet="headerTemplate"></ng-container>
</ng-template>
}
(contentTemplate) {
<ng-template #content>
<ng-container *ngComponentOutlet="contentTemplate"></ng-container>
</ng-template>
}
(footerTemplate) {
<ng-template #footer>
<ng-container *ngComponentOutlet="footerTemplate"></ng-container>
</ng-template>
}
(closeIconTemplate) {
<ng-template #closeicon>
<ng-container *ngComponentOutlet="closeIconTemplate"></ng-container>
</ng-template>
}
(maximizeIconTemplate) {
<ng-template #maximizeicon>
<ng-container *ngComponentOutlet="maximizeIconTemplate"></ng-container>
</ng-template>
}
(minimizeIconTemplate) {
<ng-template #minimizeicon>
<ng-container *ngComponentOutlet="minimizeIconTemplate"></ng-container>
</ng-template>
}
(!contentTemplate) {
<ng-template pDynamicDialogContent></ng-template>
}
(ddconfig.footer && !footerTemplate) {
<div>{{ ddconfig.footer }}</div>
}
</p-dialog>
`,
changeDetection: ChangeDetectionStrategy.Default,
encapsulation: ViewEncapsulation.None,
providers: [DynamicDialogStyle, { provide: DYNAMIC_DIALOG_INSTANCE, useExisting: DynamicDialog }, { provide: PARENT_INSTANCE, useExisting: DynamicDialog }],
hostDirectives: [Bind]
}]
}], ctorParameters: () => [], propDecorators: { insertionPoint: [{ type: i0.ViewChild, args: [i0.forwardRef(() => DynamicDialogContent), { isSignal: true }] }], dialog: [{ type: i0.ViewChild, args: [i0.forwardRef(() => Dialog), { isSignal: true }] }] } });
class DynamicDialogModule {
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DynamicDialogModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.0.6", ngImport: i0, type: DynamicDialogModule, imports: [DynamicDialog, SharedModule], exports: [DynamicDialog, SharedModule] });
static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DynamicDialogModule, imports: [DynamicDialog, SharedModule, SharedModule] });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DynamicDialogModule, decorators: [{
type: NgModule,
args: [{
imports: [DynamicDialog, SharedModule],
exports: [DynamicDialog, SharedModule]
}]
}] });
class DynamicDialogInjector {
_parentInjector;
_additionalTokens;
constructor(_parentInjector, _additionalTokens) {
this._parentInjector = _parentInjector;
this._additionalTokens = _additionalTokens;
}
get(token, notFoundValue, options) {
const value = this._additionalTokens.get(token);
if (value)
return value;
return this._parentInjector.get(token, notFoundValue);
}
}
/**
* Dynamic Dialog component methods.
* @group Service
*/
class DialogService {
appRef;
injector;
document;
dialogComponentRefMap = new Map();
constructor(appRef, injector, document) {
this.appRef = appRef;
this.injector = injector;
this.document = document;
}
/**
* Displays the dialog using the dynamic dialog object options.
* @param {*} componentType - Dynamic component for content template.
* @param {DynamicDialogConfig} config - DynamicDialog object.
* @returns {DynamicDialogRef} DynamicDialog instance.
* @group Method
*/
open(componentType, config) {
if (!this.duplicationPermission(componentType, config)) {
return null;
}
const dialogRef = this.appendDialogComponentToBody(config);
const componentRefInstance = this.dialogComponentRefMap.get(dialogRef);
if (componentRefInstance) {
componentRefInstance.instance.childComponentType = componentType;
componentRefInstance.instance.inputValues = config.inputValues || {};
}
return dialogRef;
}
/**
* Returns the dynamic dialog component instance.
* @param {DynamicDialogRef} ref - DynamicDialog instance.
* @group Method
*/
getInstance(ref) {
return this.dialogComponentRefMap.get(ref)?.instance;
}
appendDialogComponentToBody(config) {
const map = new WeakMap();
map.set(DynamicDialogConfig, config);
const dialogRef = new DynamicDialogRef();
map.set(DynamicDialogRef, dialogRef);
const sub = dialogRef.onClose.subscribe(() => {
this.dialogComponentRefMap.get(dialogRef)?.instance.close();
});
const destroySub = dialogRef.onDestroy.subscribe(() => {
this.removeDialogComponentFromBody(dialogRef);
destroySub.unsubscribe();
sub.unsubscribe();
});
const componentRef = createComponent(DynamicDialog, {
environmentInjector: this.appRef.injector,
elementInjector: new DynamicDialogInjector(this.injector, map)
});
this.appRef.attachView(componentRef.hostView);
const domElem = componentRef.hostView.rootNodes[0];
if (!config.appendTo || config.appendTo === 'body') {
this.document.body.appendChild(domElem);
}
else {
appendChild(config.appendTo, domElem);
}
this.dialogComponentRefMap.set(dialogRef, componentRef);
return dialogRef;
}
removeDialogComponentFromBody(dialogRef) {
if (!dialogRef || !this.dialogComponentRefMap.has(dialogRef)) {
return;
}
const dialogComponentRef = this.dialogComponentRefMap.get(dialogRef);
if (dialogComponentRef) {
this.appRef.detachView(dialogComponentRef.hostView);
dialogComponentRef.destroy();
dialogComponentRef.changeDetectorRef.detectChanges();
}
this.dialogComponentRefMap.delete(dialogRef);
}
duplicationPermission(componentType, config) {
if (config.duplicate) {
return true;
}
let permission = true;
for (const [, value] of this.dialogComponentRefMap) {
if (value.instance.childComponentType === componentType) {
permission = false;
break;
}
}
return permission;
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DialogService, deps: [{ token: i0.ApplicationRef }, { token: i0.Injector }, { token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DialogService });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.0.6", ngImport: i0, type: DialogService, decorators: [{
type: Injectable
}], ctorParameters: () => [{ type: i0.ApplicationRef }, { type: i0.Injector }, { type: Document, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }] });
/**
* Generated bundle index. Do not edit.
*/
export { DialogService, DynamicDialog, DynamicDialogClasses, DynamicDialogConfig, DynamicDialogInjector, DynamicDialogModule, DynamicDialogRef, DynamicDialogStyle };
//# sourceMappingURL=primeng-dynamicdialog.mjs.map