@manyducks.co/dolla 0.74.0 → 0.75.1

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 CHANGED
@@ -1070,16 +1070,21 @@ var HTML = class {
1070
1070
  const propStopCallbacks = [];
1071
1071
  if (styles == void 0) {
1072
1072
  element.style.cssText = "";
1073
+ } else if (typeof styles === "string") {
1074
+ element.style.cssText = styles;
1073
1075
  } else if (isReadable(styles)) {
1074
1076
  let unapply;
1075
1077
  const stop = observe(styles, (current) => {
1076
- render.update(() => {
1077
- if (isFunction(unapply)) {
1078
- unapply();
1079
- }
1080
- element.style.cssText = "";
1081
- unapply = this.applyStyles(element, current, stopCallbacks);
1082
- }, this.getUpdateKey("styles", "*"));
1078
+ render.update(
1079
+ () => {
1080
+ if (isFunction(unapply)) {
1081
+ unapply();
1082
+ }
1083
+ element.style.cssText = "";
1084
+ unapply = this.applyStyles(element, current, stopCallbacks);
1085
+ },
1086
+ this.getUpdateKey("styles", "*")
1087
+ );
1083
1088
  });
1084
1089
  stopCallbacks.push(stop);
1085
1090
  propStopCallbacks.push(stop);
@@ -1090,13 +1095,16 @@ var HTML = class {
1090
1095
  const setProperty = key.startsWith("--") ? (key2, value2) => value2 == null ? element.style.removeProperty(key2) : element.style.setProperty(key2, value2) : (key2, value2) => element.style[key2] = value2 ?? "";
1091
1096
  if (isReadable(value)) {
1092
1097
  const stop = observe(value, (current) => {
1093
- render.update(() => {
1094
- if (current != null) {
1095
- setProperty(key, current);
1096
- } else {
1097
- element.style.removeProperty(key);
1098
- }
1099
- }, this.getUpdateKey("style", key));
1098
+ render.update(
1099
+ () => {
1100
+ if (current != null) {
1101
+ setProperty(key, current);
1102
+ } else {
1103
+ element.style.removeProperty(key);
1104
+ }
1105
+ },
1106
+ this.getUpdateKey("style", key)
1107
+ );
1100
1108
  });
1101
1109
  stopCallbacks.push(stop);
1102
1110
  propStopCallbacks.push(stop);
@@ -1124,13 +1132,16 @@ var HTML = class {
1124
1132
  if (isReadable(classes)) {
1125
1133
  let unapply;
1126
1134
  const stop = observe(classes, (current) => {
1127
- render.update(() => {
1128
- if (isFunction(unapply)) {
1129
- unapply();
1130
- }
1131
- element.removeAttribute("class");
1132
- unapply = this.applyClasses(element, current, stopCallbacks);
1133
- }, this.getUpdateKey("attr", "class"));
1135
+ render.update(
1136
+ () => {
1137
+ if (isFunction(unapply)) {
1138
+ unapply();
1139
+ }
1140
+ element.removeAttribute("class");
1141
+ unapply = this.applyClasses(element, current, stopCallbacks);
1142
+ },
1143
+ this.getUpdateKey("attr", "class")
1144
+ );
1134
1145
  });
1135
1146
  stopCallbacks.push(stop);
1136
1147
  classStopCallbacks.push(stop);
@@ -1576,7 +1587,6 @@ function initView(config) {
1576
1587
  }
1577
1588
  },
1578
1589
  async setChildren(children) {
1579
- console.log("setChildren", { name: ctx.name, children });
1580
1590
  $$children.set(children);
1581
1591
  }
1582
1592
  };
@@ -3221,20 +3231,19 @@ function RouterStore(ctx) {
3221
3231
  if (route.meta.redirect) {
3222
3232
  let redirectPath;
3223
3233
  if (isFunction(route.meta.redirect)) {
3224
- throw new Error(`Redirect functions are not yet supported.`);
3225
3234
  } else if (isString(route.meta.redirect)) {
3226
3235
  redirectPath = route.meta.redirect;
3236
+ const match = matchRoutes(routes, redirectPath, {
3237
+ willMatch(r) {
3238
+ return r !== route;
3239
+ }
3240
+ });
3241
+ if (!match) {
3242
+ throw new Error(`Found a redirect to an undefined URL. From '${route.pattern}' to '${route.meta.redirect}'`);
3243
+ }
3227
3244
  } else {
3228
3245
  throw new TypeError(`Expected a string or redirect function. Got: ${route.meta.redirect}`);
3229
3246
  }
3230
- const match = matchRoutes(routes, redirectPath, {
3231
- willMatch(r) {
3232
- return r !== route;
3233
- }
3234
- });
3235
- if (!match) {
3236
- throw new Error(`Found a redirect to an undefined URL. From '${route.pattern}' to '${route.meta.redirect}'`);
3237
- }
3238
3247
  }
3239
3248
  }
3240
3249
  ctx.onConnected(() => {
@@ -3330,14 +3339,25 @@ function RouterStore(ctx) {
3330
3339
  ctx.info(`Matched route: '${matched.pattern}' ('${matched.path}')`);
3331
3340
  if (matched.meta.redirect != null) {
3332
3341
  if (typeof matched.meta.redirect === "string") {
3333
- let path = matched.meta.redirect;
3334
- for (const key in matched.params) {
3335
- path = path.replace(":" + key, matched.params[key].toString());
3336
- }
3342
+ const path = replaceParams(matched.meta.redirect, matched.params);
3337
3343
  ctx.info(`Redirecting to: '${path}'`);
3338
3344
  history.replace(path);
3339
3345
  } else if (typeof matched.meta.redirect === "function") {
3340
- throw new Error(`Redirect functions aren't implemented yet.`);
3346
+ const redirectContext = {
3347
+ path: matched.path,
3348
+ pattern: matched.pattern,
3349
+ params: matched.params,
3350
+ query: matched.query
3351
+ };
3352
+ let path = await matched.meta.redirect(redirectContext);
3353
+ if (typeof path !== "string") {
3354
+ throw new Error(`Redirect function must return a path to redirect to.`);
3355
+ }
3356
+ if (!path.startsWith("/")) {
3357
+ path = resolvePath(matched.path, path);
3358
+ }
3359
+ ctx.info(`Redirecting to: '${path}'`);
3360
+ history.replace(path);
3341
3361
  } else {
3342
3362
  throw new TypeError(`Redirect must either be a path string or a function.`);
3343
3363
  }
@@ -3424,6 +3444,14 @@ function RouterStore(ctx) {
3424
3444
  * @param args - One or more path segments optionally followed by an options object.
3425
3445
  */
3426
3446
  navigate
3447
+ /**
3448
+ * Updates a query param in place.
3449
+ */
3450
+ // updateQuery(key: string, value: string) {},
3451
+ /**
3452
+ * Updates a route param in place.
3453
+ */
3454
+ // updateParam(key: string, value: string) {},
3427
3455
  };
3428
3456
  }
3429
3457
  var safeExternalLink = /(noopener|noreferrer) (noopener|noreferrer)/;
@@ -3457,6 +3485,13 @@ function catchLinks(root, callback, _window = window) {
3457
3485
  root.removeEventListener("click", handler);
3458
3486
  };
3459
3487
  }
3488
+ function replaceParams(path, params) {
3489
+ for (const key in params) {
3490
+ const value = params[key].toString();
3491
+ path = path.replace(`{${key}}`, value).replace(`{#${key}}`, value);
3492
+ }
3493
+ return path;
3494
+ }
3460
3495
 
3461
3496
  // src/stores/language.ts
3462
3497
  function LanguageStore(ctx) {