From bb2f16bf5f8f06a6a917e0ad1a5dcdcb7c218472 Mon Sep 17 00:00:00 2001 From: Aaron Liu Date: Wed, 12 Nov 2025 14:13:04 +0800 Subject: [PATCH] fix(excalidraw): uploader DnD should be disabled while Excalidraw is open (fix cloudreve/cloudreve#3016) --- src/component/Uploader/Uploader.tsx | 8 +++++--- src/component/Uploader/core/index.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/component/Uploader/Uploader.tsx b/src/component/Uploader/Uploader.tsx index f722b70..d8c26b2 100644 --- a/src/component/Uploader/Uploader.tsx +++ b/src/component/Uploader/Uploader.tsx @@ -47,14 +47,15 @@ const Uploader = () => { const uploadRawFiles = useAppSelector((state) => state.globalState.uploadRawFiles); const displayOpt = useActionDisplayOpt([], ContextMenuTypes.empty, parent, FileManagerIndex.main); + const exclidrawOpen = useAppSelector((state) => state.globalState.excalidrawViewer?.open); useEffect(() => { - if (!parent) { + if (!parent || exclidrawOpen) { uploadEnabled.current = false; return; } uploadEnabled.current = displayOpt.showUpload ?? false; - }, [parent, displayOpt.showUpload]); + }, [parent, displayOpt.showUpload, exclidrawOpen]); const taskAdded = useCallback( (original?: Base) => (tasks: Base[]) => { @@ -99,10 +100,11 @@ const Uploader = () => { }, onDropLeave: (_e) => { if (!uploadEnabled.current) { - return; + return false; } dragCounter--; setDropBgOpen((value) => !value); + return true; }, onProactiveFileAdded: taskAdded(), onPoolEmpty: () => { diff --git a/src/component/Uploader/core/index.ts b/src/component/Uploader/core/index.ts index 612cef9..3d3021e 100644 --- a/src/component/Uploader/core/index.ts +++ b/src/component/Uploader/core/index.ts @@ -31,7 +31,8 @@ export interface Option { overwrite?: boolean; dropZone: HTMLElement | null; onDropOver?: (e: DragEvent) => void; - onDropLeave?: (e: DragEvent) => void; + // retuen if current dopped file should be accepted. + onDropLeave?: (e: DragEvent) => boolean; onToast: (type: MessageColor, msg: string) => void; onPoolEmpty?: () => void; onProactiveFileAdded?: (uploaders: Base[]) => void; @@ -276,7 +277,10 @@ export default class UploadManager { } const containFile = e.dataTransfer && e.dataTransfer.types.includes("Files"); if (containFile) { - this.o.onDropLeave && this.o.onDropLeave(e); + const shouldAccept = this.o.onDropLeave && this.o.onDropLeave(e); + if (!shouldAccept) { + return; + } const items = await getAllFileEntries(e.dataTransfer!.items); const uploaders = await new Promise((resolve, reject) => this.addFiles(items, this.currentPath as string, resolve, reject),