From 334e23f5775d5340f4d9d8a8982f3066cedb0b47 Mon Sep 17 00:00:00 2001 From: bobbykolev Date: Mon, 10 Feb 2025 17:33:19 +0200 Subject: [PATCH] Allow paste images from internet in MD editor. --- .../ui/forms/MarkdownInput/MarkdownInput.tsx | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/core/ui/forms/MarkdownInput/MarkdownInput.tsx b/src/core/ui/forms/MarkdownInput/MarkdownInput.tsx index 94fa6714aa..5ff3c9d36a 100644 --- a/src/core/ui/forms/MarkdownInput/MarkdownInput.tsx +++ b/src/core/ui/forms/MarkdownInput/MarkdownInput.tsx @@ -115,6 +115,10 @@ export const MarkdownInput = memo( return true; // Image } + if (clipboardData?.files?.length && clipboardData?.files[0].type.startsWith('image/')) { + return true; + } + if (item.kind === 'string' && item.type === 'text/html') { const htmlContent = clipboardData?.getData('text/html'); return htmlContent?.includes(' { - uploadFile({ - variables: { - file, - uploadData: { storageBucketId, temporaryLocation }, - }, - }); - }; - - reader.readAsDataURL(file); - imageProcessed = true; - } - } else if (item.kind === 'string' && item.type === 'text/html') { - imageProcessed = true; // HTML with images + const file = item.getAsFile(); + + if (file) { + const reader = new FileReader(); + + reader.onload = () => { + uploadFile({ + variables: { + file, + uploadData: { storageBucketId, temporaryLocation }, + }, + }); + }; + + reader.readAsDataURL(file); + imageProcessed = true; } }