@vielzeug/wayfinder 2.1.0 → 3.0.0
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 +3 -41
- package/dist/compile.cjs +1 -1
- package/dist/compile.cjs.map +1 -1
- package/dist/compile.d.ts +4 -4
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +2 -5
- package/dist/compile.js.map +1 -1
- package/dist/context.cjs +1 -1
- package/dist/context.cjs.map +1 -1
- package/dist/context.d.ts +6 -7
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +19 -18
- package/dist/context.js.map +1 -1
- package/dist/guards.cjs +1 -1
- package/dist/guards.cjs.map +1 -1
- package/dist/guards.js +1 -1
- package/dist/guards.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/path.cjs +1 -1
- package/dist/path.cjs.map +1 -1
- package/dist/path.d.ts +4 -5
- package/dist/path.d.ts.map +1 -1
- package/dist/path.js +1 -10
- package/dist/path.js.map +1 -1
- package/dist/router.cjs +1 -1
- package/dist/router.cjs.map +1 -1
- package/dist/router.d.ts +14 -22
- package/dist/router.d.ts.map +1 -1
- package/dist/router.js +179 -227
- package/dist/router.js.map +1 -1
- package/dist/types.d.ts +27 -39
- package/dist/types.d.ts.map +1 -1
- package/dist/wayfinder.cjs +1 -1
- package/dist/wayfinder.cjs.map +1 -1
- package/dist/wayfinder.iife.js +1 -1
- package/dist/wayfinder.iife.js.map +1 -1
- package/dist/wayfinder.js +1 -1
- package/dist/wayfinder.js.map +1 -1
- package/package.json +7 -18
- package/dist/devtools.cjs +0 -2
- package/dist/devtools.cjs.map +0 -1
- package/dist/devtools.d.ts +0 -47
- package/dist/devtools.d.ts.map +0 -1
- package/dist/devtools.js +0 -13
- package/dist/devtools.js.map +0 -1
- package/dist/hydration.cjs +0 -2
- package/dist/hydration.cjs.map +0 -1
- package/dist/hydration.d.ts +0 -7
- package/dist/hydration.d.ts.map +0 -1
- package/dist/hydration.js +0 -55
- package/dist/hydration.js.map +0 -1
- package/dist/preload.cjs +0 -2
- package/dist/preload.cjs.map +0 -1
- package/dist/preload.d.ts +0 -18
- package/dist/preload.d.ts.map +0 -1
- package/dist/preload.js +0 -30
- package/dist/preload.js.map +0 -1
package/dist/router.js
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { WayfinderDisposedError as e, WayfinderRedirectLoopError as t, WayfinderRouteError as n } from "./errors.js";
|
|
2
|
+
import { createBrowserHistory as r } from "./history.js";
|
|
3
|
+
import { createNavigationCoordinator as i } from "./_navigation.js";
|
|
4
|
+
import { buildUrl as a, joinPaths as o, matchRouteFor as s, matchesPrefix as c, normalizePath as l, parseQuery as u, readLocation as d, stripBase as f } from "./path.js";
|
|
4
5
|
import { compileRoutes as p } from "./compile.js";
|
|
5
6
|
import { buildMatchBranch as m, createRouteContext as h, createRouteState as g, executeMiddlewarePipeline as _, reportError as v } from "./context.js";
|
|
6
7
|
import { runLeaveBlockers as y } from "./guards.js";
|
|
7
|
-
import { createBrowserHistory as b } from "./history.js";
|
|
8
|
-
import { createHydrationManager as x } from "./hydration.js";
|
|
9
|
-
import { createPreloadManager as S } from "./preload.js";
|
|
10
8
|
//#region src/router.ts
|
|
11
|
-
function
|
|
12
|
-
let
|
|
13
|
-
if (
|
|
9
|
+
function b(e, t) {
|
|
10
|
+
let r = t.get(e);
|
|
11
|
+
if (r) return r;
|
|
14
12
|
let i = [...t.keys()].join(", ");
|
|
15
|
-
throw new
|
|
13
|
+
throw new n(i ? `Unknown route name: ${e}. Available routes: ${i}` : `Unknown route name: ${e}`);
|
|
16
14
|
}
|
|
17
|
-
function
|
|
15
|
+
function x(e, t, n = "/") {
|
|
18
16
|
if ("path" in e) return e.path;
|
|
19
|
-
let r =
|
|
17
|
+
let r = b(e.name, t), i = a(n, r.path, e.params, e.query);
|
|
20
18
|
return e.hash ? `${i}#${e.hash}` : i;
|
|
21
19
|
}
|
|
22
|
-
var
|
|
23
|
-
function
|
|
24
|
-
|
|
20
|
+
var S = Symbol("wayfinder.routerError");
|
|
21
|
+
function C(e, t) {
|
|
22
|
+
return {
|
|
23
|
+
[S]: !0,
|
|
24
|
+
context: t,
|
|
25
|
+
error: e
|
|
26
|
+
};
|
|
25
27
|
}
|
|
26
|
-
function
|
|
27
|
-
|
|
28
|
+
function w(e) {
|
|
29
|
+
return typeof e == "object" && !!e && S in e;
|
|
28
30
|
}
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
+
function T(e) {
|
|
32
|
+
throw w(e) ? e.error : e;
|
|
31
33
|
}
|
|
32
|
-
var
|
|
34
|
+
var E = class {
|
|
33
35
|
#e;
|
|
34
36
|
#t;
|
|
35
37
|
#n;
|
|
@@ -40,20 +42,20 @@ var k = class {
|
|
|
40
42
|
#s;
|
|
41
43
|
#c;
|
|
42
44
|
#l = /* @__PURE__ */ new Set();
|
|
43
|
-
#u =
|
|
45
|
+
#u = i();
|
|
44
46
|
#d;
|
|
45
47
|
#f = !1;
|
|
46
48
|
#p = new AbortController();
|
|
47
49
|
#m = "/";
|
|
48
50
|
#h = /* @__PURE__ */ new Set();
|
|
49
|
-
#g;
|
|
50
|
-
#_;
|
|
51
|
+
#g = /* @__PURE__ */ new Map();
|
|
52
|
+
#_ = /* @__PURE__ */ new Map();
|
|
51
53
|
#v;
|
|
52
54
|
#y;
|
|
53
55
|
ready;
|
|
54
56
|
constructor(e) {
|
|
55
57
|
let t = p(e);
|
|
56
|
-
if (this.#e = l(e.base ?? "/"), this.#t = e.middleware ?? [], this.#n = e.coerceSearch, this.#r = e.history ??
|
|
58
|
+
if (this.#e = l(e.base ?? "/"), this.#t = e.middleware ?? [], this.#n = e.coerceSearch, this.#r = e.history ?? r(), this.#o = e.onError, this.#s = e.scroll, this.#c = e.viewTransition ?? !1, this.#i = t.records, this.#a = t.routesByName, this.#d = g({
|
|
57
59
|
location: {
|
|
58
60
|
hash: "",
|
|
59
61
|
historyState: null,
|
|
@@ -64,12 +66,10 @@ var k = class {
|
|
|
64
66
|
status: "idle"
|
|
65
67
|
}), e.notFound) {
|
|
66
68
|
let t = e.notFound, n = {
|
|
67
|
-
component: t.component,
|
|
68
69
|
dataFn: t.data,
|
|
69
|
-
meta: t.meta,
|
|
70
70
|
name: "__notFound__"
|
|
71
71
|
};
|
|
72
|
-
this.#
|
|
72
|
+
this.#v = {
|
|
73
73
|
branchDefs: [n],
|
|
74
74
|
leaf: n,
|
|
75
75
|
matcher: {
|
|
@@ -80,51 +80,57 @@ var k = class {
|
|
|
80
80
|
ownMiddleware: t.middleware ?? [],
|
|
81
81
|
path: "/*"
|
|
82
82
|
};
|
|
83
|
-
} else this.#
|
|
83
|
+
} else this.#v = null;
|
|
84
84
|
this.#y = this.#x();
|
|
85
|
-
let { hash: n, pathname:
|
|
86
|
-
this.#m = `${
|
|
87
|
-
let
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
let n = this.#z(e);
|
|
85
|
+
let { hash: n, pathname: i, search: a } = this.#r.location;
|
|
86
|
+
this.#m = `${i}${a}${n}`;
|
|
87
|
+
let o = this.#u.begin(), s = this.#A(o, d(this.#e, this.#r), (e, t) => {
|
|
88
|
+
if (!o.isCurrent()) return;
|
|
89
|
+
let n = this.#F(e);
|
|
91
90
|
t && this.#r.replace(n, e.historyState), this.#m = n;
|
|
92
|
-
}, void 0, 0, !1).then(() => void 0)
|
|
91
|
+
}, void 0, 0, !1).then(() => void 0);
|
|
92
|
+
this.ready = s.catch(T), this.ready.catch(() => {}), this.#w(s, { source: "initial-navigation" }), this.beforeLeave = this.beforeLeave.bind(this), this.createViewRegistry = this.createViewRegistry.bind(this), this.dispose = this.dispose.bind(this), this.getSnapshot = this.getSnapshot.bind(this), this.isActive = this.isActive.bind(this), this.load = this.load.bind(this), this.match = this.match.bind(this), this.navigate = this.navigate.bind(this), this.preload = this.preload.bind(this), this.subscribe = this.subscribe.bind(this), this.url = this.url.bind(this), this.waitFor = this.waitFor.bind(this);
|
|
93
93
|
}
|
|
94
94
|
getSnapshot() {
|
|
95
95
|
return this.#d;
|
|
96
96
|
}
|
|
97
|
+
createViewRegistry(e, t) {
|
|
98
|
+
return { resolve: (n) => {
|
|
99
|
+
let r = n.matches.at(-1)?.name;
|
|
100
|
+
return r === "__notFound__" ? t?.notFound : r ? e[r] : void 0;
|
|
101
|
+
} };
|
|
102
|
+
}
|
|
97
103
|
subscribe(e) {
|
|
98
104
|
return this.#b(), this.#h.add(e), () => {
|
|
99
105
|
this.#h.delete(e);
|
|
100
106
|
};
|
|
101
107
|
}
|
|
102
108
|
navigate(e, t) {
|
|
103
|
-
let n =
|
|
104
|
-
return this.#
|
|
109
|
+
let n = x(typeof e == "string" ? { path: e } : e, this.#a);
|
|
110
|
+
return this.#L(n, t);
|
|
105
111
|
}
|
|
106
112
|
url(e, t, n) {
|
|
107
|
-
let r =
|
|
113
|
+
let r = b(e, this.#a);
|
|
108
114
|
return a(this.#e, r.path, t, n);
|
|
109
115
|
}
|
|
110
116
|
isActive(e, t = {}) {
|
|
111
|
-
let n =
|
|
117
|
+
let n = b(e, this.#a), r = this.#d.location.pathname;
|
|
112
118
|
return t.exact ?? !1 ? s(r, [n]).record != null : c(r, n);
|
|
113
119
|
}
|
|
114
120
|
match(e) {
|
|
115
121
|
let t = f(l(e), this.#e), { params: n, record: r } = s(t, this.#i);
|
|
116
122
|
if (!r || r.redirect) return null;
|
|
117
|
-
let i =
|
|
118
|
-
return
|
|
123
|
+
let i = m(r.branchDefs, n, t, r.branchDefs.map(() => void 0));
|
|
124
|
+
return i.length ? i : null;
|
|
119
125
|
}
|
|
120
126
|
async load(e, t) {
|
|
121
|
-
let n = await this.#
|
|
127
|
+
let n = await this.#D(e);
|
|
122
128
|
if (n.type !== "matched") return null;
|
|
123
|
-
let { location: r, params: i, record: a, resolvedQuery: o } = n, s =
|
|
129
|
+
let { location: r, params: i, record: a, resolvedQuery: o } = n, s = a.branchDefs, c = s.some((e) => e.dataFn != null), l = s.map(() => void 0), u, d = "idle";
|
|
124
130
|
if (c) {
|
|
125
131
|
let e = t?.signal ?? new AbortController().signal, n = m(s, i, r.pathname, l), a = h(r, o, i, n, () => Promise.resolve());
|
|
126
132
|
try {
|
|
127
|
-
l = await this.#
|
|
133
|
+
l = await this.#E(s, a, e);
|
|
128
134
|
} catch (e) {
|
|
129
135
|
u = e, d = "error";
|
|
130
136
|
}
|
|
@@ -136,6 +142,25 @@ var k = class {
|
|
|
136
142
|
status: d
|
|
137
143
|
});
|
|
138
144
|
}
|
|
145
|
+
async preload(e) {
|
|
146
|
+
this.#b();
|
|
147
|
+
let t = this.#N(x(e, this.#a, this.#e)), n = this.#_.get(t);
|
|
148
|
+
if (n) return n;
|
|
149
|
+
let r = this.load(t, { signal: this.#p.signal }).then((e) => {
|
|
150
|
+
if (this.#f) throw this.#p.signal.reason;
|
|
151
|
+
if (e?.status === "error") throw e.error;
|
|
152
|
+
if (e) {
|
|
153
|
+
let t = this.#F(e.location);
|
|
154
|
+
this.#g.size >= 20 && this.#g.delete(this.#g.keys().next().value), this.#g.set(t, e.matches.map((e) => e.data));
|
|
155
|
+
}
|
|
156
|
+
return e;
|
|
157
|
+
}).catch((e) => {
|
|
158
|
+
throw this.#o && this.#C(e, { source: "preload" }), e;
|
|
159
|
+
}).finally(() => {
|
|
160
|
+
this.#_.delete(t);
|
|
161
|
+
});
|
|
162
|
+
return this.#_.set(t, r), r;
|
|
163
|
+
}
|
|
139
164
|
waitFor(e) {
|
|
140
165
|
return this.#b(), new Promise((t, n) => {
|
|
141
166
|
let r = (t) => t.status === "idle" && t.matches.some((t) => t.name === e);
|
|
@@ -155,20 +180,6 @@ var k = class {
|
|
|
155
180
|
}, { once: !0 });
|
|
156
181
|
});
|
|
157
182
|
}
|
|
158
|
-
async preload(e, t, n) {
|
|
159
|
-
this.#b();
|
|
160
|
-
let r = C(e, this.#a), a = i(this.#e, r.path, t, n), o = this.#v.getInflight(a);
|
|
161
|
-
if (o) return o;
|
|
162
|
-
let s = this.#A(a, this.#p.signal, n).finally(() => {
|
|
163
|
-
this.#v.untrack(a);
|
|
164
|
-
});
|
|
165
|
-
this.#v.track(a, s);
|
|
166
|
-
try {
|
|
167
|
-
return await s;
|
|
168
|
-
} catch (e) {
|
|
169
|
-
throw this.#c && this.#C(e, { source: "preload" }), e;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
183
|
beforeLeave(e, t) {
|
|
173
184
|
this.#b();
|
|
174
185
|
let n = {
|
|
@@ -186,13 +197,13 @@ var k = class {
|
|
|
186
197
|
return this.#f;
|
|
187
198
|
}
|
|
188
199
|
dispose() {
|
|
189
|
-
this.#f || (this.#f = !0, this.#l.clear(), this.#h.clear(), this.#u.invalidate(new
|
|
200
|
+
this.#f || (this.#f = !0, this.#l.clear(), this.#h.clear(), this.#g.clear(), this.#_.clear(), this.#u.invalidate(new e()), this.#y(), this.#p.abort(new e()));
|
|
190
201
|
}
|
|
191
202
|
[Symbol.dispose]() {
|
|
192
203
|
this.dispose();
|
|
193
204
|
}
|
|
194
205
|
#b() {
|
|
195
|
-
if (this.#f) throw new
|
|
206
|
+
if (this.#f) throw new e();
|
|
196
207
|
}
|
|
197
208
|
#x() {
|
|
198
209
|
return this.#r.onPopstate(() => {
|
|
@@ -201,25 +212,25 @@ var k = class {
|
|
|
201
212
|
});
|
|
202
213
|
}
|
|
203
214
|
async #S(e, t) {
|
|
204
|
-
let n = this.#u.begin(), r = this.#d.matches.map((e) => e.name), i = this.#
|
|
215
|
+
let n = this.#u.begin(), r = this.#d.matches.map((e) => e.name), i = this.#I(e), a = await y(this.#l, r, i);
|
|
205
216
|
if (!n.isCurrent()) return;
|
|
206
217
|
if (!a) {
|
|
207
218
|
this.#r.replace(t, this.#d.location.historyState);
|
|
208
219
|
return;
|
|
209
220
|
}
|
|
210
|
-
let o = await this.#
|
|
221
|
+
let o = await this.#A(n, d(this.#e, this.#r), (e, t) => {
|
|
211
222
|
if (!n.isCurrent()) return;
|
|
212
|
-
let r = this.#
|
|
223
|
+
let r = this.#F(e);
|
|
213
224
|
t && this.#r.replace(r, e.historyState), this.#m = r;
|
|
214
225
|
}, void 0, 0, !1);
|
|
215
226
|
n.isCurrent() && !o && this.#r.replace(t, this.#d.location.historyState);
|
|
216
227
|
}
|
|
217
228
|
#C(e, t) {
|
|
218
|
-
v(e, t, this.#
|
|
229
|
+
v(e, t, this.#o);
|
|
219
230
|
}
|
|
220
231
|
#w(e, t) {
|
|
221
232
|
e.catch((e) => {
|
|
222
|
-
this.#C(e,
|
|
233
|
+
w(e) ? this.#C(e.error, e.context) : this.#C(e, t);
|
|
223
234
|
});
|
|
224
235
|
}
|
|
225
236
|
#T() {
|
|
@@ -227,105 +238,39 @@ var k = class {
|
|
|
227
238
|
e(this.#d);
|
|
228
239
|
});
|
|
229
240
|
}
|
|
230
|
-
async #E(e, t) {
|
|
231
|
-
let n;
|
|
232
|
-
for (;;) {
|
|
233
|
-
if (t.aborted) return await e.return(void 0).catch(() => void 0), n;
|
|
234
|
-
let { done: r, value: i } = await e.next();
|
|
235
|
-
if (r) return i ?? n;
|
|
236
|
-
n = i;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
async #D(e, t, n) {
|
|
241
|
+
async #E(e, t, n) {
|
|
240
242
|
return Promise.all(e.map(async (e) => {
|
|
241
243
|
if (!e.dataFn) return;
|
|
242
|
-
let r = e.dataFn
|
|
243
|
-
...t,
|
|
244
|
-
signal: n
|
|
245
|
-
});
|
|
244
|
+
let r = e.dataFn;
|
|
246
245
|
try {
|
|
247
|
-
return
|
|
248
|
-
} catch (r) {
|
|
249
|
-
if (e.onError) return e.onError(r, {
|
|
246
|
+
return await r({
|
|
250
247
|
...t,
|
|
251
248
|
signal: n
|
|
252
249
|
});
|
|
253
|
-
throw r;
|
|
254
|
-
}
|
|
255
|
-
}));
|
|
256
|
-
}
|
|
257
|
-
async #O(e, t, n, r, i, a) {
|
|
258
|
-
let o = e.map((e) => {
|
|
259
|
-
if (!e.dataFn) return;
|
|
260
|
-
let r = e.dataFn;
|
|
261
|
-
return r({
|
|
262
|
-
...t,
|
|
263
|
-
signal: n
|
|
264
|
-
});
|
|
265
|
-
}), s = [], c = await Promise.all(o.map(async (r, i) => {
|
|
266
|
-
if (O(r)) {
|
|
267
|
-
s.push(i);
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
if (r !== void 0) try {
|
|
271
|
-
return await r;
|
|
272
250
|
} catch (r) {
|
|
273
|
-
|
|
274
|
-
if (a.onError) return a.onError(r, {
|
|
251
|
+
if (e.onError) return e.onError(r, {
|
|
275
252
|
...t,
|
|
276
253
|
signal: n
|
|
277
254
|
});
|
|
278
255
|
throw r;
|
|
279
256
|
}
|
|
280
257
|
}));
|
|
281
|
-
if (s.length === 0) return c;
|
|
282
|
-
let l = [...c], u = (t, n) => {
|
|
283
|
-
if (!r()) return;
|
|
284
|
-
l[n] = t;
|
|
285
|
-
let o = e.map((e, t) => s.includes(t) ? "streaming" : "idle");
|
|
286
|
-
this.#d = g({
|
|
287
|
-
location: i,
|
|
288
|
-
matches: m(e, a, i.pathname, l, o),
|
|
289
|
-
status: "streaming"
|
|
290
|
-
}), this.#T();
|
|
291
|
-
};
|
|
292
|
-
return await Promise.all(s.map(async (i) => {
|
|
293
|
-
let a = o[i];
|
|
294
|
-
try {
|
|
295
|
-
l[i] = await this.#M(a, i, n, r, u);
|
|
296
|
-
} catch (r) {
|
|
297
|
-
let a = e[i];
|
|
298
|
-
if (a.onError) l[i] = await a.onError(r, {
|
|
299
|
-
...t,
|
|
300
|
-
signal: n
|
|
301
|
-
});
|
|
302
|
-
else throw r;
|
|
303
|
-
}
|
|
304
|
-
})), l;
|
|
305
258
|
}
|
|
306
|
-
async #
|
|
307
|
-
let
|
|
259
|
+
async #D(e) {
|
|
260
|
+
let n = e;
|
|
308
261
|
for (let e = 0; e < 5; e += 1) {
|
|
309
|
-
let e = new URL(
|
|
262
|
+
let e = new URL(n, "http://localhost"), t = {
|
|
310
263
|
hash: e.hash.replace(/^#/, ""),
|
|
311
264
|
historyState: null,
|
|
312
265
|
pathname: f(e.pathname, this.#e),
|
|
313
266
|
query: u(e.search)
|
|
314
|
-
}, r = await this.#
|
|
267
|
+
}, r = await this.#O(t);
|
|
315
268
|
if (r.type !== "redirect") return r;
|
|
316
|
-
|
|
269
|
+
n = this.#N(r.redirectTo);
|
|
317
270
|
}
|
|
318
|
-
throw new
|
|
271
|
+
throw new t();
|
|
319
272
|
}
|
|
320
|
-
async #
|
|
321
|
-
let r = await this.#k(e);
|
|
322
|
-
if (r.type !== "matched") return;
|
|
323
|
-
let { location: a, params: o, record: s, resolvedQuery: c } = r, l = this.#_.effectiveDefs(s);
|
|
324
|
-
if (!l.some((e) => e.dataFn != null)) return;
|
|
325
|
-
let u = m(l, o, a.pathname, l.map(() => void 0)), d = h(a, c, o, u, () => Promise.resolve()), f = await this.#D(l, d, t);
|
|
326
|
-
this.#v.set(i(this.#e, s.path, o, n ?? a.query), f);
|
|
327
|
-
}
|
|
328
|
-
async #j(e) {
|
|
273
|
+
async #O(e) {
|
|
329
274
|
let { params: t, record: n } = s(e.pathname, this.#i);
|
|
330
275
|
if (!n) return {
|
|
331
276
|
location: e,
|
|
@@ -335,7 +280,7 @@ var k = class {
|
|
|
335
280
|
if (n.redirect) return {
|
|
336
281
|
location: e,
|
|
337
282
|
params: t,
|
|
338
|
-
redirectTo:
|
|
283
|
+
redirectTo: x(n.redirect, this.#a, this.#e),
|
|
339
284
|
type: "redirect"
|
|
340
285
|
};
|
|
341
286
|
let r = e.query, i = n.coerceSearch ?? this.#n;
|
|
@@ -344,10 +289,8 @@ var k = class {
|
|
|
344
289
|
} catch (t) {
|
|
345
290
|
this.#C(t, { source: "coerce-search" }), r = e.query;
|
|
346
291
|
}
|
|
347
|
-
await this.#_.hydrate(n);
|
|
348
|
-
let a = this.#_.effectiveDefs(n);
|
|
349
292
|
return {
|
|
350
|
-
branch: m(
|
|
293
|
+
branch: m(n.branchDefs, t, e.pathname, n.branchDefs.map(() => void 0)),
|
|
351
294
|
location: e,
|
|
352
295
|
params: t,
|
|
353
296
|
record: n,
|
|
@@ -355,116 +298,121 @@ var k = class {
|
|
|
355
298
|
type: "matched"
|
|
356
299
|
};
|
|
357
300
|
}
|
|
358
|
-
async #
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
for (;;) {
|
|
362
|
-
if (n.aborted || !r()) return await e.return(void 0), a;
|
|
363
|
-
let { done: o, value: s } = await e.next();
|
|
364
|
-
if (o) return s ?? a;
|
|
365
|
-
a = s, i(s, t);
|
|
366
|
-
}
|
|
367
|
-
} catch (t) {
|
|
368
|
-
throw await e.return(void 0).catch(() => void 0), t;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
async #N(e, t, n, r, a, o) {
|
|
372
|
-
if (!o()) return;
|
|
373
|
-
let s = this.#_.effectiveDefs(e), c = s.some((e) => e.dataFn != null), l = s.map(() => void 0);
|
|
301
|
+
async #k(e, t, n, r, i, a, o) {
|
|
302
|
+
if (!a()) return;
|
|
303
|
+
let s = e.branchDefs, c = s.some((e) => e.dataFn != null), l = s.map(() => void 0);
|
|
374
304
|
if (c) {
|
|
375
|
-
let
|
|
376
|
-
if (
|
|
305
|
+
let e = this.#F(n), c = this.#_.get(e);
|
|
306
|
+
if (c && (await c.catch(() => void 0), !a())) return;
|
|
307
|
+
let u = this.#g.get(e);
|
|
308
|
+
if (u) this.#g.delete(e), l = u;
|
|
377
309
|
else {
|
|
378
|
-
let i = s.map((e) => e.dataFn ? "loading" : "idle");
|
|
379
310
|
this.#d = g({
|
|
380
311
|
location: n,
|
|
381
|
-
matches: m(s, r, n.pathname, l
|
|
312
|
+
matches: m(s, r, n.pathname, l),
|
|
382
313
|
status: "loading"
|
|
383
314
|
}), this.#T();
|
|
384
315
|
try {
|
|
385
|
-
l = await this.#
|
|
386
|
-
} catch (
|
|
387
|
-
if (!
|
|
316
|
+
l = await this.#E(s, t, i);
|
|
317
|
+
} catch (e) {
|
|
318
|
+
if (!a()) return;
|
|
388
319
|
throw this.#d = g({
|
|
389
|
-
error:
|
|
320
|
+
error: e,
|
|
390
321
|
location: n,
|
|
391
322
|
matches: m(s, r, n.pathname, l),
|
|
392
323
|
status: "error"
|
|
393
|
-
}),
|
|
394
|
-
routeName: e.leaf.name,
|
|
395
|
-
source: "data-loader"
|
|
396
|
-
}), t;
|
|
324
|
+
}), o?.(e), e;
|
|
397
325
|
}
|
|
398
326
|
}
|
|
399
327
|
}
|
|
400
|
-
|
|
328
|
+
a() && (this.#d = g({
|
|
401
329
|
location: n,
|
|
402
330
|
matches: m(s, r, n.pathname, l),
|
|
403
331
|
status: "idle"
|
|
404
332
|
}));
|
|
405
333
|
}
|
|
406
|
-
async #
|
|
407
|
-
|
|
408
|
-
let t = document;
|
|
409
|
-
if (t.startViewTransition) {
|
|
410
|
-
await t.startViewTransition(e).finished;
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
await e();
|
|
415
|
-
}
|
|
416
|
-
async #F(e, t, r, i, a = 0, o = !1) {
|
|
417
|
-
let s = this.#d, c = () => e.isCurrent() && !this.#f, l = await this.#j(t);
|
|
334
|
+
async #A(e, n, r, i, a = 0, o = !1) {
|
|
335
|
+
let s = this.#d, c = () => e.isCurrent() && !this.#f, l = await this.#O(n);
|
|
418
336
|
if (!c()) return !1;
|
|
419
337
|
if (l.type === "redirect") {
|
|
420
|
-
if (a >= 5) throw new
|
|
421
|
-
return this.#
|
|
338
|
+
if (a >= 5) throw new t();
|
|
339
|
+
return this.#A(e, this.#P(l.redirectTo, n.historyState), r, i, a + 1, !0);
|
|
422
340
|
}
|
|
423
341
|
if (l.type === "unmatched") {
|
|
424
|
-
if (this.#
|
|
425
|
-
let
|
|
342
|
+
if (this.#v) {
|
|
343
|
+
let t = [this.#v.leaf], a = m(t, {}, n.pathname, [void 0]), l = !1, u, d = !1, f = !1, p = n.query;
|
|
426
344
|
if (this.#n) try {
|
|
427
|
-
|
|
345
|
+
p = this.#n(n.query);
|
|
428
346
|
} catch (e) {
|
|
429
347
|
this.#C(e, { source: "coerce-search" });
|
|
430
348
|
}
|
|
431
|
-
let
|
|
349
|
+
let g = async () => {
|
|
432
350
|
if (!c()) return;
|
|
433
|
-
let
|
|
434
|
-
|
|
435
|
-
c() && (l = !0, r(
|
|
436
|
-
|
|
351
|
+
let t = h(n, p, {}, a, (e, t) => this.navigate(e, t));
|
|
352
|
+
f = await _(t, [...this.#t, ...this.#v.ownMiddleware], async () => {
|
|
353
|
+
c() && (l = !0, r(n, o), c() && await this.#k(this.#v, t, n, {}, e.signal, c, (e) => {
|
|
354
|
+
u = e, d = !0;
|
|
355
|
+
}));
|
|
356
|
+
}, (e) => w(e) || d && e === u ? e : C(e, {
|
|
357
|
+
routeName: "__notFound__",
|
|
358
|
+
source: "middleware"
|
|
359
|
+
}));
|
|
437
360
|
};
|
|
438
361
|
try {
|
|
439
|
-
await this.#
|
|
362
|
+
await this.#j(g, i);
|
|
363
|
+
} catch (e) {
|
|
364
|
+
throw d && e === u ? C(e, {
|
|
365
|
+
routeName: "__notFound__",
|
|
366
|
+
source: "data-loader"
|
|
367
|
+
}) : e;
|
|
440
368
|
} finally {
|
|
441
|
-
c() && l && (this.#T(), this.#
|
|
369
|
+
c() && l && (this.#T(), this.#M(this.#d, s));
|
|
442
370
|
}
|
|
443
|
-
return
|
|
371
|
+
return f && l;
|
|
444
372
|
}
|
|
445
373
|
return !c() || (r(l.location, o), !c()) ? !1 : (this.#d = g({
|
|
446
374
|
location: l.location,
|
|
447
375
|
matches: [],
|
|
448
376
|
status: "idle"
|
|
449
|
-
}), this.#T(), this.#
|
|
377
|
+
}), this.#T(), this.#M(this.#d, s), !0);
|
|
450
378
|
}
|
|
451
|
-
let { branch: u, location: d, params: f, record: p, resolvedQuery: v } = l, y = !1, b = !1,
|
|
379
|
+
let { branch: u, location: d, params: f, record: p, resolvedQuery: v } = l, y = !1, b, x = !1, S = !1, T = async () => {
|
|
452
380
|
if (!c()) return;
|
|
453
381
|
let t = h(d, v, f, u, (e, t) => this.navigate(e, t));
|
|
454
|
-
|
|
455
|
-
c() && (y = !0, r(d, o), c() && await this.#
|
|
456
|
-
|
|
382
|
+
S = await _(t, [...this.#t, ...p.ownMiddleware], async () => {
|
|
383
|
+
c() && (y = !0, r(d, o), c() && await this.#k(p, t, d, f, e.signal, c, (e) => {
|
|
384
|
+
b = e, x = !0;
|
|
385
|
+
}));
|
|
386
|
+
}, (e) => w(e) || x && e === b ? e : C(e, {
|
|
387
|
+
routeName: p.leaf.name,
|
|
388
|
+
source: "middleware"
|
|
389
|
+
}));
|
|
457
390
|
};
|
|
458
391
|
try {
|
|
459
|
-
await this.#
|
|
392
|
+
await this.#j(T, i);
|
|
393
|
+
} catch (e) {
|
|
394
|
+
throw x && e === b ? C(e, {
|
|
395
|
+
routeName: p.leaf.name,
|
|
396
|
+
source: "data-loader"
|
|
397
|
+
}) : e;
|
|
460
398
|
} finally {
|
|
461
|
-
c() && y && (this.#T(), this.#
|
|
399
|
+
c() && y && (this.#T(), this.#M(this.#d, s));
|
|
462
400
|
}
|
|
463
|
-
return
|
|
401
|
+
return S && y;
|
|
464
402
|
}
|
|
465
|
-
#
|
|
466
|
-
if (
|
|
467
|
-
|
|
403
|
+
async #j(e, t) {
|
|
404
|
+
if ((t ?? this.#c) && typeof document < "u") {
|
|
405
|
+
let t = document.startViewTransition;
|
|
406
|
+
if (t) {
|
|
407
|
+
await t.call(document, e).finished;
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
await e();
|
|
412
|
+
}
|
|
413
|
+
#M(e, t) {
|
|
414
|
+
if (!this.#s || typeof window > "u") return;
|
|
415
|
+
let n = this.#s(e, t);
|
|
468
416
|
if (n !== "preserve") {
|
|
469
417
|
if (n === "top") {
|
|
470
418
|
window.scrollTo(0, 0);
|
|
@@ -473,12 +421,12 @@ var k = class {
|
|
|
473
421
|
window.scrollTo(n.x, n.y);
|
|
474
422
|
}
|
|
475
423
|
}
|
|
476
|
-
#
|
|
424
|
+
#N(e) {
|
|
477
425
|
let t = new URL(e, "http://localhost"), n = f(t.pathname, this.#e);
|
|
478
426
|
return `${o(this.#e, n)}${t.search}${t.hash}`;
|
|
479
427
|
}
|
|
480
|
-
#
|
|
481
|
-
let n = new URL(this.#
|
|
428
|
+
#P(e, t) {
|
|
429
|
+
let n = new URL(this.#N(e), "http://localhost");
|
|
482
430
|
return {
|
|
483
431
|
hash: n.hash.replace(/^#/, ""),
|
|
484
432
|
historyState: t,
|
|
@@ -486,7 +434,7 @@ var k = class {
|
|
|
486
434
|
query: u(n.search)
|
|
487
435
|
};
|
|
488
436
|
}
|
|
489
|
-
#
|
|
437
|
+
#F(e) {
|
|
490
438
|
let t = new URLSearchParams();
|
|
491
439
|
for (let [n, r] of Object.entries(e.query)) Array.isArray(r) ? r.forEach((e) => {
|
|
492
440
|
t.append(n, e);
|
|
@@ -494,7 +442,7 @@ var k = class {
|
|
|
494
442
|
let n = t.toString(), r = e.hash ? `#${e.hash}` : "";
|
|
495
443
|
return `${o(this.#e, e.pathname)}${n ? `?${n}` : ""}${r}`;
|
|
496
444
|
}
|
|
497
|
-
#
|
|
445
|
+
#I(e) {
|
|
498
446
|
let t = new URL(e, "http://localhost"), n = f(t.pathname, this.#e), { params: r, record: i } = s(n, this.#i);
|
|
499
447
|
return {
|
|
500
448
|
name: i?.leaf.name,
|
|
@@ -503,22 +451,26 @@ var k = class {
|
|
|
503
451
|
query: u(t.search)
|
|
504
452
|
};
|
|
505
453
|
}
|
|
506
|
-
async #
|
|
454
|
+
async #L(e, t = {}) {
|
|
507
455
|
this.#b();
|
|
508
|
-
let n = this.#
|
|
456
|
+
let n = this.#N(e);
|
|
509
457
|
if (!t.force && n === this.#m) return;
|
|
510
|
-
let r = this.#u.begin(), i = this.#d.matches.map((e) => e.name), a = await y(this.#l, i, this.#
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
458
|
+
let r = this.#u.begin(), i = this.#d.matches.map((e) => e.name), a = await y(this.#l, i, this.#I(n));
|
|
459
|
+
if (r.isCurrent() && a) try {
|
|
460
|
+
await this.#A(r, this.#P(n, t.state), (e, t) => {
|
|
461
|
+
if (!r.isCurrent()) return;
|
|
462
|
+
let n = this.#F(e);
|
|
463
|
+
t ? this.#r.replace(n, e.historyState) : this.#r.push(n, e.historyState), this.#m = n;
|
|
464
|
+
}, t.viewTransition, 0, t.replace ?? !1);
|
|
465
|
+
} catch (e) {
|
|
466
|
+
throw w(e) ? e.error : e;
|
|
467
|
+
}
|
|
516
468
|
}
|
|
517
469
|
};
|
|
518
|
-
function
|
|
519
|
-
return new
|
|
470
|
+
function D(e) {
|
|
471
|
+
return new E(e);
|
|
520
472
|
}
|
|
521
473
|
//#endregion
|
|
522
|
-
export {
|
|
474
|
+
export { D as createRouter };
|
|
523
475
|
|
|
524
476
|
//# sourceMappingURL=router.js.map
|