@manyducks.co/dolla 2.0.0-alpha.28 → 2.0.0-alpha.29

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/dist/index.js CHANGED
@@ -3,8 +3,8 @@ var Ie = (o) => {
3
3
  throw TypeError(o);
4
4
  };
5
5
  var it = (o, e, t) => e in o ? nt(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
6
- var d = (o, e, t) => it(o, typeof e != "symbol" ? e + "" : e, t), xe = (o, e, t) => e.has(o) || Ie("Cannot " + t);
7
- var i = (o, e, t) => (xe(o, e, "read from private field"), t ? t.call(o) : e.get(o)), l = (o, e, t) => e.has(o) ? Ie("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(o) : e.set(o, t), m = (o, e, t, s) => (xe(o, e, "write to private field"), s ? s.call(o, t) : e.set(o, t), t), u = (o, e, t) => (xe(o, e, "access private method"), t);
6
+ var d = (o, e, t) => it(o, typeof e != "symbol" ? e + "" : e, t), Me = (o, e, t) => e.has(o) || Ie("Cannot " + t);
7
+ var i = (o, e, t) => (Me(o, e, "read from private field"), t ? t.call(o) : e.get(o)), l = (o, e, t) => e.has(o) ? Ie("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(o) : e.set(o, t), m = (o, e, t, s) => (Me(o, e, "write to private field"), s ? s.call(o, t) : e.set(o, t), t), u = (o, e, t) => (Me(o, e, "access private method"), t);
8
8
  var Z = (o, e, t, s) => ({
9
9
  set _(r) {
10
10
  m(o, e, r, t);
@@ -13,8 +13,8 @@ var Z = (o, e, t, s) => ({
13
13
  return i(o, e, s);
14
14
  }
15
15
  });
16
- import { i as Y, c as Ue, d as x, a as E, b as at, e as se, t as qe, f as Qe, g as ot, s as We, h as Ae, P as Je, j as Ge, k as lt, l as He, p as ht, m as Be, S as ct, n as ut, o as ft, q as dt, r as mt, u as wt, C as pt, v as gt, w as Fe, x as yt, y as ze, z as bt, A as be, B as $e, V as $t, D as vt, E as Et } from "./passthrough-1MySicTa.js";
17
- import { F as Yt, J as Zt, H as es, I as ts, G as ss } from "./passthrough-1MySicTa.js";
16
+ import { i as Y, c as Ue, d as M, a as E, b as at, e as se, t as qe, f as Qe, g as ot, s as We, h as Ae, P as Je, j as Ge, k as lt, l as He, p as ht, m as Be, S as ct, n as ut, o as ft, q as dt, r as mt, u as wt, C as pt, v as gt, w as De, x as yt, y as ze, z as bt, A as be, B as $e, V as $t, D as vt, E as Et } from "./passthrough-eH8w4zJi.js";
17
+ import { F as Yt, J as Zt, H as es, I as ts, G as ss } from "./passthrough-eH8w4zJi.js";
18
18
  var U, ke, Se, re, R, _;
19
19
  class kt {
20
20
  constructor(e) {
@@ -168,8 +168,8 @@ class Lt {
168
168
  };
169
169
  }
170
170
  }
171
- var Re, K, B, De, Xe;
172
- class Mt {
171
+ var Re, K, B, Fe, Xe;
172
+ class xt {
173
173
  constructor(e, t) {
174
174
  l(this, B);
175
175
  d(this, "dolla");
@@ -199,7 +199,7 @@ class Mt {
199
199
  }
200
200
  }
201
201
  if (e) {
202
- const t = u(this, B, De).call(this, e);
202
+ const t = u(this, B, Fe).call(this, e);
203
203
  for (const s of t)
204
204
  i(this, K).set(s[0], s[1]);
205
205
  } else
@@ -214,7 +214,7 @@ class Mt {
214
214
  return i(this, K).has(e);
215
215
  }
216
216
  }
217
- Re = new WeakMap(), K = new WeakMap(), B = new WeakSet(), De = function(e, t = []) {
217
+ Re = new WeakMap(), K = new WeakMap(), B = new WeakSet(), Fe = function(e, t = []) {
218
218
  const s = [];
219
219
  for (const r in e)
220
220
  switch (qe(e[r])) {
@@ -222,7 +222,7 @@ Re = new WeakMap(), K = new WeakMap(), B = new WeakSet(), De = function(e, t = [
222
222
  s.push([[...t, r].join("."), u(this, B, Xe).call(this, e[r])]);
223
223
  break;
224
224
  case "object":
225
- s.push(...u(this, B, De).call(this, e[r], [...t, r]));
225
+ s.push(...u(this, B, Fe).call(this, e[r], [...t, r]));
226
226
  break;
227
227
  default:
228
228
  throw new Error(
@@ -280,7 +280,7 @@ Re = new WeakMap(), K = new WeakMap(), B = new WeakSet(), De = function(e, t = [
280
280
  return a === 0 && r.length > 0 && s.segments.push({ type: 0, text: r }), s;
281
281
  };
282
282
  var ne, P, y, ie, ae, oe, le, b, Ye, Pe, Ne, Te, Ze;
283
- class xt {
283
+ class Mt {
284
284
  constructor(e) {
285
285
  l(this, b);
286
286
  l(this, ne);
@@ -302,7 +302,7 @@ class xt {
302
302
  }
303
303
  setup(e) {
304
304
  if (e.translations.forEach((t) => {
305
- i(this, y).set(t.locale, new Mt(t, i(this, ne)));
305
+ i(this, y).set(t.locale, new xt(t, i(this, ne)));
306
306
  }), e.locale && e.locale !== "auto") {
307
307
  if (!e.translations.some((s) => s.locale === e.locale))
308
308
  throw new Error(`Initial locale '${e.locale}' is not registered in the locales array.`);
@@ -355,7 +355,7 @@ class xt {
355
355
  let s = [], r = [];
356
356
  for (const n in t)
357
357
  s.push(n), r.push(t[n]);
358
- return x([this.$locale, ...r], (n, ...a) => {
358
+ return M([this.$locale, ...r], (n, ...a) => {
359
359
  if (n == null)
360
360
  return "[NO LOCALE SET]";
361
361
  const f = {};
@@ -396,7 +396,7 @@ class xt {
396
396
  * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat#options
397
397
  */
398
398
  number(e, t) {
399
- return x([this.$locale, e], (s, r) => u(this, b, Pe).call(this, r, t));
399
+ return M([this.$locale, e], (s, r) => u(this, b, Pe).call(this, r, t));
400
400
  }
401
401
  /**
402
402
  * Returns a State containing the date formatted for the current locale. Uses `Intl.DateTimeFormat` under the hood.
@@ -408,7 +408,7 @@ class xt {
408
408
  * const $formatted = Dolla.i18n.dateTime(date, { dateFormat: "short" });
409
409
  */
410
410
  dateTime(e, t) {
411
- return x([this.$locale, e], (s, r) => u(this, b, Ne).call(this, r, t));
411
+ return M([this.$locale, e], (s, r) => u(this, b, Ne).call(this, r, t));
412
412
  }
413
413
  /**
414
414
  * Returns a State containing the date formatted for the current locale. Uses `Intl.DateTimeFormat` under the hood.
@@ -420,7 +420,7 @@ class xt {
420
420
  * const $formatted = Dolla.i18n.list(list, { });
421
421
  */
422
422
  list(e, t) {
423
- return x([this.$locale, e], (s, r) => u(this, b, Te).call(this, r, t));
423
+ return M([this.$locale, e], (s, r) => u(this, b, Te).call(this, r, t));
424
424
  }
425
425
  }
426
426
  ne = new WeakMap(), P = new WeakMap(), y = new WeakMap(), ie = new WeakMap(), ae = new WeakMap(), oe = new WeakMap(), le = new WeakMap(), b = new WeakSet(), Ye = function(e, t, s) {
@@ -442,18 +442,18 @@ ne = new WeakMap(), P = new WeakMap(), y = new WeakMap(), ie = new WeakMap(), ae
442
442
  if (w.type === 0)
443
443
  f += w.text;
444
444
  else if (w.type === 1) {
445
- let v = Ft(s, w.name);
445
+ let v = Dt(s, w.name);
446
446
  const k = ((h = s.formatOverrides) == null ? void 0 : h[w.name]) ?? [...w.formats];
447
447
  w.name === "count" && k.length === 0 && k.push({ name: "number", options: {} });
448
448
  for (const c of k) {
449
- const D = i(this, ae).get(c.name);
450
- if (D == null) {
449
+ const F = i(this, ae).get(c.name);
450
+ if (F == null) {
451
451
  const S = new Error(
452
452
  `Failed to load format '${c.name}' when processing '${t}', template: ${a}`
453
453
  );
454
454
  throw i(this, P).crash(S), S;
455
455
  }
456
- v = D(e, v, c.options);
456
+ v = F(e, v, c.options);
457
457
  }
458
458
  f += v;
459
459
  }
@@ -471,7 +471,7 @@ Ze = function(e, t) {
471
471
  if (s[0] === e && at(s[1], t))
472
472
  return s[2];
473
473
  };
474
- function Ft(o, e) {
474
+ function Dt(o, e) {
475
475
  const t = String(e).split(/[\.\[\]]/).filter((r) => r.trim() !== "");
476
476
  let s = o;
477
477
  for (; t.length > 0; ) {
@@ -515,7 +515,7 @@ function ve(o, e) {
515
515
  break;
516
516
  return z([t, e]);
517
517
  }
518
- function Dt(o) {
518
+ function Ft(o) {
519
519
  if (!o) return {};
520
520
  o.startsWith("?") && (o = o.slice(1));
521
521
  const e = o.split("&").filter((t) => t.trim() !== "").map((t) => {
@@ -533,26 +533,26 @@ function et(o, e, t = {}) {
533
533
  continue e;
534
534
  const v = [];
535
535
  t: for (let c = 0; c < h.length; c++) {
536
- const D = n[c], S = h[c];
537
- if (D == null && S.type !== 3)
536
+ const F = n[c], S = h[c];
537
+ if (F == null && S.type !== 3)
538
538
  continue e;
539
539
  switch (S.type) {
540
540
  case 1:
541
- if (S.name.toLowerCase() === D.toLowerCase()) {
541
+ if (S.name.toLowerCase() === F.toLowerCase()) {
542
542
  v.push(S);
543
543
  break;
544
544
  } else
545
545
  continue e;
546
546
  case 2:
547
- v.push({ ...S, value: D });
547
+ v.push({ ...S, value: F });
548
548
  break;
549
549
  case 3:
550
550
  v.push({ ...S, value: n.slice(c).join("/") });
551
551
  break t;
552
552
  case 4:
553
- if (isNaN(Number(D)))
553
+ if (isNaN(Number(F)))
554
554
  continue e;
555
- v.push({ ...S, value: Number(D) });
555
+ v.push({ ...S, value: Number(F) });
556
556
  break;
557
557
  default:
558
558
  throw new Error(`Unknown fragment type: ${S.type}`);
@@ -565,7 +565,7 @@ function et(o, e, t = {}) {
565
565
  path: "/" + v.map((c) => c.value).join("/"),
566
566
  pattern: "/" + h.map((c) => c.type === 2 ? `{${c.name}}` : c.type === 4 ? `{#${c.name}}` : c.name).join("/"),
567
567
  params: k,
568
- query: Dt(r),
568
+ query: Ft(r),
569
569
  meta: f.meta
570
570
  };
571
571
  }
@@ -648,7 +648,7 @@ class Tt {
648
648
  * The current query params. Changes to this object will be reflected in the URL.
649
649
  */
650
650
  d(this, "$query");
651
- m(this, I, e), m(this, L, e.createLogger("Dolla.router")), [Z(this, T)._, Z(this, he)._] = Ue(), this.$pattern = x([i(this, T)], (t) => t == null ? void 0 : t.pattern), this.$path = x([i(this, T)], (t) => (t == null ? void 0 : t.path) ?? window.location.pathname), this.$params = x([i(this, T)], (t) => (t == null ? void 0 : t.params) ?? {}, { equals: We }), this.$query = x([i(this, T)], (t) => (t == null ? void 0 : t.query) ?? {}, { equals: We }), e.beforeMount(async () => {
651
+ m(this, I, e), m(this, L, e.createLogger("Dolla.router")), [Z(this, T)._, Z(this, he)._] = Ue(), this.$pattern = M([i(this, T)], (t) => t == null ? void 0 : t.pattern), this.$path = M([i(this, T)], (t) => (t == null ? void 0 : t.path) ?? window.location.pathname), this.$params = M([i(this, T)], (t) => (t == null ? void 0 : t.params) ?? {}, { equals: We }), this.$query = M([i(this, T)], (t) => (t == null ? void 0 : t.query) ?? {}, { equals: We }), e.beforeMount(async () => {
652
652
  const t = () => {
653
653
  u(this, p, ee).call(this);
654
654
  };
@@ -913,10 +913,10 @@ function qt(o) {
913
913
  </div>
914
914
  `;
915
915
  }
916
- var ce, J, C, A, G, X, Le, M, ue, F, Ve, Ee;
916
+ var ce, J, C, A, G, X, Le, x, ue, D, Ve, Ee;
917
917
  class Wt {
918
918
  constructor(e) {
919
- l(this, F);
919
+ l(this, D);
920
920
  l(this, ce);
921
921
  l(this, J);
922
922
  // Keys ensure only the most recent callback queued with a certain key
@@ -932,7 +932,7 @@ class Wt {
932
932
  // the state partially rendered for a brief second and certain elements can be seen to update after the fact.
933
933
  // But the tradeoff here is snappier navigation with possibly slightly out of date DOM updates on heavy pages.
934
934
  l(this, Le, !0);
935
- l(this, M, 0);
935
+ l(this, x, 0);
936
936
  l(this, ue, new Intl.NumberFormat("en-US", {
937
937
  maximumFractionDigits: 2,
938
938
  minimumFractionDigits: 0,
@@ -946,22 +946,22 @@ class Wt {
946
946
  * Queues a callback that runs before the next batch of writes.
947
947
  */
948
948
  read(e) {
949
- i(this, G).push(e), u(this, F, Ve).call(this);
949
+ i(this, G).push(e), u(this, D, Ve).call(this);
950
950
  }
951
951
  /**
952
952
  * Queues a callback to run in the next render batch.
953
953
  * Always put DOM mutations in a write callback when possible to help Dolla batch them efficiently.
954
954
  */
955
955
  write(e, t) {
956
- t ? i(this, C).set(t, e) : i(this, A).push(e), u(this, F, Ve).call(this);
956
+ t ? i(this, C).set(t, e) : i(this, A).push(e), u(this, D, Ve).call(this);
957
957
  }
958
958
  }
959
- ce = new WeakMap(), J = new WeakMap(), C = new WeakMap(), A = new WeakMap(), G = new WeakMap(), X = new WeakMap(), Le = new WeakMap(), M = new WeakMap(), ue = new WeakMap(), F = new WeakSet(), Ve = function() {
959
+ ce = new WeakMap(), J = new WeakMap(), C = new WeakMap(), A = new WeakMap(), G = new WeakMap(), X = new WeakMap(), Le = new WeakMap(), x = new WeakMap(), ue = new WeakMap(), D = new WeakSet(), Ve = function() {
960
960
  if (!i(this, X)) {
961
961
  m(this, X, !0);
962
962
  const e = i(this, ce).getEnv() === "development";
963
963
  queueMicrotask(() => {
964
- u(this, F, Ee).call(this, e);
964
+ u(this, D, Ee).call(this, e);
965
965
  });
966
966
  }
967
967
  }, Ee = function(e = !1) {
@@ -969,10 +969,10 @@ ce = new WeakMap(), J = new WeakMap(), C = new WeakMap(), A = new WeakMap(), G =
969
969
  let s = 0;
970
970
  const r = i(this, G).length + i(this, C).size + i(this, A).length;
971
971
  let n = 0;
972
- const a = () => (n++, s = performance.now() - t, i(this, Le) && s > 12 && n < r ? (Z(this, M)._++, e && i(this, J).warn(
973
- `⚠️ Deferring batch to next frame. Performed ${n} of ${r} batched operation${n === 1 ? "" : "s"} in ${i(this, ue).format(s)} (deferral ${i(this, M)}).`
972
+ const a = () => (n++, s = performance.now() - t, i(this, Le) && s > 12 && n < r ? (Z(this, x)._++, e && i(this, J).warn(
973
+ `⚠️ Deferring batch to next frame. Performed ${n} of ${r} batched operation${n === 1 ? "" : "s"} in ${i(this, ue).format(s)} (deferral ${i(this, x)}).`
974
974
  ), requestAnimationFrame(() => {
975
- u(this, F, Ee).call(this, e);
975
+ u(this, D, Ee).call(this, e);
976
976
  }), !0) : !1), f = [...i(this, C).entries()];
977
977
  let h, w;
978
978
  for (; w = i(this, G).shift(); )
@@ -982,12 +982,12 @@ ce = new WeakMap(), J = new WeakMap(), C = new WeakMap(), A = new WeakMap(), G =
982
982
  for (; w = i(this, A).shift(); )
983
983
  if (w(), a()) return;
984
984
  e && i(this, J)[s > 16 ? "warn" : "info"](
985
- `${s > 16 ? "⚠️ (>=16ms) " : ""}Executed ${n} operation${n === 1 ? "" : "s"} in ${i(this, ue).format(s)}${i(this, M) > 0 ? ` (after ${i(this, M)} deferral${i(this, M) === 1 ? "" : "s"})` : ""}.`
986
- ), m(this, M, 0), i(this, G).length || i(this, C).size || i(this, A).length ? queueMicrotask(() => {
987
- u(this, F, Ee).call(this, e);
985
+ `${s > 16 ? "⚠️ (>=16ms) " : ""}Executed ${n} operation${n === 1 ? "" : "s"} in ${i(this, ue).format(s)}${i(this, x) > 0 ? ` (after ${i(this, x)} deferral${i(this, x) === 1 ? "" : "s"})` : ""}.`
986
+ ), m(this, x, 0), i(this, G).length || i(this, C).size || i(this, A).length ? queueMicrotask(() => {
987
+ u(this, D, Ee).call(this, e);
988
988
  }) : m(this, X, !1);
989
989
  };
990
- var O, fe, j, H, de, me, we, pe, ge, ye, $, g, V, Me;
990
+ var O, fe, j, H, de, me, we, pe, ge, ye, $, g, V, xe;
991
991
  class At {
992
992
  constructor() {
993
993
  d(this, "batch");
@@ -1010,7 +1010,8 @@ class At {
1010
1010
  root: this,
1011
1011
  data: {},
1012
1012
  emitter: new ht(),
1013
- stores: /* @__PURE__ */ new Map()
1013
+ stores: /* @__PURE__ */ new Map(),
1014
+ viewName: "Dolla"
1014
1015
  });
1015
1016
  l(this, g, {
1016
1017
  info: "development",
@@ -1021,17 +1022,17 @@ class At {
1021
1022
  l(this, V, Be("*,-Dolla.*"));
1022
1023
  // Registration functions for modules.
1023
1024
  // All modules will be registered before mount.
1024
- l(this, Me, []);
1025
+ l(this, xe, []);
1025
1026
  d(this, "watch", i(this, me).watch);
1026
1027
  d(this, "createState", Ue);
1027
1028
  d(this, "toState", ut);
1028
1029
  d(this, "toValue", ft);
1029
1030
  d(this, "isState", dt);
1030
- d(this, "derive", x);
1031
+ d(this, "derive", M);
1031
1032
  d(this, "createWatcher", He);
1032
1033
  d(this, "createRef", mt);
1033
1034
  d(this, "isRef", wt);
1034
- this.batch = new Wt(this), this.stats = new ct(this), this.http = new kt(this), this.i18n = new xt(this), this.router = new Tt(this);
1035
+ this.batch = new Wt(this), this.stats = new ct(this), this.http = new kt(this), this.i18n = new Mt(this), this.router = new Tt(this);
1035
1036
  }
1036
1037
  /**
1037
1038
  * True when the app is connected to a DOM node and displayed to the user.
@@ -1118,7 +1119,10 @@ class At {
1118
1119
  * Attaches a new store to this context.
1119
1120
  */
1120
1121
  attachStore(e) {
1121
- e.attach(i(this, $));
1122
+ if (!e.attach(i(this, $))) {
1123
+ let s = e.name ? `'${e.name}'` : "this store";
1124
+ console.warn(`An instance of ${s} was already attached to this context.`);
1125
+ }
1122
1126
  }
1123
1127
  /**
1124
1128
  * Gets the nearest instance of a store. Throws an error if the store isn't provided higher in the tree.
@@ -1127,11 +1131,11 @@ class At {
1127
1131
  if (gt(e)) {
1128
1132
  const t = e.key, s = i(this, $).stores.get(t);
1129
1133
  if (s == null)
1130
- throw new Fe("Store not found on this context.");
1134
+ throw new De("Store not found on this context.");
1131
1135
  return s.value;
1132
- } else throw yt(e) ? new Fe(
1136
+ } else throw yt(e) ? new De(
1133
1137
  "Received a Store instance. Please pass the Store factory function to useStore without calling it."
1134
- ) : new Fe("Invalid store.");
1138
+ ) : new De("Invalid store.");
1135
1139
  }
1136
1140
  async mount(e, t) {
1137
1141
  if (i(this, O))
@@ -1142,11 +1146,11 @@ class At {
1142
1146
  } else
1143
1147
  ze(HTMLElement, e, "Expected an HTML element or a selector string. Got type: %t, value: %v"), m(this, j, e);
1144
1148
  const s = bt(t ?? Je);
1145
- m(this, H, this.constructView(s.type, s.props)), await Promise.all(i(this, Me).map((r) => r())), await Promise.all(i(this, we).map((r) => r())), i(this, H).mount(i(this, j)), m(this, O, !0);
1146
- for (const r of i(this, pe))
1147
- r();
1149
+ m(this, H, this.constructView(s.type, s.props)), await Promise.all(i(this, xe).map((r) => r())), await Promise.all(i(this, we).map((r) => r())), i(this, H).mount(i(this, j)), m(this, O, !0);
1148
1150
  for (const r of i(this, $).stores.values())
1149
1151
  r.handleMount();
1152
+ for (const r of i(this, pe))
1153
+ r();
1150
1154
  }
1151
1155
  async unmount() {
1152
1156
  var e;
@@ -1286,7 +1290,7 @@ class At {
1286
1290
  return vt(Et(i(this, $), e));
1287
1291
  }
1288
1292
  }
1289
- O = new WeakMap(), fe = new WeakMap(), j = new WeakMap(), H = new WeakMap(), de = new WeakMap(), me = new WeakMap(), we = new WeakMap(), pe = new WeakMap(), ge = new WeakMap(), ye = new WeakMap(), $ = new WeakMap(), g = new WeakMap(), V = new WeakMap(), Me = new WeakMap();
1293
+ O = new WeakMap(), fe = new WeakMap(), j = new WeakMap(), H = new WeakMap(), de = new WeakMap(), me = new WeakMap(), we = new WeakMap(), pe = new WeakMap(), ge = new WeakMap(), ye = new WeakMap(), $ = new WeakMap(), g = new WeakMap(), V = new WeakMap(), xe = new WeakMap();
1290
1294
  function Gt() {
1291
1295
  if (typeof window < "u" && window.console)
1292
1296
  return window.console;
@@ -1309,7 +1313,7 @@ export {
1309
1313
  Zt as createView,
1310
1314
  at as deepEqual,
1311
1315
  Ke as default,
1312
- x as derive,
1316
+ M as derive,
1313
1317
  Qt as getDevDebug,
1314
1318
  Ge as html,
1315
1319
  wt as isRef,