@byloth/vuert
Advanced tools
Comparing version 1.2.2-rc.2 to 1.2.2-rc.3
@@ -1,7 +0,65 @@ | ||
import { ref as T, computed as D, getCurrentScope as j, inject as A, defineComponent as C, shallowRef as N, onMounted as V, onUnmounted as k, openBlock as F, createBlock as I, resolveDynamicComponent as U, withCtx as $, renderSlot as E, createCommentVNode as R, nextTick as P } from "vue"; | ||
import { ValueException as _, RuntimeException as b } from "@byloth/exceptions"; | ||
import { DeferredPromise as B, Subscribers as a, delay as v } from "@byloth/core"; | ||
const g = { $vuert: Symbol("[vuert]: vuert") }; | ||
class y { | ||
import { getCurrentScope as S, inject as O, ref as x, computed as T, defineComponent as D, shallowRef as A, onMounted as C, onUnmounted as j, openBlock as E, createBlock as N, resolveDynamicComponent as V, withCtx as F, renderSlot as I, createCommentVNode as k, nextTick as U } from "vue"; | ||
import { RuntimeException as u, ValueException as m } from "@byloth/exceptions"; | ||
import { DeferredPromise as $, Subscribers as a, delay as f } from "@byloth/core"; | ||
const v = { $vuert: Symbol("[vuert]: vuert") }; | ||
class P extends u { | ||
constructor(e, s, i, r = "AlertThrottledException") { | ||
s === void 0 && (s = "The alert has been throttled to prevent spamming the user with too many alerts."), super(s, i, r), this.alert = e; | ||
} | ||
} | ||
const h = class h { | ||
static get DEFAULT_OPTS() { | ||
return { | ||
useThrottling: !0, | ||
throttlingDuration: 100, | ||
transitionDuration: 200 | ||
}; | ||
} | ||
get options() { | ||
return { ...this._options }; | ||
} | ||
constructor(e) { | ||
this._subscribers = [], this._throttlers = /* @__PURE__ */ new Map(), this._options = { ...h.DEFAULT_OPTS, ...e }, this._options.useThrottling ? this._throttle = (s) => { | ||
if (!s.id) | ||
return !1; | ||
const i = Date.now(), r = this._throttlers.get(s.id) ?? 0; | ||
return i - r > this._options.throttlingDuration ? (this._throttlers.set(s.id, i), !1) : !0; | ||
} : this._throttle = () => !1; | ||
} | ||
emit(e) { | ||
if (this._throttle(e)) | ||
throw new P(e); | ||
const r = this._subscribers.slice().map((o) => o(e)).filter((o) => !!o); | ||
if (!r.length) | ||
throw new u("Unable to handle the emitted alert properly. There wasn't found any supported subscribers."); | ||
if (r.length > 1) | ||
throw new u("Unable to handle the emitted alert properly. There were found too many supported subscribers."); | ||
return r[0]; | ||
} | ||
subscribe(e) { | ||
return this._subscribers.push(e), () => { | ||
const s = this._subscribers.indexOf(e); | ||
return this._subscribers.splice(s, 1)[0]; | ||
}; | ||
} | ||
}; | ||
h.VERSION = "1.2.2-rc.3"; | ||
let b = h, w; | ||
const R = (t) => { | ||
w = t; | ||
}, B = () => S() ? O(v.$vuert) : w, q = (t) => ({ | ||
install: ({ config: e, provide: s }) => { | ||
const i = new b(t); | ||
R(i), e.globalProperties.$vuert = i, s(v.$vuert, i); | ||
} | ||
}), _ = () => { | ||
const t = B(); | ||
if (!t) | ||
throw new u( | ||
"`useVuert()` was called but there was not active Vuert. Did you forget to install `Vuert` plugin in your App?" | ||
); | ||
return t; | ||
}; | ||
class g { | ||
constructor(e) { | ||
this.id = e.id ?? Symbol(), this.type = e.type ?? "secondary", this.icon = e.icon, this.label = e.label, this.callback = e.callback ?? (() => { | ||
@@ -11,10 +69,10 @@ }); | ||
} | ||
class l { | ||
class c { | ||
constructor(e, s) { | ||
var r; | ||
var i; | ||
if (this.id = e.id ?? Symbol(), this.type = e.type ?? "info", this.priority = e.priority ?? "normal", this.icon = e.icon, this.title = e.title, e.message !== void 0 && e.component !== void 0) | ||
throw new _("The `message` and `component` properties cannot both be valued at the same time."); | ||
if (this.message = e.message, this.component = e.component, this.props = e.props, this.actions = ((r = e.actions) == null ? void 0 : r.map((o) => new y(o))) ?? [], this.dismissible = e.dismissible || !1, e.timeout !== void 0) { | ||
throw new m("The `message` and `component` properties cannot both be valued at the same time."); | ||
if (this.message = e.message, this.component = e.component, this.props = e.props, this.actions = ((i = e.actions) == null ? void 0 : i.map((r) => new g(r))) ?? [], this.dismissible = e.dismissible || !1, e.timeout !== void 0) { | ||
if (e.timeout <= 0) | ||
throw new _("The `timeout` property must be a positive integer or -at least- `undefined`."); | ||
throw new m("The `timeout` property must be a positive integer or -at least- `undefined`."); | ||
this.timeout = e.timeout; | ||
@@ -25,16 +83,12 @@ } else | ||
} | ||
class h extends B { | ||
static Resolved(e) { | ||
const s = new h(e, 0); | ||
return s.resolve(), s; | ||
} | ||
class H extends $ { | ||
constructor(e, s) { | ||
const r = async () => { | ||
const i = async () => { | ||
if (!this._isOpen.value) | ||
throw new Error("Unable to close the alert. It has already been closed or not even opened yet."); | ||
this._isOpen.value = !1, this._timeoutId !== void 0 && (clearTimeout(this._timeoutId), this._timeoutId = void 0), this._closingSubscribers.call(), await v(this._duration.leave), this._closedSubscribers.call(); | ||
}, o = (n) => (r(), n instanceof y ? n.callback() : n instanceof Function ? n() : n), c = (n) => { | ||
throw r(), n; | ||
this._isOpen.value = !1, this._timeoutId !== void 0 && (clearTimeout(this._timeoutId), this._timeoutId = void 0), this._closingSubscribers.call(), await f(this._duration.leave), this._closedSubscribers.call(); | ||
}, r = (l) => (i(), l instanceof g ? l.callback() : l instanceof Function ? l() : l), o = (l) => { | ||
throw i(), l; | ||
}; | ||
if (super(o, c), typeof s == "object") | ||
if (super(r, o), typeof s == "object") | ||
this._duration = { | ||
@@ -45,9 +99,9 @@ enter: Number(s.enter), | ||
else { | ||
const n = Number(s); | ||
const l = Number(s); | ||
this._duration = { | ||
enter: n, | ||
leave: n | ||
enter: l, | ||
leave: l | ||
}; | ||
} | ||
this._openingSubscribers = new a(), this._openedSubscribers = new a(), this._closingSubscribers = new a(), this._closedSubscribers = new a(), this.alert = new l(e), this._isOpen = T(!1), this.isOpen = D(() => this._isOpen.value); | ||
this._openingSubscribers = new a(), this._openedSubscribers = new a(), this._closingSubscribers = new a(), this._closedSubscribers = new a(), this.alert = new c(e), this._isOpen = x(!1), this.isOpen = T(() => this._isOpen.value); | ||
} | ||
@@ -57,3 +111,3 @@ async open() { | ||
throw new Error("Unable to open the alert. It has already been opened."); | ||
this._isOpen.value = !0, this._openingSubscribers.call(), await v(this._duration.enter), this._openedSubscribers.call(), this.alert.timeout && (this._timeoutId = setTimeout(this.resolve, this.alert.timeout)); | ||
this._isOpen.value = !0, this._openingSubscribers.call(), await f(this._duration.enter), this._openedSubscribers.call(), this.alert.timeout && (this._timeoutId = setTimeout(this.resolve, this.alert.timeout)); | ||
} | ||
@@ -73,55 +127,3 @@ onOpening(e) { | ||
} | ||
const u = class u { | ||
static get DEFAULT_OPTS() { | ||
return { | ||
useThrottling: !0, | ||
throttleDuration: 1e3, | ||
transitionDuration: 200 | ||
}; | ||
} | ||
get options() { | ||
return { ...this._options }; | ||
} | ||
constructor(e) { | ||
this._subscribers = [], this._throttlers = /* @__PURE__ */ new Map(), this._options = { ...u.DEFAULT_OPTS, ...e }, this._options.useThrottling ? this._throttle = (s) => { | ||
if (!s.id) | ||
return !1; | ||
const r = Date.now(), o = this._throttlers.get(s.id) ?? 0; | ||
return r - o > this._options.throttleDuration ? (this._throttlers.set(s.id, r), !1) : !0; | ||
} : this._throttle = () => !1; | ||
} | ||
emit(e) { | ||
if (this._throttle(e)) | ||
return h.Resolved(e); | ||
const o = this._subscribers.slice().map((c) => c(e)).filter((c) => !!c); | ||
if (!o.length) | ||
throw new b("Unable to handle the emitted alert properly. There wasn't found any supported subscribers."); | ||
if (o.length > 1) | ||
throw new b("Unable to handle the emitted alert properly. There were found too many supported subscribers."); | ||
return o[0]; | ||
} | ||
subscribe(e) { | ||
return this._subscribers.push(e), () => { | ||
const s = this._subscribers.indexOf(e); | ||
return this._subscribers.splice(s, 1)[0]; | ||
}; | ||
} | ||
}; | ||
u.VERSION = "1.2.2-rc.2"; | ||
let p = u, S; | ||
const H = (t) => { | ||
S = t; | ||
}, L = () => j() ? A(g.$vuert) : S, z = (t) => ({ | ||
install: ({ config: e, provide: s }) => { | ||
const r = new p(t); | ||
H(r), e.globalProperties.$vuert = r, s(g.$vuert, r); | ||
} | ||
}), w = () => { | ||
const t = L(); | ||
if (!t) | ||
throw new b( | ||
"`useVuert()` was called but there was not active Vuert. Did you forget to install `Vuert` plugin in your App?" | ||
); | ||
return t; | ||
}, G = /* @__PURE__ */ C({ | ||
const z = /* @__PURE__ */ D({ | ||
__name: "AlertHandler", | ||
@@ -133,43 +135,43 @@ props: { | ||
}, | ||
duration: { | ||
default: () => w().options.transitionDuration, | ||
type: [Number, Object], | ||
validator: (t) => t instanceof Object ? "enter" in t && "leave" in t ? isFinite(Number(t.enter)) && isFinite(Number(t.leave)) : !1 : isFinite(Number(t)) | ||
}, | ||
filter: { | ||
default: () => !0, | ||
type: Function | ||
}, | ||
transitionDuration: { | ||
default: () => _().options.transitionDuration, | ||
type: [Number, Object], | ||
validator: (t) => t instanceof Object ? "enter" in t && "leave" in t ? isFinite(Number(t.enter)) && isFinite(Number(t.leave)) : !1 : isFinite(Number(t)) | ||
} | ||
}, | ||
emits: { | ||
opening: (t) => t instanceof l, | ||
opened: (t) => t instanceof l, | ||
closing: (t) => t instanceof l, | ||
closed: (t) => t instanceof l | ||
opening: (t) => t instanceof c, | ||
opened: (t) => t instanceof c, | ||
closing: (t) => t instanceof c, | ||
closed: (t) => t instanceof c | ||
}, | ||
setup(t, { emit: e }) { | ||
const s = w(), r = t, o = e, c = [], n = N(), O = () => new Promise((i) => P(i)), m = async () => { | ||
const i = c[0]; | ||
i.onOpening(() => o("opening", i.alert)), i.onOpened(() => o("opened", i.alert)), i.onClosing(() => o("closing", i.alert)), i.onClosed(async () => { | ||
o("closed", i.alert), c.shift(), n.value = void 0, await O(), c.length > 0 && m(); | ||
}), n.value = i, await i.open(); | ||
}, x = (i) => { | ||
const d = new h(i, r.duration); | ||
return c.push(d), c.length === 1 && m(), d; | ||
const s = t, i = e, r = [], o = A(), l = async () => { | ||
const n = r[0]; | ||
n.onOpening(() => i("opening", n.alert)), n.onOpened(() => i("opened", n.alert)), n.onClosing(() => i("closing", n.alert)), n.onClosed(async () => { | ||
i("closed", n.alert), r.shift(), o.value = void 0, await U(), r.length > 0 && l(); | ||
}), o.value = n, await n.open(); | ||
}, y = (n) => { | ||
const d = new H(n, s.transitionDuration); | ||
return r.push(d), r.length === 1 && l(), d; | ||
}; | ||
let f; | ||
return V(() => { | ||
f = s.subscribe((i) => { | ||
if (r.filter(i)) | ||
return x(i); | ||
let p; | ||
return C(() => { | ||
p = _().subscribe((n) => { | ||
if (s.filter(n)) | ||
return y(n); | ||
}); | ||
}), k(() => f()), (i, d) => (F(), I(U(t.is), null, { | ||
default: $(() => [ | ||
n.value ? E(i.$slots, "default", { | ||
}), j(() => p()), (n, d) => (E(), N(V(t.is), null, { | ||
default: F(() => [ | ||
o.value ? I(n.$slots, "default", { | ||
key: 0, | ||
alert: n.value.alert, | ||
isOpen: n.value.isOpen.value, | ||
resolve: n.value.resolve, | ||
reject: n.value.reject | ||
}) : R("", !0) | ||
alert: o.value.alert, | ||
isOpen: o.value.isOpen.value, | ||
resolve: o.value.resolve, | ||
reject: o.value.reject | ||
}) : k("", !0) | ||
]), | ||
@@ -181,10 +183,10 @@ _: 3 | ||
export { | ||
y as Action, | ||
l as Alert, | ||
G as AlertHandler, | ||
h as Context, | ||
z as createVuert, | ||
p as default, | ||
w as useVuert | ||
g as Action, | ||
c as Alert, | ||
z as AlertHandler, | ||
H as Context, | ||
q as createVuert, | ||
b as default, | ||
_ as useVuert | ||
}; | ||
//# sourceMappingURL=vuert.js.map |
{ | ||
"name": "@byloth/vuert", | ||
"version": "1.2.2-rc.2", | ||
"version": "1.2.2-rc.3", | ||
"description": "The headless alerts, notifications & popups library for Vue.js craftsmen. ℹ", | ||
@@ -56,3 +56,3 @@ "keywords": [ | ||
"@byloth/exceptions": "^2.2.2", | ||
"vue": "^3.4.16" | ||
"vue": "^3.4.18" | ||
}, | ||
@@ -62,3 +62,3 @@ "devDependencies": { | ||
"@byloth/eslint-config-vue": "^2.6.8", | ||
"@types/node": "^20.11.16", | ||
"@types/node": "^20.11.17", | ||
"@typescript-eslint/eslint-plugin": "^6.21.0", | ||
@@ -70,7 +70,7 @@ "@typescript-eslint/parser": "^6.21.0", | ||
"typescript": "^5.3.3", | ||
"vite": "^5.1.0", | ||
"vite": "^5.1.1", | ||
"vue-eslint-parser": "^9.4.2", | ||
"vue-tsc": "^1.8.27" | ||
}, | ||
"gitHead": "7946297c0d91e7d129c87cc9f3c076452a512d40" | ||
"gitHead": "20b1482063721180ee2877c39e3a8cb78753a6a4" | ||
} |
@@ -10,3 +10,7 @@ import type { Component, PropType } from "vue"; | ||
}; | ||
duration: { | ||
filter: { | ||
default: () => boolean; | ||
type: PropType<(options: AlertOptions<unknown>) => boolean>; | ||
}; | ||
transitionDuration: { | ||
default: () => number | Duration; | ||
@@ -16,6 +20,2 @@ type: PropType<number | Duration>; | ||
}; | ||
filter: { | ||
default: () => boolean; | ||
type: PropType<(options: AlertOptions<unknown>) => boolean>; | ||
}; | ||
}, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, { | ||
@@ -31,3 +31,7 @@ opening: (alert: Alert<unknown>) => void; | ||
}; | ||
duration: { | ||
filter: { | ||
default: () => boolean; | ||
type: PropType<(options: AlertOptions<unknown>) => boolean>; | ||
}; | ||
transitionDuration: { | ||
default: () => number | Duration; | ||
@@ -37,6 +41,2 @@ type: PropType<number | Duration>; | ||
}; | ||
filter: { | ||
default: () => boolean; | ||
type: PropType<(options: AlertOptions<unknown>) => boolean>; | ||
}; | ||
}>> & { | ||
@@ -49,3 +49,3 @@ onOpening?: ((alert: Alert<unknown>) => any) | undefined; | ||
filter: (options: AlertOptions<unknown>) => boolean; | ||
duration: number | Duration; | ||
transitionDuration: number | Duration; | ||
is: string | Component; | ||
@@ -52,0 +52,0 @@ }, {}>, { |
@@ -18,10 +18,2 @@ import { computed, ref } from "vue"; | ||
{ | ||
public static Resolved<R>(options: AlertOptions<R>): Context<R | void> | ||
{ | ||
const context = new Context<R | void>(options, 0); | ||
context.resolve(); | ||
return context; | ||
} | ||
protected _duration: Duration; | ||
@@ -28,0 +20,0 @@ protected _timeoutId?: Timeout; |
@@ -1,5 +0,4 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { RuntimeException } from "@byloth/exceptions"; | ||
import { AlertThrottledException } from "./exceptions"; | ||
import { Context } from "./models/index.js"; | ||
@@ -15,3 +14,3 @@ | ||
useThrottling: boolean; | ||
throttleDuration: number; | ||
throttlingDuration: number; | ||
transitionDuration: number | Duration; | ||
@@ -23,3 +22,3 @@ } | ||
{ | ||
public static readonly VERSION: string = "1.2.2-rc.2"; | ||
public static readonly VERSION: string = "1.2.2-rc.3"; | ||
@@ -30,3 +29,3 @@ public static get DEFAULT_OPTS(): VuertOptions | ||
useThrottling: true, | ||
throttleDuration: 1000, | ||
throttlingDuration: 100, | ||
transitionDuration: 200 | ||
@@ -36,2 +35,3 @@ }; | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
protected _subscribers: VuertSubscriber<any>[]; | ||
@@ -64,3 +64,3 @@ protected _throttlers: Map<symbol, number>; | ||
if ((now - last) > this._options.throttleDuration) | ||
if ((now - last) > this._options.throttlingDuration) | ||
{ | ||
@@ -88,6 +88,8 @@ this._throttlers.set(alert.id, now); | ||
{ | ||
if (this._throttle(alert)) { return Context.Resolved(alert); } | ||
if (this._throttle(alert)) { throw new AlertThrottledException(alert); } | ||
const subscribers = this._subscribers.slice(); | ||
const contexts = subscribers.map((subscriber) => subscriber(alert)); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const results = contexts.filter((context) => !!(context)) as Context<any>[]; | ||
@@ -94,0 +96,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
97136
27
726
Updatedvue@^3.4.18