@igo2/core 21.0.0-next.3 → 21.0.0-next.30
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 +7 -7
- 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 +340 -169
- 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 +1 -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 +15 -0
- package/types/igo2-core-message.d.ts +113 -28
- package/types/igo2-core-storage.d.ts +1 -1
|
@@ -1,168 +1,342 @@
|
|
|
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 } 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.23", ngImport: i0, type: ToastComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
116
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.23", 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:#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 });
|
|
117
|
+
}
|
|
118
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.23", 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:#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"] }]
|
|
127
|
+
}], propDecorators: { removed: [{ type: i0.Output, args: ["removed"] }] } });
|
|
128
|
+
|
|
129
|
+
class ToastContainerComponent {
|
|
130
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ToastContainerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
131
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "21.2.23", 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.23", 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.23", ngImport: i0, type: ToastService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
266
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: ToastService, providedIn: 'root' });
|
|
28
267
|
}
|
|
268
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.23", 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
|
languageService = inject(LanguageService);
|
|
289
|
+
toastService = inject(ToastService);
|
|
68
290
|
messages$ = new BehaviorSubject([]);
|
|
69
291
|
options;
|
|
70
|
-
activeMessageTranslations = [];
|
|
71
292
|
constructor() {
|
|
72
293
|
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
294
|
}
|
|
121
295
|
showError(httpError) {
|
|
122
|
-
httpError.error
|
|
123
|
-
|
|
296
|
+
const errorPayload = httpError.error;
|
|
297
|
+
if (errorPayload && typeof errorPayload === 'object') {
|
|
298
|
+
errorPayload.caught = true;
|
|
299
|
+
}
|
|
300
|
+
const message = typeof errorPayload?.message === 'string'
|
|
301
|
+
? errorPayload.message
|
|
302
|
+
: httpError.message;
|
|
303
|
+
const title = typeof errorPayload?.title === 'string'
|
|
304
|
+
? errorPayload.title
|
|
305
|
+
: 'igo.core.message.error';
|
|
306
|
+
return this.error(message, title);
|
|
124
307
|
}
|
|
125
308
|
message(message) {
|
|
126
|
-
const messageType = message.type;
|
|
127
|
-
this.toastr.toastrConfig.iconClasses[messageType] = `toast-${messageType}`;
|
|
128
309
|
this.messages$.next(this.messages$.value.concat([message]));
|
|
129
|
-
const options = message.options
|
|
310
|
+
const options = { ...(message.options ?? {}) };
|
|
130
311
|
const currentDate = new Date();
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
312
|
+
const fromDate = this.parseDate(options.from, new Date('1 jan 1900'));
|
|
313
|
+
const toDate = this.parseDate(options.to, new Date('1 jan 3000'));
|
|
314
|
+
options.from = fromDate;
|
|
315
|
+
options.to = toDate;
|
|
316
|
+
if (message.showIcon !== undefined) {
|
|
317
|
+
options.showIcon = message.showIcon;
|
|
135
318
|
}
|
|
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
|
-
}
|
|
319
|
+
if (currentDate >= fromDate && currentDate <= toDate) {
|
|
144
320
|
message = this.handleTemplate(message);
|
|
145
321
|
if (message.text) {
|
|
146
322
|
let messageShown;
|
|
147
323
|
switch (message.type) {
|
|
148
324
|
case MessageType.SUCCESS:
|
|
149
|
-
messageShown = this.success(message.text, message.title,
|
|
325
|
+
messageShown = this.success(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
|
|
150
326
|
break;
|
|
151
327
|
case MessageType.ERROR:
|
|
152
|
-
messageShown = this.error(message.text, message.title,
|
|
328
|
+
messageShown = this.error(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
|
|
153
329
|
break;
|
|
154
330
|
case MessageType.INFO:
|
|
155
|
-
messageShown = this.info(message.text, message.title, message.options, message.textInterpolateParams, message.titleInterpolateParams);
|
|
156
|
-
break;
|
|
157
331
|
case MessageType.SHOW:
|
|
158
|
-
messageShown = this.
|
|
332
|
+
messageShown = this.info(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
|
|
159
333
|
break;
|
|
160
334
|
case MessageType.ALERT:
|
|
161
335
|
case MessageType.WARNING:
|
|
162
|
-
messageShown = this.alert(message.text, message.title,
|
|
336
|
+
messageShown = this.alert(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
|
|
163
337
|
break;
|
|
164
338
|
default:
|
|
165
|
-
messageShown = this.info(message.text, message.title,
|
|
339
|
+
messageShown = this.info(message.text, message.title, options, message.textInterpolateParams, message.titleInterpolateParams);
|
|
166
340
|
break;
|
|
167
341
|
}
|
|
168
342
|
options.id = messageShown.toastId;
|
|
@@ -171,74 +345,71 @@ class MessageService {
|
|
|
171
345
|
}
|
|
172
346
|
}
|
|
173
347
|
success(text, title = 'igo.core.message.success', options = {}, textInterpolateParams, titleInterpolateParams) {
|
|
174
|
-
return this.
|
|
348
|
+
return this.handleToast('success', text, title, options, textInterpolateParams, titleInterpolateParams);
|
|
175
349
|
}
|
|
176
350
|
error(text, title = 'igo.core.message.error', options = {}, textInterpolateParams, titleInterpolateParams) {
|
|
177
|
-
return this.
|
|
351
|
+
return this.handleToast('error', text, title, options, textInterpolateParams, titleInterpolateParams);
|
|
178
352
|
}
|
|
179
353
|
info(text, title = 'igo.core.message.info', options = {}, textInterpolateParams, titleInterpolateParams) {
|
|
180
|
-
return this.
|
|
354
|
+
return this.handleToast('info', text, title, options, textInterpolateParams, titleInterpolateParams);
|
|
181
355
|
}
|
|
182
356
|
alert(text, title = 'igo.core.message.alert', options = {}, textInterpolateParams, titleInterpolateParams) {
|
|
183
|
-
return this.
|
|
357
|
+
return this.handleToast('warning', text, title, options, textInterpolateParams, titleInterpolateParams);
|
|
184
358
|
}
|
|
185
359
|
show(text, title = 'igo.core.message.info', options = {}, textInterpolateParams, titleInterpolateParams) {
|
|
186
|
-
return this.
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
const translatedTextInterpolateParams =
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const value = textInterpolateParams[k];
|
|
194
|
-
if (value) {
|
|
195
|
-
translatedTextInterpolateParams[k] =
|
|
196
|
-
typeof value === 'string'
|
|
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);
|
|
360
|
+
return this.handleToast('info', text, title, options, textInterpolateParams, titleInterpolateParams);
|
|
361
|
+
}
|
|
362
|
+
handleToast(type, text, title, options = {}, textInterpolateParams, titleInterpolateParams) {
|
|
363
|
+
const translatedTextInterpolateParams = this.translateInterpolateParams(textInterpolateParams);
|
|
364
|
+
const translatedTitleInterpolateParams = this.translateInterpolateParams(titleInterpolateParams);
|
|
365
|
+
const translatedMessage = this.languageService.translate.instant(text, translatedTextInterpolateParams);
|
|
366
|
+
const translatedTitle = this.languageService.translate.instant(title, translatedTitleInterpolateParams);
|
|
215
367
|
let activeToast;
|
|
216
368
|
switch (type) {
|
|
217
369
|
case 'success':
|
|
218
|
-
activeToast = this.
|
|
370
|
+
activeToast = this.toastService.success(translatedMessage, translatedTitle, options);
|
|
219
371
|
break;
|
|
220
372
|
case 'error':
|
|
221
|
-
activeToast = this.
|
|
373
|
+
activeToast = this.toastService.error(translatedMessage, translatedTitle, options);
|
|
222
374
|
break;
|
|
223
|
-
case 'show':
|
|
224
375
|
case 'info':
|
|
225
|
-
activeToast = this.
|
|
376
|
+
activeToast = this.toastService.info(translatedMessage, translatedTitle, options);
|
|
226
377
|
break;
|
|
227
|
-
case '
|
|
228
|
-
activeToast = this.
|
|
378
|
+
case 'warning':
|
|
379
|
+
activeToast = this.toastService.warning(translatedMessage, translatedTitle, options);
|
|
229
380
|
break;
|
|
230
381
|
}
|
|
231
|
-
this.activeMessageTranslations.push({
|
|
232
|
-
id: activeToast.toastId,
|
|
233
|
-
titleKey: title,
|
|
234
|
-
textKey: text,
|
|
235
|
-
textInterpolateParams,
|
|
236
|
-
titleInterpolateParams
|
|
237
|
-
});
|
|
238
382
|
return activeToast;
|
|
239
383
|
}
|
|
384
|
+
parseDate(value, fallback) {
|
|
385
|
+
if (!value) {
|
|
386
|
+
return fallback;
|
|
387
|
+
}
|
|
388
|
+
if (value instanceof Date) {
|
|
389
|
+
return value;
|
|
390
|
+
}
|
|
391
|
+
const directParse = new Date(value);
|
|
392
|
+
if (!Number.isNaN(directParse.getTime())) {
|
|
393
|
+
return directParse;
|
|
394
|
+
}
|
|
395
|
+
const normalizedParse = new Date(Date.parse(value.replace(/-/g, ' ')));
|
|
396
|
+
return Number.isNaN(normalizedParse.getTime()) ? fallback : normalizedParse;
|
|
397
|
+
}
|
|
398
|
+
translateInterpolateParams(params) {
|
|
399
|
+
if (!params) {
|
|
400
|
+
return {};
|
|
401
|
+
}
|
|
402
|
+
return Object.keys(params).reduce((acc, key) => {
|
|
403
|
+
const value = params[key];
|
|
404
|
+
acc[key] =
|
|
405
|
+
typeof value === 'string'
|
|
406
|
+
? this.languageService.translate.instant(value)
|
|
407
|
+
: value;
|
|
408
|
+
return acc;
|
|
409
|
+
}, {});
|
|
410
|
+
}
|
|
240
411
|
remove(id) {
|
|
241
|
-
this.
|
|
412
|
+
this.toastService.remove(id);
|
|
242
413
|
}
|
|
243
414
|
removeAllAreNotError() {
|
|
244
415
|
for (const mess of this.messages$.value) {
|
|
@@ -261,10 +432,10 @@ class MessageService {
|
|
|
261
432
|
message.title = undefined;
|
|
262
433
|
return message;
|
|
263
434
|
}
|
|
264
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.
|
|
265
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.
|
|
435
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: MessageService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
436
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: MessageService, providedIn: 'root' });
|
|
266
437
|
}
|
|
267
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.
|
|
438
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.23", ngImport: i0, type: MessageService, decorators: [{
|
|
268
439
|
type: Injectable,
|
|
269
440
|
args: [{
|
|
270
441
|
providedIn: 'root'
|
|
@@ -275,5 +446,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.10", ngImpo
|
|
|
275
446
|
* Generated bundle index. Do not edit.
|
|
276
447
|
*/
|
|
277
448
|
|
|
278
|
-
export {
|
|
449
|
+
export { DEFAULT_TOAST_CONFIG, MessageService, MessageType, ToastComponent, ToastContainerComponent, ToastService, provideMessage };
|
|
279
450
|
//# sourceMappingURL=igo2-core-message.mjs.map
|