@addapptables/notifier
Version:
Material notifier library for angular
1,493 lines • 58.6 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/animations'), require('rxjs'), require('rxjs/operators'), require('@angular/core'), require('@angular/cdk/portal'), require('@addapptables/core'), require('@angular/common')) :
typeof define === 'function' && define.amd ? define('@addapptables/notifier', ['exports', '@angular/animations', 'rxjs', 'rxjs/operators', '@angular/core', '@angular/cdk/portal', '@addapptables/core', '@angular/common'], factory) :
(global = global || self, factory((global.addapptables = global.addapptables || {}, global.addapptables.notifier = {}), global.ng.animations, global.rxjs, global.rxjs.operators, global.ng.core, global.ng.cdk.portal, global['addapptables-core'], global.ng.common));
}(this, function (exports, animations, rxjs, operators, core, portal, core$1, common) { 'use strict';
/*! *****************************************************************************
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 __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
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 __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
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;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var slideInDown = [
animations.style({
transform: 'translate3d(0,-100%, 0)',
visibility: 'visible',
offset: 0
}),
animations.style({
transform: 'translate3d(0, 0, 0)',
offset: 1
})
];
/** @type {?} */
var zoomOut = [
animations.style({
opacity: 1,
offset: 0
}),
animations.style({
transform: 'scale3d(0.3, 0.3, 0.3)',
offset: .5
}),
animations.style({
opacity: 0,
offset: 1
})
];
/** @type {?} */
var slideInUp = [
animations.style({
transform: 'translate3d(0, 100%, 0)',
visibility: 'visible',
offset: 0
}),
animations.style({
transform: 'translate3d(0, 0, 0)',
offset: 1
})
];
/** @type {?} */
var notifierAnimation = {
notifierAnimator: notifierTriggerAnimation()
};
/**
* @return {?}
*/
function notifierTriggerAnimation() {
return animations.trigger('notifierAnimator', [
animations.transition('* => slideInUp', animations.animate(150, animations.keyframes(slideInUp))),
animations.transition('* => slideInDown', animations.animate(150, animations.keyframes(slideInDown))),
animations.transition('* => exit', animations.animate(150, animations.keyframes(zoomOut)))
]);
}
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
var NOTIFIER = 'addapptable-notifier-';
/** @type {?} */
var NOTIFIER_CONTAINER = 'addapptable-notifier-container';
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NotifierConfiguration = /** @class */ (function () {
function NotifierConfiguration() {
}
return 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} */
var 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} */
var 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
*/
var /**
* @template D, T
*/
Notifier = /** @class */ (function () {
function Notifier() {
}
return 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
*/
var NotifierRef = /** @class */ (function () {
function NotifierRef(component, portal, document, id) {
this._afterClose = new rxjs.Subject();
this._component = component;
this._portal = portal;
this._component._id = id;
this._document = document;
this._component._close.subscribe(this.close.bind(this));
}
Object.defineProperty(NotifierRef.prototype, "component", {
get: /**
* @return {?}
*/
function () {
return this._component;
},
enumerable: true,
configurable: true
});
/**
* @return {?}
*/
NotifierRef.prototype.afterClosed = /**
* @return {?}
*/
function () {
return this._afterClose.asObservable();
};
/**
* @return {?}
*/
NotifierRef.prototype.close = /**
* @return {?}
*/
function () {
var _this = this;
this._component._animationStateChanged.pipe(operators.filter((/**
* @param {?} x
* @return {?}
*/
function (x) { return x.phaseName === 'done'; })), operators.take(1))
.subscribe((/**
* @return {?}
*/
function () {
_this._afterClose.next(_this._component._id);
_this._afterClose.complete();
_this._destroyPortal();
}));
this._component.startExitAnimation();
};
/**
* @param {?} style
* @return {?}
*/
NotifierRef.prototype.changedStyle = /**
* @param {?} style
* @return {?}
*/
function (style) {
this._component._style = style;
};
/**
* @private
* @return {?}
*/
NotifierRef.prototype._destroyPortal = /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var componentContainer = this._document.getElementById(this._component._id);
this._portal.detach();
componentContainer && componentContainer.parentNode.removeChild(componentContainer);
};
return NotifierRef;
}());
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 {?} */
var ADDAPPTABLE_CONFIGURATION_NOTIFIER_DATA = new core.InjectionToken('AddapptableConfigurationNotifierData');
/** @type {?} */
var ADDAPPTABLE_NOTIFIER_DATA = new core.InjectionToken('ADDAPPTABLE_NOTIFIER');
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NotifierComponent = /** @class */ (function () {
function NotifierComponent(configuration, data, componentFactoryResolver) {
this.data = data;
this.componentFactoryResolver = componentFactoryResolver;
this._state = 'slideInUp';
this._close = new core.EventEmitter();
this._animationStateChanged = new core.EventEmitter();
this._style = {};
this.subject = new rxjs.Subject();
this.seconds = rxjs.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 = rxjs.interval(this.configuration.timeout);
}
/**
* @return {?}
*/
NotifierComponent.prototype.ngOnInit = /**
* @return {?}
*/
function () {
if (this.data.templateOrComponent) {
this.resolveComponent(this.data.templateOrComponent, this.appDynamic.viewContainerRef);
}
};
/**
* @return {?}
*/
NotifierComponent.prototype.ngAfterViewInit = /**
* @return {?}
*/
function () {
this._timeOut();
};
/**
* @return {?}
*/
NotifierComponent.prototype.onMouseOver = /**
* @return {?}
*/
function () {
this.subject.next();
this.subject.complete();
};
/**
* @return {?}
*/
NotifierComponent.prototype.onMouseLeave = /**
* @return {?}
*/
function () {
this.subject = new rxjs.Subject();
this._timeOut();
};
/**
* @private
* @return {?}
*/
NotifierComponent.prototype._timeOut = /**
* @private
* @return {?}
*/
function () {
var _this = this;
this.seconds.pipe(operators.takeUntil(this.subject), operators.take(1), operators.tap((/**
* @return {?}
*/
function () { return _this.close(); }))).subscribe();
};
/**
* @return {?}
*/
NotifierComponent.prototype.close = /**
* @return {?}
*/
function () {
this._close.emit();
};
/**
* @return {?}
*/
NotifierComponent.prototype.startExitAnimation = /**
* @return {?}
*/
function () {
this._state = 'exit';
};
/**
* @private
* @param {?} component
* @param {?} viewContainerRef
* @return {?}
*/
NotifierComponent.prototype.resolveComponent = /**
* @private
* @param {?} component
* @param {?} viewContainerRef
* @return {?}
*/
function (component, viewContainerRef) {
if (!component) {
return;
}
viewContainerRef.clear();
if (component instanceof core.TemplateRef) {
viewContainerRef.createEmbeddedView(component, { $implicit: this.data });
}
else {
/** @type {?} */
var componentFactory = component && this.componentFactoryResolver.resolveComponentFactory(component);
/** @type {?} */
var injector = this.createInjector(viewContainerRef.injector);
viewContainerRef.createComponent(componentFactory, null, injector);
}
};
/**
* @private
* @param {?} injector
* @return {?}
*/
NotifierComponent.prototype.createInjector = /**
* @private
* @param {?} injector
* @return {?}
*/
function (injector) {
/** @type {?} */
var injectionTokens = new WeakMap([
[ADDAPPTABLE_NOTIFIER_DATA, this.data]
]);
return new portal.PortalInjector(injector, injectionTokens);
};
/**
* @return {?}
*/
NotifierComponent.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.subject.next();
this.subject.complete();
};
NotifierComponent.decorators = [
{ type: core.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: core.ChangeDetectionStrategy.Default,
animations: [notifierAnimation.notifierAnimator],
encapsulation: core.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 = function () { return [
{ type: NotifierConfiguration, decorators: [{ type: core.Inject, args: [ADDAPPTABLE_CONFIGURATION_NOTIFIER_DATA,] }] },
{ type: Notifier, decorators: [{ type: core.Inject, args: [ADDAPPTABLE_NOTIFIER_DATA,] }] },
{ type: core.ComponentFactoryResolver }
]; };
NotifierComponent.propDecorators = {
appDynamic: [{ type: core.ViewChild, args: [core$1.DynamicDirective, { static: true },] }],
onMouseOver: [{ type: core.HostListener, args: ['mouseover',] }],
onMouseLeave: [{ type: core.HostListener, args: ['mouseleave',] }]
};
return NotifierComponent;
}());
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
*/
var NotifierContainerService = /** @class */ (function () {
function NotifierContainerService(_document) {
this._document = _document;
}
/**
* @return {?}
*/
NotifierContainerService.prototype.getContainerElement = /**
* @return {?}
*/
function () {
if (!this._containerElement) {
this._createContainer();
}
return this._containerElement;
};
/**
* @protected
* @return {?}
*/
NotifierContainerService.prototype._createContainer = /**
* @protected
* @return {?}
*/
function () {
/** @type {?} */
var container = this._document.createElement('div');
container.classList.add(NOTIFIER_CONTAINER);
this._document.body.appendChild(container);
this._containerElement = container;
};
/**
* @return {?}
*/
NotifierContainerService.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
if (this._containerElement && this._containerElement.parentNode) {
this._containerElement.parentNode.removeChild(this._containerElement);
}
};
NotifierContainerService.decorators = [
{ type: core.Injectable, args: [{
providedIn: 'root'
},] }
];
/** @nocollapse */
NotifierContainerService.ctorParameters = function () { return [
{ type: undefined, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] }] }
]; };
/** @nocollapse */ NotifierContainerService.ngInjectableDef = core.ɵɵdefineInjectable({ factory: function NotifierContainerService_Factory() { return new NotifierContainerService(core.ɵɵinject(common.DOCUMENT)); }, token: NotifierContainerService, providedIn: "root" });
return NotifierContainerService;
}());
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 {?} */
var nextUniqueId = 0;
var NotifierPortalService = /** @class */ (function () {
function NotifierPortalService(_notifierContainerService, _document, _injector, _componentFactoryResolver) {
this._notifierContainerService = _notifierContainerService;
this._document = _document;
this._injector = _injector;
this._componentFactoryResolver = _componentFactoryResolver;
}
/**
* @return {?}
*/
NotifierPortalService.prototype.create = /**
* @return {?}
*/
function () {
/** @type {?} */
var pane = this._createPaneElement();
/** @type {?} */
var portal = this._createPortalOutlet(pane);
return portal;
};
/**
* @private
* @param {?} pane
* @return {?}
*/
NotifierPortalService.prototype._createPortalOutlet = /**
* @private
* @param {?} pane
* @return {?}
*/
function (pane) {
if (!this._appRef) {
this._appRef = this._injector.get(core.ApplicationRef);
}
return new portal.DomPortalOutlet(pane, this._componentFactoryResolver, this._appRef, this._injector);
};
/**
* @private
* @return {?}
*/
NotifierPortalService.prototype._createPaneElement = /**
* @private
* @return {?}
*/
function () {
/** @type {?} */
var pane = this._document.createElement('div');
pane.id = "" + (NOTIFIER + nextUniqueId++);
this._notifierContainerService.getContainerElement().appendChild(pane);
return pane;
};
Object.defineProperty(NotifierPortalService.prototype, "getLastUniqueId", {
get: /**
* @return {?}
*/
function () {
return "" + (NOTIFIER + (nextUniqueId - 1));
},
enumerable: true,
configurable: true
});
NotifierPortalService.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
NotifierPortalService.ctorParameters = function () { return [
{ type: NotifierContainerService },
{ type: undefined, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] }] },
{ type: core.Injector },
{ type: core.ComponentFactoryResolver }
]; };
return NotifierPortalService;
}());
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
*/
var AbstractStrategy = /** @class */ (function () {
function AbstractStrategy(_document) {
this._document = _document;
this.notifiers = [];
this.margin = 30;
this.maxNotifiers = 5;
this.notifiers = [];
}
/**
* @param {?} notifierRef
* @return {?}
*/
AbstractStrategy.prototype.newNotifier = /**
* @param {?} notifierRef
* @return {?}
*/
function (notifierRef) {
var _this = this;
notifierRef.afterClosed().pipe(operators.take(1)).subscribe(this.deletePortal.bind(this));
notifierRef.changedStyle(this.getStyleNewNotifier(notifierRef));
setTimeout((/**
* @return {?}
*/
function () {
if (_this.notifiers.length >= _this.maxNotifiers) {
/** @type {?} */
var notifier = _this.notifiers.shift();
notifier.close();
}
/** @type {?} */
var element = _this._document.querySelector("#" + notifierRef.component._id + " > addapptable-notifier > .addapptable-notifier");
_this.notifiers.forEach((/**
* @param {?} notifier
* @return {?}
*/
function (notifier) {
/** @type {?} */
var 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 {?}
*/
AbstractStrategy.prototype.deletePortal = /**
* @private
* @param {?} id
* @return {?}
*/
function (id) {
/** @type {?} */
var notifier = this.notifiers.findIndex((/**
* @param {?} x
* @return {?}
*/
function (x) { return x.component._id === id; }));
if (notifier >= 0) {
/** @type {?} */
var element = this._document
.querySelector("#" + this.notifiers[notifier].component._id + " > addapptable-notifier > .addapptable-notifier");
/** @type {?} */
var clientHeightElementDelete = element.clientHeight;
this.notifiers.splice(notifier, 1);
for (var index = notifier - 1; index >= 0; index--) {
/** @type {?} */
var notifierStyle = this.notifiers[index];
/** @type {?} */
var elementChange = this._document
.querySelector("#" + notifierStyle.component._id + " > addapptable-notifier > .addapptable-notifier");
notifierStyle.changedStyle(this.getStyleDeleteNotifier(elementChange, clientHeightElementDelete));
}
}
};
/**
* @return {?}
*/
AbstractStrategy.prototype.ngOnDestroy = /**
* @return {?}
*/
function () {
this.notifiers.forEach((/**
* @param {?} notifier
* @return {?}
*/
function (notifier) {
notifier.close();
}));
};
/** @nocollapse */
AbstractStrategy.ctorParameters = function () { return [
{ type: HTMLDocument, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] }] }
]; };
return AbstractStrategy;
}());
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
*/
var BottomRightStrategy = /** @class */ (function (_super) {
__extends(BottomRightStrategy, _super);
function BottomRightStrategy() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* @protected
* @param {?} notifierRef
* @return {?}
*/
BottomRightStrategy.prototype.getStyleNewNotifier = /**
* @protected
* @param {?} notifierRef
* @return {?}
*/
function (notifierRef) {
notifierRef.component._state = 'slideInUp';
return { bottom: "0px", right: '0px' };
};
/**
* @protected
* @param {?} divNotifier
* @param {?} clientHeight
* @return {?}
*/
BottomRightStrategy.prototype.getStyleNotifierPosition = /**
* @protected
* @param {?} divNotifier
* @param {?} clientHeight
* @return {?}
*/
function (divNotifier, clientHeight) {
/** @type {?} */
var lastValueBottom = Number(divNotifier.style.bottom.replace('px', ''));
return { bottom: clientHeight + lastValueBottom + this.margin + "px", right: '0px' };
};
/**
* @protected
* @param {?} elementChange
* @param {?} clientHeightElementDelete
* @return {?}
*/
BottomRightStrategy.prototype.getStyleDeleteNotifier = /**
* @protected
* @param {?} elementChange
* @param {?} clientHeightElementDelete
* @return {?}
*/
function (elementChange, clientHeightElementDelete) {
/** @type {?} */
var valueBottomChange = Number(elementChange.style.bottom.replace('px', ''));
return { bottom: valueBottomChange - clientHeightElementDelete - this.margin + "px", right: '0px' };
};
BottomRightStrategy.decorators = [
{ type: core.Injectable }
];
return BottomRightStrategy;
}(AbstractStrategy));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var TopRightStrategy = /** @class */ (function (_super) {
__extends(TopRightStrategy, _super);
function TopRightStrategy() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* @protected
* @param {?} notifierRef
* @return {?}
*/
TopRightStrategy.prototype.getStyleNewNotifier = /**
* @protected
* @param {?} notifierRef
* @return {?}
*/
function (notifierRef) {
notifierRef.component._state = 'slideInDown';
return { top: "20px", right: '0px' };
};
/**
* @protected
* @param {?} divNotifier
* @param {?} clientHeight
* @return {?}
*/
TopRightStrategy.prototype.getStyleNotifierPosition = /**
* @protected
* @param {?} divNotifier
* @param {?} clientHeight
* @return {?}
*/
function (divNotifier, clientHeight) {
/** @type {?} */
var lastValueBottom = Number(divNotifier.style.top.replace('px', ''));
return { top: clientHeight + lastValueBottom + this.margin + "px", right: '0px' };
};
/**
* @protected
* @param {?} elementChange
* @param {?} clientHeightElementDelete
* @return {?}
*/
TopRightStrategy.prototype.getStyleDeleteNotifier = /**
* @protected
* @param {?} elementChange
* @param {?} clientHeightElementDelete
* @return {?}
*/
function (elementChange, clientHeightElementDelete) {
/** @type {?} */
var valueBottomChange = Number(elementChange.style.top.replace('px', ''));
return { top: valueBottomChange - clientHeightElementDelete - this.margin + "px", right: '0px' };
};
TopRightStrategy.decorators = [
{ type: core.Injectable }
];
return TopRightStrategy;
}(AbstractStrategy));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var BottomLeftStrategy = /** @class */ (function (_super) {
__extends(BottomLeftStrategy, _super);
function BottomLeftStrategy() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* @protected
* @param {?} notifierRef
* @return {?}
*/
BottomLeftStrategy.prototype.getStyleNewNotifier = /**
* @protected
* @param {?} notifierRef
* @return {?}
*/
function (notifierRef) {
notifierRef.component._state = 'slideInUp';
return { bottom: "0px", left: '0px' };
};
/**
* @protected
* @param {?} divNotifier
* @param {?} clientHeight
* @return {?}
*/
BottomLeftStrategy.prototype.getStyleNotifierPosition = /**
* @protected
* @param {?} divNotifier
* @param {?} clientHeight
* @return {?}
*/
function (divNotifier, clientHeight) {
/** @type {?} */
var lastValueBottom = Number(divNotifier.style.bottom.replace('px', ''));
return { bottom: clientHeight + lastValueBottom + this.margin + "px", left: '0px' };
};
/**
* @protected
* @param {?} elementChange
* @param {?} clientHeightElementDelete
* @return {?}
*/
BottomLeftStrategy.prototype.getStyleDeleteNotifier = /**
* @protected
* @param {?} elementChange
* @param {?} clientHeightElementDelete
* @return {?}
*/
function (elementChange, clientHeightElementDelete) {
/** @type {?} */
var valueBottomChange = Number(elementChange.style.bottom.replace('px', ''));
return { bottom: valueBottomChange - clientHeightElementDelete - this.margin + "px", left: '0px' };
};
BottomLeftStrategy.decorators = [
{ type: core.Injectable }
];
return BottomLeftStrategy;
}(AbstractStrategy));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var TopLeftStrategy = /** @class */ (function (_super) {
__extends(TopLeftStrategy, _super);
function TopLeftStrategy() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* @protected
* @param {?} notifierRef
* @return {?}
*/
TopLeftStrategy.prototype.getStyleNewNotifier = /**
* @protected
* @param {?} notifierRef
* @return {?}
*/
function (notifierRef) {
notifierRef.component._state = 'slideInDown';
return { top: "20px", left: '0px' };
};
/**
* @protected
* @param {?} divNotifier
* @param {?} clientHeight
* @return {?}
*/
TopLeftStrategy.prototype.getStyleNotifierPosition = /**
* @protected
* @param {?} divNotifier
* @param {?} clientHeight
* @return {?}
*/
function (divNotifier, clientHeight) {
/** @type {?} */
var lastValueBottom = Number(divNotifier.style.top.replace('px', ''));
return { top: clientHeight + lastValueBottom + this.margin + "px", left: '0px' };
};
/**
* @protected
* @param {?} elementChange
* @param {?} clientHeightElementDelete
* @return {?}
*/
TopLeftStrategy.prototype.getStyleDeleteNotifier = /**
* @protected
* @param {?} elementChange
* @param {?} clientHeightElementDelete
* @return {?}
*/
function (elementChange, clientHeightElementDelete) {
/** @type {?} */
var valueBottomChange = Number(elementChange.style.top.replace('px', ''));
return { top: valueBottomChange - clientHeightElementDelete - this.margin + "px", left: '0px' };
};
TopLeftStrategy.decorators = [
{ type: core.Injectable }
];
return TopLeftStrategy;
}(AbstractStrategy));
/**
* @fileoverview added by tsickle
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
var NotifierService = /** @class */ (function () {
function NotifierService(_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 {?}
*/
NotifierService.prototype.openSuccess = /**
* @param {?} message
* @param {?=} configuration
* @return {?}
*/
function (message, configuration) {
if (configuration === void 0) { configuration = (/** @type {?} */ ({})); }
return this.open({ message: message, type: NotifierType.success }, configuration);
};
/**
* @param {?} message
* @param {?=} configuration
* @return {?}
*/
NotifierService.prototype.openError = /**
* @param {?} message
* @param {?=} configuration
* @return {?}
*/
function (message, configuration) {
if (configuration === void 0) { configuration = (/** @type {?} */ ({})); }
return this.open({ message: message, type: NotifierType.danger }, configuration);
};
/**
* @param {?} message
* @param {?=} configuration
* @return {?}
*/
NotifierService.prototype.openInfo = /**
* @param {?} message
* @param {?=} configuration
* @return {?}
*/
function (message, configuration) {
if (configuration === void 0) { configuration = (/** @type {?} */ ({})); }
return this.open({ message: message, type: NotifierType.info }, configuration);
};
/**
* @param {?} message
* @param {?=} configuration
* @return {?}
*/
NotifierService.prototype.openWarning = /**
* @param {?} message
* @param {?=} configuration
* @return {?}
*/
function (message, configuration) {
if (configuration === void 0) { configuration = (/** @type {?} */ ({})); }
return this.open({ message: message, type: NotifierType.warning }, configuration);
};
/**
* @param {?} data
* @param {?=} configuration
* @return {?}
*/
NotifierService.prototype.open = /**
* @param {?} data
* @param {?=} configuration
* @return {?}
*/
function (data, configuration) {
if (configuration === void 0) { configuration = (/** @type {?} */ ({})); }
/** @type {?} */
var portal = this._notifierPortalService.create();
/** @type {?} */
var componentPortal = this._createComponentPortal(data);
/** @type {?} */
var componentRef = portal.attach(componentPortal);
/** @type {?} */
var notifierRef = new NotifierRef(componentRef.instance, portal, this._document, this._notifierPortalService.getLastUniqueId);
/** @type {?} */
var mergeConfiguration = Object.assign(this.defaultConfiguration, configuration);
this._factoryStrategy(mergeConfiguration).newNotifier(notifierRef);
return notifierRef;
};
/**
* @private
* @param {?} configuration
* @return {?}
*/
NotifierService.prototype._factoryStrategy = /**
* @private
* @param {?} configuration
* @return {?}
*/
function (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 {?}
*/
NotifierService.prototype._createComponentPortal = /**
* @private
* @param {?} data
* @return {?}
*/
function (data) {
/** @type {?} */
var injectionTokens = new WeakMap([
[ADDAPPTABLE_NOTIFIER_DATA, data]
]);
/** @type {?} */
var injector = new portal.PortalInjector(this._injector, injectionTokens);
return new portal.ComponentPortal(NotifierComponent, null, injector);
};
NotifierService.decorators = [
{ type: core.Injectable }
];
/** @nocollapse */
NotifierService.ctorParameters = function () { return [
{ type: NotifierPortalService },
{ type: core.Injector },
{ type: undefined, decorators: [{ type: core.Inject, args: [common.DOCUMENT,] }] },
{ type: NotifierConfiguration, decorators: [{ type: core.Inject, args: [ADDAPPTABLE_CONFIGURATION_NOTIFIER_DATA,] }] }
]; };
return NotifierService;
}());
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
*/
var NotifierModule = /** @class */ (function () {
function NotifierModule() {
}
/**
* @param {?=} config
* @return {?}
*/
NotifierModule.forRoot = /**
* @param {?=} config
* @return {?}
*/
function (config) {
if (config === void 0) { 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: core.NgModule, args: [{
declarations: [NotifierComponent],
imports: [
common.CommonModule,
core$1.CoreModule
],
entryComponents: [NotifierComponent],
providers: [
NotifierService,
NotifierPortalService,
BottomRightStrategy,
TopRightStrategy,
TopLeftStrategy,
BottomLeftStrategy
]
},] }
];
return NotifierModule;
}());
exports.ADDAPPTABLE_CONFIGURATION_NOTIFIER_DATA = ADDAPPTABLE_CONFIGURATION_NOTIFIER_DATA;
exports.ADDAPPTABLE_NOTIFIER_DATA = ADDAPPTABLE_NOTIFIER_DATA;
exports.NOTIFIER = NOTIFIER;
exports.NOTIFIER_CONTAINER = NOTIFIER_CONTAINER;
exports.Notifier = Notifier;
exports.NotifierComponent = NotifierComponent;
exports.NotifierConfiguration = NotifierConfiguration;
exports.NotifierContainerService = NotifierContainerService;
exports.NotifierModule = NotifierModule;
exports.NotifierPortalService = NotifierPortalService;
exports.NotifierPositionType = NotifierPositionType;
exports.NotifierRef = NotifierRef;
exports.NotifierService = NotifierService;
exports.NotifierType = NotifierType;
exports.notifierAnimation = notifierAnimation;
exports.notifierTriggerAnimation = notifierTriggerAnimation;
exports.slideInDown = slideInDown;
exports.slideInUp = slideInUp;
exports.zoomOut = zoomOut;
exports.ɵa = BottomRightStrategy;
exports.ɵb = AbstractStrategy;
exports.ɵc = TopRightStrategy;
exports.ɵd = TopLeftStrategy;
exports.ɵe = BottomLeftStrategy;
Object.defineProperty(exports, '__esModule', { value: true });
}));
//# sourceMappingURL=addapptables-notifier.umd.js.map