UNPKG

@hxui/angular

Version:

* * *

1,285 lines (1,271 loc) 1.12 MB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('@angular/common'), require('@angular/platform-browser'), require('@angular/animations'), require('lodash'), require('rxjs/index'), require('rxjs/internal/operators'), require('rxjs/operators'), require('@angular/cdk/portal'), require('@angular/cdk/overlay'), require('@angular/forms'), require('moment'), require('@angular/cdk/bidi'), require('@angular/cdk/a11y'), require('array-sort-by'), require('@angular/common/http'), require('@angular/router'), require('@angular/platform-browser/animations')) : typeof define === 'function' && define.amd ? define('@hxui/angular', ['exports', '@angular/core', 'rxjs', '@angular/common', '@angular/platform-browser', '@angular/animations', 'lodash', 'rxjs/index', 'rxjs/internal/operators', 'rxjs/operators', '@angular/cdk/portal', '@angular/cdk/overlay', '@angular/forms', 'moment', '@angular/cdk/bidi', '@angular/cdk/a11y', 'array-sort-by', '@angular/common/http', '@angular/router', '@angular/platform-browser/animations'], factory) : (factory((global.hxui = global.hxui || {}, global.hxui.angular = {}),global.ng.core,global.rxjs,global.ng.common,global.ng.platformBrowser,global.ng.animations,null,global.rxjs.index,global.rxjs['internal/operators'],global.rxjs.operators,global.ng.cdk.portal,global.ng.cdk.overlay,global.ng.forms,null,global.ng.cdk.bidi,global.ng.cdk.a11y,null,global.ng.common.http,global.ng.router,global.ng.platformBrowser.animations)); }(this, (function (exports,i0,rxjs,i2,i3,animations,_,index,operators,operators$1,portal,overlay,forms,moment_,bidi,a11y,sortBy,http,router,animations$1) { 'use strict'; sortBy = sortBy && sortBy.hasOwnProperty('default') ? sortBy['default'] : sortBy; /** * @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: i0.Directive, args: [{ selector: '[hxaToastrContainer]', exportAs: 'hxaToastrContainer', },] }, ]; /** @nocollapse */ ToastrContainerDirective.ctorParameters = function () { return [ { type: i0.ElementRef } ]; }; return ToastrContainerDirective; }()); var ToastrContainerModule = /** @class */ (function () { function ToastrContainerModule() { } ToastrContainerModule.decorators = [ { type: i0.NgModule, args: [{ declarations: [ToastrContainerDirective], exports: [ToastrContainerDirective], },] }, ]; return ToastrContainerModule; }()); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } var __assign = function () { __assign = Object.assign || function __assign(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; function __decorate(decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; } function __values(o) { var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0; if (m) return m.call(o); return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; } function __read(o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; } function __spread() { for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); return ar; } /** * @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 rxjs.Subject(); this._onAction = new rxjs.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 i0.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 = /** @class */ (function () { function ComponentPortal(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.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.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.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.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; }()); /** * 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$$1, newestOnTop) { this._attachedPortal = portal$$1; return this.attachComponentPortal(portal$$1, 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$$1, newestOnTop) { var _this = this; /** @type {?} */ var componentFactory = this._componentFactoryResolver.resolveComponentFactory(portal$$1.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$$1.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: i0.Injectable, args: [{ providedIn: 'root' },] }, ]; /** @nocollapse */ OverlayContainer.ctorParameters = function () { return [ { type: undefined, decorators: [{ type: i0.Inject, args: [i2.DOCUMENT,] }] } ]; }; /** @nocollapse */ OverlayContainer.ngInjectableDef = i0.defineInjectable({ factory: function OverlayContainer_Factory() { return new OverlayContainer(i0.inject(i2.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$$1, newestOnTop) { if (newestOnTop === void 0) { newestOnTop = true; } return this._portalHost.attach(portal$$1, 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 = /** @class */ (function () { function Overlay(_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.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.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.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.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.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.decorators = [ { type: i0.Injectable, args: [{ providedIn: 'root' },] }, ]; /** @nocollapse */ Overlay.ctorParameters = function () { return [ { type: OverlayContainer }, { type: i0.ComponentFactoryResolver }, { type: i0.ApplicationRef }, { type: undefined, decorators: [{ type: i0.Inject, args: [i2.DOCUMENT,] }] } ]; }; /** @nocollapse */ Overlay.ngInjectableDef = i0.defineInjectable({ factory: function Overlay_Factory() { return new Overlay(i0.inject(OverlayContainer), i0.inject(i0.ComponentFactoryResolver), i0.inject(i0.ApplicationRef), i0.inject(i2.DOCUMENT)); }, token: Overlay, providedIn: "root" }); return Overlay; }()); /** * @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 rxjs.Subject(); /** * triggered when toast is activated */ this._activate = new rxjs.Subject(); /** * notifies the toast that it should close before the timeout */ this._manualClose = new rxjs.Subject(); /** * notifies the toast that it should reset the timeouts */ this._resetTimeout = new rxjs.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$$1, _injector, sanitizer, ngZone) { this.overlay = overlay$$1; 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