@manyducks.co/dolla 2.0.0-alpha.60 → 2.0.0-alpha.61
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/dist/core/context.d.ts +0 -2
- package/dist/core/context.test.d.ts +1 -0
- package/dist/core/index.d.ts +4 -5
- package/dist/core/logger.test.d.ts +0 -0
- package/dist/core/markup.d.ts +16 -37
- package/dist/core/markup.test.d.ts +0 -0
- package/dist/core/mount.test.d.ts +0 -0
- package/dist/core/nodes/_markup.d.ts +36 -0
- package/dist/core/nodes/dom.d.ts +5 -6
- package/dist/core/nodes/dynamic.d.ts +6 -13
- package/dist/core/nodes/{html.d.ts → element.d.ts} +9 -8
- package/dist/core/nodes/portal.d.ts +6 -7
- package/dist/core/nodes/repeat.d.ts +7 -5
- package/dist/core/nodes/view.d.ts +6 -5
- package/dist/core/ref.test.d.ts +1 -0
- package/dist/core/signals.d.ts +17 -2
- package/dist/core/views/default-crash-view.d.ts +5 -2
- package/dist/hooks/index.d.ts +64 -0
- package/dist/hooks/index.test.d.ts +1 -0
- package/dist/hooks.js +69 -0
- package/dist/hooks.js.map +1 -0
- package/dist/i18n.js +49 -49
- package/dist/i18n.js.map +1 -1
- package/dist/index.js +50 -60
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.js +1 -1
- package/dist/jsx-runtime.js +1 -1
- package/dist/logger-Bl496yfY.js +91 -0
- package/dist/logger-Bl496yfY.js.map +1 -0
- package/dist/markup-CX27GJ1M.js +1030 -0
- package/dist/markup-CX27GJ1M.js.map +1 -0
- package/dist/ref-BD79iqlg.js +15 -0
- package/dist/ref-BD79iqlg.js.map +1 -0
- package/dist/router/router.d.ts +29 -18
- package/dist/{router-BpuJQ6OA.js → router-CjCkk4dA.js} +217 -190
- package/dist/router-CjCkk4dA.js.map +1 -0
- package/dist/router.js +1 -1
- package/dist/signals-gCwiIe5X.js +450 -0
- package/dist/signals-gCwiIe5X.js.map +1 -0
- package/dist/types.d.ts +1 -1
- package/docs/hooks.md +211 -0
- package/docs/i18n.md +1 -1
- package/package.json +5 -1
- package/vite.config.js +1 -0
- package/dist/core/symbols.d.ts +0 -2
- package/dist/logger-MPwl-Xqu.js +0 -524
- package/dist/logger-MPwl-Xqu.js.map +0 -1
- package/dist/markup-BGlfQYQk.js +0 -996
- package/dist/markup-BGlfQYQk.js.map +0 -1
- package/dist/router-BpuJQ6OA.js.map +0 -1
|
@@ -3,25 +3,26 @@ var V = (n) => {
|
|
|
3
3
|
throw TypeError(n);
|
|
4
4
|
};
|
|
5
5
|
var rt = (n, t, e) => t in n ? et(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e;
|
|
6
|
-
var
|
|
7
|
-
var l = (n, t, e) => (C(n, t, "read from private field"), e ? e.call(n) : t.get(n)),
|
|
6
|
+
var P = (n, t, e) => rt(n, typeof t != "symbol" ? t + "" : t, e), C = (n, t, e) => t.has(n) || V("Cannot " + e);
|
|
7
|
+
var l = (n, t, e) => (C(n, t, "read from private field"), e ? e.call(n) : t.get(n)), b = (n, t, e) => t.has(n) ? V("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(n) : t.set(n, e), M = (n, t, e, r) => (C(n, t, "write to private field"), r ? r.call(n, e) : t.set(n, e), e), g = (n, t, e) => (C(n, t, "access private method"), e);
|
|
8
8
|
var D = (n, t, e, r) => ({
|
|
9
9
|
set _(a) {
|
|
10
|
-
|
|
10
|
+
M(n, t, a, e);
|
|
11
11
|
},
|
|
12
12
|
get _() {
|
|
13
13
|
return l(n, t, r);
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
import {
|
|
17
|
-
import { D as st, V as
|
|
18
|
-
import {
|
|
16
|
+
import { c as nt } from "./logger-Bl496yfY.js";
|
|
17
|
+
import { D as st, V as it, m as at, b as ot } from "./markup-CX27GJ1M.js";
|
|
18
|
+
import { $ as R, d as ct, s as B, u as H, b as lt } from "./signals-gCwiIe5X.js";
|
|
19
|
+
import { d as ht, e as X, c as G, f as ft, g as J, i as ut, b as U, h as pt } from "./typeChecking-CbltMOUt.js";
|
|
19
20
|
function O(n) {
|
|
20
21
|
return X(n, "Expected `path` to be a string. Got type: %t, value: %v"), n.split("/").map((t) => t.trim()).filter((t) => t !== "");
|
|
21
22
|
}
|
|
22
|
-
function
|
|
23
|
+
function N(n) {
|
|
23
24
|
var e;
|
|
24
|
-
|
|
25
|
+
ht(
|
|
25
26
|
(r) => G(r == null ? void 0 : r.toString),
|
|
26
27
|
n,
|
|
27
28
|
"Expected `parts` to be an array of objects with a .toString() method. Got type: %t, value: %v"
|
|
@@ -49,9 +50,9 @@ function T(n, t) {
|
|
|
49
50
|
t = t.replace(/^\.\/?/, "");
|
|
50
51
|
else
|
|
51
52
|
break;
|
|
52
|
-
return
|
|
53
|
+
return N([e, t]);
|
|
53
54
|
}
|
|
54
|
-
function
|
|
55
|
+
function dt(n) {
|
|
55
56
|
if (!n) return {};
|
|
56
57
|
n.startsWith("?") && (n = n.slice(1));
|
|
57
58
|
const t = n.split("&").filter((e) => e.trim() !== "").map(
|
|
@@ -60,70 +61,70 @@ function pt(n) {
|
|
|
60
61
|
return Object.fromEntries(t);
|
|
61
62
|
}
|
|
62
63
|
function Y(n, t, e = {}) {
|
|
63
|
-
var
|
|
64
|
-
const [r, a] = t.split("?"),
|
|
64
|
+
var s;
|
|
65
|
+
const [r, a] = t.split("?"), i = O(r);
|
|
65
66
|
t: for (const h of n) {
|
|
66
67
|
const { fragments: o } = h;
|
|
67
|
-
if (!(((
|
|
68
|
+
if (!(((s = o[o.length - 1]) == null ? void 0 : s.type) === 3) && o.length !== i.length || e.willMatch && !e.willMatch(h))
|
|
68
69
|
continue t;
|
|
69
|
-
const
|
|
70
|
+
const f = [];
|
|
70
71
|
e: for (let c = 0; c < o.length; c++) {
|
|
71
|
-
const u =
|
|
72
|
-
if (u == null &&
|
|
72
|
+
const u = i[c], m = o[c];
|
|
73
|
+
if (u == null && m.type !== 3)
|
|
73
74
|
continue t;
|
|
74
|
-
switch (
|
|
75
|
+
switch (m.type) {
|
|
75
76
|
case 1:
|
|
76
|
-
if (
|
|
77
|
-
|
|
77
|
+
if (m.name.toLowerCase() === u.toLowerCase()) {
|
|
78
|
+
f.push(m);
|
|
78
79
|
break;
|
|
79
80
|
} else
|
|
80
81
|
continue t;
|
|
81
82
|
case 2:
|
|
82
|
-
|
|
83
|
+
f.push({ ...m, value: u });
|
|
83
84
|
break;
|
|
84
85
|
case 3:
|
|
85
|
-
|
|
86
|
+
f.push({ ...m, value: i.slice(c).join("/") });
|
|
86
87
|
break e;
|
|
87
88
|
case 4:
|
|
88
89
|
if (isNaN(Number(u)))
|
|
89
90
|
continue t;
|
|
90
|
-
|
|
91
|
+
f.push({ ...m, value: u });
|
|
91
92
|
break;
|
|
92
93
|
default:
|
|
93
|
-
throw new Error(`Unknown fragment type: ${
|
|
94
|
+
throw new Error(`Unknown fragment type: ${m.type}`);
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
|
-
const
|
|
97
|
-
for (const c of
|
|
98
|
-
c.type === 2 && (
|
|
97
|
+
const p = {};
|
|
98
|
+
for (const c of f)
|
|
99
|
+
c.type === 2 && (p[c.name] = decodeURIComponent(c.value)), c.type === 4 && (p[c.name] = String(c.value)), c.type === 3 && (p.wildcard = "/" + decodeURIComponent(c.value));
|
|
99
100
|
return {
|
|
100
|
-
path: "/" +
|
|
101
|
+
path: "/" + f.map((c) => c.value).join("/"),
|
|
101
102
|
pattern: "/" + o.map((c) => c.type === 2 ? `{${c.name}}` : c.type === 4 ? `{#${c.name}}` : c.name).join("/"),
|
|
102
|
-
params:
|
|
103
|
-
query:
|
|
103
|
+
params: p,
|
|
104
|
+
query: dt(a),
|
|
104
105
|
meta: h.meta
|
|
105
106
|
};
|
|
106
107
|
}
|
|
107
108
|
}
|
|
108
|
-
function
|
|
109
|
+
function mt(n) {
|
|
109
110
|
const t = [], e = [], r = [], a = [];
|
|
110
|
-
for (const
|
|
111
|
-
const { fragments: h } =
|
|
111
|
+
for (const s of n) {
|
|
112
|
+
const { fragments: h } = s;
|
|
112
113
|
h.some(
|
|
113
114
|
(o) => o.type === 3
|
|
114
115
|
/* Wildcard */
|
|
115
|
-
) ? a.push(
|
|
116
|
+
) ? a.push(s) : h.some(
|
|
116
117
|
(o) => o.type === 4
|
|
117
118
|
/* NumericParam */
|
|
118
|
-
) ? e.push(
|
|
119
|
+
) ? e.push(s) : h.some(
|
|
119
120
|
(o) => o.type === 2
|
|
120
121
|
/* Param */
|
|
121
|
-
) ? r.push(
|
|
122
|
+
) ? r.push(s) : t.push(s);
|
|
122
123
|
}
|
|
123
|
-
const
|
|
124
|
-
return t.sort(
|
|
124
|
+
const i = (s, h) => s.fragments.length > h.fragments.length ? -1 : 1;
|
|
125
|
+
return t.sort(i), e.sort(i), r.sort(i), a.sort(i), [...t, ...e, ...r, ...a];
|
|
125
126
|
}
|
|
126
|
-
function
|
|
127
|
+
function wt(n) {
|
|
127
128
|
const t = O(n), e = [];
|
|
128
129
|
for (let r = 0; r < t.length; r++) {
|
|
129
130
|
const a = t[r];
|
|
@@ -147,107 +148,124 @@ function mt(n) {
|
|
|
147
148
|
}
|
|
148
149
|
return e;
|
|
149
150
|
}
|
|
150
|
-
const
|
|
151
|
-
function
|
|
152
|
-
function r(
|
|
153
|
-
return !
|
|
151
|
+
const yt = /(noopener|noreferrer) (noopener|noreferrer)/, gt = /^[\w-_]+:/;
|
|
152
|
+
function bt(n, t, e = window) {
|
|
153
|
+
function r(i) {
|
|
154
|
+
return !i || i === n ? null : i.localName !== "a" || i.href === void 0 ? r(i.parentNode) : i;
|
|
154
155
|
}
|
|
155
|
-
function a(
|
|
156
|
-
if (
|
|
156
|
+
function a(i) {
|
|
157
|
+
if (i.button && i.button !== 0 || i.ctrlKey || i.metaKey || i.altKey || i.shiftKey || i.defaultPrevented)
|
|
157
158
|
return;
|
|
158
|
-
const
|
|
159
|
-
|
|
159
|
+
const s = r(i.target);
|
|
160
|
+
s && (e.location.protocol !== s.protocol || e.location.hostname !== s.hostname || e.location.port !== s.port || s.hasAttribute("data-router-ignore") || s.hasAttribute("download") || s.getAttribute("target") === "_blank" && yt.test(s.getAttribute("rel")) || gt.test(s.getAttribute("href")) || (i.preventDefault(), t(s)));
|
|
160
161
|
}
|
|
161
162
|
return n.addEventListener("click", a), function() {
|
|
162
163
|
n.removeEventListener("click", a);
|
|
163
164
|
};
|
|
164
165
|
}
|
|
165
|
-
function
|
|
166
|
+
function $t(n, t) {
|
|
166
167
|
for (const e in t) {
|
|
167
168
|
const r = t[e].toString();
|
|
168
169
|
n = n.replace(`{${e}}`, r).replace(`{#${e}}`, r);
|
|
169
170
|
}
|
|
170
171
|
return n;
|
|
171
172
|
}
|
|
172
|
-
const
|
|
173
|
-
var S, I, v,
|
|
174
|
-
class
|
|
173
|
+
const vt = Symbol(), kt = Symbol();
|
|
174
|
+
var S, I, v, j, Q, x, k, L, $, w, Z, _, tt, W, F, K;
|
|
175
|
+
class xt {
|
|
175
176
|
constructor(t) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
177
|
+
b(this, w);
|
|
178
|
+
b(this, S, nt("dolla.router"));
|
|
179
|
+
b(this, I, 0);
|
|
180
|
+
b(this, v, []);
|
|
181
|
+
b(this, j, []);
|
|
182
|
+
b(this, Q, !1);
|
|
183
|
+
b(this, x);
|
|
183
184
|
/**
|
|
184
185
|
* Use hash routing when true. Configured in router options.
|
|
185
186
|
*/
|
|
186
|
-
|
|
187
|
+
b(this, k, !1);
|
|
187
188
|
/**
|
|
188
189
|
* Cleanup functions to call on unmount.
|
|
189
190
|
*/
|
|
190
|
-
|
|
191
|
+
b(this, L, []);
|
|
192
|
+
/**
|
|
193
|
+
* The current match object (internal).
|
|
194
|
+
*/
|
|
195
|
+
b(this, $, R());
|
|
191
196
|
/**
|
|
192
197
|
* The current match object.
|
|
193
198
|
*/
|
|
194
|
-
|
|
199
|
+
P(this, "$match", R(
|
|
200
|
+
() => {
|
|
201
|
+
const t = l(this, $).call(this);
|
|
202
|
+
if (t)
|
|
203
|
+
return {
|
|
204
|
+
path: t.path,
|
|
205
|
+
pattern: t.pattern,
|
|
206
|
+
params: { ...t.params },
|
|
207
|
+
query: { ...t.query },
|
|
208
|
+
data: t.meta.data ?? {}
|
|
209
|
+
};
|
|
210
|
+
},
|
|
211
|
+
{ equals: ct }
|
|
212
|
+
));
|
|
195
213
|
/**
|
|
196
214
|
* The currently matched route pattern, if any.
|
|
197
215
|
*/
|
|
198
|
-
|
|
216
|
+
P(this, "$pattern", R(() => {
|
|
199
217
|
var t;
|
|
200
|
-
return (t = l(this,
|
|
218
|
+
return (t = l(this, $).call(this)) == null ? void 0 : t.pattern;
|
|
201
219
|
}));
|
|
202
220
|
/**
|
|
203
221
|
* The current URL path.
|
|
204
222
|
*/
|
|
205
|
-
|
|
223
|
+
P(this, "$path", R(() => {
|
|
206
224
|
var t;
|
|
207
|
-
return ((t = l(this,
|
|
225
|
+
return ((t = l(this, $).call(this)) == null ? void 0 : t.path) ?? window.location.pathname;
|
|
208
226
|
}));
|
|
209
227
|
/**
|
|
210
228
|
* The current named path params.
|
|
211
229
|
*/
|
|
212
|
-
|
|
230
|
+
P(this, "$params", R(() => {
|
|
213
231
|
var t;
|
|
214
|
-
return ((t = l(this,
|
|
232
|
+
return ((t = l(this, $).call(this)) == null ? void 0 : t.params) ?? {};
|
|
215
233
|
}, { equals: B }));
|
|
216
234
|
/**
|
|
217
235
|
* The current query params.
|
|
218
236
|
*/
|
|
219
|
-
|
|
237
|
+
P(this, "$query", R(() => {
|
|
220
238
|
var t;
|
|
221
|
-
return ((t = l(this,
|
|
239
|
+
return ((t = l(this, $).call(this)) == null ? void 0 : t.query) ?? {};
|
|
222
240
|
}, { equals: B }));
|
|
223
|
-
|
|
224
|
-
t.routes.flatMap((e) =>
|
|
241
|
+
ft(t, "Options must be an object. Got: %t"), t.hash && M(this, k, !0), M(this, j, mt(
|
|
242
|
+
t.routes.flatMap((e) => g(this, w, K).call(this, e)).map((e) => ({
|
|
225
243
|
pattern: e.pattern,
|
|
226
244
|
meta: e.meta,
|
|
227
|
-
fragments:
|
|
245
|
+
fragments: wt(e.pattern)
|
|
228
246
|
}))
|
|
229
|
-
)),
|
|
247
|
+
)), Et(l(this, j));
|
|
230
248
|
}
|
|
231
|
-
async [
|
|
232
|
-
const r =
|
|
233
|
-
|
|
249
|
+
async [vt](t, e) {
|
|
250
|
+
const r = R();
|
|
251
|
+
M(this, x, {
|
|
234
252
|
id: D(this, I)._++,
|
|
235
|
-
|
|
253
|
+
node: new st(e, r),
|
|
236
254
|
context: e,
|
|
237
255
|
$slot: r
|
|
238
256
|
});
|
|
239
|
-
const a = () =>
|
|
257
|
+
const a = () => g(this, w, W).call(this);
|
|
240
258
|
return window.addEventListener("popstate", a), l(this, L).push(() => window.removeEventListener("popstate", a)), l(this, L).push(
|
|
241
|
-
|
|
242
|
-
l(this, S).info("intercepted click on <a> tag",
|
|
243
|
-
const
|
|
244
|
-
this.go(
|
|
245
|
-
preserveQuery:
|
|
259
|
+
bt(t, (i) => {
|
|
260
|
+
l(this, S).info("intercepted click on <a> tag", i);
|
|
261
|
+
const s = i.getAttribute("href"), h = i.getAttribute("data-router-preserve-query");
|
|
262
|
+
this.go(s, {
|
|
263
|
+
preserveQuery: qt(h)
|
|
246
264
|
});
|
|
247
265
|
})
|
|
248
|
-
), l(this, S).info("will intercept clicks on <a> tags within parent element:", t),
|
|
266
|
+
), l(this, S).info("will intercept clicks on <a> tags within parent element:", t), M(this, Q, !0), await g(this, w, W).call(this), l(this, x).node;
|
|
249
267
|
}
|
|
250
|
-
async [
|
|
268
|
+
async [kt]() {
|
|
251
269
|
for (const t of l(this, L))
|
|
252
270
|
t();
|
|
253
271
|
l(this, L).length = 0;
|
|
@@ -273,34 +291,34 @@ class Pt {
|
|
|
273
291
|
*/
|
|
274
292
|
go(t, e = {}) {
|
|
275
293
|
let r;
|
|
276
|
-
Array.isArray(t) ? r =
|
|
294
|
+
Array.isArray(t) ? r = N(t) : r = t.toString(), r = T(window.location.pathname, r), e.replace ? g(this, w, _).call(this, r, e) : g(this, w, Z).call(this, r, e);
|
|
277
295
|
}
|
|
278
296
|
/**
|
|
279
297
|
* Updates query params, keeping existing ones and applying new ones. Removes the query param if value is set to `null`.
|
|
280
298
|
*/
|
|
281
299
|
updateQuery(t) {
|
|
282
|
-
const e = H(l(this,
|
|
283
|
-
for (const
|
|
284
|
-
const h = t[
|
|
285
|
-
h === null ? delete r[
|
|
300
|
+
const e = H(l(this, $)), r = { ...this.$query() };
|
|
301
|
+
for (const s in t) {
|
|
302
|
+
const h = t[s];
|
|
303
|
+
h === null ? delete r[s] : r[s] = h.toString();
|
|
286
304
|
}
|
|
287
305
|
let a = [];
|
|
288
|
-
for (const
|
|
289
|
-
a.push(`${
|
|
290
|
-
const
|
|
291
|
-
l(this,
|
|
306
|
+
for (const s in r)
|
|
307
|
+
a.push(`${s}=${r[s]}`);
|
|
308
|
+
const i = a.length > 0 ? "?" + a.join("&") : "";
|
|
309
|
+
l(this, $).call(this, { ...e, query: r }), window.history.replaceState(null, "", l(this, k) ? "/#" + e.path + i : e.path + i);
|
|
292
310
|
}
|
|
293
311
|
}
|
|
294
|
-
S = new WeakMap(), I = new WeakMap(), v = new WeakMap(),
|
|
295
|
-
l(this, S).info("(push)", t), window.history.pushState(null, "", l(this, k) ? "/#" + t : t),
|
|
312
|
+
S = new WeakMap(), I = new WeakMap(), v = new WeakMap(), j = new WeakMap(), Q = new WeakMap(), x = new WeakMap(), k = new WeakMap(), L = new WeakMap(), $ = new WeakMap(), w = new WeakSet(), Z = function(t, e) {
|
|
313
|
+
l(this, S).info("(push)", t), window.history.pushState(null, "", l(this, k) ? "/#" + t : t), g(this, w, W).call(this, t, e);
|
|
296
314
|
}, _ = function(t, e) {
|
|
297
|
-
l(this, S).info("(replace)", t), window.history.replaceState(null, "", l(this, k) ? "/#" + t : t),
|
|
315
|
+
l(this, S).info("(replace)", t), window.history.replaceState(null, "", l(this, k) ? "/#" + t : t), g(this, w, W).call(this, t, e);
|
|
298
316
|
}, tt = function() {
|
|
299
317
|
return l(this, k) ? new URL(window.location.hash.slice(1), window.location.origin) : new URL(window.location.pathname, window.location.origin);
|
|
300
|
-
},
|
|
301
|
-
const r = l(this, S), a = t ? new URL(t, window.location.origin) :
|
|
302
|
-
for (let
|
|
303
|
-
const c =
|
|
318
|
+
}, W = async function(t, e = {}) {
|
|
319
|
+
const r = l(this, S), a = t ? new URL(t, window.location.origin) : g(this, w, tt).call(this), { match: i, journey: s, state: h } = await g(this, w, F).call(this, a);
|
|
320
|
+
for (let p = 0; p < s.length; p++) {
|
|
321
|
+
const c = s[p], u = `(update: step ${p + 1} of ${s.length})`;
|
|
304
322
|
switch (c.kind) {
|
|
305
323
|
case "match":
|
|
306
324
|
r == null || r.info(`${u} 📍 ${c.message}`);
|
|
@@ -313,119 +331,120 @@ S = new WeakMap(), I = new WeakMap(), v = new WeakMap(), P = new WeakMap(), Q =
|
|
|
313
331
|
break;
|
|
314
332
|
}
|
|
315
333
|
}
|
|
316
|
-
if (!
|
|
334
|
+
if (!i) {
|
|
317
335
|
if (l(this, Q))
|
|
318
336
|
throw r.crash(new Rt(`Failed to match route '${a.pathname}'`));
|
|
319
337
|
return;
|
|
320
338
|
}
|
|
321
|
-
let o =
|
|
339
|
+
let o = i.query, d = [];
|
|
322
340
|
if (e.preserveQuery === !0)
|
|
323
|
-
o = Object.assign({}, this.$query(),
|
|
341
|
+
o = Object.assign({}, this.$query(), i.query);
|
|
324
342
|
else if (J(e.preserveQuery)) {
|
|
325
|
-
const
|
|
343
|
+
const p = {}, c = this.$query();
|
|
326
344
|
for (const u in c)
|
|
327
|
-
e.preserveQuery.includes(u) && (
|
|
328
|
-
o = Object.assign({},
|
|
345
|
+
e.preserveQuery.includes(u) && (p[u] = c[u]);
|
|
346
|
+
o = Object.assign({}, p, i.query);
|
|
329
347
|
}
|
|
330
|
-
for (const
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
return (
|
|
334
|
-
const
|
|
335
|
-
if (l(this,
|
|
348
|
+
for (const p in o)
|
|
349
|
+
d.push(`${p}=${o[p]}`);
|
|
350
|
+
const f = d.length > 0 ? "?" + d.join("&") : "";
|
|
351
|
+
return (i.path !== location.pathname || location.search !== f) && window.history.replaceState(null, "", l(this, k) ? "/#" + i.path + f : i.path + f), lt(() => {
|
|
352
|
+
const p = H(this.$pattern);
|
|
353
|
+
if (l(this, $).call(this, { ...i, query: o }), i.pattern === p) {
|
|
336
354
|
for (const u of l(this, v)) {
|
|
337
|
-
const
|
|
338
|
-
|
|
355
|
+
const m = h.get(u.id);
|
|
356
|
+
m && u.context.setState(m);
|
|
339
357
|
}
|
|
340
358
|
return;
|
|
341
359
|
}
|
|
342
|
-
const c =
|
|
343
|
-
r.info("mounting",
|
|
360
|
+
const c = i.meta.layers;
|
|
361
|
+
r.info("mounting", i);
|
|
344
362
|
for (let u = 0; u < c.length; u++) {
|
|
345
|
-
const
|
|
346
|
-
if ((
|
|
347
|
-
|
|
348
|
-
const E = l(this, v).at(-1) ?? l(this,
|
|
349
|
-
children: ot
|
|
350
|
-
}), z = h.get(
|
|
351
|
-
z &&
|
|
352
|
-
id:
|
|
353
|
-
|
|
354
|
-
context:
|
|
355
|
-
$slot:
|
|
356
|
-
}), E.$slot(
|
|
363
|
+
const m = c[u], y = l(this, v)[u];
|
|
364
|
+
if ((y == null ? void 0 : y.id) !== m.id) {
|
|
365
|
+
M(this, v, l(this, v).slice(0, u)), y == null || y.node.unmount();
|
|
366
|
+
const E = l(this, v).at(-1) ?? l(this, x), q = R(), A = new it(E.context, m.view, {
|
|
367
|
+
children: at(ot.Dynamic, { source: q })
|
|
368
|
+
}), z = h.get(m.id);
|
|
369
|
+
z && A.context.setState(z), l(this, v).push({
|
|
370
|
+
id: m.id,
|
|
371
|
+
node: A,
|
|
372
|
+
context: A.context,
|
|
373
|
+
$slot: q
|
|
374
|
+
}), E.$slot(A);
|
|
357
375
|
} else {
|
|
358
|
-
const E = h.get(
|
|
359
|
-
E &&
|
|
376
|
+
const E = h.get(y.id);
|
|
377
|
+
E && y.context.setState(E);
|
|
360
378
|
}
|
|
361
379
|
}
|
|
362
|
-
}), { match:
|
|
380
|
+
}), { match: i, journey: s };
|
|
363
381
|
}, F = async function(t, e = [], r = /* @__PURE__ */ new Map()) {
|
|
364
|
-
return new Promise((a,
|
|
365
|
-
var
|
|
366
|
-
const
|
|
367
|
-
if (!
|
|
382
|
+
return new Promise((a, i) => {
|
|
383
|
+
var d;
|
|
384
|
+
const s = Y(l(this, j), t.pathname);
|
|
385
|
+
if (!s)
|
|
368
386
|
return a({
|
|
369
387
|
match: null,
|
|
370
388
|
journey: [...e, { kind: "miss", message: `no match for '${t.pathname}'` }],
|
|
371
389
|
state: r
|
|
372
390
|
});
|
|
373
|
-
let h =
|
|
391
|
+
let h = s.meta.redirect;
|
|
374
392
|
const o = async () => {
|
|
375
393
|
if (h != null) {
|
|
376
|
-
let
|
|
394
|
+
let f;
|
|
377
395
|
if (U(h))
|
|
378
|
-
|
|
396
|
+
f = $t(h, s.params);
|
|
379
397
|
else if (G(h)) {
|
|
380
|
-
const
|
|
381
|
-
path:
|
|
382
|
-
pattern:
|
|
383
|
-
params:
|
|
384
|
-
query:
|
|
398
|
+
const p = {
|
|
399
|
+
path: s.path,
|
|
400
|
+
pattern: s.pattern,
|
|
401
|
+
params: s.params,
|
|
402
|
+
query: s.query,
|
|
403
|
+
data: s.meta.data ?? {}
|
|
385
404
|
};
|
|
386
|
-
if (
|
|
387
|
-
return
|
|
388
|
-
|
|
405
|
+
if (f = await h(p), !U(f))
|
|
406
|
+
return i(new Error("Redirect function must return a path to redirect to."));
|
|
407
|
+
f.startsWith("/") || (f = T(s.path, f));
|
|
389
408
|
} else
|
|
390
|
-
return
|
|
409
|
+
return i(new TypeError("Redirect must either be a path string or a function."));
|
|
391
410
|
a(
|
|
392
|
-
|
|
411
|
+
g(this, w, F).call(this, new URL(f, window.location.origin), [
|
|
393
412
|
...e,
|
|
394
|
-
{ kind: "redirect", message: `redirecting '${
|
|
413
|
+
{ kind: "redirect", message: `redirecting '${s.path}' -> '${f}'` }
|
|
395
414
|
])
|
|
396
415
|
);
|
|
397
416
|
} else
|
|
398
|
-
a({ match:
|
|
417
|
+
a({ match: s, journey: [...e, { kind: "match", message: `matched route '${s.path}'` }], state: r });
|
|
399
418
|
};
|
|
400
|
-
if ((
|
|
401
|
-
const
|
|
402
|
-
let
|
|
419
|
+
if ((d = s.meta.beforeMatch) != null && d.length) {
|
|
420
|
+
const f = s.meta.beforeMatch;
|
|
421
|
+
let p = -1;
|
|
403
422
|
const c = () => {
|
|
404
|
-
if (
|
|
423
|
+
if (p++, p === f.length)
|
|
405
424
|
o();
|
|
406
425
|
else {
|
|
407
426
|
let u = !1;
|
|
408
|
-
const
|
|
409
|
-
path:
|
|
410
|
-
pattern:
|
|
411
|
-
params:
|
|
412
|
-
query:
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
427
|
+
const m = f[p].fn({
|
|
428
|
+
path: s.path,
|
|
429
|
+
pattern: s.pattern,
|
|
430
|
+
params: s.params,
|
|
431
|
+
query: s.query,
|
|
432
|
+
data: s.meta.data ?? {},
|
|
433
|
+
setState: (...y) => {
|
|
434
|
+
const E = f[p].layerId, q = [];
|
|
435
|
+
if (y.length === 1 && pt(J, y[0]))
|
|
436
|
+
q.push(...y[0]);
|
|
437
|
+
else if (y.length === 2)
|
|
438
|
+
q.push([y[0], y[1]]);
|
|
419
439
|
else
|
|
420
440
|
throw new Error("Invalid arguments.");
|
|
421
|
-
r.get(E) ?
|
|
441
|
+
r.get(E) ? q.push(...q) : r.set(E, q);
|
|
422
442
|
},
|
|
423
|
-
redirect: (
|
|
424
|
-
h =
|
|
443
|
+
redirect: (y) => {
|
|
444
|
+
h = y, u = !0, o();
|
|
425
445
|
}
|
|
426
|
-
// next,
|
|
427
446
|
});
|
|
428
|
-
u || (
|
|
447
|
+
u || (m instanceof Promise ? m.then(c) : c());
|
|
429
448
|
}
|
|
430
449
|
};
|
|
431
450
|
c();
|
|
@@ -451,38 +470,46 @@ K = function(t, e = [], r = []) {
|
|
|
451
470
|
for (const o of e)
|
|
452
471
|
a.push(...O(o.path));
|
|
453
472
|
a.push(...O(t.path)), a[a.length - 1] === "*" && a.pop();
|
|
454
|
-
const
|
|
473
|
+
const i = [];
|
|
455
474
|
if (t.redirect) {
|
|
456
475
|
let o = t.redirect;
|
|
457
|
-
|
|
458
|
-
|
|
476
|
+
U(o) && (o = T(N(a), o), o.startsWith("/") || (o = "/" + o));
|
|
477
|
+
const d = {
|
|
478
|
+
pattern: "/" + N([...a, ...O(t.path)]),
|
|
459
479
|
meta: {
|
|
460
480
|
redirect: o
|
|
461
481
|
}
|
|
462
|
-
}
|
|
482
|
+
};
|
|
483
|
+
return i.push(d), i;
|
|
463
484
|
}
|
|
464
|
-
let
|
|
485
|
+
let s = (o) => o.children;
|
|
465
486
|
if (G(t.view))
|
|
466
|
-
|
|
487
|
+
s = t.view;
|
|
467
488
|
else if (t.view)
|
|
468
489
|
throw new TypeError(`Route '${t.path}' expected a view function or undefined. Got: ${t.view}`);
|
|
469
|
-
const h = { id: D(this, I)._++, view:
|
|
490
|
+
const h = { id: D(this, I)._++, view: s };
|
|
470
491
|
if (t.routes)
|
|
471
492
|
for (const o of t.routes)
|
|
472
|
-
|
|
473
|
-
else
|
|
474
|
-
|
|
475
|
-
pattern: e.length ?
|
|
493
|
+
i.push(...g(this, w, K).call(this, o, [...e, t], [...r, h]));
|
|
494
|
+
else {
|
|
495
|
+
const o = {
|
|
496
|
+
pattern: e.length ? N([...e.map((d) => d.path), t.path]) : t.path,
|
|
476
497
|
meta: {
|
|
477
498
|
pattern: t.path,
|
|
478
499
|
layers: [...r, h],
|
|
479
500
|
// Store the layer ID with each beforeMatch so we can correlate which context needs to get any state that is set.
|
|
480
|
-
beforeMatch: e.flatMap((
|
|
501
|
+
beforeMatch: e.flatMap((d, f) => d.beforeMatch ? { fn: d.beforeMatch, layerId: r[f].id } : null).concat(t.beforeMatch ? { fn: t.beforeMatch, layerId: h.id } : null).filter((d) => d != null)
|
|
481
502
|
}
|
|
482
|
-
}
|
|
483
|
-
|
|
503
|
+
};
|
|
504
|
+
if (t.data) {
|
|
505
|
+
const d = e.at(-1);
|
|
506
|
+
d ? o.meta.data = { ...d.data, ...t.data } : o.meta.data = t.data;
|
|
507
|
+
}
|
|
508
|
+
i.push(o);
|
|
509
|
+
}
|
|
510
|
+
return i;
|
|
484
511
|
};
|
|
485
|
-
function
|
|
512
|
+
function Et(n) {
|
|
486
513
|
for (const t of n)
|
|
487
514
|
if (t.meta.redirect) {
|
|
488
515
|
let e;
|
|
@@ -497,7 +524,7 @@ function kt(n) {
|
|
|
497
524
|
throw new TypeError(`Expected a string or redirect function. Got: ${t.meta.redirect}`);
|
|
498
525
|
}
|
|
499
526
|
}
|
|
500
|
-
function
|
|
527
|
+
function qt(n) {
|
|
501
528
|
if (n === null)
|
|
502
529
|
return !1;
|
|
503
530
|
if (n === !0 || n === !1)
|
|
@@ -509,8 +536,8 @@ function Et(n) {
|
|
|
509
536
|
class Rt extends Error {
|
|
510
537
|
}
|
|
511
538
|
export {
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
539
|
+
vt as M,
|
|
540
|
+
xt as R,
|
|
541
|
+
kt as U
|
|
515
542
|
};
|
|
516
|
-
//# sourceMappingURL=router-
|
|
543
|
+
//# sourceMappingURL=router-CjCkk4dA.js.map
|