@manyducks.co/dolla 0.69.4 → 0.69.5
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/lib/app.d.ts +0 -3
- package/lib/index.js +111 -137
- package/lib/index.js.map +4 -4
- package/lib/routing.d.ts +4 -4
- package/lib/stores/language.d.ts +2 -2
- package/lib/stores/router.d.ts +1 -1
- package/lib/views/default-crash-page.d.ts +7 -0
- package/lib/views/default-view.d.ts +2 -0
- package/package.json +1 -1
package/lib/app.d.ts
CHANGED
|
@@ -53,9 +53,6 @@ interface ConfigureContext {
|
|
|
53
53
|
type ConfigureCallback = (ctx: ConfigureContext) => void | Promise<void>;
|
|
54
54
|
export interface IApp {
|
|
55
55
|
readonly isConnected: boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Makes this store accessible from any other component in the app, except for stores registered before this one.
|
|
58
|
-
*/
|
|
59
56
|
/**
|
|
60
57
|
* Runs `callback` after app-level stores are connected to the app, but before views are connected to the DOM.
|
|
61
58
|
* Use this function to run async configuration code before displaying content to the user.
|
package/lib/index.js
CHANGED
|
@@ -2195,10 +2195,65 @@ function RenderStore(ctx) {
|
|
|
2195
2195
|
};
|
|
2196
2196
|
}
|
|
2197
2197
|
|
|
2198
|
-
// src/
|
|
2199
|
-
function
|
|
2198
|
+
// src/views/default-crash-page.ts
|
|
2199
|
+
function DefaultCrashPage({ message, error, componentName }) {
|
|
2200
|
+
return m(
|
|
2201
|
+
"div",
|
|
2202
|
+
{
|
|
2203
|
+
style: {
|
|
2204
|
+
backgroundColor: "#880000",
|
|
2205
|
+
color: "#fff",
|
|
2206
|
+
padding: "2rem",
|
|
2207
|
+
position: "fixed",
|
|
2208
|
+
inset: 0,
|
|
2209
|
+
fontSize: "20px"
|
|
2210
|
+
}
|
|
2211
|
+
},
|
|
2212
|
+
m("h1", { style: { marginBottom: "0.5rem" } }, "The app has crashed"),
|
|
2213
|
+
m(
|
|
2214
|
+
"p",
|
|
2215
|
+
{ style: { marginBottom: "0.25rem" } },
|
|
2216
|
+
m("span", { style: { fontFamily: "monospace" } }, componentName),
|
|
2217
|
+
" says:"
|
|
2218
|
+
),
|
|
2219
|
+
m(
|
|
2220
|
+
"blockquote",
|
|
2221
|
+
{
|
|
2222
|
+
style: {
|
|
2223
|
+
backgroundColor: "#991111",
|
|
2224
|
+
padding: "0.25em",
|
|
2225
|
+
borderRadius: "6px",
|
|
2226
|
+
fontFamily: "monospace",
|
|
2227
|
+
marginBottom: "1rem"
|
|
2228
|
+
}
|
|
2229
|
+
},
|
|
2230
|
+
m(
|
|
2231
|
+
"span",
|
|
2232
|
+
{
|
|
2233
|
+
style: {
|
|
2234
|
+
display: "inline-block",
|
|
2235
|
+
backgroundColor: "red",
|
|
2236
|
+
padding: "0.1em 0.4em",
|
|
2237
|
+
marginRight: "0.5em",
|
|
2238
|
+
borderRadius: "4px",
|
|
2239
|
+
fontSize: "0.9em",
|
|
2240
|
+
fontWeight: "bold"
|
|
2241
|
+
}
|
|
2242
|
+
},
|
|
2243
|
+
error.name
|
|
2244
|
+
),
|
|
2245
|
+
message
|
|
2246
|
+
),
|
|
2247
|
+
m("p", {}, "Please see the browser console for details.")
|
|
2248
|
+
);
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
// src/views/default-view.ts
|
|
2252
|
+
function DefaultView(_, ctx) {
|
|
2200
2253
|
return ctx.outlet();
|
|
2201
2254
|
}
|
|
2255
|
+
|
|
2256
|
+
// src/app.ts
|
|
2202
2257
|
function isAppOptions(value) {
|
|
2203
2258
|
return isObject(value);
|
|
2204
2259
|
}
|
|
@@ -2207,7 +2262,7 @@ function App(options) {
|
|
|
2207
2262
|
throw new TypeError(`App options must be an object. Got: ${options}`);
|
|
2208
2263
|
}
|
|
2209
2264
|
let isConnected = false;
|
|
2210
|
-
let mainView = m(options?.view ??
|
|
2265
|
+
let mainView = m(options?.view ?? DefaultView);
|
|
2211
2266
|
let configureCallback;
|
|
2212
2267
|
const settings = merge(
|
|
2213
2268
|
{
|
|
@@ -2292,12 +2347,9 @@ function App(options) {
|
|
|
2292
2347
|
// TODO: Add context methods
|
|
2293
2348
|
});
|
|
2294
2349
|
}
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
resolve2();
|
|
2299
|
-
};
|
|
2300
|
-
done();
|
|
2350
|
+
appContext.rootView.connect(appContext.rootElement);
|
|
2351
|
+
isConnected = true;
|
|
2352
|
+
resolve2();
|
|
2301
2353
|
});
|
|
2302
2354
|
}
|
|
2303
2355
|
async function disconnect() {
|
|
@@ -2324,54 +2376,6 @@ function App(options) {
|
|
|
2324
2376
|
get isConnected() {
|
|
2325
2377
|
return isConnected;
|
|
2326
2378
|
},
|
|
2327
|
-
// language(tag: string, config: LanguageConfig) {
|
|
2328
|
-
// languages.set(tag, config);
|
|
2329
|
-
//
|
|
2330
|
-
// return app;
|
|
2331
|
-
// },
|
|
2332
|
-
//
|
|
2333
|
-
// setLanguage(tag: string, fallback?: string) {
|
|
2334
|
-
// if (tag === "auto") {
|
|
2335
|
-
// let tags = [];
|
|
2336
|
-
//
|
|
2337
|
-
// if (typeof navigator === "object") {
|
|
2338
|
-
// const nav = navigator as any;
|
|
2339
|
-
//
|
|
2340
|
-
// if (nav.languages?.length > 0) {
|
|
2341
|
-
// tags.push(...nav.languages);
|
|
2342
|
-
// } else if (nav.language) {
|
|
2343
|
-
// tags.push(nav.language);
|
|
2344
|
-
// } else if (nav.browserLanguage) {
|
|
2345
|
-
// tags.push(nav.browserLanguage);
|
|
2346
|
-
// } else if (nav.userLanguage) {
|
|
2347
|
-
// tags.push(nav.userLanguage);
|
|
2348
|
-
// }
|
|
2349
|
-
// }
|
|
2350
|
-
//
|
|
2351
|
-
// for (const tag of tags) {
|
|
2352
|
-
// if (languages.has(tag)) {
|
|
2353
|
-
// // Found a matching language.
|
|
2354
|
-
// currentLanguage = tag;
|
|
2355
|
-
// return this;
|
|
2356
|
-
// }
|
|
2357
|
-
// }
|
|
2358
|
-
//
|
|
2359
|
-
// if (!currentLanguage && fallback) {
|
|
2360
|
-
// if (languages.has(fallback)) {
|
|
2361
|
-
// currentLanguage = fallback;
|
|
2362
|
-
// }
|
|
2363
|
-
// }
|
|
2364
|
-
// } else {
|
|
2365
|
-
// // Tag is the actual tag to set.
|
|
2366
|
-
// if (languages.has(tag)) {
|
|
2367
|
-
// currentLanguage = tag;
|
|
2368
|
-
// } else {
|
|
2369
|
-
// throw new Error(`Language '${tag}' has not been added to this app yet.`);
|
|
2370
|
-
// }
|
|
2371
|
-
// }
|
|
2372
|
-
//
|
|
2373
|
-
// return app;
|
|
2374
|
-
// },
|
|
2375
2379
|
configure(callback) {
|
|
2376
2380
|
if (configureCallback !== void 0) {
|
|
2377
2381
|
debugChannel.warn(`Configure callback is already defined. Only the final configure call will take effect.`);
|
|
@@ -2382,57 +2386,6 @@ function App(options) {
|
|
|
2382
2386
|
};
|
|
2383
2387
|
return app;
|
|
2384
2388
|
}
|
|
2385
|
-
function DefaultCrashPage({ message, error, componentName }) {
|
|
2386
|
-
return m(
|
|
2387
|
-
"div",
|
|
2388
|
-
{
|
|
2389
|
-
style: {
|
|
2390
|
-
backgroundColor: "#880000",
|
|
2391
|
-
color: "#fff",
|
|
2392
|
-
padding: "2rem",
|
|
2393
|
-
position: "fixed",
|
|
2394
|
-
inset: 0,
|
|
2395
|
-
fontSize: "20px"
|
|
2396
|
-
}
|
|
2397
|
-
},
|
|
2398
|
-
m("h1", { style: { marginBottom: "0.5rem" } }, "The app has crashed"),
|
|
2399
|
-
m(
|
|
2400
|
-
"p",
|
|
2401
|
-
{ style: { marginBottom: "0.25rem" } },
|
|
2402
|
-
m("span", { style: { fontFamily: "monospace" } }, componentName),
|
|
2403
|
-
" says:"
|
|
2404
|
-
),
|
|
2405
|
-
m(
|
|
2406
|
-
"blockquote",
|
|
2407
|
-
{
|
|
2408
|
-
style: {
|
|
2409
|
-
backgroundColor: "#991111",
|
|
2410
|
-
padding: "0.25em",
|
|
2411
|
-
borderRadius: "6px",
|
|
2412
|
-
fontFamily: "monospace",
|
|
2413
|
-
marginBottom: "1rem"
|
|
2414
|
-
}
|
|
2415
|
-
},
|
|
2416
|
-
m(
|
|
2417
|
-
"span",
|
|
2418
|
-
{
|
|
2419
|
-
style: {
|
|
2420
|
-
display: "inline-block",
|
|
2421
|
-
backgroundColor: "red",
|
|
2422
|
-
padding: "0.1em 0.4em",
|
|
2423
|
-
marginRight: "0.5em",
|
|
2424
|
-
borderRadius: "4px",
|
|
2425
|
-
fontSize: "0.9em",
|
|
2426
|
-
fontWeight: "bold"
|
|
2427
|
-
}
|
|
2428
|
-
},
|
|
2429
|
-
error.name
|
|
2430
|
-
),
|
|
2431
|
-
message
|
|
2432
|
-
),
|
|
2433
|
-
m("p", {}, "Please see the browser console for details.")
|
|
2434
|
-
);
|
|
2435
|
-
}
|
|
2436
2389
|
|
|
2437
2390
|
// src/views/fragment.ts
|
|
2438
2391
|
function Fragment(_, ctx) {
|
|
@@ -3122,9 +3075,7 @@ function patternToFragments(pattern) {
|
|
|
3122
3075
|
const part = parts[i];
|
|
3123
3076
|
if (part === "*") {
|
|
3124
3077
|
if (i !== parts.length - 1) {
|
|
3125
|
-
throw new Error(
|
|
3126
|
-
`Wildcard must be at the end of a pattern. Received: ${pattern}`
|
|
3127
|
-
);
|
|
3078
|
+
throw new Error(`Wildcard must be at the end of a pattern. Received: ${pattern}`);
|
|
3128
3079
|
}
|
|
3129
3080
|
fragments.push({
|
|
3130
3081
|
type: 3 /* Wildcard */,
|
|
@@ -3149,7 +3100,6 @@ function patternToFragments(pattern) {
|
|
|
3149
3100
|
}
|
|
3150
3101
|
|
|
3151
3102
|
// src/stores/router.ts
|
|
3152
|
-
var DefaultView = (_, ctx) => ctx.outlet();
|
|
3153
3103
|
function RouterStore(ctx) {
|
|
3154
3104
|
ctx.name = "dolla/router";
|
|
3155
3105
|
const { appContext, elementContext } = getStoreSecrets(ctx);
|
|
@@ -3488,37 +3438,61 @@ function LanguageStore(ctx) {
|
|
|
3488
3438
|
}
|
|
3489
3439
|
return template;
|
|
3490
3440
|
}
|
|
3491
|
-
|
|
3492
|
-
|
|
3493
|
-
|
|
3494
|
-
|
|
3495
|
-
|
|
3496
|
-
|
|
3497
|
-
|
|
3441
|
+
async function setLanguage(tag) {
|
|
3442
|
+
let realTag;
|
|
3443
|
+
if (tag === "auto") {
|
|
3444
|
+
let tags = [];
|
|
3445
|
+
if (typeof navigator === "object") {
|
|
3446
|
+
const nav = navigator;
|
|
3447
|
+
if (nav.languages?.length > 0) {
|
|
3448
|
+
tags.push(...nav.languages);
|
|
3449
|
+
} else if (nav.language) {
|
|
3450
|
+
tags.push(nav.language);
|
|
3451
|
+
} else if (nav.browserLanguage) {
|
|
3452
|
+
tags.push(nav.browserLanguage);
|
|
3453
|
+
} else if (nav.userLanguage) {
|
|
3454
|
+
tags.push(nav.userLanguage);
|
|
3455
|
+
}
|
|
3456
|
+
}
|
|
3457
|
+
for (const tag2 of tags) {
|
|
3458
|
+
if (languages.has(tag2)) {
|
|
3459
|
+
realTag = tag2;
|
|
3460
|
+
}
|
|
3461
|
+
}
|
|
3462
|
+
} else {
|
|
3463
|
+
if (languages.has(tag)) {
|
|
3464
|
+
realTag = tag;
|
|
3465
|
+
}
|
|
3466
|
+
}
|
|
3467
|
+
if (realTag == null) {
|
|
3468
|
+
const firstLanguage = ctx.options.languages[0];
|
|
3469
|
+
if (firstLanguage) {
|
|
3470
|
+
realTag = firstLanguage.name;
|
|
3471
|
+
}
|
|
3472
|
+
}
|
|
3473
|
+
if (!realTag || !languages.has(tag)) {
|
|
3474
|
+
throw new Error(`Language '${tag}' is not configured for this app.`);
|
|
3475
|
+
}
|
|
3476
|
+
const lang = languages.get(tag);
|
|
3477
|
+
try {
|
|
3478
|
+
const translation = await getTranslation(lang);
|
|
3498
3479
|
$$translation.set(translation);
|
|
3499
|
-
$$
|
|
3500
|
-
|
|
3480
|
+
$$language.set(tag);
|
|
3481
|
+
ctx.info("set language to " + tag);
|
|
3482
|
+
} catch (error) {
|
|
3483
|
+
if (error instanceof Error) {
|
|
3484
|
+
ctx.crash(error);
|
|
3485
|
+
}
|
|
3486
|
+
}
|
|
3501
3487
|
}
|
|
3488
|
+
setLanguage(ctx.options.defaultLanguage ?? "auto").then(() => {
|
|
3489
|
+
$$isLoaded.set(true);
|
|
3490
|
+
});
|
|
3502
3491
|
return {
|
|
3503
3492
|
$isLoaded: $($$isLoaded),
|
|
3504
3493
|
$currentLanguage: $($$language),
|
|
3505
3494
|
supportedLanguages: [...languages.keys()],
|
|
3506
|
-
|
|
3507
|
-
if (!languages.has(tag)) {
|
|
3508
|
-
throw new Error(`Language '${tag}' is not supported.`);
|
|
3509
|
-
}
|
|
3510
|
-
const lang = languages.get(tag);
|
|
3511
|
-
try {
|
|
3512
|
-
const translation = await getTranslation(lang);
|
|
3513
|
-
$$translation.set(translation);
|
|
3514
|
-
$$language.set(tag);
|
|
3515
|
-
ctx.info("set language to " + tag);
|
|
3516
|
-
} catch (error) {
|
|
3517
|
-
if (error instanceof Error) {
|
|
3518
|
-
ctx.crash(error);
|
|
3519
|
-
}
|
|
3520
|
-
}
|
|
3521
|
-
},
|
|
3495
|
+
setLanguage,
|
|
3522
3496
|
/**
|
|
3523
3497
|
* Returns a Readable of the translated value.
|
|
3524
3498
|
|