@manyducks.co/dolla 2.0.0-alpha.2 → 2.0.0-alpha.21
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 +994 -727
- 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-6Lrg96Id.js +1393 -0
- package/dist/passthrough-6Lrg96Id.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 Dt = 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 Nt = (i, e, t) => e in i ? Dt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
|
|
6
|
+
var P = (i, e, t) => Nt(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), b = (i, e, t, r) => (Ze(i, e, "write to private field"), r ? r.call(i, t) : e.set(i, t), t), v = (i, e, t) => (Ze(i, e, "access private method"), t);
|
|
8
|
+
var et = (i, e, t, r) => ({
|
|
9
|
+
set _(n) {
|
|
10
|
+
b(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 oe, d as be, b as dt, e as V, t as gt, f as kt, j as Mt, k as nt, P as St, l as wt, m as qt, n as Ft, o as At, v as _t, p as Ct, q as Vt, r as yt, s as It, u as Ut, w as Ce, x as Ve, V as Ht, y as Wt, z as Bt } from "./passthrough-6Lrg96Id.js";
|
|
17
|
+
import { A as kr, B as Sr, C as Pr } from "./passthrough-6Lrg96Id.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 J,
|
|
66
|
-
class
|
|
65
|
+
var J, Qe, j, F;
|
|
66
|
+
class zt {
|
|
67
67
|
constructor() {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
68
|
+
h(this, j);
|
|
69
|
+
h(this, J, []);
|
|
70
|
+
h(this, Qe, Kt());
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
73
|
* Adds a new middleware that will apply to subsequent requests.
|
|
@@ -76,364 +76,557 @@ 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, J).push(e), () => {
|
|
80
|
+
s(this, J).splice(s(this, J).indexOf(e), 1);
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
83
|
async get(e, t) {
|
|
84
|
-
return
|
|
84
|
+
return v(this, j, F).call(this, "get", e, t);
|
|
85
85
|
}
|
|
86
86
|
async put(e, t) {
|
|
87
|
-
return
|
|
87
|
+
return v(this, j, F).call(this, "put", e, t);
|
|
88
88
|
}
|
|
89
89
|
async patch(e, t) {
|
|
90
|
-
return
|
|
90
|
+
return v(this, j, F).call(this, "patch", e, t);
|
|
91
91
|
}
|
|
92
92
|
async post(e, t) {
|
|
93
|
-
return
|
|
93
|
+
return v(this, j, F).call(this, "post", e, t);
|
|
94
94
|
}
|
|
95
95
|
async delete(e, t) {
|
|
96
|
-
return
|
|
96
|
+
return v(this, j, F).call(this, "delete", e, t);
|
|
97
97
|
}
|
|
98
98
|
async head(e, t) {
|
|
99
|
-
return
|
|
99
|
+
return v(this, j, F).call(this, "head", e, t);
|
|
100
100
|
}
|
|
101
101
|
async options(e, t) {
|
|
102
|
-
return
|
|
102
|
+
return v(this, j, F).call(this, "options", e, t);
|
|
103
103
|
}
|
|
104
104
|
async trace(e, t) {
|
|
105
|
-
return
|
|
105
|
+
return v(this, j, F).call(this, "trace", e, t);
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
|
-
J = new WeakMap(),
|
|
109
|
-
return
|
|
108
|
+
J = new WeakMap(), Qe = new WeakMap(), j = 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, J),
|
|
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, le, ne, at, Pt;
|
|
230
|
+
class er {
|
|
200
231
|
constructor(e, t) {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
232
|
+
h(this, ne);
|
|
233
|
+
P(this, "dolla");
|
|
234
|
+
P(this, "config");
|
|
235
|
+
h(this, Je, !1);
|
|
236
|
+
h(this, le, /* @__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 = v(this, ne, at).call(this, e);
|
|
260
|
+
for (const r of t)
|
|
261
|
+
s(this, le).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, le).get(e) ?? {
|
|
267
|
+
segments: [{ type: 0, text: `[MISSING: ${e}]` }]
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
hasTemplate(e) {
|
|
271
|
+
return s(this, le).has(e);
|
|
230
272
|
}
|
|
231
273
|
}
|
|
232
|
-
|
|
233
|
-
|
|
274
|
+
Je = new WeakMap(), le = new WeakMap(), ne = 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("."), v(this, ne, Pt).call(this, e[n])]);
|
|
280
|
+
break;
|
|
281
|
+
case "object":
|
|
282
|
+
r.push(...v(this, ne, 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
|
+
}, Pt = 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 $e, I, L, Ee, ke, Se, Pe, R, xt, st, it, ot, Ot;
|
|
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, $e);
|
|
344
|
+
h(this, I);
|
|
345
|
+
h(this, L, /* @__PURE__ */ new Map());
|
|
346
|
+
h(this, Ee, []);
|
|
347
|
+
h(this, ke, /* @__PURE__ */ new Map());
|
|
348
|
+
h(this, Se, "auto");
|
|
349
|
+
P(this, "$locale");
|
|
350
|
+
h(this, Pe);
|
|
351
|
+
b(this, $e, e), b(this, I, e.createLogger("dolla/i18n"));
|
|
352
|
+
const [t, r] = oe();
|
|
353
|
+
this.$locale = t, b(this, Pe, r), this.addFormat("number", (n, a, o) => v(this, R, st).call(this, Number(a), o)), this.addFormat("datetime", (n, a, o) => v(this, R, it).call(this, a, o)), this.addFormat("list", (n, a, o) => v(this, R, ot).call(this, a, o)), e.beforeMount(async () => {
|
|
354
|
+
s(this, L).size > 0 && await this.setLocale(s(this, Se));
|
|
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, $e)));
|
|
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
|
+
b(this, Se, 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(), b(this, Ee, []), s(this, Pe).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 v(this, R, xt).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, ke).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) => v(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) => v(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) => v(this, R, ot).call(this, n, t));
|
|
334
481
|
}
|
|
335
482
|
}
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
483
|
+
$e = new WeakMap(), I = new WeakMap(), L = new WeakMap(), Ee = new WeakMap(), ke = new WeakMap(), Se = new WeakMap(), Pe = new WeakMap(), R = new WeakSet(), xt = function(e, t, r) {
|
|
484
|
+
var l;
|
|
485
|
+
const n = v(this, R, Ot).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, ke).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
|
+
Ot = function(e, t) {
|
|
529
|
+
for (const r of s(this, Ee))
|
|
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 X,
|
|
357
|
-
class
|
|
542
|
+
var xe, ce, U, Y, X, ue, Ye, A, Oe, _, lt, Ie;
|
|
543
|
+
class nr {
|
|
358
544
|
constructor(e) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
//
|
|
545
|
+
h(this, _);
|
|
546
|
+
h(this, xe);
|
|
547
|
+
h(this, ce);
|
|
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, U, /* @__PURE__ */ new Map());
|
|
551
|
+
// All unkeyed writes are run on every batch.
|
|
552
|
+
h(this, Y, []);
|
|
553
|
+
// All read callbacks are run before updates on every batch.
|
|
554
|
+
h(this, X, []);
|
|
555
|
+
h(this, ue, !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
|
+
b(this, xe, e), b(this, ce, 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, X).push(e), v(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
|
+
t ? s(this, U).set(t, e) : s(this, Y).push(e), v(this, _, lt).call(this);
|
|
396
577
|
}
|
|
397
578
|
}
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
579
|
+
xe = new WeakMap(), ce = new WeakMap(), U = new WeakMap(), Y = new WeakMap(), X = new WeakMap(), ue = new WeakMap(), Ye = new WeakMap(), A = new WeakMap(), Oe = new WeakMap(), _ = new WeakSet(), lt = function() {
|
|
580
|
+
if (!s(this, ue)) {
|
|
581
|
+
b(this, ue, !0);
|
|
582
|
+
const e = s(this, xe).getEnv() === "development";
|
|
583
|
+
queueMicrotask(() => {
|
|
584
|
+
v(this, _, Ie).call(this, e);
|
|
585
|
+
});
|
|
405
586
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
587
|
+
}, Ie = function(e = !1) {
|
|
588
|
+
const t = performance.now();
|
|
589
|
+
let r = 0;
|
|
590
|
+
const n = s(this, X).length + s(this, U).size + s(this, Y).length;
|
|
591
|
+
let a = 0;
|
|
592
|
+
const o = () => (a++, r = performance.now() - t, s(this, Ye) && r > 12 && a < n ? (et(this, A)._++, e && s(this, ce).warn(
|
|
593
|
+
`⚠️ 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)}).`
|
|
594
|
+
), requestAnimationFrame(() => {
|
|
595
|
+
v(this, _, Ie).call(this, e);
|
|
596
|
+
}), !0) : !1), p = [...s(this, U).entries()];
|
|
597
|
+
let l;
|
|
598
|
+
for (; l = s(this, X).shift(); )
|
|
599
|
+
if (l(), o()) return;
|
|
600
|
+
for (const [f, m] of p)
|
|
601
|
+
if (m(), s(this, U).delete(f), o()) return;
|
|
602
|
+
for (; l = s(this, Y).shift(); )
|
|
603
|
+
if (l(), o()) return;
|
|
604
|
+
e && s(this, ce)[r > 16 ? "warn" : "info"](
|
|
605
|
+
`${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"})` : ""}.`
|
|
606
|
+
), b(this, A, 0), s(this, X).length || s(this, U).size || s(this, Y).length ? queueMicrotask(() => {
|
|
607
|
+
v(this, _, Ie).call(this, e);
|
|
608
|
+
}) : b(this, ue, !1);
|
|
415
609
|
};
|
|
416
|
-
function
|
|
417
|
-
return
|
|
610
|
+
function pe() {
|
|
611
|
+
return pe = Object.assign ? Object.assign.bind() : function(i) {
|
|
418
612
|
for (var e = 1; e < arguments.length; e++) {
|
|
419
613
|
var t = arguments[e];
|
|
420
|
-
for (var r in t)
|
|
421
|
-
Object.prototype.hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
614
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (i[r] = t[r]);
|
|
422
615
|
}
|
|
423
|
-
return
|
|
424
|
-
},
|
|
616
|
+
return i;
|
|
617
|
+
}, pe.apply(null, arguments);
|
|
425
618
|
}
|
|
426
|
-
var
|
|
427
|
-
(function(
|
|
428
|
-
|
|
429
|
-
})(
|
|
430
|
-
var
|
|
431
|
-
return Object.freeze(
|
|
432
|
-
} : function(
|
|
433
|
-
return
|
|
619
|
+
var M;
|
|
620
|
+
(function(i) {
|
|
621
|
+
i.Pop = "POP", i.Push = "PUSH", i.Replace = "REPLACE";
|
|
622
|
+
})(M || (M = {}));
|
|
623
|
+
var Be = process.env.NODE_ENV !== "production" ? function(i) {
|
|
624
|
+
return Object.freeze(i);
|
|
625
|
+
} : function(i) {
|
|
626
|
+
return i;
|
|
434
627
|
};
|
|
435
|
-
function
|
|
436
|
-
if (!
|
|
628
|
+
function Ue(i, e) {
|
|
629
|
+
if (!i) {
|
|
437
630
|
typeof console < "u" && console.warn(e);
|
|
438
631
|
try {
|
|
439
632
|
throw new Error(e);
|
|
@@ -441,38 +634,38 @@ function je(n, e) {
|
|
|
441
634
|
}
|
|
442
635
|
}
|
|
443
636
|
}
|
|
444
|
-
var
|
|
445
|
-
function
|
|
446
|
-
|
|
447
|
-
var e =
|
|
448
|
-
function
|
|
449
|
-
var
|
|
450
|
-
return [E.idx,
|
|
451
|
-
pathname:
|
|
452
|
-
search:
|
|
453
|
-
hash:
|
|
637
|
+
var Ge = "beforeunload", ar = "hashchange", Lt = "popstate";
|
|
638
|
+
function sr(i) {
|
|
639
|
+
i === void 0 && (i = {});
|
|
640
|
+
var e = i, t = e.window, r = t === void 0 ? document.defaultView : t, n = r.history;
|
|
641
|
+
function a() {
|
|
642
|
+
var w = r.location, c = w.pathname, d = w.search, $ = w.hash, E = n.state || {};
|
|
643
|
+
return [E.idx, Be({
|
|
644
|
+
pathname: c,
|
|
645
|
+
search: d,
|
|
646
|
+
hash: $,
|
|
454
647
|
state: E.usr || null,
|
|
455
648
|
key: E.key || "default"
|
|
456
649
|
})];
|
|
457
650
|
}
|
|
458
651
|
var o = null;
|
|
459
|
-
function
|
|
652
|
+
function p() {
|
|
460
653
|
if (o)
|
|
461
|
-
|
|
654
|
+
y.call(o), o = null;
|
|
462
655
|
else {
|
|
463
|
-
var
|
|
464
|
-
if (
|
|
465
|
-
if (
|
|
466
|
-
var E =
|
|
656
|
+
var w = M.Pop, c = a(), d = c[0], $ = c[1];
|
|
657
|
+
if (y.length)
|
|
658
|
+
if (d != null) {
|
|
659
|
+
var E = m - d;
|
|
467
660
|
E && (o = {
|
|
468
|
-
action:
|
|
469
|
-
location:
|
|
661
|
+
action: w,
|
|
662
|
+
location: $,
|
|
470
663
|
retry: function() {
|
|
471
|
-
|
|
664
|
+
C(E * -1);
|
|
472
665
|
}
|
|
473
|
-
},
|
|
666
|
+
}, C(E));
|
|
474
667
|
} else
|
|
475
|
-
process.env.NODE_ENV !== "production" &&
|
|
668
|
+
process.env.NODE_ENV !== "production" && Ue(
|
|
476
669
|
!1,
|
|
477
670
|
// TODO: Write up a doc that explains our blocking strategy in
|
|
478
671
|
// detail and link to it here so people can understand better what
|
|
@@ -480,137 +673,137 @@ function Ht(n) {
|
|
|
480
673
|
"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
674
|
);
|
|
482
675
|
else
|
|
483
|
-
|
|
676
|
+
ae(w);
|
|
484
677
|
}
|
|
485
678
|
}
|
|
486
|
-
r.addEventListener(
|
|
487
|
-
var
|
|
488
|
-
|
|
489
|
-
idx:
|
|
679
|
+
r.addEventListener(Lt, p);
|
|
680
|
+
var l = M.Pop, f = a(), m = f[0], g = f[1], u = Ke(), y = Ke();
|
|
681
|
+
m == null && (m = 0, n.replaceState(pe({}, n.state, {
|
|
682
|
+
idx: m
|
|
490
683
|
}), ""));
|
|
491
|
-
function
|
|
492
|
-
return typeof
|
|
684
|
+
function k(w) {
|
|
685
|
+
return typeof w == "string" ? w : He(w);
|
|
493
686
|
}
|
|
494
|
-
function
|
|
495
|
-
return
|
|
496
|
-
pathname:
|
|
687
|
+
function me(w, c) {
|
|
688
|
+
return c === void 0 && (c = null), Be(pe({
|
|
689
|
+
pathname: g.pathname,
|
|
497
690
|
hash: "",
|
|
498
691
|
search: ""
|
|
499
|
-
}, typeof
|
|
500
|
-
state:
|
|
501
|
-
key:
|
|
692
|
+
}, typeof w == "string" ? ct(w) : w, {
|
|
693
|
+
state: c,
|
|
694
|
+
key: Rt()
|
|
502
695
|
}));
|
|
503
696
|
}
|
|
504
|
-
function
|
|
697
|
+
function ge(w, c) {
|
|
505
698
|
return [{
|
|
506
|
-
usr:
|
|
507
|
-
key:
|
|
508
|
-
idx:
|
|
509
|
-
},
|
|
510
|
-
}
|
|
511
|
-
function
|
|
512
|
-
return !
|
|
513
|
-
action:
|
|
514
|
-
location:
|
|
515
|
-
retry:
|
|
699
|
+
usr: w.state,
|
|
700
|
+
key: w.key,
|
|
701
|
+
idx: c
|
|
702
|
+
}, k(w)];
|
|
703
|
+
}
|
|
704
|
+
function we(w, c, d) {
|
|
705
|
+
return !y.length || (y.call({
|
|
706
|
+
action: w,
|
|
707
|
+
location: c,
|
|
708
|
+
retry: d
|
|
516
709
|
}), !1);
|
|
517
710
|
}
|
|
518
|
-
function
|
|
519
|
-
|
|
520
|
-
var
|
|
521
|
-
|
|
522
|
-
action:
|
|
523
|
-
location:
|
|
711
|
+
function ae(w) {
|
|
712
|
+
l = w;
|
|
713
|
+
var c = a();
|
|
714
|
+
m = c[0], g = c[1], u.call({
|
|
715
|
+
action: l,
|
|
716
|
+
location: g
|
|
524
717
|
});
|
|
525
718
|
}
|
|
526
|
-
function
|
|
527
|
-
var
|
|
719
|
+
function se(w, c) {
|
|
720
|
+
var d = M.Push, $ = me(w, c);
|
|
528
721
|
function E() {
|
|
529
|
-
|
|
722
|
+
se(w, c);
|
|
530
723
|
}
|
|
531
|
-
if (
|
|
532
|
-
var
|
|
724
|
+
if (we(d, $, E)) {
|
|
725
|
+
var x = ge($, m + 1), D = x[0], T = x[1];
|
|
533
726
|
try {
|
|
534
|
-
|
|
727
|
+
n.pushState(D, "", T);
|
|
535
728
|
} catch {
|
|
536
|
-
r.location.assign(
|
|
729
|
+
r.location.assign(T);
|
|
537
730
|
}
|
|
538
|
-
|
|
731
|
+
ae(d);
|
|
539
732
|
}
|
|
540
733
|
}
|
|
541
|
-
function
|
|
542
|
-
var
|
|
734
|
+
function ye(w, c) {
|
|
735
|
+
var d = M.Replace, $ = me(w, c);
|
|
543
736
|
function E() {
|
|
544
|
-
|
|
737
|
+
ye(w, c);
|
|
545
738
|
}
|
|
546
|
-
if (
|
|
547
|
-
var
|
|
548
|
-
|
|
739
|
+
if (we(d, $, E)) {
|
|
740
|
+
var x = ge($, m), D = x[0], T = x[1];
|
|
741
|
+
n.replaceState(D, "", T), ae(d);
|
|
549
742
|
}
|
|
550
743
|
}
|
|
551
|
-
function
|
|
552
|
-
|
|
744
|
+
function C(w) {
|
|
745
|
+
n.go(w);
|
|
553
746
|
}
|
|
554
747
|
var Q = {
|
|
555
748
|
get action() {
|
|
556
|
-
return
|
|
749
|
+
return l;
|
|
557
750
|
},
|
|
558
751
|
get location() {
|
|
559
|
-
return
|
|
752
|
+
return g;
|
|
560
753
|
},
|
|
561
|
-
createHref:
|
|
562
|
-
push:
|
|
563
|
-
replace:
|
|
564
|
-
go:
|
|
754
|
+
createHref: k,
|
|
755
|
+
push: se,
|
|
756
|
+
replace: ye,
|
|
757
|
+
go: C,
|
|
565
758
|
back: function() {
|
|
566
|
-
|
|
759
|
+
C(-1);
|
|
567
760
|
},
|
|
568
761
|
forward: function() {
|
|
569
|
-
|
|
762
|
+
C(1);
|
|
570
763
|
},
|
|
571
|
-
listen: function(
|
|
572
|
-
return
|
|
764
|
+
listen: function(c) {
|
|
765
|
+
return u.push(c);
|
|
573
766
|
},
|
|
574
|
-
block: function(
|
|
575
|
-
var
|
|
576
|
-
return
|
|
577
|
-
|
|
767
|
+
block: function(c) {
|
|
768
|
+
var d = y.push(c);
|
|
769
|
+
return y.length === 1 && r.addEventListener(Ge, ze), function() {
|
|
770
|
+
d(), y.length || r.removeEventListener(Ge, ze);
|
|
578
771
|
};
|
|
579
772
|
}
|
|
580
773
|
};
|
|
581
774
|
return Q;
|
|
582
775
|
}
|
|
583
|
-
function
|
|
584
|
-
|
|
585
|
-
var e =
|
|
586
|
-
function
|
|
587
|
-
var
|
|
588
|
-
return [
|
|
589
|
-
pathname:
|
|
590
|
-
search:
|
|
591
|
-
hash:
|
|
592
|
-
state:
|
|
593
|
-
key:
|
|
776
|
+
function ir(i) {
|
|
777
|
+
i === void 0 && (i = {});
|
|
778
|
+
var e = i, t = e.window, r = t === void 0 ? document.defaultView : t, n = r.history;
|
|
779
|
+
function a() {
|
|
780
|
+
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, T = D === void 0 ? "" : D, q = n.state || {};
|
|
781
|
+
return [q.idx, Be({
|
|
782
|
+
pathname: $,
|
|
783
|
+
search: x,
|
|
784
|
+
hash: T,
|
|
785
|
+
state: q.usr || null,
|
|
786
|
+
key: q.key || "default"
|
|
594
787
|
})];
|
|
595
788
|
}
|
|
596
789
|
var o = null;
|
|
597
|
-
function
|
|
790
|
+
function p() {
|
|
598
791
|
if (o)
|
|
599
|
-
|
|
792
|
+
y.call(o), o = null;
|
|
600
793
|
else {
|
|
601
|
-
var
|
|
602
|
-
if (
|
|
603
|
-
if (
|
|
604
|
-
var
|
|
605
|
-
|
|
606
|
-
action:
|
|
794
|
+
var c = M.Pop, d = a(), $ = d[0], E = d[1];
|
|
795
|
+
if (y.length)
|
|
796
|
+
if ($ != null) {
|
|
797
|
+
var x = m - $;
|
|
798
|
+
x && (o = {
|
|
799
|
+
action: c,
|
|
607
800
|
location: E,
|
|
608
801
|
retry: function() {
|
|
609
|
-
Q(
|
|
802
|
+
Q(x * -1);
|
|
610
803
|
}
|
|
611
|
-
}, Q(
|
|
804
|
+
}, Q(x));
|
|
612
805
|
} else
|
|
613
|
-
process.env.NODE_ENV !== "production" &&
|
|
806
|
+
process.env.NODE_ENV !== "production" && Ue(
|
|
614
807
|
!1,
|
|
615
808
|
// TODO: Write up a doc that explains our blocking strategy in
|
|
616
809
|
// detail and link to it here so people can understand better
|
|
@@ -618,98 +811,98 @@ function _t(n) {
|
|
|
618
811
|
"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
812
|
);
|
|
620
813
|
else
|
|
621
|
-
|
|
814
|
+
se(c);
|
|
622
815
|
}
|
|
623
816
|
}
|
|
624
|
-
r.addEventListener(
|
|
625
|
-
var
|
|
626
|
-
|
|
817
|
+
r.addEventListener(Lt, p), r.addEventListener(ar, function() {
|
|
818
|
+
var c = a(), d = c[1];
|
|
819
|
+
He(d) !== He(g) && p();
|
|
627
820
|
});
|
|
628
|
-
var
|
|
629
|
-
|
|
630
|
-
idx:
|
|
821
|
+
var l = M.Pop, f = a(), m = f[0], g = f[1], u = Ke(), y = Ke();
|
|
822
|
+
m == null && (m = 0, n.replaceState(pe({}, n.state, {
|
|
823
|
+
idx: m
|
|
631
824
|
}), ""));
|
|
632
|
-
function
|
|
633
|
-
var
|
|
634
|
-
if (
|
|
635
|
-
var
|
|
636
|
-
|
|
825
|
+
function k() {
|
|
826
|
+
var c = document.querySelector("base"), d = "";
|
|
827
|
+
if (c && c.getAttribute("href")) {
|
|
828
|
+
var $ = r.location.href, E = $.indexOf("#");
|
|
829
|
+
d = E === -1 ? $ : $.slice(0, E);
|
|
637
830
|
}
|
|
638
|
-
return
|
|
831
|
+
return d;
|
|
639
832
|
}
|
|
640
|
-
function
|
|
641
|
-
return
|
|
833
|
+
function me(c) {
|
|
834
|
+
return k() + "#" + (typeof c == "string" ? c : He(c));
|
|
642
835
|
}
|
|
643
|
-
function
|
|
644
|
-
return
|
|
645
|
-
pathname:
|
|
836
|
+
function ge(c, d) {
|
|
837
|
+
return d === void 0 && (d = null), Be(pe({
|
|
838
|
+
pathname: g.pathname,
|
|
646
839
|
hash: "",
|
|
647
840
|
search: ""
|
|
648
|
-
}, typeof
|
|
649
|
-
state:
|
|
650
|
-
key:
|
|
841
|
+
}, typeof c == "string" ? ct(c) : c, {
|
|
842
|
+
state: d,
|
|
843
|
+
key: Rt()
|
|
651
844
|
}));
|
|
652
845
|
}
|
|
653
|
-
function
|
|
846
|
+
function we(c, d) {
|
|
654
847
|
return [{
|
|
655
|
-
usr:
|
|
656
|
-
key:
|
|
657
|
-
idx:
|
|
658
|
-
},
|
|
848
|
+
usr: c.state,
|
|
849
|
+
key: c.key,
|
|
850
|
+
idx: d
|
|
851
|
+
}, me(c)];
|
|
659
852
|
}
|
|
660
|
-
function
|
|
661
|
-
return !
|
|
662
|
-
action:
|
|
663
|
-
location:
|
|
664
|
-
retry:
|
|
853
|
+
function ae(c, d, $) {
|
|
854
|
+
return !y.length || (y.call({
|
|
855
|
+
action: c,
|
|
856
|
+
location: d,
|
|
857
|
+
retry: $
|
|
665
858
|
}), !1);
|
|
666
859
|
}
|
|
667
|
-
function
|
|
668
|
-
|
|
669
|
-
var
|
|
670
|
-
|
|
671
|
-
action:
|
|
672
|
-
location:
|
|
860
|
+
function se(c) {
|
|
861
|
+
l = c;
|
|
862
|
+
var d = a();
|
|
863
|
+
m = d[0], g = d[1], u.call({
|
|
864
|
+
action: l,
|
|
865
|
+
location: g
|
|
673
866
|
});
|
|
674
867
|
}
|
|
675
|
-
function
|
|
676
|
-
var
|
|
677
|
-
function
|
|
678
|
-
|
|
868
|
+
function ye(c, d) {
|
|
869
|
+
var $ = M.Push, E = ge(c, d);
|
|
870
|
+
function x() {
|
|
871
|
+
ye(c, d);
|
|
679
872
|
}
|
|
680
|
-
if (process.env.NODE_ENV !== "production" &&
|
|
681
|
-
var
|
|
873
|
+
if (process.env.NODE_ENV !== "production" && Ue(E.pathname.charAt(0) === "/", "Relative pathnames are not supported in hash history.push(" + JSON.stringify(c) + ")"), ae($, E, x)) {
|
|
874
|
+
var D = we(E, m + 1), T = D[0], q = D[1];
|
|
682
875
|
try {
|
|
683
|
-
|
|
876
|
+
n.pushState(T, "", q);
|
|
684
877
|
} catch {
|
|
685
|
-
r.location.assign(
|
|
878
|
+
r.location.assign(q);
|
|
686
879
|
}
|
|
687
|
-
|
|
880
|
+
se($);
|
|
688
881
|
}
|
|
689
882
|
}
|
|
690
|
-
function
|
|
691
|
-
var
|
|
692
|
-
function
|
|
693
|
-
|
|
883
|
+
function C(c, d) {
|
|
884
|
+
var $ = M.Replace, E = ge(c, d);
|
|
885
|
+
function x() {
|
|
886
|
+
C(c, d);
|
|
694
887
|
}
|
|
695
|
-
if (process.env.NODE_ENV !== "production" &&
|
|
696
|
-
var
|
|
697
|
-
|
|
888
|
+
if (process.env.NODE_ENV !== "production" && Ue(E.pathname.charAt(0) === "/", "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(c) + ")"), ae($, E, x)) {
|
|
889
|
+
var D = we(E, m), T = D[0], q = D[1];
|
|
890
|
+
n.replaceState(T, "", q), se($);
|
|
698
891
|
}
|
|
699
892
|
}
|
|
700
|
-
function Q(
|
|
701
|
-
|
|
893
|
+
function Q(c) {
|
|
894
|
+
n.go(c);
|
|
702
895
|
}
|
|
703
|
-
var
|
|
896
|
+
var w = {
|
|
704
897
|
get action() {
|
|
705
|
-
return
|
|
898
|
+
return l;
|
|
706
899
|
},
|
|
707
900
|
get location() {
|
|
708
|
-
return
|
|
901
|
+
return g;
|
|
709
902
|
},
|
|
710
|
-
createHref:
|
|
711
|
-
push:
|
|
712
|
-
replace:
|
|
903
|
+
createHref: me,
|
|
904
|
+
push: ye,
|
|
905
|
+
replace: C,
|
|
713
906
|
go: Q,
|
|
714
907
|
back: function() {
|
|
715
908
|
Q(-1);
|
|
@@ -717,80 +910,80 @@ function _t(n) {
|
|
|
717
910
|
forward: function() {
|
|
718
911
|
Q(1);
|
|
719
912
|
},
|
|
720
|
-
listen: function(
|
|
721
|
-
return
|
|
913
|
+
listen: function(d) {
|
|
914
|
+
return u.push(d);
|
|
722
915
|
},
|
|
723
|
-
block: function(
|
|
724
|
-
var
|
|
725
|
-
return
|
|
726
|
-
|
|
916
|
+
block: function(d) {
|
|
917
|
+
var $ = y.push(d);
|
|
918
|
+
return y.length === 1 && r.addEventListener(Ge, ze), function() {
|
|
919
|
+
$(), y.length || r.removeEventListener(Ge, ze);
|
|
727
920
|
};
|
|
728
921
|
}
|
|
729
922
|
};
|
|
730
|
-
return
|
|
923
|
+
return w;
|
|
731
924
|
}
|
|
732
|
-
function
|
|
733
|
-
|
|
925
|
+
function ze(i) {
|
|
926
|
+
i.preventDefault(), i.returnValue = "";
|
|
734
927
|
}
|
|
735
|
-
function
|
|
736
|
-
var
|
|
928
|
+
function Ke() {
|
|
929
|
+
var i = [];
|
|
737
930
|
return {
|
|
738
931
|
get length() {
|
|
739
|
-
return
|
|
932
|
+
return i.length;
|
|
740
933
|
},
|
|
741
934
|
push: function(t) {
|
|
742
|
-
return
|
|
743
|
-
|
|
935
|
+
return i.push(t), function() {
|
|
936
|
+
i = i.filter(function(r) {
|
|
744
937
|
return r !== t;
|
|
745
938
|
});
|
|
746
939
|
};
|
|
747
940
|
},
|
|
748
941
|
call: function(t) {
|
|
749
|
-
|
|
942
|
+
i.forEach(function(r) {
|
|
750
943
|
return r && r(t);
|
|
751
944
|
});
|
|
752
945
|
}
|
|
753
946
|
};
|
|
754
947
|
}
|
|
755
|
-
function
|
|
948
|
+
function Rt() {
|
|
756
949
|
return Math.random().toString(36).substr(2, 8);
|
|
757
950
|
}
|
|
758
|
-
function
|
|
759
|
-
var e =
|
|
760
|
-
return
|
|
951
|
+
function He(i) {
|
|
952
|
+
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;
|
|
953
|
+
return n && n !== "?" && (t += n.charAt(0) === "?" ? n : "?" + n), o && o !== "#" && (t += o.charAt(0) === "#" ? o : "#" + o), t;
|
|
761
954
|
}
|
|
762
|
-
function
|
|
955
|
+
function ct(i) {
|
|
763
956
|
var e = {};
|
|
764
|
-
if (
|
|
765
|
-
var t =
|
|
766
|
-
t >= 0 && (e.hash =
|
|
767
|
-
var r =
|
|
768
|
-
r >= 0 && (e.search =
|
|
957
|
+
if (i) {
|
|
958
|
+
var t = i.indexOf("#");
|
|
959
|
+
t >= 0 && (e.hash = i.substr(t), i = i.substr(0, t));
|
|
960
|
+
var r = i.indexOf("?");
|
|
961
|
+
r >= 0 && (e.search = i.substr(r), i = i.substr(0, r)), i && (e.pathname = i);
|
|
769
962
|
}
|
|
770
963
|
return e;
|
|
771
964
|
}
|
|
772
|
-
function
|
|
773
|
-
return
|
|
965
|
+
function ve(i) {
|
|
966
|
+
return kt(i, "Expected `path` to be a string. Got type: %t, value: %v"), i.split("/").map((e) => e.trim()).filter((e) => e !== "");
|
|
774
967
|
}
|
|
775
|
-
function
|
|
968
|
+
function ie(i) {
|
|
776
969
|
var t;
|
|
777
|
-
|
|
778
|
-
(r) =>
|
|
779
|
-
|
|
970
|
+
Mt(
|
|
971
|
+
(r) => dt(r == null ? void 0 : r.toString),
|
|
972
|
+
i,
|
|
780
973
|
"Expected `parts` to be an array of objects with a .toString() method. Got type: %t, value: %v"
|
|
781
|
-
),
|
|
782
|
-
let e = (t =
|
|
974
|
+
), i = i.filter((r) => r).flatMap(String);
|
|
975
|
+
let e = (t = i.shift()) == null ? void 0 : t.toString();
|
|
783
976
|
if (e) {
|
|
784
|
-
for (const r of
|
|
785
|
-
r.startsWith(".") ? e =
|
|
977
|
+
for (const r of i.map((n) => n.toString()))
|
|
978
|
+
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
979
|
e && e !== "/" && e.endsWith("/") && (e = e.slice(0, e.length - 1));
|
|
787
980
|
}
|
|
788
981
|
return e ?? "";
|
|
789
982
|
}
|
|
790
|
-
function
|
|
791
|
-
if (
|
|
983
|
+
function We(i, e) {
|
|
984
|
+
if (kt(i, "Expected `base` to be a string. Got type: %t, value: %v"), e == null && (e = i, i = ""), e.startsWith("/"))
|
|
792
985
|
return e;
|
|
793
|
-
let t =
|
|
986
|
+
let t = i;
|
|
794
987
|
for (; ; )
|
|
795
988
|
if (e.startsWith("..")) {
|
|
796
989
|
for (let r = t.length; r > 0; --r)
|
|
@@ -802,179 +995,196 @@ function qe(n, e) {
|
|
|
802
995
|
e = e.replace(/^\.\/?/, "");
|
|
803
996
|
else
|
|
804
997
|
break;
|
|
805
|
-
return
|
|
998
|
+
return ie([t, e]);
|
|
806
999
|
}
|
|
807
|
-
function
|
|
808
|
-
if (!
|
|
809
|
-
|
|
810
|
-
const e =
|
|
811
|
-
const [r,
|
|
812
|
-
return
|
|
1000
|
+
function ut(i) {
|
|
1001
|
+
if (!i) return {};
|
|
1002
|
+
i.startsWith("?") && (i = i.slice(1));
|
|
1003
|
+
const e = i.split("&").filter((t) => t.trim() !== "").map((t) => {
|
|
1004
|
+
const [r, n] = t.split("=").map((a) => a.trim());
|
|
1005
|
+
return n.toLowerCase() === "true" ? [r, !0] : n.toLowerCase() === "false" ? [r, !1] : isNaN(Number(n)) ? [r, n] : [r, Number(n)];
|
|
813
1006
|
});
|
|
814
1007
|
return Object.fromEntries(e);
|
|
815
1008
|
}
|
|
816
|
-
function
|
|
1009
|
+
function vt(i, e, t = {}) {
|
|
817
1010
|
var o;
|
|
818
|
-
const [r,
|
|
819
|
-
e: for (const
|
|
820
|
-
const { fragments:
|
|
821
|
-
if (!(((o =
|
|
1011
|
+
const [r, n] = e.split("?"), a = ve(r);
|
|
1012
|
+
e: for (const p of i) {
|
|
1013
|
+
const { fragments: l } = p;
|
|
1014
|
+
if (!(((o = l[l.length - 1]) == null ? void 0 : o.type) === 3) && l.length !== a.length || t.willMatch && !t.willMatch(p))
|
|
822
1015
|
continue e;
|
|
823
|
-
const
|
|
824
|
-
t: for (let
|
|
825
|
-
const
|
|
826
|
-
if (
|
|
1016
|
+
const m = [];
|
|
1017
|
+
t: for (let u = 0; u < l.length; u++) {
|
|
1018
|
+
const y = a[u], k = l[u];
|
|
1019
|
+
if (y == null && k.type !== 3)
|
|
827
1020
|
continue e;
|
|
828
|
-
switch (
|
|
1021
|
+
switch (k.type) {
|
|
829
1022
|
case 1:
|
|
830
|
-
if (
|
|
831
|
-
|
|
1023
|
+
if (k.name.toLowerCase() === y.toLowerCase()) {
|
|
1024
|
+
m.push(k);
|
|
832
1025
|
break;
|
|
833
1026
|
} else
|
|
834
1027
|
continue e;
|
|
835
1028
|
case 2:
|
|
836
|
-
|
|
1029
|
+
m.push({ ...k, value: y });
|
|
837
1030
|
break;
|
|
838
1031
|
case 3:
|
|
839
|
-
|
|
1032
|
+
m.push({ ...k, value: a.slice(u).join("/") });
|
|
840
1033
|
break t;
|
|
841
1034
|
case 4:
|
|
842
|
-
if (isNaN(Number(
|
|
1035
|
+
if (isNaN(Number(y)))
|
|
843
1036
|
continue e;
|
|
844
|
-
|
|
1037
|
+
m.push({ ...k, value: Number(y) });
|
|
845
1038
|
break;
|
|
846
1039
|
default:
|
|
847
|
-
throw new Error(`Unknown fragment type: ${
|
|
1040
|
+
throw new Error(`Unknown fragment type: ${k.type}`);
|
|
848
1041
|
}
|
|
849
1042
|
}
|
|
850
|
-
const
|
|
851
|
-
for (const
|
|
852
|
-
|
|
1043
|
+
const g = {};
|
|
1044
|
+
for (const u of m)
|
|
1045
|
+
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
1046
|
return {
|
|
854
|
-
path: "/" +
|
|
855
|
-
pattern: "/" +
|
|
856
|
-
params:
|
|
857
|
-
query:
|
|
858
|
-
meta:
|
|
1047
|
+
path: "/" + m.map((u) => u.value).join("/"),
|
|
1048
|
+
pattern: "/" + l.map((u) => u.type === 2 ? `{${u.name}}` : u.type === 4 ? `{#${u.name}}` : u.name).join("/"),
|
|
1049
|
+
params: g,
|
|
1050
|
+
query: ut(n),
|
|
1051
|
+
meta: p.meta
|
|
859
1052
|
};
|
|
860
1053
|
}
|
|
861
1054
|
}
|
|
862
|
-
function
|
|
863
|
-
const e = [], t = [], r = [],
|
|
864
|
-
for (const o of
|
|
865
|
-
const { fragments:
|
|
866
|
-
|
|
867
|
-
(
|
|
1055
|
+
function or(i) {
|
|
1056
|
+
const e = [], t = [], r = [], n = [];
|
|
1057
|
+
for (const o of i) {
|
|
1058
|
+
const { fragments: p } = o;
|
|
1059
|
+
p.some(
|
|
1060
|
+
(l) => l.type === 3
|
|
868
1061
|
/* Wildcard */
|
|
869
|
-
) ?
|
|
870
|
-
(
|
|
1062
|
+
) ? n.push(o) : p.some(
|
|
1063
|
+
(l) => l.type === 4
|
|
871
1064
|
/* NumericParam */
|
|
872
|
-
) ? t.push(o) :
|
|
873
|
-
(
|
|
1065
|
+
) ? t.push(o) : p.some(
|
|
1066
|
+
(l) => l.type === 2
|
|
874
1067
|
/* Param */
|
|
875
1068
|
) ? r.push(o) : e.push(o);
|
|
876
1069
|
}
|
|
877
|
-
const
|
|
878
|
-
return e.sort(
|
|
1070
|
+
const a = (o, p) => o.fragments.length > p.fragments.length ? -1 : 1;
|
|
1071
|
+
return e.sort(a), t.sort(a), r.sort(a), n.sort(a), [...e, ...t, ...r, ...n];
|
|
879
1072
|
}
|
|
880
|
-
function
|
|
881
|
-
const e =
|
|
1073
|
+
function lr(i) {
|
|
1074
|
+
const e = ve(i), t = [];
|
|
882
1075
|
for (let r = 0; r < e.length; r++) {
|
|
883
|
-
const
|
|
884
|
-
if (
|
|
1076
|
+
const n = e[r];
|
|
1077
|
+
if (n === "*") {
|
|
885
1078
|
if (r !== e.length - 1)
|
|
886
|
-
throw new Error(`Wildcard must be at the end of a pattern. Received: ${
|
|
1079
|
+
throw new Error(`Wildcard must be at the end of a pattern. Received: ${i}`);
|
|
887
1080
|
t.push({
|
|
888
1081
|
type: 3,
|
|
889
1082
|
name: "*",
|
|
890
1083
|
value: null
|
|
891
1084
|
});
|
|
892
|
-
} else
|
|
893
|
-
type:
|
|
894
|
-
name:
|
|
1085
|
+
} else n.at(0) === "{" && n.at(-1) === "}" ? t.push({
|
|
1086
|
+
type: n[1] === "#" ? 4 : 2,
|
|
1087
|
+
name: n[1] === "#" ? n.slice(2, -1) : n.slice(1, -1),
|
|
895
1088
|
value: null
|
|
896
1089
|
}) : t.push({
|
|
897
1090
|
type: 1,
|
|
898
|
-
name:
|
|
899
|
-
value:
|
|
1091
|
+
name: n,
|
|
1092
|
+
value: n
|
|
900
1093
|
});
|
|
901
1094
|
}
|
|
902
1095
|
return t;
|
|
903
1096
|
}
|
|
904
|
-
|
|
905
|
-
|
|
1097
|
+
const $t = (i, e) => {
|
|
1098
|
+
if (Object.keys(i).length !== Object.keys(e).length)
|
|
1099
|
+
return !1;
|
|
1100
|
+
for (const t in i)
|
|
1101
|
+
if (i[t] !== e[t])
|
|
1102
|
+
return !1;
|
|
1103
|
+
return !0;
|
|
1104
|
+
};
|
|
1105
|
+
var Le, N, Z, Re, S, Xe, H, De, ee, te, he, fe, de, Ne, K, ht, ft;
|
|
1106
|
+
class cr {
|
|
906
1107
|
constructor(e, t) {
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
1108
|
+
h(this, K);
|
|
1109
|
+
h(this, Le);
|
|
1110
|
+
h(this, N);
|
|
1111
|
+
h(this, Z);
|
|
1112
|
+
h(this, Re, nt());
|
|
1113
|
+
h(this, S);
|
|
1114
|
+
h(this, Xe, 0);
|
|
1115
|
+
h(this, H, []);
|
|
1116
|
+
h(this, De);
|
|
1117
|
+
h(this, ee, []);
|
|
916
1118
|
// Callbacks that need to be called on unmount.
|
|
917
|
-
|
|
1119
|
+
h(this, te, []);
|
|
918
1120
|
/**
|
|
919
1121
|
* The currently matched route pattern, if any.
|
|
920
1122
|
*/
|
|
921
|
-
|
|
922
|
-
|
|
1123
|
+
P(this, "$pattern");
|
|
1124
|
+
h(this, he);
|
|
923
1125
|
/**
|
|
924
1126
|
* The current URL path.
|
|
925
1127
|
*/
|
|
926
|
-
|
|
927
|
-
|
|
1128
|
+
P(this, "$path");
|
|
1129
|
+
h(this, fe);
|
|
928
1130
|
/**
|
|
929
1131
|
* The current named path params.
|
|
930
1132
|
*/
|
|
931
|
-
|
|
932
|
-
|
|
1133
|
+
P(this, "$params");
|
|
1134
|
+
h(this, de);
|
|
933
1135
|
/**
|
|
934
1136
|
* The current query params. Changes to this object will be reflected in the URL.
|
|
935
1137
|
*/
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
const [r,
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
1138
|
+
P(this, "$query");
|
|
1139
|
+
h(this, Ne);
|
|
1140
|
+
b(this, Le, e), b(this, N, e.createLogger("dolla/router")), b(this, Z, t);
|
|
1141
|
+
const [r, n] = oe(null), [a, o] = oe(""), [p, l] = oe({}, { equals: $t }), [f, m] = oe(
|
|
1142
|
+
ut(typeof window > "u" ? "" : window.location.search ?? ""),
|
|
1143
|
+
{ equals: $t }
|
|
1144
|
+
);
|
|
1145
|
+
this.$pattern = r, b(this, he, n), this.$path = a, b(this, fe, o), this.$params = p, b(this, de, l), this.$query = f, b(this, Ne, m), e.beforeMount(() => {
|
|
1146
|
+
s(this, S) != null && (s(this, Re).watch([f], (g) => {
|
|
1147
|
+
const u = new URLSearchParams();
|
|
1148
|
+
for (const k in g)
|
|
1149
|
+
u.set(k, String(g[k]));
|
|
1150
|
+
const y = "?" + u.toString();
|
|
1151
|
+
y != s(this, S).location.search && s(this, S).replace({
|
|
1152
|
+
pathname: s(this, S).location.pathname,
|
|
1153
|
+
search: y
|
|
1154
|
+
});
|
|
1155
|
+
}), s(this, te).push(s(this, S).listen(v(this, K, ft).bind(this))), v(this, K, ft).call(this, s(this, S)), s(this, te).push(
|
|
1156
|
+
fr(s(this, Z).rootElement, (g) => {
|
|
1157
|
+
let u = g.getAttribute("href");
|
|
1158
|
+
s(this, N).info("Intercepted link click", g, u), /^https?:\/\/|^\//.test(u) || (u = ie([s(this, S).location.pathname, u])), s(this, S).push(u);
|
|
956
1159
|
})
|
|
957
|
-
),
|
|
1160
|
+
), s(this, N).info("Intercepting <a> clicks within root element:", s(this, Z).rootElement));
|
|
958
1161
|
}), e.onUnmount(() => {
|
|
959
|
-
for (;
|
|
960
|
-
|
|
1162
|
+
for (; s(this, te).length > 0; )
|
|
1163
|
+
s(this, te).pop()();
|
|
1164
|
+
s(this, Re).stopAll();
|
|
961
1165
|
});
|
|
962
1166
|
}
|
|
963
1167
|
setup(e) {
|
|
964
|
-
|
|
965
|
-
|
|
1168
|
+
if (s(this, Le).isMounted) {
|
|
1169
|
+
s(this, N).crash(
|
|
1170
|
+
new Error("Dolla is already mounted. Router setup must be called before Dolla.mount is called.")
|
|
1171
|
+
);
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
e.style === "hash" ? b(this, S, ir()) : b(this, S, sr()), b(this, ee, or(
|
|
1175
|
+
e.routes.flatMap((t) => v(this, K, ht).call(this, t)).map((t) => ({
|
|
966
1176
|
pattern: t.pattern,
|
|
967
1177
|
meta: t.meta,
|
|
968
|
-
fragments:
|
|
1178
|
+
fragments: lr(t.pattern)
|
|
969
1179
|
}))
|
|
970
1180
|
));
|
|
971
|
-
for (const t of
|
|
1181
|
+
for (const t of s(this, ee))
|
|
972
1182
|
if (t.meta.redirect) {
|
|
973
1183
|
let r;
|
|
974
|
-
if (!
|
|
975
|
-
if (r = t.meta.redirect, !
|
|
976
|
-
willMatch(
|
|
977
|
-
return
|
|
1184
|
+
if (!dt(t.meta.redirect)) if (V(t.meta.redirect)) {
|
|
1185
|
+
if (r = t.meta.redirect, !vt(s(this, ee), r, {
|
|
1186
|
+
willMatch(a) {
|
|
1187
|
+
return a !== t;
|
|
978
1188
|
}
|
|
979
1189
|
}))
|
|
980
1190
|
throw new Error(
|
|
@@ -988,33 +1198,57 @@ class Ft {
|
|
|
988
1198
|
* Navigates to another route.
|
|
989
1199
|
*
|
|
990
1200
|
* @example
|
|
991
|
-
*
|
|
992
|
-
*
|
|
1201
|
+
* Dolla.router.go("/login"); // navigate to `/login`
|
|
1202
|
+
* Dolla.router.go["/users", 215], { replace: true }); // replace current history entry with `/users/215`
|
|
993
1203
|
*/
|
|
994
1204
|
go(e, t = {}) {
|
|
1205
|
+
if (s(this, S) == null) {
|
|
1206
|
+
s(this, N).crash(
|
|
1207
|
+
new Error(
|
|
1208
|
+
"Router.go was called, but the router was never configured! Run 'Dolla.router.setup' before 'Dolla.mount' to configure routes."
|
|
1209
|
+
)
|
|
1210
|
+
);
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
995
1213
|
let r;
|
|
996
|
-
Array.isArray(e) ? r =
|
|
1214
|
+
Array.isArray(e) ? r = ie(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
1215
|
}
|
|
998
1216
|
/**
|
|
999
1217
|
* Navigate backward. Pass a number of steps to hit the back button that many times.
|
|
1000
1218
|
*/
|
|
1001
1219
|
back(e = 1) {
|
|
1002
|
-
|
|
1220
|
+
if (s(this, S) == null) {
|
|
1221
|
+
s(this, N).crash(
|
|
1222
|
+
new Error(
|
|
1223
|
+
"Router.back was called, but the router was never configured! Run 'Dolla.router.setup' before 'Dolla.mount' to configure routes."
|
|
1224
|
+
)
|
|
1225
|
+
);
|
|
1226
|
+
return;
|
|
1227
|
+
}
|
|
1228
|
+
s(this, S).go(-e);
|
|
1003
1229
|
}
|
|
1004
1230
|
/**
|
|
1005
1231
|
* Navigate forward. Pass a number of steps to hit the forward button that many times.
|
|
1006
1232
|
*/
|
|
1007
1233
|
forward(e = 1) {
|
|
1008
|
-
|
|
1234
|
+
if (s(this, S) == null) {
|
|
1235
|
+
s(this, N).crash(
|
|
1236
|
+
new Error(
|
|
1237
|
+
"Router.forward was called, but the router was never configured! Run 'Dolla.router.setup' before 'Dolla.mount' to configure routes."
|
|
1238
|
+
)
|
|
1239
|
+
);
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
s(this, S).go(e);
|
|
1009
1243
|
}
|
|
1010
1244
|
}
|
|
1011
|
-
|
|
1245
|
+
Le = new WeakMap(), N = new WeakMap(), Z = new WeakMap(), Re = new WeakMap(), S = new WeakMap(), Xe = new WeakMap(), H = new WeakMap(), De = new WeakMap(), ee = new WeakMap(), te = new WeakMap(), he = new WeakMap(), fe = new WeakMap(), de = new WeakMap(), Ne = new WeakMap(), K = new WeakSet(), /**
|
|
1012
1246
|
* Parses a route definition object into a set of matchable routes.
|
|
1013
1247
|
*
|
|
1014
1248
|
* @param route - Route config object.
|
|
1015
1249
|
* @param layers - Array of parent layers. Passed when this function calls itself on nested routes.
|
|
1016
1250
|
*/
|
|
1017
|
-
|
|
1251
|
+
ht = function(e, t = [], r = []) {
|
|
1018
1252
|
if (!(typeof e == "object" && !Array.isArray(e)) || typeof e.path != "string")
|
|
1019
1253
|
throw new TypeError(`Route configs must be objects with a 'path' string property. Got: ${e}`);
|
|
1020
1254
|
if (e.redirect && e.routes)
|
|
@@ -1023,56 +1257,57 @@ Je = function(e, t = [], r = []) {
|
|
|
1023
1257
|
throw new Error("Route cannot have both a 'redirect' and a 'view'.");
|
|
1024
1258
|
if (!e.view && !e.routes && !e.redirect)
|
|
1025
1259
|
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
|
|
1260
|
+
let n = [];
|
|
1261
|
+
for (const l of t)
|
|
1262
|
+
n.push(...ve(l.path));
|
|
1263
|
+
n.push(...ve(e.path)), n[n.length - 1] === "*" && n.pop();
|
|
1264
|
+
const a = [];
|
|
1031
1265
|
if (e.redirect) {
|
|
1032
|
-
let
|
|
1033
|
-
return
|
|
1034
|
-
pattern: "/" +
|
|
1266
|
+
let l = e.redirect;
|
|
1267
|
+
return V(l) && (l = We(ie(n), l), l.startsWith("/") || (l = "/" + l)), a.push({
|
|
1268
|
+
pattern: "/" + ie([...n, ...ve(e.path)]),
|
|
1035
1269
|
meta: {
|
|
1036
|
-
redirect:
|
|
1270
|
+
redirect: l
|
|
1037
1271
|
}
|
|
1038
|
-
}),
|
|
1272
|
+
}), a;
|
|
1039
1273
|
}
|
|
1040
|
-
let o =
|
|
1274
|
+
let o = St;
|
|
1041
1275
|
if (typeof e.view == "function")
|
|
1042
1276
|
o = e.view;
|
|
1043
1277
|
else if (e.view)
|
|
1044
1278
|
throw new TypeError(`Route '${e.path}' expected a view function or undefined. Got: ${e.view}`);
|
|
1045
|
-
const
|
|
1279
|
+
const p = { id: et(this, Xe)._++, view: o };
|
|
1046
1280
|
if (e.routes)
|
|
1047
|
-
for (const
|
|
1048
|
-
|
|
1281
|
+
for (const l of e.routes)
|
|
1282
|
+
a.push(...v(this, K, ht).call(this, l, [...t, e], [...r, p]));
|
|
1049
1283
|
else
|
|
1050
|
-
|
|
1051
|
-
pattern: parent ?
|
|
1284
|
+
a.push({
|
|
1285
|
+
pattern: parent ? ie([...t.map((l) => l.path), e.path]) : e.path,
|
|
1052
1286
|
meta: {
|
|
1053
1287
|
pattern: e.path,
|
|
1054
|
-
layers: [...r,
|
|
1288
|
+
layers: [...r, p],
|
|
1055
1289
|
beforeMatch: e.beforeMatch
|
|
1056
1290
|
}
|
|
1057
1291
|
});
|
|
1058
|
-
return
|
|
1059
|
-
},
|
|
1060
|
-
e.search !==
|
|
1061
|
-
const t =
|
|
1292
|
+
return a;
|
|
1293
|
+
}, ft = async function({ location: e }) {
|
|
1294
|
+
e.search !== s(this, De) && (b(this, De, e.search), s(this, Ne).call(this, ut(e.search)));
|
|
1295
|
+
const t = vt(s(this, ee), e.pathname);
|
|
1062
1296
|
if (!t) {
|
|
1063
|
-
|
|
1297
|
+
s(this, he).call(this, null), s(this, fe).call(this, e.pathname), s(this, de).call(this, {
|
|
1064
1298
|
wildcard: e.pathname
|
|
1065
1299
|
});
|
|
1066
1300
|
return;
|
|
1067
1301
|
}
|
|
1068
1302
|
if (t.meta.beforeMatch && await t.meta.beforeMatch({
|
|
1303
|
+
// TODO: Allow setting context variables from here.
|
|
1069
1304
|
redirect: (r) => {
|
|
1070
1305
|
throw new Error("Redirect not yet implemented.");
|
|
1071
1306
|
}
|
|
1072
|
-
}),
|
|
1307
|
+
}), t.meta.redirect != null)
|
|
1073
1308
|
if (typeof t.meta.redirect == "string") {
|
|
1074
|
-
const r =
|
|
1075
|
-
|
|
1309
|
+
const r = dr(t.meta.redirect, t.params);
|
|
1310
|
+
s(this, N).info(`↩️ redirecting from '${t.path}' to '${r}'`), s(this, S).replace(r);
|
|
1076
1311
|
} else if (typeof t.meta.redirect == "function") {
|
|
1077
1312
|
const r = {
|
|
1078
1313
|
path: t.path,
|
|
@@ -1080,86 +1315,94 @@ Je = function(e, t = [], r = []) {
|
|
|
1080
1315
|
params: t.params,
|
|
1081
1316
|
query: t.query
|
|
1082
1317
|
};
|
|
1083
|
-
let
|
|
1084
|
-
if (typeof
|
|
1318
|
+
let n = await t.meta.redirect(r);
|
|
1319
|
+
if (typeof n != "string")
|
|
1085
1320
|
throw new Error("Redirect function must return a path to redirect to.");
|
|
1086
|
-
|
|
1321
|
+
n.startsWith("/") || (n = We(t.path, n)), s(this, N).info(`Redirecting to: '${n}'`), s(this, S).replace(n);
|
|
1087
1322
|
} else
|
|
1088
1323
|
throw new TypeError("Redirect must either be a path string or a function.");
|
|
1089
|
-
else if (
|
|
1090
|
-
|
|
1324
|
+
else if (s(this, N).info(`📍 navigating to '${t.path}'`), s(this, fe).call(this, t.path), s(this, de).call(this, t.params), t.pattern !== this.$pattern.get()) {
|
|
1325
|
+
s(this, he).call(this, t.pattern);
|
|
1091
1326
|
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()
|
|
1327
|
+
for (let n = 0; n < r.length; n++) {
|
|
1328
|
+
const a = r[n], o = s(this, H)[n];
|
|
1329
|
+
if ((o == null ? void 0 : o.id) !== a.id) {
|
|
1330
|
+
b(this, H, s(this, H).slice(0, n));
|
|
1331
|
+
const p = s(this, H).at(-1);
|
|
1332
|
+
o && o.node.isMounted && o.node.unmount(!1);
|
|
1333
|
+
let l;
|
|
1334
|
+
p ? l = p.node.setChildView(a.view) : l = s(this, Z).rootView.setChildView(a.view), s(this, H).push({ id: a.id, node: l });
|
|
1098
1335
|
}
|
|
1099
1336
|
}
|
|
1100
1337
|
}
|
|
1101
1338
|
};
|
|
1102
|
-
const
|
|
1103
|
-
function
|
|
1104
|
-
function r(
|
|
1105
|
-
return !
|
|
1339
|
+
const ur = /(noopener|noreferrer) (noopener|noreferrer)/, hr = /^[\w-_]+:/;
|
|
1340
|
+
function fr(i, e, t = window) {
|
|
1341
|
+
function r(a) {
|
|
1342
|
+
return !a || a === i ? null : a.localName !== "a" || a.href === void 0 ? r(a.parentNode) : a;
|
|
1106
1343
|
}
|
|
1107
|
-
function
|
|
1108
|
-
if (
|
|
1344
|
+
function n(a) {
|
|
1345
|
+
if (a.button && a.button !== 0 || a.ctrlKey || a.metaKey || a.altKey || a.shiftKey || a.defaultPrevented)
|
|
1109
1346
|
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" &&
|
|
1347
|
+
const o = r(a.target);
|
|
1348
|
+
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
1349
|
}
|
|
1113
|
-
return
|
|
1114
|
-
|
|
1350
|
+
return i.addEventListener("click", n), function() {
|
|
1351
|
+
i.removeEventListener("click", n);
|
|
1115
1352
|
};
|
|
1116
1353
|
}
|
|
1117
|
-
function
|
|
1354
|
+
function dr(i, e) {
|
|
1118
1355
|
for (const t in e) {
|
|
1119
1356
|
const r = e[t].toString();
|
|
1120
|
-
|
|
1357
|
+
i = i.replace(`{${t}}`, r).replace(`{#${t}}`, r);
|
|
1121
1358
|
}
|
|
1122
|
-
return
|
|
1359
|
+
return i;
|
|
1123
1360
|
}
|
|
1124
|
-
var
|
|
1125
|
-
class
|
|
1361
|
+
var W, je, B, re, Te, Me, qe, Fe, Ae, _e, G, O, z;
|
|
1362
|
+
class pr {
|
|
1126
1363
|
constructor() {
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1364
|
+
P(this, "http");
|
|
1365
|
+
P(this, "i18n");
|
|
1366
|
+
P(this, "render");
|
|
1367
|
+
P(this, "router");
|
|
1368
|
+
h(this, W, !1);
|
|
1369
|
+
h(this, je, "production");
|
|
1370
|
+
h(this, B);
|
|
1371
|
+
h(this, re);
|
|
1372
|
+
h(this, Te, Gt);
|
|
1373
|
+
h(this, Me, nt());
|
|
1374
|
+
h(this, qe, []);
|
|
1375
|
+
h(this, Fe, []);
|
|
1376
|
+
h(this, Ae, []);
|
|
1377
|
+
h(this, _e, []);
|
|
1378
|
+
h(this, G, {
|
|
1379
|
+
root: this,
|
|
1380
|
+
data: {}
|
|
1381
|
+
});
|
|
1382
|
+
h(this, O, {
|
|
1141
1383
|
info: "development",
|
|
1142
1384
|
log: "development",
|
|
1143
1385
|
warn: "development",
|
|
1144
1386
|
error: !0
|
|
1145
1387
|
});
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1388
|
+
h(this, z, wt("*,-dolla/*"));
|
|
1389
|
+
P(this, "watch", s(this, Me).watch);
|
|
1390
|
+
P(this, "createState", oe);
|
|
1391
|
+
P(this, "createSettableState", qt);
|
|
1392
|
+
P(this, "toSettableState", Ft);
|
|
1393
|
+
P(this, "toState", At);
|
|
1394
|
+
P(this, "valueOf", _t);
|
|
1395
|
+
P(this, "derive", be);
|
|
1396
|
+
P(this, "createWatcher", nt);
|
|
1397
|
+
P(this, "createRef", Ct);
|
|
1398
|
+
P(this, "isRef", Vt);
|
|
1156
1399
|
const e = this;
|
|
1157
|
-
this.http = new
|
|
1400
|
+
this.http = new zt(), this.i18n = new tr(this), this.render = new nr(this), this.router = new cr(this, {
|
|
1158
1401
|
get rootElement() {
|
|
1159
|
-
return
|
|
1402
|
+
return s(e, B);
|
|
1160
1403
|
},
|
|
1161
1404
|
get rootView() {
|
|
1162
|
-
return
|
|
1405
|
+
return s(e, re);
|
|
1163
1406
|
}
|
|
1164
1407
|
});
|
|
1165
1408
|
}
|
|
@@ -1167,47 +1410,65 @@ class Kt {
|
|
|
1167
1410
|
* True when the app is connected to a DOM node and displayed to the user.
|
|
1168
1411
|
*/
|
|
1169
1412
|
get isMounted() {
|
|
1170
|
-
return
|
|
1413
|
+
return s(this, W);
|
|
1171
1414
|
}
|
|
1172
1415
|
/**
|
|
1173
1416
|
* Get the current environment that this app is running in.
|
|
1174
1417
|
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
1175
1418
|
*/
|
|
1176
1419
|
getEnv() {
|
|
1177
|
-
return
|
|
1420
|
+
return s(this, je);
|
|
1178
1421
|
}
|
|
1179
1422
|
/**
|
|
1180
1423
|
* Sets the environment that this app is running in.
|
|
1181
1424
|
* Environment affects which log messages will print and how much debugging info is included in the DOM.
|
|
1182
1425
|
*/
|
|
1183
1426
|
setEnv(e) {
|
|
1184
|
-
|
|
1427
|
+
b(this, je, e);
|
|
1185
1428
|
}
|
|
1186
1429
|
/**
|
|
1187
1430
|
* Sets the view that will be shown when the `crash` method is called on any logger.
|
|
1188
1431
|
* When a crash is reported the app will be unmounted and replaced with this crash page.
|
|
1189
1432
|
*/
|
|
1190
1433
|
setCrashView(e) {
|
|
1191
|
-
|
|
1434
|
+
b(this, Te, e);
|
|
1435
|
+
}
|
|
1436
|
+
/**
|
|
1437
|
+
* Sets a context variable and returns its value. Context variables are accessible on the app and in child views.
|
|
1438
|
+
*/
|
|
1439
|
+
set(e, t) {
|
|
1440
|
+
return s(this, G).data[e] = t, t;
|
|
1441
|
+
}
|
|
1442
|
+
/**
|
|
1443
|
+
* Gets the value of a context variable. Returns null if the variable is not set.
|
|
1444
|
+
*/
|
|
1445
|
+
get(e) {
|
|
1446
|
+
return s(this, G).data[e] ?? null;
|
|
1447
|
+
}
|
|
1448
|
+
/**
|
|
1449
|
+
* Returns an object of all context variables stored at the app level.
|
|
1450
|
+
*/
|
|
1451
|
+
getAll() {
|
|
1452
|
+
return { ...s(this, G).data };
|
|
1192
1453
|
}
|
|
1193
1454
|
async mount(e, t) {
|
|
1194
|
-
if (
|
|
1455
|
+
if (s(this, W))
|
|
1195
1456
|
throw new Error("Dolla is already mounted.");
|
|
1196
|
-
if (
|
|
1197
|
-
const
|
|
1198
|
-
|
|
1457
|
+
if (V(e)) {
|
|
1458
|
+
const n = document.querySelector(e);
|
|
1459
|
+
yt(HTMLElement, n, `Selector '${e}' did not match any element.`), b(this, B, n);
|
|
1199
1460
|
} else
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
for (const
|
|
1204
|
-
|
|
1461
|
+
yt(HTMLElement, e, "Expected an HTML element or a selector string. Got type: %t, value: %v"), b(this, B, e);
|
|
1462
|
+
const r = It(t ?? St);
|
|
1463
|
+
b(this, re, this.constructView(r.type, r.props)), await Promise.all(s(this, qe).map((n) => n())), s(this, re).mount(s(this, B)), b(this, W, !0);
|
|
1464
|
+
for (const n of s(this, Fe))
|
|
1465
|
+
n();
|
|
1205
1466
|
}
|
|
1206
1467
|
async unmount() {
|
|
1207
1468
|
var e;
|
|
1208
|
-
if (
|
|
1209
|
-
await Promise.all(
|
|
1210
|
-
for (const t of
|
|
1469
|
+
if (s(this, W)) {
|
|
1470
|
+
await Promise.all(s(this, Ae).map((t) => t())), (e = s(this, re)) == null || e.unmount(!1), s(this, Me).stopAll(), b(this, W, !1);
|
|
1471
|
+
for (const t of s(this, _e))
|
|
1211
1472
|
t();
|
|
1212
1473
|
}
|
|
1213
1474
|
}
|
|
@@ -1216,26 +1477,26 @@ class Kt {
|
|
|
1216
1477
|
* it will be awaited before mounting finishes. Use this to perform initial setup before the app is displayed to the user.
|
|
1217
1478
|
*/
|
|
1218
1479
|
beforeMount(e) {
|
|
1219
|
-
|
|
1480
|
+
s(this, qe).push(e);
|
|
1220
1481
|
}
|
|
1221
1482
|
/**
|
|
1222
1483
|
* Registers a `callback` to run after the app is mounted.
|
|
1223
1484
|
*/
|
|
1224
1485
|
onMount(e) {
|
|
1225
|
-
|
|
1486
|
+
s(this, Fe).push(e);
|
|
1226
1487
|
}
|
|
1227
1488
|
/**
|
|
1228
1489
|
* Registers a `callback` to run after `Dolla.unmount` is called, before the app is unmounted. If `callback` returns a Promise,
|
|
1229
1490
|
* it will be awaited before unmounting finishes. Use this to perform cleanup.
|
|
1230
1491
|
*/
|
|
1231
1492
|
beforeUnmount(e) {
|
|
1232
|
-
|
|
1493
|
+
s(this, Ae).push(e);
|
|
1233
1494
|
}
|
|
1234
1495
|
/**
|
|
1235
1496
|
* Registers a `callback` to run after the app is unmounted.
|
|
1236
1497
|
*/
|
|
1237
1498
|
onUnmount(e) {
|
|
1238
|
-
|
|
1499
|
+
s(this, _e).push(e);
|
|
1239
1500
|
}
|
|
1240
1501
|
/**
|
|
1241
1502
|
* Update log type toggles. Values that are not passed will remain unchanged.
|
|
@@ -1243,26 +1504,28 @@ class Kt {
|
|
|
1243
1504
|
setLoggles(e) {
|
|
1244
1505
|
for (const t in e) {
|
|
1245
1506
|
const r = e[t];
|
|
1246
|
-
r && (
|
|
1507
|
+
r && (s(this, O)[t] = r);
|
|
1247
1508
|
}
|
|
1248
1509
|
}
|
|
1249
1510
|
setLogFilter(e) {
|
|
1250
|
-
|
|
1511
|
+
b(this, z, wt(e));
|
|
1251
1512
|
}
|
|
1252
1513
|
createLogger(e, t) {
|
|
1253
|
-
const r =
|
|
1514
|
+
const r = (t == null ? void 0 : t.console) ?? Ut(), n = this;
|
|
1254
1515
|
return {
|
|
1516
|
+
setName(a) {
|
|
1517
|
+
return e = a, this;
|
|
1518
|
+
},
|
|
1255
1519
|
get info() {
|
|
1256
|
-
var
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
return Oe;
|
|
1520
|
+
var a;
|
|
1521
|
+
if (s(n, O).info === !1 || V(s(n, O).info) && s(n, O).info !== n.getEnv() || !s(a = n, z).call(a, e))
|
|
1522
|
+
return Ce;
|
|
1260
1523
|
{
|
|
1261
|
-
let
|
|
1262
|
-
return t != null && t.uid ?
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
`color:${
|
|
1524
|
+
let o = `%c${e}`;
|
|
1525
|
+
return t != null && t.uid ? o += ` %c[uid: %c${t.uid}%c]` : o += "%c%c%c", r.info.bind(
|
|
1526
|
+
r,
|
|
1527
|
+
o,
|
|
1528
|
+
`color:${Ve(o)};font-weight:bold`,
|
|
1266
1529
|
"color:#777",
|
|
1267
1530
|
"color:#aaa",
|
|
1268
1531
|
"color:#777"
|
|
@@ -1270,16 +1533,15 @@ class Kt {
|
|
|
1270
1533
|
}
|
|
1271
1534
|
},
|
|
1272
1535
|
get log() {
|
|
1273
|
-
var
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
return Oe;
|
|
1536
|
+
var a;
|
|
1537
|
+
if (s(n, O).log === !1 || V(s(n, O).log) && s(n, O).log !== n.getEnv() || !s(a = n, z).call(a, e))
|
|
1538
|
+
return Ce;
|
|
1277
1539
|
{
|
|
1278
|
-
let
|
|
1279
|
-
return t != null && t.uid ?
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
`color:${
|
|
1540
|
+
let o = `%c${e}`;
|
|
1541
|
+
return t != null && t.uid ? o += ` %c[uid: %c${t.uid}%c]` : o += "%c%c%c", r.log.bind(
|
|
1542
|
+
r,
|
|
1543
|
+
o,
|
|
1544
|
+
`color:${Ve(o)};font-weight:bold`,
|
|
1283
1545
|
"color:#777",
|
|
1284
1546
|
"color:#aaa",
|
|
1285
1547
|
"color:#777"
|
|
@@ -1287,16 +1549,15 @@ class Kt {
|
|
|
1287
1549
|
}
|
|
1288
1550
|
},
|
|
1289
1551
|
get warn() {
|
|
1290
|
-
var
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
return Oe;
|
|
1552
|
+
var a;
|
|
1553
|
+
if (s(n, O).warn === !1 || V(s(n, O).warn) && s(n, O).warn !== n.getEnv() || !s(a = n, z).call(a, e))
|
|
1554
|
+
return Ce;
|
|
1294
1555
|
{
|
|
1295
|
-
let
|
|
1296
|
-
return t != null && t.uid ?
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
`color:${
|
|
1556
|
+
let o = `%c${e}`;
|
|
1557
|
+
return t != null && t.uid ? o += ` %c[uid: %c${t.uid}%c]` : o += "%c%c%c", r.warn.bind(
|
|
1558
|
+
r,
|
|
1559
|
+
o,
|
|
1560
|
+
`color:${Ve(o)};font-weight:bold`,
|
|
1300
1561
|
"color:#777",
|
|
1301
1562
|
"color:#aaa",
|
|
1302
1563
|
"color:#777"
|
|
@@ -1304,28 +1565,27 @@ class Kt {
|
|
|
1304
1565
|
}
|
|
1305
1566
|
},
|
|
1306
1567
|
get error() {
|
|
1307
|
-
var
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
return Oe;
|
|
1568
|
+
var a;
|
|
1569
|
+
if (s(n, O).error === !1 || V(s(n, O).error) && s(n, O).error !== n.getEnv() || !s(a = n, z).call(a, e))
|
|
1570
|
+
return Ce;
|
|
1311
1571
|
{
|
|
1312
|
-
let
|
|
1313
|
-
return t != null && t.uid ?
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
`color:${
|
|
1572
|
+
let o = `%c${e}`;
|
|
1573
|
+
return t != null && t.uid ? o += ` %c[uid: %c${t.uid}%c]` : o += "%c%c%c", r.error.bind(
|
|
1574
|
+
r,
|
|
1575
|
+
o,
|
|
1576
|
+
`color:${Ve(o)};font-weight:bold`,
|
|
1317
1577
|
"color:#777",
|
|
1318
1578
|
"color:#aaa",
|
|
1319
1579
|
"color:#777"
|
|
1320
1580
|
);
|
|
1321
1581
|
}
|
|
1322
1582
|
},
|
|
1323
|
-
crash(
|
|
1324
|
-
throw
|
|
1325
|
-
error:
|
|
1326
|
-
loggerName:
|
|
1583
|
+
crash(a) {
|
|
1584
|
+
throw n.isMounted && (n.unmount(), n.constructView(s(n, Te), {
|
|
1585
|
+
error: a,
|
|
1586
|
+
loggerName: e,
|
|
1327
1587
|
uid: t == null ? void 0 : t.uid
|
|
1328
|
-
}).mount(
|
|
1588
|
+
}).mount(s(n, B))), a;
|
|
1329
1589
|
}
|
|
1330
1590
|
};
|
|
1331
1591
|
}
|
|
@@ -1333,34 +1593,41 @@ class Kt {
|
|
|
1333
1593
|
*
|
|
1334
1594
|
*/
|
|
1335
1595
|
constructView(e, t, r = []) {
|
|
1336
|
-
return
|
|
1596
|
+
return new Ht(s(this, G), e, t, r);
|
|
1337
1597
|
}
|
|
1338
1598
|
/**
|
|
1339
1599
|
*
|
|
1340
1600
|
*/
|
|
1341
1601
|
constructMarkup(e) {
|
|
1342
|
-
return
|
|
1602
|
+
return Wt(Bt(s(this, G), e));
|
|
1343
1603
|
}
|
|
1344
1604
|
}
|
|
1345
|
-
|
|
1346
|
-
const
|
|
1605
|
+
W = new WeakMap(), je = new WeakMap(), B = new WeakMap(), re = new WeakMap(), Te = new WeakMap(), Me = new WeakMap(), qe = new WeakMap(), Fe = new WeakMap(), Ae = new WeakMap(), _e = new WeakMap(), G = new WeakMap(), O = new WeakMap(), z = new WeakMap();
|
|
1606
|
+
const Et = new pr(), yr = Et.i18n.t.bind(Et.i18n);
|
|
1607
|
+
function br(i) {
|
|
1608
|
+
typeof window < "u" && (window.DOLLA_DEV_DEBUG = i);
|
|
1609
|
+
}
|
|
1610
|
+
function vr() {
|
|
1611
|
+
return typeof window < "u" ? window.DOLLA_DEV_DEBUG === !0 : !1;
|
|
1612
|
+
}
|
|
1347
1613
|
export {
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1614
|
+
jt as cond,
|
|
1615
|
+
It as createMarkup,
|
|
1616
|
+
Ct as createRef,
|
|
1617
|
+
qt as createSettableState,
|
|
1618
|
+
kr as createSetter,
|
|
1619
|
+
oe as createState,
|
|
1620
|
+
Et as default,
|
|
1621
|
+
be as derive,
|
|
1622
|
+
vr as getDevDebug,
|
|
1623
|
+
mt as html,
|
|
1624
|
+
Vt as isRef,
|
|
1625
|
+
Sr as portal,
|
|
1626
|
+
Pr as repeat,
|
|
1627
|
+
br as setDevDebug,
|
|
1628
|
+
yr as t,
|
|
1629
|
+
Ft as toSettableState,
|
|
1630
|
+
At as toState,
|
|
1631
|
+
_t as valueOf
|
|
1365
1632
|
};
|
|
1366
1633
|
//# sourceMappingURL=index.js.map
|