@igo2/core 21.0.0-next.2 → 21.0.0-next.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/fesm2022/igo2-core-activity.mjs +10 -10
  2. package/fesm2022/igo2-core-analytics.mjs +4 -4
  3. package/fesm2022/igo2-core-analytics.mjs.map +1 -1
  4. package/fesm2022/igo2-core-auth.mjs +14 -0
  5. package/fesm2022/igo2-core-auth.mjs.map +1 -0
  6. package/fesm2022/igo2-core-config.mjs +29 -46
  7. package/fesm2022/igo2-core-config.mjs.map +1 -1
  8. package/fesm2022/igo2-core-language.mjs +13 -11
  9. package/fesm2022/igo2-core-language.mjs.map +1 -1
  10. package/fesm2022/igo2-core-media.mjs +3 -3
  11. package/fesm2022/igo2-core-media.mjs.map +1 -1
  12. package/fesm2022/igo2-core-message.mjs +343 -177
  13. package/fesm2022/igo2-core-message.mjs.map +1 -1
  14. package/fesm2022/igo2-core-network.mjs +6 -12
  15. package/fesm2022/igo2-core-network.mjs.map +1 -1
  16. package/fesm2022/igo2-core-regex.mjs +3 -3
  17. package/fesm2022/igo2-core-regex.mjs.map +1 -1
  18. package/fesm2022/igo2-core-request.mjs +14 -14
  19. package/fesm2022/igo2-core-request.mjs.map +1 -1
  20. package/fesm2022/igo2-core-route.mjs +3 -3
  21. package/fesm2022/igo2-core-route.mjs.map +1 -1
  22. package/fesm2022/igo2-core-storage.mjs +11 -11
  23. package/fesm2022/igo2-core-storage.mjs.map +1 -1
  24. package/fesm2022/igo2-core.mjs +5 -6
  25. package/fesm2022/igo2-core.mjs.map +1 -1
  26. package/locale/en.json +1 -1
  27. package/locale/fr.json +1 -1
  28. package/package.json +6 -3
  29. package/src/style/style.scss +0 -2
  30. package/src/theming/themes/_theme.scss +0 -4
  31. package/style/all-style.css +1 -223
  32. package/style/style.css +0 -222
  33. package/theming/prebuilt-themes/blue-theme.css +0 -3
  34. package/theming/prebuilt-themes/bluedark-theme.css +0 -3
  35. package/theming/prebuilt-themes/bluedq-theme.css +0 -3
  36. package/theming/prebuilt-themes/teal-theme.css +0 -3
  37. package/types/igo2-core-auth.d.ts +15 -0
  38. package/types/igo2-core-language.d.ts +2 -2
  39. package/types/igo2-core-media.d.ts +4 -4
  40. package/types/igo2-core-message.d.ts +118 -33
  41. package/types/igo2-core-monitoring.d.ts +1 -1
  42. package/types/igo2-core-network.d.ts +3 -4
  43. package/types/igo2-core-regex.d.ts +1 -1
  44. package/types/igo2-core-storage.d.ts +2 -2
@@ -1,252 +1,416 @@
1
1
  import * as i0 from '@angular/core';
2
- import { makeEnvironmentProviders, NgModule, inject, Injector, Injectable } from '@angular/core';
3
- import { provideToastr, ToastrService } from 'ngx-toastr';
4
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
2
+ import { ChangeDetectionStrategy, Component, inject, ApplicationRef, createComponent, Injectable, signal, provideAppInitializer } from '@angular/core';
3
+ import { DOCUMENT, NgClass } from '@angular/common';
4
+ import { MatIconButton } from '@angular/material/button';
5
+ import * as i1 from '@angular/material/icon';
6
+ import { MatIconModule } from '@angular/material/icon';
7
+ import { MatProgressBar } from '@angular/material/progress-bar';
8
+ import { DomSanitizer } from '@angular/platform-browser';
5
9
  import { ConfigService } from '@igo2/core/config';
6
10
  import { LanguageService } from '@igo2/core/language';
7
- import { BehaviorSubject, forkJoin } from 'rxjs';
8
- import { debounceTime, first } from 'rxjs/operators';
11
+ import { BehaviorSubject } from 'rxjs';
9
12
 
10
- const TOASTR_CONFIG = {
11
- positionClass: 'toast-bottom-right',
13
+ var MessageType;
14
+ (function (MessageType) {
15
+ MessageType["ERROR"] = "error";
16
+ MessageType["ALERT"] = "warning";
17
+ // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
18
+ MessageType["WARNING"] = "warning";
19
+ MessageType["INFO"] = "info";
20
+ MessageType["SUCCESS"] = "success";
21
+ MessageType["SHOW"] = "show";
22
+ })(MessageType || (MessageType = {}));
23
+
24
+ class ToastContainerComponent {
25
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.19", ngImport: i0, type: ToastContainerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
26
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.19", type: ToastContainerComponent, isStandalone: true, selector: "igo-toast-container", ngImport: i0, template: `<ng-content></ng-content>`, isInline: true, styles: [":host{position:fixed;pointer-events:none;z-index:10000;display:flex;flex-direction:column;row-gap:8px}:host.toast-bottom-right{bottom:12px;right:12px;align-items:flex-end}:host.toast-bottom-left{bottom:12px;left:12px;align-items:flex-start}:host.toast-top-right{top:12px;right:12px;align-items:flex-end}:host.toast-top-left{top:12px;left:12px;align-items:flex-start}:host.toast-top-center{top:12px;left:50%;transform:translate(-50%);align-items:center}:host.toast-bottom-center{bottom:12px;left:50%;transform:translate(-50%);align-items:center}\n"], changeDetection: i0.ChangeDetectionStrategy.OnPush });
27
+ }
28
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.19", ngImport: i0, type: ToastContainerComponent, decorators: [{
29
+ type: Component,
30
+ args: [{ selector: 'igo-toast-container', standalone: true, changeDetection: ChangeDetectionStrategy.OnPush, template: `<ng-content></ng-content>`, styles: [":host{position:fixed;pointer-events:none;z-index:10000;display:flex;flex-direction:column;row-gap:8px}:host.toast-bottom-right{bottom:12px;right:12px;align-items:flex-end}:host.toast-bottom-left{bottom:12px;left:12px;align-items:flex-start}:host.toast-top-right{top:12px;right:12px;align-items:flex-end}:host.toast-top-left{top:12px;left:12px;align-items:flex-start}:host.toast-top-center{top:12px;left:50%;transform:translate(-50%);align-items:center}:host.toast-bottom-center{bottom:12px;left:50%;transform:translate(-50%);align-items:center}\n"] }]
31
+ }] });
32
+
33
+ const DEFAULT_TOAST_CONFIG = {
12
34
  timeOut: 10000,
13
35
  extendedTimeOut: 10000,
14
- titleClass: 'toastr-message-title',
15
- messageClass: 'toast-message',
16
36
  closeButton: true,
17
37
  progressBar: true,
18
- enableHtml: true,
19
38
  tapToDismiss: true,
39
+ positionClass: 'toast-bottom-right',
20
40
  maxOpened: 4,
21
41
  preventDuplicates: true,
22
- resetTimeoutOnDuplicate: true,
23
- countDuplicates: false,
24
- includeTitleDuplicates: true
42
+ enableHtml: true,
43
+ disableTimeOut: false,
44
+ showIcon: false,
45
+ freezeProgressOnHover: true
25
46
  };
26
- function provideMessage() {
27
- return makeEnvironmentProviders([provideToastr(TOASTR_CONFIG)]);
47
+
48
+ class ToastService {
49
+ appRef = inject(ApplicationRef);
50
+ document = inject(DOCUMENT);
51
+ toastIdCounter = 0;
52
+ toasts = new Map();
53
+ containerRef = null;
54
+ config = { ...DEFAULT_TOAST_CONFIG };
55
+ lastMessage = '';
56
+ lastTitle = '';
57
+ configure(config) {
58
+ this.config = { ...this.config, ...config };
59
+ }
60
+ success(message, title, options) {
61
+ return this.show('success', message, title, options);
62
+ }
63
+ error(message, title, options) {
64
+ return this.show('error', message, title, options);
65
+ }
66
+ info(message, title, options) {
67
+ return this.show('info', message, title, options);
68
+ }
69
+ warning(message, title, options) {
70
+ return this.show('warning', message, title, options);
71
+ }
72
+ remove(toastId) {
73
+ const ref = this.toasts.get(toastId);
74
+ if (ref) {
75
+ ref.instance.remove();
76
+ }
77
+ }
78
+ /** Called by ToastComponent when removal animation completes */
79
+ removeToast(toastId) {
80
+ const ref = this.toasts.get(toastId);
81
+ if (ref) {
82
+ this.appRef.detachView(ref.hostView);
83
+ ref.destroy();
84
+ this.toasts.delete(toastId);
85
+ }
86
+ if (this.toasts.size === 0 && this.containerRef) {
87
+ this.appRef.detachView(this.containerRef.hostView);
88
+ this.containerRef.destroy();
89
+ this.containerRef = null;
90
+ }
91
+ }
92
+ getActiveToasts() {
93
+ return Array.from(this.toasts.entries()).map(([id, ref]) => ({
94
+ toastId: id,
95
+ message: ref.instance.message,
96
+ title: ref.instance.title,
97
+ type: ref.instance.type,
98
+ config: ref.instance.config
99
+ }));
100
+ }
101
+ updateToast(toastId, message, title) {
102
+ const ref = this.toasts.get(toastId);
103
+ if (ref) {
104
+ ref.instance.message = message;
105
+ ref.instance.title = title;
106
+ }
107
+ }
108
+ show(type, message, title, options) {
109
+ const mergedConfig = { ...this.config, ...options };
110
+ // Prevent duplicates
111
+ if (mergedConfig.preventDuplicates) {
112
+ if (this.lastMessage === message && this.lastTitle === title) {
113
+ // Return last toast id
114
+ const lastEntry = Array.from(this.toasts.entries()).pop();
115
+ if (lastEntry) {
116
+ return { toastId: lastEntry[0] };
117
+ }
118
+ }
119
+ }
120
+ // Enforce max opened
121
+ if (mergedConfig.maxOpened && this.toasts.size >= mergedConfig.maxOpened) {
122
+ const firstKey = this.toasts.keys().next().value;
123
+ this.remove(firstKey);
124
+ }
125
+ this.lastMessage = message;
126
+ this.lastTitle = title;
127
+ const toastId = ++this.toastIdCounter;
128
+ const container = this.getOrCreateContainer(mergedConfig.positionClass || 'toast-bottom-right');
129
+ const toastRef = createComponent(ToastComponent, {
130
+ environmentInjector: this.appRef.injector
131
+ });
132
+ toastRef.instance.toastId = toastId;
133
+ toastRef.instance.type = type;
134
+ toastRef.instance.message = message;
135
+ toastRef.instance.title = title;
136
+ toastRef.instance.config = mergedConfig;
137
+ toastRef.instance.enableHtml = mergedConfig.enableHtml ?? true;
138
+ toastRef.instance.showIcon = mergedConfig.showIcon ?? false;
139
+ this.toasts.set(toastId, toastRef);
140
+ this.appRef.attachView(toastRef.hostView);
141
+ container.location.nativeElement.appendChild(toastRef.location.nativeElement);
142
+ return { toastId };
143
+ }
144
+ getOrCreateContainer(positionClass) {
145
+ if (this.containerRef) {
146
+ return this.containerRef;
147
+ }
148
+ this.containerRef = createComponent(ToastContainerComponent, {
149
+ environmentInjector: this.appRef.injector
150
+ });
151
+ this.appRef.attachView(this.containerRef.hostView);
152
+ const el = this.containerRef.location.nativeElement;
153
+ el.classList.add(positionClass);
154
+ this.document.body.appendChild(el);
155
+ return this.containerRef;
156
+ }
157
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.19", ngImport: i0, type: ToastService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
158
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.19", ngImport: i0, type: ToastService, providedIn: 'root' });
28
159
  }
160
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.19", ngImport: i0, type: ToastService, decorators: [{
161
+ type: Injectable,
162
+ args: [{ providedIn: 'root' }]
163
+ }] });
29
164
 
30
- /**
31
- * @deprecated import the provideMessage directly
32
- */
33
- class IgoMessageModule {
34
- static forRoot() {
35
- return {
36
- ngModule: IgoMessageModule,
37
- providers: []
38
- };
39
- }
40
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: IgoMessageModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
41
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "21.2.10", ngImport: i0, type: IgoMessageModule });
42
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: IgoMessageModule, providers: [provideMessage()] });
165
+ class ToastComponent {
166
+ toastService = inject(ToastService);
167
+ sanitizer = inject(DomSanitizer);
168
+ toastId;
169
+ type;
170
+ title = '';
171
+ config;
172
+ enableHtml = false;
173
+ showIcon = false;
174
+ _message = '';
175
+ safeMessage = '';
176
+ get message() {
177
+ return this._message;
178
+ }
179
+ set message(value) {
180
+ this._message = value;
181
+ this.safeMessage = this.sanitizer.bypassSecurityTrustHtml(value);
182
+ }
183
+ progress = signal(100, ...(ngDevMode ? [{ debugName: "progress" }] : /* istanbul ignore next */ []));
184
+ animationState = signal('inactive', ...(ngDevMode ? [{ debugName: "animationState" }] : /* istanbul ignore next */ []));
185
+ timeoutId = null;
186
+ progressIntervalId = null;
187
+ startTime = 0;
188
+ remainingTime = 0;
189
+ totalTimeOut = 0;
190
+ ngOnInit() {
191
+ this.animationState.set('active');
192
+ if (!this.config.disableTimeOut) {
193
+ this.remainingTime = this.config.timeOut ?? 10000;
194
+ this.totalTimeOut = this.remainingTime;
195
+ this.startTimer();
196
+ }
197
+ }
198
+ ngOnDestroy() {
199
+ this.clearTimers();
200
+ }
201
+ onEnter() {
202
+ if (!this.config.disableTimeOut) {
203
+ this.remainingTime = (this.progress() / 100) * this.totalTimeOut;
204
+ this.clearTimers();
205
+ }
206
+ }
207
+ onLeave() {
208
+ if (!this.config.disableTimeOut) {
209
+ if (!this.config.freezeProgressOnHover) {
210
+ const extendedTimeOut = this.config.extendedTimeOut ?? 10000;
211
+ this.remainingTime = extendedTimeOut;
212
+ this.totalTimeOut = extendedTimeOut;
213
+ }
214
+ this.startTimer();
215
+ }
216
+ }
217
+ onTap() {
218
+ if (this.config.tapToDismiss) {
219
+ this.remove();
220
+ }
221
+ }
222
+ close(event) {
223
+ event.stopPropagation();
224
+ this.remove();
225
+ }
226
+ remove() {
227
+ this.clearTimers();
228
+ this.animationState.set('removed');
229
+ setTimeout(() => {
230
+ this.toastService.removeToast(this.toastId);
231
+ }, 300);
232
+ }
233
+ startTimer() {
234
+ this.startTime = Date.now();
235
+ const duration = this.remainingTime;
236
+ this.progress.set((duration / this.totalTimeOut) * 100);
237
+ this.progressIntervalId = setInterval(() => {
238
+ const elapsed = Date.now() - this.startTime;
239
+ const remaining = Math.max(0, duration - elapsed);
240
+ this.progress.set((remaining / this.totalTimeOut) * 100);
241
+ }, 50);
242
+ this.timeoutId = setTimeout(() => {
243
+ this.remove();
244
+ }, duration);
245
+ }
246
+ clearTimers() {
247
+ if (this.timeoutId) {
248
+ clearTimeout(this.timeoutId);
249
+ this.timeoutId = null;
250
+ }
251
+ if (this.progressIntervalId) {
252
+ clearInterval(this.progressIntervalId);
253
+ this.progressIntervalId = null;
254
+ }
255
+ }
256
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.19", ngImport: i0, type: ToastComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
257
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.19", type: ToastComponent, isStandalone: true, selector: "igo-toast", host: { listeners: { "mouseenter": "onEnter()", "mouseleave": "onLeave()", "touchstart": "onEnter()", "touchend": "onLeave()" }, properties: { "class": "animationState()" } }, ngImport: i0, template: "<div\n class=\"igo-toast\"\n [ngClass]=\"'toast-' + type\"\n [attr.tabindex]=\"config.tapToDismiss ? '0' : null\"\n (click)=\"onTap()\"\n (keydown.enter)=\"onTap()\"\n>\n @if (showIcon) {\n <mat-icon class=\"toast-icon\">\n @switch (type) {\n @case ('success') {\n check_circle\n }\n @case ('error') {\n error\n }\n @case ('warning') {\n warning\n }\n @default {\n info\n }\n }\n </mat-icon>\n }\n <div class=\"toast-content\">\n @if (title) {\n <header class=\"toast-title\">{{ title }}</header>\n }\n @if (!enableHtml) {\n <p class=\"toast-message\">{{ message }}</p>\n } @else {\n <p class=\"toast-message\" [innerHTML]=\"safeMessage\"></p>\n }\n </div>\n @if (config.closeButton) {\n <button matIconButton class=\"toast-close-button\" (click)=\"close($event)\">\n <mat-icon>close</mat-icon>\n </button>\n }\n @if (config.progressBar && !config.disableTimeOut) {\n <mat-progress-bar mode=\"determinate\" [value]=\"progress()\" />\n }\n</div>\n", styles: [":host{display:block;pointer-events:all;opacity:0;transition:opacity .3s ease-out}:host.active{opacity:1;transition:opacity .3s ease-in}:host.inactive,:host.removed{opacity:0}:host ::ng-deep .mdc-linear-progress__bar{transition:transform .15s 0ms cubic-bezier(.4,0,.6,1)}.igo-toast{position:relative;overflow:hidden;padding:12px 16px;border-radius:4px;box-shadow:0 3px 6px -1px #0000001f,0 10px 36px -4px #4d60e84d;color:#fff;min-width:300px;max-width:400px;cursor:pointer;display:flex;align-items:flex-start;gap:12px}.toast-success{background-color:#51a351}.toast-error{background-color:#bd362f}.toast-info{background-color:#2f96b4}.toast-warning{background-color:#f89406}.toast-show{background-color:#2f96b4}.toast-icon{flex-shrink:0;font-size:22px;width:22px;height:22px}.toast-content{flex:1;min-width:0}.toast-title{font-weight:700;font-size:var(--sdg-font-size-h5, 19px);line-height:24px}.toast-message{color:inherit;font-size:13px;word-wrap:break-word;margin-bottom:0!important}.toast-close-button{position:absolute;top:4px;right:4px;opacity:.8;color:inherit}.toast-close-button:hover{opacity:1}mat-progress-bar{position:absolute;bottom:0;left:0;width:100%;--mdc-linear-progress-active-indicator-transition-duration: 0ms;--mdc-linear-progress-active-indicator-color: rgba( 255, 255, 255, .7 ) !important;--mdc-linear-progress-track-color: rgba(255, 255, 255, .3) !important;--mat-progress-bar-active-indicator-color: rgba(255, 255, 255, .7);--mat-progress-bar-track-color: rgba(255, 255, 255, .3);--mdc-linear-progress-track-height: 3px;--mdc-linear-progress-active-indicator-height: 3px}\n"], dependencies: [{ kind: "directive", type: NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { kind: "ngmodule", type: MatIconModule }, { kind: "component", type: i1.MatIcon, selector: "mat-icon", inputs: ["color", "inline", "svgIcon", "fontSet", "fontIcon"], exportAs: ["matIcon"] }, { kind: "component", type: MatIconButton, selector: "button[mat-icon-button], a[mat-icon-button], button[matIconButton], a[matIconButton]", exportAs: ["matButton", "matAnchor"] }, { kind: "component", type: MatProgressBar, selector: "mat-progress-bar", inputs: ["color", "value", "bufferValue", "mode"], outputs: ["animationEnd"], exportAs: ["matProgressBar"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
43
258
  }
44
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: IgoMessageModule, decorators: [{
45
- type: NgModule,
46
- args: [{
47
- imports: [],
48
- providers: [provideMessage()],
49
- exports: []
50
- }]
259
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.19", ngImport: i0, type: ToastComponent, decorators: [{
260
+ type: Component,
261
+ args: [{ selector: 'igo-toast', standalone: true, imports: [NgClass, MatIconModule, MatIconButton, MatProgressBar], changeDetection: ChangeDetectionStrategy.OnPush, host: {
262
+ '[class]': 'animationState()',
263
+ '(mouseenter)': 'onEnter()',
264
+ '(mouseleave)': 'onLeave()',
265
+ '(touchstart)': 'onEnter()',
266
+ '(touchend)': 'onLeave()'
267
+ }, template: "<div\n class=\"igo-toast\"\n [ngClass]=\"'toast-' + type\"\n [attr.tabindex]=\"config.tapToDismiss ? '0' : null\"\n (click)=\"onTap()\"\n (keydown.enter)=\"onTap()\"\n>\n @if (showIcon) {\n <mat-icon class=\"toast-icon\">\n @switch (type) {\n @case ('success') {\n check_circle\n }\n @case ('error') {\n error\n }\n @case ('warning') {\n warning\n }\n @default {\n info\n }\n }\n </mat-icon>\n }\n <div class=\"toast-content\">\n @if (title) {\n <header class=\"toast-title\">{{ title }}</header>\n }\n @if (!enableHtml) {\n <p class=\"toast-message\">{{ message }}</p>\n } @else {\n <p class=\"toast-message\" [innerHTML]=\"safeMessage\"></p>\n }\n </div>\n @if (config.closeButton) {\n <button matIconButton class=\"toast-close-button\" (click)=\"close($event)\">\n <mat-icon>close</mat-icon>\n </button>\n }\n @if (config.progressBar && !config.disableTimeOut) {\n <mat-progress-bar mode=\"determinate\" [value]=\"progress()\" />\n }\n</div>\n", styles: [":host{display:block;pointer-events:all;opacity:0;transition:opacity .3s ease-out}:host.active{opacity:1;transition:opacity .3s ease-in}:host.inactive,:host.removed{opacity:0}:host ::ng-deep .mdc-linear-progress__bar{transition:transform .15s 0ms cubic-bezier(.4,0,.6,1)}.igo-toast{position:relative;overflow:hidden;padding:12px 16px;border-radius:4px;box-shadow:0 3px 6px -1px #0000001f,0 10px 36px -4px #4d60e84d;color:#fff;min-width:300px;max-width:400px;cursor:pointer;display:flex;align-items:flex-start;gap:12px}.toast-success{background-color:#51a351}.toast-error{background-color:#bd362f}.toast-info{background-color:#2f96b4}.toast-warning{background-color:#f89406}.toast-show{background-color:#2f96b4}.toast-icon{flex-shrink:0;font-size:22px;width:22px;height:22px}.toast-content{flex:1;min-width:0}.toast-title{font-weight:700;font-size:var(--sdg-font-size-h5, 19px);line-height:24px}.toast-message{color:inherit;font-size:13px;word-wrap:break-word;margin-bottom:0!important}.toast-close-button{position:absolute;top:4px;right:4px;opacity:.8;color:inherit}.toast-close-button:hover{opacity:1}mat-progress-bar{position:absolute;bottom:0;left:0;width:100%;--mdc-linear-progress-active-indicator-transition-duration: 0ms;--mdc-linear-progress-active-indicator-color: rgba( 255, 255, 255, .7 ) !important;--mdc-linear-progress-track-color: rgba(255, 255, 255, .3) !important;--mat-progress-bar-active-indicator-color: rgba(255, 255, 255, .7);--mat-progress-bar-track-color: rgba(255, 255, 255, .3);--mdc-linear-progress-track-height: 3px;--mdc-linear-progress-active-indicator-height: 3px}\n"] }]
51
268
  }] });
52
269
 
53
- var MessageType;
54
- (function (MessageType) {
55
- MessageType["ERROR"] = "error";
56
- MessageType["ALERT"] = "warning";
57
- // eslint-disable-next-line @typescript-eslint/no-duplicate-enum-values
58
- MessageType["WARNING"] = "warning";
59
- MessageType["INFO"] = "info";
60
- MessageType["SUCCESS"] = "success";
61
- MessageType["SHOW"] = "show";
62
- })(MessageType || (MessageType = {}));
270
+ /**
271
+ * Provides the message service with custom toast configuration.
272
+ * Since ToastService is providedIn: 'root', this simply configures it.
273
+ */
274
+ function provideMessage(config) {
275
+ return provideAppInitializer(() => {
276
+ if (!config) {
277
+ return;
278
+ }
279
+ inject(ToastService).configure(config);
280
+ });
281
+ }
63
282
 
64
283
  class MessageService {
65
- injector = inject(Injector);
66
284
  configService = inject(ConfigService);
67
285
  languageService = inject(LanguageService);
286
+ toastService = inject(ToastService);
68
287
  messages$ = new BehaviorSubject([]);
69
288
  options;
70
- activeMessageTranslations = [];
71
289
  constructor() {
72
290
  this.options = this.configService.getConfig('message');
73
- this.languageService.language$
74
- .pipe(debounceTime(500), takeUntilDestroyed())
75
- .subscribe(() => {
76
- if (this.toastr.toasts.length === 0) {
77
- this.activeMessageTranslations = [];
78
- }
79
- this.toastr.toasts.forEach((toast) => {
80
- const activeMessageTranslation = this.activeMessageTranslations.find((amt) => amt.id === toast.toastId);
81
- if (activeMessageTranslation) {
82
- const translatedTextInterpolateParams = {
83
- ...activeMessageTranslation.textInterpolateParams
84
- };
85
- const translatedTitleInterpolateParams = {
86
- ...activeMessageTranslation.titleInterpolateParams
87
- };
88
- if (activeMessageTranslation.textInterpolateParams) {
89
- Object.keys(activeMessageTranslation.textInterpolateParams).forEach((k) => {
90
- if (k) {
91
- translatedTextInterpolateParams[k] =
92
- this.languageService.translate.instant(activeMessageTranslation.textInterpolateParams[k]);
93
- }
94
- });
95
- }
96
- if (activeMessageTranslation.titleInterpolateParams) {
97
- Object.keys(activeMessageTranslation.titleInterpolateParams).forEach((k) => {
98
- if (k) {
99
- translatedTitleInterpolateParams[k] =
100
- this.languageService.translate.instant(activeMessageTranslation.titleInterpolateParams[k]);
101
- }
102
- });
103
- }
104
- forkJoin([
105
- this.languageService.translate.get(activeMessageTranslation.textKey, translatedTextInterpolateParams),
106
- this.languageService.translate.get(activeMessageTranslation.titleKey, translatedTitleInterpolateParams)
107
- ])
108
- .pipe(first())
109
- .subscribe((res) => {
110
- const instance = toast.toastRef.componentInstance;
111
- instance.message = res[0];
112
- instance.title = res[1];
113
- });
114
- }
115
- });
116
- });
117
- }
118
- get toastr() {
119
- return this.injector.get(ToastrService);
120
291
  }
121
292
  showError(httpError) {
122
- httpError.error.caught = true;
123
- return this.error(httpError.error.message, httpError.error.title);
293
+ const errorPayload = httpError.error;
294
+ if (errorPayload && typeof errorPayload === 'object') {
295
+ errorPayload.caught = true;
296
+ }
297
+ const message = typeof errorPayload?.message === 'string'
298
+ ? errorPayload.message
299
+ : httpError.message;
300
+ const title = typeof errorPayload?.title === 'string'
301
+ ? errorPayload.title
302
+ : 'igo.core.message.error';
303
+ return this.error(message, title);
124
304
  }
125
305
  message(message) {
126
- const messageType = message.type;
127
- this.toastr.toastrConfig.iconClasses[messageType] = `toast-${messageType}`;
128
306
  this.messages$.next(this.messages$.value.concat([message]));
129
- message.options = message.options || {};
307
+ const options = { ...(message.options ?? {}) };
130
308
  const currentDate = new Date();
131
- message.options.from = message.options.from
132
- ? message.options.from
133
- : new Date('1 jan 1900');
134
- message.options.to = message.options.to
135
- ? message.options.to
136
- : new Date('1 jan 3000');
137
- if (typeof message.options.from === 'string') {
138
- message.options.from = new Date(Date.parse(message.options.from.replace(/-/g, ' ')));
139
- }
140
- if (typeof message.options.to === 'string') {
141
- message.options.to = new Date(Date.parse(message.options.to.replace(/-/g, ' ')));
309
+ const fromDate = this.parseDate(options.from, new Date('1 jan 1900'));
310
+ const toDate = this.parseDate(options.to, new Date('1 jan 3000'));
311
+ options.from = fromDate;
312
+ options.to = toDate;
313
+ if (message.showIcon !== undefined) {
314
+ options.showIcon = message.showIcon;
142
315
  }
143
- if (currentDate > message.options.from &&
144
- currentDate < message.options.to) {
145
- if (message.showIcon === false) {
146
- this.toastr.toastrConfig.iconClasses[messageType] =
147
- `toast-${messageType} toast-no-icon`;
148
- }
316
+ if (currentDate >= fromDate && currentDate <= toDate) {
149
317
  message = this.handleTemplate(message);
150
318
  if (message.text) {
151
319
  let messageShown;
152
320
  switch (message.type) {
153
321
  case MessageType.SUCCESS:
154
- messageShown = this.success(message.text, message.title, message.options, message.textInterpolateParams, message.titleInterpolateParams);
322
+ messageShown = this.success(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
155
323
  break;
156
324
  case MessageType.ERROR:
157
- messageShown = this.error(message.text, message.title, message.options, message.textInterpolateParams, message.titleInterpolateParams);
325
+ messageShown = this.error(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
158
326
  break;
159
327
  case MessageType.INFO:
160
- messageShown = this.info(message.text, message.title, message.options, message.textInterpolateParams, message.titleInterpolateParams);
161
- break;
162
328
  case MessageType.SHOW:
163
- messageShown = this.show(message.text, message.title, message.options, message.textInterpolateParams, message.titleInterpolateParams);
329
+ messageShown = this.info(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
164
330
  break;
165
331
  case MessageType.ALERT:
166
332
  case MessageType.WARNING:
167
- messageShown = this.alert(message.text, message.title, message.options, message.textInterpolateParams, message.titleInterpolateParams);
333
+ messageShown = this.alert(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
168
334
  break;
169
335
  default:
170
- messageShown = this.info(message.text, message.title, message.options, message.textInterpolateParams, message.titleInterpolateParams);
336
+ messageShown = this.info(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
171
337
  break;
172
338
  }
173
- message.options.id = messageShown.toastId;
339
+ options.id = messageShown.toastId;
340
+ message.options = options;
174
341
  }
175
342
  }
176
343
  }
177
344
  success(text, title = 'igo.core.message.success', options = {}, textInterpolateParams, titleInterpolateParams) {
178
- return this.handleNgxToastr('success', text, title, options, textInterpolateParams, titleInterpolateParams);
345
+ return this.handleToast('success', text, title, options, textInterpolateParams, titleInterpolateParams);
179
346
  }
180
347
  error(text, title = 'igo.core.message.error', options = {}, textInterpolateParams, titleInterpolateParams) {
181
- return this.handleNgxToastr('error', text, title, options, textInterpolateParams, titleInterpolateParams);
348
+ return this.handleToast('error', text, title, options, textInterpolateParams, titleInterpolateParams);
182
349
  }
183
350
  info(text, title = 'igo.core.message.info', options = {}, textInterpolateParams, titleInterpolateParams) {
184
- return this.handleNgxToastr('info', text, title, options, textInterpolateParams, titleInterpolateParams);
351
+ return this.handleToast('info', text, title, options, textInterpolateParams, titleInterpolateParams);
185
352
  }
186
353
  alert(text, title = 'igo.core.message.alert', options = {}, textInterpolateParams, titleInterpolateParams) {
187
- return this.handleNgxToastr('alert', text, title, options, textInterpolateParams, titleInterpolateParams);
354
+ return this.handleToast('warning', text, title, options, textInterpolateParams, titleInterpolateParams);
188
355
  }
189
356
  show(text, title = 'igo.core.message.info', options = {}, textInterpolateParams, titleInterpolateParams) {
190
- return this.handleNgxToastr('show', text, title, options, textInterpolateParams, titleInterpolateParams);
191
- }
192
- handleNgxToastr(type, text, title, options = {}, textInterpolateParams, titleInterpolateParams) {
193
- const translatedTextInterpolateParams = { ...textInterpolateParams };
194
- const translatedTitlenterpolateParams = { ...titleInterpolateParams };
195
- if (textInterpolateParams) {
196
- Object.keys(textInterpolateParams).forEach((k) => {
197
- const value = textInterpolateParams[k];
198
- if (value) {
199
- translatedTextInterpolateParams[k] =
200
- typeof value === 'string'
201
- ? this.languageService.translate.instant(value)
202
- : value;
203
- }
204
- });
205
- }
206
- if (titleInterpolateParams) {
207
- Object.keys(titleInterpolateParams).forEach((k) => {
208
- if (k) {
209
- const value = titleInterpolateParams[k];
210
- translatedTitlenterpolateParams[k] =
211
- typeof value === 'string'
212
- ? this.languageService.translate.instant(value)
213
- : value;
214
- }
215
- });
216
- }
217
- const message = this.languageService.translate.instant(text, translatedTextInterpolateParams);
218
- const translatedTitle = this.languageService.translate.instant(title, translatedTitlenterpolateParams);
357
+ return this.handleToast('info', text, title, options, textInterpolateParams, titleInterpolateParams);
358
+ }
359
+ handleToast(type, text, title, options = {}, textInterpolateParams, titleInterpolateParams) {
360
+ const translatedTextInterpolateParams = this.translateInterpolateParams(textInterpolateParams);
361
+ const translatedTitleInterpolateParams = this.translateInterpolateParams(titleInterpolateParams);
362
+ const translatedMessage = this.languageService.translate.instant(text, translatedTextInterpolateParams);
363
+ const translatedTitle = this.languageService.translate.instant(title, translatedTitleInterpolateParams);
219
364
  let activeToast;
220
365
  switch (type) {
221
366
  case 'success':
222
- activeToast = this.toastr.success(message, translatedTitle, options);
367
+ activeToast = this.toastService.success(translatedMessage, translatedTitle, options);
223
368
  break;
224
369
  case 'error':
225
- activeToast = this.toastr.error(message, translatedTitle, options);
370
+ activeToast = this.toastService.error(translatedMessage, translatedTitle, options);
226
371
  break;
227
- case 'show':
228
372
  case 'info':
229
- activeToast = this.toastr.info(message, translatedTitle, options);
373
+ activeToast = this.toastService.info(translatedMessage, translatedTitle, options);
230
374
  break;
231
- case 'alert':
232
- activeToast = this.toastr.warning(message, translatedTitle, options);
375
+ case 'warning':
376
+ activeToast = this.toastService.warning(translatedMessage, translatedTitle, options);
233
377
  break;
234
378
  }
235
- this.activeMessageTranslations.push({
236
- id: activeToast.toastId,
237
- titleKey: title,
238
- textKey: text,
239
- textInterpolateParams,
240
- titleInterpolateParams
241
- });
242
379
  return activeToast;
243
380
  }
381
+ parseDate(value, fallback) {
382
+ if (!value) {
383
+ return fallback;
384
+ }
385
+ if (value instanceof Date) {
386
+ return value;
387
+ }
388
+ const directParse = new Date(value);
389
+ if (!Number.isNaN(directParse.getTime())) {
390
+ return directParse;
391
+ }
392
+ const normalizedParse = new Date(Date.parse(value.replace(/-/g, ' ')));
393
+ return Number.isNaN(normalizedParse.getTime()) ? fallback : normalizedParse;
394
+ }
395
+ translateInterpolateParams(params) {
396
+ if (!params) {
397
+ return {};
398
+ }
399
+ return Object.keys(params).reduce((acc, key) => {
400
+ const value = params[key];
401
+ acc[key] =
402
+ typeof value === 'string'
403
+ ? this.languageService.translate.instant(value)
404
+ : value;
405
+ return acc;
406
+ }, {});
407
+ }
244
408
  remove(id) {
245
- this.toastr.remove(id);
409
+ this.toastService.remove(id);
246
410
  }
247
411
  removeAllAreNotError() {
248
412
  for (const mess of this.messages$.value) {
249
- if (mess.type !== MessageType.ERROR) {
413
+ if (mess.options?.id && mess.type !== MessageType.ERROR) {
250
414
  this.remove(mess.options.id);
251
415
  }
252
416
  }
@@ -257,16 +421,18 @@ class MessageService {
257
421
  }
258
422
  let html = this.options?.template;
259
423
  html = html.replace('${text}', message.text);
260
- html = html.replace('${title}', message.title);
424
+ if (message.title) {
425
+ html = html.replace('${title}', message.title);
426
+ }
261
427
  message.html = undefined;
262
428
  message.text = html;
263
429
  message.title = undefined;
264
430
  return message;
265
431
  }
266
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: MessageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
267
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: MessageService, providedIn: 'root' });
432
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.19", ngImport: i0, type: MessageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
433
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.19", ngImport: i0, type: MessageService, providedIn: 'root' });
268
434
  }
269
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImport: i0, type: MessageService, decorators: [{
435
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.19", ngImport: i0, type: MessageService, decorators: [{
270
436
  type: Injectable,
271
437
  args: [{
272
438
  providedIn: 'root'
@@ -277,5 +443,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImpo
277
443
  * Generated bundle index. Do not edit.
278
444
  */
279
445
 
280
- export { IgoMessageModule, MessageService, MessageType, provideMessage };
446
+ export { DEFAULT_TOAST_CONFIG, MessageService, MessageType, ToastComponent, ToastContainerComponent, ToastService, provideMessage };
281
447
  //# sourceMappingURL=igo2-core-message.mjs.map