@aerogel/plugin-routing 0.1.1 → 0.1.2-next.32f939e7d49fc700848bfc8d6d8e7377371e954b
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/LICENSE +21 -0
- package/dist/aerogel-plugin-routing.d.ts +36 -3
- package/dist/aerogel-plugin-routing.js +246 -230
- package/dist/aerogel-plugin-routing.js.map +1 -1
- package/package.json +49 -43
- package/src/components/Page.vue +11 -3
- package/src/components/PageTitle.vue +14 -0
- package/src/components/index.ts +1 -0
- package/src/index.css +5 -0
- package/src/index.test.ts +12 -15
- package/src/index.ts +2 -3
- package/src/pages/NotFound.vue +0 -1
- package/src/services/Router.test.ts +33 -0
- package/src/services/Router.ts +30 -18
- package/src/testing/setup.ts +24 -0
- package/src/testing/stubs/models/Post.schema.ts +5 -0
- package/src/testing/stubs/models/Post.ts +9 -0
- package/src/utils/BindingNotFound.ts +0 -2
- package/src/utils/index.ts +1 -0
- package/src/utils/internal.ts +2 -3
- package/src/utils/routes.ts +11 -7
- package/src/utils/soukai.test.ts +71 -0
- package/src/utils/soukai.ts +33 -0
- package/src/utils/urls.ts +6 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Noel De Martin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -4,9 +4,11 @@ import { ComputedRef } from 'vue';
|
|
|
4
4
|
import { DefineComponent } from 'vue';
|
|
5
5
|
import { Facade } from '@noeldemartin/utils';
|
|
6
6
|
import { HTMLAttributes } from 'vue';
|
|
7
|
+
import { ModelConstructor } from 'soukai-bis';
|
|
7
8
|
import { Plugin as Plugin_2 } from '@aerogel/core';
|
|
8
9
|
import { PublicProps } from 'vue';
|
|
9
10
|
import { Ref } from 'vue';
|
|
11
|
+
import { RouteLocationNormalized } from 'vue-router';
|
|
10
12
|
import { RouteLocationNormalizedLoaded } from 'vue-router';
|
|
11
13
|
import { RouteLocationRaw } from 'vue-router';
|
|
12
14
|
import { RouteParams } from 'vue-router';
|
|
@@ -18,8 +20,16 @@ import { WatchStopHandle } from 'vue';
|
|
|
18
20
|
|
|
19
21
|
declare const __VLS_component: DefineComponent<__VLS_Props, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLElement>;
|
|
20
22
|
|
|
23
|
+
declare const __VLS_component_2: DefineComponent<__VLS_Props_2, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<__VLS_Props_2> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, false, {}, HTMLHeadingElement>;
|
|
24
|
+
|
|
21
25
|
declare type __VLS_Props = {
|
|
22
26
|
class?: HTMLAttributes['class'];
|
|
27
|
+
title?: string;
|
|
28
|
+
fullbleed?: boolean;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
declare type __VLS_Props_2 = {
|
|
32
|
+
class?: HTMLAttributes['class'];
|
|
23
33
|
};
|
|
24
34
|
|
|
25
35
|
declare function __VLS_template(): {
|
|
@@ -31,14 +41,31 @@ declare function __VLS_template(): {
|
|
|
31
41
|
rootEl: HTMLElement;
|
|
32
42
|
};
|
|
33
43
|
|
|
44
|
+
declare function __VLS_template_2(): {
|
|
45
|
+
attrs: Partial<{}>;
|
|
46
|
+
slots: {
|
|
47
|
+
default?(_: {}): any;
|
|
48
|
+
};
|
|
49
|
+
refs: {};
|
|
50
|
+
rootEl: HTMLHeadingElement;
|
|
51
|
+
};
|
|
52
|
+
|
|
34
53
|
declare type __VLS_TemplateResult = ReturnType<typeof __VLS_template>;
|
|
35
54
|
|
|
55
|
+
declare type __VLS_TemplateResult_2 = ReturnType<typeof __VLS_template_2>;
|
|
56
|
+
|
|
36
57
|
declare type __VLS_WithTemplateSlots<T, S> = T & {
|
|
37
58
|
new (): {
|
|
38
59
|
$slots: S;
|
|
39
60
|
};
|
|
40
61
|
};
|
|
41
62
|
|
|
63
|
+
declare type __VLS_WithTemplateSlots_2<T, S> = T & {
|
|
64
|
+
new (): {
|
|
65
|
+
$slots: S;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
42
69
|
export declare type AerogelRoute = RouteRecordRaw & {
|
|
43
70
|
title?: string | ((params: Record<string, unknown>) => string | undefined | null);
|
|
44
71
|
};
|
|
@@ -48,6 +75,8 @@ export declare class BindingNotFound {
|
|
|
48
75
|
constructor(value: string);
|
|
49
76
|
}
|
|
50
77
|
|
|
78
|
+
export declare function bindingNotFound(slug: string): BindingNotFound;
|
|
79
|
+
|
|
51
80
|
declare const _default: ServiceWithState< {
|
|
52
81
|
flashRoute: RouteLocationRaw | null;
|
|
53
82
|
}, {}, Partial<{
|
|
@@ -73,7 +102,9 @@ export declare interface Options {
|
|
|
73
102
|
|
|
74
103
|
export declare const Page: __VLS_WithTemplateSlots<typeof __VLS_component, __VLS_TemplateResult["slots"]>;
|
|
75
104
|
|
|
76
|
-
export declare
|
|
105
|
+
export declare const PageTitle: __VLS_WithTemplateSlots_2<typeof __VLS_component_2, __VLS_TemplateResult_2["slots"]>;
|
|
106
|
+
|
|
107
|
+
export declare type RouteBinding = ModelConstructor | ((slug: string, params: Record<string, unknown>) => unknown);
|
|
77
108
|
|
|
78
109
|
export declare type RouteBindings = Record<string, RouteBinding>;
|
|
79
110
|
|
|
@@ -92,16 +123,18 @@ export declare class RouterService extends _default {
|
|
|
92
123
|
}): void;
|
|
93
124
|
protected boot(): Promise<void>;
|
|
94
125
|
protected __get(property: string): unknown;
|
|
95
|
-
protected onEnterRoute(
|
|
126
|
+
protected onEnterRoute(route: RouteLocationNormalized): Promise<void>;
|
|
96
127
|
protected handleStatic404Redirect(): void;
|
|
97
128
|
protected storeFlashRoute(): void;
|
|
98
129
|
protected restoreFlashRoute(): Promise<void>;
|
|
99
|
-
protected resolveBinding(
|
|
130
|
+
protected resolveBinding(route: RouteLocationNormalized, name: string, value: RouteParamValue | RouteParamValue[]): Promise<Ref<unknown>>;
|
|
100
131
|
}
|
|
101
132
|
|
|
102
133
|
export declare interface RouterService extends Omit<Router_2, 'currentRoute'> {
|
|
103
134
|
}
|
|
104
135
|
|
|
136
|
+
export declare function routeUrl(route: RouteLocationRaw): URL;
|
|
137
|
+
|
|
105
138
|
declare function routing(options: Options): Plugin_2;
|
|
106
139
|
export default routing;
|
|
107
140
|
|
|
@@ -1,244 +1,260 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
set: () => console.warn("Computed models ref was not set (it is immutable).")
|
|
24
|
-
};
|
|
25
|
-
});
|
|
1
|
+
import { App as e, Events as t, Link as n, UI as r, bootServices as i, classes as a, computedAsync as o, defineServiceState as s, setMarkdownRouter as c } from "@aerogel/core";
|
|
2
|
+
import l from "virtual:aerogel";
|
|
3
|
+
import { RouterLink as u, createRouter as ee, createWebHistory as te, useRoute as d } from "vue-router";
|
|
4
|
+
import { Storage as f, facade as p, memo as ne, objectOnly as m, objectWithout as h, once as g, tap as re } from "@noeldemartin/utils";
|
|
5
|
+
import { computed as _, createBlock as v, createCommentVNode as y, createElementBlock as b, createElementVNode as ie, createTextVNode as x, createVNode as ae, customRef as S, defineComponent as C, h as w, normalizeClass as T, openBlock as E, ref as oe, renderSlot as D, resolveComponent as se, shallowRef as O, toDisplayString as k, unref as A, watch as j, watchEffect as M, withCtx as N } from "vue";
|
|
6
|
+
import { computedModel as P, findTrackedModel as F, getTrackedModels as I, loadTrackedModels as L } from "@aerogel/plugin-solid";
|
|
7
|
+
import { isModelClass as R } from "soukai-bis";
|
|
8
|
+
//#region src/utils/internal.ts
|
|
9
|
+
function z(e, t) {
|
|
10
|
+
return S((n, r) => {
|
|
11
|
+
let i = h($.routesParams.value[e] ?? {}, t);
|
|
12
|
+
return j($.routesParams, () => {
|
|
13
|
+
let n = h($.routesParams.value[e] ?? {}, t);
|
|
14
|
+
for (let [e, t] of Object.entries(n)) if (t === i[e]) {
|
|
15
|
+
i = n, r();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
}), {
|
|
19
|
+
get: () => re(i, () => n()),
|
|
20
|
+
set: () => console.warn("Computed models ref was not set (it is immutable).")
|
|
21
|
+
};
|
|
22
|
+
});
|
|
26
23
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
[t]: {
|
|
75
|
-
...this.routesParams.value[t],
|
|
76
|
-
[a]: B
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}), o[a] = v.value;
|
|
80
|
-
}
|
|
81
|
-
this.history = this.history.slice(0, 3), this.history.unshift(t);
|
|
82
|
-
const n = {
|
|
83
|
-
...this.routesParams.value,
|
|
84
|
-
[t]: {
|
|
85
|
-
...o,
|
|
86
|
-
...this.routesParams.value[t] ?? {}
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
for (const a in n)
|
|
90
|
-
this.history.includes(a) || (i = this.routesStopWatchers[a]) == null || i.forEach((m) => m());
|
|
91
|
-
this.routesParams.value = d(n, this.history), this.routesStopWatchers = d(this.routesStopWatchers, this.history);
|
|
92
|
-
}
|
|
93
|
-
handleStatic404Redirect() {
|
|
94
|
-
const t = oe.pull("static-404-redirect");
|
|
95
|
-
t && this.replace(t);
|
|
96
|
-
}
|
|
97
|
-
storeFlashRoute() {
|
|
98
|
-
this.flashRoute = d(this.currentRoute.value, [
|
|
99
|
-
"path",
|
|
100
|
-
"query",
|
|
101
|
-
"hash"
|
|
102
|
-
]);
|
|
103
|
-
}
|
|
104
|
-
async restoreFlashRoute() {
|
|
105
|
-
if (!this.flashRoute)
|
|
106
|
-
return;
|
|
107
|
-
const t = this.flashRoute;
|
|
108
|
-
l.whenReady(() => this.replace(t)), this.flashRoute = null;
|
|
109
|
-
}
|
|
110
|
-
async resolveBinding(t, r, o) {
|
|
111
|
-
const n = this.bindings[r];
|
|
112
|
-
if (Array.isArray(o) || !n)
|
|
113
|
-
return H(o);
|
|
114
|
-
await l.ready;
|
|
115
|
-
const i = ne(t, r), a = j(() => Promise.resolve(n(o, i.value)));
|
|
116
|
-
return ee(() => a.value);
|
|
117
|
-
}
|
|
24
|
+
//#endregion
|
|
25
|
+
//#region src/components/Page.vue
|
|
26
|
+
var B = /* @__PURE__ */ C({
|
|
27
|
+
__name: "Page",
|
|
28
|
+
props: {
|
|
29
|
+
class: { type: [
|
|
30
|
+
Boolean,
|
|
31
|
+
null,
|
|
32
|
+
String,
|
|
33
|
+
Object,
|
|
34
|
+
Array
|
|
35
|
+
] },
|
|
36
|
+
title: {},
|
|
37
|
+
fullbleed: { type: Boolean }
|
|
38
|
+
},
|
|
39
|
+
setup(e) {
|
|
40
|
+
let t = _(() => a("mx-auto flex w-full grow flex-col px-edge py-8", e.fullbleed || "max-w-screen-content", e.class));
|
|
41
|
+
return (n, r) => {
|
|
42
|
+
let i = se("PageTitle");
|
|
43
|
+
return E(), b("main", { class: T(t.value) }, [e.title ? (E(), v(i, { key: 0 }, {
|
|
44
|
+
default: N(() => [x(k(e.title), 1)]),
|
|
45
|
+
_: 1
|
|
46
|
+
})) : y("", !0), D(n.$slots, "default")], 2);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}), V = { class: "text-2xl font-bold" }, H = /* @__PURE__ */ C({
|
|
50
|
+
__name: "NotFound",
|
|
51
|
+
setup(e) {
|
|
52
|
+
return (e, t) => (E(), v(B, { class: "items-center justify-center" }, {
|
|
53
|
+
default: N(() => [ie("h2", V, k(e.$td("notFound.title", "404: Not Found")), 1), ae(A(n), { route: "home" }, {
|
|
54
|
+
default: N(() => [x(k(e.$td("notFound.home", "Go home")), 1)]),
|
|
55
|
+
_: 1
|
|
56
|
+
})]),
|
|
57
|
+
_: 1
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
}), U = class {
|
|
61
|
+
value;
|
|
62
|
+
constructor(e) {
|
|
63
|
+
this.value = e;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/utils/routes.ts
|
|
68
|
+
function W(e, t) {
|
|
69
|
+
let n = d(), r = _(() => $.routesParams?.value[n.path]), i = _(() => !t?.title || !r.value ? null : typeof t.title == "string" ? t.title : t.title(r.value));
|
|
70
|
+
return M(() => ue(i.value)), () => Object.values(r.value ?? {}).some((e) => e instanceof U) ? w(H) : w(e, r.value);
|
|
118
71
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
constructor(s) {
|
|
122
|
-
this.value = s;
|
|
123
|
-
}
|
|
72
|
+
function G(e, t) {
|
|
73
|
+
return C({ setup: () => W(e, t) });
|
|
124
74
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
}), le = { class: "text-2xl font-bold" }, F = /* @__PURE__ */ p({
|
|
139
|
-
__name: "NotFound",
|
|
140
|
-
setup(e) {
|
|
141
|
-
return (s, t) => (x(), K(ce, { class: "items-center justify-center" }, {
|
|
142
|
-
default: y(() => [
|
|
143
|
-
Q("h2", le, g(s.$td("notFound.title", "404: Not Found")), 1),
|
|
144
|
-
X(N(V), { route: "home" }, {
|
|
145
|
-
default: y(() => [
|
|
146
|
-
Y(g(s.$td("notFound.home", "Go home")), 1)
|
|
147
|
-
]),
|
|
148
|
-
_: 1
|
|
149
|
-
})
|
|
150
|
-
]),
|
|
151
|
-
_: 1
|
|
152
|
-
}));
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
function he(e, s) {
|
|
156
|
-
const t = z(), r = h(() => {
|
|
157
|
-
var n;
|
|
158
|
-
return (n = c.routesParams) == null ? void 0 : n.value[t.path];
|
|
159
|
-
}), o = h(() => !(s != null && s.title) || !r.value ? null : typeof s.title == "string" ? s.title : s.title(r.value));
|
|
160
|
-
return Z(() => de(o.value)), () => Object.values(r.value ?? {}).some((n) => n instanceof ie) ? b(F) : b(e, r.value);
|
|
75
|
+
function ce(e) {
|
|
76
|
+
if (e.component) {
|
|
77
|
+
if (typeof e.component == "function") {
|
|
78
|
+
let t = e.component;
|
|
79
|
+
e.component = async () => {
|
|
80
|
+
let { default: n } = await t();
|
|
81
|
+
return G(n, e);
|
|
82
|
+
};
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
e.component = G(e.component, e);
|
|
86
|
+
}
|
|
161
87
|
}
|
|
162
|
-
function
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
88
|
+
function K(t) {
|
|
89
|
+
return async function(...n) {
|
|
90
|
+
return await e.ready, t.call(this, ...n);
|
|
91
|
+
};
|
|
166
92
|
}
|
|
167
|
-
function
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
return;
|
|
176
|
-
}
|
|
177
|
-
e.component = _(e.component, e);
|
|
178
|
-
}
|
|
93
|
+
function le(e) {
|
|
94
|
+
if (e.beforeEnter) {
|
|
95
|
+
if (Array.isArray(e.beforeEnter)) {
|
|
96
|
+
e.beforeEnter = e.beforeEnter.map(K);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
e.beforeEnter = K(e.beforeEnter);
|
|
100
|
+
}
|
|
179
101
|
}
|
|
180
|
-
function
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
102
|
+
function ue(t) {
|
|
103
|
+
if (globalThis.document) {
|
|
104
|
+
if (!t) {
|
|
105
|
+
globalThis.document.title = e.name;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
globalThis.document.title = `${t} | ${e.name}`;
|
|
109
|
+
}
|
|
184
110
|
}
|
|
185
|
-
function
|
|
186
|
-
|
|
187
|
-
if (Array.isArray(e.beforeEnter)) {
|
|
188
|
-
e.beforeEnter = e.beforeEnter.map(w);
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
e.beforeEnter = w(e.beforeEnter);
|
|
192
|
-
}
|
|
111
|
+
function q(e) {
|
|
112
|
+
return ce(e), le(e), e;
|
|
193
113
|
}
|
|
194
114
|
function de(e) {
|
|
195
|
-
|
|
196
|
-
if (!e) {
|
|
197
|
-
globalThis.document.title = l.name;
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
globalThis.document.title = `${e} | ${l.name}`;
|
|
201
|
-
}
|
|
115
|
+
return e;
|
|
202
116
|
}
|
|
203
|
-
function
|
|
204
|
-
|
|
117
|
+
function J(e) {
|
|
118
|
+
let t = e.map(q);
|
|
119
|
+
return t.some((e) => e.name === "not-found" || e.name === "404") || t.push(q({
|
|
120
|
+
name: "not-found",
|
|
121
|
+
path: "/:path(.*)*",
|
|
122
|
+
component: H
|
|
123
|
+
})), t;
|
|
205
124
|
}
|
|
206
|
-
function
|
|
207
|
-
|
|
125
|
+
function Y(e) {
|
|
126
|
+
return ne(`binding-not-found-${e}`, () => new U(e));
|
|
208
127
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
name: "not-found",
|
|
214
|
-
path: "/:path(.*)*",
|
|
215
|
-
component: F
|
|
216
|
-
})
|
|
217
|
-
), s;
|
|
128
|
+
//#endregion
|
|
129
|
+
//#region src/utils/soukai.ts
|
|
130
|
+
function X(e, t, n) {
|
|
131
|
+
return I(e).find((e) => n && e.url === n || e.getSlug() === t);
|
|
218
132
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
routes: e.routes,
|
|
225
|
-
history: M(e.basePath ?? W.basePath)
|
|
226
|
-
});
|
|
227
|
-
O.registerComponent("router-link", q), c.use(t, e), s.use(t), C({
|
|
228
|
-
resolve: (r) => t.resolve({ name: r }).href,
|
|
229
|
-
visit: async (r) => void await t.push({ name: r })
|
|
230
|
-
}), await G(s, pe);
|
|
231
|
-
}
|
|
232
|
-
};
|
|
133
|
+
async function Z(e, t, n) {
|
|
134
|
+
let r = typeof n?.query?.url == "string" ? n.query.url : null, i = X(e, t, r);
|
|
135
|
+
if (i) return i;
|
|
136
|
+
let a = await F(e, r ?? e.urlFromSlug(t));
|
|
137
|
+
return a && (r || a.getSlug() === t) ? a : (await L(e), X(e, t, r) ?? Y(t));
|
|
233
138
|
}
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region src/services/Router.state.ts
|
|
141
|
+
var fe = s({
|
|
142
|
+
name: "router",
|
|
143
|
+
initialState: { flashRoute: null },
|
|
144
|
+
persist: ["flashRoute"]
|
|
145
|
+
}), Q = class extends fe {
|
|
146
|
+
currentRoute;
|
|
147
|
+
routesParams;
|
|
148
|
+
router;
|
|
149
|
+
bindings;
|
|
150
|
+
history;
|
|
151
|
+
routesStopWatchers;
|
|
152
|
+
constructor() {
|
|
153
|
+
super(), this.router = O(null), this.bindings = {}, this.history = [], this.routesStopWatchers = {}, this.routesParams = O({}), this.currentRoute = _(() => {
|
|
154
|
+
let e = this.router.value, t = this.routesParams.value;
|
|
155
|
+
if (!e) return null;
|
|
156
|
+
let n = A(e.currentRoute);
|
|
157
|
+
return {
|
|
158
|
+
...n,
|
|
159
|
+
params: t?.[n.path],
|
|
160
|
+
rawParams: n.params
|
|
161
|
+
};
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
use(e, t = {}) {
|
|
165
|
+
this.router.value = e, this.bindings = t.bindings ?? {}, e.beforeEach(g(() => this.handleStatic404Redirect())), e.beforeEach((e) => this.onEnterRoute(e));
|
|
166
|
+
}
|
|
167
|
+
async boot() {
|
|
168
|
+
t.on("auth:before-login", () => this.storeFlashRoute()), t.on("auth:login", () => this.restoreFlashRoute()), t.on("purge-storage", () => this.push({ name: "home" }));
|
|
169
|
+
}
|
|
170
|
+
__get(e) {
|
|
171
|
+
return this.router.value ? super.__get(e) ?? Reflect.get(this.router.value, e) : super.__get(e);
|
|
172
|
+
}
|
|
173
|
+
async onEnterRoute(e) {
|
|
174
|
+
let { path: t, params: n } = e;
|
|
175
|
+
if (t in this.routesParams.value) return;
|
|
176
|
+
let r = { ...n }, i = [];
|
|
177
|
+
for (let [a, o] of Object.entries(n)) {
|
|
178
|
+
let n = await this.resolveBinding(e, a, o), s = j(n, (e) => {
|
|
179
|
+
this.routesParams.value = {
|
|
180
|
+
...this.routesParams.value,
|
|
181
|
+
[t]: {
|
|
182
|
+
...this.routesParams.value[t],
|
|
183
|
+
[a]: e
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
});
|
|
187
|
+
i.push(s), r[a] = n.value;
|
|
188
|
+
}
|
|
189
|
+
this.history = this.history.slice(0, 3), this.history.unshift(t);
|
|
190
|
+
let a = {
|
|
191
|
+
...this.routesParams.value,
|
|
192
|
+
[t]: {
|
|
193
|
+
...r,
|
|
194
|
+
...this.routesParams.value[t]
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
for (let e in a) this.history.includes(e) || this.routesStopWatchers[e]?.forEach((e) => e());
|
|
198
|
+
this.routesParams.value = m(a, this.history), this.routesStopWatchers = m(this.routesStopWatchers, this.history);
|
|
199
|
+
}
|
|
200
|
+
handleStatic404Redirect() {
|
|
201
|
+
let e = f.pull("static-404-redirect");
|
|
202
|
+
e && this.replace(e);
|
|
203
|
+
}
|
|
204
|
+
storeFlashRoute() {
|
|
205
|
+
this.flashRoute = m(this.currentRoute.value, [
|
|
206
|
+
"path",
|
|
207
|
+
"query",
|
|
208
|
+
"hash"
|
|
209
|
+
]);
|
|
210
|
+
}
|
|
211
|
+
async restoreFlashRoute() {
|
|
212
|
+
if (!this.flashRoute) return;
|
|
213
|
+
let t = this.flashRoute;
|
|
214
|
+
e.whenReady(() => this.replace(t)), this.flashRoute = null;
|
|
215
|
+
}
|
|
216
|
+
async resolveBinding(t, n, r) {
|
|
217
|
+
let i = this.bindings[n];
|
|
218
|
+
if (Array.isArray(r) || !i) return oe(r);
|
|
219
|
+
await e.ready;
|
|
220
|
+
let a = z(t.path, n), s = R(i) ? await Z(i, r, t) : void 0, c = R(i) ? o(() => Z(i, r, t)) : o(() => Promise.resolve(i(r, a.value)));
|
|
221
|
+
return P(() => c.value ?? s);
|
|
222
|
+
}
|
|
223
|
+
}, $ = p(Q);
|
|
224
|
+
//#endregion
|
|
225
|
+
//#region src/utils/urls.ts
|
|
226
|
+
function pe(e) {
|
|
227
|
+
return new URL($.resolve(e).href, location.origin);
|
|
228
|
+
}
|
|
229
|
+
//#endregion
|
|
230
|
+
//#region src/components/PageTitle.vue
|
|
231
|
+
var me = /* @__PURE__ */ C({
|
|
232
|
+
__name: "PageTitle",
|
|
233
|
+
props: { class: { type: [
|
|
234
|
+
Boolean,
|
|
235
|
+
null,
|
|
236
|
+
String,
|
|
237
|
+
Object,
|
|
238
|
+
Array
|
|
239
|
+
] } },
|
|
240
|
+
setup(e) {
|
|
241
|
+
let t = _(() => a("text-page-title text-slate-900", e.class));
|
|
242
|
+
return (e, n) => (E(), b("h1", { class: T(t.value) }, [D(e.$slots, "default")], 2));
|
|
243
|
+
}
|
|
244
|
+
}), he = { $router: $ };
|
|
245
|
+
function ge(e) {
|
|
246
|
+
return { async install(t) {
|
|
247
|
+
let n = ee({
|
|
248
|
+
routes: e.routes,
|
|
249
|
+
history: te(e.basePath ?? l.basePath)
|
|
250
|
+
});
|
|
251
|
+
r.registerComponent("router-link", u), $.use(n, e), t.use(n), c({
|
|
252
|
+
resolve: (e) => n.resolve({ name: e }).href,
|
|
253
|
+
visit: async (e) => void await n.push({ name: e })
|
|
254
|
+
}), await i(t, he);
|
|
255
|
+
} };
|
|
256
|
+
}
|
|
257
|
+
//#endregion
|
|
258
|
+
export { U as BindingNotFound, B as Page, me as PageTitle, $ as Router, Q as RouterService, Y as bindingNotFound, ge as default, q as defineRoute, de as defineRouteBindings, J as defineRoutes, pe as routeUrl };
|
|
259
|
+
|
|
260
|
+
//# sourceMappingURL=aerogel-plugin-routing.js.map
|