@wcstack/router 4.3.0 → 4.5.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/README.ja.md CHANGED
@@ -184,7 +184,7 @@ router は、スタンプしたルート本文の終わりにコメントの印
184
184
  | `data` | output のみ | 現在のナビゲーションの guard 関数がロードしたデータ — `true` の代わりにオブジェクトを返した guard の返り値([ルート commit 前のデータロード](#ルート-commit-前のデータロード) 参照)。どの guard もオブジェクトを返さなければ `null`(初期化前も `null`)。クエリのみの遷移(same-match)では前の値を保つ。上の各メンバーと違い **frozen にしない** — guard が返したオブジェクトをそのまま露出する。`wcs-router:data-changed` を発火 |
185
185
  | `navigateUrl` | 書き込み面(null-idle transient) | ターゲットを書くと push 遷移。null は待機、文字列の書き込みで `navigate()` が起動し、完了後に自分で null へ戻る。null / `""` の書き込みは no-op。書くのは**ルートのパス** — basename は router が付ける: リンクの `href` ではなく `/products/3` を書く(basename `/ja` の下で `/ja/products/3` を書くと `/ja/ja/products/3` へ行く) |
186
186
  | `replaceUrl` | 書き込み面(null-idle transient) | `navigateUrl` と完全同型の契約。ただし現在の履歴エントリを**置き換える** |
187
- | `leaveConfirm` | input(属性 `leave-confirm`) | 空でない文字列の間、**別のルート**へのナビゲーション(リンク・戻る / 進む・`navigate()`)の前に `confirm(leaveConfirm)` を出し、断られたら留まる。**ページを離れる**ナビゲーションのうちページが取り消せるもの(router の `basename` の外へのリンク — 言語を basename に持つページの言語の切り替え — や別のサイトへのリンク、フォームの送信)も、Navigation API があれば同じく聞く(無ければブラウザの確認)。受け入れたらブラウザは聞き直さない。ページを閉じる・読み直すときはブラウザ自身の確認(`beforeunload`)。未保存の変更に束ねる: `data-wcs="leaveConfirm: discardPrompt"` と `get discardPrompt() { return this.dirty ? "変更を破棄しますか?" : null; }`。クエリだけの遷移と、確認済みの遷移のリダイレクトでは聞かない。保存のハンドラが同じ更新でこれを外して `navigateUrl` を書いてもよい — router はその更新の後で確かめる。ブラウザがページに取り消させない戻る / 進むでは聞けない。`null` は属性を外す |
187
+ | `leaveConfirm` | input(属性 `leave-confirm`) | 空でない文字列の間、**別のルート**へのナビゲーション(リンク・戻る / 進む・`navigate()`)の前に `confirm(leaveConfirm)` を出し、断られたら留まる。**ページを離れる**ナビゲーションのうちページが取り消せるもの(router の `basename` の外へのリンク — 言語を basename に持つページの言語の切り替え — や別のサイトへのリンク、フォームの送信)も、Navigation API があれば同じく聞く(無ければブラウザの確認)。受け入れたらブラウザは聞き直さない。ページを閉じる・読み直すときはブラウザ自身の確認(`beforeunload`)。1 つの切り替えで両方を扱います。読み直しでは失われるがルートの移動では残るもの(ページ直下の要素で進行中のアップロード)だけを守るには、それには `leaveConfirm` を使わず、`$connectedCallback` で自分の `beforeunload` リスナーを足してください。未保存の変更に束ねる: `data-wcs="leaveConfirm: discardPrompt"` と `get discardPrompt() { return this.dirty ? "変更を破棄しますか?" : null; }`。クエリだけの遷移と、確認済みの遷移のリダイレクトでは聞かない。保存のハンドラが同じ更新でこれを外して `navigateUrl` を書いてもよい — router はその更新の後で確かめる。ブラウザがページに取り消させない戻る / 進むでは聞けない。`null` は属性を外す |
188
188
  | `basename` | input | `basename` 属性に書く。Router はこの属性を初期化のときに一度だけ読むので、それより前に書く(後から書いてもルーティングの基準は変わらない。属性を書き換えたときと同じ)。読むと使われている basename を返す(初期化前は `""`)。`null` は属性を外し、`undefined` は最初の属性へ戻す |
189
189
 
190
190
  コマンド `navigate(path)` / `replace(path)`(いずれも async)も宣言され、command-token プロトコルから起動できる。
package/README.md CHANGED
@@ -184,7 +184,7 @@ Define routes and layout slots inside a child template tag. A direct child templ
184
184
  | `data` | output only | Data the current navigation's guard functions loaded — a guard that returns an object instead of `true` (see [Loading data before a route commits](#loading-data-before-a-route-commits)). `null` when no guard returned data, including before initialization; a query-only (same-match) navigation keeps the previous value. Unlike the members above it is **not** frozen: it is the object your guard returned, passed through as-is. Fires `wcs-router:data-changed`. |
185
185
  | `navigateUrl` | write surface (null-idle transient) | Write a target to push-navigate. `null` means idle; writing a string starts `navigate()`, and the property resets itself to `null` when the navigation finishes. `null` / `""` writes are no-ops. The target is a **route path** — the basename is added for you: write `/products/3`, not the `href` of a link (`/ja/products/3` under the basename `/ja` lands on `/ja/ja/products/3`). |
186
186
  | `replaceUrl` | write surface (null-idle transient) | Identical contract to `navigateUrl`, but the navigation **replaces** the current history entry. |
187
- | `leaveConfirm` | input (attribute `leave-confirm`) | While it is a non-empty string, a navigation to **another route** — a link, Back / Forward, `navigate()` — first asks `confirm(leaveConfirm)` and stays when it is declined. So does a navigation that **leaves the page** and the page may cancel — a link outside the router's `basename` (a language switch, with the locale in the basename) or to another site, a form submission — where the Navigation API is (elsewhere it gets the browser's prompt); when it is accepted, the browser does not ask again. Closing or reloading the page gets the browser's own prompt (`beforeunload`). Bind it to unsaved changes: `data-wcs="leaveConfirm: discardPrompt"` with `get discardPrompt() { return this.dirty ? "Discard your changes?" : null; }`. A query-only navigation does not ask, nor does the redirect of a navigation already confirmed. A save handler may clear it and write `navigateUrl` in the same update: the router checks after that update. A Back / Forward the browser does not let a page cancel is not asked. `null` removes the attribute. |
187
+ | `leaveConfirm` | input (attribute `leave-confirm`) | While it is a non-empty string, a navigation to **another route** — a link, Back / Forward, `navigate()` — first asks `confirm(leaveConfirm)` and stays when it is declined. So does a navigation that **leaves the page** and the page may cancel — a link outside the router's `basename` (a language switch, with the locale in the basename) or to another site, a form submission — where the Navigation API is (elsewhere it gets the browser's prompt); when it is accepted, the browser does not ask again. Closing or reloading the page gets the browser's own prompt (`beforeunload`). The one switch covers both: to guard only what a reload loses but a route change keeps (uploads still running in a page-level element), leave `leaveConfirm` unset for them and add your own `beforeunload` listener in `$connectedCallback`. Bind it to unsaved changes: `data-wcs="leaveConfirm: discardPrompt"` with `get discardPrompt() { return this.dirty ? "Discard your changes?" : null; }`. A query-only navigation does not ask, nor does the redirect of a navigation already confirmed. A save handler may clear it and write `navigateUrl` in the same update: the router checks after that update. A Back / Forward the browser does not let a page cancel is not asked. `null` removes the attribute. |
188
188
  | `basename` | input | Writes the `basename` attribute, which the router reads once, when it initializes: set it before then (a later write does not move the routing base, as with the attribute). Reading it returns the basename in effect (`""` before initialization). `null` removes the attribute; `undefined` restores the attribute the element started with. |
189
189
 
190
190
  Commands `navigate(path)` and `replace(path)` (both async) are also declared, so they can be invoked through the command-token protocol.
package/dist/index.esm.js CHANGED
@@ -4427,7 +4427,7 @@ function bootstrapRouter(config, registry) {
4427
4427
  registerComponents(registry);
4428
4428
  }
4429
4429
 
4430
- var version = "4.3.0";
4430
+ var version = "4.5.0";
4431
4431
  var pkg = {
4432
4432
  version: version};
4433
4433
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wcstack/router",
3
- "version": "4.3.0",
3
+ "version": "4.5.0",
4
4
  "description": "Declarative SPA routing for Web Components with Navigation API support. Zero dependencies, buildless.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.esm.js",