@mustib/web-components 0.0.0-alpha.5 → 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.d.ts +46 -1
- package/components/mu-range.js +97 -19
- 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.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 +7 -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
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { TemplateResult, PropertyValues, CSSResultGroup } from 'lit';
|
|
2
|
+
import { MuElement, MuElementComponent } from './components/mu-element.js';
|
|
3
|
+
import { MuIcon } from './components/mu-icon.js';
|
|
4
|
+
import { EventData, CustomEventEmitter } from '@mustib/utils';
|
|
5
|
+
|
|
6
|
+
type LockedEvent<T = undefined> = EventData<T, T, false, false>;
|
|
7
|
+
|
|
8
|
+
type AnimationKeyframes = Keyframe[] | PropertyIndexedKeyframes;
|
|
9
|
+
|
|
10
|
+
type ToastData = {
|
|
11
|
+
/**
|
|
12
|
+
* The message to display in the toast
|
|
13
|
+
*/
|
|
14
|
+
message: string | TemplateResult;
|
|
15
|
+
|
|
16
|
+
spinner?: boolean | TemplateResult;
|
|
17
|
+
|
|
18
|
+
direction?: 'ltr' | 'rtl';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The label of the toast
|
|
22
|
+
*/
|
|
23
|
+
label?: undefined | string | TemplateResult;
|
|
24
|
+
|
|
25
|
+
role?: 'alert' | 'status';
|
|
26
|
+
|
|
27
|
+
leaveAnimationDuration?: number;
|
|
28
|
+
|
|
29
|
+
enterAnimationDuration?: number;
|
|
30
|
+
|
|
31
|
+
priority?: 'immediate' | 'normal' | 'important';
|
|
32
|
+
|
|
33
|
+
enterAnimationKeyframes?: AnimationKeyframes;
|
|
34
|
+
|
|
35
|
+
progressAnimationKeyframes?: AnimationKeyframes;
|
|
36
|
+
|
|
37
|
+
leaveAnimationKeyframes?: AnimationKeyframes;
|
|
38
|
+
|
|
39
|
+
interactingBehavior?: 'reset-progress' | 'pause-progress' | 'nothing';
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Remove the toast if it is not rendered within the specified time (in ms).
|
|
43
|
+
* If the toast fails to render in this time, it will be discarded.
|
|
44
|
+
* If not set, the toast will wait indefinitely to render if queued.
|
|
45
|
+
*/
|
|
46
|
+
maxRenderWaitTime?: undefined | number;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The action of the toast
|
|
50
|
+
*/
|
|
51
|
+
action?:
|
|
52
|
+
| undefined
|
|
53
|
+
| ((toast: Toast) => TemplateResult)
|
|
54
|
+
| {
|
|
55
|
+
label: string;
|
|
56
|
+
onClick: (toast: Toast) => void;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* The duration of the toast
|
|
61
|
+
*/
|
|
62
|
+
duration?: undefined | number;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The hue of the toast color
|
|
66
|
+
*/
|
|
67
|
+
colorHue?: undefined | number;
|
|
68
|
+
|
|
69
|
+
closeBtn?: boolean | TemplateResult;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* The name of the icon to display in the toast. This is the name of the icon from the {@link MuIcon} component
|
|
73
|
+
* @see {@link MuIcon.icons} or a custom lit {@link TemplateResult}
|
|
74
|
+
*/
|
|
75
|
+
labelIcon?: undefined | keyof typeof MuIcon.icons | TemplateResult;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
type Events$3 = {
|
|
79
|
+
'state.request.remove.toast': LockedEvent<{
|
|
80
|
+
toast: Toast$1;
|
|
81
|
+
}>;
|
|
82
|
+
};
|
|
83
|
+
declare class ToastController {
|
|
84
|
+
private portal;
|
|
85
|
+
private toastsIdMap;
|
|
86
|
+
private queuedToastsQueue;
|
|
87
|
+
toastsQueue: Toast$1[];
|
|
88
|
+
private _maxVisibleToastsCount;
|
|
89
|
+
private _stackToasts;
|
|
90
|
+
interactingBehavior: Toast$1['interactingBehavior'];
|
|
91
|
+
colorHue: {
|
|
92
|
+
success: number;
|
|
93
|
+
error: number;
|
|
94
|
+
warning: number;
|
|
95
|
+
info: number;
|
|
96
|
+
};
|
|
97
|
+
defaultDuration: number;
|
|
98
|
+
defaultLeaveAnimationDuration: number;
|
|
99
|
+
defaultEnterAnimationDuration: number;
|
|
100
|
+
defaultDirection: "ltr" | "rtl";
|
|
101
|
+
get maxVisibleToastsCount(): number;
|
|
102
|
+
set maxVisibleToastsCount(value: number);
|
|
103
|
+
get position(): MuToast["position"];
|
|
104
|
+
set position(value: MuToast['position']);
|
|
105
|
+
set stackToasts(value: boolean);
|
|
106
|
+
/**
|
|
107
|
+
* Indicates if toast notifications should stack atop each other,
|
|
108
|
+
* such that only the latest is fully visible while older toasts
|
|
109
|
+
* are partially hidden beneath it. This enhances focus and reduces clutter.
|
|
110
|
+
*/
|
|
111
|
+
get stackToasts(): boolean;
|
|
112
|
+
constructor(portal: MuToast);
|
|
113
|
+
gracefulRemoveVisible(): void;
|
|
114
|
+
gracefulRemoveAll(): void;
|
|
115
|
+
/**
|
|
116
|
+
* Re-parents the toast portal to the specified node.
|
|
117
|
+
*
|
|
118
|
+
* Useful for ensuring toasts appear correctly when top-layer elements like fullscreen containers
|
|
119
|
+
* or dialogs are active. The specified node should be a valid container element (not void elements like <img />).
|
|
120
|
+
*
|
|
121
|
+
* @param node - The new parent node for the toast portal.
|
|
122
|
+
*/
|
|
123
|
+
reParent(node?: Node): void;
|
|
124
|
+
/**
|
|
125
|
+
* Makes the toast portal a popover,
|
|
126
|
+
* ensuring that toasts appear above all other elements
|
|
127
|
+
* (e.g., dialogs, fullscreen content) in the top-layer.
|
|
128
|
+
* This is useful for proper overlay stacking and visibility.
|
|
129
|
+
*/
|
|
130
|
+
popover(): void;
|
|
131
|
+
success(message: string): Toast$1;
|
|
132
|
+
error(message: string): Toast$1;
|
|
133
|
+
warning(message: string): Toast$1;
|
|
134
|
+
info(message: string): Toast$1;
|
|
135
|
+
create(toastData: ToastData | string): Toast$1;
|
|
136
|
+
private rolloverQueuedToasts;
|
|
137
|
+
emitter: CustomEventEmitter<Events$3>;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
type Events$2 = {
|
|
141
|
+
'state.toast-item.first.rendered': LockedEvent<{
|
|
142
|
+
element: MuToastItem;
|
|
143
|
+
}>;
|
|
144
|
+
'state.await.rendering': LockedEvent;
|
|
145
|
+
'internal.status.enter': LockedEvent;
|
|
146
|
+
'internal.status.progress': LockedEvent;
|
|
147
|
+
'internal.status.leave': LockedEvent;
|
|
148
|
+
};
|
|
149
|
+
declare class Toast$1 {
|
|
150
|
+
private controller;
|
|
151
|
+
private internalToast;
|
|
152
|
+
get id(): string;
|
|
153
|
+
get action(): ((toast: Toast$1) => TemplateResult) | {
|
|
154
|
+
label: string;
|
|
155
|
+
onClick: (toast: Toast$1) => void;
|
|
156
|
+
} | undefined;
|
|
157
|
+
get message(): string | TemplateResult;
|
|
158
|
+
get label(): string | TemplateResult | undefined;
|
|
159
|
+
get role(): "alert" | "status";
|
|
160
|
+
get duration(): number;
|
|
161
|
+
get colorHue(): number;
|
|
162
|
+
get spinner(): boolean | TemplateResult;
|
|
163
|
+
get labelIcon(): keyof typeof MuIcon.icons | TemplateResult | undefined;
|
|
164
|
+
get closeBtn(): boolean | TemplateResult;
|
|
165
|
+
get leaveAnimationDuration(): number;
|
|
166
|
+
get enterAnimationDuration(): number;
|
|
167
|
+
get direction(): "rtl" | "ltr";
|
|
168
|
+
get interactingBehavior(): "reset-progress" | "pause-progress" | "nothing";
|
|
169
|
+
get status(): "queued" | "await-rendering" | "enter" | "progress" | "leave";
|
|
170
|
+
get priority(): "immediate" | "normal" | "important";
|
|
171
|
+
set colorHue(value: number);
|
|
172
|
+
set spinner(value: boolean | TemplateResult);
|
|
173
|
+
set labelIcon(value: keyof typeof MuIcon.icons | TemplateResult | undefined);
|
|
174
|
+
set message(value: string | TemplateResult);
|
|
175
|
+
set label(value: string | TemplateResult | undefined);
|
|
176
|
+
set action(value: ((toast: Toast$1) => TemplateResult) | {
|
|
177
|
+
label: string;
|
|
178
|
+
onClick: (toast: Toast$1) => void;
|
|
179
|
+
} | undefined);
|
|
180
|
+
set closeBtn(value: boolean | TemplateResult);
|
|
181
|
+
set duration(value: number);
|
|
182
|
+
constructor({ toastData, controller, }: {
|
|
183
|
+
toastData: ToastData;
|
|
184
|
+
controller: ToastController;
|
|
185
|
+
});
|
|
186
|
+
private _generateInternalToastData;
|
|
187
|
+
gracefulRemove(): Promise<void>;
|
|
188
|
+
remove(): void;
|
|
189
|
+
pauseProgress(): Promise<void>;
|
|
190
|
+
resumeProgress(): Promise<void>;
|
|
191
|
+
resetProgress(): Promise<void>;
|
|
192
|
+
emitter: CustomEventEmitter<Events$2>;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
type MuToastItemComponent = {
|
|
196
|
+
attributes: Attributes$1;
|
|
197
|
+
events: Events$1;
|
|
198
|
+
};
|
|
199
|
+
type Events$1 = object;
|
|
200
|
+
type Attributes$1 = MuElementComponent['attributes'];
|
|
201
|
+
declare class MuToastItem extends MuElement {
|
|
202
|
+
static styles: any[];
|
|
203
|
+
eventActionData: undefined;
|
|
204
|
+
_addEventActionAttributes: undefined;
|
|
205
|
+
toast: Toast$1;
|
|
206
|
+
progressElement?: HTMLElement;
|
|
207
|
+
protected firstUpdated(_changedProperties: PropertyValues): void;
|
|
208
|
+
private pausedByEvents;
|
|
209
|
+
render(): unknown;
|
|
210
|
+
}
|
|
211
|
+
declare global {
|
|
212
|
+
interface HTMLElementTagNameMap {
|
|
213
|
+
'mu-toast-item': MuToastItem;
|
|
214
|
+
}
|
|
215
|
+
interface GlobalEventHandlersEventMap extends Events$1 {
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
type MuToastComponent = {
|
|
220
|
+
attributes: Attributes;
|
|
221
|
+
events: Events;
|
|
222
|
+
};
|
|
223
|
+
type Events = object;
|
|
224
|
+
type Attributes = MuElementComponent['attributes'] & {
|
|
225
|
+
/**
|
|
226
|
+
* The position of the toast
|
|
227
|
+
*/
|
|
228
|
+
position?: 'top-center' | 'bottom-center' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end';
|
|
229
|
+
/**
|
|
230
|
+
* Automatically re-parent the toast container to top-layer elements such as
|
|
231
|
+
* open `<dialog>`s or the fullscreen element. This is useful when the toast
|
|
232
|
+
* must appear above modals, dialogs or fullscreen content without requiring
|
|
233
|
+
* manual re-parenting.
|
|
234
|
+
*
|
|
235
|
+
* ⚠️ **Performance note:** enabling this feature causes the component to
|
|
236
|
+
* observe the entire document for attribute and child‑list mutations. It
|
|
237
|
+
* tracks changes to determine when dialogs are opened or closed, which can
|
|
238
|
+
* be expensive in applications with frequent DOM modifications. Use only when
|
|
239
|
+
* necessary and test performance impact in your target environment.
|
|
240
|
+
*/
|
|
241
|
+
'auto-re-parent'?: boolean;
|
|
242
|
+
/**
|
|
243
|
+
* Indicates if the toast is empty
|
|
244
|
+
* must not be set directly, it is managed internally
|
|
245
|
+
*/
|
|
246
|
+
empty?: boolean;
|
|
247
|
+
};
|
|
248
|
+
declare class MuToast extends MuElement {
|
|
249
|
+
static styles?: CSSResultGroup | undefined;
|
|
250
|
+
protected _addEventActionAttributes: undefined;
|
|
251
|
+
eventActionData: undefined;
|
|
252
|
+
controller: ToastController;
|
|
253
|
+
position: Exclude<Attributes['position'], undefined>;
|
|
254
|
+
autoReParent: boolean;
|
|
255
|
+
private setIsEmpty;
|
|
256
|
+
private _topLayerElements;
|
|
257
|
+
private _fullscreenElement;
|
|
258
|
+
private autoReParentObserver;
|
|
259
|
+
private addTopLayerElement;
|
|
260
|
+
private removeTopLayerElement;
|
|
261
|
+
fullscreenReParentHandler: () => void;
|
|
262
|
+
protected willUpdate(_changedProperties: PropertyValues): void;
|
|
263
|
+
connectedCallback(): void;
|
|
264
|
+
disconnectedCallback(): void;
|
|
265
|
+
protected render(): unknown;
|
|
266
|
+
}
|
|
267
|
+
declare global {
|
|
268
|
+
interface HTMLElementTagNameMap {
|
|
269
|
+
'mu-toast': MuToast;
|
|
270
|
+
}
|
|
271
|
+
interface GlobalEventHandlersEventMap extends Events {
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export { Toast$1 as T, MuToast as b, MuToastItem as c, ToastController as d };
|
|
276
|
+
export type { AnimationKeyframes as A, LockedEvent as L, MuToastComponent as M, MuToastItemComponent as a, ToastData as e };
|
package/package.json
CHANGED
|
@@ -3,9 +3,12 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "A customizable web-components library with lit",
|
|
5
5
|
"private": false,
|
|
6
|
-
"version": "0.0.0-alpha.
|
|
6
|
+
"version": "0.0.0-alpha.7",
|
|
7
|
+
"lint-staged": {
|
|
8
|
+
"*.{js,ts,astro}": "biome check --write"
|
|
9
|
+
},
|
|
7
10
|
"dependencies": {
|
|
8
|
-
"@mustib/utils": "2.
|
|
11
|
+
"@mustib/utils": "2.9.0"
|
|
9
12
|
},
|
|
10
13
|
"peerDependencies": {
|
|
11
14
|
"lit": "^3.3.1"
|
|
@@ -18,6 +21,8 @@
|
|
|
18
21
|
"@tailwindcss/vite": "^4.1.12",
|
|
19
22
|
"@types/node": "^24.9.2",
|
|
20
23
|
"astro": "^5.12.8",
|
|
24
|
+
"husky": "^9.1.7",
|
|
25
|
+
"lint-staged": "^16.2.7",
|
|
21
26
|
"rollup": "^4.52.5",
|
|
22
27
|
"rollup-plugin-dts": "^6.2.3",
|
|
23
28
|
"tailwindcss": "^4.1.12",
|
package/utils/Toast.d.ts
ADDED
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 };
|