vue-toasts-lite 0.1.0 → 0.1.1
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/README.md +8 -0
- package/dist/index.js +66 -55
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
# Vue Toasts Lite
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/vue-toasts-lite)
|
|
4
|
+
[](https://scheron.github.io/vue-toasts-lite/)
|
|
5
|
+
|
|
3
6
|
A lightweight toast notifications library for Vue 3.
|
|
4
7
|
|
|
8
|
+
📖 **[Check docs](https://scheron.github.io/vue-toasts-lite/)**
|
|
9
|
+
|
|
10
|
+
> ⚠️ **Note**: This is primarily a personal utility library created for my own use. I don't discourage others from using it, but I should mention that I'm not currently using it in production myself. The main purpose of this library is to provide me with a simple and quick way to integrate toast notifications into my personal projects without the need to configure and set up larger, more complex libraries. If you find it useful, feel free to use it, but keep in mind that it's tailored to my personal needs and workflow.
|
|
11
|
+
|
|
12
|
+
|
|
5
13
|
## Features
|
|
6
14
|
|
|
7
15
|
- 🚀 Lightweight and easy to use
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { defineComponent as
|
|
1
|
+
var L = Object.defineProperty;
|
|
2
|
+
var M = (a, t, e) => t in a ? L(a, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[t] = e;
|
|
3
|
+
var f = (a, t, e) => M(a, typeof t != "symbol" ? t + "" : t, e);
|
|
4
|
+
import { defineComponent as w, ref as h, watchEffect as O, createElementBlock as m, openBlock as d, withModifiers as E, normalizeStyle as $, createCommentVNode as U, createElementVNode as v, normalizeClass as C, toDisplayString as D, computed as k, onBeforeUpdate as x, createBlock as g, Teleport as B, Fragment as b, renderList as T, createVNode as P, TransitionGroup as A, withCtx as I, unref as N } from "vue";
|
|
5
5
|
const S = {
|
|
6
6
|
key: 0,
|
|
7
7
|
class: "toasts-lite__icon"
|
|
8
|
-
}, V = { class: "toasts-lite__content" }, z = { class: "toasts-lite__content-message" }, F = /* @__PURE__ */
|
|
8
|
+
}, V = { class: "toasts-lite__content" }, z = { class: "toasts-lite__content-message" }, F = /* @__PURE__ */ w({
|
|
9
9
|
__name: "ToastsLiteItem",
|
|
10
10
|
props: {
|
|
11
11
|
id: {},
|
|
@@ -17,33 +17,33 @@ const S = {
|
|
|
17
17
|
},
|
|
18
18
|
emits: ["close"],
|
|
19
19
|
setup(a, { expose: t, emit: e }) {
|
|
20
|
-
const o = a, n = e,
|
|
20
|
+
const o = a, n = e, i = h(null), p = h(0), c = h(0);
|
|
21
21
|
function s() {
|
|
22
|
-
|
|
22
|
+
i.value && clearTimeout(i.value), n("close");
|
|
23
23
|
}
|
|
24
24
|
function r() {
|
|
25
|
-
|
|
25
|
+
i.value && (clearTimeout(i.value), i.value = null, c.value = o.duration - (Date.now() - p.value));
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
!
|
|
27
|
+
function u() {
|
|
28
|
+
!i.value && c.value > 0 && (i.value = setTimeout(s, c.value));
|
|
29
29
|
}
|
|
30
|
-
return
|
|
31
|
-
o.autoClose && (p.value = Date.now(),
|
|
30
|
+
return O(() => {
|
|
31
|
+
i.value && (clearTimeout(i.value), i.value = null), o.autoClose && (p.value = Date.now(), c.value = o.duration, i.value = setTimeout(s, o.duration));
|
|
32
32
|
}), t({
|
|
33
33
|
pause: r,
|
|
34
|
-
resume:
|
|
35
|
-
}), (
|
|
34
|
+
resume: u
|
|
35
|
+
}), (l, _) => (d(), m("div", {
|
|
36
36
|
class: "toasts-lite__toast",
|
|
37
|
-
style:
|
|
38
|
-
onClick:
|
|
37
|
+
style: $(`--toast-duration: ${a.duration}s;`),
|
|
38
|
+
onClick: E(s, ["prevent"])
|
|
39
39
|
}, [
|
|
40
|
-
["success", "error", "loading", "warn"].includes(a.type) ? (
|
|
41
|
-
|
|
42
|
-
class:
|
|
40
|
+
["success", "error", "loading", "warn"].includes(a.type) ? (d(), m("div", S, [
|
|
41
|
+
v("div", {
|
|
42
|
+
class: C(`toasts-lite__${a.type}`)
|
|
43
43
|
}, null, 2)
|
|
44
|
-
])) :
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
])) : U("", !0),
|
|
45
|
+
v("div", V, [
|
|
46
|
+
v("div", z, D(a.message), 1)
|
|
47
47
|
])
|
|
48
48
|
], 4));
|
|
49
49
|
}
|
|
@@ -51,7 +51,7 @@ const S = {
|
|
|
51
51
|
class R extends Map {
|
|
52
52
|
constructor() {
|
|
53
53
|
super(...arguments);
|
|
54
|
-
|
|
54
|
+
f(this, "subscribers", []);
|
|
55
55
|
}
|
|
56
56
|
set(e, o) {
|
|
57
57
|
return super.set(e, o), this.notify(), this;
|
|
@@ -81,8 +81,8 @@ const j = {
|
|
|
81
81
|
};
|
|
82
82
|
class G {
|
|
83
83
|
constructor() {
|
|
84
|
-
|
|
85
|
-
|
|
84
|
+
f(this, "counter", 0);
|
|
85
|
+
f(this, "toasts");
|
|
86
86
|
this.toasts = new R();
|
|
87
87
|
}
|
|
88
88
|
get toastList() {
|
|
@@ -184,58 +184,69 @@ class G {
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
-
const y = new G(), H = ["onMouseenter", "onMouseleave"], K = /* @__PURE__ */
|
|
187
|
+
const y = new G(), H = ["onMouseenter", "onMouseleave"], K = /* @__PURE__ */ w({
|
|
188
188
|
__name: "ToastsLiteProvider",
|
|
189
189
|
setup(a) {
|
|
190
|
-
const t =
|
|
190
|
+
const t = [
|
|
191
|
+
"top-left",
|
|
192
|
+
"top-center",
|
|
193
|
+
"top-right",
|
|
194
|
+
"middle-center",
|
|
195
|
+
"bottom-left",
|
|
196
|
+
"bottom-center",
|
|
197
|
+
"bottom-right"
|
|
198
|
+
], e = h(y.toastList);
|
|
191
199
|
y.onToastsListChange((s) => {
|
|
192
|
-
|
|
200
|
+
e.value = s;
|
|
193
201
|
});
|
|
194
|
-
const
|
|
202
|
+
const o = k(() => {
|
|
195
203
|
const s = /* @__PURE__ */ new Map();
|
|
196
|
-
return
|
|
197
|
-
const
|
|
198
|
-
s.has(
|
|
204
|
+
return e.value.forEach((r) => {
|
|
205
|
+
const u = r.position || "top-center";
|
|
206
|
+
s.has(u) || s.set(u, []), s.get(u).push(r);
|
|
199
207
|
}), s;
|
|
200
|
-
}),
|
|
208
|
+
}), n = h({});
|
|
201
209
|
x(() => {
|
|
202
|
-
for (const s of
|
|
210
|
+
for (const s of t)
|
|
203
211
|
n.value[s] = [];
|
|
204
212
|
});
|
|
205
|
-
function
|
|
213
|
+
function i(s) {
|
|
206
214
|
n.value[s] && n.value[s].forEach((r) => r == null ? void 0 : r.pause());
|
|
207
215
|
}
|
|
208
216
|
function p(s) {
|
|
209
217
|
n.value[s] && n.value[s].forEach((r) => r == null ? void 0 : r.resume());
|
|
210
218
|
}
|
|
211
|
-
function
|
|
219
|
+
function c(s, r) {
|
|
212
220
|
n.value[s] || (n.value[s] = []), r && "pause" in r && "resume" in r && n.value[s].push(r);
|
|
213
221
|
}
|
|
214
|
-
return (s, r) => (
|
|
215
|
-
(
|
|
216
|
-
key:
|
|
217
|
-
class:
|
|
218
|
-
onMouseenter: (
|
|
219
|
-
onMouseleave: (
|
|
222
|
+
return (s, r) => (d(), g(B, { to: "body" }, [
|
|
223
|
+
(d(), m(b, null, T(t, (u) => v("div", {
|
|
224
|
+
key: u,
|
|
225
|
+
class: C(["toasts-lite__toast-container", `toasts-lite__${u}`]),
|
|
226
|
+
onMouseenter: (l) => i(u),
|
|
227
|
+
onMouseleave: (l) => p(u)
|
|
220
228
|
}, [
|
|
221
|
-
A
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
229
|
+
P(A, {
|
|
230
|
+
name: "toasts-lite",
|
|
231
|
+
appear: ""
|
|
232
|
+
}, {
|
|
233
|
+
default: I(() => [
|
|
234
|
+
(d(!0), m(b, null, T(o.value.get(u) || [], (l) => (d(), g(F, {
|
|
235
|
+
id: l.id,
|
|
225
236
|
ref_for: !0,
|
|
226
|
-
ref: (
|
|
227
|
-
key:
|
|
228
|
-
type:
|
|
229
|
-
message:
|
|
230
|
-
"auto-close":
|
|
231
|
-
duration:
|
|
232
|
-
position:
|
|
233
|
-
onClose: (
|
|
237
|
+
ref: (_) => c(u, _),
|
|
238
|
+
key: l.id,
|
|
239
|
+
type: l.type,
|
|
240
|
+
message: l.message,
|
|
241
|
+
"auto-close": l.autoClose,
|
|
242
|
+
duration: l.duration,
|
|
243
|
+
position: l.position,
|
|
244
|
+
onClose: (_) => N(y).remove(l.id)
|
|
234
245
|
}, null, 8, ["id", "type", "message", "auto-close", "duration", "position", "onClose"]))), 128))
|
|
235
246
|
]),
|
|
236
247
|
_: 2
|
|
237
248
|
}, 1024)
|
|
238
|
-
], 42, H))
|
|
249
|
+
], 42, H)), 64))
|
|
239
250
|
]));
|
|
240
251
|
}
|
|
241
252
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vue-toasts-lite",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "scheron",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"scripts": {
|
|
27
27
|
"dev": "vite",
|
|
28
28
|
"build": "vite build",
|
|
29
|
+
"build:example": "cd example && bun run build",
|
|
29
30
|
"preview": "vite preview"
|
|
30
31
|
},
|
|
31
32
|
"peerDependencies": {
|