@t007/toast 0.0.20 → 0.0.22
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/index.d.ts +178 -2
- package/dist/index.global.js +8 -6
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import "@t007/utils";
|
|
2
2
|
|
|
3
|
+
/** Toast severity level. */
|
|
3
4
|
export type ToastType = "info" | "success" | "error" | "warning";
|
|
5
|
+
/** Screen anchor for toast placement. */
|
|
4
6
|
export type ToastPosition =
|
|
5
7
|
| "top-left"
|
|
6
8
|
| "top-center"
|
|
@@ -11,6 +13,7 @@ export type ToastPosition =
|
|
|
11
13
|
| "center-left"
|
|
12
14
|
| "center-center"
|
|
13
15
|
| "center-right";
|
|
16
|
+
/** Motion preset used when a toast enters or leaves the screen. */
|
|
14
17
|
export type ToastAnimation =
|
|
15
18
|
| "fade"
|
|
16
19
|
| "zoom"
|
|
@@ -20,6 +23,7 @@ export type ToastAnimation =
|
|
|
20
23
|
| "slide-up"
|
|
21
24
|
| "slide-down"
|
|
22
25
|
| boolean;
|
|
26
|
+
/** Allowed drag directions for dismiss gestures. */
|
|
23
27
|
export type ToastDragDir =
|
|
24
28
|
| "x"
|
|
25
29
|
| "y"
|
|
@@ -37,107 +41,279 @@ export type ToastDragDir =
|
|
|
37
41
|
| "x||y+"
|
|
38
42
|
| "x||y-";
|
|
39
43
|
|
|
44
|
+
/** Configuration object for creating and updating a toast. */
|
|
40
45
|
export interface ToastOptions {
|
|
46
|
+
/** Explicit toast id. */
|
|
41
47
|
id?: string;
|
|
48
|
+
/** Prefix used when ids are generated automatically. */
|
|
42
49
|
idPrefix?: string;
|
|
50
|
+
/** Delay before the toast is initialized. */
|
|
43
51
|
delay?: number | null;
|
|
52
|
+
/** Container element used to host toast stacks. */
|
|
44
53
|
rootElement?: HTMLElement;
|
|
54
|
+
/** Text rendered as the toast body. */
|
|
45
55
|
render?: string | (() => string);
|
|
56
|
+
/** Rich HTML rendered as the toast body. */
|
|
46
57
|
bodyHTML?: string | (() => string);
|
|
58
|
+
/** Severity variant for default styling and icons. */
|
|
47
59
|
type?: ToastType;
|
|
60
|
+
/** Custom icon HTML or a boolean that selects the default icon. */
|
|
48
61
|
icon?: string | boolean;
|
|
62
|
+
/** Optional image url shown beside the message. */
|
|
49
63
|
image?: string | false;
|
|
64
|
+
/** Auto-close delay in milliseconds, or false to keep open. */
|
|
50
65
|
autoClose?: number | boolean;
|
|
66
|
+
/** Where the toast stack should appear. */
|
|
51
67
|
position?: ToastPosition;
|
|
68
|
+
/** Loading state used by promise flows and deferred updates. */
|
|
52
69
|
isLoading?: boolean | string;
|
|
70
|
+
/** Show or hide the close button. */
|
|
53
71
|
closeButton?: boolean;
|
|
72
|
+
/** Close the toast when the body is clicked. */
|
|
54
73
|
closeOnClick?: boolean;
|
|
74
|
+
/** Hide the progress bar. */
|
|
55
75
|
hideProgressBar?: boolean;
|
|
76
|
+
/** Pause auto-close while the pointer is over the toast. */
|
|
56
77
|
pauseOnHover?: boolean;
|
|
78
|
+
/** Pause auto-close while the document is hidden. */
|
|
57
79
|
pauseOnFocusLoss?: boolean;
|
|
80
|
+
/** Enable drag-to-dismiss gestures and optionally limit pointer types. */
|
|
58
81
|
dragToClose?: boolean | "mouse" | "pen" | "touch";
|
|
82
|
+
/** Percentage threshold needed to dismiss by drag. */
|
|
59
83
|
dragToClosePercent?: number | { x?: number; y?: number };
|
|
84
|
+
/** Axis or direction filter used by the drag gesture system. */
|
|
60
85
|
dragToCloseDir?: ToastDragDir;
|
|
86
|
+
/** Remove other toasts with the same tag before showing this one. */
|
|
61
87
|
renotify?: boolean;
|
|
88
|
+
/** Arbitrary tag used for grouping, filtering, and renotify matching. */
|
|
62
89
|
tag?: string | number;
|
|
90
|
+
/** Trigger vibration when the toast appears. */
|
|
63
91
|
vibrate?: boolean | number[];
|
|
92
|
+
/** Entry/exit animation preset. */
|
|
64
93
|
animation?: ToastAnimation;
|
|
94
|
+
/** Put new toasts at the front of the stack. */
|
|
65
95
|
newestOnTop?: boolean;
|
|
96
|
+
/** Maximum number of toasts allowed in a container. */
|
|
66
97
|
maxToasts?: number;
|
|
67
|
-
|
|
98
|
+
/** Action buttons rendered under the message body. */
|
|
99
|
+
actions?: Record<string, (e: MouseEvent, toast: ToastInstance) => void> | false;
|
|
100
|
+
/** Callback fired when the toast closes. */
|
|
68
101
|
onClose?: (timeElapsed?: boolean | false) => void;
|
|
102
|
+
/** Callback fired as the toast auto-close timer advances. */
|
|
69
103
|
onTimeUpdate?: (timeVisible: number) => void;
|
|
70
104
|
[key: string]: any; // To allow arbitrary overrides internally if needed
|
|
71
105
|
}
|
|
72
106
|
|
|
107
|
+
/** Live toast instance returned by the runtime. */
|
|
73
108
|
export interface ToastInstance {
|
|
109
|
+
/** Unique toast id. */
|
|
74
110
|
id: string;
|
|
111
|
+
/** Current option bag applied to the instance. */
|
|
75
112
|
opts: ToastOptions;
|
|
113
|
+
/** Pending timeouts waiting to apply queued updates. */
|
|
76
114
|
queue: number[];
|
|
115
|
+
/** Whether the toast has been removed from the DOM. */
|
|
77
116
|
destroyed: boolean;
|
|
117
|
+
/** Root DOM node for the toast. */
|
|
78
118
|
toastElement: HTMLElement;
|
|
119
|
+
/** Build the DOM node and attach it to the stack. */
|
|
79
120
|
init(): void;
|
|
121
|
+
/** Apply new options and return the toast id.
|
|
122
|
+
* @param options Options to apply.
|
|
123
|
+
* @returns Toast id.
|
|
124
|
+
*/
|
|
80
125
|
update(options: ToastOptions): string;
|
|
126
|
+
/** Resume auto-close progress. */
|
|
81
127
|
play(): void;
|
|
128
|
+
/** Pause auto-close progress. */
|
|
82
129
|
pause(): void;
|
|
130
|
+
/** Remove the toast from view.
|
|
131
|
+
* @param manner Removal mode.
|
|
132
|
+
* @param timeElapsed Whether the auto-close timer already elapsed.
|
|
133
|
+
*/
|
|
83
134
|
_remove(manner?: "smooth" | "instant", timeElapsed?: boolean): void;
|
|
84
135
|
}
|
|
85
136
|
|
|
137
|
+
/** Promise state configuration used by toast.promise. */
|
|
86
138
|
export interface ToastPromiseState<T = any> extends Omit<ToastOptions, "render" | "bodyHTML"> {
|
|
139
|
+
/** Render text for the promise state. */
|
|
87
140
|
render?: string | ((response: T) => string);
|
|
141
|
+
/** Render HTML for the promise state. */
|
|
88
142
|
bodyHTML?: string | ((response: T) => string);
|
|
89
143
|
}
|
|
90
144
|
|
|
145
|
+
/** Configuration object accepted by toast.promise. */
|
|
91
146
|
export interface ToastPromiseConfig<T = any> {
|
|
147
|
+
/** Pending-state text or options. */
|
|
92
148
|
pending?: string | ToastOptions;
|
|
149
|
+
/** Success-state text or options. */
|
|
93
150
|
success?: string | ToastPromiseState<T>;
|
|
151
|
+
/** Error-state text or options. */
|
|
94
152
|
error?: string | ToastPromiseState<any>;
|
|
95
153
|
}
|
|
96
154
|
|
|
155
|
+
/** Public toast API exposed to consumers. */
|
|
97
156
|
export interface Toast {
|
|
157
|
+
/** Create a default toast.
|
|
158
|
+
* @param render Body text for the toast.
|
|
159
|
+
* @param options Toast configuration.
|
|
160
|
+
* @returns Toast id.
|
|
161
|
+
*/
|
|
98
162
|
(render?: string, options?: ToastOptions): string;
|
|
163
|
+
/** Update an existing toast by id.
|
|
164
|
+
* @param id Toast id.
|
|
165
|
+
* @param options Options to apply.
|
|
166
|
+
* @returns Updated toast id or false when no toast was found.
|
|
167
|
+
*/
|
|
99
168
|
update(id: string, options: ToastOptions): string | false;
|
|
169
|
+
/** Show an info toast.
|
|
170
|
+
* @param render Body text.
|
|
171
|
+
* @param options Toast configuration.
|
|
172
|
+
* @returns Toast id.
|
|
173
|
+
*/
|
|
100
174
|
info(render?: string, options?: ToastOptions): string;
|
|
175
|
+
/** Show a success toast.
|
|
176
|
+
* @param render Body text.
|
|
177
|
+
* @param options Toast configuration.
|
|
178
|
+
* @returns Toast id.
|
|
179
|
+
*/
|
|
101
180
|
success(render?: string, options?: ToastOptions): string;
|
|
181
|
+
/** Show a warning toast.
|
|
182
|
+
* @param render Body text.
|
|
183
|
+
* @param options Toast configuration.
|
|
184
|
+
* @returns Toast id.
|
|
185
|
+
*/
|
|
102
186
|
warn(render?: string, options?: ToastOptions): string;
|
|
187
|
+
/** Show an error toast.
|
|
188
|
+
* @param render Body text.
|
|
189
|
+
* @param options Toast configuration.
|
|
190
|
+
* @returns Toast id.
|
|
191
|
+
*/
|
|
103
192
|
error(render?: string, options?: ToastOptions): string;
|
|
193
|
+
/** Show a loading toast.
|
|
194
|
+
* @param render Body text.
|
|
195
|
+
* @param options Toast configuration.
|
|
196
|
+
* @returns Toast id.
|
|
197
|
+
*/
|
|
104
198
|
loading(render?: string, options?: ToastOptions): string;
|
|
199
|
+
/** Bind a promise to the toast lifecycle.
|
|
200
|
+
* @param promise Promise to observe.
|
|
201
|
+
* @param options Pending, success, and error states.
|
|
202
|
+
* @returns The original promise.
|
|
203
|
+
*/
|
|
105
204
|
promise<T>(promise: Promise<T>, options?: ToastPromiseConfig<T>): Promise<T>;
|
|
205
|
+
/** Dismiss a single toast or the whole stack.
|
|
206
|
+
* @param id Toast id to dismiss.
|
|
207
|
+
* @param manner Removal mode.
|
|
208
|
+
* @param timeElapsed Whether the auto-close timer already elapsed.
|
|
209
|
+
*/
|
|
106
210
|
dismiss(id?: string, manner?: "smooth" | "instant", timeElapsed?: boolean): void;
|
|
211
|
+
/** Dismiss every toast that matches an optional prefix.
|
|
212
|
+
* @param idPrefix Optional id prefix filter.
|
|
213
|
+
*/
|
|
107
214
|
dismissAll(idPrefix?: string): void;
|
|
215
|
+
/** Run an action against every matching toast instance.
|
|
216
|
+
* @param action Instance method to invoke.
|
|
217
|
+
* @param options Options forwarded to the instance method.
|
|
218
|
+
* @param idPrefix Optional id prefix filter.
|
|
219
|
+
*/
|
|
108
220
|
doForAll(action: string, options?: any, idPrefix?: string): void;
|
|
221
|
+
/** Return every matching toast instance.
|
|
222
|
+
* @param idPrefix Optional id prefix filter.
|
|
223
|
+
* @returns Matching toast instances.
|
|
224
|
+
*/
|
|
109
225
|
getAll(idPrefix?: string): ToastInstance[];
|
|
110
226
|
}
|
|
111
227
|
|
|
228
|
+
/** Helper methods used internally by toaster() and promise flows. */
|
|
112
229
|
export interface Toasting {
|
|
230
|
+
/** Update an existing toast or recreate it if needed.
|
|
231
|
+
* @param base Toast factory to use.
|
|
232
|
+
* @param id Toast id.
|
|
233
|
+
* @param options Options to apply.
|
|
234
|
+
* @returns Updated id or false when no toast exists.
|
|
235
|
+
*/
|
|
113
236
|
update(base: Toast, id: string, options: ToastOptions): boolean | string;
|
|
237
|
+
/** Attach a helper like info/success/warn/error to the base toast function.
|
|
238
|
+
* @param base Toast factory to extend.
|
|
239
|
+
* @param defaults Default option factory.
|
|
240
|
+
* @param action Helper name to create.
|
|
241
|
+
*/
|
|
114
242
|
message(base: Toast, defaults: () => ToastOptions, action: string): void;
|
|
243
|
+
/** Create a loading toast from an id or a message.
|
|
244
|
+
* @param base Toast factory to use.
|
|
245
|
+
* @param renderOrId Toast id or loading text.
|
|
246
|
+
* @param options Loading options.
|
|
247
|
+
* @returns Toast id.
|
|
248
|
+
*/
|
|
115
249
|
loading(base: Toast, renderOrId: string, options?: ToastOptions): string;
|
|
250
|
+
/** Bind promise resolution states to an active toast.
|
|
251
|
+
* @param base Toast factory to use.
|
|
252
|
+
* @param promise Promise to observe.
|
|
253
|
+
* @param config Promise state configuration.
|
|
254
|
+
* @returns The original promise.
|
|
255
|
+
*/
|
|
116
256
|
promise<T>(base: Toast, promise: Promise<T>, config?: ToastPromiseConfig<T>): Promise<T>;
|
|
257
|
+
/** Dismiss a toast by id or clear all matching toasts.
|
|
258
|
+
* @param base Toast factory to use.
|
|
259
|
+
* @param id Toast id.
|
|
260
|
+
* @param manner Removal mode.
|
|
261
|
+
* @param timeElapsed Whether the auto-close timer already elapsed.
|
|
262
|
+
*/
|
|
117
263
|
dismiss(base: Toast, id?: string, manner?: string, timeElapsed?: boolean): void;
|
|
264
|
+
/** Dismiss all matching toasts.
|
|
265
|
+
* @param base Toast factory to use.
|
|
266
|
+
* @param idPrefix Optional id prefix filter.
|
|
267
|
+
*/
|
|
118
268
|
dismissAll(base: Toast, idPrefix?: string): void;
|
|
269
|
+
/** Run a method on every matching toast instance.
|
|
270
|
+
* @param base Toast factory to use.
|
|
271
|
+
* @param action Instance method to invoke.
|
|
272
|
+
* @param options Options forwarded to the instance method.
|
|
273
|
+
* @param idPrefix Optional id prefix filter.
|
|
274
|
+
*/
|
|
119
275
|
doForAll(base: Toast, action: string, options?: any, idPrefix?: string): void;
|
|
276
|
+
/** Return every matching toast instance.
|
|
277
|
+
* @param base Toast factory to use.
|
|
278
|
+
* @param idPrefix Optional id prefix filter.
|
|
279
|
+
* @returns Matching toast instances.
|
|
280
|
+
*/
|
|
120
281
|
getAll(base: Toast, idPrefix?: string): ToastInstance[];
|
|
121
282
|
}
|
|
122
283
|
|
|
123
284
|
// BUNDLE EXPORTS & GLOBAL DECLARATIONS
|
|
285
|
+
|
|
286
|
+
/** Internal helper methods used by the toast factory. */
|
|
124
287
|
export const toasting: Toasting;
|
|
288
|
+
/** Create a toast factory with custom defaults.
|
|
289
|
+
* @param defOptions Default options merged into every toast.
|
|
290
|
+
* @param idPrefix Prefix applied to generated ids.
|
|
291
|
+
* @returns Toast factory.
|
|
292
|
+
*/
|
|
125
293
|
export function toaster(defOptions?: ToastOptions, idPrefix?: string): Toast;
|
|
294
|
+
/** Default toast factory instance attached by the bundle. */
|
|
126
295
|
declare const toast: Toast;
|
|
127
296
|
export default toast;
|
|
128
297
|
|
|
129
298
|
declare global {
|
|
130
299
|
interface T007Namespace {
|
|
300
|
+
/** Default toast factory instance. */
|
|
131
301
|
toast: Toast;
|
|
302
|
+
/** Lower-level helper methods used by the toast factory. */
|
|
132
303
|
toasting: Toasting;
|
|
304
|
+
/** Factory used to create isolated toast instances. */
|
|
133
305
|
toaster: typeof toaster;
|
|
306
|
+
/** Registry of live toast instances. */
|
|
134
307
|
toasts: Map<string, ToastInstance>;
|
|
308
|
+
/** Default runtime options merged into every toast. */
|
|
135
309
|
TOAST_DEFAULT_OPTIONS: ToastOptions;
|
|
310
|
+
/** Default auto-close durations by toast type. */
|
|
136
311
|
TOAST_DURATIONS: Record<ToastType, number>;
|
|
312
|
+
/** Default vibration patterns by toast type. */
|
|
137
313
|
TOAST_VIBRATIONS: Record<ToastType, number[]>;
|
|
314
|
+
/** Default SVG icons by toast type. */
|
|
138
315
|
TOAST_ICONS: Record<ToastType | "loading", string>;
|
|
139
316
|
}
|
|
140
|
-
|
|
141
317
|
interface Window {
|
|
142
318
|
Toast?: Toast;
|
|
143
319
|
}
|
package/dist/index.global.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
|
-
//
|
|
3
|
+
// ../../node_modules/sia-reactor/dist/chunk-IBAPWB27.js
|
|
4
|
+
function clamp(min = 0, val, max = Infinity) {
|
|
5
|
+
return Math.min(Math.max(val, min), max);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
// ../../node_modules/sia-reactor/dist/chunk-RVYL3OLW.js
|
|
4
9
|
function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
|
|
5
10
|
return assignEl(el, props, dataset, styles), el;
|
|
6
11
|
}
|
|
@@ -17,7 +22,7 @@
|
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
24
|
|
|
20
|
-
//
|
|
25
|
+
// ../../node_modules/sia-reactor/dist/chunk-3OT72G7R.js
|
|
21
26
|
function onAllMethods(owner, callback, skipOwn = true, nested = false) {
|
|
22
27
|
let proto = owner;
|
|
23
28
|
while (proto && proto !== Object.prototype) {
|
|
@@ -34,11 +39,8 @@
|
|
|
34
39
|
owner2[method] = owner2[method].bind(owner2);
|
|
35
40
|
});
|
|
36
41
|
}
|
|
37
|
-
function clamp(min = 0, val, max = Infinity) {
|
|
38
|
-
return Math.min(Math.max(val, min), max);
|
|
39
|
-
}
|
|
40
42
|
|
|
41
|
-
//
|
|
43
|
+
// ../../node_modules/sia-reactor/dist/chunk-EZ4VRGYI.js
|
|
42
44
|
var CTX = {
|
|
43
45
|
/** Flag indicating whether the application is running in development mode. */
|
|
44
46
|
isDevEnv: "undefined" !== typeof process ? process.env.NODE_ENV !== "production" : true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t007/toast",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.22",
|
|
4
4
|
"description": "A lightweight, pure JS toast system.",
|
|
5
5
|
"author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,6 +53,6 @@
|
|
|
53
53
|
"promise"
|
|
54
54
|
],
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@t007/utils": "^0.0.
|
|
56
|
+
"@t007/utils": "^0.0.24"
|
|
57
57
|
}
|
|
58
58
|
}
|