@datagouv/components-next 1.0.2-dev.172 → 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-CES67S3v.js → Datafair.client-BU2gspr8.js} +9 -9
  2. package/dist/ImagePreview.client-BU5QNqG_.js +36 -0
  3. package/dist/{JsonPreview.client-DtCw5aCA.js → JsonPreview.client-CvOpMCxW.js} +2 -2
  4. package/dist/{MapContainer.client-Q3TmXpPR.js → MapContainer.client-DNOQ5XTT.js} +9 -9
  5. package/dist/{PdfPreview.client-BXJzS-Hm.js → PdfPreview.client-DwAvLLq_.js} +438 -427
  6. package/dist/{Pmtiles.client-DNiYcHH3.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-CPfIZl9q.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-CXeG6J6C.js → index-Dw1lR0oe.js} +1 -1
  13. package/dist/{leaflet-src-BwEce6uO.js → leaflet-src-BoMqG6Yx.js} +1 -1
  14. package/dist/{main-D7EaQcIR.js → main-I9G-L-lg.js} +16280 -15511
  15. package/dist/{vue3-xml-viewer.common-DznVepCg.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 +68 -995
  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-c_SJXLpr.js +0 -36
  57. package/dist/PreviewWrapper.vue_vue_type_script_setup_true_lang-B3ByRwHK.js +0 -58
@@ -3,111 +3,49 @@
3
3
  v-slot="{ open, close }"
4
4
  class="relative inline-block"
5
5
  >
6
- <slot
7
- name="trigger"
8
- :open="open"
6
+ <PopoverButton
7
+ class="inline-flex items-center justify-center size-6 rounded text-gray-plain hover:bg-gray-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-new-primary"
8
+ :aria-label="t('Choisir une autre ressource')"
9
9
  >
10
- <PopoverButton
11
- class="inline-flex items-center justify-center size-6 rounded text-gray-plain hover:bg-gray-100 focus:outline-none focus-visible:ring-2 focus-visible:ring-new-primary"
12
- :aria-label="t('Choisir une autre ressource')"
13
- >
14
- <RiArrowDownSLine
15
- class="size-4"
16
- :class="{ 'rotate-180': open }"
17
- aria-hidden="true"
18
- />
19
- </PopoverButton>
20
- </slot>
21
- <PopoverPanel
22
- :class="searchable
23
- ? 'absolute left-0 top-full z-50 mt-2 w-96 max-w-[calc(100vw-2rem)] bg-white border border-gray-default rounded shadow-lg p-3 space-y-2'
24
- : 'absolute left-0 top-full z-50 mt-1 w-80 max-h-96 overflow-auto bg-white border border-gray-default rounded shadow-lg p-1'"
25
- >
26
- <input
27
- v-if="searchable"
28
- v-model="searchQuery"
29
- type="search"
30
- class="w-full border border-gray-default rounded px-2.5 py-1.5 text-sm"
31
- :placeholder="t('Rechercher dans les ressources…')"
32
- >
33
- <ul
34
- v-if="filteredResources.length > 0"
35
- class="list-none p-0 m-0 space-y-0.5 max-h-80 overflow-y-auto"
36
- >
10
+ <RiArrowDownSLine
11
+ class="size-4"
12
+ :class="{ 'rotate-180': open }"
13
+ aria-hidden="true"
14
+ />
15
+ </PopoverButton>
16
+ <PopoverPanel class="absolute left-0 top-full z-50 mt-1 w-80 max-h-96 overflow-auto bg-white border border-gray-default rounded shadow-lg p-1">
17
+ <ul class="list-none p-0 m-0 space-y-0.5 max-h-80 overflow-y-auto">
37
18
  <li
38
- v-for="r in filteredResources"
19
+ v-for="r in resources"
39
20
  :key="r.id"
40
21
  >
41
- <button
42
- v-if="!isDisabled?.(r)"
43
- type="button"
44
- class="flex items-center gap-1.5 w-full text-left px-2 py-1.5 rounded text-sm hover:bg-gray-100 focus:outline-none focus-visible:bg-gray-100"
45
- :class="{ 'font-bold bg-blue-50 text-new-primary': r.id === selectedId }"
46
- @click="emit('select', r); close()"
47
- >
48
- <ResourceIcon
49
- :resource="r"
50
- class="size-3.5 shrink-0"
51
- />
52
- <span class="truncate">{{ r.title || t('Fichier sans nom') }}</span>
53
- <span
54
- v-if="r.format"
55
- class="ml-auto text-xs text-gray-medium uppercase shrink-0"
56
- >
57
- {{ r.format }}
58
- </span>
59
- </button>
60
- <div
61
- v-else
62
- class="flex items-center gap-1.5 px-2 py-1.5 rounded text-sm text-gray-medium cursor-not-allowed"
63
- :title="disabledTitle"
64
- >
65
- <ResourceIcon
66
- :resource="r"
67
- class="size-3.5 shrink-0 opacity-50"
68
- />
69
- <span class="truncate opacity-70">{{ r.title || t('Fichier sans nom') }}</span>
70
- </div>
22
+ <ResourceListItem
23
+ :resource="r"
24
+ :to="resourceTo(r)"
25
+ :replace
26
+ :selected="r.id === selectedId"
27
+ @click="close()"
28
+ />
71
29
  </li>
72
30
  </ul>
73
- <p
74
- v-else
75
- class="text-sm text-gray-medium italic mb-0 px-2 py-2"
76
- >
77
- {{ t('Aucune ressource correspondante') }}
78
- </p>
79
31
  </PopoverPanel>
80
32
  </Popover>
81
33
  </template>
82
34
 
83
35
  <script setup lang="ts">
84
- import { computed, ref } from 'vue'
36
+ import type { RouteLocationRaw } from 'vue-router'
85
37
  import { Popover, PopoverButton, PopoverPanel } from '@headlessui/vue'
86
38
  import { RiArrowDownSLine } from '@remixicon/vue'
87
39
  import { useTranslation } from '../../composables/useTranslation'
88
- import ResourceIcon from '../ResourceAccordion/ResourceIcon.vue'
40
+ import ResourceListItem from '../ResourceListItem.vue'
89
41
  import type { Resource } from '../../types/resources'
90
42
 
91
- const props = defineProps<{
43
+ defineProps<{
92
44
  resources: Resource[]
93
45
  selectedId: string
94
- searchable?: boolean
95
- isDisabled?: (resource: Resource) => boolean
96
- disabledTitle?: string
97
- }>()
98
-
99
- const emit = defineEmits<{
100
- select: [resource: Resource]
46
+ resourceTo: (resource: Resource) => RouteLocationRaw
47
+ replace?: boolean
101
48
  }>()
102
49
 
103
50
  const { t } = useTranslation()
104
-
105
- const searchQuery = ref('')
106
-
107
- const filteredResources = computed(() => {
108
- if (!props.searchable) return props.resources
109
- const q = searchQuery.value.trim().toLowerCase()
110
- if (!q) return props.resources
111
- return props.resources.filter(r => (r.title ?? '').toLowerCase().includes(q))
112
- })
113
51
  </script>
@@ -0,0 +1,115 @@
1
+ <template>
2
+ <header class="flex h-14 shrink-0 items-center justify-between gap-2 border-b border-gray-default bg-gray-some px-3">
3
+ <div class="flex min-w-0 items-center gap-1.5 overflow-hidden text-[13px] text-gray-medium">
4
+ <ResourceIcon
5
+ :resource
6
+ class="size-4 shrink-0"
7
+ />
8
+ <span
9
+ class="min-w-0 truncate font-medium text-gray-title"
10
+ :title="resource.title || t('Fichier sans nom')"
11
+ >{{ resource.title || t('Fichier sans nom') }}</span>
12
+ <ResourceSelector
13
+ v-if="resources && resources.length > 1 && resourceTo"
14
+ :resources
15
+ :selected-id="resource.id"
16
+ :resource-to
17
+ :replace
18
+ class="shrink-0 md:hidden"
19
+ />
20
+ <!-- Metadata gives way long before the title does (hence the shrink factor), so
21
+ the resource name stays readable — and the title truncates rather than being
22
+ clipped by the row, which would push the copy button out of view.
23
+ Inline flow (not flex) so text-overflow renders the ellipsis; spacing is
24
+ carried by the separators' margins. -->
25
+ <div class="min-w-0 truncate [flex-shrink:9999]">
26
+ <span class="mr-1.5">·</span>
27
+ <span :title="formatDate(resource.last_modified)">{{ t('mis à jour {date}', { date: formatRelativeIfRecentDate(resource.last_modified) }) }}</span>
28
+ <template v-if="resourceFilesize">
29
+ <span class="mx-1.5">·</span>
30
+ <span>{{ filesize(resourceFilesize) }}</span>
31
+ </template>
32
+ <template v-if="resource.format">
33
+ <span class="mx-1.5">·</span>
34
+ <span class="rounded bg-gray-lower px-1.5 py-0.5 text-[12px] uppercase leading-4 text-gray-medium">{{ resource.format }}</span>
35
+ </template>
36
+ <template v-if="resource.schema?.name || resource.schema?.url">
37
+ <span class="mx-1.5">·</span>
38
+ <SchemaBadge :resource />
39
+ </template>
40
+ <span class="mx-1.5">·</span>
41
+ <span class="inline-flex items-center gap-0.5 align-middle">
42
+ <RiDownloadLine class="size-3" />
43
+ {{ summarize(resource.metrics.views) }}
44
+ </span>
45
+ </div>
46
+ <CopyButton
47
+ :label="t('Copier le lien')"
48
+ :copied-label="t('Lien copié !')"
49
+ :text="resourceExternalUrl"
50
+ icon-only
51
+ class="hidden shrink-0 md:inline-flex"
52
+ />
53
+ </div>
54
+ <div
55
+ v-if="!fullscreen"
56
+ class="flex shrink-0 items-center gap-2"
57
+ >
58
+ <ResourceMainAction
59
+ :resource="resource"
60
+ :dataset="dataset"
61
+ />
62
+ <BrandedButton
63
+ v-if="exploreTo"
64
+ :href="exploreTo(resource)"
65
+ :icon="RiFullscreenLine"
66
+ icon-only
67
+ color="secondary"
68
+ size="xs"
69
+ :title="t('Explorer les données')"
70
+ @click="trackEvent('Jeux de données', 'Explorer les données', 'Bouton : explorer les données')"
71
+ >
72
+ {{ t('Explorer les données') }}
73
+ </BrandedButton>
74
+ </div>
75
+ </header>
76
+ </template>
77
+
78
+ <script setup lang="ts">
79
+ import { computed } from 'vue'
80
+ import { RiDownloadLine, RiFullscreenLine } from '@remixicon/vue'
81
+ import BrandedButton from '../BrandedButton.vue'
82
+ import CopyButton from '../CopyButton.vue'
83
+ import ResourceIcon from '../ResourceAccordion/ResourceIcon.vue'
84
+ import SchemaBadge from '../ResourceAccordion/SchemaBadge.vue'
85
+ import ResourceSelector from './ResourceSelector.vue'
86
+ import ResourceMainAction from './ResourceMainAction.vue'
87
+ import { filesize, summarize } from '../../functions/helpers'
88
+ import { getResourceExternalUrl, getResourceFilesize } from '../../functions/resources'
89
+ import { trackEvent } from '../../functions/matomo'
90
+ import { useFormatDate } from '../../functions/dates'
91
+ import { useTranslation } from '../../composables/useTranslation'
92
+ import type { RouteLocationRaw } from 'vue-router'
93
+ import type { Resource } from '../../types/resources'
94
+ import type { Dataset, DatasetV2 } from '../../types/datasets'
95
+
96
+ // Shared by the viewer and its loading skeleton: everything here comes from the
97
+ // resource itself, so the skeleton renders the real header instead of pulsing
98
+ // placeholders over data it already holds.
99
+ const props = defineProps<{
100
+ dataset: Dataset | DatasetV2
101
+ resource: Resource
102
+ resources?: Resource[]
103
+ resourceTo?: (resource: Resource) => RouteLocationRaw
104
+ exploreTo?: (resource: Resource) => string
105
+ replace?: boolean
106
+ // Fullscreen mode hides the inline actions — they live in the dataset context bar above.
107
+ fullscreen?: boolean
108
+ }>()
109
+
110
+ const { t } = useTranslation()
111
+ const { formatRelativeIfRecentDate, formatDate } = useFormatDate()
112
+
113
+ const resourceFilesize = computed(() => getResourceFilesize(props.resource))
114
+ const resourceExternalUrl = computed(() => getResourceExternalUrl(props.dataset, props.resource))
115
+ </script>
@@ -0,0 +1,94 @@
1
+ <template>
2
+ <div :class="fullscreen ? 'flex min-h-0 flex-1 flex-col' : ''">
3
+ <!-- Header and tabs are the real ones: everything they show comes from the
4
+ resource we already hold, so there is nothing to wait for. Only the preview
5
+ body below is a placeholder. -->
6
+ <ResourceViewerHeader
7
+ :dataset
8
+ :resource
9
+ :resources
10
+ :resource-to
11
+ :explore-to="exploreTo"
12
+ :replace
13
+ :fullscreen
14
+ />
15
+
16
+ <!-- Inert copy of the viewer's tab row: same components, so the pills keep their
17
+ exact size and labels, but nothing to select until the viewer resolves. -->
18
+ <TabGroup
19
+ size="sm"
20
+ aria-hidden="true"
21
+ class="pointer-events-none"
22
+ >
23
+ <div class="flex shrink-0 items-center border-b border-gray-default p-2">
24
+ <TabList class="max-w-full overflow-x-auto">
25
+ <Tab
26
+ v-for="tab in tabsOptions"
27
+ :key="tab.key"
28
+ >
29
+ {{ tab.label }}
30
+ </Tab>
31
+ </TabList>
32
+ </div>
33
+ </TabGroup>
34
+
35
+ <!-- Tabular preview: the same toolbar + table skeleton the data tab shows while
36
+ TabularExplorer loads. Other previews fall back below. -->
37
+ <TabularSkeleton
38
+ v-if="previewKind === 'tabular'"
39
+ :fill="fullscreen"
40
+ />
41
+
42
+ <!-- PDF preview: the same A4 skeleton the PdfPreview shows while pdfjs loads. -->
43
+ <PdfSkeleton
44
+ v-else-if="previewKind === 'pdf'"
45
+ :fill="fullscreen"
46
+ />
47
+
48
+ <!-- Other non-tabular previews (JSON, map…) — a simple placeholder for now. -->
49
+ <div
50
+ v-else
51
+ class="animate-pulse-placeholder p-4"
52
+ :class="fullscreen ? 'min-h-0 flex-1' : ''"
53
+ role="status"
54
+ :aria-label="t('Chargement de l\'aperçu…')"
55
+ >
56
+ <div
57
+ class="w-full rounded bg-gray-200"
58
+ :class="fullscreen ? 'h-full' : 'h-96'"
59
+ />
60
+ </div>
61
+ </div>
62
+ </template>
63
+
64
+ <script setup lang="ts">
65
+ import PdfSkeleton from '../ResourceAccordion/PdfSkeleton.vue'
66
+ import TabularSkeleton from '../TabularExplorer/TabularSkeleton.vue'
67
+ import TabGroup from '../Tabs/TabGroup.vue'
68
+ import TabList from '../Tabs/TabList.vue'
69
+ import Tab from '../Tabs/Tab.vue'
70
+ import ResourceViewerHeader from './ResourceViewerHeader.vue'
71
+ import { useTranslation } from '../../composables/useTranslation'
72
+ import { useResourceCapabilities } from '../../composables/useResourceCapabilities'
73
+ import type { RouteLocationRaw } from 'vue-router'
74
+ import type { Resource } from '../../types/resources'
75
+ import type { Dataset, DatasetV2 } from '../../types/datasets'
76
+
77
+ const props = defineProps<{
78
+ resource: Resource
79
+ dataset: Dataset | DatasetV2
80
+ resources?: Resource[]
81
+ resourceTo?: (resource: Resource) => RouteLocationRaw
82
+ exploreTo?: (resource: Resource) => string
83
+ replace?: boolean
84
+ fullscreen?: boolean
85
+ }>()
86
+
87
+ const { t } = useTranslation()
88
+ // `previewKind` is the viewer's own decision, so the skeleton always picks the
89
+ // shape the resolved viewer will show.
90
+ const { previewKind, tabsOptions } = useResourceCapabilities(
91
+ () => props.resource,
92
+ () => props.dataset,
93
+ )
94
+ </script>
@@ -0,0 +1,154 @@
1
+ <template>
2
+ <AppLink
3
+ ref="row"
4
+ v-bind="$attrs"
5
+ :to
6
+ :replace
7
+ :class="selected ? '[&&]:!bg-gray-200' : '[&&]:hover:!bg-gray-100'"
8
+ class="grid h-7 w-full grid-cols-[auto_minmax(0,1fr)_auto] items-center gap-1 rounded px-1 py-1 text-left !bg-none !no-underline"
9
+ @pointerenter="openOnHover"
10
+ @pointerleave="closeTooltip"
11
+ @focus="show = true"
12
+ @blur="closeTooltip"
13
+ >
14
+ <span
15
+ :class="[iconColor, '[&_svg]:fill-current']"
16
+ class="flex size-5 shrink-0 items-center justify-center rounded-[1px]"
17
+ >
18
+ <component
19
+ :is="iconComponent"
20
+ class="size-4"
21
+ aria-hidden="true"
22
+ />
23
+ </span>
24
+ <div class="flex min-w-0 items-baseline gap-0.5 whitespace-nowrap leading-4">
25
+ <span
26
+ class="truncate text-[13px]"
27
+ :class="selected ? 'font-extrabold text-gray-title' : 'font-medium text-gray-medium'"
28
+ >{{ resource.title || t('Fichier sans nom') }}</span>
29
+ <template v-if="humanFilesize">
30
+ <span class="shrink-0 text-[13px] text-gray-medium">·</span>
31
+ <span class="shrink-0 text-[12px] text-gray-medium">{{ humanFilesize }}</span>
32
+ </template>
33
+ </div>
34
+ <!-- Capped and truncated: an `auto` grid track floors at its content width, so an
35
+ unusually long format (`www:link-1.0-http--samples`) would otherwise squeeze
36
+ the title track to nothing and overflow the fixed-height row. -->
37
+ <span
38
+ v-if="resource.format"
39
+ class="max-w-24 truncate rounded bg-gray-lower px-1.5 py-0.5 text-[12px] uppercase leading-4 text-gray-medium"
40
+ :title="resource.format"
41
+ >{{ resource.format }}</span>
42
+ </AppLink>
43
+
44
+ <!-- Hover card: the row truncates the title, so surface the full name plus the
45
+ same metadata line as the viewer header. Placed beside the row (not below) so
46
+ it doesn't hide the sibling rows we're scanning. -->
47
+ <Teleport to="body">
48
+ <div
49
+ v-if="show"
50
+ ref="card"
51
+ role="tooltip"
52
+ class="pointer-events-none z-[80] w-max rounded border border-gray-default bg-white p-2 text-left shadow-[0_2px_4px_rgba(0,0,0,0.04),2px_4px_16px_rgba(0,0,0,0.12)]"
53
+ :style="floatingStyles"
54
+ >
55
+ <span class="block whitespace-nowrap text-[13px] font-medium leading-5 text-gray-title">{{ resource.title || t('Fichier sans nom') }}</span>
56
+ <div class="mt-1 flex items-center gap-1 text-[12px] leading-4 text-gray-medium">
57
+ <span>{{ t('mis à jour {date}', { date: formatRelativeIfRecentDate(resource.last_modified) }) }}</span>
58
+ <template v-if="humanFilesize">
59
+ <span>·</span>
60
+ <span>{{ humanFilesize }}</span>
61
+ </template>
62
+ <template v-if="resource.format">
63
+ <span>·</span>
64
+ <span class="rounded bg-gray-lower px-1.5 py-0.5 uppercase leading-4">{{ resource.format }}</span>
65
+ </template>
66
+ <span>·</span>
67
+ <span class="inline-flex items-center gap-0.5">
68
+ <RiDownloadLine
69
+ class="size-3"
70
+ aria-hidden="true"
71
+ />
72
+ {{ summarize(resource.metrics.views) }}
73
+ </span>
74
+ </div>
75
+ </div>
76
+ </Teleport>
77
+ </template>
78
+
79
+ <script setup lang="ts">
80
+ import { computed, ref, useTemplateRef } from 'vue'
81
+ import { autoUpdate, flip, offset, shift, useFloating } from '@floating-ui/vue'
82
+ import { useEventListener } from '@vueuse/core'
83
+ import type { RouteLocationRaw } from 'vue-router'
84
+ import { RiDownloadLine } from '@remixicon/vue'
85
+ import AppLink from './AppLink.vue'
86
+ import File from './Icons/File.vue'
87
+ import { getResourceFormatIcon, getResourceIconColor, getResourceFilesize } from '../functions/resources'
88
+ import { filesize, summarize } from '../functions/helpers'
89
+ import { useFormatDate } from '../functions/dates'
90
+ import { useTranslation } from '../composables/useTranslation'
91
+ import type { Resource } from '../types/resources'
92
+
93
+ // The hover card below is a second root node, so Vue drops fallthrough attributes
94
+ // unless we place them ourselves: without this, a listener bound by the parent
95
+ // (the selector's `@click="close()"`) would silently never fire.
96
+ defineOptions({ inheritAttrs: false })
97
+
98
+ // Shared row for a single resource (sidebar + resource selector). Renders as a
99
+ // navigation link so switching resource is a real link — the URL is the source of
100
+ // truth for the selection.
101
+ const props = withDefaults(defineProps<{
102
+ resource: Resource
103
+ to: RouteLocationRaw
104
+ selected?: boolean
105
+ replace?: boolean
106
+ }>(), {
107
+ selected: false,
108
+ replace: false,
109
+ })
110
+
111
+ const { t } = useTranslation()
112
+ const { formatRelativeIfRecentDate } = useFormatDate()
113
+
114
+ // Render the icon directly (not via ResourceIcon which forces a gray color) so the
115
+ // colored badge can tint it through currentColor + [&_svg]:fill-current.
116
+ const iconComponent = computed(() => (props.resource.format ? getResourceFormatIcon(props.resource.format) : null) ?? File)
117
+ const iconColor = computed(() => getResourceIconColor(props.resource.format))
118
+
119
+ const humanFilesize = computed(() => {
120
+ const size = getResourceFilesize(props.resource)
121
+ return size ? filesize(size) : null
122
+ })
123
+
124
+ // Hover card teleported to <body> so the sidebar's `overflow` doesn't clip it, hence
125
+ // the fixed strategy. `shift` keeps it inside the viewport for a row near an edge, and
126
+ // `autoUpdate` follows the row when its scrollable container moves under the pointer.
127
+ const show = ref(false)
128
+ const row = useTemplateRef<InstanceType<typeof AppLink>>('row')
129
+ const card = useTemplateRef<HTMLElement>('card')
130
+ const rowEl = computed(() => row.value?.$el as HTMLElement | undefined)
131
+ const { floatingStyles } = useFloating(rowEl, card, {
132
+ placement: 'right-start',
133
+ strategy: 'fixed',
134
+ middleware: [offset(16), flip(), shift({ padding: 8 })],
135
+ whileElementsMounted: autoUpdate,
136
+ })
137
+
138
+ // A tap fires a pointer enter too, so the card would flash on every touch selection
139
+ // in the mobile resource picker. Only a real pointer opens it — keyboard focus still
140
+ // does, through @focus.
141
+ function openOnHover(event: PointerEvent) {
142
+ if (event.pointerType === 'mouse') show.value = true
143
+ }
144
+
145
+ function closeTooltip() {
146
+ show.value = false
147
+ }
148
+
149
+ // A hover-shown card gets no `mouseleave` when the window loses focus (alt-tab) or
150
+ // the pointer leaves the document, so it would linger on return — close it in those
151
+ // cases too.
152
+ useEventListener(window, 'blur', closeTooltip)
153
+ useEventListener(document, 'mouseleave', closeTooltip)
154
+ </script>
@@ -0,0 +1,79 @@
1
+ <template>
2
+ <div
3
+ v-if="activeFilters.length > 0 || sort"
4
+ class="flex flex-wrap items-center gap-1.5"
5
+ >
6
+ <!-- Sort chip -->
7
+ <span
8
+ v-if="sort"
9
+ class="inline-flex h-6 items-center gap-1 rounded border border-new-primary/20 bg-new-primary/10 pl-1.5 pr-0.5 text-[12px] leading-4 text-new-primary"
10
+ >
11
+ <component
12
+ :is="sort.direction === 'asc' ? RiArrowUpLine : RiArrowDownLine"
13
+ class="size-3.5"
14
+ aria-hidden="true"
15
+ />
16
+ <span class="font-medium">{{ sort.column }}</span>
17
+ <span>{{ sort.direction === 'asc' ? t('croissant') : t('décroissant') }}</span>
18
+ <button
19
+ :aria-label="t('Supprimer le tri')"
20
+ class="flex size-5 items-center justify-center rounded hover:bg-new-primary/15"
21
+ @click="sort = null"
22
+ >
23
+ <RiCloseLine
24
+ class="size-3.5"
25
+ aria-hidden="true"
26
+ />
27
+ </button>
28
+ </span>
29
+
30
+ <!-- Filter chips -->
31
+ <span
32
+ v-for="af in activeFilters"
33
+ :key="af.column"
34
+ :data-testid="`active-filter-${af.column}`"
35
+ class="inline-flex h-6 items-center gap-1 rounded border border-new-primary/20 bg-new-primary/10 pl-1.5 pr-0.5 text-[12px] leading-4 text-new-primary"
36
+ >
37
+ <component
38
+ :is="getColumnDisplay(af.column).icon"
39
+ class="size-3.5"
40
+ aria-hidden="true"
41
+ />
42
+ <span class="font-medium">{{ af.column }}</span>
43
+ <span>{{ af.label }}</span>
44
+ <button
45
+ :aria-label="t('Supprimer ce filtre')"
46
+ class="flex size-5 items-center justify-center rounded hover:bg-new-primary/15"
47
+ @click="removeFilter(af.column)"
48
+ >
49
+ <RiCloseLine
50
+ class="size-3.5"
51
+ aria-hidden="true"
52
+ />
53
+ </button>
54
+ </span>
55
+
56
+ <!-- Clear all -->
57
+ <BrandedButton
58
+ v-if="withClear"
59
+ color="tertiary"
60
+ size="2xs"
61
+ :icon="RiCloseLine"
62
+ @click="clearAllFilters(); sort = null"
63
+ >
64
+ {{ t('Tout effacer') }}
65
+ </BrandedButton>
66
+ </div>
67
+ </template>
68
+
69
+ <script setup lang="ts">
70
+ import { RiArrowDownLine, RiArrowUpLine, RiCloseLine } from '@remixicon/vue'
71
+ import BrandedButton from '../BrandedButton.vue'
72
+ import { useTranslation } from '../../composables/useTranslation'
73
+ import { useTabularContext } from './useTabularContext'
74
+
75
+ defineProps<{ withClear?: boolean }>()
76
+
77
+ const { t } = useTranslation()
78
+ const { activeFilters, sort, removeFilter, clearAllFilters, getColumnDisplay } = useTabularContext()
79
+ </script>
@@ -17,8 +17,7 @@
17
17
  </span>
18
18
  <span
19
19
  v-else-if="columnType === 'categorical'"
20
- class="inline-block rounded font-medium px-2 py-0.5 text-xs max-w-full truncate"
21
- :style="categoryBadgeStyle ? { backgroundColor: categoryBadgeStyle.backgroundColor, color: categoryBadgeStyle.color } : undefined"
20
+ class="inline-block max-w-full truncate rounded bg-gray-lower px-2 py-0.5 text-xs text-gray-plain"
22
21
  >{{ value }}</span>
23
22
  <span
24
23
  v-else-if="columnType === 'number' || columnType === 'year'"
@@ -37,12 +36,11 @@
37
36
  <script setup lang="ts">
38
37
  import { useTranslation } from '../../composables/useTranslation'
39
38
  import { useFormatTabular, isTruthy } from '../../functions/tabular'
40
- import type { ColumnType, BadgeStyle } from './types'
39
+ import type { ColumnType } from './types'
41
40
 
42
41
  defineProps<{
43
42
  value: unknown
44
43
  columnType: ColumnType
45
- categoryBadgeStyle?: BadgeStyle
46
44
  compact?: boolean
47
45
  noNumberFormat?: boolean
48
46
  }>()