@mustib/web-components 0.0.0-alpha.6 → 0.0.0-alpha.7
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/common-BBjg-zl9.js +604 -0
- package/components/mu-element.d.ts +3 -1
- package/components/mu-element.js +2 -1
- package/components/mu-icon.d.ts +4 -0
- package/components/mu-icon.js +14 -1
- package/components/mu-range-fill.js +2 -1
- package/components/mu-range-thumb-value.js +2 -1
- package/components/mu-range-thumb.js +2 -1
- package/components/mu-range.js +2 -1
- package/components/mu-select-item.js +2 -1
- package/components/mu-select-items.js +2 -1
- package/components/mu-select-label-content.js +2 -1
- package/components/mu-select-label.d.ts +1 -1
- package/components/mu-select-label.js +2 -1
- package/components/mu-select.js +2 -1
- package/components/mu-sortable-item.js +2 -1
- package/components/mu-sortable-trigger.js +2 -1
- package/components/mu-sortable.js +2 -1
- package/components/mu-toast-item.d.ts +6 -0
- package/components/mu-toast-item.js +229 -0
- package/components/mu-toast.d.ts +6 -0
- package/components/mu-toast.js +216 -0
- package/components/mu-transparent.js +2 -1
- package/components/mu-trigger.js +2 -1
- package/constants-DPnKJ57t.js +8 -0
- package/index.d.ts +9 -2
- package/index.js +11 -1
- package/{mu-element-CEvBHYiI.js → mu-element-yEZ17QUl.js} +2 -195
- package/mu-toast-DfNHcc7U.d.ts +276 -0
- package/package.json +2 -2
- package/utils/Toast.d.ts +6 -0
- package/utils/Toast.js +321 -0
- package/utils/ToastController.d.ts +6 -0
- package/utils/ToastController.js +189 -0
package/utils/Toast.js
ADDED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
import { C as CustomEventEmitter, D as DeferredValue } from '../common-BBjg-zl9.js';
|
|
2
|
+
import { T as TOAST_LOCK_SYMBOL } from '../constants-DPnKJ57t.js';
|
|
3
|
+
|
|
4
|
+
const internalLockKey = Symbol('internal-toast');
|
|
5
|
+
class Toast {
|
|
6
|
+
get id() {
|
|
7
|
+
return this.internalToast.id;
|
|
8
|
+
}
|
|
9
|
+
get action() {
|
|
10
|
+
return this.internalToast.action;
|
|
11
|
+
}
|
|
12
|
+
get message() {
|
|
13
|
+
return this.internalToast.message;
|
|
14
|
+
}
|
|
15
|
+
get label() {
|
|
16
|
+
return this.internalToast.label;
|
|
17
|
+
}
|
|
18
|
+
get role() {
|
|
19
|
+
return this.internalToast.role;
|
|
20
|
+
}
|
|
21
|
+
get duration() {
|
|
22
|
+
return this.internalToast.duration;
|
|
23
|
+
}
|
|
24
|
+
get colorHue() {
|
|
25
|
+
return this.internalToast.colorHue;
|
|
26
|
+
}
|
|
27
|
+
get spinner() {
|
|
28
|
+
return this.internalToast.spinner;
|
|
29
|
+
}
|
|
30
|
+
get labelIcon() {
|
|
31
|
+
return this.internalToast.labelIcon;
|
|
32
|
+
}
|
|
33
|
+
get closeBtn() {
|
|
34
|
+
return this.internalToast.closeBtn;
|
|
35
|
+
}
|
|
36
|
+
get leaveAnimationDuration() {
|
|
37
|
+
return this.internalToast.leaveAnimationDuration;
|
|
38
|
+
}
|
|
39
|
+
get enterAnimationDuration() {
|
|
40
|
+
return this.internalToast.enterAnimationDuration;
|
|
41
|
+
}
|
|
42
|
+
get direction() {
|
|
43
|
+
return this.internalToast.direction;
|
|
44
|
+
}
|
|
45
|
+
get interactingBehavior() {
|
|
46
|
+
return this.internalToast.interactingBehavior;
|
|
47
|
+
}
|
|
48
|
+
get status() {
|
|
49
|
+
return this.internalToast.status;
|
|
50
|
+
}
|
|
51
|
+
get priority() {
|
|
52
|
+
return this.internalToast.priority;
|
|
53
|
+
}
|
|
54
|
+
set colorHue(value) {
|
|
55
|
+
this.internalToast.colorHue = value;
|
|
56
|
+
if (this.internalToast.host.isResolved)
|
|
57
|
+
this.internalToast.host.resolvedValue.requestUpdate();
|
|
58
|
+
}
|
|
59
|
+
set spinner(value) {
|
|
60
|
+
this.internalToast.spinner = value;
|
|
61
|
+
if (this.internalToast.host.isResolved)
|
|
62
|
+
this.internalToast.host.resolvedValue.requestUpdate();
|
|
63
|
+
}
|
|
64
|
+
set labelIcon(value) {
|
|
65
|
+
this.internalToast.labelIcon = value;
|
|
66
|
+
if (this.internalToast.host.isResolved)
|
|
67
|
+
this.internalToast.host.resolvedValue.requestUpdate();
|
|
68
|
+
}
|
|
69
|
+
set message(value) {
|
|
70
|
+
this.internalToast.message = value;
|
|
71
|
+
if (this.internalToast.host.isResolved)
|
|
72
|
+
this.internalToast.host.resolvedValue.requestUpdate();
|
|
73
|
+
}
|
|
74
|
+
set label(value) {
|
|
75
|
+
this.internalToast.label = value;
|
|
76
|
+
if (this.internalToast.host.isResolved)
|
|
77
|
+
this.internalToast.host.resolvedValue.requestUpdate();
|
|
78
|
+
}
|
|
79
|
+
set action(value) {
|
|
80
|
+
this.internalToast.action = value;
|
|
81
|
+
if (this.internalToast.host.isResolved)
|
|
82
|
+
this.internalToast.host.resolvedValue.requestUpdate();
|
|
83
|
+
}
|
|
84
|
+
set closeBtn(value) {
|
|
85
|
+
this.internalToast.closeBtn = value;
|
|
86
|
+
if (this.internalToast.host.isResolved)
|
|
87
|
+
this.internalToast.host.resolvedValue.requestUpdate();
|
|
88
|
+
}
|
|
89
|
+
set duration(value) {
|
|
90
|
+
this.internalToast.duration = value;
|
|
91
|
+
if (this.internalToast.progressAnimation.isResolved) {
|
|
92
|
+
const currTime = this.internalToast.progressAnimation.resolvedValue.currentTime || 0;
|
|
93
|
+
this.internalToast.progressAnimation.resolvedValue.effect?.updateTiming({
|
|
94
|
+
duration: +currTime + value,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
constructor({ toastData, controller, }) {
|
|
99
|
+
this.emitter = new CustomEventEmitter({
|
|
100
|
+
'state.await.rendering': {
|
|
101
|
+
runningBehavior: 'async-sequential',
|
|
102
|
+
dispatchable: false,
|
|
103
|
+
lockSymbol: TOAST_LOCK_SYMBOL,
|
|
104
|
+
beforeAll: () => {
|
|
105
|
+
if (!this.internalToast.host.isPending)
|
|
106
|
+
return;
|
|
107
|
+
this.internalToast.status = 'await-rendering';
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
'state.toast-item.first.rendered': {
|
|
111
|
+
runningBehavior: 'async-sequential',
|
|
112
|
+
dispatchable: false,
|
|
113
|
+
lockSymbol: TOAST_LOCK_SYMBOL,
|
|
114
|
+
beforeAll: (data) => {
|
|
115
|
+
if (!this.internalToast.host.isPending)
|
|
116
|
+
return;
|
|
117
|
+
this.internalToast.host.resolve(data.listenerValue.element);
|
|
118
|
+
clearTimeout(this.internalToast.maxRenderWaitTimeTimeoutId);
|
|
119
|
+
this.emitter.dispatch('internal.status.enter', undefined, {
|
|
120
|
+
lockSymbol: internalLockKey,
|
|
121
|
+
});
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
'internal.status.enter': {
|
|
125
|
+
runningBehavior: 'async-sequential',
|
|
126
|
+
dispatchable: false,
|
|
127
|
+
lockSymbol: internalLockKey,
|
|
128
|
+
beforeAll: () => {
|
|
129
|
+
if (this.internalToast.status !== 'await-rendering')
|
|
130
|
+
return;
|
|
131
|
+
let animation;
|
|
132
|
+
if (this.internalToast.enterAnimation.isPending) {
|
|
133
|
+
animation = new Animation(new KeyframeEffect(this.internalToast.host.resolvedValue, this.internalToast.enterAnimationKeyframes, {
|
|
134
|
+
duration: this.internalToast.enterAnimationDuration,
|
|
135
|
+
easing: 'ease-in-out',
|
|
136
|
+
}));
|
|
137
|
+
this.internalToast.enterAnimation.resolve(animation);
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
animation = this.internalToast.enterAnimation.resolvedValue;
|
|
141
|
+
}
|
|
142
|
+
animation.play();
|
|
143
|
+
this.internalToast.status = 'enter';
|
|
144
|
+
animation.onfinish = () => {
|
|
145
|
+
this.emitter.dispatch('internal.status.progress', undefined, {
|
|
146
|
+
lockSymbol: internalLockKey,
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
'internal.status.progress': {
|
|
152
|
+
runningBehavior: 'async-sequential',
|
|
153
|
+
dispatchable: false,
|
|
154
|
+
lockSymbol: internalLockKey,
|
|
155
|
+
beforeAll: () => {
|
|
156
|
+
if (this.internalToast.status !== 'enter')
|
|
157
|
+
return;
|
|
158
|
+
let animation;
|
|
159
|
+
if (this.internalToast.progressAnimation.isPending) {
|
|
160
|
+
animation = new Animation(new KeyframeEffect(this.internalToast.host.resolvedValue.progressElement || null, this.internalToast.progressAnimationKeyframes, {
|
|
161
|
+
duration: this.internalToast.duration,
|
|
162
|
+
easing: 'linear',
|
|
163
|
+
}));
|
|
164
|
+
this.internalToast.progressAnimation.resolve(animation);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
animation = this.internalToast.progressAnimation.resolvedValue;
|
|
168
|
+
}
|
|
169
|
+
animation.play();
|
|
170
|
+
this.internalToast.status = 'progress';
|
|
171
|
+
animation.onfinish = () => {
|
|
172
|
+
this.emitter.dispatch('internal.status.leave', undefined, {
|
|
173
|
+
lockSymbol: internalLockKey,
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
'internal.status.leave': {
|
|
179
|
+
runningBehavior: 'async-sequential',
|
|
180
|
+
dispatchable: false,
|
|
181
|
+
lockSymbol: internalLockKey,
|
|
182
|
+
beforeAll: () => {
|
|
183
|
+
if (this.internalToast.status !== 'progress')
|
|
184
|
+
return;
|
|
185
|
+
let animation;
|
|
186
|
+
if (this.internalToast.leaveAnimation.isPending) {
|
|
187
|
+
animation = new Animation(new KeyframeEffect(this.internalToast.host.resolvedValue, this.internalToast.leaveAnimationKeyframes, {
|
|
188
|
+
duration: this.internalToast.leaveAnimationDuration,
|
|
189
|
+
easing: 'ease-in-out',
|
|
190
|
+
}));
|
|
191
|
+
this.internalToast.leaveAnimation.resolve(animation);
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
animation = this.internalToast.leaveAnimation.resolvedValue;
|
|
195
|
+
}
|
|
196
|
+
animation.play();
|
|
197
|
+
this.internalToast.status = 'leave';
|
|
198
|
+
animation.onfinish = () => {
|
|
199
|
+
this.remove();
|
|
200
|
+
};
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
});
|
|
204
|
+
this.controller = controller;
|
|
205
|
+
this.internalToast = this._generateInternalToastData(toastData);
|
|
206
|
+
}
|
|
207
|
+
_generateInternalToastData(toastData) {
|
|
208
|
+
const id = crypto.randomUUID();
|
|
209
|
+
const duration = typeof toastData.duration === 'number'
|
|
210
|
+
? toastData.duration
|
|
211
|
+
: this.controller.defaultDuration;
|
|
212
|
+
const leaveAnimationDuration = typeof toastData.leaveAnimationDuration === 'number'
|
|
213
|
+
? toastData.leaveAnimationDuration
|
|
214
|
+
: this.controller.defaultLeaveAnimationDuration;
|
|
215
|
+
const enterAnimationDuration = typeof toastData.enterAnimationDuration === 'number'
|
|
216
|
+
? toastData.enterAnimationDuration
|
|
217
|
+
: this.controller.defaultEnterAnimationDuration;
|
|
218
|
+
const direction = toastData.direction ?? this.controller.defaultDirection;
|
|
219
|
+
const transformOrigin = direction === 'rtl' ? 'right' : 'left';
|
|
220
|
+
const internalToast = {
|
|
221
|
+
id,
|
|
222
|
+
action: toastData.action,
|
|
223
|
+
closeBtn: toastData.closeBtn ?? true,
|
|
224
|
+
colorHue: typeof toastData.colorHue === 'number'
|
|
225
|
+
? toastData.colorHue
|
|
226
|
+
: this.controller.colorHue.info,
|
|
227
|
+
duration,
|
|
228
|
+
enterAnimationDuration,
|
|
229
|
+
direction,
|
|
230
|
+
priority: toastData.priority ?? 'normal',
|
|
231
|
+
host: new DeferredValue(),
|
|
232
|
+
enterAnimation: new DeferredValue(),
|
|
233
|
+
progressAnimation: new DeferredValue(),
|
|
234
|
+
leaveAnimation: new DeferredValue(),
|
|
235
|
+
enterAnimationKeyframes: toastData.enterAnimationKeyframes ?? [
|
|
236
|
+
{ scale: '0' },
|
|
237
|
+
{ scale: '1' },
|
|
238
|
+
],
|
|
239
|
+
progressAnimationKeyframes: toastData.progressAnimationKeyframes ?? [
|
|
240
|
+
{ scale: '0 1', visibility: 'visible', transformOrigin },
|
|
241
|
+
{ scale: '1 1', visibility: 'visible', transformOrigin },
|
|
242
|
+
],
|
|
243
|
+
leaveAnimationKeyframes: toastData.leaveAnimationKeyframes ?? [
|
|
244
|
+
{ scale: '1' },
|
|
245
|
+
{ scale: '0' },
|
|
246
|
+
],
|
|
247
|
+
interactingBehavior: toastData.interactingBehavior || this.controller.interactingBehavior,
|
|
248
|
+
leaveAnimationDuration,
|
|
249
|
+
label: toastData.label,
|
|
250
|
+
labelIcon: toastData.labelIcon,
|
|
251
|
+
maxRenderWaitTimeTimeoutId: undefined,
|
|
252
|
+
message: toastData.message,
|
|
253
|
+
role: toastData.role || 'status',
|
|
254
|
+
spinner: toastData.spinner || false,
|
|
255
|
+
status: 'queued',
|
|
256
|
+
};
|
|
257
|
+
if (typeof toastData.maxRenderWaitTime === 'number' &&
|
|
258
|
+
toastData.maxRenderWaitTime > 0 &&
|
|
259
|
+
toastData.maxRenderWaitTime !== Infinity) {
|
|
260
|
+
internalToast.maxRenderWaitTimeTimeoutId = setTimeout(() => {
|
|
261
|
+
this.remove();
|
|
262
|
+
}, toastData.maxRenderWaitTime);
|
|
263
|
+
}
|
|
264
|
+
return internalToast;
|
|
265
|
+
}
|
|
266
|
+
async gracefulRemove() {
|
|
267
|
+
switch (this.internalToast.status) {
|
|
268
|
+
case 'queued':
|
|
269
|
+
case 'await-rendering':
|
|
270
|
+
this.remove();
|
|
271
|
+
break;
|
|
272
|
+
case 'enter':
|
|
273
|
+
{
|
|
274
|
+
const enterAnimation = await this.internalToast.enterAnimation.current;
|
|
275
|
+
enterAnimation.finish();
|
|
276
|
+
await enterAnimation.finished;
|
|
277
|
+
const progressAnimation = await this.internalToast.progressAnimation.current;
|
|
278
|
+
progressAnimation.finish();
|
|
279
|
+
}
|
|
280
|
+
break;
|
|
281
|
+
case 'progress':
|
|
282
|
+
{
|
|
283
|
+
const progressAnimation = await this.internalToast.progressAnimation.current;
|
|
284
|
+
progressAnimation.finish();
|
|
285
|
+
}
|
|
286
|
+
break;
|
|
287
|
+
case 'leave':
|
|
288
|
+
break;
|
|
289
|
+
default:
|
|
290
|
+
this.internalToast.status;
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
remove() {
|
|
295
|
+
this.controller.emitter.dispatch('state.request.remove.toast', {
|
|
296
|
+
toast: this,
|
|
297
|
+
}, {
|
|
298
|
+
lockSymbol: TOAST_LOCK_SYMBOL,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
async pauseProgress() {
|
|
302
|
+
if (this.internalToast.status === 'leave')
|
|
303
|
+
return;
|
|
304
|
+
const animation = await this.internalToast.progressAnimation.current;
|
|
305
|
+
animation.pause();
|
|
306
|
+
}
|
|
307
|
+
async resumeProgress() {
|
|
308
|
+
if (this.internalToast.status === 'leave')
|
|
309
|
+
return;
|
|
310
|
+
const animation = await this.internalToast.progressAnimation.current;
|
|
311
|
+
animation.play();
|
|
312
|
+
}
|
|
313
|
+
async resetProgress() {
|
|
314
|
+
if (this.internalToast.status === 'leave')
|
|
315
|
+
return;
|
|
316
|
+
const animation = await this.internalToast.progressAnimation.current;
|
|
317
|
+
animation.currentTime = 0;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
export { Toast };
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { C as CustomEventEmitter } from '../common-BBjg-zl9.js';
|
|
2
|
+
import { T as TOAST_LOCK_SYMBOL } from '../constants-DPnKJ57t.js';
|
|
3
|
+
import { Toast } from './Toast.js';
|
|
4
|
+
|
|
5
|
+
class ToastController {
|
|
6
|
+
get maxVisibleToastsCount() {
|
|
7
|
+
return this._maxVisibleToastsCount;
|
|
8
|
+
}
|
|
9
|
+
set maxVisibleToastsCount(value) {
|
|
10
|
+
this._maxVisibleToastsCount = value;
|
|
11
|
+
this.rolloverQueuedToasts();
|
|
12
|
+
}
|
|
13
|
+
get position() {
|
|
14
|
+
return this.portal.position;
|
|
15
|
+
}
|
|
16
|
+
set position(value) {
|
|
17
|
+
this.portal.position = value;
|
|
18
|
+
}
|
|
19
|
+
set stackToasts(value) {
|
|
20
|
+
this._stackToasts = value;
|
|
21
|
+
this.portal.requestUpdate();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Indicates if toast notifications should stack atop each other,
|
|
25
|
+
* such that only the latest is fully visible while older toasts
|
|
26
|
+
* are partially hidden beneath it. This enhances focus and reduces clutter.
|
|
27
|
+
*/
|
|
28
|
+
get stackToasts() {
|
|
29
|
+
return this._stackToasts;
|
|
30
|
+
}
|
|
31
|
+
constructor(portal) {
|
|
32
|
+
this.portal = portal;
|
|
33
|
+
this.toastsIdMap = new Map();
|
|
34
|
+
this.queuedToastsQueue = [];
|
|
35
|
+
this.toastsQueue = [];
|
|
36
|
+
this._maxVisibleToastsCount = 3;
|
|
37
|
+
this._stackToasts = true;
|
|
38
|
+
this.interactingBehavior = 'pause-progress';
|
|
39
|
+
this.colorHue = {
|
|
40
|
+
success: 120,
|
|
41
|
+
error: 0,
|
|
42
|
+
warning: 60,
|
|
43
|
+
info: 200,
|
|
44
|
+
};
|
|
45
|
+
this.defaultDuration = 10000;
|
|
46
|
+
this.defaultLeaveAnimationDuration = 300;
|
|
47
|
+
this.defaultEnterAnimationDuration = 300;
|
|
48
|
+
this.defaultDirection = getComputedStyle(this.portal).direction;
|
|
49
|
+
this.emitter = new CustomEventEmitter({
|
|
50
|
+
'state.request.remove.toast': {
|
|
51
|
+
runningBehavior: 'async-sequential',
|
|
52
|
+
dispatchable: false,
|
|
53
|
+
lockSymbol: TOAST_LOCK_SYMBOL,
|
|
54
|
+
beforeAll: (data) => {
|
|
55
|
+
const toast = data.listenerValue.toast;
|
|
56
|
+
this.toastsIdMap.delete(toast.id);
|
|
57
|
+
if (toast.status === 'queued') {
|
|
58
|
+
this.queuedToastsQueue = this.queuedToastsQueue.filter((t) => t.id !== toast.id);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.toastsQueue = this.toastsQueue.filter((t) => t.id !== toast.id);
|
|
62
|
+
this.rolloverQueuedToasts();
|
|
63
|
+
this.portal.requestUpdate();
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
gracefulRemoveVisible() {
|
|
69
|
+
this.toastsQueue.forEach((t) => {
|
|
70
|
+
t.gracefulRemove();
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
gracefulRemoveAll() {
|
|
74
|
+
this.gracefulRemoveVisible();
|
|
75
|
+
this.queuedToastsQueue.forEach((t) => {
|
|
76
|
+
t.remove();
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Re-parents the toast portal to the specified node.
|
|
81
|
+
*
|
|
82
|
+
* Useful for ensuring toasts appear correctly when top-layer elements like fullscreen containers
|
|
83
|
+
* or dialogs are active. The specified node should be a valid container element (not void elements like <img />).
|
|
84
|
+
*
|
|
85
|
+
* @param node - The new parent node for the toast portal.
|
|
86
|
+
*/
|
|
87
|
+
reParent(node = document.body) {
|
|
88
|
+
if (node === this.portal.parentNode)
|
|
89
|
+
return;
|
|
90
|
+
node.appendChild(this.portal);
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Makes the toast portal a popover,
|
|
94
|
+
* ensuring that toasts appear above all other elements
|
|
95
|
+
* (e.g., dialogs, fullscreen content) in the top-layer.
|
|
96
|
+
* This is useful for proper overlay stacking and visibility.
|
|
97
|
+
*/
|
|
98
|
+
popover() {
|
|
99
|
+
const { portal } = this;
|
|
100
|
+
portal.popover = 'manual';
|
|
101
|
+
portal.hidePopover();
|
|
102
|
+
portal.showPopover();
|
|
103
|
+
}
|
|
104
|
+
success(message) {
|
|
105
|
+
return this.create({
|
|
106
|
+
message,
|
|
107
|
+
label: 'Success:',
|
|
108
|
+
labelIcon: 'checkMark',
|
|
109
|
+
role: 'status',
|
|
110
|
+
colorHue: this.colorHue.success,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
error(message) {
|
|
114
|
+
return this.create({
|
|
115
|
+
message,
|
|
116
|
+
label: 'Error:',
|
|
117
|
+
labelIcon: 'error',
|
|
118
|
+
role: 'alert',
|
|
119
|
+
colorHue: this.colorHue.error,
|
|
120
|
+
priority: 'important',
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
warning(message) {
|
|
124
|
+
return this.create({
|
|
125
|
+
message,
|
|
126
|
+
label: 'Warning:',
|
|
127
|
+
labelIcon: 'warning',
|
|
128
|
+
role: 'alert',
|
|
129
|
+
colorHue: this.colorHue.warning,
|
|
130
|
+
priority: 'important',
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
info(message) {
|
|
134
|
+
return this.create({
|
|
135
|
+
message,
|
|
136
|
+
label: 'Info:',
|
|
137
|
+
role: 'status',
|
|
138
|
+
labelIcon: 'info',
|
|
139
|
+
colorHue: this.colorHue.info,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
create(toastData) {
|
|
143
|
+
const toast = new Toast({
|
|
144
|
+
toastData: typeof toastData === 'string' ? { message: toastData } : toastData,
|
|
145
|
+
controller: this,
|
|
146
|
+
});
|
|
147
|
+
this.toastsIdMap.set(toast.id, toast);
|
|
148
|
+
switch (toast.priority) {
|
|
149
|
+
case 'immediate':
|
|
150
|
+
this.queuedToastsQueue.unshift(toast);
|
|
151
|
+
if (this.toastsQueue.length >= this._maxVisibleToastsCount) {
|
|
152
|
+
(this.toastsQueue.find((t) => t.priority === 'normal') ||
|
|
153
|
+
this.toastsQueue[0])?.remove();
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
156
|
+
case 'important':
|
|
157
|
+
this.queuedToastsQueue.unshift(toast);
|
|
158
|
+
if (this.toastsQueue.length >= this._maxVisibleToastsCount) {
|
|
159
|
+
(this.toastsQueue.find((t) => t.priority === 'normal') ||
|
|
160
|
+
this.toastsQueue[0])?.gracefulRemove();
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
163
|
+
case 'normal':
|
|
164
|
+
this.queuedToastsQueue.push(toast);
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
this.rolloverQueuedToasts();
|
|
168
|
+
return toast;
|
|
169
|
+
}
|
|
170
|
+
rolloverQueuedToasts() {
|
|
171
|
+
if (this.toastsQueue.length >= this.maxVisibleToastsCount) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const rolloverToastsCount = this.maxVisibleToastsCount - this.toastsQueue.length;
|
|
175
|
+
const rolloverToasts = this.queuedToastsQueue.splice(0, rolloverToastsCount);
|
|
176
|
+
if (rolloverToasts.length === 0) {
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
rolloverToasts.forEach((t) => {
|
|
180
|
+
t.emitter.dispatch('state.await.rendering', undefined, {
|
|
181
|
+
lockSymbol: TOAST_LOCK_SYMBOL,
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
this.toastsQueue.push(...rolloverToasts);
|
|
185
|
+
this.portal.requestUpdate();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export { ToastController };
|