@manyducks.co/dolla 2.0.0-alpha.2 → 2.0.0-alpha.20
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 +168 -513
- package/dist/index.d.ts +12 -10
- package/dist/index.js +997 -732
- package/dist/index.js.map +1 -1
- package/dist/jsx-dev-runtime.js +2 -2
- package/dist/jsx-runtime.js +2 -2
- package/dist/markup.d.ts +39 -26
- package/dist/modules/dolla.d.ts +28 -14
- package/dist/modules/i18n.d.ts +129 -0
- package/dist/modules/render.d.ts +5 -8
- package/dist/modules/router.d.ts +8 -8
- package/dist/nodes/cond.d.ts +7 -7
- package/dist/nodes/html.d.ts +12 -6
- package/dist/nodes/observer.d.ts +9 -8
- package/dist/nodes/outlet.d.ts +8 -8
- package/dist/nodes/portal.d.ts +4 -4
- package/dist/nodes/repeat.d.ts +14 -14
- package/dist/nodes/text.d.ts +6 -6
- package/dist/passthrough-DrILnMr2.js +1393 -0
- package/dist/passthrough-DrILnMr2.js.map +1 -0
- package/dist/state.d.ts +151 -0
- package/dist/types.d.ts +12 -12
- package/dist/utils.d.ts +0 -1
- package/dist/view.d.ts +45 -9
- package/docs/http.md +5 -0
- package/docs/i18n.md +5 -0
- package/docs/router.md +5 -0
- package/docs/states.md +5 -0
- package/docs/views.md +5 -0
- package/notes/context-vars.md +21 -0
- package/notes/readme-scratch.md +222 -0
- package/notes/route-middleware.md +42 -0
- package/notes/scratch.md +93 -6
- package/package.json +13 -13
- package/tests/{signals.test.js → state.test.js} +6 -6
- package/dist/modules/language.d.ts +0 -41
- package/dist/passthrough-DrtCifRF.js +0 -1228
- package/dist/passthrough-DrtCifRF.js.map +0 -1
- package/dist/signals.d.ts +0 -101
package/dist/index.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
throw TypeError(
|
|
1
|
+
var Nt = Object.defineProperty;
|
|
2
|
+
var pt = (i) => {
|
|
3
|
+
throw TypeError(i);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
var et = (
|
|
9
|
-
set _(
|
|
10
|
-
|
|
5
|
+
var Mt = (i, e, t) => e in i ? Nt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
6
|
+
var P = (i, e, t) => Mt(i, typeof e != "symbol" ? e + "" : e, t), Ze = (i, e, t) => e.has(i) || pt("Cannot " + t);
|
|
7
|
+
var s = (i, e, t) => (Ze(i, e, "read from private field"), t ? t.call(i) : e.get(i)), h = (i, e, t) => e.has(i) ? pt("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(i) : e.set(i, t), v = (i, e, t, r) => (Ze(i, e, "write to private field"), r ? r.call(i, t) : e.set(i, t), t), b = (i, e, t) => (Ze(i, e, "access private method"), t);
|
|
8
|
+
var et = (i, e, t, r) => ({
|
|
9
|
+
set _(n) {
|
|
10
|
+
v(i, e, n, t);
|
|
11
11
|
},
|
|
12
12
|
get _() {
|
|
13
|
-
return
|
|
13
|
+
return s(i, e, r);
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
import { h as
|
|
17
|
-
import {
|
|
18
|
-
function
|
|
19
|
-
return
|
|
16
|
+
import { h as mt, c as jt, i as rt, g as Tt, a as ce, d as be, b as dt, e as V, t as gt, f as St, j as qt, k as nt, P as Pt, l as wt, m as Ft, n as At, o as _t, v as Ct, p as Vt, q as It, r as yt, s as vt, u as Ut, w as Ce, x as Ve, V as Ht, y as Wt, z as Bt } from "./passthrough-DrILnMr2.js";
|
|
17
|
+
import { A as kr, B as Sr, C as Pr } from "./passthrough-DrILnMr2.js";
|
|
18
|
+
function Gt(i) {
|
|
19
|
+
return mt`
|
|
20
20
|
<div
|
|
21
21
|
style=${{
|
|
22
22
|
backgroundColor: "#880000",
|
|
@@ -29,8 +29,8 @@ function Nt(n) {
|
|
|
29
29
|
>
|
|
30
30
|
<h1 style=${{ marginBottom: "0.5rem" }}>The app has crashed</h1>
|
|
31
31
|
<p style=${{ marginBottom: "0.25rem" }}>
|
|
32
|
-
<span style=${{ fontFamily: "monospace" }}>${
|
|
33
|
-
${
|
|
32
|
+
<span style=${{ fontFamily: "monospace" }}>${i.loggerName}</span>
|
|
33
|
+
${jt(i.uid, mt`<span style=${{ fontFamily: "monospace", opacity: 0.5 }}> [uid: ${i.uid}]</span>`)}
|
|
34
34
|
${" "}says:
|
|
35
35
|
</p>
|
|
36
36
|
<blockquote
|
|
@@ -53,21 +53,21 @@ function Nt(n) {
|
|
|
53
53
|
fontWeight: "bold"
|
|
54
54
|
}}
|
|
55
55
|
>
|
|
56
|
-
${
|
|
56
|
+
${i.error.name}
|
|
57
57
|
</span>
|
|
58
|
-
${
|
|
58
|
+
${i.error.message}
|
|
59
59
|
</blockquote>
|
|
60
60
|
|
|
61
61
|
<p>Please see the browser console for details.</p>
|
|
62
62
|
</div>
|
|
63
63
|
`;
|
|
64
64
|
}
|
|
65
|
-
var
|
|
66
|
-
class
|
|
65
|
+
var Y, Qe, M, F;
|
|
66
|
+
class zt {
|
|
67
67
|
constructor() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
h(this, M);
|
|
69
|
+
h(this, Y, []);
|
|
70
|
+
h(this, Qe, Kt());
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* Adds a new middleware that will apply to subsequent requests.
|
|
@@ -76,364 +76,555 @@ class Ot {
|
|
|
76
76
|
* @param middleware - A middleware function that will intercept requests.
|
|
77
77
|
*/
|
|
78
78
|
use(e) {
|
|
79
|
-
return
|
|
80
|
-
|
|
79
|
+
return s(this, Y).push(e), () => {
|
|
80
|
+
s(this, Y).splice(s(this, Y).indexOf(e), 1);
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
async get(e, t) {
|
|
84
|
-
return
|
|
84
|
+
return b(this, M, F).call(this, "get", e, t);
|
|
85
85
|
}
|
|
86
86
|
async put(e, t) {
|
|
87
|
-
return
|
|
87
|
+
return b(this, M, F).call(this, "put", e, t);
|
|
88
88
|
}
|
|
89
89
|
async patch(e, t) {
|
|
90
|
-
return
|
|
90
|
+
return b(this, M, F).call(this, "patch", e, t);
|
|
91
91
|
}
|
|
92
92
|
async post(e, t) {
|
|
93
|
-
return
|
|
93
|
+
return b(this, M, F).call(this, "post", e, t);
|
|
94
94
|
}
|
|
95
95
|
async delete(e, t) {
|
|
96
|
-
return
|
|
96
|
+
return b(this, M, F).call(this, "delete", e, t);
|
|
97
97
|
}
|
|
98
98
|
async head(e, t) {
|
|
99
|
-
return
|
|
99
|
+
return b(this, M, F).call(this, "head", e, t);
|
|
100
100
|
}
|
|
101
101
|
async options(e, t) {
|
|
102
|
-
return
|
|
102
|
+
return b(this, M, F).call(this, "options", e, t);
|
|
103
103
|
}
|
|
104
104
|
async trace(e, t) {
|
|
105
|
-
return
|
|
105
|
+
return b(this, M, F).call(this, "trace", e, t);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
|
|
109
|
-
return
|
|
108
|
+
Y = new WeakMap(), Qe = new WeakMap(), M = new WeakSet(), F = async function(e, t, r) {
|
|
109
|
+
return Jt({
|
|
110
110
|
...r,
|
|
111
111
|
method: e,
|
|
112
112
|
uri: t,
|
|
113
|
-
middleware:
|
|
114
|
-
fetch:
|
|
113
|
+
middleware: s(this, Y),
|
|
114
|
+
fetch: s(this, Qe)
|
|
115
115
|
});
|
|
116
116
|
};
|
|
117
|
-
function
|
|
117
|
+
function Kt() {
|
|
118
118
|
if (typeof window < "u" && window.fetch)
|
|
119
119
|
return window.fetch.bind(window);
|
|
120
120
|
if (typeof global < "u" && global.fetch)
|
|
121
121
|
return global.fetch.bind(global);
|
|
122
122
|
throw new Error("Running in neither browser nor node. Please run this app in one of the supported environments.");
|
|
123
123
|
}
|
|
124
|
-
class
|
|
124
|
+
class Qt extends Error {
|
|
125
125
|
constructor(t) {
|
|
126
|
-
const { status: r, statusText:
|
|
127
|
-
super(
|
|
128
|
-
|
|
126
|
+
const { status: r, statusText: n, method: a, uri: o } = t, p = `${r} ${n}: Request failed (${a.toUpperCase()} ${o})`;
|
|
127
|
+
super(p);
|
|
128
|
+
P(this, "response");
|
|
129
129
|
this.response = t;
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
|
-
async function
|
|
133
|
-
const { headers: e, query: t, fetch: r, middleware:
|
|
134
|
-
method:
|
|
135
|
-
uri:
|
|
132
|
+
async function Jt(i) {
|
|
133
|
+
const { headers: e, query: t, fetch: r, middleware: n } = i, a = {
|
|
134
|
+
method: i.method,
|
|
135
|
+
uri: i.uri,
|
|
136
136
|
get sameOrigin() {
|
|
137
|
-
return !
|
|
137
|
+
return !a.uri.startsWith("http");
|
|
138
138
|
},
|
|
139
139
|
query: new URLSearchParams(),
|
|
140
140
|
headers: new Headers(),
|
|
141
|
-
body:
|
|
141
|
+
body: i.body
|
|
142
142
|
};
|
|
143
143
|
if (e)
|
|
144
144
|
if (e instanceof Map || e instanceof Headers)
|
|
145
|
-
e.forEach((
|
|
146
|
-
|
|
145
|
+
e.forEach((l, f) => {
|
|
146
|
+
a.headers.set(f, l);
|
|
147
147
|
});
|
|
148
148
|
else if (e != null && typeof e == "object" && !Array.isArray(e))
|
|
149
|
-
for (const
|
|
150
|
-
const
|
|
151
|
-
|
|
149
|
+
for (const l in e) {
|
|
150
|
+
const f = e[l];
|
|
151
|
+
f instanceof Date ? a.headers.set(l, f.toISOString()) : f != null && a.headers.set(l, String(f));
|
|
152
152
|
}
|
|
153
153
|
else
|
|
154
154
|
throw new TypeError(`Unknown headers type. Got: ${e}`);
|
|
155
155
|
if (t)
|
|
156
156
|
if (t instanceof Map || t instanceof URLSearchParams)
|
|
157
|
-
t.forEach((
|
|
158
|
-
|
|
157
|
+
t.forEach((l, f) => {
|
|
158
|
+
a.query.set(f, l);
|
|
159
159
|
});
|
|
160
160
|
else if (t != null && typeof t == "object" && !Array.isArray(t))
|
|
161
|
-
for (const
|
|
162
|
-
const
|
|
163
|
-
|
|
161
|
+
for (const l in t) {
|
|
162
|
+
const f = t[l];
|
|
163
|
+
f instanceof Date ? a.query.set(l, f.toISOString()) : f != null && a.query.set(l, String(f));
|
|
164
164
|
}
|
|
165
165
|
else
|
|
166
166
|
throw new TypeError(`Unknown query params type. Got: ${t}`);
|
|
167
167
|
let o;
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
let
|
|
171
|
-
!
|
|
172
|
-
const
|
|
173
|
-
method:
|
|
174
|
-
headers:
|
|
175
|
-
body:
|
|
176
|
-
}),
|
|
177
|
-
let
|
|
178
|
-
|
|
179
|
-
method:
|
|
180
|
-
uri:
|
|
181
|
-
status:
|
|
182
|
-
statusText:
|
|
183
|
-
headers:
|
|
184
|
-
body:
|
|
168
|
+
const p = async () => {
|
|
169
|
+
const l = a.query.toString(), f = l.length > 0 ? a.uri + "?" + l : a.uri;
|
|
170
|
+
let m;
|
|
171
|
+
!a.headers.has("content-type") && rt(a.body) ? (a.headers.set("content-type", "application/json"), m = JSON.stringify(a.body)) : m = a.body;
|
|
172
|
+
const g = await r(f, {
|
|
173
|
+
method: a.method,
|
|
174
|
+
headers: a.headers,
|
|
175
|
+
body: m
|
|
176
|
+
}), u = Object.fromEntries(g.headers.entries()), y = u["content-type"];
|
|
177
|
+
let k;
|
|
178
|
+
y != null && y.includes("application/json") ? k = await g.json() : y != null && y.includes("application/x-www-form-urlencoded") ? k = await g.formData() : k = await g.text(), o = {
|
|
179
|
+
method: a.method,
|
|
180
|
+
uri: a.uri,
|
|
181
|
+
status: g.status,
|
|
182
|
+
statusText: g.statusText,
|
|
183
|
+
headers: u,
|
|
184
|
+
body: k
|
|
185
185
|
};
|
|
186
186
|
};
|
|
187
|
-
if (
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
-
return async () =>
|
|
187
|
+
if (n.length > 0) {
|
|
188
|
+
const l = (f = 0) => {
|
|
189
|
+
const m = n[f], g = n[f + 1] ? l(f + 1) : p;
|
|
190
|
+
return async () => m(a, async () => (await g(), o));
|
|
191
191
|
};
|
|
192
|
-
await
|
|
192
|
+
await l()();
|
|
193
193
|
} else
|
|
194
|
-
await
|
|
194
|
+
await p();
|
|
195
195
|
if (o.status < 200 || o.status >= 400)
|
|
196
|
-
throw new
|
|
196
|
+
throw new Qt(o);
|
|
197
197
|
return o;
|
|
198
198
|
}
|
|
199
|
-
|
|
199
|
+
var tt, bt;
|
|
200
|
+
function Yt() {
|
|
201
|
+
return bt || (bt = 1, tt = function i(e, t) {
|
|
202
|
+
if (e === t) return !0;
|
|
203
|
+
if (e && t && typeof e == "object" && typeof t == "object") {
|
|
204
|
+
if (e.constructor !== t.constructor) return !1;
|
|
205
|
+
var r, n, a;
|
|
206
|
+
if (Array.isArray(e)) {
|
|
207
|
+
if (r = e.length, r != t.length) return !1;
|
|
208
|
+
for (n = r; n-- !== 0; )
|
|
209
|
+
if (!i(e[n], t[n])) return !1;
|
|
210
|
+
return !0;
|
|
211
|
+
}
|
|
212
|
+
if (e.constructor === RegExp) return e.source === t.source && e.flags === t.flags;
|
|
213
|
+
if (e.valueOf !== Object.prototype.valueOf) return e.valueOf() === t.valueOf();
|
|
214
|
+
if (e.toString !== Object.prototype.toString) return e.toString() === t.toString();
|
|
215
|
+
if (a = Object.keys(e), r = a.length, r !== Object.keys(t).length) return !1;
|
|
216
|
+
for (n = r; n-- !== 0; )
|
|
217
|
+
if (!Object.prototype.hasOwnProperty.call(t, a[n])) return !1;
|
|
218
|
+
for (n = r; n-- !== 0; ) {
|
|
219
|
+
var o = a[n];
|
|
220
|
+
if (!i(e[o], t[o])) return !1;
|
|
221
|
+
}
|
|
222
|
+
return !0;
|
|
223
|
+
}
|
|
224
|
+
return e !== e && t !== t;
|
|
225
|
+
}), tt;
|
|
226
|
+
}
|
|
227
|
+
var Xt = Yt();
|
|
228
|
+
const Zt = /* @__PURE__ */ Tt(Xt);
|
|
229
|
+
var Je, ue, se, at, xt;
|
|
230
|
+
class er {
|
|
200
231
|
constructor(e, t) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
232
|
+
h(this, se);
|
|
233
|
+
P(this, "dolla");
|
|
234
|
+
P(this, "config");
|
|
235
|
+
h(this, Je, !1);
|
|
236
|
+
h(this, ue, /* @__PURE__ */ new Map());
|
|
204
237
|
this.config = e, this.dolla = t;
|
|
205
238
|
}
|
|
206
239
|
async load() {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
if (
|
|
211
|
-
this.strings = e;
|
|
212
|
-
else
|
|
240
|
+
let e;
|
|
241
|
+
if (!s(this, Je)) {
|
|
242
|
+
if (dt(this.config.fetch)) {
|
|
243
|
+
if (e = await this.config.fetch(), !rt(e))
|
|
213
244
|
throw new Error(`Fetch function did not return an object of language strings: ${e}`);
|
|
214
|
-
} else if (
|
|
215
|
-
const
|
|
216
|
-
if (
|
|
217
|
-
if (
|
|
218
|
-
|
|
245
|
+
} else if (V(this.config.path)) {
|
|
246
|
+
const t = await this.dolla.http.get(this.config.path);
|
|
247
|
+
if (t.status >= 200 && t.status < 300)
|
|
248
|
+
if (rt(t.body))
|
|
249
|
+
e = t.body;
|
|
219
250
|
else
|
|
220
251
|
throw new Error(
|
|
221
|
-
`Language path '${this.config.path}' did not return an object of language strings: ${
|
|
252
|
+
`Language path '${this.config.path}' did not return an object of language strings: ${t.body}`
|
|
222
253
|
);
|
|
223
254
|
else
|
|
224
255
|
throw new Error("HTTP request failed.");
|
|
225
256
|
}
|
|
226
257
|
}
|
|
227
|
-
if (
|
|
258
|
+
if (e) {
|
|
259
|
+
const t = b(this, se, at).call(this, e);
|
|
260
|
+
for (const r of t)
|
|
261
|
+
s(this, ue).set(r[0], r[1]);
|
|
262
|
+
} else
|
|
228
263
|
throw new Error("Language could not be loaded.");
|
|
229
|
-
|
|
264
|
+
}
|
|
265
|
+
getTemplate(e) {
|
|
266
|
+
return s(this, ue).get(e) ?? {
|
|
267
|
+
segments: [{ type: 0, text: `[MISSING: ${e}]` }]
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
hasTemplate(e) {
|
|
271
|
+
return s(this, ue).has(e);
|
|
230
272
|
}
|
|
231
273
|
}
|
|
232
|
-
|
|
233
|
-
|
|
274
|
+
Je = new WeakMap(), ue = new WeakMap(), se = new WeakSet(), at = function(e, t = []) {
|
|
275
|
+
const r = [];
|
|
276
|
+
for (const n in e)
|
|
277
|
+
switch (gt(e[n])) {
|
|
278
|
+
case "string":
|
|
279
|
+
r.push([[...t, n].join("."), b(this, se, xt).call(this, e[n])]);
|
|
280
|
+
break;
|
|
281
|
+
case "object":
|
|
282
|
+
r.push(...b(this, se, at).call(this, e[n], [...t, n]));
|
|
283
|
+
break;
|
|
284
|
+
default:
|
|
285
|
+
throw new Error(
|
|
286
|
+
`Expected to find a string or object at ${[...t, n].join(".")}. Got: ${gt(e[n])}`
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
return r;
|
|
290
|
+
}, xt = function(e) {
|
|
291
|
+
let t;
|
|
292
|
+
((u) => {
|
|
293
|
+
u[u.Static = 0] = "Static", u[u.ValueName = 1] = "ValueName", u[u.FormatName = 2] = "FormatName", u[u.FormatOptionName = 3] = "FormatOptionName", u[u.FormatOptionValue = 4] = "FormatOptionValue", u[u.FormatOptionEnd = 5] = "FormatOptionEnd";
|
|
294
|
+
})(t || (t = {}));
|
|
295
|
+
const r = {
|
|
296
|
+
segments: []
|
|
297
|
+
};
|
|
298
|
+
let n = "", a = 0, o = 0, p, l, f;
|
|
299
|
+
const m = () => {
|
|
300
|
+
p = {
|
|
301
|
+
type: 1,
|
|
302
|
+
name: "",
|
|
303
|
+
formats: []
|
|
304
|
+
};
|
|
305
|
+
}, g = () => {
|
|
306
|
+
l = {
|
|
307
|
+
name: "",
|
|
308
|
+
options: {}
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
for (; a < e.length; ) {
|
|
312
|
+
if (o !== 0 && e[a] === " ") {
|
|
313
|
+
a++;
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
switch (o) {
|
|
317
|
+
case 0:
|
|
318
|
+
e[a] === "{" && e[a + 1] === "{" ? (o = 1, a += 2, n.length > 0 && (r.segments.push({ type: 0, text: n }), n = ""), m()) : (n += e[a], a++);
|
|
319
|
+
break;
|
|
320
|
+
case 1:
|
|
321
|
+
e[a] === "|" ? (o = 2, a += 1, p.name = n, n = "", g()) : e[a] === "}" && e[a + 1] === "}" ? (o = 0, a += 2, p.name = n, n = "", r.segments.push(p)) : (n += e[a], a++);
|
|
322
|
+
break;
|
|
323
|
+
case 2:
|
|
324
|
+
e[a] === "(" ? (o = 3, a += 1, l.name = n, n = "") : e[a] === "}" && e[a + 1] === "}" ? (o = 0, a += 2, p.formats.push(l), r.segments.push(p)) : (n += e[a], a++);
|
|
325
|
+
break;
|
|
326
|
+
case 3:
|
|
327
|
+
e[a] === ")" || (e[a] === ":" ? (o = 4, a += 1, f = n, n = "") : e[a] === "}" && e[a + 1] === "}" || (n += e[a], a++));
|
|
328
|
+
break;
|
|
329
|
+
case 4:
|
|
330
|
+
e[a] === ")" ? (o = 5, a += 1, l.options[f] = n, n = "", p.formats.push(l)) : e[a] === "," ? (o = 3, a += 1, l.options[f] = n, n = "") : e[a] === "}" && e[a + 1] === "}" || (n += e[a], a++);
|
|
331
|
+
break;
|
|
332
|
+
case 5:
|
|
333
|
+
e[a] === "|" ? (o = 2, a += 1, g()) : e[a] === "}" && e[a + 1] === "}" && (o = 0, a += 2, r.segments.push(p));
|
|
334
|
+
break;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
return o === 0 && n.length > 0 && r.segments.push({ type: 0, text: n }), r;
|
|
338
|
+
};
|
|
339
|
+
var Ee, I, L, ke, Se, Pe, xe, R, Ot, st, it, ot, Lt;
|
|
340
|
+
class tr {
|
|
234
341
|
constructor(e) {
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
a(this, x).size > 0 && await this.setLanguage(a(this, we));
|
|
342
|
+
h(this, R);
|
|
343
|
+
h(this, Ee);
|
|
344
|
+
h(this, I);
|
|
345
|
+
h(this, L, /* @__PURE__ */ new Map());
|
|
346
|
+
h(this, ke, []);
|
|
347
|
+
h(this, Se, /* @__PURE__ */ new Map());
|
|
348
|
+
h(this, Pe, "auto");
|
|
349
|
+
P(this, "$locale");
|
|
350
|
+
h(this, xe);
|
|
351
|
+
v(this, Ee, e), v(this, I, e.createLogger("dolla/i18n"));
|
|
352
|
+
const [t, r] = ce();
|
|
353
|
+
this.$locale = t, v(this, xe, r), this.addFormat("number", (n, a, o) => b(this, R, st).call(this, Number(a), o)), this.addFormat("datetime", (n, a, o) => b(this, R, it).call(this, a, o)), this.addFormat("list", (n, a, o) => b(this, R, ot).call(this, a, o)), e.beforeMount(async () => {
|
|
354
|
+
s(this, L).size > 0 && await this.setLocale(s(this, Pe));
|
|
249
355
|
});
|
|
250
356
|
}
|
|
251
|
-
get
|
|
252
|
-
return [...
|
|
357
|
+
get locales() {
|
|
358
|
+
return [...s(this, L).keys()];
|
|
253
359
|
}
|
|
254
360
|
setup(e) {
|
|
255
|
-
if (e.
|
|
256
|
-
|
|
257
|
-
}), e.
|
|
258
|
-
if (!e.
|
|
259
|
-
throw new Error(`Initial
|
|
260
|
-
|
|
361
|
+
if (e.translations.forEach((t) => {
|
|
362
|
+
s(this, L).set(t.locale, new er(t, s(this, Ee)));
|
|
363
|
+
}), e.locale && e.locale !== "auto") {
|
|
364
|
+
if (!e.translations.some((r) => r.locale === e.locale))
|
|
365
|
+
throw new Error(`Initial locale '${e.locale}' is not registered in the locales array.`);
|
|
366
|
+
v(this, Pe, e.locale);
|
|
261
367
|
}
|
|
262
|
-
|
|
263
|
-
`${
|
|
368
|
+
s(this, I).info(
|
|
369
|
+
`${s(this, L).size} language${s(this, L).size === 1 ? "" : "s"} supported: '${[...s(this, L).keys()].join("', '")}'`
|
|
264
370
|
);
|
|
265
371
|
}
|
|
266
|
-
async
|
|
267
|
-
var
|
|
372
|
+
async setLocale(e) {
|
|
373
|
+
var n;
|
|
268
374
|
let t;
|
|
269
375
|
if (e === "auto") {
|
|
270
|
-
let
|
|
376
|
+
let a = [];
|
|
271
377
|
if (typeof navigator == "object") {
|
|
272
378
|
const o = navigator;
|
|
273
|
-
((
|
|
379
|
+
((n = o.languages) == null ? void 0 : n.length) > 0 ? a.push(...o.languages) : o.language ? a.push(o.language) : o.browserLanguage ? a.push(o.browserLanguage) : o.userLanguage && a.push(o.userLanguage);
|
|
274
380
|
}
|
|
275
|
-
for (const o of
|
|
276
|
-
|
|
381
|
+
for (const o of a)
|
|
382
|
+
s(this, L).has(o) && (t = o);
|
|
277
383
|
} else
|
|
278
|
-
|
|
384
|
+
s(this, L).has(e) && (t = e);
|
|
279
385
|
if (t == null) {
|
|
280
|
-
const
|
|
281
|
-
|
|
386
|
+
const a = s(this, L).keys().next().value;
|
|
387
|
+
a && (t = a);
|
|
282
388
|
}
|
|
283
|
-
if (!t || !
|
|
284
|
-
throw new Error(`
|
|
285
|
-
const r =
|
|
389
|
+
if (!t || !s(this, L).has(t))
|
|
390
|
+
throw new Error(`Locale '${e}' has no translation.`);
|
|
391
|
+
const r = s(this, L).get(t);
|
|
286
392
|
try {
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
i instanceof Error && a(this, Y).crash(i);
|
|
393
|
+
await r.load(), v(this, ke, []), s(this, xe).call(this, t), s(this, I).info("set language to " + t);
|
|
394
|
+
} catch (a) {
|
|
395
|
+
a instanceof Error && s(this, I).crash(a);
|
|
291
396
|
}
|
|
292
397
|
}
|
|
293
398
|
/**
|
|
294
|
-
* Returns a
|
|
399
|
+
* Returns a State containing the value at `key`.
|
|
295
400
|
|
|
296
|
-
* @param
|
|
297
|
-
* @param
|
|
401
|
+
* @param selector - Key to the translated value.
|
|
402
|
+
* @param options - A map of `{{placeholder}}` names and the values to replace them with.
|
|
403
|
+
*
|
|
404
|
+
* @example
|
|
405
|
+
* const $value = t("your.key.here", { count: 5 });
|
|
298
406
|
*/
|
|
299
407
|
t(e, t) {
|
|
300
408
|
if (this === void 0)
|
|
301
409
|
throw new Error(
|
|
302
410
|
`The 't' function cannot be destructured. If you need a standalone version you can import it like so: 'import { t } from "@manyducks.co/dolla"'`
|
|
303
411
|
);
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
const
|
|
311
|
-
for (
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
if (o.length > 0) {
|
|
315
|
-
const f = o.map((y) => y[1]), c = Be([a(this, se), ...f], (y, ...w) => {
|
|
316
|
-
const p = w.map(($, j) => o[j]), d = {
|
|
317
|
-
...t
|
|
318
|
-
};
|
|
319
|
-
for (let $ = 0; $ < p.length; $++) {
|
|
320
|
-
const j = p[$][0];
|
|
321
|
-
d[j] = w[$];
|
|
322
|
-
}
|
|
323
|
-
const b = st(y, e) || `[NO TRANSLATION: ${e}]`;
|
|
324
|
-
return it(b, d);
|
|
325
|
-
});
|
|
326
|
-
return a(this, ie).push([e, t, c]), c;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
const s = Be([a(this, se)], (i) => {
|
|
330
|
-
let o = st(i, e) || `[NO TRANSLATION: ${e}]`;
|
|
331
|
-
return t && (o = it(o, t)), o;
|
|
412
|
+
let r = [], n = [];
|
|
413
|
+
for (const a in t)
|
|
414
|
+
r.push(a), n.push(t[a]);
|
|
415
|
+
return be([this.$locale, ...n], (a, ...o) => {
|
|
416
|
+
if (a == null)
|
|
417
|
+
return "[NO LOCALE SET]";
|
|
418
|
+
const p = {};
|
|
419
|
+
for (let l = 0; l < o.length; l++)
|
|
420
|
+
p[r[l]] = o[l];
|
|
421
|
+
return b(this, R, Ot).call(this, a, e, p);
|
|
332
422
|
});
|
|
333
|
-
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Add a custom format callback.
|
|
426
|
+
*
|
|
427
|
+
* @example
|
|
428
|
+
* Dolla.i18n.addFormat("uppercase", (locale, value, options) => {
|
|
429
|
+
* return value.toUpperCase();
|
|
430
|
+
* });
|
|
431
|
+
*
|
|
432
|
+
* {
|
|
433
|
+
* "greeting": "Hello, {{name|uppercase}}!"
|
|
434
|
+
* }
|
|
435
|
+
*
|
|
436
|
+
* t("greeting", {name: "world"}); // State<"Hello, WORLD!">
|
|
437
|
+
*/
|
|
438
|
+
addFormat(e, t) {
|
|
439
|
+
s(this, Se).set(e, t);
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Creates an `Intl.Collator` configured for the current locale.
|
|
443
|
+
* NOTE: The Collator remains bound to the locale it was created with, even when the app's locale changes.
|
|
444
|
+
*
|
|
445
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Collator/Collator#options
|
|
446
|
+
*/
|
|
447
|
+
collator(e) {
|
|
448
|
+
return new Intl.Collator(this.$locale.get(), e);
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* Returns a State containing the number formatted for the current locale. Uses `Intl.NumberFormat` under the hood.
|
|
452
|
+
*
|
|
453
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
|
|
454
|
+
*/
|
|
455
|
+
number(e, t) {
|
|
456
|
+
return be([this.$locale, e], (r, n) => b(this, R, st).call(this, n, t));
|
|
457
|
+
}
|
|
458
|
+
/**
|
|
459
|
+
* Returns a State containing the date formatted for the current locale. Uses `Intl.DateTimeFormat` under the hood.
|
|
460
|
+
*
|
|
461
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options
|
|
462
|
+
*
|
|
463
|
+
* @example
|
|
464
|
+
* const date = new Date();
|
|
465
|
+
* const $formatted = Dolla.i18n.dateTime(date, { dateFormat: "short" });
|
|
466
|
+
*/
|
|
467
|
+
dateTime(e, t) {
|
|
468
|
+
return be([this.$locale, e], (r, n) => b(this, R, it).call(this, n, t));
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Returns a State containing the date formatted for the current locale. Uses `Intl.DateTimeFormat` under the hood.
|
|
472
|
+
*
|
|
473
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/DateTimeFormat/DateTimeFormat#options
|
|
474
|
+
*
|
|
475
|
+
* @example
|
|
476
|
+
* const list = new Date();
|
|
477
|
+
* const $formatted = Dolla.i18n.list(list, { });
|
|
478
|
+
*/
|
|
479
|
+
list(e, t) {
|
|
480
|
+
return be([this.$locale, e], (r, n) => b(this, R, ot).call(this, n, t));
|
|
334
481
|
}
|
|
335
482
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
483
|
+
Ee = new WeakMap(), I = new WeakMap(), L = new WeakMap(), ke = new WeakMap(), Se = new WeakMap(), Pe = new WeakMap(), xe = new WeakMap(), R = new WeakSet(), Ot = function(e, t, r) {
|
|
484
|
+
var l;
|
|
485
|
+
const n = b(this, R, Lt).call(this, t, r);
|
|
486
|
+
if (n) return n;
|
|
487
|
+
const a = s(this, L).get(e);
|
|
488
|
+
if (r.context != null && (t += "_" + r.context), r.count != null)
|
|
489
|
+
if (r.ordinal) {
|
|
490
|
+
const f = `${t}_ordinal_(=${r.count})`;
|
|
491
|
+
a.hasTemplate(f) ? t = f : t += "_ordinal_" + new Intl.PluralRules(e, { type: "ordinal" }).select(r.count);
|
|
492
|
+
} else {
|
|
493
|
+
const f = `${t}_(=${r.count})`;
|
|
494
|
+
a.hasTemplate(f) ? t = f : t += "_" + new Intl.PluralRules(e).select(r.count);
|
|
495
|
+
}
|
|
496
|
+
const o = a.getTemplate(t);
|
|
497
|
+
let p = "";
|
|
498
|
+
for (const f of o.segments)
|
|
499
|
+
if (f.type === 0)
|
|
500
|
+
p += f.text;
|
|
501
|
+
else if (f.type === 1) {
|
|
502
|
+
let m = rr(r, f.name);
|
|
503
|
+
const g = ((l = r.formatOverrides) == null ? void 0 : l[f.name]) ?? [...f.formats];
|
|
504
|
+
f.name === "count" && g.length === 0 && g.push({ name: "number", options: {} });
|
|
505
|
+
for (const u of g) {
|
|
506
|
+
const y = s(this, Se).get(u.name);
|
|
507
|
+
if (y == null) {
|
|
508
|
+
const k = new Error(
|
|
509
|
+
`Failed to load format '${u.name}' when processing '${t}', template: ${o}`
|
|
510
|
+
);
|
|
511
|
+
throw s(this, I).crash(k), k;
|
|
512
|
+
}
|
|
513
|
+
m = y(e, m, u.options);
|
|
514
|
+
}
|
|
515
|
+
p += m;
|
|
516
|
+
}
|
|
517
|
+
return p;
|
|
518
|
+
}, st = function(e, t) {
|
|
519
|
+
return new Intl.NumberFormat(this.$locale.get(), t).format(e);
|
|
520
|
+
}, it = function(e, t) {
|
|
521
|
+
return new Intl.DateTimeFormat(this.$locale.get(), t).format(
|
|
522
|
+
typeof e == "string" ? new Date(e) : e
|
|
523
|
+
);
|
|
524
|
+
}, ot = function(e, t) {
|
|
525
|
+
return new Intl.ListFormat(this.$locale.get(), t).format(e);
|
|
526
|
+
}, // relativeTime(): State<string> {
|
|
527
|
+
// }
|
|
528
|
+
Lt = function(e, t) {
|
|
529
|
+
for (const r of s(this, ke))
|
|
530
|
+
if (r[0] === e && Zt(r[1], t))
|
|
339
531
|
return r[2];
|
|
340
532
|
};
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
n = n.replace(`{{${t}}}`, String(e[t]));
|
|
345
|
-
return n;
|
|
346
|
-
}
|
|
347
|
-
function st(n, e) {
|
|
348
|
-
const t = String(e).split(/[\.\[\]]/).filter((s) => s.trim() !== "");
|
|
349
|
-
let r = n;
|
|
533
|
+
function rr(i, e) {
|
|
534
|
+
const t = String(e).split(/[\.\[\]]/).filter((n) => n.trim() !== "");
|
|
535
|
+
let r = i;
|
|
350
536
|
for (; t.length > 0; ) {
|
|
351
|
-
const
|
|
352
|
-
r != null ? r = r[
|
|
537
|
+
const n = t.shift();
|
|
538
|
+
r != null ? r = r[n] : r = void 0;
|
|
353
539
|
}
|
|
354
540
|
return r;
|
|
355
541
|
}
|
|
356
|
-
var
|
|
357
|
-
class
|
|
542
|
+
var U, he, H, X, Z, ee, Ye, A, Oe, _, lt, Ie;
|
|
543
|
+
class nr {
|
|
358
544
|
constructor(e) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
//
|
|
545
|
+
h(this, _);
|
|
546
|
+
h(this, U);
|
|
547
|
+
h(this, he);
|
|
548
|
+
// Keys ensure only the most recent callback queued with a certain key
|
|
363
549
|
// will be called, keeping DOM operations to a minimum.
|
|
364
|
-
|
|
365
|
-
// All unkeyed
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
550
|
+
h(this, H, /* @__PURE__ */ new Map());
|
|
551
|
+
// All unkeyed writes are run on every batch.
|
|
552
|
+
h(this, X, []);
|
|
553
|
+
// All read callbacks are run before updates on every batch.
|
|
554
|
+
h(this, Z, []);
|
|
555
|
+
h(this, ee, !1);
|
|
556
|
+
// When true, batches that would exceed 16ms will be split and deferred to a rAF.
|
|
557
|
+
// This may not be desirable, because while it does prevent hitching it sometimes leaves
|
|
558
|
+
// the state partially rendered for a brief second and certain elements can be seen to update after the fact.
|
|
559
|
+
// But the tradeoff here is snappier navigation with possibly slightly out of date DOM updates on heavy pages.
|
|
560
|
+
h(this, Ye, !0);
|
|
561
|
+
h(this, A, 0);
|
|
562
|
+
h(this, Oe, new Intl.NumberFormat("en-US", { maximumFractionDigits: 2, minimumFractionDigits: 0 }));
|
|
563
|
+
v(this, U, e), v(this, he, e.createLogger("dolla/render"));
|
|
370
564
|
}
|
|
371
565
|
/**
|
|
372
|
-
* Queues a callback
|
|
373
|
-
* Running your DOM mutations in update callbacks reduces layout thrashing.
|
|
374
|
-
* Returns a Promise that resolves once the callback has run.
|
|
566
|
+
* Queues a callback that runs before the next batch of writes.
|
|
375
567
|
*/
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
t ? a(this, H).set(t, () => {
|
|
379
|
-
e(), r();
|
|
380
|
-
}) : a(this, _).push(() => {
|
|
381
|
-
e(), r();
|
|
382
|
-
}), !a(this, U) && a(this, X).isMounted && (m(this, U, !0), P(this, ce, Ae).call(this));
|
|
383
|
-
});
|
|
568
|
+
read(e) {
|
|
569
|
+
s(this, U).isMounted && (s(this, Z).push(e), b(this, _, lt).call(this));
|
|
384
570
|
}
|
|
385
571
|
/**
|
|
386
|
-
* Queues a callback
|
|
387
|
-
*
|
|
388
|
-
* Returns a Promise that resolves once the callback has run.
|
|
572
|
+
* Queues a callback to run in the next render batch.
|
|
573
|
+
* Always put DOM mutations in a write callback when possible to help Dolla batch them efficiently.
|
|
389
574
|
*/
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
a(this, oe).push(() => {
|
|
393
|
-
e(), t();
|
|
394
|
-
}), !a(this, U) && a(this, X).isMounted && (m(this, U, !0), P(this, ce, Ae).call(this));
|
|
395
|
-
});
|
|
575
|
+
write(e, t) {
|
|
576
|
+
s(this, U).isMounted && (t ? s(this, H).set(t, e) : s(this, X).push(e), b(this, _, lt).call(this));
|
|
396
577
|
}
|
|
397
578
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
a(this,
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
579
|
+
U = new WeakMap(), he = new WeakMap(), H = new WeakMap(), X = new WeakMap(), Z = new WeakMap(), ee = new WeakMap(), Ye = new WeakMap(), A = new WeakMap(), Oe = new WeakMap(), _ = new WeakSet(), lt = function() {
|
|
580
|
+
s(this, ee) || (v(this, ee, !0), queueMicrotask(() => {
|
|
581
|
+
b(this, _, Ie).call(this);
|
|
582
|
+
}));
|
|
583
|
+
}, Ie = function() {
|
|
584
|
+
const e = s(this, U).getEnv() === "development";
|
|
585
|
+
s(this, U).isMounted || v(this, ee, !1);
|
|
586
|
+
const t = performance.now();
|
|
587
|
+
let r = 0;
|
|
588
|
+
const n = s(this, Z).length + s(this, H).size + s(this, X).length;
|
|
589
|
+
let a = 0;
|
|
590
|
+
const o = () => (a++, r = performance.now() - t, s(this, Ye) && r > 12 && a < n ? (et(this, A)._++, e && s(this, he).warn(
|
|
591
|
+
`⚠️ Deferring batch to next frame. Performed ${a} of ${n} batched operation${a === 1 ? "" : "s"} in ${s(this, Oe).format(r)}ms (deferral ${s(this, A)}).`
|
|
592
|
+
), requestAnimationFrame(() => {
|
|
593
|
+
b(this, _, Ie).call(this);
|
|
594
|
+
}), !0) : !1), p = [...s(this, H).entries()];
|
|
595
|
+
let l;
|
|
596
|
+
for (; l = s(this, Z).shift(); )
|
|
597
|
+
if (l(), o()) return;
|
|
598
|
+
for (const [f, m] of p)
|
|
599
|
+
if (m(), s(this, H).delete(f), o()) return;
|
|
600
|
+
for (; l = s(this, X).shift(); )
|
|
601
|
+
if (l(), o()) return;
|
|
602
|
+
e && s(this, he)[r > 16 ? "warn" : "info"](
|
|
603
|
+
`${r > 16 ? "⚠️ (>=16ms) " : ""}Executed ${a} operation${a === 1 ? "" : "s"} in ${s(this, Oe).format(r)}ms${s(this, A) > 0 ? ` (after ${s(this, A)} deferral${s(this, A) === 1 ? "" : "s"})` : ""}.`
|
|
604
|
+
), v(this, A, 0), s(this, Z).length || s(this, H).size || s(this, X).length ? queueMicrotask(() => {
|
|
605
|
+
b(this, _, Ie).call(this);
|
|
606
|
+
}) : v(this, ee, !1);
|
|
415
607
|
};
|
|
416
|
-
function
|
|
417
|
-
return
|
|
608
|
+
function me() {
|
|
609
|
+
return me = Object.assign ? Object.assign.bind() : function(i) {
|
|
418
610
|
for (var e = 1; e < arguments.length; e++) {
|
|
419
611
|
var t = arguments[e];
|
|
420
|
-
for (var r in t)
|
|
421
|
-
Object.prototype.hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
612
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (i[r] = t[r]);
|
|
422
613
|
}
|
|
423
|
-
return
|
|
424
|
-
},
|
|
614
|
+
return i;
|
|
615
|
+
}, me.apply(null, arguments);
|
|
425
616
|
}
|
|
426
|
-
var
|
|
427
|
-
(function(
|
|
428
|
-
|
|
429
|
-
})(
|
|
430
|
-
var
|
|
431
|
-
return Object.freeze(
|
|
432
|
-
} : function(
|
|
433
|
-
return
|
|
617
|
+
var T;
|
|
618
|
+
(function(i) {
|
|
619
|
+
i.Pop = "POP", i.Push = "PUSH", i.Replace = "REPLACE";
|
|
620
|
+
})(T || (T = {}));
|
|
621
|
+
var Be = process.env.NODE_ENV !== "production" ? function(i) {
|
|
622
|
+
return Object.freeze(i);
|
|
623
|
+
} : function(i) {
|
|
624
|
+
return i;
|
|
434
625
|
};
|
|
435
|
-
function
|
|
436
|
-
if (!
|
|
626
|
+
function Ue(i, e) {
|
|
627
|
+
if (!i) {
|
|
437
628
|
typeof console < "u" && console.warn(e);
|
|
438
629
|
try {
|
|
439
630
|
throw new Error(e);
|
|
@@ -441,38 +632,38 @@ function je(n, e) {
|
|
|
441
632
|
}
|
|
442
633
|
}
|
|
443
634
|
}
|
|
444
|
-
var
|
|
445
|
-
function
|
|
446
|
-
|
|
447
|
-
var e =
|
|
448
|
-
function
|
|
449
|
-
var
|
|
450
|
-
return [E.idx,
|
|
451
|
-
pathname:
|
|
452
|
-
search:
|
|
453
|
-
hash:
|
|
635
|
+
var Ge = "beforeunload", ar = "hashchange", Rt = "popstate";
|
|
636
|
+
function sr(i) {
|
|
637
|
+
i === void 0 && (i = {});
|
|
638
|
+
var e = i, t = e.window, r = t === void 0 ? document.defaultView : t, n = r.history;
|
|
639
|
+
function a() {
|
|
640
|
+
var w = r.location, c = w.pathname, d = w.search, $ = w.hash, E = n.state || {};
|
|
641
|
+
return [E.idx, Be({
|
|
642
|
+
pathname: c,
|
|
643
|
+
search: d,
|
|
644
|
+
hash: $,
|
|
454
645
|
state: E.usr || null,
|
|
455
646
|
key: E.key || "default"
|
|
456
647
|
})];
|
|
457
648
|
}
|
|
458
649
|
var o = null;
|
|
459
|
-
function
|
|
650
|
+
function p() {
|
|
460
651
|
if (o)
|
|
461
|
-
|
|
652
|
+
y.call(o), o = null;
|
|
462
653
|
else {
|
|
463
|
-
var
|
|
464
|
-
if (
|
|
465
|
-
if (
|
|
466
|
-
var E =
|
|
654
|
+
var w = T.Pop, c = a(), d = c[0], $ = c[1];
|
|
655
|
+
if (y.length)
|
|
656
|
+
if (d != null) {
|
|
657
|
+
var E = m - d;
|
|
467
658
|
E && (o = {
|
|
468
|
-
action:
|
|
469
|
-
location:
|
|
659
|
+
action: w,
|
|
660
|
+
location: $,
|
|
470
661
|
retry: function() {
|
|
471
|
-
|
|
662
|
+
C(E * -1);
|
|
472
663
|
}
|
|
473
|
-
},
|
|
664
|
+
}, C(E));
|
|
474
665
|
} else
|
|
475
|
-
process.env.NODE_ENV !== "production" &&
|
|
666
|
+
process.env.NODE_ENV !== "production" && Ue(
|
|
476
667
|
!1,
|
|
477
668
|
// TODO: Write up a doc that explains our blocking strategy in
|
|
478
669
|
// detail and link to it here so people can understand better what
|
|
@@ -480,137 +671,137 @@ function Ht(n) {
|
|
|
480
671
|
"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."
|
|
481
672
|
);
|
|
482
673
|
else
|
|
483
|
-
|
|
674
|
+
ie(w);
|
|
484
675
|
}
|
|
485
676
|
}
|
|
486
|
-
r.addEventListener(
|
|
487
|
-
var
|
|
488
|
-
|
|
489
|
-
idx:
|
|
677
|
+
r.addEventListener(Rt, p);
|
|
678
|
+
var l = T.Pop, f = a(), m = f[0], g = f[1], u = Ke(), y = Ke();
|
|
679
|
+
m == null && (m = 0, n.replaceState(me({}, n.state, {
|
|
680
|
+
idx: m
|
|
490
681
|
}), ""));
|
|
491
|
-
function
|
|
492
|
-
return typeof
|
|
682
|
+
function k(w) {
|
|
683
|
+
return typeof w == "string" ? w : He(w);
|
|
493
684
|
}
|
|
494
|
-
function
|
|
495
|
-
return
|
|
496
|
-
pathname:
|
|
685
|
+
function ge(w, c) {
|
|
686
|
+
return c === void 0 && (c = null), Be(me({
|
|
687
|
+
pathname: g.pathname,
|
|
497
688
|
hash: "",
|
|
498
689
|
search: ""
|
|
499
|
-
}, typeof
|
|
500
|
-
state:
|
|
501
|
-
key:
|
|
690
|
+
}, typeof w == "string" ? ct(w) : w, {
|
|
691
|
+
state: c,
|
|
692
|
+
key: Dt()
|
|
502
693
|
}));
|
|
503
694
|
}
|
|
504
|
-
function
|
|
695
|
+
function we(w, c) {
|
|
505
696
|
return [{
|
|
506
|
-
usr:
|
|
507
|
-
key:
|
|
508
|
-
idx:
|
|
509
|
-
},
|
|
510
|
-
}
|
|
511
|
-
function
|
|
512
|
-
return !
|
|
513
|
-
action:
|
|
514
|
-
location:
|
|
515
|
-
retry:
|
|
697
|
+
usr: w.state,
|
|
698
|
+
key: w.key,
|
|
699
|
+
idx: c
|
|
700
|
+
}, k(w)];
|
|
701
|
+
}
|
|
702
|
+
function ye(w, c, d) {
|
|
703
|
+
return !y.length || (y.call({
|
|
704
|
+
action: w,
|
|
705
|
+
location: c,
|
|
706
|
+
retry: d
|
|
516
707
|
}), !1);
|
|
517
708
|
}
|
|
518
|
-
function
|
|
519
|
-
|
|
520
|
-
var
|
|
521
|
-
|
|
522
|
-
action:
|
|
523
|
-
location:
|
|
709
|
+
function ie(w) {
|
|
710
|
+
l = w;
|
|
711
|
+
var c = a();
|
|
712
|
+
m = c[0], g = c[1], u.call({
|
|
713
|
+
action: l,
|
|
714
|
+
location: g
|
|
524
715
|
});
|
|
525
716
|
}
|
|
526
|
-
function
|
|
527
|
-
var
|
|
717
|
+
function oe(w, c) {
|
|
718
|
+
var d = T.Push, $ = ge(w, c);
|
|
528
719
|
function E() {
|
|
529
|
-
|
|
720
|
+
oe(w, c);
|
|
530
721
|
}
|
|
531
|
-
if (
|
|
532
|
-
var
|
|
722
|
+
if (ye(d, $, E)) {
|
|
723
|
+
var x = we($, m + 1), D = x[0], j = x[1];
|
|
533
724
|
try {
|
|
534
|
-
|
|
725
|
+
n.pushState(D, "", j);
|
|
535
726
|
} catch {
|
|
536
|
-
r.location.assign(
|
|
727
|
+
r.location.assign(j);
|
|
537
728
|
}
|
|
538
|
-
|
|
729
|
+
ie(d);
|
|
539
730
|
}
|
|
540
731
|
}
|
|
541
|
-
function
|
|
542
|
-
var
|
|
732
|
+
function ve(w, c) {
|
|
733
|
+
var d = T.Replace, $ = ge(w, c);
|
|
543
734
|
function E() {
|
|
544
|
-
|
|
735
|
+
ve(w, c);
|
|
545
736
|
}
|
|
546
|
-
if (
|
|
547
|
-
var
|
|
548
|
-
|
|
737
|
+
if (ye(d, $, E)) {
|
|
738
|
+
var x = we($, m), D = x[0], j = x[1];
|
|
739
|
+
n.replaceState(D, "", j), ie(d);
|
|
549
740
|
}
|
|
550
741
|
}
|
|
551
|
-
function
|
|
552
|
-
|
|
742
|
+
function C(w) {
|
|
743
|
+
n.go(w);
|
|
553
744
|
}
|
|
554
|
-
var
|
|
745
|
+
var J = {
|
|
555
746
|
get action() {
|
|
556
|
-
return
|
|
747
|
+
return l;
|
|
557
748
|
},
|
|
558
749
|
get location() {
|
|
559
|
-
return
|
|
750
|
+
return g;
|
|
560
751
|
},
|
|
561
|
-
createHref:
|
|
562
|
-
push:
|
|
563
|
-
replace:
|
|
564
|
-
go:
|
|
752
|
+
createHref: k,
|
|
753
|
+
push: oe,
|
|
754
|
+
replace: ve,
|
|
755
|
+
go: C,
|
|
565
756
|
back: function() {
|
|
566
|
-
|
|
757
|
+
C(-1);
|
|
567
758
|
},
|
|
568
759
|
forward: function() {
|
|
569
|
-
|
|
760
|
+
C(1);
|
|
570
761
|
},
|
|
571
|
-
listen: function(
|
|
572
|
-
return
|
|
762
|
+
listen: function(c) {
|
|
763
|
+
return u.push(c);
|
|
573
764
|
},
|
|
574
|
-
block: function(
|
|
575
|
-
var
|
|
576
|
-
return
|
|
577
|
-
|
|
765
|
+
block: function(c) {
|
|
766
|
+
var d = y.push(c);
|
|
767
|
+
return y.length === 1 && r.addEventListener(Ge, ze), function() {
|
|
768
|
+
d(), y.length || r.removeEventListener(Ge, ze);
|
|
578
769
|
};
|
|
579
770
|
}
|
|
580
771
|
};
|
|
581
|
-
return
|
|
772
|
+
return J;
|
|
582
773
|
}
|
|
583
|
-
function
|
|
584
|
-
|
|
585
|
-
var e =
|
|
586
|
-
function
|
|
587
|
-
var
|
|
588
|
-
return [
|
|
589
|
-
pathname:
|
|
590
|
-
search:
|
|
591
|
-
hash:
|
|
592
|
-
state:
|
|
593
|
-
key:
|
|
774
|
+
function ir(i) {
|
|
775
|
+
i === void 0 && (i = {});
|
|
776
|
+
var e = i, t = e.window, r = t === void 0 ? document.defaultView : t, n = r.history;
|
|
777
|
+
function a() {
|
|
778
|
+
var c = ct(r.location.hash.substr(1)), d = c.pathname, $ = d === void 0 ? "/" : d, E = c.search, x = E === void 0 ? "" : E, D = c.hash, j = D === void 0 ? "" : D, q = n.state || {};
|
|
779
|
+
return [q.idx, Be({
|
|
780
|
+
pathname: $,
|
|
781
|
+
search: x,
|
|
782
|
+
hash: j,
|
|
783
|
+
state: q.usr || null,
|
|
784
|
+
key: q.key || "default"
|
|
594
785
|
})];
|
|
595
786
|
}
|
|
596
787
|
var o = null;
|
|
597
|
-
function
|
|
788
|
+
function p() {
|
|
598
789
|
if (o)
|
|
599
|
-
|
|
790
|
+
y.call(o), o = null;
|
|
600
791
|
else {
|
|
601
|
-
var
|
|
602
|
-
if (
|
|
603
|
-
if (
|
|
604
|
-
var
|
|
605
|
-
|
|
606
|
-
action:
|
|
792
|
+
var c = T.Pop, d = a(), $ = d[0], E = d[1];
|
|
793
|
+
if (y.length)
|
|
794
|
+
if ($ != null) {
|
|
795
|
+
var x = m - $;
|
|
796
|
+
x && (o = {
|
|
797
|
+
action: c,
|
|
607
798
|
location: E,
|
|
608
799
|
retry: function() {
|
|
609
|
-
|
|
800
|
+
J(x * -1);
|
|
610
801
|
}
|
|
611
|
-
},
|
|
802
|
+
}, J(x));
|
|
612
803
|
} else
|
|
613
|
-
process.env.NODE_ENV !== "production" &&
|
|
804
|
+
process.env.NODE_ENV !== "production" && Ue(
|
|
614
805
|
!1,
|
|
615
806
|
// TODO: Write up a doc that explains our blocking strategy in
|
|
616
807
|
// detail and link to it here so people can understand better
|
|
@@ -618,179 +809,179 @@ function _t(n) {
|
|
|
618
809
|
"You are trying to block a POP navigation to a location that was not created by the history library. The block will fail silently in production, but in general you should do all navigation with the history library (instead of using window.history.pushState directly) to avoid this situation."
|
|
619
810
|
);
|
|
620
811
|
else
|
|
621
|
-
|
|
812
|
+
oe(c);
|
|
622
813
|
}
|
|
623
814
|
}
|
|
624
|
-
r.addEventListener(
|
|
625
|
-
var
|
|
626
|
-
|
|
815
|
+
r.addEventListener(Rt, p), r.addEventListener(ar, function() {
|
|
816
|
+
var c = a(), d = c[1];
|
|
817
|
+
He(d) !== He(g) && p();
|
|
627
818
|
});
|
|
628
|
-
var
|
|
629
|
-
|
|
630
|
-
idx:
|
|
819
|
+
var l = T.Pop, f = a(), m = f[0], g = f[1], u = Ke(), y = Ke();
|
|
820
|
+
m == null && (m = 0, n.replaceState(me({}, n.state, {
|
|
821
|
+
idx: m
|
|
631
822
|
}), ""));
|
|
632
|
-
function
|
|
633
|
-
var
|
|
634
|
-
if (
|
|
635
|
-
var
|
|
636
|
-
|
|
823
|
+
function k() {
|
|
824
|
+
var c = document.querySelector("base"), d = "";
|
|
825
|
+
if (c && c.getAttribute("href")) {
|
|
826
|
+
var $ = r.location.href, E = $.indexOf("#");
|
|
827
|
+
d = E === -1 ? $ : $.slice(0, E);
|
|
637
828
|
}
|
|
638
|
-
return
|
|
829
|
+
return d;
|
|
639
830
|
}
|
|
640
|
-
function
|
|
641
|
-
return
|
|
831
|
+
function ge(c) {
|
|
832
|
+
return k() + "#" + (typeof c == "string" ? c : He(c));
|
|
642
833
|
}
|
|
643
|
-
function
|
|
644
|
-
return
|
|
645
|
-
pathname:
|
|
834
|
+
function we(c, d) {
|
|
835
|
+
return d === void 0 && (d = null), Be(me({
|
|
836
|
+
pathname: g.pathname,
|
|
646
837
|
hash: "",
|
|
647
838
|
search: ""
|
|
648
|
-
}, typeof
|
|
649
|
-
state:
|
|
650
|
-
key:
|
|
839
|
+
}, typeof c == "string" ? ct(c) : c, {
|
|
840
|
+
state: d,
|
|
841
|
+
key: Dt()
|
|
651
842
|
}));
|
|
652
843
|
}
|
|
653
|
-
function
|
|
844
|
+
function ye(c, d) {
|
|
654
845
|
return [{
|
|
655
|
-
usr:
|
|
656
|
-
key:
|
|
657
|
-
idx:
|
|
658
|
-
},
|
|
846
|
+
usr: c.state,
|
|
847
|
+
key: c.key,
|
|
848
|
+
idx: d
|
|
849
|
+
}, ge(c)];
|
|
659
850
|
}
|
|
660
|
-
function
|
|
661
|
-
return !
|
|
662
|
-
action:
|
|
663
|
-
location:
|
|
664
|
-
retry:
|
|
851
|
+
function ie(c, d, $) {
|
|
852
|
+
return !y.length || (y.call({
|
|
853
|
+
action: c,
|
|
854
|
+
location: d,
|
|
855
|
+
retry: $
|
|
665
856
|
}), !1);
|
|
666
857
|
}
|
|
667
|
-
function
|
|
668
|
-
|
|
669
|
-
var
|
|
670
|
-
|
|
671
|
-
action:
|
|
672
|
-
location:
|
|
858
|
+
function oe(c) {
|
|
859
|
+
l = c;
|
|
860
|
+
var d = a();
|
|
861
|
+
m = d[0], g = d[1], u.call({
|
|
862
|
+
action: l,
|
|
863
|
+
location: g
|
|
673
864
|
});
|
|
674
865
|
}
|
|
675
|
-
function
|
|
676
|
-
var
|
|
677
|
-
function
|
|
678
|
-
|
|
866
|
+
function ve(c, d) {
|
|
867
|
+
var $ = T.Push, E = we(c, d);
|
|
868
|
+
function x() {
|
|
869
|
+
ve(c, d);
|
|
679
870
|
}
|
|
680
|
-
if (process.env.NODE_ENV !== "production" &&
|
|
681
|
-
var
|
|
871
|
+
if (process.env.NODE_ENV !== "production" && Ue(E.pathname.charAt(0) === "/", "Relative pathnames are not supported in hash history.push(" + JSON.stringify(c) + ")"), ie($, E, x)) {
|
|
872
|
+
var D = ye(E, m + 1), j = D[0], q = D[1];
|
|
682
873
|
try {
|
|
683
|
-
|
|
874
|
+
n.pushState(j, "", q);
|
|
684
875
|
} catch {
|
|
685
|
-
r.location.assign(
|
|
876
|
+
r.location.assign(q);
|
|
686
877
|
}
|
|
687
|
-
|
|
878
|
+
oe($);
|
|
688
879
|
}
|
|
689
880
|
}
|
|
690
|
-
function
|
|
691
|
-
var
|
|
692
|
-
function
|
|
693
|
-
|
|
881
|
+
function C(c, d) {
|
|
882
|
+
var $ = T.Replace, E = we(c, d);
|
|
883
|
+
function x() {
|
|
884
|
+
C(c, d);
|
|
694
885
|
}
|
|
695
|
-
if (process.env.NODE_ENV !== "production" &&
|
|
696
|
-
var
|
|
697
|
-
|
|
886
|
+
if (process.env.NODE_ENV !== "production" && Ue(E.pathname.charAt(0) === "/", "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(c) + ")"), ie($, E, x)) {
|
|
887
|
+
var D = ye(E, m), j = D[0], q = D[1];
|
|
888
|
+
n.replaceState(j, "", q), oe($);
|
|
698
889
|
}
|
|
699
890
|
}
|
|
700
|
-
function
|
|
701
|
-
|
|
891
|
+
function J(c) {
|
|
892
|
+
n.go(c);
|
|
702
893
|
}
|
|
703
|
-
var
|
|
894
|
+
var w = {
|
|
704
895
|
get action() {
|
|
705
|
-
return
|
|
896
|
+
return l;
|
|
706
897
|
},
|
|
707
898
|
get location() {
|
|
708
|
-
return
|
|
899
|
+
return g;
|
|
709
900
|
},
|
|
710
|
-
createHref:
|
|
711
|
-
push:
|
|
712
|
-
replace:
|
|
713
|
-
go:
|
|
901
|
+
createHref: ge,
|
|
902
|
+
push: ve,
|
|
903
|
+
replace: C,
|
|
904
|
+
go: J,
|
|
714
905
|
back: function() {
|
|
715
|
-
|
|
906
|
+
J(-1);
|
|
716
907
|
},
|
|
717
908
|
forward: function() {
|
|
718
|
-
|
|
909
|
+
J(1);
|
|
719
910
|
},
|
|
720
|
-
listen: function(
|
|
721
|
-
return
|
|
911
|
+
listen: function(d) {
|
|
912
|
+
return u.push(d);
|
|
722
913
|
},
|
|
723
|
-
block: function(
|
|
724
|
-
var
|
|
725
|
-
return
|
|
726
|
-
|
|
914
|
+
block: function(d) {
|
|
915
|
+
var $ = y.push(d);
|
|
916
|
+
return y.length === 1 && r.addEventListener(Ge, ze), function() {
|
|
917
|
+
$(), y.length || r.removeEventListener(Ge, ze);
|
|
727
918
|
};
|
|
728
919
|
}
|
|
729
920
|
};
|
|
730
|
-
return
|
|
921
|
+
return w;
|
|
731
922
|
}
|
|
732
|
-
function
|
|
733
|
-
|
|
923
|
+
function ze(i) {
|
|
924
|
+
i.preventDefault(), i.returnValue = "";
|
|
734
925
|
}
|
|
735
|
-
function
|
|
736
|
-
var
|
|
926
|
+
function Ke() {
|
|
927
|
+
var i = [];
|
|
737
928
|
return {
|
|
738
929
|
get length() {
|
|
739
|
-
return
|
|
930
|
+
return i.length;
|
|
740
931
|
},
|
|
741
932
|
push: function(t) {
|
|
742
|
-
return
|
|
743
|
-
|
|
933
|
+
return i.push(t), function() {
|
|
934
|
+
i = i.filter(function(r) {
|
|
744
935
|
return r !== t;
|
|
745
936
|
});
|
|
746
937
|
};
|
|
747
938
|
},
|
|
748
939
|
call: function(t) {
|
|
749
|
-
|
|
940
|
+
i.forEach(function(r) {
|
|
750
941
|
return r && r(t);
|
|
751
942
|
});
|
|
752
943
|
}
|
|
753
944
|
};
|
|
754
945
|
}
|
|
755
|
-
function
|
|
946
|
+
function Dt() {
|
|
756
947
|
return Math.random().toString(36).substr(2, 8);
|
|
757
948
|
}
|
|
758
|
-
function
|
|
759
|
-
var e =
|
|
760
|
-
return
|
|
949
|
+
function He(i) {
|
|
950
|
+
var e = i.pathname, t = e === void 0 ? "/" : e, r = i.search, n = r === void 0 ? "" : r, a = i.hash, o = a === void 0 ? "" : a;
|
|
951
|
+
return n && n !== "?" && (t += n.charAt(0) === "?" ? n : "?" + n), o && o !== "#" && (t += o.charAt(0) === "#" ? o : "#" + o), t;
|
|
761
952
|
}
|
|
762
|
-
function
|
|
953
|
+
function ct(i) {
|
|
763
954
|
var e = {};
|
|
764
|
-
if (
|
|
765
|
-
var t =
|
|
766
|
-
t >= 0 && (e.hash =
|
|
767
|
-
var r =
|
|
768
|
-
r >= 0 && (e.search =
|
|
955
|
+
if (i) {
|
|
956
|
+
var t = i.indexOf("#");
|
|
957
|
+
t >= 0 && (e.hash = i.substr(t), i = i.substr(0, t));
|
|
958
|
+
var r = i.indexOf("?");
|
|
959
|
+
r >= 0 && (e.search = i.substr(r), i = i.substr(0, r)), i && (e.pathname = i);
|
|
769
960
|
}
|
|
770
961
|
return e;
|
|
771
962
|
}
|
|
772
|
-
function
|
|
773
|
-
return
|
|
963
|
+
function $e(i) {
|
|
964
|
+
return St(i, "Expected `path` to be a string. Got type: %t, value: %v"), i.split("/").map((e) => e.trim()).filter((e) => e !== "");
|
|
774
965
|
}
|
|
775
|
-
function
|
|
966
|
+
function le(i) {
|
|
776
967
|
var t;
|
|
777
|
-
|
|
778
|
-
(r) =>
|
|
779
|
-
|
|
968
|
+
qt(
|
|
969
|
+
(r) => dt(r == null ? void 0 : r.toString),
|
|
970
|
+
i,
|
|
780
971
|
"Expected `parts` to be an array of objects with a .toString() method. Got type: %t, value: %v"
|
|
781
|
-
),
|
|
782
|
-
let e = (t =
|
|
972
|
+
), i = i.filter((r) => r).flatMap(String);
|
|
973
|
+
let e = (t = i.shift()) == null ? void 0 : t.toString();
|
|
783
974
|
if (e) {
|
|
784
|
-
for (const r of
|
|
785
|
-
r.startsWith(".") ? e =
|
|
975
|
+
for (const r of i.map((n) => n.toString()))
|
|
976
|
+
r.startsWith(".") ? e = We(e, r) : e[e.length - 1] !== "/" ? r[0] !== "/" ? e += "/" + r : e += r : r[0] === "/" ? e += r.slice(1) : e += r;
|
|
786
977
|
e && e !== "/" && e.endsWith("/") && (e = e.slice(0, e.length - 1));
|
|
787
978
|
}
|
|
788
979
|
return e ?? "";
|
|
789
980
|
}
|
|
790
|
-
function
|
|
791
|
-
if (
|
|
981
|
+
function We(i, e) {
|
|
982
|
+
if (St(i, "Expected `base` to be a string. Got type: %t, value: %v"), e == null && (e = i, i = ""), e.startsWith("/"))
|
|
792
983
|
return e;
|
|
793
|
-
let t =
|
|
984
|
+
let t = i;
|
|
794
985
|
for (; ; )
|
|
795
986
|
if (e.startsWith("..")) {
|
|
796
987
|
for (let r = t.length; r > 0; --r)
|
|
@@ -802,179 +993,196 @@ function qe(n, e) {
|
|
|
802
993
|
e = e.replace(/^\.\/?/, "");
|
|
803
994
|
else
|
|
804
995
|
break;
|
|
805
|
-
return
|
|
996
|
+
return le([t, e]);
|
|
806
997
|
}
|
|
807
|
-
function
|
|
808
|
-
if (!
|
|
809
|
-
|
|
810
|
-
const e =
|
|
811
|
-
const [r,
|
|
812
|
-
return
|
|
998
|
+
function ut(i) {
|
|
999
|
+
if (!i) return {};
|
|
1000
|
+
i.startsWith("?") && (i = i.slice(1));
|
|
1001
|
+
const e = i.split("&").filter((t) => t.trim() !== "").map((t) => {
|
|
1002
|
+
const [r, n] = t.split("=").map((a) => a.trim());
|
|
1003
|
+
return n.toLowerCase() === "true" ? [r, !0] : n.toLowerCase() === "false" ? [r, !1] : isNaN(Number(n)) ? [r, n] : [r, Number(n)];
|
|
813
1004
|
});
|
|
814
1005
|
return Object.fromEntries(e);
|
|
815
1006
|
}
|
|
816
|
-
function
|
|
1007
|
+
function $t(i, e, t = {}) {
|
|
817
1008
|
var o;
|
|
818
|
-
const [r,
|
|
819
|
-
e: for (const
|
|
820
|
-
const { fragments:
|
|
821
|
-
if (!(((o =
|
|
1009
|
+
const [r, n] = e.split("?"), a = $e(r);
|
|
1010
|
+
e: for (const p of i) {
|
|
1011
|
+
const { fragments: l } = p;
|
|
1012
|
+
if (!(((o = l[l.length - 1]) == null ? void 0 : o.type) === 3) && l.length !== a.length || t.willMatch && !t.willMatch(p))
|
|
822
1013
|
continue e;
|
|
823
|
-
const
|
|
824
|
-
t: for (let
|
|
825
|
-
const
|
|
826
|
-
if (
|
|
1014
|
+
const m = [];
|
|
1015
|
+
t: for (let u = 0; u < l.length; u++) {
|
|
1016
|
+
const y = a[u], k = l[u];
|
|
1017
|
+
if (y == null && k.type !== 3)
|
|
827
1018
|
continue e;
|
|
828
|
-
switch (
|
|
1019
|
+
switch (k.type) {
|
|
829
1020
|
case 1:
|
|
830
|
-
if (
|
|
831
|
-
|
|
1021
|
+
if (k.name.toLowerCase() === y.toLowerCase()) {
|
|
1022
|
+
m.push(k);
|
|
832
1023
|
break;
|
|
833
1024
|
} else
|
|
834
1025
|
continue e;
|
|
835
1026
|
case 2:
|
|
836
|
-
|
|
1027
|
+
m.push({ ...k, value: y });
|
|
837
1028
|
break;
|
|
838
1029
|
case 3:
|
|
839
|
-
|
|
1030
|
+
m.push({ ...k, value: a.slice(u).join("/") });
|
|
840
1031
|
break t;
|
|
841
1032
|
case 4:
|
|
842
|
-
if (isNaN(Number(
|
|
1033
|
+
if (isNaN(Number(y)))
|
|
843
1034
|
continue e;
|
|
844
|
-
|
|
1035
|
+
m.push({ ...k, value: Number(y) });
|
|
845
1036
|
break;
|
|
846
1037
|
default:
|
|
847
|
-
throw new Error(`Unknown fragment type: ${
|
|
1038
|
+
throw new Error(`Unknown fragment type: ${k.type}`);
|
|
848
1039
|
}
|
|
849
1040
|
}
|
|
850
|
-
const
|
|
851
|
-
for (const
|
|
852
|
-
|
|
1041
|
+
const g = {};
|
|
1042
|
+
for (const u of m)
|
|
1043
|
+
u.type === 2 && (g[u.name] = decodeURIComponent(u.value)), u.type === 4 && (g[u.name] = u.value), u.type === 3 && (g.wildcard = "/" + decodeURIComponent(u.value));
|
|
853
1044
|
return {
|
|
854
|
-
path: "/" +
|
|
855
|
-
pattern: "/" +
|
|
856
|
-
params:
|
|
857
|
-
query:
|
|
858
|
-
meta:
|
|
1045
|
+
path: "/" + m.map((u) => u.value).join("/"),
|
|
1046
|
+
pattern: "/" + l.map((u) => u.type === 2 ? `{${u.name}}` : u.type === 4 ? `{#${u.name}}` : u.name).join("/"),
|
|
1047
|
+
params: g,
|
|
1048
|
+
query: ut(n),
|
|
1049
|
+
meta: p.meta
|
|
859
1050
|
};
|
|
860
1051
|
}
|
|
861
1052
|
}
|
|
862
|
-
function
|
|
863
|
-
const e = [], t = [], r = [],
|
|
864
|
-
for (const o of
|
|
865
|
-
const { fragments:
|
|
866
|
-
|
|
867
|
-
(
|
|
1053
|
+
function or(i) {
|
|
1054
|
+
const e = [], t = [], r = [], n = [];
|
|
1055
|
+
for (const o of i) {
|
|
1056
|
+
const { fragments: p } = o;
|
|
1057
|
+
p.some(
|
|
1058
|
+
(l) => l.type === 3
|
|
868
1059
|
/* Wildcard */
|
|
869
|
-
) ?
|
|
870
|
-
(
|
|
1060
|
+
) ? n.push(o) : p.some(
|
|
1061
|
+
(l) => l.type === 4
|
|
871
1062
|
/* NumericParam */
|
|
872
|
-
) ? t.push(o) :
|
|
873
|
-
(
|
|
1063
|
+
) ? t.push(o) : p.some(
|
|
1064
|
+
(l) => l.type === 2
|
|
874
1065
|
/* Param */
|
|
875
1066
|
) ? r.push(o) : e.push(o);
|
|
876
1067
|
}
|
|
877
|
-
const
|
|
878
|
-
return e.sort(
|
|
1068
|
+
const a = (o, p) => o.fragments.length > p.fragments.length ? -1 : 1;
|
|
1069
|
+
return e.sort(a), t.sort(a), r.sort(a), n.sort(a), [...e, ...t, ...r, ...n];
|
|
879
1070
|
}
|
|
880
|
-
function
|
|
881
|
-
const e =
|
|
1071
|
+
function lr(i) {
|
|
1072
|
+
const e = $e(i), t = [];
|
|
882
1073
|
for (let r = 0; r < e.length; r++) {
|
|
883
|
-
const
|
|
884
|
-
if (
|
|
1074
|
+
const n = e[r];
|
|
1075
|
+
if (n === "*") {
|
|
885
1076
|
if (r !== e.length - 1)
|
|
886
|
-
throw new Error(`Wildcard must be at the end of a pattern. Received: ${
|
|
1077
|
+
throw new Error(`Wildcard must be at the end of a pattern. Received: ${i}`);
|
|
887
1078
|
t.push({
|
|
888
1079
|
type: 3,
|
|
889
1080
|
name: "*",
|
|
890
1081
|
value: null
|
|
891
1082
|
});
|
|
892
|
-
} else
|
|
893
|
-
type:
|
|
894
|
-
name:
|
|
1083
|
+
} else n.at(0) === "{" && n.at(-1) === "}" ? t.push({
|
|
1084
|
+
type: n[1] === "#" ? 4 : 2,
|
|
1085
|
+
name: n[1] === "#" ? n.slice(2, -1) : n.slice(1, -1),
|
|
895
1086
|
value: null
|
|
896
1087
|
}) : t.push({
|
|
897
1088
|
type: 1,
|
|
898
|
-
name:
|
|
899
|
-
value:
|
|
1089
|
+
name: n,
|
|
1090
|
+
value: n
|
|
900
1091
|
});
|
|
901
1092
|
}
|
|
902
1093
|
return t;
|
|
903
1094
|
}
|
|
904
|
-
|
|
905
|
-
|
|
1095
|
+
const Et = (i, e) => {
|
|
1096
|
+
if (Object.keys(i).length !== Object.keys(e).length)
|
|
1097
|
+
return !1;
|
|
1098
|
+
for (const t in i)
|
|
1099
|
+
if (i[t] !== e[t])
|
|
1100
|
+
return !1;
|
|
1101
|
+
return !0;
|
|
1102
|
+
};
|
|
1103
|
+
var Le, N, te, Re, S, Xe, W, De, re, ne, fe, de, pe, Ne, Q, ht, ft;
|
|
1104
|
+
class cr {
|
|
906
1105
|
constructor(e, t) {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
1106
|
+
h(this, Q);
|
|
1107
|
+
h(this, Le);
|
|
1108
|
+
h(this, N);
|
|
1109
|
+
h(this, te);
|
|
1110
|
+
h(this, Re, nt());
|
|
1111
|
+
h(this, S);
|
|
1112
|
+
h(this, Xe, 0);
|
|
1113
|
+
h(this, W, []);
|
|
1114
|
+
h(this, De);
|
|
1115
|
+
h(this, re, []);
|
|
916
1116
|
// Callbacks that need to be called on unmount.
|
|
917
|
-
|
|
1117
|
+
h(this, ne, []);
|
|
918
1118
|
/**
|
|
919
1119
|
* The currently matched route pattern, if any.
|
|
920
1120
|
*/
|
|
921
|
-
|
|
922
|
-
|
|
1121
|
+
P(this, "$pattern");
|
|
1122
|
+
h(this, fe);
|
|
923
1123
|
/**
|
|
924
1124
|
* The current URL path.
|
|
925
1125
|
*/
|
|
926
|
-
|
|
927
|
-
|
|
1126
|
+
P(this, "$path");
|
|
1127
|
+
h(this, de);
|
|
928
1128
|
/**
|
|
929
1129
|
* The current named path params.
|
|
930
1130
|
*/
|
|
931
|
-
|
|
932
|
-
|
|
1131
|
+
P(this, "$params");
|
|
1132
|
+
h(this, pe);
|
|
933
1133
|
/**
|
|
934
1134
|
* The current query params. Changes to this object will be reflected in the URL.
|
|
935
1135
|
*/
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
const [r,
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
1136
|
+
P(this, "$query");
|
|
1137
|
+
h(this, Ne);
|
|
1138
|
+
v(this, Le, e), v(this, N, e.createLogger("dolla/router")), v(this, te, t);
|
|
1139
|
+
const [r, n] = ce(null), [a, o] = ce(""), [p, l] = ce({}, { equals: Et }), [f, m] = ce(
|
|
1140
|
+
ut(typeof window > "u" ? "" : window.location.search ?? ""),
|
|
1141
|
+
{ equals: Et }
|
|
1142
|
+
);
|
|
1143
|
+
this.$pattern = r, v(this, fe, n), this.$path = a, v(this, de, o), this.$params = p, v(this, pe, l), this.$query = f, v(this, Ne, m), e.beforeMount(() => {
|
|
1144
|
+
s(this, S) != null && (s(this, Re).watch([f], (g) => {
|
|
1145
|
+
const u = new URLSearchParams();
|
|
1146
|
+
for (const k in g)
|
|
1147
|
+
u.set(k, String(g[k]));
|
|
1148
|
+
const y = "?" + u.toString();
|
|
1149
|
+
y != s(this, S).location.search && s(this, S).replace({
|
|
1150
|
+
pathname: s(this, S).location.pathname,
|
|
1151
|
+
search: y
|
|
1152
|
+
});
|
|
1153
|
+
}), s(this, ne).push(s(this, S).listen(b(this, Q, ft).bind(this))), b(this, Q, ft).call(this, s(this, S)), s(this, ne).push(
|
|
1154
|
+
fr(s(this, te).rootElement, (g) => {
|
|
1155
|
+
let u = g.getAttribute("href");
|
|
1156
|
+
s(this, N).info("Intercepted link click", g, u), /^https?:\/\/|^\//.test(u) || (u = le([s(this, S).location.pathname, u])), s(this, S).push(u);
|
|
956
1157
|
})
|
|
957
|
-
),
|
|
1158
|
+
), s(this, N).info("Intercepting <a> clicks within root element:", s(this, te).rootElement));
|
|
958
1159
|
}), e.onUnmount(() => {
|
|
959
|
-
for (;
|
|
960
|
-
|
|
1160
|
+
for (; s(this, ne).length > 0; )
|
|
1161
|
+
s(this, ne).pop()();
|
|
1162
|
+
s(this, Re).stopAll();
|
|
961
1163
|
});
|
|
962
1164
|
}
|
|
963
1165
|
setup(e) {
|
|
964
|
-
|
|
965
|
-
|
|
1166
|
+
if (s(this, Le).isMounted) {
|
|
1167
|
+
s(this, N).crash(
|
|
1168
|
+
new Error("Dolla is already mounted. Router setup must be called before Dolla.mount is called.")
|
|
1169
|
+
);
|
|
1170
|
+
return;
|
|
1171
|
+
}
|
|
1172
|
+
e.style === "hash" ? v(this, S, ir()) : v(this, S, sr()), v(this, re, or(
|
|
1173
|
+
e.routes.flatMap((t) => b(this, Q, ht).call(this, t)).map((t) => ({
|
|
966
1174
|
pattern: t.pattern,
|
|
967
1175
|
meta: t.meta,
|
|
968
|
-
fragments:
|
|
1176
|
+
fragments: lr(t.pattern)
|
|
969
1177
|
}))
|
|
970
1178
|
));
|
|
971
|
-
for (const t of
|
|
1179
|
+
for (const t of s(this, re))
|
|
972
1180
|
if (t.meta.redirect) {
|
|
973
1181
|
let r;
|
|
974
|
-
if (!
|
|
975
|
-
if (r = t.meta.redirect,
|
|
976
|
-
willMatch(
|
|
977
|
-
return
|
|
1182
|
+
if (!dt(t.meta.redirect)) if (V(t.meta.redirect)) {
|
|
1183
|
+
if (r = t.meta.redirect, !$t(s(this, re), r, {
|
|
1184
|
+
willMatch(a) {
|
|
1185
|
+
return a !== t;
|
|
978
1186
|
}
|
|
979
1187
|
}))
|
|
980
1188
|
throw new Error(
|
|
@@ -988,33 +1196,57 @@ class Ft {
|
|
|
988
1196
|
* Navigates to another route.
|
|
989
1197
|
*
|
|
990
1198
|
* @example
|
|
991
|
-
*
|
|
992
|
-
*
|
|
1199
|
+
* Dolla.router.go("/login"); // navigate to `/login`
|
|
1200
|
+
* Dolla.router.go["/users", 215], { replace: true }); // replace current history entry with `/users/215`
|
|
993
1201
|
*/
|
|
994
1202
|
go(e, t = {}) {
|
|
1203
|
+
if (s(this, S) == null) {
|
|
1204
|
+
s(this, N).crash(
|
|
1205
|
+
new Error(
|
|
1206
|
+
"Router.go was called, but the router was never configured! Run 'Dolla.router.setup' before 'Dolla.mount' to configure routes."
|
|
1207
|
+
)
|
|
1208
|
+
);
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
995
1211
|
let r;
|
|
996
|
-
Array.isArray(e) ? r =
|
|
1212
|
+
Array.isArray(e) ? r = le(e) : r = e.toString(), r = We(s(this, S).location.pathname, r), t.preserveQuery && (r += s(this, S).location.search), t.replace ? s(this, S).replace(r) : s(this, S).push(r);
|
|
997
1213
|
}
|
|
998
1214
|
/**
|
|
999
1215
|
* Navigate backward. Pass a number of steps to hit the back button that many times.
|
|
1000
1216
|
*/
|
|
1001
1217
|
back(e = 1) {
|
|
1002
|
-
|
|
1218
|
+
if (s(this, S) == null) {
|
|
1219
|
+
s(this, N).crash(
|
|
1220
|
+
new Error(
|
|
1221
|
+
"Router.back was called, but the router was never configured! Run 'Dolla.router.setup' before 'Dolla.mount' to configure routes."
|
|
1222
|
+
)
|
|
1223
|
+
);
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
s(this, S).go(-e);
|
|
1003
1227
|
}
|
|
1004
1228
|
/**
|
|
1005
1229
|
* Navigate forward. Pass a number of steps to hit the forward button that many times.
|
|
1006
1230
|
*/
|
|
1007
1231
|
forward(e = 1) {
|
|
1008
|
-
|
|
1232
|
+
if (s(this, S) == null) {
|
|
1233
|
+
s(this, N).crash(
|
|
1234
|
+
new Error(
|
|
1235
|
+
"Router.forward was called, but the router was never configured! Run 'Dolla.router.setup' before 'Dolla.mount' to configure routes."
|
|
1236
|
+
)
|
|
1237
|
+
);
|
|
1238
|
+
return;
|
|
1239
|
+
}
|
|
1240
|
+
s(this, S).go(e);
|
|
1009
1241
|
}
|
|
1010
1242
|
}
|
|
1011
|
-
|
|
1243
|
+
Le = new WeakMap(), N = new WeakMap(), te = new WeakMap(), Re = new WeakMap(), S = new WeakMap(), Xe = new WeakMap(), W = new WeakMap(), De = new WeakMap(), re = new WeakMap(), ne = new WeakMap(), fe = new WeakMap(), de = new WeakMap(), pe = new WeakMap(), Ne = new WeakMap(), Q = new WeakSet(), /**
|
|
1012
1244
|
* Parses a route definition object into a set of matchable routes.
|
|
1013
1245
|
*
|
|
1014
1246
|
* @param route - Route config object.
|
|
1015
1247
|
* @param layers - Array of parent layers. Passed when this function calls itself on nested routes.
|
|
1016
1248
|
*/
|
|
1017
|
-
|
|
1249
|
+
ht = function(e, t = [], r = []) {
|
|
1018
1250
|
if (!(typeof e == "object" && !Array.isArray(e)) || typeof e.path != "string")
|
|
1019
1251
|
throw new TypeError(`Route configs must be objects with a 'path' string property. Got: ${e}`);
|
|
1020
1252
|
if (e.redirect && e.routes)
|
|
@@ -1023,56 +1255,57 @@ Je = function(e, t = [], r = []) {
|
|
|
1023
1255
|
throw new Error("Route cannot have both a 'redirect' and a 'view'.");
|
|
1024
1256
|
if (!e.view && !e.routes && !e.redirect)
|
|
1025
1257
|
throw new Error("Route must have a 'view', a 'redirect', or a set of nested 'routes'.");
|
|
1026
|
-
let
|
|
1027
|
-
for (const
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
const
|
|
1258
|
+
let n = [];
|
|
1259
|
+
for (const l of t)
|
|
1260
|
+
n.push(...$e(l.path));
|
|
1261
|
+
n.push(...$e(e.path)), n[n.length - 1] === "*" && n.pop();
|
|
1262
|
+
const a = [];
|
|
1031
1263
|
if (e.redirect) {
|
|
1032
|
-
let
|
|
1033
|
-
return
|
|
1034
|
-
pattern: "/" +
|
|
1264
|
+
let l = e.redirect;
|
|
1265
|
+
return V(l) && (l = We(le(n), l), l.startsWith("/") || (l = "/" + l)), a.push({
|
|
1266
|
+
pattern: "/" + le([...n, ...$e(e.path)]),
|
|
1035
1267
|
meta: {
|
|
1036
|
-
redirect:
|
|
1268
|
+
redirect: l
|
|
1037
1269
|
}
|
|
1038
|
-
}),
|
|
1270
|
+
}), a;
|
|
1039
1271
|
}
|
|
1040
|
-
let o =
|
|
1272
|
+
let o = Pt;
|
|
1041
1273
|
if (typeof e.view == "function")
|
|
1042
1274
|
o = e.view;
|
|
1043
1275
|
else if (e.view)
|
|
1044
1276
|
throw new TypeError(`Route '${e.path}' expected a view function or undefined. Got: ${e.view}`);
|
|
1045
|
-
const
|
|
1277
|
+
const p = { id: et(this, Xe)._++, view: o };
|
|
1046
1278
|
if (e.routes)
|
|
1047
|
-
for (const
|
|
1048
|
-
|
|
1279
|
+
for (const l of e.routes)
|
|
1280
|
+
a.push(...b(this, Q, ht).call(this, l, [...t, e], [...r, p]));
|
|
1049
1281
|
else
|
|
1050
|
-
|
|
1051
|
-
pattern: parent ?
|
|
1282
|
+
a.push({
|
|
1283
|
+
pattern: parent ? le([...t.map((l) => l.path), e.path]) : e.path,
|
|
1052
1284
|
meta: {
|
|
1053
1285
|
pattern: e.path,
|
|
1054
|
-
layers: [...r,
|
|
1286
|
+
layers: [...r, p],
|
|
1055
1287
|
beforeMatch: e.beforeMatch
|
|
1056
1288
|
}
|
|
1057
1289
|
});
|
|
1058
|
-
return
|
|
1059
|
-
},
|
|
1060
|
-
e.search !==
|
|
1061
|
-
const t =
|
|
1290
|
+
return a;
|
|
1291
|
+
}, ft = async function({ location: e }) {
|
|
1292
|
+
e.search !== s(this, De) && (v(this, De, e.search), s(this, Ne).call(this, ut(e.search)));
|
|
1293
|
+
const t = $t(s(this, re), e.pathname);
|
|
1062
1294
|
if (!t) {
|
|
1063
|
-
|
|
1295
|
+
s(this, fe).call(this, null), s(this, de).call(this, e.pathname), s(this, pe).call(this, {
|
|
1064
1296
|
wildcard: e.pathname
|
|
1065
1297
|
});
|
|
1066
1298
|
return;
|
|
1067
1299
|
}
|
|
1068
1300
|
if (t.meta.beforeMatch && await t.meta.beforeMatch({
|
|
1301
|
+
// TODO: Allow setting context variables from here.
|
|
1069
1302
|
redirect: (r) => {
|
|
1070
1303
|
throw new Error("Redirect not yet implemented.");
|
|
1071
1304
|
}
|
|
1072
|
-
}),
|
|
1305
|
+
}), t.meta.redirect != null)
|
|
1073
1306
|
if (typeof t.meta.redirect == "string") {
|
|
1074
|
-
const r =
|
|
1075
|
-
|
|
1307
|
+
const r = dr(t.meta.redirect, t.params);
|
|
1308
|
+
s(this, N).info(`↩️ redirecting from '${t.path}' to '${r}'`), s(this, S).replace(r);
|
|
1076
1309
|
} else if (typeof t.meta.redirect == "function") {
|
|
1077
1310
|
const r = {
|
|
1078
1311
|
path: t.path,
|
|
@@ -1080,86 +1313,94 @@ Je = function(e, t = [], r = []) {
|
|
|
1080
1313
|
params: t.params,
|
|
1081
1314
|
query: t.query
|
|
1082
1315
|
};
|
|
1083
|
-
let
|
|
1084
|
-
if (typeof
|
|
1316
|
+
let n = await t.meta.redirect(r);
|
|
1317
|
+
if (typeof n != "string")
|
|
1085
1318
|
throw new Error("Redirect function must return a path to redirect to.");
|
|
1086
|
-
|
|
1319
|
+
n.startsWith("/") || (n = We(t.path, n)), s(this, N).info(`Redirecting to: '${n}'`), s(this, S).replace(n);
|
|
1087
1320
|
} else
|
|
1088
1321
|
throw new TypeError("Redirect must either be a path string or a function.");
|
|
1089
|
-
else if (
|
|
1090
|
-
|
|
1322
|
+
else if (s(this, N).info(`📍 navigating to '${t.path}'`), s(this, de).call(this, t.path), s(this, pe).call(this, t.params), t.pattern !== this.$pattern.get()) {
|
|
1323
|
+
s(this, fe).call(this, t.pattern);
|
|
1091
1324
|
const r = t.meta.layers;
|
|
1092
|
-
for (let
|
|
1093
|
-
const
|
|
1094
|
-
if ((o == null ? void 0 : o.id) !==
|
|
1095
|
-
|
|
1096
|
-
const
|
|
1097
|
-
o && o.node.isMounted && o.node.unmount()
|
|
1325
|
+
for (let n = 0; n < r.length; n++) {
|
|
1326
|
+
const a = r[n], o = s(this, W)[n];
|
|
1327
|
+
if ((o == null ? void 0 : o.id) !== a.id) {
|
|
1328
|
+
v(this, W, s(this, W).slice(0, n));
|
|
1329
|
+
const p = s(this, W).at(-1);
|
|
1330
|
+
o && o.node.isMounted && o.node.unmount(!1);
|
|
1331
|
+
let l;
|
|
1332
|
+
p ? l = p.node.setChildView(a.view) : l = s(this, te).rootView.setChildView(a.view), s(this, W).push({ id: a.id, node: l });
|
|
1098
1333
|
}
|
|
1099
1334
|
}
|
|
1100
1335
|
}
|
|
1101
1336
|
};
|
|
1102
|
-
const
|
|
1103
|
-
function
|
|
1104
|
-
function r(
|
|
1105
|
-
return !
|
|
1337
|
+
const ur = /(noopener|noreferrer) (noopener|noreferrer)/, hr = /^[\w-_]+:/;
|
|
1338
|
+
function fr(i, e, t = window) {
|
|
1339
|
+
function r(a) {
|
|
1340
|
+
return !a || a === i ? null : a.localName !== "a" || a.href === void 0 ? r(a.parentNode) : a;
|
|
1106
1341
|
}
|
|
1107
|
-
function
|
|
1108
|
-
if (
|
|
1342
|
+
function n(a) {
|
|
1343
|
+
if (a.button && a.button !== 0 || a.ctrlKey || a.metaKey || a.altKey || a.shiftKey || a.defaultPrevented)
|
|
1109
1344
|
return;
|
|
1110
|
-
const o = r(
|
|
1111
|
-
o && (t.location.protocol !== o.protocol || t.location.hostname !== o.hostname || t.location.port !== o.port || o.hasAttribute("data-router-ignore") || o.hasAttribute("download") || o.getAttribute("target") === "_blank" &&
|
|
1345
|
+
const o = r(a.target);
|
|
1346
|
+
o && (t.location.protocol !== o.protocol || t.location.hostname !== o.hostname || t.location.port !== o.port || o.hasAttribute("data-router-ignore") || o.hasAttribute("download") || o.getAttribute("target") === "_blank" && ur.test(o.getAttribute("rel")) || hr.test(o.getAttribute("href")) || (a.preventDefault(), e(o)));
|
|
1112
1347
|
}
|
|
1113
|
-
return
|
|
1114
|
-
|
|
1348
|
+
return i.addEventListener("click", n), function() {
|
|
1349
|
+
i.removeEventListener("click", n);
|
|
1115
1350
|
};
|
|
1116
1351
|
}
|
|
1117
|
-
function
|
|
1352
|
+
function dr(i, e) {
|
|
1118
1353
|
for (const t in e) {
|
|
1119
1354
|
const r = e[t].toString();
|
|
1120
|
-
|
|
1355
|
+
i = i.replace(`{${t}}`, r).replace(`{#${t}}`, r);
|
|
1121
1356
|
}
|
|
1122
|
-
return
|
|
1357
|
+
return i;
|
|
1123
1358
|
}
|
|
1124
|
-
var
|
|
1125
|
-
class
|
|
1359
|
+
var B, Me, G, ae, je, Te, qe, Fe, Ae, _e, z, O, K;
|
|
1360
|
+
class pr {
|
|
1126
1361
|
constructor() {
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1362
|
+
P(this, "http");
|
|
1363
|
+
P(this, "i18n");
|
|
1364
|
+
P(this, "render");
|
|
1365
|
+
P(this, "router");
|
|
1366
|
+
h(this, B, !1);
|
|
1367
|
+
h(this, Me, "production");
|
|
1368
|
+
h(this, G);
|
|
1369
|
+
h(this, ae);
|
|
1370
|
+
h(this, je, Gt);
|
|
1371
|
+
h(this, Te, nt());
|
|
1372
|
+
h(this, qe, []);
|
|
1373
|
+
h(this, Fe, []);
|
|
1374
|
+
h(this, Ae, []);
|
|
1375
|
+
h(this, _e, []);
|
|
1376
|
+
h(this, z, {
|
|
1377
|
+
root: this,
|
|
1378
|
+
data: {}
|
|
1379
|
+
});
|
|
1380
|
+
h(this, O, {
|
|
1141
1381
|
info: "development",
|
|
1142
1382
|
log: "development",
|
|
1143
1383
|
warn: "development",
|
|
1144
1384
|
error: !0
|
|
1145
1385
|
});
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1386
|
+
h(this, K, wt("*,-dolla/*"));
|
|
1387
|
+
P(this, "watch", s(this, Te).watch);
|
|
1388
|
+
P(this, "createState", ce);
|
|
1389
|
+
P(this, "createSettableState", Ft);
|
|
1390
|
+
P(this, "toSettableState", At);
|
|
1391
|
+
P(this, "toState", _t);
|
|
1392
|
+
P(this, "valueOf", Ct);
|
|
1393
|
+
P(this, "derive", be);
|
|
1394
|
+
P(this, "createWatcher", nt);
|
|
1395
|
+
P(this, "createRef", Vt);
|
|
1396
|
+
P(this, "isRef", It);
|
|
1156
1397
|
const e = this;
|
|
1157
|
-
this.http = new
|
|
1398
|
+
this.http = new zt(), this.i18n = new tr(this), this.render = new nr(this), this.router = new cr(this, {
|
|
1158
1399
|
get rootElement() {
|
|
1159
|
-
return
|
|
1400
|
+
return s(e, G);
|
|
1160
1401
|
},
|
|
1161
1402
|
get rootView() {
|
|
1162
|
-
return
|
|
1403
|
+
return s(e, ae);
|
|
1163
1404
|
}
|
|
1164
1405
|
});
|
|
1165
1406
|
}
|
|
@@ -1167,47 +1408,65 @@ class Kt {
|
|
|
1167
1408
|
* True when the app is connected to a DOM node and displayed to the user.
|
|
1168
1409
|
*/
|
|
1169
1410
|
get isMounted() {
|
|
1170
|
-
return
|
|
1411
|
+
return s(this, B);
|
|
1171
1412
|
}
|
|
1172
1413
|
/**
|
|
1173
1414
|
* Get the current environment that this app is running in.
|
|
1174
1415
|
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
1175
1416
|
*/
|
|
1176
1417
|
getEnv() {
|
|
1177
|
-
return
|
|
1418
|
+
return s(this, Me);
|
|
1178
1419
|
}
|
|
1179
1420
|
/**
|
|
1180
1421
|
* Sets the environment that this app is running in.
|
|
1181
1422
|
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
1182
1423
|
*/
|
|
1183
1424
|
setEnv(e) {
|
|
1184
|
-
|
|
1425
|
+
v(this, Me, e);
|
|
1185
1426
|
}
|
|
1186
1427
|
/**
|
|
1187
1428
|
* Sets the view that will be shown when the `crash` method is called on any logger.
|
|
1188
1429
|
* When a crash is reported the app will be unmounted and replaced with this crash page.
|
|
1189
1430
|
*/
|
|
1190
1431
|
setCrashView(e) {
|
|
1191
|
-
|
|
1432
|
+
v(this, je, e);
|
|
1433
|
+
}
|
|
1434
|
+
/**
|
|
1435
|
+
* Sets a context variable and returns its value. Context variables are accessible on the app and in child views.
|
|
1436
|
+
*/
|
|
1437
|
+
set(e, t) {
|
|
1438
|
+
return s(this, z).data[e] = t, t;
|
|
1439
|
+
}
|
|
1440
|
+
/**
|
|
1441
|
+
* Gets the value of a context variable. Returns null if the variable is not set.
|
|
1442
|
+
*/
|
|
1443
|
+
get(e) {
|
|
1444
|
+
return s(this, z).data[e] ?? null;
|
|
1445
|
+
}
|
|
1446
|
+
/**
|
|
1447
|
+
* Returns an object of all context variables stored at the app level.
|
|
1448
|
+
*/
|
|
1449
|
+
getAll() {
|
|
1450
|
+
return { ...s(this, z).data };
|
|
1192
1451
|
}
|
|
1193
1452
|
async mount(e, t) {
|
|
1194
|
-
if (
|
|
1453
|
+
if (s(this, B))
|
|
1195
1454
|
throw new Error("Dolla is already mounted.");
|
|
1196
|
-
if (
|
|
1197
|
-
const
|
|
1198
|
-
|
|
1455
|
+
if (V(e)) {
|
|
1456
|
+
const n = document.querySelector(e);
|
|
1457
|
+
yt(HTMLElement, n, `Selector '${e}' did not match any element.`), v(this, G, n);
|
|
1199
1458
|
} else
|
|
1200
|
-
|
|
1459
|
+
yt(HTMLElement, e, "Expected an HTML element or a selector string. Got type: %t, value: %v"), v(this, G, e);
|
|
1201
1460
|
let r;
|
|
1202
|
-
t ? r =
|
|
1203
|
-
for (const
|
|
1204
|
-
|
|
1461
|
+
t ? r = vt(t) : r = vt(Pt), v(this, ae, this.constructView(r.type, r.props)), await Promise.all(s(this, qe).map((n) => n())), s(this, ae).mount(s(this, G)), v(this, B, !0);
|
|
1462
|
+
for (const n of s(this, Fe))
|
|
1463
|
+
n();
|
|
1205
1464
|
}
|
|
1206
1465
|
async unmount() {
|
|
1207
1466
|
var e;
|
|
1208
|
-
if (
|
|
1209
|
-
await Promise.all(
|
|
1210
|
-
for (const t of
|
|
1467
|
+
if (s(this, B)) {
|
|
1468
|
+
await Promise.all(s(this, Ae).map((t) => t())), (e = s(this, ae)) == null || e.unmount(!1), s(this, Te).stopAll(), v(this, B, !1);
|
|
1469
|
+
for (const t of s(this, _e))
|
|
1211
1470
|
t();
|
|
1212
1471
|
}
|
|
1213
1472
|
}
|
|
@@ -1216,26 +1475,26 @@ class Kt {
|
|
|
1216
1475
|
* it will be awaited before mounting finishes. Use this to perform initial setup before the app is displayed to the user.
|
|
1217
1476
|
*/
|
|
1218
1477
|
beforeMount(e) {
|
|
1219
|
-
|
|
1478
|
+
s(this, qe).push(e);
|
|
1220
1479
|
}
|
|
1221
1480
|
/**
|
|
1222
1481
|
* Registers a `callback` to run after the app is mounted.
|
|
1223
1482
|
*/
|
|
1224
1483
|
onMount(e) {
|
|
1225
|
-
|
|
1484
|
+
s(this, Fe).push(e);
|
|
1226
1485
|
}
|
|
1227
1486
|
/**
|
|
1228
1487
|
* Registers a `callback` to run after `Dolla.unmount` is called, before the app is unmounted. If `callback` returns a Promise,
|
|
1229
1488
|
* it will be awaited before unmounting finishes. Use this to perform cleanup.
|
|
1230
1489
|
*/
|
|
1231
1490
|
beforeUnmount(e) {
|
|
1232
|
-
|
|
1491
|
+
s(this, Ae).push(e);
|
|
1233
1492
|
}
|
|
1234
1493
|
/**
|
|
1235
1494
|
* Registers a `callback` to run after the app is unmounted.
|
|
1236
1495
|
*/
|
|
1237
1496
|
onUnmount(e) {
|
|
1238
|
-
|
|
1497
|
+
s(this, _e).push(e);
|
|
1239
1498
|
}
|
|
1240
1499
|
/**
|
|
1241
1500
|
* Update log type toggles. Values that are not passed will remain unchanged.
|
|
@@ -1243,26 +1502,28 @@ class Kt {
|
|
|
1243
1502
|
setLoggles(e) {
|
|
1244
1503
|
for (const t in e) {
|
|
1245
1504
|
const r = e[t];
|
|
1246
|
-
r && (
|
|
1505
|
+
r && (s(this, O)[t] = r);
|
|
1247
1506
|
}
|
|
1248
1507
|
}
|
|
1249
1508
|
setLogFilter(e) {
|
|
1250
|
-
|
|
1509
|
+
v(this, K, wt(e));
|
|
1251
1510
|
}
|
|
1252
1511
|
createLogger(e, t) {
|
|
1253
|
-
const r =
|
|
1512
|
+
const r = (t == null ? void 0 : t.console) ?? Ut(), n = this;
|
|
1254
1513
|
return {
|
|
1514
|
+
setName(a) {
|
|
1515
|
+
return e = a, this;
|
|
1516
|
+
},
|
|
1255
1517
|
get info() {
|
|
1256
|
-
var
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
return Oe;
|
|
1518
|
+
var a;
|
|
1519
|
+
if (s(n, O).info === !1 || V(s(n, O).info) && s(n, O).info !== n.getEnv() || !s(a = n, K).call(a, e))
|
|
1520
|
+
return Ce;
|
|
1260
1521
|
{
|
|
1261
|
-
let
|
|
1262
|
-
return t != null && t.uid ?
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
`color:${
|
|
1522
|
+
let o = `%c${e}`;
|
|
1523
|
+
return t != null && t.uid ? o += ` %c[uid: %c${t.uid}%c]` : o += "%c%c%c", r.info.bind(
|
|
1524
|
+
r,
|
|
1525
|
+
o,
|
|
1526
|
+
`color:${Ve(o)};font-weight:bold`,
|
|
1266
1527
|
"color:#777",
|
|
1267
1528
|
"color:#aaa",
|
|
1268
1529
|
"color:#777"
|
|
@@ -1270,16 +1531,15 @@ class Kt {
|
|
|
1270
1531
|
}
|
|
1271
1532
|
},
|
|
1272
1533
|
get log() {
|
|
1273
|
-
var
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
return Oe;
|
|
1534
|
+
var a;
|
|
1535
|
+
if (s(n, O).log === !1 || V(s(n, O).log) && s(n, O).log !== n.getEnv() || !s(a = n, K).call(a, e))
|
|
1536
|
+
return Ce;
|
|
1277
1537
|
{
|
|
1278
|
-
let
|
|
1279
|
-
return t != null && t.uid ?
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
`color:${
|
|
1538
|
+
let o = `%c${e}`;
|
|
1539
|
+
return t != null && t.uid ? o += ` %c[uid: %c${t.uid}%c]` : o += "%c%c%c", r.log.bind(
|
|
1540
|
+
r,
|
|
1541
|
+
o,
|
|
1542
|
+
`color:${Ve(o)};font-weight:bold`,
|
|
1283
1543
|
"color:#777",
|
|
1284
1544
|
"color:#aaa",
|
|
1285
1545
|
"color:#777"
|
|
@@ -1287,16 +1547,15 @@ class Kt {
|
|
|
1287
1547
|
}
|
|
1288
1548
|
},
|
|
1289
1549
|
get warn() {
|
|
1290
|
-
var
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
return Oe;
|
|
1550
|
+
var a;
|
|
1551
|
+
if (s(n, O).warn === !1 || V(s(n, O).warn) && s(n, O).warn !== n.getEnv() || !s(a = n, K).call(a, e))
|
|
1552
|
+
return Ce;
|
|
1294
1553
|
{
|
|
1295
|
-
let
|
|
1296
|
-
return t != null && t.uid ?
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
`color:${
|
|
1554
|
+
let o = `%c${e}`;
|
|
1555
|
+
return t != null && t.uid ? o += ` %c[uid: %c${t.uid}%c]` : o += "%c%c%c", r.warn.bind(
|
|
1556
|
+
r,
|
|
1557
|
+
o,
|
|
1558
|
+
`color:${Ve(o)};font-weight:bold`,
|
|
1300
1559
|
"color:#777",
|
|
1301
1560
|
"color:#aaa",
|
|
1302
1561
|
"color:#777"
|
|
@@ -1304,28 +1563,27 @@ class Kt {
|
|
|
1304
1563
|
}
|
|
1305
1564
|
},
|
|
1306
1565
|
get error() {
|
|
1307
|
-
var
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
return Oe;
|
|
1566
|
+
var a;
|
|
1567
|
+
if (s(n, O).error === !1 || V(s(n, O).error) && s(n, O).error !== n.getEnv() || !s(a = n, K).call(a, e))
|
|
1568
|
+
return Ce;
|
|
1311
1569
|
{
|
|
1312
|
-
let
|
|
1313
|
-
return t != null && t.uid ?
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
`color:${
|
|
1570
|
+
let o = `%c${e}`;
|
|
1571
|
+
return t != null && t.uid ? o += ` %c[uid: %c${t.uid}%c]` : o += "%c%c%c", r.error.bind(
|
|
1572
|
+
r,
|
|
1573
|
+
o,
|
|
1574
|
+
`color:${Ve(o)};font-weight:bold`,
|
|
1317
1575
|
"color:#777",
|
|
1318
1576
|
"color:#aaa",
|
|
1319
1577
|
"color:#777"
|
|
1320
1578
|
);
|
|
1321
1579
|
}
|
|
1322
1580
|
},
|
|
1323
|
-
crash(
|
|
1324
|
-
throw
|
|
1325
|
-
error:
|
|
1326
|
-
loggerName:
|
|
1581
|
+
crash(a) {
|
|
1582
|
+
throw n.isMounted && (n.unmount(), n.constructView(s(n, je), {
|
|
1583
|
+
error: a,
|
|
1584
|
+
loggerName: e,
|
|
1327
1585
|
uid: t == null ? void 0 : t.uid
|
|
1328
|
-
}).mount(
|
|
1586
|
+
}).mount(s(n, G))), a;
|
|
1329
1587
|
}
|
|
1330
1588
|
};
|
|
1331
1589
|
}
|
|
@@ -1333,34 +1591,41 @@ class Kt {
|
|
|
1333
1591
|
*
|
|
1334
1592
|
*/
|
|
1335
1593
|
constructView(e, t, r = []) {
|
|
1336
|
-
return
|
|
1594
|
+
return new Ht(s(this, z), e, t, r);
|
|
1337
1595
|
}
|
|
1338
1596
|
/**
|
|
1339
1597
|
*
|
|
1340
1598
|
*/
|
|
1341
1599
|
constructMarkup(e) {
|
|
1342
|
-
return
|
|
1600
|
+
return Wt(Bt(s(this, z), e));
|
|
1343
1601
|
}
|
|
1344
1602
|
}
|
|
1345
|
-
|
|
1346
|
-
const
|
|
1603
|
+
B = new WeakMap(), Me = new WeakMap(), G = new WeakMap(), ae = new WeakMap(), je = new WeakMap(), Te = new WeakMap(), qe = new WeakMap(), Fe = new WeakMap(), Ae = new WeakMap(), _e = new WeakMap(), z = new WeakMap(), O = new WeakMap(), K = new WeakMap();
|
|
1604
|
+
const kt = new pr(), yr = kt.i18n.t.bind(kt.i18n);
|
|
1605
|
+
function vr(i) {
|
|
1606
|
+
typeof window < "u" && (window.DOLLA_DEV_DEBUG = i);
|
|
1607
|
+
}
|
|
1608
|
+
function br() {
|
|
1609
|
+
return typeof window < "u" ? window.DOLLA_DEV_DEBUG === !0 : !1;
|
|
1610
|
+
}
|
|
1347
1611
|
export {
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1612
|
+
jt as cond,
|
|
1613
|
+
vt as createMarkup,
|
|
1614
|
+
Vt as createRef,
|
|
1615
|
+
Ft as createSettableState,
|
|
1616
|
+
kr as createSetter,
|
|
1617
|
+
ce as createState,
|
|
1618
|
+
kt as default,
|
|
1619
|
+
be as derive,
|
|
1620
|
+
br as getDevDebug,
|
|
1621
|
+
mt as html,
|
|
1622
|
+
It as isRef,
|
|
1623
|
+
Sr as portal,
|
|
1624
|
+
Pr as repeat,
|
|
1625
|
+
vr as setDevDebug,
|
|
1626
|
+
yr as t,
|
|
1627
|
+
At as toSettableState,
|
|
1628
|
+
_t as toState,
|
|
1629
|
+
Ct as valueOf
|
|
1365
1630
|
};
|
|
1366
1631
|
//# sourceMappingURL=index.js.map
|