@wcstack/router 4.10.0 → 4.10.1

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.esm.js CHANGED
@@ -233,6 +233,14 @@ function queryIncludes(current, required) {
233
233
  }
234
234
  return true;
235
235
  }
236
+ /**
237
+ * 2 つのクエリが同じパラメータを同じ値で持つか(順序は問わない — `queryIncludes` を両向きに)。`<wcs-link>` の
238
+ * `aria-current="page"` は、`to` のクエリが今のページのクエリと等しいときだけ(docs/seam-apps.md、city-library の
239
+ * 取り込み: `page` を省いた 1 ページ目へのリンクが、含む規則ではどのページでも現在のページだった)。
240
+ */
241
+ function queryEquals(a, b) {
242
+ return queryIncludes(a, b) && queryIncludes(b, a);
243
+ }
236
244
 
237
245
  /**
238
246
  * guard 判定関数に渡す第 3 引数を組み立てる。
@@ -4321,23 +4329,30 @@ class Link extends HTMLElement {
4321
4329
  if (this._path.startsWith('?') && this._anchorElement) {
4322
4330
  this._setAnchorHref(this._anchorElement, this._path);
4323
4331
  }
4324
- // active 判定は pathname の比較(§1.1 欠陥 7 の修理)に、`to` のクエリが今のページのクエリに含まれること
4325
- // を足す(`to` にクエリが無ければ pathname だけ)。`/search?q=a` の「次のページ」(`?q=a&page=2`)が
4326
- // 「現在のページ」と読み上げられていた(docs/seam-apps.md、city-library)
4332
+ // active 判定は pathname の比較(§1.1 欠陥 7 の修理)に、`to` のクエリを足す(`to` にクエリが無ければ
4333
+ // pathname だけ)。そのページ(aria-current="page")は今のページのクエリが `to` のクエリと等しいとき、
4334
+ // match="prefix" なら含むときも("true"、パスの「下」と同じ)。`/search?q=a` の「次のページ」
4335
+ // (`?q=a&page=2`)が「現在のページ」と読み上げられ(docs/seam-apps.md、city-library)、含む規則では
4336
+ // `page` を省いた 1 ページ目へのリンクがどのページでもそうだった(city-library の取り込み)
4327
4337
  const current = new URL(window.location.href);
4328
4338
  const currentPath = this._normalizePathname(current.pathname);
4329
4339
  const { pathname, search } = splitUrlTarget(this._path);
4330
- const queryMatches = queryIncludes(current.search, effectiveSearch(search));
4340
+ const wanted = effectiveSearch(search);
4341
+ const queryIncluded = queryIncludes(current.search, wanted);
4342
+ const queryEqual = wanted === '' || queryEquals(current.search, wanted);
4331
4343
  const linkPath = this._normalizePathname(this._isInternalTarget(this._path)
4332
4344
  ? (pathname === ""
4333
4345
  ? window.location.pathname
4334
4346
  : this._joinInternalPath(this.router.basename, pathname))
4335
4347
  : pathname);
4336
- // match="prefix": 下のパスでも active(サイドナビの「商品」が /products/3 でも印を付ける —
4337
- // docs/seam-apps.md、router-admin)。そのページそのものではないので aria-current は "true"
4348
+ // match="prefix": 下のパスでも、`to` のクエリを含む余分なパラメータ付きのクエリでも active(サイドナビの
4349
+ // 「商品」が /products/3 でも印を付ける — docs/seam-apps.md、router-admin)。そのページそのものではないので
4350
+ // aria-current は "true"
4338
4351
  // 行き先の無いリンク(`to` が空)はどこでも active ではない(空のパスは "/" に正規化される)
4339
- const exact = this._path !== '' && queryMatches && currentPath === linkPath;
4340
- const within = !exact && this._path !== '' && queryMatches && this.getAttribute('match') === 'prefix' && currentPath.startsWith(linkPath + '/');
4352
+ const samePath = currentPath === linkPath;
4353
+ const exact = this._path !== '' && samePath && queryEqual;
4354
+ const within = !exact && this._path !== '' && queryIncluded && this.getAttribute('match') === 'prefix'
4355
+ && (samePath || currentPath.startsWith(linkPath + '/'));
4341
4356
  if (this._anchorElement) {
4342
4357
  if (exact || within) {
4343
4358
  this._anchorElement.classList.add('active');
@@ -4673,7 +4688,7 @@ function bootstrapRouter(config, registry) {
4673
4688
  registerComponents(registry);
4674
4689
  }
4675
4690
 
4676
- var version = "4.10.0";
4691
+ var version = "4.10.1";
4677
4692
  var pkg = {
4678
4693
  version: version};
4679
4694