From 021f6d37d4691666666ff978a3298b45dc71a55e Mon Sep 17 00:00:00 2001 From: zsviczian Date: Tue, 4 Feb 2025 20:07:47 +0100 Subject: [PATCH 1/4] Fixes SAMSUNG update issue where blob.type === "" when adding image from gallery --- packages/excalidraw/data/blob.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/excalidraw/data/blob.ts b/packages/excalidraw/data/blob.ts index 2293f860c..ffa472767 100644 --- a/packages/excalidraw/data/blob.ts +++ b/packages/excalidraw/data/blob.ts @@ -107,6 +107,17 @@ export const isImageFileHandle = (handle: FileSystemHandle | null) => { return type === "png" || type === "svg"; }; +const getExtensionFromFilename = (filename?: string): string | null => { + if (!filename) return null; + const ext = filename.split('.').pop()?.toLowerCase(); + return ext || null; +}; + +const isSupportedExtension = (filename?: string) => { + const extension = getExtensionFromFilename(filename); + return !!extension && extension in IMAGE_MIME_TYPES; +}; + export const isSupportedImageFileType = (type: string | null | undefined) => { return !!type && (Object.values(IMAGE_MIME_TYPES) as string[]).includes(type); }; @@ -115,7 +126,11 @@ export const isSupportedImageFile = ( blob: Blob | null | undefined, ): blob is Blob & { type: ValueOf } => { const { type } = blob || {}; - return isSupportedImageFileType(type); + if (type) { + return isSupportedImageFileType(type); + } + const { name } = blob || {}; + return isSupportedExtension(name); }; export const loadSceneOrLibraryFromBlob = async ( From 413f852cf6a74cfc2b052fc70817f6e928fe5ae0 Mon Sep 17 00:00:00 2001 From: zsviczian Date: Tue, 4 Feb 2025 20:14:31 +0100 Subject: [PATCH 2/4] lint --- packages/excalidraw/data/blob.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/excalidraw/data/blob.ts b/packages/excalidraw/data/blob.ts index ffa472767..0934b8efd 100644 --- a/packages/excalidraw/data/blob.ts +++ b/packages/excalidraw/data/blob.ts @@ -108,8 +108,10 @@ export const isImageFileHandle = (handle: FileSystemHandle | null) => { }; const getExtensionFromFilename = (filename?: string): string | null => { - if (!filename) return null; - const ext = filename.split('.').pop()?.toLowerCase(); + if (!filename) { + return null; + } + const ext = filename.split(".").pop()?.toLowerCase(); return ext || null; }; From 2e876e98d7db56f6664d7240b6cb476c866af9f3 Mon Sep 17 00:00:00 2001 From: zsviczian Date: Tue, 4 Feb 2025 21:11:29 +0100 Subject: [PATCH 3/4] Update App.tsx --- packages/excalidraw/components/App.tsx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx index dc81f9181..122f5972e 100644 --- a/packages/excalidraw/components/App.tsx +++ b/packages/excalidraw/components/App.tsx @@ -9817,13 +9817,23 @@ class App extends React.Component { this.state, ); - const imageFile = await fileOpen({ + let imageFile = await fileOpen({ description: "Image", extensions: Object.keys( IMAGE_MIME_TYPES, ) as (keyof typeof IMAGE_MIME_TYPES)[], }); + //maybe temporary fix: https://github.com/excalidraw/excalidraw/issues/9091 + if (imageFile && !imageFile.type) { + const extension = imageFile.name.split(".").pop()?.toLowerCase(); + const mimeType = + IMAGE_MIME_TYPES[extension as keyof typeof IMAGE_MIME_TYPES]; + if (mimeType) { + imageFile = new File([imageFile], imageFile.name, { type: mimeType }); + } + } + const imageElement = this.createImageElement({ sceneX: x, sceneY: y, From 0aa260879970c40882b25fae688adab433ad761e Mon Sep 17 00:00:00 2001 From: zsviczian Date: Tue, 4 Feb 2025 21:12:18 +0100 Subject: [PATCH 4/4] Update blob.ts --- packages/excalidraw/data/blob.ts | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/packages/excalidraw/data/blob.ts b/packages/excalidraw/data/blob.ts index 0934b8efd..2293f860c 100644 --- a/packages/excalidraw/data/blob.ts +++ b/packages/excalidraw/data/blob.ts @@ -107,19 +107,6 @@ export const isImageFileHandle = (handle: FileSystemHandle | null) => { return type === "png" || type === "svg"; }; -const getExtensionFromFilename = (filename?: string): string | null => { - if (!filename) { - return null; - } - const ext = filename.split(".").pop()?.toLowerCase(); - return ext || null; -}; - -const isSupportedExtension = (filename?: string) => { - const extension = getExtensionFromFilename(filename); - return !!extension && extension in IMAGE_MIME_TYPES; -}; - export const isSupportedImageFileType = (type: string | null | undefined) => { return !!type && (Object.values(IMAGE_MIME_TYPES) as string[]).includes(type); }; @@ -128,11 +115,7 @@ export const isSupportedImageFile = ( blob: Blob | null | undefined, ): blob is Blob & { type: ValueOf } => { const { type } = blob || {}; - if (type) { - return isSupportedImageFileType(type); - } - const { name } = blob || {}; - return isSupportedExtension(name); + return isSupportedImageFileType(type); }; export const loadSceneOrLibraryFromBlob = async (