Fix: #21566 Copy-Paste from Excel triggers file upload instead of pasting content (#21606)

This commit is contained in:
Shailesh Parmar 2025-06-05 20:37:11 +05:30 committed by GitHub
parent 472b95516d
commit 51e0f8b107
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View File

@ -21,7 +21,10 @@ import React, {
useRef,
} from 'react';
import { useTranslation } from 'react-i18next';
import { EDITOR_OPTIONS } from '../../constants/BlockEditor.constants';
import {
EDITOR_OPTIONS,
TEXT_TYPES,
} from '../../constants/BlockEditor.constants';
import { formatContent, setEditorContent } from '../../utils/BlockEditorUtils';
import Banner from '../common/Banner/Banner';
import { useEntityAttachment } from '../common/EntityDescription/EntityAttachmentProvider/EntityAttachmentProvider';
@ -79,12 +82,16 @@ const BlockEditor = forwardRef<BlockEditorRef, BlockEditorProps>(
},
handleDOMEvents: {
paste: (view, event) => {
// Allow paste if either image or file upload is enabled
if (!allowImageUpload && !allowFileUpload) {
const items = Array.from(event.clipboardData?.items || []);
// Check if the paste contains text types
const hasText = items.some(
(item) => item.kind === 'string' && TEXT_TYPES.includes(item.type)
);
// Allow paste if either image or file upload is enabled or if the paste contains text types
if ((!allowImageUpload && !allowFileUpload) || hasText) {
return false;
}
const items = Array.from(event.clipboardData?.items || []);
const files = items
.filter((item) => item.kind === FileType.FILE)
.map((item) => item.getAsFile())

View File

@ -73,3 +73,5 @@ export const LINK_PASTE_REGEX =
/(?:^|\s)\[([^\]]*)?\]\((\S+)(?: ["“](.+)["”])?\)/gi;
export const UPLOADED_ASSETS_URL = '/api/v1/attachments/';
export const TEXT_TYPES = ['text/plain', 'text/rtf'];