@manyducks.co/dolla 0.73.0 → 0.75.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +44 -17
- package/lib/index.js.map +2 -2
- package/lib/stores/router.d.ts +5 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -738,6 +738,9 @@ var Conditional = class {
|
|
|
738
738
|
handle.disconnect();
|
|
739
739
|
}
|
|
740
740
|
this.connectedContent = [];
|
|
741
|
+
if (this.node.parentNode == null) {
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
741
744
|
if (value && this.thenContent) {
|
|
742
745
|
this.connectedContent = renderMarkupToDOM(this.thenContent, this);
|
|
743
746
|
} else if (!value && this.elseContent) {
|
|
@@ -1573,7 +1576,6 @@ function initView(config) {
|
|
|
1573
1576
|
}
|
|
1574
1577
|
},
|
|
1575
1578
|
async setChildren(children) {
|
|
1576
|
-
console.log("setChildren", { name: ctx.name, children });
|
|
1577
1579
|
$$children.set(children);
|
|
1578
1580
|
}
|
|
1579
1581
|
};
|
|
@@ -3175,7 +3177,6 @@ function RouterStore(ctx) {
|
|
|
3175
3177
|
redirect = "/" + redirect;
|
|
3176
3178
|
}
|
|
3177
3179
|
}
|
|
3178
|
-
console.log({ parts, route, parents, layers });
|
|
3179
3180
|
routes2.push({
|
|
3180
3181
|
pattern: "/" + joinPath([...parts, ...splitPath(route.path)]),
|
|
3181
3182
|
meta: {
|
|
@@ -3219,20 +3220,19 @@ function RouterStore(ctx) {
|
|
|
3219
3220
|
if (route.meta.redirect) {
|
|
3220
3221
|
let redirectPath;
|
|
3221
3222
|
if (isFunction(route.meta.redirect)) {
|
|
3222
|
-
throw new Error(`Redirect functions are not yet supported.`);
|
|
3223
3223
|
} else if (isString(route.meta.redirect)) {
|
|
3224
3224
|
redirectPath = route.meta.redirect;
|
|
3225
|
+
const match = matchRoutes(routes, redirectPath, {
|
|
3226
|
+
willMatch(r) {
|
|
3227
|
+
return r !== route;
|
|
3228
|
+
}
|
|
3229
|
+
});
|
|
3230
|
+
if (!match) {
|
|
3231
|
+
throw new Error(`Found a redirect to an undefined URL. From '${route.pattern}' to '${route.meta.redirect}'`);
|
|
3232
|
+
}
|
|
3225
3233
|
} else {
|
|
3226
3234
|
throw new TypeError(`Expected a string or redirect function. Got: ${route.meta.redirect}`);
|
|
3227
3235
|
}
|
|
3228
|
-
const match = matchRoutes(routes, redirectPath, {
|
|
3229
|
-
willMatch(r) {
|
|
3230
|
-
return r !== route;
|
|
3231
|
-
}
|
|
3232
|
-
});
|
|
3233
|
-
if (!match) {
|
|
3234
|
-
throw new Error(`Found a redirect to an undefined URL. From '${route.pattern}' to '${route.meta.redirect}'`);
|
|
3235
|
-
}
|
|
3236
3236
|
}
|
|
3237
3237
|
}
|
|
3238
3238
|
ctx.onConnected(() => {
|
|
@@ -3260,8 +3260,10 @@ function RouterStore(ctx) {
|
|
|
3260
3260
|
ctx.onConnected(() => {
|
|
3261
3261
|
history.listen(onRouteChange);
|
|
3262
3262
|
onRouteChange(history);
|
|
3263
|
+
ctx.info("Intercepting <a> clicks within root element:", appContext.rootElement);
|
|
3263
3264
|
catchLinks(appContext.rootElement, (anchor) => {
|
|
3264
3265
|
let href = anchor.getAttribute("href");
|
|
3266
|
+
ctx.info("Intercepted link click", anchor, href);
|
|
3265
3267
|
if (!/^https?:\/\/|^\//.test(href)) {
|
|
3266
3268
|
href = joinPath([history.location.pathname, href]);
|
|
3267
3269
|
}
|
|
@@ -3326,14 +3328,25 @@ function RouterStore(ctx) {
|
|
|
3326
3328
|
ctx.info(`Matched route: '${matched.pattern}' ('${matched.path}')`);
|
|
3327
3329
|
if (matched.meta.redirect != null) {
|
|
3328
3330
|
if (typeof matched.meta.redirect === "string") {
|
|
3329
|
-
|
|
3330
|
-
for (const key in matched.params) {
|
|
3331
|
-
path = path.replace(":" + key, matched.params[key].toString());
|
|
3332
|
-
}
|
|
3331
|
+
const path = replaceParams(matched.meta.redirect, matched.params);
|
|
3333
3332
|
ctx.info(`Redirecting to: '${path}'`);
|
|
3334
3333
|
history.replace(path);
|
|
3335
3334
|
} else if (typeof matched.meta.redirect === "function") {
|
|
3336
|
-
|
|
3335
|
+
const redirectContext = {
|
|
3336
|
+
path: matched.path,
|
|
3337
|
+
pattern: matched.pattern,
|
|
3338
|
+
params: matched.params,
|
|
3339
|
+
query: matched.query
|
|
3340
|
+
};
|
|
3341
|
+
let path = await matched.meta.redirect(redirectContext);
|
|
3342
|
+
if (typeof path !== "string") {
|
|
3343
|
+
throw new Error(`Redirect function must return a path to redirect to.`);
|
|
3344
|
+
}
|
|
3345
|
+
if (!path.startsWith("/")) {
|
|
3346
|
+
path = resolvePath(matched.path, path);
|
|
3347
|
+
}
|
|
3348
|
+
ctx.info(`Redirecting to: '${path}'`);
|
|
3349
|
+
history.replace(path);
|
|
3337
3350
|
} else {
|
|
3338
3351
|
throw new TypeError(`Redirect must either be a path string or a function.`);
|
|
3339
3352
|
}
|
|
@@ -3358,7 +3371,6 @@ function RouterStore(ctx) {
|
|
|
3358
3371
|
}
|
|
3359
3372
|
if (parentLayer) {
|
|
3360
3373
|
parentLayer.handle.setChildren(rendered);
|
|
3361
|
-
ctx.log({ rendered, markup: matchedLayer.markup });
|
|
3362
3374
|
} else {
|
|
3363
3375
|
appContext.rootView.setChildren(rendered);
|
|
3364
3376
|
}
|
|
@@ -3421,6 +3433,14 @@ function RouterStore(ctx) {
|
|
|
3421
3433
|
* @param args - One or more path segments optionally followed by an options object.
|
|
3422
3434
|
*/
|
|
3423
3435
|
navigate
|
|
3436
|
+
/**
|
|
3437
|
+
* Updates a query param in place.
|
|
3438
|
+
*/
|
|
3439
|
+
// updateQuery(key: string, value: string) {},
|
|
3440
|
+
/**
|
|
3441
|
+
* Updates a route param in place.
|
|
3442
|
+
*/
|
|
3443
|
+
// updateParam(key: string, value: string) {},
|
|
3424
3444
|
};
|
|
3425
3445
|
}
|
|
3426
3446
|
var safeExternalLink = /(noopener|noreferrer) (noopener|noreferrer)/;
|
|
@@ -3454,6 +3474,13 @@ function catchLinks(root, callback, _window = window) {
|
|
|
3454
3474
|
root.removeEventListener("click", handler);
|
|
3455
3475
|
};
|
|
3456
3476
|
}
|
|
3477
|
+
function replaceParams(path, params) {
|
|
3478
|
+
for (const key in params) {
|
|
3479
|
+
const value = params[key].toString();
|
|
3480
|
+
path = path.replace(`{${key}}`, value).replace(`{#${key}}`, value);
|
|
3481
|
+
}
|
|
3482
|
+
return path;
|
|
3483
|
+
}
|
|
3457
3484
|
|
|
3458
3485
|
// src/stores/language.ts
|
|
3459
3486
|
function LanguageStore(ctx) {
|