| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114 |
- import { __decorate, __metadata, __param } from 'tslib';
- import { Directive, ElementRef, NgModule, InjectionToken, defineInjectable, inject, Injectable, Inject, ComponentFactoryResolver, ApplicationRef, SecurityContext, INJECTOR, NgZone, Injector, HostBinding, HostListener, Component } from '@angular/core';
- import { trigger, state, style, transition, animate } from '@angular/animations';
- import { Subject } from 'rxjs';
- import { DomSanitizer } from '@angular/platform-browser';
- import { DOCUMENT, CommonModule } from '@angular/common';
- let ToastContainerDirective = class ToastContainerDirective {
- constructor(el) {
- this.el = el;
- }
- getContainerElement() {
- return this.el.nativeElement;
- }
- };
- ToastContainerDirective = __decorate([
- Directive({
- selector: '[toastContainer]',
- exportAs: 'toastContainer',
- }),
- __metadata("design:paramtypes", [ElementRef])
- ], ToastContainerDirective);
- let ToastContainerModule = class ToastContainerModule {
- };
- ToastContainerModule = __decorate([
- NgModule({
- declarations: [ToastContainerDirective],
- exports: [ToastContainerDirective],
- })
- ], ToastContainerModule);
- /**
- * Everything a toast needs to launch
- */
- class ToastPackage {
- constructor(toastId, config, message, title, toastType, toastRef) {
- this.toastId = toastId;
- this.config = config;
- this.message = message;
- this.title = title;
- this.toastType = toastType;
- this.toastRef = toastRef;
- this._onTap = new Subject();
- this._onAction = new Subject();
- this.toastRef.afterClosed().subscribe(() => {
- this._onAction.complete();
- this._onTap.complete();
- });
- }
- /** Fired on click */
- triggerTap() {
- this._onTap.next();
- if (this.config.tapToDismiss) {
- this._onTap.complete();
- }
- }
- onTap() {
- return this._onTap.asObservable();
- }
- /** available for use in custom toast */
- triggerAction(action) {
- this._onAction.next(action);
- }
- onAction() {
- return this._onAction.asObservable();
- }
- }
- const DefaultNoComponentGlobalConfig = {
- maxOpened: 0,
- autoDismiss: false,
- newestOnTop: true,
- preventDuplicates: false,
- countDuplicates: false,
- resetTimeoutOnDuplicate: false,
- iconClasses: {
- error: 'toast-error',
- info: 'toast-info',
- success: 'toast-success',
- warning: 'toast-warning',
- },
- // Individual
- closeButton: false,
- disableTimeOut: false,
- timeOut: 5000,
- extendedTimeOut: 1000,
- enableHtml: false,
- progressBar: false,
- toastClass: 'ngx-toastr',
- positionClass: 'toast-top-right',
- titleClass: 'toast-title',
- messageClass: 'toast-message',
- easing: 'ease-in',
- easeTime: 300,
- tapToDismiss: true,
- onActivateTick: false,
- progressAnimation: 'decreasing',
- };
- const TOAST_CONFIG = new InjectionToken('ToastConfig');
- /**
- * A `ComponentPortal` is a portal that instantiates some Component upon attachment.
- */
- class ComponentPortal {
- constructor(component, injector) {
- this.component = component;
- this.injector = injector;
- }
- /** Attach this portal to a host. */
- attach(host, newestOnTop) {
- this._attachedHost = host;
- return host.attach(this, newestOnTop);
- }
- /** Detach this portal from its host */
- detach() {
- const host = this._attachedHost;
- if (host) {
- this._attachedHost = undefined;
- return host.detach();
- }
- }
- /** Whether this portal is attached to a host. */
- get isAttached() {
- return this._attachedHost != null;
- }
- /**
- * Sets the PortalHost reference without performing `attach()`. This is used directly by
- * the PortalHost when it is performing an `attach()` or `detach()`.
- */
- setAttachedHost(host) {
- this._attachedHost = host;
- }
- }
- /**
- * Partial implementation of PortalHost that only deals with attaching a
- * ComponentPortal
- */
- class BasePortalHost {
- attach(portal, newestOnTop) {
- this._attachedPortal = portal;
- return this.attachComponentPortal(portal, newestOnTop);
- }
- detach() {
- if (this._attachedPortal) {
- this._attachedPortal.setAttachedHost();
- }
- this._attachedPortal = undefined;
- if (this._disposeFn) {
- this._disposeFn();
- this._disposeFn = undefined;
- }
- }
- setDisposeFn(fn) {
- this._disposeFn = fn;
- }
- }
- /**
- * A PortalHost for attaching portals to an arbitrary DOM element outside of the Angular
- * application context.
- *
- * This is the only part of the portal core that directly touches the DOM.
- */
- class DomPortalHost extends BasePortalHost {
- constructor(_hostDomElement, _componentFactoryResolver, _appRef) {
- super();
- this._hostDomElement = _hostDomElement;
- this._componentFactoryResolver = _componentFactoryResolver;
- this._appRef = _appRef;
- }
- /**
- * Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
- * @param portal Portal to be attached
- */
- attachComponentPortal(portal, newestOnTop) {
- const componentFactory = this._componentFactoryResolver.resolveComponentFactory(portal.component);
- let componentRef;
- // If the portal specifies a ViewContainerRef, we will use that as the attachment point
- // for the component (in terms of Angular's component tree, not rendering).
- // When the ViewContainerRef is missing, we use the factory to create the component directly
- // and then manually attach the ChangeDetector for that component to the application (which
- // happens automatically when using a ViewContainer).
- componentRef = componentFactory.create(portal.injector);
- // When creating a component outside of a ViewContainer, we need to manually register
- // its ChangeDetector with the application. This API is unfortunately not yet published
- // in Angular core. The change detector must also be deregistered when the component
- // is destroyed to prevent memory leaks.
- this._appRef.attachView(componentRef.hostView);
- this.setDisposeFn(() => {
- this._appRef.detachView(componentRef.hostView);
- componentRef.destroy();
- });
- // At this point the component has been instantiated, so we move it to the location in the DOM
- // where we want it to be rendered.
- if (newestOnTop) {
- this._hostDomElement.insertBefore(this._getComponentRootNode(componentRef), this._hostDomElement.firstChild);
- }
- else {
- this._hostDomElement.appendChild(this._getComponentRootNode(componentRef));
- }
- return componentRef;
- }
- /** Gets the root HTMLElement for an instantiated component. */
- _getComponentRootNode(componentRef) {
- return componentRef.hostView.rootNodes[0];
- }
- }
- /** Container inside which all toasts will render. */
- let OverlayContainer = class OverlayContainer {
- constructor(_document) {
- this._document = _document;
- }
- ngOnDestroy() {
- if (this._containerElement && this._containerElement.parentNode) {
- this._containerElement.parentNode.removeChild(this._containerElement);
- }
- }
- /**
- * This method returns the overlay container element. It will lazily
- * create the element the first time it is called to facilitate using
- * the container in non-browser environments.
- * @returns the container element
- */
- getContainerElement() {
- if (!this._containerElement) {
- this._createContainer();
- }
- return this._containerElement;
- }
- /**
- * Create the overlay container element, which is simply a div
- * with the 'cdk-overlay-container' class on the document body.
- */
- _createContainer() {
- const container = this._document.createElement('div');
- container.classList.add('overlay-container');
- this._document.body.appendChild(container);
- this._containerElement = container;
- }
- };
- OverlayContainer.ngInjectableDef = defineInjectable({ factory: function OverlayContainer_Factory() { return new OverlayContainer(inject(DOCUMENT)); }, token: OverlayContainer, providedIn: "root" });
- OverlayContainer = __decorate([
- Injectable({ providedIn: 'root' }),
- __param(0, Inject(DOCUMENT)),
- __metadata("design:paramtypes", [Object])
- ], OverlayContainer);
- /**
- * Reference to an overlay that has been created with the Overlay service.
- * Used to manipulate or dispose of said overlay.
- */
- class OverlayRef {
- constructor(_portalHost) {
- this._portalHost = _portalHost;
- }
- attach(portal, newestOnTop = true) {
- return this._portalHost.attach(portal, newestOnTop);
- }
- /**
- * Detaches an overlay from a portal.
- * @returns Resolves when the overlay has been detached.
- */
- detach() {
- return this._portalHost.detach();
- }
- }
- /**
- * 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.
- */
- let Overlay = class Overlay {
- constructor(_overlayContainer, _componentFactoryResolver, _appRef, _document) {
- this._overlayContainer = _overlayContainer;
- this._componentFactoryResolver = _componentFactoryResolver;
- this._appRef = _appRef;
- this._document = _document;
- // Namespace panes by overlay container
- this._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));
- }
- };
- Overlay.ngInjectableDef = defineInjectable({ factory: function Overlay_Factory() { return new Overlay(inject(OverlayContainer), inject(ComponentFactoryResolver), inject(ApplicationRef), inject(DOCUMENT)); }, token: Overlay, providedIn: "root" });
- Overlay = __decorate([
- Injectable({ providedIn: 'root' }),
- __param(3, Inject(DOCUMENT)),
- __metadata("design:paramtypes", [OverlayContainer,
- ComponentFactoryResolver,
- ApplicationRef, Object])
- ], Overlay);
- /**
- * Reference to a toast opened via the Toastr service.
- */
- class ToastRef {
- constructor(_overlayRef) {
- this._overlayRef = _overlayRef;
- /** Count of duplicates of this toast */
- this.duplicatesCount = 0;
- /** Subject for notifying the user that the toast has finished closing. */
- this._afterClosed = new Subject();
- /** triggered when toast is activated */
- this._activate = new Subject();
- /** notifies the toast that it should close before the timeout */
- this._manualClose = new Subject();
- /** notifies the toast that it should reset the timeouts */
- this._resetTimeout = new Subject();
- /** notifies the toast that it should count a duplicate toast */
- this._countDuplicate = new Subject();
- }
- manualClose() {
- this._manualClose.next();
- this._manualClose.complete();
- }
- manualClosed() {
- return this._manualClose.asObservable();
- }
- timeoutReset() {
- return this._resetTimeout.asObservable();
- }
- countDuplicate() {
- return this._countDuplicate.asObservable();
- }
- /**
- * Close the toast.
- */
- close() {
- this._overlayRef.detach();
- this._afterClosed.next();
- this._manualClose.next();
- this._afterClosed.complete();
- this._manualClose.complete();
- this._activate.complete();
- this._resetTimeout.complete();
- this._countDuplicate.complete();
- }
- /** Gets an observable that is notified when the toast is finished closing. */
- afterClosed() {
- return this._afterClosed.asObservable();
- }
- isInactive() {
- return this._activate.isStopped;
- }
- activate() {
- this._activate.next();
- this._activate.complete();
- }
- /** Gets an observable that is notified when the toast has started opening. */
- afterActivate() {
- return this._activate.asObservable();
- }
- /** Reset the toast timouts and count duplicates */
- onDuplicate(resetTimeout, countDuplicate) {
- if (resetTimeout) {
- this._resetTimeout.next();
- }
- if (countDuplicate) {
- this._countDuplicate.next(++this.duplicatesCount);
- }
- }
- }
- /** Custom injector type specifically for instantiating components with a toast. */
- class ToastInjector {
- constructor(_toastPackage, _parentInjector) {
- this._toastPackage = _toastPackage;
- this._parentInjector = _parentInjector;
- }
- get(token, notFoundValue, flags) {
- if (token === ToastPackage) {
- return this._toastPackage;
- }
- return this._parentInjector.get(token, notFoundValue, flags);
- }
- }
- let ToastrService = class ToastrService {
- constructor(token, overlay, _injector, sanitizer, ngZone) {
- this.overlay = overlay;
- this._injector = _injector;
- this.sanitizer = sanitizer;
- this.ngZone = ngZone;
- this.currentlyActive = 0;
- this.toasts = [];
- this.index = 0;
- this.toastrConfig = Object.assign({}, token.default, token.config);
- if (token.config.iconClasses) {
- this.toastrConfig.iconClasses = Object.assign({}, 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(message, resetOnDuplicate, countDuplicates) {
- for (let i = 0; i < this.toasts.length; i++) {
- const toast = this.toasts[i];
- if (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 Object.assign({}, 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(message, this.toastrConfig.resetTimeoutOnDuplicate && config.timeOut > 0, this.toastrConfig.countDuplicates);
- if (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);
- const toastInjector = new ToastInjector(toastPackage, this._injector);
- const component = new ComponentPortal(config.toastComponent, toastInjector);
- const portal = overlayRef.attach(component, this.toastrConfig.newestOnTop);
- toastRef.componentInstance = portal._component;
- const ins = {
- toastId: this.index,
- message: message || '',
- toastRef,
- onShown: toastRef.afterActivate(),
- onHidden: toastRef.afterClosed(),
- onTap: toastPackage.onTap(),
- onAction: toastPackage.onAction(),
- portal
- };
- if (!keepInactive) {
- setTimeout(() => {
- ins.toastRef.activate();
- this.currentlyActive = this.currentlyActive + 1;
- });
- }
- this.toasts.push(ins);
- return ins;
- }
- };
- ToastrService.ngInjectableDef = defineInjectable({ factory: function ToastrService_Factory() { return new ToastrService(inject(TOAST_CONFIG), inject(Overlay), inject(INJECTOR), inject(DomSanitizer), inject(NgZone)); }, token: ToastrService, providedIn: "root" });
- ToastrService = __decorate([
- Injectable({ providedIn: 'root' }),
- __param(0, Inject(TOAST_CONFIG)),
- __metadata("design:paramtypes", [Object, Overlay,
- Injector,
- DomSanitizer,
- NgZone])
- ], ToastrService);
- let Toast = class Toast {
- constructor(toastrService, toastPackage, ngZone) {
- this.toastrService = toastrService;
- this.toastPackage = toastPackage;
- this.ngZone = ngZone;
- /** width of progress bar */
- this.width = -1;
- /** a combination of toast type and options.toastClass */
- this.toastClasses = '';
- /** controls animation */
- this.state = {
- value: 'inactive',
- params: {
- easeTime: this.toastPackage.config.easeTime,
- easing: 'ease-in'
- }
- };
- this.message = toastPackage.message;
- this.title = toastPackage.title;
- this.options = toastPackage.config;
- this.originalTimeout = toastPackage.config.timeOut;
- this.toastClasses = `${toastPackage.toastType} ${toastPackage.config.toastClass}`;
- this.sub = toastPackage.toastRef.afterActivate().subscribe(() => {
- this.activateToast();
- });
- this.sub1 = toastPackage.toastRef.manualClosed().subscribe(() => {
- this.remove();
- });
- this.sub2 = toastPackage.toastRef.timeoutReset().subscribe(() => {
- this.resetTimeout();
- });
- this.sub3 = toastPackage.toastRef.countDuplicate().subscribe(count => {
- this.duplicatesCount = count;
- });
- }
- /** hides component when waiting to be displayed */
- get displayStyle() {
- if (this.state.value === 'inactive') {
- return 'none';
- }
- }
- ngOnDestroy() {
- this.sub.unsubscribe();
- this.sub1.unsubscribe();
- this.sub2.unsubscribe();
- this.sub3.unsubscribe();
- clearInterval(this.intervalId);
- clearTimeout(this.timeout);
- }
- /**
- * activates toast and sets timeout
- */
- activateToast() {
- this.state = Object.assign({}, this.state, { value: 'active' });
- if (!this.options.disableTimeOut && this.options.timeOut) {
- this.outsideTimeout(() => this.remove(), this.options.timeOut);
- this.hideTime = new Date().getTime() + this.options.timeOut;
- if (this.options.progressBar) {
- this.outsideInterval(() => this.updateProgress(), 10);
- }
- }
- }
- /**
- * updates progress bar width
- */
- updateProgress() {
- if (this.width === 0 || this.width === 100 || !this.options.timeOut) {
- return;
- }
- const now = new Date().getTime();
- const remaining = this.hideTime - now;
- this.width = (remaining / this.options.timeOut) * 100;
- if (this.options.progressAnimation === 'increasing') {
- this.width = 100 - this.width;
- }
- if (this.width <= 0) {
- this.width = 0;
- }
- if (this.width >= 100) {
- this.width = 100;
- }
- }
- resetTimeout() {
- clearTimeout(this.timeout);
- clearInterval(this.intervalId);
- this.state = Object.assign({}, this.state, { value: 'active' });
- this.outsideTimeout(() => this.remove(), this.originalTimeout);
- this.options.timeOut = this.originalTimeout;
- this.hideTime = new Date().getTime() + (this.options.timeOut || 0);
- this.width = -1;
- if (this.options.progressBar) {
- this.outsideInterval(() => this.updateProgress(), 10);
- }
- }
- /**
- * tells toastrService to remove this toast after animation time
- */
- remove() {
- if (this.state.value === 'removed') {
- return;
- }
- clearTimeout(this.timeout);
- this.state = Object.assign({}, this.state, { value: 'removed' });
- this.outsideTimeout(() => this.toastrService.remove(this.toastPackage.toastId), +this.toastPackage.config.easeTime);
- }
- tapToast() {
- if (this.state.value === 'removed') {
- return;
- }
- this.toastPackage.triggerTap();
- if (this.options.tapToDismiss) {
- this.remove();
- }
- }
- stickAround() {
- if (this.state.value === 'removed') {
- return;
- }
- clearTimeout(this.timeout);
- this.options.timeOut = 0;
- this.hideTime = 0;
- // disable progressBar
- clearInterval(this.intervalId);
- this.width = 0;
- }
- delayedHideToast() {
- if (this.options.disableTimeOut ||
- this.options.extendedTimeOut === 0 ||
- this.state.value === 'removed') {
- return;
- }
- this.outsideTimeout(() => this.remove(), this.options.extendedTimeOut);
- this.options.timeOut = this.options.extendedTimeOut;
- this.hideTime = new Date().getTime() + (this.options.timeOut || 0);
- this.width = -1;
- if (this.options.progressBar) {
- this.outsideInterval(() => this.updateProgress(), 10);
- }
- }
- outsideTimeout(func, timeout) {
- if (this.ngZone) {
- this.ngZone.runOutsideAngular(() => (this.timeout = setTimeout(() => this.runInsideAngular(func), timeout)));
- }
- else {
- this.timeout = setTimeout(() => func(), timeout);
- }
- }
- outsideInterval(func, timeout) {
- if (this.ngZone) {
- this.ngZone.runOutsideAngular(() => (this.intervalId = setInterval(() => this.runInsideAngular(func), timeout)));
- }
- else {
- this.intervalId = setInterval(() => func(), timeout);
- }
- }
- runInsideAngular(func) {
- if (this.ngZone) {
- this.ngZone.run(() => func());
- }
- else {
- func();
- }
- }
- };
- __decorate([
- HostBinding('class'),
- __metadata("design:type", Object)
- ], Toast.prototype, "toastClasses", void 0);
- __decorate([
- HostBinding('@flyInOut'),
- __metadata("design:type", Object)
- ], Toast.prototype, "state", void 0);
- __decorate([
- HostBinding('style.display'),
- __metadata("design:type", Object),
- __metadata("design:paramtypes", [])
- ], Toast.prototype, "displayStyle", null);
- __decorate([
- HostListener('click'),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", []),
- __metadata("design:returntype", void 0)
- ], Toast.prototype, "tapToast", null);
- __decorate([
- HostListener('mouseenter'),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", []),
- __metadata("design:returntype", void 0)
- ], Toast.prototype, "stickAround", null);
- __decorate([
- HostListener('mouseleave'),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", []),
- __metadata("design:returntype", void 0)
- ], Toast.prototype, "delayedHideToast", null);
- Toast = __decorate([
- Component({
- selector: '[toast-component]',
- template: `
- <button *ngIf="options.closeButton" (click)="remove()" class="toast-close-button" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- <div *ngIf="title" [class]="options.titleClass" [attr.aria-label]="title">
- {{ title }} <ng-container *ngIf="duplicatesCount">[{{ duplicatesCount + 1 }}]</ng-container>
- </div>
- <div *ngIf="message && options.enableHtml" role="alertdialog" aria-live="polite"
- [class]="options.messageClass" [innerHTML]="message">
- </div>
- <div *ngIf="message && !options.enableHtml" role="alertdialog" aria-live="polite"
- [class]="options.messageClass" [attr.aria-label]="message">
- {{ message }}
- </div>
- <div *ngIf="options.progressBar">
- <div class="toast-progress" [style.width]="width + '%'"></div>
- </div>
- `,
- animations: [
- trigger('flyInOut', [
- state('inactive', style({ opacity: 0 })),
- state('active', style({ opacity: 1 })),
- state('removed', style({ opacity: 0 })),
- transition('inactive => active', animate('{{ easeTime }}ms {{ easing }}')),
- transition('active => removed', animate('{{ easeTime }}ms {{ easing }}'))
- ])
- ],
- preserveWhitespaces: false
- }),
- __metadata("design:paramtypes", [ToastrService,
- ToastPackage,
- NgZone])
- ], Toast);
- var ToastrModule_1;
- const DefaultGlobalConfig = Object.assign({}, DefaultNoComponentGlobalConfig, { toastComponent: Toast });
- let ToastrModule = ToastrModule_1 = class ToastrModule {
- static forRoot(config = {}) {
- return {
- ngModule: ToastrModule_1,
- providers: [
- {
- provide: TOAST_CONFIG,
- useValue: {
- default: DefaultGlobalConfig,
- config,
- },
- },
- ],
- };
- }
- };
- ToastrModule = ToastrModule_1 = __decorate([
- NgModule({
- imports: [CommonModule],
- declarations: [Toast],
- exports: [Toast],
- entryComponents: [Toast],
- })
- ], ToastrModule);
- let ToastrComponentlessModule = class ToastrComponentlessModule {
- static forRoot(config = {}) {
- return {
- ngModule: ToastrModule,
- providers: [
- {
- provide: TOAST_CONFIG,
- useValue: {
- default: DefaultNoComponentGlobalConfig,
- config,
- },
- },
- ],
- };
- }
- };
- ToastrComponentlessModule = __decorate([
- NgModule({
- imports: [CommonModule],
- })
- ], ToastrComponentlessModule);
- var ToastNoAnimationModule_1;
- let ToastNoAnimation = class ToastNoAnimation {
- constructor(toastrService, toastPackage, appRef) {
- this.toastrService = toastrService;
- this.toastPackage = toastPackage;
- this.appRef = appRef;
- /** width of progress bar */
- this.width = -1;
- /** a combination of toast type and options.toastClass */
- this.toastClasses = '';
- /** controls animation */
- this.state = 'inactive';
- this.message = toastPackage.message;
- this.title = toastPackage.title;
- this.options = toastPackage.config;
- this.originalTimeout = toastPackage.config.timeOut;
- this.toastClasses = `${toastPackage.toastType} ${toastPackage.config.toastClass}`;
- this.sub = toastPackage.toastRef.afterActivate().subscribe(() => {
- this.activateToast();
- });
- this.sub1 = toastPackage.toastRef.manualClosed().subscribe(() => {
- this.remove();
- });
- this.sub2 = toastPackage.toastRef.timeoutReset().subscribe(() => {
- this.resetTimeout();
- });
- this.sub3 = toastPackage.toastRef.countDuplicate().subscribe(count => {
- this.duplicatesCount = count;
- });
- }
- /** hides component when waiting to be displayed */
- get displayStyle() {
- if (this.state === 'inactive') {
- return 'none';
- }
- }
- ngOnDestroy() {
- this.sub.unsubscribe();
- this.sub1.unsubscribe();
- this.sub2.unsubscribe();
- this.sub3.unsubscribe();
- clearInterval(this.intervalId);
- clearTimeout(this.timeout);
- }
- /**
- * activates toast and sets timeout
- */
- activateToast() {
- this.state = 'active';
- if (!this.options.disableTimeOut && this.options.timeOut) {
- this.timeout = setTimeout(() => {
- this.remove();
- }, this.options.timeOut);
- this.hideTime = new Date().getTime() + this.options.timeOut;
- if (this.options.progressBar) {
- this.intervalId = setInterval(() => this.updateProgress(), 10);
- }
- }
- if (this.options.onActivateTick) {
- this.appRef.tick();
- }
- }
- /**
- * updates progress bar width
- */
- updateProgress() {
- if (this.width === 0 || this.width === 100 || !this.options.timeOut) {
- return;
- }
- const now = new Date().getTime();
- const remaining = this.hideTime - now;
- this.width = (remaining / this.options.timeOut) * 100;
- if (this.options.progressAnimation === 'increasing') {
- this.width = 100 - this.width;
- }
- if (this.width <= 0) {
- this.width = 0;
- }
- if (this.width >= 100) {
- this.width = 100;
- }
- }
- resetTimeout() {
- clearTimeout(this.timeout);
- clearInterval(this.intervalId);
- this.state = 'active';
- this.options.timeOut = this.originalTimeout;
- this.timeout = setTimeout(() => this.remove(), this.originalTimeout);
- this.hideTime = new Date().getTime() + (this.originalTimeout || 0);
- this.width = -1;
- if (this.options.progressBar) {
- this.intervalId = setInterval(() => this.updateProgress(), 10);
- }
- }
- /**
- * tells toastrService to remove this toast after animation time
- */
- remove() {
- if (this.state === 'removed') {
- return;
- }
- clearTimeout(this.timeout);
- this.state = 'removed';
- this.timeout = setTimeout(() => this.toastrService.remove(this.toastPackage.toastId));
- }
- tapToast() {
- if (this.state === 'removed') {
- return;
- }
- this.toastPackage.triggerTap();
- if (this.options.tapToDismiss) {
- this.remove();
- }
- }
- stickAround() {
- if (this.state === 'removed') {
- return;
- }
- clearTimeout(this.timeout);
- this.options.timeOut = 0;
- this.hideTime = 0;
- // disable progressBar
- clearInterval(this.intervalId);
- this.width = 0;
- }
- delayedHideToast() {
- if (this.options.disableTimeOut ||
- this.options.extendedTimeOut === 0 ||
- this.state === 'removed') {
- return;
- }
- this.timeout = setTimeout(() => this.remove(), this.options.extendedTimeOut);
- this.options.timeOut = this.options.extendedTimeOut;
- this.hideTime = new Date().getTime() + (this.options.timeOut || 0);
- this.width = -1;
- if (this.options.progressBar) {
- this.intervalId = setInterval(() => this.updateProgress(), 10);
- }
- }
- };
- __decorate([
- HostBinding('class'),
- __metadata("design:type", Object)
- ], ToastNoAnimation.prototype, "toastClasses", void 0);
- __decorate([
- HostBinding('style.display'),
- __metadata("design:type", Object),
- __metadata("design:paramtypes", [])
- ], ToastNoAnimation.prototype, "displayStyle", null);
- __decorate([
- HostListener('click'),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", []),
- __metadata("design:returntype", void 0)
- ], ToastNoAnimation.prototype, "tapToast", null);
- __decorate([
- HostListener('mouseenter'),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", []),
- __metadata("design:returntype", void 0)
- ], ToastNoAnimation.prototype, "stickAround", null);
- __decorate([
- HostListener('mouseleave'),
- __metadata("design:type", Function),
- __metadata("design:paramtypes", []),
- __metadata("design:returntype", void 0)
- ], ToastNoAnimation.prototype, "delayedHideToast", null);
- ToastNoAnimation = __decorate([
- Component({
- selector: '[toast-component]',
- template: `
- <button *ngIf="options.closeButton" (click)="remove()" class="toast-close-button" aria-label="Close">
- <span aria-hidden="true">×</span>
- </button>
- <div *ngIf="title" [class]="options.titleClass" [attr.aria-label]="title">
- {{ title }} <ng-container *ngIf="duplicatesCount">[{{ duplicatesCount + 1 }}]</ng-container>
- </div>
- <div *ngIf="message && options.enableHtml" role="alert" aria-live="polite"
- [class]="options.messageClass" [innerHTML]="message">
- </div>
- <div *ngIf="message && !options.enableHtml" role="alert" aria-live="polite"
- [class]="options.messageClass" [attr.aria-label]="message">
- {{ message }}
- </div>
- <div *ngIf="options.progressBar">
- <div class="toast-progress" [style.width]="width + '%'"></div>
- </div>
- `
- }),
- __metadata("design:paramtypes", [ToastrService,
- ToastPackage,
- ApplicationRef])
- ], ToastNoAnimation);
- const DefaultNoAnimationsGlobalConfig = Object.assign({}, DefaultNoComponentGlobalConfig, { toastComponent: ToastNoAnimation });
- let ToastNoAnimationModule = ToastNoAnimationModule_1 = class ToastNoAnimationModule {
- static forRoot(config = {}) {
- return {
- ngModule: ToastNoAnimationModule_1,
- providers: [
- {
- provide: TOAST_CONFIG,
- useValue: {
- default: DefaultNoAnimationsGlobalConfig,
- config,
- },
- },
- ],
- };
- }
- };
- ToastNoAnimationModule = ToastNoAnimationModule_1 = __decorate([
- NgModule({
- imports: [CommonModule],
- declarations: [ToastNoAnimation],
- exports: [ToastNoAnimation],
- entryComponents: [ToastNoAnimation],
- })
- ], ToastNoAnimationModule);
- /**
- * Generated bundle index. Do not edit.
- */
- export { BasePortalHost, ComponentPortal, DefaultGlobalConfig, DefaultNoAnimationsGlobalConfig, DefaultNoComponentGlobalConfig, Overlay, OverlayContainer, OverlayRef, TOAST_CONFIG, Toast, ToastContainerDirective, ToastContainerModule, ToastInjector, ToastNoAnimation, ToastNoAnimationModule, ToastPackage, ToastRef, ToastrComponentlessModule, ToastrModule, ToastrService };
- //# sourceMappingURL=ngx-toastr.js.map
|