(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/animations'), require('@angular/common'), require('primeng/dom'), require('rxjs')) : typeof define === 'function' && define.amd ? define('primeng/dynamicdialog', ['exports', '@angular/core', '@angular/animations', '@angular/common', 'primeng/dom', 'rxjs'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.primeng = global.primeng || {}, global.primeng.dynamicdialog = {}), global.ng.core, global.ng.animations, global.ng.common, global.primeng.dom, global.rxjs)); }(this, (function (exports, core, animations, common, dom, rxjs) { 'use strict'; var DynamicDialogContent = /** @class */ (function () { function DynamicDialogContent(viewContainerRef) { this.viewContainerRef = viewContainerRef; } return DynamicDialogContent; }()); DynamicDialogContent.decorators = [ { type: core.Directive, args: [{ selector: '[pDynamicDialogContent]' },] } ]; DynamicDialogContent.ctorParameters = function () { return [ { type: core.ViewContainerRef } ]; }; var DynamicDialogConfig = /** @class */ (function () { function DynamicDialogConfig() { } return DynamicDialogConfig; }()); var DynamicDialogRef = /** @class */ (function () { function DynamicDialogRef() { this._onClose = new rxjs.Subject(); this.onClose = this._onClose.asObservable(); this._onDestroy = new rxjs.Subject(); this.onDestroy = this._onDestroy.asObservable(); } DynamicDialogRef.prototype.close = function (result) { this._onClose.next(result); }; DynamicDialogRef.prototype.destroy = function () { this._onDestroy.next(); }; return DynamicDialogRef; }()); var showAnimation = animations.animation([ animations.style({ transform: '{{transform}}', opacity: 0 }), animations.animate('{{transition}}', animations.style({ transform: 'none', opacity: 1 })) ]); var hideAnimation = animations.animation([ animations.animate('{{transition}}', animations.style({ transform: '{{transform}}', opacity: 0 })) ]); var DynamicDialogComponent = /** @class */ (function () { function DynamicDialogComponent(componentFactoryResolver, cd, renderer, config, dialogRef, zone) { this.componentFactoryResolver = componentFactoryResolver; this.cd = cd; this.renderer = renderer; this.config = config; this.dialogRef = dialogRef; this.zone = zone; this.visible = true; this.transformOptions = "scale(0.7)"; } DynamicDialogComponent.prototype.ngAfterViewInit = function () { this.loadChildComponent(this.childComponentType); this.cd.detectChanges(); }; DynamicDialogComponent.prototype.loadChildComponent = function (componentType) { var componentFactory = this.componentFactoryResolver.resolveComponentFactory(componentType); var viewContainerRef = this.insertionPoint.viewContainerRef; viewContainerRef.clear(); this.componentRef = viewContainerRef.createComponent(componentFactory); }; DynamicDialogComponent.prototype.moveOnTop = function () { if (this.config.autoZIndex !== false) { var zIndex = (this.config.baseZIndex || 0) + (++dom.DomHandler.zindex); this.container.style.zIndex = String(zIndex); this.maskViewChild.nativeElement.style.zIndex = String(zIndex - 1); } }; DynamicDialogComponent.prototype.onAnimationStart = function (event) { switch (event.toState) { case 'visible': this.container = event.element; this.wrapper = this.container.parentElement; this.moveOnTop(); this.bindGlobalListeners(); if (this.config.modal !== false) { this.enableModality(); } this.focus(); break; case 'void': this.onContainerDestroy(); break; } }; DynamicDialogComponent.prototype.onAnimationEnd = function (event) { if (event.toState === 'void') { this.dialogRef.destroy(); } }; DynamicDialogComponent.prototype.onContainerDestroy = function () { this.unbindGlobalListeners(); if (this.config.modal !== false) { this.disableModality(); } this.container = null; }; DynamicDialogComponent.prototype.close = function () { this.visible = false; this.cd.markForCheck(); }; DynamicDialogComponent.prototype.hide = function () { if (this.dialogRef) { this.dialogRef.close(); } }; DynamicDialogComponent.prototype.enableModality = function () { var _this = this; if (this.config.closable !== false && this.config.dismissableMask) { this.maskClickListener = this.renderer.listen(this.wrapper, 'click', function (event) { if (_this.wrapper && _this.wrapper.isSameNode(event.target)) { _this.hide(); } }); } if (this.config.modal !== false) { dom.DomHandler.addClass(document.body, 'p-overflow-hidden'); } }; DynamicDialogComponent.prototype.disableModality = function () { if (this.wrapper) { if (this.config.dismissableMask) { this.unbindMaskClickListener(); } if (this.config.modal !== false) { dom.DomHandler.removeClass(document.body, 'p-overflow-hidden'); } if (!this.cd.destroyed) { this.cd.detectChanges(); } } }; DynamicDialogComponent.prototype.onKeydown = function (event) { if (event.which === 9) { event.preventDefault(); var focusableElements = dom.DomHandler.getFocusableElements(this.container); if (focusableElements && focusableElements.length > 0) { if (!focusableElements[0].ownerDocument.activeElement) { focusableElements[0].focus(); } else { var focusedIndex = focusableElements.indexOf(focusableElements[0].ownerDocument.activeElement); if (event.shiftKey) { if (focusedIndex == -1 || focusedIndex === 0) focusableElements[focusableElements.length - 1].focus(); else focusableElements[focusedIndex - 1].focus(); } else { if (focusedIndex == -1 || focusedIndex === (focusableElements.length - 1)) focusableElements[0].focus(); else focusableElements[focusedIndex + 1].focus(); } } } } }; DynamicDialogComponent.prototype.focus = function () { var focusable = dom.DomHandler.findSingle(this.container, '[autofocus]'); if (focusable) { this.zone.runOutsideAngular(function () { setTimeout(function () { return focusable.focus(); }, 5); }); } }; DynamicDialogComponent.prototype.bindGlobalListeners = function () { this.bindDocumentKeydownListener(); if (this.config.closeOnEscape !== false && this.config.closable !== false) { this.bindDocumentEscapeListener(); } }; DynamicDialogComponent.prototype.unbindGlobalListeners = function () { this.unbindDocumentKeydownListener(); this.unbindDocumentEscapeListener(); }; DynamicDialogComponent.prototype.bindDocumentKeydownListener = function () { var _this = this; this.zone.runOutsideAngular(function () { _this.documentKeydownListener = _this.onKeydown.bind(_this); window.document.addEventListener('keydown', _this.documentKeydownListener); }); }; DynamicDialogComponent.prototype.unbindDocumentKeydownListener = function () { if (this.documentKeydownListener) { window.document.removeEventListener('keydown', this.documentKeydownListener); this.documentKeydownListener = null; } }; DynamicDialogComponent.prototype.bindDocumentEscapeListener = function () { var _this = this; var documentTarget = this.maskViewChild ? this.maskViewChild.nativeElement.ownerDocument : 'document'; this.documentEscapeListener = this.renderer.listen(documentTarget, 'keydown', function (event) { if (event.which == 27) { if (parseInt(_this.container.style.zIndex) == (dom.DomHandler.zindex + (_this.config.baseZIndex ? _this.config.baseZIndex : 0))) { _this.hide(); } } }); }; DynamicDialogComponent.prototype.unbindDocumentEscapeListener = function () { if (this.documentEscapeListener) { this.documentEscapeListener(); this.documentEscapeListener = null; } }; DynamicDialogComponent.prototype.unbindMaskClickListener = function () { if (this.maskClickListener) { this.maskClickListener(); this.maskClickListener = null; } }; DynamicDialogComponent.prototype.ngOnDestroy = function () { this.onContainerDestroy(); if (this.componentRef) { this.componentRef.destroy(); } }; return DynamicDialogComponent; }()); DynamicDialogComponent.decorators = [ { type: core.Component, args: [{ selector: 'p-dynamicDialog', template: "\n