wrec 0.22.8 → 0.22.9

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 CHANGED
@@ -29,6 +29,8 @@ For each expression, a new value is computed.
29
29
  Then wrec uses `#exprToRefsMap` to find all the references to that expression
30
30
  and updates them.
31
31
 
32
+ An architecture diagram for this flow is in [docs/how-wrec-works.md](docs/how-wrec-works.md).
33
+
32
34
  ## Releasing New Versions
33
35
 
34
36
  To release a new version of the wrec library:
package/dist/wrec.es.js CHANGED
@@ -1,8 +1,8 @@
1
1
  var B = (r) => {
2
2
  throw TypeError(r);
3
3
  };
4
- var N = (r, t, e) => t.has(r) || B("Cannot " + e);
5
- var u = (r, t, e) => (N(r, t, "read from private field"), e ? e.call(r) : t.get(r)), b = (r, t, e) => t.has(r) ? B("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, e), w = (r, t, e, s) => (N(r, t, "write to private field"), s ? s.call(r, e) : t.set(r, e), e), V = (r, t, e) => (N(r, t, "access private method"), e);
4
+ var L = (r, t, e) => t.has(r) || B("Cannot " + e);
5
+ var u = (r, t, e) => (L(r, t, "read from private field"), e ? e.call(r) : t.get(r)), b = (r, t, e) => t.has(r) ? B("Cannot add the same private member more than once") : t instanceof WeakSet ? t.add(r) : t.set(r, e), w = (r, t, e, s) => (L(r, t, "write to private field"), s ? s.call(r, e) : t.set(r, e), e), V = (r, t, e) => (L(r, t, "access private method"), e);
6
6
  import W from "xss";
7
7
  function U(r, t, e = "") {
8
8
  const s = /* @__PURE__ */ new WeakMap(), o = {
@@ -148,8 +148,8 @@ y = new WeakMap(), $ = new WeakMap(), d = new WeakMap(), v = new WeakMap(), C =
148
148
  sessionStorage.setItem("wrec-state-" + t, JSON.stringify(s));
149
149
  }
150
150
  });
151
- let F = T;
152
- P && process.env.NODE_ENV === "development" && (window.WrecState = F);
151
+ let _ = T;
152
+ P && process.env.NODE_ENV === "development" && (window.WrecState = _);
153
153
  function q(r, t) {
154
154
  let e = r;
155
155
  for (const s of t.split("."))
@@ -163,7 +163,7 @@ function ot(r, t, e) {
163
163
  c === o ? i[n] = e : i = i[n];
164
164
  });
165
165
  }
166
- const it = /* @__PURE__ */ new Set(["input", "label", "option", "th"]), J = "__WREC", X = "__";
166
+ const it = /* @__PURE__ */ new Set(["button", "input", "label", "option", "th"]), J = "__WREC", X = "__";
167
167
  function nt(r) {
168
168
  const t = {
169
169
  allowCommentTag: !0,
@@ -207,7 +207,7 @@ const rt = /* @__PURE__ */ new Set([
207
207
  "tabindex",
208
208
  "title"
209
209
  ]), ct = globalThis.HTMLElement ?? class {
210
- }, _ = globalThis.customElements ?? {
210
+ }, F = globalThis.customElements ?? {
211
211
  get: (r) => {
212
212
  },
213
213
  getName: () => "",
@@ -221,7 +221,7 @@ const rt = /* @__PURE__ */ new Set([
221
221
  };
222
222
  class E extends Error {
223
223
  }
224
- const at = /([a-zA-Z-]+)\s*:\s*([^;}]+)/g, G = "a-zA-Z_$", ft = G + "0-9", A = `[${G}][${ft}]*`, lt = /<!--\s*(.*?)\s*-->/, ht = /<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g, L = new RegExp(`^this\\.${A}$`), j = new RegExp(`this\\.${A}(\\.${A})*`, "g"), Q = new RegExp(`this\\.${A}(\\.${A})*`), ut = 5;
224
+ const at = /([a-zA-Z-]+)\s*:\s*([^;}]+)/g, G = "a-zA-Z_$", ft = G + "0-9", A = `[${G}][${ft}]*`, lt = /<!--\s*(.*?)\s*-->/, ht = /<(\w+)(?:\s[^>]*)?>((?:[^<]|<(?!\w))*?)<\/\1>/g, N = new RegExp(`^this\\.${A}$`), j = new RegExp(`this\\.${A}(\\.${A})*`, "g"), Q = new RegExp(`this\\.${A}(\\.${A})*`), ut = 5;
225
225
  function pt(r) {
226
226
  return r instanceof HTMLButtonElement || r instanceof HTMLFieldSetElement || r instanceof HTMLInputElement || r instanceof HTMLSelectElement || r instanceof HTMLTextAreaElement || r instanceof p;
227
227
  }
@@ -304,7 +304,7 @@ async function bt(r) {
304
304
  return Promise.all(
305
305
  [...t].map(
306
306
  async (s) => Promise.race([
307
- _.whenDefined(s),
307
+ F.whenDefined(s),
308
308
  e(s)
309
309
  ])
310
310
  )
@@ -352,24 +352,24 @@ class p extends ct {
352
352
  static propToExprsMap;
353
353
  static template = null;
354
354
  // This is true while the batchSet method is running.
355
- #h = !1;
355
+ #u = !1;
356
356
  // This holds the names of computed properties
357
357
  // that are currently being updated.
358
- #u = /* @__PURE__ */ new Set();
358
+ #p = /* @__PURE__ */ new Set();
359
359
  #t = this.constructor;
360
360
  // This is a map from expressions to references to them
361
361
  // which can be found in element text content,
362
362
  // attribute values, and CSS property values.
363
363
  // Each component instance needs its own map.
364
364
  #s = /* @__PURE__ */ new Map();
365
- #p = {};
365
+ #d = {};
366
366
  #i;
367
367
  // For components that set `formAssociated` to true,
368
368
  // this stores in the initial value of each property
369
369
  // in the formAssociatedCallback method
370
370
  // so they can be restored in the formResetCallback method.
371
- #d = {};
372
- #m = null;
371
+ #m = {};
372
+ #b = null;
373
373
  // This is a map from properties in this web component
374
374
  // to corresponding properties in a parent web component.
375
375
  // This must be an instance property because
@@ -377,15 +377,15 @@ class p extends ct {
377
377
  // to the properties of different parent components.
378
378
  // This is used to update a parent property
379
379
  // when the corresponding child property value changes.
380
- #b = /* @__PURE__ */ new Map();
380
+ #g = /* @__PURE__ */ new Map();
381
381
  // This is a map from component properties to state bindings.
382
382
  // It must be instance-specific because each component instance
383
383
  // can bind the same property to a different WrecState/path.
384
384
  #r = /* @__PURE__ */ new Map();
385
385
  static define(t) {
386
- if (this.elementName = t, _.get(t))
386
+ if (this.elementName = t, F.get(t))
387
387
  throw new E(`custom element ${t} is already defined`);
388
- _.define(t, this);
388
+ F.define(t, this);
389
389
  }
390
390
  constructor() {
391
391
  super(), this.attachShadow({ mode: "open" });
@@ -393,19 +393,19 @@ class p extends ct {
393
393
  this.#n("attrToPropMap") || (t.attrToPropMap = /* @__PURE__ */ new Map()), this.#n("properties") || (t.properties = {}), this.#n("propToAttrMap") || (t.propToAttrMap = /* @__PURE__ */ new Map()), this.#n("propToComputedMap") || (t.propToComputedMap = /* @__PURE__ */ new Map()), this.#n("propToExprsMap") || (t.propToExprsMap = /* @__PURE__ */ new Map());
394
394
  }
395
395
  attributeChangedCallback(t, e, s) {
396
- t === "disabled" && this.#w();
396
+ t === "disabled" && this.#E();
397
397
  const o = p.getPropName(t);
398
- if (this.#c(o)) {
398
+ if (!this.#a(o) && this.#c(o)) {
399
399
  const i = this.#x(o, s);
400
400
  this[o] = i;
401
- const n = this.#p[o];
401
+ const n = this.#d[o];
402
402
  n && this.setFormValue(n, String(i)), this.propertyChangedCallback(o, e, s);
403
403
  }
404
404
  }
405
405
  // This applies multiple property changes and only updates
406
406
  // the affected parts of the DOM after all of them are made.
407
407
  batchSet(t) {
408
- this.#h = !0;
408
+ this.#u = !0;
409
409
  const e = this.#t.propToExprsMap, s = /* @__PURE__ */ new Set();
410
410
  for (const [c, a] of Object.entries(t)) {
411
411
  this[c] = a;
@@ -421,7 +421,7 @@ class p extends ct {
421
421
  }
422
422
  for (const c of i) {
423
423
  const a = n[c];
424
- this.#a(c, this.#o(a));
424
+ this.#f(c, this.#o(a));
425
425
  const f = e.get(c) ?? [];
426
426
  for (const l of f)
427
427
  s.add(l);
@@ -430,11 +430,11 @@ class p extends ct {
430
430
  let c = !1;
431
431
  for (const a of i) {
432
432
  const f = n[a], l = this.#o(f), h = this[a];
433
- JSON.stringify(l) !== JSON.stringify(h) && (this.#a(a, l), c = !0);
433
+ JSON.stringify(l) !== JSON.stringify(h) && (this.#f(a, l), c = !0);
434
434
  }
435
435
  if (!c) break;
436
436
  }
437
- this.#E([...s]), this.#h = !1;
437
+ this.#T([...s]), this.#u = !1;
438
438
  }
439
439
  async #$() {
440
440
  const t = this.#t;
@@ -454,23 +454,23 @@ class p extends ct {
454
454
  this[e] = s;
455
455
  }
456
456
  connectedCallback() {
457
- this.#D(), this.#N(), this.#$().then(() => {
458
- this.hasAttribute("disabled") && this.#w(), this.#R(this.shadowRoot), this.#M(this.shadowRoot), this.#O();
457
+ this.#D(), this.#L(), this.#$().then(() => {
458
+ this.hasAttribute("disabled") && this.#E(), this.#R(this.shadowRoot), this.#M(this.shadowRoot), this.#O();
459
459
  });
460
460
  }
461
461
  #O() {
462
462
  const t = this.#t, { properties: e } = t;
463
463
  for (const [s, { computed: o }] of Object.entries(e))
464
- o && this.#a(s, this.#o(o));
464
+ o && this.#f(s, this.#o(o));
465
465
  }
466
- #N() {
466
+ #L() {
467
467
  const t = this.#t, { observedAttributes: e, properties: s } = t;
468
468
  for (const [o, i] of Object.entries(s))
469
- i.computed || this.#y(o, i, e);
469
+ i.computed || this.#w(o, i, e);
470
470
  for (const [o, i] of Object.entries(s))
471
- i.computed && this.#y(o, i, e);
471
+ i.computed && this.#w(o, i, e);
472
472
  }
473
- #y(t, e, s) {
473
+ #w(t, e, s) {
474
474
  if (t === "class" || t === "style")
475
475
  throw new E(`"${t}" is a reserved property`);
476
476
  const o = p.getAttrName(t), i = this.hasAttribute(o);
@@ -484,7 +484,7 @@ class p extends ct {
484
484
  return this[f];
485
485
  },
486
486
  set(l) {
487
- e.computed && !this.#u.has(t) && this.#e(
487
+ e.computed && !this.#p.has(t) && this.#e(
488
488
  null,
489
489
  t,
490
490
  "is a computed property and cannot be set directly"
@@ -493,8 +493,8 @@ class p extends ct {
493
493
  if (l === h) return;
494
494
  this.#V(t, c, l), this[f] = l;
495
495
  const m = this.#r.get(t);
496
- m && ot(m.state, m.stateProp, l), this.#F(t, c, l, o), this.#h || (this.#_(t), this.#v(t)), this.#I(t, l);
497
- const x = this.#p[t];
496
+ m && ot(m.state, m.stateProp, l), this.#_(t, c, l, o), this.#u || (this.#F(t), this.#v(t)), this.#I(t, l);
497
+ const x = this.#d[t];
498
498
  x && this.setFormValue(x, String(l)), this.propertyChangedCallback(t, h, l), e.dispatch && this.dispatch("change", {
499
499
  tagName: this.localName,
500
500
  property: t,
@@ -504,7 +504,7 @@ class p extends ct {
504
504
  }
505
505
  });
506
506
  }
507
- #w() {
507
+ #E() {
508
508
  const t = this.hasAttribute("disabled"), e = R(this.shadowRoot);
509
509
  for (const s of e)
510
510
  pt(s) && (s.disabled = t);
@@ -512,7 +512,7 @@ class p extends ct {
512
512
  disconnectedCallback() {
513
513
  for (const { state: t } of this.#r.values())
514
514
  t.removeListener(this);
515
- this.#s.clear(), this.#d.clear(), this.#b.clear(), this.#r.clear();
515
+ this.#s.clear(), this.#m.clear(), this.#g.clear(), this.#r.clear();
516
516
  }
517
517
  dispatch(t, e) {
518
518
  this.dispatchEvent(
@@ -528,24 +528,24 @@ class p extends ct {
528
528
  displayIfSet(t, e = "block") {
529
529
  return `display: ${t ? e : "none"}`;
530
530
  }
531
- #L(t) {
531
+ #N(t) {
532
532
  const e = t instanceof p;
533
533
  for (const s of t.getAttributeNames()) {
534
534
  const o = t.getAttribute(s), i = this.#A(t, o);
535
535
  if (i) {
536
536
  const n = this[i];
537
- n === void 0 && this.#l(t, s, i);
537
+ n === void 0 && this.#h(t, s, i);
538
538
  let [c, a] = s.split(":");
539
- const f = p.getPropName(c), l = this.#T(i);
540
- e && t.#T(f) || (t[f] = n), c === "value" && (a ? (t["on" + a] === void 0 && this.#e(t, s, "refers to an unsupported event name"), t.setAttribute(c, this[i])) : a = "change"), e && !l && t.#b.set(
539
+ const f = p.getPropName(c), l = this.#a(i);
540
+ e && t.#a(f) || (t[f] = n), c === "value" && (a ? (t["on" + a] === void 0 && this.#e(t, s, "refers to an unsupported event name"), t.setAttribute(c, this[i])) : a = "change"), e && !l && t.#g.set(
541
541
  p.getPropName(c),
542
542
  i
543
543
  );
544
544
  }
545
- this.#f(o, t, s);
545
+ this.#l(o, t, s);
546
546
  }
547
547
  }
548
- #E(t) {
548
+ #T(t) {
549
549
  for (const e of t) {
550
550
  const s = this.#o(e), o = this.#s.get(e) ?? [], i = /* @__PURE__ */ new Set();
551
551
  for (const n of o) {
@@ -584,13 +584,13 @@ class p extends ct {
584
584
  for (const a of c)
585
585
  if (a.startsWith("--")) {
586
586
  const f = n.style.getPropertyValue(a);
587
- this.#f(f, n, a);
587
+ this.#l(f, n, a);
588
588
  }
589
589
  }
590
590
  } else {
591
591
  let s = "";
592
592
  if (S(t)) {
593
- this.#f(t.textContent, t);
593
+ this.#l(t.textContent, t);
594
594
  const o = t.textContent?.match(lt);
595
595
  o && (s = o[1]);
596
596
  } else {
@@ -601,7 +601,7 @@ class p extends ct {
601
601
  }
602
602
  if (s) {
603
603
  const o = this.#A(t, s);
604
- o && S(t) ? t.textContent = this[o] : this.#f(s, t);
604
+ o && S(t) ? t.textContent = this[o] : this.#l(s, t);
605
605
  }
606
606
  }
607
607
  }
@@ -626,16 +626,16 @@ class p extends ct {
626
626
  const [c, a] = n.split(":");
627
627
  e[c.trim()] = a.trim();
628
628
  }
629
- this.#p = e, this.#i = new FormData(), this.#m = this.attachInternals(), this.#m.setFormValue(this.#i);
630
- const o = Object.keys(this.#t.properties), i = this.#d;
629
+ this.#d = e, this.#i = new FormData(), this.#b = this.attachInternals(), this.#b.setFormValue(this.#i);
630
+ const o = Object.keys(this.#t.properties), i = this.#m;
631
631
  for (const n of o)
632
632
  i[n] = this[n];
633
633
  }
634
634
  formResetCallback() {
635
- const t = this.#d;
635
+ const t = this.#m;
636
636
  for (const e of Object.keys(t)) {
637
637
  let s = t[e];
638
- L.test(s) && (s = this.#o(s)), this[e] = s;
638
+ N.test(s) && (s = this.#o(s)), this[e] = s;
639
639
  }
640
640
  }
641
641
  static getAttrName(t) {
@@ -649,7 +649,7 @@ class p extends ct {
649
649
  #H(t, e, s) {
650
650
  if (s.length !== 1) return;
651
651
  const [o] = s;
652
- if (!L.test(o)) return;
652
+ if (!N.test(o)) return;
653
653
  const i = D(t) || S(t);
654
654
  let [n, c] = (e ?? "").split(":");
655
655
  if (!(i && n === "value" || S(t))) return;
@@ -668,13 +668,13 @@ class p extends ct {
668
668
  #c(t) {
669
669
  return !!this.#t.properties[t];
670
670
  }
671
- #T(t) {
671
+ #a(t) {
672
672
  return !!this.#t.properties[t]?.computed;
673
673
  }
674
674
  #M(t) {
675
675
  const e = Array.from(t.querySelectorAll("*"));
676
676
  for (const s of e)
677
- this.#L(s), s.firstElementChild || this.#j(s);
677
+ this.#N(s), s.firstElementChild || this.#j(s);
678
678
  }
679
679
  // formAssociated is only needed when the component is inside a form.
680
680
  #S() {
@@ -687,22 +687,20 @@ class p extends ct {
687
687
  );
688
688
  }
689
689
  static get observedAttributes() {
690
- const t = Object.keys(this.properties || {}).map(
691
- (e) => p.getAttrName(e)
692
- );
690
+ const t = Object.entries(this.properties || {}).filter(([e, s]) => !s.computed).map(([e]) => p.getAttrName(e));
693
691
  return t.includes("disabled") || t.push("disabled"), t;
694
692
  }
695
693
  // Subclasses can override this to add functionality.
696
694
  propertyChangedCallback(t, e, s) {
697
695
  }
698
696
  #A(t, e) {
699
- if (!e || !L.test(e)) return;
697
+ if (!e || !N.test(e)) return;
700
698
  const s = M(e);
701
- return this[s] === void 0 && this.#l(t, "", s), s;
699
+ return this[s] === void 0 && this.#h(t, "", s), s;
702
700
  }
703
701
  #v(t) {
704
702
  const e = this.#t.propToExprsMap.get(t) || [];
705
- this.#E(e);
703
+ this.#T(e);
706
704
  }
707
705
  #k(t, e) {
708
706
  const { computed: s, uses: o } = e, i = this.#t.propToComputedMap;
@@ -713,25 +711,25 @@ class p extends ct {
713
711
  const c = s.match(j) || [];
714
712
  for (const a of c) {
715
713
  const f = M(a);
716
- this[f] === void 0 && this.#l(null, t, f), typeof this[f] != "function" && n(f, s);
714
+ this[f] === void 0 && this.#h(null, t, f), typeof this[f] != "function" && n(f, s);
717
715
  }
718
716
  if (o)
719
717
  for (const a of o.split(","))
720
718
  n(a.trim(), s);
721
719
  }
722
- #a(t, e) {
723
- this.#u.add(t);
720
+ #f(t, e) {
721
+ this.#p.add(t);
724
722
  try {
725
723
  this[t] = e;
726
724
  } finally {
727
- this.#u.delete(t);
725
+ this.#p.delete(t);
728
726
  }
729
727
  }
730
728
  // WARNING: Do not place untrusted JavaScript expressions
731
729
  // in attribute values or the text content of elements!
732
- #f(t, e, s = void 0) {
730
+ #l(t, e, s = void 0) {
733
731
  if (!t) return;
734
- const o = this.#g(e, s, t);
732
+ const o = this.#y(e, s, t);
735
733
  if (!o) {
736
734
  const a = t.replaceAll("this..", "this.");
737
735
  s ? k(e, s, a) : "textContent" in e && (e.textContent = a);
@@ -764,7 +762,7 @@ class p extends ct {
764
762
  this.hasAttribute(t) || this.setAttribute(t, e);
765
763
  }
766
764
  setFormValue(t, e) {
767
- !this.#i || !I(e) || (this.#i.set(t, e), this.#m?.setFormValue(this.#i));
765
+ !this.#i || !I(e) || (this.#i.set(t, e), this.#b?.setFormValue(this.#i));
768
766
  }
769
767
  static ssr(t = {}) {
770
768
  throw new E('Import Wrec from "wrec/ssr" to use the ssr method.');
@@ -775,7 +773,7 @@ class p extends ct {
775
773
  `component ${this.#t.elementName}` + (t ? `, element "${o}"` : "") + (e ? `, attribute "${e}"` : "") + ` ${s}`
776
774
  );
777
775
  }
778
- #l(t, e, s) {
776
+ #h(t, e, s) {
779
777
  this.#e(t, e, `refers to missing property "${s}"`);
780
778
  }
781
779
  #C(t, e) {
@@ -807,18 +805,18 @@ class p extends ct {
807
805
  }
808
806
  // Updates the matching attribute for a property.
809
807
  // VS Code thinks this is never called, but it is called by #defineProp.
810
- #F(t, e, s, o) {
811
- if (I(s)) {
808
+ #_(t, e, s, o) {
809
+ if (I(s) && !this.#a(t)) {
812
810
  const i = e === Boolean ? this.hasAttribute(o) : this.#C(t, o);
813
811
  s !== i && st(this, o || t, s);
814
812
  }
815
813
  }
816
814
  // Updates all computed properties that reference this property.
817
815
  // VS Code thinks this is never called, but it is called by #defineProp.
818
- #_(t) {
816
+ #F(t) {
819
817
  const s = this.#t.propToComputedMap.get(t) || [];
820
818
  for (const [o, i] of s)
821
- this.#a(o, this.#o(i));
819
+ this.#f(o, this.#o(i));
822
820
  }
823
821
  #P(t, e) {
824
822
  if (e === void 0) return;
@@ -841,7 +839,7 @@ class p extends ct {
841
839
  // Update corresponding parent web component property if bound to one.
842
840
  // VS Code thinks this is never called, but it is called by #defineProp.
843
841
  #I(t, e) {
844
- const s = this.#b.get(t);
842
+ const s = this.#g.get(t);
845
843
  if (!s) return;
846
844
  const o = this.getRootNode();
847
845
  if (!(o instanceof ShadowRoot)) return;
@@ -886,12 +884,12 @@ class p extends ct {
886
884
  }
887
885
  }
888
886
  }
889
- #g(t, e, s) {
887
+ #y(t, e, s) {
890
888
  const o = s.match(j);
891
889
  if (o)
892
890
  return o.forEach((i) => {
893
891
  const n = M(i);
894
- this[n] === void 0 && this.#l(t, e, n);
892
+ this[n] === void 0 && this.#h(t, e, n);
895
893
  }), o;
896
894
  }
897
895
  #B(t, e) {
@@ -938,9 +936,9 @@ class p extends ct {
938
936
  let c = n.slice(2);
939
937
  c = c[0].toLowerCase() + c.slice(1).toLowerCase();
940
938
  const a = i.value;
941
- this.#g(s, n, a);
939
+ this.#y(s, n, a);
942
940
  let f;
943
- typeof this[a] == "function" ? f = (l) => this[a](l) : (this.#g(s, n, a), f = () => this.#o(a)), s.addEventListener(c, f), o.push(n);
941
+ typeof this[a] == "function" ? f = (l) => this[a](l) : (this.#y(s, n, a), f = () => this.#o(a)), s.addEventListener(c, f), o.push(n);
944
942
  }
945
943
  }
946
944
  for (const i of o)
@@ -980,7 +978,7 @@ function Mt(r, ...t) {
980
978
  }
981
979
  export {
982
980
  p as Wrec,
983
- F as WrecState,
981
+ _ as WrecState,
984
982
  Et as createElement,
985
983
  Tt as css,
986
984
  Mt as html
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "wrec",
3
3
  "description": "a small library that greatly simplifies building web components",
4
4
  "author": "R. Mark Volkmann",
5
- "version": "0.22.8",
5
+ "version": "0.22.9",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",