@manyducks.co/dolla 3.2.0 â 4.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/dist/core/context.d.ts +9 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/root.d.ts +4 -6
- package/dist/core/signals.d.ts +34 -1
- package/dist/{core-2CFW0uRa.js â core-CHBZF6Mb.js} +113 -101
- package/dist/core-CHBZF6Mb.js.map +1 -0
- package/dist/index.js +2 -2
- package/dist/jsx-dev-runtime.js +1 -1
- package/dist/jsx-runtime.js +1 -1
- package/dist/router/index.d.ts +1 -1
- package/dist/router/router.d.ts +1 -1
- package/dist/router.js +139 -139
- package/dist/router.js.map +1 -1
- package/dist/translate/index.d.ts +1 -1
- package/dist/translate.js +18 -18
- package/dist/translate.js.map +1 -1
- package/package.json +1 -1
- package/dist/core-2CFW0uRa.js.map +0 -1
package/dist/router.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { B as e, D as t, E as n, F as r, I as i, L as a, M as o, O as s, P as c, R as l, S as u, T as d, _ as f, b as p, c as m, f as h, g, h as _, p as v, w as y, x as b, y as x, z as S } from "./core-CHBZF6Mb.js";
|
|
2
2
|
//#region src/router/utils.ts
|
|
3
3
|
function C(e) {
|
|
4
4
|
return e.split("/").map((e) => e.trim()).filter(Boolean);
|
|
@@ -17,12 +17,12 @@ function T(e, t = null) {
|
|
|
17
17
|
function E(e) {
|
|
18
18
|
return Object.fromEntries(new URLSearchParams(e));
|
|
19
19
|
}
|
|
20
|
-
function D(e, t,
|
|
21
|
-
let
|
|
22
|
-
if (
|
|
23
|
-
else if (n
|
|
24
|
-
for (let [e, n] of Object.entries(t)) n === null ? delete
|
|
25
|
-
return new URLSearchParams(
|
|
20
|
+
function D(e, t, n) {
|
|
21
|
+
let r = {};
|
|
22
|
+
if (n === !0) Object.assign(r, e);
|
|
23
|
+
else if (i(n)) for (let t of n) t in e && (r[t] = e[t]);
|
|
24
|
+
for (let [e, n] of Object.entries(t)) n === null ? delete r[e] : r[e] = n;
|
|
25
|
+
return new URLSearchParams(r);
|
|
26
26
|
}
|
|
27
27
|
var O = class {
|
|
28
28
|
staticChildren = /* @__PURE__ */ new Map();
|
|
@@ -33,68 +33,68 @@ var O = class {
|
|
|
33
33
|
paramName;
|
|
34
34
|
numericName;
|
|
35
35
|
};
|
|
36
|
-
function k(
|
|
37
|
-
let
|
|
38
|
-
function
|
|
39
|
-
let r = C(e), i =
|
|
36
|
+
function k(t) {
|
|
37
|
+
let n = new O(), i = [];
|
|
38
|
+
function o(e, t) {
|
|
39
|
+
let r = C(e), i = n;
|
|
40
40
|
for (let e of r) if (e === "*") i = i.wildcardChild ??= new O();
|
|
41
41
|
else if (e.charCodeAt(0) === 123) e.charCodeAt(1) === 35 ? (i = i.numericChild ??= new O(), i.numericName = e.slice(2, -1)) : (i = i.paramChild ??= new O(), i.paramName = e.slice(1, -1));
|
|
42
42
|
else {
|
|
43
43
|
let t = e.toLowerCase(), n = i.staticChildren.get(t);
|
|
44
44
|
n || i.staticChildren.set(t, n = new O()), i = n;
|
|
45
45
|
}
|
|
46
|
-
i.route =
|
|
46
|
+
i.route = t;
|
|
47
47
|
}
|
|
48
|
-
function
|
|
49
|
-
|
|
50
|
-
let u =
|
|
48
|
+
function s(t, n = [], c = []) {
|
|
49
|
+
r(l(t) && S(t.path), "Invalid route object");
|
|
50
|
+
let u = n.map((e) => e.path), d = n.at(-1), f = d && t.meta ? {
|
|
51
51
|
...d.meta,
|
|
52
|
-
...
|
|
53
|
-
} :
|
|
54
|
-
if (
|
|
55
|
-
|
|
56
|
-
let
|
|
57
|
-
|
|
58
|
-
for (let
|
|
59
|
-
let
|
|
60
|
-
pattern:
|
|
52
|
+
...t.meta
|
|
53
|
+
} : t.meta || {}, p = u.length ? w([...u, t.path]) : t.path, m = N(p);
|
|
54
|
+
if (t.redirect) {
|
|
55
|
+
r(!t.routes && !t.view, "Route cannot mix redirect with view/routes");
|
|
56
|
+
let e = t.redirect;
|
|
57
|
+
S(e) && (e = T(w(u), e), e.startsWith("/") || (e = "/" + e));
|
|
58
|
+
for (let t of m) {
|
|
59
|
+
let n = {
|
|
60
|
+
pattern: t,
|
|
61
61
|
meta: f,
|
|
62
|
-
redirect:
|
|
62
|
+
redirect: e
|
|
63
63
|
};
|
|
64
|
-
|
|
64
|
+
o(t, n), S(e) && i.push(n);
|
|
65
65
|
}
|
|
66
66
|
return;
|
|
67
67
|
}
|
|
68
|
-
|
|
69
|
-
let h =
|
|
70
|
-
if (!
|
|
71
|
-
if (
|
|
72
|
-
let
|
|
73
|
-
id:
|
|
68
|
+
r(t.view || t.routes, "Route must have view, redirect, or routes");
|
|
69
|
+
let h = t.view || ((e) => e.children);
|
|
70
|
+
if (!a(h) && !h._lazy) throw TypeError(`Expected view function for ${t.path}`);
|
|
71
|
+
if (t.routes) {
|
|
72
|
+
let r = {
|
|
73
|
+
id: e(),
|
|
74
74
|
pattern: p,
|
|
75
75
|
view: h,
|
|
76
|
-
preload:
|
|
77
|
-
errorView:
|
|
76
|
+
preload: t.preload,
|
|
77
|
+
errorView: t.errorView
|
|
78
78
|
};
|
|
79
|
-
for (let
|
|
80
|
-
} else for (let
|
|
81
|
-
let
|
|
82
|
-
id:
|
|
83
|
-
pattern:
|
|
79
|
+
for (let e of t.routes) s(e, [...n, t], [...c, r]);
|
|
80
|
+
} else for (let n of m) {
|
|
81
|
+
let r = {
|
|
82
|
+
id: e(),
|
|
83
|
+
pattern: n,
|
|
84
84
|
view: h,
|
|
85
|
-
preload:
|
|
86
|
-
errorView:
|
|
85
|
+
preload: t.preload,
|
|
86
|
+
errorView: t.errorView
|
|
87
87
|
};
|
|
88
|
-
|
|
89
|
-
pattern:
|
|
88
|
+
o(n, {
|
|
89
|
+
pattern: n,
|
|
90
90
|
meta: f,
|
|
91
|
-
layers: [...
|
|
91
|
+
layers: [...c, r]
|
|
92
92
|
});
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
-
for (let
|
|
96
|
-
for (let e of
|
|
97
|
-
return
|
|
95
|
+
for (let e of t) s(e);
|
|
96
|
+
for (let e of i) r(A(n, e.redirect, { willMatch: (t) => t !== e }), `Dead redirect: ${e.pattern} -> ${e.redirect}`);
|
|
97
|
+
return n;
|
|
98
98
|
}
|
|
99
99
|
function A(e, t, n = {}) {
|
|
100
100
|
let [r, i] = t.split("?"), a = C(r), o = {};
|
|
@@ -152,23 +152,23 @@ function A(e, t, n = {}) {
|
|
|
152
152
|
return s(e, 0);
|
|
153
153
|
}
|
|
154
154
|
async function j(e, t, n = []) {
|
|
155
|
-
let
|
|
156
|
-
if (!
|
|
155
|
+
let i = A(e, t);
|
|
156
|
+
if (!i) return { journey: [...n, {
|
|
157
157
|
kind: "miss",
|
|
158
158
|
message: `no match for '${t}'`
|
|
159
159
|
}] };
|
|
160
|
-
if (
|
|
161
|
-
let t =
|
|
162
|
-
return
|
|
160
|
+
if (i.redirect != null) {
|
|
161
|
+
let t = i.redirect;
|
|
162
|
+
return S(t) ? t = P(t, i.params) : (t = await t(i), r(S(t), "Redirect function must return a path."), t.startsWith("/") || (t = T(i.path, t))), j(e, t, [...n, {
|
|
163
163
|
kind: "redirect",
|
|
164
|
-
message: `redirecting '${
|
|
164
|
+
message: `redirecting '${i.path}' -> '${t}'`
|
|
165
165
|
}]);
|
|
166
166
|
}
|
|
167
167
|
return {
|
|
168
|
-
match:
|
|
168
|
+
match: i,
|
|
169
169
|
journey: [...n, {
|
|
170
170
|
kind: "match",
|
|
171
|
-
message: `matched route '${
|
|
171
|
+
message: `matched route '${i.path}'`
|
|
172
172
|
}]
|
|
173
173
|
};
|
|
174
174
|
}
|
|
@@ -200,75 +200,75 @@ function P(e, t) {
|
|
|
200
200
|
}
|
|
201
201
|
return e = e.replace(/\{#?[a-zA-Z0-9_]+\?\}/g, ""), e = e.replace(/\/+/g, "/"), e.length > 1 && e.endsWith("/") && (e = e.slice(0, -1)), e;
|
|
202
202
|
}
|
|
203
|
-
function F(
|
|
204
|
-
let
|
|
203
|
+
function F(t) {
|
|
204
|
+
let n = window.history.state?.index || 0;
|
|
205
205
|
window.history.state?.index === void 0 && window.history.replaceState({
|
|
206
206
|
...window.history.state,
|
|
207
207
|
key: Date.now().toString(),
|
|
208
|
-
index:
|
|
208
|
+
index: n
|
|
209
209
|
}, "");
|
|
210
|
-
let
|
|
210
|
+
let r = t ? () => window.location.hash.slice(1).split("?")[0] || "/" : () => window.location.pathname, i = t ? () => {
|
|
211
211
|
let e = window.location.hash, t = e.indexOf("?");
|
|
212
212
|
return t === -1 ? "" : e.slice(t);
|
|
213
|
-
} : () => window.location.search,
|
|
213
|
+
} : () => window.location.search, a = () => window.history.state?.key || "root";
|
|
214
214
|
return {
|
|
215
|
-
getPath:
|
|
216
|
-
getSearch:
|
|
217
|
-
getKey:
|
|
215
|
+
getPath: r,
|
|
216
|
+
getSearch: i,
|
|
217
|
+
getKey: a,
|
|
218
218
|
getIndex: () => window.history.state?.index || 0,
|
|
219
|
-
push: (
|
|
220
|
-
|
|
221
|
-
let
|
|
219
|
+
push: (r) => {
|
|
220
|
+
n++;
|
|
221
|
+
let i = t ? "/#" : "";
|
|
222
222
|
window.history.pushState({
|
|
223
|
-
key:
|
|
224
|
-
index:
|
|
225
|
-
}, "",
|
|
223
|
+
key: e(),
|
|
224
|
+
index: n
|
|
225
|
+
}, "", i + r);
|
|
226
226
|
},
|
|
227
|
-
replace: (
|
|
228
|
-
let r =
|
|
227
|
+
replace: (e) => {
|
|
228
|
+
let r = t ? "/#" : "";
|
|
229
229
|
window.history.replaceState({
|
|
230
|
-
key:
|
|
231
|
-
index:
|
|
232
|
-
}, "", r +
|
|
230
|
+
key: a(),
|
|
231
|
+
index: n
|
|
232
|
+
}, "", r + e);
|
|
233
233
|
}
|
|
234
234
|
};
|
|
235
235
|
}
|
|
236
236
|
//#endregion
|
|
237
237
|
//#region src/router/store.ts
|
|
238
|
-
function I({ currentMatch:
|
|
238
|
+
function I({ currentMatch: e, setCurrentMatch: n, progress: r, history: i, updateRoute: a, guards: s }) {
|
|
239
239
|
this.name = "dolla:router";
|
|
240
|
-
let
|
|
241
|
-
async function
|
|
240
|
+
let l = m(this);
|
|
241
|
+
async function u(e, t) {
|
|
242
242
|
for (let e of s) if (await e()) return;
|
|
243
|
-
|
|
243
|
+
l.info(`đēī¸ navigating to '${e}'${t ? " (replace)" : ""}`);
|
|
244
244
|
let n = T(i.getPath(), e);
|
|
245
|
-
t ? i.replace(n) : i.push(n),
|
|
245
|
+
t ? i.replace(n) : i.push(n), a();
|
|
246
246
|
}
|
|
247
247
|
return {
|
|
248
|
-
path:
|
|
249
|
-
pattern:
|
|
250
|
-
params:
|
|
251
|
-
query:
|
|
252
|
-
meta:
|
|
248
|
+
path: t(() => e().path),
|
|
249
|
+
pattern: t(() => e().pattern),
|
|
250
|
+
params: t(() => e().params),
|
|
251
|
+
query: t(() => e().query),
|
|
252
|
+
meta: t(() => e().meta),
|
|
253
253
|
progress: r,
|
|
254
|
-
setQuery(
|
|
255
|
-
let r =
|
|
254
|
+
setQuery(t) {
|
|
255
|
+
let r = o(e), a = D(r.query, t, !0), s = Object.fromEntries(a);
|
|
256
256
|
n({
|
|
257
257
|
...r,
|
|
258
|
-
query:
|
|
258
|
+
query: s
|
|
259
259
|
});
|
|
260
|
-
let
|
|
261
|
-
return i.replace(r.path +
|
|
260
|
+
let c = a.size ? "?" + a.toString() : "";
|
|
261
|
+
return i.replace(r.path + c), s;
|
|
262
262
|
},
|
|
263
263
|
back: (e = 1) => window.history.go(-e),
|
|
264
264
|
forward: (e = 1) => window.history.go(e),
|
|
265
|
-
push: (e) =>
|
|
266
|
-
replace: (e) =>
|
|
265
|
+
push: (e) => u(e, !1),
|
|
266
|
+
replace: (e) => u(e, !0),
|
|
267
267
|
block: (e) => (s.add(e), () => s.delete(e)),
|
|
268
268
|
isActive(n, r = !1) {
|
|
269
|
-
return
|
|
270
|
-
let
|
|
271
|
-
return r ?
|
|
269
|
+
return t(() => {
|
|
270
|
+
let t = c(n), i = t === "/" ? "/" : t.replace(/\/$/, ""), a = i === "/" ? "/" : i + "/", o = e().path, s = o === "/" ? "/" : o.replace(/\/$/, "");
|
|
271
|
+
return r ? s === i : s === i || s.startsWith(a);
|
|
272
272
|
});
|
|
273
273
|
}
|
|
274
274
|
};
|
|
@@ -283,40 +283,40 @@ function R(e) {
|
|
|
283
283
|
};
|
|
284
284
|
}
|
|
285
285
|
function z(e) {
|
|
286
|
-
return function(
|
|
286
|
+
return function(t) {
|
|
287
287
|
"scrollRestoration" in window.history && (window.history.scrollRestoration = "manual");
|
|
288
|
-
let r = F(!!e.hash), i = /* @__PURE__ */ new Map(), a = r.getKey(), [
|
|
288
|
+
let r = F(!!e.hash), i = /* @__PURE__ */ new Map(), a = r.getKey(), [c, l] = s({
|
|
289
289
|
path: r.getPath(),
|
|
290
290
|
pattern: "",
|
|
291
291
|
params: {},
|
|
292
292
|
query: Object.fromEntries(new URLSearchParams(r.getSearch())),
|
|
293
293
|
meta: {}
|
|
294
|
-
}), [
|
|
294
|
+
}), [g, S] = s(0), C = k(e.routes), w = /* @__PURE__ */ new Set(), T = v(t);
|
|
295
295
|
T.name = "dolla:router";
|
|
296
|
-
let E =
|
|
297
|
-
|
|
296
|
+
let E = m(T), [O, A] = s();
|
|
297
|
+
t[L] = O;
|
|
298
298
|
let N = {
|
|
299
|
-
context:
|
|
299
|
+
context: t,
|
|
300
300
|
slot: O,
|
|
301
301
|
setSlot: A
|
|
302
302
|
}, R = [];
|
|
303
|
-
async function z(
|
|
303
|
+
async function z(f) {
|
|
304
304
|
i.set(a, window.scrollY);
|
|
305
|
-
let
|
|
306
|
-
if (
|
|
307
|
-
let t =
|
|
305
|
+
let m = f ?? r.getPath(), { match: h, journey: g } = await j(C, m);
|
|
306
|
+
if (t[y]) for (let e = 0; e < g.length; e++) {
|
|
307
|
+
let t = g[e], n = `(update ${e + 1}/${g.length})`;
|
|
308
308
|
t.kind === "match" ? E.info(`đ ${n} ${t.message}`) : t.kind === "redirect" ? E.info(`âŠī¸ ${n} ${t.message}`) : E.info(`đ ${n} ${t.message}`);
|
|
309
309
|
}
|
|
310
|
-
if (!
|
|
311
|
-
let { layers:
|
|
312
|
-
for (let e = 0; e <
|
|
313
|
-
let t = `${
|
|
310
|
+
if (!h) throw Error(`Failed to match route '${m}'`);
|
|
311
|
+
let { layers: _, params: v } = h, b = [], x = 0;
|
|
312
|
+
for (let e = 0; e < _.length; e++) {
|
|
313
|
+
let t = `${_[e].id}:${P(_[e].pattern, v)}`;
|
|
314
314
|
b.push(t), x === e && R[e]?.key === t && x++;
|
|
315
315
|
}
|
|
316
316
|
let w = [], T = [];
|
|
317
|
-
for (let e = x; e <
|
|
318
|
-
let t =
|
|
319
|
-
t.preload && w.push(Promise.resolve(t.preload(
|
|
317
|
+
for (let e = x; e < _.length; e++) {
|
|
318
|
+
let t = _[e];
|
|
319
|
+
t.preload && w.push(Promise.resolve(t.preload(h)).then((t) => {
|
|
320
320
|
T[e - x] = t;
|
|
321
321
|
}));
|
|
322
322
|
let n = t.view;
|
|
@@ -336,23 +336,23 @@ function z(e) {
|
|
|
336
336
|
O = e instanceof Error ? e : Error(String(e)), k = x;
|
|
337
337
|
}
|
|
338
338
|
}
|
|
339
|
-
let A = D(
|
|
340
|
-
F !== r.getPath() + r.getSearch() && r.replace(F),
|
|
341
|
-
if (
|
|
342
|
-
...
|
|
339
|
+
let A = D(o(c).query, h.query, e.preserveQuery), M = A.toString(), F = h.path + (M ? `?${M}` : "");
|
|
340
|
+
F !== r.getPath() + r.getSearch() && r.replace(F), n(() => {
|
|
341
|
+
if (l({
|
|
342
|
+
...h,
|
|
343
343
|
query: Object.fromEntries(A)
|
|
344
|
-
}), !(x ===
|
|
344
|
+
}), !(x === _.length && R.length === _.length)) {
|
|
345
345
|
R[x] && (R[x].node.unmount(), R.length = x);
|
|
346
|
-
for (let e = x; e <
|
|
347
|
-
let t =
|
|
346
|
+
for (let e = x; e < _.length; e++) {
|
|
347
|
+
let t = _[e], n = R[e - 1] ?? N, [r, i] = s(), a = t.view, o = {
|
|
348
348
|
data: T[e - x],
|
|
349
|
-
children:
|
|
349
|
+
children: u(d, { args: [r] })
|
|
350
350
|
};
|
|
351
351
|
if (O && e === k) {
|
|
352
352
|
if (!t.errorView) throw O;
|
|
353
|
-
a = t.errorView,
|
|
353
|
+
a = t.errorView, o = { error: O };
|
|
354
354
|
}
|
|
355
|
-
let c = new
|
|
355
|
+
let c = new p(n.context, a, o);
|
|
356
356
|
if (n.setSlot(c), R.push({
|
|
357
357
|
id: t.id,
|
|
358
358
|
key: b[e],
|
|
@@ -367,40 +367,40 @@ function z(e) {
|
|
|
367
367
|
window.scrollTo(0, i.get(r.getKey()) ?? 0), a = r.getKey();
|
|
368
368
|
});
|
|
369
369
|
}
|
|
370
|
-
let B =
|
|
371
|
-
currentMatch:
|
|
372
|
-
setCurrentMatch:
|
|
373
|
-
progress:
|
|
370
|
+
let B = h(t, I, {
|
|
371
|
+
currentMatch: c,
|
|
372
|
+
setCurrentMatch: l,
|
|
373
|
+
progress: g,
|
|
374
374
|
history: r,
|
|
375
375
|
updateRoute: z,
|
|
376
376
|
guards: w
|
|
377
377
|
});
|
|
378
|
-
x(
|
|
379
|
-
let e = !1,
|
|
378
|
+
x(t, () => {
|
|
379
|
+
let e = !1, n = !1, i = r.getIndex(), a = b(window, "popstate", async () => {
|
|
380
380
|
if (e) {
|
|
381
381
|
e = !1;
|
|
382
382
|
return;
|
|
383
383
|
}
|
|
384
|
-
if (
|
|
385
|
-
|
|
384
|
+
if (n) {
|
|
385
|
+
n = !1, i = r.getIndex(), z();
|
|
386
386
|
return;
|
|
387
387
|
}
|
|
388
|
-
let
|
|
388
|
+
let t = r.getIndex(), a = i - t;
|
|
389
389
|
if (w.size > 0) {
|
|
390
390
|
e = !0, window.history.go(a);
|
|
391
|
-
let
|
|
391
|
+
let t = !1;
|
|
392
392
|
for (let e of w) if (await e()) {
|
|
393
|
-
|
|
393
|
+
t = !0;
|
|
394
394
|
break;
|
|
395
395
|
}
|
|
396
|
-
|
|
396
|
+
t || (n = !0, window.history.go(-a));
|
|
397
397
|
return;
|
|
398
398
|
}
|
|
399
|
-
i =
|
|
399
|
+
i = t, z();
|
|
400
400
|
}), o = b(window, "beforeunload", (e) => {
|
|
401
401
|
w.size > 0 && (e.preventDefault(), e.returnValue = "");
|
|
402
|
-
}), s = M(
|
|
403
|
-
|
|
402
|
+
}), s = M(_(t), B.push);
|
|
403
|
+
f(t, () => {
|
|
404
404
|
a(), o(), s();
|
|
405
405
|
}), z();
|
|
406
406
|
});
|
|
@@ -409,7 +409,7 @@ function z(e) {
|
|
|
409
409
|
function B() {
|
|
410
410
|
this.name = "dolla:router";
|
|
411
411
|
let e = this[L];
|
|
412
|
-
return
|
|
412
|
+
return r(e != null, "Router plugin not found on root."), new d(this, e);
|
|
413
413
|
}
|
|
414
414
|
var V = class extends Error {
|
|
415
415
|
constructor(e) {
|
|
@@ -419,9 +419,9 @@ var V = class extends Error {
|
|
|
419
419
|
//#endregion
|
|
420
420
|
//#region src/router/index.ts
|
|
421
421
|
function H(e) {
|
|
422
|
-
return
|
|
422
|
+
return g(e, I);
|
|
423
423
|
}
|
|
424
424
|
//#endregion
|
|
425
|
-
export { B as Outlet, V as RedirectError, z as
|
|
425
|
+
export { B as Outlet, V as RedirectError, z as createRouter, H as getRouter, R as lazy };
|
|
426
426
|
|
|
427
427
|
//# sourceMappingURL=router.js.map
|