import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Optional, ElementRef, ChangeDetectorRef, Input, ContentChildren, Output, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { trigger, transition, style, animate } from '@angular/animations'; import { MessageService, PrimeTemplate } from 'primeng/api'; import { RippleModule } from 'primeng/ripple'; class Messages { constructor(messageService, el, cd) { this.messageService = messageService; this.el = el; this.cd = cd; this.closable = true; this.enableService = true; this.escape = true; this.showTransitionOptions = '300ms ease-out'; this.hideTransitionOptions = '200ms cubic-bezier(0.86, 0, 0.07, 1)'; this.valueChange = new EventEmitter(); } ngAfterContentInit() { this.templates.forEach((item) => { switch (item.getType()) { case 'content': this.contentTemplate = item.template; break; default: this.contentTemplate = item.template; break; } }); if (this.messageService && this.enableService && !this.contentTemplate) { this.messageSubscription = this.messageService.messageObserver.subscribe((messages) => { if (messages) { if (messages instanceof Array) { let filteredMessages = messages.filter(m => this.key === m.key); this.value = this.value ? [...this.value, ...filteredMessages] : [...filteredMessages]; } else if (this.key === messages.key) { this.value = this.value ? [...this.value, ...[messages]] : [messages]; } this.cd.markForCheck(); } }); this.clearSubscription = this.messageService.clearObserver.subscribe(key => { if (key) { if (this.key === key) { this.value = null; } } else { this.value = null; } this.cd.markForCheck(); }); } } hasMessages() { let parentEl = this.el.nativeElement.parentElement; if (parentEl && parentEl.offsetParent) { return this.contentTemplate != null || this.value && this.value.length > 0; } return false; } clear() { this.value = []; this.valueChange.emit(this.value); } removeMessage(i) { this.value = this.value.filter((msg, index) => index !== i); } get icon() { const severity = this.severity || (this.hasMessages() ? this.value[0].severity : null); if (this.hasMessages()) { switch (severity) { case 'success': return 'pi-check'; break; case 'info': return 'pi-info-circle'; break; case 'error': return 'pi-times'; break; case 'warn': return 'pi-exclamation-triangle'; break; default: return 'pi-info-circle'; break; } } return null; } ngOnDestroy() { if (this.messageSubscription) { this.messageSubscription.unsubscribe(); } if (this.clearSubscription) { this.clearSubscription.unsubscribe(); } } } Messages.decorators = [ { type: Component, args: [{ selector: 'p-messages', template: ` `, animations: [ trigger('messageAnimation', [ transition(':enter', [ style({ opacity: 0, transform: 'translateY(-25%)' }), animate('{{showTransitionParams}}') ]), transition(':leave', [ animate('{{hideTransitionParams}}', style({ height: 0, marginTop: 0, marginBottom: 0, marginLeft: 0, marginRight: 0, overflow: 'hidden', opacity: 0 })) ]) ]) ], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, styles: [".p-message-close,.p-message-wrapper{-ms-flex-align:center;align-items:center;display:-ms-flexbox;display:flex}.p-message-close{-ms-flex-pack:center;justify-content:center}.p-message-close.p-link{margin-left:auto;overflow:hidden;position:relative}"] },] } ]; Messages.ctorParameters = () => [ { type: MessageService, decorators: [{ type: Optional }] }, { type: ElementRef }, { type: ChangeDetectorRef } ]; Messages.propDecorators = { value: [{ type: Input }], closable: [{ type: Input }], style: [{ type: Input }], styleClass: [{ type: Input }], enableService: [{ type: Input }], key: [{ type: Input }], escape: [{ type: Input }], severity: [{ type: Input }], showTransitionOptions: [{ type: Input }], hideTransitionOptions: [{ type: Input }], templates: [{ type: ContentChildren, args: [PrimeTemplate,] }], valueChange: [{ type: Output }] }; class MessagesModule { } MessagesModule.decorators = [ { type: NgModule, args: [{ imports: [CommonModule, RippleModule], exports: [Messages], declarations: [Messages] },] } ]; /** * Generated bundle index. Do not edit. */ export { Messages, MessagesModule }; //# sourceMappingURL=primeng-messages.js.map