@datagouv/components-next 1.0.2-dev.43 → 1.0.2-dev.45

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 (28) hide show
  1. package/dist/{Datafair.client-BAokThtJ.js → Datafair.client-hLoIoNbP.js} +1 -1
  2. package/dist/{JsonPreview.client-DGiaDxVv.js → JsonPreview.client-BUCeeFKz.js} +2 -2
  3. package/dist/{MapContainer.client-BKGsAP0Y.js → MapContainer.client-DrQRSrq_.js} +2 -2
  4. package/dist/{PdfPreview.client-CGjP5ZYb.js → PdfPreview.client-vQ4bfJx3.js} +2 -2
  5. package/dist/{Pmtiles.client-C1I7pwT5.js → Pmtiles.client-DWtu_UNl.js} +1 -1
  6. package/dist/{PreviewWrapper.vue_vue_type_script_setup_true_lang-BlcvVwW8.js → PreviewWrapper.vue_vue_type_script_setup_true_lang-4Ufr2Kmw.js} +1 -1
  7. package/dist/{XmlPreview.client-CHUVVEH6.js → XmlPreview.client-CEEHnAFF.js} +3 -3
  8. package/dist/components-next.css +1 -1
  9. package/dist/components-next.js +54 -54
  10. package/dist/components.css +1 -1
  11. package/dist/{index-CzClB3i0.js → index-CsOZmih1.js} +1 -1
  12. package/dist/main-7DRSPyNj.js +71033 -0
  13. package/dist/{vue3-xml-viewer.common-CAwAbUJl.js → vue3-xml-viewer.common-DOIGuzsk.js} +1 -1
  14. package/package.json +4 -3
  15. package/src/components/OpenApiViewer/ContentTypeSelect.vue +48 -0
  16. package/src/components/OpenApiViewer/EndpointRequest.vue +164 -0
  17. package/src/components/OpenApiViewer/EndpointResponses.vue +149 -0
  18. package/src/components/OpenApiViewer/OpenApiViewer.vue +308 -0
  19. package/src/components/OpenApiViewer/SchemaPanel.vue +53 -0
  20. package/src/components/OpenApiViewer/SchemaTree.vue +77 -0
  21. package/src/components/OpenApiViewer/openapi.ts +150 -0
  22. package/src/components/ResourceAccordion/ResourceAccordion.vue +3 -4
  23. package/src/components/ResourceExplorer/ResourceExplorerViewer.vue +3 -6
  24. package/src/main.ts +2 -2
  25. package/assets/swagger-themes/newspaper.css +0 -1670
  26. package/dist/Swagger.client-U7ZDVUHL.js +0 -4
  27. package/dist/main-CF7lWk6R.js +0 -106591
  28. package/src/components/ResourceAccordion/Swagger.client.vue +0 -48
@@ -1,4 +1,4 @@
1
- import { c as Ke } from "./main-CF7lWk6R.js";
1
+ import { c as Ke } from "./main-7DRSPyNj.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.43",
3
+ "version": "1.0.2-dev.45",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {
@@ -45,14 +45,14 @@
45
45
  "remark-rehype": "^11.1.2",
46
46
  "strip-markdown": "^6.0.0",
47
47
  "stylefire": "^7.0.3",
48
- "swagger-ui-dist": "^5.27.1",
49
48
  "unified": "^11.0.5",
50
49
  "unist-util-visit": "^5.0.0",
51
50
  "vue-content-loader": "^2.0.1",
52
51
  "vue-sonner": "^2.0.9",
53
52
  "vue3-json-viewer": "^2.4.1",
54
53
  "vue3-text-clamp": "^0.1.2",
55
- "vue3-xml-viewer": "^0.0.14"
54
+ "vue3-xml-viewer": "^0.0.14",
55
+ "yaml": "^2.8.2"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@intlify/cli": "^0.13.1",
@@ -69,6 +69,7 @@
69
69
  "eslint-plugin-vue": "^10.0",
70
70
  "jiti": "^2.4.2",
71
71
  "npm-run-all2": "^8.0",
72
+ "openapi-types": "^12.1.3",
72
73
  "prettier": "^3.0.0",
73
74
  "tailwindcss": "^4.0.8",
74
75
  "typescript": "^5.7.3",
@@ -0,0 +1,48 @@
1
+ <template>
2
+ <Tooltip v-if="contentTypes.length > 1">
3
+ <div class="relative shrink-0">
4
+ <select
5
+ :value="modelValue"
6
+ class="appearance-none text-xs font-mono bg-white border border-gray-default rounded pl-2 pr-6 py-1 text-gray-medium cursor-pointer hover:border-gray-400 transition-colors"
7
+ @change="$emit('update:modelValue', ($event.target as HTMLSelectElement).value)"
8
+ >
9
+ <option
10
+ v-for="ct in contentTypes"
11
+ :key="ct"
12
+ :value="ct"
13
+ >
14
+ {{ contentTypeLabel(ct) }}
15
+ </option>
16
+ </select>
17
+ <RiArrowDownSLine class="pointer-events-none absolute right-1 top-1/2 -translate-y-1/2 size-3.5 text-gray-medium" />
18
+ </div>
19
+ <template #tooltip>
20
+ {{ modelValue }}
21
+ </template>
22
+ </Tooltip>
23
+ <Tooltip v-else-if="contentTypes.length === 1">
24
+ <span
25
+ class="text-xs font-mono bg-white border border-gray-default rounded px-2 py-1 text-gray-medium shrink-0"
26
+ >
27
+ {{ contentTypeLabel(contentTypes[0]!) }}
28
+ </span>
29
+ <template #tooltip>
30
+ {{ contentTypes[0] }}
31
+ </template>
32
+ </Tooltip>
33
+ </template>
34
+
35
+ <script setup lang="ts">
36
+ import { RiArrowDownSLine } from '@remixicon/vue'
37
+ import Tooltip from '../Tooltip.vue'
38
+ import { contentTypeLabel } from './openapi'
39
+
40
+ defineProps<{
41
+ contentTypes: string[]
42
+ modelValue: string
43
+ }>()
44
+
45
+ defineEmits<{
46
+ 'update:modelValue': [value: string]
47
+ }>()
48
+ </script>
@@ -0,0 +1,164 @@
1
+ <template>
2
+ <div class="border border-gray-default rounded">
3
+ <div
4
+ v-if="!tabs.length"
5
+ class="p-3 text-xs text-gray-medium"
6
+ >
7
+ {{ t("Aucun paramètre de requête") }}
8
+ </div>
9
+ <TabGroup
10
+ v-else
11
+ size="sm"
12
+ @change="onTabChange"
13
+ >
14
+ <div class="bg-gray-100 px-3 py-2 border-b border-gray-default flex items-center justify-between gap-2">
15
+ <TabList>
16
+ <Tab
17
+ v-for="tab in tabs"
18
+ :key="tab.key"
19
+ >
20
+ {{ tab.label }}
21
+ </Tab>
22
+ </TabList>
23
+ <ContentTypeSelect
24
+ v-if="activeTab === 'body' && bodyContentTypes.length"
25
+ :content-types="bodyContentTypes"
26
+ :model-value="selectedBodyContentType"
27
+ @update:model-value="selectedBodyContentType = $event"
28
+ />
29
+ </div>
30
+ <TabPanels>
31
+ <TabPanel
32
+ v-for="tab in tabs"
33
+ :key="tab.key"
34
+ >
35
+ <div
36
+ v-if="tab.key === 'query'"
37
+ class="p-3"
38
+ >
39
+ <div class="space-y-0 divide-y divide-gray-100">
40
+ <div
41
+ v-for="param in queryParams"
42
+ :key="param.name"
43
+ class="py-2"
44
+ >
45
+ <div class="flex items-baseline gap-2">
46
+ <span class="font-mono text-xs text-gray-title">
47
+ {{ param.name }}
48
+ <span
49
+ v-if="param.required"
50
+ class="text-red-600"
51
+ >*</span>
52
+ </span>
53
+ <span class="font-mono text-xs text-gray-medium">{{ getSchemaType(endpoint.spec, param.schema) }}</span>
54
+ </div>
55
+ <p
56
+ v-if="param.description"
57
+ class="text-xs text-gray-medium mt-0.5 mb-0"
58
+ >
59
+ {{ param.description }}
60
+ </p>
61
+ </div>
62
+ </div>
63
+ </div>
64
+ <div
65
+ v-if="tab.key === 'path'"
66
+ class="p-3"
67
+ >
68
+ <div class="space-y-0 divide-y divide-gray-100">
69
+ <div
70
+ v-for="param in pathParams"
71
+ :key="param.name"
72
+ class="py-2"
73
+ >
74
+ <div class="flex items-baseline gap-2">
75
+ <span class="font-mono text-xs text-gray-title">
76
+ {{ param.name }}
77
+ <span class="text-red-600">*</span>
78
+ </span>
79
+ <span class="font-mono text-xs text-gray-medium">{{ getSchemaType(endpoint.spec, param.schema) }}</span>
80
+ </div>
81
+ <p
82
+ v-if="param.description"
83
+ class="text-xs text-gray-medium mt-0.5 mb-0"
84
+ >
85
+ {{ param.description }}
86
+ </p>
87
+ </div>
88
+ </div>
89
+ </div>
90
+ <div
91
+ v-if="tab.key === 'body'"
92
+ class="p-3"
93
+ >
94
+ <SchemaPanel
95
+ v-if="currentBodyMediaType?.schema"
96
+ :spec="endpoint.spec"
97
+ :schema="currentBodyMediaType.schema"
98
+ />
99
+ </div>
100
+ </TabPanel>
101
+ </TabPanels>
102
+ </TabGroup>
103
+ </div>
104
+ </template>
105
+
106
+ <script setup lang="ts">
107
+ import { computed, ref, watch } from 'vue'
108
+ import TabGroup from '../Tabs/TabGroup.vue'
109
+ import TabList from '../Tabs/TabList.vue'
110
+ import Tab from '../Tabs/Tab.vue'
111
+ import TabPanels from '../Tabs/TabPanels.vue'
112
+ import TabPanel from '../Tabs/TabPanel.vue'
113
+ import ContentTypeSelect from './ContentTypeSelect.vue'
114
+ import { useTranslation } from '../../composables/useTranslation'
115
+ import SchemaPanel from './SchemaPanel.vue'
116
+ import { getSchemaType, type Endpoint } from './openapi'
117
+
118
+ const props = defineProps<{
119
+ endpoint: Endpoint
120
+ }>()
121
+
122
+ const { t } = useTranslation()
123
+
124
+ const queryParams = computed(() => props.endpoint.parameters.filter(p => p.in === 'query'))
125
+ const pathParams = computed(() => props.endpoint.parameters.filter(p => p.in === 'path'))
126
+
127
+ const tabs = computed(() => {
128
+ const result: { key: string, label: string }[] = []
129
+ if (pathParams.value.length) {
130
+ result.push({ key: 'path', label: t('Path') })
131
+ }
132
+ if (queryParams.value.length) {
133
+ result.push({ key: 'query', label: t('Query') })
134
+ }
135
+ if (props.endpoint.requestBody) {
136
+ result.push({ key: 'body', label: t('Body') })
137
+ }
138
+ return result
139
+ })
140
+
141
+ const activeTabIndex = ref(0)
142
+ const activeTab = computed(() => tabs.value[activeTabIndex.value]?.key || '')
143
+ const selectedBodyContentType = ref('')
144
+
145
+ const bodyContentTypes = computed(() => {
146
+ if (!props.endpoint.requestBody?.content) return []
147
+ return Object.keys(props.endpoint.requestBody.content)
148
+ })
149
+
150
+ const currentBodyMediaType = computed(() => {
151
+ if (!props.endpoint.requestBody?.content) return null
152
+ const ct = selectedBodyContentType.value || bodyContentTypes.value[0]
153
+ if (!ct) return null
154
+ return props.endpoint.requestBody.content[ct] || null
155
+ })
156
+
157
+ watch(bodyContentTypes, (types) => {
158
+ selectedBodyContentType.value = types[0] || ''
159
+ }, { immediate: true })
160
+
161
+ function onTabChange(index: number) {
162
+ activeTabIndex.value = index
163
+ }
164
+ </script>
@@ -0,0 +1,149 @@
1
+ <template>
2
+ <div class="border border-gray-default rounded">
3
+ <TabGroup
4
+ size="sm"
5
+ @change="onTabChange"
6
+ >
7
+ <div class="bg-gray-100 px-3 py-2 border-b border-gray-default flex items-center gap-4">
8
+ <div
9
+ ref="tabListContainer"
10
+ class="overflow-x-auto flex-1 min-w-0"
11
+ :class="{ 'scroll-fade': canScrollRight }"
12
+ @scroll="onScroll"
13
+ >
14
+ <TabList>
15
+ <Tab
16
+ v-for="tab in tabs"
17
+ :key="tab.code"
18
+ >
19
+ <span
20
+ class="inline-block w-2 h-2 rounded-full mr-1.5"
21
+ :class="statusDotColor(tab.code)"
22
+ />
23
+ {{ tab.code }}
24
+ </Tab>
25
+ </TabList>
26
+ </div>
27
+ <ContentTypeSelect
28
+ v-if="currentContentTypes.length"
29
+ :content-types="currentContentTypes"
30
+ :model-value="selectedContentType"
31
+ @update:model-value="selectedContentType = $event"
32
+ />
33
+ </div>
34
+ <TabPanels>
35
+ <TabPanel
36
+ v-for="tab in tabs"
37
+ :key="tab.code"
38
+ >
39
+ <div class="p-3 space-y-3">
40
+ <p
41
+ v-if="tab.response.description"
42
+ class="text-xs text-gray-medium mb-0 pb-3 border-b border-gray-100"
43
+ >
44
+ {{ tab.response.description }}
45
+ </p>
46
+ <template v-if="currentMediaType?.schema">
47
+ <SchemaPanel
48
+ :spec="spec"
49
+ :schema="currentMediaType.schema"
50
+ />
51
+ </template>
52
+ <p
53
+ v-else-if="!tab.response.content"
54
+ class="text-xs text-gray-medium mb-0"
55
+ >
56
+ {{ t("Pas de contenu") }}
57
+ </p>
58
+ </div>
59
+ </TabPanel>
60
+ </TabPanels>
61
+ </TabGroup>
62
+ </div>
63
+ </template>
64
+
65
+ <script setup lang="ts">
66
+ import { computed, ref, watch, useTemplateRef, onMounted, nextTick } from 'vue'
67
+ import TabGroup from '../Tabs/TabGroup.vue'
68
+ import TabList from '../Tabs/TabList.vue'
69
+ import Tab from '../Tabs/Tab.vue'
70
+ import TabPanels from '../Tabs/TabPanels.vue'
71
+ import TabPanel from '../Tabs/TabPanel.vue'
72
+ import ContentTypeSelect from './ContentTypeSelect.vue'
73
+ import { useTranslation } from '../../composables/useTranslation'
74
+ import SchemaPanel from './SchemaPanel.vue'
75
+ import type { OpenAPIV3 } from 'openapi-types'
76
+
77
+ const props = defineProps<{
78
+ responses: Record<string, OpenAPIV3.ResponseObject>
79
+ spec: OpenAPIV3.Document
80
+ }>()
81
+
82
+ const { t } = useTranslation()
83
+
84
+ const tabListContainer = useTemplateRef('tabListContainer')
85
+ const canScrollRight = ref(false)
86
+
87
+ function checkOverflow() {
88
+ const el = tabListContainer.value
89
+ if (!el) return
90
+ canScrollRight.value = el.scrollLeft + el.clientWidth < el.scrollWidth - 1
91
+ }
92
+
93
+ function onScroll() {
94
+ checkOverflow()
95
+ }
96
+
97
+ onMounted(checkOverflow)
98
+
99
+ const tabs = computed(() =>
100
+ Object.entries(props.responses).map(([code, response]) => ({ code, response })),
101
+ )
102
+
103
+ watch(tabs, () => {
104
+ nextTick(checkOverflow)
105
+ })
106
+
107
+ const activeTabIndex = ref(0)
108
+ const selectedContentType = ref('')
109
+
110
+ const currentContentTypes = computed(() => {
111
+ const tab = tabs.value[activeTabIndex.value]
112
+ if (!tab?.response.content) return []
113
+ return Object.keys(tab.response.content)
114
+ })
115
+
116
+ const currentMediaType = computed(() => {
117
+ const tab = tabs.value[activeTabIndex.value]
118
+ if (!tab?.response.content) return null
119
+ const ct = selectedContentType.value || currentContentTypes.value[0]
120
+ if (!ct) return null
121
+ return tab.response.content[ct] || null
122
+ })
123
+
124
+ watch(currentContentTypes, (types) => {
125
+ selectedContentType.value = types[0] || ''
126
+ }, { immediate: true })
127
+
128
+ function onTabChange(index: number) {
129
+ activeTabIndex.value = index
130
+ }
131
+
132
+ function statusDotColor(code: string): string {
133
+ if (code.startsWith('2')) return 'bg-green-600'
134
+ if (code.startsWith('3')) return 'bg-blue-600'
135
+ if (code.startsWith('4')) return 'bg-orange-500'
136
+ if (code.startsWith('5')) return 'bg-red-600'
137
+ return 'bg-gray-400'
138
+ }
139
+ </script>
140
+
141
+ <style scoped>
142
+ .scroll-fade {
143
+ mask-image: linear-gradient(to right, black calc(100% - 60px), transparent);
144
+ mask-size: 100% 100%;
145
+ mask-position: center;
146
+ padding-block: 4px;
147
+ margin-block: -4px;
148
+ }
149
+ </style>