import { trigger, transition, style, animate } from '@angular/animations'; import * as i2 from '@angular/common'; import { CommonModule } from '@angular/common'; import * as i0 from '@angular/core'; import { EventEmitter, booleanAttribute, Component, ChangeDetectionStrategy, ViewEncapsulation, Optional, Input, Output, ContentChildren, NgModule } from '@angular/core'; import * as i1 from 'primeng/api'; import { PrimeTemplate } from 'primeng/api'; import { CheckIcon } from 'primeng/icons/check'; import { ExclamationTriangleIcon } from 'primeng/icons/exclamationtriangle'; import { InfoCircleIcon } from 'primeng/icons/infocircle'; import { TimesIcon } from 'primeng/icons/times'; import { TimesCircleIcon } from 'primeng/icons/timescircle'; import * as i3 from 'primeng/ripple'; import { RippleModule } from 'primeng/ripple'; import { timer } from 'rxjs'; /** * Messages is used to display alerts inline. * @group Components */ class Messages { messageService; el; cd; config; /** * An array of messages to display. * @group Props */ set value(messages) { this.messages = messages; this.startMessageLifes(this.messages); } /** * Defines if message box can be closed by the click icon. * @group Props */ closable = true; /** * Inline style of the component. * @group Props */ style; /** * Style class of the component. * @group Props */ styleClass; /** * Whether displaying services messages are enabled. * @group Props */ enableService = true; /** * Id to match the key of the message to enable scoping in service based messaging. * @group Props */ key; /** * Whether displaying messages would be escaped or not. * @group Props */ escape = true; /** * Severity level of the message. * @group Props */ severity; /** * Transition options of the show animation. * @group Props */ showTransitionOptions = '300ms ease-out'; /** * Transition options of the hide animation. * @group Props */ hideTransitionOptions = '200ms cubic-bezier(0.86, 0, 0.07, 1)'; /** * This function is executed when the value changes. * @param {Message[]} value - messages value. * @group Emits */ valueChange = new EventEmitter(); /** * This function is executed when a message is closed. * @param {Message} value - Closed message. * @group Emits */ onClose = new EventEmitter(); templates; messages; messageSubscription; clearSubscription; timerSubscriptions = []; contentTemplate; constructor(messageService, el, cd, config) { this.messageService = messageService; this.el = el; this.cd = cd; this.config = config; } 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 (!Array.isArray(messages)) { messages = [messages]; } const filteredMessages = messages.filter((m) => this.key === m.key); this.messages = this.messages ? [...this.messages, ...filteredMessages] : [...filteredMessages]; this.startMessageLifes(filteredMessages); this.cd.markForCheck(); } }); this.clearSubscription = this.messageService.clearObserver.subscribe((key) => { if (key) { if (this.key === key) { this.messages = null; } } else { this.messages = null; } this.cd.markForCheck(); }); } } hasMessages() { let parentEl = this.el.nativeElement.parentElement; if (parentEl && parentEl.offsetParent) { return this.contentTemplate != null || (this.messages && this.messages.length > 0); } return false; } clear() { this.messages = []; this.valueChange.emit(this.messages); } removeMessage(i) { const removedMessage = this.messages[i]; this.messages = this.messages?.filter((msg, index) => index !== i); removedMessage && this.onClose.emit(removedMessage); this.valueChange.emit(this.messages); } get icon() { const severity = this.severity || (this.hasMessages() ? this.messages[0].severity : null); if (this.hasMessages()) { switch (severity) { case 'success': return 'pi-check'; case 'info': return 'pi-info-circle'; case 'error': return 'pi-times'; case 'warn': return 'pi-exclamation-triangle'; default: return 'pi-info-circle'; } } return null; } get closeAriaLabel() { return this.config.translation.aria ? this.config.translation.aria.close : undefined; } ngOnDestroy() { if (this.messageSubscription) { this.messageSubscription.unsubscribe(); } if (this.clearSubscription) { this.clearSubscription.unsubscribe(); } this.timerSubscriptions?.forEach((subscription) => subscription.unsubscribe()); } startMessageLifes(messages) { messages?.forEach((message) => message.life && this.startMessageLife(message)); } startMessageLife(message) { const timerSubsctiption = timer(message.life).subscribe(() => { this.messages = this.messages?.filter((msgEl) => msgEl !== message); this.timerSubscriptions = this.timerSubscriptions?.filter((timerEl) => timerEl !== timerSubsctiption); this.valueChange.emit(this.messages); this.cd.markForCheck(); }); this.timerSubscriptions.push(timerSubsctiption); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: Messages, deps: [{ token: i1.MessageService, optional: true }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }, { token: i1.PrimeNGConfig }], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "16.1.0", version: "17.3.7", type: Messages, selector: "p-messages", inputs: { value: "value", closable: ["closable", "closable", booleanAttribute], style: "style", styleClass: "styleClass", enableService: ["enableService", "enableService", booleanAttribute], key: "key", escape: ["escape", "escape", booleanAttribute], severity: "severity", showTransitionOptions: "showTransitionOptions", hideTransitionOptions: "hideTransitionOptions" }, outputs: { valueChange: "valueChange", onClose: "onClose" }, host: { classAttribute: "p-element" }, queries: [{ propertyName: "templates", predicate: PrimeTemplate }], ngImport: i0, template: ` `, isInline: true, styles: ["@layer primeng{.p-message-wrapper{display:flex;align-items:center}.p-message-close{display:flex;align-items:center;justify-content:center;flex:none}.p-message-close.p-link{margin-left:auto;overflow:hidden;position:relative}.p-messages .p-message.ng-animating{overflow:hidden}}\n"], dependencies: [{ kind: "directive", type: i0.forwardRef(() => i2.NgClass), selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "directive", type: i0.forwardRef(() => i2.NgForOf), selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { kind: "directive", type: i0.forwardRef(() => i2.NgIf), selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { kind: "directive", type: i0.forwardRef(() => i2.NgTemplateOutlet), selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: i0.forwardRef(() => i2.NgStyle), selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "directive", type: i0.forwardRef(() => i3.Ripple), selector: "[pRipple]" }, { kind: "component", type: i0.forwardRef(() => CheckIcon), selector: "CheckIcon" }, { kind: "component", type: i0.forwardRef(() => InfoCircleIcon), selector: "InfoCircleIcon" }, { kind: "component", type: i0.forwardRef(() => TimesCircleIcon), selector: "TimesCircleIcon" }, { kind: "component", type: i0.forwardRef(() => ExclamationTriangleIcon), selector: "ExclamationTriangleIcon" }, { kind: "component", type: i0.forwardRef(() => TimesIcon), selector: "TimesIcon" }], 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, opacity: 0 }))]) ]) ], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: 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, opacity: 0 }))]) ]) ], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: { class: 'p-element' }, styles: ["@layer primeng{.p-message-wrapper{display:flex;align-items:center}.p-message-close{display:flex;align-items:center;justify-content:center;flex:none}.p-message-close.p-link{margin-left:auto;overflow:hidden;position:relative}.p-messages .p-message.ng-animating{overflow:hidden}}\n"] }] }], ctorParameters: () => [{ type: i1.MessageService, decorators: [{ type: Optional }] }, { type: i0.ElementRef }, { type: i0.ChangeDetectorRef }, { type: i1.PrimeNGConfig }], propDecorators: { value: [{ type: Input }], closable: [{ type: Input, args: [{ transform: booleanAttribute }] }], style: [{ type: Input }], styleClass: [{ type: Input }], enableService: [{ type: Input, args: [{ transform: booleanAttribute }] }], key: [{ type: Input }], escape: [{ type: Input, args: [{ transform: booleanAttribute }] }], severity: [{ type: Input }], showTransitionOptions: [{ type: Input }], hideTransitionOptions: [{ type: Input }], valueChange: [{ type: Output }], onClose: [{ type: Output }], templates: [{ type: ContentChildren, args: [PrimeTemplate] }] } }); class MessagesModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: MessagesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "17.3.7", ngImport: i0, type: MessagesModule, declarations: [Messages], imports: [CommonModule, RippleModule, CheckIcon, InfoCircleIcon, TimesCircleIcon, ExclamationTriangleIcon, TimesIcon], exports: [Messages] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: MessagesModule, imports: [CommonModule, RippleModule, CheckIcon, InfoCircleIcon, TimesCircleIcon, ExclamationTriangleIcon, TimesIcon] }); } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "17.3.7", ngImport: i0, type: MessagesModule, decorators: [{ type: NgModule, args: [{ imports: [CommonModule, RippleModule, CheckIcon, InfoCircleIcon, TimesCircleIcon, ExclamationTriangleIcon, TimesIcon], exports: [Messages], declarations: [Messages] }] }] }); /** * Generated bundle index. Do not edit. */ export { Messages, MessagesModule }; //# sourceMappingURL=primeng-messages.mjs.map