wrec 0.33.0 → 0.34.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.
@@ -45,7 +45,7 @@ var r = typeof window < "u" && window.document !== void 0, i = class extends Err
45
45
  constructor(n, a, o) {
46
46
  if (!n) throw new i("name cannot be empty");
47
47
  if (e.#e.has(n)) throw new i(`WrecState with name "${n}" already exists`);
48
- if (this.#r = n, this.#i = a, this.#a = t({}, this.#o.bind(this)), a && r) {
48
+ if (this.#r = n, this.#i = a, this.#a = t({}, this.#s.bind(this)), a && r) {
49
49
  let e = sessionStorage.getItem("wrec-state-" + n), t = e ? JSON.parse(e) : void 0;
50
50
  t && (o = t);
51
51
  }
@@ -76,18 +76,21 @@ var r = typeof window < "u" && window.document !== void 0, i = class extends Err
76
76
  get id() {
77
77
  return this.#n;
78
78
  }
79
+ #o(e, t) {
80
+ return t.some((t) => e === t || e.startsWith(t + ".") || t.startsWith(e + "."));
81
+ }
79
82
  log() {
80
83
  console.log("WrecState:", this.#r);
81
84
  for (let [e, t] of Object.entries(this.#a)) console.log(` ${e} = ${JSON.stringify(t)}`);
82
85
  }
83
- #o(e, t, n) {
86
+ #s(e, t, n) {
84
87
  let r = {
85
88
  state: this,
86
89
  statePath: e,
87
90
  oldValue: t,
88
91
  newValue: n
89
92
  };
90
- for (let { callback: t, statePaths: n } of this.#t) (n.length === 0 || n.includes(e)) && t(r);
93
+ for (let { callback: t, statePaths: n } of this.#t) (n.length === 0 || this.#o(e, n)) && t(r);
91
94
  }
92
95
  };
93
96
  r && process.env.NODE_ENV === "development" && (window.WrecState = a);
@@ -313,14 +316,14 @@ var X = class e extends m {
313
316
  constructor() {
314
317
  super(), this.attachShadow({ mode: "open" });
315
318
  let e = this.#n;
316
- this.#E("attrToPropMap") || (e.attrToPropMap = /* @__PURE__ */ new Map()), this.#E("computedGraph") || (e.computedGraph = null), this.#E("computedPropsRegistered") || (e.computedPropsRegistered = !1), this.#E("properties") || (e.properties = {}), this.#E("propToAttrMap") || (e.propToAttrMap = /* @__PURE__ */ new Map()), this.#E("propToComputedMap") || (e.propToComputedMap = /* @__PURE__ */ new Map()), this.#E("propToExprsMap") || (e.propToExprsMap = /* @__PURE__ */ new Map()), this.#E("registeredComputedProps") || (e.registeredComputedProps = /* @__PURE__ */ new Set());
319
+ this.#O("attrToPropMap") || (e.attrToPropMap = /* @__PURE__ */ new Map()), this.#O("computedGraph") || (e.computedGraph = null), this.#O("computedPropsRegistered") || (e.computedPropsRegistered = !1), this.#O("properties") || (e.properties = {}), this.#O("propToAttrMap") || (e.propToAttrMap = /* @__PURE__ */ new Map()), this.#O("propToComputedMap") || (e.propToComputedMap = /* @__PURE__ */ new Map()), this.#O("propToExprsMap") || (e.propToExprsMap = /* @__PURE__ */ new Map()), this.#O("registeredComputedProps") || (e.registeredComputedProps = /* @__PURE__ */ new Set());
317
320
  }
318
321
  attributeChangedCallback(t, n, r) {
319
322
  t === "disabled" && this.#v();
320
323
  let i = e.getPropName(t);
321
- if (!this.#O(i) && this.#D(i)) {
322
- let e = this.#V(i, r);
323
- this[i] = e;
324
+ if (!this.#A(i) && this.#k(i)) {
325
+ let e = this.#W(i, r);
326
+ this.#R(i, e);
324
327
  let t = this.#i[i];
325
328
  t && this.setFormValue(t, String(e));
326
329
  }
@@ -329,13 +332,13 @@ var X = class e extends m {
329
332
  this.#e = !0;
330
333
  let t = this.#n.propToExprsMap, n = /* @__PURE__ */ new Set();
331
334
  for (let [r, i] of Object.entries(e)) {
332
- this[r] = i;
335
+ this.#R(r, i);
333
336
  let e = t.get(r) ?? [];
334
337
  for (let t of e) n.add(t);
335
338
  }
336
339
  let r = this.#w(Object.keys(e));
337
340
  for (let [e, i] of r) {
338
- this.#F(e, this.#x(i));
341
+ this.#L(e, this.#x(i));
339
342
  let r = t.get(e) ?? [];
340
343
  for (let e of r) n.add(e);
341
344
  }
@@ -353,40 +356,40 @@ var X = class e extends m {
353
356
  return t.startsWith("<") || (t = `<span><!--${t}--></span>`), e + t;
354
357
  }
355
358
  changed(e, t, n) {
356
- this[t] = n;
359
+ this.#R(t, n);
357
360
  }
358
361
  async connectedCallback() {
359
- this.#q(), this.#h(), await this.#p(), this.hasAttribute("disabled") && this.#v(), this.#Q(this.shadowRoot), this.#A(this.shadowRoot), this.#K(), this.#m(), this.ready();
362
+ this.#X(), this.#h(), await this.#p(), this.hasAttribute("disabled") && this.#v(), this.#te(this.shadowRoot), this.#M(this.shadowRoot), this.#Y(), this.#m(), this.ready();
360
363
  }
361
364
  #m() {
362
365
  let { properties: e } = this.#n;
363
- for (let [t, { computed: n }] of Object.entries(e)) n && this.#F(t, this.#x(n));
366
+ for (let [t, { computed: n }] of Object.entries(e)) n && this.#L(t, this.#x(n));
364
367
  }
365
368
  #h() {
366
369
  let { observedAttributes: e, properties: t } = this.#n;
367
370
  for (let [n, r] of Object.entries(t)) r.computed || this.#g(n, r, e);
368
371
  for (let [n, r] of Object.entries(t)) r.computed && this.#g(n, r, e);
369
- this.#N();
372
+ this.#F();
370
373
  }
371
374
  #g(t, n, r) {
372
375
  if (t === "class" || t === "style") throw new g(`"${t}" is a reserved property`);
373
376
  let i = e.getAttrName(t), a = this.hasAttribute(i);
374
- n.required && !a && this.#R(this, i, "is a required attribute");
377
+ n.required && !a && this.#V(this, i, "is a required attribute");
375
378
  let o = n.value;
376
- this.hasOwnProperty(t) && (o = this[t], delete this[t]);
377
- let { type: c } = n, l = c === Boolean ? o || a : r.includes(i) && a ? this.#B(t, i) : o ?? k(n), u = "#" + t;
378
- this[u] = this.#k(t, c, l), Object.defineProperty(this, t, {
379
+ this.hasOwnProperty(t) && (o = this.#T(t), this.#_(t));
380
+ let { type: c } = n, l = c === Boolean ? o || a : r.includes(i) && a ? this.#U(t, i) : o ?? k(n), u = "#" + t;
381
+ this.#R(u, this.#j(t, c, l)), Object.defineProperty(this, t, {
379
382
  enumerable: !0,
380
383
  get() {
381
- return this[u];
384
+ return this.#T(u);
382
385
  },
383
386
  set(e) {
384
- n.computed && !this.#t.has(t) && this.#R(null, t, "is a computed property and cannot be set directly"), c === Number && typeof e == "string" && (e = G(e));
385
- let r = this[u];
387
+ n.computed && !this.#t.has(t) && this.#V(null, t, "is a computed property and cannot be set directly"), c === Number && typeof e == "string" && (e = G(e));
388
+ let r = this.#T(u);
386
389
  if (e === r) return;
387
- this.#X(t, c, e), e = this.#k(t, c, e), this[u] = e;
390
+ this.#$(t, c, e), e = this.#j(t, c, e), this.#R(u, e);
388
391
  let a = this.#l.get(t);
389
- a && s(a.state, a.stateProp, e), this.#H(t, c, e, i), this.#e || (this.#U(t), this.#M(t)), this.#G(t, e);
392
+ a && s(a.state, a.stateProp, e), this.#G(t, c, e, i), this.#e || (this.#K(t), this.#P(t)), this.#J(t, e);
390
393
  let o = this.#i[t];
391
394
  o && this.setFormValue(o, String(e)), this.propertyChangedCallback(t, r, e), n.dispatch && this.dispatch("change", {
392
395
  tagName: this.localName,
@@ -397,13 +400,12 @@ var X = class e extends m {
397
400
  }
398
401
  });
399
402
  }
400
- #_(e, t, n) {
401
- let r = this["#" + e], i = this.#l.get(e);
402
- i && s(i.state, i.stateProp, r), this.#e || (this.#U(e), this.#M(e)), this.#G(e, r), this.propertyChangedCallback(e, t, n);
403
+ #_(e) {
404
+ delete this[e];
403
405
  }
404
406
  #v() {
405
- let e = this.hasAttribute("disabled"), t = j(this.shadowRoot);
406
- for (let n of t) D(n) && (n.disabled = e);
407
+ let t = this.hasAttribute("disabled"), n = j(this.shadowRoot);
408
+ for (let r of n) D(r) && (r instanceof e ? t ? r.setAttribute("disabled", "") : r.removeAttribute("disabled") : r.disabled = t);
407
409
  }
408
410
  disconnectedCallback() {
409
411
  for (let { unsubscribe: e } of this.#f.values()) e();
@@ -424,22 +426,22 @@ var X = class e extends m {
424
426
  for (let r of t.getAttributeNames()) {
425
427
  let i = t.getAttribute(r);
426
428
  if (r === "ref") {
427
- this.#L(t, i);
429
+ this.#B(t, i);
428
430
  continue;
429
431
  }
430
- let a = this.#j(t, i);
432
+ let a = this.#N(t, i);
431
433
  if (a) {
432
- let i = this[a];
433
- i === void 0 && this.#z(t, r, a);
434
+ let i = this.#T(a);
435
+ i === void 0 && this.#H(t, r, a);
434
436
  let [o, s] = r.split(":"), c = e.getPropName(o);
435
437
  if (o === "checked") {
436
438
  let { type: e } = this.#n.properties[a];
437
- I(t) && e !== Boolean && this.#R(t, r, `refers to property "${a}" whose type is not Boolean`), z(t) && e !== String && this.#R(t, r, `refers to property "${a}" whose type is not String`);
439
+ I(t) && e !== Boolean && this.#V(t, r, `refers to property "${a}" whose type is not Boolean`), z(t) && e !== String && this.#V(t, r, `refers to property "${a}" whose type is not String`);
438
440
  }
439
- let l = this.#O(a);
440
- n && t.#O(c) || (o === "checked" && z(t) ? t.checked = t.value === i : t[c] = i), o === "value" && (s ? (t["on" + s] === void 0 && this.#R(t, r, "refers to an unsupported event name"), t.setAttribute(o, this[a])) : s = "change"), n && !l && t.#c.set(e.getPropName(o), a);
441
+ let l = this.#A(a);
442
+ n && t.#A(c) || (o === "checked" && z(t) ? t.checked = t.value === i : t[c] = i), o === "value" && (s ? (t["on" + s] === void 0 && this.#V(t, r, "refers to an unsupported event name"), t.setAttribute(o, this.#T(a))) : s = "change"), n && !l && t.#c.set(e.getPropName(o), a);
441
443
  }
442
- this.#I(i, t, r);
444
+ this.#z(i, t, r);
443
445
  }
444
446
  }
445
447
  #b(e) {
@@ -451,7 +453,7 @@ var X = class e extends m {
451
453
  r.add(t);
452
454
  continue;
453
455
  }
454
- if (t instanceof HTMLElement) this.#W(t, e);
456
+ if (t instanceof HTMLElement) this.#q(t, e);
455
457
  else if (!(t instanceof CSSStyleRule)) {
456
458
  let { element: n, attrName: r } = t;
457
459
  n instanceof CSSStyleRule ? n.style.setProperty(r, e) : q(n, r, e);
@@ -475,13 +477,13 @@ var X = class e extends m {
475
477
  let t = Array.from(e.style);
476
478
  for (let n of t) if (n.startsWith("--")) {
477
479
  let t = e.style.getPropertyValue(n);
478
- this.#I(t, e, n);
480
+ this.#z(t, e, n);
479
481
  }
480
482
  }
481
483
  } else {
482
484
  let t = "";
483
485
  if (B(e)) {
484
- this.#I(e.textContent, e);
486
+ this.#z(e.textContent, e);
485
487
  let n = e.textContent?.match(x);
486
488
  n && (t = n[1]);
487
489
  } else {
@@ -489,8 +491,8 @@ var X = class e extends m {
489
491
  n && (t = n.textContent?.trim() ?? "");
490
492
  }
491
493
  if (t) {
492
- let n = this.#j(e, t);
493
- n && B(e) ? e.textContent = this[n] : this.#I(t, e);
494
+ let n = this.#N(e, t);
495
+ n && B(e) ? e.textContent = this.#T(n) : this.#z(t, e);
494
496
  }
495
497
  }
496
498
  }
@@ -498,7 +500,7 @@ var X = class e extends m {
498
500
  let e = this.getAttribute("form-assoc");
499
501
  if (!e) {
500
502
  let t = this.getAttribute("name");
501
- if (t) if (this.#D("value")) e = `value:${t}`;
503
+ if (t) if (this.#k("value")) e = `value:${t}`;
502
504
  else return;
503
505
  else return;
504
506
  }
@@ -509,17 +511,17 @@ var X = class e extends m {
509
511
  }
510
512
  this.#i = t, this.#a = new FormData(), this.#s = this.attachInternals(), this.#s.setFormValue(this.#a);
511
513
  for (let [e, n] of Object.entries(t)) {
512
- let t = this[e];
514
+ let t = this.#T(e);
513
515
  R(t) && this.setFormValue(n, String(t));
514
516
  }
515
517
  let r = Object.keys(this.#n.properties), i = this.#o;
516
- for (let e of r) i[e] = this[e];
518
+ for (let e of r) i[e] = this.#T(e);
517
519
  }
518
520
  formResetCallback() {
519
521
  let e = this.#o;
520
522
  for (let t of Object.keys(e)) {
521
523
  let n = e[t];
522
- C.test(n) && (n = this.#x(n)), this[t] = n;
524
+ C.test(n) && (n = this.#x(n)), this.#R(t, n);
523
525
  }
524
526
  }
525
527
  static getAttrName(e) {
@@ -568,44 +570,51 @@ var X = class e extends m {
568
570
  if (c.length !== a.size) throw new g(`computed properties form a cycle: ${[...a].filter((e) => l.get(e) > 0).sort().join(", ")}`);
569
571
  return c.map((e) => [e, r[e]]);
570
572
  }
573
+ #T(e) {
574
+ return this[e];
575
+ }
571
576
  static getPropName(e) {
572
577
  let t = this.attrToPropMap.get(e);
573
578
  return t || (t = e.replace(/-([a-z])/g, (e, t) => t.toUpperCase()), this.attrToPropMap.set(e, t)), t;
574
579
  }
575
- #T(e, t, n) {
580
+ #E(e, t, n) {
581
+ let r = this.#T("#" + e), i = this.#l.get(e);
582
+ i && s(i.state, i.stateProp, r), this.#e || (this.#K(e), this.#P(e)), this.#J(e, r), this.propertyChangedCallback(e, t, n);
583
+ }
584
+ #D(e, t, n) {
576
585
  if (n.length !== 1) return;
577
586
  let [r] = n;
578
587
  if (!C.test(r)) return;
579
588
  let i = I(e), a = z(e), o = V(e) || B(e), [s, c] = (t ?? "").split(":");
580
589
  if (!(o && s === "value" || i && s === "checked" || a && s === "checked" || B(e))) return;
581
- c ? e["on" + c] === void 0 && this.#R(e, t, "refers to an unsupported event name") : c = "change";
590
+ c ? e["on" + c] === void 0 && this.#V(e, t, "refers to an unsupported event name") : c = "change";
582
591
  let l = N(r);
583
592
  e.addEventListener(c, (e) => {
584
593
  let { target: t } = e;
585
594
  if (!t) return;
586
595
  let { type: n } = this.#n.properties[l], r = t, { value: o } = r;
587
- s === "checked" ? i ? this[l] = r.checked : a && r.checked && (this[l] = o) : this[l] = n === Number ? G(o) : o, this.#M(l);
596
+ s === "checked" ? i ? this.#R(l, r.checked) : a && r.checked && this.#R(l, o) : this.#R(l, n === Number ? G(o) : o), this.#P(l);
588
597
  });
589
598
  }
590
- #E(e) {
599
+ #O(e) {
591
600
  return Object.hasOwn(this.#n, e);
592
601
  }
593
- #D(e) {
602
+ #k(e) {
594
603
  return !!this.#n.properties[e];
595
604
  }
596
- #O(e) {
605
+ #A(e) {
597
606
  return !!this.#n.properties[e]?.computed;
598
607
  }
599
- #k(e, n, r) {
608
+ #j(e, n, r) {
600
609
  if (typeof r != "object" || !r || n !== Array && n !== Object || this.#d.has(r)) return r;
601
610
  let i = this.#u.get(r);
602
611
  if (i) return i;
603
612
  let a = t(r, (t, n, r) => {
604
- this.#_(e, n, r);
613
+ this.#E(e, n, r);
605
614
  });
606
615
  return this.#u.set(r, a), this.#d.add(a), a;
607
616
  }
608
- #A(e) {
617
+ #M(e) {
609
618
  let t = Array.from(e.querySelectorAll("*"));
610
619
  for (let e of t) this.#y(e), e.firstElementChild || this.#S(e);
611
620
  }
@@ -614,24 +623,24 @@ var X = class e extends m {
614
623
  return t.includes("disabled") || t.push("disabled"), t;
615
624
  }
616
625
  propertyChangedCallback(e, t, n) {}
617
- #j(e, t) {
626
+ #N(e, t) {
618
627
  if (!t || !C.test(t)) return;
619
628
  let n = N(t);
620
- return this[n] === void 0 && this.#z(e, "", n), n;
629
+ return this.#T(n) === void 0 && this.#H(e, "", n), n;
621
630
  }
622
- #M(e) {
631
+ #P(e) {
623
632
  let t = this.#n.propToExprsMap.get(e) || [];
624
633
  this.#b(t);
625
634
  }
626
635
  ready() {}
627
- #N() {
636
+ #F() {
628
637
  let e = this.#n;
629
638
  if (!e.computedPropsRegistered) {
630
639
  e.computedPropsRegistered = !0, e.computedGraph = null;
631
- for (let [t, n] of Object.entries(e.properties)) n.computed && this.#P(t, n);
640
+ for (let [t, n] of Object.entries(e.properties)) n.computed && this.#I(t, n);
632
641
  }
633
642
  }
634
- #P(e, t) {
643
+ #I(e, t) {
635
644
  let n = this.#n;
636
645
  n.registeredComputedProps.add(e);
637
646
  let r = n.propToComputedMap;
@@ -642,28 +651,31 @@ var X = class e extends m {
642
651
  let a = t.computed;
643
652
  for (let t of a.matchAll(w)) {
644
653
  let r = N(t[0]);
645
- this[r] === void 0 && this.#z(null, e, r);
654
+ this.#T(r) === void 0 && this.#H(null, e, r);
646
655
  let o = H(r), s = !1;
647
656
  for (let [e, t] of Object.entries(n.properties)) J(t.usedBy)?.includes(o) && (i(e, a), s = !0);
648
- !s && typeof this[r] != "function" && i(r, a);
657
+ !s && typeof this.#T(r) != "function" && i(r, a);
649
658
  }
650
659
  for (let t of a.matchAll(b)) {
651
660
  let r = t[1];
652
- if (typeof this[r] != "function") throw new g(`property ${e} computed calls non-method ${r}`);
661
+ if (typeof this.#T(r) != "function") throw new g(`property ${e} computed calls non-method ${r}`);
653
662
  for (let [e, t] of Object.entries(n.properties)) J(t.usedBy)?.includes(r) && i(e, a);
654
663
  }
655
664
  }
656
- #F(e, t) {
665
+ #L(e, t) {
657
666
  this.#t.add(e);
658
667
  try {
659
- this[e] = t;
668
+ this.#R(e, t);
660
669
  } finally {
661
670
  this.#t.delete(e);
662
671
  }
663
672
  }
664
- #I(e, t, n = void 0) {
673
+ #R(e, t) {
674
+ this[e] = t;
675
+ }
676
+ #z(e, t, n = void 0) {
665
677
  if (!e) return;
666
- let r = this.#J(t, n, e);
678
+ let r = this.#Z(t, n, e);
667
679
  if (!r) {
668
680
  let r = e.replaceAll("this..", "this.");
669
681
  n ? q(t, n, r) : "textContent" in t && (t.textContent = r);
@@ -672,7 +684,7 @@ var X = class e extends m {
672
684
  let i = this.#n;
673
685
  r.forEach((t) => {
674
686
  let n = N(t);
675
- if (typeof this[n] == "function") return;
687
+ if (typeof this.#T(n) == "function") return;
676
688
  let r = i.propToExprsMap, a = r.get(n);
677
689
  a || (a = [], r.set(n, a)), a.includes(e) || a.push(e);
678
690
  });
@@ -684,13 +696,13 @@ var X = class e extends m {
684
696
  a || (a = [], this.#r.set(e, a)), a.push(n ? {
685
697
  element: t,
686
698
  attrName: n
687
- } : t), t instanceof HTMLElement && this.#T(t, n, r);
699
+ } : t), t instanceof HTMLElement && this.#D(t, n, r);
688
700
  let o = this.#x(e);
689
- n ? q(t, n, o) : this.#W(t, o);
701
+ n ? q(t, n, o) : this.#q(t, o);
690
702
  }
691
- #L(e, t) {
703
+ #B(e, t) {
692
704
  let n = t?.trim() ?? "", r = this.#n.properties[n];
693
- r || this.#z(e, "ref", n), r.type !== m && this.#R(e, "ref", `refers to property "${n}" whose type is not HTMLElement`), this[n] && this.#R(e, "ref", `is a duplicate reference to the property "${n}"`), this[n] = e, e.removeAttribute("ref");
705
+ r || this.#H(e, "ref", n), r.type !== m && this.#V(e, "ref", `refers to property "${n}" whose type is not HTMLElement`), this.#T(n) && this.#V(e, "ref", `is a duplicate reference to the property "${n}"`), this.#R(n, e), e.removeAttribute("ref");
694
706
  }
695
707
  setAttributeSafe(e, t) {
696
708
  this.hasAttribute(e) || this.setAttribute(e, t);
@@ -701,24 +713,24 @@ var X = class e extends m {
701
713
  static ssr(e = {}) {
702
714
  throw new g("SSR is not available in the browser build.");
703
715
  }
704
- #R(e, t, n) {
716
+ #V(e, t, n) {
705
717
  let r = e instanceof HTMLElement ? e.localName : "CSS rule";
706
718
  throw new g(`component ${this.#n.elementName}` + (e ? `, element "${r}"` : "") + (t ? `, attribute "${t}"` : "") + ` ${n}`);
707
719
  }
708
- #z(e, t, n) {
709
- this.#R(e, t, `refers to missing property "${n}"`);
720
+ #H(e, t, n) {
721
+ this.#V(e, t, `refers to missing property "${n}"`);
710
722
  }
711
- #B(e, t) {
712
- return this.#V(e, this.getAttribute(t));
723
+ #U(e, t) {
724
+ return this.#W(e, this.getAttribute(t));
713
725
  }
714
- #V(t, n) {
726
+ #W(t, n) {
715
727
  if (n?.match(w)) return n;
716
728
  let r = this.#n.properties[t], { type: i, values: a } = r;
717
- if (i || this.#R(null, t, "does not specify its type"), n === null) return i === Boolean ? !1 : k(r);
729
+ if (i || this.#V(null, t, "does not specify its type"), n === null) return i === Boolean ? !1 : k(r);
718
730
  if (i === String) {
719
731
  if (a && !a.includes(n)) {
720
732
  let e = a.map((e) => `"${e}"`).join(", ");
721
- this.#R(null, t, `must be one of ${e}`);
733
+ this.#V(null, t, `must be one of ${e}`);
722
734
  }
723
735
  return n;
724
736
  }
@@ -727,25 +739,25 @@ var X = class e extends m {
727
739
  if (n === "true") return !0;
728
740
  if (n === "false" || n === "null") return !1;
729
741
  let r = e.getAttrName(t);
730
- return n && n !== r && this.#R(null, t, "is a Boolean attribute, so its value must match attribute name or be missing"), n === "" || n === r;
742
+ return n && n !== r && this.#V(null, t, "is a Boolean attribute, so its value must match attribute name or be missing"), n === "" || n === r;
731
743
  }
732
744
  }
733
- #H(e, t, n, r) {
734
- R(n) && !this.#O(e) && n !== (t === Boolean ? this.hasAttribute(r) : this.#B(e, r)) && K(this, r || e, n);
745
+ #G(e, t, n, r) {
746
+ R(n) && !this.#A(e) && n !== (t === Boolean ? this.hasAttribute(r) : this.#U(e, r)) && K(this, r || e, n);
735
747
  }
736
- #U(e) {
737
- for (let [t, n] of this.#w([e])) this.#F(t, this.#x(n));
748
+ #K(e) {
749
+ for (let [t, n] of this.#w([e])) this.#L(t, this.#x(n));
738
750
  }
739
- #W(e, t) {
751
+ #q(e, t) {
740
752
  if (t === void 0) return;
741
753
  let n = e instanceof HTMLElement;
742
754
  Array.isArray(t) && (t = t.join(""));
743
755
  let r = typeof t;
744
- r !== "string" && r !== "number" && this.#R(e, void 0, " computed content is not a string or number");
756
+ r !== "string" && r !== "number" && this.#V(e, void 0, " computed content is not a string or number");
745
757
  let i = String(t);
746
- e instanceof HTMLElement && B(e) ? e.value = i : n && r === "string" && i.trim().startsWith("<") ? (e.innerHTML = d(i), this.#Q(e), this.#A(e)) : n && (e.textContent = i);
758
+ e instanceof HTMLElement && B(e) ? e.value = i : n && r === "string" && i.trim().startsWith("<") ? (e.innerHTML = d(i), this.#te(e), this.#M(e)) : n && (e.textContent = i);
747
759
  }
748
- #G(e, t) {
760
+ #J(e, t) {
749
761
  let n = this.#c.get(e);
750
762
  if (!n) return;
751
763
  let r = this.getRootNode();
@@ -755,7 +767,7 @@ var X = class e extends m {
755
767
  let a = i;
756
768
  a[n] = t;
757
769
  }
758
- #K() {
770
+ #Y() {
759
771
  let e = this.#n, t = (e, t, n) => {
760
772
  let r = e.get(t);
761
773
  r || (r = [], e.set(t, r)), r.includes(n) || r.push(n);
@@ -778,7 +790,7 @@ var X = class e extends m {
778
790
  if (L(e)) {
779
791
  let n = P(e);
780
792
  if (typeof M(this, n)?.get != "function") throw new g(`property ${t} usedBy contains non-getter ${e}`);
781
- } else if (typeof this[e] != "function") throw new g(`property ${t} usedBy contains non-method ${e}`);
793
+ } else if (typeof this.#T(e) != "function") throw new g(`property ${t} usedBy contains non-method ${e}`);
782
794
  let n = o.get(e) || [];
783
795
  for (let e of n) s.includes(e) || s.push(e);
784
796
  }
@@ -789,10 +801,10 @@ var X = class e extends m {
789
801
  t = {};
790
802
  for (let n of Object.keys(e)) t[n] = n;
791
803
  }
792
- this.#Y(e, t);
793
- for (let [n, r] of Object.entries(t)) if (this.#D(r)) {
804
+ this.#Q(e, t);
805
+ for (let [n, r] of Object.entries(t)) if (this.#k(r)) {
794
806
  let t = o(e, n);
795
- t !== void 0 && (this[r] = t), this.#l.set(r, {
807
+ t !== void 0 && this.#R(r, t), this.#l.set(r, {
796
808
  state: e,
797
809
  stateProp: n
798
810
  });
@@ -802,64 +814,71 @@ var X = class e extends m {
802
814
  ...t
803
815
  };
804
816
  n?.unsubscribe();
805
- let i = e.subscribe(({ statePath: e, newValue: t }) => {
806
- let n = r[e];
807
- n && (this[n] = t);
817
+ let i = e.subscribe(({ statePath: t, newValue: n }) => {
818
+ let i = r[t];
819
+ if (i) {
820
+ this.#R(i, n);
821
+ return;
822
+ }
823
+ let a = Object.keys(r).find((e) => t.startsWith(e + ".") || e.startsWith(t + "."));
824
+ if (!a) return;
825
+ let s = r[a];
826
+ this.#R(s, o(e, a));
808
827
  }, Object.keys(r));
809
828
  this.#f.set(e, {
810
829
  map: r,
811
830
  unsubscribe: i
812
831
  });
813
832
  }
814
- #q() {
833
+ #X() {
815
834
  let t = new Set(Object.keys(this.#n.properties));
816
835
  for (let n of this.getAttributeNames()) if (!p.has(n) && !n.startsWith("on") && n !== "ref") {
817
836
  if (n === "form-assoc") {
818
- this.#Z();
837
+ this.#ee();
819
838
  continue;
820
839
  }
821
840
  if (!t.has(e.getPropName(n))) {
822
841
  if (n === "name") {
823
- this.#Z();
842
+ this.#ee();
824
843
  continue;
825
844
  }
826
- this.#R(null, n, "is not a supported attribute");
845
+ this.#V(null, n, "is not a supported attribute");
827
846
  }
828
847
  }
829
848
  }
830
- #J(e, t, n) {
849
+ #Z(e, t, n) {
831
850
  let r = n.match(w);
832
851
  if (r) return r.forEach((n) => {
833
852
  let r = N(n);
834
- this[r] === void 0 && this.#z(e, t, r);
853
+ this.#T(r) === void 0 && this.#H(e, t, r);
835
854
  }), r;
836
855
  }
837
- #Y(e, t) {
856
+ #Q(e, t) {
838
857
  for (let [n, r] of Object.entries(t)) {
839
858
  let t = o(e, n);
840
- t === void 0 && this.#R(this, void 0, `invalid state path "${n}"`), t = this[r], this.#D(r) || this.#R(null, r, "refers to missing property in useState map");
859
+ t === void 0 && this.#V(this, void 0, `invalid state path "${n}"`), t = this.#T(r), this.#k(r) || this.#V(null, r, "refers to missing property in useState map");
841
860
  }
842
861
  }
843
- #X(e, t, n) {
862
+ #$(e, t, n) {
844
863
  let { values: r } = this.#n.properties[e];
845
864
  if (r) {
846
865
  let i;
847
- t === String ? typeof n == "string" ? r.includes(n) || (i = `must be one of ${r.map((e) => `"${e}"`).join(", ")}`) : i = `value is a ${typeof n}, but type is String` : i = "declares allowed values, but its type is not String", i && this.#R(null, e, i);
866
+ t === String ? typeof n == "string" ? r.includes(n) || (i = `must be one of ${r.map((e) => `"${e}"`).join(", ")}`) : i = `value is a ${typeof n}, but type is String` : i = "declares allowed values, but its type is not String", i && this.#V(null, e, i);
848
867
  }
849
868
  if (n instanceof t) return;
850
869
  let i = typeof n;
851
870
  if (i === "object") {
852
871
  let { constructor: r } = n;
853
- i = r.name, r !== t && this.#R(null, e, `was set to a ${i}, but must be a ${t.name}`);
872
+ i = r.name, r !== t && this.#V(null, e, `was set to a ${i}, but must be a ${t.name}`);
854
873
  }
855
- i !== t.name.toLowerCase() && this.#R(null, e, `was set to a ${i}, but must be a ${t.name}`);
874
+ i !== t.name.toLowerCase() && this.#V(null, e, `was set to a ${i}, but must be a ${t.name}`);
856
875
  }
857
- #Z() {
876
+ #ee() {
858
877
  if (this.#n.formAssociated || this.closest("form") === null) return;
859
878
  let e = this.#n.name;
860
- this.#R(this, void 0, `inside form, class ${e} requires "static formAssociated = true;"`);
879
+ this.#V(this, void 0, `inside form, class ${e} requires "static formAssociated = true;"`);
861
880
  }
862
- #Q(e) {
881
+ #te(e) {
863
882
  let t = Array.from(e.querySelectorAll("*"));
864
883
  for (let e of t) {
865
884
  let t = [];
@@ -869,9 +888,9 @@ var X = class e extends m {
869
888
  let i = r.slice(2);
870
889
  i = i[0].toLowerCase() + i.slice(1).toLowerCase();
871
890
  let a = n.value;
872
- this.#J(e, r, a);
891
+ this.#Z(e, r, a);
873
892
  let o;
874
- typeof this[a] == "function" ? o = (e) => this[a](e) : (this.#J(e, r, a), o = () => this.#x(a)), e.addEventListener(i, o), t.push(r);
893
+ typeof this.#T(a) == "function" ? o = (e) => this.#T(a).call(this, e) : (this.#Z(e, r, a), o = () => this.#x(a)), e.addEventListener(i, o), t.push(r);
875
894
  }
876
895
  }
877
896
  for (let n of t) e.removeAttribute(n);
@@ -15,14 +15,14 @@ declare const HTMLElementBase: {
15
15
 
16
16
  declare type LooseObject = Record<string, unknown>;
17
17
 
18
- declare type PropertyConfig = {
18
+ declare type PropertyConfig<T = any> = {
19
19
  computed?: string;
20
20
  dispatch?: boolean;
21
21
  required?: boolean;
22
22
  type: AnyClass;
23
23
  usedBy?: string | string[];
24
- value?: any;
25
- values?: string[];
24
+ value?: T;
25
+ values?: T extends string ? string[] : never;
26
26
  };
27
27
 
28
28
  declare type StateChange = {
@@ -53,7 +53,6 @@ export declare abstract class Wrec extends HTMLElementBase {
53
53
  private static registeredComputedProps;
54
54
  private static computedPropsRegistered;
55
55
  private static template;
56
- [key: string]: any;
57
56
  static define(elementName: string): void;
58
57
  constructor();
59
58
  attributeChangedCallback(attrName: string, _oldValue: string | null, newValue: string | null): void;
@@ -1,4 +1,4 @@
1
- import { a as e, i as t, n, r, t as i } from "./wrec-BL9AvT9R.js";
1
+ import { a as e, i as t, n, r, t as i } from "./wrec-BugZmj1G.js";
2
2
  //#region \0rolldown/runtime.js
3
3
  var a = Object.defineProperty, o = Object.getOwnPropertyDescriptor, s = Object.getOwnPropertyNames, c = Object.prototype.hasOwnProperty, l = (e, t) => () => (e && (t = e(e = 0)), t), u = (e, t) => () => (t || e((t = { exports: {} }).exports, t), t.exports), d = (e, t) => {
4
4
  let n = {};
package/dist/wrec.d.ts CHANGED
@@ -15,14 +15,14 @@ declare const HTMLElementBase: {
15
15
 
16
16
  declare type LooseObject = Record<string, unknown>;
17
17
 
18
- declare type PropertyConfig = {
18
+ declare type PropertyConfig<T = any> = {
19
19
  computed?: string;
20
20
  dispatch?: boolean;
21
21
  required?: boolean;
22
22
  type: AnyClass;
23
23
  usedBy?: string | string[];
24
- value?: any;
25
- values?: string[];
24
+ value?: T;
25
+ values?: T extends string ? string[] : never;
26
26
  };
27
27
 
28
28
  declare type StateChange = {
@@ -53,7 +53,6 @@ export declare abstract class Wrec extends HTMLElementBase {
53
53
  private static registeredComputedProps;
54
54
  private static computedPropsRegistered;
55
55
  private static template;
56
- [key: string]: any;
57
56
  static define(elementName: string): void;
58
57
  constructor();
59
58
  attributeChangedCallback(attrName: string, _oldValue: string | null, newValue: string | null): void;
package/dist/wrec.es.js CHANGED
@@ -1,2 +1,2 @@
1
- import { a as e, i as t, n, r, t as i } from "./wrec-BL9AvT9R.js";
1
+ import { a as e, i as t, n, r, t as i } from "./wrec-BugZmj1G.js";
2
2
  export { i as Wrec, e as WrecState, n as createElement, r as css, t as html };
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "wrec",
3
- "description": "a small library that greatly simplifies building web components",
3
+ "description": "a library that greatly simplifies building web components",
4
4
  "author": "R. Mark Volkmann",
5
- "version": "0.33.0",
5
+ "version": "0.34.0",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",