@datagouv/components-next 1.0.2-dev.173 → 1.0.2-dev.174

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 (57) hide show
  1. package/dist/{Datafair.client-DrxHU3d_.js → Datafair.client-BU2gspr8.js} +9 -9
  2. package/dist/ImagePreview.client-BU5QNqG_.js +36 -0
  3. package/dist/{JsonPreview.client-CvmhvpbB.js → JsonPreview.client-CvOpMCxW.js} +2 -2
  4. package/dist/{MapContainer.client-9VrKlUPt.js → MapContainer.client-DNOQ5XTT.js} +9 -9
  5. package/dist/{PdfPreview.client-CiPvfzzR.js → PdfPreview.client-DwAvLLq_.js} +438 -427
  6. package/dist/{Pmtiles.client-0R3Z5sYM.js → Pmtiles.client-CgaDrCHk.js} +1341 -1337
  7. package/dist/PreviewWrapper.vue_vue_type_script_setup_true_lang-CrWEJnPl.js +60 -0
  8. package/dist/{XmlPreview.client-N2n5j4WI.js → XmlPreview.client-B24FIhU7.js} +3 -3
  9. package/dist/components-next.css +1 -1
  10. package/dist/components-next.js +144 -138
  11. package/dist/components.css +1 -1
  12. package/dist/{index-D0JOBDBD.js → index-Dw1lR0oe.js} +1 -1
  13. package/dist/{leaflet-src-DxB74Wpp.js → leaflet-src-BoMqG6Yx.js} +1 -1
  14. package/dist/{main-QOs57DKh.js → main-I9G-L-lg.js} +16280 -15512
  15. package/dist/{vue3-xml-viewer.common-BnexQtzg.js → vue3-xml-viewer.common-PTUJZpH4.js} +1 -1
  16. package/package.json +1 -1
  17. package/src/components/AppLink.vue +3 -0
  18. package/src/components/CopyButton.vue +6 -2
  19. package/src/components/ResourceAccordion/Datafair.client.vue +1 -1
  20. package/src/components/ResourceAccordion/ImagePreview.client.vue +3 -3
  21. package/src/components/ResourceAccordion/MapContainer.client.vue +1 -8
  22. package/src/components/ResourceAccordion/PdfPreview.client.vue +36 -12
  23. package/src/components/ResourceAccordion/PdfSkeleton.vue +44 -0
  24. package/src/components/ResourceAccordion/Pmtiles.client.vue +25 -12
  25. package/src/components/ResourceAccordion/PreviewWrapper.vue +17 -10
  26. package/src/components/ResourceAccordion/ResourceAccordion.vue +4 -1
  27. package/src/components/ResourceExplorer/ResourceExplorer.vue +98 -209
  28. package/src/components/ResourceExplorer/ResourceExplorerHeader.vue +74 -0
  29. package/src/components/ResourceExplorer/ResourceExplorerSidebar.vue +103 -71
  30. package/src/components/ResourceExplorer/ResourceExplorerViewer.vue +123 -187
  31. package/src/components/ResourceExplorer/ResourceMainAction.vue +240 -0
  32. package/src/components/ResourceExplorer/ResourceSelector.vue +24 -86
  33. package/src/components/ResourceExplorer/ResourceViewerHeader.vue +115 -0
  34. package/src/components/ResourceExplorer/ResourceViewerSkeleton.vue +94 -0
  35. package/src/components/ResourceListItem.vue +154 -0
  36. package/src/components/TabularExplorer/TabularActiveFilters.vue +79 -0
  37. package/src/components/TabularExplorer/TabularCell.vue +2 -4
  38. package/src/components/TabularExplorer/TabularColumnsMenu.vue +112 -0
  39. package/src/components/TabularExplorer/TabularExplorer.vue +63 -994
  40. package/src/components/TabularExplorer/TabularFilterContent.vue +2 -10
  41. package/src/components/TabularExplorer/TabularFilterPopover.vue +5 -6
  42. package/src/components/TabularExplorer/TabularMobileFilterButton.vue +21 -0
  43. package/src/components/TabularExplorer/TabularMobileFilters.vue +150 -0
  44. package/src/components/TabularExplorer/TabularRowsInfo.vue +31 -0
  45. package/src/components/TabularExplorer/TabularSkeleton.vue +92 -0
  46. package/src/components/TabularExplorer/TabularTable.vue +481 -0
  47. package/src/components/TabularExplorer/TabularToolbar.vue +25 -0
  48. package/src/components/TabularExplorer/types.ts +0 -5
  49. package/src/components/TabularExplorer/useColumnMetadata.ts +98 -0
  50. package/src/components/TabularExplorer/useTabularContext.ts +82 -0
  51. package/src/composables/useDatasetResources.ts +164 -0
  52. package/src/composables/useResizable.ts +46 -0
  53. package/src/composables/useResourceCapabilities.ts +20 -7
  54. package/src/functions/resources.ts +19 -0
  55. package/src/main.ts +8 -0
  56. package/dist/ImagePreview.client-DHrr-JCM.js +0 -36
  57. package/dist/PreviewWrapper.vue_vue_type_script_setup_true_lang-B0PyOeL6.js +0 -58
@@ -1,680 +1,39 @@
1
1
  <template>
2
- <div>
3
- <!-- Outside the branches below: this slot holds the query controls (search
4
- input…), so it has to stay reachable when the query itself failed. -->
5
- <slot name="toolbar-top" />
6
-
7
- <div
8
- v-if="previewError"
9
- class="max-w-3xl mx-auto"
10
- >
11
- <SimpleBanner
12
- type="warning"
13
- class="mb-4"
14
- >
15
- {{ t("L'aperçu de ce fichier n'a pas pu être chargé.") }}
16
- <pre class="text-xs mt-2 whitespace-pre-wrap break-words">{{ previewError }}</pre>
17
- </SimpleBanner>
18
- </div>
19
-
20
- <div
21
- v-else-if="previewLoading"
22
- class="animate-pulse-placeholder"
23
- :aria-label="t('Chargement de l\'aperçu…')"
24
- role="status"
25
- >
26
- <div>
27
- <div class="flex items-center justify-end gap-4 py-3">
28
- <div class="h-4 w-20 bg-gray-200" />
29
- <div class="h-4 w-20 bg-gray-200" />
30
- </div>
31
- </div>
32
- <div class="overflow-hidden">
33
- <table class="w-full text-sm border-collapse">
34
- <thead class="shadow-[inset_0_-1px_0_0_#E5E5E5]">
35
- <tr>
36
- <th
37
- v-for="i in 6"
38
- :key="i"
39
- class="px-3 py-2 text-left"
40
- >
41
- <div class="h-4 w-24 bg-gray-200" />
42
- </th>
43
- </tr>
44
- </thead>
45
- <tbody>
46
- <tr
47
- v-for="row in 8"
48
- :key="row"
49
- class="border-b border-gray-100"
50
- >
51
- <td
52
- v-for="col in 6"
53
- :key="col"
54
- class="px-3 py-2.5"
55
- >
56
- <div class="h-3 bg-gray-200" />
57
- </td>
58
- </tr>
59
- </tbody>
60
- </table>
61
- </div>
62
- </div>
63
-
2
+ <div class="flex min-h-0 flex-1 flex-col">
3
+ <PreviewUnavailable v-if="previewError">
4
+ {{ t("L'aperçu de ce fichier n'a pas pu être chargé.") }}
5
+ <br>
6
+ <span class="text-xs break-words">{{ previewError }}</span>
7
+ </PreviewUnavailable>
8
+
9
+ <!-- Same skeleton as the Suspense fallback above us: in both cases the slot isn't
10
+ rendered yet, so its toolbar is a placeholder too. -->
11
+ <TabularSkeleton v-else-if="previewLoading" />
12
+
13
+ <!-- Loaded: the consumer composes the parts (toolbar, table, mobile sheet) from
14
+ the provided context, so it controls the framing and layout. -->
64
15
  <template v-else-if="tableData && profileData">
65
- <!-- Toolbar & active filters inherit the host's 1rem horizontal padding
66
- (px-4 on ResourceExplorerViewer's TabPanel, .container on
67
- ExploreResourceView), so they line up with the resource title /
68
- download button above. Only the table itself goes edge-to-edge
69
- (via -mx-4 below). -->
70
- <div>
71
- <div class="flex items-center py-3 gap-2">
72
- <!-- Mobile: filter & sort button -->
73
- <BrandedButton
74
- class="md:hidden"
75
- color="tertiary"
76
- size="2xs"
77
- :icon="RiFilterLine"
78
- keep-margins-even-without-borders
79
- @click="mobileFilterOpen = true"
80
- >
81
- {{ t('Filtres & tri') }}
82
- </BrandedButton>
83
-
84
- <div class="flex-1" />
85
-
86
- <!-- Right: Stats -->
87
- <div class="flex items-center gap-4">
88
- <!-- Columns (clickable, opens column popover) -->
89
- <Popover
90
- ref="columnAnchor"
91
- v-slot="{ open }"
92
- class="relative"
93
- >
94
- <PopoverButton class="flex items-center gap-1.5 text-xs text-gray-plain rounded px-2 py-1 hover:bg-gray-50 focus:outline-none">
95
- <RiLayoutColumnLine
96
- class="size-3"
97
- aria-hidden="true"
98
- />
99
- <span class="font-bold hidden md:inline">{{ t('Colonnes') }}</span>
100
- <span class="font-mono tabular-nums">{{ visibleColumns.size }}/{{ allColumns.length }}</span>
101
- <RiArrowDownSLine
102
- class="size-3 opacity-50"
103
- aria-hidden="true"
104
- />
105
- </PopoverButton>
106
-
107
- <ClientOnly>
108
- <Teleport to="#tooltips">
109
- <PopoverPanel
110
- v-show="open"
111
- ref="columnPanel"
112
- static
113
- class="bg-white border border-gray-default rounded shadow-lg w-72 absolute z-[800]"
114
- :style="columnFloatingStyles"
115
- >
116
- <div class="px-3 py-2 border-b border-gray-default space-y-1.5">
117
- <span class="block text-xs font-medium text-gray-title">
118
- {{ visibleColumns.size }} {{ t('sur') }} {{ allColumns.length }} {{ t('colonnes visibles') }}
119
- </span>
120
- <div class="flex items-center gap-1">
121
- <BrandedButton
122
- v-if="hiddenCount"
123
- color="tertiary"
124
- size="2xs"
125
- @click="showAllColumns"
126
- >
127
- {{ t('Tout afficher') }}
128
- </BrandedButton>
129
- <BrandedButton
130
- v-if="visibleColumns.size > 0"
131
- color="tertiary"
132
- size="2xs"
133
- @click="hideAllColumns"
134
- >
135
- {{ t('Tout masquer') }}
136
- </BrandedButton>
137
- </div>
138
- </div>
139
- <div class="max-h-64 overflow-auto p-1">
140
- <div
141
- v-for="col in allColumns"
142
- :key="col"
143
- class="group/col flex items-center gap-2 px-2 py-1.5 rounded hover:bg-gray-50 text-xs"
144
- >
145
- <label class="flex items-center gap-2 flex-1 min-w-0 cursor-pointer">
146
- <input
147
- type="checkbox"
148
- :checked="visibleColumns.has(col)"
149
- class="size-3.5 accent-new-primary"
150
- @change="toggleColumn(col)"
151
- >
152
- <span class="truncate">{{ col }}</span>
153
- </label>
154
- <button
155
- class="shrink-0 px-1 text-new-primary hover:underline hidden group-hover/col:block group-focus-within/col:block"
156
- @click="selectOnlyColumn(col)"
157
- >
158
- {{ t('Uniquement') }}
159
- </button>
160
- </div>
161
- </div>
162
- </PopoverPanel>
163
- </Teleport>
164
- </ClientOnly>
165
- </Popover>
166
-
167
- <!-- Rows -->
168
- <span class="flex items-center gap-1.5 text-xs text-gray-plain">
169
- <RiLoader5Line
170
- v-if="isRefreshing"
171
- class="size-3 text-new-primary animate-spin"
172
- aria-hidden="true"
173
- />
174
- <RiLayoutRowLine
175
- v-else
176
- class="size-3 text-mention-grey"
177
- aria-hidden="true"
178
- />
179
- <span class="font-bold hidden md:inline">{{ t('Lignes') }}</span>
180
- <!-- The count stays in place while refreshing: the spinner already
181
- says it is stale, and swapping it for a word of another width
182
- would shift the whole toolbar on every search. -->
183
- <span
184
- data-testid="row-count"
185
- class="font-mono tabular-nums"
186
- >{{ tableData.meta.total.toLocaleString() }}/{{ totalLines.toLocaleString() }}</span>
187
- </span>
188
- </div>
189
- </div>
190
-
191
- <!-- Active filters & sort -->
192
- <div
193
- v-if="activeFilters.length > 0 || sort"
194
- class="bg-gray-some border border-gray-default rounded-xl px-3 py-2.5 mb-3 space-y-2.5"
195
- >
196
- <!-- Header -->
197
- <div class="flex items-center justify-between">
198
- <div class="flex items-center gap-2">
199
- <RiFilterLine
200
- class="size-3.5"
201
- aria-hidden="true"
202
- />
203
- <span class="text-xs text-gray-plain">{{ activeFilters.length > 0 ? t('Filtres actifs') : t('Tri actif') }}</span>
204
- <span
205
- v-if="activeFilters.length > 0"
206
- class="inline-flex items-center justify-center rounded-full bg-new-primary/10 text-new-primary text-xs tabular-nums min-w-5 h-5 px-1.5"
207
- >
208
- {{ activeFilters.length }}
209
- </span>
210
- </div>
211
- <BrandedButton
212
- color="tertiary"
213
- size="2xs"
214
- :icon="RiCloseLine"
215
- @click="clearAllFilters(); sort = null"
216
- >
217
- {{ t('Tout effacer') }}
218
- </BrandedButton>
219
- </div>
220
- <!-- Chips -->
221
- <div class="flex flex-wrap gap-1.5">
222
- <!-- Sort chip -->
223
- <span
224
- v-if="sort"
225
- class="inline-flex items-center gap-1.5 bg-white border border-gray-silver rounded-lg pl-2 pr-1 py-1 text-xs"
226
- >
227
- <component
228
- :is="sort.direction === 'asc' ? RiArrowUpLine : RiArrowDownLine"
229
- class="size-3 text-new-primary"
230
- aria-hidden="true"
231
- />
232
- <span class="text-gray-plain">{{ t('Tri') }}</span>
233
- <span class="text-gray-title">{{ sort.column }}</span>
234
- <span class="text-gray-plain">{{ sort.direction === 'asc' ? t('croissant') : t('décroissant') }}</span>
235
- <button
236
- class="rounded p-0.5 text-gray-low hover:text-gray-plain hover:bg-gray-100"
237
- @click="sort = null"
238
- >
239
- <RiCloseLine
240
- class="size-3"
241
- aria-hidden="true"
242
- />
243
- <span class="sr-only">{{ t('Supprimer le tri') }}</span>
244
- </button>
245
- </span>
246
- <!-- Filter chips -->
247
- <span
248
- v-for="af in activeFilters"
249
- :key="af.column"
250
- :data-testid="`active-filter-${af.column}`"
251
- class="inline-flex items-center gap-1.5 bg-white border border-gray-silver rounded-lg pl-2 pr-1 py-1 text-xs"
252
- >
253
- <component
254
- :is="getColumnDisplay(af.column).icon"
255
- class="size-3 text-gray-title"
256
- aria-hidden="true"
257
- />
258
- <span class="text-gray-title">{{ af.column }}</span>
259
- <span class="text-gray-plain">{{ af.label }}</span>
260
- <button
261
- class="rounded p-0.5 text-gray-low hover:text-gray-plain hover:bg-gray-100"
262
- @click="removeFilter(af.column)"
263
- >
264
- <RiCloseLine
265
- class="size-3"
266
- aria-hidden="true"
267
- />
268
- <span class="sr-only">{{ t('Supprimer ce filtre') }}</span>
269
- </button>
270
- </span>
271
- </div>
272
- </div>
273
- </div>
274
- <!-- /toolbar & active filters -->
275
-
276
- <!-- No column selected -->
277
- <div
278
- v-if="displayedColumns.length === 0"
279
- class="flex flex-col items-center py-12"
280
- >
281
- <img
282
- :src="noColumnsSrc"
283
- class="h-32"
284
- alt=""
285
- >
286
- <p class="font-bold text-gray-title my-3">
287
- {{ t('Aucune colonne sélectionnée') }}
288
- </p>
289
- <BrandedButton
290
- color="secondary"
291
- size="xs"
292
- @click="showAllColumns"
293
- >
294
- {{ t('Afficher toutes les colonnes') }}
295
- </BrandedButton>
296
- </div>
297
-
298
- <!-- Desktop: scrollable table -->
299
- <!-- The table goes edge-to-edge while the toolbar / active-filter rows
300
- above keep the host's horizontal padding:
301
- - default: `-mx-4` cancels the host's 1rem padding (px-4 on
302
- ResourceExplorerViewer's TabPanel), so the table reaches the
303
- host box edge.
304
- - `fullBleed`: the table breaks out of the (max-width) container to
305
- span almost the whole viewport (explore page), keeping a 2rem
306
- gutter on each side so it doesn't touch the screen edges. Centered
307
- on the viewport via the classic `left-1/2` + `-translate-x-1/2`
308
- trick (works because the container is itself centered). -->
309
- <div
310
- v-if="displayedColumns.length > 0"
311
- ref="scrollContainer"
312
- class="hidden md:block overflow-auto max-h-[70vh] transition-opacity"
313
- :class="[
314
- fullBleed ? 'relative left-1/2 w-[calc(100vw_-_4rem)] -translate-x-1/2' : '-mx-4',
315
- { 'opacity-40': isRefreshing },
316
- ]"
317
- :aria-busy="isRefreshing"
318
- >
319
- <table class="text-sm border-collapse">
320
- <thead class="sticky top-0 bg-white z-10 shadow-[inset_0_-1px_0_0_#E5E5E5]">
321
- <tr class="border-b border-gray-default">
322
- <th
323
- v-for="col in displayedColumns"
324
- :key="col"
325
- class="group/th relative h-14 px-2 last:pr-5 text-left align-middle whitespace-nowrap border-r border-gray-default last:border-r-0"
326
- :style="columnWidths[col] ? { width: columnWidths[col] + 'px', minWidth: columnWidths[col] + 'px', maxWidth: columnWidths[col] + 'px' } : { maxWidth: '300px' }"
327
- >
328
- <div class="flex items-center gap-0.5 min-w-0">
329
- <span
330
- class="font-extrabold text-sm truncate"
331
- :title="col"
332
- >{{ col }}</span>
333
- <RiArrowUpLine
334
- v-if="sort?.column === col && sort.direction === 'asc'"
335
- class="size-3.5 shrink-0 text-new-primary"
336
- aria-hidden="true"
337
- />
338
- <RiArrowDownLine
339
- v-else-if="sort?.column === col && sort.direction === 'desc'"
340
- class="size-3.5 shrink-0 text-new-primary"
341
- aria-hidden="true"
342
- />
343
- <TabularFilterPopover
344
- v-model:sort="sort"
345
- v-model:filters="filters"
346
- class="mt-1"
347
- :column="col"
348
- :column-type="getColumnType(col)"
349
- :column-profile="getColumnProfile(col)"
350
- :null-percent="getNullPercent(col)"
351
- :total-lines="totalLines"
352
- :category-badge-styles="getColumnType(col) === 'categorical' ? getCategoryBadgeStylesForColumn(col) : undefined"
353
- :boolean-counts="getColumnType(col) === 'boolean' ? getBooleanCounts(col) : undefined"
354
- />
355
- </div>
356
- <!-- Column type (semantic format when available) -->
357
- <span class="font-mono text-xs text-gray-plain -mt-0.5 inline-flex items-center gap-1 max-w-full">
358
- <component
359
- :is="getColumnDisplay(col).icon"
360
- class="size-3 shrink-0"
361
- aria-hidden="true"
362
- />
363
- <span class="mt-px truncate">{{ getColumnDisplay(col).label }}</span>
364
- </span>
365
- <!-- Resize handle: wide hit zone, thin visible bar -->
366
- <div
367
- class="absolute top-0 bottom-0 w-3 z-20 cursor-col-resize group/resize"
368
- :class="col === displayedColumns[displayedColumns.length - 1] ? 'right-3' : '-right-1.5'"
369
- @mousedown.prevent="startResize(col, $event)"
370
- >
371
- <div
372
- class="absolute inset-y-0 left-1/2 w-1 -translate-x-1/2 rounded-full bg-primary/40 opacity-0 group-hover/resize:opacity-100"
373
- :class="{ '!opacity-100': resizing?.column === col }"
374
- />
375
- </div>
376
- </th>
377
- </tr>
378
- </thead>
379
- <tbody>
380
- <tr v-if="allRows.length === 0">
381
- <td
382
- :colspan="displayedColumns.length"
383
- class="py-16 text-center"
384
- >
385
- <div class="flex flex-col items-center gap-2">
386
- <RiSearchLine
387
- class="size-8 text-gray-low"
388
- aria-hidden="true"
389
- />
390
- <span class="text-sm text-gray-low">{{ t('Aucun résultat trouvé.') }}</span>
391
- </div>
392
- </td>
393
- </tr>
394
- <tr
395
- v-for="(row, i) in allRows"
396
- :key="row.__id ?? i"
397
- class="border-b border-gray-default even:bg-gray-lowest-2 hover:bg-gray-100"
398
- >
399
- <td
400
- v-for="col in displayedColumns"
401
- :key="col"
402
- data-cell
403
- class="p-2 align-middle whitespace-nowrap border-r border-gray-default last:border-r-0 overflow-hidden cursor-pointer hover:bg-gray-200/50"
404
- :class="{ 'text-right font-mono tabular-nums text-sm': getColumnType(col) === 'number' || getColumnType(col) === 'date' || getColumnType(col) === 'year' }"
405
- :style="columnWidths[col] ? { maxWidth: columnWidths[col] + 'px' } : { maxWidth: '300px' }"
406
- @click="onCellClick(col, row[col], $event)"
407
- >
408
- <AppLink
409
- v-if="isLinkColumn(col)"
410
- :to="getRowHref(row)"
411
- class="link"
412
- >
413
- <TabularCell v-bind="cellProps(col, row)" />
414
- </AppLink>
415
- <TabularCell
416
- v-else
417
- v-bind="cellProps(col, row)"
418
- />
419
- </td>
420
- </tr>
421
- </tbody>
422
- </table>
423
- <InfiniteLoader
424
- v-if="hasMore"
425
- :root="scrollContainerRef"
426
- @intersect="loadNextPage"
427
- />
428
- </div>
429
-
430
- <!-- Cell popover -->
431
- <TabularCellPopover
432
- v-model:cell="activeCell"
433
- v-model:filters="filters"
434
- />
435
-
436
- <!-- Mobile: card layout -->
437
- <div
438
- v-if="displayedColumns.length > 0"
439
- class="md:hidden space-y-2 px-1 transition-opacity"
440
- :class="{ 'opacity-40': isRefreshing }"
441
- :aria-busy="isRefreshing"
442
- >
443
- <div
444
- v-if="allRows.length === 0"
445
- class="py-16 text-center"
446
- >
447
- <div class="flex flex-col items-center gap-2">
448
- <RiSearchLine
449
- class="size-8 text-gray-low"
450
- aria-hidden="true"
451
- />
452
- <span class="text-sm text-gray-low">{{ t('Aucun résultat trouvé.') }}</span>
453
- </div>
454
- </div>
455
- <div
456
- v-for="(row, i) in allRows"
457
- :key="row.__id ?? i"
458
- class="border border-gray-default rounded-lg p-3 space-y-2"
459
- :class="i % 2 === 1 ? 'bg-gray-lowest-2' : 'bg-white'"
460
- >
461
- <div
462
- v-for="col in mobileVisibleFields(i)"
463
- :key="col"
464
- class="flex flex-col gap-0.5 min-w-0"
465
- >
466
- <div class="flex items-center gap-1 min-w-0">
467
- <component
468
- :is="getColumnDisplay(col).icon"
469
- class="size-3 text-gray-low shrink-0"
470
- aria-hidden="true"
471
- />
472
- <span
473
- class="text-xs text-gray-plain truncate"
474
- :title="col"
475
- >{{ col }}</span>
476
- </div>
477
- <!-- Numbers and dates take their colour from here rather than from
478
- the cell, so a link wrapping one (see `rowHref`) keeps its own. -->
479
- <div
480
- data-cell
481
- class="min-w-0 pl-4 cursor-pointer text-gray-title"
482
- @click="onCellClick(col, row[col], $event)"
483
- >
484
- <AppLink
485
- v-if="isLinkColumn(col)"
486
- :to="getRowHref(row)"
487
- class="link"
488
- >
489
- <TabularCell
490
- v-bind="cellProps(col, row)"
491
- compact
492
- />
493
- </AppLink>
494
- <TabularCell
495
- v-else
496
- v-bind="cellProps(col, row)"
497
- compact
498
- />
499
- </div>
500
- </div>
501
- <button
502
- v-if="displayedColumns.length > 4"
503
- class="text-xs text-gray-title hover:underline pt-1 flex items-center gap-1"
504
- @click="toggleMobileExpand(i)"
505
- >
506
- <RiArrowDownSLine
507
- class="size-3 transition-transform"
508
- :class="{ 'rotate-180': mobileExpandedRows.has(i) }"
509
- aria-hidden="true"
510
- />
511
- {{ mobileExpandedRows.has(i) ? t('Moins') : `+${displayedColumns.length - 4} ${t('champs')}` }}
512
- </button>
513
- </div>
514
- </div>
515
-
516
- <!-- Mobile: filter bottom sheet -->
517
- <TransitionRoot
518
- :show="mobileFilterOpen"
519
- as="template"
520
- >
521
- <Dialog
522
- class="relative z-[900]"
523
- @close="mobileFilterOpen = false"
524
- >
525
- <!-- Backdrop -->
526
- <TransitionChild
527
- as="template"
528
- enter="ease-out duration-300"
529
- enter-from="opacity-0"
530
- enter-to="opacity-100"
531
- leave="ease-in duration-200"
532
- leave-from="opacity-100"
533
- leave-to="opacity-0"
534
- >
535
- <div class="fixed inset-0 bg-black/30" />
536
- </TransitionChild>
537
- <!-- Panel -->
538
- <TransitionChild
539
- as="template"
540
- enter="ease-out duration-300"
541
- enter-from="translate-y-full"
542
- enter-to="translate-y-0"
543
- leave="ease-in duration-200"
544
- leave-from="translate-y-0"
545
- leave-to="translate-y-full"
546
- >
547
- <div class="fixed inset-x-0 bottom-0 max-h-[80vh] flex flex-col bg-white rounded-t-2xl shadow-xl">
548
- <!-- Header -->
549
- <DialogPanel class="flex flex-col max-h-[80vh]">
550
- <div class="px-4 pt-4 pb-2 border-b border-gray-default">
551
- <DialogTitle class="text-sm font-bold">
552
- {{ t('Filtres & tri par colonne') }}
553
- </DialogTitle>
554
- <p class="text-xs text-gray-low">
555
- {{ allColumns.length }} {{ t('colonnes') }} · {{ activeFilters.length }} {{ t('filtre') }}{{ activeFilters.length !== 1 ? 's' : '' }}
556
- </p>
557
- </div>
558
- <!-- Column list -->
559
- <div class="flex-1 overflow-y-auto">
560
- <div
561
- v-for="col in allColumns"
562
- :key="col"
563
- class="border-b border-gray-default last:border-b-0"
564
- >
565
- <button
566
- class="flex items-center gap-2 w-full px-3 py-2.5 text-left"
567
- :class="hasFilterForColumn(col) ? 'bg-new-primary/5' : ''"
568
- @click="toggleMobileFilterColumn(col)"
569
- >
570
- <component
571
- :is="getColumnDisplay(col).icon"
572
- class="size-3.5 text-gray-low shrink-0"
573
- aria-hidden="true"
574
- />
575
- <span class="flex-1 text-sm text-gray-title truncate">{{ col }}</span>
576
- <RiArrowUpLine
577
- v-if="sort?.column === col && sort.direction === 'asc'"
578
- class="size-3 text-new-primary shrink-0"
579
- aria-hidden="true"
580
- />
581
- <RiArrowDownLine
582
- v-if="sort?.column === col && sort.direction === 'desc'"
583
- class="size-3 text-new-primary shrink-0"
584
- aria-hidden="true"
585
- />
586
- <span
587
- v-if="hasFilterForColumn(col)"
588
- class="size-2 rounded-full bg-new-primary shrink-0"
589
- />
590
- <RiArrowDownSLine
591
- class="size-3.5 text-gray-low shrink-0 transition-transform"
592
- :class="{ 'rotate-180': mobileFilterExpandedCol === col }"
593
- aria-hidden="true"
594
- />
595
- </button>
596
- <div
597
- v-if="mobileFilterExpandedCol === col"
598
- class="pb-1"
599
- >
600
- <TabularFilterContent
601
- v-model:sort="sort"
602
- v-model:filters="filters"
603
- :column="col"
604
- :column-type="getColumnType(col)"
605
- :column-profile="getColumnProfile(col)"
606
- :null-percent="getNullPercent(col)"
607
- :total-lines="totalLines"
608
- :category-badge-styles="getColumnType(col) === 'categorical' ? getCategoryBadgeStylesForColumn(col) : undefined"
609
- :boolean-counts="getColumnType(col) === 'boolean' ? getBooleanCounts(col) : undefined"
610
- />
611
- </div>
612
- </div>
613
- </div>
614
- <!-- Reset all -->
615
- <div
616
- v-if="activeFilters.length > 0 || sort"
617
- class="border-t border-gray-default px-4 py-3"
618
- >
619
- <BrandedButton
620
- color="secondary"
621
- size="xs"
622
- class="w-full"
623
- @click="clearAllFilters(); sort = null; mobileFilterOpen = false"
624
- >
625
- {{ t('Tout réinitialiser') }}
626
- </BrandedButton>
627
- </div>
628
- </DialogPanel>
629
- </div>
630
- </TransitionChild>
631
- </Dialog>
632
- </TransitionRoot>
16
+ <slot />
633
17
  </template>
634
18
  </div>
635
19
  </template>
636
20
 
637
21
  <script setup lang="ts">
638
- import { computed, nextTick, onUnmounted, ref, watch, useTemplateRef } from 'vue'
22
+ import { computed, ref, watch } from 'vue'
639
23
  import { ofetch } from 'ofetch'
640
- import { useElementSize } from '@vueuse/core'
641
- import { flip, shift, autoUpdate, useFloating } from '@floating-ui/vue'
642
- import { Dialog, DialogPanel, DialogTitle, Popover, PopoverButton, PopoverPanel, TransitionChild, TransitionRoot } from '@headlessui/vue'
643
- import {
644
- RiLayoutColumnLine,
645
- RiLayoutRowLine,
646
- RiArrowDownSLine,
647
- RiArrowUpLine,
648
- RiArrowDownLine,
649
- RiFilterLine,
650
- RiCloseLine,
651
- RiSearchLine,
652
- RiLoader5Line,
653
- } from '@remixicon/vue'
654
24
  import { useFetch } from '../../functions/api'
655
25
  import { useComponentsConfig } from '../../config'
656
26
  import { useTranslation } from '../../composables/useTranslation'
657
27
  import { injectTabularProfile } from '../../composables/useTabularProfile'
658
- import { buildTypeConfig, buildFormatConfig, humanizeFormat, GENERIC_FORMATS, hasFilterForColumn as _hasFilterForColumn, isTruthy, isFalsy, resolveColumnType, buildGlobalSearchConditions } from '../../functions/tabular'
659
- import AppLink from '../AppLink.vue'
660
- import ClientOnly from '../ClientOnly.vue'
661
- import SimpleBanner from '../SimpleBanner.vue'
662
- import BrandedButton from '../BrandedButton.vue'
663
- import InfiniteLoader from '../InfiniteLoader.vue'
664
- import TabularCell from './TabularCell.vue'
665
- import TabularCellPopover from './TabularCellPopover.vue'
666
- import type { CellInfo } from './TabularCellPopover.vue'
667
- import TabularFilterContent from './TabularFilterContent.vue'
668
- import TabularFilterPopover from './TabularFilterPopover.vue'
669
- import type { TabularDataResponse, TabularRow, ColumnType, SortConfig, ColumnFilters, BadgeStyle } from './types'
670
- import noColumnsSrc from '../../../assets/illustrations/_table.svg?url'
28
+ import { hasFilterForColumn as _hasFilterForColumn, buildGlobalSearchConditions } from '../../functions/tabular'
29
+ import PreviewUnavailable from '../ResourceAccordion/PreviewUnavailable.vue'
30
+ import TabularSkeleton from './TabularSkeleton.vue'
31
+ import type { TabularDataResponse, TabularRow, SortConfig, ColumnFilters } from './types'
32
+ import { provideTabularContext, type ActiveFilter } from './useTabularContext'
33
+ import { useColumnMetadata } from './useColumnMetadata'
671
34
 
672
35
  const props = defineProps<{
673
36
  resourceId: string
674
- // When true, the table breaks out to the full viewport width instead of just
675
- // the host's padding. Used on the standalone explore page where the table
676
- // should span the whole screen while the toolbar stays inside the container.
677
- fullBleed?: boolean
678
37
  // When set, searches across multiple columns using the Tabular API's or(...)
679
38
  // parameter. Text and categorical columns get a __contains filter; number
680
39
  // columns get a __exact filter (since __contains is not supported for numbers
@@ -690,47 +49,11 @@ const props = defineProps<{
690
49
  // Same ownership rule as `initialFilters`: the explorer owns it afterwards,
691
50
  // and the user can drop it from the active-sort chip.
692
51
  initialSort?: SortConfig
693
- // When set, renders <a> tags inside the specified column cells for native
694
- // browser UX (hover URL, ctrl+click, middle-click).
695
- rowHref?: { columns: string[], href: (row: TabularRow) => string }
696
- // Columns listed here render their values raw (no number formatting).
697
- // Useful for identifier columns.
698
- noFormatColumns?: string[]
699
52
  }>()
700
53
 
701
- function getRowHref(row: TabularRow): string | undefined {
702
- return props.rowHref?.href(row)
703
- }
704
-
705
- function isLinkColumn(col: string): boolean {
706
- return props.rowHref?.columns.includes(col) ?? false
707
- }
708
-
709
- function cellProps(col: string, row: TabularRow) {
710
- const columnType = getColumnType(col)
711
- return {
712
- value: row[col],
713
- columnType,
714
- categoryBadgeStyle: columnType === 'categorical' ? getCategoryBadgeStyle(col, String(row[col])) : undefined,
715
- noNumberFormat: props.noFormatColumns?.includes(col),
716
- }
717
- }
718
-
719
54
  const { t } = useTranslation()
720
55
  const config = useComponentsConfig()
721
56
 
722
- // Column selector popover positioning
723
- const columnAnchorComponent = useTemplateRef<InstanceType<typeof Popover>>('columnAnchor')
724
- const columnPanelComponent = useTemplateRef<InstanceType<typeof PopoverPanel>>('columnPanel')
725
- const columnAnchorEl = computed(() => columnAnchorComponent.value?.$el as HTMLElement | undefined)
726
- const columnPanelEl = computed(() => columnPanelComponent.value?.$el as HTMLElement | undefined)
727
-
728
- const { floatingStyles: columnFloatingStyles } = useFloating(columnAnchorEl, columnPanelEl, {
729
- placement: 'bottom-start',
730
- middleware: [flip(), shift()],
731
- whileElementsMounted: autoUpdate,
732
- })
733
-
734
57
  const dataUrl = computed(() =>
735
58
  `${config.tabularApiUrl}/api/resources/${props.resourceId}/data/`,
736
59
  )
@@ -744,26 +67,17 @@ const { data: profileData, error: profileError, status: profileStatus } = await
744
67
 
745
68
  const allColumns = computed(() => profileData.value?.profile?.header ?? [])
746
69
 
747
- // Column type helpers
748
- function getColumnTypeFromName(col: string): ColumnType {
749
- const profile = profileData.value?.profile
750
- if (!profile) return 'text'
751
- const colInfo = profile.columns[col]
752
- if (!colInfo) return 'text'
753
- return resolveColumnType(colInfo, profile.categorical.includes(col))
754
- }
755
-
756
- const columnTypesMap = computed(() => {
757
- const map: Record<string, ColumnType> = {}
758
- for (const col of allColumns.value) {
759
- map[col] = getColumnTypeFromName(col)
760
- }
761
- return map
762
- })
763
-
764
- function getColumnType(col: string): ColumnType {
765
- return columnTypesMap.value[col] ?? 'text'
766
- }
70
+ // Column metadata (display type, label/icon, null ratio, boolean counts) — pure
71
+ // derivations of the profile, extracted to keep this component focused on data
72
+ // fetching, pagination and filter/column state.
73
+ const {
74
+ columnTypesMap,
75
+ getColumnType,
76
+ getColumnProfile,
77
+ getColumnDisplay,
78
+ getNullPercent,
79
+ getBooleanCounts,
80
+ } = useColumnMetadata(profileData, allColumns, t)
767
81
 
768
82
  // Sort & filter state
769
83
  const sort = ref<SortConfig | null>(props.initialSort ? { ...props.initialSort } : null)
@@ -824,7 +138,6 @@ const currentPage = ref(1)
824
138
  const hasMore = ref(false)
825
139
  const loadingMore = ref(false)
826
140
  const generation = ref(0)
827
- const scrollContainerRef = useTemplateRef<HTMLElement>('scrollContainer')
828
141
 
829
142
  watch(() => tableData.value, (data) => {
830
143
  generation.value++
@@ -895,178 +208,7 @@ function selectOnlyColumn(col: string) {
895
208
  visibleColumns.value = new Set([col])
896
209
  }
897
210
 
898
- // Column widths
899
- //
900
- // Strategy:
901
- // - `naturalWidths` holds each column's content-driven width, measured ONCE
902
- // from the DOM while the <th> are still auto-sized. It's the stable base and
903
- // never re-measured (re-measuring would require unlocking the widths first).
904
- // - `columnWidths` is the applied result: `naturalWidths` distributed to fill
905
- // the container. It's recomputed from the base whenever the set of displayed
906
- // columns changes (toggling, isolating or hiding columns via the menu), so
907
- // reducing to a few columns re-stretches them instead of leaving blank space.
908
- // Pagination / filtering / sorting don't change the column set, so they keep
909
- // the locked widths and never trigger a layout shift.
910
- // - Manual resize writes directly to `columnWidths` during the drag, then stores
911
- // the final width back into `naturalWidths` so it survives later redistribution.
912
- const columnWidths = ref<Record<string, number>>({})
913
- const naturalWidths = ref<Record<string, number>>({})
914
- const resizing = ref<{ column: string, startX: number, startWidth: number } | null>(null)
915
-
916
- // Measure content-driven widths once, while the <th> are still auto-sized.
917
- function measureNaturalWidths() {
918
- const container = scrollContainerRef.value
919
- if (!container) return
920
- const ths = container.querySelectorAll('th')
921
- if (!ths || ths.length === 0) return
922
-
923
- const widths: Record<string, number> = {}
924
- ths.forEach((th, i) => {
925
- const col = displayedColumns.value[i]
926
- if (col) widths[col] = th.offsetWidth
927
- })
928
- naturalWidths.value = widths
929
- }
930
-
931
- // Distribute the natural widths of the currently displayed columns to fill the
932
- // container (inflating proportionally when they don't naturally cover it).
933
- function redistributeColumnWidths() {
934
- const container = scrollContainerRef.value
935
- if (!container) return
936
- const cols = displayedColumns.value
937
- let naturalSum = 0
938
- for (const col of cols) naturalSum += naturalWidths.value[col] ?? 0
939
- if (naturalSum === 0) return
940
-
941
- const ratio = naturalSum < container.clientWidth ? container.clientWidth / naturalSum : 1
942
- const widths: Record<string, number> = {}
943
- for (const col of cols) widths[col] = Math.floor((naturalWidths.value[col] ?? 0) * ratio)
944
- columnWidths.value = widths
945
- }
946
-
947
- // Measure the natural widths once (the <th> must still be auto-sized) and
948
- // distribute them. No-op once measured or while no column is displayed.
949
- function ensureMeasured() {
950
- if (Object.keys(naturalWidths.value).length > 0) return
951
- if (displayedColumns.value.length === 0) return
952
- measureNaturalWidths()
953
- redistributeColumnWidths()
954
- }
955
-
956
- // Drive measurement and re-stretch off the container's reactive width
957
- // (`useElementSize` wraps a ResizeObserver and disconnects it on unmount). The
958
- // width goes 0 -> N once the table is laid out in the DOM, which is also when
959
- // the <thead> carries its content-driven natural widths: the first non-zero
960
- // width measures the stable base, later changes (window resize) only
961
- // redistribute it.
962
- const { width: containerWidth } = useElementSize(scrollContainerRef)
963
-
964
- watch(containerWidth, (width) => {
965
- if (width === 0) return
966
- if (Object.keys(naturalWidths.value).length === 0) {
967
- ensureMeasured()
968
- }
969
- else {
970
- redistributeColumnWidths()
971
- }
972
- })
973
-
974
- // Fallback: re-run once columns appear if they weren't available when the
975
- // container was first sized (standalone usage where the profile resolves late).
976
- watch(
977
- () => [tableData.value !== null, displayedColumns.value.length] as const,
978
- async ([dataReady, colCount]) => {
979
- if (!dataReady || colCount === 0) return
980
- if (Object.keys(naturalWidths.value).length > 0) return
981
- await nextTick()
982
- ensureMeasured()
983
- },
984
- )
985
-
986
- // Re-stretch the remaining columns whenever the displayed set changes (columns
987
- // toggled / hidden / isolated from the menu). No DOM measurement needed — we
988
- // redistribute the already-measured natural widths over the new container space.
989
- watch(displayedColumns, async () => {
990
- if (Object.keys(naturalWidths.value).length === 0) return
991
- // Wait for the table to (re)mount before reading the container: the desktop
992
- // table is `v-if`-ed out when no column is displayed, so going from 0 → N
993
- // columns means `scrollContainer` only exists after the next render.
994
- await nextTick()
995
- redistributeColumnWidths()
996
- })
997
-
998
- function startResize(col: string, e: MouseEvent) {
999
- // Fallback in case the user grabs the handle before the initial measure ran.
1000
- if (!Object.keys(naturalWidths.value).length) {
1001
- measureNaturalWidths()
1002
- redistributeColumnWidths()
1003
- }
1004
- resizing.value = { column: col, startX: e.clientX, startWidth: columnWidths.value[col] ?? 100 }
1005
- // Disable smooth scroll during resize
1006
- if (scrollContainerRef.value) scrollContainerRef.value.style.scrollBehavior = 'auto'
1007
- document.addEventListener('mousemove', onResize)
1008
- document.addEventListener('mouseup', stopResize)
1009
- }
1010
-
1011
- function onResize(e: MouseEvent) {
1012
- if (!resizing.value) return
1013
- const container = scrollContainerRef.value
1014
- // Auto-scroll when mouse approaches the right edge, and adjust startX to compensate
1015
- if (container) {
1016
- const rect = container.getBoundingClientRect()
1017
- const distFromRight = rect.right - e.clientX
1018
- if (distFromRight < 50) {
1019
- const oldScroll = container.scrollLeft
1020
- container.scrollLeft += Math.max(1, (50 - distFromRight) * 0.5)
1021
- resizing.value.startX -= container.scrollLeft - oldScroll
1022
- }
1023
- }
1024
- const delta = e.clientX - resizing.value.startX
1025
- const newWidth = Math.max(60, resizing.value.startWidth + delta)
1026
- columnWidths.value = { ...columnWidths.value, [resizing.value.column]: newWidth }
1027
- }
1028
-
1029
- function stopResize() {
1030
- if (scrollContainerRef.value) scrollContainerRef.value.style.scrollBehavior = ''
1031
- // Persist the manual width as the column's new base so it survives later
1032
- // redistribution when other columns are toggled.
1033
- if (resizing.value) {
1034
- const col = resizing.value.column
1035
- const width = columnWidths.value[col]
1036
- if (width != null) naturalWidths.value = { ...naturalWidths.value, [col]: width }
1037
- }
1038
- resizing.value = null
1039
- document.removeEventListener('mousemove', onResize)
1040
- document.removeEventListener('mouseup', stopResize)
1041
- }
1042
-
1043
- onUnmounted(() => {
1044
- document.removeEventListener('mousemove', onResize)
1045
- document.removeEventListener('mouseup', stopResize)
1046
- })
1047
-
1048
- // Cell popover
1049
- const activeCell = ref<CellInfo | null>(null)
1050
-
1051
- function onCellClick(col: string, value: unknown, event: MouseEvent) {
1052
- // A link inside a cell (see `rowHref`) owns its clicks: navigate, don't open
1053
- // the popover on top of the page we're leaving.
1054
- if ((event.target as HTMLElement).closest('a')) return
1055
- const el = (event.target as HTMLElement).closest('[data-cell]') as HTMLElement | null
1056
- if (!el) return
1057
- if (activeCell.value && activeCell.value.element === el) {
1058
- activeCell.value = null
1059
- return
1060
- }
1061
- activeCell.value = { column: col, columnType: columnTypesMap.value[col] ?? 'text', value, element: el }
1062
- }
1063
-
1064
211
  // Active filters
1065
- interface ActiveFilter {
1066
- column: string
1067
- label: string
1068
- }
1069
-
1070
212
  const activeFilters = computed<ActiveFilter[]>(() => {
1071
213
  const result: ActiveFilter[] = []
1072
214
  for (const [col, filter] of Object.entries(filters.value)) {
@@ -1120,111 +262,38 @@ function hasFilterForColumn(col: string): boolean {
1120
262
  return _hasFilterForColumn(filters.value, col)
1121
263
  }
1122
264
 
1123
- // Mobile state
265
+ // Whether the mobile filter sheet is open (button lives in the toolbar).
1124
266
  const mobileFilterOpen = ref(false)
1125
- const mobileExpandedRows = ref(new Set<number>())
1126
- const mobileFilterExpandedCol = ref<string | null>(null)
1127
267
 
1128
- function mobileVisibleFields(index: number): string[] {
1129
- if (displayedColumns.value.length <= 4 || mobileExpandedRows.value.has(index)) {
1130
- return displayedColumns.value
1131
- }
1132
- return displayedColumns.value.slice(0, 4)
1133
- }
1134
-
1135
- function toggleMobileExpand(index: number) {
1136
- const next = new Set(mobileExpandedRows.value)
1137
- if (next.has(index)) next.delete(index)
1138
- else next.add(index)
1139
- mobileExpandedRows.value = next
1140
- }
1141
-
1142
- function toggleMobileFilterColumn(col: string) {
1143
- mobileFilterExpandedCol.value = mobileFilterExpandedCol.value === col ? null : col
1144
- }
1145
-
1146
- function getColumnProfile(col: string) {
1147
- return profileData.value?.profile?.profile?.[col] ?? null
1148
- }
1149
-
1150
- function getTopsEntries(col: string) {
1151
- return getColumnProfile(col)?.tops ?? []
1152
- }
1153
-
1154
- function getNullPercent(col: string) {
1155
- const colProfile = getColumnProfile(col)
1156
- const total = profileData.value?.profile?.total_lines
1157
- if (!colProfile || !total) return '0%'
1158
- return `${((colProfile.nb_missing_values / total) * 100).toFixed(1)}%`
1159
- }
1160
-
1161
- const typeConfig = buildTypeConfig(t)
1162
- const formatConfig = buildFormatConfig(t)
1163
-
1164
- function getTypeConfig(col: string) {
1165
- return typeConfig[getColumnType(col)]
1166
- }
1167
-
1168
- // Header display: prefer the rich semantic format detected by csv-detective
1169
- // (code INSEE, UAI, département, SIREN, email…) over the generic display type.
1170
- // Tolerant: generic formats fall back to the type config, and unknown semantic
1171
- // formats are humanized rather than dropped.
1172
- function getColumnDisplay(col: string) {
1173
- const format = profileData.value?.profile?.columns?.[col]?.format
1174
- const fallback = getTypeConfig(col)
1175
- if (!format || GENERIC_FORMATS.has(format)) return fallback
1176
- return formatConfig[format] ?? { icon: fallback.icon, label: humanizeFormat(format) }
1177
- }
1178
-
1179
- const BADGE_PALETTE = [
1180
- { bg: '#E6EEFE', text: '#3558A2' }, // blue-cumulus
1181
- { bg: '#E8E3DB', text: '#6A6156' }, // beige-gris-galet
1182
- { bg: '#FEECC2', text: '#695240' }, // yellow-tournesol
1183
- { bg: '#C7F6FC', text: '#006A6F' }, // green-archipel
1184
- { bg: '#E9EDFE', text: '#2323FF' }, // blue-ecume
1185
- { bg: '#FFE0C7', text: '#885B40' }, // orange-terre-battue
1186
- { bg: '#F2E9DB', text: '#6B4C35' }, // brown-cafe-creme
1187
- { bg: '#BAFAEE', text: '#297254' }, // green-menthe
1188
- { bg: '#FEE0EB', text: '#8D5368' }, // pink-macaron
1189
- { bg: '#FCE164', text: '#695240' }, // yellow-moutarde
1190
- ] as const
1191
-
1192
- const BADGE_FALLBACK = { bg: '#F0E0CF', text: '#745B47' } // brown-opera
1193
-
1194
- const badgeColorMap = computed(() => {
1195
- const map = new Map<string, { bg: string, text: string }>()
1196
- const profile = profileData.value?.profile
1197
- if (!profile) return map
1198
- for (const col of profile.categorical) {
1199
- getTopsEntries(col).forEach((top, i) => {
1200
- map.set(`${col}::${top.value}`, BADGE_PALETTE[i % BADGE_PALETTE.length]!)
1201
- })
1202
- }
1203
- return map
268
+ // Provide the shared state so child components (active filters, columns menu, rows
269
+ // info, table…) can inject it instead of receiving a wall of props.
270
+ provideTabularContext({
271
+ tableData,
272
+ totalLines,
273
+ allRows,
274
+ hasMore,
275
+ loadNextPage,
276
+ isRefreshing,
277
+ sort,
278
+ filters,
279
+ activeFilters,
280
+ removeFilter,
281
+ clearAllFilters,
282
+ hasFilterForColumn,
283
+ allColumns,
284
+ visibleColumns,
285
+ displayedColumns,
286
+ hiddenCount,
287
+ toggleColumn,
288
+ showAllColumns,
289
+ hideAllColumns,
290
+ selectOnlyColumn,
291
+ mobileFilterOpen,
292
+ columnTypesMap,
293
+ getColumnType,
294
+ getColumnProfile,
295
+ getColumnDisplay,
296
+ getNullPercent,
297
+ getBooleanCounts,
1204
298
  })
1205
-
1206
- function getCategoryBadgeStyle(col: string, value: string): BadgeStyle {
1207
- const colors = badgeColorMap.value.get(`${col}::${value}`) ?? BADGE_FALLBACK
1208
- return { backgroundColor: colors.bg, color: colors.text }
1209
- }
1210
-
1211
- function getCategoryBadgeStylesForColumn(col: string): Record<string, BadgeStyle> {
1212
- const styles: Record<string, BadgeStyle> = {}
1213
- for (const top of getTopsEntries(col)) {
1214
- styles[top.value] = getCategoryBadgeStyle(col, top.value)
1215
- }
1216
- return styles
1217
- }
1218
-
1219
- function getBooleanCounts(col: string): { trueCount: number, falseCount: number } {
1220
- const profile = getColumnProfile(col)
1221
- if (!profile?.tops) return { trueCount: 0, falseCount: 0 }
1222
- let trueCount = 0
1223
- let falseCount = 0
1224
- for (const top of profile.tops) {
1225
- if (isTruthy(top.value ?? '')) trueCount += top.count
1226
- else if (isFalsy(top.value ?? '')) falseCount += top.count
1227
- }
1228
- return { trueCount, falseCount }
1229
- }
1230
299
  </script>