[59329aa] | 1 | import * as i0 from '@angular/core';
|
---|
| 2 | import { EventEmitter, Component, ChangeDetectionStrategy, ViewEncapsulation, Optional, Input, ContentChildren, Output, NgModule } from '@angular/core';
|
---|
| 3 | import * as i2 from '@angular/common';
|
---|
| 4 | import { CommonModule } from '@angular/common';
|
---|
| 5 | import { trigger, transition, style, animate } from '@angular/animations';
|
---|
| 6 | import * as i1 from 'primeng/api';
|
---|
| 7 | import { PrimeTemplate } from 'primeng/api';
|
---|
| 8 | import * as i3 from 'primeng/ripple';
|
---|
| 9 | import { RippleModule } from 'primeng/ripple';
|
---|
| 10 |
|
---|
| 11 | class Messages {
|
---|
| 12 | constructor(messageService, el, cd) {
|
---|
| 13 | this.messageService = messageService;
|
---|
| 14 | this.el = el;
|
---|
| 15 | this.cd = cd;
|
---|
| 16 | this.closable = true;
|
---|
| 17 | this.enableService = true;
|
---|
| 18 | this.escape = true;
|
---|
| 19 | this.showTransitionOptions = '300ms ease-out';
|
---|
| 20 | this.hideTransitionOptions = '200ms cubic-bezier(0.86, 0, 0.07, 1)';
|
---|
| 21 | this.valueChange = new EventEmitter();
|
---|
| 22 | }
|
---|
| 23 | ngAfterContentInit() {
|
---|
| 24 | this.templates.forEach((item) => {
|
---|
| 25 | switch (item.getType()) {
|
---|
| 26 | case 'content':
|
---|
| 27 | this.contentTemplate = item.template;
|
---|
| 28 | break;
|
---|
| 29 | default:
|
---|
| 30 | this.contentTemplate = item.template;
|
---|
| 31 | break;
|
---|
| 32 | }
|
---|
| 33 | });
|
---|
| 34 | if (this.messageService && this.enableService && !this.contentTemplate) {
|
---|
| 35 | this.messageSubscription = this.messageService.messageObserver.subscribe((messages) => {
|
---|
| 36 | if (messages) {
|
---|
| 37 | if (messages instanceof Array) {
|
---|
| 38 | let filteredMessages = messages.filter(m => this.key === m.key);
|
---|
| 39 | this.value = this.value ? [...this.value, ...filteredMessages] : [...filteredMessages];
|
---|
| 40 | }
|
---|
| 41 | else if (this.key === messages.key) {
|
---|
| 42 | this.value = this.value ? [...this.value, ...[messages]] : [messages];
|
---|
| 43 | }
|
---|
| 44 | this.cd.markForCheck();
|
---|
| 45 | }
|
---|
| 46 | });
|
---|
| 47 | this.clearSubscription = this.messageService.clearObserver.subscribe(key => {
|
---|
| 48 | if (key) {
|
---|
| 49 | if (this.key === key) {
|
---|
| 50 | this.value = null;
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 | else {
|
---|
| 54 | this.value = null;
|
---|
| 55 | }
|
---|
| 56 | this.cd.markForCheck();
|
---|
| 57 | });
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 | hasMessages() {
|
---|
| 61 | let parentEl = this.el.nativeElement.parentElement;
|
---|
| 62 | if (parentEl && parentEl.offsetParent) {
|
---|
| 63 | return this.contentTemplate != null || this.value && this.value.length > 0;
|
---|
| 64 | }
|
---|
| 65 | return false;
|
---|
| 66 | }
|
---|
| 67 | clear() {
|
---|
| 68 | this.value = [];
|
---|
| 69 | this.valueChange.emit(this.value);
|
---|
| 70 | }
|
---|
| 71 | removeMessage(i) {
|
---|
| 72 | this.value = this.value.filter((msg, index) => index !== i);
|
---|
| 73 | this.valueChange.emit(this.value);
|
---|
| 74 | }
|
---|
| 75 | get icon() {
|
---|
| 76 | const severity = this.severity || (this.hasMessages() ? this.value[0].severity : null);
|
---|
| 77 | if (this.hasMessages()) {
|
---|
| 78 | switch (severity) {
|
---|
| 79 | case 'success':
|
---|
| 80 | return 'pi-check';
|
---|
| 81 | break;
|
---|
| 82 | case 'info':
|
---|
| 83 | return 'pi-info-circle';
|
---|
| 84 | break;
|
---|
| 85 | case 'error':
|
---|
| 86 | return 'pi-times';
|
---|
| 87 | break;
|
---|
| 88 | case 'warn':
|
---|
| 89 | return 'pi-exclamation-triangle';
|
---|
| 90 | break;
|
---|
| 91 | default:
|
---|
| 92 | return 'pi-info-circle';
|
---|
| 93 | break;
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 | return null;
|
---|
| 97 | }
|
---|
| 98 | ngOnDestroy() {
|
---|
| 99 | if (this.messageSubscription) {
|
---|
| 100 | this.messageSubscription.unsubscribe();
|
---|
| 101 | }
|
---|
| 102 | if (this.clearSubscription) {
|
---|
| 103 | this.clearSubscription.unsubscribe();
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | Messages.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Messages, deps: [{ token: i1.MessageService, optional: true }, { token: i0.ElementRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
|
---|
| 108 | Messages.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.0.0", type: Messages, selector: "p-messages", inputs: { value: "value", closable: "closable", style: "style", styleClass: "styleClass", enableService: "enableService", key: "key", escape: "escape", severity: "severity", showTransitionOptions: "showTransitionOptions", hideTransitionOptions: "hideTransitionOptions" }, outputs: { valueChange: "valueChange" }, host: { classAttribute: "p-element" }, queries: [{ propertyName: "templates", predicate: PrimeTemplate }], ngImport: i0, template: `
|
---|
| 109 | <div class="p-messages p-component" role="alert" [ngStyle]="style" [class]="styleClass">
|
---|
| 110 | <ng-container *ngIf="!contentTemplate; else staticMessage">
|
---|
| 111 | <div *ngFor="let msg of value; let i=index" [ngClass]="'p-message p-message-' + msg.severity" role="alert"
|
---|
| 112 | [@messageAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}">
|
---|
| 113 | <div class="p-message-wrapper">
|
---|
| 114 | <span [class]="'p-message-icon pi' + (msg.icon ? ' ' + msg.icon : '')" [ngClass]="{'pi-info-circle': msg.severity === 'info',
|
---|
| 115 | 'pi-check': msg.severity === 'success',
|
---|
| 116 | 'pi-exclamation-triangle': msg.severity === 'warn',
|
---|
| 117 | 'pi-times-circle': msg.severity === 'error'}"></span>
|
---|
| 118 | <ng-container *ngIf="!escape; else escapeOut">
|
---|
| 119 | <span *ngIf="msg.summary" class="p-message-summary" [innerHTML]="msg.summary"></span>
|
---|
| 120 | <span *ngIf="msg.detail" class="p-message-detail" [innerHTML]="msg.detail"></span>
|
---|
| 121 | </ng-container>
|
---|
| 122 | <ng-template #escapeOut>
|
---|
| 123 | <span *ngIf="msg.summary" class="p-message-summary">{{msg.summary}}</span>
|
---|
| 124 | <span *ngIf="msg.detail" class="p-message-detail">{{msg.detail}}</span>
|
---|
| 125 | </ng-template>
|
---|
| 126 | <button class="p-message-close p-link" (click)="removeMessage(i)" *ngIf="closable" type="button" pRipple>
|
---|
| 127 | <i class="p-message-close-icon pi pi-times"></i>
|
---|
| 128 | </button>
|
---|
| 129 | </div>
|
---|
| 130 | </div>
|
---|
| 131 | </ng-container>
|
---|
| 132 | <ng-template #staticMessage>
|
---|
| 133 | <div [ngClass]="'p-message p-message-' + severity" role="alert">
|
---|
| 134 | <div class="p-message-wrapper">
|
---|
| 135 | <ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
|
---|
| 136 | </div>
|
---|
| 137 | </div>
|
---|
| 138 | </ng-template>
|
---|
| 139 | </div>
|
---|
| 140 | `, isInline: true, styles: [".p-message-wrapper{display:flex;align-items:center}.p-message-close{display:flex;align-items:center;justify-content:center}.p-message-close.p-link{margin-left:auto;overflow:hidden;position:relative}\n"], directives: [{ type: i2.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i2.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i2.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: i2.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i3.Ripple, selector: "[pRipple]" }, { type: i2.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }], animations: [
|
---|
| 141 | trigger('messageAnimation', [
|
---|
| 142 | transition(':enter', [
|
---|
| 143 | style({ opacity: 0, transform: 'translateY(-25%)' }),
|
---|
| 144 | animate('{{showTransitionParams}}')
|
---|
| 145 | ]),
|
---|
| 146 | transition(':leave', [
|
---|
| 147 | animate('{{hideTransitionParams}}', style({ height: 0, marginTop: 0, marginBottom: 0, marginLeft: 0, marginRight: 0, overflow: 'hidden', opacity: 0 }))
|
---|
| 148 | ])
|
---|
| 149 | ])
|
---|
| 150 | ], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
|
---|
| 151 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: Messages, decorators: [{
|
---|
| 152 | type: Component,
|
---|
| 153 | args: [{ selector: 'p-messages', template: `
|
---|
| 154 | <div class="p-messages p-component" role="alert" [ngStyle]="style" [class]="styleClass">
|
---|
| 155 | <ng-container *ngIf="!contentTemplate; else staticMessage">
|
---|
| 156 | <div *ngFor="let msg of value; let i=index" [ngClass]="'p-message p-message-' + msg.severity" role="alert"
|
---|
| 157 | [@messageAnimation]="{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}">
|
---|
| 158 | <div class="p-message-wrapper">
|
---|
| 159 | <span [class]="'p-message-icon pi' + (msg.icon ? ' ' + msg.icon : '')" [ngClass]="{'pi-info-circle': msg.severity === 'info',
|
---|
| 160 | 'pi-check': msg.severity === 'success',
|
---|
| 161 | 'pi-exclamation-triangle': msg.severity === 'warn',
|
---|
| 162 | 'pi-times-circle': msg.severity === 'error'}"></span>
|
---|
| 163 | <ng-container *ngIf="!escape; else escapeOut">
|
---|
| 164 | <span *ngIf="msg.summary" class="p-message-summary" [innerHTML]="msg.summary"></span>
|
---|
| 165 | <span *ngIf="msg.detail" class="p-message-detail" [innerHTML]="msg.detail"></span>
|
---|
| 166 | </ng-container>
|
---|
| 167 | <ng-template #escapeOut>
|
---|
| 168 | <span *ngIf="msg.summary" class="p-message-summary">{{msg.summary}}</span>
|
---|
| 169 | <span *ngIf="msg.detail" class="p-message-detail">{{msg.detail}}</span>
|
---|
| 170 | </ng-template>
|
---|
| 171 | <button class="p-message-close p-link" (click)="removeMessage(i)" *ngIf="closable" type="button" pRipple>
|
---|
| 172 | <i class="p-message-close-icon pi pi-times"></i>
|
---|
| 173 | </button>
|
---|
| 174 | </div>
|
---|
| 175 | </div>
|
---|
| 176 | </ng-container>
|
---|
| 177 | <ng-template #staticMessage>
|
---|
| 178 | <div [ngClass]="'p-message p-message-' + severity" role="alert">
|
---|
| 179 | <div class="p-message-wrapper">
|
---|
| 180 | <ng-container *ngTemplateOutlet="contentTemplate"></ng-container>
|
---|
| 181 | </div>
|
---|
| 182 | </div>
|
---|
| 183 | </ng-template>
|
---|
| 184 | </div>
|
---|
| 185 | `, animations: [
|
---|
| 186 | trigger('messageAnimation', [
|
---|
| 187 | transition(':enter', [
|
---|
| 188 | style({ opacity: 0, transform: 'translateY(-25%)' }),
|
---|
| 189 | animate('{{showTransitionParams}}')
|
---|
| 190 | ]),
|
---|
| 191 | transition(':leave', [
|
---|
| 192 | animate('{{hideTransitionParams}}', style({ height: 0, marginTop: 0, marginBottom: 0, marginLeft: 0, marginRight: 0, overflow: 'hidden', opacity: 0 }))
|
---|
| 193 | ])
|
---|
| 194 | ])
|
---|
| 195 | ], changeDetection: ChangeDetectionStrategy.OnPush, encapsulation: ViewEncapsulation.None, host: {
|
---|
| 196 | 'class': 'p-element'
|
---|
| 197 | }, styles: [".p-message-wrapper{display:flex;align-items:center}.p-message-close{display:flex;align-items:center;justify-content:center}.p-message-close.p-link{margin-left:auto;overflow:hidden;position:relative}\n"] }]
|
---|
| 198 | }], ctorParameters: function () { return [{ type: i1.MessageService, decorators: [{
|
---|
| 199 | type: Optional
|
---|
| 200 | }] }, { type: i0.ElementRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { value: [{
|
---|
| 201 | type: Input
|
---|
| 202 | }], closable: [{
|
---|
| 203 | type: Input
|
---|
| 204 | }], style: [{
|
---|
| 205 | type: Input
|
---|
| 206 | }], styleClass: [{
|
---|
| 207 | type: Input
|
---|
| 208 | }], enableService: [{
|
---|
| 209 | type: Input
|
---|
| 210 | }], key: [{
|
---|
| 211 | type: Input
|
---|
| 212 | }], escape: [{
|
---|
| 213 | type: Input
|
---|
| 214 | }], severity: [{
|
---|
| 215 | type: Input
|
---|
| 216 | }], showTransitionOptions: [{
|
---|
| 217 | type: Input
|
---|
| 218 | }], hideTransitionOptions: [{
|
---|
| 219 | type: Input
|
---|
| 220 | }], templates: [{
|
---|
| 221 | type: ContentChildren,
|
---|
| 222 | args: [PrimeTemplate]
|
---|
| 223 | }], valueChange: [{
|
---|
| 224 | type: Output
|
---|
| 225 | }] } });
|
---|
| 226 | class MessagesModule {
|
---|
| 227 | }
|
---|
| 228 | MessagesModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MessagesModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
---|
| 229 | MessagesModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MessagesModule, declarations: [Messages], imports: [CommonModule, RippleModule], exports: [Messages] });
|
---|
| 230 | MessagesModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MessagesModule, imports: [[CommonModule, RippleModule]] });
|
---|
| 231 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.0.0", ngImport: i0, type: MessagesModule, decorators: [{
|
---|
| 232 | type: NgModule,
|
---|
| 233 | args: [{
|
---|
| 234 | imports: [CommonModule, RippleModule],
|
---|
| 235 | exports: [Messages],
|
---|
| 236 | declarations: [Messages]
|
---|
| 237 | }]
|
---|
| 238 | }] });
|
---|
| 239 |
|
---|
| 240 | /**
|
---|
| 241 | * Generated bundle index. Do not edit.
|
---|
| 242 | */
|
---|
| 243 |
|
---|
| 244 | export { Messages, MessagesModule };
|
---|