@datagouv/components-next 1.0.2-dev.121 → 1.0.2-dev.123

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.
@@ -1,4 +1,4 @@
1
- import { b4 as Ke } from "./main-BpO1p4v0.js";
1
+ import { b4 as Ke } from "./main-B40Z2ZUX.js";
2
2
  import We from "vue";
3
3
  function Fe(I, K) {
4
4
  for (var V = 0; V < K.length; V++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datagouv/components-next",
3
- "version": "1.0.2-dev.121",
3
+ "version": "1.0.2-dev.123",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {
@@ -549,20 +549,34 @@ const allFilters: Record<string, Ref<unknown>> = {
549
549
  type: reuseType,
550
550
  }
551
551
 
552
- // Reset sort and filters when changing type if they're not valid for the new type
552
+ // Reset page, sort and filters when changing type. Every reset below goes
553
+ // through useRouteQuery, so VueUse coalesces them into a single router.replace
554
+ // (its shared _queriesQueue flushes once on nextTick). Custom filters are cleared
555
+ // here too, rather than in useSearchFilter's onunmount, so their URL change joins
556
+ // that same batch instead of racing it with a separate router.replace.
553
557
  watch(currentType, () => {
558
+ // page=1 is the default and is dropped from the URL, so only reset when needed.
559
+ if (page.value !== 1) page.value = 1
560
+
554
561
  // Reset sort if not valid
555
562
  const validSortValues = activeSortOptions.value.map(o => o.value as string)
556
563
  if (sort.value && !validSortValues.includes(sort.value)) {
557
564
  sort.value = undefined
558
565
  }
559
566
 
560
- // Reset filters that are not enabled for the new type
567
+ // Reset built-in filters that are not enabled for the new type
561
568
  for (const [filterName, filterRef] of Object.entries(allFilters)) {
562
569
  if (filterRef.value !== undefined && !activeFilters.value.includes(filterName)) {
563
570
  filterRef.value = undefined
564
571
  }
565
572
  }
573
+
574
+ // Reset type-scoped custom filters that don't apply to the new type
575
+ for (const entry of customFilterRegistry.values()) {
576
+ if (entry.typeKeys && !entry.typeKeys.includes(currentType.value) && isCustomFilterActive(entry)) {
577
+ entry.ref.value = entry.defaultValue
578
+ }
579
+ }
566
580
  })
567
581
 
568
582
  // Create stable params for each type
@@ -94,10 +94,12 @@ export function useSearchFilter(
94
94
  })
95
95
 
96
96
  onScopeDispose(() => {
97
- // Clear the URL param when the scope ends. This mirrors GlobalSearch's
98
- // own `watch(currentType)` logic that drops built-in filters which don't
99
- // apply to the new type: a custom filter's applicability is signalled
100
- // by the consumer via `v-if`, so its unmount is the equivalent signal.
97
+ // Type-scoped filters (typeKeys set) are cleared by GlobalSearch's
98
+ // watch(currentType) instead, so their URL update batches with the other
99
+ // type-change resets via useRouteQuery rather than racing them with the
100
+ // separate router.replace below. Here we only clear filters that apply to
101
+ // all types: their unmount is a consumer signal unrelated to a type switch,
102
+ // which GlobalSearch has no way to detect.
101
103
  //
102
104
  // We cannot use `value.value = defaultValue` here because VueUse's
103
105
  // useRouteQuery registers its own tryOnScopeDispose cleanup that zeroes
@@ -105,7 +107,7 @@ export function useSearchFilter(
105
107
  // The setter then sees `query === v` and early-returns without ever
106
108
  // calling router.replace(). Instead we read the live route.query directly
107
109
  // (which is router state, not affected by that cleanup) and push the update.
108
- if (route.query[urlParam] !== undefined) {
110
+ if (normalizedTypeKeys === undefined && route.query[urlParam] !== undefined) {
109
111
  const { [urlParam]: _removed, ...restQuery } = route.query
110
112
  router.replace({
111
113
  query: defaultValue === undefined ? restQuery : { ...restQuery, [urlParam]: String(defaultValue) },