Skip to content

Commit d075160

Browse files
author
kyvg
committed
3.2.0
1 parent 9d677c9 commit d075160

File tree

5 files changed

+71
-65
lines changed

5 files changed

+71
-65
lines changed

dist/index.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export default _default;
1414

1515
export declare type NotificationItem = Pick<NotificationsOptions, 'id' | 'title' | 'text' | 'type' | 'speed' | 'data'> & {
1616
length: number;
17+
duplicates: number;
1718
};
1819

1920
export declare const Notifications: DefineComponent<{

dist/index.es.js

+66-61
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(function(){var o;"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.nonce=(o=document.head.querySelector("meta[property=csp-nonce]"))==null?void 0:o.content,e.appendChild(document.createTextNode(".vue-notification-group{display:block;position:fixed;z-index:5000}.vue-notification-wrapper{display:block;overflow:hidden;width:100%;margin:0;padding:0}.notification-title{font-weight:600}.vue-notification-template{display:block;box-sizing:border-box;background:white;text-align:left}.vue-notification{display:block;box-sizing:border-box;text-align:left;font-size:12px;padding:10px;margin:0 5px 5px;color:#fff;background:#44A4FC;border-left:5px solid #187FE7}.vue-notification.warn{background:#ffb648;border-left-color:#f48a06}.vue-notification.error{background:#E54D42;border-left-color:#b82e24}.vue-notification.success{background:#68CD86;border-left-color:#42a85f}.vn-fade-enter-active,.vn-fade-leave-active,.vn-fade-move{transition:all .5s}.vn-fade-enter-from,.vn-fade-leave-to{opacity:0}")),document.head.appendChild(e)}}catch(i){console.error("vite-plugin-css-injected-by-js",i)}})();
2-
import { defineComponent as D, createVNode as l, TransitionGroup as H, ref as $, computed as g, onMounted as et, Fragment as C, isVNode as nt } from "vue";
3-
const R = /* @__PURE__ */ new Map();
2+
import { defineComponent as S, createVNode as l, TransitionGroup as R, ref as C, computed as g, onMounted as et, Fragment as M, isVNode as nt } from "vue";
3+
const j = /* @__PURE__ */ new Map();
44
class it {
55
constructor(n, o, a) {
66
this.remaining = o, this.callback = n, this.notifyItem = a, this.resume();
@@ -28,7 +28,7 @@ function ot(t) {
2828
});
2929
} };
3030
}
31-
const b = ot(), T = "[-+]?[0-9]*.?[0-9]+", M = [
31+
const b = ot(), T = "[-+]?[0-9]*.?[0-9]+", k = [
3232
{
3333
name: "px",
3434
regexp: new RegExp(`^${T}px$`)
@@ -51,8 +51,8 @@ const b = ot(), T = "[-+]?[0-9]*.?[0-9]+", M = [
5151
type: t,
5252
value: 0
5353
};
54-
for (let n = 0; n < M.length; n++) {
55-
const o = M[n];
54+
for (let n = 0; n < k.length; n++) {
55+
const o = k[n];
5656
if (o.regexp.test(t))
5757
return {
5858
type: o.name,
@@ -72,14 +72,14 @@ const b = ot(), T = "[-+]?[0-9]*.?[0-9]+", M = [
7272
default:
7373
return { type: "", value: t };
7474
}
75-
}, k = {
75+
}, H = {
7676
x: /* @__PURE__ */ new Set(["left", "center", "right"]),
7777
y: /* @__PURE__ */ new Set(["top", "bottom"])
7878
}, st = ((t) => () => t++)(0), lt = (t) => typeof t != "string" ? [] : t.split(/\s+/gi).filter(Boolean), ct = (t) => {
7979
typeof t == "string" && (t = lt(t));
8080
let n = null, o = null;
8181
return t.forEach((a) => {
82-
k.y.has(a) && (o = a), k.x.has(a) && (n = a);
82+
H.y.has(a) && (o = a), H.x.has(a) && (n = a);
8383
}), { x: n, y: o };
8484
}, E = {
8585
position: ["top", "right"],
@@ -94,7 +94,7 @@ const b = ot(), T = "[-+]?[0-9]*.?[0-9]+", M = [
9494
opacity: [0, 1]
9595
}
9696
}
97-
}, ut = /* @__PURE__ */ D({
97+
}, ut = /* @__PURE__ */ S({
9898
name: "velocity-group",
9999
inheritAttrs: !1,
100100
props: {
@@ -121,7 +121,7 @@ const b = ot(), T = "[-+]?[0-9]*.?[0-9]+", M = [
121121
}, h = () => {
122122
o("afterLeave");
123123
};
124-
return () => l(H, {
124+
return () => l(R, {
125125
tag: "div",
126126
css: !1,
127127
name: t.name,
@@ -135,7 +135,7 @@ const b = ot(), T = "[-+]?[0-9]*.?[0-9]+", M = [
135135
}
136136
});
137137
}
138-
}), ft = /* @__PURE__ */ D({
138+
}), ft = /* @__PURE__ */ S({
139139
name: "css-group",
140140
inheritAttrs: !1,
141141
props: {
@@ -146,7 +146,7 @@ const b = ot(), T = "[-+]?[0-9]*.?[0-9]+", M = [
146146
},
147147
setup: (t, {
148148
slots: n
149-
}) => () => l(H, {
149+
}) => () => l(R, {
150150
tag: "div",
151151
name: t.name
152152
}, {
@@ -162,7 +162,7 @@ function dt(t) {
162162
const x = {
163163
IDLE: 0,
164164
DESTROYED: 2
165-
}, pt = /* @__PURE__ */ D({
165+
}, pt = /* @__PURE__ */ S({
166166
// eslint-disable-next-line vue/multi-word-component-names
167167
name: "notifications",
168168
props: {
@@ -255,77 +255,82 @@ const x = {
255255
slots: o,
256256
expose: a
257257
}) => {
258-
const s = $([]), h = $(null), c = R.get("velocity"), u = g(() => t.animationType === "velocity"), j = g(() => u.value ? ut : ft), f = g(() => s.value.filter((e) => e.state !== x.DESTROYED)), A = g(() => rt(t.width)), N = g(() => {
258+
const s = C([]), h = C(null), c = j.get("velocity"), u = g(() => t.animationType === "velocity"), B = g(() => u.value ? ut : ft), f = g(() => s.value.filter((e) => e.state !== x.DESTROYED)), N = g(() => rt(t.width)), O = g(() => {
259259
const {
260260
x: e,
261261
y: i
262-
} = ct(t.position), r = A.value.value, d = A.value.type, m = {
262+
} = ct(t.position), r = N.value.value, d = N.value.type, m = {
263263
width: r + d
264264
};
265265
return i && (m[i] = "0px"), e && (e === "center" ? m.left = `calc(50% - ${+r / 2}${d})` : m[e] = "0px"), m;
266-
}), O = g(() => "bottom" in N.value), B = (e) => {
266+
}), w = g(() => "bottom" in O.value), V = (e) => {
267267
n("click", e), t.closeOnClick && y(e);
268-
}, V = () => {
268+
}, Y = () => {
269269
var e;
270270
t.pauseOnHover && ((e = h.value) == null || e.pause());
271-
}, Y = () => {
271+
}, G = () => {
272272
var e;
273273
t.pauseOnHover && ((e = h.value) == null || e.resume());
274-
}, G = (e = {}) => {
274+
}, _ = (e = {}) => {
275275
if (e.group || (e.group = ""), e.data || (e.data = {}), t.group !== e.group)
276276
return;
277277
if (e.clean || e.clear) {
278-
q();
278+
z();
279279
return;
280280
}
281281
const i = typeof e.duration == "number" ? e.duration : t.duration, r = typeof e.speed == "number" ? e.speed : t.speed, d = typeof e.ignoreDuplicates == "boolean" ? e.ignoreDuplicates : t.ignoreDuplicates, {
282282
title: m,
283-
text: K,
284-
type: Q,
285-
data: U,
286-
id: X
283+
text: Q,
284+
type: U,
285+
data: X,
286+
id: Z
287287
} = e, p = {
288-
id: X || st(),
288+
id: Z || st(),
289289
title: m,
290-
text: K,
291-
type: Q,
290+
text: Q,
291+
type: U,
292292
state: x.IDLE,
293293
speed: r,
294294
length: i + 2 * r,
295-
data: U
295+
data: X,
296+
duplicates: 0
296297
};
297298
i >= 0 && (h.value = new it(() => y(p), p.length, p));
298-
const Z = t.reverse ? !O.value : O.value;
299+
const tt = t.reverse ? !w.value : w.value;
299300
let v = -1;
300-
const tt = f.value.some((L) => L.title === e.title && L.text === e.text);
301-
(!d || !tt) && (Z ? (s.value.push(p), n("start", p), f.value.length > t.max && (v = 0)) : (s.value.unshift(p), n("start", p), f.value.length > t.max && (v = f.value.length - 1)), v !== -1 && y(f.value[v]));
302-
}, _ = (e) => {
303-
W(e);
304-
}, F = (e) => ["vue-notification-template", t.classes, e.type || ""], P = (e) => u.value ? void 0 : {
301+
const L = f.value.find(($) => $.title === e.title && $.text === e.text);
302+
if (d && L) {
303+
L.duplicates++;
304+
return;
305+
}
306+
tt ? (s.value.push(p), n("start", p), f.value.length > t.max && (v = 0)) : (s.value.unshift(p), n("start", p), f.value.length > t.max && (v = f.value.length - 1)), v !== -1 && y(f.value[v]);
307+
}, F = (e) => {
308+
q(e);
309+
}, P = (e) => ["vue-notification-template", t.classes, e.type || ""], W = (e) => u.value ? void 0 : {
305310
transition: `all ${e.speed}ms`
306311
}, y = (e) => {
307312
clearTimeout(e.timer), e.state = x.DESTROYED, I(), n("destroy", e);
308-
}, W = (e) => {
313+
}, q = (e) => {
309314
const i = s.value.find((r) => r.id === e);
310315
i && y(i);
311-
}, q = () => {
316+
}, z = () => {
312317
f.value.forEach(y);
313-
}, w = (e, i) => {
318+
}, A = (e, i) => {
314319
var d;
315320
const r = (d = t.animation) == null ? void 0 : d[e];
316321
return typeof r == "function" ? r(i) : r;
317-
}, z = (e, i) => {
322+
}, J = (e, i) => {
318323
if (!u.value)
319324
return;
320-
const r = w("enter", e);
325+
const r = A("enter", e);
321326
c(e, r, {
322327
duration: t.speed,
323328
complete: i
324329
});
325-
}, J = (e, i) => {
330+
}, K = (e, i) => {
326331
if (!u.value)
327332
return;
328-
const r = w("leave", e);
333+
const r = A("leave", e);
329334
c(e, r, {
330335
duration: t.speed,
331336
complete: i
@@ -335,38 +340,38 @@ const x = {
335340
s.value = s.value.filter((e) => e.state !== x.DESTROYED);
336341
}
337342
return et(() => {
338-
b.on("add", G), b.on("close", _);
343+
b.on("add", _), b.on("close", F);
339344
}), () => {
340345
let e;
341346
return l("div", {
342347
class: "vue-notification-group",
343-
style: N.value
344-
}, [l(j.value, {
348+
style: O.value
349+
}, [l(B.value, {
345350
name: t.animationName,
346-
onEnter: z,
347-
onLeave: J,
351+
onEnter: J,
352+
onLeave: K,
348353
onAfterLeave: I
349354
}, dt(e = f.value.map((i) => l("div", {
350355
key: i.id,
351356
class: "vue-notification-wrapper",
352-
style: P(i),
357+
style: W(i),
353358
"data-id": i.id,
354-
onMouseenter: V,
355-
onMouseleave: Y
359+
onMouseenter: Y,
360+
onMouseleave: G
356361
}, [o.body ? o.body({
357362
item: i,
358363
class: [t.classes, i.type],
359364
close: () => y(i)
360365
}) : l("div", {
361-
class: F(i),
362-
onClick: () => B(i)
363-
}, [t.dangerouslySetInnerHtml ? l(C, null, [i.title ? l("div", {
366+
class: P(i),
367+
onClick: () => V(i)
368+
}, [t.dangerouslySetInnerHtml ? l(M, null, [i.title ? l("div", {
364369
class: "notification-title",
365370
innerHTML: i.title
366371
}, null) : null, l("div", {
367372
class: "notification-content",
368373
innerHTML: i.text
369-
}, null)]) : l(C, null, [i.title ? l("div", {
374+
}, null)]) : l(M, null, [i.title ? l("div", {
370375
class: "notification-title"
371376
}, [i.title]) : null, l("div", {
372377
class: "notification-content"
@@ -375,24 +380,24 @@ const x = {
375380
})]);
376381
};
377382
}
378-
}), S = (t) => {
383+
}), D = (t) => {
379384
typeof t == "string" && (t = { title: "", text: t }), typeof t == "object" && b.emit("add", t);
380385
};
381-
S.close = (t) => {
386+
D.close = (t) => {
382387
b.emit("close", t);
383388
};
384-
const vt = () => ({ notify: S }), yt = "Notifications";
389+
const ht = () => ({ notify: D }), yt = "Notifications";
385390
function mt(t, n = {}) {
386-
Object.entries(n).forEach((a) => R.set(...a));
391+
Object.entries(n).forEach((a) => j.set(...a));
387392
const o = n.name || "notify";
388-
t.config.globalProperties["$" + o] = S, t.component(n.componentName || yt, pt);
393+
t.config.globalProperties["$" + o] = D, t.component(n.componentName || yt, pt);
389394
}
390-
const xt = {
395+
const vt = {
391396
install: mt
392397
};
393398
export {
394399
pt as Notifications,
395-
xt as default,
396-
S as notify,
397-
vt as useNotification
400+
vt as default,
401+
D as notify,
402+
ht as useNotification
398403
};

0 commit comments

Comments
 (0)