@txstate-mws/svelte-components 1.6.6 → 1.6.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/dist/stores/toasts.d.ts +0 -1
- package/dist/stores/toasts.js +3 -4
- package/package.json +1 -1
package/dist/stores/toasts.d.ts
CHANGED
|
@@ -19,7 +19,6 @@ export interface ToastStorage extends Required<Toast> {
|
|
|
19
19
|
suspended: boolean;
|
|
20
20
|
}
|
|
21
21
|
export declare class ToastStore extends Store<ToastStorage[]> {
|
|
22
|
-
timers: Record<string, number>;
|
|
23
22
|
add(msg: string, type?: Toast['type'], ttlMs?: number): void;
|
|
24
23
|
close(id: string): void;
|
|
25
24
|
suspend(id: string): void;
|
package/dist/stores/toasts.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Store } from '@txstate-mws/svelte-store';
|
|
2
2
|
import { randomid } from 'txstate-utils';
|
|
3
3
|
export class ToastStore extends Store {
|
|
4
|
-
timers = {};
|
|
5
4
|
add(msg, type, ttlMs) {
|
|
6
5
|
const resolvedType = type ?? 'error';
|
|
7
6
|
const id = randomid();
|
|
@@ -14,7 +13,7 @@ export class ToastStore extends Store {
|
|
|
14
13
|
ttlMs: ttlMs ?? (['error', 'warning'].includes(resolvedType) ? 8000 : 5000)
|
|
15
14
|
};
|
|
16
15
|
this.update(v => [...v.filter(t => t.message !== stored.message), stored]);
|
|
17
|
-
|
|
16
|
+
setTimeout(() => { this.clean(); }, stored.ttlMs);
|
|
18
17
|
}
|
|
19
18
|
close(id) {
|
|
20
19
|
this.update(v => v.filter(t => t.id !== id));
|
|
@@ -24,11 +23,11 @@ export class ToastStore extends Store {
|
|
|
24
23
|
}
|
|
25
24
|
resume(id) {
|
|
26
25
|
this.update(v => v.map(t => t.id !== id ? t : { ...t, suspended: false }));
|
|
27
|
-
this.clean();
|
|
26
|
+
setTimeout(() => { this.clean(); }, 100);
|
|
28
27
|
}
|
|
29
28
|
clean() {
|
|
30
29
|
const now = new Date().getTime();
|
|
31
|
-
this.update(v => v.
|
|
30
|
+
this.update(v => v.some(t => t.suspended) ? v : v.filter(t => now - t.stamp.getTime() <= t.ttlMs));
|
|
32
31
|
}
|
|
33
32
|
}
|
|
34
33
|
export const toasts = new ToastStore([]);
|