@wcstack/router 4.7.0 → 4.9.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
@@ -385,7 +385,7 @@ declare class Router extends HTMLElement implements IRouter {
385
385
  get basename(): string;
386
386
  set basename(value: string | null | undefined);
387
387
  get leaveConfirm(): string | null;
388
- set leaveConfirm(value: string | null | undefined);
388
+ set leaveConfirm(value: string | boolean | null | undefined);
389
389
  private _onBeforeUnload;
390
390
  /** beforeunload は leaveConfirm がある間だけ聞く(リスナーがあるだけで bfcache を外すブラウザがある) */
391
391
  private _syncBeforeUnload;
@@ -791,6 +791,10 @@ declare class Head extends HTMLElement {
791
791
  connectedCallback(): void;
792
792
  disconnectedCallback(): void;
793
793
  get childElementArray(): Element[];
794
+ /**
795
+ * head へ入れる子のクローン。束縛を持つ子は、束ねたクローンを使い回す(boundClones)
796
+ */
797
+ private _cloneOf;
794
798
  /**
795
799
  * 要素の一意キーを生成(WeakMap でキャッシュ)
796
800
  */
package/dist/index.esm.js CHANGED
@@ -2753,6 +2753,8 @@ function inSsr() {
2753
2753
  }
2754
2754
 
2755
2755
  const EMPTY_RECORD = Object.freeze({});
2756
+ /** `leaveConfirm = true` で聞く文言(ページの言語で聞くなら文字列を束ねる) */
2757
+ const DEFAULT_LEAVE_CONFIRM = "Leave this page? Changes you made may not be saved.";
2756
2758
  /**
2757
2759
  * AppRoutes - Root component for @wcstack/router
2758
2760
  *
@@ -2952,11 +2954,13 @@ class Router extends HTMLElement {
2952
2954
  // オリジンへのリンク、フォームの送信)の前に confirm(値) を出し、断られたら出ない。ページを閉じる・
2953
2955
  // 読み直すとき(と Navigation API の無いブラウザでページを離れるとき)はブラウザ自身の確認(beforeunload)。未保存の変更を守る口(docs/seam-apps.md、
2954
2956
  // router-admin — Navigation API を直接使うしかなかった)。null は属性を外し、undefined は最初の属性へ戻す。
2957
+ // 真偽値(`leaveConfirm: dirty`)は、true なら既定の文言で聞き、false なら聞かない — 文字列にすると
2958
+ // confirm("false") が遷移のたびに出ていた(docs/seam-apps.md、family-ledger)。
2955
2959
  get leaveConfirm() {
2956
2960
  return this.getAttribute("leave-confirm") || null;
2957
2961
  }
2958
2962
  set leaveConfirm(value) {
2959
- reflectAttribute(this, "leave-confirm", value);
2963
+ reflectAttribute(this, "leave-confirm", value === true ? DEFAULT_LEAVE_CONFIRM : value === false ? null : value);
2960
2964
  this._syncBeforeUnload();
2961
2965
  }
2962
2966
  _onBeforeUnload = (e) => {
@@ -4192,6 +4196,14 @@ let initialHeadCaptured = false;
4192
4196
  * 要素の属性変更には追随しない(Head 内要素は初期化時に固定される前提)。
4193
4197
  */
4194
4198
  const keyCache = new WeakMap();
4199
+ /**
4200
+ * 束縛を持つ子ごとに、head へ入れる束ねたクローンを 1 つだけ持つ。
4201
+ * binder には束縛を解く口が無く(docs/binder-protocol-design.md §6-2)、state は束ねたノードを
4202
+ * エンジンの寿命まで持つ。遷移のたびに新しいクローンを束ねさせると、外したクローンが 1 つずつ
4203
+ * 残った(束ねた `<title>` で遷移ごとに 2 ノード — docs/seam-apps.md、shift-desk)。同じクローンを
4204
+ * 入れ直せば、bind は冪等で、外れている間も値は届いている。
4205
+ */
4206
+ const boundClones = new WeakMap();
4195
4207
  class Head extends HTMLElement {
4196
4208
  _initialized = false;
4197
4209
  _childElementArray = [];
@@ -4243,6 +4255,20 @@ class Head extends HTMLElement {
4243
4255
  }
4244
4256
  return this._childElementArray;
4245
4257
  }
4258
+ /**
4259
+ * head へ入れる子のクローン。束縛を持つ子は、束ねたクローンを使い回す(boundClones)
4260
+ */
4261
+ _cloneOf(child) {
4262
+ if (!hasBinding(child)) {
4263
+ return child.cloneNode(true);
4264
+ }
4265
+ let clone = boundClones.get(child);
4266
+ if (clone === undefined) {
4267
+ clone = child.cloneNode(true);
4268
+ boundClones.set(child, clone);
4269
+ }
4270
+ return clone;
4271
+ }
4246
4272
  /**
4247
4273
  * 要素の一意キーを生成(WeakMap でキャッシュ)
4248
4274
  */
@@ -4371,7 +4397,7 @@ class Head extends HTMLElement {
4371
4397
  const head = headStack[i];
4372
4398
  for (const child of head._childElementArray) {
4373
4399
  if (this._getKey(child) === key) {
4374
- targetElement = child.cloneNode(true);
4400
+ targetElement = this._cloneOf(child);
4375
4401
  break;
4376
4402
  }
4377
4403
  }
@@ -4386,9 +4412,13 @@ class Head extends HTMLElement {
4386
4412
  }
4387
4413
  // headを更新
4388
4414
  const current = headElementMap.get(key) ?? null;
4415
+ // 束ねたクローンが既に入っている(同じ Head の再適用)
4416
+ if (targetElement !== null && current === targetElement) {
4417
+ continue;
4418
+ }
4389
4419
  // 同じ要素は入れ直さない。入れ直すとスタイルシートを取り直し、<base> の差し替えは base-uri の
4390
4420
  // CSP を毎回検査させる(WebKit は遷移ごとに違反を報告した — docs/seam-apps.md、prod-booking)。
4391
- // 束縛を持つ要素は、束ねたクローンを入れるため従来どおり入れ直す
4421
+ // 束縛を持つ要素は、束ねたクローン(boundClones)が入っていれば上で残した。別の要素が入っていれば入れ直す
4392
4422
  if (targetElement && current?.isEqualNode(targetElement) && !hasBinding(targetElement)) {
4393
4423
  continue;
4394
4424
  }
@@ -4462,7 +4492,7 @@ function bootstrapRouter(config, registry) {
4462
4492
  registerComponents(registry);
4463
4493
  }
4464
4494
 
4465
- var version = "4.7.0";
4495
+ var version = "4.9.0";
4466
4496
  var pkg = {
4467
4497
  version: version};
4468
4498