fix: Embed block inputs accepts empty input #364

This commit is contained in:
swve 2024-11-28 22:42:03 +01:00
parent 780968ba06
commit a6506d5339

View file

@ -53,22 +53,29 @@ function EmbedObjectsComponent(props: any) {
const handleUrlChange = (event: React.ChangeEvent<HTMLInputElement>) => { const handleUrlChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const newUrl = event.target.value; const newUrl = event.target.value;
// Sanitize the URL const trimmedUrl = newUrl.trim();
const sanitizedUrl = DOMPurify.sanitize(newUrl); // Only update if URL is not just whitespace
setEmbedUrl(sanitizedUrl); if (newUrl === '' || trimmedUrl) {
props.updateAttributes({ const sanitizedUrl = DOMPurify.sanitize(newUrl);
embedUrl: sanitizedUrl, setEmbedUrl(sanitizedUrl);
embedType: 'url', props.updateAttributes({
}); embedUrl: sanitizedUrl,
embedType: 'url',
});
}
}; };
const handleCodeChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => { const handleCodeChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
const newCode = event.target.value; const newCode = event.target.value;
setEmbedCode(newCode); const trimmedCode = newCode.trim();
props.updateAttributes({ // Only update if code is not just whitespace
embedCode: newCode, if (newCode === '' || trimmedCode) {
embedType: 'code', setEmbedCode(newCode);
}); props.updateAttributes({
embedCode: newCode,
embedType: 'code',
});
}
}; };
const handleResizeStart = (event: React.MouseEvent<HTMLDivElement>, direction: 'horizontal' | 'vertical') => { const handleResizeStart = (event: React.MouseEvent<HTMLDivElement>, direction: 'horizontal' | 'vertical') => {