primeng
Version:
[](https://opensource.org/licenses/MIT) [](https://badge.fury.io/js/primeng) [ • 15.8 kB
JavaScript
import { ViewContainerRef, Directive, ComponentFactoryResolver, ChangeDetectorRef, Renderer2, NgZone, ViewChild, Component, ChangeDetectionStrategy, NgModule, ApplicationRef, Injector, Injectable } from '@angular/core';
import { animation, style, animate, trigger, transition, useAnimation } from '@angular/animations';
import { CommonModule } from '@angular/common';
import { DomHandler } from 'primeng/dom';
import { Subject } from 'rxjs';
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var DynamicDialogContent = /** @class */ (function () {
function DynamicDialogContent(viewContainerRef) {
this.viewContainerRef = viewContainerRef;
}
DynamicDialogContent.ctorParameters = function () { return [
{ type: ViewContainerRef }
]; };
DynamicDialogContent = __decorate([
Directive({
selector: '[pDynamicDialogContent]'
})
], DynamicDialogContent);
return DynamicDialogContent;
}());
var DynamicDialogConfig = /** @class */ (function () {
function DynamicDialogConfig() {
}
return DynamicDialogConfig;
}());
var DynamicDialogRef = /** @class */ (function () {
function DynamicDialogRef() {
this._onClose = new Subject();
this.onClose = this._onClose.asObservable();
this._onDestroy = new 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 __decorate$1 = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var showAnimation = animation([
style({ transform: '{{transform}}', opacity: 0 }),
animate('{{transition}}', style({ transform: 'none', opacity: 1 }))
]);
var hideAnimation = animation([
animate('{{transition}}', 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.onOverlayClicked = function (evt) {
this.dialogRef.close();
};
DynamicDialogComponent.prototype.onDialogClicked = function (evt) {
evt.stopPropagation();
};
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) + (++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.moveOnTop();
this.bindGlobalListeners();
DomHandler.addClass(document.body, 'ui-overflow-hidden');
this.focus();
break;
case 'void':
this.onContainerDestroy();
break;
}
};
DynamicDialogComponent.prototype.onAnimationEnd = function (event) {
if (event.toState === 'void') {
this.dialogRef.destroy();
}
};
DynamicDialogComponent.prototype.onContainerDestroy = function () {
DomHandler.removeClass(document.body, 'ui-overflow-hidden');
this.unbindGlobalListeners();
this.container = null;
};
DynamicDialogComponent.prototype.close = function () {
this.visible = false;
};
DynamicDialogComponent.prototype.onMaskClick = function () {
if (this.config.dismissableMask) {
this.close();
}
};
DynamicDialogComponent.prototype.onKeydown = function (event) {
if (event.which === 9) {
event.preventDefault();
var focusableElements = DomHandler.getFocusableElements(this.container);
if (focusableElements && focusableElements.length > 0) {
if (!document.activeElement) {
focusableElements[0].focus();
}
else {
var focusedIndex = focusableElements.indexOf(document.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 = DomHandler.findSingle(this.container, 'a');
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;
this.documentEscapeListener = this.renderer.listen('document', 'keydown', function (event) {
if (event.which == 27) {
if (parseInt(_this.container.style.zIndex) == (DomHandler.zindex + _this.config.baseZIndex)) {
_this.close();
}
}
});
};
DynamicDialogComponent.prototype.unbindDocumentEscapeListener = function () {
if (this.documentEscapeListener) {
this.documentEscapeListener();
this.documentEscapeListener = null;
}
};
DynamicDialogComponent.prototype.ngOnDestroy = function () {
this.onContainerDestroy();
if (this.componentRef) {
this.componentRef.destroy();
}
};
DynamicDialogComponent.ctorParameters = function () { return [
{ type: ComponentFactoryResolver },
{ type: ChangeDetectorRef },
{ type: Renderer2 },
{ type: DynamicDialogConfig },
{ type: DynamicDialogRef },
{ type: NgZone }
]; };
__decorate$1([
ViewChild(DynamicDialogContent)
], DynamicDialogComponent.prototype, "insertionPoint", void 0);
__decorate$1([
ViewChild('mask')
], DynamicDialogComponent.prototype, "maskViewChild", void 0);
DynamicDialogComponent = __decorate$1([
Component({
selector: 'p-dynamicDialog',
template: "\n <div #mask class=\"ui-widget-overlay ui-dialog-mask ui-dialog-visible ui-dialog-mask-scrollblocker\">\n <div [ngClass]=\"{'ui-dialog ui-dynamicdialog ui-widget ui-widget-content ui-corner-all ui-shadow':true, 'ui-dialog-rtl': config.rtl}\" [ngStyle]=\"config.style\" [class]=\"config.styleClass\"\n [@animation]=\"{value: 'visible', params: {transform: transformOptions, transition: config.transitionOptions || '150ms cubic-bezier(0, 0, 0.2, 1)'}}\"\n (@animation.start)=\"onAnimationStart($event)\" (@animation.done)=\"onAnimationEnd($event)\" role=\"dialog\" *ngIf=\"visible\"\n [style.width]=\"config.width\" [style.height]=\"config.height\">\n <div class=\"ui-dialog-titlebar ui-widget-header ui-helper-clearfix ui-corner-top\" *ngIf=\"config.showHeader === false ? false: true\">\n <span class=\"ui-dialog-title\">{{config.header}}</span>\n <div class=\"ui-dialog-titlebar-icons\">\n <a [ngClass]=\"'ui-dialog-titlebar-icon ui-dialog-titlebar-close ui-corner-all'\" tabindex=\"0\" role=\"button\" (click)=\"close()\" (keydown.enter)=\"close()\" *ngIf=\"config.closable !== false\">\n <span class=\"pi pi-times\"></span>\n </a>\n </div>\n </div>\n <div class=\"ui-dialog-content ui-widget-content\" [ngStyle]=\"config.contentStyle\">\n <ng-template pDynamicDialogContent></ng-template>\n </div>\n <div class=\"ui-dialog-footer ui-widget-content\" *ngIf=\"config.footer\">\n {{config.footer}}\n </div>\n </div>\n </div>\n\t",
animations: [
trigger('animation', [
transition('void => visible', [
useAnimation(showAnimation)
]),
transition('visible => void', [
useAnimation(hideAnimation)
])
])
],
changeDetection: ChangeDetectionStrategy.Default
})
], DynamicDialogComponent);
return DynamicDialogComponent;
}());
var DynamicDialogModule = /** @class */ (function () {
function DynamicDialogModule() {
}
DynamicDialogModule = __decorate$1([
NgModule({
imports: [CommonModule],
declarations: [DynamicDialogComponent, DynamicDialogContent],
entryComponents: [DynamicDialogComponent]
})
], DynamicDialogModule);
return DynamicDialogModule;
}());
var DynamicDialogInjector = /** @class */ (function () {
function DynamicDialogInjector(_parentInjector, _additionalTokens) {
this._parentInjector = _parentInjector;
this._additionalTokens = _additionalTokens;
}
DynamicDialogInjector.prototype.get = function (token, notFoundValue, flags) {
var value = this._additionalTokens.get(token);
if (value)
return value;
return this._parentInjector.get(token, notFoundValue);
};
return DynamicDialogInjector;
}());
var __decorate$2 = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var DialogService = /** @class */ (function () {
function DialogService(componentFactoryResolver, appRef, injector) {
this.componentFactoryResolver = componentFactoryResolver;
this.appRef = appRef;
this.injector = injector;
}
DialogService.prototype.open = function (componentType, config) {
var dialogRef = this.appendDialogComponentToBody(config);
this.dialogComponentRef.instance.childComponentType = componentType;
return dialogRef;
};
DialogService.prototype.appendDialogComponentToBody = function (config) {
var _this = this;
var map = new WeakMap();
map.set(DynamicDialogConfig, config);
var dialogRef = new DynamicDialogRef();
map.set(DynamicDialogRef, dialogRef);
var sub = dialogRef.onClose.subscribe(function () {
_this.dialogComponentRef.instance.close();
});
var destroySub = dialogRef.onDestroy.subscribe(function () {
_this.removeDialogComponentFromBody();
destroySub.unsubscribe();
sub.unsubscribe();
});
var componentFactory = this.componentFactoryResolver.resolveComponentFactory(DynamicDialogComponent);
var componentRef = componentFactory.create(new DynamicDialogInjector(this.injector, map));
this.appRef.attachView(componentRef.hostView);
var domElem = componentRef.hostView.rootNodes[0];
document.body.appendChild(domElem);
this.dialogComponentRef = componentRef;
return dialogRef;
};
DialogService.prototype.removeDialogComponentFromBody = function () {
this.appRef.detachView(this.dialogComponentRef.hostView);
this.dialogComponentRef.destroy();
};
DialogService.ctorParameters = function () { return [
{ type: ComponentFactoryResolver },
{ type: ApplicationRef },
{ type: Injector }
]; };
DialogService = __decorate$2([
Injectable()
], DialogService);
return DialogService;
}());
/**
* Generated bundle index. Do not edit.
*/
export { DialogService, DynamicDialogComponent, DynamicDialogConfig, DynamicDialogInjector, DynamicDialogModule, DynamicDialogRef, DynamicDialogContent as ɵa };
//# sourceMappingURL=primeng-dynamicdialog.js.map