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, useRef,
} from 'react'; } from 'react';
import { useTranslation } from 'react-i18next'; 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 { formatContent, setEditorContent } from '../../utils/BlockEditorUtils';
import Banner from '../common/Banner/Banner'; import Banner from '../common/Banner/Banner';
import { useEntityAttachment } from '../common/EntityDescription/EntityAttachmentProvider/EntityAttachmentProvider'; import { useEntityAttachment } from '../common/EntityDescription/EntityAttachmentProvider/EntityAttachmentProvider';
@ -79,12 +82,16 @@ const BlockEditor = forwardRef<BlockEditorRef, BlockEditorProps>(
}, },
handleDOMEvents: { handleDOMEvents: {
paste: (view, event) => { paste: (view, event) => {
// Allow paste if either image or file upload is enabled const items = Array.from(event.clipboardData?.items || []);
if (!allowImageUpload && !allowFileUpload) { // 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; return false;
} }
const items = Array.from(event.clipboardData?.items || []);
const files = items const files = items
.filter((item) => item.kind === FileType.FILE) .filter((item) => item.kind === FileType.FILE)
.map((item) => item.getAsFile()) .map((item) => item.getAsFile())

View File

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