@wcstack/router 1.23.0 → 1.24.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/dist/index.d.ts CHANGED
@@ -1,7 +1,24 @@
1
+ /**
2
+ * Observation semantics of a `properties` entry.
3
+ *
4
+ * "state" — current value. A snapshot may cache it, and equality-based dedupe is safe.
5
+ * "event" — occurrence. Repeated identical payloads are distinct occurrences; never dedupe.
6
+ * "handle" — live / opaque resource with its own lifecycle (e.g. MediaStream). Not
7
+ * snapshot-safe and not necessarily serializable; consumers need an explicit
8
+ * ref / callback surface rather than a value slot.
9
+ */
10
+ type WcBindableSemantics = "state" | "event" | "handle";
1
11
  interface IWcBindableProperty {
2
12
  readonly name: string;
3
13
  readonly event: string;
4
14
  readonly getter?: (event: Event) => any;
15
+ /**
16
+ * Optional, additive, forward-compatible. An absent value means **unspecified**, NOT
17
+ * "state": a reader that finds no `semantics` MUST keep the behavior it had before this
18
+ * field existed (deliver the update as-is; do not start deduping, caching or serializing
19
+ * on assumption). Only an explicit value licenses a reader to change its handling.
20
+ */
21
+ readonly semantics?: WcBindableSemantics;
5
22
  }
6
23
  interface IWcBindableInput {
7
24
  readonly name: string;
package/dist/index.esm.js CHANGED
@@ -167,9 +167,9 @@ class RouteCore extends EventTarget {
167
167
  protocol: "wc-bindable",
168
168
  version: 1,
169
169
  properties: [
170
- { name: "params", event: "wcs-route:params-changed" },
171
- { name: "typedParams", event: "wcs-route:params-changed", getter: (e) => e.detail.typedParams },
172
- { name: "active", event: "wcs-route:active-changed" },
170
+ { name: "params", event: "wcs-route:params-changed", semantics: "state" },
171
+ { name: "typedParams", event: "wcs-route:params-changed", semantics: "state", getter: (e) => e.detail.typedParams },
172
+ { name: "active", event: "wcs-route:active-changed", semantics: "state" },
173
173
  ],
174
174
  };
175
175
  _target;
@@ -1518,6 +1518,48 @@ function normalizeBasename(path) {
1518
1518
  return p;
1519
1519
  }
1520
1520
 
1521
+ // ===========================================================================
1522
+ // AUTO-GENERATED FILE - DO NOT EDIT.
1523
+ // Generated from /protocol/upgrade-properties.ts by scripts/sync-protocol-types.mjs.
1524
+ // Run `node scripts/sync-protocol-types.mjs` after editing the source.
1525
+ // ===========================================================================
1526
+ function hasAccessorOnPrototype(target, name) {
1527
+ let proto = Object.getPrototypeOf(target);
1528
+ while (proto !== null) {
1529
+ const descriptor = Object.getOwnPropertyDescriptor(proto, name);
1530
+ if (descriptor !== undefined) {
1531
+ return typeof descriptor.get === "function" || typeof descriptor.set === "function";
1532
+ }
1533
+ proto = Object.getPrototypeOf(proto);
1534
+ }
1535
+ return false;
1536
+ }
1537
+ /**
1538
+ * `connectedCallback` の先頭で呼ぶ。宣言済み input のうち upgrade 前の代入で
1539
+ * accessor をシャドウしている own プロパティを、delete → 再代入で setter に通し直す。
1540
+ *
1541
+ * - 冪等: 再代入は accessor を通るので own プロパティは残らず、2 回目以降は no-op。
1542
+ * - 宣言に `inputs` が無い要素、`wcBindable` を持たない要素では何もしない。
1543
+ * - 値の意味は変えない。今まで捨てられていた代入が届くようになる一方向の変化。
1544
+ */
1545
+ function upgradeProperties(element) {
1546
+ const declaration = element.constructor?.wcBindable;
1547
+ const inputs = declaration?.inputs;
1548
+ if (inputs === undefined)
1549
+ return;
1550
+ for (const input of inputs) {
1551
+ const name = input.name;
1552
+ if (!Object.prototype.hasOwnProperty.call(element, name))
1553
+ continue;
1554
+ if (!hasAccessorOnPrototype(element, name))
1555
+ continue;
1556
+ const record = element;
1557
+ const value = record[name];
1558
+ delete record[name];
1559
+ record[name] = value;
1560
+ }
1561
+ }
1562
+
1521
1563
  /**
1522
1564
  * AppRoutes - Root component for @wcstack/router
1523
1565
  *
@@ -1528,8 +1570,8 @@ class Router extends HTMLElement {
1528
1570
  protocol: "wc-bindable",
1529
1571
  version: 1,
1530
1572
  properties: [
1531
- { name: "navigateUrl", event: "wcs-router:navigate-url-changed" },
1532
- { name: "path", event: "wcs-router:path-changed" },
1573
+ { name: "navigateUrl", event: "wcs-router:navigate-url-changed", semantics: "state" },
1574
+ { name: "path", event: "wcs-router:path-changed", semantics: "state" },
1533
1575
  ],
1534
1576
  // `navigateUrl` は observable output であると同時に settable な書き込み面でもある
1535
1577
  // (setter が navigate() を起動し、完了後に自分で null へ戻す)。properties にだけ
@@ -1771,6 +1813,9 @@ class Router extends HTMLElement {
1771
1813
  }
1772
1814
  }
1773
1815
  async connectedCallback() {
1816
+ // upgrade 前に代入された input を取り込み直す(doc 13 §1.2 / Phase A1)。
1817
+ // await より前に同期で行い、初期化が古い値を読まないようにする。
1818
+ upgradeProperties(this);
1774
1819
  if (!this._initialized) {
1775
1820
  this._disconnectedDuringInit = false;
1776
1821
  await this._initialize();
@@ -2239,7 +2284,7 @@ function bootstrapRouter(config) {
2239
2284
  registerComponents();
2240
2285
  }
2241
2286
 
2242
- var version = "1.23.0";
2287
+ var version = "1.24.0";
2243
2288
  var pkg = {
2244
2289
  version: version};
2245
2290