vue-sonner
Advanced tools
Comparing version 0.2.0 to 0.2.1
var me = Object.defineProperty; | ||
var pe = (t, e, s) => e in t ? me(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s; | ||
var b = (t, e, s) => (pe(t, typeof e != "symbol" ? e + "" : e, s), s); | ||
import { defineComponent as j, openBlock as l, createElementBlock as f, createElementVNode as B, Fragment as L, renderList as ne, unref as r, ref as c, computed as p, onMounted as Z, watchEffect as _, onUnmounted as ae, normalizeClass as oe, normalizeStyle as ee, createVNode as he, createCommentVNode as T, createBlock as F, createTextVNode as ie, toDisplayString as U, resolveDynamicComponent as ye, useAttrs as ge } from "vue"; | ||
let R = 0; | ||
import { defineComponent as j, openBlock as l, createElementBlock as f, createElementVNode as B, Fragment as L, renderList as ne, unref as r, ref as c, computed as p, onMounted as Z, watchEffect as R, onUnmounted as ae, normalizeClass as oe, normalizeStyle as ee, createVNode as he, createCommentVNode as w, createBlock as F, createTextVNode as ie, toDisplayString as U, resolveDynamicComponent as ye, useAttrs as ge } from "vue"; | ||
let H = 0; | ||
class be { | ||
@@ -23,19 +23,19 @@ constructor() { | ||
b(this, "message", (e, s) => { | ||
const i = (s == null ? void 0 : s.id) || R++; | ||
const i = (s == null ? void 0 : s.id) || H++; | ||
return this.publish({ ...s, id: i, title: e }), i; | ||
}); | ||
b(this, "error", (e, s) => { | ||
const i = (s == null ? void 0 : s.id) || R++; | ||
const i = (s == null ? void 0 : s.id) || H++; | ||
return this.publish({ ...s, id: i, type: "error", title: e }), i; | ||
}); | ||
b(this, "success", (e, s) => { | ||
const i = (s == null ? void 0 : s.id) || R++; | ||
const i = (s == null ? void 0 : s.id) || H++; | ||
return this.publish({ ...s, id: i, type: "success", title: e }), i; | ||
}); | ||
b(this, "promise", (e, s) => { | ||
const i = (s == null ? void 0 : s.id) || R++; | ||
const i = (s == null ? void 0 : s.id) || H++; | ||
return this.publish({ ...s, promise: e, id: i }), i; | ||
}); | ||
b(this, "custom", (e, s) => { | ||
const i = (s == null ? void 0 : s.id) || R++; | ||
const i = (s == null ? void 0 : s.id) || H++; | ||
this.publish({ ...s, id: i, title: e }); | ||
@@ -47,3 +47,3 @@ }); | ||
const N = new be(), xe = (t, e) => { | ||
const s = (e == null ? void 0 : e.id) || R++; | ||
const s = (e == null ? void 0 : e.id) || H++; | ||
return N.publish({ | ||
@@ -54,3 +54,3 @@ title: t, | ||
}), s; | ||
}, we = xe, it = Object.assign(we, { | ||
}, Te = xe, it = Object.assign(Te, { | ||
success: N.success, | ||
@@ -62,4 +62,3 @@ error: N.error, | ||
dismiss: N.dismiss | ||
}); | ||
const Te = ["data-visible"], ke = { className: "sonner-spinner" }, Be = /* @__PURE__ */ j({ | ||
}), we = ["data-visible"], ke = { className: "sonner-spinner" }, Be = /* @__PURE__ */ j({ | ||
__name: "Loader", | ||
@@ -81,3 +80,3 @@ props: { | ||
]) | ||
], 8, Te)); | ||
], 8, we)); | ||
} | ||
@@ -105,3 +104,3 @@ }), A = (t, e) => { | ||
} | ||
const Pe = /* @__PURE__ */ A(Ce, [["render", Ee], ["__file", "/Users/xiaoyunwei/Documents/GitHub/private/vue-sonner/packages/assets/SuccessIcon.vue"]]), Se = {}, qe = { | ||
const _e = /* @__PURE__ */ A(Ce, [["render", Ee], ["__file", "/Users/xiaoyunwei/Documents/GitHub/private/vue-sonner/packages/assets/SuccessIcon.vue"]]), Pe = {}, Se = { | ||
xmlns: "http://www.w3.org/2000/svg", | ||
@@ -112,13 +111,13 @@ viewBox: "0 0 20 20", | ||
width: "20" | ||
}, Oe = /* @__PURE__ */ B("path", { | ||
}, qe = /* @__PURE__ */ B("path", { | ||
"fill-rule": "evenodd", | ||
d: "M18 10a8 8 0 11-16 0 8 8 0 0116 0zm-8-5a.75.75 0 01.75.75v4.5a.75.75 0 01-1.5 0v-4.5A.75.75 0 0110 5zm0 10a1 1 0 100-2 1 1 0 000 2z", | ||
"clip-rule": "evenodd" | ||
}, null, -1), He = [ | ||
Oe | ||
}, null, -1), Oe = [ | ||
qe | ||
]; | ||
function Re(t, e) { | ||
return l(), f("svg", qe, He); | ||
function He(t, e) { | ||
return l(), f("svg", Se, Oe); | ||
} | ||
const _e = /* @__PURE__ */ A(Se, [["render", Re], ["__file", "/Users/xiaoyunwei/Documents/GitHub/private/vue-sonner/packages/assets/ErrorIcon.vue"]]), Ae = {}, Me = { | ||
const Re = /* @__PURE__ */ A(Pe, [["render", He], ["__file", "/Users/xiaoyunwei/Documents/GitHub/private/vue-sonner/packages/assets/ErrorIcon.vue"]]), Ae = {}, Me = { | ||
xmlns: "http://www.w3.org/2000/svg", | ||
@@ -218,3 +217,3 @@ width: "12", | ||
setup(t) { | ||
const e = t, s = 4e3, i = 14, D = 20, K = 200, m = (o) => Boolean(o.promise), I = c(!1), g = c(!1), $ = c(!1), P = c(!1), v = c(null), S = c(0), z = c(0), q = c(null), d = c(null), n = p(() => e.index === 0), h = p(() => e.index + 1 <= e.visibleToasts), x = p(() => e.toast.type), O = e.toast.className || "", E = e.toast.descriptionClassName || "", C = p( | ||
const e = t, s = 4e3, i = 14, D = 20, K = 200, m = (o) => Boolean(o.promise), I = c(!1), g = c(!1), $ = c(!1), _ = c(!1), v = c(null), P = c(0), z = c(0), S = c(null), d = c(null), n = p(() => e.index === 0), h = p(() => e.index + 1 <= e.visibleToasts), x = p(() => e.toast.type), q = e.toast.className || "", E = e.toast.descriptionClassName || "", C = p( | ||
() => e.heights.findIndex((o) => o.toastId === e.toast.id) || 0 | ||
@@ -235,5 +234,5 @@ ), G = p( | ||
case "success": | ||
return typeof e.toast.success == "function" ? q.value : e.toast.success; | ||
return typeof e.toast.success == "function" ? S.value : e.toast.success; | ||
case "error": | ||
return typeof e.toast.error == "function" ? q.value : e.toast.error; | ||
return typeof e.toast.error == "function" ? S.value : e.toast.error; | ||
default: | ||
@@ -243,5 +242,5 @@ return null; | ||
}); | ||
Z(() => I.value = !0), _(() => { | ||
Z(() => I.value = !0), R(() => { | ||
M.value = C.value * i + re.value; | ||
}), _(() => { | ||
}), R(() => { | ||
var o, a; | ||
@@ -251,10 +250,10 @@ if (e.toast && m(e.toast)) { | ||
v.value = "loading"; | ||
const w = (y) => { | ||
const T = (y) => { | ||
y.then((k) => { | ||
u.success && typeof u.success == "function" && (q.value = u.success(k)), v.value = "success"; | ||
u.success && typeof u.success == "function" && (S.value = u.success(k)), v.value = "success"; | ||
}).catch((k) => { | ||
u.error && typeof u.error == "function" && (q.value = u.error(k)), v.value = "error"; | ||
u.error && typeof u.error == "function" && (S.value = u.error(k)), v.value = "error"; | ||
}); | ||
}; | ||
e.toast.promise instanceof Promise ? w(e.toast.promise) : typeof e.toast.promise == "function" && w((a = (o = e.toast) == null ? void 0 : o.promise) == null ? void 0 : a.call(o)); | ||
e.toast.promise instanceof Promise ? T(e.toast.promise) : typeof e.toast.promise == "function" && T((a = (o = e.toast) == null ? void 0 : o.promise) == null ? void 0 : a.call(o)); | ||
} | ||
@@ -264,6 +263,6 @@ }); | ||
var o, a; | ||
Q.value || (H(), (a = (o = e.toast).onDismiss) == null || a.call(o, e.toast)); | ||
Q.value || (O(), (a = (o = e.toast).onDismiss) == null || a.call(o, e.toast)); | ||
} | ||
function H() { | ||
g.value = !0, S.value = M.value, e.setHeights( | ||
function O() { | ||
g.value = !0, P.value = M.value, e.setHeights( | ||
e.heights.filter((o) => o.toastId !== e.toast.id) | ||
@@ -275,6 +274,6 @@ ), setTimeout(() => { | ||
const de = (o) => { | ||
Q || (S.value = M.value, o.target.setPointerCapture(o.pointerId), o.target.tagName !== "BUTTON" && ($.value = !0, V.value = o.clientY)); | ||
Q || (P.value = M.value, o.target.setPointerCapture(o.pointerId), o.target.tagName !== "BUTTON" && ($.value = !0, V.value = o.clientY)); | ||
}, ve = (o) => { | ||
var u, w, y, k; | ||
if (P.value) | ||
var u, T, y, k; | ||
if (_.value) | ||
return; | ||
@@ -285,3 +284,3 @@ const a = Number( | ||
if (Math.abs(a) >= D) { | ||
S.value = M.value, (y = (w = e.toast).onDismiss) == null || y.call(w, e.toast), H(), P.value = !0; | ||
P.value = M.value, (y = (T = e.toast).onDismiss) == null || y.call(T, e.toast), O(), _.value = !0; | ||
return; | ||
@@ -291,3 +290,3 @@ } | ||
}, fe = (o) => { | ||
var w, y; | ||
var T, y; | ||
if (!V.value) | ||
@@ -297,3 +296,3 @@ return; | ||
if (!(J.value[0] === "top" ? a < 0 : a > 0)) { | ||
(w = d.value) == null || w.style.setProperty("--swipe-amount", "0px"); | ||
(T = d.value) == null || T.style.setProperty("--swipe-amount", "0px"); | ||
return; | ||
@@ -303,3 +302,3 @@ } | ||
}; | ||
return _((o) => { | ||
return R((o) => { | ||
if (e.toast.promise && v.value === "loading" || e.toast.duration === 1 / 0) | ||
@@ -314,9 +313,9 @@ return; | ||
te.value = new Date().getTime(); | ||
}, w = () => { | ||
}, T = () => { | ||
W.value = new Date().getTime(), a = setTimeout(() => { | ||
var y, k; | ||
(k = (y = e.toast).onAutoClose) == null || k.call(y, e.toast), H(); | ||
(k = (y = e.toast).onAutoClose) == null || k.call(y, e.toast), O(); | ||
}, Y.value); | ||
}; | ||
e.expanded || e.interacting ? u() : w(), o(() => { | ||
e.expanded || e.interacting ? u() : T(), o(() => { | ||
clearTimeout(a); | ||
@@ -333,4 +332,4 @@ }); | ||
); | ||
}), _(() => { | ||
e.toast.delete && H(); | ||
}), R(() => { | ||
e.toast.delete && O(); | ||
}), (o, a) => (l(), f("li", { | ||
@@ -344,3 +343,3 @@ "aria-live": t.toast.important ? "assertive" : "polite", | ||
"data-sonner-toast": "", | ||
class: oe(r(O)), | ||
class: oe(r(q)), | ||
"data-styled": !r(X), | ||
@@ -358,3 +357,3 @@ "data-mounted": I.value, | ||
"data-invert": r(le), | ||
"data-swipe-out": P.value, | ||
"data-swipe-out": _.value, | ||
"data-expanded": Boolean(e.expanded || e.expandByDefault && I.value), | ||
@@ -365,3 +364,3 @@ style: ee({ | ||
"--z-index": t.toasts.length - e.index, | ||
"--offset": `${g.value ? S.value : M.value}px`, | ||
"--offset": `${g.value ? P.value : M.value}px`, | ||
"--initial-height": e.expandByDefault ? "auto" : `${z.value}px`, | ||
@@ -382,3 +381,3 @@ ...t.toast | ||
he(Ge) | ||
], 8, je)) : T("v-if", !0), | ||
], 8, je)) : w("v-if", !0), | ||
r(x) || t.toast.icon || t.toast.promise ? (l(), f("div", Ke, [ | ||
@@ -388,6 +387,6 @@ typeof t.toast.promise == "function" ? (l(), F($e, { | ||
visible: v.value === "loading" | ||
}, null, 8, ["visible"])) : T("v-if", !0), | ||
r(se) === "success" ? (l(), F(Pe, { key: 1 })) : T("v-if", !0), | ||
r(se) === "error" ? (l(), F(_e, { key: 2 })) : T("v-if", !0) | ||
])) : T("v-if", !0), | ||
}, null, 8, ["visible"])) : w("v-if", !0), | ||
r(se) === "success" ? (l(), F(_e, { key: 1 })) : w("v-if", !0), | ||
r(se) === "error" ? (l(), F(Re, { key: 2 })) : w("v-if", !0) | ||
])) : w("v-if", !0), | ||
B("div", We, [ | ||
@@ -399,3 +398,3 @@ B("div", Ye, [ | ||
ie(U(r(ue)), 1) | ||
], 64)) : r(X) ? (l(), F(ye(t.toast.title), { key: 2 })) : T("v-if", !0) | ||
], 64)) : r(X) ? (l(), F(ye(t.toast.title), { key: 2 })) : w("v-if", !0) | ||
]), | ||
@@ -406,3 +405,3 @@ t.toast.description ? (l(), f("div", { | ||
class: oe(t.descriptionClass + r(E)) | ||
}, U(t.toast.description), 3)) : T("v-if", !0) | ||
}, U(t.toast.description), 3)) : w("v-if", !0) | ||
]), | ||
@@ -415,5 +414,5 @@ t.toast.cancel ? (l(), f("button", { | ||
var u; | ||
H(), (u = t.toast.cancel) != null && u.onClick && t.toast.cancel.onClick(); | ||
O(), (u = t.toast.cancel) != null && u.onClick && t.toast.cancel.onClick(); | ||
}) | ||
}, U(t.toast.cancel.label), 1)) : T("v-if", !0), | ||
}, U(t.toast.cancel.label), 1)) : w("v-if", !0), | ||
t.toast.action ? (l(), f("button", { | ||
@@ -424,8 +423,9 @@ key: 3, | ||
var u; | ||
H(), (u = t.toast.action) == null || u.onClick(); | ||
O(), (u = t.toast.action) == null || u.onClick(); | ||
}) | ||
}, U(t.toast.action.label), 1)) : T("v-if", !0) | ||
}, U(t.toast.action.label), 1)) : w("v-if", !0) | ||
], 46, Ve)); | ||
} | ||
}), Qe = /* @__PURE__ */ A(Je, [["__file", "/Users/xiaoyunwei/Documents/GitHub/private/vue-sonner/packages/Toast.vue"]]), Xe = ["aria-label"], Ze = ["data-theme", "data-rich-colors", "data-y-position", "data-x-position"], et = j({ | ||
}); | ||
const Qe = /* @__PURE__ */ A(Je, [["__file", "/Users/xiaoyunwei/Documents/GitHub/private/vue-sonner/packages/Toast.vue"]]), Xe = ["aria-label"], Ze = ["data-theme", "data-rich-colors", "data-y-position", "data-x-position"], et = j({ | ||
inheritAttrs: !1 | ||
@@ -468,7 +468,7 @@ }), tt = /* @__PURE__ */ j({ | ||
setup(t) { | ||
const e = t, s = "32px", i = 356, D = 14, K = ge(), m = c([]), I = c([]), g = c(!1), $ = c(!1), P = p(() => e.position.split("-")), v = c(null), S = e.hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, ""); | ||
const e = t, s = "32px", i = 356, D = 14, K = ge(), m = c([]), I = c([]), g = c(!1), $ = c(!1), _ = p(() => e.position.split("-")), v = c(null), P = e.hotkey.join("+").replace(/Key/g, "").replace(/Digit/g, ""); | ||
function z(d) { | ||
I.value = d; | ||
} | ||
function q(d) { | ||
function S(d) { | ||
m.value = m.value.filter(({ id: n }) => n !== d.id); | ||
@@ -489,10 +489,10 @@ } | ||
}); | ||
}), _(() => { | ||
}), R(() => { | ||
m.value.length <= 1 && (g.value = !1); | ||
}), _((d) => { | ||
}), R((d) => { | ||
function n(h) { | ||
var O, E; | ||
var q, E; | ||
e.hotkey.every( | ||
(C) => h[C] || h.code === C | ||
) && (g.value = !0, (O = v.value) == null || O.focus()), h.code === "Escape" && (document.activeElement === v.value || ((E = v.value) == null ? void 0 : E.contains(document.activeElement))) && (g.value = !1); | ||
) && (g.value = !0, (q = v.value) == null || q.focus()), h.code === "Escape" && (document.activeElement === v.value || ((E = v.value) == null ? void 0 : E.contains(document.activeElement))) && (g.value = !1); | ||
} | ||
@@ -505,5 +505,5 @@ document.addEventListener("keydown", n), d(() => { | ||
return l(), f(L, null, [ | ||
T(" Remove item from normal navigation flow, only available via hotkey "), | ||
w(" Remove item from normal navigation flow, only available via hotkey "), | ||
B("section", { | ||
"aria-label": `Notifications ${r(S)}`, | ||
"aria-label": `Notifications ${r(P)}`, | ||
tabIndex: -1 | ||
@@ -518,4 +518,4 @@ }, [ | ||
"data-rich-colors": t.richColors, | ||
"data-y-position": r(P)[0], | ||
"data-x-position": r(P)[1], | ||
"data-y-position": r(_)[0], | ||
"data-x-position": r(_)[1], | ||
style: ee( | ||
@@ -538,7 +538,7 @@ { | ||
}, [ | ||
(l(!0), f(L, null, ne(m.value, (x, O) => { | ||
(l(!0), f(L, null, ne(m.value, (x, q) => { | ||
var E, C, G; | ||
return l(), F(Qe, { | ||
key: x.id, | ||
index: O, | ||
index: q, | ||
toast: x, | ||
@@ -554,3 +554,3 @@ duration: t.duration, | ||
style: ee((G = t.toastOptions) == null ? void 0 : G.style), | ||
removeToast: q, | ||
removeToast: S, | ||
toasts: m.value, | ||
@@ -557,0 +557,0 @@ heights: I.value, |
{ | ||
"name": "vue-sonner", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "author": "xiaoluoboding <xiaoluoboding@gmail.com>", |
Sorry, the diff of this file is not supported yet
53138