@datagouv/components-next 1.3.0 → 1.4.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.
Files changed (131) hide show
  1. package/dist/{Control-b-43UT2B.js → Control-B9WQxlpJ.js} +10 -10
  2. package/dist/{Datafair.client-BrjISlaZ.js → Datafair.client-D_6yzJUG.js} +9 -9
  3. package/dist/{Event-py_AAwJY.js → Event-iXDrp-fy.js} +15 -15
  4. package/dist/{Image-BHQYZWzH.js → Image-mNMBOofs.js} +22 -22
  5. package/dist/ImagePreview.client-B0iPhFm3.js +36 -0
  6. package/dist/{JsonPreview.client-DivFAnbN.js → JsonPreview.client-DSl1kiwC.js} +2 -2
  7. package/dist/{Map-CtP7leHl.js → Map-BfqKMw0S.js} +165 -165
  8. package/dist/{MapContainer.client-Cq8tNLZZ.js → MapContainer.client-BSfpk_rT.js} +17 -17
  9. package/dist/{OSM-gdDSIsDA.js → OSM-CcrUhItr.js} +1 -1
  10. package/dist/{PdfPreview.client-BNBgLsK2.js → PdfPreview.client-BANFeM6K.js} +438 -427
  11. package/dist/{Pmtiles.client-CQi5Rw8W.js → Pmtiles.client-DH9ZrsZR.js} +6177 -5967
  12. package/dist/PreviewWrapper.vue_vue_type_script_setup_true_lang-I8EZCgzp.js +60 -0
  13. package/dist/{ScaleLine-hG-FhNqy.js → ScaleLine-VGQ7nkMS.js} +2 -2
  14. package/dist/{Tile-D6rFonpT.js → Tile-CSpn0Ca8.js} +47 -47
  15. package/dist/{TileImage-cfrEgz5y.js → TileImage-CpbaEFwd.js} +44 -44
  16. package/dist/{View-vp7vDb9q.js → View-BYBpt-AU.js} +58 -58
  17. package/dist/{XmlPreview.client-XCsNvnsZ.js → XmlPreview.client-KCB5mwVf.js} +3 -3
  18. package/dist/{common-C8efyyuc.js → common-BoeTUnDZ.js} +58 -58
  19. package/dist/components-next.css +1 -1
  20. package/dist/components-next.js +199 -172
  21. package/dist/components.css +1 -1
  22. package/dist/{index-CXUamc8Z.js → index-DHWzX5vK.js} +4668 -4466
  23. package/dist/{leaflet-src-BRKv9Ksv.js → leaflet-src-pVQfonBI.js} +1 -1
  24. package/dist/{main-DKu5SOAl.js → main-BDcYkhOc.js} +41684 -33432
  25. package/dist/{proj-CsjVeojN.js → proj-DxGbobp7.js} +110 -110
  26. package/dist/{tilecoord-CPcQJnrF.js → tilecoord-DvX7WWiA.js} +94 -94
  27. package/dist/{vue3-xml-viewer.common-BIaEIFYG.js → vue3-xml-viewer.common-Bdcn54ST.js} +1 -1
  28. package/package.json +28 -27
  29. package/src/components/ActivityList/ActivityList.vue +21 -12
  30. package/src/components/AppLink.vue +3 -0
  31. package/src/components/BannerAction.vue +6 -2
  32. package/src/components/Chart/ChartViewer.vue +111 -17
  33. package/src/components/Chart/ChartViewerWrapper.vue +28 -16
  34. package/src/components/ChartCard.vue +112 -0
  35. package/src/components/CopyButton.vue +6 -2
  36. package/src/components/DataserviceCard.vue +23 -6
  37. package/src/components/DataserviceQuality.vue +82 -0
  38. package/src/components/DataserviceQualityInline.vue +31 -0
  39. package/src/components/DataserviceQualityTooltipContent.vue +79 -0
  40. package/src/components/DatasetCard.vue +17 -6
  41. package/src/components/DatasetInformation/DatasetTemporalitySection.vue +7 -4
  42. package/src/components/DatasetQuality.vue +11 -11
  43. package/src/components/DatasetQualityInline.vue +2 -2
  44. package/src/components/DatasetQualityTooltipContent.vue +1 -1
  45. package/src/components/DiscussionMessageCard.vue +14 -15
  46. package/src/components/Form/SchemaSelect.vue +2 -0
  47. package/src/components/FormattedDate.vue +69 -0
  48. package/src/components/LoadingBlock.vue +4 -1
  49. package/src/components/ObjectCard.vue +4 -1
  50. package/src/components/ObjectCardOwner.vue +13 -1
  51. package/src/components/Pagination.vue +18 -58
  52. package/src/components/Placeholder.vue +3 -2
  53. package/src/components/PostCard.vue +13 -15
  54. package/src/components/ResourceAccordion/Datafair.client.vue +1 -1
  55. package/src/components/ResourceAccordion/Downloads.vue +19 -7
  56. package/src/components/ResourceAccordion/ImagePreview.client.vue +48 -0
  57. package/src/components/ResourceAccordion/MapContainer.client.vue +1 -8
  58. package/src/components/ResourceAccordion/Metadata.vue +21 -5
  59. package/src/components/ResourceAccordion/PdfPreview.client.vue +36 -12
  60. package/src/components/ResourceAccordion/PdfSkeleton.vue +44 -0
  61. package/src/components/ResourceAccordion/Pmtiles.client.vue +27 -18
  62. package/src/components/ResourceAccordion/Preview.vue +8 -4
  63. package/src/components/ResourceAccordion/PreviewWrapper.vue +17 -10
  64. package/src/components/ResourceAccordion/ResourceAccordion.vue +29 -9
  65. package/src/components/ResourceExplorer/ResourceExplorer.vue +105 -209
  66. package/src/components/ResourceExplorer/ResourceExplorerHeader.vue +79 -0
  67. package/src/components/ResourceExplorer/ResourceExplorerSidebar.vue +104 -71
  68. package/src/components/ResourceExplorer/ResourceExplorerViewer.vue +136 -183
  69. package/src/components/ResourceExplorer/ResourceMainAction.vue +240 -0
  70. package/src/components/ResourceExplorer/ResourceSelector.vue +24 -86
  71. package/src/components/ResourceExplorer/ResourceViewerHeader.vue +124 -0
  72. package/src/components/ResourceExplorer/ResourceViewerSkeleton.vue +96 -0
  73. package/src/components/ResourceListItem.vue +168 -0
  74. package/src/components/ReuseCard.vue +18 -6
  75. package/src/components/ReuseDetails.vue +2 -2
  76. package/src/components/ReuseHorizontalCard.vue +4 -3
  77. package/src/components/SchemaCard.vue +10 -1
  78. package/src/components/Search/Filter/AccessTypeFilter.vue +2 -2
  79. package/src/components/Search/GlobalSearch.vue +12 -8
  80. package/src/components/Search/SearchInput.vue +1 -1
  81. package/src/components/Search/Sidemenu.vue +4 -3
  82. package/src/components/SmallChart.vue +11 -10
  83. package/src/components/StatBox.vue +13 -5
  84. package/src/components/TabularExplorer/TabularActiveFilters.vue +79 -0
  85. package/src/components/TabularExplorer/TabularCell.vue +7 -8
  86. package/src/components/TabularExplorer/TabularCellPopover.vue +19 -3
  87. package/src/components/TabularExplorer/TabularColumnsMenu.vue +112 -0
  88. package/src/components/TabularExplorer/TabularDateField.vue +41 -0
  89. package/src/components/TabularExplorer/TabularDateFilter.vue +403 -0
  90. package/src/components/TabularExplorer/TabularExplorer.vue +122 -913
  91. package/src/components/TabularExplorer/TabularFilterContent.vue +33 -25
  92. package/src/components/TabularExplorer/TabularFilterPopover.vue +7 -7
  93. package/src/components/TabularExplorer/TabularMobileFilterButton.vue +21 -0
  94. package/src/components/TabularExplorer/TabularMobileFilters.vue +150 -0
  95. package/src/components/TabularExplorer/TabularRowsInfo.vue +31 -0
  96. package/src/components/TabularExplorer/TabularSkeleton.vue +92 -0
  97. package/src/components/TabularExplorer/TabularTable.vue +484 -0
  98. package/src/components/TabularExplorer/TabularToolbar.vue +25 -0
  99. package/src/components/TabularExplorer/types.ts +32 -20
  100. package/src/components/TabularExplorer/useColumnMetadata.ts +98 -0
  101. package/src/components/TabularExplorer/useTabularContext.ts +82 -0
  102. package/src/components/TopicCard.vue +15 -14
  103. package/src/composables/useActiveDescendant.ts +5 -0
  104. package/src/composables/useDatasetResources.ts +164 -0
  105. package/src/composables/useHasTabularData.ts +2 -1
  106. package/src/composables/useResizable.ts +46 -0
  107. package/src/composables/useResourceCapabilities.ts +47 -39
  108. package/src/composables/useTranslation.ts +24 -9
  109. package/src/config.ts +1 -0
  110. package/src/functions/charts.ts +32 -1
  111. package/src/functions/dates.ts +26 -7
  112. package/src/functions/helpers.ts +15 -0
  113. package/src/functions/metrics.ts +57 -56
  114. package/src/functions/owned.ts +21 -0
  115. package/src/functions/paginate.ts +46 -0
  116. package/src/functions/resourceCapabilities.ts +34 -0
  117. package/src/functions/resources.ts +83 -0
  118. package/src/functions/schemas.ts +27 -0
  119. package/src/functions/scroll.ts +20 -0
  120. package/src/functions/tabular.ts +119 -4
  121. package/src/functions/tabularApi.ts +1 -43
  122. package/src/main.ts +32 -6
  123. package/src/types/dataservices.ts +15 -0
  124. package/src/types/organizations.ts +10 -0
  125. package/src/types/reuses.ts +12 -1
  126. package/src/types/search.ts +2 -2
  127. package/src/types/visualizations.ts +5 -0
  128. package/dist/PreviewWrapper.vue_vue_type_script_setup_true_lang-C3dDzrIr.js +0 -61
  129. /package/src/components/{DatasetQualityItem.vue → QualityItem.vue} +0 -0
  130. /package/src/components/{DatasetQualityItemWarning.vue → QualityItemWarning.vue} +0 -0
  131. /package/src/components/{DatasetQualityScore.vue → QualityScore.vue} +0 -0
@@ -0,0 +1,82 @@
1
+ import type { Component, ComputedRef, InjectionKey, Ref } from 'vue'
2
+ import { inject, provide } from 'vue'
3
+ import type {
4
+ ColumnFilters,
5
+ ColumnType,
6
+ SortConfig,
7
+ TabularColumnProfile,
8
+ TabularDataResponse,
9
+ TabularRow,
10
+ } from './types'
11
+
12
+ export type ActiveFilter = {
13
+ column: string
14
+ label: string
15
+ }
16
+
17
+ export type ColumnDisplay = {
18
+ icon: Component
19
+ label: string
20
+ }
21
+
22
+ // Data + cross-cutting state shared by the tabular explorer's parts (toolbar, header
23
+ // filters, table). Provided by <TabularExplorer>, injected by children so they can be
24
+ // arranged freely without prop-drilling.
25
+ //
26
+ // NOT here — kept local to whoever renders it, because nothing else needs it:
27
+ // - column widths / resize, cell popover, mobile row expansion → TabularTable
28
+ // - mobile filter sheet's expanded column → TabularMobileFilters
29
+ export type TabularContext = {
30
+ // Data & pagination (the parent owns the fetch, children just render it)
31
+ tableData: Ref<TabularDataResponse | null>
32
+ totalLines: ComputedRef<number>
33
+ allRows: Ref<TabularRow[]>
34
+ hasMore: Ref<boolean>
35
+ loadNextPage: () => Promise<void>
36
+ // A sort / filter / search change is refetching while the previous rows are
37
+ // still on screen.
38
+ isRefreshing: ComputedRef<boolean>
39
+
40
+ // Sort & filters
41
+ sort: Ref<SortConfig | null>
42
+ filters: Ref<Record<string, ColumnFilters>>
43
+ activeFilters: ComputedRef<ActiveFilter[]>
44
+ removeFilter: (column: string) => void
45
+ clearAllFilters: () => void
46
+ hasFilterForColumn: (col: string) => boolean
47
+
48
+ // Columns visibility
49
+ allColumns: ComputedRef<string[]>
50
+ visibleColumns: Ref<Set<string>>
51
+ displayedColumns: ComputedRef<string[]>
52
+ hiddenCount: ComputedRef<number>
53
+ toggleColumn: (col: string) => void
54
+ showAllColumns: () => void
55
+ hideAllColumns: () => void
56
+ selectOnlyColumn: (col: string) => void
57
+
58
+ // Mobile filter sheet open/close (button lives in the toolbar, sheet elsewhere)
59
+ mobileFilterOpen: Ref<boolean>
60
+
61
+ // Column metadata helpers (pure derivations of the profile)
62
+ columnTypesMap: ComputedRef<Record<string, ColumnType>>
63
+ getColumnType: (col: string) => ColumnType
64
+ getColumnProfile: (col: string) => TabularColumnProfile | null
65
+ getColumnDisplay: (col: string) => ColumnDisplay
66
+ getNullPercent: (col: string) => string
67
+ getBooleanCounts: (col: string) => { trueCount: number, falseCount: number }
68
+ }
69
+
70
+ const TABULAR_CONTEXT_KEY: InjectionKey<TabularContext> = Symbol('tabular-context')
71
+
72
+ export function provideTabularContext(context: TabularContext) {
73
+ provide(TABULAR_CONTEXT_KEY, context)
74
+ }
75
+
76
+ export function useTabularContext(): TabularContext {
77
+ const context = inject(TABULAR_CONTEXT_KEY)
78
+ if (!context) {
79
+ throw new Error('useTabularContext() must be used inside a <TabularExplorer>')
80
+ }
81
+ return context
82
+ }
@@ -35,18 +35,27 @@
35
35
  <ObjectCardOwner
36
36
  :organization="topic.organization"
37
37
  :owner="topic.owner"
38
+ :organization-url="organizationUrl"
38
39
  />
39
40
  <RiSubtractLine
40
41
  v-if="(topic.organization || topic.owner) && topic.last_modified"
41
42
  aria-hidden="true"
42
43
  class="hidden md:block size-4 flex-none fill-gray-medium"
43
44
  />
44
- <div
45
+ <TranslationT
45
46
  v-if="topic.last_modified"
47
+ tag="div"
46
48
  class="w-full md:w-auto text-gray-medium whitespace-nowrap"
49
+ keypath="Mis à jour {date}"
47
50
  >
48
- {{ t('Mis à jour {date}', { date: formatDate(topic.last_modified) }) }}
49
- </div>
51
+ <template #date>
52
+ <FormattedDate
53
+ :date="topic.last_modified"
54
+ format="relative"
55
+ :options="{ dateStyle: 'long' }"
56
+ />
57
+ </template>
58
+ </TranslationT>
50
59
  </div>
51
60
 
52
61
  <ObjectCardShortDescription :text="topic.description" />
@@ -97,8 +106,6 @@
97
106
  import { RiBookShelfLine, RiDatabase2Line, RiLineChartLine, RiSubtractLine, RiTerminalLine } from '@remixicon/vue'
98
107
  import type { RouteLocationRaw } from 'vue-router'
99
108
  import type { TopicV2 } from '../types/topics'
100
- import { useFormatDate } from '../functions/dates'
101
- import { useTranslation } from '../composables/useTranslation'
102
109
  import ObjectCardHeader from './ObjectCardHeader.vue'
103
110
  import ObjectCardOwner from './ObjectCardOwner.vue'
104
111
  import ObjectCardShortDescription from './ObjectCardShortDescription.vue'
@@ -106,6 +113,8 @@ import OrganizationLogo from './OrganizationLogo.vue'
106
113
  import Avatar from './Avatar.vue'
107
114
  import Placeholder from './Placeholder.vue'
108
115
  import ObjectCard from './ObjectCard.vue'
116
+ import FormattedDate from './FormattedDate.vue'
117
+ import TranslationT from './TranslationT.vue'
109
118
 
110
119
  type TopicWithStats = TopicV2 & {
111
120
  nb_datasets?: number
@@ -116,19 +125,11 @@ type TopicWithStats = TopicV2 & {
116
125
  withDefaults(defineProps<{
117
126
  topic: TopicWithStats
118
127
  topicUrl?: RouteLocationRaw
128
+ organizationUrl?: RouteLocationRaw | null
119
129
  showLogo?: boolean
120
130
  showStats?: boolean
121
131
  }>(), {
122
132
  showLogo: true,
123
133
  showStats: true,
124
134
  })
125
-
126
- const { t } = useTranslation()
127
- const { formatRelativeIfRecentDate } = useFormatDate()
128
-
129
- const formatDate = (dateString: string) => {
130
- return formatRelativeIfRecentDate(dateString, {
131
- dateStyle: 'long',
132
- })
133
- }
134
135
  </script>
@@ -60,23 +60,28 @@ export function useActiveDescendant<T extends Option>(options: MaybeRefOrGetter<
60
60
 
61
61
  function handleKeyPressForActiveDescendant(key: KeyboardEvent, alreadyMovedDown = false) {
62
62
  switch (key.key as CommonKeyboardKeys) {
63
+ // An arrow that moves the active option must not also scroll the page behind it
63
64
  case 'ArrowDown':
64
65
  if (direction === 'vertical' && !alreadyMovedDown && !key.altKey) {
66
+ key.preventDefault()
65
67
  activateNextOption()
66
68
  }
67
69
  break
68
70
  case 'ArrowUp':
69
71
  if (direction === 'vertical') {
72
+ key.preventDefault()
70
73
  activatePreviousOption()
71
74
  }
72
75
  break
73
76
  case 'ArrowLeft':
74
77
  if (direction === 'horizontal') {
78
+ key.preventDefault()
75
79
  activatePreviousOption()
76
80
  }
77
81
  break
78
82
  case 'ArrowRight':
79
83
  if (direction === 'horizontal' && !alreadyMovedDown && !key.altKey) {
84
+ key.preventDefault()
80
85
  activateNextOption()
81
86
  }
82
87
  break
@@ -0,0 +1,164 @@
1
+ import { computed, ref, toValue, watch, type MaybeRefOrGetter, type Ref } from 'vue'
2
+ import { useRouteQuery } from '@vueuse/router'
3
+ import { useComponentsConfig } from '../config'
4
+ import { useDebouncedRef } from './useDebouncedRef'
5
+ import { useFetch } from '../functions/api'
6
+ import { RESOURCE_EXPLORER_PAGE_SIZE, RESOURCE_TYPE } from '../functions/resources'
7
+ import type { PaginatedArray } from '../types/api'
8
+ import type { DatasetV2 } from '../types/datasets'
9
+ import type { Resource, ResourceGroup, ResourceType } from '../types/resources'
10
+
11
+ // Fetches a dataset's resources grouped by type (paginated per type, searchable)
12
+ // and derives the currently selected resource from the `resource_id` query param.
13
+ // Shared by the dataset page and the explore page so the left navigation behaves
14
+ // identically in both.
15
+ export async function useDatasetResources(datasetGetter: MaybeRefOrGetter<DatasetV2>) {
16
+ const config = useComponentsConfig()
17
+
18
+ const search = ref('')
19
+ const { debounced: searchDebounced, flush } = useDebouncedRef(search, config.searchDebounce ?? 300)
20
+
21
+ const datasetId = computed(() => toValue(datasetGetter).id)
22
+ const url = computed(() => `/api/2/datasets/${datasetId.value}/resources/`)
23
+
24
+ const makeParams = (type: ResourceType) => computed(() => ({
25
+ type,
26
+ page_size: RESOURCE_EXPLORER_PAGE_SIZE,
27
+ q: searchDebounced.value || undefined,
28
+ }))
29
+
30
+ // Evaluated once at setup (before any search) — never changes afterwards
31
+ const hasAnyResources = computed(() => toValue(datasetGetter).resources.total > 0)
32
+
33
+ const extraResourcesByType: Ref<Resource[]>[] = RESOURCE_TYPE.map(() => ref<Resource[]>([]))
34
+ const pageByType: Ref<number>[] = RESOURCE_TYPE.map(() => ref(1))
35
+
36
+ watch(searchDebounced, () => {
37
+ for (let i = 0; i < RESOURCE_TYPE.length; i++) {
38
+ extraResourcesByType[i]!.value = []
39
+ pageByType[i]!.value = 1
40
+ }
41
+ })
42
+
43
+ // Separate useFetch for loadMore, initialized with immediate: false so it doesn't
44
+ // fetch until execute() is called from the event handler.
45
+ const loadMoreType = ref<ResourceType>('main')
46
+ const loadMorePage = ref(1)
47
+ const loadMoreParams = computed(() => ({
48
+ type: loadMoreType.value,
49
+ page_size: RESOURCE_EXPLORER_PAGE_SIZE,
50
+ page: loadMorePage.value,
51
+ q: searchDebounced.value || undefined,
52
+ }))
53
+
54
+ const resourceIdQuery = useRouteQuery<string | undefined>('resource_id')
55
+ const initialResourceId = resourceIdQuery.value
56
+
57
+ // Vue rule: composables must be called synchronously, before any `await` — `inject()`
58
+ // needs the active component instance, which a plain .ts composable loses after its
59
+ // first await (documented in useTabularProfile.ts). The package's `useFetch` calls
60
+ // `useComponentsConfig()` (an inject) on every call, so we kick off every request
61
+ // up-front, then await them together. This is also the idiomatic Nuxt parallel-fetch.
62
+ const typeFetches = RESOURCE_TYPE.map(type =>
63
+ useFetch<PaginatedArray<Resource>>(url, {
64
+ params: makeParams(type),
65
+ // Only main is server-rendered; the rest hydrate client-side to keep SSR light.
66
+ server: type === 'main',
67
+ }),
68
+ )
69
+ const loadMoreFetch = useFetch<PaginatedArray<Resource>>(url, { params: loadMoreParams, immediate: false, watch: false })
70
+ // The resource pointed at by `resource_id` (SSR / deep link) may live beyond the first
71
+ // page of its type group, so it wouldn't be in flatResources — fetch it directly.
72
+ const fetchedResourceFetch = initialResourceId
73
+ ? useFetch<Resource>(`/api/1/datasets/${datasetId.value}/resources/${initialResourceId}/`)
74
+ : null
75
+
76
+ const typeResults = await Promise.all(typeFetches)
77
+ const { data: loadMoreData, execute: executeLoadMore } = await loadMoreFetch
78
+ const fetchedResource = fetchedResourceFetch ? (await fetchedResourceFetch).data : ref<Resource | null>(null)
79
+
80
+ const rawDataByType = typeResults.map(result => result.data)
81
+
82
+ // Which type group is currently loading its next page. A single loadMoreFetch is
83
+ // shared across types, so we track the type here to show the spinner on the right
84
+ // group's "Charger plus…" button.
85
+ const loadingType = ref<ResourceType | null>(null)
86
+
87
+ const loadMore = async (type: ResourceType) => {
88
+ const index = RESOURCE_TYPE.indexOf(type)
89
+ if (index === -1) return
90
+ const pageRef = pageByType[index]!
91
+ const extraRef = extraResourcesByType[index]!
92
+ pageRef.value++
93
+
94
+ loadMoreType.value = type
95
+ loadMorePage.value = pageRef.value
96
+ loadingType.value = type
97
+ try {
98
+ await executeLoadMore()
99
+
100
+ if (loadMoreData.value) {
101
+ extraRef.value = [...extraRef.value, ...loadMoreData.value.data]
102
+ }
103
+ }
104
+ finally {
105
+ loadingType.value = null
106
+ }
107
+ }
108
+
109
+ const groups = computed<ResourceGroup[]>(() => {
110
+ return RESOURCE_TYPE
111
+ .map((type, index) => {
112
+ const rawData = rawDataByType[index]!
113
+ const extraData = extraResourcesByType[index]!
114
+ return {
115
+ type: type as ResourceType,
116
+ total: rawData.value?.total ?? 0,
117
+ items: [...(rawData.value?.data ?? []), ...extraData.value],
118
+ }
119
+ })
120
+ .filter(group => group.items.length > 0)
121
+ })
122
+
123
+ const flatResources = computed(() => groups.value.flatMap(g => g.items))
124
+
125
+ // The URL is the single source of truth for the selection: no ref to keep in
126
+ // sync, navigation is done with plain links that change `resource_id`.
127
+ let lastShown: Resource | null = null
128
+ const remember = (resource: Resource | null) => {
129
+ if (resource) lastShown = resource
130
+ return resource
131
+ }
132
+
133
+ const selectedResource = computed<Resource | null>(() => {
134
+ const wantedId = resourceIdQuery.value
135
+ const fromList = flatResources.value.find(r => r.id === wantedId)
136
+ if (fromList) return remember(fromList)
137
+ // `fetchedResource` answers for `initialResourceId` only: it holds that one
138
+ // resource, so using it for any other id would show something the URL doesn't
139
+ // point at.
140
+ if (wantedId && wantedId === initialResourceId) return remember(fetchedResource.value)
141
+ // A search that matches nothing narrows the navigation, it doesn't unload the
142
+ // viewer — keep showing what we had, which is the dataset's first resource when
143
+ // nothing has been clicked yet.
144
+ return remember(flatResources.value[0] ?? null) ?? lastShown
145
+ })
146
+
147
+ function updateSearch(newSearch: string) {
148
+ search.value = newSearch
149
+ // Only a reset skips the debounce: typing must stay debounced, since each
150
+ // change fires one request per resource type.
151
+ if (!newSearch) flush()
152
+ }
153
+
154
+ return {
155
+ groups,
156
+ flatResources,
157
+ hasAnyResources,
158
+ selectedResource,
159
+ loadMore,
160
+ loadingType,
161
+ search,
162
+ updateSearch,
163
+ }
164
+ }
@@ -1,4 +1,5 @@
1
1
  import { useComponentsConfig } from '../config'
2
+ import { hasTabularParsingError } from '../functions/resources'
2
3
  import type { Resource } from '../types/resources'
3
4
 
4
5
  /**
@@ -20,7 +21,7 @@ export const useHasTabularData = () => {
20
21
  return (
21
22
  config.tabularApiUrl
22
23
  && resource.extras['analysis:parsing:parsing_table']
23
- && !resource.extras['analysis:parsing:error']
24
+ && !hasTabularParsingError(resource)
24
25
  && !sourceUnreachable
25
26
  && (config.tabularAllowRemote || resource.filetype === 'file')
26
27
  )
@@ -0,0 +1,46 @@
1
+ import { ref } from 'vue'
2
+ import { useEventListener } from '@vueuse/core'
3
+
4
+ type UseResizableOptions = {
5
+ initialWidth: number
6
+ minWidth: number
7
+ maxWidth: number
8
+ }
9
+
10
+ // Drag-to-resize a horizontal panel. Returns the reactive width, a `resizing`
11
+ // flag (to disable width transitions while dragging) and a `startResize` handler
12
+ // to bind on a drag handle's `mousedown`. Encapsulates the drag math, clamping and
13
+ // the temporary body cursor / text-selection lock. VueUse has no ready-made panel
14
+ // resize (useResizeObserver only observes size), so we build it on `useEventListener`
15
+ // which handles listener cleanup and SSR for us.
16
+ export function useResizable({ initialWidth, minWidth, maxWidth }: UseResizableOptions) {
17
+ const width = ref(initialWidth)
18
+ const resizing = ref(false)
19
+ let startX = 0
20
+ let startWidth = 0
21
+
22
+ const clamp = (value: number) => Math.min(maxWidth, Math.max(minWidth, Math.round(value)))
23
+
24
+ function startResize(event: MouseEvent) {
25
+ event.preventDefault()
26
+ startX = event.clientX
27
+ startWidth = width.value
28
+ resizing.value = true
29
+ document.body.style.userSelect = 'none'
30
+ document.body.style.cursor = 'col-resize'
31
+ }
32
+
33
+ useEventListener('mousemove', (event: MouseEvent) => {
34
+ if (!resizing.value) return
35
+ width.value = clamp(startWidth + event.clientX - startX)
36
+ })
37
+
38
+ useEventListener('mouseup', () => {
39
+ if (!resizing.value) return
40
+ resizing.value = false
41
+ document.body.style.userSelect = ''
42
+ document.body.style.cursor = ''
43
+ })
44
+
45
+ return { width, resizing, startResize }
46
+ }
@@ -1,16 +1,20 @@
1
- import { computed, toValue, type MaybeRefOrGetter } from 'vue'
1
+ import { computed, type MaybeRefOrGetter, toValue } from 'vue'
2
2
  import { useComponentsConfig } from '../config'
3
- import { useTranslation } from './useTranslation'
4
- import { useHasTabularData } from './useHasTabularData'
5
- import { detectOgcService } from '../functions/resources'
6
3
  import { isOrganizationCertified } from '../functions/organizations'
7
- import type { Resource, WfsMetadata } from '../types/resources'
4
+ import { getGeneratedFormats, getWfsExportFormats } from '../functions/resourceCapabilities'
5
+ import { detectOgcService, getParsingErrorMessage, getParsingErrorStep, isImagePreviewFormat } from '../functions/resources'
8
6
  import type { Dataset, DatasetV2 } from '../types/datasets'
9
- import { getWfsExportFormats } from '../functions/resourceCapabilities'
7
+ import type { Resource, WfsMetadata } from '../types/resources'
8
+ import { useHasTabularData } from './useHasTabularData'
9
+ import { useTranslation } from './useTranslation'
10
10
 
11
- const GENERATED_FORMATS = ['parquet', 'pmtiles', 'geojson']
12
11
  const URL_FORMATS = ['url', 'doi', 'www:link', 'www:link-1.0-http--link', 'www:link-1.0-http--partners', 'www:link-1.0-http--related', 'www:link-1.0-http--samples']
13
12
 
13
+ // Which preview the data tab shows. Single source of truth: the viewer renders it and
14
+ // the skeleton picks the matching placeholder shape, so each holding its own copy of
15
+ // this precedence would let the two drift apart.
16
+ export type PreviewKind = 'json' | 'pdf' | 'xml' | 'image' | 'datafair' | 'openapi' | 'tabular' | 'unavailable'
17
+
14
18
  export function useResourceCapabilities(
15
19
  resource: MaybeRefOrGetter<Resource>,
16
20
  dataset: MaybeRefOrGetter<Dataset | DatasetV2>,
@@ -19,11 +23,6 @@ export function useResourceCapabilities(
19
23
  const { t } = useTranslation()
20
24
  const checkTabularData = useHasTabularData()
21
25
 
22
- const hasPreview = computed(() => {
23
- const format = toValue(resource).format?.toLowerCase()
24
- return format === 'json' || format === 'pdf' || format === 'xml'
25
- })
26
-
27
26
  const hasTabularData = computed(() => {
28
27
  const r = toValue(resource)
29
28
  return checkTabularData(r)
@@ -49,24 +48,12 @@ export function useResourceCapabilities(
49
48
  const ogcService = computed(() => detectOgcService(toValue(resource)))
50
49
  const ogcWms = computed(() => ogcService.value === 'wms')
51
50
 
52
- const generatedFormats = computed(() => {
53
- const r = toValue(resource)
54
- const formats = GENERATED_FORMATS
55
- .filter(format => `analysis:parsing:${format}_url` in r.extras)
56
- .map(format => ({
57
- url: r.extras[`analysis:parsing:${format}_url`] as string,
58
- size: r.extras[`analysis:parsing:${format}_size`] as number | undefined,
59
- format,
60
- }))
61
- if ('analysis:parsing:parsing_table' in r.extras) {
62
- formats.push({
63
- url: `${config.tabularApiUrl}/api/resources/${r.id}/data/json/`,
64
- size: undefined,
65
- format: 'json',
66
- })
67
- }
68
- return formats
69
- })
51
+ // The map is built from a pmtiles export; when that export fails we still want
52
+ // to show the Carte tab, but with the reason it could not be generated.
53
+ const hasPmtilesError = computed(() => getParsingErrorStep(toValue(resource)) === 'pmtiles_export')
54
+ const pmtilesError = computed(() => hasPmtilesError.value ? getParsingErrorMessage(toValue(resource)) : null)
55
+
56
+ const generatedFormats = computed(() => getGeneratedFormats(toValue(resource), config.tabularApiUrl))
70
57
 
71
58
  const wfsFormats = computed(() => {
72
59
  return getWfsExportFormats(toValue(resource))
@@ -81,31 +68,50 @@ export function useResourceCapabilities(
81
68
 
82
69
  const isResourceUrl = computed(() => URL_FORMATS.includes(toValue(resource).format))
83
70
 
71
+ // A dedicated preview always wins over the interactive table: a PDF that also
72
+ // carries a parsing table is a PDF first.
73
+ const previewKind = computed<PreviewKind>(() => {
74
+ const format = toValue(resource).format?.toLowerCase()
75
+ if (format === 'json') return 'json'
76
+ if (format === 'pdf') return 'pdf'
77
+ if (format === 'xml') return 'xml'
78
+ if (isImagePreviewFormat(format)) return 'image'
79
+ if (hasDatafairPreview.value) return 'datafair'
80
+ if (hasOpenAPIPreview.value) return 'openapi'
81
+ if (hasTabularData.value) return 'tabular'
82
+ return 'unavailable'
83
+ })
84
+
84
85
  const tabsOptions = computed(() => {
85
86
  const r = toValue(resource)
86
87
  const options = []
87
88
 
88
- if (hasTabularData.value) {
89
- options.push({ key: 'data', label: t('Données') })
89
+ const dataTab = { key: 'data', label: hasTabularData.value ? t('Données') : t('Aperçu') }
90
+ const mapTab = { key: 'map', label: t('Carte') }
91
+ const hasMap = hasPmtiles.value || ogcWms.value
92
+
93
+ // The map is the most visual preview: when it is available, show it first.
94
+ // When its generation failed, keep the data preview first and surface the
95
+ // Carte tab (with its error) right after.
96
+ if (hasMap) {
97
+ options.push(mapTab, dataTab)
98
+ }
99
+ else if (hasPmtilesError.value) {
100
+ options.push(dataTab, mapTab)
90
101
  }
91
102
  else {
92
- options.push({ key: 'data', label: t('Aperçu') })
103
+ options.push(dataTab)
93
104
  }
94
105
 
95
106
  if (hasTabularData.value) {
96
107
  options.push({ key: 'data-structure', label: t('Structure des données') })
97
108
  }
98
109
 
99
- if (hasPmtiles.value || ogcWms.value) {
100
- options.push({ key: 'map', label: t('Carte') })
101
- }
102
-
103
110
  if (r.description) {
104
111
  options.push({ key: 'description', label: t('Description') })
105
112
  }
106
113
 
107
114
  options.push({ key: 'metadata', label: t('Métadonnées') })
108
- options.push({ key: 'downloads', label: t('Téléchargements') })
109
115
 
110
116
  if (hasTabularData.value) {
111
117
  options.push({ key: 'api', label: t('API') })
@@ -115,9 +121,11 @@ export function useResourceCapabilities(
115
121
  })
116
122
 
117
123
  return {
118
- hasPreview,
124
+ previewKind,
119
125
  hasTabularData,
120
126
  hasPmtiles,
127
+ hasPmtilesError,
128
+ pmtilesError,
121
129
  hasDatafairPreview,
122
130
  hasOpenAPIPreview,
123
131
  ogcService,
@@ -14,24 +14,39 @@ const translationModules = import.meta.glob<Record<string, string>>('../../../lo
14
14
  import: 'default',
15
15
  })
16
16
 
17
+ const LANGUAGE_SUBTAG_REGEX = /^[a-z]{2,3}$/
18
+
19
+ /**
20
+ * Extract the language subtag of an `accept-language` header or of
21
+ * `navigator.language`, and return it only if it is a well-formed one.
22
+ *
23
+ * Both are user-controlled, and the locale is handed over to `Intl` formatters,
24
+ * which throw a `RangeError` on anything that is not a valid language tag. The
25
+ * wildcard `*` is rejected here too: it means "any language", so it must fall
26
+ * back to the next detection step.
27
+ */
28
+ function parseLanguage(value: string | undefined | null): string | null {
29
+ if (!value) {
30
+ return null
31
+ }
32
+ const language = value.split(';')[0]!.split(',')[0]!.split('-')[0]!.toLowerCase()
33
+ return LANGUAGE_SUBTAG_REGEX.test(language) ? language : null
34
+ }
35
+
17
36
  function detectLanguage(): string {
18
37
  // Server-side (Nuxt)
19
38
  try {
20
- const header = useRequestHeader?.('accept-language')
21
- const acceptLanguage = header
22
- if (acceptLanguage) {
23
- const primaryLang = acceptLanguage.split(';')[0]!.split(',')[0]!.split('-')[0]!.toLowerCase()
24
- // Ignore wildcard * language, that should fallback to client side detection or default language
25
- if (primaryLang !== '*') return primaryLang
26
- }
39
+ const language = parseLanguage(useRequestHeader?.('accept-language'))
40
+ if (language) return language
27
41
  }
28
42
  catch {
29
43
  // useRequestHeaders not available, continue to client-side detection
30
44
  }
31
45
 
32
46
  // Client-side
33
- if (typeof window !== 'undefined' && navigator.language) {
34
- return navigator.language.split('-')[0]!.toLowerCase()
47
+ if (typeof window !== 'undefined') {
48
+ const language = parseLanguage(navigator.language)
49
+ if (language) return language
35
50
  }
36
51
 
37
52
  return 'fr'
package/src/config.ts CHANGED
@@ -12,6 +12,7 @@ export type PluginConfig = {
12
12
  datasetQualityGuideUrl?: string
13
13
  maxJsonPreviewCharSize?: number // Maximum size of JSON to preview in characters. JSON preview module is partly collapsed by default so we can have a preview for large files.
14
14
  maxPdfPreviewByteSize?: number // Maximum size of PDF to preview in bytes
15
+ maxImagePreviewByteSize?: number // Maximum size of image to preview in bytes
15
16
  maxXmlPreviewCharSize?: number // Maximum size of XML to preview in characters. XML preview module can NOT be collapsed by default so we should not have a preview for large files.
16
17
  pmtilesViewerBaseUrl?: string | null // Base URL of a pmtiles viewer (ex: https://pmtiles.io/#url=)
17
18
  metricsApiUrl?: string
@@ -1,4 +1,6 @@
1
- import type { Chart, ChartForm, ChartForApi, Filter } from '../types/visualizations'
1
+ import type { Chart, ChartForm, ChartForApi, Filter, ColumnDefinition } from '../types/visualizations'
2
+ import type { ColumnType, TabularProfile } from '../components/TabularExplorer/types'
3
+ import { resolveColumnType } from './tabular'
2
4
 
3
5
  export function toChartForm(chart: Chart) {
4
6
  const seriesFilter = chart.series[0]?.filters as Filter | null
@@ -66,3 +68,32 @@ export function toChartApi(chartForm: ChartForm): ChartForApi {
66
68
  extras: chartForm.extras,
67
69
  }
68
70
  }
71
+
72
+ export function buildColumnsFromProfile(profile: { profile: TabularProfile }): Array<ColumnDefinition> {
73
+ return profile.profile.header.map((name) => {
74
+ const colInfo = profile.profile.columns[name]
75
+ const isCategorical = profile.profile.categorical?.includes(name) ?? false
76
+ // The chart stack only branches on 'number' and 'date' (continuous axis,
77
+ // aggregatable series, time formatting): it has no notion of a year column,
78
+ // and on an axis a year is a number.
79
+ const resolvedType = resolveColumnType(colInfo ?? { python_type: 'unknown', format: undefined }, isCategorical)
80
+ const colType = resolvedType === 'year' ? 'number' : resolvedType
81
+ const colProfile = profile.profile.profile?.[name]
82
+ return {
83
+ name,
84
+ type: colType,
85
+ min: normalizeProfileNumber(colProfile?.min, colType),
86
+ max: normalizeProfileNumber(colProfile?.max, colType),
87
+ }
88
+ })
89
+ }
90
+
91
+ function normalizeProfileNumber(value: number | string | undefined, type: ColumnType): number | undefined {
92
+ if (value === undefined || value === null) return undefined
93
+ if (type === 'date' && typeof value === 'string') {
94
+ const timestamp = new Date(value).getTime()
95
+ return Number.isNaN(timestamp) ? undefined : timestamp
96
+ }
97
+ const parsed = Number(value)
98
+ return Number.isNaN(parsed) ? undefined : parsed
99
+ }