Icard/angular-clarity-master(work.../node_modules/primeng/esm2022/dynamicdialog/dialogservice.mjs

102 lines
14 KiB
JavaScript
Raw Normal View History

2024-07-16 14:55:36 +00:00
import { Injectable, Inject, createComponent } from '@angular/core';
import { DomHandler } from 'primeng/dom';
import { DynamicDialogComponent } from './dynamicdialog';
import { DynamicDialogInjector } from './dynamicdialog-injector';
import { DynamicDialogConfig } from './dynamicdialog-config';
import { DynamicDialogRef } from './dynamicdialog-ref';
import { DOCUMENT } from '@angular/common';
import * as i0 from "@angular/core";
/**
* Dynamic Dialog component methods.
* @group Service
*/
export 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, componentType);
this.dialogComponentRefMap.get(dialogRef).instance.childComponentType = componentType;
return dialogRef;
}
/**
* Returns the dynamic dialog component instance.
* @param {ref} DynamicDialogRef - DynamicDialog instance.
* @group Method
*/
getInstance(ref) {
return this.dialogComponentRefMap.get(ref).instance;
}
appendDialogComponentToBody(config, componentType) {
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(DynamicDialogComponent, { 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 {
DomHandler.appendChild(domElem, config.appendTo);
}
this.dialogComponentRefMap.set(dialogRef, componentRef);
return dialogRef;
}
removeDialogComponentFromBody(dialogRef) {
if (!dialogRef || !this.dialogComponentRefMap.has(dialogRef)) {
return;
}
const dialogComponentRef = this.dialogComponentRefMap.get(dialogRef);
this.appRef.detachView(dialogComponentRef.hostView);
dialogComponentRef.destroy();
this.dialogComponentRefMap.delete(dialogRef);
}
duplicationPermission(componentType, config) {
if (config.duplicate) {
return true;
}
let permission = true;
for (const [key, value] of this.dialogComponentRefMap) {
if (value.instance.childComponentType === componentType) {
permission = false;
break;
}
}
return permission;
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", 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: "17.3.7", ngImport: i0, type: DialogService });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: DialogService, decorators: [{
type: Injectable
}], ctorParameters: () => [{ type: i0.ApplicationRef }, { type: i0.Injector }, { type: Document, decorators: [{
type: Inject,
args: [DOCUMENT]
}] }] });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGlhbG9nc2VydmljZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9hcHAvY29tcG9uZW50cy9keW5hbWljZGlhbG9nL2RpYWxvZ3NlcnZpY2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFVBQVUsRUFBaUUsTUFBTSxFQUFFLGVBQWUsRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUNuSSxPQUFPLEVBQUUsVUFBVSxFQUFF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