@hxui/angular
Version:
* * *
1,482 lines (1,472 loc) • 1.02 MB
JavaScript
import { Directive, ElementRef, NgModule, InjectionToken, Inject, Injectable, Component, Input, ChangeDetectorRef, ViewChild, HostListener, TemplateRef, EventEmitter, HostBinding, Output, ReflectiveInjector, ComponentFactoryResolver, Optional, ViewContainerRef, Injector, Renderer2, forwardRef, IterableDiffers, ViewEncapsulation, CUSTOM_ELEMENTS_SCHEMA, Pipe, NgZone, ContentChild, SecurityContext, defineInjectable, inject, INJECTOR, ApplicationRef } from '@angular/core';
import { Subject, Observable, from } from 'rxjs';
import { __assign, __values, __decorate, __spread, __extends } from 'tslib';
import { DOCUMENT, CommonModule } from '@angular/common';
import { DomSanitizer, BrowserModule } from '@angular/platform-browser';
import { animate, state, style, transition, trigger } from '@angular/animations';
import { takeUntil, take, debounceTime as debounceTime$1, mergeMap, filter, toArray } from 'rxjs/operators';
import { Subject as Subject$1, Subscription, fromEvent } from 'rxjs/index';
import { TemplatePortal, ComponentPortal, PortalModule } from '@angular/cdk/portal';
import { Overlay, ScrollDispatcher, OverlayModule } from '@angular/cdk/overlay';
import { isEqual, cloneDeep } from 'lodash';
import { debounceTime } from 'rxjs/internal/operators';
import { FormsModule, NG_VALUE_ACCESSOR, NG_VALIDATORS, NgControl } from '@angular/forms';
import * as moment_ from 'moment';
import { Directionality } from '@angular/cdk/bidi';
import { FocusTrapFactory, A11yModule } from '@angular/cdk/a11y';
import sortBy from 'array-sort-by';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
var ToastrContainerDirective = /** @class */ (function () {
function ToastrContainerDirective(el) {
this.el = el;
}
/**
* @return {?}
*/
ToastrContainerDirective.prototype.getContainerElement = /**
* @return {?}
*/
function () {
return this.el.nativeElement;
};
ToastrContainerDirective.decorators = [
{ type: Directive, args: [{
selector: '[hxaToastrContainer]',
exportAs: 'hxaToastrContainer',
},] },
];
/** @nocollapse */
ToastrContainerDirective.ctorParameters = function () { return [
{ type: ElementRef }
]; };
return ToastrContainerDirective;
}());
var ToastrContainerModule = /** @class */ (function () {
function ToastrContainerModule() {
}
ToastrContainerModule.decorators = [
{ type: NgModule, args: [{
declarations: [ToastrContainerDirective],
exports: [ToastrContainerDirective],
},] },
];
return ToastrContainerModule;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
/** @enum {number} */
var ToastrPosition = {
CENTER_CENTER: 0,
TOP_CENTER: 1,
BOTTOM_CENTER: 2,
TOP_FULL_WIDTH: 3,
BOTTOM_FULL_WIDTH: 4,
TOP_LEFT: 5,
TOP_RIGHT: 6,
BOTTOM_LEFT: 7,
BOTTOM_RIGHT: 8,
};
ToastrPosition[ToastrPosition.CENTER_CENTER] = 'CENTER_CENTER';
ToastrPosition[ToastrPosition.TOP_CENTER] = 'TOP_CENTER';
ToastrPosition[ToastrPosition.BOTTOM_CENTER] = 'BOTTOM_CENTER';
ToastrPosition[ToastrPosition.TOP_FULL_WIDTH] = 'TOP_FULL_WIDTH';
ToastrPosition[ToastrPosition.BOTTOM_FULL_WIDTH] = 'BOTTOM_FULL_WIDTH';
ToastrPosition[ToastrPosition.TOP_LEFT] = 'TOP_LEFT';
ToastrPosition[ToastrPosition.TOP_RIGHT] = 'TOP_RIGHT';
ToastrPosition[ToastrPosition.BOTTOM_LEFT] = 'BOTTOM_LEFT';
ToastrPosition[ToastrPosition.BOTTOM_RIGHT] = 'BOTTOM_RIGHT';
/**
* Everything a toast needs to launch
*/
var /**
* Everything a toast needs to launch
*/
ToastPackage = /** @class */ (function () {
function ToastPackage(toastId, config, message, title, toastType, toastRef) {
var _this = this;
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(function () {
_this._onAction.complete();
_this._onTap.complete();
});
}
/** Fired on click */
/**
* Fired on click
* @return {?}
*/
ToastPackage.prototype.triggerTap = /**
* Fired on click
* @return {?}
*/
function () {
this._onTap.next();
if (this.config.tapToDismiss) {
this._onTap.complete();
}
};
/**
* @return {?}
*/
ToastPackage.prototype.onTap = /**
* @return {?}
*/
function () {
return this._onTap.asObservable();
};
/** available for use in custom toast */
/**
* available for use in custom toast
* @param {?=} action
* @return {?}
*/
ToastPackage.prototype.triggerAction = /**
* available for use in custom toast
* @param {?=} action
* @return {?}
*/
function (action) {
this._onAction.next(action);
};
/**
* @return {?}
*/
ToastPackage.prototype.onAction = /**
* @return {?}
*/
function () {
return this._onAction.asObservable();
};
return ToastPackage;
}());
/** @type {?} */
var DefaultNoComponentGlobalConfig = {
maxOpened: 0,
autoDismiss: false,
newestOnTop: true,
preventDuplicates: false,
resetTimeoutOnDuplicate: false,
iconClasses: {
none: '',
error: 'is-error',
info: 'is-info',
success: 'is-success',
warning: 'is-warning',
},
// Individual
closeButton: false,
disableTimeOut: false,
timeOut: 5000,
extendedTimeOut: 1000,
enableHtml: false,
progressBar: false,
toastClass: 'hx-alert',
position: ToastrPosition.TOP_RIGHT,
titleClass: 'toast-title',
messageClass: 'toast-message',
easing: 'ease-in',
easeTime: 300,
tapToDismiss: true,
onActivateTick: false,
progressAnimation: 'decreasing',
};
/** @type {?} */
var TOAST_CONFIG = new InjectionToken('ToastrConfig');
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
/**
* A `ComponentPortal` is a portal that instantiates some Component upon attachment.
* @template T
*/
var /**
* A `ComponentPortal` is a portal that instantiates some Component upon attachment.
* @template T
*/
ComponentPortal$1 = /** @class */ (function () {
function ComponentPortal$$1(component, injector) {
this.component = component;
this.injector = injector;
}
/** Attach this portal to a host. */
/**
* Attach this portal to a host.
* @param {?} host
* @param {?} newestOnTop
* @return {?}
*/
ComponentPortal$$1.prototype.attach = /**
* Attach this portal to a host.
* @param {?} host
* @param {?} newestOnTop
* @return {?}
*/
function (host, newestOnTop) {
this._attachedHost = host;
return host.attach(this, newestOnTop);
};
/** Detach this portal from its host */
/**
* Detach this portal from its host
* @return {?}
*/
ComponentPortal$$1.prototype.detach = /**
* Detach this portal from its host
* @return {?}
*/
function () {
/** @type {?} */
var host = this._attachedHost;
if (host) {
this._attachedHost = undefined;
return host.detach();
}
};
Object.defineProperty(ComponentPortal$$1.prototype, "isAttached", {
/** Whether this portal is attached to a host. */
get: /**
* Whether this portal is attached to a host.
* @return {?}
*/
function () {
return this._attachedHost != null;
},
enumerable: true,
configurable: true
});
/**
* Sets the PortalHost reference without performing `attach()`. This is used directly by
* the PortalHost when it is performing an `attach()` or `detach()`.
*/
/**
* Sets the PortalHost reference without performing `attach()`. This is used directly by
* the PortalHost when it is performing an `attach()` or `detach()`.
* @param {?=} host
* @return {?}
*/
ComponentPortal$$1.prototype.setAttachedHost = /**
* Sets the PortalHost reference without performing `attach()`. This is used directly by
* the PortalHost when it is performing an `attach()` or `detach()`.
* @param {?=} host
* @return {?}
*/
function (host) {
this._attachedHost = host;
};
return ComponentPortal$$1;
}());
/**
* Partial implementation of PortalHost that only deals with attaching a
* ComponentPortal
* @abstract
*/
var /**
* Partial implementation of PortalHost that only deals with attaching a
* ComponentPortal
* @abstract
*/
BasePortalHost = /** @class */ (function () {
function BasePortalHost() {
}
/**
* @param {?} portal
* @param {?} newestOnTop
* @return {?}
*/
BasePortalHost.prototype.attach = /**
* @param {?} portal
* @param {?} newestOnTop
* @return {?}
*/
function (portal, newestOnTop) {
this._attachedPortal = portal;
return this.attachComponentPortal(portal, newestOnTop);
};
/**
* @return {?}
*/
BasePortalHost.prototype.detach = /**
* @return {?}
*/
function () {
if (this._attachedPortal) {
this._attachedPortal.setAttachedHost();
}
this._attachedPortal = undefined;
if (this._disposeFn) {
this._disposeFn();
this._disposeFn = undefined;
}
};
/**
* @param {?} fn
* @return {?}
*/
BasePortalHost.prototype.setDisposeFn = /**
* @param {?} fn
* @return {?}
*/
function (fn) {
this._disposeFn = fn;
};
return BasePortalHost;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
/**
* 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.
*/
var /**
* 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.
*/
DomPortalHost = /** @class */ (function (_super) {
__extends(DomPortalHost, _super);
function DomPortalHost(_hostDomElement, _componentFactoryResolver, _appRef) {
var _this = _super.call(this) || this;
_this._hostDomElement = _hostDomElement;
_this._componentFactoryResolver = _componentFactoryResolver;
_this._appRef = _appRef;
return _this;
}
/**
* Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
* @param portal Portal to be attached
*/
/**
* Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
* @template T
* @param {?} portal Portal to be attached
* @param {?} newestOnTop
* @return {?}
*/
DomPortalHost.prototype.attachComponentPortal = /**
* Attach the given ComponentPortal to DOM element using the ComponentFactoryResolver.
* @template T
* @param {?} portal Portal to be attached
* @param {?} newestOnTop
* @return {?}
*/
function (portal, newestOnTop) {
var _this = this;
/** @type {?} */
var componentFactory = this._componentFactoryResolver.resolveComponentFactory(portal.component);
/** @type {?} */
var 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(function () {
_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. */
/**
* Gets the root HTMLElement for an instantiated component.
* @param {?} componentRef
* @return {?}
*/
DomPortalHost.prototype._getComponentRootNode = /**
* Gets the root HTMLElement for an instantiated component.
* @param {?} componentRef
* @return {?}
*/
function (componentRef) {
return (/** @type {?} */ (((/** @type {?} */ (componentRef.hostView))).rootNodes[0]));
};
return DomPortalHost;
}(BasePortalHost));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
/**
* Container inside which all toasts will render.
*/
var OverlayContainer = /** @class */ (function () {
function OverlayContainer(_document) {
this._document = _document;
}
/**
* @return {?}
*/
OverlayContainer.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
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
*/
/**
* 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.
* @return {?} the container element
*/
OverlayContainer.prototype.getContainerElement = /**
* 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.
* @return {?} the container element
*/
function () {
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.
*/
/**
* Create the overlay container element, which is simply a div
* with the 'cdk-overlay-container' class on the document body.
* @return {?}
*/
OverlayContainer.prototype._createContainer = /**
* Create the overlay container element, which is simply a div
* with the 'cdk-overlay-container' class on the document body.
* @return {?}
*/
function () {
/** @type {?} */
var container = this._document.createElement('div');
container.classList.add('overlay-container');
this._document.body.appendChild(container);
this._containerElement = container;
};
OverlayContainer.decorators = [
{ type: Injectable, args: [{ providedIn: 'root' },] },
];
/** @nocollapse */
OverlayContainer.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
]; };
/** @nocollapse */ OverlayContainer.ngInjectableDef = defineInjectable({ factory: function OverlayContainer_Factory() { return new OverlayContainer(inject(DOCUMENT)); }, token: OverlayContainer, providedIn: "root" });
return OverlayContainer;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
/**
* Reference to an overlay that has been created with the Overlay service.
* Used to manipulate or dispose of said overlay.
*/
var /**
* Reference to an overlay that has been created with the Overlay service.
* Used to manipulate or dispose of said overlay.
*/
OverlayRef = /** @class */ (function () {
function OverlayRef(_portalHost) {
this._portalHost = _portalHost;
}
/**
* @param {?} portal
* @param {?=} newestOnTop
* @return {?}
*/
OverlayRef.prototype.attach = /**
* @param {?} portal
* @param {?=} newestOnTop
* @return {?}
*/
function (portal, newestOnTop) {
if (newestOnTop === void 0) { newestOnTop = true; }
return this._portalHost.attach(portal, newestOnTop);
};
/**
* Detaches an overlay from a portal.
* @returns Resolves when the overlay has been detached.
*/
/**
* Detaches an overlay from a portal.
* @return {?} Resolves when the overlay has been detached.
*/
OverlayRef.prototype.detach = /**
* Detaches an overlay from a portal.
* @return {?} Resolves when the overlay has been detached.
*/
function () {
return this._portalHost.detach();
};
return OverlayRef;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
/**
* 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.
*/
var Overlay$1 = /** @class */ (function () {
function Overlay$$1(_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.
*/
/**
* Creates an overlay.
* @param {?=} position
* @param {?=} overlayContainer
* @return {?} A reference to the created overlay.
*/
Overlay$$1.prototype.create = /**
* Creates an overlay.
* @param {?=} position
* @param {?=} overlayContainer
* @return {?} A reference to the created overlay.
*/
function (position, overlayContainer) {
// get existing pane if possible
return this._createOverlayRef(this.getPaneElement(position, overlayContainer));
};
/**
* @param {?=} position
* @param {?=} overlayContainer
* @return {?}
*/
Overlay$$1.prototype.getPaneElement = /**
* @param {?=} position
* @param {?=} overlayContainer
* @return {?}
*/
function (position, overlayContainer) {
if (position === void 0) { position = ToastrPosition.TOP_RIGHT; }
if (!this._paneElements.get(overlayContainer)) {
this._paneElements.set(overlayContainer, {});
}
if (!this._paneElements.get(overlayContainer)[position]) {
this._paneElements.get(overlayContainer)[position] = this._createPaneElement(position, overlayContainer);
}
return this._paneElements.get(overlayContainer)[position];
};
/**
* Creates the DOM element for an overlay and appends it to the overlay container.
* @returns Newly-created pane element
*/
/**
* Creates the DOM element for an overlay and appends it to the overlay container.
* @param {?} position
* @param {?=} overlayContainer
* @return {?} Newly-created pane element
*/
Overlay$$1.prototype._createPaneElement = /**
* Creates the DOM element for an overlay and appends it to the overlay container.
* @param {?} position
* @param {?=} overlayContainer
* @return {?} Newly-created pane element
*/
function (position, overlayContainer) {
/** @type {?} */
var pane = this._document.createElement('div');
pane.id = 'hxa-toastr-container';
/// pane.classList.add(positionClass);
pane.classList.add('hxa-toastr-container');
pane.classList.add('hxui-reset');
pane.style.position = 'fixed';
pane.style['z-index'] = 1000;
if (position === ToastrPosition.CENTER_CENTER) {
pane.style.top = '50%';
pane.style.left = '50%';
pane.style.transform = 'translate(-50%, -50%)';
}
else if (position === ToastrPosition.TOP_CENTER) {
pane.style.top = '0';
pane.style.right = '0';
pane.style.width = '100%';
}
else if (position === ToastrPosition.BOTTOM_CENTER) {
pane.style.bottom = '0';
pane.style.right = '0';
pane.style.width = '100%';
}
else if (position === ToastrPosition.TOP_FULL_WIDTH) {
pane.style.top = '0';
pane.style.right = '0';
pane.style.width = '100%';
}
else if (position === ToastrPosition.BOTTOM_FULL_WIDTH) {
pane.style.bottom = '0';
pane.style.right = '0';
pane.style.width = '100%';
}
else if (position === ToastrPosition.TOP_LEFT) {
pane.style.top = '2rem';
pane.style.left = '2rem';
}
else if (position === ToastrPosition.TOP_RIGHT) {
pane.style.top = '2rem';
pane.style.right = '2rem';
}
else if (position === ToastrPosition.BOTTOM_RIGHT) {
pane.style.bottom = '2rem';
pane.style.right = '2rem';
}
else if (position === ToastrPosition.BOTTOM_LEFT) {
pane.style.bottom = '2rem';
pane.style.left = '2rem';
}
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.
*/
/**
* Create a DomPortalHost into which the overlay content can be loaded.
* @param {?} pane The DOM element to turn into a portal host.
* @return {?} A portal host for the given DOM element.
*/
Overlay$$1.prototype._createPortalHost = /**
* Create a DomPortalHost into which the overlay content can be loaded.
* @param {?} pane The DOM element to turn into a portal host.
* @return {?} A portal host for the given DOM element.
*/
function (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
*/
/**
* Creates an OverlayRef for an overlay in the given DOM element.
* @param {?} pane DOM element for the overlay
* @return {?}
*/
Overlay$$1.prototype._createOverlayRef = /**
* Creates an OverlayRef for an overlay in the given DOM element.
* @param {?} pane DOM element for the overlay
* @return {?}
*/
function (pane) {
return new OverlayRef(this._createPortalHost(pane));
};
Overlay$$1.decorators = [
{ type: Injectable, args: [{ providedIn: 'root' },] },
];
/** @nocollapse */
Overlay$$1.ctorParameters = function () { return [
{ type: OverlayContainer },
{ type: ComponentFactoryResolver },
{ type: ApplicationRef },
{ type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }
]; };
/** @nocollapse */ Overlay$$1.ngInjectableDef = defineInjectable({ factory: function Overlay_Factory() { return new Overlay$$1(inject(OverlayContainer), inject(ComponentFactoryResolver), inject(ApplicationRef), inject(DOCUMENT)); }, token: Overlay$$1, providedIn: "root" });
return Overlay$$1;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
/**
* Reference to a toast opened via the Toastr service.
* @template T
*/
var /**
* Reference to a toast opened via the Toastr service.
* @template T
*/
ToastrRef = /** @class */ (function () {
function ToastrRef(_overlayRef) {
this._overlayRef = _overlayRef;
/**
* 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();
}
/**
* @return {?}
*/
ToastrRef.prototype.manualClose = /**
* @return {?}
*/
function () {
this._manualClose.next();
this._manualClose.complete();
};
/**
* @return {?}
*/
ToastrRef.prototype.manualClosed = /**
* @return {?}
*/
function () {
return this._manualClose.asObservable();
};
/**
* @return {?}
*/
ToastrRef.prototype.timeoutReset = /**
* @return {?}
*/
function () {
return this._resetTimeout.asObservable();
};
/**
* Close the toast.
*/
/**
* Close the toast.
* @return {?}
*/
ToastrRef.prototype.close = /**
* Close the toast.
* @return {?}
*/
function () {
this._overlayRef.detach();
this._afterClosed.next();
this._manualClose.next();
this._afterClosed.complete();
this._manualClose.complete();
this._activate.complete();
this._resetTimeout.complete();
};
/** Gets an observable that is notified when the toast is finished closing. */
/**
* Gets an observable that is notified when the toast is finished closing.
* @return {?}
*/
ToastrRef.prototype.afterClosed = /**
* Gets an observable that is notified when the toast is finished closing.
* @return {?}
*/
function () {
return this._afterClosed.asObservable();
};
/**
* @return {?}
*/
ToastrRef.prototype.isInactive = /**
* @return {?}
*/
function () {
return this._activate.isStopped;
};
/**
* @return {?}
*/
ToastrRef.prototype.activate = /**
* @return {?}
*/
function () {
this._activate.next();
this._activate.complete();
};
/** Gets an observable that is notified when the toast has started opening. */
/**
* Gets an observable that is notified when the toast has started opening.
* @return {?}
*/
ToastrRef.prototype.afterActivate = /**
* Gets an observable that is notified when the toast has started opening.
* @return {?}
*/
function () {
return this._activate.asObservable();
};
/** Reset the toast timouts */
/**
* Reset the toast timouts
* @return {?}
*/
ToastrRef.prototype.resetTimeout = /**
* Reset the toast timouts
* @return {?}
*/
function () {
this._resetTimeout.next();
};
return ToastrRef;
}());
/**
* Custom injector type specifically for instantiating components with a toast.
*/
var /**
* Custom injector type specifically for instantiating components with a toast.
*/
ToastrInjector = /** @class */ (function () {
function ToastrInjector(_toastPackage, _parentInjector) {
this._toastPackage = _toastPackage;
this._parentInjector = _parentInjector;
}
/**
* @template T
* @param {?} token
* @param {?=} notFoundValue
* @param {?=} flags
* @return {?}
*/
ToastrInjector.prototype.get = /**
* @template T
* @param {?} token
* @param {?=} notFoundValue
* @param {?=} flags
* @return {?}
*/
function (token, notFoundValue, flags) {
if (token === ToastPackage) {
return this._toastPackage;
}
return this._parentInjector.get(token, notFoundValue, flags);
};
return ToastrInjector;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
var ToastrService = /** @class */ (function () {
function ToastrService(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 = __assign({}, token.default, token.config);
if (token.config.iconClasses) {
this.toastrConfig.iconClasses = __assign({}, token.default.iconClasses, token.config.iconClasses);
}
}
/** show toast */
/**
* show toast
* @param {?=} message
* @param {?=} title
* @param {?=} override
* @param {?=} type
* @return {?}
*/
ToastrService.prototype.show = /**
* show toast
* @param {?=} message
* @param {?=} title
* @param {?=} override
* @param {?=} type
* @return {?}
*/
function (message, title, override, type) {
if (override === void 0) { override = {}; }
if (type === void 0) { type = ''; }
return this._preBuildNotification(type, message, title, this.applyConfig(override));
};
/** show successful toast */
/**
* show successful toast
* @param {?=} message
* @param {?=} title
* @param {?=} override
* @return {?}
*/
ToastrService.prototype.success = /**
* show successful toast
* @param {?=} message
* @param {?=} title
* @param {?=} override
* @return {?}
*/
function (message, title, override) {
if (override === void 0) { override = {}; }
/** @type {?} */
var type = this.toastrConfig.iconClasses.success || '';
return this._preBuildNotification(type, message, title, this.applyConfig(override));
};
/** show error toast */
/**
* show error toast
* @param {?=} message
* @param {?=} title
* @param {?=} override
* @return {?}
*/
ToastrService.prototype.error = /**
* show error toast
* @param {?=} message
* @param {?=} title
* @param {?=} override
* @return {?}
*/
function (message, title, override) {
if (override === void 0) { override = {}; }
/** @type {?} */
var type = this.toastrConfig.iconClasses.error || '';
return this._preBuildNotification(type, message, title, this.applyConfig(override));
};
/** show info toast */
/**
* show info toast
* @param {?=} message
* @param {?=} title
* @param {?=} override
* @return {?}
*/
ToastrService.prototype.info = /**
* show info toast
* @param {?=} message
* @param {?=} title
* @param {?=} override
* @return {?}
*/
function (message, title, override) {
if (override === void 0) { override = {}; }
/** @type {?} */
var type = this.toastrConfig.iconClasses.info || '';
return this._preBuildNotification(type, message, title, this.applyConfig(override));
};
/** show warning toast */
/**
* show warning toast
* @param {?=} message
* @param {?=} title
* @param {?=} override
* @return {?}
*/
ToastrService.prototype.warning = /**
* show warning toast
* @param {?=} message
* @param {?=} title
* @param {?=} override
* @return {?}
*/
function (message, title, override) {
if (override === void 0) { override = {}; }
/** @type {?} */
var type = this.toastrConfig.iconClasses.warning || '';
return this._preBuildNotification(type, message, title, this.applyConfig(override));
};
/**
* Remove all or a single toast by id
*/
/**
* Remove all or a single toast by id
* @param {?=} toastId
* @return {?}
*/
ToastrService.prototype.clear = /**
* Remove all or a single toast by id
* @param {?=} toastId
* @return {?}
*/
function (toastId) {
var e_1, _a;
try {
// Call every toastRef manualClose function
for (var _b = __values(this.toasts), _c = _b.next(); !_c.done; _c = _b.next()) {
var toast = _c.value;
if (toastId !== undefined) {
if (toast.toastId === toastId) {
toast.toastRef.manualClose();
return;
}
}
else {
toast.toastRef.manualClose();
}
}
}
catch (e_1_1) { e_1 = { error: e_1_1 }; }
finally {
try {
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
}
finally { if (e_1) throw e_1.error; }
}
};
/**
* Remove and destroy a single toast by id
*/
/**
* Remove and destroy a single toast by id
* @param {?} toastId
* @return {?}
*/
ToastrService.prototype.remove = /**
* Remove and destroy a single toast by id
* @param {?} toastId
* @return {?}
*/
function (toastId) {
/** @type {?} */
var 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]) {
/** @type {?} */
var p = this.toasts[this.currentlyActive].toastRef;
if (!p.isInactive()) {
this.currentlyActive = this.currentlyActive + 1;
p.activate();
}
}
return true;
};
/**
* Finds a duplicate toast if one exists
*/
/**
* Finds a duplicate toast if one exists
* @param {?} message
* @param {?} resetOnDuplicate
* @return {?}
*/
ToastrService.prototype.findDuplicate = /**
* Finds a duplicate toast if one exists
* @param {?} message
* @param {?} resetOnDuplicate
* @return {?}
*/
function (message, resetOnDuplicate) {
for (var i = 0; i < this.toasts.length; i++) {
/** @type {?} */
var toast = this.toasts[i];
if (toast.message === message) {
if (resetOnDuplicate && toast.toastRef.componentInstance.resetTimeout) {
toast.toastRef.resetTimeout();
}
return toast;
}
}
return null;
};
/** create a clone of global config and apply individual settings */
/**
* create a clone of global config and apply individual settings
* @param {?=} override
* @return {?}
*/
ToastrService.prototype.applyConfig = /**
* create a clone of global config and apply individual settings
* @param {?=} override
* @return {?}
*/
function (override) {
if (override === void 0) { override = {}; }
return __assign({}, this.toastrConfig, override);
};
/**
* Find toast object by id
*/
/**
* Find toast object by id
* @param {?} toastId
* @return {?}
*/
ToastrService.prototype._findToast = /**
* Find toast object by id
* @param {?} toastId
* @return {?}
*/
function (toastId) {
for (var 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
*/
/**
* Determines the need to run inside angular's zone then builds the toast
* @param {?} toastType
* @param {?} message
* @param {?} title
* @param {?} config
* @return {?}
*/
ToastrService.prototype._preBuildNotification = /**
* Determines the need to run inside angular's zone then builds the toast
* @param {?} toastType
* @param {?} message
* @param {?} title
* @param {?} config
* @return {?}
*/
function (toastType, message, title, config) {
var _this = this;
if (config.onActivateTick) {
return this.ngZone.run(function () {
return _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.
*/
/**
* Creates and attaches toast data to component
* returns the active toast, or in case preventDuplicates is enabled the original/non-duplicate active toast.
* @param {?} toastType
* @param {?} message
* @param {?} title
* @param {?} config
* @return {?}
*/
ToastrService.prototype._buildNotification = /**
* Creates and attaches toast data to component
* returns the active toast, or in case preventDuplicates is enabled the original/non-duplicate active toast.
* @param {?} toastType
* @param {?} message
* @param {?} title
* @param {?} config
* @return {?}
*/
function (toastType, message, title, config) {
var _this = this;
if (!config.toastComponent) {
throw new Error('toastComponent required');
}
// max opened and auto dismiss = true
if (message &&
this.toastrConfig.preventDuplicates) {
/** @type {?} */
var duplicate = this.findDuplicate(message, this.toastrConfig.resetTimeoutOnDuplicate);
if (duplicate !== null) {
return duplicate;
}
}
this.previousToastMessage = message;
/** @type {?} */
var keepInactive = false;
if (this.toastrConfig.maxOpened &&
this.currentlyActive >= this.toastrConfig.maxOpened) {
keepInactive = true;
if (this.toastrConfig.autoDismiss) {
this.clear(this.toasts[0].toastId);
}
}
/** @type {?} */
var overlayRef = this.overlay.create(config.position, this.overlayContainer);
this.index = this.index + 1;
/** @type {?} */
var sanitizedMessage = message;
if (message && config.enableHtml) {
sanitizedMessage = this.sanitizer.sanitize(SecurityContext.HTML, message);
}
/** @type {?} */
var toastRef = new ToastrRef(overlayRef);
/** @type {?} */
var toastPackage = new ToastPackage(this.index, config, sanitizedMessage, title, toastType, toastRef);
/** @type {?} */
var toastInjector = new ToastrInjector(toastPackage, this._injector);
/** @type {?} */
var component = new ComponentPortal$1(config.toastComponent, toastInjector);
/** @type {?} */
var portal = overlayRef.attach(component, this.toastrConfig.newestOnTop);
toastRef.componentInstance = ((/** @type {?} */ (portal)))._component;
/** @type {?} */
var ins = {
toastId: this.index,
message: message || '',
toastRef: toastRef,
onShown: toastRef.afterActivate(),
onHidden: toastRef.afterClosed(),
onTap: toastPackage.onTap(),
onAction: toastPackage.onAction(),
portal: portal
};
if (!keepInactive) {
setTimeout(function () {
ins.toastRef.activate();
_this.currentlyActive = _this.currentlyActive + 1;
});
}
this.toasts.push(ins);
return ins;
};
ToastrService.decorators = [
{ type: Injectable, args: [{ providedIn: 'root' },] },
];
/** @nocollapse */
ToastrService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: Inject, args: [TOAST_CONFIG,] }] },
{ type: Overlay$1 },
{ type: Injector },
{ type: DomSanitizer },
{ type: NgZone }
]; };
/** @nocollapse */ ToastrService.ngInjectableDef = defineInjectable({ factory: function ToastrService_Factory() { return new ToastrService(inject(TOAST_CONFIG), inject(Overlay$1), inject(INJECTOR), inject(DomSanitizer), inject(NgZone)); }, token: ToastrService, providedIn: "root" });
return ToastrService;
}());
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,extraRequire,missingReturn,uselessCode} checked by tsc
*/
var ToastrComponent = /** @class */ (function () {
function ToastrComponent(toastrService, toastPackage, ngZone) {
var _this = this;
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(function () {
_this.activateToast();
});
this.sub1 = toastPackage.toastRef.manualClosed().subscribe(function () {
_this.remove();
});
this.sub2 = toastPackage.toastRef.timeoutReset().subscribe(function () {
_this.resetTimeout();
});
}
/**
* @return {?}
*/
ToastrComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.sub.unsubscribe();
this.sub1.unsubscribe();
this.sub2.unsubscribe();
clearInterval(this.intervalId);
clearTimeout(this.timeout);
};
/**
* activates toast and sets timeout
*/
/**
* activates toast and sets timeout
* @return {?}
*/
ToastrComponent.prototype.activateToast = /**
* activates toast and sets timeout
* @return {?}
*/
function () {
var _this = this;
this.state = __assign({}, this.state, { value: 'active' });
if (!this.options.disableTimeOut && this.options.timeOut) {
this.outsideTimeout(function () { return _this.remove(); }, this.options.timeOut);
this.hideTime = new Date().getTime() + this.options.timeOut;
if (this.options.progressBar) {
this.outsideInterval(function () { return _this.updateProgress(); }, 10);
}
}
};
/**
* updates progress bar width
*/
/**
* updates progress bar width
* @return {?}
*/
ToastrComponent.prototype.updateProgress = /**
* updates progress bar width
* @return {?}
*/
function () {
if (this.width === 0 || this.width === 100 || !this.options.timeOut) {
return;
}
/** @type {?} */
var now = new Date().getTime();
/** @type {?} */
var 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;
}
};
/**
* @return {?}
*/
ToastrComponent.prototype.resetTimeout = /**
* @return {?}
*/
function () {
var _this = this;
clearTimeout(this.timeout);
clearInterval(this.intervalId);
this.state = __assign({}, this.state, { value: 'active' });
this.outsideTimeout(function () { return _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(function () { return _this.updateProgress(); }, 10);
}
};
/**
* tells toastrService to remove this toast after animation time
*/
/**
* tells toastrService to remove this toast after animation time
* @return {?}
*/
ToastrComponent.prototype.remove = /**
* tells toastrService to remove this toast after animation time
* @return {?}
*/
function () {
var _this = this;
if (this.state.value === 'removed') {
return;
}
clearTimeout(this.timeout);
this.state = __assign({}, this.state, { value: 'removed' });
this.outsideTimeout(function () { return _this.toastrService.remove(_this.toastPackage.toastId); }, +this.toastPackage.config.easeTime);
};
/**
* @return {?}
*/
ToastrComponent.prototype.tapToast = /**
* @return {?}
*/
function () {
if (this.state.value === 'removed') {
return;
}
this.toastPackage.triggerTap();
if (this.options.tapToDismiss) {
this.remove();
}
};
/**
* @return {?}
*/
ToastrComponent.prototype.stickAround = /**
* @return {?}
*/
function () {
if (this.state.value === 'removed') {
return;
}
clearTimeout(this.timeout);
this.options.timeOut = 0;
this.hideTime = 0;
// disable progressBar
clearInterval(this.intervalId);
this.width = 0;
};
/**
* @return {?}
*/
ToastrComponent.prototype.delayedHideToast = /**
* @return {?}
*/
function () {
var _thi