@datagouv/components-next 1.0.2-dev.40 → 1.0.2-dev.41

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.
@@ -1,45 +1,24 @@
1
1
  <template>
2
- <div class="fr-text--xs">
3
- <div v-if="xmlData">
4
- <XmlViewer :xml="xmlData" />
5
- </div>
6
- <div
7
- v-else-if="loading"
8
- class="text-gray-medium"
9
- >
10
- {{ t("Chargement de l'aperçu XML...") }}
11
- </div>
12
- <PreviewUnavailable v-else-if="fileTooLarge">
13
- {{ fileSizeBytes
14
- ? t("Le fichier XML est trop volumineux pour être prévisualisé. Téléchargez-le depuis l'onglet Téléchargements.")
15
- : t("La taille du fichier est inconnue, l'aperçu n'est pas disponible. Téléchargez-le depuis l'onglet Téléchargements.")
16
- }}
17
- </PreviewUnavailable>
18
- <PreviewUnavailable v-else-if="error === 'cors'">
19
- {{ t("Ce fichier XML ne peut pas être prévisualisé car il est hébergé sur un site distant qui restreint l'accès (CORS). Téléchargez-le depuis l'onglet Téléchargements.") }}
20
- </PreviewUnavailable>
21
- <PreviewUnavailable v-else-if="error === 'network'">
22
- {{ t("Ce fichier est hébergé sur un site externe qui ne permet pas la prévisualisation. Téléchargez-le depuis l'onglet Téléchargements.") }}
23
- </PreviewUnavailable>
24
- <PreviewUnavailable v-else-if="error">
25
- {{ t("L'aperçu de ce fichier n'a pas pu être chargé. Téléchargez-le depuis l'onglet Téléchargements.") }}
26
- </PreviewUnavailable>
27
- </div>
2
+ <PreviewWrapper
3
+ v-slot="{ data }"
4
+ file-type="XML"
5
+ :resource="resource"
6
+ :max-size="config.maxXmlPreviewCharSize"
7
+ :load="load"
8
+ >
9
+ <XmlViewer :xml="(data as string)" />
10
+ </PreviewWrapper>
28
11
  </template>
29
12
 
30
13
  <script setup lang="ts">
31
- import { computed, defineAsyncComponent, onMounted, ref } from 'vue'
14
+ import { defineAsyncComponent } from 'vue'
32
15
  import { useComponentsConfig } from '../../config'
33
- import PreviewUnavailable from './PreviewUnavailable.vue'
16
+ import PreviewWrapper from './PreviewWrapper.vue'
34
17
  import type { Resource } from '../../types/resources'
35
- import { getResourceFilesize, getResourceCorsStatus } from '../../functions/resources'
36
- import { useTranslation } from '../../composables/useTranslation'
37
18
  import '../../types/vue3-xml-viewer.d'
38
19
 
39
20
  const XmlViewer = defineAsyncComponent(() =>
40
- import('vue3-xml-viewer').then((module) => {
41
- return module.default || module.XmlViewer
42
- }),
21
+ import('vue3-xml-viewer').then(module => module.default || module.XmlViewer),
43
22
  )
44
23
 
45
24
  const props = defineProps<{
@@ -47,75 +26,10 @@ const props = defineProps<{
47
26
  }>()
48
27
 
49
28
  const config = useComponentsConfig()
50
- const { t } = useTranslation()
51
29
 
52
- const xmlData = ref<string | null>(null)
53
- const loading = ref(false)
54
- const error = ref<string | null>(null)
55
- const fileTooLarge = ref(false)
56
-
57
- const fileSizeBytes = computed(() => getResourceFilesize(props.resource))
58
-
59
- const corsStatus = computed(() => getResourceCorsStatus(props.resource))
60
-
61
- const isSizeAllowed = computed(() => {
62
- const size = fileSizeBytes.value
63
- // Convert maxXmlPreviewCharSize from characters to bytes (rough estimate)
64
- // Assuming average 1 byte per character for XML
65
- const maxByteSize = config.maxXmlPreviewCharSize
66
-
67
- // If we don't know the size or the max size, don't risk loading a potentially huge file
68
- if (!size || !maxByteSize) return false
69
-
70
- return size <= maxByteSize
71
- })
72
-
73
- const fetchXmlData = async () => {
74
- error.value = null
75
- fileTooLarge.value = false
76
-
77
- // Check if file is too large or size is unknown
78
- if (!isSizeAllowed.value) {
79
- fileTooLarge.value = true
80
- return
81
- }
82
-
83
- // Check if CORS is allowed
84
- if (corsStatus.value === 'blocked') {
85
- error.value = 'cors'
86
- return
87
- }
88
-
89
- loading.value = true
90
- try {
91
- const response = await fetch(props.resource.url)
92
- // const response = await fetch('/test-data.xml') // For testing locally without CORS issues
93
- if (!response.ok) {
94
- throw new Error(`HTTP error! status: ${response.status}`)
95
- }
96
- const data = await response.text()
97
-
98
- // Use the XML data as string - let the XML viewer handle large files
99
- xmlData.value = data
100
- }
101
- catch (err) {
102
- console.error('Error loading XML:', err)
103
-
104
- if (err instanceof TypeError) {
105
- error.value = 'network'
106
- }
107
- else {
108
- error.value = 'generic'
109
- }
110
-
111
- xmlData.value = null
112
- }
113
- finally {
114
- loading.value = false
115
- }
30
+ const load = async () => {
31
+ const response = await fetch(props.resource.url)
32
+ if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`)
33
+ return response.text()
116
34
  }
117
-
118
- onMounted(() => {
119
- fetchXmlData()
120
- })
121
35
  </script>
package/src/main.ts CHANGED
@@ -13,7 +13,7 @@ import type { License } from './types/licenses'
13
13
  import type { Member, MemberRole, NewOrganization, Organization, OrganizationOrSuggest, OrganizationReference, OrganizationSuggest } from './types/organizations'
14
14
  import type { Owned, OwnedWithFullObject, OwnedWithId } from './types/owned'
15
15
  import type { Comment, Thread } from './types/discussions'
16
- import type { Page, PageBloc, ContentBloc, BlocWithTitle, DatasetsListBloc, DataservicesListBloc, ReusesListBloc, LinkInBloc, LinksListBloc, MarkdownBloc, AccordionItemBloc, AccordionListBloc, HeroBloc } from './types/pages'
16
+ import type { PageBloc, ContentBloc, BlocWithTitle, DatasetsListBloc, DataservicesListBloc, ReusesListBloc, LinkInBloc, LinksListBloc, MarkdownBloc, AccordionItemBloc, AccordionListBloc, HeroBloc } from './types/pages'
17
17
  import type { Post } from './types/posts'
18
18
  import type { ReuseReference, NewReuse, Reuse, ReuseTopic, ReuseType } from './types/reuses'
19
19
  import type { RegisteredSchema, Schema, SchemaDetails, SchemaField, SchemaPath, SchemaPublicationMode, SchemaResponseData, SchemaVersion, ValidataError } from './types/schemas'
@@ -167,7 +167,6 @@ export type {
167
167
  Owned,
168
168
  OwnedWithFullObject,
169
169
  OwnedWithId,
170
- Page,
171
170
  PageBloc,
172
171
  ContentBloc,
173
172
  BlocWithTitle,
@@ -2,11 +2,6 @@ import type { DatasetV2 } from './datasets'
2
2
  import type { Dataservice } from './dataservices'
3
3
  import type { Reuse } from './reuses'
4
4
 
5
- export type Page = {
6
- id: string
7
- blocs: Array<PageBloc>
8
- }
9
-
10
5
  export type BlocWithTitle = {
11
6
  title: string
12
7
  subtitle: string | null
@@ -1,12 +1,12 @@
1
1
  import type { Dataset } from './datasets'
2
- import type { Page } from './pages'
2
+ import type { PageBloc } from './pages'
3
3
  import type { Reuse } from './reuses'
4
4
  import type { User } from './users'
5
5
 
6
6
  export type Post = {
7
7
  body_type: 'markdown' | 'html' | 'blocs'
8
+ blocs: Array<PageBloc>
8
9
  content: string
9
- content_as_page: Page | null
10
10
  created_at: string
11
11
  credit_to: string
12
12
  credit_url: string
package/src/types/site.ts CHANGED
@@ -1,9 +1,11 @@
1
+ import type { PageBloc } from './pages'
2
+
1
3
  export type Site = {
2
4
  id: string
3
5
  title: string
4
- datasets_page: string | null
5
- reuses_page: string | null
6
- dataservices_page: string | null
6
+ datasets_blocs: Array<PageBloc>
7
+ reuses_blocs: Array<PageBloc>
8
+ dataservices_blocs: Array<PageBloc>
7
9
  version: string
8
10
  metrics: {
9
11
  'dataservices': number
@@ -1,78 +0,0 @@
1
- import { defineComponent as S, defineAsyncComponent as z, ref as u, computed as g, onMounted as J, createElementBlock as m, openBlock as r, createBlock as i, createCommentVNode as N, createVNode as b, unref as s, toDisplayString as l, withCtx as c, createTextVNode as p } from "vue";
2
- import { u as B, a as O, g as V, b as E, _ as d } from "./main-ifX24DGW.js";
3
- const L = { class: "fr-text--xs" }, D = { key: 0 }, P = {
4
- key: 1,
5
- class: "text-gray-medium"
6
- }, q = /* @__PURE__ */ S({
7
- __name: "JsonPreview.client",
8
- props: {
9
- resource: {}
10
- },
11
- setup(T) {
12
- const y = z(
13
- () => import("./vue3-json-viewer-BXwup7nO.js").then((e) => (Promise.resolve({ }), e.JsonViewer))
14
- ), f = T, x = B(), { t: a } = O(), o = u(null), h = u(!1), t = u(null), v = u(!1), _ = g(() => V(f.resource)), k = g(() => E(f.resource)), w = g(() => {
15
- const e = _.value, n = x.maxJsonPreviewCharSize;
16
- return !e || !n ? !1 : e <= n;
17
- }), C = async () => {
18
- if (t.value = null, v.value = !1, !w.value) {
19
- v.value = !0;
20
- return;
21
- }
22
- if (k.value === "blocked") {
23
- t.value = "cors";
24
- return;
25
- }
26
- h.value = !0;
27
- try {
28
- const e = await fetch(f.resource.url);
29
- if (!e.ok)
30
- throw new Error(`HTTP error! status: ${e.status}`);
31
- const n = await e.json();
32
- o.value = n;
33
- } catch (e) {
34
- console.error("Error loading JSON:", e), e instanceof TypeError ? t.value = "network" : t.value = "generic", o.value = null;
35
- } finally {
36
- h.value = !1;
37
- }
38
- };
39
- return J(() => {
40
- C();
41
- }), (e, n) => (r(), m("div", L, [
42
- o.value ? (r(), m("div", D, [
43
- b(s(y), {
44
- value: o.value,
45
- boxed: "",
46
- sort: "",
47
- theme: "light",
48
- "max-depth": 3,
49
- "expand-depth": 2,
50
- "indent-width": 2
51
- }, null, 8, ["value"])
52
- ])) : h.value ? (r(), m("div", P, l(s(a)("Chargement de l'aperçu JSON...")), 1)) : v.value ? (r(), i(d, { key: 2 }, {
53
- default: c(() => [
54
- p(l(_.value ? s(a)("Le fichier JSON est trop volumineux pour être prévisualisé. Téléchargez-le depuis l'onglet Téléchargements.") : s(a)("La taille du fichier est inconnue, l'aperçu n'est pas disponible. Téléchargez-le depuis l'onglet Téléchargements.")), 1)
55
- ]),
56
- _: 1
57
- })) : t.value === "cors" ? (r(), i(d, { key: 3 }, {
58
- default: c(() => [
59
- p(l(s(a)("Ce fichier JSON ne peut pas être prévisualisé car il est hébergé sur un site distant qui restreint l'accès (CORS). Téléchargez-le depuis l'onglet Téléchargements.")), 1)
60
- ]),
61
- _: 1
62
- })) : t.value === "network" ? (r(), i(d, { key: 4 }, {
63
- default: c(() => [
64
- p(l(s(a)("Ce fichier est hébergé sur un site externe qui ne permet pas la prévisualisation. Téléchargez-le depuis l'onglet Téléchargements.")), 1)
65
- ]),
66
- _: 1
67
- })) : t.value ? (r(), i(d, { key: 5 }, {
68
- default: c(() => [
69
- p(l(s(a)("L'aperçu de ce fichier n'a pas pu être chargé. Téléchargez-le depuis l'onglet Téléchargements.")), 1)
70
- ]),
71
- _: 1
72
- })) : N("", !0)
73
- ]));
74
- }
75
- });
76
- export {
77
- q as default
78
- };
@@ -1,4 +0,0 @@
1
- import { j as f } from "./main-ifX24DGW.js";
2
- export {
3
- f as default
4
- };
@@ -1,70 +0,0 @@
1
- import { defineComponent as z, defineAsyncComponent as X, ref as u, computed as v, onMounted as L, createElementBlock as g, openBlock as r, createBlock as i, createCommentVNode as S, createVNode as b, unref as s, toDisplayString as n, withCtx as c, createTextVNode as f } from "vue";
2
- import { u as B, a as M, g as V, b as E, _ as p } from "./main-ifX24DGW.js";
3
- const D = { class: "fr-text--xs" }, N = { key: 0 }, P = {
4
- key: 1,
5
- class: "text-gray-medium"
6
- }, A = /* @__PURE__ */ z({
7
- __name: "XmlPreview.client",
8
- props: {
9
- resource: {}
10
- },
11
- setup(T) {
12
- const x = X(
13
- () => import("./vue3-xml-viewer.common-Bkgr-tAS.js").then((e) => e.v).then((e) => e.default || e.XmlViewer)
14
- ), d = T, y = B(), { t: a } = M(), o = u(null), m = u(!1), t = u(null), h = u(!1), _ = v(() => V(d.resource)), k = v(() => E(d.resource)), w = v(() => {
15
- const e = _.value, l = y.maxXmlPreviewCharSize;
16
- return !e || !l ? !1 : e <= l;
17
- }), C = async () => {
18
- if (t.value = null, h.value = !1, !w.value) {
19
- h.value = !0;
20
- return;
21
- }
22
- if (k.value === "blocked") {
23
- t.value = "cors";
24
- return;
25
- }
26
- m.value = !0;
27
- try {
28
- const e = await fetch(d.resource.url);
29
- if (!e.ok)
30
- throw new Error(`HTTP error! status: ${e.status}`);
31
- const l = await e.text();
32
- o.value = l;
33
- } catch (e) {
34
- console.error("Error loading XML:", e), e instanceof TypeError ? t.value = "network" : t.value = "generic", o.value = null;
35
- } finally {
36
- m.value = !1;
37
- }
38
- };
39
- return L(() => {
40
- C();
41
- }), (e, l) => (r(), g("div", D, [
42
- o.value ? (r(), g("div", N, [
43
- b(s(x), { xml: o.value }, null, 8, ["xml"])
44
- ])) : m.value ? (r(), g("div", P, n(s(a)("Chargement de l'aperçu XML...")), 1)) : h.value ? (r(), i(p, { key: 2 }, {
45
- default: c(() => [
46
- f(n(_.value ? s(a)("Le fichier XML est trop volumineux pour être prévisualisé. Téléchargez-le depuis l'onglet Téléchargements.") : s(a)("La taille du fichier est inconnue, l'aperçu n'est pas disponible. Téléchargez-le depuis l'onglet Téléchargements.")), 1)
47
- ]),
48
- _: 1
49
- })) : t.value === "cors" ? (r(), i(p, { key: 3 }, {
50
- default: c(() => [
51
- f(n(s(a)("Ce fichier XML ne peut pas être prévisualisé car il est hébergé sur un site distant qui restreint l'accès (CORS). Téléchargez-le depuis l'onglet Téléchargements.")), 1)
52
- ]),
53
- _: 1
54
- })) : t.value === "network" ? (r(), i(p, { key: 4 }, {
55
- default: c(() => [
56
- f(n(s(a)("Ce fichier est hébergé sur un site externe qui ne permet pas la prévisualisation. Téléchargez-le depuis l'onglet Téléchargements.")), 1)
57
- ]),
58
- _: 1
59
- })) : t.value ? (r(), i(p, { key: 5 }, {
60
- default: c(() => [
61
- f(n(s(a)("L'aperçu de ce fichier n'a pas pu être chargé. Téléchargez-le depuis l'onglet Téléchargements.")), 1)
62
- ]),
63
- _: 1
64
- })) : S("", !0)
65
- ]));
66
- }
67
- });
68
- export {
69
- A as default
70
- };