kitzo 2.3.42 → 2.3.44
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 +4 -2
- package/dist/react/components/toast/Toaster.js +31 -28
- package/dist/react/components/toast/helpers/addToastStyles.js +21 -8
- package/dist/react/components/toast/helpers/createToast.js +30 -29
- package/dist/react/components/toast/helpers/listenars.js +31 -0
- package/dist/react/components/toast/helpers/manageToasts/addToasts.js +7 -7
- package/dist/react/components/toast/helpers/manageToasts/dismissToasts.js +13 -15
- package/dist/react/components/toast/helpers/manageToasts/swipeClose.js +31 -33
- package/dist/react/components/toast/helpers/manageToasts/timers.js +60 -66
- package/dist/react/components/toast/helpers/manageToasts/updateToasts.js +10 -5
- package/dist/react/components/toast/helpers/triggerToasts.js +25 -26
- package/dist/react/components/toast/partials/Toast.js +34 -23
- package/package.json +1 -1
- package/dist/react/components/toast/helpers/listenar.js +0 -14
package/dist/index.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ declare type PromiseToastMsgs<T, E = unknown> = {
|
|
|
27
27
|
error: ReactNode | ((err: E) => ReactNode | Promise<ReactNode>);
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
declare type PromiseToastOptions = Omit<ToastOptions, 'id' | 'type'
|
|
30
|
+
declare type PromiseToastOptions = Omit<ToastOptions, 'id' | 'type'>;
|
|
31
31
|
|
|
32
32
|
export declare const toast: ToastFn;
|
|
33
33
|
|
|
@@ -44,6 +44,7 @@ declare type ToasterProps = {
|
|
|
44
44
|
isDark?: boolean;
|
|
45
45
|
pauseOnHover?: boolean;
|
|
46
46
|
swipeToClose?: boolean;
|
|
47
|
+
toasterId?: string | number;
|
|
47
48
|
};
|
|
48
49
|
|
|
49
50
|
declare type ToastFn = {
|
|
@@ -55,7 +56,7 @@ declare type ToastFn = {
|
|
|
55
56
|
promise: PromiseToastFn;
|
|
56
57
|
loading: (content: ToastContent, options?: Options) => void;
|
|
57
58
|
custom: (content: ToastContent, options?: Options) => void;
|
|
58
|
-
dismiss: (id?: string | number) => void;
|
|
59
|
+
dismiss: (id?: string | number, toasterId?: string | number) => void;
|
|
59
60
|
update: (id: string | number, content: ToastContent, options?: UpdateToastOptions) => void;
|
|
60
61
|
};
|
|
61
62
|
|
|
@@ -68,6 +69,7 @@ declare type ToastOptions = {
|
|
|
68
69
|
id?: string | number;
|
|
69
70
|
type?: ToastType;
|
|
70
71
|
swipeToClose?: boolean;
|
|
72
|
+
toasterId?: string | number;
|
|
71
73
|
};
|
|
72
74
|
|
|
73
75
|
declare type ToastOptionsWithoutType = Omit<ToastOptions, 'type'>;
|
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
import { jsx as a } from "react/jsx-runtime";
|
|
2
2
|
import t from "react";
|
|
3
|
-
import { subscribe as E } from "./helpers/
|
|
3
|
+
import { subscribe as E } from "./helpers/listenars.js";
|
|
4
4
|
import w from "./helpers/manageToasts/manageToasts.js";
|
|
5
5
|
import M from "./partials/ToastContainer.js";
|
|
6
6
|
import { ToasterContext as O } from "./context/ToasterContext.js";
|
|
7
7
|
import { initSwipeToClose as S } from "./helpers/manageToasts/swipeClose.js";
|
|
8
|
-
function
|
|
8
|
+
function D(i) {
|
|
9
9
|
const {
|
|
10
10
|
position: h = "top-center",
|
|
11
|
-
richColors:
|
|
11
|
+
richColors: l = !1,
|
|
12
12
|
animateTransformOrigin: g = !0,
|
|
13
13
|
gap: s = 8,
|
|
14
|
-
edgeOffset:
|
|
15
|
-
isDark:
|
|
14
|
+
edgeOffset: n = 16,
|
|
15
|
+
isDark: c,
|
|
16
16
|
pauseOnHover: b = !0,
|
|
17
17
|
swipeToClose: y = !0
|
|
18
|
-
} =
|
|
18
|
+
} = i, [k, T] = t.useState(!1);
|
|
19
19
|
t.useEffect(() => {
|
|
20
20
|
T(!0);
|
|
21
21
|
}, []);
|
|
22
|
-
const [
|
|
22
|
+
const [p, m] = t.useState([]);
|
|
23
23
|
t.useEffect(() => {
|
|
24
|
-
const e = E(
|
|
24
|
+
const e = E(
|
|
25
|
+
(o) => w({ toast: o, setToasts: m }),
|
|
26
|
+
i.toasterId
|
|
27
|
+
), r = S();
|
|
25
28
|
return () => {
|
|
26
29
|
e(), r();
|
|
27
30
|
};
|
|
28
|
-
}, []);
|
|
29
|
-
const
|
|
30
|
-
if (!
|
|
31
|
-
const e =
|
|
31
|
+
}, [i.toasterId]);
|
|
32
|
+
const f = t.useRef(null), u = t.useCallback(() => {
|
|
33
|
+
if (!f.current) return;
|
|
34
|
+
const e = f.current.querySelectorAll("[data-toast-container]"), r = {
|
|
32
35
|
"top-left": 0,
|
|
33
36
|
"top-center": 0,
|
|
34
37
|
"top-right": 0,
|
|
@@ -37,29 +40,29 @@ function I(d) {
|
|
|
37
40
|
"bottom-right": 0
|
|
38
41
|
};
|
|
39
42
|
e.forEach((o) => {
|
|
40
|
-
const
|
|
41
|
-
o.style.setProperty("--toast-offset-y", `${r[
|
|
43
|
+
const d = o.getAttribute("data-toast-position") || "top-center", x = parseFloat(o.style.getPropertyValue("--toast-height")) || 0;
|
|
44
|
+
o.style.setProperty("--toast-offset-y", `${r[d]}px`);
|
|
42
45
|
const C = isNaN(+s) ? 8 : +s;
|
|
43
|
-
r[
|
|
46
|
+
r[d] += x + C;
|
|
44
47
|
});
|
|
45
48
|
}, [s]);
|
|
46
49
|
if (t.useLayoutEffect(() => {
|
|
47
|
-
|
|
48
|
-
}, [
|
|
49
|
-
const v = typeof
|
|
50
|
+
u();
|
|
51
|
+
}, [p, u]), !k) return null;
|
|
52
|
+
const v = typeof c == "boolean" ? c : window.matchMedia("(prefers-color-scheme: dark)").matches;
|
|
50
53
|
return /* @__PURE__ */ a(
|
|
51
54
|
"div",
|
|
52
55
|
{
|
|
53
|
-
ref:
|
|
56
|
+
ref: f,
|
|
54
57
|
style: {
|
|
55
58
|
position: "fixed",
|
|
56
59
|
inset: 0,
|
|
57
60
|
zIndex: 2147483647,
|
|
58
61
|
pointerEvents: "none",
|
|
59
62
|
display: "grid",
|
|
60
|
-
padding:
|
|
63
|
+
padding: n != null ? `${Math.max(Math.min(+n, 200), 0)}px` : 16
|
|
61
64
|
},
|
|
62
|
-
className: `kitzo-toaster ${
|
|
65
|
+
className: `kitzo-toaster ${l ? "kitzo-toaster-rich-colors" : ""} ${v ? "kitzo-toaster-dark" : ""}`,
|
|
63
66
|
children: /* @__PURE__ */ a(
|
|
64
67
|
"div",
|
|
65
68
|
{
|
|
@@ -71,17 +74,17 @@ function I(d) {
|
|
|
71
74
|
{
|
|
72
75
|
value: {
|
|
73
76
|
position: h,
|
|
74
|
-
richColors:
|
|
75
|
-
isDark:
|
|
77
|
+
richColors: l,
|
|
78
|
+
isDark: c,
|
|
76
79
|
gap: s,
|
|
77
|
-
edgeOffset:
|
|
80
|
+
edgeOffset: n,
|
|
78
81
|
animateTransformOrigin: g,
|
|
79
82
|
pauseOnHover: b,
|
|
80
83
|
swipeToClose: y,
|
|
81
|
-
setToasts:
|
|
82
|
-
updateOffsets:
|
|
84
|
+
setToasts: m,
|
|
85
|
+
updateOffsets: u
|
|
83
86
|
},
|
|
84
|
-
children:
|
|
87
|
+
children: p.map((e) => /* @__PURE__ */ a(M, { t: e }, e.id))
|
|
85
88
|
}
|
|
86
89
|
)
|
|
87
90
|
}
|
|
@@ -90,5 +93,5 @@ function I(d) {
|
|
|
90
93
|
);
|
|
91
94
|
}
|
|
92
95
|
export {
|
|
93
|
-
|
|
96
|
+
D as default
|
|
94
97
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const
|
|
1
|
+
const a = `.kitzo-toaster {
|
|
2
2
|
--default-bg: hsl(0, 0%, 100%);
|
|
3
3
|
--default-text: hsl(0, 0%, 10%);
|
|
4
4
|
--default-border: hsl(0, 0%, 94%);
|
|
@@ -182,14 +182,27 @@ const o = `.kitzo-toaster {
|
|
|
182
182
|
translateY(var(--motion-y)) scale(var(--scale));
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
.kitzo-toast[data-
|
|
186
|
-
animation: update
|
|
185
|
+
.kitzo-toast[data-update-state='updated'] {
|
|
186
|
+
animation: update 250ms ease;
|
|
187
|
+
}
|
|
188
|
+
.kitzo-toast[data-update-state='updated-again'] {
|
|
189
|
+
animation: update-again 250ms ease;
|
|
187
190
|
}
|
|
188
191
|
|
|
189
192
|
@keyframes update {
|
|
190
193
|
0% {
|
|
191
|
-
transform: scale(0.
|
|
192
|
-
opacity: 0.
|
|
194
|
+
transform: scale(0.96);
|
|
195
|
+
opacity: 0.8;
|
|
196
|
+
}
|
|
197
|
+
100% {
|
|
198
|
+
opacity: 1;
|
|
199
|
+
transform: scale(1);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
@keyframes update-again {
|
|
203
|
+
0% {
|
|
204
|
+
transform: scale(0.96);
|
|
205
|
+
opacity: 0.8;
|
|
193
206
|
}
|
|
194
207
|
100% {
|
|
195
208
|
opacity: 1;
|
|
@@ -271,12 +284,12 @@ const o = `.kitzo-toaster {
|
|
|
271
284
|
rotate: 360deg;
|
|
272
285
|
}
|
|
273
286
|
}`;
|
|
274
|
-
function
|
|
287
|
+
function o() {
|
|
275
288
|
if (!document.getElementById("kitzo-toast-styles")) {
|
|
276
289
|
const t = document.createElement("style");
|
|
277
|
-
t.id = "kitzo-toast-styles", t.textContent =
|
|
290
|
+
t.id = "kitzo-toast-styles", t.textContent = a, document.head.appendChild(t);
|
|
278
291
|
}
|
|
279
292
|
}
|
|
280
293
|
export {
|
|
281
|
-
|
|
294
|
+
o as default
|
|
282
295
|
};
|
|
@@ -1,49 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
import { DEFAULT_TOASTER_ID as r } from "./listenars.js";
|
|
2
|
+
const e = {
|
|
2
3
|
duration: 2800,
|
|
3
4
|
showIcon: !0,
|
|
4
5
|
animateTransformOrigin: void 0,
|
|
5
6
|
swipeToClose: void 0
|
|
6
7
|
};
|
|
7
|
-
let
|
|
8
|
-
const d = () => crypto.randomUUID?.() ?? ++
|
|
8
|
+
let s = 0;
|
|
9
|
+
const d = () => crypto.randomUUID?.() ?? ++s;
|
|
9
10
|
let u = 1;
|
|
10
|
-
function
|
|
11
|
-
type:
|
|
12
|
-
action:
|
|
13
|
-
content:
|
|
14
|
-
|
|
15
|
-
options: a
|
|
11
|
+
function p({
|
|
12
|
+
type: a,
|
|
13
|
+
action: i,
|
|
14
|
+
content: n,
|
|
15
|
+
options: o
|
|
16
16
|
}) {
|
|
17
|
-
const
|
|
17
|
+
const t = typeof o == "object" && o !== null ? o : {};
|
|
18
18
|
return {
|
|
19
|
-
id:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
id: `${t.id ?? d()}`,
|
|
20
|
+
toasterId: `${t.toasterId ?? r}`,
|
|
21
|
+
duration: t.duration ?? e.duration,
|
|
22
|
+
showIcon: t.showIcon ?? e.showIcon,
|
|
23
|
+
animateTransformOrigin: t.animateTransformOrigin ?? e.animateTransformOrigin,
|
|
24
|
+
position: t.position,
|
|
25
|
+
icon: t.icon,
|
|
26
|
+
type: a === "default" ? t.type ?? "default" : a,
|
|
26
27
|
status: "entering",
|
|
27
28
|
zIndex: ++u,
|
|
28
|
-
content:
|
|
29
|
-
action:
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
content: n,
|
|
30
|
+
action: i,
|
|
31
|
+
swipeToClose: t.swipeToClose ?? e.swipeToClose,
|
|
32
|
+
updateState: "initial"
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
|
-
function l({ id:
|
|
35
|
-
const
|
|
35
|
+
function l({ id: a, content: i, options: n }) {
|
|
36
|
+
const o = typeof n == "object" && n !== null ? n : {};
|
|
36
37
|
return {
|
|
37
|
-
...
|
|
38
|
-
id:
|
|
39
|
-
content:
|
|
38
|
+
...o,
|
|
39
|
+
id: a,
|
|
40
|
+
content: i,
|
|
40
41
|
action: "update",
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
duration: o.duration ?? e.duration,
|
|
43
|
+
toasterId: `${o.toasterId ?? r}`
|
|
43
44
|
};
|
|
44
45
|
}
|
|
45
46
|
export {
|
|
46
|
-
|
|
47
|
+
p as createToast,
|
|
47
48
|
d as genId,
|
|
48
49
|
l as updateToast
|
|
49
50
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import u from "./addToastStyles.js";
|
|
2
|
+
const r = /* @__PURE__ */ new Map(), s = "default";
|
|
3
|
+
function l(t, e = s) {
|
|
4
|
+
u(), e = `toaster-id:${e ?? s}`, r.has(e) || r.set(e, /* @__PURE__ */ new Set());
|
|
5
|
+
const n = r.get(e);
|
|
6
|
+
return n && n.add(t), () => {
|
|
7
|
+
n?.delete(t), n?.size === 0 && r.delete(e);
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function o(t, e) {
|
|
11
|
+
if (e != null)
|
|
12
|
+
return e = `${e}`, e.startsWith(t) ? e : `${t}${e}`;
|
|
13
|
+
}
|
|
14
|
+
function a(t) {
|
|
15
|
+
if (t.id == null) {
|
|
16
|
+
r.forEach((i) => {
|
|
17
|
+
i.forEach((c) => c({ ...t }));
|
|
18
|
+
});
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const e = o("toast-id:", t.id), n = o(
|
|
22
|
+
"toaster-id:",
|
|
23
|
+
t.toasterId ?? s
|
|
24
|
+
), f = r.get(n);
|
|
25
|
+
f && f.forEach((i) => i({ ...t, id: e, toasterId: n }));
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
s as DEFAULT_TOASTER_ID,
|
|
29
|
+
a as notify,
|
|
30
|
+
l as subscribe
|
|
31
|
+
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { addTimers as
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
(i) => i.map((
|
|
1
|
+
import { addTimers as e } from "./timers.js";
|
|
2
|
+
function u({ toast: d, setToasts: n }) {
|
|
3
|
+
n((i) => i.find((r) => r.id === d.id) ? i : [d, ...i]), requestAnimationFrame(() => {
|
|
4
|
+
n(
|
|
5
|
+
(i) => i.map((s) => s.id === d.id ? { ...s, status: "visible" } : s)
|
|
6
6
|
);
|
|
7
|
-
}),
|
|
7
|
+
}), e(d);
|
|
8
8
|
}
|
|
9
9
|
export {
|
|
10
|
-
|
|
10
|
+
u as default
|
|
11
11
|
};
|
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
import { LEAVE_DELAY as
|
|
2
|
-
function
|
|
3
|
-
if (l.id == null) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
},
|
|
1
|
+
import { LEAVE_DELAY as r, clearAllTimers as s, clearTimer as u } from "./timers.js";
|
|
2
|
+
function a({ toast: l, setToasts: n }) {
|
|
3
|
+
if (l.action === "dismiss" && l.id == null) {
|
|
4
|
+
n((i) => i.map((e) => ({ ...e, status: "leaving" }))), setTimeout(() => {
|
|
5
|
+
n((i) => i.filter((e) => e.status !== "leaving"));
|
|
6
|
+
}, r), s();
|
|
7
7
|
return;
|
|
8
8
|
}
|
|
9
|
-
n(l.id)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
(
|
|
13
|
-
|
|
14
|
-
d(
|
|
15
|
-
(e) => e.filter((i) => !(i.id === r && i.status === "leaving"))
|
|
9
|
+
n((i) => (i.find((d) => d.id === l.id) && u(l.id), i.map(
|
|
10
|
+
(d) => d.id === l.id ? { ...d, status: "leaving" } : d
|
|
11
|
+
))), setTimeout(() => {
|
|
12
|
+
n(
|
|
13
|
+
(i) => i.filter((e) => !(e.id === l.id && e.status === "leaving"))
|
|
16
14
|
);
|
|
17
|
-
},
|
|
15
|
+
}, r);
|
|
18
16
|
}
|
|
19
17
|
export {
|
|
20
|
-
|
|
18
|
+
a as default
|
|
21
19
|
};
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import b from "../triggerToasts.js";
|
|
2
|
-
let s = !1,
|
|
2
|
+
let s = !1, e = null, c = null, m = 0, r = 0, a = !1, l = null;
|
|
3
3
|
const L = 2, y = 90, S = 20, g = 100;
|
|
4
|
-
function
|
|
5
|
-
const o = Math.sign(
|
|
4
|
+
function x(t) {
|
|
5
|
+
const o = Math.sign(t) || 1, n = Math.abs(t), h = S * (1 - Math.exp(-n / g));
|
|
6
6
|
return o * h;
|
|
7
7
|
}
|
|
8
|
-
function E(
|
|
9
|
-
|
|
10
|
-
const o = e.dataset.swipeable === "true", n = e.dataset.isPromise === "true";
|
|
11
|
-
return o && !n;
|
|
8
|
+
function E(t) {
|
|
9
|
+
return t ? t.dataset.swipeable === "true" : !1;
|
|
12
10
|
}
|
|
13
|
-
function i(
|
|
14
|
-
if (!
|
|
15
|
-
if (document.body.style.userSelect = "auto",
|
|
11
|
+
function i(t = !0) {
|
|
12
|
+
if (!e) return;
|
|
13
|
+
if (document.body.style.userSelect = "auto", t && l != null)
|
|
16
14
|
try {
|
|
17
|
-
|
|
15
|
+
e.releasePointerCapture(l);
|
|
18
16
|
} catch {
|
|
19
17
|
console.error("");
|
|
20
18
|
}
|
|
21
|
-
|
|
22
|
-
const o =
|
|
23
|
-
if (
|
|
19
|
+
e.style.setProperty("--swipe-x", "0px"), e.classList.remove("is-swiping");
|
|
20
|
+
const o = e;
|
|
21
|
+
if (e = null, c = null, l = null, a = !1, s = !1, r = 0, !o.matches(":hover")) {
|
|
24
22
|
const n = new MouseEvent("mouseleave", {
|
|
25
23
|
bubbles: !0,
|
|
26
24
|
cancelable: !0,
|
|
@@ -29,50 +27,50 @@ function i(e = !0) {
|
|
|
29
27
|
o.dispatchEvent(n);
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
|
-
function d(
|
|
33
|
-
const n =
|
|
34
|
-
n && (
|
|
30
|
+
function d(t) {
|
|
31
|
+
const n = t.target.closest(".kitzo-toast");
|
|
32
|
+
n && (e = n, c = n.id, m = t.clientX, r = 0, a = !0, s = !1, l = t.pointerId);
|
|
35
33
|
}
|
|
36
|
-
function p(
|
|
37
|
-
if (!a || !
|
|
38
|
-
if (r =
|
|
39
|
-
s = !0,
|
|
34
|
+
function p(t) {
|
|
35
|
+
if (!a || !e) return;
|
|
36
|
+
if (r = t.clientX - m, !s && Math.abs(r) > L) {
|
|
37
|
+
s = !0, e.classList.add("is-swiping");
|
|
40
38
|
try {
|
|
41
|
-
|
|
39
|
+
e.setPointerCapture(t.pointerId), document.body.style.userSelect = "none";
|
|
42
40
|
} catch {
|
|
43
41
|
console.error("Failed to capture pointer");
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
if (!s) return;
|
|
47
|
-
const n = E(
|
|
48
|
-
|
|
45
|
+
const n = E(e) ? r : x(r);
|
|
46
|
+
e.style.setProperty("--swipe-x", `${n}px`);
|
|
49
47
|
}
|
|
50
48
|
function f() {
|
|
51
|
-
if (!a || !
|
|
49
|
+
if (!a || !e || c == null) {
|
|
52
50
|
i();
|
|
53
51
|
return;
|
|
54
52
|
}
|
|
55
|
-
const
|
|
56
|
-
if (s &&
|
|
53
|
+
const t = E(e);
|
|
54
|
+
if (s && t && Math.abs(r) > y) {
|
|
57
55
|
const o = r > 0 ? 1 : -1, n = Math.abs(r) + 220;
|
|
58
|
-
|
|
56
|
+
e.style.setProperty("--exit-x", `${o * n}px`), e.dataset.exit = "swipe", b.dismiss(c, e.dataset.toasterId);
|
|
59
57
|
}
|
|
60
58
|
i();
|
|
61
59
|
}
|
|
62
60
|
function v() {
|
|
63
61
|
i();
|
|
64
62
|
}
|
|
65
|
-
function
|
|
63
|
+
function w() {
|
|
66
64
|
a && i();
|
|
67
65
|
}
|
|
68
66
|
let u = !1;
|
|
69
|
-
function
|
|
67
|
+
function P() {
|
|
70
68
|
return u ? () => {
|
|
71
|
-
} : (u = !0, document.addEventListener("pointerdown", d), document.addEventListener("pointermove", p), document.addEventListener("pointerup", f), document.addEventListener("pointercancel", v), window.addEventListener("blur",
|
|
72
|
-
i(), u = !1, document.removeEventListener("pointerdown", d), document.removeEventListener("pointermove", p), document.removeEventListener("pointerup", f), document.removeEventListener("pointercancel", v), window.removeEventListener("blur",
|
|
69
|
+
} : (u = !0, document.addEventListener("pointerdown", d), document.addEventListener("pointermove", p), document.addEventListener("pointerup", f), document.addEventListener("pointercancel", v), window.addEventListener("blur", w), () => {
|
|
70
|
+
i(), u = !1, document.removeEventListener("pointerdown", d), document.removeEventListener("pointermove", p), document.removeEventListener("pointerup", f), document.removeEventListener("pointercancel", v), window.removeEventListener("blur", w);
|
|
73
71
|
});
|
|
74
72
|
}
|
|
75
73
|
export {
|
|
76
74
|
s as dragStarted,
|
|
77
|
-
|
|
75
|
+
P as initSwipeToClose
|
|
78
76
|
};
|
|
@@ -1,79 +1,73 @@
|
|
|
1
|
-
import { dragStarted as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return {
|
|
8
|
-
totalTime: i,
|
|
9
|
-
leavingDuration: i,
|
|
10
|
-
leftDuration: i + f
|
|
11
|
-
};
|
|
1
|
+
import { dragStarted as m } from "./swipeClose.js";
|
|
2
|
+
import { notify as s } from "../listenars.js";
|
|
3
|
+
const i = /* @__PURE__ */ new Map(), T = 500, u = 0;
|
|
4
|
+
function a(t) {
|
|
5
|
+
const e = Number(t);
|
|
6
|
+
return isFinite(e) ? Math.max(u, e) : null;
|
|
12
7
|
}
|
|
13
|
-
function
|
|
14
|
-
const
|
|
15
|
-
|
|
8
|
+
function c(t) {
|
|
9
|
+
const e = i.get(t);
|
|
10
|
+
e && (clearTimeout(e.timeoutId), i.delete(t));
|
|
16
11
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
clearTimeout(
|
|
20
|
-
}),
|
|
12
|
+
function l() {
|
|
13
|
+
i.forEach(({ timeoutId: t }) => {
|
|
14
|
+
clearTimeout(t);
|
|
15
|
+
}), i.clear();
|
|
21
16
|
}
|
|
22
|
-
function
|
|
23
|
-
const
|
|
24
|
-
if (!
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
totalTime: i.totalTime,
|
|
17
|
+
function I(t) {
|
|
18
|
+
const e = a(t.duration);
|
|
19
|
+
if (!e) return;
|
|
20
|
+
c(t.id);
|
|
21
|
+
const n = setTimeout(() => {
|
|
22
|
+
s({
|
|
23
|
+
action: "dismiss",
|
|
24
|
+
id: t.id,
|
|
25
|
+
toasterId: t.toasterId
|
|
26
|
+
}), i.delete(t.id);
|
|
27
|
+
}, e), r = Date.now();
|
|
28
|
+
i.set(t.id, {
|
|
29
|
+
timeoutId: n,
|
|
30
|
+
startingTime: r,
|
|
31
|
+
totalTime: e,
|
|
38
32
|
remainningTime: 0,
|
|
39
|
-
paused: !1
|
|
33
|
+
paused: !1,
|
|
34
|
+
toasterId: t.toasterId
|
|
40
35
|
});
|
|
41
36
|
}
|
|
42
|
-
function
|
|
43
|
-
const
|
|
44
|
-
if (!
|
|
45
|
-
const
|
|
46
|
-
|
|
37
|
+
function g(t) {
|
|
38
|
+
const e = i.get(t);
|
|
39
|
+
if (!e || e.paused) return;
|
|
40
|
+
const r = Date.now() - e.startingTime, o = Math.max(e.totalTime - r, 0);
|
|
41
|
+
o !== 0 && (i.set(t, { ...e, remainningTime: o, paused: !0 }), clearTimeout(e.timeoutId));
|
|
47
42
|
}
|
|
48
|
-
function
|
|
49
|
-
if (
|
|
50
|
-
const
|
|
51
|
-
if (!
|
|
52
|
-
const
|
|
53
|
-
if (!
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
},
|
|
61
|
-
|
|
43
|
+
function p(t) {
|
|
44
|
+
if (m || !t) return;
|
|
45
|
+
const e = i.get(t);
|
|
46
|
+
if (!e || !e.paused) return;
|
|
47
|
+
const n = a(e.remainningTime);
|
|
48
|
+
if (!n) return;
|
|
49
|
+
const r = setTimeout(() => {
|
|
50
|
+
s({
|
|
51
|
+
action: "dismiss",
|
|
52
|
+
id: t,
|
|
53
|
+
toasterId: e.toasterId
|
|
54
|
+
}), i.delete(t);
|
|
55
|
+
}, n);
|
|
56
|
+
i.set(t, {
|
|
57
|
+
timeoutId: r,
|
|
62
58
|
startingTime: Date.now(),
|
|
63
|
-
totalTime:
|
|
59
|
+
totalTime: e.remainningTime,
|
|
64
60
|
remainningTime: 0,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
paused: !1
|
|
61
|
+
paused: !1,
|
|
62
|
+
toasterId: e.toasterId
|
|
68
63
|
});
|
|
69
64
|
}
|
|
70
65
|
export {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
v as resumeToast
|
|
66
|
+
T as LEAVE_DELAY,
|
|
67
|
+
u as MIN_VISIBLE,
|
|
68
|
+
I as addTimers,
|
|
69
|
+
l as clearAllTimers,
|
|
70
|
+
c as clearTimer,
|
|
71
|
+
g as pauseToast,
|
|
72
|
+
p as resumeToast
|
|
79
73
|
};
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { clearTimer as
|
|
2
|
-
function
|
|
3
|
-
|
|
4
|
-
(
|
|
1
|
+
import { clearTimer as u, addTimers as t } from "./timers.js";
|
|
2
|
+
function r({ toast: d, setToasts: a }) {
|
|
3
|
+
a((e) => e.find((i) => i.id === d.id) ? (u(d.id), t(d), e.map(
|
|
4
|
+
(i) => i.id === d.id ? {
|
|
5
|
+
...i,
|
|
6
|
+
...d,
|
|
7
|
+
status: "visible",
|
|
8
|
+
updateState: i.updateState?.includes("again") ? "updated" : "updated-again"
|
|
9
|
+
} : i
|
|
5
10
|
)) : e);
|
|
6
11
|
}
|
|
7
12
|
export {
|
|
8
|
-
|
|
13
|
+
r as default
|
|
9
14
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createToast as a, updateToast as s, genId as c } from "./createToast.js";
|
|
2
|
-
import { notify as
|
|
3
|
-
const
|
|
4
|
-
r != null &&
|
|
2
|
+
import { notify as i } from "./listenars.js";
|
|
3
|
+
const e = (r, t) => {
|
|
4
|
+
r != null && i(
|
|
5
5
|
a({
|
|
6
6
|
type: "default",
|
|
7
7
|
action: "add",
|
|
@@ -10,11 +10,11 @@ const i = (r, t) => {
|
|
|
10
10
|
})
|
|
11
11
|
);
|
|
12
12
|
};
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
e.dismiss = (r, t) => {
|
|
14
|
+
i({ action: "dismiss", id: r, toasterId: `${t}` });
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
r != null &&
|
|
16
|
+
e.info = (r, t) => {
|
|
17
|
+
r != null && i(
|
|
18
18
|
a({
|
|
19
19
|
action: "add",
|
|
20
20
|
type: "info",
|
|
@@ -23,8 +23,8 @@ i.info = (r, t) => {
|
|
|
23
23
|
})
|
|
24
24
|
);
|
|
25
25
|
};
|
|
26
|
-
|
|
27
|
-
r != null &&
|
|
26
|
+
e.success = (r, t) => {
|
|
27
|
+
r != null && i(
|
|
28
28
|
a({
|
|
29
29
|
action: "add",
|
|
30
30
|
type: "success",
|
|
@@ -33,8 +33,8 @@ i.success = (r, t) => {
|
|
|
33
33
|
})
|
|
34
34
|
);
|
|
35
35
|
};
|
|
36
|
-
|
|
37
|
-
r != null &&
|
|
36
|
+
e.warning = (r, t) => {
|
|
37
|
+
r != null && i(
|
|
38
38
|
a({
|
|
39
39
|
action: "add",
|
|
40
40
|
type: "warning",
|
|
@@ -43,8 +43,8 @@ i.warning = (r, t) => {
|
|
|
43
43
|
})
|
|
44
44
|
);
|
|
45
45
|
};
|
|
46
|
-
|
|
47
|
-
r != null &&
|
|
46
|
+
e.error = (r, t) => {
|
|
47
|
+
r != null && i(
|
|
48
48
|
a({
|
|
49
49
|
action: "add",
|
|
50
50
|
type: "error",
|
|
@@ -53,8 +53,8 @@ i.error = (r, t) => {
|
|
|
53
53
|
})
|
|
54
54
|
);
|
|
55
55
|
};
|
|
56
|
-
|
|
57
|
-
r != null &&
|
|
56
|
+
e.loading = (r, t) => {
|
|
57
|
+
r != null && i(
|
|
58
58
|
a({
|
|
59
59
|
action: "add",
|
|
60
60
|
type: "loading",
|
|
@@ -63,8 +63,8 @@ i.loading = (r, t) => {
|
|
|
63
63
|
})
|
|
64
64
|
);
|
|
65
65
|
};
|
|
66
|
-
|
|
67
|
-
r != null &&
|
|
66
|
+
e.custom = (r, t) => {
|
|
67
|
+
r != null && i(
|
|
68
68
|
a({
|
|
69
69
|
action: "add",
|
|
70
70
|
type: "custom",
|
|
@@ -73,28 +73,27 @@ i.custom = (r, t) => {
|
|
|
73
73
|
})
|
|
74
74
|
);
|
|
75
75
|
};
|
|
76
|
-
|
|
77
|
-
t != null &&
|
|
76
|
+
e.update = (r, t, n) => {
|
|
77
|
+
r != null && t != null && i(s({ id: `${r}`, content: t, options: n }));
|
|
78
78
|
};
|
|
79
|
-
|
|
79
|
+
e.promise = (async (r, t, n) => {
|
|
80
80
|
const u = c();
|
|
81
|
-
|
|
81
|
+
i(
|
|
82
82
|
a({
|
|
83
83
|
action: "add",
|
|
84
84
|
type: "loading",
|
|
85
85
|
content: t.loading,
|
|
86
|
-
|
|
87
|
-
options: { ...n, id: u, duration: 1 / 0 }
|
|
86
|
+
options: { ...n, id: u, duration: 1 / 0, swipeToClose: !1 }
|
|
88
87
|
})
|
|
89
88
|
);
|
|
90
89
|
try {
|
|
91
90
|
const o = await r, d = typeof t.success == "function" ? await t.success(o) : t.success;
|
|
92
|
-
return
|
|
91
|
+
return e.update(u, d, { ...n, type: "success" }), o;
|
|
93
92
|
} catch (o) {
|
|
94
93
|
const d = typeof t.error == "function" ? await t.error(o) : t.error;
|
|
95
|
-
throw
|
|
94
|
+
throw e.update(u, d, { ...n, type: "error" }), o;
|
|
96
95
|
}
|
|
97
96
|
});
|
|
98
97
|
export {
|
|
99
|
-
|
|
98
|
+
e as default
|
|
100
99
|
};
|
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
import { jsxs as x, jsx as t, Fragment as
|
|
2
|
-
import { resumeToast as
|
|
1
|
+
import { jsxs as x, jsx as t, Fragment as s } from "react/jsx-runtime";
|
|
2
|
+
import { resumeToast as p, pauseToast as u } from "../helpers/manageToasts/timers.js";
|
|
3
3
|
import S from "../helpers/triggerToasts.js";
|
|
4
|
-
import { InfoSvg as w, ErrorSvg as
|
|
5
|
-
import { useToasterContext as
|
|
6
|
-
function
|
|
7
|
-
t:
|
|
4
|
+
import { InfoSvg as w, ErrorSvg as I, WarningSvg as E, SuccessSvg as k, LoadingSvg as L } from "./Svgs.js";
|
|
5
|
+
import { useToasterContext as M } from "../context/ToasterContext.js";
|
|
6
|
+
function P({
|
|
7
|
+
t: d,
|
|
8
8
|
position: n,
|
|
9
9
|
shouldAnimateTransformOrigin: c,
|
|
10
|
-
swipeToClose:
|
|
10
|
+
swipeToClose: m
|
|
11
11
|
}) {
|
|
12
|
-
const {
|
|
13
|
-
|
|
12
|
+
const { pauseOnHover: o } = M(), {
|
|
13
|
+
id: e,
|
|
14
|
+
type: r,
|
|
15
|
+
action: f,
|
|
16
|
+
content: i,
|
|
17
|
+
status: g,
|
|
18
|
+
showIcon: v,
|
|
19
|
+
icon: a,
|
|
20
|
+
toasterId: h,
|
|
21
|
+
updateState: y
|
|
22
|
+
} = d, l = {
|
|
23
|
+
loading: /* @__PURE__ */ t(L, {}),
|
|
14
24
|
success: /* @__PURE__ */ t(k, {}),
|
|
15
|
-
warning: /* @__PURE__ */ t(
|
|
16
|
-
error: /* @__PURE__ */ t(
|
|
25
|
+
warning: /* @__PURE__ */ t(E, {}),
|
|
26
|
+
error: /* @__PURE__ */ t(I, {}),
|
|
17
27
|
info: /* @__PURE__ */ t(w, {}),
|
|
18
28
|
default: null,
|
|
19
29
|
custom: null
|
|
@@ -29,23 +39,24 @@ function C({
|
|
|
29
39
|
gap: 8,
|
|
30
40
|
whiteSpace: "pre-wrap"
|
|
31
41
|
},
|
|
32
|
-
"data-
|
|
33
|
-
"data-
|
|
42
|
+
"data-toaster-id": h,
|
|
43
|
+
"data-action": f,
|
|
44
|
+
"data-status": g,
|
|
34
45
|
"data-type": r,
|
|
35
46
|
"data-position": n,
|
|
36
47
|
"data-screen-x": n.split("-")[1],
|
|
37
48
|
"data-screen-y": n.split("-")[0],
|
|
38
49
|
"data-exit": "auto",
|
|
39
|
-
"data-
|
|
40
|
-
"data-swipeable": u,
|
|
50
|
+
"data-swipeable": m,
|
|
41
51
|
"data-animate-transform-origin": c,
|
|
52
|
+
"data-update-state": y,
|
|
53
|
+
onPointerEnter: () => o && u(e),
|
|
54
|
+
onPointerLeave: () => o && p(e),
|
|
55
|
+
onMouseEnter: () => o && u(e),
|
|
56
|
+
onMouseLeave: () => o && p(e),
|
|
42
57
|
className: `kitzo-toast ${c ? `transform-origin-${n}` : ""}`,
|
|
43
|
-
onPointerEnter: () => s && p(e),
|
|
44
|
-
onPointerLeave: () => s && m(e, l),
|
|
45
|
-
onMouseEnter: () => s && p(e),
|
|
46
|
-
onMouseLeave: () => s && m(e, l),
|
|
47
58
|
children: [
|
|
48
|
-
|
|
59
|
+
v && /* @__PURE__ */ t(s, { children: a ? /* @__PURE__ */ t(s, { children: typeof a == "string" || typeof a == "number" ? /* @__PURE__ */ t(
|
|
49
60
|
"div",
|
|
50
61
|
{
|
|
51
62
|
style: {
|
|
@@ -54,14 +65,14 @@ function C({
|
|
|
54
65
|
className: "svg-container",
|
|
55
66
|
children: a
|
|
56
67
|
}
|
|
57
|
-
) : /* @__PURE__ */ t(
|
|
68
|
+
) : /* @__PURE__ */ t(s, { children: a }) }) : /* @__PURE__ */ t(s, { children: l[r] && /* @__PURE__ */ t("div", { style: { flexShrink: 0 }, className: "svg-container", children: l[r] }) }) }),
|
|
58
69
|
/* @__PURE__ */ t(
|
|
59
70
|
"div",
|
|
60
71
|
{
|
|
61
72
|
style: {
|
|
62
73
|
flex: 1
|
|
63
74
|
},
|
|
64
|
-
children: typeof i == "function" ? i(() => S.dismiss(e)) : i
|
|
75
|
+
children: typeof i == "function" ? i(() => S.dismiss(e, d.toasterId)) : i
|
|
65
76
|
}
|
|
66
77
|
)
|
|
67
78
|
]
|
|
@@ -69,5 +80,5 @@ function C({
|
|
|
69
80
|
);
|
|
70
81
|
}
|
|
71
82
|
export {
|
|
72
|
-
|
|
83
|
+
P as default
|
|
73
84
|
};
|
package/package.json
CHANGED