@datagouv/components-next 1.0.2-dev.7 → 1.0.2-dev.71

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 (83) hide show
  1. package/assets/main.css +4 -0
  2. package/dist/Datafair.client-BzW-ctDf.js +30 -0
  3. package/dist/JsonPreview.client-BfMSzR07.js +40 -0
  4. package/dist/{MapContainer.client-DRkAmdOc.js → MapContainer.client-CLs-im9i.js} +35 -38
  5. package/dist/{PdfPreview.client-C-w6-w44.js → PdfPreview.client-C13PQCU_.js} +822 -865
  6. package/dist/{Pmtiles.client-BR7_ldHY.js → Pmtiles.client-CL7PXXDl.js} +574 -579
  7. package/dist/PreviewWrapper.vue_vue_type_script_setup_true_lang-C6XnsZ-7.js +61 -0
  8. package/dist/XmlPreview.client-KaENrbbG.js +34 -0
  9. package/dist/components-next.css +3 -3
  10. package/dist/components-next.js +166 -148
  11. package/dist/components.css +1 -1
  12. package/dist/{index-SrYZwgCT.js → index-C7WVVGgD.js} +1 -1
  13. package/dist/{main-B2kXxWRG.js → main-K-42Oe8-.js} +91315 -75834
  14. package/dist/{vue3-xml-viewer.common-BRxsqI9j.js → vue3-xml-viewer.common-sHPSE-jD.js} +1 -1
  15. package/package.json +16 -10
  16. package/src/components/ActivityList/ActivityList.vue +0 -2
  17. package/src/components/Chart/ChartViewer.vue +226 -0
  18. package/src/components/Chart/ChartViewerWrapper.vue +170 -0
  19. package/src/components/Form/Listbox.vue +101 -0
  20. package/src/components/Form/SearchableSelect.vue +2 -1
  21. package/src/components/InfiniteLoader.vue +53 -0
  22. package/src/components/OpenApiViewer/ContentTypeSelect.vue +48 -0
  23. package/src/components/OpenApiViewer/EndpointRequest.vue +164 -0
  24. package/src/components/OpenApiViewer/EndpointResponses.vue +149 -0
  25. package/src/components/OpenApiViewer/OpenApiViewer.vue +308 -0
  26. package/src/components/OpenApiViewer/SchemaPanel.vue +53 -0
  27. package/src/components/OpenApiViewer/SchemaTree.vue +77 -0
  28. package/src/components/OpenApiViewer/openapi.ts +150 -0
  29. package/src/components/OrganizationNameWithCertificate.vue +3 -2
  30. package/src/components/Pagination.vue +8 -5
  31. package/src/components/ReadMore.vue +1 -1
  32. package/src/components/ResourceAccordion/Datafair.client.vue +4 -10
  33. package/src/components/ResourceAccordion/JsonPreview.client.vue +23 -121
  34. package/src/components/ResourceAccordion/MapContainer.client.vue +7 -11
  35. package/src/components/ResourceAccordion/Metadata.vue +1 -2
  36. package/src/components/ResourceAccordion/PdfPreview.client.vue +24 -103
  37. package/src/components/ResourceAccordion/Pmtiles.client.vue +5 -10
  38. package/src/components/ResourceAccordion/Preview.vue +16 -21
  39. package/src/components/ResourceAccordion/PreviewLoader.vue +1 -2
  40. package/src/components/ResourceAccordion/PreviewUnavailable.vue +22 -0
  41. package/src/components/ResourceAccordion/PreviewWrapper.vue +82 -0
  42. package/src/components/ResourceAccordion/ResourceAccordion.vue +5 -7
  43. package/src/components/ResourceAccordion/XmlPreview.client.vue +16 -115
  44. package/src/components/ResourceExplorer/ResourceExplorer.vue +81 -13
  45. package/src/components/ResourceExplorer/ResourceExplorerSidebar.vue +2 -2
  46. package/src/components/ResourceExplorer/ResourceExplorerViewer.vue +30 -11
  47. package/src/components/Search/GlobalSearch.vue +173 -108
  48. package/src/components/Search/SearchInput.vue +3 -3
  49. package/src/components/TabularExplorer/TabularCell.vue +51 -0
  50. package/src/components/TabularExplorer/TabularCellPopover.vue +170 -0
  51. package/src/components/TabularExplorer/TabularExplorer.vue +870 -0
  52. package/src/components/TabularExplorer/TabularFilterContent.vue +351 -0
  53. package/src/components/TabularExplorer/TabularFilterPopover.vue +111 -0
  54. package/src/components/TabularExplorer/types.ts +83 -0
  55. package/src/composables/useHasTabularData.ts +6 -0
  56. package/src/composables/useResourceCapabilities.ts +1 -1
  57. package/src/composables/useSearchFilter.ts +118 -0
  58. package/src/composables/useStableQueryParams.ts +31 -3
  59. package/src/config.ts +3 -0
  60. package/src/functions/api.ts +34 -33
  61. package/src/functions/api.types.ts +1 -0
  62. package/src/functions/charts.ts +68 -0
  63. package/src/functions/datasets.ts +0 -17
  64. package/src/functions/resources.ts +56 -1
  65. package/src/functions/tabular.ts +60 -0
  66. package/src/functions/tabularApi.ts +138 -11
  67. package/src/main.ts +55 -7
  68. package/src/types/dataservices.ts +2 -0
  69. package/src/types/pages.ts +0 -5
  70. package/src/types/posts.ts +2 -2
  71. package/src/types/reports.ts +3 -0
  72. package/src/types/search.ts +52 -1
  73. package/src/types/site.ts +5 -3
  74. package/src/types/users.ts +0 -1
  75. package/src/types/visualizations.ts +89 -0
  76. package/assets/swagger-themes/newspaper.css +0 -1670
  77. package/dist/Datafair.client-E5D6ePRC.js +0 -35
  78. package/dist/JsonPreview.client-C-6eBbPw.js +0 -87
  79. package/dist/Swagger.client-D4-F6yEf.js +0 -4
  80. package/dist/XmlPreview.client-Dl2VCgXF.js +0 -79
  81. package/src/components/ResourceAccordion/Swagger.client.vue +0 -48
  82. package/src/functions/pagination.ts +0 -9
  83. /package/assets/illustrations/{_microscope.svg → microscope.svg} +0 -0
@@ -1,4 +1,4 @@
1
- import { b as Ke } from "./main-B2kXxWRG.js";
1
+ import { c as Ke } from "./main-K-42Oe8-.js";
2
2
  import We from "vue";
3
3
  function Fe(I, K) {
4
4
  for (var V = 0; V < K.length; V++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datagouv/components-next",
3
- "version": "1.0.2-dev.7",
3
+ "version": "1.0.2-dev.71",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {
@@ -16,15 +16,16 @@
16
16
  "src"
17
17
  ],
18
18
  "dependencies": {
19
- "@floating-ui/vue": "^1.1.8",
20
- "@types/leaflet": "^1.9.17",
19
+ "@floating-ui/vue": "^1.1.11",
21
20
  "@headlessui/vue": "^1.7.23",
22
21
  "@remixicon/vue": "^4.5.0",
23
22
  "@types/hast": "^3.0.4",
24
- "@vueuse/core": "^13.1.0",
25
- "@vueuse/router": "^13.1.0",
23
+ "@types/leaflet": "^1.9.17",
24
+ "@vueuse/core": "^14.2.1",
25
+ "@vueuse/router": "^14.2.1",
26
26
  "chart.js": "^4.4.8",
27
27
  "dompurify": "^3.2.5",
28
+ "echarts": "^6.0.0",
28
29
  "geopf-extensions-openlayers": "^1.0.0-beta.5",
29
30
  "leaflet": "^1.9.4",
30
31
  "maplibre-gl": "^5.6.2",
@@ -45,16 +46,14 @@
45
46
  "remark-rehype": "^11.1.2",
46
47
  "strip-markdown": "^6.0.0",
47
48
  "stylefire": "^7.0.3",
48
- "swagger-ui-dist": "^5.27.1",
49
49
  "unified": "^11.0.5",
50
50
  "unist-util-visit": "^5.0.0",
51
- "vue": "^3.5.13",
52
51
  "vue-content-loader": "^2.0.1",
53
- "vue-router": "^4.5.0",
54
52
  "vue-sonner": "^2.0.9",
55
53
  "vue3-json-viewer": "^2.4.1",
56
54
  "vue3-text-clamp": "^0.1.2",
57
- "vue3-xml-viewer": "^0.0.14"
55
+ "vue3-xml-viewer": "^0.0.14",
56
+ "yaml": "^2.8.2"
58
57
  },
59
58
  "devDependencies": {
60
59
  "@intlify/cli": "^0.13.1",
@@ -71,13 +70,20 @@
71
70
  "eslint-plugin-vue": "^10.0",
72
71
  "jiti": "^2.4.2",
73
72
  "npm-run-all2": "^8.0",
73
+ "openapi-types": "^12.1.3",
74
74
  "prettier": "^3.0.0",
75
75
  "tailwindcss": "^4.0.8",
76
- "typescript": "^5.7.3",
76
+ "typescript": "^5.9.3",
77
77
  "vite": "^7.0",
78
78
  "vite-plugin-vue-devtools": "^8.0",
79
+ "vue": "^3.5.33",
80
+ "vue-router": "^5.0.4",
79
81
  "vue-tsc": "^3.0"
80
82
  },
83
+ "peerDependencies": {
84
+ "vue": "^3.5.13",
85
+ "vue-router": "^4.5.0 || ^5.0.0"
86
+ },
81
87
  "scarfSettings": {
82
88
  "enabled": false
83
89
  },
@@ -90,7 +90,6 @@
90
90
  :total-results="activities.total"
91
91
  :page-size="activities.page_size"
92
92
  :page="activities.page"
93
- :link="getLink"
94
93
  @change="(newPage: number) => page = newPage"
95
94
  />
96
95
  </template>
@@ -117,7 +116,6 @@ import { useTranslation } from '../../composables/useTranslation'
117
116
  import { getActivityTranslation } from '../../functions/activities'
118
117
  import { useFetch } from '../../functions/api'
119
118
  import { useFormatDate } from '../../functions/dates'
120
- import { getLink } from '../../functions/pagination'
121
119
  import type { PaginatedArray } from '../../types/api'
122
120
  import type { Activity } from '../../types/activity'
123
121
  import Avatar from '../Avatar.vue'
@@ -0,0 +1,226 @@
1
+ <template>
2
+ <div
3
+ ref="chartContainer"
4
+ class="w-full min-h-96"
5
+ />
6
+ </template>
7
+
8
+ <script setup lang="ts">
9
+ import { format, use, type ComposeOption } from 'echarts/core'
10
+ import { CanvasRenderer } from 'echarts/renderers'
11
+ import { LineChart, BarChart, type BarSeriesOption, type LineSeriesOption } from 'echarts/charts'
12
+ import { TitleComponent, TooltipComponent, LegendComponent, GridComponent, DatasetComponent } from 'echarts/components'
13
+ import { init, type ECharts as EChartsType } from 'echarts'
14
+ import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
15
+ import { summarize } from '../../functions/helpers'
16
+ import type { Chart, XAxis, YAxis, XAxisForm, ChartForApi } from '../../types/visualizations'
17
+ import { useTranslation } from '../../composables/useTranslation'
18
+
19
+ use([CanvasRenderer, LineChart, BarChart, TitleComponent, TooltipComponent, LegendComponent, GridComponent, DatasetComponent])
20
+
21
+ const props = defineProps<{
22
+ chart: Chart | ChartForApi
23
+ series: {
24
+ data: Record<string, Array<Record<string, unknown>>>
25
+ columns: Record<string, Array<string>>
26
+ }
27
+ }>()
28
+
29
+ const { locale } = useTranslation()
30
+ const chartContainer = ref<HTMLElement | null>(null)
31
+ let echartsInstance: EChartsType | null = null
32
+
33
+ function mapXAxisType(xAxis: XAxis | XAxisForm): 'category' | 'value' {
34
+ if (!xAxis) return 'category'
35
+ return (xAxis.type ?? 'discrete') === 'continuous' ? 'value' : 'category'
36
+ }
37
+
38
+ function buildYAxisFormatter(yAxis: YAxis): ((value: number) => string) | undefined {
39
+ return (value: number) => {
40
+ const v = summarize(value)
41
+ if (!yAxis.unit) return v
42
+ if (yAxis.unit_position === 'prefix') return `${yAxis.unit} ${v}`
43
+ return `${v} ${yAxis.unit}`
44
+ }
45
+ }
46
+
47
+ const echartsOption = computed(() => {
48
+ const seriesCount = props.chart.series.length
49
+ if (!props.chart.series || seriesCount === 0) return
50
+
51
+ const seriesArray = props.chart.series.map((s) => {
52
+ const xColumn = s.column_x_name_override ?? props.chart.x_axis.column_x
53
+ const yColumn = s.aggregate_y ? `${s.column_y}__${s.aggregate_y}` : s.column_y
54
+ const resourceId = s.resource_id
55
+
56
+ if (!xColumn || !yColumn || !resourceId || !s.type || !props.series.data[resourceId] || !props.series.columns[resourceId]) {
57
+ return null
58
+ }
59
+
60
+ const sortedData = [...props.series.data[resourceId]]
61
+ const sortBy = props.chart.x_axis.sort_x_by
62
+ const sortDirection = props.chart.x_axis.sort_x_direction ?? 'asc'
63
+
64
+ if (sortBy && sortDirection && props.chart.x_axis.column_x) {
65
+ const sortKey = sortBy === 'axis_x' ? xColumn : yColumn
66
+ sortedData.sort((a, b) => {
67
+ const valA = a[sortKey]
68
+ const valB = b[sortKey]
69
+
70
+ const aNullish = valA === null || valA === undefined
71
+ const bNullish = valB === null || valB === undefined
72
+ if (aNullish && bNullish) return 0
73
+ if (aNullish) return sortDirection === 'asc' ? -1 : 1
74
+ if (bNullish) return sortDirection === 'asc' ? 1 : -1
75
+
76
+ if (valA instanceof Date && valB instanceof Date) {
77
+ const timeA = valA.getTime()
78
+ const timeB = valB.getTime()
79
+ if (timeA < timeB) return sortDirection === 'asc' ? -1 : 1
80
+ if (timeA > timeB) return sortDirection === 'asc' ? 1 : -1
81
+ return 0
82
+ }
83
+
84
+ if (typeof valA === 'boolean' && typeof valB === 'boolean') {
85
+ if (valA === valB) return 0
86
+ // false comes before true in ascending order
87
+ if (valB) return sortDirection === 'asc' ? -1 : 1
88
+ return sortDirection === 'asc' ? 1 : -1
89
+ }
90
+
91
+ const numA = Number(valA)
92
+ const numB = Number(valB)
93
+ const bothNumeric = !isNaN(numA) && !isNaN(numB)
94
+
95
+ if (bothNumeric) {
96
+ if (numA < numB) return sortDirection === 'asc' ? -1 : 1
97
+ if (numA > numB) return sortDirection === 'asc' ? 1 : -1
98
+ return 0
99
+ }
100
+
101
+ const strA = String(valA)
102
+ const strB = String(valB)
103
+ return strA.localeCompare(strB, locale, {
104
+ sensitivity: 'base',
105
+ numeric: true,
106
+ }) * (sortDirection === 'asc' ? 1 : -1)
107
+ })
108
+ }
109
+
110
+ return {
111
+ series: {
112
+ type: s.type === 'histogram' ? 'bar' : 'line',
113
+ dimensions: s.aggregate_y ? [xColumn, yColumn] : props.series.columns[resourceId],
114
+ name: yColumn,
115
+ encode: {
116
+ x: xColumn,
117
+ y: yColumn,
118
+ },
119
+ } as LineSeriesOption | BarSeriesOption,
120
+ data: {
121
+ source: sortedData,
122
+ dimensions: s.aggregate_y ? [xColumn, yColumn] : props.series.columns[resourceId],
123
+ },
124
+ }
125
+ })
126
+
127
+ const seriesData = {
128
+ series: [] as Array<LineSeriesOption | BarSeriesOption>,
129
+ data: [] as Array<Record<string, unknown>>,
130
+ }
131
+
132
+ for (const curr of seriesArray) {
133
+ if (!curr) continue
134
+ seriesData.series.push(curr.series)
135
+ seriesData.data.push(curr.data)
136
+ }
137
+
138
+ return {
139
+ dataset: [...seriesData.data],
140
+ title: {
141
+ text: props.chart.title,
142
+ left: 'center',
143
+ },
144
+ tooltip: {
145
+ trigger: 'axis' as const,
146
+ formatter: (params: Array<{ value: Record<string, unknown>, axisValueLabel: string, seriesName: string }>) => {
147
+ let tooltip = ''
148
+ const formatter = new Intl.NumberFormat('fr-FR')
149
+ for (const param of params) {
150
+ const seriesName = param.seriesName
151
+ tooltip += `${format.encodeHTML(param.axisValueLabel)}: <strong>${formatter.format(Number(param.value[seriesName]))}</strong><br>`
152
+ }
153
+ return tooltip
154
+ },
155
+ },
156
+ legend: {
157
+ show: seriesData.series.length > 1,
158
+ bottom: 0,
159
+ },
160
+ grid: {
161
+ top: 60,
162
+ bottom: 40,
163
+ left: 20,
164
+ right: 20,
165
+ containLabel: true,
166
+ },
167
+ xAxis: {
168
+ type: mapXAxisType(props.chart.x_axis),
169
+ name: (props.chart.x_axis as XAxis).column_x,
170
+ },
171
+ yAxis: {
172
+ type: 'value' as const,
173
+ name: props.chart.y_axis.label ?? undefined,
174
+ min: props.chart.y_axis.min ?? undefined,
175
+ max: props.chart.y_axis.max ?? undefined,
176
+ axisLabel: {
177
+ formatter: buildYAxisFormatter(props.chart.y_axis),
178
+ },
179
+ },
180
+ series: seriesData.series,
181
+ } satisfies ComposeOption<
182
+ | BarSeriesOption
183
+ | LineSeriesOption
184
+ >
185
+ })
186
+
187
+ onMounted(() => {
188
+ if (chartContainer.value) {
189
+ echartsInstance = init(chartContainer.value)
190
+ updateChart()
191
+ }
192
+ })
193
+
194
+ onUnmounted(() => {
195
+ if (echartsInstance) {
196
+ echartsInstance.dispose()
197
+ echartsInstance = null
198
+ }
199
+ })
200
+
201
+ watch(() => props.chart, updateChart, { deep: true })
202
+
203
+ watch(() => props.series, updateChart, { deep: true })
204
+
205
+ function updateChart() {
206
+ if (!echartsInstance) return
207
+ const option = echartsOption.value
208
+ if (option) {
209
+ echartsInstance.setOption(option, { notMerge: true })
210
+ }
211
+ }
212
+
213
+ const handleResize = () => {
214
+ if (echartsInstance) {
215
+ echartsInstance.resize()
216
+ }
217
+ }
218
+
219
+ onMounted(() => {
220
+ window.addEventListener('resize', handleResize)
221
+ })
222
+
223
+ onUnmounted(() => {
224
+ window.removeEventListener('resize', handleResize)
225
+ })
226
+ </script>
@@ -0,0 +1,170 @@
1
+ <template>
2
+ <LoadingBlock
3
+ :status="status"
4
+ :data="series"
5
+ >
6
+ <template #default="{ data }">
7
+ <ChartViewer
8
+ :chart="chart"
9
+ :series="data"
10
+ />
11
+ </template>
12
+ <template #error>
13
+ <div class="text-center py-8 text-gray-500">
14
+ {{ t('Une erreur est survenue lors du chargement des données du graphique.') }}
15
+ </div>
16
+ </template>
17
+ </LoadingBlock>
18
+ </template>
19
+
20
+ <script setup lang="ts">
21
+ import { reactive, ref, watch } from 'vue'
22
+ import ChartViewer from './ChartViewer.vue'
23
+ import LoadingBlock from '../../components/LoadingBlock.vue'
24
+ import { useComponentsConfig } from '../../config'
25
+ import { fetchTabularData, useGetProfile } from '../../functions/tabularApi'
26
+ import type { Chart, ChartForApi } from '../../types/visualizations'
27
+ import { useTranslation } from '../../composables/useTranslation'
28
+
29
+ const props = defineProps<{
30
+ chart: Chart | ChartForApi
31
+ }>()
32
+
33
+ const emit = defineEmits<{
34
+ columns: [columns: Record<string, Array<string>>]
35
+ }>()
36
+
37
+ const { t } = useTranslation()
38
+ const config = useComponentsConfig()
39
+ const getProfile = useGetProfile()
40
+
41
+ const status = ref<'idle' | 'pending' | 'success' | 'error'>('idle')
42
+ const error = ref<Error | null>(null)
43
+
44
+ const pendingOperations = ref(0)
45
+
46
+ const series = reactive<{
47
+ data: Record<string, Array<Record<string, unknown>>>
48
+ columns: Record<string, Array<string>>
49
+ }>({
50
+ data: {},
51
+ columns: {},
52
+ })
53
+
54
+ async function fetchSeriesProfile() {
55
+ pendingOperations.value++
56
+ status.value = 'pending'
57
+ error.value = null
58
+
59
+ try {
60
+ if (props.chart.series.length === 0) {
61
+ status.value = 'success'
62
+ series.data = {}
63
+ series.columns = {}
64
+ return
65
+ }
66
+
67
+ const fetchPromises = props.chart.series
68
+ .filter(serie => serie.resource_id)
69
+ .map(async (serie) => {
70
+ return {
71
+ id: serie.resource_id,
72
+ profile: await getProfile(serie.resource_id),
73
+ }
74
+ })
75
+
76
+ const results = (await Promise.allSettled(fetchPromises))
77
+ .filter(r => r.status === 'fulfilled')
78
+ .map(r => r.value)
79
+ series.columns = Object.fromEntries(results.map(result => [
80
+ result.id,
81
+ result.profile.profile.header,
82
+ ]))
83
+ }
84
+ catch (err) {
85
+ error.value = err instanceof Error ? err : new Error('Failed to fetch series profile')
86
+ status.value = 'error'
87
+ console.error(err)
88
+ series.columns = {}
89
+ }
90
+ finally {
91
+ pendingOperations.value--
92
+ }
93
+ }
94
+
95
+ async function fetchSeriesData() {
96
+ pendingOperations.value++
97
+ status.value = 'pending'
98
+ error.value = null
99
+
100
+ try {
101
+ if (props.chart.series.length === 0 || !props.chart.x_axis.column_x) {
102
+ status.value = 'success'
103
+ series.data = {}
104
+ return
105
+ }
106
+
107
+ const fetchPromises = props.chart.series
108
+ .filter((serie) => {
109
+ const xColumn = serie.column_x_name_override ?? props.chart.x_axis.column_x
110
+ return xColumn && serie.resource_id && serie.column_y
111
+ })
112
+ .map(async (serie) => {
113
+ const xColumn = serie.column_x_name_override ?? props.chart.x_axis.column_x
114
+ return {
115
+ id: serie.resource_id,
116
+ data: await fetchTabularData(config, {
117
+ columns: serie.aggregate_y ? undefined : [xColumn, serie.column_y],
118
+ resourceId: serie.resource_id,
119
+ page: 1,
120
+ pageSize: 100,
121
+ groupBy: xColumn,
122
+ aggregation: serie.column_y && serie.aggregate_y
123
+ ? {
124
+ column: serie.column_y,
125
+ type: serie.aggregate_y,
126
+ }
127
+ : undefined,
128
+ filters: serie.filters ?? undefined,
129
+ }),
130
+ }
131
+ })
132
+
133
+ const results = (await Promise.allSettled(fetchPromises))
134
+ .filter(r => r.status === 'fulfilled')
135
+ .map(r => r.value)
136
+ series.data = Object.fromEntries(results.map(result => [
137
+ result.id,
138
+ result.data.data,
139
+ ]))
140
+ }
141
+ catch (err) {
142
+ error.value = err instanceof Error ? err : new Error('Failed to fetch series data')
143
+ status.value = 'error'
144
+ series.data = {}
145
+ }
146
+ finally {
147
+ pendingOperations.value--
148
+ }
149
+ }
150
+
151
+ watch(() => props.chart.series, async () => {
152
+ await fetchSeriesProfile()
153
+ }, { immediate: true, deep: true })
154
+
155
+ watch([() => props.chart.series, () => props.chart.x_axis.column_x], async () => {
156
+ await fetchSeriesData()
157
+ }, { immediate: true, deep: true })
158
+
159
+ watch(() => series.columns, () => {
160
+ emit('columns', series.columns)
161
+ })
162
+
163
+ watch(pendingOperations, (count) => {
164
+ if (count === 0) {
165
+ if (error.value === null && status.value === 'pending') {
166
+ status.value = 'success'
167
+ }
168
+ }
169
+ })
170
+ </script>
@@ -0,0 +1,101 @@
1
+ <template>
2
+ <Listbox v-model="model">
3
+ <div class="relative min-w-0">
4
+ <div
5
+ ref="floatingReference"
6
+ class="relative w-full cursor-default overflow-hidden bg-white text-left shadow-md focus:outline-none focus-visible:ring-2 focus-visible:ring-white/75 focus-visible:ring-offset-2 focus-visible:ring-offset-teal-300 sm:text-sm"
7
+ >
8
+ <ListboxButton class="input shadow-input text-sm flex items-center gap-2">
9
+ <slot name="button">
10
+ <div class="w-full flex items-center justify-between gap-2">
11
+ <div
12
+ class="truncate"
13
+ :class="{ 'text-new-disabled-text': isDisabled(model) }"
14
+ >
15
+ {{ displayValue(model) }}
16
+ </div>
17
+ <RiArrowDownSLine class="flex-none size-4 justify-self-end" />
18
+ </div>
19
+ </slot>
20
+ </ListboxButton>
21
+ </div>
22
+
23
+ <ListboxOptions
24
+ ref="popover"
25
+ :style="floatingStyles"
26
+ class="z-10 mt-1 absolute max-h-60 min-w-80 w-full overflow-auto rounded-md bg-white text-base shadow-lg ring-1 ring-black/5 focus:outline-none sm:text-sm pl-0"
27
+ >
28
+ <ListboxOption
29
+ v-for="option in options"
30
+ :key="getOptionId(toValue(option))"
31
+ v-slot="{ active, selected }"
32
+ as="template"
33
+ :value="option"
34
+ >
35
+ <li
36
+ class="relative cursor-default select-none py-2 pr-4 list-none flex items-center gap-2 text-gray-900"
37
+ :class="{
38
+ 'bg-gray-lower': active && !isDisabled(toValue(option)),
39
+ 'text-new-disabled-text': isDisabled(toValue(option)),
40
+ 'pl-2': selected,
41
+ 'pl-6': !selected,
42
+ }"
43
+ >
44
+ <div class="flex items-center justify-center aspect-square">
45
+ <RiCheckLine
46
+ v-if="selected"
47
+ class="size-4"
48
+ :class="isDisabled(toValue(option)) ?' text-new-disabled-text' : 'text-new-primary'"
49
+ />
50
+ </div>
51
+ <slot
52
+ name="option"
53
+ v-bind="{ option, active }"
54
+ >
55
+ {{ displayValue(option) }}
56
+ </slot>
57
+ </li>
58
+ </ListboxOption>
59
+ </ListboxOptions>
60
+ </div>
61
+ </Listbox>
62
+ </template>
63
+
64
+ <script setup lang="ts" generic="T extends string | number | object">
65
+ import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from '@headlessui/vue'
66
+ import { useFloating, autoUpdate, autoPlacement } from '@floating-ui/vue'
67
+ import { toValue, useTemplateRef } from 'vue'
68
+ import { RiArrowDownSLine, RiCheckLine } from '@remixicon/vue'
69
+
70
+ withDefaults(defineProps<{
71
+ options?: Array<T>
72
+ getOptionId?: (option: T) => string | number
73
+ displayValue: (option: T | null) => string
74
+ isDisabled?: (option: T | null) => boolean
75
+ }>(), {
76
+ getOptionId: (option: T): string | number => {
77
+ if (typeof option === 'string') return option
78
+ if (typeof option === 'number') return option
79
+ if (typeof option === 'object' && 'id' in option) return option.id as string
80
+
81
+ throw new Error('Please set getOptionId()')
82
+ },
83
+ isDisabled: (option: T | null): boolean => {
84
+ if (option && typeof option === 'object' && 'disabled' in option) return option.disabled as boolean
85
+
86
+ return false
87
+ },
88
+ })
89
+
90
+ const model = defineModel<T | null>({ required: true })
91
+
92
+ const referenceRef = useTemplateRef('floatingReference')
93
+ const floatingRef = useTemplateRef<InstanceType<typeof ListboxOptions>>('popover')
94
+ const { floatingStyles } = useFloating(referenceRef, floatingRef, {
95
+ middleware: [autoPlacement({
96
+ allowedPlacements: ['bottom-start', 'bottom', 'bottom-end'],
97
+ crossAxis: true,
98
+ })],
99
+ whileElementsMounted: autoUpdate,
100
+ })
101
+ </script>
@@ -10,8 +10,9 @@
10
10
  :class="{ 'sr-only': hideLabel }"
11
11
  >
12
12
  {{ label }}
13
+ <!-- $props needed: in generic components, vue-tsc resolves `required` to the Nuxt auto-imported function instead of the prop -->
13
14
  <span
14
- v-if="required"
15
+ v-if="$props.required"
15
16
  class="text-new-primary"
16
17
  >*</span>
17
18
  <span
@@ -0,0 +1,53 @@
1
+ <template>
2
+ <div ref="sentinel">
3
+ <slot>
4
+ <div class="flex items-center justify-center p-4">
5
+ <span class="inline-flex items-center gap-2 text-xs text-gray-medium">
6
+ <RiLoader4Line
7
+ class="size-4 animate-spin"
8
+ aria-hidden="true"
9
+ />
10
+ {{ t('Chargement…') }}
11
+ </span>
12
+ </div>
13
+ </slot>
14
+ </div>
15
+ </template>
16
+
17
+ <script setup lang="ts">
18
+ import { onMounted, onUnmounted, useTemplateRef, watch } from 'vue'
19
+ import { RiLoader4Line } from '@remixicon/vue'
20
+ import { useTranslation } from '../composables/useTranslation'
21
+
22
+ const props = defineProps<{
23
+ root?: HTMLElement | null
24
+ }>()
25
+
26
+ const emit = defineEmits<{
27
+ intersect: []
28
+ }>()
29
+
30
+ const { t } = useTranslation()
31
+
32
+ const sentinelRef = useTemplateRef<HTMLElement>('sentinel')
33
+ let observer: IntersectionObserver | null = null
34
+
35
+ function setupObserver() {
36
+ observer?.disconnect()
37
+ const el = sentinelRef.value
38
+ if (!el) return
39
+ observer = new IntersectionObserver(
40
+ (entries) => {
41
+ if (entries[0]?.isIntersecting) {
42
+ emit('intersect')
43
+ }
44
+ },
45
+ { root: props.root ?? null, rootMargin: '200px' },
46
+ )
47
+ observer.observe(el)
48
+ }
49
+
50
+ onMounted(setupObserver)
51
+ watch([sentinelRef, () => props.root], setupObserver)
52
+ onUnmounted(() => observer?.disconnect())
53
+ </script>