primeng
Version:
PrimeNG is an open source UI library for Angular featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeB
1,293 lines (1,267 loc) • 60.7 kB
JavaScript
import { animation, style, animate, trigger, transition, useAnimation } from '@angular/animations';
import * as i1 from '@angular/common';
import { isPlatformBrowser, CommonModule } from '@angular/common';
import * as i0 from '@angular/core';
import { Injectable, EventEmitter, inject, NgZone, booleanAttribute, numberAttribute, ContentChildren, ContentChild, Input, ViewChild, Output, ViewEncapsulation, ChangeDetectionStrategy, Component, NgModule } from '@angular/core';
import { uuid, blockBodyScroll, unblockBodyScroll, setAttribute, hasClass, addClass, getOuterWidth, getOuterHeight, getViewport, removeClass, appendChild } from '@primeuix/utils';
import { TranslationKeys, SharedModule, PrimeTemplate } from 'primeng/api';
import { BaseComponent } from 'primeng/basecomponent';
import { Button } from 'primeng/button';
import { DomHandler } from 'primeng/dom';
import { FocusTrap } from 'primeng/focustrap';
import { TimesIcon, WindowMaximizeIcon, WindowMinimizeIcon } from 'primeng/icons';
import { ZIndexUtils } from 'primeng/utils';
import { BaseStyle } from 'primeng/base';
const theme = ({ dt }) => `
.p-dialog {
max-height: 90%;
transform: scale(1);
border-radius: ${dt('dialog.border.radius')};
box-shadow: ${dt('dialog.shadow')};
background: ${dt('dialog.background')};
border: 1px solid ${dt('dialog.border.color')};
color: ${dt('dialog.color')};
display: flex;
flex-direction: column;
pointer-events: auto
}
.p-dialog-content {
overflow-y: auto;
padding: ${dt('dialog.content.padding')};
flex-grow: 1;
}
.p-dialog-header {
display: flex;
align-items: center;
justify-content: space-between;
flex-shrink: 0;
padding: ${dt('dialog.header.padding')};
}
.p-dialog-title {
font-weight: ${dt('dialog.title.font.weight')};
font-size: ${dt('dialog.title.font.size')};
}
.p-dialog-footer {
flex-shrink: 0;
padding: ${dt('dialog.footer.padding')};
display: flex;
justify-content: flex-end;
gap: ${dt('dialog.footer.gap')};
}
.p-dialog-header-actions {
display: flex;
align-items: center;
gap: ${dt('dialog.header.gap')};
}
.p-dialog-enter-active {
transition: all 150ms cubic-bezier(0, 0, 0.2, 1);
}
.p-dialog-leave-active {
transition: all 150ms cubic-bezier(0.4, 0, 0.2, 1);
}
.p-dialog-enter-from,
.p-dialog-leave-to {
opacity: 0;
transform: scale(0.7);
}
.p-dialog-top .p-dialog,
.p-dialog-bottom .p-dialog,
.p-dialog-left .p-dialog,
.p-dialog-right .p-dialog,
.p-dialog-topleft .p-dialog,
.p-dialog-topright .p-dialog,
.p-dialog-bottomleft .p-dialog,
.p-dialog-bottomright .p-dialog {
margin: 0.75rem;
transform: translate3d(0px, 0px, 0px);
}
.p-dialog-top .p-dialog-enter-active,
.p-dialog-top .p-dialog-leave-active,
.p-dialog-bottom .p-dialog-enter-active,
.p-dialog-bottom .p-dialog-leave-active,
.p-dialog-left .p-dialog-enter-active,
.p-dialog-left .p-dialog-leave-active,
.p-dialog-right .p-dialog-enter-active,
.p-dialog-right .p-dialog-leave-active,
.p-dialog-topleft .p-dialog-enter-active,
.p-dialog-topleft .p-dialog-leave-active,
.p-dialog-topright .p-dialog-enter-active,
.p-dialog-topright .p-dialog-leave-active,
.p-dialog-bottomleft .p-dialog-enter-active,
.p-dialog-bottomleft .p-dialog-leave-active,
.p-dialog-bottomright .p-dialog-enter-active,
.p-dialog-bottomright .p-dialog-leave-active {
transition: all 0.3s ease-out;
}
.p-dialog-top .p-dialog-enter-from,
.p-dialog-top .p-dialog-leave-to {
transform: translate3d(0px, -100%, 0px);
}
.p-dialog-bottom .p-dialog-enter-from,
.p-dialog-bottom .p-dialog-leave-to {
transform: translate3d(0px, 100%, 0px);
}
.p-dialog-left .p-dialog-enter-from,
.p-dialog-left .p-dialog-leave-to,
.p-dialog-topleft .p-dialog-enter-from,
.p-dialog-topleft .p-dialog-leave-to,
.p-dialog-bottomleft .p-dialog-enter-from,
.p-dialog-bottomleft .p-dialog-leave-to {
transform: translate3d(-100%, 0px, 0px);
}
.p-dialog-right .p-dialog-enter-from,
.p-dialog-right .p-dialog-leave-to,
.p-dialog-topright .p-dialog-enter-from,
.p-dialog-topright .p-dialog-leave-to,
.p-dialog-bottomright .p-dialog-enter-from,
.p-dialog-bottomright .p-dialog-leave-to {
transform: translate3d(100%, 0px, 0px);
}
.p-dialog-left:dir(rtl) .p-dialog-enter-from,
.p-dialog-left:dir(rtl) .p-dialog-leave-to,
.p-dialog-topleft:dir(rtl) .p-dialog-enter-from,
.p-dialog-topleft:dir(rtl) .p-dialog-leave-to,
.p-dialog-bottomleft:dir(rtl) .p-dialog-enter-from,
.p-dialog-bottomleft:dir(rtl) .p-dialog-leave-to {
transform: translate3d(100%, 0px, 0px);
}
.p-dialog-right:dir(rtl) .p-dialog-enter-from,
.p-dialog-right:dir(rtl) .p-dialog-leave-to,
.p-dialog-topright:dir(rtl) .p-dialog-enter-from,
.p-dialog-topright:dir(rtl) .p-dialog-leave-to,
.p-dialog-bottomright:dir(rtl) .p-dialog-enter-from,
.p-dialog-bottomright:dir(rtl) .p-dialog-leave-to {
transform: translate3d(-100%, 0px, 0px);
}
.p-dialog-maximized {
width: 100vw !important;
height: 100vh !important;
top: 0px !important;
left: 0px !important;
max-height: 100%;
height: 100%;
border-radius: 0;
}
.p-dialog-maximized .p-dialog-content {
flex-grow: 1;
}
.p-overlay-mask:dir(rtl) {
flex-direction: row-reverse;
}
/* For PrimeNG */
.p-dialog .p-resizable-handle {
position: absolute;
font-size: 0.1px;
display: block;
cursor: se-resize;
width: 12px;
height: 12px;
right: 1px;
bottom: 1px;
}
.p-confirm-dialog .p-dialog-content {
display: flex;
align-items: center;
}
`;
/* Position */
const inlineStyles = {
mask: ({ instance }) => ({
position: 'fixed',
height: '100%',
width: '100%',
left: 0,
top: 0,
display: 'flex',
justifyContent: instance.position === 'left' || instance.position === 'topleft' || instance.position === 'bottomleft'
? 'flex-start'
: instance.position === 'right' || instance.position === 'topright' || instance.position === 'bottomright'
? 'flex-end'
: 'center',
alignItems: instance.position === 'top' || instance.position === 'topleft' || instance.position === 'topright'
? 'flex-start'
: instance.position === 'bottom' || instance.position === 'bottomleft' || instance.position === 'bottomright'
? 'flex-end'
: 'center',
pointerEvents: instance.modal ? 'auto' : 'none'
}),
root: {
display: 'flex',
flexDirection: 'column',
pointerEvents: 'auto'
}
};
const classes = {
mask: ({ instance }) => {
const positions = ['left', 'right', 'top', 'topleft', 'topright', 'bottom', 'bottomleft', 'bottomright'];
const pos = positions.find((item) => item === instance.position);
return {
'p-dialog-mask': true,
'p-overlay-mask p-overlay-mask-enter': instance.modal,
[`p-dialog-${pos}`]: pos
};
},
root: ({ instance }) => ({ 'p-dialog p-component': true, 'p-dialog-maximized': instance.maximizable && instance.maximized }),
header: 'p-dialog-header',
title: 'p-dialog-title',
resizeHandle: 'p-resizable-handle',
headerActions: 'p-dialog-header-actions',
pcMaximizeButton: 'p-dialog-maximize-button',
pcCloseButton: 'p-dialog-close-button',
content: 'p-dialog-content',
footer: 'p-dialog-footer'
};
class DialogStyle extends BaseStyle {
name = 'dialog';
theme = theme;
classes = classes;
inlineStyles = inlineStyles;
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: DialogStyle, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: DialogStyle });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: DialogStyle, decorators: [{
type: Injectable
}] });
/**
*
* Dialog is a container to display content in an overlay window.
*
* [Live Demo](https://www.primeng.org/dialog)
*
* @module dialogstyle
*
*/
var DialogClasses;
(function (DialogClasses) {
/**
* Class name of the mask element
*/
DialogClasses["mask"] = "p-dialog-mask";
/**
* Class name of the root element
*/
DialogClasses["root"] = "p-dialog";
/**
* Class name of the header element
*/
DialogClasses["header"] = "p-dialog-header";
/**
* Class name of the title element
*/
DialogClasses["title"] = "p-dialog-title";
/**
* Class name of the header actions element
*/
DialogClasses["headerActions"] = "p-dialog-header-actions";
/**
* Class name of the maximize button element
*/
DialogClasses["pcMaximizeButton"] = "p-dialog-maximize-button";
/**
* Class name of the close button element
*/
DialogClasses["pcCloseButton"] = "p-dialog-close-button";
/**
* Class name of the content element
*/
DialogClasses["content"] = "p-dialog-content";
/**
* Class name of the footer element
*/
DialogClasses["footer"] = "p-dialog-footer";
})(DialogClasses || (DialogClasses = {}));
const showAnimation = animation([style({ transform: '{{transform}}', opacity: 0 }), animate('{{transition}}')]);
const hideAnimation = animation([animate('{{transition}}', style({ transform: '{{transform}}', opacity: 0 }))]);
/**
* Dialog is a container to display content in an overlay window.
* @group Components
*/
class Dialog extends BaseComponent {
/**
* Title text of the dialog.
* @group Props
*/
header;
/**
* Enables dragging to change the position using header.
* @group Props
*/
draggable = true;
/**
* Enables resizing of the content.
* @group Props
*/
resizable = true;
/**
* Defines the left offset of dialog.
* @group Props
* @deprecated positionLeft property is deprecated.
*/
get positionLeft() {
return 0;
}
set positionLeft(_positionLeft) {
console.log('positionLeft property is deprecated.');
}
/**
* Defines the top offset of dialog.
* @group Props
* @deprecated positionTop property is deprecated.
*/
get positionTop() {
return 0;
}
set positionTop(_positionTop) {
console.log('positionTop property is deprecated.');
}
/**
* Style of the content section.
* @group Props
*/
contentStyle;
/**
* Style class of the content.
* @group Props
*/
contentStyleClass;
/**
* Defines if background should be blocked when dialog is displayed.
* @group Props
*/
modal = false;
/**
* Specifies if pressing escape key should hide the dialog.
* @group Props
*/
closeOnEscape = true;
/**
* Specifies if clicking the modal background should hide the dialog.
* @group Props
*/
dismissableMask = false;
/**
* When enabled dialog is displayed in RTL direction.
* @group Props
*/
rtl = false;
/**
* Adds a close icon to the header to hide the dialog.
* @group Props
*/
closable = true;
/**
* Defines if the component is responsive.
* @group Props
* @deprecated Responsive property is deprecated.
*/
get responsive() {
return false;
}
set responsive(_responsive) {
console.log('Responsive property is deprecated.');
}
/**
* Target element to attach the dialog, 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;
/**
* Object literal to define widths per screen size.
* @group Props
*/
breakpoints;
/**
* Style class of the component.
* @group Props
*/
styleClass;
/**
* Style class of the mask.
* @group Props
*/
maskStyleClass;
/**
* Style of the mask.
* @group Props
*/
maskStyle;
/**
* Whether to show the header or not.
* @group Props
*/
showHeader = true;
/**
* Defines the breakpoint of the component responsive.
* @group Props
* @deprecated Breakpoint property is not utilized and deprecated. Use breakpoints or CSS media queries instead.
*/
get breakpoint() {
return 649;
}
set breakpoint(_breakpoint) {
console.log('Breakpoint property is not utilized and deprecated, use breakpoints or CSS media queries instead.');
}
/**
* Whether background scroll should be blocked when dialog is visible.
* @group Props
*/
blockScroll = false;
/**
* Whether to automatically manage layering.
* @group Props
*/
autoZIndex = true;
/**
* Base zIndex value to use in layering.
* @group Props
*/
baseZIndex = 0;
/**
* Minimum value for the left coordinate of dialog in dragging.
* @group Props
*/
minX = 0;
/**
* Minimum value for the top coordinate of dialog in dragging.
* @group Props
*/
minY = 0;
/**
* When enabled, first focusable element receives focus on show.
* @group Props
*/
focusOnShow = true;
/**
* Whether the dialog can be displayed full screen.
* @group Props
*/
maximizable = false;
/**
* Keeps dialog in the viewport.
* @group Props
*/
keepInViewport = true;
/**
* When enabled, can only focus on elements inside the dialog.
* @group Props
*/
focusTrap = true;
/**
* Transition options of the animation.
* @group Props
*/
transitionOptions = '150ms cubic-bezier(0, 0, 0.2, 1)';
/**
* Name of the close icon.
* @group Props
*/
closeIcon;
/**
* Defines a string that labels the close button for accessibility.
* @group Props
*/
closeAriaLabel;
/**
* Index of the close button in tabbing order.
* @group Props
*/
closeTabindex = '0';
/**
* Name of the minimize icon.
* @group Props
*/
minimizeIcon;
/**
* Name of the maximize icon.
* @group Props
*/
maximizeIcon;
/**
* Used to pass all properties of the ButtonProps to the Button component.
* @group Props
*/
closeButtonProps = {
severity: 'secondary',
text: true,
rounded: true
};
/**
* Used to pass all properties of the ButtonProps to the Button component.
* @group Props
*/
maximizeButtonProps = {
severity: 'secondary',
text: true,
rounded: true
};
/**
* Specifies the visibility of the dialog.
* @group Props
*/
get visible() {
return this._visible;
}
set visible(value) {
this._visible = value;
if (this._visible && !this.maskVisible) {
this.maskVisible = true;
}
}
/**
* Inline style of the component.
* @group Props
*/
get style() {
return this._style;
}
set style(value) {
if (value) {
this._style = { ...value };
this.originalStyle = value;
}
}
/**
* Position of the dialog.
* @group Props
*/
get position() {
return this._position;
}
set position(value) {
this._position = value;
switch (value) {
case 'topleft':
case 'bottomleft':
case 'left':
this.transformOptions = 'translate3d(-100%, 0px, 0px)';
break;
case 'topright':
case 'bottomright':
case 'right':
this.transformOptions = 'translate3d(100%, 0px, 0px)';
break;
case 'bottom':
this.transformOptions = 'translate3d(0px, 100%, 0px)';
break;
case 'top':
this.transformOptions = 'translate3d(0px, -100%, 0px)';
break;
default:
this.transformOptions = 'scale(0.7)';
break;
}
}
/**
* Role attribute of html element.
* @group Emits
*/
role = 'dialog';
/**
* Callback to invoke when dialog is shown.
* @group Emits
*/
onShow = new EventEmitter();
/**
* Callback to invoke when dialog is hidden.
* @group Emits
*/
onHide = new EventEmitter();
/**
* This EventEmitter is used to notify changes in the visibility state of a component.
* @param {boolean} value - New value.
* @group Emits
*/
visibleChange = new EventEmitter();
/**
* Callback to invoke when dialog resizing is initiated.
* @param {MouseEvent} event - Mouse event.
* @group Emits
*/
onResizeInit = new EventEmitter();
/**
* Callback to invoke when dialog resizing is completed.
* @param {MouseEvent} event - Mouse event.
* @group Emits
*/
onResizeEnd = new EventEmitter();
/**
* Callback to invoke when dialog dragging is completed.
* @param {DragEvent} event - Drag event.
* @group Emits
*/
onDragEnd = new EventEmitter();
/**
* Callback to invoke when dialog maximized or unmaximized.
* @group Emits
*/
onMaximize = new EventEmitter();
headerViewChild;
contentViewChild;
footerViewChild;
/**
* Header template.
* @group Props
*/
headerTemplate;
/**
* Content template.
* @group Props
*/
contentTemplate;
/**
* Footer template.
* @group Props
*/
footerTemplate;
/**
* Close icon template.
* @group Props
*/
closeIconTemplate;
/**
* Maximize icon template.
* @group Props
*/
maximizeIconTemplate;
/**
* Minimize icon template.
* @group Props
*/
minimizeIconTemplate;
/**
* Headless template.
* @group Props
*/
headlessTemplate;
_headerTemplate;
_contentTemplate;
_footerTemplate;
_closeiconTemplate;
_maximizeiconTemplate;
_minimizeiconTemplate;
_headlessTemplate;
_visible = false;
maskVisible;
container;
wrapper;
dragging;
ariaLabelledBy = this.getAriaLabelledBy();
documentDragListener;
documentDragEndListener;
resizing;
documentResizeListener;
documentResizeEndListener;
documentEscapeListener;
maskClickListener;
lastPageX;
lastPageY;
preventVisibleChangePropagation;
maximized;
preMaximizeContentHeight;
preMaximizeContainerWidth;
preMaximizeContainerHeight;
preMaximizePageX;
preMaximizePageY;
id = uuid('pn_id_');
_style = {};
_position = 'center';
originalStyle;
transformOptions = 'scale(0.7)';
styleElement;
window;
_componentStyle = inject(DialogStyle);
headerT;
contentT;
footerT;
closeIconT;
maximizeIconT;
minimizeIconT;
headlessT;
get maximizeLabel() {
return this.config.getTranslation(TranslationKeys.ARIA)['maximizeLabel'];
}
zone = inject(NgZone);
get maskClass() {
const positions = ['left', 'right', 'top', 'topleft', 'topright', 'bottom', 'bottomleft', 'bottomright'];
const pos = positions.find((item) => item === this.position);
return {
'p-dialog-mask': true,
'p-overlay-mask p-overlay-mask-enter': this.modal || this.dismissableMask,
[`p-dialog-${pos}`]: pos
};
}
ngOnInit() {
super.ngOnInit();
if (this.breakpoints) {
this.createStyle();
}
}
templates;
ngAfterContentInit() {
this.templates?.forEach((item) => {
switch (item.getType()) {
case 'header':
this.headerT = item.template;
break;
case 'content':
this.contentT = item.template;
break;
case 'footer':
this.footerT = item.template;
break;
case 'closeicon':
this.closeIconT = item.template;
break;
case 'maximizeicon':
this.maximizeIconT = item.template;
break;
case 'minimizeicon':
this.minimizeIconT = item.template;
break;
case 'headless':
this.headlessT = item.template;
break;
default:
this.contentT = item.template;
break;
}
});
}
getAriaLabelledBy() {
return this.header !== null ? uuid('pn_id_') + '_header' : null;
}
parseDurationToMilliseconds(durationString) {
const transitionTimeRegex = /([\d\.]+)(ms|s)\b/g;
let totalMilliseconds = 0;
let match;
while ((match = transitionTimeRegex.exec(durationString)) !== null) {
const value = parseFloat(match[1]);
const unit = match[2];
if (unit === 'ms') {
totalMilliseconds += value;
}
else if (unit === 's') {
totalMilliseconds += value * 1000;
}
}
if (totalMilliseconds === 0) {
return undefined;
}
return totalMilliseconds;
}
_focus(focusParentElement) {
if (focusParentElement) {
const timeoutDuration = this.parseDurationToMilliseconds(this.transitionOptions);
let _focusableElements = DomHandler.getFocusableElements(focusParentElement);
if (_focusableElements && _focusableElements.length > 0) {
this.zone.runOutsideAngular(() => {
setTimeout(() => _focusableElements[0].focus(), timeoutDuration || 5);
});
return true;
}
}
return false;
}
focus(focusParentElement) {
let focused = this._focus(focusParentElement);
if (!focused) {
focused = this._focus(this.footerViewChild?.nativeElement);
if (!focused) {
focused = this._focus(this.headerViewChild?.nativeElement);
if (!focused) {
this._focus(this.contentViewChild?.nativeElement);
}
}
}
}
close(event) {
this.visibleChange.emit(false);
event.preventDefault();
}
enableModality() {
if (this.closable && this.dismissableMask) {
this.maskClickListener = this.renderer.listen(this.wrapper, 'mousedown', (event) => {
if (this.wrapper && this.wrapper.isSameNode(event.target)) {
this.close(event);
}
});
}
if (this.modal) {
blockBodyScroll();
}
}
disableModality() {
if (this.wrapper) {
if (this.dismissableMask) {
this.unbindMaskClickListener();
}
// for nested dialogs w/modal
const scrollBlockers = document.querySelectorAll('.p-dialog-mask-scrollblocker');
if (this.modal && scrollBlockers && scrollBlockers.length == 1) {
unblockBodyScroll();
}
if (!this.cd.destroyed) {
this.cd.detectChanges();
}
}
}
maximize() {
this.maximized = !this.maximized;
if (!this.modal && !this.blockScroll) {
if (this.maximized) {
blockBodyScroll();
}
else {
unblockBodyScroll();
}
}
this.onMaximize.emit({ maximized: this.maximized });
}
unbindMaskClickListener() {
if (this.maskClickListener) {
this.maskClickListener();
this.maskClickListener = null;
}
}
moveOnTop() {
if (this.autoZIndex) {
ZIndexUtils.set('modal', this.container, this.baseZIndex + this.config.zIndex.modal);
this.wrapper.style.zIndex = String(parseInt(this.container.style.zIndex, 10) - 1);
}
}
createStyle() {
if (isPlatformBrowser(this.platformId)) {
if (!this.styleElement) {
this.styleElement = this.renderer.createElement('style');
this.styleElement.type = 'text/css';
this.renderer.appendChild(this.document.head, this.styleElement);
let innerHTML = '';
for (let breakpoint in this.breakpoints) {
innerHTML += `
@media screen and (max-width: ${breakpoint}) {
.p-dialog[${this.id}]:not(.p-dialog-maximized) {
width: ${this.breakpoints[breakpoint]} !important;
}
}
`;
}
this.renderer.setProperty(this.styleElement, 'innerHTML', innerHTML);
setAttribute(this.styleElement, 'nonce', this.config?.csp()?.nonce);
}
}
}
initDrag(event) {
if (hasClass(event.target, 'p-dialog-maximize-icon') || hasClass(event.target, 'p-dialog-header-close-icon') || hasClass(event.target.parentElement, 'p-dialog-header-icon')) {
return;
}
if (this.draggable) {
this.dragging = true;
this.lastPageX = event.pageX;
this.lastPageY = event.pageY;
this.container.style.margin = '0';
addClass(this.document.body, 'p-unselectable-text');
}
}
onDrag(event) {
if (this.dragging) {
const containerWidth = getOuterWidth(this.container);
const containerHeight = getOuterHeight(this.container);
const deltaX = event.pageX - this.lastPageX;
const deltaY = event.pageY - this.lastPageY;
const offset = this.container.getBoundingClientRect();
const containerComputedStyle = getComputedStyle(this.container);
const leftMargin = parseFloat(containerComputedStyle.marginLeft);
const topMargin = parseFloat(containerComputedStyle.marginTop);
const leftPos = offset.left + deltaX - leftMargin;
const topPos = offset.top + deltaY - topMargin;
const viewport = getViewport();
this.container.style.position = 'fixed';
if (this.keepInViewport) {
if (leftPos >= this.minX && leftPos + containerWidth < viewport.width) {
this._style.left = `${leftPos}px`;
this.lastPageX = event.pageX;
this.container.style.left = `${leftPos}px`;
}
if (topPos >= this.minY && topPos + containerHeight < viewport.height) {
this._style.top = `${topPos}px`;
this.lastPageY = event.pageY;
this.container.style.top = `${topPos}px`;
}
}
else {
this.lastPageX = event.pageX;
this.container.style.left = `${leftPos}px`;
this.lastPageY = event.pageY;
this.container.style.top = `${topPos}px`;
}
}
}
endDrag(event) {
if (this.dragging) {
this.dragging = false;
removeClass(this.document.body, 'p-unselectable-text');
this.cd.detectChanges();
this.onDragEnd.emit(event);
}
}
resetPosition() {
this.container.style.position = '';
this.container.style.left = '';
this.container.style.top = '';
this.container.style.margin = '';
}
//backward compatibility
center() {
this.resetPosition();
}
initResize(event) {
if (this.resizable) {
this.resizing = true;
this.lastPageX = event.pageX;
this.lastPageY = event.pageY;
addClass(this.document.body, 'p-unselectable-text');
this.onResizeInit.emit(event);
}
}
onResize(event) {
if (this.resizing) {
let deltaX = event.pageX - this.lastPageX;
let deltaY = event.pageY - this.lastPageY;
let containerWidth = getOuterWidth(this.container);
let containerHeight = getOuterHeight(this.container);
let contentHeight = getOuterHeight(this.contentViewChild?.nativeElement);
let newWidth = containerWidth + deltaX;
let newHeight = containerHeight + deltaY;
let minWidth = this.container.style.minWidth;
let minHeight = this.container.style.minHeight;
let offset = this.container.getBoundingClientRect();
let viewport = getViewport();
let hasBeenDragged = !parseInt(this.container.style.top) || !parseInt(this.container.style.left);
if (hasBeenDragged) {
newWidth += deltaX;
newHeight += deltaY;
}
if ((!minWidth || newWidth > parseInt(minWidth)) && offset.left + newWidth < viewport.width) {
this._style.width = newWidth + 'px';
this.container.style.width = this._style.width;
}
if ((!minHeight || newHeight > parseInt(minHeight)) && offset.top + newHeight < viewport.height) {
this.contentViewChild.nativeElement.style.height = contentHeight + newHeight - containerHeight + 'px';
if (this._style.height) {
this._style.height = newHeight + 'px';
this.container.style.height = this._style.height;
}
}
this.lastPageX = event.pageX;
this.lastPageY = event.pageY;
}
}
resizeEnd(event) {
if (this.resizing) {
this.resizing = false;
removeClass(this.document.body, 'p-unselectable-text');
this.onResizeEnd.emit(event);
}
}
bindGlobalListeners() {
if (this.draggable) {
this.bindDocumentDragListener();
this.bindDocumentDragEndListener();
}
if (this.resizable) {
this.bindDocumentResizeListeners();
}
if (this.closeOnEscape && this.closable) {
this.bindDocumentEscapeListener();
}
}
unbindGlobalListeners() {
this.unbindDocumentDragListener();
this.unbindDocumentDragEndListener();
this.unbindDocumentResizeListeners();
this.unbindDocumentEscapeListener();
}
bindDocumentDragListener() {
if (!this.documentDragListener) {
this.zone.runOutsideAngular(() => {
this.documentDragListener = this.renderer.listen(this.document.defaultView, 'mousemove', this.onDrag.bind(this));
});
}
}
unbindDocumentDragListener() {
if (this.documentDragListener) {
this.documentDragListener();
this.documentDragListener = null;
}
}
bindDocumentDragEndListener() {
if (!this.documentDragEndListener) {
this.zone.runOutsideAngular(() => {
this.documentDragEndListener = this.renderer.listen(this.document.defaultView, 'mouseup', this.endDrag.bind(this));
});
}
}
unbindDocumentDragEndListener() {
if (this.documentDragEndListener) {
this.documentDragEndListener();
this.documentDragEndListener = null;
}
}
bindDocumentResizeListeners() {
if (!this.documentResizeListener && !this.documentResizeEndListener) {
this.zone.runOutsideAngular(() => {
this.documentResizeListener = this.renderer.listen(this.document.defaultView, 'mousemove', this.onResize.bind(this));
this.documentResizeEndListener = this.renderer.listen(this.document.defaultView, 'mouseup', this.resizeEnd.bind(this));
});
}
}
unbindDocumentResizeListeners() {
if (this.documentResizeListener && this.documentResizeEndListener) {
this.documentResizeListener();
this.documentResizeEndListener();
this.documentResizeListener = null;
this.documentResizeEndListener = null;
}
}
bindDocumentEscapeListener() {
const documentTarget = this.el ? this.el.nativeElement.ownerDocument : 'document';
this.documentEscapeListener = this.renderer.listen(documentTarget, 'keydown', (event) => {
if (event.key == 'Escape') {
this.close(event);
}
});
}
unbindDocumentEscapeListener() {
if (this.documentEscapeListener) {
this.documentEscapeListener();
this.documentEscapeListener = null;
}
}
appendContainer() {
if (this.appendTo) {
if (this.appendTo === 'body')
this.renderer.appendChild(this.document.body, this.wrapper);
else
appendChild(this.appendTo, this.wrapper);
}
}
restoreAppend() {
if (this.container && this.appendTo) {
this.renderer.appendChild(this.el.nativeElement, this.wrapper);
}
}
onAnimationStart(event) {
switch (event.toState) {
case 'visible':
this.container = event.element;
this.wrapper = this.container?.parentElement;
this.appendContainer();
this.moveOnTop();
this.bindGlobalListeners();
this.container?.setAttribute(this.id, '');
if (this.modal) {
this.enableModality();
}
// if (!this.modal && this.blockScroll) {
// addClass(this.document.body, 'p-overflow-hidden');
// }
if (this.focusOnShow) {
this.focus();
}
break;
case 'void':
if (this.wrapper && this.modal) {
addClass(this.wrapper, 'p-overlay-mask-leave');
}
break;
}
}
onAnimationEnd(event) {
switch (event.toState) {
case 'void':
this.onContainerDestroy();
this.onHide.emit({});
this.cd.markForCheck();
if (this.maskVisible !== this.visible) {
this.maskVisible = this.visible;
}
break;
case 'visible':
this.onShow.emit({});
break;
}
}
onContainerDestroy() {
this.unbindGlobalListeners();
this.dragging = false;
this.maskVisible = false;
if (this.maximized) {
// removeClass(this.document.body, 'p-overflow-hidden')
this.document.body.style.removeProperty('--scrollbar;-width');
this.maximized = false;
}
if (this.modal) {
this.disableModality();
}
// if (this.blockScroll) {
// removeClass(this.document.body, 'p-overflow-hidden');
// }
if (hasClass(this.document.body, 'p-overflow-hidden')) {
removeClass(this.document.body, 'p-overflow-hidden');
}
if (this.container && this.autoZIndex) {
ZIndexUtils.clear(this.container);
}
this.container = null;
this.wrapper = null;
this._style = this.originalStyle ? { ...this.originalStyle } : {};
}
destroyStyle() {
if (this.styleElement) {
this.renderer.removeChild(this.document.head, this.styleElement);
this.styleElement = null;
}
}
ngOnDestroy() {
if (this.container) {
this.restoreAppend();
this.onContainerDestroy();
}
this.destroyStyle();
super.ngOnDestroy();
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: Dialog, deps: null, target: i0.ɵɵFactoryTarget.Component });
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "19.2.2", type: Dialog, isStandalone: true, selector: "p-dialog", inputs: { header: "header", draggable: ["draggable", "draggable", booleanAttribute], resizable: ["resizable", "resizable", booleanAttribute], positionLeft: "positionLeft", positionTop: "positionTop", contentStyle: "contentStyle", contentStyleClass: "contentStyleClass", modal: ["modal", "modal", booleanAttribute], closeOnEscape: ["closeOnEscape", "closeOnEscape", booleanAttribute], dismissableMask: ["dismissableMask", "dismissableMask", booleanAttribute], rtl: ["rtl", "rtl", booleanAttribute], closable: ["closable", "closable", booleanAttribute], responsive: "responsive", appendTo: "appendTo", breakpoints: "breakpoints", styleClass: "styleClass", maskStyleClass: "maskStyleClass", maskStyle: "maskStyle", showHeader: ["showHeader", "showHeader", booleanAttribute], breakpoint: "breakpoint", blockScroll: ["blockScroll", "blockScroll", booleanAttribute], autoZIndex: ["autoZIndex", "autoZIndex", booleanAttribute], baseZIndex: ["baseZIndex", "baseZIndex", numberAttribute], minX: ["minX", "minX", numberAttribute], minY: ["minY", "minY", numberAttribute], focusOnShow: ["focusOnShow", "focusOnShow", booleanAttribute], maximizable: ["maximizable", "maximizable", booleanAttribute], keepInViewport: ["keepInViewport", "keepInViewport", booleanAttribute], focusTrap: ["focusTrap", "focusTrap", booleanAttribute], transitionOptions: "transitionOptions", closeIcon: "closeIcon", closeAriaLabel: "closeAriaLabel", closeTabindex: "closeTabindex", minimizeIcon: "minimizeIcon", maximizeIcon: "maximizeIcon", closeButtonProps: "closeButtonProps", maximizeButtonProps: "maximizeButtonProps", visible: "visible", style: "style", position: "position", role: "role", headerTemplate: ["content", "headerTemplate"], contentTemplate: "contentTemplate", footerTemplate: "footerTemplate", closeIconTemplate: "closeIconTemplate", maximizeIconTemplate: "maximizeIconTemplate", minimizeIconTemplate: "minimizeIconTemplate", headlessTemplate: "headlessTemplate" }, outputs: { onShow: "onShow", onHide: "onHide", visibleChange: "visibleChange", onResizeInit: "onResizeInit", onResizeEnd: "onResizeEnd", onDragEnd: "onDragEnd", onMaximize: "onMaximize" }, providers: [DialogStyle], queries: [{ propertyName: "_headerTemplate", first: true, predicate: ["header"] }, { propertyName: "_contentTemplate", first: true, predicate: ["content"] }, { propertyName: "_footerTemplate", first: true, predicate: ["footer"] }, { propertyName: "_closeiconTemplate", first: true, predicate: ["closeicon"] }, { propertyName: "_maximizeiconTemplate", first: true, predicate: ["maximizeicon"] }, { propertyName: "_minimizeiconTemplate", first: true, predicate: ["minimizeicon"] }, { propertyName: "_headlessTemplate", first: true, predicate: ["headless"] }, { propertyName: "templates", predicate: PrimeTemplate }], viewQueries: [{ propertyName: "headerViewChild", first: true, predicate: ["titlebar"], descendants: true }, { propertyName: "contentViewChild", first: true, predicate: ["content"], descendants: true }, { propertyName: "footerViewChild", first: true, predicate: ["footer"], descendants: true }], usesInheritance: true, ngImport: i0, template: `
<div
*ngIf="maskVisible"
[ngClass]="maskClass"
[class]="maskStyleClass"
[ngStyle]="{
position: 'fixed',
height: '100%',
width: '100%',
left: 0,
top: 0,
display: 'flex',
'justify-content': position === 'left' || position === 'topleft' || position === 'bottomleft' ? 'flex-start' : position === 'right' || position === 'topright' || position === 'bottomright' ? 'flex-end' : 'center',
'align-items': position === 'top' || position === 'topleft' || position === 'topright' ? 'flex-start' : position === 'bottom' || position === 'bottomleft' || position === 'bottomright' ? 'flex-end' : 'center',
'pointer-events': modal ? 'auto' : 'none'
}"
[style]="maskStyle"
>
<div
*ngIf="visible"
#container
[class]="styleClass"
[ngClass]="{ 'p-dialog p-component': true, 'p-dialog-maximized': maximizable && maximized }"
[ngStyle]="{ display: 'flex', 'flex-direction': 'column', 'pointer-events': 'auto' }"
[style]="style"
pFocusTrap
[pFocusTrapDisabled]="focusTrap === false"
[@animation]="{
value: 'visible',
params: { transform: transformOptions, transition: transitionOptions }
}"
(@animation.start)="onAnimationStart($event)"
(@animation.done)="onAnimationEnd($event)"
[attr.role]="role"
[attr.aria-labelledby]="ariaLabelledBy"
[attr.aria-modal]="true"
>
<ng-container *ngIf="_headlessTemplate || headlessTemplate || headlessT; else notHeadless">
<ng-container *ngTemplateOutlet="_headlessTemplate || headlessTemplate || headlessT"></ng-container>
</ng-container>
<ng-template #notHeadless>
<div *ngIf="resizable" [ngClass]="cx('resizeHandle')" style="z-index: 90;" (mousedown)="initResize($event)"></div>
<div #titlebar [ngClass]="cx('header')" (mousedown)="initDrag($event)" *ngIf="showHeader">
<span [id]="ariaLabelledBy" [ngClass]="cx('title')" *ngIf="!_headerTemplate && !headerTemplate && !headerT">{{ header }}</span>
<ng-container *ngTemplateOutlet="_headerTemplate || headerTemplate || headerT"></ng-container>
<div [ngClass]="cx('headerActions')">
<p-button *ngIf="maximizable" [styleClass]="cx('pcMaximizeButton')" (onClick)="maximize()" (keydown.enter)="maximize()" [tabindex]="maximizable ? '0' : '-1'" [ariaLabel]="maximizeLabel" [buttonProps]="maximizeButtonProps">
<span *ngIf="maximizeIcon && !_maximizeiconTemplate && !_minimizeiconTemplate" [ngClass]="maximized ? minimizeIcon : maximizeIcon"></span>
<ng-container *ngIf="!maximizeIcon && !maximizeButtonProps?.icon">
<WindowMaximizeIcon *ngIf="!maximized && !_maximizeiconTemplate && !maximizeIconTemplate && !maximizeIconT" />
<WindowMinimizeIcon *ngIf="maximized && !_minimizeiconTemplate && !minimizeIconTemplate && !minimizeIconT" />
</ng-container>
<ng-container *ngIf="!maximized">
<ng-template *ngTemplateOutlet="_maximizeiconTemplate || maximizeIconTemplate || maximizeIconT"></ng-template>
</ng-container>
<ng-container *ngIf="maximized">
<ng-template *ngTemplateOutlet="_minimizeiconTemplate || minimizeIconTemplate || minimizeIconT"></ng-template>
</ng-container>
</p-button>
<p-button *ngIf="closable" [styleClass]="cx('pcCloseButton')" [ariaLabel]="closeAriaLabel" (onClick)="close($event)" (keydown.enter)="close($event)" [tabindex]="closeTabindex" [buttonProps]="closeButtonProps">
<ng-template #icon>
<ng-container *ngIf="!_closeiconTemplate && !closeIconTemplate && !closeIconT && !closeButtonProps?.icon">
<span *ngIf="closeIcon" [ngClass]="closeIcon"></span>
<TimesIcon *ngIf="!closeIcon" />
</ng-container>
<span *ngIf="_closeiconTemplate || closeIconTemplate || closeIconT">
<ng-template *ngTemplateOutlet="_closeiconTemplate || closeIconTemplate || closeIconT"></ng-template>
</span>
</ng-template>
</p-button>
</div>
</div>
<div #content [ngClass]="cx('content')" [class]="contentStyleClass" [ngStyle]="contentStyle" [attr.data-pc-section]="'content'">
<ng-content></ng-content>
<ng-container *ngTemplateOutlet="_contentTemplate || contentTemplate || contentT"></ng-container>
</div>
<div #footer [ngClass]="cx('footer')" *ngIf="_footerTemplate || footerTemplate || footerT">
<ng-content select="p-footer"></ng-content>
<ng-container *ngTemplateOutlet="_footerTemplate || footerTemplate || footerT"></ng-container>
</div>
</ng-template>
</div>
</div>
`, isInline: true, dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i1.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i1.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: Button, selector: "p-button", inputs: ["type", "iconPos", "icon", "badge", "label", "disabled", "loading", "loadingIcon", "raised", "rounded", "text", "plain", "severity", "outlined", "link", "tabindex", "size", "variant", "style", "styleClass", "badgeClass", "badgeSeverity", "ariaLabel", "autofocus", "fluid", "buttonProps"], outputs: ["onClick", "onFocus", "onBlur"] }, { kind: "directive", type: FocusTrap, selector: "[pFocusTrap]", inputs: ["pFocusTrapDisabled"] }, { kind: "component", type: TimesIcon, selector: "TimesIcon" }, { kind: "component", type: WindowMaximizeIcon, selector: "WindowMaximizeIcon" }, { kind: "component", type: WindowMinimizeIcon, selector: "WindowMinimizeIcon" }, { kind: "ngmodule", type: SharedModule }], animations: [trigger('animation', [transition('void => visible', [useAnimation(showAnimation)]), transition('visible => void', [useAnimation(hideAnimation)])])], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: Dialog, decorators: [{
type: Component,
args: [{
selector: 'p-dialog',
standalone: true,
imports: [CommonModule, Button, FocusTrap, TimesIcon, WindowMaximizeIcon, WindowMinimizeIcon, SharedModule],
template: `
<div
*ngIf="maskVisible"
[ngClass]="maskClass"
[class]="maskStyleClass"
[ngStyle]="{
position: 'fixed',
height: '100%',
width: '100%',
left: 0,
top: 0,
display: 'flex',
'justify-content': position === 'left' || position === 'topleft' || position === 'bottomleft' ? 'flex-start' : position === 'right' || position === 'topright' || position === 'bottomright' ? 'flex-end' : 'center',
'align-items': position === 'top' || position === 'topleft' || position === 'topright' ? 'flex-start' : position === 'bottom' || position === 'bottomleft' || position === 'bottomright' ? 'flex-end' : 'center',
'pointer-events': modal ? 'auto' : 'none'
}"
[style]="maskStyle"
>
<div
*ngIf="visible"
#container
[class]="styleClass"
[ngClass]="{ 'p-dialog p-component': true, 'p-dialog-maximized': maximizable && maximized }"
[ngStyle]="{ display: 'flex', 'flex-direction': 'column', 'pointer-events': 'auto' }"
[style]="style"
pFocusTrap
[pFocusTrapDisabled]="focusTrap === false"
[@animation]="{
value: 'visible',
params: { transform: transformOptions, transition: transitionOptions }
}"
(@animation.start)="onAnimationStart($event)"
(@animation.done)="onAnimationEnd($event)"
[attr.role]="role"
[attr.aria-labelledby]="ariaLabelledBy"
[attr.aria-modal]="true"
>
<ng-container *ngIf="_headlessTemplate || headlessTemplate || headlessT; else notHeadless">
<ng-container *ngTemplateOutlet="_headlessTemplate || headlessTemplate || headlessT"></ng-container>
</ng-container>
<ng-template #notHeadless>
<div *ngIf="resizable" [ngClass]="cx('resizeHandle')" style="z-index: 90;" (mousedown)="initResize($event)"></div>
<div #titlebar [ngClass]="cx('header')" (mousedown)="initDrag($event)" *ngIf="showHea