@manyducks.co/dolla 2.0.0-alpha.34 → 2.0.0-alpha.36
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 +9 -22
- package/dist/core/{batch.d.ts → _batch.d.ts} +4 -0
- package/dist/core/_signals_new.d.ts +130 -0
- package/dist/core/context.d.ts +7 -55
- package/dist/core/dolla.d.ts +7 -48
- package/dist/core/markup.d.ts +9 -31
- package/dist/core/nodes/{observer.d.ts → dynamic.d.ts} +10 -12
- package/dist/core/nodes/html.d.ts +11 -17
- package/dist/core/nodes/list.d.ts +28 -0
- package/dist/core/nodes/outlet.d.ts +7 -7
- package/dist/core/nodes/portal.d.ts +2 -2
- package/dist/core/nodes/view.d.ts +21 -34
- package/dist/core/ref.d.ts +5 -6
- package/dist/core/signals.d.ts +128 -0
- package/dist/core/store.d.ts +14 -18
- package/dist/core/symbols.d.ts +0 -3
- package/dist/{views → core/views}/default-crash-view.d.ts +1 -1
- package/dist/{views → core/views}/passthrough.d.ts +2 -2
- package/dist/{modules/http.d.ts → http/index.d.ts} +1 -2
- package/dist/index.d.ts +8 -11
- package/dist/index.js +517 -695
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.d.ts +1 -1
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx-runtime.d.ts +1 -1
- package/dist/jsx-runtime.js +2 -2
- package/dist/jsx-runtime.js.map +1 -1
- package/dist/markup-ILMFXzoo.js +1442 -0
- package/dist/markup-ILMFXzoo.js.map +1 -0
- package/dist/{modules/router.d.ts → router/index.d.ts} +5 -5
- package/dist/router/router.utils.test.d.ts +1 -0
- package/dist/{modules/i18n.d.ts → translate/index.d.ts} +20 -16
- package/dist/typeChecking.d.ts +0 -96
- package/dist/types.d.ts +9 -9
- package/dist/utils.d.ts +4 -1
- package/docs/signals.md +149 -0
- package/docs/views.md +1 -87
- package/notes/atomic.md +146 -0
- package/notes/context-routes.md +56 -0
- package/notes/elimination.md +33 -0
- package/package.json +9 -7
- package/vite.config.js +3 -0
- package/dist/core/nodes/repeat.d.ts +0 -36
- package/dist/core/state.d.ts +0 -126
- package/dist/core/stats.d.ts +0 -31
- package/dist/markup-B3FV_fq9.js +0 -1525
- package/dist/markup-B3FV_fq9.js.map +0 -1
- package/notes/viewstate.md +0 -15
- package/tests/state.test.js +0 -135
- /package/dist/{modules/router.utils.test.d.ts → core/signals.test.d.ts} +0 -0
- /package/dist/{modules → router}/router.utils.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,42 +1,51 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
throw TypeError(
|
|
1
|
+
var zt = Object.defineProperty;
|
|
2
|
+
var $t = (i) => {
|
|
3
|
+
throw TypeError(i);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
set _(
|
|
10
|
-
|
|
5
|
+
var Bt = (i, t, e) => t in i ? zt(i, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : i[t] = e;
|
|
6
|
+
var w = (i, t, e) => Bt(i, typeof t != "symbol" ? t + "" : t, e), mt = (i, t, e) => t.has(i) || $t("Cannot " + e);
|
|
7
|
+
var a = (i, t, e) => (mt(i, t, "read from private field"), e ? e.call(i) : t.get(i)), u = (i, t, e) => t.has(i) ? $t("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(i) : t.set(i, e), d = (i, t, e, s) => (mt(i, t, "write to private field"), s ? s.call(i, e) : t.set(i, e), e), f = (i, t, e) => (mt(i, t, "access private method"), e);
|
|
8
|
+
var Rt = (i, t, e, s) => ({
|
|
9
|
+
set _(r) {
|
|
10
|
+
d(i, t, r, e);
|
|
11
11
|
},
|
|
12
12
|
get _() {
|
|
13
|
-
return i
|
|
13
|
+
return a(i, t, s);
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
import { a as
|
|
17
|
-
import {
|
|
18
|
-
function
|
|
19
|
-
return
|
|
16
|
+
import { a as Ft, b as Kt, i as B, I as Ot, c as Ut, d as U, g as E, s as _t, e as Qt, f as M, h as V, P as jt, j as Jt, t as St, k as Mt, l as Xt, m as xt, S as Yt, n as Tt, o as Nt, p as Zt, V as te, q as ee, r as se, u as ne, v as re } from "./markup-ILMFXzoo.js";
|
|
17
|
+
import { w as Ue, B as je, y as Ce, A as De, x as Ie, z as Ve } from "./markup-ILMFXzoo.js";
|
|
18
|
+
function Ne(i) {
|
|
19
|
+
return () => {
|
|
20
|
+
if (arguments.length === 1)
|
|
21
|
+
i = arguments[0];
|
|
22
|
+
else if (arguments.length > 1)
|
|
23
|
+
throw new Error(`Too many arguments. Expected 0 or 1. Got: ${arguments.length}`);
|
|
24
|
+
return i;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function Q(i) {
|
|
28
|
+
return Ft(i, "Expected `path` to be a string. Got type: %t, value: %v"), i.split("/").map((t) => t.trim()).filter((t) => t !== "");
|
|
20
29
|
}
|
|
21
|
-
function
|
|
30
|
+
function G(i) {
|
|
22
31
|
var e;
|
|
23
|
-
|
|
24
|
-
(s) =>
|
|
25
|
-
|
|
32
|
+
Kt(
|
|
33
|
+
(s) => B(s == null ? void 0 : s.toString),
|
|
34
|
+
i,
|
|
26
35
|
"Expected `parts` to be an array of objects with a .toString() method. Got type: %t, value: %v"
|
|
27
|
-
),
|
|
28
|
-
let t = (e =
|
|
36
|
+
), i = i.filter((s) => s).flatMap(String);
|
|
37
|
+
let t = (e = i.shift()) == null ? void 0 : e.toString();
|
|
29
38
|
if (t) {
|
|
30
|
-
for (const s of
|
|
31
|
-
s.startsWith(".") ? t =
|
|
39
|
+
for (const s of i.map((r) => r.toString()))
|
|
40
|
+
s.startsWith(".") ? t = ct(t, s) : t[t.length - 1] !== "/" ? s[0] !== "/" ? t += "/" + s : t += s : s[0] === "/" ? t += s.slice(1) : t += s;
|
|
32
41
|
t && t !== "/" && t.endsWith("/") && (t = t.slice(0, t.length - 1));
|
|
33
42
|
}
|
|
34
43
|
return t ?? "";
|
|
35
44
|
}
|
|
36
|
-
function
|
|
37
|
-
if (
|
|
45
|
+
function ct(i, t) {
|
|
46
|
+
if (Ft(i, "Expected `base` to be a string. Got type: %t, value: %v"), t == null && (t = i, i = ""), t.startsWith("/"))
|
|
38
47
|
return t;
|
|
39
|
-
let e =
|
|
48
|
+
let e = i;
|
|
40
49
|
for (; ; )
|
|
41
50
|
if (t.startsWith("..")) {
|
|
42
51
|
for (let s = e.length; s > 0; --s)
|
|
@@ -48,182 +57,193 @@ function Rt(o, t) {
|
|
|
48
57
|
t = t.replace(/^\.\/?/, "");
|
|
49
58
|
else
|
|
50
59
|
break;
|
|
51
|
-
return
|
|
60
|
+
return G([e, t]);
|
|
52
61
|
}
|
|
53
|
-
function
|
|
54
|
-
if (!
|
|
55
|
-
|
|
56
|
-
const t =
|
|
57
|
-
const [s,
|
|
58
|
-
return
|
|
62
|
+
function ae(i) {
|
|
63
|
+
if (!i) return {};
|
|
64
|
+
i.startsWith("?") && (i = i.slice(1));
|
|
65
|
+
const t = i.split("&").filter((e) => e.trim() !== "").map((e) => {
|
|
66
|
+
const [s, r] = e.split("=").map((n) => n.trim());
|
|
67
|
+
return r.toLowerCase() === "true" ? [s, !0] : r.toLowerCase() === "false" ? [s, !1] : isNaN(Number(r)) ? [s, r] : [s, Number(r)];
|
|
59
68
|
});
|
|
60
69
|
return Object.fromEntries(t);
|
|
61
70
|
}
|
|
62
|
-
function
|
|
63
|
-
var
|
|
64
|
-
const [s,
|
|
65
|
-
t: for (const c of
|
|
66
|
-
const { fragments:
|
|
67
|
-
if (!(((
|
|
71
|
+
function Ct(i, t, e = {}) {
|
|
72
|
+
var o;
|
|
73
|
+
const [s, r] = t.split("?"), n = Q(s);
|
|
74
|
+
t: for (const c of i) {
|
|
75
|
+
const { fragments: l } = c;
|
|
76
|
+
if (!(((o = l[l.length - 1]) == null ? void 0 : o.type) === 3) && l.length !== n.length || e.willMatch && !e.willMatch(c))
|
|
68
77
|
continue t;
|
|
69
78
|
const v = [];
|
|
70
|
-
e: for (let
|
|
71
|
-
const
|
|
72
|
-
if (
|
|
79
|
+
e: for (let h = 0; h < l.length; h++) {
|
|
80
|
+
const x = n[h], $ = l[h];
|
|
81
|
+
if (x == null && $.type !== 3)
|
|
73
82
|
continue t;
|
|
74
|
-
switch (
|
|
83
|
+
switch ($.type) {
|
|
75
84
|
case 1:
|
|
76
|
-
if (
|
|
77
|
-
v.push(
|
|
85
|
+
if ($.name.toLowerCase() === x.toLowerCase()) {
|
|
86
|
+
v.push($);
|
|
78
87
|
break;
|
|
79
88
|
} else
|
|
80
89
|
continue t;
|
|
81
90
|
case 2:
|
|
82
|
-
v.push({
|
|
91
|
+
v.push({ ...$, value: x });
|
|
83
92
|
break;
|
|
84
93
|
case 3:
|
|
85
|
-
v.push({
|
|
94
|
+
v.push({ ...$, value: n.slice(h).join("/") });
|
|
86
95
|
break e;
|
|
87
96
|
case 4:
|
|
88
|
-
if (isNaN(Number(
|
|
97
|
+
if (isNaN(Number(x)))
|
|
89
98
|
continue t;
|
|
90
|
-
v.push({
|
|
99
|
+
v.push({ ...$, value: Number(x) });
|
|
91
100
|
break;
|
|
92
101
|
default:
|
|
93
|
-
throw new Error(`Unknown fragment type: ${
|
|
102
|
+
throw new Error(`Unknown fragment type: ${$.type}`);
|
|
94
103
|
}
|
|
95
104
|
}
|
|
96
105
|
const k = {};
|
|
97
|
-
for (const
|
|
98
|
-
|
|
106
|
+
for (const h of v)
|
|
107
|
+
h.type === 2 && (k[h.name] = decodeURIComponent(h.value)), h.type === 4 && (k[h.name] = h.value), h.type === 3 && (k.wildcard = "/" + decodeURIComponent(h.value));
|
|
99
108
|
return {
|
|
100
|
-
path: "/" + v.map((
|
|
101
|
-
pattern: "/" +
|
|
109
|
+
path: "/" + v.map((h) => h.value).join("/"),
|
|
110
|
+
pattern: "/" + l.map((h) => h.type === 2 ? `{${h.name}}` : h.type === 4 ? `{#${h.name}}` : h.name).join("/"),
|
|
102
111
|
params: k,
|
|
103
|
-
query:
|
|
112
|
+
query: ae(r),
|
|
104
113
|
meta: c.meta
|
|
105
114
|
};
|
|
106
115
|
}
|
|
107
116
|
}
|
|
108
|
-
function
|
|
109
|
-
const t = [], e = [], s = [],
|
|
110
|
-
for (const
|
|
111
|
-
const { fragments: c } =
|
|
117
|
+
function ie(i) {
|
|
118
|
+
const t = [], e = [], s = [], r = [];
|
|
119
|
+
for (const o of i) {
|
|
120
|
+
const { fragments: c } = o;
|
|
112
121
|
c.some(
|
|
113
|
-
(
|
|
122
|
+
(l) => l.type === 3
|
|
114
123
|
/* Wildcard */
|
|
115
|
-
) ?
|
|
116
|
-
(
|
|
124
|
+
) ? r.push(o) : c.some(
|
|
125
|
+
(l) => l.type === 4
|
|
117
126
|
/* NumericParam */
|
|
118
|
-
) ? e.push(
|
|
119
|
-
(
|
|
127
|
+
) ? e.push(o) : c.some(
|
|
128
|
+
(l) => l.type === 2
|
|
120
129
|
/* Param */
|
|
121
|
-
) ? s.push(
|
|
130
|
+
) ? s.push(o) : t.push(o);
|
|
122
131
|
}
|
|
123
|
-
const
|
|
124
|
-
return t.sort(
|
|
132
|
+
const n = (o, c) => o.fragments.length > c.fragments.length ? -1 : 1;
|
|
133
|
+
return t.sort(n), e.sort(n), s.sort(n), r.sort(n), [...t, ...e, ...s, ...r];
|
|
125
134
|
}
|
|
126
|
-
function
|
|
127
|
-
const t =
|
|
135
|
+
function oe(i) {
|
|
136
|
+
const t = Q(i), e = [];
|
|
128
137
|
for (let s = 0; s < t.length; s++) {
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
138
|
+
const r = t[s];
|
|
139
|
+
if (r === "*") {
|
|
131
140
|
if (s !== t.length - 1)
|
|
132
|
-
throw new Error(`Wildcard must be at the end of a pattern. Received: ${
|
|
141
|
+
throw new Error(`Wildcard must be at the end of a pattern. Received: ${i}`);
|
|
133
142
|
e.push({
|
|
134
143
|
type: 3,
|
|
135
144
|
name: "*",
|
|
136
145
|
value: null
|
|
137
146
|
});
|
|
138
|
-
} else
|
|
139
|
-
type:
|
|
140
|
-
name:
|
|
147
|
+
} else r.at(0) === "{" && r.at(-1) === "}" ? e.push({
|
|
148
|
+
type: r[1] === "#" ? 4 : 2,
|
|
149
|
+
name: r[1] === "#" ? r.slice(2, -1) : r.slice(1, -1),
|
|
141
150
|
value: null
|
|
142
151
|
}) : e.push({
|
|
143
152
|
type: 1,
|
|
144
|
-
name:
|
|
145
|
-
value:
|
|
153
|
+
name: r,
|
|
154
|
+
value: r
|
|
146
155
|
});
|
|
147
156
|
}
|
|
148
157
|
return e;
|
|
149
158
|
}
|
|
150
|
-
function
|
|
151
|
-
return new
|
|
159
|
+
function Pe(i) {
|
|
160
|
+
return new he(i);
|
|
152
161
|
}
|
|
153
|
-
const
|
|
154
|
-
function
|
|
155
|
-
return (
|
|
162
|
+
const Dt = Symbol.for("DollaRouterMountMethod"), It = Symbol.for("DollaRouterUnmountMethod");
|
|
163
|
+
function pt(i) {
|
|
164
|
+
return (i == null ? void 0 : i[Ot]) === !0;
|
|
156
165
|
}
|
|
157
|
-
async function
|
|
158
|
-
return
|
|
166
|
+
async function le(i, t) {
|
|
167
|
+
return i[Dt](t);
|
|
159
168
|
}
|
|
160
|
-
async function
|
|
161
|
-
return
|
|
169
|
+
async function ce(i) {
|
|
170
|
+
return i[It]();
|
|
162
171
|
}
|
|
163
|
-
var
|
|
164
|
-
class
|
|
172
|
+
var Lt, W, S, ht, T, A, J, j, C, N, m, wt, Vt, qt, K, Gt, gt, yt;
|
|
173
|
+
class he {
|
|
165
174
|
constructor(t) {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
175
|
+
u(this, m);
|
|
176
|
+
w(this, Lt, !0);
|
|
177
|
+
u(this, W);
|
|
178
|
+
u(this, S);
|
|
179
|
+
u(this, ht, 0);
|
|
180
|
+
u(this, T, []);
|
|
181
|
+
u(this, A, []);
|
|
182
|
+
u(this, J, !1);
|
|
174
183
|
/**
|
|
175
184
|
* Use hash routing when true. Configured in router options.
|
|
176
185
|
*/
|
|
177
|
-
|
|
186
|
+
u(this, j, !1);
|
|
178
187
|
// Callbacks that need to be called on unmount.
|
|
179
|
-
|
|
188
|
+
u(this, C, []);
|
|
180
189
|
/**
|
|
181
190
|
* The current match object.
|
|
182
191
|
*/
|
|
183
|
-
|
|
184
|
-
l(this, at);
|
|
192
|
+
u(this, N, Ut());
|
|
185
193
|
/**
|
|
186
194
|
* The currently matched route pattern, if any.
|
|
187
195
|
*/
|
|
188
|
-
|
|
196
|
+
w(this, "pattern", U(() => {
|
|
197
|
+
var t;
|
|
198
|
+
return (t = E(a(this, N))) == null ? void 0 : t.pattern;
|
|
199
|
+
}));
|
|
189
200
|
/**
|
|
190
201
|
* The current URL path.
|
|
191
202
|
*/
|
|
192
|
-
|
|
203
|
+
w(this, "path", U(() => {
|
|
204
|
+
var t;
|
|
205
|
+
return ((t = E(a(this, N))) == null ? void 0 : t.path) ?? window.location.pathname;
|
|
206
|
+
}));
|
|
193
207
|
/**
|
|
194
208
|
* The current named path params.
|
|
195
209
|
*/
|
|
196
|
-
|
|
210
|
+
w(this, "params", U(() => {
|
|
211
|
+
var t;
|
|
212
|
+
return ((t = E(a(this, N))) == null ? void 0 : t.params) ?? {};
|
|
213
|
+
}, { equals: _t }));
|
|
197
214
|
/**
|
|
198
215
|
* The current query params. Changes to this object will be reflected in the URL.
|
|
199
216
|
*/
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
217
|
+
w(this, "query", U(() => {
|
|
218
|
+
var t;
|
|
219
|
+
return ((t = E(a(this, N))) == null ? void 0 : t.query) ?? {};
|
|
220
|
+
}, { equals: _t }));
|
|
221
|
+
Qt(t, "Options must be an object. Got: %t"), t.hash && d(this, j, !0), d(this, A, ie(
|
|
222
|
+
t.routes.flatMap((e) => f(this, m, yt).call(this, e)).map((e) => ({
|
|
203
223
|
pattern: e.pattern,
|
|
204
224
|
meta: e.meta,
|
|
205
|
-
fragments:
|
|
225
|
+
fragments: oe(e.pattern)
|
|
206
226
|
}))
|
|
207
|
-
)),
|
|
227
|
+
)), pe(a(this, A));
|
|
208
228
|
}
|
|
209
|
-
async [(
|
|
210
|
-
|
|
229
|
+
async [(Lt = Ot, Dt)](t) {
|
|
230
|
+
d(this, W, t), d(this, S, t.createLogger("Dolla.router"));
|
|
211
231
|
const e = () => {
|
|
212
|
-
f(this,
|
|
232
|
+
f(this, m, K).call(this);
|
|
213
233
|
};
|
|
214
|
-
window.addEventListener("popstate", e),
|
|
234
|
+
window.addEventListener("popstate", e), a(this, C).push(() => window.removeEventListener("popstate", e));
|
|
215
235
|
const s = t.getRootElement();
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
let
|
|
219
|
-
|
|
236
|
+
a(this, C).push(
|
|
237
|
+
de(s, (r) => {
|
|
238
|
+
let n = r.getAttribute("href");
|
|
239
|
+
a(this, S).info("intercepted click on <a> tag", r), /^https?:\/\/|^\//.test(n) || (n = G([window.location.pathname, n])), f(this, m, wt).call(this, n);
|
|
220
240
|
})
|
|
221
|
-
),
|
|
241
|
+
), a(this, S).info("will intercept clicks on <a> tags within root element", s), d(this, J, !0), await f(this, m, K).call(this);
|
|
222
242
|
}
|
|
223
|
-
async [
|
|
224
|
-
for (const t of
|
|
243
|
+
async [It]() {
|
|
244
|
+
for (const t of a(this, C))
|
|
225
245
|
t();
|
|
226
|
-
|
|
246
|
+
d(this, C, []);
|
|
227
247
|
}
|
|
228
248
|
/**
|
|
229
249
|
* Navigate backward. Pass a number of steps to hit the back button that many times.
|
|
@@ -245,97 +265,97 @@ class Oe {
|
|
|
245
265
|
* router.go["/users", 215], { replace: true }); // replace current history entry with `/users/215`
|
|
246
266
|
*/
|
|
247
267
|
go(t, e = {}) {
|
|
248
|
-
if (
|
|
268
|
+
if (a(this, W) == null)
|
|
249
269
|
throw new Error("Routa methods won't work until you register it: Dolla.use(Routa, { /* ...options */ })");
|
|
250
270
|
let s;
|
|
251
|
-
Array.isArray(t) ? s =
|
|
271
|
+
Array.isArray(t) ? s = G(t) : s = t.toString(), s = ct(window.location.pathname, s), e.preserveQuery && (s += window.location.search), e.replace ? f(this, m, Vt).call(this, s) : f(this, m, wt).call(this, s);
|
|
252
272
|
}
|
|
253
273
|
}
|
|
254
|
-
|
|
274
|
+
W = new WeakMap(), S = new WeakMap(), ht = new WeakMap(), T = new WeakMap(), A = new WeakMap(), J = new WeakMap(), j = new WeakMap(), C = new WeakMap(), N = new WeakMap(), m = new WeakSet(), wt = function(t, e) {
|
|
255
275
|
var s;
|
|
256
|
-
(s =
|
|
257
|
-
},
|
|
276
|
+
(s = a(this, S)) == null || s.info("(push)", t), window.history.pushState(e, "", a(this, j) ? "/#" + t : t), f(this, m, K).call(this, t);
|
|
277
|
+
}, Vt = function(t, e) {
|
|
258
278
|
var s;
|
|
259
|
-
(s =
|
|
260
|
-
},
|
|
261
|
-
return
|
|
262
|
-
},
|
|
279
|
+
(s = a(this, S)) == null || s.info("(replace)", t), window.history.replaceState(e, "", a(this, j) ? "/#" + t : t), f(this, m, K).call(this, t);
|
|
280
|
+
}, qt = function() {
|
|
281
|
+
return a(this, j) ? new URL(window.location.hash.slice(1), window.location.origin) : new URL(window.location.pathname, window.location.origin);
|
|
282
|
+
}, K = async function(t) {
|
|
263
283
|
var c;
|
|
264
|
-
const e =
|
|
265
|
-
for (const
|
|
266
|
-
switch (
|
|
284
|
+
const e = a(this, S), s = (c = a(this, W)) == null ? void 0 : c.getRootView(), r = t ? new URL(t, window.location.origin) : f(this, m, qt).call(this), { match: n, journey: o } = await f(this, m, gt).call(this, r);
|
|
285
|
+
for (const l of o)
|
|
286
|
+
switch (l.kind) {
|
|
267
287
|
case "match":
|
|
268
|
-
e == null || e.info(`📍 ${
|
|
288
|
+
e == null || e.info(`📍 ${l.message}`);
|
|
269
289
|
break;
|
|
270
290
|
case "redirect":
|
|
271
|
-
e == null || e.info(`↩️ ${
|
|
291
|
+
e == null || e.info(`↩️ ${l.message}`);
|
|
272
292
|
break;
|
|
273
293
|
case "miss":
|
|
274
|
-
e == null || e.info(`💀 ${
|
|
294
|
+
e == null || e.info(`💀 ${l.message}`);
|
|
275
295
|
break;
|
|
276
296
|
}
|
|
277
|
-
if (
|
|
278
|
-
const
|
|
279
|
-
|
|
297
|
+
if (n) {
|
|
298
|
+
const l = this.pattern.value;
|
|
299
|
+
a(this, N).value = n, s && n.pattern !== l && f(this, m, Gt).call(this, s, n);
|
|
280
300
|
} else
|
|
281
|
-
|
|
282
|
-
return { match:
|
|
283
|
-
},
|
|
284
|
-
|
|
301
|
+
a(this, J) && e.crash(new we(`Failed to match route '${r.pathname}'`));
|
|
302
|
+
return { match: n, journey: o };
|
|
303
|
+
}, /**
|
|
304
|
+
* Takes a matched route and mounts it.
|
|
305
|
+
*/
|
|
306
|
+
Gt = function(t, e) {
|
|
307
|
+
const s = e.meta.layers;
|
|
308
|
+
for (let r = 0; r < s.length; r++) {
|
|
309
|
+
const n = s[r], o = a(this, T)[r];
|
|
310
|
+
if ((o == null ? void 0 : o.id) !== n.id) {
|
|
311
|
+
d(this, T, a(this, T).slice(0, r)), o == null || o.view.unmount();
|
|
312
|
+
const c = a(this, T).at(-1), p = ((c == null ? void 0 : c.view) ?? t).setChildView(n.view);
|
|
313
|
+
a(this, T).push({ id: n.id, view: p });
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}, gt = async function(t, e = []) {
|
|
317
|
+
const s = Ct(a(this, A), t.pathname);
|
|
285
318
|
if (!s)
|
|
286
319
|
return {
|
|
287
320
|
match: null,
|
|
288
321
|
journey: [...e, { kind: "miss", message: `no match for '${t.pathname}'` }]
|
|
289
322
|
};
|
|
290
|
-
let
|
|
323
|
+
let r = s.meta.redirect;
|
|
291
324
|
if (s.meta.beforeMatch && await s.meta.beforeMatch({
|
|
292
325
|
// TODO: Allow setting context variables from here? Would apply to the context of the matched view.
|
|
293
|
-
redirect: (
|
|
294
|
-
|
|
326
|
+
redirect: (n) => {
|
|
327
|
+
r = n;
|
|
295
328
|
}
|
|
296
|
-
}),
|
|
297
|
-
let
|
|
298
|
-
if (
|
|
299
|
-
|
|
300
|
-
else if (
|
|
301
|
-
const
|
|
329
|
+
}), r != null) {
|
|
330
|
+
let n;
|
|
331
|
+
if (M(r))
|
|
332
|
+
n = me(r, s.params);
|
|
333
|
+
else if (B(r)) {
|
|
334
|
+
const o = {
|
|
302
335
|
path: s.path,
|
|
303
336
|
pattern: s.pattern,
|
|
304
337
|
params: s.params,
|
|
305
338
|
query: s.query
|
|
306
339
|
};
|
|
307
|
-
if (
|
|
340
|
+
if (n = await r(o), !M(n))
|
|
308
341
|
throw new Error("Redirect function must return a path to redirect to.");
|
|
309
|
-
|
|
342
|
+
n.startsWith("/") || (n = ct(s.path, n));
|
|
310
343
|
} else
|
|
311
344
|
throw new TypeError("Redirect must either be a path string or a function.");
|
|
312
|
-
return f(this,
|
|
345
|
+
return f(this, m, gt).call(this, new URL(n, window.location.origin), [
|
|
313
346
|
...e,
|
|
314
|
-
{ kind: "redirect", message: `redirecting '${s.path}' -> '${
|
|
347
|
+
{ kind: "redirect", message: `redirecting '${s.path}' -> '${n}'` }
|
|
315
348
|
]);
|
|
316
349
|
} else
|
|
317
350
|
return { match: s, journey: [...e, { kind: "match", message: `matched route '${s.path}'` }] };
|
|
318
|
-
}, /**
|
|
319
|
-
* Takes a matched route and mounts it.
|
|
320
|
-
*/
|
|
321
|
-
oe = function(t, e) {
|
|
322
|
-
const s = e.meta.layers;
|
|
323
|
-
for (let n = 0; n < s.length; n++) {
|
|
324
|
-
const r = s[n], a = i(this, N)[n];
|
|
325
|
-
if ((a == null ? void 0 : a.id) !== r.id) {
|
|
326
|
-
m(this, N, i(this, N).slice(0, n)), a == null || a.view.unmount();
|
|
327
|
-
const c = i(this, N).at(-1), w = ((c == null ? void 0 : c.view) ?? t).setChildView(r.view);
|
|
328
|
-
i(this, N).push({ id: r.id, view: w });
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
351
|
}, /**
|
|
332
352
|
* Parses a route definition object into a set of matchable routes.
|
|
333
353
|
*
|
|
334
354
|
* @param route - Route config object.
|
|
335
355
|
* @param layers - Array of parent layers. Passed when this function calls itself on nested routes.
|
|
336
356
|
*/
|
|
337
|
-
|
|
338
|
-
if (!
|
|
357
|
+
yt = function(t, e = [], s = []) {
|
|
358
|
+
if (!V(t) || !M(t.path))
|
|
339
359
|
throw new TypeError(`Route configs must be objects with a 'path' string property. Got: ${t}`);
|
|
340
360
|
if (t.redirect && t.routes)
|
|
341
361
|
throw new Error("Route cannot have both a 'redirect' and nested 'routes'.");
|
|
@@ -343,70 +363,70 @@ Ut = function(t, e = [], s = []) {
|
|
|
343
363
|
throw new Error("Route cannot have both a 'redirect' and a 'view'.");
|
|
344
364
|
if (!t.view && !t.routes && !t.redirect)
|
|
345
365
|
throw new Error("Route must have a 'view', a 'redirect', or a set of nested 'routes'.");
|
|
346
|
-
let
|
|
347
|
-
for (const
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
const
|
|
366
|
+
let r = [];
|
|
367
|
+
for (const l of e)
|
|
368
|
+
r.push(...Q(l.path));
|
|
369
|
+
r.push(...Q(t.path)), r[r.length - 1] === "*" && r.pop();
|
|
370
|
+
const n = [];
|
|
351
371
|
if (t.redirect) {
|
|
352
|
-
let
|
|
353
|
-
return
|
|
354
|
-
pattern: "/" +
|
|
372
|
+
let l = t.redirect;
|
|
373
|
+
return M(l) && (l = ct(G(r), l), l.startsWith("/") || (l = "/" + l)), n.push({
|
|
374
|
+
pattern: "/" + G([...r, ...Q(t.path)]),
|
|
355
375
|
meta: {
|
|
356
|
-
redirect:
|
|
376
|
+
redirect: l
|
|
357
377
|
}
|
|
358
|
-
}),
|
|
378
|
+
}), n;
|
|
359
379
|
}
|
|
360
|
-
let
|
|
361
|
-
if (
|
|
362
|
-
|
|
380
|
+
let o = jt;
|
|
381
|
+
if (B(t.view))
|
|
382
|
+
o = t.view;
|
|
363
383
|
else if (t.view)
|
|
364
384
|
throw new TypeError(`Route '${t.path}' expected a view function or undefined. Got: ${t.view}`);
|
|
365
|
-
const c = { id:
|
|
385
|
+
const c = { id: Rt(this, ht)._++, view: o };
|
|
366
386
|
if (t.routes)
|
|
367
|
-
for (const
|
|
368
|
-
|
|
387
|
+
for (const l of t.routes)
|
|
388
|
+
n.push(...f(this, m, yt).call(this, l, [...e, t], [...s, c]));
|
|
369
389
|
else
|
|
370
|
-
|
|
371
|
-
pattern: parent ?
|
|
390
|
+
n.push({
|
|
391
|
+
pattern: parent ? G([...e.map((l) => l.path), t.path]) : t.path,
|
|
372
392
|
meta: {
|
|
373
393
|
pattern: t.path,
|
|
374
394
|
layers: [...s, c],
|
|
375
395
|
beforeMatch: t.beforeMatch
|
|
376
396
|
}
|
|
377
397
|
});
|
|
378
|
-
return
|
|
398
|
+
return n;
|
|
379
399
|
};
|
|
380
|
-
const
|
|
381
|
-
function
|
|
382
|
-
function s(
|
|
383
|
-
return !
|
|
400
|
+
const ue = /(noopener|noreferrer) (noopener|noreferrer)/, fe = /^[\w-_]+:/;
|
|
401
|
+
function de(i, t, e = window) {
|
|
402
|
+
function s(n) {
|
|
403
|
+
return !n || n === i ? null : n.localName !== "a" || n.href === void 0 ? s(n.parentNode) : n;
|
|
384
404
|
}
|
|
385
|
-
function n
|
|
386
|
-
if (
|
|
405
|
+
function r(n) {
|
|
406
|
+
if (n.button && n.button !== 0 || n.ctrlKey || n.metaKey || n.altKey || n.shiftKey || n.defaultPrevented)
|
|
387
407
|
return;
|
|
388
|
-
const
|
|
389
|
-
|
|
408
|
+
const o = s(n.target);
|
|
409
|
+
o && (e.location.protocol !== o.protocol || e.location.hostname !== o.hostname || e.location.port !== o.port || o.hasAttribute("data-router-ignore") || o.hasAttribute("download") || o.getAttribute("target") === "_blank" && ue.test(o.getAttribute("rel")) || fe.test(o.getAttribute("href")) || (n.preventDefault(), t(o)));
|
|
390
410
|
}
|
|
391
|
-
return
|
|
392
|
-
|
|
411
|
+
return i.addEventListener("click", r), function() {
|
|
412
|
+
i.removeEventListener("click", r);
|
|
393
413
|
};
|
|
394
414
|
}
|
|
395
|
-
function
|
|
415
|
+
function me(i, t) {
|
|
396
416
|
for (const e in t) {
|
|
397
417
|
const s = t[e].toString();
|
|
398
|
-
|
|
418
|
+
i = i.replace(`{${e}}`, s).replace(`{#${e}}`, s);
|
|
399
419
|
}
|
|
400
|
-
return
|
|
420
|
+
return i;
|
|
401
421
|
}
|
|
402
|
-
function
|
|
403
|
-
for (const t of
|
|
422
|
+
function pe(i) {
|
|
423
|
+
for (const t of i)
|
|
404
424
|
if (t.meta.redirect) {
|
|
405
425
|
let e;
|
|
406
|
-
if (!
|
|
407
|
-
if (e = t.meta.redirect, !
|
|
408
|
-
willMatch(
|
|
409
|
-
return
|
|
426
|
+
if (!B(t.meta.redirect)) if (M(t.meta.redirect)) {
|
|
427
|
+
if (e = t.meta.redirect, !Ct(i, e, {
|
|
428
|
+
willMatch(r) {
|
|
429
|
+
return r !== t;
|
|
410
430
|
}
|
|
411
431
|
}))
|
|
412
432
|
throw new Error(`Found a redirect to an undefined URL. From '${t.pattern}' to '${t.meta.redirect}'`);
|
|
@@ -414,17 +434,16 @@ function Ie(o) {
|
|
|
414
434
|
throw new TypeError(`Expected a string or redirect function. Got: ${t.meta.redirect}`);
|
|
415
435
|
}
|
|
416
436
|
}
|
|
417
|
-
class
|
|
437
|
+
class we extends Error {
|
|
418
438
|
}
|
|
419
|
-
var
|
|
420
|
-
class
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
m(this, Mt, t), m(this, ot, t.createLogger("Dolla.http"));
|
|
439
|
+
var D, ut, R, _;
|
|
440
|
+
class ge {
|
|
441
|
+
// #dolla: Dolla;
|
|
442
|
+
// #logger: Logger;
|
|
443
|
+
constructor() {
|
|
444
|
+
u(this, R);
|
|
445
|
+
u(this, D, []);
|
|
446
|
+
u(this, ut, ye());
|
|
428
447
|
}
|
|
429
448
|
/**
|
|
430
449
|
* Adds a new middleware that will apply to subsequent requests.
|
|
@@ -433,66 +452,65 @@ class We {
|
|
|
433
452
|
* @param middleware - A middleware function that will intercept requests.
|
|
434
453
|
*/
|
|
435
454
|
use(t) {
|
|
436
|
-
return
|
|
437
|
-
|
|
455
|
+
return a(this, D).push(t), () => {
|
|
456
|
+
a(this, D).splice(a(this, D).indexOf(t), 1);
|
|
438
457
|
};
|
|
439
458
|
}
|
|
440
459
|
async get(t, e) {
|
|
441
|
-
return f(this,
|
|
460
|
+
return f(this, R, _).call(this, "get", t, e);
|
|
442
461
|
}
|
|
443
462
|
async put(t, e) {
|
|
444
|
-
return f(this,
|
|
463
|
+
return f(this, R, _).call(this, "put", t, e);
|
|
445
464
|
}
|
|
446
465
|
async patch(t, e) {
|
|
447
|
-
return f(this,
|
|
466
|
+
return f(this, R, _).call(this, "patch", t, e);
|
|
448
467
|
}
|
|
449
468
|
async post(t, e) {
|
|
450
|
-
return f(this,
|
|
469
|
+
return f(this, R, _).call(this, "post", t, e);
|
|
451
470
|
}
|
|
452
471
|
async delete(t, e) {
|
|
453
|
-
return f(this,
|
|
472
|
+
return f(this, R, _).call(this, "delete", t, e);
|
|
454
473
|
}
|
|
455
474
|
async head(t, e) {
|
|
456
|
-
return f(this,
|
|
475
|
+
return f(this, R, _).call(this, "head", t, e);
|
|
457
476
|
}
|
|
458
477
|
async options(t, e) {
|
|
459
|
-
return f(this,
|
|
478
|
+
return f(this, R, _).call(this, "options", t, e);
|
|
460
479
|
}
|
|
461
480
|
async trace(t, e) {
|
|
462
|
-
return f(this,
|
|
481
|
+
return f(this, R, _).call(this, "trace", t, e);
|
|
463
482
|
}
|
|
464
483
|
}
|
|
465
|
-
|
|
466
|
-
return new
|
|
484
|
+
D = new WeakMap(), ut = new WeakMap(), R = new WeakSet(), _ = async function(t, e, s) {
|
|
485
|
+
return new Ee({
|
|
467
486
|
...s,
|
|
468
487
|
method: t,
|
|
469
488
|
uri: e,
|
|
470
|
-
middleware:
|
|
471
|
-
fetch:
|
|
472
|
-
logger: i(this, ot)
|
|
489
|
+
middleware: a(this, D),
|
|
490
|
+
fetch: a(this, ut)
|
|
473
491
|
}).fetch();
|
|
474
492
|
};
|
|
475
|
-
function
|
|
493
|
+
function ye() {
|
|
476
494
|
if (typeof window < "u" && window.fetch)
|
|
477
495
|
return window.fetch.bind(window);
|
|
478
496
|
if (typeof global < "u" && global.fetch)
|
|
479
497
|
return global.fetch.bind(global);
|
|
480
498
|
throw new Error("Running in neither browser nor node. Please run this app in one of the supported environments.");
|
|
481
499
|
}
|
|
482
|
-
class
|
|
500
|
+
class be extends Error {
|
|
483
501
|
constructor(e) {
|
|
484
|
-
const { status: s, statusText:
|
|
502
|
+
const { status: s, statusText: r, method: n, url: o } = e, c = `${s} ${r}: Request failed (${n.toUpperCase()} ${o.toString()})`;
|
|
485
503
|
super(c);
|
|
486
|
-
|
|
504
|
+
w(this, "response");
|
|
487
505
|
this.response = e;
|
|
488
506
|
}
|
|
489
507
|
}
|
|
490
|
-
class
|
|
508
|
+
class ve {
|
|
491
509
|
constructor(t) {
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
510
|
+
w(this, "method");
|
|
511
|
+
w(this, "url");
|
|
512
|
+
w(this, "headers", new Headers());
|
|
513
|
+
w(this, "body");
|
|
496
514
|
this.method = t.method, this.body = t.body, t.uri.startsWith("http") ? this.url = new URL(t.uri) : this.url = new URL(t.uri, window.location.origin), this._applyHeaders(t.headers), this._applyQueryParams(t.query);
|
|
497
515
|
}
|
|
498
516
|
get isSameOrigin() {
|
|
@@ -504,7 +522,7 @@ class Be {
|
|
|
504
522
|
t.forEach((e, s) => {
|
|
505
523
|
this.headers.set(s, e);
|
|
506
524
|
});
|
|
507
|
-
else if (
|
|
525
|
+
else if (V(t))
|
|
508
526
|
for (const e in t) {
|
|
509
527
|
const s = t[e];
|
|
510
528
|
s instanceof Date ? this.headers.set(e, s.toISOString()) : s != null && this.headers.set(e, String(s));
|
|
@@ -518,7 +536,7 @@ class Be {
|
|
|
518
536
|
t.forEach((e, s) => {
|
|
519
537
|
this.url.searchParams.set(s, e);
|
|
520
538
|
});
|
|
521
|
-
else if (
|
|
539
|
+
else if (V(t))
|
|
522
540
|
for (const e in t) {
|
|
523
541
|
const s = t[e];
|
|
524
542
|
s instanceof Date ? this.url.searchParams.set(e, s.toISOString()) : s != null && this.url.searchParams.set(e, String(s));
|
|
@@ -527,69 +545,71 @@ class Be {
|
|
|
527
545
|
throw new TypeError(`Unknown query params type. Got: ${t}`);
|
|
528
546
|
}
|
|
529
547
|
}
|
|
530
|
-
class
|
|
548
|
+
class Ee {
|
|
531
549
|
constructor(t) {
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
this._middleware = t.middleware, this._fetch = t.fetch, this._request = new
|
|
550
|
+
w(this, "_middleware");
|
|
551
|
+
w(this, "_fetch");
|
|
552
|
+
w(this, "_request");
|
|
553
|
+
w(this, "_response");
|
|
554
|
+
this._middleware = t.middleware, this._fetch = t.fetch, this._request = new ve(t);
|
|
537
555
|
}
|
|
538
556
|
async fetch() {
|
|
539
557
|
if (this._middleware.length > 0) {
|
|
540
558
|
const t = (e = 0) => {
|
|
541
|
-
const s = this._middleware[e],
|
|
542
|
-
return async () => s(this._request, async () => (await
|
|
559
|
+
const s = this._middleware[e], r = this._middleware[e + 1] ? t(e + 1) : this._handler.bind(this);
|
|
560
|
+
return async () => s(this._request, async () => (await r(), this._response));
|
|
543
561
|
};
|
|
544
562
|
await t()();
|
|
545
563
|
} else
|
|
546
564
|
await this._handler();
|
|
547
565
|
if (this._response.status < 200 || this._response.status >= 400)
|
|
548
|
-
throw new
|
|
566
|
+
throw new be(this._response);
|
|
549
567
|
return this._response;
|
|
550
568
|
}
|
|
551
569
|
// This is the function that performs the actual request after the final middleware.
|
|
552
570
|
async _handler() {
|
|
553
571
|
let t;
|
|
554
572
|
const e = this._request;
|
|
555
|
-
!e.headers.has("content-type") &&
|
|
573
|
+
!e.headers.has("content-type") && V(e.body) ? (e.headers.set("content-type", "application/json"), t = JSON.stringify(e.body)) : t = e.body;
|
|
556
574
|
const s = await this._fetch(e.url.toString(), {
|
|
557
575
|
method: e.method,
|
|
558
576
|
headers: e.headers,
|
|
559
577
|
body: t
|
|
560
|
-
}),
|
|
561
|
-
let
|
|
562
|
-
|
|
578
|
+
}), r = s.headers.get("content-type");
|
|
579
|
+
let n;
|
|
580
|
+
r != null && r.includes("application/json") ? n = await s.json() : r != null && r.includes("application/x-www-form-urlencoded") ? n = await s.formData() : n = await s.text(), this._response = {
|
|
563
581
|
method: e.method,
|
|
564
582
|
url: e.url,
|
|
565
583
|
status: s.status,
|
|
566
584
|
statusText: s.statusText,
|
|
567
585
|
headers: s.headers,
|
|
568
|
-
body:
|
|
586
|
+
body: n
|
|
569
587
|
};
|
|
570
588
|
}
|
|
571
589
|
}
|
|
572
|
-
var
|
|
573
|
-
class
|
|
590
|
+
var ft, H, q, bt, Wt;
|
|
591
|
+
class ke {
|
|
574
592
|
constructor(t, e) {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
593
|
+
u(this, q);
|
|
594
|
+
w(this, "dolla");
|
|
595
|
+
w(this, "config");
|
|
596
|
+
u(this, ft, !1);
|
|
597
|
+
u(this, H, /* @__PURE__ */ new Map());
|
|
580
598
|
this.config = t, this.dolla = e;
|
|
581
599
|
}
|
|
582
600
|
async load() {
|
|
583
601
|
let t;
|
|
584
|
-
if (!
|
|
585
|
-
if (
|
|
586
|
-
|
|
602
|
+
if (!a(this, ft)) {
|
|
603
|
+
if (V(this.config.strings))
|
|
604
|
+
t = this.config.strings;
|
|
605
|
+
else if (B(this.config.fetch)) {
|
|
606
|
+
if (t = await this.config.fetch(), !V(t))
|
|
587
607
|
throw new Error(`Fetch function did not return an object of language strings: ${t}`);
|
|
588
|
-
} else if (
|
|
608
|
+
} else if (M(this.config.path)) {
|
|
589
609
|
const e = await fetch(this.config.path);
|
|
590
610
|
if (e.ok) {
|
|
591
611
|
const s = await e.json();
|
|
592
|
-
if (
|
|
612
|
+
if (V(s))
|
|
593
613
|
t = s;
|
|
594
614
|
else
|
|
595
615
|
throw new Error(
|
|
@@ -600,46 +620,46 @@ class ze {
|
|
|
600
620
|
}
|
|
601
621
|
}
|
|
602
622
|
if (t) {
|
|
603
|
-
const e = f(this,
|
|
623
|
+
const e = f(this, q, bt).call(this, t);
|
|
604
624
|
for (const s of e)
|
|
605
|
-
|
|
625
|
+
a(this, H).set(s[0], s[1]);
|
|
606
626
|
} else
|
|
607
627
|
throw new Error("Language could not be loaded.");
|
|
608
628
|
}
|
|
609
629
|
getTemplate(t) {
|
|
610
|
-
return
|
|
630
|
+
return a(this, H).get(t) ?? {
|
|
611
631
|
segments: [{ type: 0, text: `[MISSING: ${t}]` }]
|
|
612
632
|
};
|
|
613
633
|
}
|
|
614
634
|
hasTemplate(t) {
|
|
615
|
-
return
|
|
635
|
+
return a(this, H).has(t);
|
|
616
636
|
}
|
|
617
637
|
}
|
|
618
|
-
|
|
638
|
+
ft = new WeakMap(), H = new WeakMap(), q = new WeakSet(), bt = function(t, e = []) {
|
|
619
639
|
const s = [];
|
|
620
|
-
for (const
|
|
621
|
-
switch (
|
|
640
|
+
for (const r in t)
|
|
641
|
+
switch (St(t[r])) {
|
|
622
642
|
case "string":
|
|
623
|
-
s.push([[...e,
|
|
643
|
+
s.push([[...e, r].join("."), f(this, q, Wt).call(this, t[r])]);
|
|
624
644
|
break;
|
|
625
645
|
case "object":
|
|
626
|
-
s.push(...f(this,
|
|
646
|
+
s.push(...f(this, q, bt).call(this, t[r], [...e, r]));
|
|
627
647
|
break;
|
|
628
648
|
default:
|
|
629
649
|
throw new Error(
|
|
630
|
-
`Expected to find a string or object at ${[...e,
|
|
650
|
+
`Expected to find a string or object at ${[...e, r].join(".")}. Got: ${St(t[r])}`
|
|
631
651
|
);
|
|
632
652
|
}
|
|
633
653
|
return s;
|
|
634
|
-
},
|
|
654
|
+
}, Wt = function(t) {
|
|
635
655
|
let e;
|
|
636
|
-
((
|
|
637
|
-
|
|
656
|
+
((h) => {
|
|
657
|
+
h[h.Static = 0] = "Static", h[h.ValueName = 1] = "ValueName", h[h.FormatName = 2] = "FormatName", h[h.FormatOptionName = 3] = "FormatOptionName", h[h.FormatOptionValue = 4] = "FormatOptionValue", h[h.FormatOptionEnd = 5] = "FormatOptionEnd";
|
|
638
658
|
})(e || (e = {}));
|
|
639
659
|
const s = {
|
|
640
660
|
segments: []
|
|
641
661
|
};
|
|
642
|
-
let
|
|
662
|
+
let r = "", n = 0, o = 0, c, l, p;
|
|
643
663
|
const v = () => {
|
|
644
664
|
c = {
|
|
645
665
|
type: 1,
|
|
@@ -647,122 +667,117 @@ xt = new WeakMap(), J = new WeakMap(), H = new WeakSet(), Ct = function(t, e = [
|
|
|
647
667
|
formats: []
|
|
648
668
|
};
|
|
649
669
|
}, k = () => {
|
|
650
|
-
|
|
670
|
+
l = {
|
|
651
671
|
name: "",
|
|
652
672
|
options: {}
|
|
653
673
|
};
|
|
654
674
|
};
|
|
655
|
-
for (;
|
|
656
|
-
if (
|
|
657
|
-
|
|
675
|
+
for (; n < t.length; ) {
|
|
676
|
+
if (o !== 0 && t[n] === " ") {
|
|
677
|
+
n++;
|
|
658
678
|
continue;
|
|
659
679
|
}
|
|
660
|
-
switch (
|
|
680
|
+
switch (o) {
|
|
661
681
|
case 0:
|
|
662
|
-
t[
|
|
682
|
+
t[n] === "{" && t[n + 1] === "{" ? (o = 1, n += 2, r.length > 0 && (s.segments.push({ type: 0, text: r }), r = ""), v()) : (r += t[n], n++);
|
|
663
683
|
break;
|
|
664
684
|
case 1:
|
|
665
|
-
t[
|
|
685
|
+
t[n] === "|" ? (o = 2, n += 1, c.name = r, r = "", k()) : t[n] === "}" && t[n + 1] === "}" ? (o = 0, n += 2, c.name = r, r = "", s.segments.push(c)) : (r += t[n], n++);
|
|
666
686
|
break;
|
|
667
687
|
case 2:
|
|
668
|
-
t[
|
|
688
|
+
t[n] === "(" ? (o = 3, n += 1, l.name = r, r = "") : t[n] === "}" && t[n + 1] === "}" ? (o = 0, n += 2, c.formats.push(l), s.segments.push(c)) : (r += t[n], n++);
|
|
669
689
|
break;
|
|
670
690
|
case 3:
|
|
671
|
-
t[
|
|
691
|
+
t[n] === ")" || (t[n] === ":" ? (o = 4, n += 1, p = r, r = "") : t[n] === "}" && t[n + 1] === "}" || (r += t[n], n++));
|
|
672
692
|
break;
|
|
673
693
|
case 4:
|
|
674
|
-
t[
|
|
694
|
+
t[n] === ")" ? (o = 5, n += 1, l.options[p] = r, r = "", c.formats.push(l)) : t[n] === "," ? (o = 3, n += 1, l.options[p] = r, r = "") : t[n] === "}" && t[n + 1] === "}" || (r += t[n], n++);
|
|
675
695
|
break;
|
|
676
696
|
case 5:
|
|
677
|
-
t[
|
|
697
|
+
t[n] === "|" ? (o = 2, n += 1, k()) : t[n] === "}" && t[n + 1] === "}" && (o = 0, n += 2, s.segments.push(c));
|
|
678
698
|
break;
|
|
679
699
|
}
|
|
680
700
|
}
|
|
681
|
-
return
|
|
701
|
+
return o === 0 && r.length > 0 && s.segments.push({ type: 0, text: r }), s;
|
|
682
702
|
};
|
|
683
|
-
var
|
|
684
|
-
class
|
|
703
|
+
var X, P, g, Y, Z, tt, b, y, At, vt, Et, kt, Ht;
|
|
704
|
+
class $e {
|
|
685
705
|
constructor(t) {
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
const [e, s] = Wt();
|
|
697
|
-
this.$locale = e, m(this, ft, s), this.addFormat("number", (n, r, a) => f(this, $, jt).call(this, Number(r), a)), this.addFormat("datetime", (n, r, a) => f(this, $, Vt).call(this, r, a)), this.addFormat("list", (n, r, a) => f(this, $, It).call(this, r, a)), t.beforeMount(async () => {
|
|
698
|
-
i(this, b).size > 0 && await this.setLocale(i(this, ut));
|
|
706
|
+
u(this, y);
|
|
707
|
+
u(this, X);
|
|
708
|
+
u(this, P);
|
|
709
|
+
u(this, g, /* @__PURE__ */ new Map());
|
|
710
|
+
u(this, Y, []);
|
|
711
|
+
u(this, Z, /* @__PURE__ */ new Map());
|
|
712
|
+
u(this, tt, "auto");
|
|
713
|
+
u(this, b, Ut(""));
|
|
714
|
+
d(this, X, t), d(this, P, t.createLogger("Dolla.i18n")), this.addFormat("number", (e, s, r) => f(this, y, vt).call(this, Number(s), r)), this.addFormat("datetime", (e, s, r) => f(this, y, Et).call(this, s, r)), this.addFormat("list", (e, s, r) => f(this, y, kt).call(this, s, r)), t.beforeMount(async () => {
|
|
715
|
+
a(this, g).size > 0 && await this.setLocale(a(this, tt));
|
|
699
716
|
});
|
|
700
717
|
}
|
|
718
|
+
get locale() {
|
|
719
|
+
return a(this, b);
|
|
720
|
+
}
|
|
701
721
|
get locales() {
|
|
702
|
-
return [...
|
|
722
|
+
return [...a(this, g).keys()];
|
|
703
723
|
}
|
|
704
724
|
setup(t) {
|
|
705
725
|
if (t.translations.forEach((e) => {
|
|
706
|
-
|
|
726
|
+
a(this, g).set(e.locale, new ke(e, a(this, X)));
|
|
707
727
|
}), t.locale && t.locale !== "auto") {
|
|
708
728
|
if (!t.translations.some((s) => s.locale === t.locale))
|
|
709
729
|
throw new Error(`Initial locale '${t.locale}' is not registered in the locales array.`);
|
|
710
|
-
|
|
730
|
+
d(this, tt, t.locale);
|
|
711
731
|
}
|
|
712
|
-
|
|
713
|
-
`${
|
|
732
|
+
a(this, P).info(
|
|
733
|
+
`${a(this, g).size} language${a(this, g).size === 1 ? "" : "s"} supported: '${[...a(this, g).keys()].join("', '")}'`
|
|
714
734
|
);
|
|
715
735
|
}
|
|
716
736
|
async setLocale(t) {
|
|
717
|
-
var
|
|
737
|
+
var r;
|
|
718
738
|
let e;
|
|
719
739
|
if (t === "auto") {
|
|
720
|
-
let
|
|
740
|
+
let n = [];
|
|
721
741
|
if (typeof navigator < "u") {
|
|
722
|
-
const
|
|
723
|
-
((
|
|
742
|
+
const o = navigator;
|
|
743
|
+
((r = o.languages) == null ? void 0 : r.length) > 0 ? n.push(...o.languages) : o.language ? n.push(o.language) : o.browserLanguage ? n.push(o.browserLanguage) : o.userLanguage && n.push(o.userLanguage);
|
|
724
744
|
}
|
|
725
|
-
for (const
|
|
726
|
-
|
|
745
|
+
for (const o of n)
|
|
746
|
+
a(this, g).has(o) && (e = o);
|
|
727
747
|
} else
|
|
728
|
-
|
|
748
|
+
a(this, g).has(t) && (e = t);
|
|
729
749
|
if (e == null) {
|
|
730
|
-
const
|
|
731
|
-
|
|
750
|
+
const n = a(this, g).keys().next().value;
|
|
751
|
+
n && (e = n);
|
|
732
752
|
}
|
|
733
|
-
if (!e || !
|
|
753
|
+
if (!e || !a(this, g).has(e))
|
|
734
754
|
throw new Error(`Locale '${t}' has no translation.`);
|
|
735
|
-
const s =
|
|
755
|
+
const s = a(this, g).get(e);
|
|
736
756
|
try {
|
|
737
|
-
await s.load(),
|
|
738
|
-
} catch (
|
|
739
|
-
|
|
757
|
+
await s.load(), d(this, Y, []), a(this, b).value = e, a(this, P).info("set language to " + e);
|
|
758
|
+
} catch (n) {
|
|
759
|
+
n instanceof Error && a(this, P).crash(n);
|
|
740
760
|
}
|
|
741
761
|
}
|
|
742
762
|
/**
|
|
743
|
-
|
|
763
|
+
* Returns a State containing the value at `key`.
|
|
744
764
|
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
765
|
+
* @param selector - Key to the translated value.
|
|
766
|
+
* @param options - A map of `{{placeholder}}` names and the values to replace them with.
|
|
767
|
+
*
|
|
768
|
+
* @example
|
|
769
|
+
* const $value = t("your.key.here", { count: 5 });
|
|
770
|
+
*/
|
|
751
771
|
t(t, e) {
|
|
752
772
|
if (this === void 0)
|
|
753
773
|
throw new Error(
|
|
754
774
|
`The 't' function cannot be destructured. If you need a standalone version you can import it like so: 'import { t } from "@manyducks.co/dolla"'`
|
|
755
775
|
);
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
return "[NO LOCALE SET]";
|
|
762
|
-
const c = {};
|
|
763
|
-
for (let h = 0; h < a.length; h++)
|
|
764
|
-
c[s[h]] = a[h];
|
|
765
|
-
return f(this, $, he).call(this, r, t, c);
|
|
776
|
+
return U(() => {
|
|
777
|
+
const s = {};
|
|
778
|
+
for (const r in e)
|
|
779
|
+
s[r] = E(e[r]);
|
|
780
|
+
return f(this, y, At).call(this, E(a(this, b)), t, s);
|
|
766
781
|
});
|
|
767
782
|
}
|
|
768
783
|
/**
|
|
@@ -780,7 +795,7 @@ class Ke {
|
|
|
780
795
|
* t("greeting", {name: "world"}); // State<"Hello, WORLD!">
|
|
781
796
|
*/
|
|
782
797
|
addFormat(t, e) {
|
|
783
|
-
|
|
798
|
+
a(this, Z).set(t, e);
|
|
784
799
|
}
|
|
785
800
|
/**
|
|
786
801
|
* Creates an `Intl.Collator` configured for the current locale.
|
|
@@ -789,18 +804,18 @@ class Ke {
|
|
|
789
804
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options
|
|
790
805
|
*/
|
|
791
806
|
collator(t) {
|
|
792
|
-
return new Intl.Collator(this
|
|
807
|
+
return new Intl.Collator(a(this, b).value, t);
|
|
793
808
|
}
|
|
794
809
|
/**
|
|
795
|
-
*
|
|
810
|
+
* Formats a number for the current locale. Uses `Intl.NumberFormat` under the hood.
|
|
796
811
|
*
|
|
797
812
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
|
|
798
813
|
*/
|
|
799
814
|
number(t, e) {
|
|
800
|
-
return
|
|
815
|
+
return U(() => (E(a(this, b)), f(this, y, vt).call(this, E(t), e)));
|
|
801
816
|
}
|
|
802
817
|
/**
|
|
803
|
-
*
|
|
818
|
+
* Formats a date for the current locale. Uses `Intl.DateTimeFormat` under the hood.
|
|
804
819
|
*
|
|
805
820
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options
|
|
806
821
|
*
|
|
@@ -809,10 +824,10 @@ class Ke {
|
|
|
809
824
|
* const $formatted = Dolla.i18n.dateTime(date, { dateFormat: "short" });
|
|
810
825
|
*/
|
|
811
826
|
dateTime(t, e) {
|
|
812
|
-
return
|
|
827
|
+
return U(() => (E(a(this, b)), f(this, y, Et).call(this, E(t), e)));
|
|
813
828
|
}
|
|
814
829
|
/**
|
|
815
|
-
*
|
|
830
|
+
* Formats a list for the current locale. Uses `Intl.ListFormat` under the hood.
|
|
816
831
|
*
|
|
817
832
|
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options
|
|
818
833
|
*
|
|
@@ -821,68 +836,68 @@ class Ke {
|
|
|
821
836
|
* const $formatted = Dolla.i18n.list(list, { });
|
|
822
837
|
*/
|
|
823
838
|
list(t, e) {
|
|
824
|
-
return
|
|
839
|
+
return U(() => (E(a(this, b)), f(this, y, kt).call(this, E(t), e)));
|
|
825
840
|
}
|
|
826
841
|
}
|
|
827
|
-
|
|
828
|
-
var
|
|
829
|
-
const
|
|
830
|
-
if (
|
|
831
|
-
const
|
|
842
|
+
X = new WeakMap(), P = new WeakMap(), g = new WeakMap(), Y = new WeakMap(), Z = new WeakMap(), tt = new WeakMap(), b = new WeakMap(), y = new WeakSet(), At = function(t, e, s) {
|
|
843
|
+
var l;
|
|
844
|
+
const r = f(this, y, Ht).call(this, e, s);
|
|
845
|
+
if (r) return r;
|
|
846
|
+
const n = a(this, g).get(t);
|
|
832
847
|
if (s.context != null && (e += "_" + s.context), s.count != null)
|
|
833
848
|
if (s.ordinal) {
|
|
834
|
-
const
|
|
835
|
-
|
|
849
|
+
const p = `${e}_ordinal_(=${s.count})`;
|
|
850
|
+
n.hasTemplate(p) ? e = p : e += "_ordinal_" + new Intl.PluralRules(t, { type: "ordinal" }).select(s.count);
|
|
836
851
|
} else {
|
|
837
|
-
const
|
|
838
|
-
|
|
852
|
+
const p = `${e}_(=${s.count})`;
|
|
853
|
+
n.hasTemplate(p) ? e = p : e += "_" + new Intl.PluralRules(t).select(s.count);
|
|
839
854
|
}
|
|
840
|
-
const
|
|
855
|
+
const o = n.getTemplate(e);
|
|
841
856
|
let c = "";
|
|
842
|
-
for (const
|
|
843
|
-
if (
|
|
844
|
-
c +=
|
|
845
|
-
else if (
|
|
846
|
-
let v =
|
|
847
|
-
const k = ((
|
|
848
|
-
|
|
849
|
-
for (const
|
|
850
|
-
const
|
|
851
|
-
if (
|
|
852
|
-
const
|
|
853
|
-
`Failed to load format '${
|
|
857
|
+
for (const p of o.segments)
|
|
858
|
+
if (p.type === 0)
|
|
859
|
+
c += p.text;
|
|
860
|
+
else if (p.type === 1) {
|
|
861
|
+
let v = Re(s, p.name);
|
|
862
|
+
const k = ((l = s.formatOverrides) == null ? void 0 : l[p.name]) ?? [...p.formats];
|
|
863
|
+
p.name === "count" && k.length === 0 && k.push({ name: "number", options: {} });
|
|
864
|
+
for (const h of k) {
|
|
865
|
+
const x = a(this, Z).get(h.name);
|
|
866
|
+
if (x == null) {
|
|
867
|
+
const $ = new Error(
|
|
868
|
+
`Failed to load format '${h.name}' when processing '${e}', template: ${o}`
|
|
854
869
|
);
|
|
855
|
-
throw
|
|
870
|
+
throw a(this, P).crash($), $;
|
|
856
871
|
}
|
|
857
|
-
v =
|
|
872
|
+
v = x(t, v, h.options);
|
|
858
873
|
}
|
|
859
874
|
c += v;
|
|
860
875
|
}
|
|
861
876
|
return c;
|
|
862
|
-
},
|
|
863
|
-
return new Intl.NumberFormat(this
|
|
864
|
-
},
|
|
865
|
-
return new Intl.DateTimeFormat(this
|
|
866
|
-
},
|
|
867
|
-
return new Intl.ListFormat(this
|
|
877
|
+
}, vt = function(t, e) {
|
|
878
|
+
return new Intl.NumberFormat(a(this, b).value, e).format(t);
|
|
879
|
+
}, Et = function(t, e) {
|
|
880
|
+
return new Intl.DateTimeFormat(a(this, b).value, e).format(M(t) ? new Date(t) : t);
|
|
881
|
+
}, kt = function(t, e) {
|
|
882
|
+
return new Intl.ListFormat(a(this, b).value, e).format(t);
|
|
868
883
|
}, // relativeTime(): State<string> {
|
|
869
884
|
// }
|
|
870
|
-
|
|
871
|
-
for (const s of
|
|
872
|
-
if (s[0] === t &&
|
|
885
|
+
Ht = function(t, e) {
|
|
886
|
+
for (const s of a(this, Y))
|
|
887
|
+
if (s[0] === t && Jt(s[1], e))
|
|
873
888
|
return s[2];
|
|
874
889
|
};
|
|
875
|
-
function
|
|
876
|
-
const e = String(t).split(/[\.\[\]]/).filter((
|
|
877
|
-
let s =
|
|
890
|
+
function Re(i, t) {
|
|
891
|
+
const e = String(t).split(/[\.\[\]]/).filter((r) => r.trim() !== "");
|
|
892
|
+
let s = i;
|
|
878
893
|
for (; e.length > 0; ) {
|
|
879
|
-
const
|
|
880
|
-
s != null ? s = s[
|
|
894
|
+
const r = e.shift();
|
|
895
|
+
s != null ? s = s[r] : s = void 0;
|
|
881
896
|
}
|
|
882
897
|
return s;
|
|
883
898
|
}
|
|
884
|
-
function
|
|
885
|
-
return
|
|
899
|
+
function _e(i) {
|
|
900
|
+
return Mt`
|
|
886
901
|
<div
|
|
887
902
|
style=${{
|
|
888
903
|
backgroundColor: "#880000",
|
|
@@ -895,8 +910,8 @@ function Je(o) {
|
|
|
895
910
|
>
|
|
896
911
|
<h1 style=${{ marginBottom: "0.5rem" }}>The app has crashed</h1>
|
|
897
912
|
<p style=${{ marginBottom: "0.25rem" }}>
|
|
898
|
-
<span style=${{ fontFamily: "monospace" }}>${
|
|
899
|
-
${
|
|
913
|
+
<span style=${{ fontFamily: "monospace" }}>${i.loggerName}</span>
|
|
914
|
+
${Xt(i.uid, Mt`<span style=${{ fontFamily: "monospace", opacity: 0.5 }}> [uid: ${i.uid}]</span>`)}
|
|
900
915
|
${" "}says:
|
|
901
916
|
</p>
|
|
902
917
|
<blockquote
|
|
@@ -919,276 +934,129 @@ function Je(o) {
|
|
|
919
934
|
fontWeight: "bold"
|
|
920
935
|
}}
|
|
921
936
|
>
|
|
922
|
-
${
|
|
937
|
+
${i.error.name}
|
|
923
938
|
</span>
|
|
924
|
-
${
|
|
939
|
+
${i.error.message}
|
|
925
940
|
</blockquote>
|
|
926
941
|
|
|
927
942
|
<p>Please see the browser console for details.</p>
|
|
928
943
|
</div>
|
|
929
944
|
`;
|
|
930
945
|
}
|
|
931
|
-
var
|
|
932
|
-
class
|
|
933
|
-
constructor(t) {
|
|
934
|
-
l(this, D);
|
|
935
|
-
l(this, dt);
|
|
936
|
-
l(this, X);
|
|
937
|
-
// Keys ensure only the most recent callback queued with a certain key
|
|
938
|
-
// will be called, keeping DOM operations to a minimum.
|
|
939
|
-
l(this, O, /* @__PURE__ */ new Map());
|
|
940
|
-
// All unkeyed writes are run on every batch.
|
|
941
|
-
l(this, A, []);
|
|
942
|
-
// All read callbacks are run before updates on every batch.
|
|
943
|
-
l(this, G, []);
|
|
944
|
-
l(this, Y, !1);
|
|
945
|
-
// When true, batches that would exceed 16ms will be split and deferred to a rAF.
|
|
946
|
-
// This may not be desirable, because while it does prevent hitching it sometimes leaves
|
|
947
|
-
// the state partially rendered for a brief second and certain elements can be seen to update after the fact.
|
|
948
|
-
// But the tradeoff here is snappier navigation with possibly slightly out of date DOM updates on heavy pages.
|
|
949
|
-
l(this, Dt, !0);
|
|
950
|
-
l(this, M, 0);
|
|
951
|
-
l(this, mt, new Intl.NumberFormat("en-US", {
|
|
952
|
-
maximumFractionDigits: 2,
|
|
953
|
-
minimumFractionDigits: 0,
|
|
954
|
-
style: "unit",
|
|
955
|
-
unit: "millisecond",
|
|
956
|
-
unitDisplay: "short"
|
|
957
|
-
}));
|
|
958
|
-
m(this, dt, t), m(this, X, t.createLogger("Dolla.batch"));
|
|
959
|
-
}
|
|
960
|
-
/**
|
|
961
|
-
* Queues a callback that runs before the next batch of writes.
|
|
962
|
-
*/
|
|
963
|
-
read(t) {
|
|
964
|
-
i(this, G).push(t), f(this, D, qt).call(this);
|
|
965
|
-
}
|
|
966
|
-
/**
|
|
967
|
-
* Queues a callback to run in the next render batch.
|
|
968
|
-
* Always put DOM mutations in a write callback when possible to help Dolla batch them efficiently.
|
|
969
|
-
*/
|
|
970
|
-
write(t, e) {
|
|
971
|
-
e ? i(this, O).set(e, t) : i(this, A).push(t), f(this, D, qt).call(this);
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
dt = new WeakMap(), X = new WeakMap(), O = new WeakMap(), A = new WeakMap(), G = new WeakMap(), Y = new WeakMap(), Dt = new WeakMap(), M = new WeakMap(), mt = new WeakMap(), D = new WeakSet(), qt = function() {
|
|
975
|
-
if (!i(this, Y)) {
|
|
976
|
-
m(this, Y, !0);
|
|
977
|
-
const t = i(this, dt).getEnv() === "development";
|
|
978
|
-
queueMicrotask(() => {
|
|
979
|
-
f(this, D, _t).call(this, t);
|
|
980
|
-
});
|
|
981
|
-
}
|
|
982
|
-
}, _t = function(t = !1) {
|
|
983
|
-
const e = performance.now();
|
|
984
|
-
let s = 0;
|
|
985
|
-
const n = i(this, G).length + i(this, O).size + i(this, A).length;
|
|
986
|
-
let r = 0;
|
|
987
|
-
const a = () => (r++, s = performance.now() - e, i(this, Dt) && s > 12 && r < n ? (st(this, M)._++, t && i(this, X).warn(
|
|
988
|
-
`⚠️ Deferring batch to next frame. Performed ${r} of ${n} batched operation${r === 1 ? "" : "s"} in ${i(this, mt).format(s)} (deferral ${i(this, M)}).`
|
|
989
|
-
), requestAnimationFrame(() => {
|
|
990
|
-
f(this, D, _t).call(this, t);
|
|
991
|
-
}), !0) : !1), c = [...i(this, O).entries()];
|
|
992
|
-
let h, w;
|
|
993
|
-
for (; w = i(this, G).shift(); )
|
|
994
|
-
if (w(), a()) return;
|
|
995
|
-
for ([h, w] of c)
|
|
996
|
-
if (w(), i(this, O).delete(h), a()) return;
|
|
997
|
-
for (; w = i(this, A).shift(); )
|
|
998
|
-
if (w(), a()) return;
|
|
999
|
-
t && i(this, X)[s > 16 ? "warn" : "info"](
|
|
1000
|
-
`${s > 16 ? "⚠️ (>=16ms) " : ""}Executed ${r} operation${r === 1 ? "" : "s"} in ${i(this, mt).format(s)}${i(this, M) > 0 ? ` (after ${i(this, M)} deferral${i(this, M) === 1 ? "" : "s"})` : ""}.`
|
|
1001
|
-
), m(this, M, 0), i(this, G).length || i(this, O).size || i(this, A).length ? queueMicrotask(() => {
|
|
1002
|
-
f(this, D, _t).call(this, t);
|
|
1003
|
-
}) : m(this, Y, !1);
|
|
1004
|
-
};
|
|
1005
|
-
var U, wt, C, B, pt, gt, Z, yt, bt, $t, vt, g, y, j, V, Ft;
|
|
1006
|
-
class Ye {
|
|
946
|
+
var L, et, F, I, st, z, nt, rt, at, it, O, ot, lt, dt;
|
|
947
|
+
class Se {
|
|
1007
948
|
constructor() {
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
l(this, $t, []);
|
|
1023
|
-
l(this, vt, []);
|
|
1024
|
-
l(this, g, {
|
|
949
|
+
// TODO: Take these off the global Dolla object.
|
|
950
|
+
w(this, "http");
|
|
951
|
+
w(this, "i18n");
|
|
952
|
+
u(this, L, !1);
|
|
953
|
+
u(this, et, "production");
|
|
954
|
+
u(this, F);
|
|
955
|
+
u(this, I);
|
|
956
|
+
u(this, st, _e);
|
|
957
|
+
u(this, z);
|
|
958
|
+
u(this, nt, []);
|
|
959
|
+
u(this, rt, []);
|
|
960
|
+
u(this, at, []);
|
|
961
|
+
u(this, it, []);
|
|
962
|
+
u(this, O, {
|
|
1025
963
|
root: this,
|
|
1026
|
-
data: {},
|
|
1027
|
-
emitter: new ge(),
|
|
1028
964
|
stores: /* @__PURE__ */ new Map(),
|
|
1029
965
|
viewName: "Dolla"
|
|
1030
966
|
});
|
|
1031
|
-
|
|
967
|
+
u(this, ot, {
|
|
1032
968
|
info: "development",
|
|
1033
969
|
log: "development",
|
|
1034
970
|
warn: "development",
|
|
1035
971
|
error: !0
|
|
1036
972
|
});
|
|
1037
|
-
|
|
1038
|
-
l(this, V, /* @__PURE__ */ new Map());
|
|
973
|
+
u(this, lt, xt("*,-Dolla.*"));
|
|
1039
974
|
// Registration functions for modules.
|
|
1040
975
|
// All modules will be registered before mount.
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
d(this, "createState", Wt);
|
|
1044
|
-
d(this, "toState", be);
|
|
1045
|
-
d(this, "toValue", $e);
|
|
1046
|
-
d(this, "isState", ve);
|
|
1047
|
-
d(this, "derive", x);
|
|
1048
|
-
d(this, "createWatcher", zt);
|
|
1049
|
-
d(this, "createRef", Ee);
|
|
1050
|
-
d(this, "isRef", ke);
|
|
1051
|
-
this.batch = new Xe(this), this.stats = new ye(this), this.http = new We(this), this.i18n = new Ke(this);
|
|
976
|
+
u(this, dt, []);
|
|
977
|
+
this.http = new ge(), this.i18n = new $e(this);
|
|
1052
978
|
}
|
|
1053
979
|
/**
|
|
1054
980
|
* True when the app is connected to a DOM node and displayed to the user.
|
|
1055
981
|
*/
|
|
1056
982
|
get isMounted() {
|
|
1057
|
-
return
|
|
983
|
+
return a(this, L);
|
|
1058
984
|
}
|
|
1059
985
|
/**
|
|
1060
986
|
* Get the current environment that this app is running in.
|
|
1061
987
|
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
1062
988
|
*/
|
|
1063
989
|
getEnv() {
|
|
1064
|
-
return
|
|
990
|
+
return a(this, et);
|
|
1065
991
|
}
|
|
1066
992
|
/**
|
|
1067
993
|
* Sets the environment that this app is running in.
|
|
1068
994
|
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
1069
995
|
*/
|
|
1070
996
|
setEnv(t) {
|
|
1071
|
-
|
|
997
|
+
d(this, et, t);
|
|
1072
998
|
}
|
|
1073
999
|
/**
|
|
1074
1000
|
* Sets the view that will be shown when the `crash` method is called on any logger.
|
|
1075
1001
|
* When a crash is reported the app will be unmounted and replaced with this crash page.
|
|
1076
1002
|
*/
|
|
1077
1003
|
setCrashView(t) {
|
|
1078
|
-
|
|
1004
|
+
d(this, st, t);
|
|
1079
1005
|
}
|
|
1080
1006
|
/**
|
|
1081
1007
|
* Returns the HTMLElement Dolla is mounted to. This will return undefined until Dolla.mount() is called.
|
|
1082
1008
|
*/
|
|
1083
1009
|
getRootElement() {
|
|
1084
|
-
return
|
|
1010
|
+
return a(this, F);
|
|
1085
1011
|
}
|
|
1086
1012
|
/**
|
|
1087
1013
|
* Returns the top level view Dolla is rendering inside the root element. This will return undefined until Dolla.mount() is called.
|
|
1088
1014
|
*/
|
|
1089
1015
|
getRootView() {
|
|
1090
|
-
return
|
|
1091
|
-
}
|
|
1092
|
-
/**
|
|
1093
|
-
* Sets a context variable and returns its value. Context variables are accessible on the app and in child views.
|
|
1094
|
-
*/
|
|
1095
|
-
set(t, e) {
|
|
1096
|
-
return i(this, g).data[t] = e, e;
|
|
1097
|
-
}
|
|
1098
|
-
/**
|
|
1099
|
-
* Gets the value of a context variable. Returns null if the variable is not set.
|
|
1100
|
-
*/
|
|
1101
|
-
get(t) {
|
|
1102
|
-
return i(this, g).data[t] ?? null;
|
|
1103
|
-
}
|
|
1104
|
-
/**
|
|
1105
|
-
* Returns an object of all context variables stored at the app level.
|
|
1106
|
-
*/
|
|
1107
|
-
// getAll(): Record<string | symbol, unknown> {
|
|
1108
|
-
// return { ...this.#rootElementContext.data };
|
|
1109
|
-
// }
|
|
1110
|
-
/**
|
|
1111
|
-
* Adds a listener to be called when an event with a matching `type` is emitted.
|
|
1112
|
-
*/
|
|
1113
|
-
on(t, e) {
|
|
1114
|
-
if (t === "*") {
|
|
1115
|
-
const s = (n, r, ...a) => {
|
|
1116
|
-
e(r, ...a);
|
|
1117
|
-
};
|
|
1118
|
-
i(this, g).emitter.on(t, s), i(this, V).set(e, s);
|
|
1119
|
-
} else
|
|
1120
|
-
i(this, g).emitter.on(t, e);
|
|
1121
|
-
}
|
|
1122
|
-
/**
|
|
1123
|
-
* Removes a listener from the list to be called when an event with a matching `type` is emitted.
|
|
1124
|
-
*/
|
|
1125
|
-
off(t, e) {
|
|
1126
|
-
if (t === "*") {
|
|
1127
|
-
const s = i(this, V).get(e);
|
|
1128
|
-
s && (i(this, g).emitter.off(t, s), i(this, V).delete(e));
|
|
1129
|
-
} else
|
|
1130
|
-
i(this, g).emitter.off(t, e);
|
|
1131
|
-
}
|
|
1132
|
-
/**
|
|
1133
|
-
* Adds a listener to be called when an event with a matching `type` is emitted. The listener is immediately removed after being called once.
|
|
1134
|
-
*/
|
|
1135
|
-
once(t, e) {
|
|
1136
|
-
if (t === "*") {
|
|
1137
|
-
const s = (n, r, ...a) => {
|
|
1138
|
-
i(this, V).delete(e), e(r, ...a);
|
|
1139
|
-
};
|
|
1140
|
-
i(this, g).emitter.once(t, s), i(this, V).set(e, s);
|
|
1141
|
-
} else
|
|
1142
|
-
i(this, g).emitter.once(t, e);
|
|
1143
|
-
}
|
|
1144
|
-
/**
|
|
1145
|
-
* Emits a new event to all listeners.
|
|
1146
|
-
*/
|
|
1147
|
-
emit(t, ...e) {
|
|
1148
|
-
return i(this, g).emitter.emit(t, new Re(t), ...e);
|
|
1016
|
+
return a(this, I);
|
|
1149
1017
|
}
|
|
1150
1018
|
provide(t, e) {
|
|
1151
|
-
const s = new
|
|
1152
|
-
if (s.attach(
|
|
1019
|
+
const s = new Yt(t, e);
|
|
1020
|
+
if (s.attach(a(this, O)))
|
|
1153
1021
|
return s.value;
|
|
1154
1022
|
{
|
|
1155
|
-
let
|
|
1156
|
-
return console.warn(`An instance of ${
|
|
1023
|
+
let n = t.name ? `'${t.name}'` : "this store";
|
|
1024
|
+
return console.warn(`An instance of ${n} was already attached to this context.`), this.get(t);
|
|
1157
1025
|
}
|
|
1158
1026
|
}
|
|
1159
1027
|
/**
|
|
1160
1028
|
* Gets the nearest instance of a store. Throws an error if the store isn't provided higher in the tree.
|
|
1161
1029
|
*/
|
|
1162
|
-
|
|
1163
|
-
if (
|
|
1164
|
-
const e =
|
|
1030
|
+
get(t) {
|
|
1031
|
+
if (B(t)) {
|
|
1032
|
+
const e = a(this, O).stores.get(t);
|
|
1165
1033
|
if (e == null)
|
|
1166
|
-
throw new
|
|
1034
|
+
throw new Tt("Store not found on this context.");
|
|
1167
1035
|
return e.value;
|
|
1168
1036
|
} else
|
|
1169
|
-
throw new
|
|
1037
|
+
throw new Tt("Invalid store.");
|
|
1170
1038
|
}
|
|
1171
1039
|
async mount(t, e) {
|
|
1172
|
-
if (
|
|
1040
|
+
if (a(this, L))
|
|
1173
1041
|
throw new Error("Dolla is already mounted.");
|
|
1174
|
-
if (
|
|
1175
|
-
const
|
|
1176
|
-
|
|
1042
|
+
if (M(t)) {
|
|
1043
|
+
const n = document.querySelector(t);
|
|
1044
|
+
Nt(HTMLElement, n, `Selector '${t}' did not match any element.`), d(this, F, n);
|
|
1177
1045
|
} else
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
const s =
|
|
1181
|
-
|
|
1182
|
-
for (const
|
|
1183
|
-
|
|
1184
|
-
for (const
|
|
1185
|
-
|
|
1046
|
+
Nt(HTMLElement, t, "Expected an HTML element or a selector string. Got type: %t, value: %v"), d(this, F, t);
|
|
1047
|
+
pt(e) && d(this, z, e);
|
|
1048
|
+
const s = pt(e) ? jt : e, r = Zt(s);
|
|
1049
|
+
d(this, I, this.constructView(r.type, r.props)), await Promise.all(a(this, dt).map((n) => n())), pt(e) && await le(e, this), await Promise.all(a(this, nt).map((n) => n())), a(this, I).mount(a(this, F)), d(this, L, !0);
|
|
1050
|
+
for (const n of a(this, O).stores.values())
|
|
1051
|
+
n.handleMount();
|
|
1052
|
+
for (const n of a(this, rt))
|
|
1053
|
+
n();
|
|
1186
1054
|
}
|
|
1187
1055
|
async unmount() {
|
|
1188
1056
|
var t;
|
|
1189
|
-
if (
|
|
1190
|
-
await Promise.all(
|
|
1191
|
-
for (const e of
|
|
1057
|
+
if (a(this, L)) {
|
|
1058
|
+
await Promise.all(a(this, at).map((e) => e())), (t = a(this, I)) == null || t.unmount(!1), a(this, z) && await ce(a(this, z)), d(this, L, !1);
|
|
1059
|
+
for (const e of a(this, it))
|
|
1192
1060
|
e();
|
|
1193
1061
|
}
|
|
1194
1062
|
}
|
|
@@ -1197,26 +1065,26 @@ class Ye {
|
|
|
1197
1065
|
* it will be awaited before mounting finishes. Use this to perform initial setup before the app is displayed to the user.
|
|
1198
1066
|
*/
|
|
1199
1067
|
beforeMount(t) {
|
|
1200
|
-
|
|
1068
|
+
a(this, nt).push(t);
|
|
1201
1069
|
}
|
|
1202
1070
|
/**
|
|
1203
1071
|
* Registers a `callback` to run after the app is mounted.
|
|
1204
1072
|
*/
|
|
1205
1073
|
onMount(t) {
|
|
1206
|
-
|
|
1074
|
+
a(this, rt).push(t);
|
|
1207
1075
|
}
|
|
1208
1076
|
/**
|
|
1209
1077
|
* Registers a `callback` to run after `Dolla.unmount` is called, before the app is unmounted. If `callback` returns a Promise,
|
|
1210
1078
|
* it will be awaited before unmounting finishes. Use this to perform cleanup.
|
|
1211
1079
|
*/
|
|
1212
1080
|
beforeUnmount(t) {
|
|
1213
|
-
|
|
1081
|
+
a(this, at).push(t);
|
|
1214
1082
|
}
|
|
1215
1083
|
/**
|
|
1216
1084
|
* Registers a `callback` to run after the app is unmounted.
|
|
1217
1085
|
*/
|
|
1218
1086
|
onUnmount(t) {
|
|
1219
|
-
|
|
1087
|
+
a(this, it).push(t);
|
|
1220
1088
|
}
|
|
1221
1089
|
/**
|
|
1222
1090
|
* Update log type toggles. Values that are not passed will remain unchanged.
|
|
@@ -1224,88 +1092,50 @@ class Ye {
|
|
|
1224
1092
|
setLoggles(t) {
|
|
1225
1093
|
for (const e in t) {
|
|
1226
1094
|
const s = t[e];
|
|
1227
|
-
s && (
|
|
1095
|
+
s && (a(this, ot)[e] = s);
|
|
1228
1096
|
}
|
|
1229
1097
|
}
|
|
1230
1098
|
setLogFilter(t) {
|
|
1231
|
-
|
|
1099
|
+
d(this, lt, xt(t));
|
|
1232
1100
|
}
|
|
1233
1101
|
createLogger(t, e) {
|
|
1234
|
-
const s = (e == null ? void 0 : e.console) ??
|
|
1102
|
+
const s = (e == null ? void 0 : e.console) ?? Me(), r = this, n = a(this, ot), o = (c) => {
|
|
1103
|
+
if (n[c] === !1 || M(n[c]) && n[c] !== r.getEnv() || !a(this, lt).call(this, t))
|
|
1104
|
+
return ne;
|
|
1105
|
+
{
|
|
1106
|
+
let l = `%c${t}`;
|
|
1107
|
+
return e != null && e.uid ? l += ` %c[uid: %c${e.uid}%c]` : l += "%c%c%c", s[c].bind(
|
|
1108
|
+
s,
|
|
1109
|
+
l,
|
|
1110
|
+
`color:${re(l)};font-weight:bold`,
|
|
1111
|
+
"color:#777",
|
|
1112
|
+
"color:#aaa",
|
|
1113
|
+
"color:#777"
|
|
1114
|
+
);
|
|
1115
|
+
}
|
|
1116
|
+
};
|
|
1235
1117
|
return {
|
|
1236
|
-
setName(
|
|
1237
|
-
return t =
|
|
1118
|
+
setName(c) {
|
|
1119
|
+
return t = c, this;
|
|
1238
1120
|
},
|
|
1239
1121
|
get info() {
|
|
1240
|
-
|
|
1241
|
-
if (i(n, y).info === !1 || E(i(n, y).info) && i(n, y).info !== n.getEnv() || !i(r = n, j).call(r, t))
|
|
1242
|
-
return Et;
|
|
1243
|
-
{
|
|
1244
|
-
let a = `%c${t}`;
|
|
1245
|
-
return e != null && e.uid ? a += ` %c[uid: %c${e.uid}%c]` : a += "%c%c%c", s.info.bind(
|
|
1246
|
-
s,
|
|
1247
|
-
a,
|
|
1248
|
-
`color:${kt(a)};font-weight:bold`,
|
|
1249
|
-
"color:#777",
|
|
1250
|
-
"color:#aaa",
|
|
1251
|
-
"color:#777"
|
|
1252
|
-
);
|
|
1253
|
-
}
|
|
1122
|
+
return o("info");
|
|
1254
1123
|
},
|
|
1255
1124
|
get log() {
|
|
1256
|
-
|
|
1257
|
-
if (i(n, y).log === !1 || E(i(n, y).log) && i(n, y).log !== n.getEnv() || !i(r = n, j).call(r, t))
|
|
1258
|
-
return Et;
|
|
1259
|
-
{
|
|
1260
|
-
let a = `%c${t}`;
|
|
1261
|
-
return e != null && e.uid ? a += ` %c[uid: %c${e.uid}%c]` : a += "%c%c%c", s.log.bind(
|
|
1262
|
-
s,
|
|
1263
|
-
a,
|
|
1264
|
-
`color:${kt(a)};font-weight:bold`,
|
|
1265
|
-
"color:#777",
|
|
1266
|
-
"color:#aaa",
|
|
1267
|
-
"color:#777"
|
|
1268
|
-
);
|
|
1269
|
-
}
|
|
1125
|
+
return o("log");
|
|
1270
1126
|
},
|
|
1271
1127
|
get warn() {
|
|
1272
|
-
|
|
1273
|
-
if (i(n, y).warn === !1 || E(i(n, y).warn) && i(n, y).warn !== n.getEnv() || !i(r = n, j).call(r, t))
|
|
1274
|
-
return Et;
|
|
1275
|
-
{
|
|
1276
|
-
let a = `%c${t}`;
|
|
1277
|
-
return e != null && e.uid ? a += ` %c[uid: %c${e.uid}%c]` : a += "%c%c%c", s.warn.bind(
|
|
1278
|
-
s,
|
|
1279
|
-
a,
|
|
1280
|
-
`color:${kt(a)};font-weight:bold`,
|
|
1281
|
-
"color:#777",
|
|
1282
|
-
"color:#aaa",
|
|
1283
|
-
"color:#777"
|
|
1284
|
-
);
|
|
1285
|
-
}
|
|
1128
|
+
return o("warn");
|
|
1286
1129
|
},
|
|
1287
1130
|
get error() {
|
|
1288
|
-
|
|
1289
|
-
if (i(n, y).error === !1 || E(i(n, y).error) && i(n, y).error !== n.getEnv() || !i(r = n, j).call(r, t))
|
|
1290
|
-
return Et;
|
|
1291
|
-
{
|
|
1292
|
-
let a = `%c${t}`;
|
|
1293
|
-
return e != null && e.uid ? a += ` %c[uid: %c${e.uid}%c]` : a += "%c%c%c", s.error.bind(
|
|
1294
|
-
s,
|
|
1295
|
-
a,
|
|
1296
|
-
`color:${kt(a)};font-weight:bold`,
|
|
1297
|
-
"color:#777",
|
|
1298
|
-
"color:#aaa",
|
|
1299
|
-
"color:#777"
|
|
1300
|
-
);
|
|
1301
|
-
}
|
|
1131
|
+
return o("error");
|
|
1302
1132
|
},
|
|
1303
|
-
crash(
|
|
1304
|
-
|
|
1305
|
-
error:
|
|
1133
|
+
crash(c) {
|
|
1134
|
+
r.isMounted && (r.unmount(), r.constructView(a(r, st), {
|
|
1135
|
+
error: c,
|
|
1306
1136
|
loggerName: t,
|
|
1307
1137
|
uid: e == null ? void 0 : e.uid
|
|
1308
|
-
}).mount(
|
|
1138
|
+
}).mount(a(r, F)));
|
|
1309
1139
|
}
|
|
1310
1140
|
};
|
|
1311
1141
|
}
|
|
@@ -1313,49 +1143,41 @@ class Ye {
|
|
|
1313
1143
|
*
|
|
1314
1144
|
*/
|
|
1315
1145
|
constructView(t, e, s = []) {
|
|
1316
|
-
return new
|
|
1146
|
+
return new te(a(this, O), t, e, s);
|
|
1317
1147
|
}
|
|
1318
1148
|
/**
|
|
1319
1149
|
*
|
|
1320
1150
|
*/
|
|
1321
1151
|
constructMarkup(t) {
|
|
1322
|
-
return
|
|
1152
|
+
return ee(se(a(this, O), t));
|
|
1323
1153
|
}
|
|
1324
1154
|
}
|
|
1325
|
-
|
|
1326
|
-
function
|
|
1155
|
+
L = new WeakMap(), et = new WeakMap(), F = new WeakMap(), I = new WeakMap(), st = new WeakMap(), z = new WeakMap(), nt = new WeakMap(), rt = new WeakMap(), at = new WeakMap(), it = new WeakMap(), O = new WeakMap(), ot = new WeakMap(), lt = new WeakMap(), dt = new WeakMap();
|
|
1156
|
+
function Me() {
|
|
1327
1157
|
if (typeof window < "u" && window.console)
|
|
1328
1158
|
return window.console;
|
|
1329
1159
|
if (typeof global < "u" && global.console)
|
|
1330
1160
|
return global.console;
|
|
1331
1161
|
}
|
|
1332
|
-
const
|
|
1333
|
-
function ns(o) {
|
|
1334
|
-
typeof window < "u" && (window.DOLLA_DEV_DEBUG = o);
|
|
1335
|
-
}
|
|
1336
|
-
function is() {
|
|
1337
|
-
return typeof window < "u" ? window.DOLLA_DEV_DEBUG === !0 : !1;
|
|
1338
|
-
}
|
|
1162
|
+
const Pt = new Se(), Le = Pt.i18n.t.bind(Pt.i18n);
|
|
1339
1163
|
export {
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
be as toState,
|
|
1359
|
-
$e as toValue
|
|
1164
|
+
Ut as atom,
|
|
1165
|
+
U as compose,
|
|
1166
|
+
Xt as cond,
|
|
1167
|
+
Zt as createMarkup,
|
|
1168
|
+
Pe as createRouter,
|
|
1169
|
+
Jt as deepEqual,
|
|
1170
|
+
Pt as default,
|
|
1171
|
+
Ue as effect,
|
|
1172
|
+
E as get,
|
|
1173
|
+
Mt as html,
|
|
1174
|
+
je as list,
|
|
1175
|
+
Ce as peek,
|
|
1176
|
+
De as portal,
|
|
1177
|
+
Ne as ref,
|
|
1178
|
+
Ie as set,
|
|
1179
|
+
_t as shallowEqual,
|
|
1180
|
+
Ve as strictEqual,
|
|
1181
|
+
Le as t
|
|
1360
1182
|
};
|
|
1361
1183
|
//# sourceMappingURL=index.js.map
|