@@ -58,6 +58,8 @@ import WdsIcon from "@/wds/WdsIcon.vue";
5858import { validatorArrayOfString } from " @/constants/validators" ;
5959import type { PDFSrc } from " @tato30/vue-pdf" ;
6060import { dataURLToArrayBuffer } from " @/utils/base64" ;
61+ import type { EncodedFile } from " @/composables/useFilesEncoder/useFilesEncoder" ;
62+ import { isPlainObject } from " @/utils/object" ;
6163
6264const description = " A component to embed PDF documents." ;
6365
@@ -133,10 +135,47 @@ const loading = ref(false);
133135const pagesLoaded = ref (0 );
134136const highlightsList = ref ([]);
135137
138+ function isEncodedFile(input : unknown ): input is EncodedFile {
139+ return (
140+ isPlainObject (input ) &&
141+ " name" in input &&
142+ " type" in input &&
143+ " data" in input &&
144+ typeof input .data === " string" &&
145+ input .data .startsWith (" data:" )
146+ );
147+ }
148+
149+ function extractDataURLFromSource(source : unknown ): string | undefined {
150+ if (typeof source !== " string" || ! source .trim ()) {
151+ return undefined ;
152+ }
153+
154+ // Try to parse as JSON array (file upload format)
155+ try {
156+ const parsed = JSON .parse (source );
157+ if (Array .isArray (parsed ) && parsed .length > 0 ) {
158+ const firstFile = parsed [0 ];
159+ if (isEncodedFile (firstFile )) {
160+ return firstFile .data ;
161+ }
162+ }
163+ } catch {
164+ // Not valid JSON or not in expected format, continue to use source directly
165+ }
166+
167+ // Return source as-is (could be a direct URL or data URL)
168+ return source ;
169+ }
170+
136171const pdfData = computed (() => {
137172 if (! fields .source ?.value ) return undefined ;
173+
174+ const dataURL = extractDataURLFromSource (fields .source .value );
175+ if (! dataURL ) return undefined ;
176+
138177 try {
139- return dataURLToArrayBuffer (fields . source . value );
178+ return dataURLToArrayBuffer (dataURL );
140179 } catch {
141180 return undefined ;
142181 }
0 commit comments