You're Invited: Meet the Socket team at BSidesSF and RSAC - April 27 - May 1.RSVP
Socket
Sign inDemoInstall
Socket

@steveyuowo/vue-hot-toast

Package Overview
Dependencies
Maintainers
0
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@steveyuowo/vue-hot-toast - npm Package Compare versions

Comparing version

to
1.3.0

dist/style.css

3

dist/core/store.d.ts

@@ -1,2 +0,2 @@

import { CreateToast, ToastType } from "./type";
import { CreateToast, ToastType, ToastPosition } from "./type";
export declare const globalState: {

@@ -10,2 +10,3 @@ notifications: {

icon?: string | undefined;
position?: ToastPosition | undefined;
}[];

@@ -12,0 +13,0 @@ };

export type ToastType = "success" | "loading" | "error";
export type ToastPosition = "top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right" | "middle-center";
export interface ToastProps {

@@ -27,2 +28,6 @@ /**

icon?: string;
/**
* Position of the toast on the screen.
*/
position?: ToastPosition;
}

@@ -43,2 +48,3 @@ export type Id = string;

error: string;
position?: ToastPosition;
}) => Promise<string>;

@@ -51,3 +57,4 @@ }

duration: number;
position: string;
};
//# sourceMappingURL=type.d.ts.map

@@ -1,6 +0,6 @@

import { Id } from "core/type";
export declare function toastLoading(message: string): string;
export declare function toastSuccess(message: string, id: Id): void;
export declare function toastError(e: string | Error, id: Id): void;
import { Id, ToastPosition } from "core/type";
export declare function toastLoading(message: string, position?: ToastPosition): string;
export declare function toastSuccess(message: string, id: Id, position?: ToastPosition): void;
export declare function toastError(e: string | Error, id: Id, position?: ToastPosition): void;
export default function toReadableErrorMessage(e: Error | string): any;
//# sourceMappingURL=helper.d.ts.map

@@ -1,12 +0,12 @@

import { defineComponent as x, ref as d, watchEffect as h, openBlock as n, createElementBlock as i, normalizeStyle as m, withModifiers as y, createElementVNode as u, createCommentVNode as v, toDisplayString as T, reactive as C, createBlock as f, Teleport as O, createVNode as k, Transition as V, withCtx as w, Fragment as H, renderList as b, unref as g } from "vue";
const E = ["onClick"], j = { class: "VueHotToast__icon" }, I = { key: 0 }, S = ["src"], B = {
import { defineComponent as x, ref as d, watchEffect as y, openBlock as i, createElementBlock as c, normalizeStyle as h, withModifiers as m, createElementVNode as u, createCommentVNode as v, toDisplayString as T, reactive as C, computed as O, createBlock as f, Teleport as k, createVNode as V, Transition as w, withCtx as H, normalizeClass as b, Fragment as E, renderList as I, unref as g } from "vue";
const j = ["onClick"], S = { class: "VueHotToast__icon" }, B = { key: 0 }, D = ["src"], M = {
key: 1,
class: "VueHotToast__checkmark"
}, D = {
}, N = {
key: 2,
class: "VueHotToast__error"
}, M = {
}, U = {
key: 3,
class: "VueHotToast__loading"
}, N = { class: "content" }, U = { class: "content-message" }, $ = /* @__PURE__ */ x({
}, z = { class: "content" }, L = { class: "content-message" }, $ = /* @__PURE__ */ x({
__name: "ToasterItem",

@@ -19,18 +19,19 @@ props: {

duration: {},
icon: {}
icon: {},
position: {}
},
emits: ["close"],
setup(t, { emit: e }) {
const s = t, o = d(null), r = d(0), _ = d(0), p = () => {
e("close");
setup(t, { emit: o }) {
const e = t, s = d(null), n = d(0), _ = d(0), p = () => {
o("close");
};
return h(() => {
s.autoClose && (r.value = Date.now(), _.value = s.duration, o.value = setTimeout(p, _.value));
}), (a, R) => (n(), i("div", {
return y(() => {
e.autoClose && (n.value = Date.now(), _.value = e.duration, s.value = setTimeout(p, _.value));
}), (a, K) => (i(), c("div", {
class: "VueHotToast__toast",
style: m(`--toast-duration: ${a.duration}s;`),
onClick: y(p, ["prevent"])
style: h(`--toast-duration: ${a.duration}s;`),
onClick: m(p, ["prevent"])
}, [
u("div", j, [
a.icon ? (n(), i("div", I, [
u("div", S, [
a.icon ? (i(), c("div", B, [
u("img", {

@@ -42,78 +43,84 @@ class: "VueHotToast__custom-icon",

alt: "Toast Icon"
}, null, 8, S)
])) : a.type === "success" ? (n(), i("div", B)) : a.type === "error" ? (n(), i("div", D)) : a.type === "loading" ? (n(), i("div", M)) : v("", !0)
}, null, 8, D)
])) : a.type === "success" ? (i(), c("div", M)) : a.type === "error" ? (i(), c("div", N)) : a.type === "loading" ? (i(), c("div", U)) : v("", !0)
]),
u("div", N, [
u("div", U, T(a.message), 1)
u("div", z, [
u("div", L, T(a.message), 1)
])
], 12, E));
], 12, j));
}
}), L = {
}), A = {
type: "info",
message: "Here's your toast.",
autoClose: !0,
duration: 3e3
duration: 3e3,
position: "top-center"
};
function z() {
function F() {
let t = (/* @__PURE__ */ new Date()).getTime();
var e = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
var o = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
/[xy]/g,
function(s) {
var o = (t + Math.random() * 16) % 16 | 0;
return t = Math.floor(t / 16), (s == "x" ? o : o & 3 | 8).toString(16);
function(e) {
var s = (t + Math.random() * 16) % 16 | 0;
return t = Math.floor(t / 16), (e == "x" ? s : s & 3 | 8).toString(16);
}
);
return e;
return o;
}
const c = C({
const r = C({
notifications: []
}), l = function() {
const t = (e) => {
const s = Object.assign({ ...L }, e), o = z();
return c.notifications.push(
const t = (o) => {
const e = Object.assign({ ...A }, o), s = F();
return r.notifications.push(
{
id: o,
...s
id: s,
...e
}
), o;
), s;
};
return t.update = (e, s) => {
const o = c.notifications.findIndex(
(r) => r.id === e
return t.update = (o, e) => {
const s = r.notifications.findIndex(
(n) => n.id === o
);
if (o === -1)
throw t(s), new Error("Can't find toast");
return Object.assign(c.notifications[o], s), e;
}, t._handleOptions = (e, s) => {
const o = Object.assign(s ?? {}, { type: e });
return t(o);
}, t.loading = (e, s) => t._handleOptions(
if (s === -1)
throw t(e), new Error("Can't find toast");
return Object.assign(r.notifications[s], e), o;
}, t._handleOptions = (o, e) => {
const s = Object.assign(e ?? {}, { type: o });
return t(s);
}, t.loading = (o, e) => t._handleOptions(
"loading",
Object.assign(s ?? {}, { message: e })
), t.success = (e, s) => t._handleOptions(
Object.assign(e ?? {}, { message: o })
), t.success = (o, e) => t._handleOptions(
"success",
Object.assign(s ?? {}, { message: e })
), t.error = (e, s) => t._handleOptions(
Object.assign(e ?? {}, { message: o })
), t.error = (o, e) => t._handleOptions(
"error",
Object.assign(s ?? {}, { message: e })
), t.promise = (e, s) => {
const o = t.loading(s.loading);
return e.then((r) => (t.update(o, {
message: s.success,
type: "success"
}), o)).catch((r) => {
throw t.update(o, {
message: s.error,
type: "error"
}), r;
Object.assign(e ?? {}, { message: o })
), t.promise = (o, e) => {
const s = t.loading(e.loading, {
position: e.position
});
return o.then((n) => (t.update(s, {
message: e.success,
type: "success",
position: e.position
}), s)).catch((n) => {
throw t.update(s, {
message: e.error,
type: "error",
position: e.position
}), n;
});
}, t;
}(), A = (t) => {
const e = c.notifications.findIndex((s) => s.id === t);
e !== -1 && c.notifications.splice(e, 1);
}, F = { class: "VueHotToast__toast-container" }, G = /* @__PURE__ */ x({
}(), J = (t) => {
const o = r.notifications.findIndex((e) => e.id === t);
o !== -1 && r.notifications.splice(o, 1);
}, R = /* @__PURE__ */ x({
__name: "Toaster",
setup(t) {
return (e, s) => (n(), f(O, { to: "body" }, [
k(V, {
const o = O(() => r.notifications.length > 0 ? r.notifications[0].position : "top-center");
return (e, s) => (i(), f(k, { to: "body" }, [
V(w, {
name: "VueHotToast__teleport-transition",

@@ -123,17 +130,20 @@ tag: "div",

}, {
default: w(() => [
u("div", F, [
(n(!0), i(H, null, b(g(c).notifications, (o) => (n(), f($, {
key: o.id,
id: o.id,
type: o.type,
message: o.message,
"auto-close": o.autoClose,
duration: o.duration,
icon: o.icon,
default: H(() => [
u("div", {
class: b(["VueHotToast__toast-container", o.value])
}, [
(i(!0), c(E, null, I(g(r).notifications, (n) => (i(), f($, {
key: n.id,
id: n.id,
type: n.type,
message: n.message,
"auto-close": n.autoClose,
duration: n.duration,
icon: n.icon,
position: n.position,
onClose: () => {
g(A)(o.id);
g(J)(n.id);
}
}, null, 8, ["id", "type", "message", "auto-close", "duration", "icon", "onClose"]))), 128))
])
}, null, 8, ["id", "type", "message", "auto-close", "duration", "icon", "position", "onClose"]))), 128))
], 2)
]),

@@ -145,24 +155,33 @@ _: 1

});
function K(t) {
const q = (t, o) => {
const e = t.__vccOpts || t;
for (const [s, n] of o)
e[s] = n;
return e;
}, Q = /* @__PURE__ */ q(R, [["__scopeId", "data-v-93511d3f"]]);
function W(t, o) {
return l.loading(t, {
autoClose: !1
autoClose: !1,
position: o
});
}
function P(t, e) {
l.update(e, {
function X(t, o, e) {
l.update(o, {
message: t,
type: "success",
autoClose: !0,
duration: 3e3
duration: 3e3,
position: e
});
}
function Q(t, e) {
l.update(e, {
message: J(t),
function Y(t, o, e) {
l.update(o, {
message: G(t),
type: "error",
autoClose: !0,
duration: 3e3
duration: 3e3,
position: e
});
}
function J(t) {
function G(t) {
if (!t)

@@ -173,4 +192,4 @@ return "Undefined Error";

if (t instanceof Error) {
const e = t;
return e.reason ?? e.message;
const o = t;
return o.reason ?? o.message;
} else

@@ -180,7 +199,7 @@ return JSON.stringify(t);

export {
G as Toaster,
Q as Toaster,
l as toast,
Q as toastError,
K as toastLoading,
P as toastSuccess
Y as toastError,
W as toastLoading,
X as toastSuccess
};

@@ -1,1 +0,1 @@

(function(a,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(a=typeof globalThis<"u"?globalThis:a||self,t(a["vue-hot-toast"]={},a.Vue))})(this,function(a,t){"use strict";const f=["onClick"],p={class:"VueHotToast__icon"},_={key:0},m=["src"],g={key:1,class:"VueHotToast__checkmark"},h={key:2,class:"VueHotToast__error"},y={key:3,class:"VueHotToast__loading"},x={class:"content"},k={class:"content-message"},T=t.defineComponent({__name:"ToasterItem",props:{id:{},type:{},message:{},autoClose:{type:Boolean},duration:{},icon:{}},emits:["close"],setup(e,{emit:o}){const s=e,n=t.ref(null),c=t.ref(0),d=t.ref(0),u=()=>{o("close")};return t.watchEffect(()=>{s.autoClose&&(c.value=Date.now(),d.value=s.duration,n.value=setTimeout(u,d.value))}),(r,j)=>(t.openBlock(),t.createElementBlock("div",{class:"VueHotToast__toast",style:t.normalizeStyle(`--toast-duration: ${r.duration}s;`),onClick:t.withModifiers(u,["prevent"])},[t.createElementVNode("div",p,[r.icon?(t.openBlock(),t.createElementBlock("div",_,[t.createElementVNode("img",{class:"VueHotToast__custom-icon",src:r.icon,width:24,height:24,alt:"Toast Icon"},null,8,m)])):r.type==="success"?(t.openBlock(),t.createElementBlock("div",g)):r.type==="error"?(t.openBlock(),t.createElementBlock("div",h)):r.type==="loading"?(t.openBlock(),t.createElementBlock("div",y)):t.createCommentVNode("",!0)]),t.createElementVNode("div",x,[t.createElementVNode("div",k,t.toDisplayString(r.message),1)])],12,f))}}),E={type:"info",message:"Here's your toast.",autoClose:!0,duration:3e3};function B(){let e=new Date().getTime();var o="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(s){var n=(e+Math.random()*16)%16|0;return e=Math.floor(e/16),(s=="x"?n:n&3|8).toString(16)});return o}const i=t.reactive({notifications:[]}),l=function(){const e=o=>{const s=Object.assign({...E},o),n=B();return i.notifications.push({id:n,...s}),n};return e.update=(o,s)=>{const n=i.notifications.findIndex(c=>c.id===o);if(n===-1)throw e(s),new Error("Can't find toast");return Object.assign(i.notifications[n],s),o},e._handleOptions=(o,s)=>{const n=Object.assign(s??{},{type:o});return e(n)},e.loading=(o,s)=>e._handleOptions("loading",Object.assign(s??{},{message:o})),e.success=(o,s)=>e._handleOptions("success",Object.assign(s??{},{message:o})),e.error=(o,s)=>e._handleOptions("error",Object.assign(s??{},{message:o})),e.promise=(o,s)=>{const n=e.loading(s.loading);return o.then(c=>(e.update(n,{message:s.success,type:"success"}),n)).catch(c=>{throw e.update(n,{message:s.error,type:"error"}),c})},e}(),V=e=>{const o=i.notifications.findIndex(s=>s.id===e);o!==-1&&i.notifications.splice(o,1)},C={class:"VueHotToast__toast-container"},O=t.defineComponent({__name:"Toaster",setup(e){return(o,s)=>(t.openBlock(),t.createBlock(t.Teleport,{to:"body"},[t.createVNode(t.Transition,{name:"VueHotToast__teleport-transition",tag:"div",class:"VueHotToast__teleport-transition"},{default:t.withCtx(()=>[t.createElementVNode("div",C,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(i).notifications,n=>(t.openBlock(),t.createBlock(T,{key:n.id,id:n.id,type:n.type,message:n.message,"auto-close":n.autoClose,duration:n.duration,icon:n.icon,onClose:()=>{t.unref(V)(n.id)}},null,8,["id","type","message","auto-close","duration","icon","onClose"]))),128))])]),_:1})]))}});function b(e){return l.loading(e,{autoClose:!1})}function w(e,o){l.update(o,{message:e,type:"success",autoClose:!0,duration:3e3})}function H(e,o){l.update(o,{message:S(e),type:"error",autoClose:!0,duration:3e3})}function S(e){if(!e)return"Undefined Error";if(typeof e=="string")return e;if(e instanceof Error){const o=e;return o.reason??o.message}else return JSON.stringify(e)}a.Toaster=O,a.toast=l,a.toastError=H,a.toastLoading=b,a.toastSuccess=w,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})});
(function(r,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(r=typeof globalThis<"u"?globalThis:r||self,t(r["vue-hot-toast"]={},r.Vue))})(this,function(r,t){"use strict";const p=["onClick"],_={class:"VueHotToast__icon"},f={key:0},g=["src"],m={key:1,class:"VueHotToast__checkmark"},y={key:2,class:"VueHotToast__error"},h={key:3,class:"VueHotToast__loading"},x={class:"content"},k={class:"content-message"},T=t.defineComponent({__name:"ToasterItem",props:{id:{},type:{},message:{},autoClose:{type:Boolean},duration:{},icon:{},position:{}},emits:["close"],setup(e,{emit:o}){const n=e,s=t.ref(null),i=t.ref(0),d=t.ref(0),u=()=>{o("close")};return t.watchEffect(()=>{n.autoClose&&(i.value=Date.now(),d.value=n.duration,s.value=setTimeout(u,d.value))}),(c,I)=>(t.openBlock(),t.createElementBlock("div",{class:"VueHotToast__toast",style:t.normalizeStyle(`--toast-duration: ${c.duration}s;`),onClick:t.withModifiers(u,["prevent"])},[t.createElementVNode("div",_,[c.icon?(t.openBlock(),t.createElementBlock("div",f,[t.createElementVNode("img",{class:"VueHotToast__custom-icon",src:c.icon,width:24,height:24,alt:"Toast Icon"},null,8,g)])):c.type==="success"?(t.openBlock(),t.createElementBlock("div",m)):c.type==="error"?(t.openBlock(),t.createElementBlock("div",y)):c.type==="loading"?(t.openBlock(),t.createElementBlock("div",h)):t.createCommentVNode("",!0)]),t.createElementVNode("div",x,[t.createElementVNode("div",k,t.toDisplayString(c.message),1)])],12,p))}}),E={type:"info",message:"Here's your toast.",autoClose:!0,duration:3e3,position:"top-center"};function B(){let e=new Date().getTime();var o="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(n){var s=(e+Math.random()*16)%16|0;return e=Math.floor(e/16),(n=="x"?s:s&3|8).toString(16)});return o}const a=t.reactive({notifications:[]}),l=function(){const e=o=>{const n=Object.assign({...E},o),s=B();return a.notifications.push({id:s,...n}),s};return e.update=(o,n)=>{const s=a.notifications.findIndex(i=>i.id===o);if(s===-1)throw e(n),new Error("Can't find toast");return Object.assign(a.notifications[s],n),o},e._handleOptions=(o,n)=>{const s=Object.assign(n??{},{type:o});return e(s)},e.loading=(o,n)=>e._handleOptions("loading",Object.assign(n??{},{message:o})),e.success=(o,n)=>e._handleOptions("success",Object.assign(n??{},{message:o})),e.error=(o,n)=>e._handleOptions("error",Object.assign(n??{},{message:o})),e.promise=(o,n)=>{const s=e.loading(n.loading,{position:n.position});return o.then(i=>(e.update(s,{message:n.success,type:"success",position:n.position}),s)).catch(i=>{throw e.update(s,{message:n.error,type:"error",position:n.position}),i})},e}(),C=e=>{const o=a.notifications.findIndex(n=>n.id===e);o!==-1&&a.notifications.splice(o,1)},V=t.defineComponent({__name:"Toaster",setup(e){const o=t.computed(()=>a.notifications.length>0?a.notifications[0].position:"top-center");return(n,s)=>(t.openBlock(),t.createBlock(t.Teleport,{to:"body"},[t.createVNode(t.Transition,{name:"VueHotToast__teleport-transition",tag:"div",class:"VueHotToast__teleport-transition"},{default:t.withCtx(()=>[t.createElementVNode("div",{class:t.normalizeClass(["VueHotToast__toast-container",o.value])},[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(t.unref(a).notifications,i=>(t.openBlock(),t.createBlock(T,{key:i.id,id:i.id,type:i.type,message:i.message,"auto-close":i.autoClose,duration:i.duration,icon:i.icon,position:i.position,onClose:()=>{t.unref(C)(i.id)}},null,8,["id","type","message","auto-close","duration","icon","position","onClose"]))),128))],2)]),_:1})]))}}),j="",O=((e,o)=>{const n=e.__vccOpts||e;for(const[s,i]of o)n[s]=i;return n})(V,[["__scopeId","data-v-93511d3f"]]);function b(e,o){return l.loading(e,{autoClose:!1,position:o})}function w(e,o,n){l.update(o,{message:e,type:"success",autoClose:!0,duration:3e3,position:n})}function H(e,o,n){l.update(o,{message:S(e),type:"error",autoClose:!0,duration:3e3,position:n})}function S(e){if(!e)return"Undefined Error";if(typeof e=="string")return e;if(e instanceof Error){const o=e;return o.reason??o.message}else return JSON.stringify(e)}r.Toaster=O,r.toast=l,r.toastError=H,r.toastLoading=b,r.toastSuccess=w,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
{
"name": "@steveyuowo/vue-hot-toast",
"version": "1.2.5",
"version": "1.3.0",
"type": "module",

@@ -5,0 +5,0 @@ "repository": {

@@ -86,2 +86,12 @@ <img src="https://github.com/SteveYuOWO/vue-hot-toast/blob/main/public/header.gif" />

If you need to change positions, you can pass `position` like so:
```ts
toast({
message: 'Success',
type: 'success',
position: 'top-right',
})
```
##### 3. Updating Toasts

@@ -110,2 +120,5 @@

loading: 'Loading!',
// Optional: Pass position here to change positioning on webpage
position: 'top-right',
});

@@ -127,2 +140,5 @@

loading: 'Loading!',
// Optional: Use position here to change positioning
position: 'top-right'
})

@@ -129,0 +145,0 @@ ```

@@ -10,2 +10,3 @@ import { reactive } from "vue";

ToastType,
ToastPosition,
} from "./type";

@@ -79,5 +80,8 @@ import { createUUID } from "./uuid";

error: string;
position?: ToastPosition;
},
) => {
const id = fn.loading(options.loading);
const id = fn.loading(options.loading, {
position: options.position,
});
return promise

@@ -88,2 +92,3 @@ .then((_) => {

type: "success",
position: options.position,
});

@@ -96,2 +101,3 @@ return id;

type: "error",
position: options.position,
});

@@ -98,0 +104,0 @@ throw e;

export type ToastType = "success" | "loading" | "error";
export type ToastPosition =
| "top-left"
| "top-center"
| "top-right"
| "bottom-left"
| "bottom-center"
| "bottom-right"
| "middle-center";
export interface ToastProps {

@@ -27,2 +37,6 @@ /**

icon?: string;
/**
* Position of the toast on the screen.
*/
position?: ToastPosition;
}

@@ -47,2 +61,3 @@

error: string;
position?: ToastPosition;
},

@@ -57,2 +72,3 @@ ) => Promise<string>;

duration: 3000,
position: "top-center",
};

@@ -1,11 +0,16 @@

import { Id } from "core/type";
import { Id, ToastPosition } from "core/type";
import { toast } from "./index.ts";
export function toastLoading(message: string) {
export function toastLoading(message: string, position?: ToastPosition) {
return toast.loading(message, {
autoClose: false,
position: position,
});
}
export function toastSuccess(message: string, id: Id) {
export function toastSuccess(
message: string,
id: Id,
position?: ToastPosition,
) {
toast.update(id, {

@@ -16,6 +21,11 @@ message,

duration: 3000,
position: position,
});
}
export function toastError(e: string | Error, id: Id) {
export function toastError(
e: string | Error,
id: Id,
position?: ToastPosition,
) {
toast.update(id, {

@@ -26,2 +36,3 @@ message: toReadableErrorMessage(e),

duration: 3000,
position: position,
});

@@ -28,0 +39,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet