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 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' | 'swipeToClose'>;
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/listenar.js";
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 I(d) {
8
+ function D(i) {
9
9
  const {
10
10
  position: h = "top-center",
11
- richColors: p = !1,
11
+ richColors: l = !1,
12
12
  animateTransformOrigin: g = !0,
13
13
  gap: s = 8,
14
- edgeOffset: i = 16,
15
- isDark: n,
14
+ edgeOffset: n = 16,
15
+ isDark: c,
16
16
  pauseOnHover: b = !0,
17
17
  swipeToClose: y = !0
18
- } = d, [k, T] = t.useState(!1);
18
+ } = i, [k, T] = t.useState(!1);
19
19
  t.useEffect(() => {
20
20
  T(!0);
21
21
  }, []);
22
- const [u, l] = t.useState([]);
22
+ const [p, m] = t.useState([]);
23
23
  t.useEffect(() => {
24
- const e = E((o) => w({ toast: o, setToasts: l })), r = S();
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 c = t.useRef(null), f = t.useCallback(() => {
30
- if (!c.current) return;
31
- const e = c.current.querySelectorAll("[data-toast-container]"), r = {
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 m = o.getAttribute("data-toast-position") || "top-center", x = parseFloat(o.style.getPropertyValue("--toast-height")) || 0;
41
- o.style.setProperty("--toast-offset-y", `${r[m]}px`);
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[m] += x + C;
46
+ r[d] += x + C;
44
47
  });
45
48
  }, [s]);
46
49
  if (t.useLayoutEffect(() => {
47
- f();
48
- }, [u, f]), !k) return null;
49
- const v = typeof n == "boolean" ? n : window.matchMedia("(prefers-color-scheme: dark)").matches;
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: c,
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: i != null ? `${Math.max(Math.min(+i, 200), 0)}px` : 16
63
+ padding: n != null ? `${Math.max(Math.min(+n, 200), 0)}px` : 16
61
64
  },
62
- className: `kitzo-toaster ${p ? "kitzo-toaster-rich-colors" : ""} ${v ? "kitzo-toaster-dark" : ""}`,
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: p,
75
- isDark: n,
77
+ richColors: l,
78
+ isDark: c,
76
79
  gap: s,
77
- edgeOffset: i,
80
+ edgeOffset: n,
78
81
  animateTransformOrigin: g,
79
82
  pauseOnHover: b,
80
83
  swipeToClose: y,
81
- setToasts: l,
82
- updateOffsets: f
84
+ setToasts: m,
85
+ updateOffsets: u
83
86
  },
84
- children: u.map((e) => /* @__PURE__ */ a(M, { t: e }, e.id))
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
- I as default
96
+ D as default
94
97
  };
@@ -1,4 +1,4 @@
1
- const o = `.kitzo-toaster {
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-action='update'] {
186
- animation: update 150ms ease;
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.95);
192
- opacity: 0.5;
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 a() {
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 = o, document.head.appendChild(t);
290
+ t.id = "kitzo-toast-styles", t.textContent = a, document.head.appendChild(t);
278
291
  }
279
292
  }
280
293
  export {
281
- a as default
294
+ o as default
282
295
  };
@@ -1,49 +1,50 @@
1
- const n = {
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 r = 0;
8
- const d = () => crypto.randomUUID?.() ?? ++r;
8
+ let s = 0;
9
+ const d = () => crypto.randomUUID?.() ?? ++s;
9
10
  let u = 1;
10
- function T({
11
- type: e,
12
- action: s,
13
- content: t,
14
- isPromise: i,
15
- options: a
11
+ function p({
12
+ type: a,
13
+ action: i,
14
+ content: n,
15
+ options: o
16
16
  }) {
17
- const o = typeof a == "object" && a !== null ? a : {};
17
+ const t = typeof o == "object" && o !== null ? o : {};
18
18
  return {
19
- id: `toast-id:${o.id ?? d()}`,
20
- duration: o.duration ?? n.duration,
21
- showIcon: o.showIcon ?? n.showIcon,
22
- animateTransformOrigin: o.animateTransformOrigin ?? n.animateTransformOrigin,
23
- position: o.position,
24
- icon: o.icon,
25
- type: e === "default" ? o.type ?? "default" : e,
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: t,
29
- action: s,
30
- isPromise: !!i,
31
- swipeToClose: o.swipeToClose ?? n.swipeToClose
29
+ content: n,
30
+ action: i,
31
+ swipeToClose: t.swipeToClose ?? e.swipeToClose,
32
+ updateState: "initial"
32
33
  };
33
34
  }
34
- function l({ id: e, content: s, options: t }) {
35
- const i = typeof t == "object" && t !== null ? t : {};
35
+ function l({ id: a, content: i, options: n }) {
36
+ const o = typeof n == "object" && n !== null ? n : {};
36
37
  return {
37
- ...i,
38
- id: `toast-id:${e}`,
39
- content: s,
38
+ ...o,
39
+ id: a,
40
+ content: i,
40
41
  action: "update",
41
- isPromise: !1,
42
- duration: i.duration ?? n.duration
42
+ duration: o.duration ?? e.duration,
43
+ toasterId: `${o.toasterId ?? r}`
43
44
  };
44
45
  }
45
46
  export {
46
- T as createToast,
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 s } from "./timers.js";
2
- function e({ toast: d, setToasts: r }) {
3
- r((i) => i.find((m) => m.id === d.id) ? i : [d, ...i]), requestAnimationFrame(() => {
4
- r(
5
- (i) => i.map((n) => n.id === d.id ? { ...n, status: "visible" } : n)
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
- }), s(d, r);
7
+ }), e(d);
8
8
  }
9
9
  export {
10
- e as default
10
+ u as default
11
11
  };
@@ -1,21 +1,19 @@
1
- import { LEAVE_DELAY as u, clearAllTimers as a, clearTimer as n } from "./timers.js";
2
- function s({ toast: l, setToasts: d }) {
3
- if (l.id == null) {
4
- d((e) => e.map((i) => ({ ...i, status: "leaving" }))), setTimeout(() => {
5
- d((e) => e.filter((i) => i.status !== "leaving"));
6
- }, u), a();
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
- const r = l.id.includes("toast-id:") ? l.id : `toast-id:${l.id}`;
11
- d(
12
- (e) => e.map((i) => i.id === r ? { ...i, status: "leaving" } : i)
13
- ), setTimeout(() => {
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
- }, u);
15
+ }, r);
18
16
  }
19
17
  export {
20
- s as default
18
+ a as default
21
19
  };
@@ -1,26 +1,24 @@
1
1
  import b from "../triggerToasts.js";
2
- let s = !1, t = null, c = null, w = 0, r = 0, a = !1, l = null;
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 P(e) {
5
- const o = Math.sign(e) || 1, n = Math.abs(e), h = S * (1 - Math.exp(-n / g));
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(e) {
9
- if (!e) return !1;
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(e = !0) {
14
- if (!t) return;
15
- if (document.body.style.userSelect = "auto", e && l != null)
11
+ function i(t = !0) {
12
+ if (!e) return;
13
+ if (document.body.style.userSelect = "auto", t && l != null)
16
14
  try {
17
- t.releasePointerCapture(l);
15
+ e.releasePointerCapture(l);
18
16
  } catch {
19
17
  console.error("");
20
18
  }
21
- t.style.setProperty("--swipe-x", "0px"), t.classList.remove("is-swiping");
22
- const o = t;
23
- if (t = null, c = null, l = null, a = !1, s = !1, r = 0, !o.matches(":hover")) {
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(e) {
33
- const n = e.target.closest(".kitzo-toast");
34
- n && (t = n, c = n.id, w = e.clientX, r = 0, a = !0, s = !1, l = e.pointerId);
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(e) {
37
- if (!a || !t) return;
38
- if (r = e.clientX - w, !s && Math.abs(r) > L) {
39
- s = !0, t.classList.add("is-swiping");
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
- t.setPointerCapture(e.pointerId), document.body.style.userSelect = "none";
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(t) ? r : P(r);
48
- t.style.setProperty("--swipe-x", `${n}px`);
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 || !t || c == null) {
49
+ if (!a || !e || c == null) {
52
50
  i();
53
51
  return;
54
52
  }
55
- const e = E(t);
56
- if (s && e && Math.abs(r) > y) {
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
- t.style.setProperty("--exit-x", `${o * n}px`), t.dataset.exit = "swipe", b.dismiss(c);
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 m() {
63
+ function w() {
66
64
  a && i();
67
65
  }
68
66
  let u = !1;
69
- function M() {
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", m), () => {
72
- i(), u = !1, document.removeEventListener("pointerdown", d), document.removeEventListener("pointermove", p), document.removeEventListener("pointerup", f), document.removeEventListener("pointercancel", v), window.removeEventListener("blur", m);
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
- M as initSwipeToClose
75
+ P as initSwipeToClose
78
76
  };
@@ -1,79 +1,73 @@
1
- import { dragStarted as c } from "./swipeClose.js";
2
- const r = /* @__PURE__ */ new Map(), m = 280, f = 500, d = 0;
3
- function T(e) {
4
- const t = Number(e);
5
- if (!isFinite(t)) return null;
6
- const i = Math.max(d, t);
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 s(e) {
14
- const t = r.get(e);
15
- t && (clearTimeout(t.leavingTimeoutId), clearTimeout(t.leftTimeoutId), r.delete(e));
8
+ function c(t) {
9
+ const e = i.get(t);
10
+ e && (clearTimeout(e.timeoutId), i.delete(t));
16
11
  }
17
- function I() {
18
- r.forEach(({ leavingTimeoutId: e, leftTimeoutId: t }) => {
19
- clearTimeout(e), clearTimeout(t);
20
- }), r.clear();
12
+ function l() {
13
+ i.forEach(({ timeoutId: t }) => {
14
+ clearTimeout(t);
15
+ }), i.clear();
21
16
  }
22
- function p(e, t) {
23
- const i = T(e.duration);
24
- if (!i) return;
25
- s(e.id);
26
- const o = setTimeout(() => {
27
- t(
28
- (a) => a.map((n) => n.id === e.id ? { ...n, status: "leaving" } : n)
29
- );
30
- }, i.leavingDuration + m), u = setTimeout(() => {
31
- t((a) => a.filter((n) => n.id !== e.id)), s(e.id), r.delete(e.id);
32
- }, i.leftDuration + m), l = Date.now();
33
- r.set(e.id, {
34
- leavingTimeoutId: o,
35
- leftTimeoutId: u,
36
- startingTime: l,
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 D(e) {
43
- const t = r.get(e);
44
- if (!t || t.paused) return;
45
- const o = Date.now() - t.startingTime, u = Math.max(t.totalTime - o, 0);
46
- u !== 0 && (r.set(e, { ...t, remainningTime: u, paused: !0 }), clearTimeout(t.leavingTimeoutId), clearTimeout(t.leftTimeoutId));
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 v(e, t) {
49
- if (c) return;
50
- const i = r.get(e);
51
- if (!i || !i.paused) return;
52
- const o = T(i.remainningTime);
53
- if (!o) return;
54
- const u = setTimeout(() => {
55
- t(
56
- (a) => a.map((n) => n.id === e ? { ...n, status: "leaving" } : n)
57
- );
58
- }, o.leavingDuration + m), l = setTimeout(() => {
59
- t((a) => a.filter((n) => n.id !== e)), s(e), r.delete(e);
60
- }, o.leftDuration + m);
61
- r.set(e, {
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: i.remainningTime,
59
+ totalTime: e.remainningTime,
64
60
  remainningTime: 0,
65
- leavingTimeoutId: u,
66
- leftTimeoutId: l,
67
- paused: !1
61
+ paused: !1,
62
+ toasterId: e.toasterId
68
63
  });
69
64
  }
70
65
  export {
71
- f as LEAVE_DELAY,
72
- d as MIN_VISIBLE,
73
- m as TRANSITION_DURATION,
74
- p as addTimers,
75
- I as clearAllTimers,
76
- s as clearTimer,
77
- D as pauseToast,
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 n, addTimers as u } from "./timers.js";
2
- function s({ toast: i, setToasts: r }) {
3
- r((e) => e.find((d) => d.id === i.id) ? (n(i.id), u(i, r), e.map(
4
- (d) => d.id === i.id ? { ...d, ...i, status: "visible" } : d
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
- s as default
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 e } from "./listenar.js";
3
- const i = (r, t) => {
4
- r != null && e(
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
- i.dismiss = (r) => {
14
- e({ action: "dismiss", id: r });
13
+ e.dismiss = (r, t) => {
14
+ i({ action: "dismiss", id: r, toasterId: `${t}` });
15
15
  };
16
- i.info = (r, t) => {
17
- r != null && e(
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
- i.success = (r, t) => {
27
- r != null && e(
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
- i.warning = (r, t) => {
37
- r != null && e(
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
- i.error = (r, t) => {
47
- r != null && e(
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
- i.loading = (r, t) => {
57
- r != null && e(
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
- i.custom = (r, t) => {
67
- r != null && e(
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
- i.update = (r, t, n) => {
77
- t != null && e(s({ id: `${r}`, content: t, options: n }));
76
+ e.update = (r, t, n) => {
77
+ r != null && t != null && i(s({ id: `${r}`, content: t, options: n }));
78
78
  };
79
- i.promise = (async (r, t, n) => {
79
+ e.promise = (async (r, t, n) => {
80
80
  const u = c();
81
- e(
81
+ i(
82
82
  a({
83
83
  action: "add",
84
84
  type: "loading",
85
85
  content: t.loading,
86
- isPromise: !0,
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 i.update(u, d, { ...n, type: "success" }), o;
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 i.update(u, d, { ...n, type: "error" }), o;
94
+ throw e.update(u, d, { ...n, type: "error" }), o;
96
95
  }
97
96
  });
98
97
  export {
99
- i as default
98
+ e as default
100
99
  };
@@ -1,19 +1,29 @@
1
- import { jsxs as x, jsx as t, Fragment as o } from "react/jsx-runtime";
2
- import { resumeToast as m, pauseToast as p } from "../helpers/manageToasts/timers.js";
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 E, WarningSvg as T, SuccessSvg as k, LoadingSvg as I } from "./Svgs.js";
5
- import { useToasterContext as L } from "../context/ToasterContext.js";
6
- function C({
7
- t: f,
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: u
10
+ swipeToClose: m
11
11
  }) {
12
- const { setToasts: l, pauseOnHover: s } = L(), { id: e, type: r, action: g, content: i, status: v, showIcon: h, icon: a, isPromise: y } = f, d = {
13
- loading: /* @__PURE__ */ t(I, {}),
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(T, {}),
16
- error: /* @__PURE__ */ t(E, {}),
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-action": g,
33
- "data-status": v,
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-is-promise": y,
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
- h && /* @__PURE__ */ t(o, { children: a ? /* @__PURE__ */ t(o, { children: typeof a == "string" || typeof a == "number" ? /* @__PURE__ */ t(
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(o, { children: a }) }) : /* @__PURE__ */ t(o, { children: d[r] && /* @__PURE__ */ t("div", { style: { flexShrink: 0 }, className: "svg-container", children: d[r] }) }) }),
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
- C as default
83
+ P as default
73
84
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kitzo",
3
- "version": "2.3.42",
3
+ "version": "2.3.44",
4
4
  "description": "A lightweight React micro-utility.",
5
5
  "type": "module",
6
6
  "files": [
@@ -1,14 +0,0 @@
1
- import n from "./addToastStyles.js";
2
- const e = /* @__PURE__ */ new Set();
3
- function s(t) {
4
- return n(), e.add(t), () => {
5
- e.delete(t);
6
- };
7
- }
8
- function i(t) {
9
- e.forEach((o) => o(t));
10
- }
11
- export {
12
- i as notify,
13
- s as subscribe
14
- };