UNPKG

@addapptables/notifier

Version:
1,064 lines (1,042 loc) 35.2 kB
import { style, trigger, transition, animate, keyframes } from '@angular/animations'; import { Subject, interval } from 'rxjs'; import { filter, take, takeUntil, tap } from 'rxjs/operators'; import { InjectionToken, EventEmitter, TemplateRef, Component, ChangeDetectionStrategy, ViewEncapsulation, Inject, ComponentFactoryResolver, ViewChild, HostListener, Injectable, ɵɵdefineInjectable, ɵɵinject, ApplicationRef, Injector, NgModule } from '@angular/core'; import { PortalInjector, DomPortalOutlet, ComponentPortal } from '@angular/cdk/portal'; import { DynamicDirective, CoreModule } from '@addapptables/core'; import { DOCUMENT, CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const slideInDown = [ style({ transform: 'translate3d(0,-100%, 0)', visibility: 'visible', offset: 0 }), style({ transform: 'translate3d(0, 0, 0)', offset: 1 }) ]; /** @type {?} */ const zoomOut = [ style({ opacity: 1, offset: 0 }), style({ transform: 'scale3d(0.3, 0.3, 0.3)', offset: .5 }), style({ opacity: 0, offset: 1 }) ]; /** @type {?} */ const slideInUp = [ style({ transform: 'translate3d(0, 100%, 0)', visibility: 'visible', offset: 0 }), style({ transform: 'translate3d(0, 0, 0)', offset: 1 }) ]; /** @type {?} */ const notifierAnimation = { notifierAnimator: notifierTriggerAnimation() }; /** * @return {?} */ function notifierTriggerAnimation() { return trigger('notifierAnimator', [ transition('* => slideInUp', animate(150, keyframes(slideInUp))), transition('* => slideInDown', animate(150, keyframes(slideInDown))), transition('* => exit', animate(150, keyframes(zoomOut))) ]); } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const NOTIFIER = 'addapptable-notifier-'; /** @type {?} */ const NOTIFIER_CONTAINER = 'addapptable-notifier-container'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NotifierConfiguration { } if (false) { /** @type {?} */ NotifierConfiguration.prototype.position; /** @type {?} */ NotifierConfiguration.prototype.iconValue; /** @type {?} */ NotifierConfiguration.prototype.classIcon; /** @type {?} */ NotifierConfiguration.prototype.timeout; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {number} */ const NotifierPositionType = { topRight: 0, topLeft: 1, bottomRight: 2, bottomLeft: 3, }; NotifierPositionType[NotifierPositionType.topRight] = 'topRight'; NotifierPositionType[NotifierPositionType.topLeft] = 'topLeft'; NotifierPositionType[NotifierPositionType.bottomRight] = 'bottomRight'; NotifierPositionType[NotifierPositionType.bottomLeft] = 'bottomLeft'; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @enum {string} */ const NotifierType = { primary: 'addapptable-notifier-primary', accent: 'addapptable-notifier-accent', success: 'addapptable-notifier-success', warning: 'addapptable-notifier-warning', danger: 'addapptable-notifier-danger', info: 'addapptable-notifier-info', }; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @template D, T */ class Notifier { } if (false) { /** @type {?} */ Notifier.prototype.message; /** @type {?} */ Notifier.prototype.type; /** @type {?} */ Notifier.prototype.data; /** @type {?} */ Notifier.prototype.templateOrComponent; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NotifierRef { /** * @param {?} component * @param {?} portal * @param {?} document * @param {?} id */ constructor(component, portal, document, id) { this._afterClose = new Subject(); this._component = component; this._portal = portal; this._component._id = id; this._document = document; this._component._close.subscribe(this.close.bind(this)); } /** * @return {?} */ get component() { return this._component; } /** * @return {?} */ afterClosed() { return this._afterClose.asObservable(); } /** * @return {?} */ close() { this._component._animationStateChanged.pipe(filter((/** * @param {?} x * @return {?} */ x => x.phaseName === 'done')), take(1)) .subscribe((/** * @return {?} */ () => { this._afterClose.next(this._component._id); this._afterClose.complete(); this._destroyPortal(); })); this._component.startExitAnimation(); } /** * @param {?} style * @return {?} */ changedStyle(style) { this._component._style = style; } /** * @private * @return {?} */ _destroyPortal() { /** @type {?} */ const componentContainer = this._document.getElementById(this._component._id); this._portal.detach(); componentContainer && componentContainer.parentNode.removeChild(componentContainer); } } if (false) { /** * @type {?} * @private */ NotifierRef.prototype._component; /** * @type {?} * @private */ NotifierRef.prototype._portal; /** * @type {?} * @private */ NotifierRef.prototype._document; /** * @type {?} * @private */ NotifierRef.prototype._afterClose; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ const ADDAPPTABLE_CONFIGURATION_NOTIFIER_DATA = new InjectionToken('AddapptableConfigurationNotifierData'); /** @type {?} */ const ADDAPPTABLE_NOTIFIER_DATA = new InjectionToken('ADDAPPTABLE_NOTIFIER'); /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NotifierComponent { /** * @param {?} configuration * @param {?} data * @param {?} componentFactoryResolver */ constructor(configuration, data, componentFactoryResolver) { this.data = data; this.componentFactoryResolver = componentFactoryResolver; this._state = 'slideInUp'; this._close = new EventEmitter(); this._animationStateChanged = new EventEmitter(); this._style = {}; this.subject = new Subject(); this.seconds = interval(5000); this.configuration = { position: NotifierPositionType.bottomRight, timeout: 5000, classIcon: 'material-icons', iconValue: 'notifications' }; this.configuration = Object.assign({ position: NotifierPositionType.bottomRight, timeout: 5000, classIcon: 'material-icons', iconValue: 'notifications' }, configuration); this.seconds = interval(this.configuration.timeout); } /** * @return {?} */ ngOnInit() { if (this.data.templateOrComponent) { this.resolveComponent(this.data.templateOrComponent, this.appDynamic.viewContainerRef); } } /** * @return {?} */ ngAfterViewInit() { this._timeOut(); } /** * @return {?} */ onMouseOver() { this.subject.next(); this.subject.complete(); } /** * @return {?} */ onMouseLeave() { this.subject = new Subject(); this._timeOut(); } /** * @private * @return {?} */ _timeOut() { this.seconds.pipe(takeUntil(this.subject), take(1), tap((/** * @return {?} */ () => this.close()))).subscribe(); } /** * @return {?} */ close() { this._close.emit(); } /** * @return {?} */ startExitAnimation() { this._state = 'exit'; } /** * @private * @param {?} component * @param {?} viewContainerRef * @return {?} */ resolveComponent(component, viewContainerRef) { if (!component) { return; } viewContainerRef.clear(); if (component instanceof TemplateRef) { viewContainerRef.createEmbeddedView(component, { $implicit: this.data }); } else { /** @type {?} */ const componentFactory = component && this.componentFactoryResolver.resolveComponentFactory(component); /** @type {?} */ const injector = this.createInjector(viewContainerRef.injector); viewContainerRef.createComponent(componentFactory, null, injector); } } /** * @private * @param {?} injector * @return {?} */ createInjector(injector) { /** @type {?} */ const injectionTokens = new WeakMap([ [ADDAPPTABLE_NOTIFIER_DATA, this.data] ]); return new PortalInjector(injector, injectionTokens); } /** * @return {?} */ ngOnDestroy() { this.subject.next(); this.subject.complete(); } } NotifierComponent.decorators = [ { type: Component, args: [{ selector: 'addapptable-notifier', template: "<div [class]=\"'addapptable-notifier '+ data.type\" [@notifierAnimator]=\"_state\" (@notifierAnimator.start)=\"_animationStateChanged.emit($event)\"\n (@notifierAnimator.done)=\"_animationStateChanged.emit($event)\" [ngStyle]=\"_style\">\n <i *ngIf=\"configuration.classIcon\" [class]=\"configuration.classIcon\">{{configuration.iconValue}}</i>\n <button type=\"button\" (click)=\"close()\">x</button>\n <span class=\"message\">\n <ng-template addapptablesDynamic></ng-template>\n <span *ngIf=\"!data.templateOrComponent\">{{data.message}}</span>\n </span>\n</div>", changeDetection: ChangeDetectionStrategy.Default, animations: [notifierAnimation.notifierAnimator], encapsulation: ViewEncapsulation.None, styles: [".addapptable-notifier{margin:1em;display:inline-block;position:fixed;z-index:1031;border-radius:3px;transition:.19s ease-in-out}.addapptable-notifier-success{background-color:#5cb85c;color:#5cb85c}.addapptable-notifier-info{background-color:#20a9d2;color:#20a9d2}.addapptable-notifier-warning{background-color:#e09d3d;color:#e09d3d}.addapptable-notifier-danger{background-color:#d43934;color:#d43934}.addapptable-notifier>i{display:block;left:15px;position:absolute;margin-top:-26px;font-size:20px;background-color:#fff!important;padding:9px;border-radius:50%;max-width:38px;box-shadow:0 16px 38px -12px rgba(0,0,0,.56),0 4px 25px 0 rgba(0,0,0,.12),0 8px 10px -5px rgba(0,0,0,.2)}.addapptable-notifier>button{float:right;min-width:auto;color:#fff!important;text-shadow:none;opacity:.9;box-sizing:border-box;position:relative;cursor:pointer;outline:0;border:none;white-space:nowrap;text-decoration:none;vertical-align:baseline;text-align:center;margin:0;line-height:36px;padding:0 16px;border-radius:4px;overflow:visible;background-color:transparent}.addapptable-notifier .message{display:block;color:#fff;min-width:376px;max-width:500px;padding:1.5em;text-align:justify}"] }] } ]; /** @nocollapse */ NotifierComponent.ctorParameters = () => [ { type: NotifierConfiguration, decorators: [{ type: Inject, args: [ADDAPPTABLE_CONFIGURATION_NOTIFIER_DATA,] }] }, { type: Notifier, decorators: [{ type: Inject, args: [ADDAPPTABLE_NOTIFIER_DATA,] }] }, { type: ComponentFactoryResolver } ]; NotifierComponent.propDecorators = { appDynamic: [{ type: ViewChild, args: [DynamicDirective, { static: true },] }], onMouseOver: [{ type: HostListener, args: ['mouseover',] }], onMouseLeave: [{ type: HostListener, args: ['mouseleave',] }] }; if (false) { /** @type {?} */ NotifierComponent.prototype._id; /** @type {?} */ NotifierComponent.prototype._state; /** @type {?} */ NotifierComponent.prototype._close; /** @type {?} */ NotifierComponent.prototype._animationStateChanged; /** @type {?} */ NotifierComponent.prototype._style; /** @type {?} */ NotifierComponent.prototype.subject; /** @type {?} */ NotifierComponent.prototype.seconds; /** @type {?} */ NotifierComponent.prototype.configuration; /** @type {?} */ NotifierComponent.prototype.appDynamic; /** @type {?} */ NotifierComponent.prototype.data; /** * @type {?} * @private */ NotifierComponent.prototype.componentFactoryResolver; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NotifierContainerService { /** * @param {?} _document */ constructor(_document) { this._document = _document; } /** * @return {?} */ getContainerElement() { if (!this._containerElement) { this._createContainer(); } return this._containerElement; } /** * @protected * @return {?} */ _createContainer() { /** @type {?} */ const container = this._document.createElement('div'); container.classList.add(NOTIFIER_CONTAINER); this._document.body.appendChild(container); this._containerElement = container; } /** * @return {?} */ ngOnDestroy() { if (this._containerElement && this._containerElement.parentNode) { this._containerElement.parentNode.removeChild(this._containerElement); } } } NotifierContainerService.decorators = [ { type: Injectable, args: [{ providedIn: 'root' },] } ]; /** @nocollapse */ NotifierContainerService.ctorParameters = () => [ { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] } ]; /** @nocollapse */ NotifierContainerService.ngInjectableDef = ɵɵdefineInjectable({ factory: function NotifierContainerService_Factory() { return new NotifierContainerService(ɵɵinject(DOCUMENT)); }, token: NotifierContainerService, providedIn: "root" }); if (false) { /** * @type {?} * @protected */ NotifierContainerService.prototype._containerElement; /** * @type {?} * @protected */ NotifierContainerService.prototype._document; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** @type {?} */ let nextUniqueId = 0; class NotifierPortalService { /** * @param {?} _notifierContainerService * @param {?} _document * @param {?} _injector * @param {?} _componentFactoryResolver */ constructor(_notifierContainerService, _document, _injector, _componentFactoryResolver) { this._notifierContainerService = _notifierContainerService; this._document = _document; this._injector = _injector; this._componentFactoryResolver = _componentFactoryResolver; } /** * @return {?} */ create() { /** @type {?} */ const pane = this._createPaneElement(); /** @type {?} */ const portal = this._createPortalOutlet(pane); return portal; } /** * @private * @param {?} pane * @return {?} */ _createPortalOutlet(pane) { if (!this._appRef) { this._appRef = this._injector.get(ApplicationRef); } return new DomPortalOutlet(pane, this._componentFactoryResolver, this._appRef, this._injector); } /** * @private * @return {?} */ _createPaneElement() { /** @type {?} */ const pane = this._document.createElement('div'); pane.id = `${NOTIFIER + nextUniqueId++}`; this._notifierContainerService.getContainerElement().appendChild(pane); return pane; } /** * @return {?} */ get getLastUniqueId() { return `${NOTIFIER + (nextUniqueId - 1)}`; } } NotifierPortalService.decorators = [ { type: Injectable } ]; /** @nocollapse */ NotifierPortalService.ctorParameters = () => [ { type: NotifierContainerService }, { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }, { type: Injector }, { type: ComponentFactoryResolver } ]; if (false) { /** * @type {?} * @private */ NotifierPortalService.prototype._appRef; /** * @type {?} * @private */ NotifierPortalService.prototype._notifierContainerService; /** * @type {?} * @private */ NotifierPortalService.prototype._document; /** * @type {?} * @private */ NotifierPortalService.prototype._injector; /** * @type {?} * @private */ NotifierPortalService.prototype._componentFactoryResolver; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @abstract */ class AbstractStrategy { /** * @param {?} _document */ constructor(_document) { this._document = _document; this.notifiers = []; this.margin = 30; this.maxNotifiers = 5; this.notifiers = []; } /** * @param {?} notifierRef * @return {?} */ newNotifier(notifierRef) { notifierRef.afterClosed().pipe(take(1)).subscribe(this.deletePortal.bind(this)); notifierRef.changedStyle(this.getStyleNewNotifier(notifierRef)); setTimeout((/** * @return {?} */ () => { if (this.notifiers.length >= this.maxNotifiers) { /** @type {?} */ const notifier = this.notifiers.shift(); notifier.close(); } /** @type {?} */ const element = this._document.querySelector(`#${notifierRef.component._id} > addapptable-notifier > .addapptable-notifier`); this.notifiers.forEach((/** * @param {?} notifier * @return {?} */ notifier => { /** @type {?} */ const elementNotifier = this._document .querySelector(`#${notifier.component._id} > addapptable-notifier > .addapptable-notifier`); notifier.changedStyle(this.getStyleNotifierPosition(elementNotifier, element.clientHeight)); })); this.notifiers.push(notifierRef); })); } /** * @private * @param {?} id * @return {?} */ deletePortal(id) { /** @type {?} */ const notifier = this.notifiers.findIndex((/** * @param {?} x * @return {?} */ x => x.component._id === id)); if (notifier >= 0) { /** @type {?} */ const element = this._document .querySelector(`#${this.notifiers[notifier].component._id} > addapptable-notifier > .addapptable-notifier`); /** @type {?} */ const clientHeightElementDelete = element.clientHeight; this.notifiers.splice(notifier, 1); for (let index = notifier - 1; index >= 0; index--) { /** @type {?} */ const notifierStyle = this.notifiers[index]; /** @type {?} */ const elementChange = this._document .querySelector(`#${notifierStyle.component._id} > addapptable-notifier > .addapptable-notifier`); notifierStyle.changedStyle(this.getStyleDeleteNotifier(elementChange, clientHeightElementDelete)); } } } /** * @return {?} */ ngOnDestroy() { this.notifiers.forEach((/** * @param {?} notifier * @return {?} */ notifier => { notifier.close(); })); } } /** @nocollapse */ AbstractStrategy.ctorParameters = () => [ { type: HTMLDocument, decorators: [{ type: Inject, args: [DOCUMENT,] }] } ]; if (false) { /** @type {?} */ AbstractStrategy.prototype.notifiers; /** @type {?} */ AbstractStrategy.prototype.margin; /** @type {?} */ AbstractStrategy.prototype.maxNotifiers; /** * @type {?} * @private */ AbstractStrategy.prototype._document; /** * @abstract * @protected * @param {?} notifierRef * @return {?} */ AbstractStrategy.prototype.getStyleNewNotifier = function (notifierRef) { }; /** * @abstract * @protected * @param {?} divNotifier * @param {?} clientHeight * @return {?} */ AbstractStrategy.prototype.getStyleNotifierPosition = function (divNotifier, clientHeight) { }; /** * @abstract * @protected * @param {?} elementChange * @param {?} clientHeightElementDelete * @return {?} */ AbstractStrategy.prototype.getStyleDeleteNotifier = function (elementChange, clientHeightElementDelete) { }; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class BottomRightStrategy extends AbstractStrategy { /** * @protected * @param {?} notifierRef * @return {?} */ getStyleNewNotifier(notifierRef) { notifierRef.component._state = 'slideInUp'; return { bottom: `0px`, right: '0px' }; } /** * @protected * @param {?} divNotifier * @param {?} clientHeight * @return {?} */ getStyleNotifierPosition(divNotifier, clientHeight) { /** @type {?} */ const lastValueBottom = Number(divNotifier.style.bottom.replace('px', '')); return { bottom: `${clientHeight + lastValueBottom + this.margin}px`, right: '0px' }; } /** * @protected * @param {?} elementChange * @param {?} clientHeightElementDelete * @return {?} */ getStyleDeleteNotifier(elementChange, clientHeightElementDelete) { /** @type {?} */ const valueBottomChange = Number(elementChange.style.bottom.replace('px', '')); return { bottom: `${valueBottomChange - clientHeightElementDelete - this.margin}px`, right: '0px' }; } } BottomRightStrategy.decorators = [ { type: Injectable } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class TopRightStrategy extends AbstractStrategy { /** * @protected * @param {?} notifierRef * @return {?} */ getStyleNewNotifier(notifierRef) { notifierRef.component._state = 'slideInDown'; return { top: `20px`, right: '0px' }; } /** * @protected * @param {?} divNotifier * @param {?} clientHeight * @return {?} */ getStyleNotifierPosition(divNotifier, clientHeight) { /** @type {?} */ const lastValueBottom = Number(divNotifier.style.top.replace('px', '')); return { top: `${clientHeight + lastValueBottom + this.margin}px`, right: '0px' }; } /** * @protected * @param {?} elementChange * @param {?} clientHeightElementDelete * @return {?} */ getStyleDeleteNotifier(elementChange, clientHeightElementDelete) { /** @type {?} */ const valueBottomChange = Number(elementChange.style.top.replace('px', '')); return { top: `${valueBottomChange - clientHeightElementDelete - this.margin}px`, right: '0px' }; } } TopRightStrategy.decorators = [ { type: Injectable } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class BottomLeftStrategy extends AbstractStrategy { /** * @protected * @param {?} notifierRef * @return {?} */ getStyleNewNotifier(notifierRef) { notifierRef.component._state = 'slideInUp'; return { bottom: `0px`, left: '0px' }; } /** * @protected * @param {?} divNotifier * @param {?} clientHeight * @return {?} */ getStyleNotifierPosition(divNotifier, clientHeight) { /** @type {?} */ const lastValueBottom = Number(divNotifier.style.bottom.replace('px', '')); return { bottom: `${clientHeight + lastValueBottom + this.margin}px`, left: '0px' }; } /** * @protected * @param {?} elementChange * @param {?} clientHeightElementDelete * @return {?} */ getStyleDeleteNotifier(elementChange, clientHeightElementDelete) { /** @type {?} */ const valueBottomChange = Number(elementChange.style.bottom.replace('px', '')); return { bottom: `${valueBottomChange - clientHeightElementDelete - this.margin}px`, left: '0px' }; } } BottomLeftStrategy.decorators = [ { type: Injectable } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class TopLeftStrategy extends AbstractStrategy { /** * @protected * @param {?} notifierRef * @return {?} */ getStyleNewNotifier(notifierRef) { notifierRef.component._state = 'slideInDown'; return { top: `20px`, left: '0px' }; } /** * @protected * @param {?} divNotifier * @param {?} clientHeight * @return {?} */ getStyleNotifierPosition(divNotifier, clientHeight) { /** @type {?} */ const lastValueBottom = Number(divNotifier.style.top.replace('px', '')); return { top: `${clientHeight + lastValueBottom + this.margin}px`, left: '0px' }; } /** * @protected * @param {?} elementChange * @param {?} clientHeightElementDelete * @return {?} */ getStyleDeleteNotifier(elementChange, clientHeightElementDelete) { /** @type {?} */ const valueBottomChange = Number(elementChange.style.top.replace('px', '')); return { top: `${valueBottomChange - clientHeightElementDelete - this.margin}px`, left: '0px' }; } } TopLeftStrategy.decorators = [ { type: Injectable } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NotifierService { /** * @param {?} _notifierPortalService * @param {?} _injector * @param {?} _document * @param {?} configuration */ constructor(_notifierPortalService, _injector, _document, configuration) { this._notifierPortalService = _notifierPortalService; this._injector = _injector; this._document = _document; this.defaultConfiguration = { position: NotifierPositionType.bottomRight, timeout: 5000, classIcon: 'material-icons', iconValue: 'notifications' }; this.defaultConfiguration = Object.assign(this.defaultConfiguration, configuration); } /** * @param {?} message * @param {?=} configuration * @return {?} */ openSuccess(message, configuration = (/** @type {?} */ ({}))) { return this.open({ message: message, type: NotifierType.success }, configuration); } /** * @param {?} message * @param {?=} configuration * @return {?} */ openError(message, configuration = (/** @type {?} */ ({}))) { return this.open({ message: message, type: NotifierType.danger }, configuration); } /** * @param {?} message * @param {?=} configuration * @return {?} */ openInfo(message, configuration = (/** @type {?} */ ({}))) { return this.open({ message: message, type: NotifierType.info }, configuration); } /** * @param {?} message * @param {?=} configuration * @return {?} */ openWarning(message, configuration = (/** @type {?} */ ({}))) { return this.open({ message: message, type: NotifierType.warning }, configuration); } /** * @param {?} data * @param {?=} configuration * @return {?} */ open(data, configuration = (/** @type {?} */ ({}))) { /** @type {?} */ const portal = this._notifierPortalService.create(); /** @type {?} */ const componentPortal = this._createComponentPortal(data); /** @type {?} */ const componentRef = portal.attach(componentPortal); /** @type {?} */ const notifierRef = new NotifierRef(componentRef.instance, portal, this._document, this._notifierPortalService.getLastUniqueId); /** @type {?} */ const mergeConfiguration = Object.assign(this.defaultConfiguration, configuration); this._factoryStrategy(mergeConfiguration).newNotifier(notifierRef); return notifierRef; } /** * @private * @param {?} configuration * @return {?} */ _factoryStrategy(configuration) { switch (configuration.position) { case NotifierPositionType.bottomRight: return this._injector.get(BottomRightStrategy); case NotifierPositionType.bottomLeft: return this._injector.get(BottomLeftStrategy); case NotifierPositionType.topLeft: return this._injector.get(TopLeftStrategy); case NotifierPositionType.topRight: return this._injector.get(TopRightStrategy); default: return this._injector.get(BottomRightStrategy); } } /** * @private * @param {?} data * @return {?} */ _createComponentPortal(data) { /** @type {?} */ const injectionTokens = new WeakMap([ [ADDAPPTABLE_NOTIFIER_DATA, data] ]); /** @type {?} */ const injector = new PortalInjector(this._injector, injectionTokens); return new ComponentPortal(NotifierComponent, null, injector); } } NotifierService.decorators = [ { type: Injectable } ]; /** @nocollapse */ NotifierService.ctorParameters = () => [ { type: NotifierPortalService }, { type: Injector }, { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] }, { type: NotifierConfiguration, decorators: [{ type: Inject, args: [ADDAPPTABLE_CONFIGURATION_NOTIFIER_DATA,] }] } ]; if (false) { /** @type {?} */ NotifierService.prototype.defaultConfiguration; /** * @type {?} * @private */ NotifierService.prototype._notifierPortalService; /** * @type {?} * @private */ NotifierService.prototype._injector; /** * @type {?} * @private */ NotifierService.prototype._document; } /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ class NotifierModule { /** * @param {?=} config * @return {?} */ static forRoot(config = { position: NotifierPositionType.bottomRight, timeout: 5000, classIcon: 'material-icons', iconValue: 'notifications' }) { return { ngModule: NotifierModule, providers: [ { provide: ADDAPPTABLE_CONFIGURATION_NOTIFIER_DATA, useValue: config } ] }; } } NotifierModule.decorators = [ { type: NgModule, args: [{ declarations: [NotifierComponent], imports: [ CommonModule, CoreModule ], entryComponents: [NotifierComponent], providers: [ NotifierService, NotifierPortalService, BottomRightStrategy, TopRightStrategy, TopLeftStrategy, BottomLeftStrategy ] },] } ]; /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * @fileoverview added by tsickle * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ export { ADDAPPTABLE_CONFIGURATION_NOTIFIER_DATA, ADDAPPTABLE_NOTIFIER_DATA, NOTIFIER, NOTIFIER_CONTAINER, Notifier, NotifierComponent, NotifierConfiguration, NotifierContainerService, NotifierModule, NotifierPortalService, NotifierPositionType, NotifierRef, NotifierService, NotifierType, notifierAnimation, notifierTriggerAnimation, slideInDown, slideInUp, zoomOut, BottomRightStrategy as ɵa, AbstractStrategy as ɵb, TopRightStrategy as ɵc, TopLeftStrategy as ɵd, BottomLeftStrategy as ɵe }; //# sourceMappingURL=addapptables-notifier.js.map