Icard/angular-clarity-master(work.../node_modules/ngx-toastr/esm2022/overlay/overlay.mjs

79 lines
11 KiB
JavaScript
Raw Normal View History

2024-07-16 14:55:36 +00:00
import { DOCUMENT } from '@angular/common';
import { ApplicationRef, ComponentFactoryResolver, inject, Injectable } from '@angular/core';
import { DomPortalHost } from '../portal/dom-portal-host';
import { OverlayContainer } from './overlay-container';
import { OverlayRef } from './overlay-ref';
import * as i0 from "@angular/core";
/**
* Service to create Overlays. Overlays are dynamically added pieces of floating UI, meant to be
* used as a low-level building building block for other components. Dialogs, tooltips, menus,
* selects, etc. can all be built using overlays. The service should primarily be used by authors
* of re-usable components rather than developers building end-user applications.
*
* An overlay *is* a PortalHost, so any kind of Portal can be loaded into one.
*/
class Overlay {
_overlayContainer = inject(OverlayContainer);
_componentFactoryResolver = inject(ComponentFactoryResolver);
_appRef = inject(ApplicationRef);
_document = inject(DOCUMENT);
// Namespace panes by overlay container
_paneElements = new Map();
/**
* Creates an overlay.
* @returns A reference to the created overlay.
*/
create(positionClass, overlayContainer) {
// get existing pane if possible
return this._createOverlayRef(this.getPaneElement(positionClass, overlayContainer));
}
getPaneElement(positionClass = '', overlayContainer) {
if (!this._paneElements.get(overlayContainer)) {
this._paneElements.set(overlayContainer, {});
}
if (!this._paneElements.get(overlayContainer)[positionClass]) {
this._paneElements.get(overlayContainer)[positionClass] = this._createPaneElement(positionClass, overlayContainer);
}
return this._paneElements.get(overlayContainer)[positionClass];
}
/**
* Creates the DOM element for an overlay and appends it to the overlay container.
* @returns Newly-created pane element
*/
_createPaneElement(positionClass, overlayContainer) {
const pane = this._document.createElement('div');
pane.id = 'toast-container';
pane.classList.add(positionClass);
pane.classList.add('toast-container');
if (!overlayContainer) {
this._overlayContainer.getContainerElement().appendChild(pane);
}
else {
overlayContainer.getContainerElement().appendChild(pane);
}
return pane;
}
/**
* Create a DomPortalHost into which the overlay content can be loaded.
* @param pane The DOM element to turn into a portal host.
* @returns A portal host for the given DOM element.
*/
_createPortalHost(pane) {
return new DomPortalHost(pane, this._componentFactoryResolver, this._appRef);
}
/**
* Creates an OverlayRef for an overlay in the given DOM element.
* @param pane DOM element for the overlay
*/
_createOverlayRef(pane) {
return new OverlayRef(this._createPortalHost(pane));
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: Overlay, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: Overlay, providedIn: 'root' });
}
export { Overlay };
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: Overlay, decorators: [{
type: Injectable,
args: [{ providedIn: 'root' }]
}] });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoib3ZlcmxheS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9saWIvb3ZlcmxheS9vdmVybGF5LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxRQUFRLEVBQUUsTUFBTSxpQkFBaUIsQ0FBQztBQUMzQyxPQUFPLEVBQUUsY0FBYyxFQUFFLHdCQUF3QixFQUFFLE1BQU0sRUFBRSxVQUFVLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFFN0YsT0FBTyxFQUFFLGFBQWEsRUFBRSxNQUFNLDJCQUEyQixDQUFDO0FBRTFELE9BQU8sRUFBRSxnQkFBZ0IsRUFBRSxNQUFNLHFCQUFxQixDQUFDO0FBQ3ZELE9BQU8sRUFBRSxVQUFVLEVBQUUsTUFBTSxlQUFlLENBQUM7O0FBRTNDOzs7Ozs7O0dBT0c7QUFDSCxNQUNhLE9BQU87SUFDVixpQkFBaUIsR0FBRyxNQUFNLENBQUMsZ0JBQWdCLENBQUMsQ0FBQztJQUM3Qyx5QkFBeUIsR0FBRyxNQUFNLENBQUMsd0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