@igo2/core 21.0.0-next.5 → 21.0.0-next.51
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.
- package/fesm2022/igo2-core-activity.mjs +10 -10
- package/fesm2022/igo2-core-activity.mjs.map +1 -1
- package/fesm2022/igo2-core-analytics.mjs +3 -3
- package/fesm2022/igo2-core-analytics.mjs.map +1 -1
- package/fesm2022/igo2-core-auth.mjs +14 -0
- package/fesm2022/igo2-core-auth.mjs.map +1 -0
- package/fesm2022/igo2-core-config.mjs +10 -27
- package/fesm2022/igo2-core-config.mjs.map +1 -1
- package/fesm2022/igo2-core-language.mjs +14 -8
- package/fesm2022/igo2-core-language.mjs.map +1 -1
- package/fesm2022/igo2-core-media.mjs +3 -3
- package/fesm2022/igo2-core-media.mjs.map +1 -1
- package/fesm2022/igo2-core-message.mjs +348 -170
- package/fesm2022/igo2-core-message.mjs.map +1 -1
- package/fesm2022/igo2-core-monitoring.mjs.map +1 -1
- package/fesm2022/igo2-core-network.mjs +3 -3
- package/fesm2022/igo2-core-network.mjs.map +1 -1
- package/fesm2022/igo2-core-regex.mjs +3 -3
- package/fesm2022/igo2-core-regex.mjs.map +1 -1
- package/fesm2022/igo2-core-request.mjs +14 -14
- package/fesm2022/igo2-core-request.mjs.map +1 -1
- package/fesm2022/igo2-core-route.mjs +3 -3
- package/fesm2022/igo2-core-route.mjs.map +1 -1
- package/fesm2022/igo2-core-storage.mjs +5 -5
- package/fesm2022/igo2-core-storage.mjs.map +1 -1
- package/fesm2022/igo2-core.mjs +5 -6
- package/fesm2022/igo2-core.mjs.map +1 -1
- package/locale/en.json +1 -1
- package/locale/fr.json +1 -1
- package/package.json +6 -3
- package/src/style/style.scss +0 -2
- package/src/theming/themes/_theme.scss +0 -4
- package/style/all-style.css +13 -223
- package/style/style.css +0 -222
- package/theming/prebuilt-themes/blue-theme.css +0 -3
- package/theming/prebuilt-themes/bluedark-theme.css +0 -3
- package/theming/prebuilt-themes/bluedq-theme.css +0 -3
- package/theming/prebuilt-themes/teal-theme.css +0 -3
- package/types/igo2-core-auth.d.ts +16 -0
- package/types/igo2-core-message.d.ts +115 -29
- package/types/igo2-core-storage.d.ts +1 -1
|
@@ -1,168 +1,345 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { inject, output, signal, ChangeDetectionStrategy, Component, ApplicationRef, createComponent, Injectable, provideAppInitializer, Injector } from '@angular/core';
|
|
3
|
+
import { NgClass, DOCUMENT } 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
|
|
8
|
-
import { debounceTime, first } from 'rxjs/operators';
|
|
11
|
+
import { BehaviorSubject } from 'rxjs';
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
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 ToastComponent {
|
|
25
|
+
sanitizer = inject(DomSanitizer);
|
|
26
|
+
removed = output();
|
|
27
|
+
toastId;
|
|
28
|
+
type;
|
|
29
|
+
title = '';
|
|
30
|
+
config;
|
|
31
|
+
enableHtml = false;
|
|
32
|
+
showIcon = false;
|
|
33
|
+
_message = '';
|
|
34
|
+
safeMessage = '';
|
|
35
|
+
get message() {
|
|
36
|
+
return this._message;
|
|
37
|
+
}
|
|
38
|
+
set message(value) {
|
|
39
|
+
this._message = value;
|
|
40
|
+
this.safeMessage = this.sanitizer.bypassSecurityTrustHtml(value);
|
|
41
|
+
}
|
|
42
|
+
progress = signal(100, ...(ngDevMode ? [{ debugName: "progress" }] : /* istanbul ignore next */ []));
|
|
43
|
+
animationState = signal('inactive', ...(ngDevMode ? [{ debugName: "animationState" }] : /* istanbul ignore next */ []));
|
|
44
|
+
timeoutId = null;
|
|
45
|
+
progressIntervalId = null;
|
|
46
|
+
startTime = 0;
|
|
47
|
+
remainingTime = 0;
|
|
48
|
+
totalTimeOut = 0;
|
|
49
|
+
ngOnInit() {
|
|
50
|
+
this.animationState.set('active');
|
|
51
|
+
if (!this.config.disableTimeOut) {
|
|
52
|
+
this.remainingTime = this.config.timeOut ?? 10000;
|
|
53
|
+
this.totalTimeOut = this.remainingTime;
|
|
54
|
+
this.startTimer();
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
ngOnDestroy() {
|
|
58
|
+
this.clearTimers();
|
|
59
|
+
}
|
|
60
|
+
onEnter() {
|
|
61
|
+
if (!this.config.disableTimeOut) {
|
|
62
|
+
this.remainingTime = (this.progress() / 100) * this.totalTimeOut;
|
|
63
|
+
this.clearTimers();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
onLeave() {
|
|
67
|
+
if (!this.config.disableTimeOut) {
|
|
68
|
+
if (!this.config.freezeProgressOnHover) {
|
|
69
|
+
const extendedTimeOut = this.config.extendedTimeOut ?? 10000;
|
|
70
|
+
this.remainingTime = extendedTimeOut;
|
|
71
|
+
this.totalTimeOut = extendedTimeOut;
|
|
72
|
+
}
|
|
73
|
+
this.startTimer();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
onTap() {
|
|
77
|
+
if (this.config.tapToDismiss) {
|
|
78
|
+
this.remove();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
close(event) {
|
|
82
|
+
event.stopPropagation();
|
|
83
|
+
this.remove();
|
|
84
|
+
}
|
|
85
|
+
remove() {
|
|
86
|
+
this.clearTimers();
|
|
87
|
+
this.animationState.set('removed');
|
|
88
|
+
setTimeout(() => {
|
|
89
|
+
this.removed.emit(this.toastId);
|
|
90
|
+
}, 300);
|
|
91
|
+
}
|
|
92
|
+
startTimer() {
|
|
93
|
+
this.startTime = Date.now();
|
|
94
|
+
const duration = this.remainingTime;
|
|
95
|
+
this.progress.set((duration / this.totalTimeOut) * 100);
|
|
96
|
+
this.progressIntervalId = setInterval(() => {
|
|
97
|
+
const elapsed = Date.now() - this.startTime;
|
|
98
|
+
const remaining = Math.max(0, duration - elapsed);
|
|
99
|
+
this.progress.set((remaining / this.totalTimeOut) * 100);
|
|
100
|
+
}, 50);
|
|
101
|
+
this.timeoutId = setTimeout(() => {
|
|
102
|
+
this.remove();
|
|
103
|
+
}, duration);
|
|
104
|
+
}
|
|
105
|
+
clearTimers() {
|
|
106
|
+
if (this.timeoutId) {
|
|
107
|
+
clearTimeout(this.timeoutId);
|
|
108
|
+
this.timeoutId = null;
|
|
109
|
+
}
|
|
110
|
+
if (this.progressIntervalId) {
|
|
111
|
+
clearInterval(this.progressIntervalId);
|
|
112
|
+
this.progressIntervalId = null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ToastComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
116
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.25", type: ToastComponent, isStandalone: true, selector: "igo-toast", outputs: { removed: "removed" }, 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:var(--mat-sys-error);color:var(--mat-sys-on-error)}.toast-info{background-color:var(--mat-sys-primary);color:var(--mat-sys-on-primary)}.toast-warning{background-color:#f89406}.toast-show{background-color:var(--mat-sys-primary);color:var(--mat-sys-on-primary)}.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 });
|
|
117
|
+
}
|
|
118
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ToastComponent, decorators: [{
|
|
119
|
+
type: Component,
|
|
120
|
+
args: [{ selector: 'igo-toast', standalone: true, imports: [NgClass, MatIconModule, MatIconButton, MatProgressBar], changeDetection: ChangeDetectionStrategy.OnPush, host: {
|
|
121
|
+
'[class]': 'animationState()',
|
|
122
|
+
'(mouseenter)': 'onEnter()',
|
|
123
|
+
'(mouseleave)': 'onLeave()',
|
|
124
|
+
'(touchstart)': 'onEnter()',
|
|
125
|
+
'(touchend)': 'onLeave()'
|
|
126
|
+
}, 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:var(--mat-sys-error);color:var(--mat-sys-on-error)}.toast-info{background-color:var(--mat-sys-primary);color:var(--mat-sys-on-primary)}.toast-warning{background-color:#f89406}.toast-show{background-color:var(--mat-sys-primary);color:var(--mat-sys-on-primary)}.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"] }]
|
|
127
|
+
}], propDecorators: { removed: [{ type: i0.Output, args: ["removed"] }] } });
|
|
128
|
+
|
|
129
|
+
class ToastContainerComponent {
|
|
130
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ToastContainerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
131
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.25", 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 });
|
|
132
|
+
}
|
|
133
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ToastContainerComponent, decorators: [{
|
|
134
|
+
type: Component,
|
|
135
|
+
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"] }]
|
|
136
|
+
}] });
|
|
137
|
+
|
|
138
|
+
const DEFAULT_TOAST_CONFIG = {
|
|
12
139
|
timeOut: 10000,
|
|
13
140
|
extendedTimeOut: 10000,
|
|
14
|
-
titleClass: 'toastr-message-title',
|
|
15
|
-
messageClass: 'toast-message',
|
|
16
141
|
closeButton: true,
|
|
17
142
|
progressBar: true,
|
|
18
|
-
enableHtml: true,
|
|
19
143
|
tapToDismiss: true,
|
|
144
|
+
positionClass: 'toast-bottom-right',
|
|
20
145
|
maxOpened: 4,
|
|
21
146
|
preventDuplicates: true,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
147
|
+
enableHtml: true,
|
|
148
|
+
disableTimeOut: false,
|
|
149
|
+
showIcon: false,
|
|
150
|
+
freezeProgressOnHover: true
|
|
25
151
|
};
|
|
26
|
-
|
|
27
|
-
|
|
152
|
+
|
|
153
|
+
class ToastService {
|
|
154
|
+
appRef = inject(ApplicationRef);
|
|
155
|
+
document = inject(DOCUMENT);
|
|
156
|
+
toastIdCounter = 0;
|
|
157
|
+
toasts = new Map();
|
|
158
|
+
containerRef = null;
|
|
159
|
+
config = { ...DEFAULT_TOAST_CONFIG };
|
|
160
|
+
lastMessage = '';
|
|
161
|
+
lastTitle = '';
|
|
162
|
+
configure(config) {
|
|
163
|
+
this.config = { ...this.config, ...config };
|
|
164
|
+
}
|
|
165
|
+
success(message, title, options) {
|
|
166
|
+
return this.show('success', message, title, options);
|
|
167
|
+
}
|
|
168
|
+
error(message, title, options) {
|
|
169
|
+
return this.show('error', message, title, options);
|
|
170
|
+
}
|
|
171
|
+
info(message, title, options) {
|
|
172
|
+
return this.show('info', message, title, options);
|
|
173
|
+
}
|
|
174
|
+
warning(message, title, options) {
|
|
175
|
+
return this.show('warning', message, title, options);
|
|
176
|
+
}
|
|
177
|
+
remove(toastId) {
|
|
178
|
+
const ref = this.toasts.get(toastId);
|
|
179
|
+
if (ref) {
|
|
180
|
+
ref.instance.remove();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** Called by ToastComponent when removal animation completes */
|
|
184
|
+
removeToast(toastId) {
|
|
185
|
+
const ref = this.toasts.get(toastId);
|
|
186
|
+
if (ref) {
|
|
187
|
+
this.appRef.detachView(ref.hostView);
|
|
188
|
+
ref.destroy();
|
|
189
|
+
this.toasts.delete(toastId);
|
|
190
|
+
}
|
|
191
|
+
if (this.toasts.size === 0 && this.containerRef) {
|
|
192
|
+
this.appRef.detachView(this.containerRef.hostView);
|
|
193
|
+
this.containerRef.destroy();
|
|
194
|
+
this.containerRef = null;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
getActiveToasts() {
|
|
198
|
+
return Array.from(this.toasts.entries()).map(([id, ref]) => ({
|
|
199
|
+
toastId: id,
|
|
200
|
+
message: ref.instance.message,
|
|
201
|
+
title: ref.instance.title,
|
|
202
|
+
type: ref.instance.type,
|
|
203
|
+
config: ref.instance.config
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
updateToast(toastId, message, title) {
|
|
207
|
+
const ref = this.toasts.get(toastId);
|
|
208
|
+
if (ref) {
|
|
209
|
+
ref.instance.message = message;
|
|
210
|
+
ref.instance.title = title;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
show(type, message, title, options) {
|
|
214
|
+
const mergedConfig = { ...this.config, ...options };
|
|
215
|
+
// Prevent duplicates
|
|
216
|
+
if (mergedConfig.preventDuplicates) {
|
|
217
|
+
if (this.lastMessage === message && this.lastTitle === title) {
|
|
218
|
+
// Return last toast id
|
|
219
|
+
const lastEntry = Array.from(this.toasts.entries()).pop();
|
|
220
|
+
if (lastEntry) {
|
|
221
|
+
return { toastId: lastEntry[0] };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Enforce max opened
|
|
226
|
+
if (mergedConfig.maxOpened && this.toasts.size >= mergedConfig.maxOpened) {
|
|
227
|
+
const firstKey = this.toasts.keys().next().value;
|
|
228
|
+
this.remove(firstKey);
|
|
229
|
+
}
|
|
230
|
+
this.lastMessage = message;
|
|
231
|
+
this.lastTitle = title;
|
|
232
|
+
const toastId = ++this.toastIdCounter;
|
|
233
|
+
const container = this.getOrCreateContainer(mergedConfig.positionClass || 'toast-bottom-right');
|
|
234
|
+
const toastRef = createComponent(ToastComponent, {
|
|
235
|
+
environmentInjector: this.appRef.injector
|
|
236
|
+
});
|
|
237
|
+
toastRef.instance.toastId = toastId;
|
|
238
|
+
toastRef.instance.type = type;
|
|
239
|
+
toastRef.instance.message = message;
|
|
240
|
+
toastRef.instance.title = title;
|
|
241
|
+
toastRef.instance.config = mergedConfig;
|
|
242
|
+
toastRef.instance.enableHtml = mergedConfig.enableHtml ?? true;
|
|
243
|
+
toastRef.instance.showIcon = mergedConfig.showIcon ?? false;
|
|
244
|
+
toastRef.instance.removed.subscribe((removedToastId) => {
|
|
245
|
+
this.removeToast(removedToastId);
|
|
246
|
+
});
|
|
247
|
+
this.toasts.set(toastId, toastRef);
|
|
248
|
+
this.appRef.attachView(toastRef.hostView);
|
|
249
|
+
container.location.nativeElement.appendChild(toastRef.location.nativeElement);
|
|
250
|
+
return { toastId };
|
|
251
|
+
}
|
|
252
|
+
getOrCreateContainer(positionClass) {
|
|
253
|
+
if (this.containerRef) {
|
|
254
|
+
return this.containerRef;
|
|
255
|
+
}
|
|
256
|
+
this.containerRef = createComponent(ToastContainerComponent, {
|
|
257
|
+
environmentInjector: this.appRef.injector
|
|
258
|
+
});
|
|
259
|
+
this.appRef.attachView(this.containerRef.hostView);
|
|
260
|
+
const el = this.containerRef.location.nativeElement;
|
|
261
|
+
el.classList.add(positionClass);
|
|
262
|
+
this.document.body.appendChild(el);
|
|
263
|
+
return this.containerRef;
|
|
264
|
+
}
|
|
265
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ToastService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
266
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ToastService, providedIn: 'root' });
|
|
28
267
|
}
|
|
268
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: ToastService, decorators: [{
|
|
269
|
+
type: Injectable,
|
|
270
|
+
args: [{ providedIn: 'root' }]
|
|
271
|
+
}] });
|
|
29
272
|
|
|
30
273
|
/**
|
|
31
|
-
*
|
|
274
|
+
* Provides the message service with custom toast configuration.
|
|
275
|
+
* Since ToastService is providedIn: 'root', this simply configures it.
|
|
32
276
|
*/
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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()] });
|
|
277
|
+
function provideMessage(config) {
|
|
278
|
+
return provideAppInitializer(() => {
|
|
279
|
+
if (!config) {
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
inject(ToastService).configure(config);
|
|
283
|
+
});
|
|
43
284
|
}
|
|
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
|
-
}]
|
|
51
|
-
}] });
|
|
52
|
-
|
|
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 = {}));
|
|
63
285
|
|
|
64
286
|
class MessageService {
|
|
65
|
-
injector = inject(Injector);
|
|
66
287
|
configService = inject(ConfigService);
|
|
67
|
-
|
|
288
|
+
injector = inject(Injector);
|
|
289
|
+
toastService = inject(ToastService);
|
|
68
290
|
messages$ = new BehaviorSubject([]);
|
|
69
291
|
options;
|
|
70
|
-
|
|
292
|
+
get languageService() {
|
|
293
|
+
return this.injector.get(LanguageService, null);
|
|
294
|
+
}
|
|
71
295
|
constructor() {
|
|
72
296
|
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
297
|
}
|
|
121
298
|
showError(httpError) {
|
|
122
|
-
httpError.error
|
|
123
|
-
|
|
299
|
+
const errorPayload = httpError.error;
|
|
300
|
+
if (errorPayload && typeof errorPayload === 'object') {
|
|
301
|
+
errorPayload.caught = true;
|
|
302
|
+
}
|
|
303
|
+
const message = typeof errorPayload?.message === 'string'
|
|
304
|
+
? errorPayload.message
|
|
305
|
+
: httpError.message;
|
|
306
|
+
const title = typeof errorPayload?.title === 'string'
|
|
307
|
+
? errorPayload.title
|
|
308
|
+
: 'igo.core.message.error';
|
|
309
|
+
return this.error(message, title);
|
|
124
310
|
}
|
|
125
311
|
message(message) {
|
|
126
|
-
const messageType = message.type;
|
|
127
|
-
this.toastr.toastrConfig.iconClasses[messageType] = `toast-${messageType}`;
|
|
128
312
|
this.messages$.next(this.messages$.value.concat([message]));
|
|
129
|
-
const options = message.options
|
|
313
|
+
const options = { ...(message.options ?? {}) };
|
|
130
314
|
const currentDate = new Date();
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
315
|
+
const fromDate = this.parseDate(options.from, new Date('1 jan 1900'));
|
|
316
|
+
const toDate = this.parseDate(options.to, new Date('1 jan 3000'));
|
|
317
|
+
options.from = fromDate;
|
|
318
|
+
options.to = toDate;
|
|
319
|
+
if (message.showIcon !== undefined) {
|
|
320
|
+
options.showIcon = message.showIcon;
|
|
135
321
|
}
|
|
136
|
-
if (
|
|
137
|
-
options.to = new Date(Date.parse(options.to.replace(/-/g, ' ')));
|
|
138
|
-
}
|
|
139
|
-
if (currentDate > options.from && currentDate < options.to) {
|
|
140
|
-
if (message.showIcon === false) {
|
|
141
|
-
this.toastr.toastrConfig.iconClasses[messageType] =
|
|
142
|
-
`toast-${messageType} toast-no-icon`;
|
|
143
|
-
}
|
|
322
|
+
if (currentDate >= fromDate && currentDate <= toDate) {
|
|
144
323
|
message = this.handleTemplate(message);
|
|
145
324
|
if (message.text) {
|
|
146
325
|
let messageShown;
|
|
147
326
|
switch (message.type) {
|
|
148
327
|
case MessageType.SUCCESS:
|
|
149
|
-
messageShown = this.success(message.text, message.title,
|
|
328
|
+
messageShown = this.success(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
|
|
150
329
|
break;
|
|
151
330
|
case MessageType.ERROR:
|
|
152
|
-
messageShown = this.error(message.text, message.title,
|
|
331
|
+
messageShown = this.error(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
|
|
153
332
|
break;
|
|
154
333
|
case MessageType.INFO:
|
|
155
|
-
messageShown = this.info(message.text, message.title, message.options, message.textInterpolateParams, message.titleInterpolateParams);
|
|
156
|
-
break;
|
|
157
334
|
case MessageType.SHOW:
|
|
158
|
-
messageShown = this.
|
|
335
|
+
messageShown = this.info(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
|
|
159
336
|
break;
|
|
160
337
|
case MessageType.ALERT:
|
|
161
338
|
case MessageType.WARNING:
|
|
162
|
-
messageShown = this.alert(message.text, message.title,
|
|
339
|
+
messageShown = this.alert(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
|
|
163
340
|
break;
|
|
164
341
|
default:
|
|
165
|
-
messageShown = this.info(message.text, message.title,
|
|
342
|
+
messageShown = this.info(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
|
|
166
343
|
break;
|
|
167
344
|
}
|
|
168
345
|
options.id = messageShown.toastId;
|
|
@@ -171,74 +348,75 @@ class MessageService {
|
|
|
171
348
|
}
|
|
172
349
|
}
|
|
173
350
|
success(text, title = 'igo.core.message.success', options = {}, textInterpolateParams, titleInterpolateParams) {
|
|
174
|
-
return this.
|
|
351
|
+
return this.handleToast('success', text, title, options, textInterpolateParams, titleInterpolateParams);
|
|
175
352
|
}
|
|
176
353
|
error(text, title = 'igo.core.message.error', options = {}, textInterpolateParams, titleInterpolateParams) {
|
|
177
|
-
return this.
|
|
354
|
+
return this.handleToast('error', text, title, options, textInterpolateParams, titleInterpolateParams);
|
|
178
355
|
}
|
|
179
356
|
info(text, title = 'igo.core.message.info', options = {}, textInterpolateParams, titleInterpolateParams) {
|
|
180
|
-
return this.
|
|
357
|
+
return this.handleToast('info', text, title, options, textInterpolateParams, titleInterpolateParams);
|
|
181
358
|
}
|
|
182
359
|
alert(text, title = 'igo.core.message.alert', options = {}, textInterpolateParams, titleInterpolateParams) {
|
|
183
|
-
return this.
|
|
360
|
+
return this.handleToast('warning', text, title, options, textInterpolateParams, titleInterpolateParams);
|
|
184
361
|
}
|
|
185
362
|
show(text, title = 'igo.core.message.info', options = {}, textInterpolateParams, titleInterpolateParams) {
|
|
186
|
-
return this.
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const translatedTextInterpolateParams =
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
? this.languageService.translate.instant(value)
|
|
198
|
-
: value;
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
if (titleInterpolateParams) {
|
|
203
|
-
Object.keys(titleInterpolateParams).forEach((k) => {
|
|
204
|
-
if (k) {
|
|
205
|
-
const value = titleInterpolateParams[k];
|
|
206
|
-
translatedTitlenterpolateParams[k] =
|
|
207
|
-
typeof value === 'string'
|
|
208
|
-
? this.languageService.translate.instant(value)
|
|
209
|
-
: value;
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
const message = this.languageService.translate.instant(text, translatedTextInterpolateParams);
|
|
214
|
-
const translatedTitle = this.languageService.translate.instant(title, translatedTitlenterpolateParams);
|
|
363
|
+
return this.handleToast('info', text, title, options, textInterpolateParams, titleInterpolateParams);
|
|
364
|
+
}
|
|
365
|
+
handleToast(type, text, title, options = {}, textInterpolateParams, titleInterpolateParams) {
|
|
366
|
+
const translatedTextInterpolateParams = this.translateInterpolateParams(textInterpolateParams);
|
|
367
|
+
const translatedTitleInterpolateParams = this.translateInterpolateParams(titleInterpolateParams);
|
|
368
|
+
const translatedMessage = this.languageService
|
|
369
|
+
? this.languageService.translate.instant(text, translatedTextInterpolateParams)
|
|
370
|
+
: text;
|
|
371
|
+
const translatedTitle = this.languageService
|
|
372
|
+
? this.languageService.translate.instant(title, translatedTitleInterpolateParams)
|
|
373
|
+
: title;
|
|
215
374
|
let activeToast;
|
|
216
375
|
switch (type) {
|
|
217
376
|
case 'success':
|
|
218
|
-
activeToast = this.
|
|
377
|
+
activeToast = this.toastService.success(translatedMessage, translatedTitle, options);
|
|
219
378
|
break;
|
|
220
379
|
case 'error':
|
|
221
|
-
activeToast = this.
|
|
380
|
+
activeToast = this.toastService.error(translatedMessage, translatedTitle, options);
|
|
222
381
|
break;
|
|
223
|
-
case 'show':
|
|
224
382
|
case 'info':
|
|
225
|
-
activeToast = this.
|
|
383
|
+
activeToast = this.toastService.info(translatedMessage, translatedTitle, options);
|
|
226
384
|
break;
|
|
227
|
-
case '
|
|
228
|
-
activeToast = this.
|
|
385
|
+
case 'warning':
|
|
386
|
+
activeToast = this.toastService.warning(translatedMessage, translatedTitle, options);
|
|
229
387
|
break;
|
|
230
388
|
}
|
|
231
|
-
this.activeMessageTranslations.push({
|
|
232
|
-
id: activeToast.toastId,
|
|
233
|
-
titleKey: title,
|
|
234
|
-
textKey: text,
|
|
235
|
-
textInterpolateParams,
|
|
236
|
-
titleInterpolateParams
|
|
237
|
-
});
|
|
238
389
|
return activeToast;
|
|
239
390
|
}
|
|
391
|
+
parseDate(value, fallback) {
|
|
392
|
+
if (!value) {
|
|
393
|
+
return fallback;
|
|
394
|
+
}
|
|
395
|
+
if (value instanceof Date) {
|
|
396
|
+
return value;
|
|
397
|
+
}
|
|
398
|
+
const directParse = new Date(value);
|
|
399
|
+
if (!Number.isNaN(directParse.getTime())) {
|
|
400
|
+
return directParse;
|
|
401
|
+
}
|
|
402
|
+
const normalizedParse = new Date(Date.parse(value.replace(/-/g, ' ')));
|
|
403
|
+
return Number.isNaN(normalizedParse.getTime()) ? fallback : normalizedParse;
|
|
404
|
+
}
|
|
405
|
+
translateInterpolateParams(params) {
|
|
406
|
+
if (!params) {
|
|
407
|
+
return {};
|
|
408
|
+
}
|
|
409
|
+
return Object.keys(params).reduce((acc, key) => {
|
|
410
|
+
const value = params[key];
|
|
411
|
+
acc[key] =
|
|
412
|
+
typeof value === 'string' && this.languageService
|
|
413
|
+
? this.languageService.translate.instant(value)
|
|
414
|
+
: value;
|
|
415
|
+
return acc;
|
|
416
|
+
}, {});
|
|
417
|
+
}
|
|
240
418
|
remove(id) {
|
|
241
|
-
this.
|
|
419
|
+
this.toastService.remove(id);
|
|
242
420
|
}
|
|
243
421
|
removeAllAreNotError() {
|
|
244
422
|
for (const mess of this.messages$.value) {
|
|
@@ -261,10 +439,10 @@ class MessageService {
|
|
|
261
439
|
message.title = undefined;
|
|
262
440
|
return message;
|
|
263
441
|
}
|
|
264
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.
|
|
265
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.
|
|
442
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: MessageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
443
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: MessageService, providedIn: 'root' });
|
|
266
444
|
}
|
|
267
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.
|
|
445
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.25", ngImport: i0, type: MessageService, decorators: [{
|
|
268
446
|
type: Injectable,
|
|
269
447
|
args: [{
|
|
270
448
|
providedIn: 'root'
|
|
@@ -275,5 +453,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImpo
|
|
|
275
453
|
* Generated bundle index. Do not edit.
|
|
276
454
|
*/
|
|
277
455
|
|
|
278
|
-
export {
|
|
456
|
+
export { DEFAULT_TOAST_CONFIG, MessageService, MessageType, ToastComponent, ToastContainerComponent, ToastService, provideMessage };
|
|
279
457
|
//# sourceMappingURL=igo2-core-message.mjs.map
|