From a6506d5339c3585bb61fbf33e2e7e5a3fc540bad Mon Sep 17 00:00:00 2001 From: swve Date: Thu, 28 Nov 2024 22:42:03 +0100 Subject: [PATCH] fix: Embed block inputs accepts empty input #364 --- .../EmbedObjects/EmbedObjectsComponent.tsx | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/apps/web/components/Objects/Editor/Extensions/EmbedObjects/EmbedObjectsComponent.tsx b/apps/web/components/Objects/Editor/Extensions/EmbedObjects/EmbedObjectsComponent.tsx index 1cf77791..c5172c94 100644 --- a/apps/web/components/Objects/Editor/Extensions/EmbedObjects/EmbedObjectsComponent.tsx +++ b/apps/web/components/Objects/Editor/Extensions/EmbedObjects/EmbedObjectsComponent.tsx @@ -53,22 +53,29 @@ function EmbedObjectsComponent(props: any) { const handleUrlChange = (event: React.ChangeEvent) => { const newUrl = event.target.value; - // Sanitize the URL - const sanitizedUrl = DOMPurify.sanitize(newUrl); - setEmbedUrl(sanitizedUrl); - props.updateAttributes({ - embedUrl: sanitizedUrl, - embedType: 'url', - }); + const trimmedUrl = newUrl.trim(); + // Only update if URL is not just whitespace + if (newUrl === '' || trimmedUrl) { + const sanitizedUrl = DOMPurify.sanitize(newUrl); + setEmbedUrl(sanitizedUrl); + props.updateAttributes({ + embedUrl: sanitizedUrl, + embedType: 'url', + }); + } }; const handleCodeChange = (event: React.ChangeEvent) => { const newCode = event.target.value; - setEmbedCode(newCode); - props.updateAttributes({ - embedCode: newCode, - embedType: 'code', - }); + const trimmedCode = newCode.trim(); + // Only update if code is not just whitespace + if (newCode === '' || trimmedCode) { + setEmbedCode(newCode); + props.updateAttributes({ + embedCode: newCode, + embedType: 'code', + }); + } }; const handleResizeStart = (event: React.MouseEvent, direction: 'horizontal' | 'vertical') => {