import { Inject, Injectable, Injector, SecurityContext } from '@angular/core'; import { ComponentPortal } from '../portal/portal'; import { ToastRef } from './toast-ref'; import { ToastPackage, TOAST_CONFIG, } from './toastr-config'; import * as i0 from "@angular/core"; import * as i1 from "../overlay/overlay"; import * as i2 from "@angular/platform-browser"; class ToastrService { overlay; _injector; sanitizer; ngZone; toastrConfig; currentlyActive = 0; toasts = []; overlayContainer; previousToastMessage; index = 0; constructor(token, overlay, _injector, sanitizer, ngZone) { this.overlay = overlay; this._injector = _injector; this.sanitizer = sanitizer; this.ngZone = ngZone; this.toastrConfig = { ...token.default, ...token.config, }; if (token.config.iconClasses) { this.toastrConfig.iconClasses = { ...token.default.iconClasses, ...token.config.iconClasses, }; } } /** show toast */ show(message, title, override = {}, type = '') { return this._preBuildNotification(type, message, title, this.applyConfig(override)); } /** show successful toast */ success(message, title, override = {}) { const type = this.toastrConfig.iconClasses.success || ''; return this._preBuildNotification(type, message, title, this.applyConfig(override)); } /** show error toast */ error(message, title, override = {}) { const type = this.toastrConfig.iconClasses.error || ''; return this._preBuildNotification(type, message, title, this.applyConfig(override)); } /** show info toast */ info(message, title, override = {}) { const type = this.toastrConfig.iconClasses.info || ''; return this._preBuildNotification(type, message, title, this.applyConfig(override)); } /** show warning toast */ warning(message, title, override = {}) { const type = this.toastrConfig.iconClasses.warning || ''; return this._preBuildNotification(type, message, title, this.applyConfig(override)); } /** * Remove all or a single toast by id */ clear(toastId) { // Call every toastRef manualClose function for (const toast of this.toasts) { if (toastId !== undefined) { if (toast.toastId === toastId) { toast.toastRef.manualClose(); return; } } else { toast.toastRef.manualClose(); } } } /** * Remove and destroy a single toast by id */ remove(toastId) { const found = this._findToast(toastId); if (!found) { return false; } found.activeToast.toastRef.close(); this.toasts.splice(found.index, 1); this.currentlyActive = this.currentlyActive - 1; if (!this.toastrConfig.maxOpened || !this.toasts.length) { return false; } if (this.currentlyActive < this.toastrConfig.maxOpened && this.toasts[this.currentlyActive]) { const p = this.toasts[this.currentlyActive].toastRef; if (!p.isInactive()) { this.currentlyActive = this.currentlyActive + 1; p.activate(); } } return true; } /** * Determines if toast message is already shown */ findDuplicate(title = '', message = '', resetOnDuplicate, countDuplicates) { const { includeTitleDuplicates } = this.toastrConfig; for (const toast of this.toasts) { const hasDuplicateTitle = includeTitleDuplicates && toast.title === title; if ((!includeTitleDuplicates || hasDuplicateTitle) && toast.message === message) { toast.toastRef.onDuplicate(resetOnDuplicate, countDuplicates); return toast; } } return null; } /** create a clone of global config and apply individual settings */ applyConfig(override = {}) { return { ...this.toastrConfig, ...override }; } /** * Find toast object by id */ _findToast(toastId) { for (let i = 0; i < this.toasts.length; i++) { if (this.toasts[i].toastId === toastId) { return { index: i, activeToast: this.toasts[i] }; } } return null; } /** * Determines the need to run inside angular's zone then builds the toast */ _preBuildNotification(toastType, message, title, config) { if (config.onActivateTick) { return this.ngZone.run(() => this._buildNotification(toastType, message, title, config)); } return this._buildNotification(toastType, message, title, config); } /** * Creates and attaches toast data to component * returns the active toast, or in case preventDuplicates is enabled the original/non-duplicate active toast. */ _buildNotification(toastType, message, title, config) { if (!config.toastComponent) { throw new Error('toastComponent required'); } // max opened and auto dismiss = true // if timeout = 0 resetting it would result in setting this.hideTime = Date.now(). Hence, we only want to reset timeout if there is // a timeout at all const duplicate = this.findDuplicate(title, message, this.toastrConfig.resetTimeoutOnDuplicate && config.timeOut > 0, this.toastrConfig.countDuplicates); if (((this.toastrConfig.includeTitleDuplicates && title) || message) && this.toastrConfig.preventDuplicates && duplicate !== null) { return duplicate; } this.previousToastMessage = message; let keepInactive = false; if (this.toastrConfig.maxOpened && this.currentlyActive >= this.toastrConfig.maxOpened) { keepInactive = true; if (this.toastrConfig.autoDismiss) { this.clear(this.toasts[0].toastId); } } const overlayRef = this.overlay.create(config.positionClass, this.overlayContainer); this.index = this.index + 1; let sanitizedMessage = message; if (message && config.enableHtml) { sanitizedMessage = this.sanitizer.sanitize(SecurityContext.HTML, message); } const toastRef = new ToastRef(overlayRef); const toastPackage = new ToastPackage(this.index, config, sanitizedMessage, title, toastType, toastRef); /** New injector that contains an instance of `ToastPackage`. */ const providers = [{ provide: ToastPackage, useValue: toastPackage }]; const toastInjector = Injector.create({ providers, parent: this._injector }); const component = new ComponentPortal(config.toastComponent, toastInjector); const portal = overlayRef.attach(component, config.newestOnTop); toastRef.componentInstance = portal.instance; const ins = { toastId: this.index, title: title || '', message: message || '', toastRef, onShown: toastRef.afterActivate(), onHidden: toastRef.afterClosed(), onTap: toastPackage.onTap(), onAction: toastPackage.onAction(), portal, }; if (!keepInactive) { this.currentlyActive = this.currentlyActive + 1; setTimeout(() => { ins.toastRef.activate(); }); } this.toasts.push(ins); return ins; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: ToastrService, deps: [{ token: TOAST_CONFIG }, { token: i1.Overlay }, { token: i0.Injector }, { token: i2.DomSanitizer }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable }); static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: ToastrService, providedIn: 'root' }); } export { ToastrService }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.1", ngImport: i0, type: ToastrService, decorators: [{ type: Injectable, args: [{ providedIn: 'root' }] }], ctorParameters: function () { return [{ type: undefined, decorators: [{ type: Inject, args: [TOAST_CONFIG] }] }, { type: i1.Overlay }, { type: i0.Injector }, { type: i2.DomSanitizer }, { type: i0.NgZone }]; } }); //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9hc3RyLnNlcnZpY2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9zcmMvbGliL3RvYXN0ci90b2FzdHIuc2VydmljZS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQWdCLE1BQU0sRUFBRSxVQUFVLEVBQUUsUUFBUSx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