@t007/toast 0.0.31 → 0.0.33
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 +35 -18
- package/dist/index.global.js +88 -59
- package/dist/index.js +33 -18
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import "@t007/utils";
|
|
2
|
-
|
|
3
1
|
/** Toast severity level. */
|
|
4
|
-
|
|
2
|
+
type ToastType = undefined | "info" | "success" | "error" | "warning";
|
|
5
3
|
/** Screen anchor for toast placement. */
|
|
6
|
-
|
|
4
|
+
type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right" | "center-left" | "center-center" | "center-right";
|
|
7
5
|
/** Motion preset used when a toast enters or leaves the screen. */
|
|
8
|
-
|
|
6
|
+
type ToastAnimation = "fade" | "zoom" | "slide" | "slide-left" | "slide-right" | "slide-up" | "slide-down" | boolean;
|
|
7
|
+
/** Allowed pointer types for drag-to-dismiss gestures. */
|
|
8
|
+
type ToastDragOption = boolean | "mouse" | "touch" | "pen";
|
|
9
9
|
/** Allowed drag directions for dismiss gestures. `|` combines axes where it can be `a` or `b` and can change anytime while `||` does not change after a pick is determined. */
|
|
10
|
-
|
|
10
|
+
type ToastDragDirection = "x" | "y" | "xy" | "x|y" | "x||y" | "x+" | "x-" | "y+" | "y-" | "xy+" | "xy-" | "x|y+" | "x|y-" | "x||y+" | "x||y-";
|
|
11
11
|
|
|
12
12
|
/** Configuration object for creating and updating a toast. */
|
|
13
|
-
|
|
13
|
+
interface ToastOptions {
|
|
14
14
|
/** Explicit toast id. Reusing an active id updates that toast in place (upsert-style), preserving position/animation state. */
|
|
15
15
|
id?: string;
|
|
16
16
|
/** Prefix used when ids are generated automatically. */
|
|
@@ -48,11 +48,11 @@ export interface ToastOptions {
|
|
|
48
48
|
/** Pause auto-close while the document is hidden. */
|
|
49
49
|
pauseOnFocusLoss?: boolean;
|
|
50
50
|
/** Enable drag-to-dismiss gestures and optionally limit pointer types. */
|
|
51
|
-
dragToClose?:
|
|
51
|
+
dragToClose?: ToastDragOption;
|
|
52
52
|
/** Percentage threshold needed to dismiss by drag. */
|
|
53
53
|
dragToClosePercent?: number | { x?: number; y?: number };
|
|
54
54
|
/** Axis or direction filter used by the drag gesture system. */
|
|
55
|
-
dragToCloseDir?:
|
|
55
|
+
dragToCloseDir?: ToastDragDirection;
|
|
56
56
|
/** When true and `tag` is provided, any other active toast with the same tag is removed before this toast renders. */
|
|
57
57
|
renotify?: boolean;
|
|
58
58
|
/** Arbitrary tag used for grouping and renotify matching. Does not update by itself; pair with `renotify` to enforce one-toast-per-tag behavior. */
|
|
@@ -71,11 +71,13 @@ export interface ToastOptions {
|
|
|
71
71
|
onClose?: (timeElapsed?: boolean | false) => void;
|
|
72
72
|
/** Callback fired as the toast auto-close timer advances. */
|
|
73
73
|
onTimeUpdate?: (timeVisible: number) => void;
|
|
74
|
-
|
|
74
|
+
/** Abort signal to control the toast's lifecycle and timeout aborts. */
|
|
75
|
+
signal?: AbortSignal;
|
|
76
|
+
// [key: string]: any; // To allow arbitrary overrides internally if needed
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
/** Live toast instance returned by the runtime. */
|
|
78
|
-
|
|
80
|
+
interface ToastInstance {
|
|
79
81
|
/** Current option bag applied to the instance. */
|
|
80
82
|
opts: ToastOptions;
|
|
81
83
|
/** Pending timeouts waiting to apply queued updates. */
|
|
@@ -103,17 +105,19 @@ export interface ToastInstance {
|
|
|
103
105
|
* @param timeElapsed Whether the auto-close timer already elapsed.
|
|
104
106
|
*/
|
|
105
107
|
remove(manner?: "smooth" | "instant", timeElapsed?: boolean): void;
|
|
108
|
+
/** Dismiss the toast immediately without any exit animation. */
|
|
109
|
+
abort(): void;
|
|
106
110
|
}
|
|
107
111
|
|
|
108
112
|
/** Promise state configuration used by toast.promise. */
|
|
109
|
-
|
|
113
|
+
interface ToastPromiseState<T = any> extends Omit<ToastOptions, "render" | "bodyHTML"> {
|
|
110
114
|
/** Render text for the promise state. */
|
|
111
115
|
render?: string | ((response: T) => string);
|
|
112
116
|
/** Render HTML for the promise state. */
|
|
113
117
|
bodyHTML?: string | ((response: T) => string);
|
|
114
118
|
}
|
|
115
119
|
/** Configuration object accepted by toast.promise. */
|
|
116
|
-
|
|
120
|
+
interface ToastPromiseConfig<T = any> {
|
|
117
121
|
/** Pending-state text or options. */
|
|
118
122
|
pending?: string | ToastOptions;
|
|
119
123
|
/** Success-state text or options. */
|
|
@@ -123,7 +127,7 @@ export interface ToastPromiseConfig<T = any> {
|
|
|
123
127
|
}
|
|
124
128
|
|
|
125
129
|
/** Public toast API exposed to consumers. */
|
|
126
|
-
|
|
130
|
+
interface Toast {
|
|
127
131
|
/** Create a default toast.
|
|
128
132
|
* @param render Body text for the toast.
|
|
129
133
|
* @param options Toast configuration.
|
|
@@ -201,7 +205,7 @@ export interface Toast {
|
|
|
201
205
|
}
|
|
202
206
|
|
|
203
207
|
/** Helper methods used internally by toaster() and promise flows. */
|
|
204
|
-
|
|
208
|
+
interface Toasting {
|
|
205
209
|
isActive(base: Toast, id: string): boolean;
|
|
206
210
|
update(base: Toast, id: string, options: ToastOptions): boolean | string;
|
|
207
211
|
message(base: Toast, getDefaults: () => ToastOptions, action: string, renderOrId: string, options?: ToastOptions): string;
|
|
@@ -216,16 +220,22 @@ export interface Toasting {
|
|
|
216
220
|
// BUNDLE EXPORTS & GLOBAL DECLARATIONS
|
|
217
221
|
|
|
218
222
|
/** Internal helper methods used by the toast factory. */
|
|
219
|
-
|
|
223
|
+
declare const toasting: Toasting;
|
|
220
224
|
/** Create a toast factory with custom defaults and a group id.
|
|
221
225
|
* @param defOptions Default options merged into every toast.
|
|
222
226
|
* @param groupId Prefix applied to generated ids.
|
|
223
227
|
* @returns Toast factory.
|
|
224
228
|
*/
|
|
225
|
-
|
|
229
|
+
declare function toaster(defOptions?: ToastOptions, groupId?: string): Toast;
|
|
226
230
|
/** Default toast factory instance attached by the bundle. */
|
|
227
231
|
declare const toast: Toast;
|
|
228
|
-
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
declare const TOAST_UI_POSITIONS: { value: ToastPosition; display: string }[];
|
|
235
|
+
declare const TOAST_UI_ANIMATIONS: { value: ToastAnimation; display: string }[];
|
|
236
|
+
declare const TOAST_UI_TYPES: { value: ToastType; display: string }[];
|
|
237
|
+
declare const TOAST_UI_DRAG_OPTIONS: { value: ToastDragOption; display: string }[];
|
|
238
|
+
declare const TOAST_UI_DRAG_DIRECTIONS: { value: ToastDragDirection; display: string }[];
|
|
229
239
|
|
|
230
240
|
declare global {
|
|
231
241
|
interface T007Namespace {
|
|
@@ -245,8 +255,15 @@ declare global {
|
|
|
245
255
|
TOAST_VIBRATIONS: Record<ToastType, number[]>;
|
|
246
256
|
/** Default SVG icons by toast type. */
|
|
247
257
|
TOAST_ICONS: Record<ToastType | "loading", string>;
|
|
258
|
+
TOAST_UI_POSITIONS: typeof TOAST_UI_POSITIONS;
|
|
259
|
+
TOAST_UI_ANIMATIONS: typeof TOAST_UI_ANIMATIONS;
|
|
260
|
+
TOAST_UI_TYPES: typeof TOAST_UI_TYPES;
|
|
261
|
+
TOAST_UI_DRAG_OPTS: typeof TOAST_UI_DRAG_OPTIONS;
|
|
262
|
+
TOAST_UI_DRAG_DIRS: typeof TOAST_UI_DRAG_DIRECTIONS;
|
|
248
263
|
}
|
|
249
264
|
interface Window {
|
|
250
265
|
toast?: Toast;
|
|
251
266
|
}
|
|
252
267
|
}
|
|
268
|
+
|
|
269
|
+
export { TOAST_UI_ANIMATIONS, TOAST_UI_DRAG_DIRECTIONS, TOAST_UI_DRAG_OPTIONS, TOAST_UI_POSITIONS, TOAST_UI_TYPES, type Toast, type ToastAnimation, type ToastDragDirection, type ToastDragOption, type ToastInstance, type ToastOptions, type ToastPosition, type ToastPromiseConfig, type ToastPromiseState, type ToastType, type Toasting, toast as default, toaster, toasting };
|
package/dist/index.global.js
CHANGED
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
|
-
// ../../../sia-reactor/dist/chunk-
|
|
3
|
+
// ../../../sia-reactor/dist/chunk-JGEI2Q4M.js
|
|
4
4
|
function clamp(min = 0, val, max = Infinity) {
|
|
5
5
|
return Math.min(Math.max(val, min), max);
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (props) {
|
|
15
|
-
for (const k of Object.keys(props)) if (props[k] !== void 0) el[k] = props[k];
|
|
16
|
-
}
|
|
17
|
-
if (dataset) {
|
|
18
|
-
for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) el.dataset[k] = String(dataset[k]);
|
|
19
|
-
}
|
|
20
|
-
if (styles) {
|
|
21
|
-
for (const k of Object.keys(styles)) if (styles[k] !== void 0) el.style[k] = styles[k];
|
|
22
|
-
}
|
|
7
|
+
function setTimeout2(handler, timeout, ...args) {
|
|
8
|
+
const sig = args[0] instanceof AbortSignal ? args.shift() : void 0;
|
|
9
|
+
if (sig?.aborted) return -1;
|
|
10
|
+
const win = args[0] instanceof Window ? args.shift() : window;
|
|
11
|
+
if (!sig) return win.setTimeout(handler, timeout, ...args);
|
|
12
|
+
const id = win.setTimeout(() => (sig.removeEventListener("abort", kill), "string" === typeof handler ? new Function(handler) : handler(...args)), timeout), kill = () => win.clearTimeout(id);
|
|
13
|
+
return sig.addEventListener("abort", kill, { once: true }), id;
|
|
23
14
|
}
|
|
24
15
|
|
|
25
|
-
// ../../../sia-reactor/dist/chunk-
|
|
16
|
+
// ../../../sia-reactor/dist/chunk-ORK3EGB6.js
|
|
26
17
|
function onAllMethods(owner, callback, skipOwn = true, nested = false) {
|
|
27
18
|
let proto = owner;
|
|
28
19
|
while (proto && proto !== Object.prototype) {
|
|
@@ -39,53 +30,72 @@
|
|
|
39
30
|
owner2[method] = owner2[method].bind(owner2);
|
|
40
31
|
});
|
|
41
32
|
}
|
|
33
|
+
function createEl(tag, props, dataset, styles, el = tag ? document?.createElement(tag) : null) {
|
|
34
|
+
return assignEl(el, props, dataset, styles);
|
|
35
|
+
}
|
|
36
|
+
function assignEl(el, props, dataset, styles, nodiff = true) {
|
|
37
|
+
if (!el) return null;
|
|
38
|
+
if (props) {
|
|
39
|
+
for (const k of Object.keys(props)) if (props[k] !== void 0) {
|
|
40
|
+
if (nodiff || el[k] !== props[k]) el[k] = props[k];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (dataset) {
|
|
44
|
+
for (const k of Object.keys(dataset)) if (dataset[k] !== void 0) {
|
|
45
|
+
if (nodiff || el.dataset[k] !== dataset[k]) el.dataset[k] = String(dataset[k]);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (styles) {
|
|
49
|
+
for (const k of Object.keys(styles)) if (styles[k] !== void 0) {
|
|
50
|
+
if (nodiff || el.style[k] !== styles[k]) el.style[k] = styles[k];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return el;
|
|
54
|
+
}
|
|
42
55
|
|
|
43
|
-
// ../../../sia-reactor/dist/chunk-
|
|
44
|
-
var CTX = {
|
|
45
|
-
/** Flag indicating whether the application is running in development mode. */
|
|
46
|
-
isDevEnv: "undefined" !== typeof process ? process.env.NODE_ENV !== "production" : true,
|
|
47
|
-
/** Flag indicating whether a cascade is currently ongoing so reactors can allow all writes. */
|
|
48
|
-
isCascading: false,
|
|
49
|
-
/** Active `Autotracker` instance, override for automatic dependency collection on `Reactor` traps. */
|
|
50
|
-
autotracker: null
|
|
51
|
-
};
|
|
56
|
+
// ../../../sia-reactor/dist/chunk-SHWIAQD2.js
|
|
52
57
|
var RTR_BATCH = "undefined" !== typeof window ? ("undefined" !== typeof queueMicrotask ? queueMicrotask : setTimeout).bind(window) : "undefined" !== typeof process && process.nextTick ? process.nextTick : setTimeout;
|
|
53
58
|
var RTR_LOG = console.log.bind(console, "[S.I.A Reactor]");
|
|
54
59
|
var NIL = Object.freeze({});
|
|
60
|
+
var isDevEnv = false;
|
|
61
|
+
try {
|
|
62
|
+
isDevEnv = process.env.NODE_ENV !== "production";
|
|
63
|
+
} catch (e) {
|
|
64
|
+
}
|
|
55
65
|
function isObj(obj, arraycheck = true) {
|
|
56
66
|
return "object" === typeof obj && obj !== null && (arraycheck ? !Array.isArray(obj) : true);
|
|
57
67
|
}
|
|
58
68
|
|
|
59
|
-
// ../utils/dist/chunk-
|
|
60
|
-
var INTERACTIVE_SELECTOR = ":is(button,[href],input:not([type='hidden']),select,textarea,details>summary,[contenteditable
|
|
69
|
+
// ../utils/dist/chunk-ZALPHCSJ.js
|
|
70
|
+
var INTERACTIVE_SELECTOR = ":is(button,[href],input:not([type='hidden']),select,textarea,details>summary,[contenteditable],iframe,audio[controls],video[controls],[tabindex]):not([disabled],[tabindex='-1'],[data-focus-guard],[inert],[inert] *)";
|
|
61
71
|
var isInteractive = (target) => target instanceof HTMLElement && target.matches(INTERACTIVE_SELECTOR);
|
|
62
72
|
var VIRTUAL_RESOURCE = /* @__PURE__ */ Symbol.for("T007_VIRTUAL_RESOURCE");
|
|
63
|
-
function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {},
|
|
64
|
-
|
|
73
|
+
function loadResource(req, type = "style", { module, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, attempts = 3, retryKey = false } = {}, win = window) {
|
|
74
|
+
win.t007 ??= {}, win.t007._resourceCache ??= {};
|
|
65
75
|
if (req === VIRTUAL_RESOURCE || isSym(req)) return Promise.resolve();
|
|
66
76
|
const src = req;
|
|
67
|
-
if (
|
|
68
|
-
const existing = type === "script" ? Array.prototype.find.call(
|
|
69
|
-
if (existing) return
|
|
70
|
-
|
|
77
|
+
if (win.t007._resourceCache[src]) return win.t007._resourceCache[src];
|
|
78
|
+
const existing = type === "script" ? Array.prototype.find.call(win.document.scripts, (s) => isSameURL(s.src, src)) : type === "style" ? Array.prototype.find.call(win.document.styleSheets, (s) => isSameURL(s.href, src)) : null;
|
|
79
|
+
if (existing) return win.t007._resourceCache[src] = Promise.resolve(existing);
|
|
80
|
+
win.t007._resourceCache[src] = new Promise((resolve, reject) => {
|
|
71
81
|
(function tryLoad(remaining, el) {
|
|
72
82
|
const onerror = () => {
|
|
73
83
|
el?.remove?.();
|
|
74
84
|
if (remaining > 1) {
|
|
75
85
|
setTimeout(tryLoad, 1e3, remaining - 1);
|
|
76
|
-
console.warn(`Retrying ${type} load (${attempts - remaining + 1})
|
|
86
|
+
console.warn(`Retrying ${type} load for "${src}" (${attempts - remaining + 1})...`);
|
|
77
87
|
} else {
|
|
78
|
-
delete
|
|
79
|
-
reject(new Error(`${type} load failed
|
|
88
|
+
delete win.t007._resourceCache[src];
|
|
89
|
+
reject(new Error(`${capitalize(type)} load failed for "${src}" after ${attempts - 1} attempts`));
|
|
80
90
|
}
|
|
81
91
|
};
|
|
82
92
|
const url = retryKey && remaining < attempts ? `${src}${src.includes("?") ? "&" : "?"}_${retryKey}=${Date.now()}` : src;
|
|
83
|
-
if (type === "script")
|
|
84
|
-
else if (type === "style")
|
|
93
|
+
if (type === "script") win.document.body.append(el = createEl("script", { src: url, type: module ? "module" : "text/javascript", crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
|
|
94
|
+
else if (type === "style") win.document.head.append(el = createEl("link", { rel: "stylesheet", href: url, media, crossOrigin, integrity, referrerPolicy, nonce, fetchPriority, onload: () => resolve(el), onerror }) || "");
|
|
85
95
|
else reject(new Error(`Unsupported resource type: ${type}`));
|
|
86
96
|
})(attempts);
|
|
87
97
|
});
|
|
88
|
-
return
|
|
98
|
+
return win.t007._resourceCache[src];
|
|
89
99
|
}
|
|
90
100
|
function isDef(val) {
|
|
91
101
|
return "undefined" !== typeof val;
|
|
@@ -105,6 +115,9 @@
|
|
|
105
115
|
function uid(prefix = "") {
|
|
106
116
|
return prefix + Date.now().toString(36) + "_" + performance.now().toString(36).replace(".", "") + "_" + Math.random().toString(36).slice(2);
|
|
107
117
|
}
|
|
118
|
+
function capitalize(word = "") {
|
|
119
|
+
return word.replace(/^(\s*)([a-z])/i, (_, s, l) => s + l.toUpperCase());
|
|
120
|
+
}
|
|
108
121
|
function cleanURL(url) {
|
|
109
122
|
try {
|
|
110
123
|
const u = new URL(url, window.location.href);
|
|
@@ -114,9 +127,15 @@
|
|
|
114
127
|
}
|
|
115
128
|
}
|
|
116
129
|
function isSameURL(url1, url2) {
|
|
130
|
+
if (url1 === url2) return true;
|
|
117
131
|
if (!isStr(url1) || !isStr(url2) || !url1 || !url2) return false;
|
|
118
132
|
return cleanURL(url1) === cleanURL(url2);
|
|
119
133
|
}
|
|
134
|
+
function bindCleanupToSignal(cleanup, signal) {
|
|
135
|
+
signal?.aborted ? cleanup() : signal?.addEventListener("abort", cleanup, { once: true });
|
|
136
|
+
if (signal && !signal.aborted) cleanup = (() => (signal.removeEventListener("abort", cleanup), cleanup()));
|
|
137
|
+
return cleanup;
|
|
138
|
+
}
|
|
120
139
|
if ("undefined" !== typeof window) {
|
|
121
140
|
(window.t007 ??= {}).VIRTUAL_RESOURCE = VIRTUAL_RESOURCE;
|
|
122
141
|
window.T007_TOAST_JS_SRC ??= `https://cdn.jsdelivr.net/npm/@t007/toast@latest`;
|
|
@@ -140,10 +159,10 @@
|
|
|
140
159
|
inactive = true;
|
|
141
160
|
#visiblityChange = () => this.#shouldUnPause = document.visibilityState === "visible";
|
|
142
161
|
constructor(options) {
|
|
143
|
-
bindAllMethods(this);
|
|
162
|
+
bindAllMethods(this), bindCleanupToSignal(this.abort, options.signal);
|
|
144
163
|
this.opts = options;
|
|
145
164
|
t007.toasts.set(this.opts.id ??= uid(this.opts.groupId ??= "t007_toast_"), this);
|
|
146
|
-
!isNum(this.opts.delay) ? this.activate() : this.queue.push(
|
|
165
|
+
!isNum(this.opts.delay) ? this.activate() : this.queue.push(setTimeout2(this.activate, this.opts.delay, this.opts.signal));
|
|
147
166
|
this.update(this.opts);
|
|
148
167
|
}
|
|
149
168
|
activate() {
|
|
@@ -154,16 +173,17 @@
|
|
|
154
173
|
update(options, constructed = this.#constructed) {
|
|
155
174
|
if (!options || !isObj(options) || constructed && this.inactive) return this.opts.id;
|
|
156
175
|
try {
|
|
176
|
+
if (constructed) options.signal !== this.opts.signal && (this.opts.signal.removeEventListener("abort", this.abort), bindCleanupToSignal(this.abort, this.opts.signal));
|
|
157
177
|
this.opts = { ...this.opts, ...options };
|
|
158
178
|
const run = () => (Object.keys(options).forEach((key) => this[key] = options[key]), this.#constructed = true, !constructed && (this.position = this.opts.position));
|
|
159
|
-
!isNum(this.opts.delay) ? run() : this.queue.push(
|
|
179
|
+
!isNum(this.opts.delay) ? run() : this.queue.push(setTimeout2(run, this.opts.delay, this.opts.signal));
|
|
160
180
|
this.opts.delay = null;
|
|
161
181
|
} catch (err) {
|
|
162
182
|
console.error("t007 toast update failed:", err);
|
|
163
183
|
}
|
|
164
184
|
return this.opts.id;
|
|
165
185
|
}
|
|
166
|
-
play = () =>
|
|
186
|
+
play = () => setTimeout2(() => this.#isPaused = false, 0, this.opts.signal);
|
|
167
187
|
pause = () => this.#isPaused = true;
|
|
168
188
|
get rootElement() {
|
|
169
189
|
return this.opts.rootElement ?? document.body;
|
|
@@ -285,7 +305,7 @@
|
|
|
285
305
|
set position(value) {
|
|
286
306
|
if (!this.#constructed) return;
|
|
287
307
|
const currContainer = this.toastElement.parentElement, container = this.rootElement.querySelector(`:scope > .t007-toast-container[data-position="${value}"]`) || this._createContainer(value);
|
|
288
|
-
container[this.opts.newestOnTop ? "prepend" : "append"](this.toastElement);
|
|
308
|
+
!container.contains(this.toastElement) && container[this.opts.newestOnTop ? "prepend" : "append"](this.toastElement);
|
|
289
309
|
this.toastElement.classList.toggle("t007-toast-scoped", this.scoped);
|
|
290
310
|
if (!(currContainer == null || currContainer.hasChildNodes())) currContainer.remove();
|
|
291
311
|
}
|
|
@@ -321,7 +341,7 @@
|
|
|
321
341
|
}
|
|
322
342
|
set renotify(value) {
|
|
323
343
|
if (value && this.opts.tag) {
|
|
324
|
-
for (const toast2 of t007.toasts.values()) if (toast2.opts.tag === this.opts.tag && toast2.opts.id !== this.opts.id) toast2.
|
|
344
|
+
for (const toast2 of t007.toasts.values()) if (toast2.opts.tag === this.opts.tag && toast2.opts.id !== this.opts.id) toast2.abort();
|
|
325
345
|
}
|
|
326
346
|
}
|
|
327
347
|
get vibrate() {
|
|
@@ -333,7 +353,7 @@
|
|
|
333
353
|
set limit(value) {
|
|
334
354
|
const toastsInContainer = [...this.toastElement?.parentElement?.children || []];
|
|
335
355
|
if (!toastsInContainer.length) return;
|
|
336
|
-
for (let i = 0; i < toastsInContainer.length - value; i++) [...t007.toasts.values()].find((t) => t.toastElement === (this.opts.newestOnTop ? toastsInContainer[toastsInContainer.length - 1 - i] : toastsInContainer[i]))?.
|
|
356
|
+
for (let i = 0; i < toastsInContainer.length - value; i++) [...t007.toasts.values()].find((t) => t.toastElement === (this.opts.newestOnTop ? toastsInContainer[toastsInContainer.length - 1 - i] : toastsInContainer[i]))?.abort();
|
|
337
357
|
}
|
|
338
358
|
set newestOnTop(value) {
|
|
339
359
|
this.toastElement?.parentElement?.[value ? "prepend" : "append"](this.toastElement);
|
|
@@ -358,6 +378,8 @@
|
|
|
358
378
|
e.preventDefault();
|
|
359
379
|
if (this._ptrTicker) return;
|
|
360
380
|
this._ptrRAF = requestAnimationFrame(() => {
|
|
381
|
+
const selection = window.getSelection();
|
|
382
|
+
if (selection?.toString().length && this.toastElement.contains(selection.anchorNode)) return this._handleToastPointerUp(e);
|
|
361
383
|
const has = (str) => this.opts.dragToCloseDir.includes(str), x = e.clientX ?? e.targetTouches[0]?.clientX, y = e.clientY ?? e.targetTouches[0]?.clientY;
|
|
362
384
|
this._ptrDir ||= Math.abs(x - this._ptrStartX) >= Math.abs(y - this._ptrStartY) ? "x" : "y";
|
|
363
385
|
this._ptrDeltaX = (has("|") ? this._ptrDir == "x" : has("x")) && !has(x - this._ptrStartX > 0 ? "-" : "+") ? x - this._ptrStartX : 0;
|
|
@@ -374,7 +396,7 @@
|
|
|
374
396
|
_handleToastPointerUp(e) {
|
|
375
397
|
if (isStr(this._ptrType) && e.pointerType !== this._ptrType) return;
|
|
376
398
|
cancelAnimationFrame(this._ptrRAF);
|
|
377
|
-
if (Math.abs(this._ptrDeltaX) > this.toastElement.offsetWidth * ((this.opts.dragToClosePercent.x ?? this.opts.dragToClosePercent) / 100) || Math.abs(this._ptrDeltaY) > this.toastElement.offsetHeight * ((this.opts.dragToClosePercent.y ?? this.opts.dragToClosePercent) / 100)) return this.
|
|
399
|
+
if (Math.abs(this._ptrDeltaX) > this.toastElement.offsetWidth * ((this.opts.dragToClosePercent.x ?? this.opts.dragToClosePercent) / 100) || Math.abs(this._ptrDeltaY) > this.toastElement.offsetHeight * ((this.opts.dragToClosePercent.y ?? this.opts.dragToClosePercent) / 100)) return this.abort();
|
|
378
400
|
this.#isPaused = this._ptrTicker = this._ptrDirSet = this._ptrDir = false;
|
|
379
401
|
this.toastElement.removeEventListener("pointermove", this._handleToastPointerMove, { passive: false });
|
|
380
402
|
for (const prop of ["transition", "transform", "opacity"]) this.toastElement.style.removeProperty(prop);
|
|
@@ -389,6 +411,7 @@
|
|
|
389
411
|
this.toastElement.classList.remove("t007-toast-show");
|
|
390
412
|
this.onClose?.(timeElapsed);
|
|
391
413
|
}
|
|
414
|
+
abort = () => this.remove("instant", false);
|
|
392
415
|
_createContainer(position) {
|
|
393
416
|
const container = createEl("div", { className: "t007-toast-container" }, { position });
|
|
394
417
|
container.style.setProperty("--t007-toast-container-position", !this.scoped ? "fixed" : "absolute");
|
|
@@ -401,8 +424,8 @@
|
|
|
401
424
|
if (!this.toastElement.querySelector(".t007-toast-body")) imageWrapper().insertAdjacentElement("afterend", createEl("div", { className: "t007-toast-body" }));
|
|
402
425
|
}
|
|
403
426
|
_cleanUpToast() {
|
|
404
|
-
const container = this.toastElement
|
|
405
|
-
this.toastElement
|
|
427
|
+
const container = this.toastElement?.parentElement;
|
|
428
|
+
this.toastElement?.remove();
|
|
406
429
|
if (!container?.hasChildNodes()) container?.remove();
|
|
407
430
|
this.inactive = true;
|
|
408
431
|
}
|
|
@@ -414,7 +437,8 @@
|
|
|
414
437
|
update(base, id, options, _toast) {
|
|
415
438
|
const toast2 = _toast ?? t007.toasts.get(id);
|
|
416
439
|
if (toast2?.queue) for (const tid of toast2.queue) clearTimeout(tid);
|
|
417
|
-
|
|
440
|
+
if (toast2 && toast2.inactive) return t007.toasts.delete(id), base(options.render, { ...toast2.opts, id, ...options });
|
|
441
|
+
return toast2 && toast2.update(options);
|
|
418
442
|
},
|
|
419
443
|
message: (base, getDefaults, action, renderOrId, options = {}) => {
|
|
420
444
|
options = { ...options, type: action === "warn" ? "warning" : action };
|
|
@@ -427,7 +451,7 @@
|
|
|
427
451
|
const id = options.id ?? renderOrId, toast2 = t007.toasts.get(id);
|
|
428
452
|
return (toast2 ? base.update : base)(id, { closeButton: false, closeOnClick: false, dragToClose: false, ...options.id ? { render: renderOrId } : null, autoClose: false, ...options, isLoading: options.isLoading || true, type: "" }, toast2 || void 0);
|
|
429
453
|
},
|
|
430
|
-
promise(base, promise = new Promise((res, rej) =>
|
|
454
|
+
promise(base, promise = new Promise((res, rej) => setTimeout2(Math.round(Math.random()) ? res : rej, 3e3)), { pending, success, error } = {}) {
|
|
431
455
|
if (!promise || !isFunc(promise.then)) return console.error("toast.promise() requires a valid promise");
|
|
432
456
|
const NFC = (input, type) => isStr(input) ? { render: input, type } : isObj(input) ? { ...input, type } : { type };
|
|
433
457
|
const pendingCfg = NFC(pending);
|
|
@@ -436,16 +460,16 @@
|
|
|
436
460
|
(response) => {
|
|
437
461
|
const successConfig = NFC(success || "Promise resolved", "success");
|
|
438
462
|
const { render, bodyHTML } = successConfig;
|
|
439
|
-
if (isFunc(render)) successConfig.render = (
|
|
440
|
-
if (isFunc(bodyHTML)) successConfig.bodyHTML = (
|
|
463
|
+
if (isFunc(render)) successConfig.render = (txt = response) => render(txt);
|
|
464
|
+
if (isFunc(bodyHTML)) successConfig.bodyHTML = (txt = response) => bodyHTML(txt);
|
|
441
465
|
base.success(pendingId, successConfig);
|
|
442
466
|
return response;
|
|
443
467
|
},
|
|
444
468
|
(err) => {
|
|
445
469
|
const errorConfig = NFC(error || "Promise rejected", "error");
|
|
446
470
|
const { render, bodyHTML } = errorConfig;
|
|
447
|
-
if (isFunc(render)) errorConfig.render = (
|
|
448
|
-
if (isFunc(bodyHTML)) errorConfig.bodyHTML = (
|
|
471
|
+
if (isFunc(render)) errorConfig.render = (txt = err) => render(txt);
|
|
472
|
+
if (isFunc(bodyHTML)) errorConfig.bodyHTML = (txt = err) => bodyHTML(txt);
|
|
449
473
|
base.error(pendingId, errorConfig);
|
|
450
474
|
return Promise.reject(err);
|
|
451
475
|
}
|
|
@@ -466,7 +490,7 @@
|
|
|
466
490
|
}
|
|
467
491
|
};
|
|
468
492
|
var toaster = (defOptions = {}, groupId = "t007_toast_") => {
|
|
469
|
-
const getDefaults = () => ({ ...t007.TOAST_DEFAULT_OPTIONS, ...defOptions }), base = (
|
|
493
|
+
const getDefaults = () => ({ ...t007.TOAST_DEFAULT_OPTIONS, ...defOptions }), base = (renderOrId, options = {}, mayBeId = renderOrId?.startsWith?.(groupId), render = mayBeId ? options.render : renderOrId, id = mayBeId ? renderOrId : options.id, toast2 = t007.toasts.get(id)) => toast2 ? toasting.update(base, id, { ...options, render }, toast2) : new T007_Toast({ ...getDefaults(), ...options, id, render, groupId }).opts.id;
|
|
470
494
|
base.isActive = (id) => toasting.isActive(base, id);
|
|
471
495
|
base.update = (id, options, _toast) => toasting.update(base, id, options, _toast);
|
|
472
496
|
for (const action of ["info", "success", "warn", "error"]) base[action] = (renderOrId, options) => toasting.message(base, getDefaults, action, renderOrId, options);
|
|
@@ -480,10 +504,15 @@
|
|
|
480
504
|
};
|
|
481
505
|
var toast = toaster();
|
|
482
506
|
var index_default = toast;
|
|
507
|
+
var TOAST_UI_POSITIONS = [{ value: "top-left", display: "Top Left" }, { value: "top-center", display: "Top Center" }, { value: "top-right", display: "Top Right" }, { value: "center-left", display: "Center Left" }, { value: "center-center", display: "Center Center" }, { value: "center-right", display: "Center Right" }, { value: "bottom-left", display: "Bottom Left" }, { value: "bottom-center", display: "Bottom Center" }, { value: "bottom-right", display: "Bottom Right" }];
|
|
508
|
+
var TOAST_UI_ANIMATIONS = [{ value: "fade", display: "Fade" }, { value: "zoom", display: "Zoom" }, { value: "slide", display: "Slide" }, { value: "slide-left", display: "Slide Left" }, { value: "slide-right", display: "Slide Right" }, { value: "slide-up", display: "Slide Up" }, { value: "slide-down", display: "Slide Down" }];
|
|
509
|
+
var TOAST_UI_TYPES = [{ value: void 0, display: "None" }, { value: "info", display: "Info" }, { value: "success", display: "Success" }, { value: "warning", display: "Warning" }, { value: "error", display: "Error" }];
|
|
510
|
+
var TOAST_UI_DRAG_OPTIONS = [{ value: true, display: "On" }, { value: "mouse", display: "Mouse" }, { value: "touch", display: "Touch" }, { value: "pen", display: "Pen" }, { value: false, display: "Off" }];
|
|
511
|
+
var TOAST_UI_DRAG_DIRECTIONS = [{ value: "x", display: "Horizontal" }, { value: "y", display: "Vertical" }, { value: "xy", display: "Horizontal and Vertical" }, { value: "x|y", display: "Horizontal or Vertical" }, { value: "x||y", display: "Horizontal or Vertical (Locked)" }, { value: "x+", display: "Right" }, { value: "x-", display: "Left" }, { value: "y+", display: "Down" }, { value: "y-", display: "Up" }, { value: "xy+", display: "Right and Down" }, { value: "xy-", display: "Left and Up" }, { value: "x|y+", display: "Right or Down" }, { value: "x|y-", display: "Left or Up" }, { value: "x||y+", display: "Right or Down (Locked)" }, { value: "x||y-", display: "Left or Up (Locked)" }];
|
|
483
512
|
if ("undefined" !== typeof window) {
|
|
484
513
|
t007.toast = toast, t007.toasting = toasting, t007.toaster = toaster;
|
|
485
514
|
t007.toasts = /* @__PURE__ */ new Map();
|
|
486
|
-
t007.TOAST_DEFAULT_OPTIONS ??= {}, t007.TOAST_DURATIONS ??= {}, t007.TOAST_VIBRATIONS ??= {}, t007.TOAST_ICONS ??= {};
|
|
515
|
+
t007.TOAST_DEFAULT_OPTIONS ??= {}, t007.TOAST_DURATIONS ??= {}, t007.TOAST_VIBRATIONS ??= {}, t007.TOAST_ICONS ??= {}, t007.T0AST_UI_POSITIONS = TOAST_UI_POSITIONS, t007.TOAST_UI_ANIMATIONS = TOAST_UI_ANIMATIONS, t007.TOAST_UI_TYPES = TOAST_UI_TYPES, t007.TOAST_UI_DRAG_OPTIONS = TOAST_UI_DRAG_OPTIONS, t007.TOAST_UI_DRAG_DIRECTIONS = TOAST_UI_DRAG_DIRECTIONS;
|
|
487
516
|
t007.TOAST_DEFAULT_OPTIONS.render ??= "";
|
|
488
517
|
t007.TOAST_DEFAULT_OPTIONS.type ??= "";
|
|
489
518
|
t007.TOAST_DEFAULT_OPTIONS.icon ??= true;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/js/index.js
|
|
2
|
-
import { isStr, isNum, isObj, isFunc, clamp, uid, bindAllMethods, isInteractive, createEl, loadResource, isDef } from "@t007/utils";
|
|
2
|
+
import { isStr, isNum, isObj, isFunc, clamp, uid, bindAllMethods, isInteractive, createEl, loadResource, isDef, setTimeout, bindCleanupToSignal } from "@t007/utils";
|
|
3
3
|
var T007_Toast = class {
|
|
4
4
|
#constructed = false;
|
|
5
5
|
// to minimize updates
|
|
@@ -12,10 +12,10 @@ var T007_Toast = class {
|
|
|
12
12
|
inactive = true;
|
|
13
13
|
#visiblityChange = () => this.#shouldUnPause = document.visibilityState === "visible";
|
|
14
14
|
constructor(options) {
|
|
15
|
-
bindAllMethods(this);
|
|
15
|
+
bindAllMethods(this), bindCleanupToSignal(this.abort, options.signal);
|
|
16
16
|
this.opts = options;
|
|
17
17
|
t007.toasts.set(this.opts.id ??= uid(this.opts.groupId ??= "t007_toast_"), this);
|
|
18
|
-
!isNum(this.opts.delay) ? this.activate() : this.queue.push(setTimeout(this.activate, this.opts.delay));
|
|
18
|
+
!isNum(this.opts.delay) ? this.activate() : this.queue.push(setTimeout(this.activate, this.opts.delay, this.opts.signal));
|
|
19
19
|
this.update(this.opts);
|
|
20
20
|
}
|
|
21
21
|
activate() {
|
|
@@ -26,16 +26,17 @@ var T007_Toast = class {
|
|
|
26
26
|
update(options, constructed = this.#constructed) {
|
|
27
27
|
if (!options || !isObj(options) || constructed && this.inactive) return this.opts.id;
|
|
28
28
|
try {
|
|
29
|
+
if (constructed) options.signal !== this.opts.signal && (this.opts.signal.removeEventListener("abort", this.abort), bindCleanupToSignal(this.abort, this.opts.signal));
|
|
29
30
|
this.opts = { ...this.opts, ...options };
|
|
30
31
|
const run = () => (Object.keys(options).forEach((key) => this[key] = options[key]), this.#constructed = true, !constructed && (this.position = this.opts.position));
|
|
31
|
-
!isNum(this.opts.delay) ? run() : this.queue.push(setTimeout(run, this.opts.delay));
|
|
32
|
+
!isNum(this.opts.delay) ? run() : this.queue.push(setTimeout(run, this.opts.delay, this.opts.signal));
|
|
32
33
|
this.opts.delay = null;
|
|
33
34
|
} catch (err) {
|
|
34
35
|
console.error("t007 toast update failed:", err);
|
|
35
36
|
}
|
|
36
37
|
return this.opts.id;
|
|
37
38
|
}
|
|
38
|
-
play = () => setTimeout(() => this.#isPaused = false);
|
|
39
|
+
play = () => setTimeout(() => this.#isPaused = false, 0, this.opts.signal);
|
|
39
40
|
pause = () => this.#isPaused = true;
|
|
40
41
|
get rootElement() {
|
|
41
42
|
return this.opts.rootElement ?? document.body;
|
|
@@ -157,7 +158,7 @@ var T007_Toast = class {
|
|
|
157
158
|
set position(value) {
|
|
158
159
|
if (!this.#constructed) return;
|
|
159
160
|
const currContainer = this.toastElement.parentElement, container = this.rootElement.querySelector(`:scope > .t007-toast-container[data-position="${value}"]`) || this._createContainer(value);
|
|
160
|
-
container[this.opts.newestOnTop ? "prepend" : "append"](this.toastElement);
|
|
161
|
+
!container.contains(this.toastElement) && container[this.opts.newestOnTop ? "prepend" : "append"](this.toastElement);
|
|
161
162
|
this.toastElement.classList.toggle("t007-toast-scoped", this.scoped);
|
|
162
163
|
if (!(currContainer == null || currContainer.hasChildNodes())) currContainer.remove();
|
|
163
164
|
}
|
|
@@ -193,7 +194,7 @@ var T007_Toast = class {
|
|
|
193
194
|
}
|
|
194
195
|
set renotify(value) {
|
|
195
196
|
if (value && this.opts.tag) {
|
|
196
|
-
for (const toast2 of t007.toasts.values()) if (toast2.opts.tag === this.opts.tag && toast2.opts.id !== this.opts.id) toast2.
|
|
197
|
+
for (const toast2 of t007.toasts.values()) if (toast2.opts.tag === this.opts.tag && toast2.opts.id !== this.opts.id) toast2.abort();
|
|
197
198
|
}
|
|
198
199
|
}
|
|
199
200
|
get vibrate() {
|
|
@@ -205,7 +206,7 @@ var T007_Toast = class {
|
|
|
205
206
|
set limit(value) {
|
|
206
207
|
const toastsInContainer = [...this.toastElement?.parentElement?.children || []];
|
|
207
208
|
if (!toastsInContainer.length) return;
|
|
208
|
-
for (let i = 0; i < toastsInContainer.length - value; i++) [...t007.toasts.values()].find((t) => t.toastElement === (this.opts.newestOnTop ? toastsInContainer[toastsInContainer.length - 1 - i] : toastsInContainer[i]))?.
|
|
209
|
+
for (let i = 0; i < toastsInContainer.length - value; i++) [...t007.toasts.values()].find((t) => t.toastElement === (this.opts.newestOnTop ? toastsInContainer[toastsInContainer.length - 1 - i] : toastsInContainer[i]))?.abort();
|
|
209
210
|
}
|
|
210
211
|
set newestOnTop(value) {
|
|
211
212
|
this.toastElement?.parentElement?.[value ? "prepend" : "append"](this.toastElement);
|
|
@@ -230,6 +231,8 @@ var T007_Toast = class {
|
|
|
230
231
|
e.preventDefault();
|
|
231
232
|
if (this._ptrTicker) return;
|
|
232
233
|
this._ptrRAF = requestAnimationFrame(() => {
|
|
234
|
+
const selection = window.getSelection();
|
|
235
|
+
if (selection?.toString().length && this.toastElement.contains(selection.anchorNode)) return this._handleToastPointerUp(e);
|
|
233
236
|
const has = (str) => this.opts.dragToCloseDir.includes(str), x = e.clientX ?? e.targetTouches[0]?.clientX, y = e.clientY ?? e.targetTouches[0]?.clientY;
|
|
234
237
|
this._ptrDir ||= Math.abs(x - this._ptrStartX) >= Math.abs(y - this._ptrStartY) ? "x" : "y";
|
|
235
238
|
this._ptrDeltaX = (has("|") ? this._ptrDir == "x" : has("x")) && !has(x - this._ptrStartX > 0 ? "-" : "+") ? x - this._ptrStartX : 0;
|
|
@@ -246,7 +249,7 @@ var T007_Toast = class {
|
|
|
246
249
|
_handleToastPointerUp(e) {
|
|
247
250
|
if (isStr(this._ptrType) && e.pointerType !== this._ptrType) return;
|
|
248
251
|
cancelAnimationFrame(this._ptrRAF);
|
|
249
|
-
if (Math.abs(this._ptrDeltaX) > this.toastElement.offsetWidth * ((this.opts.dragToClosePercent.x ?? this.opts.dragToClosePercent) / 100) || Math.abs(this._ptrDeltaY) > this.toastElement.offsetHeight * ((this.opts.dragToClosePercent.y ?? this.opts.dragToClosePercent) / 100)) return this.
|
|
252
|
+
if (Math.abs(this._ptrDeltaX) > this.toastElement.offsetWidth * ((this.opts.dragToClosePercent.x ?? this.opts.dragToClosePercent) / 100) || Math.abs(this._ptrDeltaY) > this.toastElement.offsetHeight * ((this.opts.dragToClosePercent.y ?? this.opts.dragToClosePercent) / 100)) return this.abort();
|
|
250
253
|
this.#isPaused = this._ptrTicker = this._ptrDirSet = this._ptrDir = false;
|
|
251
254
|
this.toastElement.removeEventListener("pointermove", this._handleToastPointerMove, { passive: false });
|
|
252
255
|
for (const prop of ["transition", "transform", "opacity"]) this.toastElement.style.removeProperty(prop);
|
|
@@ -261,6 +264,7 @@ var T007_Toast = class {
|
|
|
261
264
|
this.toastElement.classList.remove("t007-toast-show");
|
|
262
265
|
this.onClose?.(timeElapsed);
|
|
263
266
|
}
|
|
267
|
+
abort = () => this.remove("instant", false);
|
|
264
268
|
_createContainer(position) {
|
|
265
269
|
const container = createEl("div", { className: "t007-toast-container" }, { position });
|
|
266
270
|
container.style.setProperty("--t007-toast-container-position", !this.scoped ? "fixed" : "absolute");
|
|
@@ -273,8 +277,8 @@ var T007_Toast = class {
|
|
|
273
277
|
if (!this.toastElement.querySelector(".t007-toast-body")) imageWrapper().insertAdjacentElement("afterend", createEl("div", { className: "t007-toast-body" }));
|
|
274
278
|
}
|
|
275
279
|
_cleanUpToast() {
|
|
276
|
-
const container = this.toastElement
|
|
277
|
-
this.toastElement
|
|
280
|
+
const container = this.toastElement?.parentElement;
|
|
281
|
+
this.toastElement?.remove();
|
|
278
282
|
if (!container?.hasChildNodes()) container?.remove();
|
|
279
283
|
this.inactive = true;
|
|
280
284
|
}
|
|
@@ -286,7 +290,8 @@ var toasting = {
|
|
|
286
290
|
update(base, id, options, _toast) {
|
|
287
291
|
const toast2 = _toast ?? t007.toasts.get(id);
|
|
288
292
|
if (toast2?.queue) for (const tid of toast2.queue) clearTimeout(tid);
|
|
289
|
-
|
|
293
|
+
if (toast2 && toast2.inactive) return t007.toasts.delete(id), base(options.render, { ...toast2.opts, id, ...options });
|
|
294
|
+
return toast2 && toast2.update(options);
|
|
290
295
|
},
|
|
291
296
|
message: (base, getDefaults, action, renderOrId, options = {}) => {
|
|
292
297
|
options = { ...options, type: action === "warn" ? "warning" : action };
|
|
@@ -308,16 +313,16 @@ var toasting = {
|
|
|
308
313
|
(response) => {
|
|
309
314
|
const successConfig = NFC(success || "Promise resolved", "success");
|
|
310
315
|
const { render, bodyHTML } = successConfig;
|
|
311
|
-
if (isFunc(render)) successConfig.render = (
|
|
312
|
-
if (isFunc(bodyHTML)) successConfig.bodyHTML = (
|
|
316
|
+
if (isFunc(render)) successConfig.render = (txt = response) => render(txt);
|
|
317
|
+
if (isFunc(bodyHTML)) successConfig.bodyHTML = (txt = response) => bodyHTML(txt);
|
|
313
318
|
base.success(pendingId, successConfig);
|
|
314
319
|
return response;
|
|
315
320
|
},
|
|
316
321
|
(err) => {
|
|
317
322
|
const errorConfig = NFC(error || "Promise rejected", "error");
|
|
318
323
|
const { render, bodyHTML } = errorConfig;
|
|
319
|
-
if (isFunc(render)) errorConfig.render = (
|
|
320
|
-
if (isFunc(bodyHTML)) errorConfig.bodyHTML = (
|
|
324
|
+
if (isFunc(render)) errorConfig.render = (txt = err) => render(txt);
|
|
325
|
+
if (isFunc(bodyHTML)) errorConfig.bodyHTML = (txt = err) => bodyHTML(txt);
|
|
321
326
|
base.error(pendingId, errorConfig);
|
|
322
327
|
return Promise.reject(err);
|
|
323
328
|
}
|
|
@@ -338,7 +343,7 @@ var toasting = {
|
|
|
338
343
|
}
|
|
339
344
|
};
|
|
340
345
|
var toaster = (defOptions = {}, groupId = "t007_toast_") => {
|
|
341
|
-
const getDefaults = () => ({ ...t007.TOAST_DEFAULT_OPTIONS, ...defOptions }), base = (
|
|
346
|
+
const getDefaults = () => ({ ...t007.TOAST_DEFAULT_OPTIONS, ...defOptions }), base = (renderOrId, options = {}, mayBeId = renderOrId?.startsWith?.(groupId), render = mayBeId ? options.render : renderOrId, id = mayBeId ? renderOrId : options.id, toast2 = t007.toasts.get(id)) => toast2 ? toasting.update(base, id, { ...options, render }, toast2) : new T007_Toast({ ...getDefaults(), ...options, id, render, groupId }).opts.id;
|
|
342
347
|
base.isActive = (id) => toasting.isActive(base, id);
|
|
343
348
|
base.update = (id, options, _toast) => toasting.update(base, id, options, _toast);
|
|
344
349
|
for (const action of ["info", "success", "warn", "error"]) base[action] = (renderOrId, options) => toasting.message(base, getDefaults, action, renderOrId, options);
|
|
@@ -352,10 +357,15 @@ var toaster = (defOptions = {}, groupId = "t007_toast_") => {
|
|
|
352
357
|
};
|
|
353
358
|
var toast = toaster();
|
|
354
359
|
var index_default = toast;
|
|
360
|
+
var TOAST_UI_POSITIONS = [{ value: "top-left", display: "Top Left" }, { value: "top-center", display: "Top Center" }, { value: "top-right", display: "Top Right" }, { value: "center-left", display: "Center Left" }, { value: "center-center", display: "Center Center" }, { value: "center-right", display: "Center Right" }, { value: "bottom-left", display: "Bottom Left" }, { value: "bottom-center", display: "Bottom Center" }, { value: "bottom-right", display: "Bottom Right" }];
|
|
361
|
+
var TOAST_UI_ANIMATIONS = [{ value: "fade", display: "Fade" }, { value: "zoom", display: "Zoom" }, { value: "slide", display: "Slide" }, { value: "slide-left", display: "Slide Left" }, { value: "slide-right", display: "Slide Right" }, { value: "slide-up", display: "Slide Up" }, { value: "slide-down", display: "Slide Down" }];
|
|
362
|
+
var TOAST_UI_TYPES = [{ value: void 0, display: "None" }, { value: "info", display: "Info" }, { value: "success", display: "Success" }, { value: "warning", display: "Warning" }, { value: "error", display: "Error" }];
|
|
363
|
+
var TOAST_UI_DRAG_OPTIONS = [{ value: true, display: "On" }, { value: "mouse", display: "Mouse" }, { value: "touch", display: "Touch" }, { value: "pen", display: "Pen" }, { value: false, display: "Off" }];
|
|
364
|
+
var TOAST_UI_DRAG_DIRECTIONS = [{ value: "x", display: "Horizontal" }, { value: "y", display: "Vertical" }, { value: "xy", display: "Horizontal and Vertical" }, { value: "x|y", display: "Horizontal or Vertical" }, { value: "x||y", display: "Horizontal or Vertical (Locked)" }, { value: "x+", display: "Right" }, { value: "x-", display: "Left" }, { value: "y+", display: "Down" }, { value: "y-", display: "Up" }, { value: "xy+", display: "Right and Down" }, { value: "xy-", display: "Left and Up" }, { value: "x|y+", display: "Right or Down" }, { value: "x|y-", display: "Left or Up" }, { value: "x||y+", display: "Right or Down (Locked)" }, { value: "x||y-", display: "Left or Up (Locked)" }];
|
|
355
365
|
if ("undefined" !== typeof window) {
|
|
356
366
|
t007.toast = toast, t007.toasting = toasting, t007.toaster = toaster;
|
|
357
367
|
t007.toasts = /* @__PURE__ */ new Map();
|
|
358
|
-
t007.TOAST_DEFAULT_OPTIONS ??= {}, t007.TOAST_DURATIONS ??= {}, t007.TOAST_VIBRATIONS ??= {}, t007.TOAST_ICONS ??= {};
|
|
368
|
+
t007.TOAST_DEFAULT_OPTIONS ??= {}, t007.TOAST_DURATIONS ??= {}, t007.TOAST_VIBRATIONS ??= {}, t007.TOAST_ICONS ??= {}, t007.T0AST_UI_POSITIONS = TOAST_UI_POSITIONS, t007.TOAST_UI_ANIMATIONS = TOAST_UI_ANIMATIONS, t007.TOAST_UI_TYPES = TOAST_UI_TYPES, t007.TOAST_UI_DRAG_OPTIONS = TOAST_UI_DRAG_OPTIONS, t007.TOAST_UI_DRAG_DIRECTIONS = TOAST_UI_DRAG_DIRECTIONS;
|
|
359
369
|
t007.TOAST_DEFAULT_OPTIONS.render ??= "";
|
|
360
370
|
t007.TOAST_DEFAULT_OPTIONS.type ??= "";
|
|
361
371
|
t007.TOAST_DEFAULT_OPTIONS.icon ??= true;
|
|
@@ -388,6 +398,11 @@ if ("undefined" !== typeof window) {
|
|
|
388
398
|
console.log("%cT007 Toasts attached to window!", "color: darkturquoise");
|
|
389
399
|
}
|
|
390
400
|
export {
|
|
401
|
+
TOAST_UI_ANIMATIONS,
|
|
402
|
+
TOAST_UI_DRAG_DIRECTIONS,
|
|
403
|
+
TOAST_UI_DRAG_OPTIONS,
|
|
404
|
+
TOAST_UI_POSITIONS,
|
|
405
|
+
TOAST_UI_TYPES,
|
|
391
406
|
index_default as default,
|
|
392
407
|
toaster,
|
|
393
408
|
toasting
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t007/toast",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"description": "A lightweight, pure JS toast system.",
|
|
5
5
|
"author": "Oketade Oluwatobiloba <tobioketade007@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"types": "./dist/index.d.ts",
|
|
22
22
|
"style": "./dist/index.css",
|
|
23
23
|
"sideEffects": [
|
|
24
|
-
"
|
|
24
|
+
"**/*.css",
|
|
25
|
+
"**/*.scss"
|
|
25
26
|
],
|
|
26
27
|
"exports": {
|
|
27
28
|
".": {
|
|
@@ -54,7 +55,7 @@
|
|
|
54
55
|
"promise"
|
|
55
56
|
],
|
|
56
57
|
"dependencies": {
|
|
57
|
-
"@t007/utils": "^0.0.
|
|
58
|
+
"@t007/utils": "^0.0.35"
|
|
58
59
|
},
|
|
59
60
|
"devDependencies": {
|
|
60
61
|
"esbuild-sass-plugin": "^3.7.0"
|