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 newUrl = event.target.value;
// Sanitize the 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<HTMLTextAreaElement>) => {
const newCode = event.target.value;
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<HTMLDivElement>, direction: 'horizontal' | 'vertical') => {