Skip to content

Commit 6a1a727

Browse files
committed
ofcourse I forgot the Vue 3 plugin ... 1.2.0 RC
1 parent d515650 commit 6a1a727

File tree

3 files changed

+75
-64
lines changed

3 files changed

+75
-64
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [v1.2.0] - 2024-12-12
11+
12+
### Added
13+
- Vue 3 plugin.
14+
1015
## [v1.1.0] - 2024-12-12
1116

1217
### Added

dist/index.js

+61-61
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
var O = (e) => {
2-
throw TypeError(e);
1+
var C = (t) => {
2+
throw TypeError(t);
33
};
4-
var C = (e, t, s) => t.has(e) || O("Cannot " + s);
5-
var o = (e, t, s) => (C(e, t, "read from private field"), s ? s.call(e) : t.get(e)), y = (e, t, s) => t.has(e) ? O("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(e) : t.set(e, s), $ = (e, t, s, n) => (C(e, t, "write to private field"), n ? n.call(e, s) : t.set(e, s), s);
4+
var j = (t, e, s) => e.has(t) || C("Cannot " + s);
5+
var o = (t, e, s) => (j(t, e, "read from private field"), s ? s.call(t) : e.get(t)), y = (t, e, s) => e.has(t) ? C("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(t) : e.set(t, s), $ = (t, e, s, n) => (j(t, e, "write to private field"), n ? n.call(t, s) : e.set(t, s), s);
66
import { z as r } from "zod";
7-
import { parse as P, stringify as D } from "qs";
7+
import { parse as D, stringify as N } from "qs";
88
r.record(r.string(), r.boolean());
9-
const j = r.union([r.string(), r.number(), r.boolean()]), x = r.record(
9+
const _ = r.union([r.string(), r.number(), r.boolean()]), x = r.record(
1010
r.unknown(),
11-
j
12-
), N = r.object({
11+
_
12+
), Q = r.object({
1313
_query: r.record(
1414
x.keySchema,
15-
x.valueSchema.or(r.array(j))
15+
x.valueSchema.or(r.array(_))
1616
).optional()
1717
});
1818
r.intersection(
1919
x,
20-
N
20+
Q
2121
);
22-
const Q = r.object({
22+
const V = r.object({
2323
uri: r.string(),
2424
domain: r.string().nullable(),
2525
wheres: x
@@ -28,24 +28,24 @@ r.object({
2828
substituted: r.array(r.string()),
2929
url: r.string()
3030
});
31-
const V = r.record(r.string(), Q), A = r.object({
31+
const A = r.record(r.string(), V), F = r.object({
3232
base: r.string(),
3333
defaults: x,
34-
routes: V
35-
}), _ = (e) => typeof e == "string" || e instanceof String, k = (e) => e == null ? !0 : (_(e) || (e = String(e)), e.trim().length === 0), R = (e) => e.replace(/\/+$/, ""), F = (e) => {
36-
const t = e.indexOf("?"), s = t > -1;
34+
routes: A
35+
}), E = (t) => typeof t == "string" || t instanceof String, k = (t) => t == null ? !0 : (E(t) || (t = String(t)), t.trim().length === 0), R = (t) => t.replace(/\/+$/, ""), I = (t) => {
36+
const e = t.indexOf("?"), s = e > -1;
3737
return {
38-
location: e.substring(0, s ? t : e.length),
39-
query: e.substring(s ? t + 1 : e.length)
38+
location: t.substring(0, s ? e : t.length),
39+
query: t.substring(s ? e + 1 : t.length)
4040
};
4141
};
4242
var d, a, g;
43-
class I {
44-
constructor(t, s, n) {
43+
class W {
44+
constructor(e, s, n) {
4545
y(this, d);
4646
y(this, a);
4747
y(this, g);
48-
$(this, d, t), $(this, a, s), $(this, g, n);
48+
$(this, d, e), $(this, a, s), $(this, g, n);
4949
}
5050
/**
5151
* Retruns the route's origin
@@ -61,32 +61,32 @@ class I {
6161
* Retruns the route's template
6262
*/
6363
get template() {
64-
const t = R(`${this.origin}/${o(this, a).uri}`);
65-
return k(t) ? "/" : t;
64+
const e = R(`${this.origin}/${o(this, a).uri}`);
65+
return k(e) ? "/" : e;
6666
}
6767
/**
6868
* Retruns the route's template expected parameters
6969
*/
7070
get expects() {
71-
const t = {}, s = this.template.match(/{\w+\??}/g) ?? [];
71+
const e = {}, s = this.template.match(/{\w+\??}/g) ?? [];
7272
for (const n of s) {
7373
const h = n.replace(/\W/g, "");
74-
t[h] = n.includes("?") || (t[h] ?? !1);
74+
e[h] = n.includes("?") || (e[h] ?? !1);
7575
}
76-
return t;
76+
return e;
7777
}
7878
/**
7979
* Return the compiled URI for this route, along with an array of substituted tokens.
8080
*/
81-
compile(t) {
81+
compile(e) {
8282
var l;
8383
const s = new Array(), n = this.expects, h = Object.keys(n);
8484
if (h.length < 1)
8585
return { substituted: s, url: this.template };
8686
let f = this.template;
8787
for (const i of h) {
8888
const S = n[i];
89-
let c = (t == null ? void 0 : t[i]) ?? ((l = o(this, g).config.defaults) == null ? void 0 : l[i]) ?? "";
89+
let c = (e == null ? void 0 : e[i]) ?? ((l = o(this, g).config.defaults) == null ? void 0 : l[i]) ?? "";
9090
typeof c == "boolean" && (c = c ? 1 : 0);
9191
const b = String(c);
9292
if (!S) {
@@ -122,12 +122,12 @@ class I {
122122
/**
123123
* Determine if the current route template matches the given URL.
124124
*/
125-
matches(t) {
125+
matches(e) {
126126
var b;
127127
const s = /^[a-z]*:\/\//i;
128128
let n = this.template;
129-
(b = o(this, a).domain) != null && b.includes("{") ? t = t.replace(s, "") : (t = t.replace(/^[a-z]*:\/\/([a-z]*\.?)*/i, ""), t += t.startsWith("/") ? "" : "/", n = n.replace(/^[a-z]*:\/\/([a-z]*\.?)*/i, ""), n += n.startsWith("/") ? "" : "/");
130-
const { location: h, query: f } = F(t), l = /[/\\^$.|?*+()[\]{}]/g, i = /\\{(\w+)(\\\?)?\\}/g, S = n.replace(s, "").replace(l, "\\$&").replace(i, (m, p, w) => {
129+
(b = o(this, a).domain) != null && b.includes("{") ? e = e.replace(s, "") : (e = e.replace(/^[a-z]*:\/\/([a-z]*\.?)*/i, ""), e += e.startsWith("/") ? "" : "/", n = n.replace(/^[a-z]*:\/\/([a-z]*\.?)*/i, ""), n += n.startsWith("/") ? "" : "/");
130+
const { location: h, query: f } = I(e), l = /[/\\^$.|?*+()[\]{}]/g, i = /\\{(\w+)(\\\?)?\\}/g, S = n.replace(s, "").replace(l, "\\$&").replace(i, (m, p, w) => {
131131
const z = o(this, a).wheres[p] ?? "[^/]+";
132132
return `${w ? "?" : ""}(?<${p}>${z})${w ? "?" : ""}`;
133133
}), c = new RegExp(`^${S}/?$`).exec(h);
@@ -141,40 +141,40 @@ class I {
141141
}
142142
return {
143143
...c.groups,
144-
_query: P(f)
144+
_query: D(f)
145145
};
146146
}
147147
}
148148
d = new WeakMap(), a = new WeakMap(), g = new WeakMap();
149-
const E = () => ({
149+
const P = () => ({
150150
addQueryPrefix: !0,
151-
encoder: (e, t, s, n) => n === "value" && typeof e == "boolean" ? e ? 1 : 0 : t(e),
151+
encoder: (t, e, s, n) => n === "value" && typeof t == "boolean" ? t ? 1 : 0 : e(t),
152152
encodeValuesOnly: !0,
153153
skipNulls: !0
154-
}), W = () => ({
154+
}), J = () => ({
155155
absolute: !1,
156156
strict: !1,
157-
qsConfig: E(),
157+
qsConfig: P(),
158158
base: "/",
159159
defaults: {},
160160
routes: {}
161-
}), J = (e) => A.parse(JSON.parse(e));
161+
}), L = (t) => F.parse(JSON.parse(t));
162162
var u;
163-
class L {
164-
constructor(t) {
165-
y(this, u, W());
166-
this.config = t ?? {};
163+
class M {
164+
constructor(e) {
165+
y(this, u, J());
166+
this.config = e ?? {};
167167
}
168168
get config() {
169169
return o(this, u);
170170
}
171-
set config(t) {
172-
t = _(t) ? J(t) : t, $(this, u, {
171+
set config(e) {
172+
e = E(e) ? L(e) : e, $(this, u, {
173173
...o(this, u),
174-
...t,
174+
...e,
175175
qsConfig: {
176-
...E(),
177-
...(t == null ? void 0 : t.qsConfig) ?? {}
176+
...P(),
177+
...(e == null ? void 0 : e.qsConfig) ?? {}
178178
}
179179
});
180180
}
@@ -184,34 +184,34 @@ class L {
184184
get origin() {
185185
return o(this, u).absolute ? this.base : "";
186186
}
187-
has(t) {
188-
return Object.hasOwn(o(this, u).routes, t);
187+
has(e) {
188+
return Object.hasOwn(o(this, u).routes, e);
189189
}
190-
compile(t, s) {
191-
const n = this.getRoute(t), { substituted: h, url: f } = n.compile(s), l = s._query ?? {};
190+
compile(e, s) {
191+
const n = this.getRoute(e), { substituted: h, url: f } = n.compile(s), l = s._query ?? {};
192192
delete s._query;
193193
for (const i of Object.keys(s))
194194
h.includes(i) || (Object.hasOwn(l, i) && console.warn(`Duplicate "${i}" in params and params.query may cause issues`), l[i] = s[i]);
195-
return f + D(l, o(this, u).qsConfig);
195+
return f + N(l, o(this, u).qsConfig);
196196
}
197-
getRoute(t) {
198-
if (!this.has(t))
199-
throw new Error(`No such route "${t}" in the route list`);
200-
return new I(t, o(this, u).routes[t], this);
197+
getRoute(e) {
198+
if (!this.has(e))
199+
throw new Error(`No such route "${e}" in the route list`);
200+
return new W(e, o(this, u).routes[e], this);
201201
}
202202
}
203203
u = new WeakMap();
204-
const q = new L(), T = (e) => (q.config = e ?? {}, q.config), M = (e, t) => q.compile(e, t ?? {}), Z = (e) => q.has(e), G = {
205-
install(e) {
206-
e.mixin({
207-
methods: { route: M }
208-
});
204+
const q = new M(), T = (t) => (q.config = t ?? {}, q.config), O = (t, e) => q.compile(t, e ?? {}), Z = (t) => q.has(t), G = {
205+
install(t) {
206+
Number(t.version.split(".")[0]) < 3 ? t.mixin({
207+
methods: { route: O }
208+
}) : (t.config.globalProperties.route = O, t.provide("route", O));
209209
}
210210
};
211211
export {
212-
L as Router,
212+
M as Router,
213213
G as ZigliteVuePlugin,
214214
T as configureRouter,
215215
Z as hasRoute,
216-
M as route
216+
O as route
217217
};

js/index.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ export { Router } from "@/classes/Router";
4242

4343
export const ZigliteVuePlugin = {
4444
install(app: App) {
45-
app.mixin({
46-
methods: { route, },
47-
});
45+
const version = Number(app.version.split('.')[0])
46+
if (version < 3) {
47+
app.mixin({
48+
methods: { route, },
49+
});
50+
} else {
51+
app.config.globalProperties.route = route;
52+
app.provide('route', route);
53+
}
4854
},
4955
};

0 commit comments

Comments
 (0)